Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: Source/web/WebMediaPlayerClientImpl.cpp

Issue 302093011: Oilpan: move the MediaPlayer and MediaPlayerClient objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Have MediaController weakly track its media elements Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "web/WebMediaPlayerClientImpl.h" 6 #include "web/WebMediaPlayerClientImpl.h"
7 7
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/html/HTMLMediaElement.h" 9 #include "core/html/HTMLMediaElement.h"
10 #include "core/html/TimeRanges.h" 10 #include "core/html/TimeRanges.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 WebMediaPlayer* WebMediaPlayerClientImpl::webMediaPlayer() const 64 WebMediaPlayer* WebMediaPlayerClientImpl::webMediaPlayer() const
65 { 65 {
66 return m_webMediaPlayer.get(); 66 return m_webMediaPlayer.get();
67 } 67 }
68 68
69 // WebMediaPlayerClient -------------------------------------------------------- 69 // WebMediaPlayerClient --------------------------------------------------------
70 70
71 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl() 71 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl()
72 { 72 {
73 #if ENABLE(OILPAN)
74 #if ENABLE(WEB_AUDIO)
75 if (audioSourceProvider())
haraken 2014/06/03 09:19:47 I think this cannot be 0.
76 audioSourceProvider()->setClient(0);
77 #endif
78 // See detach() comment why we are clearing this reference.
79 m_client.clear();
80
73 // Explicitly destroy the WebMediaPlayer to allow verification of tear down. 81 // Explicitly destroy the WebMediaPlayer to allow verification of tear down.
74 m_webMediaPlayer.clear(); 82 m_webMediaPlayer.clear();
83 #else
84 // Check that detach has been called. It should always have been done
85 // with Oilpan not enabled.
86 ASSERT(!m_webMediaPlayer);
87 #endif
88 }
75 89
90 void WebMediaPlayerClientImpl::detach()
91 {
92 // FIXME: This ad-hoc notification call to the supplement is out
93 // here to avoid a core/html/ -> modules/encryptedmedia/
94 // dependency. Consider adding a detach notification from the
95 // media element supplementable to its supplements instead to
96 // avoid involving this client object as a third party.
76 HTMLMediaElementEncryptedMedia::playerDestroyed(mediaElement()); 97 HTMLMediaElementEncryptedMedia::playerDestroyed(mediaElement());
98
99 // For Oilpan, the client object is on the heap and cannot be safely
100 // accessed by WebMediaPlayerClientImpl when it later is GCed.
101 // Clear out the client reference early.
102 //
103 // FIXME: the browser-side WebMediaPlayer implementation performs a
104 // twisty callback to clear the WebLayer (i.e., calls setWebLayer(0))
105 // when being destructed. This resetting is now handled by the
106 // media element directly when detaching. Follow up and support
107 // clearing of the WebMediaPlayer's client reference, so as to
108 // avoid that callback.
109 m_client.clear();
110
111 // Explicitly destroy the WebMediaPlayer to allow verification of tear down.
112 m_webMediaPlayer.clear();
113 }
114
115 void WebMediaPlayerClientImpl::trace(Visitor* visitor)
116 {
117 visitor->trace(m_client);
118 MediaPlayer::trace(visitor);
77 } 119 }
78 120
79 void WebMediaPlayerClientImpl::networkStateChanged() 121 void WebMediaPlayerClientImpl::networkStateChanged()
80 { 122 {
81 m_client->mediaPlayerNetworkStateChanged(); 123 m_client->mediaPlayerNetworkStateChanged();
82 } 124 }
83 125
84 void WebMediaPlayerClientImpl::readyStateChanged() 126 void WebMediaPlayerClientImpl::readyStateChanged()
85 { 127 {
86 m_client->mediaPlayerReadyStateChanged(); 128 m_client->mediaPlayerReadyStateChanged();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 HTMLMediaElementEncryptedMedia::keyMessage(mediaElement(), keySystem, sessio nId, message, messageLength, defaultURL); 178 HTMLMediaElementEncryptedMedia::keyMessage(mediaElement(), keySystem, sessio nId, message, messageLength, defaultURL);
137 } 179 }
138 180
139 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns igned char* initData, unsigned initDataLength) 181 void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns igned char* initData, unsigned initDataLength)
140 { 182 {
141 HTMLMediaElementEncryptedMedia::keyNeeded(mediaElement(), contentType, initD ata, initDataLength); 183 HTMLMediaElementEncryptedMedia::keyNeeded(mediaElement(), contentType, initD ata, initDataLength);
142 } 184 }
143 185
144 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer) 186 void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer)
145 { 187 {
188 if (!m_client) {
189 // Only expect the WebLayer to be cleared when finalizing.
190 // FIXME: switch to assume a non-zero layer argument; see
191 // detach() comment.
192 ASSERT(!layer);
193 return;
194 }
146 m_client->mediaPlayerSetWebLayer(layer); 195 m_client->mediaPlayerSetWebLayer(layer);
147 } 196 }
148 197
149 void WebMediaPlayerClientImpl::addTextTrack(WebInbandTextTrack* textTrack) 198 void WebMediaPlayerClientImpl::addTextTrack(WebInbandTextTrack* textTrack)
150 { 199 {
151 m_client->mediaPlayerDidAddTextTrack(textTrack); 200 m_client->mediaPlayerDidAddTextTrack(textTrack);
152 } 201 }
153 202
154 void WebMediaPlayerClientImpl::removeTextTrack(WebInbandTextTrack* textTrack) 203 void WebMediaPlayerClientImpl::removeTextTrack(WebInbandTextTrack* textTrack)
155 { 204 {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 return timeValue; 409 return timeValue;
361 } 410 }
362 411
363 #if ENABLE(WEB_AUDIO) 412 #if ENABLE(WEB_AUDIO)
364 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider() 413 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider()
365 { 414 {
366 return &m_audioSourceProvider; 415 return &m_audioSourceProvider;
367 } 416 }
368 #endif 417 #endif
369 418
370 PassOwnPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayerClient* clie nt) 419 PassOwnPtrWillBeRawPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayer Client* client)
371 { 420 {
372 return adoptPtr(new WebMediaPlayerClientImpl(client)); 421 return adoptPtrWillBeNoop(new WebMediaPlayerClientImpl(client));
373 } 422 }
374 423
375 #if OS(ANDROID) 424 #if OS(ANDROID)
376 void WebMediaPlayerClientImpl::paintOnAndroid(WebCore::GraphicsContext* context, const IntRect& rect, uint8_t alpha) 425 void WebMediaPlayerClientImpl::paintOnAndroid(WebCore::GraphicsContext* context, const IntRect& rect, uint8_t alpha)
377 { 426 {
378 OwnPtr<blink::WebGraphicsContext3DProvider> provider = adoptPtr(blink::Platf orm::current()->createSharedOffscreenGraphicsContext3DProvider()); 427 OwnPtr<blink::WebGraphicsContext3DProvider> provider = adoptPtr(blink::Platf orm::current()->createSharedOffscreenGraphicsContext3DProvider());
379 if (!provider) 428 if (!provider)
380 return; 429 return;
381 WebGraphicsContext3D* context3D = provider->context3d(); 430 WebGraphicsContext3D* context3D = provider->context3d();
382 if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled ()) 431 if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled ())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 , m_rate(1.0) 464 , m_rate(1.0)
416 #if OS(ANDROID) 465 #if OS(ANDROID)
417 , m_usePaintOnAndroid(false) 466 , m_usePaintOnAndroid(false)
418 #endif 467 #endif
419 { 468 {
420 ASSERT(m_client); 469 ASSERT(m_client);
421 } 470 }
422 471
423 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const 472 WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const
424 { 473 {
425 return *static_cast<HTMLMediaElement*>(m_client); 474 return *static_cast<HTMLMediaElement*>(m_client.get());
426 } 475 }
427 476
428 #if ENABLE(WEB_AUDIO) 477 #if ENABLE(WEB_AUDIO)
429 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi der* provider) 478 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::wrap(WebAudioSourceProvi der* provider)
430 { 479 {
431 MutexLocker locker(provideInputLock); 480 MutexLocker locker(provideInputLock);
432 481
433 if (m_webAudioSourceProvider && provider != m_webAudioSourceProvider) 482 if (m_webAudioSourceProvider && provider != m_webAudioSourceProvider)
434 m_webAudioSourceProvider->setClient(0); 483 m_webAudioSourceProvider->setClient(0);
435 484
436 m_webAudioSourceProvider = provider; 485 m_webAudioSourceProvider = provider;
437 if (m_webAudioSourceProvider) 486 if (m_webAudioSourceProvider)
438 m_webAudioSourceProvider->setClient(m_client.get()); 487 m_webAudioSourceProvider->setClient(m_client.get());
439 } 488 }
440 489
441 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::setClient(AudioSourcePro viderClient* client) 490 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::setClient(AudioSourcePro viderClient* client)
442 { 491 {
443 MutexLocker locker(provideInputLock); 492 MutexLocker locker(provideInputLock);
444 493
445 if (client) 494 if (client)
446 m_client = adoptPtr(new WebMediaPlayerClientImpl::AudioClientImpl(client )); 495 m_client = adoptPtr(new WebMediaPlayerClientImpl::AudioClientImpl(client ));
447 else 496 else
448 m_client.clear(); 497 m_client.clear();
449 498
450 if (m_webAudioSourceProvider) 499 if (m_webAudioSourceProvider) {
451 m_webAudioSourceProvider->setClient(m_client.get()); 500 m_webAudioSourceProvider->setClient(m_client.get());
501 if (!m_client)
502 m_webAudioSourceProvider = 0;
haraken 2014/06/03 09:19:47 Having this code looks harmless, but I still don't
sof 2014/06/03 16:35:31 m_webAudioSourceProvider is something m_webMediaPl
503 }
452 } 504 }
453 505
454 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::provideInput(AudioBus* b us, size_t framesToProcess) 506 void WebMediaPlayerClientImpl::AudioSourceProviderImpl::provideInput(AudioBus* b us, size_t framesToProcess)
455 { 507 {
456 ASSERT(bus); 508 ASSERT(bus);
457 if (!bus) 509 if (!bus)
458 return; 510 return;
459 511
460 MutexTryLocker tryLocker(provideInputLock); 512 MutexTryLocker tryLocker(provideInputLock);
461 if (!tryLocker.locked() || !m_webAudioSourceProvider || !m_client.get()) { 513 if (!tryLocker.locked() || !m_webAudioSourceProvider || !m_client.get()) {
(...skipping 12 matching lines...) Expand all
474 526
475 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate) 527 void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel s, float sampleRate)
476 { 528 {
477 if (m_client) 529 if (m_client)
478 m_client->setFormat(numberOfChannels, sampleRate); 530 m_client->setFormat(numberOfChannels, sampleRate);
479 } 531 }
480 532
481 #endif 533 #endif
482 534
483 } // namespace blink 535 } // namespace blink
OLDNEW
« Source/platform/graphics/media/MediaPlayer.h ('K') | « Source/web/WebMediaPlayerClientImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698