Title: [275897] trunk/Source/WebCore
Revision
275897
Author
[email protected]
Date
2021-04-13 11:35:32 -0700 (Tue, 13 Apr 2021)

Log Message

AudioSourceProviderAVFObjC should check for m_client when dispatching setFormat
https://bugs.webkit.org/show_bug.cgi?id=224479

Patch by Kimmo Kinnunen <[email protected]> on 2021-04-13
Reviewed by Eric Carlson.

Use a weak pointer to schedule the setFormat client callback.
If client is unset before any callback is run, cancel the
pending callbacks.

* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h:
* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
(WebCore::AudioSourceProviderAVFObjC::destroyMixIfNeeded):
(WebCore::AudioSourceProviderAVFObjC::createMixIfNeeded):
(WebCore::AudioSourceProviderAVFObjC::prepare):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275896 => 275897)


--- trunk/Source/WebCore/ChangeLog	2021-04-13 18:31:14 UTC (rev 275896)
+++ trunk/Source/WebCore/ChangeLog	2021-04-13 18:35:32 UTC (rev 275897)
@@ -1,5 +1,22 @@
 2021-04-13  Kimmo Kinnunen  <[email protected]>
 
+        AudioSourceProviderAVFObjC should check for m_client when dispatching setFormat
+        https://bugs.webkit.org/show_bug.cgi?id=224479
+
+        Reviewed by Eric Carlson.
+
+        Use a weak pointer to schedule the setFormat client callback.
+        If client is unset before any callback is run, cancel the
+        pending callbacks.
+
+        * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h:
+        * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+        (WebCore::AudioSourceProviderAVFObjC::destroyMixIfNeeded):
+        (WebCore::AudioSourceProviderAVFObjC::createMixIfNeeded):
+        (WebCore::AudioSourceProviderAVFObjC::prepare):
+
+2021-04-13  Kimmo Kinnunen  <[email protected]>
+
         AudioSourceProviderAVFObjC::setClient should check for m_avAssetTrack
         https://bugs.webkit.org/show_bug.cgi?id=224478
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h (275896 => 275897)


--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h	2021-04-13 18:31:14 UTC (rev 275896)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.h	2021-04-13 18:35:32 UTC (rev 275897)
@@ -34,6 +34,7 @@
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/TypeCasts.h>
 #include <wtf/UniqueRef.h>
+#include <wtf/WeakPtr.h>
 
 OBJC_CLASS AVAssetTrack;
 OBJC_CLASS AVPlayerItem;
@@ -55,6 +56,7 @@
 
 class AudioSourceProviderAVFObjC : public ThreadSafeRefCounted<AudioSourceProviderAVFObjC>, public AudioSourceProvider {
 public:
+    using WeakValueType = AudioSourceProviderAVFObjC;
     static RefPtr<AudioSourceProviderAVFObjC> create(AVPlayerItem*);
     virtual ~AudioSourceProviderAVFObjC();
 
@@ -107,6 +109,7 @@
     std::atomic<uint64_t> m_seekTo { NoSeek };
     bool m_paused { true };
     AudioSourceProviderClient* m_client { nullptr };
+    WeakPtrFactory<AudioSourceProviderAVFObjC> m_weakFactory;
 
     class TapStorage;
     RefPtr<TapStorage> m_tapStorage;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (275896 => 275897)


--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2021-04-13 18:31:14 UTC (rev 275896)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2021-04-13 18:35:32 UTC (rev 275897)
@@ -191,6 +191,7 @@
     [m_avAudioMix setInputParameters:@[ ]];
     m_avAudioMix.clear();
     m_tap.clear();
+    m_weakFactory.revokeAll();
 }
 
 void AudioSourceProviderAVFObjC::createMixIfNeeded()
@@ -229,6 +230,7 @@
     
     [m_avAudioMix setInputParameters:@[parameters.get()]];
     [m_avPlayerItem setAudioMix:m_avAudioMix.get()];
+    m_weakFactory.initializeIfNeeded(*this);
 }
 
 void AudioSourceProviderAVFObjC::initCallback(MTAudioProcessingTapRef tap, void* clientInfo, void** tapStorageOut)
@@ -346,8 +348,10 @@
     memset(m_list.get(), 0, bufferListSize);
     m_list->mNumberBuffers = numberOfChannels;
 
-    callOnMainThread([protectedThis = makeRef(*this), numberOfChannels, sampleRate] {
-        protectedThis->m_client->setFormat(numberOfChannels, sampleRate);
+    callOnMainThread([weakThis = m_weakFactory.createWeakPtr(*this), numberOfChannels, sampleRate] {
+        auto* self = weakThis.get();
+        if (self && self->m_client)
+            self->m_client->setFormat(numberOfChannels, sampleRate);
     });
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to