| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "WebMediaPlayerClientImpl.h" | 6 #include "WebMediaPlayerClientImpl.h" |
| 7 | 7 |
| 8 #include "WebDocument.h" | 8 #include "WebDocument.h" |
| 9 #include "WebFrameClient.h" | 9 #include "WebFrameClient.h" |
| 10 #include "WebFrameImpl.h" | 10 #include "WebFrameImpl.h" |
| 11 #include "WebViewImpl.h" | 11 #include "WebViewImpl.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 #include "core/html/HTMLMediaElement.h" | 13 #include "core/html/HTMLMediaElement.h" |
| 14 #include "core/html/TimeRanges.h" | 14 #include "core/html/TimeRanges.h" |
| 15 #include "core/rendering/RenderView.h" | 15 #include "core/rendering/RenderView.h" |
| 16 #include "core/rendering/compositing/RenderLayerCompositor.h" | 16 #include "core/rendering/compositing/RenderLayerCompositor.h" |
| 17 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" |
| 18 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" |
| 17 #include "modules/mediastream/MediaStreamRegistry.h" | 19 #include "modules/mediastream/MediaStreamRegistry.h" |
| 18 #include "platform/audio/AudioBus.h" | 20 #include "platform/audio/AudioBus.h" |
| 19 #include "platform/audio/AudioSourceProviderClient.h" | 21 #include "platform/audio/AudioSourceProviderClient.h" |
| 20 #include "platform/geometry/IntSize.h" | 22 #include "platform/geometry/IntSize.h" |
| 21 #include "platform/graphics/GraphicsContext.h" | 23 #include "platform/graphics/GraphicsContext.h" |
| 22 #include "platform/graphics/GraphicsLayer.h" | 24 #include "platform/graphics/GraphicsLayer.h" |
| 23 #include "platform/graphics/gpu/Extensions3DUtil.h" | 25 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 24 #include "platform/graphics/skia/GaneshUtils.h" | 26 #include "platform/graphics/skia/GaneshUtils.h" |
| 25 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
| 26 #include "public/platform/WebAudioSourceProvider.h" | 28 #include "public/platform/WebAudioSourceProvider.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* cli
ent, const WebURL& url, LocalFrame* frame) | 55 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* cli
ent, const WebURL& url, LocalFrame* frame) |
| 54 { | 56 { |
| 55 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); | 57 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(frame); |
| 56 | 58 |
| 57 if (!webFrame->client()) | 59 if (!webFrame->client()) |
| 58 return nullptr; | 60 return nullptr; |
| 59 return adoptPtr(webFrame->client()->createMediaPlayer(webFrame, url, client)
); | 61 return adoptPtr(webFrame->client()->createMediaPlayer(webFrame, url, client)
); |
| 60 } | 62 } |
| 61 | 63 |
| 62 WebMediaPlayer* WebMediaPlayerClientImpl::mediaPlayer() const | 64 WebMediaPlayer* WebMediaPlayerClientImpl::webMediaPlayer() const |
| 63 { | 65 { |
| 64 return m_webMediaPlayer.get(); | 66 return m_webMediaPlayer.get(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 // WebMediaPlayerClient -------------------------------------------------------- | 69 // WebMediaPlayerClient -------------------------------------------------------- |
| 68 | 70 |
| 69 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() | 71 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() |
| 70 { | 72 { |
| 73 HTMLMediaElementEncryptedMedia::playerDestroyed(mediaElement()); |
| 74 |
| 71 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. | 75 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. |
| 72 m_webMediaPlayer.clear(); | 76 m_webMediaPlayer.clear(); |
| 73 } | 77 } |
| 74 | 78 |
| 75 void WebMediaPlayerClientImpl::networkStateChanged() | 79 void WebMediaPlayerClientImpl::networkStateChanged() |
| 76 { | 80 { |
| 77 m_client->mediaPlayerNetworkStateChanged(); | 81 m_client->mediaPlayerNetworkStateChanged(); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void WebMediaPlayerClientImpl::readyStateChanged() | 84 void WebMediaPlayerClientImpl::readyStateChanged() |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 m_client->mediaPlayerPlaybackStateChanged(); | 121 m_client->mediaPlayerPlaybackStateChanged(); |
| 118 } | 122 } |
| 119 | 123 |
| 120 WebMediaPlayer::Preload WebMediaPlayerClientImpl::preload() const | 124 WebMediaPlayer::Preload WebMediaPlayerClientImpl::preload() const |
| 121 { | 125 { |
| 122 return static_cast<WebMediaPlayer::Preload>(m_preload); | 126 return static_cast<WebMediaPlayer::Preload>(m_preload); |
| 123 } | 127 } |
| 124 | 128 |
| 125 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebStr
ing& sessionId) | 129 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebStr
ing& sessionId) |
| 126 { | 130 { |
| 127 m_client->mediaPlayerKeyAdded(keySystem, sessionId); | 131 HTMLMediaElementEncryptedMedia::keyAdded(mediaElement(), keySystem, sessionI
d); |
| 128 } | 132 } |
| 129 | 133 |
| 130 void WebMediaPlayerClientImpl::keyError(const WebString& keySystem, const WebStr
ing& sessionId, MediaKeyErrorCode errorCode, unsigned short systemCode) | 134 void WebMediaPlayerClientImpl::keyError(const WebString& keySystem, const WebStr
ing& sessionId, MediaKeyErrorCode errorCode, unsigned short systemCode) |
| 131 { | 135 { |
| 132 m_client->mediaPlayerKeyError(keySystem, sessionId, static_cast<MediaPlayerC
lient::MediaKeyErrorCode>(errorCode), systemCode); | 136 HTMLMediaElementEncryptedMedia::keyError(mediaElement(), keySystem, sessionI
d, errorCode, systemCode); |
| 133 } | 137 } |
| 134 | 138 |
| 135 void WebMediaPlayerClientImpl::keyMessage(const WebString& keySystem, const WebS
tring& sessionId, const unsigned char* message, unsigned messageLength, const We
bURL& defaultURL) | 139 void WebMediaPlayerClientImpl::keyMessage(const WebString& keySystem, const WebS
tring& sessionId, const unsigned char* message, unsigned messageLength, const We
bURL& defaultURL) |
| 136 { | 140 { |
| 137 m_client->mediaPlayerKeyMessage(keySystem, sessionId, message, messageLength
, defaultURL); | 141 HTMLMediaElementEncryptedMedia::keyMessage(mediaElement(), keySystem, sessio
nId, message, messageLength, defaultURL); |
| 138 } | 142 } |
| 139 | 143 |
| 140 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns
igned char* initData, unsigned initDataLength) | 144 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns
igned char* initData, unsigned initDataLength) |
| 141 { | 145 { |
| 142 m_client->mediaPlayerKeyNeeded(contentType, initData, initDataLength); | 146 HTMLMediaElementEncryptedMedia::keyNeeded(mediaElement(), contentType, initD
ata, initDataLength); |
| 143 } | 147 } |
| 144 | 148 |
| 145 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer) | 149 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer) |
| 146 { | 150 { |
| 147 m_client->mediaPlayerSetWebLayer(layer); | 151 m_client->mediaPlayerSetWebLayer(layer); |
| 148 } | 152 } |
| 149 | 153 |
| 150 void WebMediaPlayerClientImpl::addTextTrack(WebInbandTextTrack* textTrack) | 154 void WebMediaPlayerClientImpl::addTextTrack(WebInbandTextTrack* textTrack) |
| 151 { | 155 { |
| 152 m_client->mediaPlayerDidAddTextTrack(textTrack); | 156 m_client->mediaPlayerDidAddTextTrack(textTrack); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 loadInternal(); | 194 loadInternal(); |
| 191 } | 195 } |
| 192 | 196 |
| 193 void WebMediaPlayerClientImpl::loadInternal() | 197 void WebMediaPlayerClientImpl::loadInternal() |
| 194 { | 198 { |
| 195 #if ENABLE(WEB_AUDIO) | 199 #if ENABLE(WEB_AUDIO) |
| 196 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's
WebAudioSourceProvider. | 200 m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's
WebAudioSourceProvider. |
| 197 #endif | 201 #endif |
| 198 | 202 |
| 199 // FIXME: Remove this cast | 203 // FIXME: Remove this cast |
| 200 LocalFrame* frame = static_cast<HTMLMediaElement*>(m_client)->document().fra
me(); | 204 LocalFrame* frame = mediaElement().document().frame(); |
| 201 | 205 |
| 202 WebURL poster = m_client->mediaPlayerPosterURL(); | 206 WebURL poster = m_client->mediaPlayerPosterURL(); |
| 203 | 207 |
| 204 // This does not actually check whether the hardware can support accelerated | 208 // This does not actually check whether the hardware can support accelerated |
| 205 // compositing, but only if the flag is set. However, this is checked lazily | 209 // compositing, but only if the flag is set. However, this is checked lazily |
| 206 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there | 210 // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there |
| 207 // if necessary. | 211 // if necessary. |
| 208 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler
atedCompositing(); | 212 m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceler
atedCompositing(); |
| 209 | 213 |
| 210 m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame); | 214 m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame); |
| 211 if (m_webMediaPlayer) { | 215 if (m_webMediaPlayer) { |
| 212 #if ENABLE(WEB_AUDIO) | 216 #if ENABLE(WEB_AUDIO) |
| 213 // Make sure if we create/re-create the WebMediaPlayer that we update ou
r wrapper. | 217 // Make sure if we create/re-create the WebMediaPlayer that we update ou
r wrapper. |
| 214 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); | 218 m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider()); |
| 215 #endif | 219 #endif |
| 216 | 220 |
| 217 // Tell WebMediaPlayer about the poster image URL. | 221 // Tell WebMediaPlayer about the poster image URL. |
| 218 m_webMediaPlayer->setPoster(poster); | 222 m_webMediaPlayer->setPoster(poster); |
| 219 | 223 |
| 220 // Tell WebMediaPlayer about any connected CDM (may be null). | 224 // Tell WebMediaPlayer about any connected CDM (may be null). |
| 221 m_webMediaPlayer->setContentDecryptionModule(m_cdm); | 225 m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMe
dia::contentDecryptionModule(mediaElement())); |
| 222 | 226 |
| 223 WebMediaPlayer::CORSMode corsMode = static_cast<WebMediaPlayer::CORSMode
>(m_client->mediaPlayerCORSMode()); | 227 WebMediaPlayer::CORSMode corsMode = static_cast<WebMediaPlayer::CORSMode
>(m_client->mediaPlayerCORSMode()); |
| 224 m_webMediaPlayer->load(m_loadType, m_url, corsMode); | 228 m_webMediaPlayer->load(m_loadType, m_url, corsMode); |
| 225 } | 229 } |
| 226 } | 230 } |
| 227 | 231 |
| 228 void WebMediaPlayerClientImpl::play() | 232 void WebMediaPlayerClientImpl::play() |
| 229 { | 233 { |
| 230 if (m_webMediaPlayer) | 234 if (m_webMediaPlayer) |
| 231 m_webMediaPlayer->play(); | 235 m_webMediaPlayer->play(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 247 { | 251 { |
| 248 if (m_webMediaPlayer) | 252 if (m_webMediaPlayer) |
| 249 m_webMediaPlayer->exitFullscreen(); | 253 m_webMediaPlayer->exitFullscreen(); |
| 250 } | 254 } |
| 251 | 255 |
| 252 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const | 256 bool WebMediaPlayerClientImpl::canShowFullscreenOverlay() const |
| 253 { | 257 { |
| 254 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen(); | 258 return m_webMediaPlayer && m_webMediaPlayer->canEnterFullscreen(); |
| 255 } | 259 } |
| 256 | 260 |
| 257 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::generateKeyRequest(cons
t String& keySystem, const unsigned char* initData, unsigned initDataLength) | |
| 258 { | |
| 259 if (!m_webMediaPlayer) | |
| 260 return MediaPlayer::InvalidPlayerState; | |
| 261 | |
| 262 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->generateKeyRequ
est(keySystem, initData, initDataLength); | |
| 263 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 264 } | |
| 265 | |
| 266 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::addKey(const String& ke
ySystem, const unsigned char* key, unsigned keyLength, const unsigned char* init
Data, unsigned initDataLength, const String& sessionId) | |
| 267 { | |
| 268 if (!m_webMediaPlayer) | |
| 269 return MediaPlayer::InvalidPlayerState; | |
| 270 | |
| 271 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->addKey(keySyste
m, key, keyLength, initData, initDataLength, sessionId); | |
| 272 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 273 } | |
| 274 | |
| 275 MediaPlayer::MediaKeyException WebMediaPlayerClientImpl::cancelKeyRequest(const
String& keySystem, const String& sessionId) | |
| 276 { | |
| 277 if (!m_webMediaPlayer) | |
| 278 return MediaPlayer::InvalidPlayerState; | |
| 279 | |
| 280 WebMediaPlayer::MediaKeyException result = m_webMediaPlayer->cancelKeyReques
t(keySystem, sessionId); | |
| 281 return static_cast<MediaPlayer::MediaKeyException>(result); | |
| 282 } | |
| 283 | |
| 284 void WebMediaPlayerClientImpl::setContentDecryptionModule(WebContentDecryptionMo
dule* cdm) | |
| 285 { | |
| 286 m_cdm = cdm; | |
| 287 if (m_webMediaPlayer) | |
| 288 m_webMediaPlayer->setContentDecryptionModule(cdm); | |
| 289 } | |
| 290 | |
| 291 void WebMediaPlayerClientImpl::prepareToPlay() | 261 void WebMediaPlayerClientImpl::prepareToPlay() |
| 292 { | 262 { |
| 293 if (m_delayingLoad) | 263 if (m_delayingLoad) |
| 294 startDelayedLoad(); | 264 startDelayedLoad(); |
| 295 } | 265 } |
| 296 | 266 |
| 297 IntSize WebMediaPlayerClientImpl::naturalSize() const | 267 IntSize WebMediaPlayerClientImpl::naturalSize() const |
| 298 { | 268 { |
| 299 if (m_webMediaPlayer) | 269 if (m_webMediaPlayer) |
| 300 return m_webMediaPlayer->naturalSize(); | 270 return m_webMediaPlayer->naturalSize(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 554 } |
| 585 | 555 |
| 586 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) | 556 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client) |
| 587 : m_client(client) | 557 : m_client(client) |
| 588 , m_delayingLoad(false) | 558 , m_delayingLoad(false) |
| 589 , m_preload(MediaPlayer::Auto) | 559 , m_preload(MediaPlayer::Auto) |
| 590 , m_needsWebLayerForVideo(false) | 560 , m_needsWebLayerForVideo(false) |
| 591 , m_volume(1.0) | 561 , m_volume(1.0) |
| 592 , m_muted(false) | 562 , m_muted(false) |
| 593 , m_rate(1.0) | 563 , m_rate(1.0) |
| 594 , m_cdm(0) | |
| 595 , m_loadType(WebMediaPlayer::LoadTypeURL) | 564 , m_loadType(WebMediaPlayer::LoadTypeURL) |
| 596 { | 565 { |
| 597 ASSERT(m_client); | 566 ASSERT(m_client); |
| 598 } | 567 } |
| 599 | 568 |
| 600 #if ENABLE(WEB_AUDIO) | 569 #if ENABLE(WEB_AUDIO) |
| 601 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi
der* provider) | 570 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi
der* provider) |
| 602 { | 571 { |
| 603 MutexLocker locker(provideInputLock); | 572 MutexLocker locker(provideInputLock); |
| 604 | 573 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 612 |
| 644 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess); | 613 m_webAudioSourceProvider->provideInput(webAudioData, framesToProcess); |
| 645 } | 614 } |
| 646 | 615 |
| 647 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel
s, float sampleRate) | 616 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel
s, float sampleRate) |
| 648 { | 617 { |
| 649 if (m_client) | 618 if (m_client) |
| 650 m_client->setFormat(numberOfChannels, sampleRate); | 619 m_client->setFormat(numberOfChannels, sampleRate); |
| 651 } | 620 } |
| 652 | 621 |
| 622 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const |
| 623 { |
| 624 return *static_cast<HTMLMediaElement*>(m_client); |
| 625 } |
| 626 |
| 653 #endif | 627 #endif |
| 654 | 628 |
| 655 } // namespace blink | 629 } // namespace blink |
| OLD | NEW |