Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / media / MediaPlayer.h
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 #include "platform/PlatformExport.h"
30 #include "platform/graphics/GraphicsTypes3D.h"
31 #include "public/platform/WebMediaPlayer.h"
32 #include "wtf/Forward.h"
33 #include "wtf/Noncopyable.h"
34
35 namespace blink {
36 class WebGraphicsContext3D;
37 class WebContentDecryptionModule;
38 class WebInbandTextTrack;
39 class WebLayer;
40 class WebMediaSource;
41 }
42
43 namespace WebCore {
44
45 class AudioSourceProvider;
46 class GraphicsContext;
47 class IntRect;
48 class IntSize;
49 class KURL;
50 class MediaPlayer;
51 class TimeRanges;
52
53 // GL types as defined in OpenGL ES 2.0 header file gl2.h from khronos.org.
54 // That header cannot be included directly due to a conflict with NPAPI headers.
55 // See crbug.com/328085.
56 typedef unsigned GC3Denum;
57 typedef int GC3Dint;
58
59 class MediaPlayerClient {
60 public:
61     virtual ~MediaPlayerClient() { }
62
63     // the network state has changed
64     virtual void mediaPlayerNetworkStateChanged() = 0;
65
66     // the ready state has changed
67     virtual void mediaPlayerReadyStateChanged() = 0;
68
69     // time has jumped, eg. not as a result of normal playback
70     virtual void mediaPlayerTimeChanged() = 0;
71
72     // the media file duration has changed, or is now known
73     virtual void mediaPlayerDurationChanged() = 0;
74
75     // the play/pause status changed
76     virtual void mediaPlayerPlaybackStateChanged() = 0;
77
78     virtual void mediaPlayerRequestFullscreen() = 0;
79
80     virtual void mediaPlayerRequestSeek(double) = 0;
81
82     // The URL for video poster image.
83     // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
84     virtual KURL mediaPlayerPosterURL() = 0;
85
86 // Presentation-related methods
87     // a new frame of video is available
88     virtual void mediaPlayerRepaint() = 0;
89
90     // the movie size has changed
91     virtual void mediaPlayerSizeChanged() = 0;
92
93     virtual void mediaPlayerSetWebLayer(blink::WebLayer*) = 0;
94
95     virtual void mediaPlayerDidAddTextTrack(blink::WebInbandTextTrack*) = 0;
96     virtual void mediaPlayerDidRemoveTextTrack(blink::WebInbandTextTrack*) = 0;
97
98     virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) = 0;
99 };
100
101 typedef PassOwnPtr<MediaPlayer> (*CreateMediaEnginePlayer)(MediaPlayerClient*);
102
103 class PLATFORM_EXPORT MediaPlayer {
104     WTF_MAKE_NONCOPYABLE(MediaPlayer);
105 public:
106     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*);
107     static void setMediaEngineCreateFunction(CreateMediaEnginePlayer);
108
109     static double invalidTime() { return -1.0; }
110
111     MediaPlayer() { }
112     virtual ~MediaPlayer() { }
113
114     virtual void load(blink::WebMediaPlayer::LoadType, const String& url, blink::WebMediaPlayer::CORSMode) = 0;
115
116     virtual void play() = 0;
117     virtual void pause() = 0;
118
119     virtual bool supportsSave() const = 0;
120     virtual IntSize naturalSize() const = 0;
121
122     virtual bool hasVideo() const = 0;
123     virtual bool hasAudio() const = 0;
124
125     virtual double duration() const = 0;
126
127     virtual double currentTime() const = 0;
128
129     virtual void seek(double) = 0;
130
131     virtual bool seeking() const = 0;
132
133     virtual double rate() const = 0;
134     virtual void setRate(double) = 0;
135
136     virtual bool paused() const = 0;
137
138     virtual void setPoster(const KURL&) = 0;
139
140     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
141     virtual NetworkState networkState() const = 0;
142
143     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
144     virtual ReadyState readyState() const = 0;
145
146     virtual double maxTimeSeekable() const = 0;
147     virtual PassRefPtr<TimeRanges> buffered() const = 0;
148
149     virtual bool didLoadingProgress() const = 0;
150
151     virtual void paint(GraphicsContext*, const IntRect&) = 0;
152     virtual bool copyVideoTextureToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) = 0;
153
154     enum Preload { None, MetaData, Auto };
155     virtual void setPreload(Preload) = 0;
156
157     virtual void showFullscreenOverlay() = 0;
158     virtual void hideFullscreenOverlay() = 0;
159     virtual bool canShowFullscreenOverlay() const = 0;
160
161     virtual bool hasSingleSecurityOrigin() const = 0;
162
163     virtual bool didPassCORSAccessCheck() const = 0;
164
165     // Time value in the movie's time scale. It is only necessary to override this if the media
166     // engine uses rational numbers to represent media time.
167     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
168
169     virtual unsigned decodedFrameCount() const = 0;
170     virtual unsigned droppedFrameCount() const = 0;
171     virtual unsigned corruptedFrameCount() const = 0;
172     virtual unsigned audioDecodedByteCount() const = 0;
173     virtual unsigned videoDecodedByteCount() const = 0;
174
175 #if ENABLE(WEB_AUDIO)
176     virtual AudioSourceProvider* audioSourceProvider() = 0;
177 #endif
178     virtual blink::WebMediaPlayer* webMediaPlayer() const = 0;
179 };
180
181 }
182
183 #endif // MediaPlayer_h