• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef WebMediaPlayer_h
32 #define WebMediaPlayer_h
33 
34 #include "WebCanvas.h"
35 #include "WebContentDecryptionModule.h"
36 #include "WebMediaSource.h"
37 #include "WebString.h"
38 #include "WebTimeRange.h"
39 #include "third_party/skia/include/core/SkXfermode.h"
40 
41 namespace blink {
42 
43 class WebAudioSourceProvider;
44 class WebAudioSourceProviderClient;
45 class WebContentDecryptionModule;
46 class WebMediaPlayerClient;
47 class WebString;
48 class WebURL;
49 struct WebRect;
50 struct WebSize;
51 class WebGraphicsContext3D;
52 
53 class WebMediaPlayer {
54 public:
55     enum NetworkState {
56         NetworkStateEmpty,
57         NetworkStateIdle,
58         NetworkStateLoading,
59         NetworkStateLoaded,
60         NetworkStateFormatError,
61         NetworkStateNetworkError,
62         NetworkStateDecodeError,
63     };
64 
65     enum ReadyState {
66         ReadyStateHaveNothing,
67         ReadyStateHaveMetadata,
68         ReadyStateHaveCurrentData,
69         ReadyStateHaveFutureData,
70         ReadyStateHaveEnoughData,
71     };
72 
73     enum Preload {
74         PreloadNone,
75         PreloadMetaData,
76         PreloadAuto,
77     };
78 
79     // Represents synchronous exceptions that can be thrown from the Encrypted
80     // Media methods. This is different from the asynchronous MediaKeyError.
81     enum MediaKeyException {
82         MediaKeyExceptionNoError,
83         MediaKeyExceptionInvalidPlayerState,
84         MediaKeyExceptionKeySystemNotSupported,
85         MediaKeyExceptionInvalidAccess,
86     };
87 
88     enum CORSMode {
89         CORSModeUnspecified,
90         CORSModeAnonymous,
91         CORSModeUseCredentials,
92     };
93 
94     enum LoadType {
95         LoadTypeURL,
96         LoadTypeMediaSource,
97         LoadTypeMediaStream,
98     };
99 
100     typedef unsigned TrackId;
101 
~WebMediaPlayer()102     virtual ~WebMediaPlayer() { }
103 
104     virtual void load(LoadType, const WebURL&, CORSMode) = 0;
105 
106     // Playback controls.
107     virtual void play() = 0;
108     virtual void pause() = 0;
109     virtual bool supportsSave() const = 0;
110     virtual void seek(double seconds) = 0;
111     virtual void setRate(double) = 0;
112     virtual void setVolume(double) = 0;
requestRemotePlayback()113     virtual void requestRemotePlayback() { };
requestRemotePlaybackControl()114     virtual void requestRemotePlaybackControl() { };
setPreload(Preload)115     virtual void setPreload(Preload) { };
116     virtual WebTimeRanges buffered() const = 0;
117     virtual double maxTimeSeekable() const = 0;
118 
119     // True if the loaded media has a playable video/audio track.
120     virtual bool hasVideo() const = 0;
121     virtual bool hasAudio() const = 0;
122 
123     // True if the media is being played on a remote device.
isRemote()124     virtual bool isRemote() const { return false; }
125 
126     // Dimension of the video.
127     virtual WebSize naturalSize() const = 0;
128 
129     // Getters of playback state.
130     virtual bool paused() const = 0;
131     virtual bool seeking() const = 0;
132     virtual double duration() const = 0;
133     virtual double currentTime() const = 0;
134 
135     // Internal states of loading and network.
136     virtual NetworkState networkState() const = 0;
137     virtual ReadyState readyState() const = 0;
138 
139     virtual bool didLoadingProgress() = 0;
140 
141     virtual bool hasSingleSecurityOrigin() const = 0;
142     virtual bool didPassCORSAccessCheck() const = 0;
143 
144     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
145 
146     virtual unsigned decodedFrameCount() const = 0;
147     virtual unsigned droppedFrameCount() const = 0;
corruptedFrameCount()148     virtual unsigned corruptedFrameCount() const { return 0; };
149     virtual unsigned audioDecodedByteCount() const = 0;
150     virtual unsigned videoDecodedByteCount() const = 0;
151 
152     virtual void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode) = 0;
153     // Do a GPU-GPU textures copy if possible.
copyVideoTextureToPlatformTexture(WebGraphicsContext3D *,unsigned texture,unsigned level,unsigned internalFormat,unsigned type,bool premultiplyAlpha,bool flipY)154     virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned texture, unsigned level, unsigned internalFormat, unsigned type, bool premultiplyAlpha, bool flipY) { return false; }
155 
audioSourceProvider()156     virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
157 
158     // Returns whether keySystem is supported. If true, the result will be
159     // reported by an event.
generateKeyRequest(const WebString & keySystem,const unsigned char * initData,unsigned initDataLength)160     virtual MediaKeyException generateKeyRequest(const WebString& keySystem, const unsigned char* initData, unsigned initDataLength) { return MediaKeyExceptionKeySystemNotSupported; }
addKey(const WebString & keySystem,const unsigned char * key,unsigned keyLength,const unsigned char * initData,unsigned initDataLength,const WebString & sessionId)161     virtual MediaKeyException addKey(const WebString& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
cancelKeyRequest(const WebString & keySystem,const WebString & sessionId)162     virtual MediaKeyException cancelKeyRequest(const WebString& keySystem, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
setContentDecryptionModule(WebContentDecryptionModule * cdm,WebContentDecryptionModuleResult result)163     virtual void setContentDecryptionModule(WebContentDecryptionModule* cdm, WebContentDecryptionModuleResult result) { result.completeWithError(WebContentDecryptionModuleExceptionNotSupportedError, 0, "ERROR"); }
164 
165     // Sets the poster image URL.
setPoster(const WebURL & poster)166     virtual void setPoster(const WebURL& poster) { }
167 
168     // Instruct WebMediaPlayer to enter/exit fullscreen.
enterFullscreen()169     virtual void enterFullscreen() { }
170     // Returns true if the player can enter fullscreen.
canEnterFullscreen()171     virtual bool canEnterFullscreen() const { return false; }
172 
enabledAudioTracksChanged(const WebVector<TrackId> & enabledTrackIds)173     virtual void enabledAudioTracksChanged(const WebVector<TrackId>& enabledTrackIds) { }
174     // |selectedTrackId| is null if no track is selected.
selectedVideoTrackChanged(TrackId * selectedTrackId)175     virtual void selectedVideoTrackChanged(TrackId* selectedTrackId) { }
176 };
177 
178 } // namespace blink
179 
180 #endif
181