Make passing PlatformAudioData in audioSamplesAvaliable const-correct.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Feb 2017 20:28:44 +0000 (20:28 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Feb 2017 20:28:44 +0000 (20:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=168051

Reviewed by Eric Carlson.

Modify all the functions which take a (conceptually) read-only audio buffer const-correct.

Drive-by fix: AudioSampleBufferList::copyFrom() set a ivar pointer to the passed in
AudioBufferList. Ensure that the ivar is reset when copyFrom() returns by using a
SetForScope.

* platform/audio/mac/AudioSampleBufferList.cpp:
(WebCore::AudioSampleBufferList::copyFrom):
* platform/audio/mac/AudioSampleBufferList.h:
* platform/audio/mac/AudioSampleDataSource.cpp:
(WebCore::AudioSampleDataSource::pushSamplesInternal):
(WebCore::AudioSampleDataSource::pushSamples):
* platform/audio/mac/AudioSampleDataSource.h:
* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::audioSamplesAvailable):
* platform/mediastream/RealtimeMediaSource.h:
(WebCore::RealtimeMediaSource::Observer::audioSamplesAvailable):
* platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp:
(WebCore::AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable):
* platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h:
* platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp:
(WebCore::RealtimeOutgoingAudioSource::audioSamplesAvailable):
* platform/mediastream/mac/RealtimeOutgoingAudioSource.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/audio/mac/AudioSampleBufferList.cpp
Source/WebCore/platform/audio/mac/AudioSampleBufferList.h
Source/WebCore/platform/audio/mac/AudioSampleDataSource.cpp
Source/WebCore/platform/audio/mac/AudioSampleDataSource.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp
Source/WebCore/platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h
Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeOutgoingAudioSource.h

index 184afdc..6aa6b85 100644 (file)
@@ -1,5 +1,36 @@
 2017-02-09  Jer Noble  <jer.noble@apple.com>
 
+        Make passing PlatformAudioData in audioSamplesAvaliable const-correct.
+        https://bugs.webkit.org/show_bug.cgi?id=168051
+
+        Reviewed by Eric Carlson.
+
+        Modify all the functions which take a (conceptually) read-only audio buffer const-correct.
+
+        Drive-by fix: AudioSampleBufferList::copyFrom() set a ivar pointer to the passed in
+        AudioBufferList. Ensure that the ivar is reset when copyFrom() returns by using a
+        SetForScope.
+
+        * platform/audio/mac/AudioSampleBufferList.cpp:
+        (WebCore::AudioSampleBufferList::copyFrom):
+        * platform/audio/mac/AudioSampleBufferList.h:
+        * platform/audio/mac/AudioSampleDataSource.cpp:
+        (WebCore::AudioSampleDataSource::pushSamplesInternal):
+        (WebCore::AudioSampleDataSource::pushSamples):
+        * platform/audio/mac/AudioSampleDataSource.h:
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::audioSamplesAvailable):
+        * platform/mediastream/RealtimeMediaSource.h:
+        (WebCore::RealtimeMediaSource::Observer::audioSamplesAvailable):
+        * platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.cpp:
+        (WebCore::AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable):
+        * platform/mediastream/mac/AudioTrackPrivateMediaStreamCocoa.h:
+        * platform/mediastream/mac/RealtimeOutgoingAudioSource.cpp:
+        (WebCore::RealtimeOutgoingAudioSource::audioSamplesAvailable):
+        * platform/mediastream/mac/RealtimeOutgoingAudioSource.h:
+
+2017-02-09  Jer Noble  <jer.noble@apple.com>
+
         Fix some logging statements in MediaPlayerPrivateMediaStreamAVFObjC
         https://bugs.webkit.org/show_bug.cgi?id=168063
 
index 0b53a33..794e86c 100644 (file)
@@ -32,6 +32,7 @@
 #include "VectorMath.h"
 #include <Accelerate/Accelerate.h>
 #include <AudioToolbox/AudioConverter.h>
