Skip to content

Replay from a key frame after VideoToolbox send fallback - #90

Closed
Blackspirits wants to merge 1 commit into
upl/review-base-f67bfrom
fix/videotoolbox-send-fallback-replay-f67b
Closed

Replay from a key frame after VideoToolbox send fallback#90
Blackspirits wants to merge 1 commit into
upl/review-base-f67bfrom
fix/videotoolbox-send-fallback-replay-f67b

Conversation

@Blackspirits

@Blackspirits Blackspirits commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Summary

The new VideoToolbox decoder fallback handles two classes of hardware failure differently.

When avcodec_receive_frame or av_hwframe_transfer_data fails, the player reopens the decoder in software and calls Seek(Position), which gives the demuxer a new serial, seeks backward, flushes packet/frame queues and replays from a key frame.

When avcodec_send_packet fails, however, the code reopens the decoder in software, sets only the video loop's local serial = -1, frees the rejected packet and continues with the next already-demuxed packet. A fresh software decoder can therefore start in the middle of a GOP without the reference frames required by that packet.

This change makes the send-packet failure path use the same recovery contract as the other VideoToolbox failures:

  • reopen in software;
  • invalidate the local decoder serial;
  • call Seek(Position) so demux replays from a key frame.

Validation

  • based on upstream f67b07f5b143fa47c87255ca1c3ed7adb3bd7142
  • diff is limited to FfmpegPlayer.cs
  • control flow verified against PerformSeek: it calls av_seek_frame(..., AVSEEK_FLAG_BACKWARD), advances the serial and flushes video/audio/frame queues
  • the existing receive/transfer fallback already uses the same replay sequence
  • macOS VideoToolbox failure injection is not available in the Linux CI environment
  • full solution restore passed
  • full solution build passed
  • full solution test suite passed on the first run
  • UI suite: 5,150 passed, 9 skipped, 0 failed (5,159 total)
  • retry step was not used
  • validation run: #34771533047

AI assistance: ChatGPT was used to adversarially review the newly merged VideoToolbox fallback paths and identify the missing demux replay after a hardware avcodec_send_packet failure.

@Blackspirits Blackspirits left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent adversarial re-check: the send-packet hardware-failure path had diverged from the receive/transfer fallback after the rejected packet was already freed. The final diff restores the same replay contract by seeking from the current position after reopening software decoding. Full CI #34771533047 passed restore, build and the complete suite on the first run; UITests reported 5,150 passed, 9 skipped and 0 failed. macOS VideoToolbox failure injection is not exercised by Linux CI, but the control-flow defect is deterministic from the packet lifetime and existing fallback contract. No blocker identified. Keep draft; no merge performed.

Copy link
Copy Markdown
Owner Author

Superseded by current-base draft PR #93. Upstream generalized the hardware path to D3D11VA/DXVA2 after this draft; #93 reapplies the same reviewed replay fix on c77c4b4 and has full green CI. Closing the older VideoToolbox-base draft to avoid competing fixes; no merge performed.

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