Refactoring: Make sure to unprepare WebAudioSourceProviderAVFObjC when its owner...
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 22:51:12 +0000 (22:51 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2017 22:51:12 +0000 (22:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168532

Reviewed by Youenn Fablet.

Because WebAudioSourceProviderAVFObjC has a back-pointer to the object which creted it, make
sure that back-pointer is invalidated once the creating object is destroyed by calling
WebAudioSOurceProviderAVFObjC::unprepare().

Drive-by Fix: In WebAudioSourceProviderAVFObjC::audioSamplesAvailable(), PlatformAudioData will
always be of the WebAudioBufferList type. If this ever becomes untrue, an invalid downcast will
be caught by downcast<>, so just remove the is<> check.

* platform/mediastream/mac/AVAudioCaptureSource.mm:
(WebCore::AVAudioCaptureSource::~AVAudioCaptureSource):
* platform/mediastream/mac/MockRealtimeAudioSourceMac.h:
* platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
(WebCore::MockRealtimeAudioSourceMac::~MockRealtimeAudioSourceMac):
* platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
(WebCore::RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource):
* platform/mediastream/mac/RealtimeIncomingAudioSource.h:
* platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
(WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
(WebCore::WebAudioSourceProviderAVFObjC::setClient):
(WebCore::WebAudioSourceProviderAVFObjC::unprepare):
(WebCore::WebAudioSourceProviderAVFObjC::audioSamplesAvailable):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212581 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm
Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.h
Source/WebCore/platform/mediastream/mac/MockRealtimeAudioSourceMac.mm
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingAudioSource.h
Source/WebCore/platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm

index e6f83f8..0a111dc 100644 (file)
@@ -1,3 +1,32 @@
+2017-02-17  Jer Noble  <jer.noble@apple.com>
+
+        Refactoring: Make sure to unprepare WebAudioSourceProviderAVFObjC when its owner is destroyed.
+        https://bugs.webkit.org/show_bug.cgi?id=168532
+
+        Reviewed by Youenn Fablet.
+
+        Because WebAudioSourceProviderAVFObjC has a back-pointer to the object which creted it, make
+        sure that back-pointer is invalidated once the creating object is destroyed by calling
+        WebAudioSOurceProviderAVFObjC::unprepare().
+
+        Drive-by Fix: In WebAudioSourceProviderAVFObjC::audioSamplesAvailable(), PlatformAudioData will
+        always be of the WebAudioBufferList type. If this ever becomes untrue, an invalid downcast will
+        be caught by downcast<>, so just remove the is<> check.
+
+        * platform/mediastream/mac/AVAudioCaptureSource.mm:
+        (WebCore::AVAudioCaptureSource::~AVAudioCaptureSource):
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.h:
+        * platform/mediastream/mac/MockRealtimeAudioSourceMac.mm:
+        (WebCore::MockRealtimeAudioSourceMac::~MockRealtimeAudioSourceMac):
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.cpp:
+        (WebCore::RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource):
+        * platform/mediastream/mac/RealtimeIncomingAudioSource.h:
+        * platform/mediastream/mac/WebAudioSourceProviderAVFObjC.mm:
+        (WebCore::WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC):
+        (WebCore::WebAudioSourceProviderAVFObjC::setClient):
+        (WebCore::WebAudioSourceProviderAVFObjC::unprepare):
+        (WebCore::WebAudioSourceProviderAVFObjC::audioSamplesAvailable):
+
 2017-02-17  Antoine Quint  <graouts@apple.com>
 
         [Modern Media Controls] Improve handling of <video> with only audio tracks
index 8793ea8..578f28e 100644 (file)
@@ -96,6 +96,7 @@ AVAudioCaptureSource::AVAudioCaptureSource(AVCaptureDeviceTypedef* device, const
     
 AVAudioCaptureSource::~AVAudioCaptureSource()
 {
+    shutdownCaptureSession();
 }
 
 void AVAudioCaptureSource::initializeCapabilities(RealtimeMediaSourceCapabilities& capabilities)
index c620199..7c7f2f3 100644 (file)
@@ -49,6 +49,7 @@ class MockRealtimeAudioSourceMac final : public MockRealtimeAudioSource {
 private:
     friend class MockRealtimeAudioSource;
     MockRealtimeAudioSourceMac(const String&);
+    ~MockRealtimeAudioSourceMac();
 
     bool applySampleRate(int) final;
     bool applySampleSize(int) final { return false; }
index 0101dfb..3aa1d3f 100644 (file)
@@ -71,6 +71,14 @@ MockRealtimeAudioSourceMac::MockRealtimeAudioSourceMac(const String& name)
 {
 }
 
+MockRealtimeAudioSourceMac::~MockRealtimeAudioSourceMac()
+{
+    if (m_audioSourceProvider) {
+        m_audioSourceProvider->unprepare();
+        m_audioSourceProvider = nullptr;
+    }
+}
+
 RefPtr<MockRealtimeAudioSource> MockRealtimeAudioSource::createMuted(const String& name)
 {
     auto source = adoptRef(new MockRealtimeAudioSource(name));
index a57a9f1..96127cb 100644 (file)
@@ -51,6 +51,14 @@ RealtimeIncomingAudioSource::RealtimeIncomingAudioSource(rtc::scoped_refptr<webr
 {
 }
 
+RealtimeIncomingAudioSource::~RealtimeIncomingAudioSource()
+{
+    if (m_audioSourceProvider) {
+        m_audioSourceProvider->unprepare();
+        m_audioSourceProvider = nullptr;
+    }
+}
+
 void RealtimeIncomingAudioSource::OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames)
 {
     // FIXME: Implement this.
index ce4faa2..8a7d7d8 100644 (file)
@@ -50,6 +50,7 @@ public:
 
 private:
     RealtimeIncomingAudioSource(rtc::scoped_refptr<webrtc::AudioTrackInterface>&&, String&&);
+    ~RealtimeIncomingAudioSource();
 
     // webrtc::AudioTrackSinkInterface API
     void OnData(const void* audioData, int bitsPerSample, int sampleRate, size_t numberOfChannels, size_t numberOfFrames) final;
index 8ce694c..028befd 100644 (file)
@@ -73,7 +73,7 @@ WebAudioSourceProviderAVFObjC::~WebAudioSourceProviderAVFObjC()
         AudioConverterDispose(m_converter);
         m_converter = nullptr;
     }
-    if (m_connected)
+    if (m_connected && m_captureSource)
         m_captureSource->removeObserver(*this);
 }
 
@@ -128,6 +128,9 @@ void WebAudioSourceProviderAVFObjC::setClient(AudioSourceProviderClient* client)
 
     m_client = client;
 
+    if (!m_captureSource)
+        return;
+
     if (m_client && !m_connected) {
         m_connected = true;
         m_captureSource->addObserver(*this);
@@ -213,6 +216,11 @@ void WebAudioSourceProviderAVFObjC::unprepare()
     m_ringBuffer = nullptr;
     m_list = nullptr;
     m_listBufferSize = 0;
+    if (m_captureSource) {
+        m_captureSource->removeObserver(*this);
+        m_captureSource = nullptr;
+    }
+
     if (m_converter) {
         // FIXME: make and use a smart pointer for AudioConverter
         AudioConverterDispose(m_converter);
@@ -222,7 +230,7 @@ void WebAudioSourceProviderAVFObjC::unprepare()
 
 void WebAudioSourceProviderAVFObjC::audioSamplesAvailable(const MediaTime&, const PlatformAudioData& data, const AudioStreamDescription&, size_t frameCount)
 {
-    if (!m_ringBuffer || !is<WebAudioBufferList>(data))
+    if (!m_ringBuffer)
         return;
 
     auto& bufferList = downcast<WebAudioBufferList>(data);