mux: Rust 1.86 compat + fmt

- m2ts_mux: replace u64::is_multiple_of (stable in 1.87+) with %.
  CI on the pinned 1.86 toolchain rejected the unstable feature use.
- mux/{fmp4,hevc,m2ts_mux}: rustfmt drift cleanup (test-code wrapping).
This commit is contained in:
MattJackson
2026-05-13 20:30:01 -07:00
parent 6ca62b8411
commit 52eeb949e3
3 changed files with 21 additions and 7 deletions
+2 -1
View File
@@ -356,7 +356,8 @@ mod tests {
let mut sink: Vec<u8> = Vec::new(); let mut sink: Vec<u8> = Vec::new();
let mut mux = Fmp4Mux::new(&mut sink); let mut mux = Fmp4Mux::new(&mut sink);
// Trigger init emission via a single (stubbed) write. // Trigger init emission via a single (stubbed) write.
mux.write_video(0, true, &[0x00, 0x00, 0x00, 0x01, 0x40]).unwrap(); mux.write_video(0, true, &[0x00, 0x00, 0x00, 0x01, 0x40])
.unwrap();
mux.finish().unwrap(); mux.finish().unwrap();
drop(mux); drop(mux);
+5 -1
View File
@@ -222,7 +222,11 @@ mod tests {
// we can spot in the output. // we can spot in the output.
let mut hvcc = vec![0u8; 22]; let mut hvcc = vec![0u8; 22];
hvcc.push(3); // numOfArrays hvcc.push(3); // numOfArrays
for (nal_type, payload) in [(32u8, [0x40, 0x01, 0x0C, 0x01]), (33, [0x42, 0x01, 0x01, 0x01]), (34, [0x44, 0x01, 0xC1, 0x72])] { for (nal_type, payload) in [
(32u8, [0x40, 0x01, 0x0C, 0x01]),
(33, [0x42, 0x01, 0x01, 0x01]),
(34, [0x44, 0x01, 0xC1, 0x72]),
] {
hvcc.push(nal_type & 0x3F); hvcc.push(nal_type & 0x3F);
hvcc.extend_from_slice(&1u16.to_be_bytes()); // numNalus hvcc.extend_from_slice(&1u16.to_be_bytes()); // numNalus
hvcc.extend_from_slice(&(payload.len() as u16).to_be_bytes()); hvcc.extend_from_slice(&(payload.len() as u16).to_be_bytes());
+14 -5
View File
@@ -247,7 +247,8 @@ impl<W: Write> M2tsMux<W> {
let attach_pcr = first let attach_pcr = first
&& (pid == PID_VIDEO) && (pid == PID_VIDEO)
&& (pcr.is_some()) && (pcr.is_some())
&& (self.packets_written == 0 || self.video_packets_since_pcr >= PCR_INTERVAL_PACKETS); && (self.packets_written == 0
|| self.video_packets_since_pcr >= PCR_INTERVAL_PACKETS);
let af_body: Vec<u8> = if attach_pcr { let af_body: Vec<u8> = if attach_pcr {
build_pcr_adaptation(pcr.unwrap_or(0)) build_pcr_adaptation(pcr.unwrap_or(0))
@@ -317,7 +318,7 @@ impl<W: Write> M2tsMux<W> {
} }
fn maybe_emit_psi(&mut self) -> io::Result<()> { fn maybe_emit_psi(&mut self) -> io::Result<()> {
if self.packets_written == 0 || self.packets_written.is_multiple_of(PSI_INTERVAL_PACKETS) { if self.packets_written == 0 || self.packets_written % PSI_INTERVAL_PACKETS == 0 {
self.emit_pat()?; self.emit_pat()?;
self.emit_pmt()?; self.emit_pmt()?;
} }
@@ -547,7 +548,12 @@ mod tests {
/// All emitted bytes must align to 188-byte packet boundaries and /// All emitted bytes must align to 188-byte packet boundaries and
/// every packet must start with `0x47`. /// every packet must start with `0x47`.
fn assert_ts_well_formed(buf: &[u8]) { fn assert_ts_well_formed(buf: &[u8]) {
assert_eq!(buf.len() % 188, 0, "stream not packet-aligned: {} bytes", buf.len()); assert_eq!(
buf.len() % 188,
0,
"stream not packet-aligned: {} bytes",
buf.len()
);
for (i, chunk) in buf.chunks(188).enumerate() { for (i, chunk) in buf.chunks(188).enumerate() {
assert_eq!(chunk[0], 0x47, "packet {} missing sync byte", i); assert_eq!(chunk[0], 0x47, "packet {} missing sync byte", i);
} }
@@ -567,7 +573,9 @@ mod tests {
// than hardcoding sample bytes, verify the underlying algorithm // than hardcoding sample bytes, verify the underlying algorithm
// by checking that two distinct inputs produce distinct CRCs // by checking that two distinct inputs produce distinct CRCs
// and that the same input is deterministic. // and that the same input is deterministic.
let a = [0u8, 0xB0, 0x0D, 0x00, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x01, 0xE1, 0x00]; let a = [
0u8, 0xB0, 0x0D, 0x00, 0x01, 0xC1, 0x00, 0x00, 0x00, 0x01, 0xE1, 0x00,
];
let mut b = a; let mut b = a;
b[5] ^= 0x01; // flip one bit b[5] ^= 0x01; // flip one bit
let crc_a = mpegts_crc32(&a); let crc_a = mpegts_crc32(&a);
@@ -612,7 +620,8 @@ mod tests {
frame.extend_from_slice(&3u32.to_be_bytes()); frame.extend_from_slice(&3u32.to_be_bytes());
frame.extend_from_slice(&[0x40, 0x01, 0x0C]); frame.extend_from_slice(&[0x40, 0x01, 0x0C]);
mux.write_video(0, &frame).unwrap(); mux.write_video(0, &frame).unwrap();
mux.write_audio(20_000_000, &[0x0B, 0x77, 0x12, 0x34]).unwrap(); mux.write_audio(20_000_000, &[0x0B, 0x77, 0x12, 0x34])
.unwrap();
mux.finish().unwrap(); mux.finish().unwrap();
drop(mux); drop(mux);