From 49018e24b08903eb4a20e6068007b48970410fda Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 5 Oct 2022 14:15:37 +1300 Subject: [PATCH 1/3] Write silent audio frame samples --- src/domain/audio/InboundAudioStream.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/domain/audio/InboundAudioStream.ts b/src/domain/audio/InboundAudioStream.ts index 105c7829..83899f3a 100644 --- a/src/domain/audio/InboundAudioStream.ts +++ b/src/domain/audio/InboundAudioStream.ts @@ -39,9 +39,6 @@ class InboundAudioStream { #_selectedCodecName = ""; #_decoder = null; - // WEBRTC TODO: Remove when have logger with "once" function. - #_haveWarnedWriteDroppableSilentFrames = false; - /* eslint-disable */ // @ts-ignore @@ -127,12 +124,14 @@ class InboundAudioStream { #writeDroppableSilentFrames(silentFrames: number): void { // C++ int writeDroppableSilentFrames(int silentFrames) - // WEBRTC TODO: Address further C++ code. - if (!this.#_haveWarnedWriteDroppableSilentFrames) { - console.warn("InboundAudioStream.#writeDroppableSilentFrames() not implemented. Frames:", silentFrames); - this.#_haveWarnedWriteDroppableSilentFrames = true; - } + // WEBRTC TODO: Address further C++ code. Fade toward silence. + + // WEBRTC TODO: Address further C++ code. Only write as many silent frames as the AudioOutputProcessor's jitter buffer + // warrants. + // Write silent audio frames. + const silentBuffer = new Int16Array(silentFrames); // Is initialized to 0s. + this.#_audioOutput.writeData(silentBuffer); } #parseAudioData(packetData: DataView): number { From 7862aa69b0e3b76f4ba2b2b8fd3ede20b1f85a7c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 5 Oct 2022 14:16:27 +1300 Subject: [PATCH 2/3] Increase the audio output ring buffer size to match the native client --- src/domain/worklets/AudioOutputProcessor.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domain/worklets/AudioOutputProcessor.ts b/src/domain/worklets/AudioOutputProcessor.ts index ed6a292e..f8b6caac 100644 --- a/src/domain/worklets/AudioOutputProcessor.ts +++ b/src/domain/worklets/AudioOutputProcessor.ts @@ -28,10 +28,11 @@ class AudioOutputProcessor extends AudioWorkletProcessor { // Buffer blocks of audio data so that they can be played back smoothly. - // FIXME: All these fields should be private (#s) but Firefox is handling transpiled code with them (Sep 2021). + // FIXME: All these fields should be private (#s) but Firefox isn't handling transpiled code with them (Sep 2021). _audioBuffer: Int16Array[] = []; - readonly MAX_AUDIO_BUFFER_LENGTH = 16; // The maximum number of audio blocks to buffer. - readonly MIN_AUDIO_BUFFER_LENGTH = 4; // The minimum number of audio blocks to have before starting to play them. + // MAX_AUDIO_BUFFER_LENGTH = AudioClient.#RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES + readonly MAX_AUDIO_BUFFER_LENGTH = 100; // The maximum number of audio blocks to buffer + readonly MIN_AUDIO_BUFFER_LENGTH = 50; // The minimum number of audio blocks to have before starting to play them. _isPlaying = false; // Is playing audio blocks from the buffer. From 1dd9534576cf564d9ece86f6ab5ab4dbceb94110 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 5 Oct 2022 14:16:41 +1300 Subject: [PATCH 3/3] Tidying --- src/domain/worklets/AudioOutputProcessor.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/domain/worklets/AudioOutputProcessor.ts b/src/domain/worklets/AudioOutputProcessor.ts index f8b6caac..57575156 100644 --- a/src/domain/worklets/AudioOutputProcessor.ts +++ b/src/domain/worklets/AudioOutputProcessor.ts @@ -58,6 +58,7 @@ class AudioOutputProcessor extends AudioWorkletProcessor { // If we've reached the maximum buffer size, skip some of the audio blocks. if (this._audioBuffer.length > this.MAX_AUDIO_BUFFER_LENGTH) { + // console.log("AudioOutputProcessor: Overflowed", this.MAX_AUDIO_BUFFER_LENGTH); while (this._audioBuffer.length > this.MIN_AUDIO_BUFFER_LENGTH) { this._audioBuffer.shift(); } @@ -80,6 +81,8 @@ class AudioOutputProcessor extends AudioWorkletProcessor { * @param {Float32Array[][]} inputList - Input PCM audio samples. Not used. * @param {Float32Array[][]} outputList - Output PCM audio samples. * @param {Record} parameters - Processing parameters. Not used. + * @returns {boolean} true to keep the processor node alive, false to let the browser terminate + * the node. */ // eslint-disable-next-line // @ts-ignore