Bug 1444102 [wpt PR 9925] - Set array length to 0 for disconnected worklet input, a=testonly
authorRaymond Toy <rtoy@chromium.org>
Mon, 09 Apr 2018 17:05:33 +0000
changeset 413549 df3a4f8111c6e6d5da55d4071d88ba2cbafbc3c2
parent 413548 a0bdb3af03c329185647d244ed1a69b7f4914110
child 413550 e025a58f144f0a423c5c1a565f40133635930a4c
push id33850
push userapavel@mozilla.com
push dateMon, 16 Apr 2018 09:53:48 +0000
treeherdermozilla-central@6276ec7ebbf3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1444102, 817145, 953970, 543506
milestone61.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 1444102 [wpt PR 9925] - Set array length to 0 for disconnected worklet input, a=testonly Automatic update from web-platform-testsSet array length to 0 for disconnected worklet input The spec says that if an input to an AudioWorkletNode is not connected, the input should be represented as an input with a single channel with a Float32Array of length 0. Make it so by passing in nullptr for that input to the AudioWorkletGlobalScope::Process so it can fill the arrays appropriately. Bug: 817145 Change-Id: I82407ed0a9fe84c5012333af8af27f4dd08d29b8 Reviewed-on: https://chromium-review.googlesource.com/953970 Reviewed-by: Hongchan Choi <hongchan@chromium.org> Commit-Queue: Raymond Toy <rtoy@chromium.org> Cr-Commit-Position: refs/heads/master@{#543506} wpt-commits: a2d57e78fca7c449c8419ef56870e834d9c50b18 wpt-pr: 9925 wpt-commits: a2d57e78fca7c449c8419ef56870e834d9c50b18 wpt-pr: 9925
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/input-length-processor.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -294894,16 +294894,21 @@
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/processors/gain-processor.js": [
     [
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audioworklet-interface/processors/input-length-processor.js": [
+    [
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-audioworklet-interface/processors/one-pole-processor.js": [
     [
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/processors/option-test-processor.js": [
     [
      {}
@@ -364908,16 +364913,22 @@
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-constructor-options.https.html": [
     [
      "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-constructor-options.https.html",
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html": [
+    [
+     "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html",
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-onerror.https.html": [
     [
      "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-onerror.https.html",
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletprocessor-options.https.html": [
     [
@@ -601723,16 +601734,20 @@
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-construction.https.html": [
    "b2513b4b5f37b906250b4e1f78eaec80bdc41ef6",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-constructor-options.https.html": [
    "99284ab790c09dd7a23a6fa5022e8b08b9e3947d",
    "testharness"
   ],
+  "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html": [
+   "bf3ebb3a403b24078b7e8c2ff7073dcbc486bb27",
+   "testharness"
+  ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-onerror.https.html": [
    "a1cd969fe32a5aca7cd90d0d0955132fd1660b9c",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletprocessor-options.https.html": [
    "b70c4e78f5b816a5af789660285ceb91f5dddbfa",
    "testharness"
   ],
@@ -601747,16 +601762,20 @@
   "webaudio/the-audio-api/the-audioworklet-interface/processors/error-processor.js": [
    "0859e9f7bbaf00853f85bbb0e2d6eb4db85578b3",
    "support"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/processors/gain-processor.js": [
    "1561b9eede1ee15126fdd9674a6d9d63194b66c2",
    "support"
   ],
+  "webaudio/the-audio-api/the-audioworklet-interface/processors/input-length-processor.js": [
+   "bd6e7a669a2c445ecfd3de4dd6b48a4d84b214cc",
+   "support"
+  ],
   "webaudio/the-audio-api/the-audioworklet-interface/processors/one-pole-processor.js": [
    "80b817db4e8d3f49e4f5fe6e97f8e687d16f3159",
    "support"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/processors/option-test-processor.js": [
    "c2f028c2be836cad2c38a71f96246f84c04323a5",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-disconnected-input.https.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      Test AudioWorkletNode's Disconnected Input Array Length
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+    <script src="/webaudio/resources/audit-util.js"></script>
+  </head>
+  <body>
+    <script id="layout-test-code">
+      let audit = Audit.createTaskRunner();
+
+      // Arbitrary numbers used to align the test with render quantum boundary.
+      // The sample rate is a power of two to eliminate roundoff in computing
+      // the suspend time needed for the test.
+      let sampleRate = 16384;
+      let renderLength = 8 * RENDER_QUANTUM_FRAMES;
+      let context;
+
+      let filePath = 'processors/input-length-processor.js';
+
+      let testChannelValues = [1, 2, 3];
+
+      // Creates a 3-channel buffer and play with BufferSourceNode. The source
+      // goes through a bypass AudioWorkletNode (gain value of 1).
+      audit.define(
+          {
+            label: 'test',
+            description:
+                'Input array length should be zero for disconnected input'
+          },
+          (task, should) => {
+            context = new OfflineAudioContext({
+              numberOfChannels: 1,
+              length: renderLength,
+              sampleRate: sampleRate
+            });
+
+            context.audioWorklet.addModule(filePath).then(() => {
+              let sourceNode = new ConstantSourceNode(context);
+              let workletNode =
+                  new AudioWorkletNode(context, 'input-length-processor');
+
+              workletNode.connect(context.destination);
+
+              // Connect the source now.
+              let connectFrame = RENDER_QUANTUM_FRAMES;
+
+              context.suspend(connectFrame / sampleRate)
+                  .then(() => {
+                    sourceNode.connect(workletNode);
+                  })
+                  .then(() => context.resume());
+              ;
+
+              // Then disconnect the source after a few renders
+              let disconnectFrame = 3 * RENDER_QUANTUM_FRAMES;
+              context.suspend(disconnectFrame / sampleRate)
+                  .then(() => {
+                    sourceNode.disconnect(workletNode);
+                  })
+                  .then(() => context.resume());
+
+              sourceNode.start();
+              context.startRendering()
+                  .then(resultBuffer => {
+                    let data = resultBuffer.getChannelData(0);
+
+                    should(
+                        data.slice(0, connectFrame),
+                        'Before connecting the source: Input array length')
+                        .beConstantValueOf(0);
+
+                    // Find where the output is no longer 0.
+                    let nonZeroIndex = data.findIndex(x => x > 0);
+                    should(nonZeroIndex, 'First non-zero output')
+                        .beEqualTo(connectFrame);
+
+                    should(
+                        data.slice(
+                            nonZeroIndex,
+                            nonZeroIndex + (disconnectFrame - connectFrame)),
+                        'While source is connected: Input array length')
+                        .beConstantValueOf(RENDER_QUANTUM_FRAMES);
+                    should(
+                        data.slice(disconnectFrame),
+                        'After disconnecting the source: Input array length')
+                        .beConstantValueOf(0);
+                  })
+                  .then(() => task.done());
+            });
+          });
+
+      audit.run();
+    </script>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/input-length-processor.js
@@ -0,0 +1,25 @@
+/**
+ * @class InputLengthProcessor
+ * @extends AudioWorkletProcessor
+ *
+ * This processor class just sets the output to the length of the
+ * input array for verifying that the input length changes when the
+ * input is disconnected.
+ */
+class InputLengthProcessor extends AudioWorkletProcessor {
+  constructor() {
+    super();
+  }
+
+  process(inputs, outputs, parameters) {
+    let input = inputs[0];
+    let output = outputs[0];
+
+    // Set output channel to the length of the input channel array.
+    output[0].fill(input[0].length);
+
+    return true;
+  }
+}
+
+registerProcessor('input-length-processor', InputLengthProcessor);