OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / platform / graphics / MediaPlayer.h
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 "Document.h"
36 #include "IntRect.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>
43
44 #if USE(ACCELERATED_COMPOSITING)
45 #include "GraphicsLayer.h"
46 #endif
47
48 #ifdef __OBJC__
49 @class QTMovie;
50 #else
51 class QTMovie;
52 #endif
53 class QTMovieGWorld;
54 class QTMovieVisualContext;
55
56 namespace WebCore {
57
58 class GStreamerGWorld;
59 class MediaPlayerPrivateInterface;
60
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 {
66     enum {
67         None,
68         QTMovieType,
69         QTMovieGWorldType,
70         QTMovieVisualContextType,
71         GStreamerGWorldType,
72         ChromiumMediaPlayerType,
73         QtMediaPlayerType,
74     } type;
75
76     union {
77         QTMovie* qtMovie;
78         QTMovieGWorld* qtMovieGWorld;
79         QTMovieVisualContext* qtMovieVisualContext;
80         GStreamerGWorld* gstreamerGWorld;
81         MediaPlayerPrivateInterface* chromiumMediaPlayer;
82         MediaPlayerPrivateInterface* qtMediaPlayer;
83     } media;
84 };
85
86 extern const PlatformMedia NoPlatformMedia;
87
88 class ContentType;
89 class FrameView;
90 class GraphicsContext;
91 class IntRect;
92 class IntSize;
93 class MediaPlayer;
94 class TimeRanges;
95
96 class MediaPlayerClient {
97 public:
98     virtual ~MediaPlayerClient() { }
99
100     // Get the document which the media player is owned by
101     virtual Document* mediaPlayerOwningDocument() { return 0; }
102
103     // the network state has changed
104     virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { }
105
106     // the ready state has changed
107     virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { }
108
109     // the volume state has changed
110     virtual void mediaPlayerVolumeChanged(MediaPlayer*) { }
111
112     // the mute state has changed
113     virtual void mediaPlayerMuteChanged(MediaPlayer*) { }
114
115     // time has jumped, eg. not as a result of normal playback
116     virtual void mediaPlayerTimeChanged(MediaPlayer*) { }
117     
118     // the media file duration has changed, or is now known
119     virtual void mediaPlayerDurationChanged(MediaPlayer*) { }
120     
121     // the playback rate has changed
122     virtual void mediaPlayerRateChanged(MediaPlayer*) { }
123
124     // the play/pause status changed
125     virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { }
126
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*) { }
131
132 // Presentation-related methods
133     // a new frame of video is available
134     virtual void mediaPlayerRepaint(MediaPlayer*) { }
135
136     // the movie size has changed
137     virtual void mediaPlayerSizeChanged(MediaPlayer*) { }
138
139 #if USE(ACCELERATED_COMPOSITING)
140     // whether the rendering system can accelerate the display of this MediaPlayer.
141     virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; }
142
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*) { }
146 #endif
147 };
148
149 class MediaPlayer : public Noncopyable {
150 public:
151
152     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient* client)
153     {
154         return adoptPtr(new MediaPlayer(client));
155     }
156     virtual ~MediaPlayer();
157
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();
163
164     bool supportsFullscreen() const;
165     bool supportsSave() const;
166     PlatformMedia platformMedia() const;
167 #if USE(ACCELERATED_COMPOSITING)
168     PlatformLayer* platformLayer() const;
169 #endif
170
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; }
178 #endif
179     
180     void setFrameView(FrameView* frameView) { m_frameView = frameView; }
181     FrameView* frameView() { return m_frameView; }
182     bool inMediaDocument();
183     
184     IntSize size() const { return m_size; }
185     void setSize(const IntSize& size);
186     
187     void load(const String& url, const ContentType& contentType);
188     void cancelLoad();
189     
190     bool visible() const;
191     void setVisible(bool);
192     
193     void prepareToPlay();
194     void play();
195     void pause();    
196     
197     bool paused() const;
198     bool seeking() const;
199     
200     float duration() const;
201     float currentTime() const;
202     void seek(float time);
203
204     float startTime() const;
205     
206     float rate() const;
207     void setRate(float);
208
209     bool preservesPitch() const;    
210     void setPreservesPitch(bool);
211     
212     PassRefPtr<TimeRanges> buffered();
213     float maxTimeSeekable();
214
215     unsigned bytesLoaded();
216     
217     float volume() const;
218     void setVolume(float);
219
220     bool muted() const;
221     void setMuted(bool);
222
223     bool hasClosedCaptions() const;
224     void setClosedCaptionsVisible(bool closedCaptionsVisible);
225
226     bool autoplay() const;    
227     void setAutoplay(bool);
228
229     void paint(GraphicsContext*, const IntRect&);
230     void paintCurrentFrameInContext(GraphicsContext*, const IntRect&);
231     
232     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
233     NetworkState networkState();
234
235     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
236     ReadyState readyState();
237     
238     enum MovieLoadType { Unknown, Download, StoredStream, LiveStream };
239     MovieLoadType movieLoadType() const;
240
241     enum Preload { None, MetaData, Auto };
242     Preload preload() const;
243     void setPreload(Preload);
244
245     void networkStateChanged();
246     void readyStateChanged();
247     void volumeChanged(float);
248     void muteChanged(bool);
249     void timeChanged();
250     void sizeChanged();
251     void rateChanged();
252     void playbackStateChanged();
253     void durationChanged();
254
255     void repaint();
256
257     MediaPlayerClient* mediaPlayerClient() const { return m_mediaPlayerClient; }
258
259     bool hasAvailableVideoFrame() const;
260     void prepareForRendering();
261
262     bool canLoadPoster() const;
263     void setPoster(const String&);
264
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();
271 #endif
272
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();
278 #endif
279
280     bool hasSingleSecurityOrigin() const;
281
282     float mediaTimeForTimeValue(float) const;
283
284 private:
285     MediaPlayer(MediaPlayerClient*);
286
287     static void initializeMediaEngines();
288
289     MediaPlayerClient* m_mediaPlayerClient;
290     OwnPtr<MediaPlayerPrivateInterface*> m_private;
291     void* m_currentMediaEngine;
292     FrameView* m_frameView;
293     IntSize m_size;
294     Preload m_preload;
295     bool m_visible;
296     float m_rate;
297     float m_volume;
298     bool m_muted;
299     bool m_preservesPitch;
300 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
301     WebMediaPlayerProxy* m_playerProxy;    // not owned or used, passed to m_private
302 #endif
303 #if PLATFORM(ANDROID)
304     MediaElementType m_mediaElementType;
305 #endif
306 };
307
308 typedef MediaPlayerPrivateInterface* (*CreateMediaEnginePlayer)(MediaPlayer*);
309 typedef void (*MediaEngineSupportedTypes)(HashSet<String>& types);
310 typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const String& type, const String& codecs);
311
312 typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType); 
313
314
315 }
316
317 #endif // ENABLE(VIDEO)
318
319 #endif