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