diff --git a/crates/ec-mpegts/src/track.rs b/crates/ec-mpegts/src/track.rs index 2e74a7c8..fc6f59e9 100644 --- a/crates/ec-mpegts/src/track.rs +++ b/crates/ec-mpegts/src/track.rs @@ -90,6 +90,7 @@ pub(crate) struct TrueHdFacts { pub rate: u32, pub layout: ChannelLayout, pub samples: u32, + pub substreams: usize, } /// How the program-stream front end hands pictures over (see `psvideo`). @@ -779,10 +780,15 @@ impl Track { // The access unit goes on in the next PES. break; } - let Ok(head) = AccessUnitHeader::parse(&rest[..len], 0) else { + let streams = self.cfg.truehd.as_ref().map_or(0, |t| t.substreams); + let Ok(head) = AccessUnitHeader::parse(&rest[..len], streams) else { cur += 1; continue; }; + if head.substreams.is_empty() { + cur += 1; + continue; + } if let Some(m) = head.major_sync && let Ok(layout) = head.channel_layout() { @@ -791,6 +797,7 @@ impl Track { layout, // A major sync's rate code sizes the access units: 40 << n samples. samples: 40 << (m.rate_code & 7), + substreams: head.substreams.len(), }); } if cur >= new_start && !anchored && p.pts.is_some() { diff --git a/crates/ec-truehd/src/sync.rs b/crates/ec-truehd/src/sync.rs index 5ea77428..0886f33f 100644 --- a/crates/ec-truehd/src/sync.rs +++ b/crates/ec-truehd/src/sync.rs @@ -121,10 +121,9 @@ pub struct MajorSyncInfo { /// L/R, 1 = C, 2 = LFE, 3 = Ls/Rs, 6 = Lrs/Rrs; `0x4F` is standard 7.1); /// 0 when the major sync is plain MLP, which has no such field. pub ch8_assignment: u16, - /// Substreams in the access unit's directory (the major sync's - /// `num_substreams`, top nibble of `data[16]`). + /// Substreams in the directory: the top nibble of `data[16]`. pub num_substreams: usize, - /// Bytes the major sync occupies, its extension block and checksum included. + /// Bytes the major sync occupies, extension block and checksum included. pub len: usize, } @@ -220,9 +219,7 @@ pub struct AccessUnitHeader { impl AccessUnitHeader { /// Parses one access unit's header from `data`, which must hold at least - /// [`frame_length`]'s worth of bytes. `stream_substreams` is the substream - /// count the stream's last major sync declared (0 before any); a unit with - /// its own major sync uses that sync's count instead. + /// [`frame_length`]'s worth of bytes. pub fn parse(data: &[u8], stream_substreams: usize) -> Result { let length = frame_length(data)?; if data.len() < length { @@ -423,8 +420,8 @@ mod tests { ]; au.extend_from_slice(&MAJOR_SYNC_TRUEHD.to_be_bytes()); au.push(0x0F); // sample rate: group1 code 0 (48000), group2 0xF (absent) - let mut rest = [0u8; 23]; // rest of the major sync, unused here - rest[11] = 0x20; // num_substreams = 2 (byte 16's top nibble) + let mut rest = [0u8; 23]; + rest[11] = 0x20; au.extend_from_slice(&rest); au.extend_from_slice(&[0x00, 0x01]); // substream 0: end +1 word (not the last) au.extend_from_slice(&[0x00, 0x04]); // substream 1: end +4 words (lands on EOF)