log_print writes to the sys_log file (unopened in unit tests / field
debugging), so the gate looked inert next to FFmpeg's stderr error lines.
Emit arm/release one-liners to stderr alongside them.
Live verification during a severe Wi-Fi loss burst (271 HEVC errors /
3 min, NVDEC path): gate armed 19x, released 17x, dropping 29-118
corrupt frames per burst and resuming on the next clean keyframe.
The av_log bridge (273dd44) is confirmed working end-to-end.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The corruption re-arm added in 6344062 keyed off AVFrame::decode_error_flags,
but the HEVC decoder on the hwaccel (NVDEC) path never sets it: 120 s of live
Wi-Fi packet loss produced 10+ "First slice in a frame missing" / "Could not
find ref with POC n" log bursts with decode_error_flags == 0 on every frame,
so the keyframe gate never fired.
Bridge: install a process-wide av_log callback (chains to
av_log_default_callback) that maps the logging AVCodecContext back to its
CVideoDecoder and latches a per-decoder m_bCorruptSeen flag on AV_LOG_ERROR
messages. readFrame() consumes the latch alongside decode_error_flags to
re-arm the keyframe gate. With hwaccel the decoder is single-threaded, so
the logging context is exactly our AVCodecContext; SW frame-threaded paths
log from per-thread clones but set decode_error_flags instead, which the
existing check covers.
Registered after avcodec_open2, unregistered in uninit() before the context
is freed. Map lookup only on error-level messages (rare). Also promote the
gate-arm message to log_print(HT_LOG_WARN) for console visibility.
Clean-path verified live: 6105 frames / 5 min NVDEC RTSP with zero errors
and no regressions. Loss-path verification pending a naturally lossy window.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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>
Thread-local staging Mat (video_player.cpp:1400-1407) — single biggest win. Eliminates the 12 MB per-call malloc/free cycle.
Contiguous get_buffer2 allocator (video_decoder.cpp:35-102) — keeps the 3 bulk memcpys cache-friendly. Would also enable FAST/zero-copy for resolutions where visible_h % 64 == 0.
SW-decoder thread config (video_decoder.cpp:528-540) — thread_count=0, thread_type=FRAME|SLICE. FRAME is downgraded to SLICE-only by AV_CODEC_FLAG_LOW_DELAY, but decode throughput is sufficient for your input rate.
SetTargetFPS(100) delivery throttle (already there) — caps onVideoFrame post-decode work at 10 FPS. Keeps the caller path warm-cached.
Instrumentation — [MEDIA_DecInit] / [MEDIA_Convert] / [MEDIA_SWDec] / [MEDIA_Timing] / [MEDIA_JpegTiming] — always-on regression detector, zero cost when ANSCORE_DEBUGVIEW=OFF.
getImage() previously held _mutex across the 4K NV12->BGR sws_scale in
avframeToCVMat, blocking the decoder callback (onVideoFrame) for 100-300ms
per frame. Under multi-camera load this cascaded into 5-21s frame stalls
and STALE PTS events in the log.
- avframeToCVMat: drop outer _mutex. NV12/YUV420P paths touch no shared
state; avframeAnyToCvmat still locks internally for swsCtx.
- getImage: split into two short locked phases with the BGR conversion
unlocked between them. Decoder callbacks can push new frames and run
the CUDA HW capture path in parallel with the reader's conversion.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>