bug 1391482 add a method to create an AudioBuffer from AudioChunk data r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 16 Aug 2017 17:45:48 +1200
changeset 654567 aab2e830e91408b81a4ff079e2ede072696b68ec
parent 654566 108e46a68476c95af583b27e2030dd402dbe34bb
child 654568 282bbf97ce3ee98244f9fc16d5c18f24470e1a04
push id76601
push userktomlinson@mozilla.com
push dateMon, 28 Aug 2017 23:35:34 +0000
reviewerspadenot
bugs1391482
milestone57.0a1
bug 1391482 add a method to create an AudioBuffer from AudioChunk data r?padenot MozReview-Commit-ID: GkJJo6UW4gl
dom/media/webaudio/AudioBuffer.cpp
dom/media/webaudio/AudioBuffer.h
--- a/dom/media/webaudio/AudioBuffer.cpp
+++ b/dom/media/webaudio/AudioBuffer.cpp
@@ -243,16 +243,33 @@ AudioBuffer::Create(nsPIDOMWindowInner* 
   if (initialContents) {
     MOZ_ASSERT(initialContents->GetChannels() == aNumberOfChannels);
     buffer->SetSharedChannels(initialContents.forget());
   }
 
   return buffer.forget();
 }
 
+/* static */ already_AddRefed<AudioBuffer>
+AudioBuffer::Create(nsPIDOMWindowInner* aWindow, float aSampleRate,
+                    AudioChunk&& aInitialContents)
+{
+  AudioChunk initialContents = aInitialContents;
+  ErrorResult rv;
+  RefPtr<AudioBuffer> buffer =
+    new AudioBuffer(aWindow, initialContents.ChannelCount(),
+                    initialContents.mDuration, aSampleRate, rv);
+  if (rv.Failed()) {
+    return nullptr;
+  }
+  buffer->mSharedChannels = Move(aInitialContents);
+
+  return buffer.forget();
+}
+
 JSObject*
 AudioBuffer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return AudioBufferBinding::Wrap(aCx, this, aGivenProto);
 }
 
 bool
 AudioBuffer::RestoreJSChannelData(JSContext* aJSContext)
--- a/dom/media/webaudio/AudioBuffer.h
+++ b/dom/media/webaudio/AudioBuffer.h
@@ -49,16 +49,21 @@ public:
   Create(nsPIDOMWindowInner* aWindow, uint32_t aNumberOfChannels,
          uint32_t aLength, float aSampleRate,
          ErrorResult& aRv)
   {
     return Create(aWindow, aNumberOfChannels, aLength, aSampleRate,
                   nullptr, aRv);
   }
 
+  // Non-unit AudioChunk::mVolume is not supported
+  static already_AddRefed<AudioBuffer>
+  Create(nsPIDOMWindowInner* aWindow, float aSampleRate,
+         AudioChunk&& aInitialContents);
+
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioBuffer)
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioBuffer)
 
   static already_AddRefed<AudioBuffer>
   Constructor(const GlobalObject& aGlobal,
               const AudioBufferOptions& aOptions, ErrorResult& aRv);