forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/u14' into simplify/w1b

Browse files at this commit

2eb48e520d571debeeee19b91577e3b1d6202921Ahmet Kaan GümüşParent: e8adf6d06551e9
crates/ec-mpeg2/src/decoder.rsmodified+18 -26
@@ -660,9 +660,9 @@ impl Core {
660660
661661 #[allow(clippy::too_many_lines)]
662662 fn decode_slice(&mut self, code: u8, data: &[u8]) -> std::result::Result<(), ()> {
663- let seq = self.seq.clone().ok_or_else(|| trace(line!()))?;
663+ let seq = self.seq.clone().ok_or(())?;
664664 let t = tables();
665- let mut st = self.pic.take().ok_or_else(|| trace(line!()))?;
665+ let mut st = self.pic.take().ok_or(())?;
666666 let r = self.slice_inner(&seq, t, &mut st, code, data);
667667 self.pic = Some(st);
668668 r
@@ -685,19 +685,19 @@ impl Core {
685685 }
686686 let mw = seq.mb_width();
687687 if mb_row >= st.rows {
688- return Err(trace(line!()));
688+ return Err(());
689689 }
690690 let qcode = b.read(5) as usize;
691691 if qcode == 0 {
692- return Err(trace(line!()));
692+ return Err(());
693693 }
694694 while b.read1() {
695695 b.skip(8);
696696 }
697- let cur_idx = self.cur.as_ref().ok_or_else(|| trace(line!()))?.idx;
697+ let cur_idx = self.cur.as_ref().ok_or(())?.idx;
698698 // The picture must match this slice's geometry, or macroblock rows fall outside its planes.
699699 if self.pool[cur_idx].height[0] != seq.mb_height() * 16 {
700- return Err(trace(line!()));
700+ return Err(());
701701 }
702702 let ptype = hdr.picture_type;
703703 let field_pic = hdr.structure != Structure::Frame;
@@ -728,7 +728,7 @@ impl Core {
728728 // macroblock_address_increment
729729 let mut inc = 0usize;
730730 loop {
731- let v = b.vlc(&t.mba).ok_or_else(|| trace(line!()))?;
731+ let v = b.vlc(&t.mba).ok_or(())?;
732732 if v == 34 {
733733 inc += 33;
734734 } else if v == 35 {
@@ -738,7 +738,7 @@ impl Core {
738738 break;
739739 }
740740 if b.overrun() {
741- return Err(trace(line!()));
741+ return Err(());
742742 }
743743 }
744744 if first {
@@ -749,7 +749,7 @@ impl Core {
749749 for _ in 1..inc {
750750 addr += 1;
751751 if addr as usize >= total {
752- return Err(trace(line!()));
752+ return Err(());
753753 }
754754 let a = addr as usize;
755755 // Skipped macroblock.
@@ -776,7 +776,7 @@ impl Core {
776776 motion = m;
777777 }
778778 if ptype == PictureType::I {
779- return Err(trace(line!()));
779+ return Err(());
780780 }
781781 let info = MbInfo { intra: false, m, dct_field: false, cbp: 0, last: [0; 8] };
782782 self.recon_mb(seq, &hdr, st, cur_idx, a % mw, a / mw, &info, &mut blocks);
@@ -785,7 +785,7 @@ impl Core {
785785 addr += 1;
786786 }
787787 if addr < 0 || addr as usize >= total {
788- return Err(trace(line!()));
788+ return Err(());
789789 }
790790 let a = addr as usize;
791791 let mb_x = a % mw;
@@ -797,7 +797,7 @@ impl Core {
797797 PictureType::P => 1,
798798 PictureType::B => 2,
799799 };
800- let flags = b.vlc(&t.mbtype[ti]).ok_or_else(|| trace(line!()))? as u16;
800+ let flags = b.vlc(&t.mbtype[ti]).ok_or(())? as u16;
801801 let intra = flags & MB_INTRA != 0;
802802 let mut m = Motion { fwd: flags & MB_FWD != 0, bwd: flags & MB_BWD != 0, ..Motion::default() };
803803 let mut dct_field = false;
@@ -808,7 +808,7 @@ impl Core {
808808 } else {
809809 kind_code = b.read(2);
810810 if kind_code == 0 {
811- return Err(trace(line!()));
811+ return Err(());
812812 }
813813 }
814814 } else if mpeg1 {
@@ -820,7 +820,7 @@ impl Core {
820820 if flags & MB_QUANT != 0 {
821821 let qc = b.read(5) as usize;
822822 if qc == 0 {
823- return Err(trace(line!()));
823+ return Err(());
824824 }
825825 qscale = qscale_of(qc);
826826 }
@@ -872,7 +872,7 @@ impl Core {
872872 if intra {
873873 cbp = (1 << nblocks) - 1;
874874 } else if flags & MB_PAT != 0 {
875- cbp = b.vlc(&t.cbp).ok_or_else(|| trace(line!()))?;
875+ cbp = b.vlc(&t.cbp).ok_or(())?;
876876 if seq.chroma_format == 2 {
877877 cbp = (cbp << 2) | b.read(2);
878878 }
@@ -927,7 +927,7 @@ impl Core {
927927 for blk in blocks.iter_mut() {
928928 *blk = [0; 64];
929929 }
930- return Err(trace(line!()));
930+ return Err(());
931931 }
932932 let info = MbInfo { intra, m, dct_field, cbp, last };
933933 self.recon_mb(seq, &hdr, st, cur_idx, mb_x, mb_y, &info, &mut blocks);
@@ -939,7 +939,7 @@ impl Core {
939939 motion = Motion { fwd: true, ..Motion::default() };
940940 }
941941 if b.overrun() {
942- return Err(trace(line!()));
942+ return Err(());
943943 }
944944 if b.peek(23) == 0 {
945945 break;
@@ -1223,7 +1223,7 @@ fn read_motion(
12231223 if tc == 1 && frame_field {
12241224 pred >>= 1;
12251225 }
1226- let v = decode_component(b, t, hdr.f_code[s][tc], pred).ok_or_else(|| trace(line!()))?;
1226+ let v = decode_component(b, t, hdr.f_code[s][tc], pred).ok_or(())?;
12271227 pmv[r][s][tc] = if tc == 1 && frame_field { v << 1 } else { v };
12281228 m.mv[s][r][tc] = v << shift;
12291229 if dual {
@@ -1281,14 +1281,6 @@ fn conceal_mb(
12811281 }
12821282 }
12831283
1284-/// Debug aid: with `EC_MPEG2_TRACE` set, report where a slice gave up.
1285-fn trace(line: u32) {
1286- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
1287- if *ON.get_or_init(|| std::env::var_os("EC_MPEG2_TRACE").is_some()) {
1288- eprintln!("ec-mpeg2: slice error at decoder.rs:{line}");
1289- }
1290-}
1291-
12921284 fn chroma_shift(cf: u8) -> (usize, usize) {
12931285 match cf {
12941286 1 => (1, 1),
crates/ec-mpeg2/tests/regression.rsadded+19 -0
@@ -0,0 +1,19 @@
1+use ec_core::registry::{CodecId, CodecParameters};
2+use ec_mpeg2::Mpeg2Decoder;
3+
4+/// `decode_mpeg2` panic: a sequence extension changed the MB-row count (9 to 10 at 176x144)
5+/// without changing the size, so pictures allocated under the old geometry were decoded under
6+/// the new one and a macroblock row was written past the end of the plane. The decoder must
7+/// refuse the damage or conceal it and mark the frame corrupt, never panic.
8+#[test]
9+fn mb_height_change_without_resize_is_concealed() {
10+ let data = include_bytes!("data/fuzz/decode_mpeg2-mb-height-change.m2v");
11+ let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap();
12+ let mut failed = dec.send_bytes(data, None).is_err();
13+ failed |= dec.flush_stream().is_err();
14+ let mut corrupt = false;
15+ while let Some((_, info)) = dec.pop_picture() {
16+ corrupt |= info.corrupt;
17+ }
18+ assert!(failed || corrupt, "damage must surface as an error or a corrupt frame");
19+}
crates/ec-mpeg2/tests/robust.rsdeleted+0 -214
@@ -1,214 +0,0 @@
1-//! Robustness: truncated, corrupted and hostile streams must never panic and
2-//! must keep the output queue bounded.
3-#![allow(clippy::needless_range_loop, clippy::field_reassign_with_default, clippy::too_many_arguments, clippy::type_complexity)]
4-
5-mod common;
6-use common::synth::{SynthCfg, generate};
7-use common::*;
8-use ec_core::registry::{CodecId, CodecParameters};
9-use ec_mpeg2::Mpeg2Decoder;
10-
11-const MAX_QUEUE: usize = 64;
12-
13-struct Rng(u64);
14-impl Rng {
15- fn next(&mut self) -> u64 {
16- self.0 ^= self.0 << 13;
17- self.0 ^= self.0 >> 7;
18- self.0 ^= self.0 << 17;
19- self.0
20- }
21- fn below(&mut self, n: usize) -> usize {
22- (self.next() % n.max(1) as u64) as usize
23- }
24-}
25-
26-fn streams() -> Vec<Vec<u8>> {
27- [(1u64, false, false), (2, true, false), (3, false, true), (4, true, true)]
28- .into_iter()
29- .map(|(seed, fields, p422)| {
30- generate(&SynthCfg {
31- mb_w: 3,
32- mb_h: 2,
33- chroma422: p422,
34- progressive_sequence: false,
35- frames: 5,
36- seed,
37- fields,
38- heavy: fields,
39- load_matrices: seed % 2 == 0,
40- })
41- })
42- .collect()
43-}
44-
45-/// Decode `data` in chunks of `chunk`; return the frame count. Errors are ignored.
46-fn run(data: &[u8], chunk: usize) -> usize {
47- let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap();
48- let mut n = 0;
49- for c in data.chunks(chunk.max(1)) {
50- let _ = dec.send_bytes(c, None);
51- while dec.pop_picture().is_some() {
52- n += 1;
53- }
54- }
55- let _ = dec.flush_stream();
56- while dec.pop_picture().is_some() {
57- n += 1;
58- }
59- n
60-}
61-
62-/// Like `run` but never drains until the end: the queue must stay bounded.
63-fn run_undrained(data: &[u8], chunk: usize) {
64- let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap();
65- for c in data.chunks(chunk.max(1)) {
66- let _ = dec.send_bytes(c, None);
67- }
68- let _ = dec.flush_stream();
69- let mut n = 0;
70- while dec.pop_picture().is_some() {
71- n += 1;
72- }
73- assert!(n <= MAX_QUEUE, "queued {n} frames");
74-}
75-
76-#[test]
77-fn truncation_prefixes() {
78- for es in streams() {
79- assert!(run(&es, es.len()) > 0, "clean stream decodes nothing");
80- let step = (es.len() / 40).max(1);
81- for cut in (0..es.len()).step_by(step).chain([es.len() - 1, es.len() - 2]) {
82- run(&es[..cut], 97);
83- run_undrained(&es[..cut], usize::MAX);
84- }
85- }
86-}
87-
88-#[test]
89-fn chunking_is_invariant() {
90- for es in streams() {
91- let mk = |chunk: usize| {
92- let a = decode_ours(&es, chunk).expect("clean stream");
93- a.iter().map(|(f, _)| frame_bytes(f)).collect::<Vec<_>>()
94- };
95- let whole = mk(es.len());
96- assert!(!whole.is_empty());
97- assert_eq!(whole, mk(1), "1-byte chunks differ");
98- assert_eq!(whole, mk(7), "7-byte chunks differ");
99- }
100-}
101-
102-#[test]
103-fn random_corruptions() {
104- let mut rng = Rng(0x1234_5678_9ABC_DEF1);
105- let all = streams();
106- for i in 0..300 {
107- let mut es = all[i % all.len()].clone();
108- for _ in 0..1 + rng.below(6) {
109- if es.is_empty() {
110- break;
111- }
112- let p = rng.below(es.len());
113- match rng.below(4) {
114- 0 => es[p] ^= 1 << rng.below(8),
115- 1 => es[p] = rng.next() as u8,
116- 2 => {
117- let n = 1 + rng.below(8);
118- es.drain(p..(p + n).min(es.len()));
119- }
120- _ => {
121- for _ in 0..1 + rng.below(8) {
122- es.insert(p, rng.next() as u8);
123- }
124- }
125- }
126- }
127- run(&es, 1 + rng.below(300));
128- run_undrained(&es, usize::MAX);
129- }
130-}
131-
132-#[test]
133-fn garbage_is_refused() {
134- let mut rng = Rng(0xDEAD_BEEF_CAFE_F00D);
135- for len in [0usize, 1, 3, 4, 100, 5000, 200_000] {
136- let g: Vec<u8> = (0..len).map(|_| rng.next() as u8).collect();
137- run(&g, 1000);
138- run_undrained(&g, usize::MAX);
139- }
140- // Garbage dense with start codes.
141- let mut g = Vec::new();
142- for _ in 0..2000 {
143- g.extend_from_slice(&[0, 0, 1, rng.next() as u8]);
144- for _ in 0..rng.below(20) {
145- g.push(rng.next() as u8);
146- }
147- }
148- run(&g, 333);
149- run_undrained(&g, usize::MAX);
150-}
151-
152-#[test]
153-fn huge_dimensions_are_bounded() {
154- // Sequence header 4095x4095 + sequence_extension adding 3<<12 to both: 16383x16383.
155- let mut es = vec![0, 0, 1, 0xB3, 0xFF, 0xFF, 0xFF, 0x13, 0xFF, 0xFF, 0xE0, 0x18];
156- // sequence_extension: id=1, profile/level, progressive, chroma 4:2:0, size ext 3/3.
157- es.extend_from_slice(&[0, 0, 1, 0xB5, 0x14, 0x8A, 0x00, 0x01, 0x00, 0x00]);
158- es.extend_from_slice(&[0, 0, 1, 0xB5, 0x14, 0x8F, 0xFF, 0x01, 0x00, 0x00]);
159- // GOP + picture header (I) + a slice, repeated.
160- for _ in 0..3 {
161- es.extend_from_slice(&[0, 0, 1, 0xB8, 0, 0x08, 0, 0x40]);
162- es.extend_from_slice(&[0, 0, 1, 0x00, 0x00, 0x0F, 0xFF, 0xF8]);
163- es.extend_from_slice(&[0, 0, 1, 0xB5, 0x8F, 0xFF, 0xF3, 0x41, 0x00]);
164- es.extend_from_slice(&[0, 0, 1, 0x01, 0x10, 0x00, 0x00, 0x00]);
165- }
166- let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap();
167- let r = dec.send_bytes(&es, None);
168- let _ = dec.flush_stream();
169- let mut n = 0;
170- while let Some((f, _)) = dec.pop_picture() {
171- assert!(u64::from(f.width) * u64::from(f.height) <= 8192 * 4352);
172- n += 1;
173- }
174- assert!(n <= MAX_QUEUE);
175- if let Some(seq) = dec.sequence() {
176- eprintln!("sequence {}x{} (send: {:?})", seq.width, seq.height, r.is_ok());
177- }
178- // Also at the 12-bit maximum without an extension, and with the max-dimension edge.
179- for (w, h) in [(4095u32, 4095u32), (8192, 8192), (16383, 1), (1, 16383)] {
180- let mut s = vec![0, 0, 1, 0xB3, (w >> 4) as u8, (((w & 15) << 4) | (h >> 8)) as u8, h as u8, 0x13, 0xFF, 0xFF, 0xE0, 0x18];
181- s.extend_from_slice(&[0, 0, 1, 0x00, 0x00, 0x0F, 0xFF, 0xF8, 0, 0, 1, 0x01, 0x10, 0, 0]);
182- run(&s, usize::MAX);
183- run_undrained(&s, 5);
184- }
185-}
186-
187-/// `decode_mpeg2` panic: a sequence extension changed the MB-row count (9 to 10 at 176x144)
188-/// without changing the size, so pictures allocated under the old geometry were decoded under
189-/// the new one and a macroblock row was written past the end of the plane. The decoder must
190-/// refuse the damage or conceal it and mark the frame corrupt, never panic.
191-#[test]
192-fn mb_height_change_without_resize_is_concealed() {
193- let data = include_bytes!("data/fuzz/decode_mpeg2-mb-height-change.m2v");
194- let mut dec = Mpeg2Decoder::new(CodecParameters::new(CodecId::Mpeg2Video)).unwrap();
195- let mut failed = dec.send_bytes(data, None).is_err();
196- failed |= dec.flush_stream().is_err();
197- let mut corrupt = false;
198- while let Some((_, info)) = dec.pop_picture() {
199- corrupt |= info.corrupt;
200- }
201- assert!(failed || corrupt, "damage must surface as an error or a corrupt frame");
202-}
203-
204-/// Writes the synthetic streams as fuzz seeds:
205-/// `EC_SEED_DIR=crates/ec-mpeg2/fuzz/corpus/decode_mpeg2 cargo test --test robust -- --ignored dump_seeds`
206-#[test]
207-#[ignore]
208-fn dump_seeds() {
209- let Some(dir) = std::env::var_os("EC_SEED_DIR") else { return };
210- std::fs::create_dir_all(&dir).unwrap();
211- for (i, s) in streams().iter().enumerate() {
212- std::fs::write(std::path::Path::new(&dir).join(format!("syn{i}.m2v")), s).unwrap();
213- }
214-}
crates/ec-mpeg4/src/core.rsmodified+0 -2
@@ -159,7 +159,6 @@ pub struct Core {
159159 pub alternate_scan: bool,
160160 pub intra_dc_threshold: i32,
161161 pub top_field_first: bool,
162- pub partitioned: bool,
163162 pub y_dc_scale: i32,
164163 pub c_dc_scale: i32,
165164 // macroblock position / slice
@@ -237,7 +236,6 @@ impl Core {
237236 alternate_scan: false,
238237 intra_dc_threshold: 0,
239238 top_field_first: false,
240- partitioned: false,
241239 y_dc_scale: 8,
242240 c_dc_scale: 8,
243241 mb_x: 0,
crates/ec-mpeg4/src/frame.rsmodified+1 -5
@@ -117,9 +117,6 @@ impl Core {
117117 Ok(())
118118 }
119119
120- fn update_workarounds(&mut self) {
121- self.finish_workaround_flags();
122- }
123120
124121 /// Decode one VOP from `data`. Returns the byte position reached.
125122 fn decode_one_vop(&mut self, data: &[u8], pts: Option<Timestamp>) -> Result<Option<usize>> {
@@ -194,7 +191,6 @@ impl Core {
194191 self.f_code = vop.f_code;
195192 self.b_code = vop.b_code;
196193 self.set_qscale(vop.qscale);
197- self.partitioned = false;
198194 if self.vol.vo_type == 0
199195 && !self.vol.vol_control_parameters
200196 && self.ident.divx_version == -1
@@ -209,7 +205,7 @@ impl Core {
209205 "static sprite (S-VOP without GMC)".to_string(),
210206 ));
211207 }
212- self.update_workarounds();
208+ self.finish_workaround_flags();
213209 if pt != Pt::B && self.mb_num / 2 > br.left().max(0) as usize {
214210 return Err(Error::corrupt("MPEG-4: VOP too short"));
215211 }
crates/ec-mpeg4/src/h263data.rsmodified+0 -315
@@ -22,9 +22,6 @@ pub const H263_INTER_MCBPC_BITS: [u8; 28] = [
2222 1, 4, 4, 6, 5, 8, 8, 7, 3, 7, 7, 9, 6, 9, 9, 9, 3, 7, 7, 8, 9, 0, 0, 0, 11, 13, 13, 13,
2323 ];
2424
25-/// CBPC for B- and EP-pictures, indexed by the coded block pattern (Table O.4/H.263).
26-pub const CBPC_B_TAB: [[u8; 2]; 4] = [[0, 1], [2, 2], [7, 3], [6, 3]];
27-
2825 /// CBPY, indexed by the INTRA pattern value (12,34) read as four bits (Table 12/H.263); the INTER code is that of the complemented pattern.
2926 pub const H263_CBPY_TAB: [[u8; 2]; 16] = [
3027 [3, 4],
@@ -205,159 +202,6 @@ pub const INTER_RUN: [i8; 102] = [
205202 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
206203 ];
207204
208-/// INTRA TCOEF VLC for Advanced INTRA Coding, entries sorted by LAST, RUN, |LEVEL|, then ESCAPE (Table I.2/H.263).
209-pub const INTRA_VLC_AIC: [[u16; 2]; 103] = [
210- [2, 2],
211- [6, 3],
212- [14, 4],
213- [12, 5],
214- [13, 5],
215- [16, 6],
216- [17, 6],
217- [18, 6],
218- [22, 7],
219- [27, 8],
220- [32, 9],
221- [33, 9],
222- [26, 9],
223- [27, 9],
224- [28, 9],
225- [29, 9],
226- [30, 9],
227- [31, 9],
228- [35, 11],
229- [34, 11],
230- [87, 12],
231- [86, 12],
232- [85, 12],
233- [84, 12],
234- [83, 12],
235- [15, 4],
236- [20, 6],
237- [20, 7],
238- [30, 8],
239- [15, 10],
240- [33, 11],
241- [80, 12],
242- [11, 5],
243- [21, 7],
244- [14, 10],
245- [9, 10],
246- [21, 6],
247- [29, 8],
248- [13, 10],
249- [81, 12],
250- [19, 6],
251- [35, 9],
252- [7, 11],
253- [23, 7],
254- [34, 9],
255- [82, 12],
256- [28, 8],
257- [12, 10],
258- [31, 8],
259- [11, 10],
260- [37, 9],
261- [10, 10],
262- [36, 9],
263- [6, 11],
264- [33, 10],
265- [32, 10],
266- [8, 10],
267- [32, 11],
268- [7, 4],
269- [12, 6],
270- [16, 7],
271- [19, 8],
272- [17, 9],
273- [18, 9],
274- [4, 10],
275- [39, 11],
276- [38, 11],
277- [95, 12],
278- [15, 6],
279- [19, 9],
280- [5, 10],
281- [37, 11],
282- [14, 6],
283- [20, 9],
284- [36, 11],
285- [13, 6],
286- [6, 10],
287- [94, 12],
288- [17, 7],
289- [7, 10],
290- [19, 7],
291- [93, 12],
292- [18, 7],
293- [92, 12],
294- [20, 8],
295- [91, 12],
296- [21, 8],
297- [26, 8],
298- [25, 8],
299- [24, 8],
300- [23, 8],
301- [22, 8],
302- [25, 9],
303- [21, 9],
304- [22, 9],
305- [24, 9],
306- [23, 9],
307- [4, 11],
308- [5, 11],
309- [88, 12],
310- [89, 12],
311- [90, 12],
312- [3, 7],
313-];
314-
315-/// RUN of the entries of INTRA_VLC_AIC (Table I.2/H.263).
316-pub const INTRA_RUN_AIC: [i8; 102] = [
317- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
318- 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13, 0, 0, 0, 0,
319- 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13,
320- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
321-];
322-
323-/// |LEVEL| of the entries of INTRA_VLC_AIC (Table I.2/H.263).
324-pub const INTRA_LEVEL_AIC: [i8; 102] = [
325- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 1,
326- 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1,
327- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1,
328- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
329-];
330-
331-/// Advanced INTRA Coding reconstruction scale 2 * QUANT (Annex I.3: RecC = 2 * QUANT * LEVEL, applied to INTRADC too).
332-pub const AIC_DC_SCALE_TABLE: [u8; 32] = [
333- 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48,
334- 50, 52, 54, 56, 58, 60, 62,
335-];
336-
337-/// Modified Quantization: new QUANT for DQUANT = 10 (row 0) and 11 (row 1) by prior QUANT (Table T.1/H.263); slot 0 is unused.
338-pub const MODIFIED_QUANT_TAB: [[u8; 32]; 2] = [
339- [
340- 0, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 19, 20, 21, 22,
341- 23, 24, 25, 26, 27, 28,
342- ],
343- [
344- 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27,
345- 28, 29, 30, 31, 31, 31, 26,
346- ],
347-];
348-
349-/// QUANT_C for chrominance in Modified Quantization mode (Table T.2/H.263); slot 0 is unused.
350-pub const H263_CHROMA_QSCALE_TABLE: [u8; 32] = [
351- 0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14,
352- 15, 15, 15, 15, 15,
353-];
354-
355-/// Largest macroblock address per standard picture format, sub-QCIF to 2048x1152 (Table K.2/H.263).
356-pub const MBA_MAX: [u16; 6] = [47, 98, 395, 1583, 6335, 9215];
357-
358-/// MBA field width in bits for the same formats (Table K.2/H.263); the last slot repeats the 14 bits of the largest format.
359-pub const MBA_LENGTH: [u8; 7] = [6, 7, 9, 11, 13, 14, 14];
360-
361205 /// Zigzag scan: raster position (row * 8 + column) of each scan index (Figure 14/H.263).
362206 pub const ZIGZAG_DIRECT: [u8; 64] = [
363207 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20,
@@ -414,8 +258,6 @@ pub const H263_PIXEL_ASPECT: [[u8; 2]; 16] = [
414258 // Number of entries (without ESCAPE) and number of LAST = 0 entries of the TCOEF tables.
415259 pub const H263_RL_INTER_N: usize = 102;
416260 pub const H263_RL_INTER_LAST: usize = 58;
417-pub const RL_INTRA_AIC_N: usize = 102;
418-pub const RL_INTRA_AIC_LAST: usize = 58;
419261
420262 #[cfg(test)]
421263 mod spec_tests {
@@ -614,112 +456,6 @@ mod spec_tests {
614456 (1, 40, 1, "000001011111"),
615457 ];
616458 const T16_ESC: &str = "0000011";
617- /// Table I.2/H.263 rows in index order.
618- const TI2: [(u8, i8, i8, &str); 102] = [
619- (0, 0, 1, "10"),
620- (0, 1, 1, "1111"),
621- (0, 3, 1, "010101"),
622- (0, 5, 1, "0010111"),
623- (0, 7, 1, "00011111"),
624- (0, 8, 1, "000100101"),
625- (0, 9, 1, "000100100"),
626- (0, 10, 1, "0000100001"),
627- (0, 11, 1, "0000100000"),
628- (0, 4, 3, "00000000111"),
629- (0, 9, 2, "00000000110"),
630- (0, 13, 1, "00000100000"),
631- (0, 0, 2, "110"),
632- (0, 1, 2, "010100"),
633- (0, 1, 4, "00011110"),
634- (0, 1, 5, "0000001111"),
635- (0, 1, 6, "00000100001"),
636- (0, 1, 7, "000001010000"),
637- (0, 0, 3, "1110"),
638- (0, 3, 2, "00011101"),
639- (0, 2, 3, "0000001110"),
640- (0, 3, 4, "000001010001"),
641- (0, 0, 5, "01101"),
642- (0, 4, 2, "000100011"),
643- (0, 3, 3, "0000001101"),
644- (0, 0, 4, "01100"),
645- (0, 5, 2, "000100010"),
646- (0, 5, 3, "000001010010"),
647- (0, 2, 1, "01011"),
648- (0, 6, 2, "0000001100"),
649- (0, 0, 25, "000001010011"),
650- (0, 4, 1, "010011"),
651- (0, 7, 2, "0000001011"),
652- (0, 0, 24, "000001010100"),
653- (0, 0, 8, "010010"),
654- (0, 8, 2, "0000001010"),
655- (0, 0, 7, "010001"),
656- (0, 2, 4, "0000001001"),
657- (0, 0, 6, "010000"),
658- (0, 12, 1, "0000001000"),
659- (0, 0, 9, "0010110"),
660- (0, 0, 23, "000001010101"),
661- (0, 2, 2, "0010101"),
662- (0, 1, 3, "0010100"),
663- (0, 6, 1, "00011100"),
664- (0, 0, 10, "00011011"),
665- (0, 0, 12, "000100001"),
666- (0, 0, 11, "000100000"),
667- (0, 0, 18, "000011111"),
668- (0, 0, 17, "000011110"),
669- (0, 0, 16, "000011101"),
670- (0, 0, 15, "000011100"),
671- (0, 0, 14, "000011011"),
672- (0, 0, 13, "000011010"),
673- (0, 0, 20, "00000100010"),
674- (0, 0, 19, "00000100011"),
675- (0, 0, 22, "000001010110"),
676- (0, 0, 21, "000001010111"),
677- (1, 0, 1, "0111"),
678- (1, 14, 1, "000011001"),
679- (1, 20, 1, "00000000101"),
680- (1, 1, 1, "001111"),
681- (1, 19, 1, "00000000100"),
682- (1, 2, 1, "001110"),
683- (1, 3, 1, "001101"),
684- (1, 0, 2, "001100"),
685- (1, 5, 1, "0010011"),
686- (1, 6, 1, "0010010"),
687- (1, 4, 1, "0010001"),
688- (1, 0, 3, "0010000"),
689- (1, 9, 1, "00011010"),
690- (1, 10, 1, "00011001"),
691- (1, 11, 1, "00011000"),
692- (1, 12, 1, "00010111"),
693- (1, 13, 1, "00010110"),
694- (1, 8, 1, "00010101"),
695- (1, 7, 1, "00010100"),
696- (1, 0, 4, "00010011"),
697- (1, 17, 1, "000011000"),
698- (1, 18, 1, "000010111"),
699- (1, 16, 1, "000010110"),
700- (1, 15, 1, "000010101"),
701- (1, 2, 2, "000010100"),
702- (1, 1, 2, "000010011"),
703- (1, 0, 6, "000010010"),
704- (1, 0, 5, "000010001"),
705- (1, 4, 2, "0000000111"),
706- (1, 3, 2, "0000000110"),
707- (1, 1, 3, "0000000101"),
708- (1, 0, 7, "0000000100"),
709- (1, 2, 3, "00000100100"),
710- (1, 1, 4, "00000100101"),
711- (1, 0, 9, "00000100110"),
712- (1, 0, 8, "00000100111"),
713- (1, 21, 1, "000001011000"),
714- (1, 22, 1, "000001011001"),
715- (1, 23, 1, "000001011010"),
716- (1, 7, 2, "000001011011"),
717- (1, 6, 2, "000001011100"),
718- (1, 5, 2, "000001011101"),
719- (1, 3, 3, "000001011110"),
720- (1, 0, 10, "000001011111"),
721- ];
722-
723459 #[test]
724460 fn mcbpc_matches_tables_7_and_8() {
725461 for (i, r) in T7.iter().enumerate() {
@@ -801,61 +537,10 @@ mod spec_tests {
801537 &INTER_LEVEL,
802538 H263_RL_INTER_LAST,
803539 );
804- check_rl(
805- &TI2,
806- &INTRA_VLC_AIC,
807- &INTRA_RUN_AIC,
808- &INTRA_LEVEL_AIC,
809- RL_INTRA_AIC_LAST,
810- );
811- // Table I.2 re-uses the codewords of Table 16 (I.3).
812- let mut a: Vec<_> = T16.iter().map(|r| r.3).collect();
813- let mut b: Vec<_> = TI2.iter().map(|r| r.3).collect();
814- a.sort();
815- b.sort();
816- assert_eq!(a, b);
817540 }
818541
819542 #[test]
820543 fn small_tables_match_the_text() {
821- // Table O.4: 0, 10, 111, 110 for CBPC pattern 00, 01, 10, 11.
822- assert_eq!(CBPC_B_TAB, [[0, 1], [2, 2], [7, 3], [6, 3]]);
823- // Annex I.3: RecC = 2 * QUANT * LEVEL.
824- for q in 0..32 {
825- assert_eq!(AIC_DC_SCALE_TABLE[q] as usize, 2 * q);
826- }
827- // Table T.2.
828- for q in 1..32usize {
829- let c = match q {
830- 1..=6 => q,
831- 7..=9 => q - 1,
832- 10..=11 => 9,
833- 12..=13 => 10,
834- 14..=15 => 11,
835- 16..=18 => 12,
836- 19..=21 => 13,
837- 22..=26 => 14,
838- _ => 15,
839- };
840- assert_eq!(H263_CHROMA_QSCALE_TABLE[q] as usize, c, "QUANT {q}");
841- }
842- // Table T.1: change of QUANT for DQUANT = 10 / 11.
843- for q in 1..32i32 {
844- let (d10, d11) = match q {
845- 1 => (2, 1),
846- 2..=10 => (-1, 1),
847- 11..=20 => (-2, 2),
848- 21..=28 => (-3, 3),
849- 29 => (-3, 2),
850- 30 => (-3, 1),
851- _ => (-3, -5),
852- };
853- assert_eq!(MODIFIED_QUANT_TAB[0][q as usize] as i32, q + d10);
854- assert_eq!(MODIFIED_QUANT_TAB[1][q as usize] as i32, q + d11);
855- }
856- // Table K.2.
857- assert_eq!(MBA_MAX, [47, 98, 395, 1583, 6335, 9215]);
858- assert_eq!(MBA_LENGTH, [6, 7, 9, 11, 13, 14, 14]);
859544 // Table 2 (formats) and Table 5 (PAR).
860545 assert_eq!(H263_FORMAT[1], [128, 96]);
861546 assert_eq!(H263_FORMAT[5], [1408, 1152]);
crates/ec-mpeg4/src/lib.rsmodified+2 -2
@@ -19,8 +19,8 @@ mod msmpeg4;
1919 mod recon;
2020 mod vlc;
2121
22-pub mod dsp;
23-pub mod tables;
22+mod dsp;
23+mod tables;
2424
2525 pub use codec::Mpeg4Decoder;
2626 pub use core::PictureInfo;
crates/ec-mpeg4/src/mb.rsmodified+1 -1
@@ -602,7 +602,7 @@ impl Core {
602602 let mut v = br.peek(16);
603603 let ptn = pt_num(self.pt);
604604 while v <= 0xFF {
605- if self.pt == Pt::B || (v >> (8 - ptn)) != 1 || self.partitioned {
605+ if self.pt == Pt::B || (v >> (8 - ptn)) != 1 {
606606 break;
607607 }
608608 br.skip((8 + ptn) as u32);
crates/ec-mpeg4/src/tables.rsmodified+1 -409
@@ -10,14 +10,13 @@
1010 //! * `MPEG4_DCTAB_LUM`/`MPEG4_DCTAB_CHROM`: DC size VLCs.
1111 //! * `MPEG4_INTRA_VLC`/`_RUN`/`_LEVEL`: INTRA TCOEF. Its codewords are
1212 //! those of Table 16/H.263 but the RUN/LEVEL assignment is MPEG-4's own.
13-//! * `INTER_RVLC`, `INTRA_RVLC` with `_RUN`/`_LEVEL`: reversible VLCs.
1413 //! * `SPRITE_TRAJECTORY_LENS`: warping point displacement code lengths (dmv_length).
1514 //! * `MB_TYPE_B_TAB`: B-VOP macroblock type codes.
1615 //! * `MPEG4_DEFAULT_INTRA_MATRIX`/`MPEG4_DEFAULT_NON_INTRA_MATRIX`: default
1716 //! quantisation matrices.
1817 //! * `MPEG4_Y_DC_SCALE_TABLE`/`MPEG4_C_DC_SCALE_TABLE`: DC scaler.
1918 //! * `MPEG4_DC_THRESHOLD`: intra_dc_vlc_thr.
20-//! * `MPEG4_RL_INTRA_*`, `RVLC_RL_*`: entry counts of the tables above.
19+//! * `MPEG4_RL_INTRA_*`: entry counts of the tables above.
2120
2221 pub use crate::h263data::*;
2322
@@ -173,389 +172,6 @@ pub const MPEG4_INTRA_RUN: [i8; 102] = [
173172 12, 13, 14, 15, 16, 17, 18, 19, 20,
174173 ];
175174
176-pub const INTER_RVLC: [[u16; 2]; 170] = [
177- [6, 3],
178- [1, 4],
179- [4, 5],
180- [28, 7],
181- [60, 8],
182- [61, 8],
183- [124, 9],
184- [252, 10],
185- [253, 10],
186- [508, 11],
187- [509, 11],
188- [1020, 12],
189- [2044, 13],
190- [2045, 13],
191- [3068, 13],
192- [3069, 13],
193- [4092, 14],
194- [4093, 14],
195- [8188, 15],
196- [7, 3],
197- [12, 6],
198- [92, 8],
199- [125, 9],
200- [380, 10],
201- [764, 11],
202- [1021, 12],
203- [3580, 13],
204- [6140, 14],
205- [6141, 14],
206- [10, 4],
207- [29, 7],
208- [188, 9],
209- [765, 11],
210- [1532, 12],
211- [7164, 14],
212- [7165, 14],
213- [5, 5],
214- [93, 8],
215- [381, 10],
216- [1533, 12],
217- [3581, 13],
218- [7676, 14],
219- [8189, 15],
220- [8, 5],
221- [108, 8],
222- [892, 11],
223- [3836, 13],
224- [12284, 15],
225- [9, 5],
226- [189, 9],
227- [893, 11],
228- [3837, 13],
229- [13, 6],
230- [444, 10],
231- [1788, 12],
232- [7677, 14],
233- [20, 6],
234- [445, 10],
235- [1789, 12],
236- [12285, 15],
237- [21, 6],
238- [476, 10],
239- [3964, 13],
240- [44, 7],
241- [477, 10],
242- [7932, 14],
243- [45, 7],
244- [956, 11],
245- [52, 7],
246- [1916, 12],
247- [109, 8],
248- [3965, 13],
249- [116, 8],
250- [7933, 14],
251- [117, 8],
252- [8060, 14],
253- [220, 9],
254- [8061, 14],
255- [221, 9],
256- [8124, 14],
257- [236, 9],
258- [14332, 15],
259- [492, 10],
260- [493, 10],
261- [500, 10],
262- [957, 11],
263- [988, 11],
264- [989, 11],
265- [1004, 11],
266- [1005, 11],
267- [1012, 11],
268- [1917, 12],
269- [1980, 12],
270- [1981, 12],
271- [4028, 13],
272- [4029, 13],
273- [4060, 13],
274- [4061, 13],
275- [8125, 14],
276- [8156, 14],
277- [8157, 14],
278- [14333, 15],
279- [15356, 15],
280- [11, 4],
281- [120, 8],
282- [1013, 11],
283- [4076, 13],
284- [8172, 14],
285- [18, 5],
286- [237, 9],
287- [2012, 12],
288- [8173, 14],
289- [15357, 15],
290- [19, 5],
291- [1016, 11],
292- [15868, 15],
293- [24, 6],
294- [2013, 12],
295- [25, 6],
296- [2028, 12],
297- [34, 6],
298- [4077, 13],
299- [35, 6],
300- [4084, 13],
301- [53, 7],
302- [4085, 13],
303- [56, 7],
304- [4088, 13],
305- [57, 7],
306- [4089, 13],
307- [66, 7],
308- [8180, 14],
309- [67, 7],
310- [8181, 14],
311- [121, 8],
312- [8184, 14],
313- [130, 8],
314- [15869, 15],
315- [131, 8],
316- [244, 9],
317- [245, 9],
318- [248, 9],
319- [249, 9],
320- [258, 9],
321- [259, 9],
322- [501, 10],
323- [504, 10],
324- [505, 10],
325- [514, 10],
326- [515, 10],
327- [1017, 11],
328- [1026, 11],
329- [1027, 11],
330- [2029, 12],
331- [2036, 12],
332- [2037, 12],
333- [2040, 12],
334- [2041, 12],
335- [2050, 12],
336- [2051, 12],
337- [4098, 13],
338- [4099, 13],
339- [8185, 14],
340- [8194, 14],
341- [8195, 14],
342- [16124, 15],
343- [16125, 15],
344- [16252, 15],
345- [16253, 15],
346- [0, 4],
347-];
348-
349-pub const INTER_RVLC_RUN: [i8; 169] = [
350- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
351- 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9,
352- 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 19, 20, 21, 22, 23,
353- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2,
354- 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 16, 17,
355- 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
356- 42, 43, 44,
357-];
358-
359-pub const INTER_RVLC_LEVEL: [i8; 169] = [
360- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1, 2, 3, 4, 5, 6, 7, 8, 9,
361- 10, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3,
362- 4, 1, 2, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
363- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 1, 2, 1, 2, 1,
364- 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
365- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
366-];
367-
368-pub const INTRA_RVLC: [[u16; 2]; 170] = [
369- [6, 3],
370- [7, 3],
371- [10, 4],
372- [9, 5],
373- [20, 6],
374- [21, 6],
375- [52, 7],
376- [116, 8],
377- [117, 8],
378- [221, 9],
379- [236, 9],
380- [492, 10],
381- [493, 10],
382- [500, 10],
383- [1004, 11],
384- [1005, 11],
385- [1012, 11],
386- [1917, 12],
387- [1980, 12],
388- [4029, 13],
389- [4060, 13],
390- [1981, 12],
391- [4061, 13],
392- [8125, 14],
393- [8156, 14],
394- [8157, 14],
395- [8188, 15],
396- [1, 4],
397- [8, 5],
398- [45, 7],
399- [108, 8],
400- [109, 8],
401- [220, 9],
402- [477, 10],
403- [988, 11],
404- [989, 11],
405- [1916, 12],
406- [4028, 13],
407- [8061, 14],
408- [8124, 14],
409- [4, 5],
410- [44, 7],
411- [188, 9],
412- [476, 10],
413- [956, 11],
414- [957, 11],
415- [3837, 13],
416- [3964, 13],
417- [3965, 13],
418- [7933, 14],
419- [8060, 14],
420- [5, 5],
421- [92, 8],
422- [189, 9],
423- [893, 11],
424- [1788, 12],
425- [3836, 13],
426- [7677, 14],
427- [7932, 14],
428- [8189, 15],
429- [12, 6],
430- [93, 8],
431- [445, 10],
432- [1021, 12],
433- [1789, 12],
434- [7165, 14],
435- [13, 6],
436- [125, 9],
437- [764, 11],
438- [1532, 12],
439- [7164, 14],
440- [7676, 14],
441- [28, 7],
442- [380, 10],
443- [765, 11],
444- [1533, 12],
445- [12284, 15],
446- [29, 7],
447- [381, 10],
448- [892, 11],
449- [3581, 13],
450- [12285, 15],
451- [60, 8],
452- [444, 10],
453- [3069, 13],
454- [6141, 14],
455- [61, 8],
456- [509, 11],
457- [3580, 13],
458- [14332, 15],
459- [124, 9],
460- [1020, 12],
461- [252, 10],
462- [3068, 13],
463- [253, 10],
464- [14333, 15],
465- [508, 11],
466- [2044, 13],
467- [2045, 13],
468- [4092, 14],
469- [4093, 14],
470- [6140, 14],
471- [15356, 15],
472- [11, 4],
473- [120, 8],
474- [1013, 11],
475- [4076, 13],
476- [8172, 14],
477- [18, 5],
478- [237, 9],
479- [2012, 12],
480- [8173, 14],
481- [15357, 15],
482- [19, 5],
483- [1016, 11],
484- [15868, 15],
485- [24, 6],
486- [2013, 12],
487- [25, 6],
488- [2028, 12],
489- [34, 6],
490- [4077, 13],
491- [35, 6],
492- [4084, 13],
493- [53, 7],
494- [4085, 13],
495- [56, 7],
496- [4088, 13],
497- [57, 7],
498- [4089, 13],
499- [66, 7],
500- [8180, 14],
501- [67, 7],
502- [8181, 14],
503- [121, 8],
504- [8184, 14],
505- [130, 8],
506- [15869, 15],
507- [131, 8],
508- [244, 9],
509- [245, 9],
510- [248, 9],
511- [249, 9],
512- [258, 9],
513- [259, 9],
514- [501, 10],
515- [504, 10],
516- [505, 10],
517- [514, 10],
518- [515, 10],
519- [1017, 11],
520- [1026, 11],
521- [1027, 11],
522- [2029, 12],
523- [2036, 12],
524- [2037, 12],
525- [2040, 12],
526- [2041, 12],
527- [2050, 12],
528- [2051, 12],
529- [4098, 13],
530- [4099, 13],
531- [8185, 14],
532- [8194, 14],
533- [8195, 14],
534- [16124, 15],
535- [16125, 15],
536- [16252, 15],
537- [16253, 15],
538- [0, 4],
539-];
540-
541-pub const INTRA_RVLC_RUN: [i8; 169] = [
542- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
543- 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
544- 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11,
545- 12, 12, 13, 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6,
546- 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
547- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
548-];
549-
550-pub const INTRA_RVLC_LEVEL: [i8; 169] = [
551- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
552- 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2, 3, 4,
553- 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 1,
554- 2, 3, 4, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 1, 2, 1,
555- 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
556- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
557-];
558-
559175 pub const SPRITE_TRAJECTORY_LENS: [u8; 15] = [2, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
560176
561177 pub const MB_TYPE_B_TAB: [[u8; 2]; 4] = [[1, 1], [1, 2], [1, 3], [1, 4]];
@@ -590,14 +206,6 @@ pub const MPEG4_RL_INTRA_N: usize = 102;
590206
591207 pub const MPEG4_RL_INTRA_LAST: usize = 67;
592208
593-pub const RVLC_RL_INTER_N: usize = 169;
594-
595-pub const RVLC_RL_INTER_LAST: usize = 103;
596-
597-pub const RVLC_RL_INTRA_N: usize = 169;
598-
599-pub const RVLC_RL_INTRA_LAST: usize = 103;
600-
601209 #[cfg(test)]
602210 mod tests {
603211 use super::*;
@@ -629,10 +237,7 @@ mod tests {
629237 #[test]
630238 fn vlcs_prefix_free() {
631239 prefix_free("MPEG4_INTRA_VLC", &MPEG4_INTRA_VLC);
632- prefix_free("INTER_RVLC", &INTER_RVLC);
633- prefix_free("INTRA_RVLC", &INTRA_RVLC);
634240 prefix_free("INTER_VLC", &INTER_VLC);
635- prefix_free("INTRA_VLC_AIC", &INTRA_VLC_AIC);
636241 prefix_free("MVTAB", &to16(&MVTAB));
637242 prefix_free("H263_CBPY_TAB", &to16(&H263_CBPY_TAB));
638243 prefix_free("MPEG4_DCTAB_LUM", &to16(&MPEG4_DCTAB_LUM));
@@ -658,17 +263,4 @@ mod tests {
658263 is_perm(&ALTERNATE_HORIZONTAL_SCAN);
659264 is_perm(&ALTERNATE_VERTICAL_SCAN);
660265 }
661- #[test]
662- fn rl_lengths() {
663- assert_eq!(MPEG4_INTRA_RUN.len(), MPEG4_RL_INTRA_N);
664- assert_eq!(MPEG4_INTRA_LEVEL.len(), MPEG4_RL_INTRA_N);
665- assert_eq!(INTER_RUN.len(), H263_RL_INTER_N);
666- assert_eq!(INTER_LEVEL.len(), H263_RL_INTER_N);
667- assert_eq!(INTRA_RUN_AIC.len(), RL_INTRA_AIC_N);
668- assert_eq!(INTRA_LEVEL_AIC.len(), RL_INTRA_AIC_N);
669- assert_eq!(INTER_RVLC_RUN.len(), RVLC_RL_INTER_N);
670- assert_eq!(INTRA_RVLC_LEVEL.len(), RVLC_RL_INTRA_N);
671- assert_eq!(MPEG4_INTRA_VLC.len(), MPEG4_RL_INTRA_N + 1);
672- assert_eq!(INTER_RVLC.len(), RVLC_RL_INTER_N + 1);
673- }
674266 }
crates/ec-mpeg4/src/vlc.rsmodified+0 -27
@@ -108,12 +108,6 @@ pub struct Vlcs {
108108 pub mb_type_b: Vlc,
109109 pub rl_intra: Rl,
110110 pub rl_inter: Rl,
111- #[allow(dead_code)] // kept with the RVLC tables for data partitioning
112- pub rl_intra_aic: Rl,
113- #[allow(dead_code)]
114- pub rvlc_intra: Rl,
115- #[allow(dead_code)]
116- pub rvlc_inter: Rl,
117111 pub sprite_traj: Vlc,
118112 }
119113
@@ -151,27 +145,6 @@ pub fn vlcs() -> &'static Vlcs {
151145 H263_RL_INTER_N,
152146 H263_RL_INTER_LAST,
153147 ),
154- rl_intra_aic: Rl::new(
155- &INTRA_VLC_AIC,
156- &INTRA_RUN_AIC,
157- &INTRA_LEVEL_AIC,
158- RL_INTRA_AIC_N,
159- RL_INTRA_AIC_LAST,
160- ),
161- rvlc_intra: Rl::new(
162- &INTRA_RVLC,
163- &INTRA_RVLC_RUN,
164- &INTRA_RVLC_LEVEL,
165- RVLC_RL_INTRA_N,
166- RVLC_RL_INTRA_LAST,
167- ),
168- rvlc_inter: Rl::new(
169- &INTER_RVLC,
170- &INTER_RVLC_RUN,
171- &INTER_RVLC_LEVEL,
172- RVLC_RL_INTER_N,
173- RVLC_RL_INTER_LAST,
174- ),
175148 sprite_traj: {
176149 let mut c = Vec::new();
177150 let mut code = 0u32;