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 654569 0c984b92020df877640edbc50483aa381f13022f
parent 654568 282bbf97ce3ee98244f9fc16d5c18f24470e1a04
child 654570 4fe6b16893e64b499d49896aae3784bb6bbd64af
push id76601
push userktomlinson@mozilla.com
push dateMon, 28 Aug 2017 23:35:34 +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)