Repository navigation
decoder: one access unit per MediaCodec input buffer - #142
Conversation
PR Summary by QodoQueue one access unit per MediaCodec input buffer
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo
1. Malformed video packets can read past a buffer
|
dd66474 to
42fe1c5
Compare
VideoDecoder queued every NAL as its own input buffer with its own timestamp. A frame encoded as several slices is several NALs, and some decoders then show only the first slice of each frame. NALs now gather into one buffer per access unit, flushed on the RTP marker (set on the last packet of each frame) or, for a stream without markers, on the next frame's first slice. A buffer with only parameter sets is queued as CODEC_CONFIG. A single-slice stream is unchanged: one NAL per frame was already one access unit per buffer.
42fe1c5 to
b7861a0
Compare
The RTP marker flushed the gathered access unit for any H.264/H.265 packet, including ones the RTP decoder then dropped: too short, empty, a duplicate sequence number, an unsupported NAL type. A late copy of the previous frame's last packet could also flush the current frame half-built. parseRTPH264toNALU/parseRTPH265toNALU now say whether they took the packet, and the marker counts only for a taken packet whose sequence number is newer than any seen so far. A jump of more than 512 behind is taken as a restarted sender and resyncs, so a new stream's markers are not ignored until its numbers catch up.
VideoDecoder queued every NAL as its own input buffer. When a frame is encoded as several slices, that's several NALs per frame, and some decoders then show only the first slice. On a Pixel 7 Pro you get the top strip of the picture and black below.
NALs now go into one buffer per frame. The buffer is queued on the RTP marker (last packet of the frame), so there's no added delay. For a stream without markers it's queued on the next frame's first slice. A buffer with only parameter sets is queued as CODEC_CONFIG.
Single-slice streams aren't affected: one NAL per frame was already one frame per buffer.
Tested on a Pixel 7 Pro with an x265 test stream (1280x720@60) sent over RTP to port 5600: