• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 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 #include <wtf/PassOwnPtr.h>
41 
42 #ifdef __OBJC__
43 @class QTMovie;
44 #else
45 class QTMovie;
46 #endif
47 
48 namespace WebCore {
49 
50 // Structure that will hold every native
51 // types supported by the current media player.
52 // We have to do that has multiple media players
53 // backend can live at runtime.
54 typedef struct PlatformMedia {
55     QTMovie* qtMovie;
56 } PlatformMedia;
57 
58 static const PlatformMedia NoPlatformMedia = { 0 };
59 
60 class ContentType;
61 class FrameView;
62 class GraphicsContext;
63 class IntRect;
64 class IntSize;
65 class MediaPlayer;
66 class MediaPlayerPrivateInterface;
67 class String;
68 class TimeRanges;
69 
70 #if USE(ACCELERATED_COMPOSITING)
71 class GraphicsLayer;
72 #endif
73 
74 class MediaPlayerClient {
75 public:
~MediaPlayerClient()76     virtual ~MediaPlayerClient() { }
77 
78     // the network state has changed
mediaPlayerNetworkStateChanged(MediaPlayer *)79     virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
80 
81     // the ready state has changed
mediaPlayerReadyStateChanged(MediaPlayer *)82     virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
83 
84     // the volume state has changed
mediaPlayerVolumeChanged(MediaPlayer *)85     virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
86 
87     // the mute state has changed
mediaPlayerMuteChanged(MediaPlayer *)88     virtual void mediaPlayerMuteChanged(MediaPlayer*) { }
89 
90     // time has jumped, eg. not as a result of normal playback
mediaPlayerTimeChanged(MediaPlayer *)91     virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
92 
93     // the media file duration has changed, or is now known
mediaPlayerDurationChanged(MediaPlayer *)94     virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
95 
96     // the playback rate has changed
mediaPlayerRateChanged(MediaPlayer *)97     virtual void mediaPlayerRateChanged(MediaPlayer*) { }
98 
99     // The MediaPlayer has found potentially problematic media content.
100     // This is used internally to trigger swapping from a <video>
101     // element to an <embed> in standalone documents
mediaPlayerSawUnsupportedTracks(MediaPlayer *)102     virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { }
103 
104 // Presentation-related methods
105     // a new frame of video is available
mediaPlayerRepaint(MediaPlayer *)106     virtual void mediaPlayerRepaint(MediaPlayer*) { }
107 
108     // the movie size has changed
mediaPlayerSizeChanged(MediaPlayer *)109     virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
110 
111 #if USE(ACCELERATED_COMPOSITING)
112     // whether the rendering system can accelerate the display of this MediaPlayer.
mediaPlayerRenderingCanBeAccelerated(MediaPlayer *)113     virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
114 
115     // return the GraphicsLayer that will host the presentation for this MediaPlayer.
mediaPlayerGraphicsLayer(MediaPlayer *)116     virtual GraphicsLayer* mediaPlayerGraphicsLayer(MediaPlayer*) { return 0; }
117 #endif
118 };
119 
120 class MediaPlayer : public Noncopyable {
121 public:
122 
create(MediaPlayerClient * client)123     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
124     {
125         return new MediaPlayer(client);
126     }
127     virtual ~MediaPlayer();
128 
129     // media engine support
130     enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
131     static MediaPlayer::SupportsType supportsType(ContentType contentType);
132     static void getSupportedTypes(HashSet<String>&);
133     static bool isAvailable();
134 
135     bool supportsFullscreen() const;
136     bool supportsSave() const;
137     PlatformMedia platformMedia() const;
138 
139     IntSize naturalSize();
140     bool hasVideo() const;
141     bool hasAudio() const;
142 #if PLATFORM(ANDROID)
143     enum MediaElementType { Video, Audio };
setMediaElementType(MediaElementType type)144     void setMediaElementType(MediaElementType type) { m_mediaElementType = type; }
mediaElementType()145     MediaElementType mediaElementType() { return m_mediaElementType; }
146 #endif
147 
setFrameView(FrameView * frameView)148     void setFrameView(FrameView* frameView) { m_frameView = frameView; }
frameView()149     FrameView* frameView() { return m_frameView; }
150     bool inMediaDocument();
151 
size()152     IntSize size() const { return m_size; }
153     void setSize(const IntSize& size);
154 
155     void load(const String& url, const ContentType& contentType);
156     void cancelLoad();
157 
158     bool visible() const;
159     void setVisible(bool);
160 
161     void prepareToPlay();
162     void play();
163     void pause();
164 
165     bool paused() const;
166     bool seeking() const;
167 
168     float duration() const;
169     float currentTime() const;
170     void seek(float time);
171 
172     float startTime() const;
173 
174     float rate() const;
175     void setRate(float);
176 
177     bool preservesPitch() const;
178     void setPreservesPitch(bool);
179 
180     PassRefPtr<TimeRanges> buffered();
181     float maxTimeSeekable();
182 
183     unsigned bytesLoaded();
184 
185     float volume() const;
186     void setVolume(float);
187 
188     bool supportsMuting() const;
189     bool muted() const;
190     void setMuted(bool);
191 
192     bool hasClosedCaptions() const;
193     void setClosedCaptionsVisible(bool closedCaptionsVisible);
194 
195     bool autobuffer() const;
196     void setAutobuffer(bool);
197 
198     void paint(GraphicsContext*, const IntRect&);
199     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
200 
201     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
202     NetworkState networkState();
203 
204     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
205     ReadyState readyState();
206 
207     enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
208     MovieLoadType movieLoadType() const;
209 
210     void networkStateChanged();
211     void readyStateChanged();
212     void volumeChanged(float);
213     void muteChanged(bool);
214     void timeChanged();
215     void sizeChanged();
216     void rateChanged();
217     void durationChanged();
218 
219     void repaint();
220 
mediaPlayerClient()221     MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
222 
223     bool hasAvailableVideoFrame() const;
224 
225     bool canLoadPoster() const;
226     void setPoster(const String&);
227 
228 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
229     void deliverNotification(MediaPlayerProxyNotificationType notification);
230     void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
231 #endif
232 
233 #if USE(ACCELERATED_COMPOSITING)
234     // whether accelerated rendering is supported by the media engine for the current media.
235     bool supportsAcceleratedRendering() const;
236     // called when the rendering system flips the into or out of accelerated rendering mode.
237     void acceleratedRenderingStateChanged();
238 #endif
239 
240     bool hasSingleSecurityOrigin() const;
241 
242 private:
243     MediaPlayer(MediaPlayerClient*);
244 
245     static void initializeMediaEngines();
246 
247     MediaPlayerClient* m_mediaPlayerClient;
248     OwnPtr<MediaPlayerPrivateInterface*> m_private;
249     void* m_currentMediaEngine;
250     FrameView* m_frameView;
251     IntSize m_size;
252     bool m_visible;
253     float m_rate;
254     float m_volume;
255     bool m_muted;
256     bool m_preservesPitch;
257     bool m_autobuffer;
258 #if PLATFORM(ANDROID)
259     MediaElementType m_mediaElementType;
260 #endif
261 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
262     WebMediaPlayerProxy* m_playerProxy;    // not owned or used, passed to m_private
263 #endif
264 };
265 
266 typedef MediaPlayerPrivateInterface* (*CreateMediaEnginePlayer)(MediaPlayer*);
267 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
268 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs);
269 
270 typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType);
271 
272 
273 }
274 
275 #endif // ENABLE(VIDEO)
276 
277 #endif
278