Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebMediaPlayer.h
blob31d6e5bd7e81f90c207f54c9253c8932870214a1
1 /*
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
6 * met:
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.
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 "WebCallbacks.h"
35 #include "WebCanvas.h"
36 #include "WebContentDecryptionModule.h"
37 #include "WebMediaSource.h"
38 #include "WebSetSinkIdError.h"
39 #include "WebString.h"
40 #include "WebTimeRange.h"
41 #include "third_party/skia/include/core/SkXfermode.h"
43 namespace blink {
45 class WebAudioSourceProvider;
46 class WebContentDecryptionModule;
47 class WebString;
48 class WebURL;
49 struct WebRect;
50 struct WebSize;
51 class WebGraphicsContext3D;
53 class WebMediaPlayer {
54 public:
55 enum NetworkState {
56 NetworkStateEmpty,
57 NetworkStateIdle,
58 NetworkStateLoading,
59 NetworkStateLoaded,
60 NetworkStateFormatError,
61 NetworkStateNetworkError,
62 NetworkStateDecodeError,
65 enum ReadyState {
66 ReadyStateHaveNothing,
67 ReadyStateHaveMetadata,
68 ReadyStateHaveCurrentData,
69 ReadyStateHaveFutureData,
70 ReadyStateHaveEnoughData,
73 enum Preload {
74 PreloadNone,
75 PreloadMetaData,
76 PreloadAuto,
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,
88 enum CORSMode {
89 CORSModeUnspecified,
90 CORSModeAnonymous,
91 CORSModeUseCredentials,
94 // Reported to UMA. Do not change existing values.
95 enum LoadType {
96 LoadTypeURL = 0,
97 LoadTypeMediaSource = 1,
98 LoadTypeMediaStream = 2,
99 LoadTypeMax = LoadTypeMediaStream,
102 typedef unsigned TrackId;
104 virtual ~WebMediaPlayer() { }
106 virtual void load(LoadType, const WebURL&, CORSMode) = 0;
108 // Playback controls.
109 virtual void play() = 0;
110 virtual void pause() = 0;
111 virtual bool supportsSave() const = 0;
112 virtual void seek(double seconds) = 0;
113 virtual void setRate(double) = 0;
114 virtual void setVolume(double) = 0;
116 virtual void requestRemotePlayback() { }
117 virtual void requestRemotePlaybackControl() { }
118 virtual void setPreload(Preload) { }
119 virtual WebTimeRanges buffered() const = 0;
120 virtual WebTimeRanges seekable() const = 0;
122 // Attempts to switch the audio output device.
123 // Implementations of setSinkId take ownership of the WebCallbacks
124 // object, and the WebCallbacks object takes ownership of the returned
125 // error value, if any.
126 // Note also that setSinkId implementations must make sure that all
127 // methods of the WebCallbacks object, including constructors and
128 // destructors, run in the same thread where the object is created
129 // (i.e., the blink thread).
130 virtual void setSinkId(const WebString& deviceId, WebCallbacks<void, WebSetSinkIdError*>*) = 0;
132 // True if the loaded media has a playable video/audio track.
133 virtual bool hasVideo() const = 0;
134 virtual bool hasAudio() const = 0;
136 // True if the media is being played on a remote device.
137 virtual bool isRemote() const { return false; }
139 // Dimension of the video.
140 virtual WebSize naturalSize() const = 0;
142 // Getters of playback state.
143 virtual bool paused() const = 0;
144 virtual bool seeking() const = 0;
145 virtual double duration() const = 0;
146 virtual double currentTime() const = 0;
148 // Internal states of loading and network.
149 virtual NetworkState networkState() const = 0;
150 virtual ReadyState readyState() const = 0;
152 virtual bool didLoadingProgress() = 0;
154 virtual bool hasSingleSecurityOrigin() const = 0;
155 virtual bool didPassCORSAccessCheck() const = 0;
157 virtual double mediaTimeForTimeValue(double timeValue) const = 0;
159 virtual unsigned decodedFrameCount() const = 0;
160 virtual unsigned droppedFrameCount() const = 0;
161 virtual unsigned corruptedFrameCount() const { return 0; }
162 virtual unsigned audioDecodedByteCount() const = 0;
163 virtual unsigned videoDecodedByteCount() const = 0;
165 virtual void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode) = 0;
167 // TODO(dshwang): remove non-|target| version. crbug.com/349871
168 virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned texture, unsigned internalFormat, unsigned type, bool premultiplyAlpha, bool flipY) { return false; }
170 // Do a GPU-GPU textures copy. If the copy is impossible or fails, it returns false.
171 virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned target,
172 unsigned texture, unsigned internalFormat, unsigned type, int level,
173 bool premultiplyAlpha, bool flipY) { return false; }
174 // Copy sub video frame texture to |texture|. If the copy is impossible or fails, it returns false.
175 virtual bool copyVideoSubTextureToPlatformTexture(WebGraphicsContext3D*, unsigned target,
176 unsigned texture, int level, int xoffset, int yoffset, bool premultiplyAlpha,
177 bool flipY) { return false; }
179 virtual WebAudioSourceProvider* audioSourceProvider() { return nullptr; }
181 // Returns whether keySystem is supported. If true, the result will be
182 // reported by an event.
183 virtual MediaKeyException generateKeyRequest(const WebString& keySystem, const unsigned char* initData, unsigned initDataLength) { return MediaKeyExceptionKeySystemNotSupported; }
184 virtual MediaKeyException addKey(const WebString& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
185 virtual MediaKeyException cancelKeyRequest(const WebString& keySystem, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
186 virtual void setContentDecryptionModule(WebContentDecryptionModule* cdm, WebContentDecryptionModuleResult result) { result.completeWithError(WebContentDecryptionModuleExceptionNotSupportedError, 0, "ERROR"); }
188 // Sets the poster image URL.
189 virtual void setPoster(const WebURL& poster) { }
191 // Whether the WebMediaPlayer supports overlay fullscreen video mode. When
192 // this is true, the video layer will be removed from the layer tree when
193 // entering fullscreen, and the WebMediaPlayer is responsible for displaying
194 // the video in enterFullscreen().
195 virtual bool supportsOverlayFullscreenVideo() { return false; }
196 // Instruct WebMediaPlayer to enter/exit fullscreen.
197 virtual void enterFullscreen() { }
199 virtual void enabledAudioTracksChanged(const WebVector<TrackId>& enabledTrackIds) { }
200 // |selectedTrackId| is null if no track is selected.
201 virtual void selectedVideoTrackChanged(TrackId* selectedTrackId) { }
204 } // namespace blink
206 #endif