+#include <wtf/SetForScope.h>
 
 namespace WebCore {
 
@@ -244,7 +245,7 @@ OSStatus AudioSampleBufferList::audioConverterCallback(AudioConverterRef, UInt32
     return static_cast<AudioSampleBufferList*>(inRefCon)->convertInput(ioNumberDataPackets, ioData);
 }
 
-OSStatus AudioSampleBufferList::copyFrom(AudioBufferList& source, AudioConverterRef converter)
+OSStatus AudioSampleBufferList::copyFrom(const AudioBufferList& source, AudioConverterRef converter)
 {
     reset();
 
@@ -252,7 +253,7 @@ OSStatus AudioSampleBufferList::copyFrom(AudioBufferList& source, AudioConverter
     UInt32 propertyDataSize = sizeof(inputFormat);
     AudioConverterGetProperty(converter, kAudioConverterCurrentInputStreamDescription, &propertyDataSize, &inputFormat);
     m_converterInputBytesPerPacket = inputFormat.mBytesPerPacket;
-    m_converterInputBuffer = &source;
+    SetForScope<const AudioBufferList*> scopedInputBuffer(m_converterInputBuffer, &source);
 
 #if !LOG_DISABLED
     AudioStreamBasicDescription outputFormat;
index c99ee9a..e105bd3 100644 (file)
@@ -51,7 +51,7 @@ public:
     void applyGain(float);
 
     OSStatus copyFrom(const AudioSampleBufferList&, size_t count = SIZE_MAX);
-    OSStatus copyFrom(AudioBufferList&, AudioConverterRef);
+    OSStatus copyFrom(const AudioBufferList&, AudioConverterRef);
     OSStatus copyFrom(AudioSampleBufferList&, AudioConverterRef);
     OSStatus copyFrom(CARingBuffer&, size_t frameCount, uint64_t startFrame, CARingBuffer::FetchMode);
 
@@ -83,8 +83,7 @@ protected:
 
     std::unique_ptr<CAAudioStreamDescription> m_internalFormat;
 
-    AudioSampleBufferList* m_converterInputBuffer2 { nullptr };
-    AudioBufferList* m_converterInputBuffer { nullptr };
+    const AudioBufferList* m_converterInputBuffer { nullptr };
     uint32_t m_converterInputBytesPerPacket { 0 };
 
     uint64_t m_timestamp { 0 };
index 9f16352..67b2414 100644 (file)
@@ -141,11 +141,11 @@ MediaTime AudioSampleDataSource::hostTime() const
     return MediaTime::createWithDouble(mach_absolute_time() * frequency);
 }
 
-void AudioSampleDataSource::pushSamplesInternal(AudioBufferList& bufferList, const MediaTime& presentationTime, size_t sampleCount)
+void AudioSampleDataSource::pushSamplesInternal(const AudioBufferList& bufferList, const MediaTime& presentationTime, size_t sampleCount)
 {
     ASSERT(m_lock.isHeld());
 
-    AudioBufferList* sampleBufferList;
+    const AudioBufferList* sampleBufferList;
     if (m_converter) {
         m_scratchBuffer->reset();
         OSStatus err = m_scratchBuffer->copyFrom(bufferList, m_converter);
@@ -197,7 +197,7 @@ void AudioSampleDataSource::pushSamples(const AudioStreamBasicDescription& sampl
     pushSamplesInternal(list, toMediaTime(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)), CMSampleBufferGetNumSamples(sampleBuffer));
 }
 
-void AudioSampleDataSource::pushSamples(const MediaTime& sampleTime, PlatformAudioData& audioData, size_t sampleCount)
+void AudioSampleDataSource::pushSamples(const MediaTime& sampleTime, const PlatformAudioData& audioData, size_t sampleCount)
 {
     std::unique_lock<Lock> lock(m_lock, std::try_to_lock);
     ASSERT(is<WebAudioBufferList>(audioData));
index 9ac3146..34d847d 100644 (file)
@@ -52,7 +52,7 @@ public:
     OSStatus setInputFormat(const CAAudioStreamDescription&);
     OSStatus setOutputFormat(const CAAudioStreamDescription&);
 
-    void pushSamples(const MediaTime&, PlatformAudioData&, size_t);
+    void pushSamples(const MediaTime&, const PlatformAudioData&, size_t);
     void pushSamples(const AudioStreamBasicDescription&, CMSampleBufferRef);
 
     enum PullMode { Copy, Mix };
@@ -73,7 +73,7 @@ protected:
     OSStatus setupConverter();
     bool pullSamplesInternal(AudioBufferList&, size_t&, uint64_t, double, PullMode);
 
-    void pushSamplesInternal(AudioBufferList&, const MediaTime&, size_t frameCount);
+    void pushSamplesInternal(const AudioBufferList&, const MediaTime&, size_t frameCount);
 
     std::unique_ptr<CAAudioStreamDescription> m_inputDescription;
     std::unique_ptr<CAAudioStreamDescription> m_outputDescription;
index 7a8d740..54860b7 100644 (file)
@@ -119,7 +119,7 @@ void RealtimeMediaSource::videoSampleAvailable(MediaSample& mediaSample)
         observer->videoSampleAvailable(mediaSample);
 }
 
-void RealtimeMediaSource::audioSamplesAvailable(const MediaTime& time, PlatformAudioData& audioData, const AudioStreamDescription& description, size_t numberOfFrames)
+void RealtimeMediaSource::audioSamplesAvailable(const MediaTime& time, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t numberOfFrames)
 {
     for (const auto& observer : m_observers)
         observer->audioSamplesAvailable(time, audioData, description, numberOfFrames);
index 154f828..139cbfd 100644 (file)
@@ -78,7 +78,7 @@ public:
         virtual void videoSampleAvailable(MediaSample&) { }
 
         // May be called on a background thread.
-        virtual void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t /*numberOfFrames*/) { }
+        virtual void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t /*numberOfFrames*/) { }
     };
 
     virtual ~RealtimeMediaSource() { }
@@ -110,7 +110,7 @@ public:
     virtual void settingsDidChange();
 
     void videoSampleAvailable(MediaSample&);
-    void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t);
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t);
     
     bool stopped() const { return m_stopped; }
 
