2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "platform/PlatformExport.h"
30 #include "platform/graphics/GraphicsTypes3D.h"
31 #include "public/platform/WebMediaPlayer.h"
32 #include "wtf/Forward.h"
33 #include "wtf/Noncopyable.h"
36 class WebGraphicsContext3D;
37 class WebContentDecryptionModule;
38 class WebInbandTextTrack;
45 class AudioSourceProvider;
46 class GraphicsContext;
53 // GL types as defined in OpenGL ES 2.0 header file gl2.h from khronos.org.
54 // That header cannot be included directly due to a conflict with NPAPI headers.
55 // See crbug.com/328085.
56 typedef unsigned GC3Denum;
59 class MediaPlayerClient {
61 enum CORSMode { Unspecified, Anonymous, UseCredentials };
63 virtual ~MediaPlayerClient() { }
65 // the network state has changed
66 virtual void mediaPlayerNetworkStateChanged() = 0;
68 // the ready state has changed
69 virtual void mediaPlayerReadyStateChanged() = 0;
71 // time has jumped, eg. not as a result of normal playback
72 virtual void mediaPlayerTimeChanged() = 0;
74 // the media file duration has changed, or is now known
75 virtual void mediaPlayerDurationChanged() = 0;
77 // the play/pause status changed
78 virtual void mediaPlayerPlaybackStateChanged() = 0;
80 virtual void mediaPlayerRequestFullscreen() = 0;
82 virtual void mediaPlayerRequestSeek(double) = 0;
84 // The URL for video poster image.
85 // FIXME: Remove this when WebMediaPlayerClientImpl::loadInternal does not depend on it.
86 virtual KURL mediaPlayerPosterURL() = 0;
88 // Presentation-related methods
89 // a new frame of video is available
90 virtual void mediaPlayerRepaint() = 0;
92 // the movie size has changed
93 virtual void mediaPlayerSizeChanged() = 0;
95 enum MediaKeyErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError };
96 virtual void mediaPlayerKeyAdded(const String& /* keySystem */, const String& /* sessionId */) = 0;
97 virtual void mediaPlayerKeyError(const String& /* keySystem */, const String& /* sessionId */, MediaKeyErrorCode, unsigned short /* systemCode */) = 0;
98 virtual void mediaPlayerKeyMessage(const String& /* keySystem */, const String& /* sessionId */, const unsigned char* /* message */, unsigned /* messageLength */, const KURL& /* defaultURL */) = 0;
99 virtual bool mediaPlayerKeyNeeded(const String& /* contentType */, const unsigned char* /* initData */, unsigned /* initDataLength */) = 0;
101 virtual CORSMode mediaPlayerCORSMode() const = 0;
103 virtual void mediaPlayerSetWebLayer(blink::WebLayer*) = 0;
104 virtual void mediaPlayerSetOpaque(bool) = 0;
106 virtual void mediaPlayerDidAddTrack(blink::WebInbandTextTrack*) = 0;
107 virtual void mediaPlayerDidRemoveTrack(blink::WebInbandTextTrack*) = 0;
109 virtual void mediaPlayerMediaSourceOpened(blink::WebMediaSource*) = 0;
112 typedef PassOwnPtr<MediaPlayer> (*CreateMediaEnginePlayer)(MediaPlayerClient*);
114 class PLATFORM_EXPORT MediaPlayer {
115 WTF_MAKE_NONCOPYABLE(MediaPlayer);
117 static PassOwnPtr<MediaPlayer> create(MediaPlayerClient*);
118 static void setMediaEngineCreateFunction(CreateMediaEnginePlayer);
120 static double invalidTime() { return -1.0; }
123 virtual ~MediaPlayer() { }
125 virtual void load(blink::WebMediaPlayer::LoadType, const String& url) = 0;
127 virtual void prepareToPlay() = 0;
129 virtual void play() = 0;
130 virtual void pause() = 0;
132 virtual bool supportsSave() const = 0;
133 virtual IntSize naturalSize() const = 0;
135 virtual bool hasVideo() const = 0;
136 virtual bool hasAudio() const = 0;
138 virtual double duration() const = 0;
140 virtual double currentTime() const = 0;
142 virtual void seek(double) = 0;
144 virtual bool seeking() const = 0;
146 virtual double rate() const = 0;
147 virtual void setRate(double) = 0;
149 virtual bool paused() const = 0;
151 virtual void setVolume(double) = 0;
152 virtual void setMuted(bool) = 0;
154 virtual void setPoster(const KURL&) = 0;
156 enum NetworkState { Empty, Idle, Loading, Loaded, FormatError, NetworkError, DecodeError };
157 virtual NetworkState networkState() const = 0;
159 enum ReadyState { HaveNothing, HaveMetadata, HaveCurrentData, HaveFutureData, HaveEnoughData };
160 virtual ReadyState readyState() const = 0;
162 virtual double maxTimeSeekable() const = 0;
163 virtual PassRefPtr<TimeRanges> buffered() const = 0;
165 virtual bool didLoadingProgress() const = 0;
167 virtual void paint(GraphicsContext*, const IntRect&) = 0;
168 virtual bool copyVideoTextureToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject, GC3Dint, GC3Denum, GC3Denum, bool, bool) = 0;
170 enum Preload { None, MetaData, Auto };
171 virtual void setPreload(Preload) = 0;
173 virtual void showFullscreenOverlay() = 0;
174 virtual void hideFullscreenOverlay() = 0;
175 virtual bool canShowFullscreenOverlay() const = 0;
177 virtual bool hasSingleSecurityOrigin() const = 0;
179 virtual bool didPassCORSAccessCheck() const = 0;
181 // Time value in the movie's time scale. It is only necessary to override this if the media
182 // engine uses rational numbers to represent media time.
183 virtual double mediaTimeForTimeValue(double timeValue) const = 0;
185 virtual unsigned decodedFrameCount() const = 0;
186 virtual unsigned droppedFrameCount() const = 0;
187 virtual unsigned corruptedFrameCount() const = 0;
188 virtual unsigned audioDecodedByteCount() const = 0;
189 virtual unsigned videoDecodedByteCount() const = 0;
191 #if ENABLE(WEB_AUDIO)
192 virtual AudioSourceProvider* audioSourceProvider() = 0;
195 enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported, InvalidAccess };
196 virtual MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) = 0;
197 virtual MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) = 0;
198 virtual MediaKeyException cancelKeyRequest(const String&, const String&) = 0;
199 virtual void setContentDecryptionModule(blink::WebContentDecryptionModule*) = 0;
204 #endif // MediaPlayer_h