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:
2026-07-07 06:09:37 +10:00
co-authored by Claude Fable 5
parent b341392e0f
commit 7909c8db2b
4 changed files with 78 additions and 23 deletions
+26 -7
View File
@@ -265,16 +265,35 @@ BOOL h265_data_rx(H265RXI * p_rxi, uint8 * p_data, int len)
if (p_rxi->rtprxi.rxf_loss)
{
// Packet loss, until the next start packet
if (!beginPacket)
// Packet loss — resume ONLY at an access-unit boundary.
//
// The old behaviour resumed at the next NAL/FU start, but with
// multi-slice frames every slice starts a NAL, so reassembly resumed
// MID-FRAME and delivered access units missing their leading slices.
// The decoder then logs "First slice in a frame missing" / "Ignoring
// POC change between slices" and conceals the damage as green/blocky
// garbage. An AU boundary is either a non-VCL NAL (VPS/SPS/PPS/SEI,
// type >= 32, which precede an IDR) or a VCL slice with
// first_slice_segment_in_pic_flag set — the first bit after the
// 2-byte NAL header (H.265 spec 7.3.6.1).
BOOL auStart = FALSE;
if (beginPacket)
{
uint8* payload = headerStart + numBytesToSkip;
int payloadLen = (int)packetSize - (int)numBytesToSkip;
if (payloadLen >= 3)
{
uint8 nt = (payload[0] >> 1) & 0x3F;
if (nt >= 32) auStart = TRUE; // non-VCL (param sets/SEI)
else if (payload[2] & 0x80) auStart = TRUE; // first slice in picture
}
}
if (!auStart)
{
p_rxi->d_offset = 0;
return FALSE;
}
else
{
p_rxi->rtprxi.rxf_loss = 0;
}
p_rxi->rtprxi.rxf_loss = 0;
}
// save the H265 parameter sets