index c804cf0..62e498e 100644 (file)
@@ -178,7 +178,7 @@ OSStatus AudioTrackPrivateMediaStreamCocoa::setupAudioUnit()
     return err;
 }
 
-void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& sampleTime, PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
+void AudioTrackPrivateMediaStreamCocoa::audioSamplesAvailable(const MediaTime& sampleTime, const PlatformAudioData& audioData, const AudioStreamDescription& description, size_t sampleCount)
 {
     ASSERT(description.platformDescription().type == PlatformDescription::CAAudioStreamBasicType);
 
index b6e7f41..cea030f 100644 (file)
@@ -66,7 +66,7 @@ private:
     void sourceMutedChanged()  final { }
     void sourceSettingsChanged() final { }
     bool preventSourceFromStopping() final { return false; }
-    void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     static OSStatus inputProc(void*, AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32 inBusNumber, UInt32 numberOfFrames, AudioBufferList*);
     OSStatus render(UInt32 sampleCount, AudioBufferList&, UInt32 inBusNumber, const AudioTimeStamp&, AudioUnitRenderActionFlags&);
index f1e9e99..2d1eeea 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace WebCore {
 
-void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t)
+void RealtimeOutgoingAudioSource::audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t)
 {
     notImplemented();
 }
index fe1410c..78ddf73 100644 (file)
@@ -66,7 +66,7 @@ private:
     void sourceMutedChanged() final { }
     void sourceSettingsChanged() final { }
     bool preventSourceFromStopping() final { return false; }
-    void audioSamplesAvailable(const MediaTime&, PlatformAudioData&, const AudioStreamDescription&, size_t) final;
+    void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final;
 
     void convertAndSendMonoSamples();
     void convertAndSendStereoSamples();