RTP: resume at access-unit boundary after packet loss, not NAL start
After a sequence gap the H.264/H.265 depacketizers resumed reassembly at
the next NAL/FU start. On multi-slice streams every slice starts a NAL,
so reassembly resumed MID-FRAME and delivered access units missing their
leading slices — manufacturing "First slice in a frame missing" /
"Ignoring POC change between slices" / "Could not find ref" decoder
errors and green/blocky concealment output far beyond the actual loss.
Resume only at a true AU boundary instead:
H.265 - non-VCL NAL (type >= 32) or VCL slice with
first_slice_segment_in_pic_flag set (first bit after the
2-byte NAL header)
H.264 - non-VCL NAL (type >= 6) or VCL slice with
first_mb_in_slice == 0 (ue(v): MSB set after 1-byte header)
Also: stderr visibility for RTP sequence gaps (rtp_rx logs went only to
the sys_log file) and for av_log-bridge latches in video_decoder — the
global av_log level filters decoder errors from the console, which made
keyframe-gate arms look causeless during diagnosis.
Live verification, HEVC camera on lossy Wi-Fi (NVDEC decode):
before: 271 decoder errors / 3 min, delivery collapsed to ~2 fps
after: 3 errors / 2 min, full ~21 fps, zero corrupt frames displayed
Remaining rare errors show POC ref misses with ZERO RTP sequence gaps,
i.e. pre-decode queue eviction under TCP burst clumps - a separate,
much smaller issue absorbed invisibly by the keyframe gate.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,10 +43,24 @@ namespace {
|
||||
void ansAvLogBridge(void* ptr, int level, const char* fmt, va_list vl)
|
||||
{
|
||||
if (ptr && level <= AV_LOG_ERROR) {
|
||||
std::lock_guard<std::mutex> lk(s_logBridgeMutex);
|
||||
auto it = s_logBridgeMap.find(ptr);
|
||||
if (it != s_logBridgeMap.end()) {
|
||||
it->second->store(true, std::memory_order_relaxed);
|
||||
bool latched = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(s_logBridgeMutex);
|
||||
auto it = s_logBridgeMap.find(ptr);
|
||||
if (it != s_logBridgeMap.end()) {
|
||||
it->second->store(true, std::memory_order_relaxed);
|
||||
latched = true;
|
||||
}
|
||||
}
|
||||
if (latched) {
|
||||
// Show exactly which decoder-context error latched the corrupt
|
||||
// flag — av_log_default_callback may filter it out (global log
|
||||
// level), which would otherwise make gate arms look causeless.
|
||||
va_list vc;
|
||||
va_copy(vc, vl);
|
||||
fprintf(stderr, "[FFmpeg-latch] ");
|
||||
vfprintf(stderr, fmt, vc);
|
||||
va_end(vc);
|
||||
}
|
||||
}
|
||||
av_log_default_callback(ptr, level, fmt, vl);
|
||||
@@ -1176,8 +1190,9 @@ BOOL CVideoDecoder::readFrame()
|
||||
// • m_bCorruptSeen — latched by the av_log bridge; the ONLY signal
|
||||
// on the hwaccel (NVDEC) path, which logs the error but leaves
|
||||
// decode_error_flags at 0 (verified empirically).
|
||||
const bool frameCorrupt = (m_pFrame->decode_error_flags != 0)
|
||||
|| m_bCorruptSeen.exchange(false, std::memory_order_relaxed);
|
||||
const bool corruptByFlags = (m_pFrame->decode_error_flags != 0);
|
||||
const bool corruptByBridge = m_bCorruptSeen.exchange(false, std::memory_order_relaxed);
|
||||
const bool frameCorrupt = corruptByFlags || corruptByBridge;
|
||||
if (frameCorrupt) {
|
||||
if (!m_bWaitKeyframe.load(std::memory_order_relaxed)) {
|
||||
m_bWaitKeyframe.store(true, std::memory_order_relaxed);
|
||||
@@ -1188,7 +1203,8 @@ BOOL CVideoDecoder::readFrame()
|
||||
// Also to stderr so it appears next to FFmpeg's own [hevc @ ...]
|
||||
// error lines (log_print goes to the log file, which unit tests
|
||||
// and field debugging sessions usually don't have open).
|
||||
fprintf(stderr, "[MediaClient] corrupt frame detected -- gating until next keyframe\n");
|
||||
fprintf(stderr, "[MediaClient] corrupt frame detected (flags=0x%x bridge=%d) -- gating until next keyframe\n",
|
||||
m_pFrame->decode_error_flags, (int)corruptByBridge);
|
||||
ANS_DBG("MEDIA_Decode",
|
||||
"corrupt frame (decode_error_flags=0x%x) — re-arming keyframe gate",
|
||||
m_pFrame->decode_error_flags);
|
||||
|
||||
Reference in New Issue
Block a user