Changeset 165000 in webkit
- Timestamp:
- Mar 3, 2014, 12:47:59 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r164999 r165000 1 2014-03-01 Jer Noble <jer.noble@apple.com> 2 3 [Mac] Crash in MediaPlayer::rateChanged() 4 https://bugs.webkit.org/show_bug.cgi?id=129548 5 6 Reviewed by Darin Adler. 7 8 WTF::bind will automatically ref the parameters added to it. But MediaPlayerPrivate- 9 AVFoundation and -MediaSOurceAVFObjC are not RefCounted, so by the time the bound 10 function is called, the underlying objects may have been freed. 11 12 Replace or augment callOnMainThread arguments with lambdas and weakPtrs so that 13 if the argument has been destroyed, its methods will not be called. 14 15 Make the MediaPlayerPrivateAVFoundation::Notification function type a std::function: 16 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: 17 (WebCore::MediaPlayerPrivateAVFoundation::Notification::Notification): 18 (WebCore::MediaPlayerPrivateAVFoundation::Notification::function): 19 20 Make createWeakPtr() public so that it can be called from non-class methods: 21 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: 22 (WebCore::MediaPlayerPrivateAVFoundationObjC::createWeakPtr): 23 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: 24 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::createWeakPtr): 25 26 Use a weakPtr to abort callOnMainThread() if the object has been destroyed: 27 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: 28 (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): 29 * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: 30 (WebCore::CMTimebaseEffectiveRateChangedCallback): 31 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::play): 32 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::pause): 33 (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::seekWithTolerance): 34 1 35 2014-02-28 Jer Noble <jer.noble@apple.com> 2 36 -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
r164661 r165000 115 115 } 116 116 117 Notification( WTF::Function<void ()> function)117 Notification(std::function<void ()> function) 118 118 : m_type(FunctionType) 119 119 , m_time(0) … … 127 127 double time() { return m_time; } 128 128 bool finished() { return m_finished; } 129 Function<void ()>& function() { return m_function; }129 std::function<void ()>& function() { return m_function; } 130 130 131 131 private: … … 133 133 double m_time; 134 134 bool m_finished; 135 Function<void ()> m_function;135 std::function<void ()> m_function; 136 136 }; 137 137 -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
r164661 r165000 118 118 #endif 119 119 120 WeakPtr<MediaPlayerPrivateAVFoundationObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); } 121 120 122 private: 121 123 MediaPlayerPrivateAVFoundationObjC(MediaPlayer*); 122 123 WeakPtr<MediaPlayerPrivateAVFoundationObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }124 124 125 125 // engine support -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
r164661 r165000 2193 2193 return; 2194 2194 2195 m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification(function)); 2195 auto weakThis = m_callback->createWeakPtr(); 2196 m_callback->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification([weakThis, function]{ 2197 // weakThis and function both refer to the same MediaPlayerPrivateAVFoundationObjC instance. If the WeakPtr has 2198 // been cleared, the underlying object has been destroyed, and it is unsafe to call function(). 2199 if (!weakThis) 2200 return; 2201 function(); 2202 })); 2196 2203 } 2197 2204 -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h
r164529 r165000 78 78 #endif 79 79 80 WeakPtr<MediaPlayerPrivateMediaSourceAVFObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); } 81 80 82 private: 81 83 // MediaPlayerPrivateInterface … … 154 156 void destroyLayer(); 155 157 156 WeakPtr<MediaPlayerPrivateMediaSourceAVFObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }157 158 158 // MediaPlayer Factory Methods 159 159 static PassOwnPtr<MediaPlayerPrivateInterface> create(MediaPlayer*); -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
r164529 r165000 120 120 { 121 121 MediaPlayerPrivateMediaSourceAVFObjC* player = (MediaPlayerPrivateMediaSourceAVFObjC*)listener; 122 callOnMainThread(bind(&MediaPlayerPrivateMediaSourceAVFObjC::effectiveRateChanged, player)); 122 auto weakThis = player->createWeakPtr(); 123 callOnMainThread([weakThis]{ 124 if (!weakThis) 125 return; 126 weakThis.get()->effectiveRateChanged(); 127 }); 123 128 } 124 129 … … 298 303 void MediaPlayerPrivateMediaSourceAVFObjC::play() 299 304 { 300 callOnMainThread(WTF::bind(&MediaPlayerPrivateMediaSourceAVFObjC::playInternal, this)); 305 auto weakThis = createWeakPtr(); 306 callOnMainThread([weakThis]{ 307 if (!weakThis) 308 return; 309 weakThis.get()->playInternal(); 310 }); 301 311 } 302 312 … … 309 319 void MediaPlayerPrivateMediaSourceAVFObjC::pause() 310 320 { 311 callOnMainThread(WTF::bind(&MediaPlayerPrivateMediaSourceAVFObjC::pauseInternal, this)); 321 auto weakThis = createWeakPtr(); 322 callOnMainThread([weakThis]{ 323 if (!weakThis) 324 return; 325 weakThis.get()->pauseInternal(); 326 }); 312 327 } 313 328 … … 389 404 { 390 405 m_seeking = true; 391 callOnMainThread(WTF::bind(&MediaPlayerPrivateMediaSourceAVFObjC::seekInternal, this, time, negativeThreshold, positiveThreshold)); 406 auto weakThis = createWeakPtr(); 407 callOnMainThread([weakThis, time, negativeThreshold, positiveThreshold]{ 408 if (!weakThis) 409 return; 410 weakThis.get()->seekInternal(time, negativeThreshold, positiveThreshold); 411 }); 392 412 } 393 413
Note:
See TracChangeset
for help on using the changeset viewer.