forge
Explore
Log in

Don't you dare go Hollow

U18: ec-mp4 drop dead h264_split_annex_b, H264Split, av1c_record and the unused count_of file_len parameter (no caller in edith or yumush)

Browse files at this commit

80574320122ec83144518973f48f3d7ed10cc0c8Ahmet Kaan GümüşParent: 3bb98ab
crates/ec-mp4/src/config.rsmodified+0 -50
@@ -1,45 +1,10 @@
1 //! Turns encoder output (Annex-B) into mp4 samples and sample-entry config records.1 //! Turns encoder output (Annex-B) into mp4 samples and sample-entry config records.
2 2
3-const NAL_IDR: u8 = 5;
4-const NAL_SEI: u8 = 6;
5-const NAL_SPS: u8 = 7;
6-const NAL_PPS: u8 = 8;
7-const NAL_AUD: u8 = 9;
8-
9 const HEVC_VPS: u8 = 32;3 const HEVC_VPS: u8 = 32;
10 const HEVC_SPS: u8 = 33;4 const HEVC_SPS: u8 = 33;
11 const HEVC_PPS: u8 = 34;5 const HEVC_PPS: u8 = 34;
12 const HEVC_AUD: u8 = 35;6 const HEVC_AUD: u8 = 35;
13 7
14-const AV1C_HEAD: [u8; 4] = [0x81, 0x1F, 0x0C, 0x00];
15-
16-/// An H.264 sample, whether it is an IDR, and its first SPS and PPS when present.
17-pub type H264Split = (Vec<u8>, bool, Option<(Vec<u8>, Vec<u8>)>);
18-
19-/// Splits an H.264 Annex-B access unit into a length-prefixed sample.
20-///
21-/// SPS, PPS, AUD and SEI are stripped from the sample. `None` when the unit holds no coded slice.
22-pub fn h264_split_annex_b(annex_b: &[u8]) -> Option<H264Split> {
23- let nals = split_annex_b(annex_b);
24- let first = |kind: u8| nals.iter().copied().find(|n| nal_type(n) == kind);
25- let params = match (first(NAL_SPS), first(NAL_PPS)) {
26- (Some(sps), Some(pps)) => Some((sps.to_vec(), pps.to_vec())),
27- _ => None,
28- };
29- let mut out = Vec::with_capacity(annex_b.len());
30- let mut is_idr = false;
31- for nal in nals {
32- match nal_type(nal) {
33- NAL_SPS | NAL_PPS | NAL_AUD | NAL_SEI => continue,
34- NAL_IDR => is_idr = true,
35- _ => {}
36- }
37- out.extend_from_slice(&(nal.len() as u32).to_be_bytes());
38- out.extend_from_slice(nal);
39- }
40- (!out.is_empty()).then_some((out, is_idr, params))
41-}
42-
43 /// An H.264 `AVCDecoderConfigurationRecord` for one SPS and one PPS, with four-byte NAL length prefixes.8 /// An H.264 `AVCDecoderConfigurationRecord` for one SPS and one PPS, with four-byte NAL length prefixes.
44 pub fn avcc_record(sps: &[u8], pps: &[u8]) -> Vec<u8> {9 pub fn avcc_record(sps: &[u8], pps: &[u8]) -> Vec<u8> {
45 let profile = sps.get(1..4).unwrap_or(&[0, 0, 0]);10 let profile = sps.get(1..4).unwrap_or(&[0, 0, 0]);
@@ -112,17 +77,6 @@ pub fn annex_b_to_hvcc(annex_b: &[u8]) -> Option<Vec<u8>> {
112 (!out.is_empty()).then_some(out)77 (!out.is_empty()).then_some(out)
113 }78 }
114 79
115-/// An `av1C` record: the four fixed bytes, then the sequence header OBU as the config OBUs.
116-pub fn av1c_record(ten_bit: bool, config_obus: &[u8]) -> Vec<u8> {
117- let mut head = AV1C_HEAD;
118- if ten_bit {
119- head[2] |= 0x40;
120- }
121- let mut out = head.to_vec();
122- out.extend_from_slice(config_obus);
123- out
124-}
125-
126 fn hevc_nal_type(nal: &[u8]) -> u8 {80 fn hevc_nal_type(nal: &[u8]) -> u8 {
127 nal.first().map_or(0xFF, |b| (b >> 1) & 0x3F)81 nal.first().map_or(0xFF, |b| (b >> 1) & 0x3F)
128 }82 }
@@ -165,7 +119,3 @@ fn push_nal<'a>(nals: &mut Vec<&'a [u8]>, nal: &'a [u8]) {
165 nals.push(&nal[..end]);119 nals.push(&nal[..end]);
166 }120 }
167 }121 }
168-
169-fn nal_type(nal: &[u8]) -> u8 {
170- nal.first().map_or(0, |b| b & 0x1F)
171-}
crates/ec-mp4/src/demux.rsmodified+6 -6
@@ -960,7 +960,7 @@ impl<'a> SampleTable<'a> {
960 }960 }
961 b"stsc" => {961 b"stsc" => {
962 let (_, _, rest) = full(payload)?;962 let (_, _, rest) = full(payload)?;
963- let count = count_of(rest, 12, file_len)?;963+ let count = count_of(rest, 12)?;
964 me.stsc = Vec::with_capacity(count);964 me.stsc = Vec::with_capacity(count);
965 for i in 0..count {965 for i in 0..count {
966 me.stsc966 me.stsc
@@ -987,7 +987,7 @@ impl<'a> SampleTable<'a> {
987 }987 }
988 b"co64" => {988 b"co64" => {
989 let (_, _, rest) = full(payload)?;989 let (_, _, rest) = full(payload)?;
990- let count = count_of(rest, 8, file_len)?;990+ let count = count_of(rest, 8)?;
991 me.chunks = Vec::with_capacity(count);991 me.chunks = Vec::with_capacity(count);
992 for i in 0..count {992 for i in 0..count {
993 me.chunks.push(be64(rest, 4 + i * 8)?);993 me.chunks.push(be64(rest, 4 + i * 8)?);
@@ -1731,7 +1731,7 @@ fn unpack_language(packed: u16) -> Option<String> {
1731 /// The `(count, value)` pairs of an `stts`/`ctts` table.1731 /// The `(count, value)` pairs of an `stts`/`ctts` table.
1732 fn pairs<T>(payload: &[u8], make: impl Fn(u32, u32) -> T) -> Result<Vec<T>> {1732 fn pairs<T>(payload: &[u8], make: impl Fn(u32, u32) -> T) -> Result<Vec<T>> {
1733 let (_, _, rest) = full(payload)?;1733 let (_, _, rest) = full(payload)?;
1734- let count = count_of(rest, 8, u64::MAX)?;1734+ let count = count_of(rest, 8)?;
1735 let mut out = Vec::with_capacity(count);1735 let mut out = Vec::with_capacity(count);
1736 for i in 0..count {1736 for i in 0..count {
1737 out.push(make(be32(rest, 4 + i * 8)?, be32(rest, 8 + i * 8)?));1737 out.push(make(be32(rest, 4 + i * 8)?, be32(rest, 8 + i * 8)?));
@@ -1741,7 +1741,7 @@ fn pairs<T>(payload: &[u8], make: impl Fn(u32, u32) -> T) -> Result<Vec<T>> {
1741 1741
1742 /// The `u32` table of an `stss`/`stco`.1742 /// The `u32` table of an `stss`/`stco`.
1743 fn words(rest: &[u8]) -> Result<Vec<u32>> {1743 fn words(rest: &[u8]) -> Result<Vec<u32>> {
1744- let count = count_of(rest, 4, u64::MAX)?;1744+ let count = count_of(rest, 4)?;
1745 let mut out = Vec::with_capacity(count);1745 let mut out = Vec::with_capacity(count);
1746 for i in 0..count {1746 for i in 0..count {
1747 out.push(be32(rest, 4 + i * 4)?);1747 out.push(be32(rest, 4 + i * 4)?);
@@ -1751,7 +1751,7 @@ fn words(rest: &[u8]) -> Result<Vec<u32>> {
1751 1751
1752 /// An entry count, refused when the entries it claims do not fit the box it is1752 /// An entry count, refused when the entries it claims do not fit the box it is
1753 /// in — the one check that keeps a crafted count from being allocated.1753 /// in — the one check that keeps a crafted count from being allocated.
1754-fn count_of(rest: &[u8], width: usize, _file_len: u64) -> Result<usize> {1754+fn count_of(rest: &[u8], width: usize) -> Result<usize> {
1755 let count = be32(rest, 0)? as usize;1755 let count = be32(rest, 0)? as usize;
1756 let have = rest.len().saturating_sub(4) / width;1756 let have = rest.len().saturating_sub(4) / width;
1757 if count > have {1757 if count > have {
@@ -1798,7 +1798,7 @@ fn display_rotation(a: i32, b: i32, c: i32, d: i32) -> Rotation {
1798 fn elst(payload: &[u8]) -> Result<Vec<(u64, i64, u32)>> {1798 fn elst(payload: &[u8]) -> Result<Vec<(u64, i64, u32)>> {
1799 let (version, _, rest) = full(payload)?;1799 let (version, _, rest) = full(payload)?;
1800 let width = if version == 0 { 12 } else { 20 };1800 let width = if version == 0 { 12 } else { 20 };
1801- let count = count_of(rest, width, u64::MAX)?;1801+ let count = count_of(rest, width)?;
1802 let mut out = Vec::with_capacity(count);1802 let mut out = Vec::with_capacity(count);
1803 for i in 0..count {1803 for i in 0..count {
1804 let at = 4 + i * width;1804 let at = 4 + i * width;