blob: 1a4fc815fd7e641ff4641ea8cd751dd7cbac91cd [file] [log] [blame]
Ben Murdoche69819b2013-07-17 14:56:49 +01001/*
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 WebMediaPlayerClientImpl_h
32#define WebMediaPlayerClientImpl_h
33
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010034#include "platform/audio/AudioSourceProvider.h"
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000035#include "platform/graphics/media/MediaPlayer.h"
36#include "public/platform/WebAudioSourceProviderClient.h"
37#include "public/platform/WebMediaPlayerClient.h"
Torne (Richard Coles)09380292014-02-21 12:17:33 +000038#include "third_party/khronos/GLES2/gl2.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010039#if OS(ANDROID)
40#include "third_party/skia/include/core/SkBitmap.h"
41#include "third_party/skia/include/core/SkRefCnt.h"
42#include "third_party/skia/include/gpu/GrTexture.h"
43#endif
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000044#include "platform/weborigin/KURL.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010045#include "wtf/OwnPtr.h"
46#include "wtf/PassOwnPtr.h"
Torne (Richard Coles)c0e19a62013-08-30 15:15:11 +010047#include "wtf/ThreadingPrimitives.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010048
49namespace WebCore {
50class AudioSourceProviderClient;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000051class HTMLMediaElement;
Ben Murdoche69819b2013-07-17 14:56:49 +010052}
53
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000054namespace blink {
Ben Murdoche69819b2013-07-17 14:56:49 +010055
Ben Murdoche69819b2013-07-17 14:56:49 +010056class WebAudioSourceProvider;
Torne (Richard Coles)09380292014-02-21 12:17:33 +000057class WebContentDecryptionModule;
Ben Murdoche69819b2013-07-17 14:56:49 +010058class WebMediaPlayer;
Torne (Richard Coles)09380292014-02-21 12:17:33 +000059class WebGraphicsContext3D;
Ben Murdoche69819b2013-07-17 14:56:49 +010060
61// This class serves as a bridge between WebCore::MediaPlayer and
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000062// blink::WebMediaPlayer.
Torne (Richard Coles)09380292014-02-21 12:17:33 +000063class WebMediaPlayerClientImpl FINAL : public WebCore::MediaPlayer, public WebMediaPlayerClient {
Ben Murdoche69819b2013-07-17 14:56:49 +010064
65public:
66 static PassOwnPtr<WebCore::MediaPlayer> create(WebCore::MediaPlayerClient*);
67
Torne (Richard Coles)09380292014-02-21 12:17:33 +000068 virtual ~WebMediaPlayerClientImpl();
69
Ben Murdoche69819b2013-07-17 14:56:49 +010070 // WebMediaPlayerClient methods:
Torne (Richard Coles)09380292014-02-21 12:17:33 +000071 virtual void networkStateChanged() OVERRIDE;
72 virtual void readyStateChanged() OVERRIDE;
73 virtual void timeChanged() OVERRIDE;
74 virtual void repaint() OVERRIDE;
75 virtual void durationChanged() OVERRIDE;
76 virtual void sizeChanged() OVERRIDE;
77 virtual void setOpaque(bool) OVERRIDE;
78 virtual double volume() const OVERRIDE;
79 virtual void playbackStateChanged() OVERRIDE;
80 virtual WebMediaPlayer::Preload preload() const OVERRIDE;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000081
82 // WebEncryptedMediaPlayerClient methods:
Torne (Richard Coles)09380292014-02-21 12:17:33 +000083 virtual void keyAdded(const WebString& keySystem, const WebString& sessionId) OVERRIDE;
84 virtual void keyError(const WebString& keySystem, const WebString& sessionId, MediaKeyErrorCode, unsigned short systemCode) OVERRIDE;
85 virtual void keyMessage(const WebString& keySystem, const WebString& sessionId, const unsigned char* message, unsigned messageLength, const WebURL& defaultURL) OVERRIDE;
86 virtual void keyNeeded(const WebString& contentType, const unsigned char* initData, unsigned initDataLength) OVERRIDE;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000087
Torne (Richard Coles)09380292014-02-21 12:17:33 +000088 virtual void setWebLayer(WebLayer*) OVERRIDE;
89 virtual void addTextTrack(WebInbandTextTrack*) OVERRIDE;
90 virtual void removeTextTrack(WebInbandTextTrack*) OVERRIDE;
91 virtual void mediaSourceOpened(WebMediaSource*) OVERRIDE;
92 virtual void requestFullscreen() OVERRIDE;
93 virtual void requestSeek(double) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +010094
95 // MediaPlayer methods:
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000096 virtual WebMediaPlayer* webMediaPlayer() const OVERRIDE;
Ben Murdoch07a852d2014-03-31 11:51:52 +010097 virtual void load(WebMediaPlayer::LoadType, const WTF::String& url, WebMediaPlayer::CORSMode) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +010098 virtual void play() OVERRIDE;
99 virtual void pause() OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100100 virtual bool supportsSave() const OVERRIDE;
101 virtual WebCore::IntSize naturalSize() const OVERRIDE;
102 virtual bool hasVideo() const OVERRIDE;
103 virtual bool hasAudio() const OVERRIDE;
104 virtual double duration() const OVERRIDE;
105 virtual double currentTime() const OVERRIDE;
106 virtual void seek(double time) OVERRIDE;
107 virtual bool seeking() const OVERRIDE;
108 virtual double rate() const OVERRIDE;
109 virtual void setRate(double) OVERRIDE;
110 virtual bool paused() const OVERRIDE;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000111 virtual void setPoster(const WebCore::KURL&) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100112 virtual WebCore::MediaPlayer::NetworkState networkState() const OVERRIDE;
113 virtual WebCore::MediaPlayer::ReadyState readyState() const OVERRIDE;
114 virtual double maxTimeSeekable() const OVERRIDE;
115 virtual WTF::PassRefPtr<WebCore::TimeRanges> buffered() const OVERRIDE;
116 virtual bool didLoadingProgress() const OVERRIDE;
117 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000118 virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, Platform3DObject texture, GLint level, GLenum type, GLenum internalFormat, bool premultiplyAlpha, bool flipY) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100119 virtual void setPreload(WebCore::MediaPlayer::Preload) OVERRIDE;
120 virtual bool hasSingleSecurityOrigin() const OVERRIDE;
121 virtual bool didPassCORSAccessCheck() const OVERRIDE;
122 virtual double mediaTimeForTimeValue(double timeValue) const OVERRIDE;
123 virtual unsigned decodedFrameCount() const OVERRIDE;
124 virtual unsigned droppedFrameCount() const OVERRIDE;
Torne (Richard Coles)19cde672013-11-06 12:28:04 +0000125 virtual unsigned corruptedFrameCount() const OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100126 virtual unsigned audioDecodedByteCount() const OVERRIDE;
127 virtual unsigned videoDecodedByteCount() const OVERRIDE;
Torne (Richard Coles)06f816c2013-09-26 13:25:12 +0100128 virtual void showFullscreenOverlay() OVERRIDE;
129 virtual void hideFullscreenOverlay() OVERRIDE;
130 virtual bool canShowFullscreenOverlay() const OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100131
132#if ENABLE(WEB_AUDIO)
133 virtual WebCore::AudioSourceProvider* audioSourceProvider() OVERRIDE;
134#endif
135
Ben Murdoche69819b2013-07-17 14:56:49 +0100136private:
137 explicit WebMediaPlayerClientImpl(WebCore::MediaPlayerClient*);
138
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000139 WebCore::HTMLMediaElement& mediaElement() const;
140
Ben Murdoch07a852d2014-03-31 11:51:52 +0100141 WebCore::MediaPlayerClient* m_client;
142 OwnPtr<WebMediaPlayer> m_webMediaPlayer;
143 WebCore::MediaPlayer::Preload m_preload;
144 double m_rate;
145
Ben Murdoche69819b2013-07-17 14:56:49 +0100146#if OS(ANDROID)
147 // FIXME: This path "only works" on Android. It is a workaround for the problem that Skia could not handle Android's GL_TEXTURE_EXTERNAL_OES
148 // texture internally. It should be removed and replaced by the normal paint path.
149 // https://code.google.com/p/skia/issues/detail?id=1189
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000150 void paintOnAndroid(WebCore::GraphicsContext*, const WebCore::IntRect&, uint8_t alpha);
Ben Murdoche69819b2013-07-17 14:56:49 +0100151 SkBitmap m_bitmap;
Ben Murdoch07a852d2014-03-31 11:51:52 +0100152 bool m_usePaintOnAndroid;
Ben Murdoche69819b2013-07-17 14:56:49 +0100153#endif
154
Ben Murdoche69819b2013-07-17 14:56:49 +0100155#if ENABLE(WEB_AUDIO)
156 // AudioClientImpl wraps an AudioSourceProviderClient.
157 // When the audio format is known, Chromium calls setFormat() which then dispatches into WebCore.
158
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000159 class AudioClientImpl FINAL : public blink::WebAudioSourceProviderClient {
Ben Murdoche69819b2013-07-17 14:56:49 +0100160 public:
161 AudioClientImpl(WebCore::AudioSourceProviderClient* client)
162 : m_client(client)
163 {
164 }
165
166 virtual ~AudioClientImpl() { }
167
168 // WebAudioSourceProviderClient
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000169 virtual void setFormat(size_t numberOfChannels, float sampleRate) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100170
171 private:
172 WebCore::AudioSourceProviderClient* m_client;
173 };
174
175 // AudioSourceProviderImpl wraps a WebAudioSourceProvider.
176 // provideInput() calls into Chromium to get a rendered audio stream.
177
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000178 class AudioSourceProviderImpl FINAL : public WebCore::AudioSourceProvider {
Ben Murdoche69819b2013-07-17 14:56:49 +0100179 public:
180 AudioSourceProviderImpl()
181 : m_webAudioSourceProvider(0)
182 {
183 }
184
185 virtual ~AudioSourceProviderImpl() { }
186
187 // Wraps the given WebAudioSourceProvider.
188 void wrap(WebAudioSourceProvider*);
189
190 // WebCore::AudioSourceProvider
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000191 virtual void setClient(WebCore::AudioSourceProviderClient*) OVERRIDE;
192 virtual void provideInput(WebCore::AudioBus*, size_t framesToProcess) OVERRIDE;
Ben Murdoche69819b2013-07-17 14:56:49 +0100193
194 private:
195 WebAudioSourceProvider* m_webAudioSourceProvider;
196 OwnPtr<AudioClientImpl> m_client;
197 Mutex provideInputLock;
198 };
199
200 AudioSourceProviderImpl m_audioSourceProvider;
201#endif
Ben Murdoche69819b2013-07-17 14:56:49 +0100202};
203
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000204} // namespace blink
Ben Murdoche69819b2013-07-17 14:56:49 +0100205
206#endif