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 "WebMediaSource.h"
36 #include "WebString.h"
37 #include "WebTimeRange.h"
41 class WebAudioSourceProvider;
42 class WebAudioSourceProviderClient;
43 class WebContentDecryptionModule;
44 class WebMediaPlayerClient;
49 class WebGraphicsContext3D;
51 class WebMediaPlayer {
58 NetworkStateFormatError,
59 NetworkStateNetworkError,
60 NetworkStateDecodeError,
64 ReadyStateHaveNothing,
65 ReadyStateHaveMetadata,
66 ReadyStateHaveCurrentData,
67 ReadyStateHaveFutureData,
68 ReadyStateHaveEnoughData,
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,
89 CORSModeUseCredentials,
98 virtual ~WebMediaPlayer() { }
100 virtual void load(LoadType, const WebURL&, CORSMode) = 0;
102 // Playback controls.
103 virtual void play() = 0;
104 virtual void pause() = 0;
105 virtual bool supportsSave() const = 0;
106 virtual void seek(double seconds) = 0;
107 virtual void setRate(double) = 0;
108 virtual void setVolume(double) = 0;
109 virtual void setPreload(Preload) { };
110 virtual const WebTimeRanges& buffered() = 0;
111 virtual double maxTimeSeekable() const = 0;
113 virtual void paint(WebCanvas*, const WebRect&, unsigned char alpha) = 0;
115 // True if the loaded media has a playable video/audio track.
116 virtual bool hasVideo() const = 0;
117 virtual bool hasAudio() const = 0;
119 // Dimension of the video.
120 virtual WebSize naturalSize() const = 0;
122 // Getters of playback state.
123 virtual bool paused() const = 0;
124 virtual bool seeking() const = 0;
125 virtual double duration() const = 0;
126 virtual double currentTime() const = 0;
128 // Internal states of loading and network.
129 virtual NetworkState networkState() const = 0;
130 virtual ReadyState readyState() const = 0;
132 virtual bool didLoadingProgress() const = 0;
134 virtual bool hasSingleSecurityOrigin() const = 0;
135 virtual bool didPassCORSAccessCheck() const = 0;
137 virtual double mediaTimeForTimeValue(double timeValue) const = 0;
139 virtual unsigned decodedFrameCount() const = 0;
140 virtual unsigned droppedFrameCount() const = 0;
141 virtual unsigned corruptedFrameCount() const { return 0; };
142 virtual unsigned audioDecodedByteCount() const = 0;
143 virtual unsigned videoDecodedByteCount() const = 0;
145 // Do a GPU-GPU textures copy if possible.
146 virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, unsigned texture, unsigned level, unsigned internalFormat, unsigned type, bool premultiplyAlpha, bool flipY) { return false; }
148 virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
150 // Returns whether keySystem is supported. If true, the result will be
151 // reported by an event.
152 virtual MediaKeyException generateKeyRequest(const WebString& keySystem, const unsigned char* initData, unsigned initDataLength) { return MediaKeyExceptionKeySystemNotSupported; }
153 virtual MediaKeyException addKey(const WebString& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
154 virtual MediaKeyException cancelKeyRequest(const WebString& keySystem, const WebString& sessionId) { return MediaKeyExceptionKeySystemNotSupported; }
155 virtual void setContentDecryptionModule(WebContentDecryptionModule* cdm) { }
157 // Instruct WebMediaPlayer to enter/exit fullscreen.
158 virtual void enterFullscreen() { }
159 virtual void exitFullscreen() { }
160 // Returns true if the player can enter fullscreen.
161 virtual bool canEnterFullscreen() const { return false; }