forge
Explore
Log in

Don't you dare go Hollow

Judge proxy candidacy on the coded pair, not the displayed one

Browse files at this commit

6924a196cb0ae074b7fbbfee0325fdea80770e8bAhmet Kaan GümüşParent: 0c9d76c
  • fix
    • judge proxy candidacy on the coded pair, not the displayed one
Show full message
fix(engine): judge proxy candidacy on the coded pair, not the displayed one

`proxy::wanted` read `meta.width`/`meta.height`, which `VideoMeta` documents as
the DISPLAYED pair: the coded one with its axes swapped where the file carries a
90- or 270-degree display matrix, and width-stretched by a non-square sample
aspect. A full-HD AVC phone clip carrying a 90-degree turn therefore reports
1080x1920, reads as "taller than 1080p" and is judged proxy-worthy -- the whole
file goes through a decoder and an encoder in the background, and takes proxy
cache space, to stand in for a clip this machine already plays at rate. The
auto-proxy switch shows ON over a file that needed nothing.

What a decoder is handed is the stored raster, so the stored raster is what the
size test is about: `coded_width`/`coded_height`. The codec test is not a size
question and is unchanged, so a turned HEVC or AV1 file is still wanted, and a
genuinely tall stored raster is still wanted turn or not.

The unit test's `meta` helper is now a thin wrapper over a `turned_meta` that
takes a rotation and builds the displayed pair the way `demux` builds it, and
the test asserts both the refusal and the two cases that must stay wanted.
Shown RED against the pre-fix predicate.
crates/engine/src/proxy.rsmodified+71 -8
@@ -32,8 +32,8 @@
3232 //! cancel a file export has ([`Job`]).
3333
3434 use std::path::{Path, PathBuf};
35-use std::sync::atomic::AtomicBool;
3635 use std::sync::Arc;
36+use std::sync::atomic::AtomicBool;
3737 use std::time::UNIX_EPOCH;
3838
3939 use crate::demux::{Codec, Demuxer, NoVideoTrack, VideoMeta};
@@ -93,8 +93,20 @@ const BITS_PER_PIXEL: f64 = 0.3;
9393 /// Whether this is a file worth standing in for: bigger than 1080p, or coded in
9494 /// something this machine decodes slowly even at 1080p. H.264 at or under 1080p
9595 /// plays natively and a proxy of it would cost time and buy nothing.
96+///
97+/// The size test reads the **coded** pair, not the displayed one
98+/// ([`VideoMeta::coded_width`]): those differ wherever the file carries a
99+/// display matrix or a non-square pixel, and a 1920x1080 H.264 phone clip with
100+/// a 90-degree turn *displays* as 1080x1920 -- so judging the displayed pair
101+/// called a clip that plays natively proxy-worthy and put a whole film through
102+/// a decoder and an encoder to stand in for something already at speed. What a
103+/// decoder is asked to chew through is the stored raster, so the stored raster
104+/// is what this is about; the codec test is not a size question and is
105+/// unchanged.
96106 pub fn wanted(meta: &VideoMeta) -> bool {
97- meta.width > 1920 || meta.height > 1080 || matches!(meta.codec, Codec::Hevc | Codec::Av1)
107+ meta.coded_width > 1920
108+ || meta.coded_height > 1080
109+ || matches!(meta.codec, Codec::Hevc | Codec::Av1)
98110 }
99111
100112 /// The picture a proxy of `meta` is coded at: aspect kept, long edge at most
@@ -628,7 +640,27 @@ mod tests {
628640 Arc::new(AtomicBool::new(false))
629641 }
630642
631- fn meta(width: u32, height: u32, codec: Codec) -> VideoMeta {
643+ /// A meta as no container wrote it: square pixels, no turn, the displayed
644+ /// pair the same pair the samples are stored at.
645+ fn meta(coded_width: u32, coded_height: u32, codec: Codec) -> VideoMeta {
646+ turned_meta(coded_width, coded_height, Rotation::None, codec)
647+ }
648+
649+ /// The same, but with the display pair built the way `demux` builds it for
650+ /// a file carrying a display matrix: the stored pair with its axes swapped
651+ /// where the turn says they are. A phone clip shot 1920x1080 and turned to
652+ /// portrait is the case that matters -- it *displays* 1080x1920, and a
653+ /// predicate that reads the displayed pair calls it a tall 1080p film.
654+ fn turned_meta(
655+ coded_width: u32,
656+ coded_height: u32,
657+ rotation: Rotation,
658+ codec: Codec,
659+ ) -> VideoMeta {
660+ let (width, height) = match rotation.swaps_axes() {
661+ true => (coded_height, coded_width),
662+ false => (coded_width, coded_height),
663+ };
632664 VideoMeta {
633665 width,
634666 height,
@@ -636,11 +668,9 @@ mod tests {
636668 frame_count: 240,
637669 codec,
638670 color: ColorDescription::default(),
639- rotation: Rotation::None,
640- // Square pixels, coded where they are declared: a meta no
641- // container wrote, so nothing was read to disagree with it.
642- coded_width: width,
643- coded_height: height,
671+ rotation,
672+ coded_width,
673+ coded_height,
644674 pixel_aspect: crate::demux::PixelAspect::SQUARE,
645675 }
646676 }
@@ -657,6 +687,39 @@ mod tests {
657687 "1080p H.264 plays natively"
658688 );
659689 assert!(!wanted(&meta(1280, 720, Codec::H264)), "720p H.264");
690+
691+ // A turn must not turn a native file into a proxy job. What a decoder
692+ // is handed is the stored raster -- 1920x1080 of H.264 -- and that is
693+ // what plays at speed; the 1080x1920 the file *displays* is a metadata
694+ // turn, not a bigger picture. Judged on the displayed pair this file
695+ // was handed to a background decoder and an encoder to be stood in for,
696+ // which is a whole film of CPU and cache for a clip already at rate.
697+ let phone = turned_meta(1920, 1080, Rotation::Cw90, Codec::H264);
698+ assert_eq!(
699+ (phone.coded_width, phone.coded_height),
700+ (1920, 1080),
701+ "the samples are stored landscape"
702+ );
703+ assert_eq!(
704+ (phone.width, phone.height),
705+ (1080, 1920),
706+ "and the file only claims to display portrait"
707+ );
708+ assert!(
709+ !wanted(&phone),
710+ "a rotated 1080p H.264 clip plays natively: the turn is not height"
711+ );
712+ // ...while the same turn on a codec this machine decodes slowly is
713+ // still wanted, and so is a genuinely tall stored raster: the two
714+ // tests are about the stored pair, not about `rotation` itself.
715+ assert!(
716+ wanted(&turned_meta(1920, 1080, Rotation::Cw90, Codec::Hevc)),
717+ "1080p HEVC is wanted whatever turn it carries"
718+ );
719+ assert!(
720+ wanted(&turned_meta(1080, 1920, Rotation::None, Codec::H264)),
721+ "a stored 1080x1920 raster is a big one, turn or not"
722+ );
660723 }
661724
662725 /// Aspect kept, long edge capped, both axes even -- and a small source left