forge
Explore
Log in

Don't you dare go Hollow

The canvas gate asks about the pair the encoder places

Browse files at this commit

8d8aff1160b1f5241f6d78fe251fd01977630086Ahmet Kaan GümüşParent: 2d54df8
  • fix
    • the canvas gate asks about the pair the encoder places
Show full message
fix(engine): the canvas gate asks about the pair the encoder places

The gate added in 2d54df8 handed `fit_is_identity` the source's CODED
pair, so every source whose samples are not square lost the copy door:
a 1440x1080 file with a 4:3 sample aspect draws at 1920x1080, and a
project opened at that size is copying it exactly -- main writes the
source's own 1440x1080 blocks and states the ratio in the `Display*`
elements, which draws at precisely the canvas. Measured: with the
preceding commit that project encoded instead
("HW encode (VA-API) · no sound to write") and
tests/anamorphic.rs::a_matroska_copy_keeps_the_pixel_aspect went 4/5.

The picture a fit is composed against is the DRAWN one --
`VideoMeta::width`/`height`, the coded pair with the file's turn and its
pixel aspect already applied -- so that is what the gate compares with
the canvas. The coded pair keeps its own question, which the pre-existing
coded-to-coded check already asks: what a copied track *declares*.

Measured: `a_matroska_copy_keeps_the_pixel_aspect` green again, seat
line "export video: copy (source packets)"; the whole anamorphic suite
5/5; video_copy 10/10 (the resized-canvas witness still bites); export
28/28; `cargo check --all-targets` 0 warnings. Two mutations, each
biting the other half: putting the coded pair back reds the anamorphic
test (anamorphic.rs:425), and making the identity always true reds the
canvas witness ("a smaller canvas (960x540) was copied").
crates/engine/src/export.rsmodified+38 -17
@@ -1855,11 +1855,16 @@ impl CopyPlan {
18551855 };
18561856 let entries = project.sources();
18571857 let mut sources: Vec<Option<MkvDemuxer>> = (0..entries.len()).map(|_| None).collect();
1858- // The coded pair each source is stored at, kept beside its demuxer:
1859- // the fit gate below asks what a clip's own policy does with *this*
1860- // source's picture on this canvas, and the picture it has is the coded
1861- // one, not the displayed one.
1862- let mut coded: Vec<Option<(u32, u32)>> = (0..entries.len()).map(|_| None).collect();
1858+ // The DRAWN pair each source is displayed at, kept beside its demuxer:
1859+ // the fit gate below asks what a clip's policy does with this source's
1860+ // picture on this canvas, and the picture the encoder places is the
1861+ // drawn one ([`VideoMeta::width`]/`height`] -- the coded one with the
1862+ // file's turn and its pixel aspect already applied), not the pair the
1863+ // samples are stored at. A non-square source at its own displayed size
1864+ // is therefore the identity again, which is what a copy of one is: the
1865+ // aspect travels beside the track in the `Display*` elements rather
1866+ // than being resampled into it.
1867+ let mut drawn: Vec<Option<(u32, u32)>> = (0..entries.len()).map(|_| None).collect();
18631868 let mut declared: Option<(Vec<u8>, ColorDescription, crate::demux::PixelAspect)> = None;
18641869 let mut regions: Vec<CopyRegion> = Vec::new();
18651870 let r_start = settings.range.map_or(0, |(s, _)| s);
@@ -1958,7 +1963,7 @@ impl CopyPlan {
19581963 return None;
19591964 }
19601965 sources[source] = Some(demuxer);
1961- coded[source] = Some((source_meta.coded_width, source_meta.coded_height));
1966+ drawn[source] = Some((source_meta.width, source_meta.height));
19621967 }
19631968 let demuxer = sources.get_mut(source)?.as_mut()?;
19641969 // **The canvas gate** -- the condition this path was missing, and
@@ -1968,16 +1973,23 @@ impl CopyPlan {
19681973 // export writes has to be the size the *project* is, and those are
19691974 // two different pairs held in two different fields:
19701975 //
1971- // * `meta.coded_width`/`coded_height` is what the demuxer wrote
1972- // and the check above compares against it. Only a *source* ever
1973- // moves it.
1976+ // * `meta.coded_width`/`coded_height` is the pair a *copied* track
1977+ // declares -- what the samples are stored at, and what the check
1978+ // above compares every source against. Only a *source* ever moves
1979+ // it.
19741980 // * `meta.width`/`meta.height` is the canvas -- what a person chose
19751981 // with [`crate::playback::PlaybackSession::set_resolution`],
1976- // which writes those two and leaves the coded pair exactly
1977- // where it was. The encode door sizes everything from it
1982+ // which writes those two and leaves the coded pair exactly where
1983+ // it was. The encode door sizes everything from it
19781984 // ([`Composer`]), so this is the size the file must have.
19791985 //
1980- // A canvas that differs from the source's coded pair means every
1986+ // ...and the two meet in the *drawn* pair: what this span is
1987+ // composed from is the source's picture as a decoder delivers it,
1988+ // turn and pixel aspect already applied
1989+ // ([`VideoMeta::width`]/`height`]), which is what the check below is
1990+ // asked about.
1991+ //
1992+ // A canvas that differs from the source's drawn pair means every
19811993 // span is a picture the export has to *place onto* that canvas, and
19821994 // there is no resampler on this path at all -- so a copy would ship
19831995 // the source's frame size under the project's name, with the seat
@@ -1989,13 +2001,13 @@ impl CopyPlan {
19892001 // is this clip's policy the identity for this source on this canvas
19902002 // -- because that is the one thing a condition has to mean here:
19912003 // [`fit_is_identity`] computes it from [`scale::fit_rect`] itself,
1992- // so it holds for `Fill` on a canvas the size of the source's own
1993- // samples (there is nothing to crop there) and refuses a canvas of
1994- // another size under *every* policy, and a
2004+ // so it holds for `Fill` on a canvas the size of the picture the
2005+ // source draws at (there is nothing to crop there) and refuses a
2006+ // canvas of another size under *every* policy, and a
19952007 // [`crate::scale::FitPolicy`] added later is judged by what it
19962008 // places rather than by being absent from a list here.
19972009 if !fit_is_identity(
1998- coded.get(source).copied().flatten()?,
2010+ drawn.get(source).copied().flatten()?,
19992011 (meta.width, meta.height),
20002012 project.composite_fit_at(span.start),
20012013 ) {
@@ -2114,13 +2126,22 @@ impl CopyPlan {
21142126 }
21152127 }
21162128
2117-/// Whether `policy` places a source stored at `source` onto this `canvas`
2129+/// Whether `policy` places the picture `source` is DRAWN at onto this `canvas`
21182130 /// without touching a sample: the whole picture, at the whole canvas, 1:1.
21192131 ///
21202132 /// The 1:1 is the half the rects cannot state: a source scaled onto a canvas
21212133 /// of another aspect is placed whole and cropped nowhere, which is a resize
21222134 /// and not an identity -- so the pairs themselves are compared first.
21232135 ///
2136+/// The pair asked about is the **drawn** one ([`VideoMeta::width`]/`height`]),
2137+/// never the coded one: what the fit is composed against is what a decoder
2138+/// hands the canvas after the file's turn and its pixel aspect have been
2139+/// applied, so a 1440x1080 file with a 4:3 sample aspect is a 1920x1080
2140+/// picture, and a project at 1920x1080 is copying it exactly. The coded pair
2141+/// has its own question -- what a copied track *declares* -- and the coded-to-
2142+/// coded check in [`CopyPlan::of`] already asks that one; asking it twice, in
2143+/// the geometry's stead, refuses a copy main performs byte for byte.
2144+///
21242145 /// Asked from [`scale::fit_rect`] -- the one function that *is* a fit policy's
21252146 /// meaning -- rather than from the policy itself, which is what makes this
21262147 /// canvas-aware twice over: `Fill` on a canvas the size of the source's own