[Webkit-unassigned] [Bug 253952] New: AudioContext will play with 20ms callback only a MediaStream and AudioWorkletNode in graph

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Mar 15 02:50:31 PDT 2023


https://bugs.webkit.org/show_bug.cgi?id=253952

            Bug ID: 253952
           Summary: AudioContext will play with 20ms callback only a
                    MediaStream and AudioWorkletNode in graph
           Product: WebKit
           Version: Safari 16
          Hardware: All
                OS: All
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Web Audio
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: wangweisi.night12138 at bytedance.com
                CC: cdumez at apple.com

Created attachment 465444

  --> https://bugs.webkit.org/attachment.cgi?id=465444&action=review

reproduction

tiny example:
index.html
```html
<!DOCTYPE html>
<html>
<script type="application/javascript">
    class MyAudioNode extends AudioWorkletNode {
        constructor(ctx) {
            super(ctx, "my-worklet-processor");
        }
    }
    (async () => {
        const ctx = new AudioContext();
        await ctx.audioWorklet.addModule('bypass.worklet.js');
        const node = new MyAudioNode(ctx);
        const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
        const source = ctx.createMediaStreamSource(stream);
        source.connect(node).connect(ctx.destination);
        ctx.resume();
    })();
</script>

</html>
```
bypass.worklet.js
```js
class MyWorkletProcessor extends AudioWorkletProcessor {
    constructor() {
        super();
    }

    process(inputs, outputs) {
        // Use the 1st input and output only to make the example simpler. |input|
        // and |output| here have the similar structure with the AudioBuffer
        // interface. (i.e. An array of Float32Array)
        const input = inputs[0];
        if (!(input?.length)) return true;
        const output = outputs[0];
        if (!(output?.length)) return true;

        // Copy-in, process and copy-out.
        output.forEach((e, i) => e.set(input[i % input.length]));
        return true;
    }
}

registerProcessor("my-worklet-processor", MyWorkletProcessor);


```

bug occurs in code `Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm:168`
```cpp
    size_t bufferSize = m_defaultBufferSize;
    if (webAudioCount)
        bufferSize = AudioUtilities::renderQuantumSize;
    else if (captureCount || audioMediaStreamTrackCount) {
        // In case of audio capture or audio MediaStreamTrack playing, we want to grab 20 ms chunks to limit the latency so that it is not noticeable by users
        // while having a large enough buffer so that the audio rendering remains stable, hence a computation based on sample rate.
        bufferSize = WTF::roundUpToPowerOfTwo(AudioSession::sharedSession().sampleRate() / 50);
    } else if (m_supportedAudioHardwareBufferSizes && DeprecatedGlobalSettings::lowPowerVideoAudioBufferSizeEnabled())
        bufferSize = m_supportedAudioHardwareBufferSizes.nearest(kLowPowerVideoBufferSize);

    AudioSession::sharedSession().setPreferredBufferSize(bufferSize);
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230315/c40c0ef5/attachment-0001.htm>


More information about the webkit-unassigned mailing list