• 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 "WebMediaSource.h"
36 #include "WebString.h"
37 #include "WebTimeRange.h"
38 
39 namespace blink {
40 
41 class WebAudioSourceProvider;
42 class WebAudioSourceProviderClient;
43 class WebContentDecryptionModule;
44 class WebMediaPlayerClient;
45 class WebString;
46 class WebURL;
47 struct WebRect;
48 struct WebSize;
49 class WebGraphicsContext3D;
50 
51 class WebMediaPlayer {
52 public:
53     enum NetworkState {
54         NetworkStateEmpty,
55         NetworkStateIdle,
56         NetworkStateLoading,
57         NetworkStateLoaded,
58         NetworkStateFormatError,
59         NetworkStateNetworkError,
60         NetworkStateDecodeError,
61     };
62 
63     enum ReadyState {
64         ReadyStateHaveNothing,
65         ReadyStateHaveMetadata,
66         ReadyStateHaveCurrentData,
67         ReadyStateHaveFutureData,
68         ReadyStateHaveEnoughData,
69     };
70 
71     enum Preload {
72         PreloadNone,
73         PreloadMetaData,
74         PreloadAuto,
75     };
76 
77     // Represents synchronous exceptions that can be thrown from the Encrypted
78     // Media methods. This is different from the asynchronous MediaKeyError.
79     enum MediaKeyException {
80         MediaKeyExceptionNoError,
81         MediaKeyExceptionInvalidPlayerState,
82         MediaKeyExceptionKeySystemNotSupported,
83         MediaKeyExceptionInvalidAccess,
84     };
85 
86     enum CORSMode {
87         CORSModeUnspecified,
88         CORSModeAnonymous,
89         CORSModeUseCredentials,
90     };
91 
92     enum LoadType {
93         LoadTypeURL,
94         LoadTypeMediaSource,
95         LoadTypeMediaStream,
96     };
97 
98     typedef unsigned TrackId;
99 
~WebMediaPlayer()100     virtual ~WebMediaPlayer() { }
101 
102     virtual void load(LoadType, const WebURL&, CORSMode) = 0;
103 
104     // Playback controls.
105     virtual void play() = 0;
106     virtual void pause() = 0;
107     virtual bool supportsSave() const = 0;
108     virtual void seek(double seconds) = 0;
109     virtual void setRate(double) = 0;
110     virtual void setVolume(double) = 0;
setPreload(Preload)111     virtual void setPreload(Preload) { };
112     virtual WebTimeRanges buffered() const = 0;
113     virtual double maxTimeSeekable() const = 0;
114 
115     virtual void paint(WebCanvas*, const WebRect&, unsigned char alpha) = 0;
116 
117     // True if the loaded media has a playable video/audio track.
118     virtual bool hasVideo() const = 0;
119     virtual bool hasAudio() const = 0;
120 
121     // Dimension of the video.
122     virtual WebSize naturalSize() const = 0;
123 
124     // Getters of playback state.
125     virtual bool paused() const = 0;
126     virtual bool seeking() const = 0;
127     virtual double duration() const = 0;
128     virtual double currentTime() const = 0;
129 
130     // Internal states of loading and network.
131     virtual NetworkState networkState() const = 0;
132     virtual ReadyState readyState() const = 0;
133 
134     virtual bool didLoadingProgress() = 0;
135 
136     virtual bool hasSingleSecurityOrigin() const = 0;
137     virtual bool didPassCORSAccessCheck() const = 0;
138 
139     virtual double mediaTimeForTimeValue(double timeValue) const = 0;
140 
141     virtual unsigned decodedFrameCount() const = 0;
142     virtual unsigned droppedFrameCount() const = 0;
corruptedFrameCount()143     virtual unsigned corruptedFrameCount() const { return 0; };
144     virtual unsigned audioDecodedByteCount() const = 0;
145     virtual unsigned videoDecodedByteCount() const = 0;
146 
147     // Do a GPU-GPU textures copy if possible.
copyVideoTextureToPlatformTexture(WebGraphicsContext3D *,unsigned texture,unsigned level,unsigned internalFormat,unsigned type,bool premultiplyAlpha,bool flipY)148     virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned texture, unsigned level, unsigned internalFormat, unsigned type, bool premultiplyAlpha, bool flipY) { return false; }
149 
audioSourceProvider()150     virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
151 
152     // Returns whether keySystem is supported. If true, the result will be
153     // reported by an event.
generateKeyRequest(const WebString & keySystem,const unsigned char * initData,unsigned initDataLength)154     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)155     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)156     virtual MediaKeyException cancelKeyRequest(const WebString& keySystem, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
setContentDecryptionModule(WebContentDecryptionModule * cdm)157     virtual void setContentDecryptionModule(WebContentDecryptionModule* cdm) { }
158 
159     // Sets the poster image URL.
setPoster(const WebURL & poster)160     virtual void setPoster(const WebURL& poster) { }
161 
162     // Instruct WebMediaPlayer to enter/exit fullscreen.
enterFullscreen()163     virtual void enterFullscreen() { }
exitFullscreen()164     virtual void exitFullscreen() { }
165     // Returns true if the player can enter fullscreen.
canEnterFullscreen()166     virtual bool canEnterFullscreen() const { return false; }
167 
enabledAudioTracksChanged(const WebVector<TrackId> & enabledTrackIds)168     virtual void enabledAudioTracksChanged(const WebVector<TrackId>& enabledTrackIds) { }
169     // |selectedTrackId| is null if no track is selected.
selectedVideoTrackChanged(TrackId * selectedTrackId)170     virtual void selectedVideoTrackChanged(TrackId* selectedTrackId) { }
171 };
172 
173 } // namespace blink
174 
175 #endif
176