2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef WebMediaPlayer_h
32 #define WebMediaPlayer_h
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"
43 class WebAudioSourceProvider;
44 class WebAudioSourceProviderClient;
45 class WebContentDecryptionModule;
46 class WebMediaPlayerClient;
51 class WebGraphicsContext3D;
53 class WebMediaPlayer {
60 NetworkStateFormatError,
61 NetworkStateNetworkError,
62 NetworkStateDecodeError,
66 ReadyStateHaveNothing,
67 ReadyStateHaveMetadata,
68 ReadyStateHaveCurrentData,
69 ReadyStateHaveFutureData,
70 ReadyStateHaveEnoughData,
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,
91 CORSModeUseCredentials,
100 typedef unsigned TrackId;
102 virtual ~WebMediaPlayer() { }
104 virtual void load(LoadType, const WebURL&, CORSMode) = 0;
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;
113 virtual void requestRemotePlayback() { };
114 virtual void requestRemotePlaybackControl() { };
115 virtual void setPreload(Preload) { };
116 virtual WebTimeRanges buffered() const = 0;
117 virtual double maxTimeSeekable() const = 0;
119 // True if the loaded media has a playable video/audio track.
120 virtual bool hasVideo() const = 0;
121 virtual bool hasAudio() const = 0;
123 // True if the media is being played on a remote device.
124 virtual bool isRemote() const { return false; }
126 // Dimension of the video.
127 virtual WebSize naturalSize() const = 0;
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;
135 // Internal states of loading and network.
136 virtual NetworkState networkState() const = 0;
137 virtual ReadyState readyState() const = 0;
139 virtual bool didLoadingProgress() = 0;
141 virtual bool hasSingleSecurityOrigin() const = 0;
142 virtual bool didPassCORSAccessCheck() const = 0;
144 virtual double mediaTimeForTimeValue(double timeValue) const = 0;
146 virtual unsigned decodedFrameCount() const = 0;
147 virtual unsigned droppedFrameCount() const = 0;
148 virtual unsigned corruptedFrameCount() const { return 0; };
149 virtual unsigned audioDecodedByteCount() const = 0;
150 virtual unsigned videoDecodedByteCount() const = 0;
152 virtual void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode) = 0;
153 // Do a GPU-GPU textures copy if possible.
154 virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned texture, unsigned level, unsigned internalFormat, unsigned type, bool premultiplyAlpha, bool flipY) { return false; }
156 virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
158 // Returns whether keySystem is supported. If true, the result will be
159 // reported by an event.
160 virtual MediaKeyException generateKeyRequest(const WebString& keySystem, const unsigned char* initData, unsigned initDataLength) { return MediaKeyExceptionKeySystemNotSupported; }
161 virtual MediaKeyException addKey(const WebString& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
162 virtual MediaKeyException cancelKeyRequest(const WebString& keySystem, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
163 virtual void setContentDecryptionModule(WebContentDecryptionModule* cdm, WebContentDecryptionModuleResult result) { result.completeWithError(WebContentDecryptionModuleExceptionNotSupportedError, 0, "ERROR"); }
165 // Sets the poster image URL.
166 virtual void setPoster(const WebURL& poster) { }
168 // Instruct WebMediaPlayer to enter/exit fullscreen.
169 virtual void enterFullscreen() { }
170 // Returns true if the player can enter fullscreen.
171 virtual bool canEnterFullscreen() const { return false; }
173 virtual void enabledAudioTracksChanged(const WebVector<TrackId>& enabledTrackIds) { }
174 // |selectedTrackId| is null if no track is selected.
175 virtual void selectedVideoTrackChanged(TrackId* selectedTrackId) { }