forge
Explore
Log in

Don't you dare go Hollow

Merge the decode lane into main

Browse files at this commit

8a7835a435cad9068e475208c9dfefacf23c91c1Ahmet Kaan GümüşParent: 737b1714826d31
  • fix
    • merge the decode lane into main
Show full message
🐛 fix(decode): merge the decode lane into main

Grades survive a moved clip and a size-less canvas paints nothing. Lane:
lane-bughunt-decode.
crates/engine/src/decode.rsmodified+121 -22
@@ -56,7 +56,6 @@ pub enum Backend {
56 /// A gap: black frames, nothing decoded at all.56 /// A gap: black frames, nothing decoded at all.
57 Gap,57 Gap,
58 /// A waveform visualizer: the picture is painted from the audio's peaks58 /// A waveform visualizer: the picture is painted from the audio's peaks
59- /// A waveform viz_paint: 0,
60 /// ([`visualizer_i420`]), no decoder seat and no stream of pictures at all.59 /// ([`visualizer_i420`]), no decoder seat and no stream of pictures at all.
61 Visualizer,60 Visualizer,
62 }61 }
@@ -1144,7 +1143,14 @@ fn run_span(
1144 backend.set(Backend::Software);1143 backend.set(Backend::Software);
1145 run_av1(&mut opened.demuxer, &tx, start, end, &mut render, abort, speed);1144 run_av1(&mut opened.demuxer, &tx, start, end, &mut render, abort, speed);
1146 }1145 }
1147- other => eprintln!("{}", other.needs_plugin()),1146+ // Nothing decodes from here -- no software seat exists for this codec.
1147+ // Say so: the cell was left claiming the hardware session that opened
1148+ // and then produced nothing, and it reports what happened, not what
1149+ // was hoped for.
1150+ other => {
1151+ backend.set(Backend::Gap);
1152+ eprintln!("{}", other.needs_plugin());
1153+ }
1148 }1154 }
1149 }1155 }
1150 1156
@@ -1305,7 +1311,12 @@ impl Render {
1305 if let Some(tone) = &self.tone {1311 if let Some(tone) = &self.tone {
1306 tone.map(gy, gu, gv, width as usize, height as usize);1312 tone.map(gy, gu, gv, width as usize, height as usize);
1307 }1313 }
1308- if !passthrough && !self.color.is_identity() {1314+ // The same terms the branch was entered on: anywhere the fused
1315+ // conversion below will not apply the grade (a placement is
1316+ // happening, so the canvas conversion is plain), it lands here --
1317+ // including the passthrough-sized clip a transform moves, whose
1318+ // grade used to be dropped on the floor between these two guards.
1319+ if !skip_placement && !self.color.is_identity() {
1309 crate::color::apply_yuv(&self.color, gy, gu, gv);1320 crate::color::apply_yuv(&self.color, gy, gu, gv);
1310 }1321 }
1311 let desc = if self.tone.is_some() {1322 let desc = if self.tone.is_some() {
@@ -1476,19 +1487,6 @@ pub const VIZ_STYLE_RIBBON: u8 = 1;
1476 pub const VIZ_STYLE_RING: u8 = 2;1487 pub const VIZ_STYLE_RING: u8 = 2;
1477 pub const VIZ_STYLE_WAVE: u8 = 3;1488 pub const VIZ_STYLE_WAVE: u8 = 3;
1478 pub const VIZ_FAST: u8 = 1 << 3;1489 pub const VIZ_FAST: u8 = 1 << 3;
1479-/// High nibble of [`crate::project::Clip::visualizer`]: 16 inks. Zero is the
1480-/// timeline azure, then around the wheel in 22.5° steps.
1481-pub const VIZ_HUE_SHIFT: u8 = 4;
1482-
1483-/// The ink nibble stored in `flags`.
1484-pub fn viz_hue(flags: u8) -> u8 {
1485- flags >> VIZ_HUE_SHIFT
1486-}
1487-
1488-/// Keep style bits, replace the ink nibble.
1489-pub fn with_viz_hue(flags: u8, hue: u8) -> u8 {
1490- (flags & 0x0F) | ((hue & 15) << VIZ_HUE_SHIFT)
1491-}
1492 1490
1493 pub fn viz_style(flags: u8) -> u8 {1491 pub fn viz_style(flags: u8) -> u8 {
1494 (flags >> 1) & 31492 (flags >> 1) & 3
@@ -1498,12 +1496,6 @@ pub fn with_viz_style(flags: u8, style: u8) -> u8 {
1498 (flags & !0b0110) | ((style & 3) << 1)1496 (flags & !0b0110) | ((style & 3) << 1)
1499 }1497 }
1500 1498
1501-/// Ink colour for the CLIP swatches and the painter. Hue 0 is the timeline
1502-/// azure (`0x4F8FD6`), then around the wheel.
1503-pub fn viz_ink_rgb(hue: u8) -> (u8, u8, u8) {
1504- hsv_to_rgb(212.0 + f32::from(hue & 15) * 22.5, 0.63, 0.84)
1505-}
1506-
1507 /// Azure + sat 160 + 8 strands + glow 2. What `viz_paint == 0` means.1499 /// Azure + sat 160 + 8 strands + glow 2. What `viz_paint == 0` means.
1508 pub const VIZ_PAINT_AZURE: u64 = 150 | (160 << 8) | (8 << 16) | (2 << 24);1500 pub const VIZ_PAINT_AZURE: u64 = 150 | (160 << 8) | (8 << 16) | (2 << 24);
1509 1501
@@ -2113,6 +2105,16 @@ pub(crate) fn visualizer_i420(
2113 ) -> (Vec<u8>, Vec<u8>, Vec<u8>) {2105 ) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
2114 let width = width & !1;2106 let width = width & !1;
2115 let height = height & !1;2107 let height = height & !1;
2108+ // A canvas with no size asks for no picture, and must be told so: the zero
2109+ // line's row is derived from the height (`h - 1`), and a height of zero has
2110+ // no row to put it on -- `clamp` answers that by panicking, which on this
2111+ // path is a dead worker thread and a span the export aborts on. A
2112+ // `Composer::passthrough()` canvas is exactly this size and says as much
2113+ // (`places_nothing`), and a 1-pixel-high canvas floors to it (planes are
2114+ // even), so both take the empty picture they asked for.
2115+ if width == 0 || height == 0 {
2116+ return (Vec::new(), Vec::new(), Vec::new());
2117+ }
2116 let (w, h) = (width as usize, height as usize);2118 let (w, h) = (width as usize, height as usize);
2117 let (cw, ch) = crate::scale::chroma_dims(w, h);2119 let (cw, ch) = crate::scale::chroma_dims(w, h);
2118 let (bg_y, bg_u, bg_v) = rgb_yuv(8, 12, 22);2120 let (bg_y, bg_u, bg_v) = rgb_yuv(8, 12, 22);
@@ -2651,6 +2653,103 @@ mod tests {
2651 );2653 );
2652 }2654 }
2653 2655
2656+ /// The empty-peaks source -- a trackless file, or any peaks decode error
2657+ /// (`peaks_shared(..).ok().flatten().unwrap_or_default()`) -- must paint
2658+ /// the flat line, never panic: a visualizer frame always exists. The
2659+ /// `pair_at` interpolator indexes `peaks[len() - 1]`, which is only
2660+ /// reachable inside the `!peaks.is_empty()` guard, so the empty vec takes
2661+ /// the early flat-line path and no column ever samples a bucket.
2662+ #[test]
2663+ fn empty_peaks_paint_the_flat_line() {
2664+ let w = 320u32;
2665+ let h = 180u32;
2666+ let (y, _u, _v) = visualizer_i420(&mut VizScratch::default(), &[], 0.0, w, h, 1, 0);
2667+ assert_eq!((y.len(), _u.len(), _v.len()), (320 * 180, 160 * 90, 160 * 90));
2668+ // The ink's top and bottom row for a given peaks slice: one unbroken
2669+ // band, and where it sits.
2670+ let band = |peaks: &[(f32, f32)]| {
2671+ let (y, _, _) = visualizer_i420(&mut VizScratch::default(), peaks, 0.0, w, h, 1, 0);
2672+ let rows: Vec<usize> = (0..h as usize)
2673+ .filter(|&row| y[row * 320..(row + 1) * 320].iter().any(|&p| p > 40))
2674+ .collect();
2675+ assert!(
2676+ !rows.is_empty() && rows.len() == rows[rows.len() - 1] - rows[0] + 1,
2677+ "the ink must be one unbroken band, not scattered rows: {rows:?}"
2678+ );
2679+ (rows[0], rows[rows.len() - 1])
2680+ };
2681+ // Silence is the zero line and nothing else: the band is on the middle
2682+ // row and a line's thickness -- five rows here, the trace's own -- not
2683+ // a picture's.
2684+ let (first, last) = band(&[]);
2685+ let zero = h as usize / 2;
2686+ assert!(
2687+ first <= zero && zero <= last,
2688+ "the zero line itself must be inked: {first}..={last}"
2689+ );
2690+ assert!(
2691+ last - first <= (h as usize) / 8,
2692+ "a peaks-less source painted a {}-row band, not a line: {first}..={last}",
2693+ last - first + 1
2694+ );
2695+ // ...and the same seat over full-scale peaks is a picture, which is
2696+ // what makes the line above a claim about silence rather than about a
2697+ // painter that never draws anything.
2698+ let (loud_first, loud_last) = band(&[(-1.0, 1.0); 1200]);
2699+ assert!(
2700+ loud_last - loud_first > (last - first) * 3,
2701+ "full-scale peaks painted {loud_first}..={loud_last}, no taller than silence's {first}..={last}"
2702+ );
2703+ }
2704+
2705+ /// A canvas with no size has no row to draw the zero line on. The row index
2706+ /// is derived from the height (`h as isize - 1`), so a *height* of zero
2707+ /// underflows into `clamp`'s `min <= max` assert and takes the worker
2708+ /// thread with it. A `Composer::passthrough()` canvas is exactly this
2709+ /// (`dims()` is `(0, 0)`, `places_nothing()` is true for it), and a
2710+ /// one-pixel-high canvas floors to the same nothing, the planes being even.
2711+ #[test]
2712+ fn a_size_less_visualizer_canvas_paints_nothing() {
2713+ let size_less = visualizer_i420(&mut VizScratch::default(), &[], 0.0, 0, 0, 0, 0);
2714+ assert_eq!(size_less, (Vec::new(), Vec::new(), Vec::new()));
2715+ let thin = visualizer_i420(&mut VizScratch::default(), &[(0.0, 1.0)], 0.0, 2, 1, 0, 0);
2716+ assert!(
2717+ thin.0.is_empty() && thin.1.is_empty() && thin.2.is_empty(),
2718+ "a 2x1 canvas has no even-sized plane to paint on"
2719+ );
2720+ }
2721+
2722+ /// The same canvas, driven through the seat that really opens one: the
2723+ /// worker thread is where a panic *is* the defect -- it closes the frame
2724+ /// channel and the caller sees a span with no picture in it, which is what
2725+ /// the export then aborts on.
2726+ #[test]
2727+ fn a_pass_through_canvas_visualizer_paints_nothing_and_stays_alive() {
2728+ let transform = TransformParams {
2729+ pos_x: 0.25,
2730+ ..Default::default()
2731+ };
2732+ let stream = DecodeSession::open_visualizer(
2733+ &asset("test_opus_51.mka"),
2734+ 0,
2735+ 0,
2736+ 2,
2737+ 30.0,
2738+ ColorParams::default(),
2739+ transform,
2740+ Composer::passthrough(),
2741+ VIZ_STYLE_WAVE,
2742+ 0,
2743+ )
2744+ .expect("open the visualizer");
2745+ let frame = stream
2746+ .frames
2747+ .recv_timeout(Duration::from_secs(30))
2748+ .expect("a picture, not a worker that died instead of painting one");
2749+ assert_eq!((frame.width, frame.height), (0, 0));
2750+ assert!(frame.bgra.is_empty());
2751+ }
2752+
2654 #[test]2753 #[test]
2655 fn visualizer_default_is_a_blue_envelope() {2754 fn visualizer_default_is_a_blue_envelope() {
2656 let mut peaks = vec![(0.0, 0.0); 12_000];2755 let mut peaks = vec![(0.0, 0.0); 12_000];
crates/engine/tests/export_color.rsmodified+73 -5
@@ -29,12 +29,12 @@ use std::path::{Path, PathBuf};
29 use std::process::Command;29 use std::process::Command;
30 use std::time::{Duration, Instant};30 use std::time::{Duration, Instant};
31 31
32-use engine::PlaybackSession;32+use engine::colorspace::{remap, ColorDescription, Matrix, Transfer};
33-use engine::colorspace::{ColorDescription, Matrix, Transfer, remap};
34 use engine::demux::Demuxer;33 use engine::demux::Demuxer;
35 use engine::export::{ExportSettings, Format};34 use engine::export::{ExportSettings, Format};
36 use engine::scratch::Scratch;35 use engine::scratch::Scratch;
37 use engine::tonemap::{self, ToneMapper};36 use engine::tonemap::{self, ToneMapper};
37+use engine::PlaybackSession;
38 38
39 fn asset(name: &str) -> PathBuf {39 fn asset(name: &str) -> PathBuf {
40 PathBuf::from(env!("CARGO_MANIFEST_DIR"))40 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
@@ -512,8 +512,14 @@ fn a_real_hdr_film_exports_as_a_picture() {
512 // seconds and no leading black.512 // seconds and no leading black.
513 assert!(session.cut_at(605.0), "the tail cut");513 assert!(session.cut_at(605.0), "the tail cut");
514 assert!(session.cut_at(600.0), "the head cut");514 assert!(session.cut_at(600.0), "the head cut");
515- assert!(session.delete_clip(engine::project::Lane::V1, 2), "the tail");515+ assert!(
516- assert!(session.delete_clip(engine::project::Lane::V1, 0), "the head");516+ session.delete_clip(engine::project::Lane::V1, 2),
517+ "the tail"
518+ );
519+ assert!(
520+ session.delete_clip(engine::project::Lane::V1, 0),
521+ "the head"
522+ );
517 let out = out_path("hdr_film", "mp4");523 let out = out_path("hdr_film", "mp4");
518 export(&session, &out, Format::Mp4);524 export(&session, &out, Format::Mp4);
519 525
@@ -611,7 +617,11 @@ fn a_graded_clip_exports_the_picture_the_preview_showed() {
611 #[test]617 #[test]
612 fn a_declared_peak_exports_the_picture_the_preview_showed() {618 fn a_declared_peak_exports_the_picture_the_preview_showed() {
613 let mut session = two_frames(&asset("test_hdr_bright.mkv"));619 let mut session = two_frames(&asset("test_hdr_bright.mkv"));
614- assert_eq!(session.meta().color.transfer, Transfer::Pq, "an HDR fixture");620+ assert_eq!(
621+ session.meta().color.transfer,
622+ Transfer::Pq,
623+ "an HDR fixture"
624+ );
615 let preview = frame0_bgra(&mut session);625 let preview = frame0_bgra(&mut session);
616 let out = out_path("declared_peak", "mp4");626 let out = out_path("declared_peak", "mp4");
617 export(&session, &out, Format::Mp4);627 export(&session, &out, Format::Mp4);
@@ -627,3 +637,61 @@ fn a_declared_peak_exports_the_picture_the_preview_showed() {
627 drop(reopened);637 drop(reopened);
628 std::fs::remove_file(&out).unwrap();638 std::fs::remove_file(&out).unwrap();
629 }639 }
640+
641+/// The graded-clip invariant on the one placement the fused conversion cannot
642+/// take: the clip is the project's own size (so the conversion would pass it
643+/// through untouched) but a transform *moves* it, which makes it a placement
644+/// again. The grade has to land before that placement -- the export side
645+/// applies it unconditionally -- or the preview quietly drops the grade
646+/// whenever a passthrough-sized clip is moved, scaled or turned.
647+#[test]
648+fn a_moved_passthrough_clip_keeps_its_grade_in_preview_and_export() {
649+ let grade = Some(engine::color::ColorParams {
650+ brightness: 0.0,
651+ contrast: 1.0,
652+ saturation: 0.0,
653+ tint: 0.0,
654+ });
655+ let moved = engine::transform::TransformParams {
656+ pos_x: 0.25,
657+ ..Default::default()
658+ };
659+
660+ // The half that must fail loudly on the canvas: the moved passthrough
661+ // preview changes with the grade. These bars are spread ~250 per channel,
662+ // so a grade that does not land leaves the two previews identical.
663+ let mut session = two_frames(&asset("test_baseline.mp4"));
664+ assert!(
665+ session.set_transform(engine::project::Lane::V1, 0, Some(moved)),
666+ "the move went on the clip"
667+ );
668+ assert!(
669+ session.set_color(engine::project::Lane::V1, 0, grade),
670+ "the grade went on the clip"
671+ );
672+ let graded = frame0_bgra(&mut session);
673+ assert!(session.set_color(engine::project::Lane::V1, 0, None));
674+ let ungraded = frame0_bgra(&mut session);
675+ let parted = mean_abs_diff(&graded, &ungraded);
676+ eprintln!("moved passthrough: graded vs ungraded preview {parted:.2} mean codes");
677+ assert!(
678+ parted > 3.0,
679+ "the grade never reached the moved passthrough preview: {parted:.2}"
680+ );
681+
682+ // The matching half, on the file: the export -- which has always applied
683+ // the grade -- is still the picture the preview showed.
684+ assert!(session.set_color(engine::project::Lane::V1, 0, grade));
685+ let out = out_path("moved_grade", "mp4");
686+ export(&session, &out, Format::Mp4);
687+ let mut reopened = PlaybackSession::open(&*out).expect("reopen the export");
688+ let exported = frame0_bgra(&mut reopened);
689+ let diff = mean_abs_diff(&graded, &exported);
690+ eprintln!("moved passthrough: preview vs export {diff:.2} mean codes");
691+ assert!(
692+ diff <= 2.0,
693+ "the export is {diff:.2} codes from what the moved passthrough preview showed"
694+ );
695+ drop(reopened);
696+ std::fs::remove_file(&out).unwrap();
697+}