Repository navigation
Add configurable buffer headroom to the FFmpeg STREAM consumer - #1837
dedicatedbroadcastsolutions wants to merge 1 commit into
Conversation
Keep realtime input admission bounded and nonblocking while allowing transient stalls to be absorbed before dropping combined video/audio frames. Preserve FILE behavior and expose throttled realtime overflow diagnostics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
Give the realtime FFmpeg
STREAMconsumer modest, configurable buffering to tolerate transient scheduling, encoding and output stalls without immediately discarding combined video/audio input.-frame-bufferand-packet-bufferAMCP options, and corresponding XML elements for<ffmpeg>consumers with<realtime>true</realtime>.FILEand non-realtime XML consumers retain their existing 64/128 queues and behavior; attempts to use the new overrides in these modes fail explicitly.Why
An operator reproduced monitoring-audio pops with a 1080i5994 channel feeding clean DeckLink SDI plus a dynamic FFmpeg consumer: 960×540 H.264, stereo Opus, MPEG-TS over multicast UDP. The pops were present in a locally captured multicast stream, before the downstream RTP/WebRTC pipeline.
Removing asynchronous audio timestamp correction did not resolve the problem. Switching only the consumer mode from
STREAMtoFILE, retaining the same UDP destination and encoding options, produced clean audio and acceptable delay in the operator's test.That result does not isolate buffering alone: realtime codec-threading behavior also changes between these modes. It does, however, motivate improving STREAM's very small transient headroom without changing codec behavior.
The existing input queue holds combined video/audio frames. When
try_push()fails, both video and its audio samples are discarded while video and audio timestamps advance. Packet-output backpressure can stall the encoding worker and fill this input queue. Regular output Opus timestamps therefore do not prove that upstream samples were never discarded.This PR does not claim that the on-site root cause is conclusively measured or that the new defaults guarantee lossless audio.
Design and scope
Keep the existing bounded FIFO architecture and nonblocking input admission. Do not block channel/SDI playout, split audio/video pipelines, change codec threading, alter GOP/repeated-header settings, or introduce UDP pacing.
Six queued inputs represent approximately 100 ms of media at 59.94 inputs/second, including fields for interlaced channels. This is queue capacity, not an imposed startup/playback delay; queues drain whenever downstream processing permits. Total latency also includes in-flight encoding, muxing and downstream buffering.
The 16-packet queue holds encoded AVPackets, not UDP datagrams, so its capacity is not a fixed duration. Both defaults are initial bounded headroom choices open to discussion.
Under sustained overload, queues still fill and arriving input is still dropped. Warnings and cumulative counters expose that loss; this is not an unlimited-backlog workaround.
Example
Prior art informing the approach
Verification
Completed on this upstream-based branch:
-Wall -Wextra -Werror.ffmpeg_consumer.cpptranslation-unit compilation against the available system dependencies.git diff --check.Tests cover STREAM/FILE defaults, independent overrides, case-insensitive AMCP names, stripping consumer options while preserving encoder options, invalid/missing/out-of-range values, non-realtime rejection, legacy 1/1 settings, six-input bursts and draining, bounded sustained overload, fractional 48 kHz/59.94 input timestamp/sample accounting, and encoded-packet backpressure/FIFO order.
These are configuration/queue-contract tests, not full consumer/codec integration tests.
This hasn't been tested yet as this should be discussed first.
Warning throttling, real consumer replacement/shutdown, actual audio continuity, A/V sync and latency still require integration/on-site validation. Follow-up acceptance should compare original 1/1 STREAM, buffered FILE-to-UDP and patched STREAM under controlled stalls and sustained load.
Should I remove the AI generated tests and make this just a minimal patch? The rational for this is patch is that a frame only being a fraction of a frame late followed by a slightly early frame can drop an entire frame. It was made configurable so that low latency tuning can be accomplished if desired.
Summary by CodeRabbit