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
impl SequenceDecoder
Sourcepub fn new() -> Self
pub fn new() -> Self
A fresh decoder with no activated parameter sets.
Examples found in repository?
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}Sourcepub fn push_annexb(&mut self, data: &[u8]) -> Result<(), SequenceError>
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.
Sourcepub fn push_nal_unit(&mut self, unit: NalUnit) -> Result<(), SequenceError>
pub fn push_nal_unit(&mut self, unit: NalUnit) -> Result<(), SequenceError>
Examples found in repository?
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}Sourcepub fn flush(&mut self) -> Result<(), SequenceError>
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.
Sourcepub fn take_decoded(&mut self) -> Vec<DecodedFrame>
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).
Sourcepub fn max_num_reorder_pics(&self) -> Option<u32>
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).
Sourcepub fn finish(self) -> Result<Vec<DecodedFrame>, SequenceError>
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?
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}