edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! Matroska `DisplayUnit` 0: the `Display*` pair is in *pixels*, so a pair |
| 2 | //! beside the coded size is the stretch, not a crop. |
| 3 | //! |
| 4 | //! The Matroska spec is explicit that unit 0 means the `DisplayWidth` and |
| 5 | //! `DisplayHeight` pair *is* a pixel size. So `DisplayWidth=1920`, |
| 6 | //! `DisplayHeight=1080` beside a `PixelWidth=1440`, `PixelHeight=1080` track |
| 7 | //! is exactly the 4/3 anamorphic stretch -- the same picture |
| 8 | //! `test_anamorphic.mkv` states the other two ways round, in SAR (4/3) and in |
| 9 | //! DAR (16/9). |
| 10 | //! |
| 11 | //! No fixture stated it that way until this one: `scripts/gen_fixtures.sh` |
| 12 | //! produces unit 3 (ffmpeg spells the aspect as a DAR), so the unit-0 arm of |
| 13 | //! the reader had never been seen by a test, and it read as square -- the |
| 14 | //! same answer as a file that says nothing at all. The picture was shown at |
| 15 | //! 1440x1080 instead of 1920x1080, and nothing said so. |
| 16 | //! |
| 17 | //! The fixture is patched here from `test_anamorphic.mkv` rather than |
| 18 | //! committed as a binary: the `Video` element keeps its exact byte length, so |
| 19 | //! every absolute offset in the file -- the SeekHead and every CueCluster- |
| 20 | //! Position -- stays correct and the copy seeks exactly as the original does. |
| 21 | //! |
| 22 | //! ```text |
| 23 | //! cargo test -p engine --test display_unit -- --test-threads=1 |
| 24 | //! ``` |
| 25 | |
| 26 | use ; |
| 27 | |
| 28 | use ; |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | ; |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// The bytes of the `Video` element of `test_anamorphic.mkv`, as ffmpeg's |
| 58 | /// Matroska muxer wrote them: a 1440x1080 track with its aspect stated as a |
| 59 | /// 16/9 display aspect ratio. |
| 60 | const VIDEO_UNIT_3: &str = concat! |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | ; |
| 70 | |
| 71 | /// The same 30 bytes with the aspect stated the third way Matroska allows: |
| 72 | /// unit 0, where the `Display*` pair is in pixels and so *is* the drawn |
| 73 | /// size. 1920x1080 over a 1440x1080 coded track is the same 4/3 stretch. |
| 74 | /// |
| 75 | /// Byte-for-byte the same length as [`VIDEO_UNIT_3`], which is what keeps |
| 76 | /// the rest of the file's offsets honest: the `Display*` values grow from |
| 77 | /// one-byte to two-byte payloads (+3 bytes with the wider unit encoding), |
| 78 | /// `FlagInterlaced` is dropped (-3), and `MatrixCoefficients` is restated |
| 79 | /// over two bytes instead of one (+1) inside the `Colour` element. |
| 80 | const VIDEO_UNIT_0: &str = concat! |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | ; |
| 89 | |
| 90 | /// The same `DisplayUnit 0` element with a different `Display*` pixel pair, |
| 91 | /// for the ratios whose reduced form is not a small pair of integers. |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | /// A `DisplayUnit 3` (DAR) `Video` element: the coded size and the display |
| 109 | /// aspect ratio, both length-preserving. |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | /// Patches the `Video` element into a copy of `source` and returns the byte |
| 125 | /// offset it was written at, found by scanning the source rather than |
| 126 | /// assumed, since the offset depends on the muxer's layout. |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | /// The reduced form of a ratio, so a ratio stated unreduced (the DAR arm |
| 155 | /// multiplies through by the coded size) compares equal to its simplest |
| 156 | /// spelling -- the same comparison the anamorphic suite makes. |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | /// The three spellings of one anamorphic picture must name one picture. |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | /// Units 1 and 2 are physical sizes -- centimetres, inches -- which a picture |
| 239 | /// this engine shows on a screen cannot mean anything by. They stay square, |
| 240 | /// and saying so is the deliberate answer rather than an accident of the |
| 241 | /// match falling through. |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | /// The coded size is untrusted too, and it reaches an allocation directly: |
| 259 | /// `decode.rs` sizes its stretched planes as `display_width * height`. The |
| 260 | /// engine already has a bound for exactly this -- [`engine::MAX_RESOLUTION`], |
| 261 | /// 8K, the size a per-frame buffer stops being sane at -- and the demux |
| 262 | /// readers never applied it to a container-stated width or height. |
| 263 | /// |
| 264 | /// The fixture patches the `PixelWidth`/`PixelHeight` payloads to 65535 each, |
| 265 | /// which is a legal two-byte EBML integer, so the element keeps its exact |
| 266 | /// length and the copy stays seekable. |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | /// The bound is a ceiling on a real picture, not a floor on a file: the |
| 297 | /// largest size a real source states still opens, untouched. |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | /// The regression this arm must not carry: a `DisplayUnit 0` pair is a pixel |
| 309 | /// SIZE, so its *reduced* form is the size against the coded size, not a small |
| 310 | /// pair of integers -- and the common cinematic display ratios do not reduce |
| 311 | /// small. A 1920x803 scope over a 1440x1080 coded track reduces to 1440:803, |
| 312 | /// and 1920x1037 (1.85:1 flat) likewise. |
| 313 | /// |
| 314 | /// The reduced-term bound is the right test for an mp4 `pasp`, where the pair |
| 315 | /// *is* the ratio, and the wrong test here: applying it made the two most |
| 316 | /// common letterbox ratios open square, on exactly the arm this fix newly |
| 317 | /// enabled. The quantity that needs bounding on this door is the resulting |
| 318 | /// display WIDTH, which `width_factor` already caps. |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | /// The unit-3 arm, which is the same rule as unit 0 one arm away: a DAR is |
| 367 | /// not a ratio either, because bringing it onto the coded frame multiplies by |
| 368 | /// the coded size, and what reduces afterwards carries the *sizes*. |
| 369 | /// |
| 370 | /// So the same 2.39:1 scope is judged differently by the frame it sits on, |
| 371 | /// which is a bound measuring the wrong thing. Over a 1920x1080 coded track a |
| 372 | /// 239:100 DAR derives 2151:1600 and over 3840x2160 the same -- both past any |
| 373 | /// term bound -- while over 1440x1080 it derives 717:400 and passes. Base |
| 374 | /// `9f780f7` opened all three at the widths below; the bound made the first |
| 375 | /// two open square, a measured regression rather than a latent gap. |
| 376 | /// |
| 377 | /// The expected widths are the ones BASE produced, measured by running base |
| 378 | /// over these same fixtures. This is the property that matters: the arm must |
| 379 | /// read the DAR the way it always did, so the test pins base's answers rather |
| 380 | /// than a fresh computation of them. |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | /// The term bound must survive where it belongs. The unit-4 SAR pair IS a |
| 422 | /// ratio, so a hostile one is still refused -- this arm is what stops the |
| 423 | /// split from reading as "the bound was dropped". |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 |