Bug 1388591 - Implement OfflineAudioCanvas dict constructor; r=padenot,smaug
authorThomas Wisniewski <wisniewskit@gmail.com>
Tue, 08 Aug 2017 22:55:43 -0400
changeset 373678 654d5ec3370c2447f8cedaefa2502923102bbeaa
parent 373677 c4376773f9cd977c8c450f71ae33e937ed4fd026
child 373679 5f9f6cb40071bf8e4a0caa9a83334eb09b6fb6c3
push id32308
push userarchaeopteryx@coole-files.de
push dateThu, 10 Aug 2017 15:20:33 +0000
treeherdermozilla-central@5322c03f4c85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, smaug
bugs1388591
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1388591 - Implement OfflineAudioCanvas dict constructor; r=padenot,smaug MozReview-Commit-ID: F9h9JO5tYeU
dom/media/webaudio/AudioContext.cpp
dom/media/webaudio/AudioContext.h
dom/media/webaudio/test/test_OfflineAudioContext.html
dom/webidl/OfflineAudioContext.webidl
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -216,16 +216,28 @@ AudioContext::Constructor(const GlobalOb
 
   RegisterWeakMemoryReporter(object);
 
   return object.forget();
 }
 
 /* static */ already_AddRefed<AudioContext>
 AudioContext::Constructor(const GlobalObject& aGlobal,
+                          const OfflineAudioContextOptions& aOptions,
+                          ErrorResult& aRv)
+{
+  return Constructor(aGlobal,
+                     aOptions.mNumberOfChannels,
+                     aOptions.mLength,
+                     aOptions.mSampleRate,
+                     aRv);
+}
+
+/* static */ already_AddRefed<AudioContext>
+AudioContext::Constructor(const GlobalObject& aGlobal,
                           uint32_t aNumberOfChannels,
                           uint32_t aLength,
                           float aSampleRate,
                           ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
   if (!window) {
     aRv.Throw(NS_ERROR_FAILURE);
--- a/dom/media/webaudio/AudioContext.h
+++ b/dom/media/webaudio/AudioContext.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef AudioContext_h_
 #define AudioContext_h_
 
 #include "mozilla/dom/AudioChannelBinding.h"
+#include "mozilla/dom/OfflineAudioContextBinding.h"
 #include "MediaBufferDecoder.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/UniquePtr.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
@@ -149,16 +150,22 @@ public:
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   using DOMEventTargetHelper::DispatchTrustedEvent;
 
   // Constructor for regular AudioContext
   static already_AddRefed<AudioContext>
   Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
 
+  // Constructor for offline AudioContext with options object
+  static already_AddRefed<AudioContext>
+  Constructor(const GlobalObject& aGlobal,
+              const OfflineAudioContextOptions& aOptions,
+              ErrorResult& aRv);
+
   // Constructor for offline AudioContext
   static already_AddRefed<AudioContext>
   Constructor(const GlobalObject& aGlobal,
               uint32_t aNumberOfChannels,
               uint32_t aLength,
               float aSampleRate,
               ErrorResult& aRv);
 
--- a/dom/media/webaudio/test/test_OfflineAudioContext.html
+++ b/dom/media/webaudio/test/test_OfflineAudioContext.html
@@ -26,43 +26,63 @@ function setOrCompareRenderedBuffer(aRen
     finish();
   } else {
     renderedBuffer = aRenderedBuffer;
   }
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
-  var ctx = new OfflineAudioContext(2, 100, 22050);
-  ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
-  is(ctx.length, 100, "OfflineAudioContext.length is equal to the value passed to the ctor.");
+  let ctxs = [
+    new OfflineAudioContext(2, 100, 22050),
+    new OfflineAudioContext({length: 100, sampleRate: 22050}),
+    new OfflineAudioContext({channels: 2, length: 100, sampleRate: 22050}),
+  ];
 
-  var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
-  for (var i = 0; i < 2; ++i) {
-    for (var j = 0; j < 100; ++j) {
-      buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate);
+  for (let ctx of ctxs) {
+    ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
+    is(ctx.length, 100, "OfflineAudioContext.length is equal to the value passed to the ctor.");
+
+    var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
+    for (var i = 0; i < 2; ++i) {
+      for (var j = 0; j < 100; ++j) {
+        buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate);
+      }
     }
   }
 
+  is(ctxs[1].destination.channelCount, 1, "OfflineAudioContext defaults to to correct channelCount.");
+
+  let ctx = ctxs[0];
+
   expectException(function() {
     new OfflineAudioContext(2, 100, 0);
   }, DOMException.NOT_SUPPORTED_ERR);
   expectException(function() {
     new OfflineAudioContext(2, 100, -1);
   }, DOMException.NOT_SUPPORTED_ERR);
   expectException(function() {
     new OfflineAudioContext(0, 100, 44100);
   }, DOMException.NOT_SUPPORTED_ERR);
   new OfflineAudioContext(32, 100, 44100);
   expectException(function() {
     new OfflineAudioContext(33, 100, 44100);
   }, DOMException.NOT_SUPPORTED_ERR);
   expectException(function() {
     new OfflineAudioContext(2, 0, 44100);
   }, DOMException.NOT_SUPPORTED_ERR);
+  expectTypeError(function() {
+    new OfflineAudioContext({});
+  });
+  expectTypeError(function() {
+    new OfflineAudioContext({sampleRate: 44100});
+  });
+  expectTypeError(function() {
+    new OfflineAudioContext({length: 44100*40});
+  });
 
   var src = ctx.createBufferSource();
   src.buffer = buf;
   src.start(0);
   src.connect(ctx.destination);
 
   ctx.addEventListener("complete", function(e) {
     ok(e instanceof OfflineAudioCompletionEvent, "Correct event received");
--- a/dom/webidl/OfflineAudioContext.webidl
+++ b/dom/webidl/OfflineAudioContext.webidl
@@ -5,17 +5,24 @@
  *
  * The origin of this IDL file is
  * https://webaudio.github.io/web-audio-api/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
-[Constructor(unsigned long numberOfChannels, unsigned long length, float sampleRate),
+dictionary OfflineAudioContextOptions {
+             unsigned long numberOfChannels = 1;
+    required unsigned long length;
+    required float         sampleRate;
+};
+
+[Constructor (OfflineAudioContextOptions contextOptions),
+Constructor(unsigned long numberOfChannels, unsigned long length, float sampleRate),
 Pref="dom.webaudio.enabled"]
 interface OfflineAudioContext : BaseAudioContext {
 
     [Throws]
     Promise<AudioBuffer> startRendering();
 
     // TODO: Promise<void>        suspend (double suspendTime);