bug 1391482 permit AudioChunk channel data initialization when mBuffer is not shared r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 16 Aug 2017 18:37:30 +1200
changeset 654731 6f22ae465560f477b6eafcb02cb1a61863590e99
parent 654730 82a48da01dfd741fa2c15d43cef582cfa8f02572
child 654732 1f4e95b5ef0fcb10d3aed6ca023ee630882dd29c
push id76658
push userktomlinson@mozilla.com
push dateTue, 29 Aug 2017 06:20:42 +0000
reviewerspadenot
bugs1391482
milestone57.0a1
bug 1391482 permit AudioChunk channel data initialization when mBuffer is not shared r?padenot MozReview-Commit-ID: AZ30fTVHHce
dom/media/AudioSegment.h
--- a/dom/media/AudioSegment.h
+++ b/dom/media/AudioSegment.h
@@ -228,16 +228,28 @@ struct AudioChunk {
   template<typename T>
   const nsTArray<const T*>& ChannelData() const
   {
     MOZ_ASSERT(AudioSampleTypeToFormat<T>::Format == mBufferFormat);
     return *reinterpret_cast<const AutoTArray<const T*,GUESS_AUDIO_CHANNELS>*>
       (&mChannelData);
   }
 
+  /**
+   * ChannelFloatsForWrite() should be used only when mBuffer is owned solely
+   * by the calling thread.
+   */
+  template<typename T>
+  T* ChannelDataForWrite(size_t aChannel)
+  {
+    MOZ_ASSERT(AudioSampleTypeToFormat<T>::Format == mBufferFormat);
+    MOZ_ASSERT(!mBuffer->IsShared());
+    return static_cast<T*>(const_cast<void*>(mChannelData[aChannel]));
+  }
+
   PrincipalHandle GetPrincipalHandle() const { return mPrincipalHandle; }
 
   StreamTime mDuration; // in frames within the buffer
   RefPtr<ThreadSharedObject> mBuffer; // the buffer object whose lifetime is managed; null means data is all zeroes
   // one pointer per channel; empty if and only if mBuffer is null
   AutoTArray<const void*,GUESS_AUDIO_CHANNELS> mChannelData;
   float mVolume; // volume multiplier to apply (1.0f if mBuffer is nonnull)
   SampleFormat mBufferFormat; // format of frames in mBuffer (only meaningful if mBuffer is nonnull)