Repository navigation
fix(linux): keep VA-API streams alive through decode errors and stale backlogs - #1415
TheWeaklessOne wants to merge 4 commits into
Conversation
… backlogs A picture the hardware failed to decode reached the session as a generic backend error. Map it to ReferenceLost, in decode and in DMA-BUF export. Overflow recovery reopened the decoder, which takes long enough for the queue to overflow again. Decoders that can flush in place now do that (FFmpeg VA-API: avcodec_flush_buffers). A backlog that does not drain only adds latency, so 12 or more encoded frames still queued after 250 ms are dropped and a keyframe is requested. The embedded Linux queue grows to 24 frames, 200 ms at 120 fps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39768b694a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| commands | ||
| .remove_where(|queued| matches!(queued, VideoCommand::Decode { .. })); | ||
| need_keyframe = true; |
There was a problem hiding this comment.
Keep the keyframe gate closed after a stale-backlog drop
When a stale backlog is dropped on MediaCodec or the polled H.264 V4L2 path, the decoder can still have pre-drop output pending. The next poll_decoder() can return that output, which clears need_keyframe in the success handler at lines 773–775. Because this path neither resets the decoder nor sets the producer-side video_needs_keyframe gate, subsequent deltas are then decoded despite depending on the access units just removed, causing corruption or another reference-loss recovery before a recovery keyframe arrives. Keep admission gated until a recovery keyframe, and reset or otherwise isolate pending output from the previous chain.
AGENTS.md reference: AGENTS.md:L152-L154
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, polled output could reopen the gate. Fixed in 443f90d: need_keyframe now clears only when a submitted frame was decoded, and the gate only lets a keyframe through while it is set. Pending output from before the drop can still be shown, since it was decoded from valid references, but it no longer lets the following deltas in.
MediaCodec and polled H.264 V4L2 can still hold output from before a stale backlog was dropped. Polling it cleared need_keyframe, so the deltas that follow were decoded without the frames just removed. Only a submitted frame opens the gate now; startup and recovery already pass a keyframe through it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Follow-up in 443f90d for the review comment above. No new test: the gate sits inside |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 443f90d06b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let now = Instant::now(); | ||
| let since = *backlog_since.get_or_insert(now); | ||
| if now.duration_since(since) >= STALE_BACKLOG { |
There was a problem hiding this comment.
Reset the backlog timer when decoder recovery starts
If reference-loss recovery or reconfiguration occurs while backlog_since is set, that timestamp survives the decoder restart and any wait for a new keyframe. After a recovery lasting at least 250 ms, a fresh keyframe with 12 newly queued access units behind it immediately satisfies this comparison, discarding the new prediction chain and closing the keyframe gate again even though the new backlog has existed only briefly. This produces an unnecessary second freeze and keyframe request immediately after successful recovery. Clear the timer at decoder recovery and generation boundaries before measuring the new backlog.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. Fixed in f7cdbe2: every recovery ends with need_keyframe set, so the worker clears backlog_since for as long as that wait lasts. A new backlog is measured from the keyframe that ends it.
| commands | ||
| .remove_where(|queued| matches!(queued, VideoCommand::Decode { .. })); | ||
| need_keyframe = true; | ||
| emit(&events, BackendEvent::QueueOverflow { media: "video" }); |
There was a problem hiding this comment.
Propagate the actual number of stale frames dropped
When this path clears a 12–24-frame backlog, it ignores the count returned by remove_where and emits only one QueueOverflow. The embedded Linux monitor in media.rs:3626–3629 converts that event into MediaFeedback::QueueDropped { count: 1 }, and queue_drops.rs:54–72 reports video counts as frames. Consequently, recovery diagnostics report one dropped frame when a dozen or more were discarded, systematically understating the cost of this new recovery mechanism. Propagate the actual removed count into the feedback.
AGENTS.md reference: AGENTS.md:L152-L152
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. Fixed in f7cdbe2: BackendEvent::QueueOverflow now carries count, this path passes what remove_where returned, and both media.rs monitors forward it to MediaFeedback::QueueDropped. The other overflow paths drop one item and report 1.
…d frames The stale-backlog timer survived decoder recovery, so the first keyframe after a long recovery could be dropped right away with the backlog behind it. Clear it while waiting for a keyframe. QueueOverflow reported one frame for a whole dropped backlog. Carry the real count through to MediaFeedback::QueueDropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Second follow-up in f7cdbe2 for the two comments above. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7cdbe24ff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if now.duration_since(since) >= STALE_BACKLOG { | ||
| backlog_since = None; | ||
| let dropped = commands | ||
| .remove_where(|queued| matches!(queued, VideoCommand::Decode { .. })); |
There was a problem hiding this comment.
Preserve recovery frames queued by a newer generation
With a running backlog timer, an encoded-queue overflow can queue a reset: true keyframe and newer-generation deltas while the old frame is still decoding. If at least 12 new commands are waiting when that call returns and the old timer has expired, this predicate removes the recovery keyframe and its fresh prediction chain before their generation is processed. A blocked-decoder harness reproduces all 13 new-generation commands being dropped before keyframe submission, forcing another keyframe wait. Restrict stale removal to the measured generation, or preserve a queued newer-generation recovery.
AGENTS.md reference: AGENTS.md:L152-L154
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. Fixed in 81366ae: drop_stale_backlog() removes only the generation being decoded and keeps anything newer. If a newer generation's keyframe is already queued, the worker also skips the extra keyframe request, since that recovery is on its way. stale_backlog_drop_keeps_a_newer_generation_recovery covers the queue side. The worker path itself still has no test, because run_video_worker can't take a fake decoder.
A queue overflow can put a keyframe with reset set and a newer generation behind the frames still being measured. Dropping every Decode removed that recovery too and forced another keyframe wait. Drop only the generation in progress, and skip the keyframe request when a recovery is already queued. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Third follow-up in 81366ae. |
|
Folded into #1470 together with the other Linux decode fixes, rebased on |
Three problems with hardware decoding through FFmpeg's VA-API path on Linux, seen on an Odin 2 Portal (Qualcomm iris through the msm VA driver) at high bitrates:
EIOfrom a failedvaEndPicture/vaSyncSurface, orInvalidData). That made the session treat a recoverable picture as a dead decoder.Changes:
vaapi_picture_errormaps those errors toError::ReferenceLost, in decode and in DMA-BUF export (mapping syncs the surface, so a failed picture can surface there).VideoDecoder::reset_in_place(defaultfalse).FfmpegDecoderimplements it for VA-API withavcodec_flush_buffers, and the overflow path uses it instead of reopening when it is available. Decode errors still go throughReferenceLostand a full reopen.run_video_workerdrops a backlog of 12 or more encoded frames that has not drained for 250 ms, then requests a keyframe, as an overflow would (BACKLOG_FRAMES,STALE_BACKLOG,BoundedQueue::remove_where).This pairs with #1414, which keeps the keyframe request working after a recovery. Either can merge first.
Verification:
vaapi_picture_errors_are_recoverable_and_others_are_notandremove_where_keeps_the_other_items_in_order.cargo test --release -p opennow-streamer-platform-linux --features ffmpeg-bundled,vaapi(the features the app build uses) on cleandevwith this change: 254 passed, against 252 on cleandev. The one failure,fixed_audio_output_never_falls_back_and_stays_isolated, also fails on cleandevon that device (ALSA device enumeration returns -2).Not tested: a real iris decode error, which I could not trigger on purpose, so the
ReferenceLostmapping is covered by the unit test only. Other VA-API drivers were not tested.🤖 Generated with Claude Code