Upstream version 5.34.104.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     enum CORSMode { Unspecified, Anonymous, UseCredentials };
62
63     virtual ~MediaPlayerClient() { }
64
65     // the network state has changed
66     virtual void mediaPlayerNetworkStateChanged() = 0;
67
68     // the ready state has changed
69     virtual void mediaPlayerReadyStateChanged() = 0;
70
71     // time has jumped, eg. not as a result of normal playback
72     virtual void mediaPlayerTimeChanged() = 0;
73
74     // the media file duration has changed, or is now known
75     virtual void mediaPlayerDurationChanged() = 0;
76
77     // the play/pause status changed
78     virtual void mediaPlayerPlaybackStateChanged() = 0;
79
80     virtual void mediaPlayerRequestFullscreen() = 0;
81
82     virtual void mediaPlayerRequestSeek(double) = 0;
83
84     // The URL for video poster image.
85     // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
86     virtual KURL mediaPlayerPosterURL() = 0;
87
88 // Presentation-related methods
89     // a new frame of video is available
90     virtual void mediaPlayerRepaint() = 0;
91
92     // the movie size has changed
93     virtual void mediaPlayerSizeChanged() = 0;
94
95     enum MediaKeyErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError };
96     virtual void mediaPlayerKeyAdded(const String& /* keySystem */, const String& /* sessionId */) = 0;
97     virtual void mediaPlayerKeyError(const String& /* keySystem */, const String& /* sessionId */, MediaKeyErrorCode, unsigned short /* systemCode */) = 0;
98     virtual void mediaPlayerKeyMessage(const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* message */, unsigned /* messageLength */, const KURL& /* defaultURL */) = 0;
99     virtual bool mediaPlayerKeyNeeded(const String& /* contentType */, const unsigned char* /* initData */, unsigned /* initDataLength */) = 0;
100
101     virtual CORSMode mediaPlayerCORSMode() const = 0;
102
103     virtual void mediaPlayerSetWebLayer(blink::WebLayer*) = 0;
104     virtual void mediaPlayerSetOpaque(bool) = 0;
105
106     virtual void mediaPlayerDidAddTrack(blink::WebInbandTextTrack*) = 0;
107     virtual void mediaPlayerDidRemoveTrack(blink::WebInbandTextTrack*) = 0;
108
109     virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) = 0;
110 };
111
112 typedef PassOwnPtr<MediaPlayer> (*CreateMediaEnginePlayer)(MediaPlayerClient*);
113
114 class PLATFORM_EXPORT MediaPlayer {
115     WTF_MAKE_NONCOPYABLE(MediaPlayer);
116 public:
117     static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*);
118     static void setMediaEngineCreateFunction(CreateMediaEnginePlayer);
119
120     static double invalidTime() { return -1.0; }
121
122     MediaPlayer() { }
123     virtual ~MediaPlayer() { }
124
125     virtual void load(blink::WebMediaPlayer::LoadType, const String& url) = 0;
126
127     virtual void prepareToPlay() = 0;
128
129     virtual void play() = 0;
130     virtual void pause() = 0;
131
132     virtual bool supportsSave() const = 0;
133     virtual IntSize naturalSize() const = 0;
134
135     virtual bool hasVideo() const = 0;
136     virtual bool hasAudio() const = 0;
137
138     virtual double duration() const = 0;
139
140     virtual double currentTime() const = 0;
141
142     virtual void seek(double) = 0;
143
144     virtual bool seeking() const = 0;
145
146     virtual double rate() const = 0;
147     virtual void setRate(double) = 0;
148
149     virtual bool paused() const = 0;
150
151     virtual void setVolume(double) = 0;
152     virtual void setMuted(bool) = 0;
153
154     virtual void setPoster(const KURL&) = 0;
155
156     enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
157     virtual NetworkState networkState() const = 0;
158
159     enum ReadyState  { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
160     virtual ReadyState readyState() const = 0;
161
162     virtual double maxTimeSeekable() const = 0;
163     virtual PassRefPtr<TimeRanges> buffered() const = 0;
164
165     virtual bool didLoadingProgress() const = 0;
166
167     virtual void paint(GraphicsContext*, const IntRect&) = 0;
168     virtual bool copyVideoTextureToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) = 0;
169
170     enum Preload { None, MetaData, Auto };
171     virtual void setPreload(Preload) = 0;
172
173     virtual void showFullscreenOverlay() = 0;
174     virtual void hideFullscreenOverlay() = 0;
175     virtual bool canShowFullscreenOverlay() const = 0;
176
177     virtual bool hasSingleSecurityOrigin() const = 0;
178
179     virtual bool didPassCORSAccessCheck() const = 0;
180
181     // Time value in the movie's time scale. It is only necessary to override this if the media
182     // engine uses rational numbers to represent media time.
183     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
184
185     virtual unsigned decodedFrameCount() const = 0;
186     virtual unsigned droppedFrameCount() const = 0;
187     virtual unsigned corruptedFrameCount() const = 0;
188     virtual unsigned audioDecodedByteCount() const = 0;
189     virtual unsigned videoDecodedByteCount() const = 0;
190
191 #if ENABLE(WEB_AUDIO)
192     virtual AudioSourceProvider* audioSourceProvider() = 0;
193 #endif
194
195     enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported, InvalidAccess };
196     virtual MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) = 0;
197     virtual MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) = 0;
198     virtual MediaKeyException cancelKeyRequest(const String&, const String&) = 0;
199     virtual void setContentDecryptionModule(blink::WebContentDecryptionModule*) = 0;
200 };
201
202 }
203
204 #endif // MediaPlayer_h