Skip to main content

SequenceDecoder

Struct SequenceDecoder 

Source
pub struct SequenceDecoder { /* private fields */ }
Expand description

The whole-bitstream decoder: parameter-set activation + per-picture slice-data decode + the §8.3 reference cycle.

Implementations§

Source§

impl SequenceDecoder

Source

pub fn new() -> Self

A fresh decoder with no activated parameter sets.

Examples found in repository?
examples/dump_frames.rs (line 8)
5fn main() {
6    let path = std::env::args().nth(1).unwrap();
7    let data = std::fs::read(path).unwrap();
8    let mut dec = SequenceDecoder::new();
9    let mut n = 0;
10    for unit in NalIter::new(&data) {
11        let unit = unit.unwrap();
12        let t = unit.header.nal_unit_type;
13        let first = t < 32 && unit.rbsp.first().is_some_and(|b| b & 0x80 != 0);
14        if first {
15            n += 1;
16        }
17        if let Err(e) = dec.push_nal_unit(unit) {
18            eprintln!("error while pushing NAL type {t} (picture #{n}): {e}");
19            return;
20        }
21    }
22    match dec.finish() {
23        Ok(frames) => {
24            for f in &frames {
25                eprintln!("cvs={} poc={} out={}", f.cvs_index, f.poc, f.output);
26            }
27        }
28        Err(e) => eprintln!("finish error: {e}"),
29    }
30}
Source

pub fn push_annexb(&mut self, data: &[u8]) -> Result<(), SequenceError>

Feed a whole Annex B byte stream, decoding every access unit.

§Errors

Any demux / parse / decode error; the decoder state is unspecified after an error.

Source

pub fn push_nal_unit(&mut self, unit: NalUnit) -> Result<(), SequenceError>

Feed one demuxed NAL unit.

§Errors

Any parse / decode error.

Examples found in repository?
examples/dump_frames.rs (line 17)
5fn main() {
6    let path = std::env::args().nth(1).unwrap();
7    let data = std::fs::read(path).unwrap();
8    let mut dec = SequenceDecoder::new();
9    let mut n = 0;
10    for unit in NalIter::new(&data) {
11        let unit = unit.unwrap();
12        let t = unit.header.nal_unit_type;
13        let first = t < 32 && unit.rbsp.first().is_some_and(|b| b & 0x80 != 0);
14        if first {
15            n += 1;
16        }
17        if let Err(e) = dec.push_nal_unit(unit) {
18            eprintln!("error while pushing NAL type {t} (picture #{n}): {e}");
19            return;
20        }
21    }
22    match dec.finish() {
23        Ok(frames) => {
24            for f in &frames {
25                eprintln!("cvs={} poc={} out={}", f.cvs_index, f.poc, f.output);
26            }
27        }
28        Err(e) => eprintln!("finish error: {e}"),
29    }
30}
Source

pub fn flush(&mut self) -> Result<(), SequenceError>

Decode any picture still being assembled (a flush point — call when the input stream ends but the decoder object lives on).

§Errors

Any decode error from the pending picture.

Source

pub fn take_decoded(&mut self) -> Vec<DecodedFrame>

Drain the pictures decoded so far, in decode order. The caller owns output reordering (the streaming crate::decoder holds a sps_max_num_reorder_pics-deep queue; Self::finish sorts a whole sequence at once).

Source

pub fn max_num_reorder_pics(&self) -> Option<u32>

sps_max_num_reorder_pics of the highest sub-layer of the most recently activated SPS (None before any SPS).

Source

pub fn finish(self) -> Result<Vec<DecodedFrame>, SequenceError>

Decode any picture still being assembled and return every decoded frame in output order.

§Errors

Any decode error from the final pending picture.

Examples found in repository?
examples/dump_frames.rs (line 22)
5fn main() {
6    let path = std::env::args().nth(1).unwrap();
7    let data = std::fs::read(path).unwrap();
8    let mut dec = SequenceDecoder::new();
9    let mut n = 0;
10    for unit in NalIter::new(&data) {
11        let unit = unit.unwrap();
12        let t = unit.header.nal_unit_type;
13        let first = t < 32 && unit.rbsp.first().is_some_and(|b| b & 0x80 != 0);
14        if first {
15            n += 1;
16        }
17        if let Err(e) = dec.push_nal_unit(unit) {
18            eprintln!("error while pushing NAL type {t} (picture #{n}): {e}");
19            return;
20        }
21    }
22    match dec.finish() {
23        Ok(frames) => {
24            for f in &frames {
25                eprintln!("cvs={} poc={} out={}", f.cvs_index, f.poc, f.output);
26            }
27        }
28        Err(e) => eprintln!("finish error: {e}"),
29    }
30}

Trait Implementations§

Source§

impl Debug for SequenceDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SequenceDecoder

Source§

fn default() -> SequenceDecoder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.