TrueHD: Atmos directory at 36 bytes, count from num_substreams (ffmpeg mlp_parse.c:71-74,160; mlpdec.c read_access_unit)
Browse files at this commit731634a6f1649d7f9bf27c275cdd918be1f1112dParent: 2c05ed82 changed files +13 -9
crates/ec-mpegts/src/track.rsmodified+8 -1
| @@ -90,6 +90,7 @@ pub(crate) struct TrueHdFacts { | |||
| 90 | pub rate: u32, | 90 | pub rate: u32, |
| 91 | pub layout: ChannelLayout, | 91 | pub layout: ChannelLayout, |
| 92 | pub samples: u32, | 92 | pub samples: u32, |
| 93 | + pub substreams: usize, | ||
| 93 | } | 94 | } |
| 94 | 95 | ||
| 95 | /// How the program-stream front end hands pictures over (see `psvideo`). | 96 | /// How the program-stream front end hands pictures over (see `psvideo`). |
| @@ -779,10 +780,15 @@ impl Track { | |||
| 779 | // The access unit goes on in the next PES. | 780 | // The access unit goes on in the next PES. |
| 780 | break; | 781 | break; |
| 781 | } | 782 | } |
| 782 | - let Ok(head) = AccessUnitHeader::parse(&rest[..len], 0) else { | 783 | + let streams = self.cfg.truehd.as_ref().map_or(0, |t| t.substreams); |
| 784 | + let Ok(head) = AccessUnitHeader::parse(&rest[..len], streams) else { | ||
| 783 | cur += 1; | 785 | cur += 1; |
| 784 | continue; | 786 | continue; |
| 785 | }; | 787 | }; |
| 788 | + if head.substreams.is_empty() { | ||
| 789 | + cur += 1; | ||
| 790 | + continue; | ||
| 791 | + } | ||
| 786 | if let Some(m) = head.major_sync | 792 | if let Some(m) = head.major_sync |
| 787 | && let Ok(layout) = head.channel_layout() | 793 | && let Ok(layout) = head.channel_layout() |
| 788 | { | 794 | { |
| @@ -791,6 +797,7 @@ impl Track { | |||
| 791 | layout, | 797 | layout, |
| 792 | // A major sync's rate code sizes the access units: 40 << n samples. | 798 | // A major sync's rate code sizes the access units: 40 << n samples. |
| 793 | samples: 40 << (m.rate_code & 7), | 799 | samples: 40 << (m.rate_code & 7), |
| 800 | + substreams: head.substreams.len(), | ||
| 794 | }); | 801 | }); |
| 795 | } | 802 | } |
| 796 | if cur >= new_start && !anchored && p.pts.is_some() { | 803 | if cur >= new_start && !anchored && p.pts.is_some() { |
crates/ec-truehd/src/sync.rsmodified+5 -8
| @@ -121,10 +121,9 @@ pub struct MajorSyncInfo { | |||
| 121 | /// L/R, 1 = C, 2 = LFE, 3 = Ls/Rs, 6 = Lrs/Rrs; `0x4F` is standard 7.1); | 121 | /// L/R, 1 = C, 2 = LFE, 3 = Ls/Rs, 6 = Lrs/Rrs; `0x4F` is standard 7.1); |
| 122 | /// 0 when the major sync is plain MLP, which has no such field. | 122 | /// 0 when the major sync is plain MLP, which has no such field. |
| 123 | pub ch8_assignment: u16, | 123 | pub ch8_assignment: u16, |
| 124 | - /// Substreams in the access unit's directory (the major sync's | 124 | + /// Substreams in the directory: the top nibble of `data[16]`. |
| 125 | - /// `num_substreams`, top nibble of `data[16]`). | ||
| 126 | pub num_substreams: usize, | 125 | pub num_substreams: usize, |
| 127 | - /// Bytes the major sync occupies, its extension block and checksum included. | 126 | + /// Bytes the major sync occupies, extension block and checksum included. |
| 128 | pub len: usize, | 127 | pub len: usize, |
| 129 | } | 128 | } |
| 130 | 129 | ||
| @@ -220,9 +219,7 @@ pub struct AccessUnitHeader { | |||
| 220 | 219 | ||
| 221 | impl AccessUnitHeader { | 220 | impl AccessUnitHeader { |
| 222 | /// Parses one access unit's header from `data`, which must hold at least | 221 | /// Parses one access unit's header from `data`, which must hold at least |
| 223 | - /// [`frame_length`]'s worth of bytes. `stream_substreams` is the substream | 222 | + /// [`frame_length`]'s worth of bytes. |
| 224 | - /// count the stream's last major sync declared (0 before any); a unit with | ||
| 225 | - /// its own major sync uses that sync's count instead. | ||
| 226 | pub fn parse(data: &[u8], stream_substreams: usize) -> Result<AccessUnitHeader> { | 223 | pub fn parse(data: &[u8], stream_substreams: usize) -> Result<AccessUnitHeader> { |
| 227 | let length = frame_length(data)?; | 224 | let length = frame_length(data)?; |
| 228 | if data.len() < length { | 225 | if data.len() < length { |
| @@ -423,8 +420,8 @@ mod tests { | |||
| 423 | ]; | 420 | ]; |
| 424 | au.extend_from_slice(&MAJOR_SYNC_TRUEHD.to_be_bytes()); | 421 | au.extend_from_slice(&MAJOR_SYNC_TRUEHD.to_be_bytes()); |
| 425 | au.push(0x0F); // sample rate: group1 code 0 (48000), group2 0xF (absent) | 422 | au.push(0x0F); // sample rate: group1 code 0 (48000), group2 0xF (absent) |
| 426 | - let mut rest = [0u8; 23]; // rest of the major sync, unused here | 423 | + let mut rest = [0u8; 23]; |
| 427 | - rest[11] = 0x20; // num_substreams = 2 (byte 16's top nibble) | 424 | + rest[11] = 0x20; |
| 428 | au.extend_from_slice(&rest); | 425 | au.extend_from_slice(&rest); |
| 429 | au.extend_from_slice(&[0x00, 0x01]); // substream 0: end +1 word (not the last) | 426 | au.extend_from_slice(&[0x00, 0x01]); // substream 0: end +1 word (not the last) |
| 430 | au.extend_from_slice(&[0x00, 0x04]); // substream 1: end +4 words (lands on EOF) | 427 | au.extend_from_slice(&[0x00, 0x04]); // substream 1: end +4 words (lands on EOF) |