forge
Explore
Log in

Don't you dare go Hollow

Merge remote-tracking branch 'origin/main' into worktree-agent-ab6959260e5ee211c

Browse files at this commit

2eb309bf0bde0131ee43648e308aef040682592fAhmet Kaan GümüşParent: 0776b469633c84
# Conflicts:
#	scripts/gen_fixtures.sh
crates/engine-hw/src/lib.rsmodified+4 -3
@@ -59,7 +59,8 @@ type Handle = <Dec<H264> as StatelessVideoDecoder>::Handle;
5959 /// still loads and still decodes H.264 (it simply refuses the newer codecs'
6060 /// files at `Demuxer`).
6161 ///
62-/// 4:2:0 only, 8- or 10-bit: HEVC Main and Main 10, VP9 profile 0, AV1 Main.
62+/// 4:2:0 only, 8- or 10-bit: HEVC Main and Main 10, VP9 profile 0, AV1 Main at
63+/// either depth.
6364 /// A 10-bit stream decodes into a P010 pool and is read back down to the 8-bit
6465 /// I420 every frame here is ([`Session::emit`]).
6566 ///
@@ -67,8 +68,8 @@ type Handle = <Dec<H264> as StatelessVideoDecoder>::Handle;
6768 /// interface all the way to the renderer. That costs the low two bits of a Main
6869 /// 10 source; the upgrade path is a 16-bit `VhFrame`, which is a change to every
6970 /// stage between here and the texture upload, not to this file.
70-/// VP9 profile 2 and 10-bit AV1 are still refused by `Demuxer`: neither codec
71-/// states its depth where this reads it.
71+/// VP9 profile 2 is still refused by `Demuxer`: a VP9 stream does not state its
72+/// depth where that reads it (an `av1C` and an `hvcC` both do).
7273 enum Decoder {
7374 H264(Dec<H264>),
7475 Hevc(Dec<H265>),
crates/engine/src/demux.rsmodified+46 -24
@@ -103,9 +103,10 @@ impl Demuxer {
103103 }
104104
105105 /// Bits per luma sample the stream is coded at: 8 for everything but an
106- /// HEVC Main 10 track, which decodes into a P010 surface rather than an
107- /// NV12 one. Not part of [`VideoMeta`] because nothing above the plugin has
108- /// a use for it -- what comes out of the read-back is 8-bit either way.
106+ /// HEVC Main 10 or a 10-bit AV1 track, which decode into a P010 surface
107+ /// rather than an NV12 one. Not part of [`VideoMeta`] because nothing above
108+ /// the plugin has a use for it -- what comes out of the read-back is 8-bit
109+ /// either way.
109110 pub fn bit_depth(&self) -> u8 {
110111 match self {
111112 Self::Mp4(d) => d.bit_depth,
@@ -234,7 +235,9 @@ impl Mp4Demuxer {
234235 let (_, entry) = sample_entry(path, track_id)?;
235236 let av1c = child(entry.get(78..).unwrap_or_default(), b"av1C")
236237 .ok_or("no av1C box in the AV1 sample entry")?;
237- parameter_sets = parse_av1c(av1c)?;
238+ let (sets, depth) = parse_av1c(av1c)?;
239+ parameter_sets = sets;
240+ bit_depth = depth;
238241 }
239242 // No parameter sets: a VP9 sample is self-contained.
240243 Codec::Vp9 => {}
@@ -733,7 +736,10 @@ fn mkv_track_entry(
733736 // `av1C` for AV1 and an `hvcC` for HEVC, byte for byte the one an mp4
734737 // sample entry carries, so it parses with the very same reader.
735738 let (codec, nal_length, config, bit_depth) = match (kind, codec.as_str()) {
736- (1, "V_AV1") => (Codec::Av1, 4, parse_av1c(&config)?, 8),
739+ (1, "V_AV1") => {
740+ let (sets, bit_depth) = parse_av1c(&config)?;
741+ (Codec::Av1, 4, sets, bit_depth)
742+ }
737743 (1, "V_MPEGH/ISO/HEVC") => {
738744 let (nal_length, sets, bit_depth) = parse_hvcc(&config)?;
739745 (Codec::Hevc, nal_length, sets, bit_depth)
@@ -808,25 +814,33 @@ fn parse_avcc(rec: &[u8]) -> crate::Result<(usize, Vec<u8>)> {
808814 /// §2.3.3): four fixed bytes, then the sequence header OBU in the same
809815 /// low-overhead format the blocks are in, so it needs no reframing.
810816 ///
817+/// Also the bits per luma sample, out of `high_bitdepth`/`twelve_bit` in byte 2:
818+/// 10-bit decodes through the P010 pool HEVC Main 10 already goes through
819+/// ([`crate::hw`]), 12-bit is refused by name because that pool is the only
820+/// deeper one there is.
821+///
811822 /// An empty record is not an error -- an encoder that repeats its sequence
812-/// header in-band needs none -- but a 10- or 12-bit one is refused by name, for
813-/// the same reason HEVC Main 10 is: the plugin's NV12 pool and its `vaGetImage`
814-/// read-back are 8-bit, and the upgrade path is a P010 pool.
815-fn parse_av1c(rec: &[u8]) -> crate::Result<Vec<u8>> {
823+/// header in-band needs none -- and is taken as 8-bit, which is what the depth
824+/// defaults to everywhere else here.
825+fn parse_av1c(rec: &[u8]) -> crate::Result<(Vec<u8>, u8)> {
816826 if rec.is_empty() {
817- return Ok(Vec::new());
827+ return Ok((Vec::new(), 8));
818828 }
819829 let &flags = rec
820830 .get(2)
821831 .ok_or("av1C record shorter than its fixed header")?;
822- if flags & 0x40 != 0 {
823- return Err(format!(
824- "{}-bit AV1 is not supported yet — this file is not 8-bit",
825- if flags & 0x20 != 0 { 12 } else { 10 }
826- )
827- .into());
828- }
829- Ok(rec.get(4..).unwrap_or_default().to_vec())
832+ // `twelve_bit` only says anything when `high_bitdepth` is set (AV1 §5.5.1),
833+ // so it is read where the record means it and nowhere else.
834+ let bit_depth = match (flags & 0x40 != 0, flags & 0x20 != 0) {
835+ (true, true) => {
836+ return Err(
837+ "12-bit AV1 is not supported — 8- and 10-bit are what the decoder carries".into(),
838+ );
839+ }
840+ (true, false) => 10,
841+ _ => 8,
842+ };
843+ Ok((rec.get(4..).unwrap_or_default().to_vec(), bit_depth))
830844 }
831845
832846 /// Every block of track `number`, in storage order, with the presentation span
@@ -1618,8 +1632,9 @@ mod tests {
16181632 }
16191633
16201634 /// The `av1C` record: four fixed bytes and then the sequence header OBU,
1621- /// which is handed to the decoder as it stands. 10-bit is refused by name
1622- /// exactly as HEVC Main 10 is, and for the same 8-bit read-back reason.
1635+ /// which is handed to the decoder as it stands, and the depth beside it --
1636+ /// 10-bit reads as 10 (the P010 pool, exactly as HEVC Main 10), 12-bit is
1637+ /// refused by name.
16231638 #[test]
16241639 fn reads_the_sequence_header_out_of_an_av1c_record() {
16251640 // marker/version, profile 0 + level 5, 8-bit 4:2:0, no delay; then a
@@ -1628,14 +1643,16 @@ mod tests {
16281643 rec.extend_from_slice(&[
16291644 0x0A, 0x0B, 0x00, 0x00, 0x00, 0x2D, 0x4C, 0xFF, 0xB3, 0xC0, 0x2F, 0x80, 0x00,
16301645 ]);
1631- let config = parse_av1c(&rec).unwrap();
1646+ let (config, depth) = parse_av1c(&rec).unwrap();
16321647 assert_eq!(config, rec[4..], "the fixed header is not part of the OBUs");
16331648 assert_eq!((config[0] >> 3) & 0xF, 1, "OBU type 1 is a sequence header");
1649+ assert_eq!(depth, 8);
16341650
16351651 let mut ten = rec.clone();
16361652 ten[2] |= 0x40; // high_bitdepth
1637- let refused = parse_av1c(&ten).unwrap_err().to_string();
1638- assert!(refused.contains("10-bit"), "{refused}");
1653+ let (ten_config, ten_depth) = parse_av1c(&ten).unwrap();
1654+ assert_eq!(ten_depth, 10, "what picks the P010 surface pool");
1655+ assert_eq!(ten_config, config, "the OBUs are read the same either way");
16391656 let mut twelve = ten.clone();
16401657 twelve[2] |= 0x20; // twelve_bit
16411658 assert!(
@@ -1644,10 +1661,15 @@ mod tests {
16441661 .to_string()
16451662 .contains("12-bit")
16461663 );
1664+ // `twelve_bit` without `high_bitdepth` says nothing, and an 8-bit
1665+ // record reads as one whatever that bit holds.
1666+ let mut stray = rec.clone();
1667+ stray[2] |= 0x20;
1668+ assert_eq!(parse_av1c(&stray).unwrap().1, 8);
16471669
16481670 // An encoder that repeats its sequence header in-band writes no record
16491671 // at all, which is not an error; a truncated one is.
1650- assert!(parse_av1c(&[]).unwrap().is_empty());
1672+ assert!(parse_av1c(&[]).unwrap().0.is_empty());
16511673 assert!(parse_av1c(&[0x81, 0x05]).is_err());
16521674 }
16531675
crates/engine/tests/av1.rsmodified+48 -0
@@ -57,6 +57,23 @@ fn the_demuxer_reports_an_av1_track_in_matroska() {
5757 assert_eq!(vp9.codec, Codec::Vp9);
5858 }
5959
60+/// The depth, which is what picks the surface pool the plugin decodes into: an
61+/// `av1C` with `high_bitdepth` set reads as 10 and takes the P010 pool HEVC Main
62+/// 10 already goes through, and the 8-bit fixture beside it still reads as 8.
63+/// It used to be an outright refusal at open ("10-bit AV1 is not supported").
64+#[test]
65+fn a_ten_bit_av1_track_is_read_as_ten_bit() {
66+ let (meta, ten) = Demuxer::open(&asset("test_av1_10.mkv")).expect("open test_av1_10.mkv");
67+ assert_eq!(meta.codec, Codec::Av1);
68+ assert_eq!((meta.width, meta.height), (1280, 720));
69+ assert_eq!(meta.frame_count, FRAMES);
70+ assert_eq!(ten.bit_depth(), 10, "what picks the P010 surface pool");
71+
72+ // The invariant: the 8-bit file is untouched by any of it.
73+ let (_, eight) = Demuxer::open(&asset("test_av1.mkv")).expect("open test_av1.mkv");
74+ assert_eq!(eight.bit_depth(), 8);
75+}
76+
6077 /// The delivered audio scope, as an assert: a Matroska file's AAC track is read
6178 /// like any other file's (`tests/hevc_mkv.rs` is where that lives), and its
6279 /// *picture* being AV1 changes nothing about it.
@@ -181,6 +198,37 @@ fn the_plugin_decodes_every_av1_frame() {
181198 );
182199 }
183200
201+/// ...and the 10-bit file through the very call the window's open door makes: a
202+/// user opens it and the timeline shows a picture, read back off the P010 pool
203+/// to the same 8-bit BGRA every other frame arrives in. The whole point of the
204+/// slice, and the half a container test cannot say anything about.
205+#[test]
206+#[ignore = "needs libengine_hw.so and a VA-API driver with 10-bit AV1 decode"]
207+fn opening_a_ten_bit_av1_file_shows_frames() {
208+ let mut session =
209+ PlaybackSession::open(asset("test_av1_10.mkv")).expect("open the 10-bit file");
210+ assert_eq!(session.meta().codec, Codec::Av1);
211+ assert_eq!(session.meta().frame_count, FRAMES);
212+
213+ // The decoder is a thread behind the door, so a frame is waited for exactly
214+ // as the window's own pump waits for one.
215+ let deadline = Instant::now() + Duration::from_secs(60);
216+ let frame = loop {
217+ if let Some(frame) = session.try_frame() {
218+ break frame;
219+ }
220+ assert!(Instant::now() < deadline, "no frame in 60 s");
221+ std::thread::sleep(Duration::from_millis(10));
222+ };
223+ assert_eq!((frame.width, frame.height), (1280, 720));
224+ // A picture, not a flat surface: a P010 surface read back through the NV12
225+ // path would come out as noise or as nothing at all.
226+ assert!(
227+ frame.bgra.chunks_exact(4).any(|px| px != &frame.bgra[..4]),
228+ "the first frame is a single colour -- no picture was decoded"
229+ );
230+}
231+
184232 /// A seek into the second GOP hands back that very frame, not the keyframe it
185233 /// had to restart from: the demuxer's sync index and the plugin's skip count
186234 /// have to agree, and Matroska is where both are this crate's own doing.
scripts/gen_fixtures.shmodified+14 -4
@@ -103,16 +103,26 @@ ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
103103 # at all, so AV1 is read out of an mkv (`demux::MkvDemuxer`). Same A/V shape as
104104 # the others so the tests measure the codec and nothing else -- but `-g 30` is
105105 # not a preference: it puts a second keyframe at frame 30, which is what the
106-# sync index and the seek test are checked against. 8-bit Main profile, because
107-# the plugin's NV12 read-back cannot carry 10-bit. Its AAC track is deliberate
108-# too: it is the AAC a Matroska file's sound is read out of through symphonia,
109-# beside the AC-3 fixtures below that no symphonia version decodes.
106+# sync index and the seek test are checked against. 8-bit Main profile here; the
107+# 10-bit twin is below. Its AAC track is deliberate too: it is the AAC a Matroska
108+# file's sound is read out of through symphonia, beside the AC-3 fixtures further
109+# down that no symphonia version decodes.
110110 ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
111111 -f lavfi -i "sine=frequency=440:duration=2" \
112112 -f lavfi -i "sine=frequency=880:duration=2" \
113113 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
114114 -map 0:v -map "[a]" -c:v libsvtav1 -preset 8 -g 30 -pix_fmt yuv420p \
115115 -c:a aac -b:a 128k assets/test_av1.mkv
116+# ...and the same file 10-bit, which is what an `av1C` with `high_bitdepth` set
117+# reads as and what the P010 surface pool is picked by -- the AV1 seat of the
118+# pair test_hevc.mkv/test_hevc10.mkv already make for HEVC. libaom rather than
119+# SVT-AV1 because it is the encoder that writes a 10-bit `av1C` here.
120+ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
121+ -f lavfi -i "sine=frequency=440:duration=2" \
122+ -f lavfi -i "sine=frequency=880:duration=2" \
123+ -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
124+ -map 0:v -map "[a]" -c:v libaom-av1 -cpu-used 8 -row-mt 1 -g 30 -pix_fmt yuv420p10le \
125+ -c:a aac -b:a 128k assets/test_av1_10.mkv
116126 # H.264 in Matroska: the same stream the mp4 fixtures carry, in the container
117127 # that used to refuse it. Baseline profile so `rusty_h264` reads it with nothing
118128 # installed, `-g 30` for the second keyframe the sync index is checked against,