Skip to content

fix(audio): bound the audio queue by duration instead of packet count - #45

Open
code-new-bie wants to merge 1 commit into
shilapi:masterfrom
code-new-bie:pr/audio-queue-by-duration
Open

code-new-bie wants to merge 1 commit into
shilapi:masterfrom
code-new-bie:pr/audio-queue-by-duration

Conversation

@code-new-bie

Copy link
Copy Markdown

Each audio renderer creates its codec and AudioTrack before it reads its
queue, and that took about 1.2 s on a BYD head unit. The queue held 64
packets and dropped the newest when full. A wired LPCM packet holds about
7 ms of audio, so 64 packets covered under half a second and the rest of the
start-up audio was dropped: the beginning of every wired stream was cut.

The queue is now bounded by the audio it holds, 2 s, as jitter buffers such
as GStreamer's rtpjitterbuffer and WebRTC's NetEq are. When it is over budget
the oldest audio goes, so a stalled output catches up on the newest audio and
latency stays bounded. Packet durations come from the codec: LPCM from the
payload size, AAC-LC as 1024 frames, Opus from the TOC byte (RFC 6716,
section 3.1). Items without a duration are never dropped, and a cap of 2048
items guards against packets that report none.

AudioPacketQueueTest covers wired start-up audio fitting without drops, AAC,
dropping the oldest audio, a blocking take and the per-codec durations.

Each audio renderer creates its codec and AudioTrack before it reads its
queue, and that took about 1.2 s on a BYD head unit. The queue held 64
packets and dropped the newest when full. A wired LPCM packet holds about
7 ms of audio, so 64 packets covered under half a second and the rest of the
start-up audio was dropped: the beginning of every wired stream was cut.

The queue is now bounded by the audio it holds, 2 s, as jitter buffers such
as GStreamer's rtpjitterbuffer and WebRTC's NetEq are. When it is over budget
the oldest audio goes, so a stalled output catches up on the newest audio and
latency stays bounded. Packet durations come from the codec: LPCM from the
payload size, AAC-LC as 1024 frames, Opus from the TOC byte (RFC 6716,
section 3.1). Items without a duration are never dropped, and a cap of 2048
items guards against packets that report none.

AudioPacketQueueTest covers wired start-up audio fitting without drops, AAC,
dropping the oldest audio, a blocking take and the per-codec durations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant