| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "web/WebMediaPlayerClientImpl.h" | |
| 7 | |
| 8 #include "core/frame/LocalFrame.h" | |
| 9 #include "core/html/HTMLMediaElement.h" | |
| 10 #include "core/html/TimeRanges.h" | |
| 11 #include "core/layout/LayoutView.h" | |
| 12 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" | |
| 13 #include "modules/mediastream/MediaStreamRegistry.h" | |
| 14 #include "platform/audio/AudioBus.h" | |
| 15 #include "platform/audio/AudioSourceProviderClient.h" | |
| 16 #include "platform/geometry/IntSize.h" | |
| 17 #include "platform/graphics/GraphicsContext.h" | |
| 18 #include "platform/graphics/GraphicsLayer.h" | |
| 19 #include "platform/graphics/gpu/Extensions3DUtil.h" | |
| 20 #include "public/platform/Platform.h" | |
| 21 #include "public/platform/WebAudioSourceProvider.h" | |
| 22 #include "public/platform/WebCString.h" | |
| 23 #include "public/platform/WebCanvas.h" | |
| 24 #include "public/platform/WebCompositorSupport.h" | |
| 25 #include "public/platform/WebContentDecryptionModule.h" | |
| 26 #include "public/platform/WebGraphicsContext3DProvider.h" | |
| 27 #include "public/platform/WebInbandTextTrack.h" | |
| 28 #include "public/platform/WebMediaPlayer.h" | |
| 29 #include "public/platform/WebRect.h" | |
| 30 #include "public/platform/WebString.h" | |
| 31 #include "public/platform/WebURL.h" | |
| 32 #include "public/web/WebDocument.h" | |
| 33 #include "public/web/WebFrameClient.h" | |
| 34 #include "web/WebLocalFrameImpl.h" | |
| 35 #include "web/WebViewImpl.h" | |
| 36 | |
| 37 #if OS(ANDROID) | |
| 38 #include "GrContext.h" | |
| 39 #include "GrTypes.h" | |
| 40 #include "SkCanvas.h" | |
| 41 #include "SkGrPixelRef.h" | |
| 42 #endif | |
| 43 | |
| 44 | |
| 45 #include "wtf/Assertions.h" | |
| 46 #include "wtf/text/CString.h" | |
| 47 | |
| 48 namespace blink { | |
| 49 | |
| 50 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* cli
ent, const WebURL& url, LocalFrame* frame, WebContentDecryptionModule* initialCd
m) | |
| 51 { | |
| 52 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(frame); | |
| 53 | |
| 54 if (!webFrame || !webFrame->client()) | |
| 55 return nullptr; | |
| 56 return adoptPtr(webFrame->client()->createMediaPlayer(webFrame, url, client,
initialCdm)); | |
| 57 } | |
| 58 | |
| 59 WebMediaPlayer* WebMediaPlayerClientImpl::webMediaPlayer() const | |
| 60 { | |
| 61 return m_webMediaPlayer.get(); | |
| 62 } | |
| 63 | |
| 64 // WebMediaPlayerClient -------------------------------------------------------- | |
| 65 | |
| 66 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() | |
| 67 { | |
| 68 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. | |
| 69 m_webMediaPlayer.clear(); | |
| 70 } | |
| 71 | |
| 72 void WebMediaPlayerClientImpl::networkStateChanged() | |
| 73 { | |
| 74 m_client->mediaPlayerNetworkStateChanged(); | |
| 75 } | |
| 76 | |
| 77 void WebMediaPlayerClientImpl::readyStateChanged() | |
| 78 { | |
| 79 m_client->mediaPlayerReadyStateChanged(); | |
| 80 } | |
| 81 | |
| 82 void WebMediaPlayerClientImpl::timeChanged() | |
| 83 { | |
| 84 m_client->mediaPlayerTimeChanged(); | |
| 85 } | |
| 86 | |
| 87 void WebMediaPlayerClientImpl::repaint() | |
| 88 { | |
| 89 m_client->mediaPlayerRepaint(); | |
| 90 } | |
| 91 | |
| 92 void WebMediaPlayerClientImpl::durationChanged() | |
| 93 { | |
| 94 m_client->mediaPlayerDurationChanged(); | |
| 95 } | |
| 96 | |
| 97 void WebMediaPlayerClientImpl::sizeChanged() | |
| 98 { | |
| 99 m_client->mediaPlayerSizeChanged(); | |
| 100 } | |
| 101 | |
| 102 void WebMediaPlayerClientImpl::playbackStateChanged() | |
| 103 { | |
| 104 m_client->mediaPlayerPlaybackStateChanged(); | |
| 105 } | |
| 106 | |
| 107 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebStr
ing& sessionId) | |
| 108 { | |
| 109 HTMLMediaElementEncryptedMedia::keyAdded(mediaElement(), keySystem, sessionI
d); | |
| 110 } | |
| 111 | |
| 112 void WebMediaPlayerClientImpl::keyError(const WebString& keySystem, const WebStr
ing& sessionId, MediaKeyErrorCode errorCode, unsigned short systemCode) | |
| 113 { | |
| 114 HTMLMediaElementEncryptedMedia::keyError(mediaElement(), keySystem, sessionI
d, errorCode, systemCode); | |
| 115 } | |
| 116 | |
| 117 void WebMediaPlayerClientImpl::keyMessage(const WebString& keySystem, const WebS
tring& sessionId, const unsigned char* message, unsigned messageLength, const We
bURL& defaultURL) | |
| 118 { | |
| 119 HTMLMediaElementEncryptedMedia::keyMessage(mediaElement(), keySystem, sessio
nId, message, messageLength, defaultURL); | |
| 120 } | |
| 121 | |
| 122 void WebMediaPlayerClientImpl::encrypted(WebEncryptedMediaInitDataType initDataT
ype, const unsigned char* initData, unsigned initDataLength) | |
| 123 { | |
| 124 HTMLMediaElementEncryptedMedia::encrypted(mediaElement(), initDataType, init
Data, initDataLength); | |
| 125 } | |
| 126 | |
| 127 void WebMediaPlayerClientImpl::didBlockPlaybackWaitingForKey() | |
| 128 { | |
| 129 HTMLMediaElementEncryptedMedia::didBlockPlaybackWaitingForKey(mediaElement()
); | |
| 130 } | |
| 131 | |
| 132 void WebMediaPlayerClientImpl::didResumePlaybackBlockedForKey() | |
| 133 { | |
| 134 HTMLMediaElementEncryptedMedia::didResumePlaybackBlockedForKey(mediaElement(
)); | |
| 135 } | |
| 136 | |
| 137 void WebMediaPlayerClientImpl::setWebLayer(WebLayer* layer) | |
| 138 { | |
| 139 m_client->mediaPlayerSetWebLayer(layer); | |
| 140 } | |
| 141 | |
| 142 WebMediaPlayer::TrackId WebMediaPlayerClientImpl::addAudioTrack(const WebString&
id, AudioTrackKind kind, const WebString& label, const WebString& language, boo
l enabled) | |
| 143 { | |
| 144 return mediaElement().addAudioTrack(id, kind, label, language, enabled); | |
| 145 } | |
| 146 | |
| 147 void WebMediaPlayerClientImpl::removeAudioTrack(WebMediaPlayer::TrackId id) | |
| 148 { | |
| 149 mediaElement().removeAudioTrack(id); | |
| 150 } | |
| 151 | |
| 152 WebMediaPlayer::TrackId WebMediaPlayerClientImpl::addVideoTrack(const WebString&
id, VideoTrackKind kind, const WebString& label, const WebString& language, boo
l selected) | |
| 153 { | |
| 154 return mediaElement().addVideoTrack(id, kind, label, language, selected); | |
| 155 } | |
| 156 | |
| 157 void WebMediaPlayerClientImpl::removeVideoTrack(WebMediaPlayer::TrackId id) | |
| 158 { | |
| 159 mediaElement().removeVideoTrack(id); | |
| 160 } | |
| 161 | |
| 162 void WebMediaPlayerClientImpl::addTextTrack(WebInbandTextTrack* textTrack) | |
| 163 { | |
| 164 m_client->mediaPlayerDidAddTextTrack(textTrack); | |
| 165 } | |
| 166 | |
| 167 void WebMediaPlayerClientImpl::removeTextTrack(WebInbandTextTrack* textTrack) | |
| 168 { | |
| 169 m_client->mediaPlayerDidRemoveTextTrack(textTrack); | |
| 170 } | |
| 171 | |
| 172 void WebMediaPlayerClientImpl::mediaSourceOpened(WebMediaSource* webMediaSource) | |
| 173 { | |
| 174 ASSERT(webMediaSource); | |
| 175 m_client->mediaPlayerMediaSourceOpened(webMediaSource); | |
| 176 } | |
| 177 | |
| 178 void WebMediaPlayerClientImpl::requestFullscreen() | |
| 179 { | |
| 180 m_client->mediaPlayerRequestFullscreen(); | |
| 181 } | |
| 182 | |
| 183 void WebMediaPlayerClientImpl::requestSeek(double time) | |
| 184 { | |
| 185 m_client->mediaPlayerRequestSeek(time); | |
| 186 } | |
| 187 | |
| 188 void WebMediaPlayerClientImpl::remoteRouteAvailabilityChanged(bool routesAvailab
le) | |
| 189 { | |
| 190 mediaElement().remoteRouteAvailabilityChanged(routesAvailable); | |
| 191 } | |
| 192 | |
| 193 void WebMediaPlayerClientImpl::connectedToRemoteDevice() | |
| 194 { | |
| 195 mediaElement().connectedToRemoteDevice(); | |
| 196 } | |
| 197 | |
| 198 void WebMediaPlayerClientImpl::disconnectedFromRemoteDevice() | |
| 199 { | |
| 200 mediaElement().disconnectedFromRemoteDevice(); | |
| 201 } | |
| 202 | |
| 203 // MediaPlayer ------------------------------------------------- | |
| 204 void WebMediaPlayerClientImpl::load(WebMediaPlayer::LoadType loadType, const WTF
::String& url, WebMediaPlayer::CORSMode corsMode) | |
| 205 { | |
| 206 ASSERT(!m_webMediaPlayer); | |
| 207 | |
| 208 // FIXME: Remove this cast | |
| 209 LocalFrame* frame = mediaElement().document().frame(); | |
| 210 | |
| 211 WebURL poster = m_client->mediaPlayerPosterURL(); | |
| 212 | |
| 213 KURL kurl(ParsedURLString, url); | |
| 214 m_webMediaPlayer = createWebMediaPlayer(this, kurl, frame, HTMLMediaElementE
ncryptedMedia::contentDecryptionModule(mediaElement())); | |
| 215 if (!m_webMediaPlayer) | |
| 216 return; | |
| 217 | |
| 218 #if ENABLE(WEB_AUDIO) | |
| 219 // Make sure if we create/re-create the WebMediaPlayer that we update our wr
apper. | |
| 220 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); | |
| 221 #endif | |
| 222 | |
| 223 m_webMediaPlayer->setVolume(mediaElement().effectiveMediaVolume()); | |
| 224 | |
| 225 m_webMediaPlayer->setPoster(poster); | |
| 226 | |
| 227 setPreload(mediaElement().preloadType()); | |
| 228 | |
| 229 m_webMediaPlayer->load(loadType, kurl, corsMode); | |
| 230 | |
| 231 if (mediaElement().isFullscreen()) | |
| 232 m_webMediaPlayer->enterFullscreen(); | |
| 233 } | |
| 234 | |
| 235 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload) | |
| 236 { | |
| 237 if (m_webMediaPlayer) | |
| 238 m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preloa
d)); | |
| 239 } | |
| 240 | |
| 241 #if ENABLE(WEB_AUDIO) | |
| 242 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider() | |
| 243 { | |
| 244 return &m_audioSourceProvider; | |
| 245 } | |
| 246 #endif | |
| 247 | |
| 248 PassOwnPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayerClient* clie
nt) | |
| 249 { | |
| 250 return adoptPtr(new WebMediaPlayerClientImpl(client)); | |
| 251 } | |
| 252 | |
| 253 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) | |
| 254 : m_client(client) | |
| 255 { | |
| 256 ASSERT(m_client); | |
| 257 } | |
| 258 | |
| 259 HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const | |
| 260 { | |
| 261 return *static_cast<HTMLMediaElement*>(m_client); | |
| 262 } | |
| 263 | |
| 264 #if ENABLE(WEB_AUDIO) | |
| 265 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi
der* provider) | |
| 266 { | |
| 267 MutexLocker locker(provideInputLock); | |
| 268 | |
| 269 if (m_webAudioSourceProvider && provider != m_webAudioSourceProvider) | |
| 270 m_webAudioSourceProvider->setClient(0); | |
| 271 | |
| 272 m_webAudioSourceProvider = provider; | |
| 273 if (m_webAudioSourceProvider) | |
| 274 m_webAudioSourceProvider->setClient(m_client.get()); | |
| 275 } | |
| 276 | |
| 277 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::setClient(AudioSourcePro
viderClient* client) | |
| 278 { | |
| 279 MutexLocker locker(provideInputLock); | |
| 280 | |
| 281 if (client) | |
| 282 m_client = new WebMediaPlayerClientImpl::AudioClientImpl(client); | |
| 283 else | |
| 284 m_client.clear(); | |
| 285 | |
| 286 if (m_webAudioSourceProvider) | |
| 287 m_webAudioSourceProvider->setClient(m_client.get()); | |
| 288 } | |
| 289 | |
| 290 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::provideInput(AudioBus* b
us, size_t framesToProcess) | |
| 291 { | |
| 292 ASSERT(bus); | |
| 293 if (!bus) | |
| 294 return; | |
| 295 | |
| 296 MutexTryLocker tryLocker(provideInputLock); | |
| 297 if (!tryLocker.locked() || !m_webAudioSourceProvider || !m_client.get()) { | |
| 298 bus->zero(); | |
| 299 return; | |
| 300 } | |
| 301 | |
| 302 // Wrap the AudioBus channel data using WebVector. | |
| 303 size_t n = bus->numberOfChannels(); | |
| 304 WebVector<float*> webAudioData(n); | |
| 305 for (size_t i = 0; i < n; ++i) | |
| 306 webAudioData[i] = bus->channel(i)->mutableData(); | |
| 307 | |
| 308 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess); | |
| 309 } | |
| 310 | |
| 311 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel
s, float sampleRate) | |
| 312 { | |
| 313 if (m_client) | |
| 314 m_client->setFormat(numberOfChannels, sampleRate); | |
| 315 } | |
| 316 | |
| 317 DEFINE_TRACE(WebMediaPlayerClientImpl::AudioClientImpl) | |
| 318 { | |
| 319 visitor->trace(m_client); | |
| 320 } | |
| 321 | |
| 322 #endif | |
| 323 | |
| 324 } // namespace blink | |
| OLD | NEW |