• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef MediaPlayer_h
27 #define MediaPlayer_h
28 
29 #if ENABLE(VIDEO)
30 
31 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
32 #include "MediaPlayerProxy.h"
33 #endif
34 
35 #include "IntRect.h"
36 #include "StringHash.h"
37 #include <wtf/HashSet.h>
38 #include <wtf/OwnPtr.h>
39 #include <wtf/Noncopyable.h>
40 
41 namespace WebCore {
42 
43 class ContentType;
44 class FrameView;
45 class GraphicsContext;
46 class IntRect;
47 class IntSize;
48 class MediaPlayer;
49 class MediaPlayerPrivateInterface;
50 class String;
51 
52 #if USE(ACCELERATED_COMPOSITING)
53 class GraphicsLayer;
54 #endif
55 
56 class MediaPlayerClient {
57 public:
~MediaPlayerClient()58     virtual ~MediaPlayerClient() { }
59 
60     // the network state has changed
mediaPlayerNetworkStateChanged(MediaPlayer *)61     virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
62 
63     // the ready state has changed
mediaPlayerReadyStateChanged(MediaPlayer *)64     virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
65 
66     // the volume or muted state has changed
mediaPlayerVolumeChanged(MediaPlayer *)67     virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
68 
69     // time has jumped, eg. not as a result of normal playback
mediaPlayerTimeChanged(MediaPlayer *)70     virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
71 
72     // the media file duration has changed, or is now known
mediaPlayerDurationChanged(MediaPlayer *)73     virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
74 
75     // the playback rate has changed
mediaPlayerRateChanged(MediaPlayer *)76     virtual void mediaPlayerRateChanged(MediaPlayer*) { }
77 
78     // The MediaPlayer has found potentially problematic media content.
79     // This is used internally to trigger swapping from a <video>
80     // element to an <embed> in standalone documents
mediaPlayerSawUnsupportedTracks(MediaPlayer *)81     virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { }
82 
83 // Presentation-related methods
84     // a new frame of video is available
mediaPlayerRepaint(MediaPlayer *)85     virtual void mediaPlayerRepaint(MediaPlayer*) { }
86 
87     // the movie size has changed
mediaPlayerSizeChanged(MediaPlayer *)88     virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
89 
90 #if USE(ACCELERATED_COMPOSITING)
91     // whether the rendering system can accelerate the display of this MediaPlayer.
mediaPlayerRenderingCanBeAccelerated(MediaPlayer *)92     virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
93 
94     // return the GraphicsLayer that will host the presentation for this MediaPlayer.
mediaPlayerGraphicsLayer(MediaPlayer *)95     virtual GraphicsLayer* mediaPlayerGraphicsLayer(MediaPlayer*) { return 0; }
96 #endif
97 };
98 
99 class MediaPlayer : public Noncopyable {
100 public:
101     MediaPlayer(MediaPlayerClient*);
102     virtual ~MediaPlayer();
103 
104     // media engine support
105     enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
106     static MediaPlayer::SupportsType supportsType(ContentType contentType);
107     static void getSupportedTypes(HashSet<String>&);
108     static bool isAvailable();
109 
110     bool supportsFullscreen() const;
111     bool supportsSave() const;
112     IntSize naturalSize();
113     bool hasVideo();
114 
setFrameView(FrameView * frameView)115     void setFrameView(FrameView* frameView) { m_frameView = frameView; }
frameView()116     FrameView* frameView() { return m_frameView; }
117     bool inMediaDocument();
118 
size()119     IntSize size() const { return m_size; }
120     void setSize(const IntSize& size);
121 
122     void load(const String& url, const ContentType& contentType);
123     void cancelLoad();
124 
125     bool visible() const;
126     void setVisible(bool);
127 
128     void play();
129     void pause();
130 
131     bool paused() const;
132     bool seeking() const;
133 
134     float duration() const;
135     float currentTime() const;
136     void seek(float time);
137 
138     float startTime() const;
139 
140     void setEndTime(float time);
141 
142     float rate() const;
143     void setRate(float);
144 
145     bool preservesPitch() const;
146     void setPreservesPitch(bool);
147 
148     float maxTimeBuffered();
149     float maxTimeSeekable();
150 
151     unsigned bytesLoaded();
152     bool totalBytesKnown();
153     unsigned totalBytes();
154 
155     float volume() const;
156     void setVolume(float);
157 
158     int dataRate() const;
159 
160     bool autobuffer() const;
161     void setAutobuffer(bool);
162 
163     void paint(GraphicsContext*, const IntRect&);
164     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
165 
166     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
167     NetworkState networkState();
168 
169     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
170     ReadyState readyState();
171 
172     enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
173     MovieLoadType movieLoadType() const;
174 
175     void networkStateChanged();
176     void readyStateChanged();
177     void volumeChanged();
178     void timeChanged();
179     void sizeChanged();
180     void rateChanged();
181     void durationChanged();
182 
183     void repaint();
184 
mediaPlayerClient()185     MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
186 
187 #if PLATFORM(ANDROID)
188     bool canLoadPoster() const;
189     void setPoster(const String&);
190     void prepareToPlay();
191 #endif
192 
193 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
194     void setPoster(const String& url);
195     void deliverNotification(MediaPlayerProxyNotificationType notification);
196     void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
197 #endif
198 
199 #if USE(ACCELERATED_COMPOSITING)
200     // whether accelerated rendering is supported by the media engine for the current media.
201     bool supportsAcceleratedRendering() const;
202     // called when the rendering system flips the into or out of accelerated rendering mode.
203     void acceleratedRenderingStateChanged();
204 #endif
205 
206     bool hasSingleSecurityOrigin() const;
207 
208 private:
209     static void initializeMediaEngines();
210 
211     MediaPlayerClient* m_mediaPlayerClient;
212     OwnPtr<MediaPlayerPrivateInterface*> m_private;
213     void* m_currentMediaEngine;
214     FrameView* m_frameView;
215     IntSize m_size;
216     bool m_visible;
217     float m_rate;
218     float m_volume;
219     bool m_preservesPitch;
220     bool m_autobuffer;
221 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
222     WebMediaPlayerProxy* m_playerProxy;    // not owned or used, passed to m_private
223 #endif
224 };
225 
226 typedef MediaPlayerPrivateInterface* (*CreateMediaEnginePlayer)(MediaPlayer*);
227 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
228 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs);
229 
230 typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType);
231 
232 
233 }
234 
235 #endif // ENABLE(VIDEO)
236 
237 #endif
238