Function h264_reader::rbsp::decode_nal

source ·
pub fn decode_nal<'a>(nal_unit: &'a [u8]) -> Result<Cow<'a, [u8]>, Error>
Expand description

Returns RBSP from a NAL by removing the NAL header and emulation-prevention-three bytes.

See also module docs.

Returns error on invalid byte sequences. Returns a borrowed pointer if possible.

let nal_with_escape = &b"\x68\x12\x34\x00\x00\x03\x00\x86"[..];
assert!(matches!(
    decode_nal(nal_with_escape).unwrap(),
    Cow::Owned(s) if s == &b"\x12\x34\x00\x00\x00\x86"[..]));

let nal_without_escape = &b"\x68\xE8\x43\x8F\x13\x21\x30"[..];
assert_eq!(decode_nal(nal_without_escape).unwrap(), Cow::Borrowed(&nal_without_escape[1..]));

let invalid_nal = &b"\x68\x12\x34\x00\x00\x00\x86"[..];
assert_eq!(decode_nal(invalid_nal).unwrap_err().kind(), ErrorKind::InvalidData);