Bug 1454516 [wpt PR 10496] - Apply automatic pull for AudioWorkletNode with zero output, a=testonly
authorHongchan Choi <hongchan@chromium.org>
Wed, 25 Apr 2018 18:52:09 +0000
changeset 415797 05b0bfc555a70a49b3f0f0b449b255bfecf3d537
parent 415796 ffe9f0a023b594c40b248629efce8ea575e8cf9e
child 415798 45c701d6c5ed61b434a7064fba9f1d41d10b5daf
push id33910
push usershindli@mozilla.com
push dateThu, 26 Apr 2018 21:39:52 +0000
treeherdermozilla-central@63a0e2f626fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1454516, 10496, 831245, 1014388, 551210
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 1454516 [wpt PR 10496] - Apply automatic pull for AudioWorkletNode with zero output, a=testonly Automatic update from web-platform-testsApply automatic pull for AudioWorkletNode with zero output Spec: https://webaudio.github.io/web-audio-api/#rendering-loop (Step 9.5) The AudioWorkletNode with zero output must be pulled by the renderer. The actual output will be ignored just like AnalyserNode. Bug: 831245 Test: LayoutTests/external/wpt/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html Change-Id: If9bd27d6c4bfeecdcd2dd4c8445459afd8593e85 Reviewed-on: https://chromium-review.googlesource.com/1014388 Reviewed-by: Raymond Toy <rtoy@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/master@{#551210} -- wpt-commits: 7eed33a59decf3541af0b014968008e2c55a9f92 wpt-pr: 10496
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html
testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/zero-output-processor.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -296405,16 +296405,21 @@
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/processors/timing-info-processor.js": [
     [
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audioworklet-interface/processors/zero-output-processor.js": [
+    [
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-biquadfilternode-interface/.gitkeep": [
     [
      {}
     ]
    ],
    "webaudio/the-audio-api/the-channelmergernode-interface/.gitkeep": [
     [
      {}
@@ -368146,16 +368151,22 @@
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-timing-info.https.html": [
     [
      "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-timing-info.https.html",
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html": [
+    [
+     "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html",
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-channel-count.https.html": [
     [
      "/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-channel-count.https.html",
      {}
     ]
    ],
    "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-construction.https.html": [
     [
@@ -606929,16 +606940,20 @@
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-sample-rate.https.html": [
    "8228071abd6c36908a8b31372185dc0f2dfcdd0a",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletglobalscope-timing-info.https.html": [
    "ef7c004225bbb5e6d289a990191b22e2faeabcf3",
    "testharness"
   ],
+  "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html": [
+   "73d5c524d03cd7ed255056b0d26e0aff5154b740",
+   "testharness"
+  ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-channel-count.https.html": [
    "b6701142fd660a6a29fbfc68cb530b70817b3a44",
    "testharness"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-construction.https.html": [
    "b2513b4b5f37b906250b4e1f78eaec80bdc41ef6",
    "testharness"
   ],
@@ -606989,16 +607004,20 @@
   "webaudio/the-audio-api/the-audioworklet-interface/processors/port-processor.js": [
    "47092e4372a196e47612388602b6a3876deb653a",
    "support"
   ],
   "webaudio/the-audio-api/the-audioworklet-interface/processors/timing-info-processor.js": [
    "c93a76f097b441aaec052516256cc922089b4b75",
    "support"
   ],
+  "webaudio/the-audio-api/the-audioworklet-interface/processors/zero-output-processor.js": [
+   "72f40b24f52098bb8b3a63c0865e6b81cefc2de3",
+   "support"
+  ],
   "webaudio/the-audio-api/the-biquadfilternode-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
   "webaudio/the-audio-api/the-channelmergernode-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworkletnode-automatic-pull.https.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      Test AudioWorkletNode's automatic pull feature
+    </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">
+      const audit = Audit.createTaskRunner();
+
+      // Arbitrary sample rate. Anything should work.
+      const sampleRate = 48000;
+      const renderLength = RENDER_QUANTUM_FRAMES * 2;
+      const channelCount = 1;
+      const filePath = 'processors/zero-output-processor.js';
+
+      const sourceOffset = 0.5;
+
+      // Connect a constant source node to the zero-output AudioWorkletNode.
+      // Then verify if it captures the data correctly.
+      audit.define('setup-worklet', (task, should) => {
+        const context =
+            new OfflineAudioContext(channelCount, renderLength, sampleRate);
+
+        context.audioWorklet.addModule(filePath).then(() => {
+          let testSource =
+              new ConstantSourceNode(context, { offset: sourceOffset });
+          let zeroOutputWorkletNode =
+              new AudioWorkletNode(context, 'zero-output-processor', {
+                numberOfInputs: 1,
+                numberOfOutputs: 0,
+                processorOptions: {
+                  bufferLength: renderLength,
+                  channeCount: channelCount
+                }
+              });
+
+          // Start the source and stop at the first render quantum.
+          testSource.connect(zeroOutputWorkletNode);
+          testSource.start();
+          testSource.stop(RENDER_QUANTUM_FRAMES/sampleRate);
+
+          zeroOutputWorkletNode.port.onmessage = (event) => {
+            // The |capturedBuffer| can be multichannel. Iterate through it.
+            for (let i = 0; i < event.data.capturedBuffer.length; ++i) {
+              let buffer = event.data.capturedBuffer[i];
+              // Split the captured buffer in half for the easier test.
+              should(buffer.subarray(0, RENDER_QUANTUM_FRAMES),
+                     'The first half of the captured buffer')
+                  .beConstantValueOf(sourceOffset);
+              should(buffer.subarray(RENDER_QUANTUM_FRAMES, renderLength),
+                     'The second half of the captured buffer')
+                  .beConstantValueOf(0);
+            }
+            task.done();
+          };
+
+          // Starts the rendering, but we don't need the rendered buffer from
+          // the context.
+          context.startRendering();
+        });
+      });
+
+      audit.run();
+    </script>
+  </body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/processors/zero-output-processor.js
@@ -0,0 +1,42 @@
+/**
+ * @class ZeroOutputProcessor
+ * @extends AudioWorkletProcessor
+ *
+ * This processor accumulates the incoming buffer and send the buffered data
+ * to the main thread when it reaches the specified frame length. The processor
+ * only supports the single input.
+ */
+
+const kRenderQuantumFrames = 128;
+
+class ZeroOuttputProcessor extends AudioWorkletProcessor {
+  constructor(options) {
+    super();
+
+    this._framesRequested = options.processorOptions.bufferLength;
+    this._framesCaptured = 0;
+    this._buffer = [];
+    for (let i = 0; i < options.processorOptions.channeCount; ++i) {
+      this._buffer[i] = new Float32Array(this._framesRequested);
+    }
+  }
+
+  process(inputs) {
+    let input = inputs[0];
+    let startIndex = this._framesCaptured;
+    let endIndex = startIndex + kRenderQuantumFrames;
+    for (let i = 0; i < this._buffer.length; ++i) {
+      this._buffer[i].subarray(startIndex, endIndex).set(input[i]);
+    }
+    this._framesCaptured = endIndex;
+
+    if (this._framesCaptured >= this._framesRequested) {
+      this.port.postMessage({ capturedBuffer: this._buffer });
+      return false;
+    } else {
+      return true;
+    }
+  }
+}
+
+registerProcessor('zero-output-processor', ZeroOuttputProcessor);