2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
31 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
32 #include "MediaPlayerProxy.h"
37 #include <wtf/Forward.h>
38 #include <wtf/HashSet.h>
39 #include <wtf/OwnPtr.h>
40 #include <wtf/Noncopyable.h>
41 #include <wtf/PassOwnPtr.h>
42 #include <wtf/text/StringHash.h>
44 #if USE(ACCELERATED_COMPOSITING)
45 #include "GraphicsLayer.h"
54 class QTMovieVisualContext;
58 class GStreamerGWorld;
59 class MediaPlayerPrivateInterface;
61 // Structure that will hold every native
62 // types supported by the current media player.
63 // We have to do that has multiple media players
64 // backend can live at runtime.
65 struct PlatformMedia {
70 QTMovieVisualContextType,
72 ChromiumMediaPlayerType,
78 QTMovieGWorld* qtMovieGWorld;
79 QTMovieVisualContext* qtMovieVisualContext;
80 GStreamerGWorld* gstreamerGWorld;
81 MediaPlayerPrivateInterface* chromiumMediaPlayer;
82 MediaPlayerPrivateInterface* qtMediaPlayer;
86 extern const PlatformMedia NoPlatformMedia;
90 class GraphicsContext;
96 class MediaPlayerClient {
98 virtual ~MediaPlayerClient() { }
100 // Get the document which the media player is owned by
101 virtual Document* mediaPlayerOwningDocument() { return 0; }
103 // the network state has changed
104 virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
106 // the ready state has changed
107 virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
109 // the volume state has changed
110 virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
112 // the mute state has changed
113 virtual void mediaPlayerMuteChanged(MediaPlayer*) { }
115 // time has jumped, eg. not as a result of normal playback
116 virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
118 // the media file duration has changed, or is now known
119 virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
121 // the playback rate has changed
122 virtual void mediaPlayerRateChanged(MediaPlayer*) { }
124 // the play/pause status changed
125 virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { }
127 // The MediaPlayer has found potentially problematic media content.
128 // This is used internally to trigger swapping from a <video>
129 // element to an <embed> in standalone documents
130 virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { }
132 // Presentation-related methods
133 // a new frame of video is available
134 virtual void mediaPlayerRepaint(MediaPlayer*) { }
136 // the movie size has changed
137 virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
139 #if USE(ACCELERATED_COMPOSITING)
140 // whether the rendering system can accelerate the display of this MediaPlayer.
141 virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
143 // called when the media player's rendering mode changed, which indicates a change in the
144 // availability of the platformLayer().
145 virtual void mediaPlayerRenderingModeChanged(MediaPlayer*) { }
149 class MediaPlayer : public Noncopyable {
152 static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
154 return adoptPtr(new MediaPlayer(client));
156 virtual ~MediaPlayer();
158 // media engine support
159 enum SupportsType { IsNotSupported, IsSupported, MayBeSupported };
160 static MediaPlayer::SupportsType supportsType(ContentType contentType);
161 static void getSupportedTypes(HashSet<String>&);
162 static bool isAvailable();
164 bool supportsFullscreen() const;
165 bool supportsSave() const;
166 PlatformMedia platformMedia() const;
167 #if USE(ACCELERATED_COMPOSITING)
168 PlatformLayer* platformLayer() const;
171 IntSize naturalSize();
172 bool hasVideo() const;
173 bool hasAudio() const;
174 #if PLATFORM(ANDROID)
175 enum MediaElementType { Video, Audio };
176 void setMediaElementType(MediaElementType type) { m_mediaElementType = type; }
177 MediaElementType mediaElementType() { return m_mediaElementType; }
180 void setFrameView(FrameView* frameView) { m_frameView = frameView; }
181 FrameView* frameView() { return m_frameView; }
182 bool inMediaDocument();
184 IntSize size() const { return m_size; }
185 void setSize(const IntSize& size);
187 void load(const String& url, const ContentType& contentType);
190 bool visible() const;
191 void setVisible(bool);
193 void prepareToPlay();
198 bool seeking() const;
200 float duration() const;
201 float currentTime() const;
202 void seek(float time);
204 float startTime() const;
209 bool preservesPitch() const;
210 void setPreservesPitch(bool);
212 PassRefPtr<TimeRanges> buffered();
213 float maxTimeSeekable();
215 unsigned bytesLoaded();
217 float volume() const;
218 void setVolume(float);
223 bool hasClosedCaptions() const;
224 void setClosedCaptionsVisible(bool closedCaptionsVisible);
226 bool autoplay() const;
227 void setAutoplay(bool);
229 void paint(GraphicsContext*, const IntRect&);
230 void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
232 enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
233 NetworkState networkState();
235 enum ReadyState { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
236 ReadyState readyState();
238 enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
239 MovieLoadType movieLoadType() const;
241 enum Preload { None, MetaData, Auto };
242 Preload preload() const;
243 void setPreload(Preload);
245 void networkStateChanged();
246 void readyStateChanged();
247 void volumeChanged(float);
248 void muteChanged(bool);
252 void playbackStateChanged();
253 void durationChanged();
257 MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
259 bool hasAvailableVideoFrame() const;
260 void prepareForRendering();
262 bool canLoadPoster() const;
263 void setPoster(const String&);
265 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
266 void deliverNotification(MediaPlayerProxyNotificationType notification);
267 void setMediaPlayerProxy(WebMediaPlayerProxy* proxy);
268 void setControls(bool);
269 void enterFullscreen();
270 void exitFullscreen();
273 #if USE(ACCELERATED_COMPOSITING)
274 // whether accelerated rendering is supported by the media engine for the current media.
275 bool supportsAcceleratedRendering() const;
276 // called when the rendering system flips the into or out of accelerated rendering mode.
277 void acceleratedRenderingStateChanged();
280 bool hasSingleSecurityOrigin() const;
282 float mediaTimeForTimeValue(float) const;
285 MediaPlayer(MediaPlayerClient*);
287 static void initializeMediaEngines();
289 MediaPlayerClient* m_mediaPlayerClient;
290 OwnPtr<MediaPlayerPrivateInterface*> m_private;
291 void* m_currentMediaEngine;
292 FrameView* m_frameView;
299 bool m_preservesPitch;
300 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
301 WebMediaPlayerProxy* m_playerProxy; // not owned or used, passed to m_private
303 #if PLATFORM(ANDROID)
304 MediaElementType m_mediaElementType;
308 typedef MediaPlayerPrivateInterface* (*CreateMediaEnginePlayer)(MediaPlayer*);
309 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
310 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs);
312 typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType);
317 #endif // ENABLE(VIDEO)