forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB86fb0f3Tahinli6 days ago3927 commits

fuzz_api.rs50 lines, 1.6 KiBHistoryRawDownload
1//! Entry points the fuzz targets reach below the public API. Hidden from the
2//! docs; not a stable interface.
3
4use crate::{codec, demux, psi, ts};
5
6/// `buf` as a stream of PSI sections split over packets, then PAT and PMT parsers.
7pub fn psi(buf: &[u8]) -> usize {
8 let mut sections = psi::SectionBuf::default();
9 let mut out = Vec::new();
10 for (i, chunk) in buf.chunks(184).enumerate() {
11 sections.push(i % 3 == 0, chunk, &mut out);
12 }
13 let _ = psi::parse_pat(buf);
14 let _ = psi::parse_pmt(buf);
15 out.len()
16}
17
18/// `buf` as one PES packet header.
19pub fn pes(buf: &[u8]) -> bool {
20 demux::parse_pes(buf).is_some()
21}
22
23/// `buf` as an Annex-B access unit: NAL scan, config records, length-prefixing.
24pub fn access_unit(buf: &[u8]) -> usize {
25 let a = codec::scan_au(buf, false);
26 let b = codec::scan_au(buf, true);
27 let _ = codec::build_avcc(&a.sps, &a.pps);
28 let _ = codec::build_hvcc(&b.vps, &b.sps, &b.pps);
29 let _ = codec::annexb_to_length_prefixed(buf, 4);
30 codec::nal_units(buf).count()
31}
32
33/// `buf` as audio frame headers and the LPCM header.
34pub fn audio_headers(buf: &[u8]) -> usize {
35 let mut n = 0;
36 for i in 0..buf.len().min(64) {
37 let b = &buf[i..];
38 n += usize::from(codec::adts_header(b).is_some());
39 n += usize::from(codec::ac3_header(b).is_some());
40 n += usize::from(codec::mpa_header(b).is_some());
41 n += usize::from(codec::parse_lpcm_header(b).is_some());
42 }
43 n
44}
45
46/// `buf` as the head of a transport stream: layout detection and the first packet.
47pub fn packet_layer(buf: &[u8]) -> bool {
48 let _ = ts::parse(buf);
49 ts::detect(buf).is_some()
50}