Make TrackPrivateBase ThreadSafeRefCounted, so that it can be retained in non-main...
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 17:25:02 +0000 (17:25 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2017 17:25:02 +0000 (17:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168642

Reviewed by Eric Carlson.

AudioTrackPrivateMediaStreamCocoa has two entry points from background threads:
audioSamplesAvailable() and render(). Protect against being destroyed mid-execution by
retaining this for the duration of those methods.

* platform/graphics/TrackPrivateBase.h:
* platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp:
(WebCore::AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable):
(WebCore::AudioTrackPrivateMediaStreamCocoa::render):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/TrackPrivateBase.h
Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp

index b1263fb..fc7089a 100644 (file)
@@ -1,5 +1,21 @@
 2017-02-21  Jer Noble  <jer.noble@apple.com>
 
+        Make TrackPrivateBase ThreadSafeRefCounted, so that it can be retained in non-main threads
+        https://bugs.webkit.org/show_bug.cgi?id=168642
+
+        Reviewed by Eric Carlson.
+
+        AudioTrackPrivateMediaStreamCocoa has two entry points from background threads:
+        audioSamplesAvailable() and render(). Protect against being destroyed mid-execution by
+        retaining this for the duration of those methods.
+
+        * platform/graphics/TrackPrivateBase.h:
+        * platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp:
+        (WebCore::AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable):
+        (WebCore::AudioTrackPrivateMediaStreamCocoa::render):
+
+2017-02-21  Jer Noble  <jer.noble@apple.com>
+
         Pulling too quickly from an AudioSampleDataSource should increase the pre-buffer amount
         https://bugs.webkit.org/show_bug.cgi?id=168645
 
index 0b00ca5..a865ceb 100644 (file)
@@ -30,6 +30,7 @@
 #if ENABLE(VIDEO_TRACK)
 
 #include <wtf/MediaTime.h>
+#include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
@@ -43,7 +44,7 @@ public:
     virtual void willRemove() = 0;
 };
 
-class TrackPrivateBase : public RefCounted<TrackPrivateBase> {
+class TrackPrivateBase : public ThreadSafeRefCounted<TrackPrivateBase> {
     WTF_MAKE_NONCOPYABLE(TrackPrivateBase);
     WTF_MAKE_FAST_ALLOCATED;
 public:
index 62e498e..6f3bb8f 100644 (file)
@@ -180,6 +180,7 @@ OSStatus AudioTrackPrivateMediaStreamCocoa::setupAudioUnit()
 
 void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& sampleTime, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
 {
+    Ref<AudioTrackPrivateMediaStreamCocoa> protectedThis { *this };
     ASSERT(description.platformDescription().type == PlatformDescription::CAAudioStreamBasicType);
 
     std::lock_guard<Lock> lock(m_internalStateLock);
@@ -228,6 +229,8 @@ void AudioTrackPrivateMediaStreamCocoa::sourceStopped()
 
 OSStatus AudioTrackPrivateMediaStreamCocoa::render(UInt32 sampleCount, AudioBufferList& ioData, UInt32 /*inBusNumber*/, const AudioTimeStamp& timeStamp, AudioUnitRenderActionFlags& actionFlags)
 {
+    Ref<AudioTrackPrivateMediaStreamCocoa> protectedThis { *this };
+
     std::unique_lock<Lock> lock(m_internalStateLock, std::try_to_lock);
     if (!lock.owns_lock())
         return kAudioConverterErr_UnspecifiedError;