MediaClient: keyframe gating (startup + corruption re-arm), libyuv NV12 path

Restores the previously shelved decoder/player hardening and extends it:

1. Startup keyframe gating (video_decoder): after (re)start the decoder
   joins the stream mid-GOP; frames referencing unseen pictures render as
   green/blocky concealment garbage. Drop everything until the first IDR
   (300-frame safety valve so unmarked streams can't blank forever).

2. NEW - corruption re-arm: on lossy links (Wi-Fi cameras) dropped slices
   surface as "First slice in a frame missing" / "Could not find ref with
   POC n" and FFmpeg marks the output via AVFrame::decode_error_flags.
   Re-arm the keyframe gate and drop the rest of the GOP so the display
   holds the last clean frame instead of showing concealment artifacts;
   corrupt drops count toward the safety valve.

3. libyuv NV12->BGR conversion (video_player): honors NVDEC/D3D11VA padded
   strides (1080->1088 rows) that cv::cvtColorTwoPlane mishandled (green
   cast + striped noise), picks BT.601/709/2020 coefficients from the
   frame's signalled colorspace, and is ~3-5x faster than sws_scale.

Verified live against an RTSP HEVC camera (NVDEC path): steady frame flow,
no regressions on the clean-stream path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 21:49:22 +10:00
co-authored by Claude Fable 5
parent 044fedd344
commit 6344062179
4 changed files with 173 additions and 3 deletions
+8
View File
@@ -165,6 +165,14 @@ private:
std::atomic<BOOL> m_bRunning;
BOOL m_bHardwareDecoderEnabled; // Track if hardware decoder is enabled
bool m_bCudaHWAccel; // true when using AV_HWDEVICE_TYPE_CUDA
// Startup keyframe gating. On connect/reconnect we join the stream mid-GOP,
// before the first IDR, so early frames reference data we never received and
// the decoder conceals them (green / blocky macroblocks). We drop everything
// until the first keyframe (clean reference point), then deliver normally.
// The frame counter is a safety valve so a stream that never advertises a
// keyframe can't blank the display forever.
std::atomic<bool> m_bWaitKeyframe{ true }; // true until first IDR after (re)start
int m_nKeyframeWaitCount{ 0 }; // frames dropped while waiting
int m_hwGpuIndex; // GPU index assigned by HWDecoderPool (-1 = legacy)
AVFrame* m_pCudaHWFrame; // Cloned CUDA HW frame (device ptrs) for inference
const AVCodec* m_pCodec;