Skip to content

Retina should not fail on 0-length FU and FU-A units #115

@nemosupremo

Description

@nemosupremo

Currently in h264 and h265 retina will bail if the Fragmentation Unit length is 0:

retina/src/codec/h264.rs

Lines 391 to 395 in d1e5055

// FU-A. https://tools.ietf.org/html/rfc6184#section-5.8
if data.len() < 3 {
// NAL + FU-A headers take 2 byte; need at least 3 bytes to make progress.
return Err(format!("FU-A len {} too short", data.len()));
}

retina/src/codec/h265.rs

Lines 311 to 314 in d1e5055

// Fragmentation Unit. https://datatracker.ietf.org/doc/html/rfc7798#section-4.4.3
if data.len() < 2 {
return Err(format!("FU len {} too short", data.len()));
}

These checks ensure that the packet is at least the required headers + one byte. Having a non-zero length isn't actually enforced by the spec and some cameras actually send empty Frag NALs.

https://github.com/bluenviron/gortsplib/blob/a984c7c71c70c8d05de018a8cfc9aa722597ad2d/pkg/format/rtph264/decoder.go#L92-L94

https://github.com/bluenviron/gortsplib/blob/a984c7c71c70c8d05de018a8cfc9aa722597ad2d/pkg/format/rtph265/decoder.go#L107-L110

Note that gortsplib implementations, the pkt.Payload size includes the NAL header

By accepting empty Fragmentation packets, the stream can be played without interruption.

For h264, it would mean changing to:

if data.len() < 2 { 
     // NAL + FU-A headers take 2 byte
     return Err(format!("FU-A len {} too short", data.len())); 
 } 

and a 1 byte check for h265

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions