edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! AV1 import: the third source codec that is not H.264, and the first that |
| 2 | //! arrives in a container of its own -- `mp4 0.14` knows no `av01` sample entry |
| 3 | //! at all, so AV1 comes in as Matroska and the demuxer walks the EBML itself. |
| 4 | //! |
| 5 | //! Decoding has two seats: the project's own `ec-av1` in this process, and the |
| 6 | //! VA-API plugin's (`vainfo | grep AV1`) in front of it. The software seat needs |
| 7 | //! nothing installed, so its witnesses run unignored (`VE_SW` pins it); the |
| 8 | //! hardware twins need a built `libengine_hw.so` and are `#[ignore]`d: |
| 9 | //! |
| 10 | //! ```text |
| 11 | //! cargo build -p engine -p engine-hw --release |
| 12 | //! LD_LIBRARY_PATH=target/release \ |
| 13 | //! cargo test -p engine --release --test av1 -- --include-ignored --nocapture --test-threads=1 |
| 14 | //! ``` |
| 15 | //! |
| 16 | //! `VE_SW` is process-wide: every test that pins a seat takes it through |
| 17 | //! `support/seat.rs`, so the software and hardware tests here never see each |
| 18 | //! other's pin, with or without `--test-threads=1`. |
| 19 | |
| 20 | use crateseat; |
| 21 | |
| 22 | use PathBuf; |
| 23 | use ; |
| 24 | |
| 25 | use ; |
| 26 | use ExportSettings; |
| 27 | use Scratch; |
| 28 | use ; |
| 29 | |
| 30 | /// 1280x720@30, 2 s, keyframes 30 apart -- see `scripts/gen_fixtures.sh`. |
| 31 | const FRAMES: u32 = 60; |
| 32 | const KEYFRAME: u32 = 30; |
| 33 | /// The film grain twin is 3 s of the same shape, for the reason its own test |
| 34 | /// gives. |
| 35 | const GRAIN_FRAMES: u32 = 90; |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /// The container half. Matroska indexes neither frames nor rate, so all three |
| 44 | /// numbers here come out of the walk: the count is the blocks of the track, the |
| 45 | /// rate is `DefaultDuration` in nanoseconds (33333333, i.e. 30 fps to seven |
| 46 | /// digits -- the millisecond timestamps beside it would say 30.30). |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// The depth, which is what picks the surface pool the plugin decodes into: an |
| 69 | /// `av1C` with `high_bitdepth` set reads as 10 and takes the P010 pool HEVC Main |
| 70 | /// 10 already goes through, and the 8-bit fixture beside it still reads as 8. |
| 71 | /// It used to be an outright refusal at open ("10-bit AV1 is not supported"). |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | /// The delivered audio scope, as an assert: a Matroska file's AAC track is read |
| 86 | /// like any other file's (`tests/hevc_mkv.rs` is where that lives), and its |
| 87 | /// *picture* being AV1 changes nothing about it. |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | /// Every block comes back, keyframes carry the sequence header, and the sync |
| 101 | /// index is what a seek lands on. An AV1 decoder cannot start without a |
| 102 | /// sequence header, and `mkv` carries it in `CodecPrivate` -- so this is the |
| 103 | /// check that says the `av1C` record was really parsed and re-injected. |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | /// The seat this file used to refuse by name now exists: `ec-av1`, in this |
| 150 | /// process, behind the same `VE_SW` pin the H.264 seat takes. A linear open |
| 151 | /// delivers every frame the container indexes, labelled `0..n` in display |
| 152 | /// order -- the contract the transport reads and the one the hardware seat |
| 153 | /// always kept. |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | /// ...and the 10-bit twin, whose samples arrive as `u16` in `0..=1023` and |
| 164 | /// narrow to the same 8-bit planes the plugin's P010 read-back produces. |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | /// Seeking may only change *when* a picture arrives, never the picture: a seek |
| 175 | /// onto the software seat lands on the very bytes a linear decode of the same |
| 176 | /// index delivered, on either side of and away from a keyframe. The promise |
| 177 | /// `hw_decode::seek_matches_linear_every_container` makes of the hardware |
| 178 | /// seat, made here of the software one -- which is why this runs unignored. |
| 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 | /// A timeline is *not* refused a source coded differently -- every clip opens |
| 213 | /// its own decoder, and since the `ec-av1` seat that is true with no plugin |
| 214 | /// and no driver in the room: the no-plugin machine, forced, takes the AV1 |
| 215 | /// source beside its H.264 one. |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | // --- the refusal witness --------------------------------------------------- |
| 228 | // |
| 229 | // The minimal EBML this file's refusal fixture is written with -- the same |
| 230 | // builders `mkv_encodings.rs` uses, kept local because test binaries do not |
| 231 | // share code. Every size goes out in the 8-byte long form, legal everywhere |
| 232 | // and arithmetic-free. |
| 233 | |
| 234 | const SEGMENT: u32 = 0x1853_8067; |
| 235 | const INFO: u32 = 0x1549_A966; |
| 236 | const TIMESTAMP_SCALE: u32 = 0x2AD7B1; |
| 237 | const TRACKS: u32 = 0x1654_AE6B; |
| 238 | const TRACK_ENTRY: u32 = 0xAE; |
| 239 | const TRACK_NUMBER: u32 = 0xD7; |
| 240 | const TRACK_TYPE: u32 = 0x83; |
| 241 | const CODEC_ID: u32 = 0x86; |
| 242 | const CODEC_PRIVATE: u32 = 0x63A2; |
| 243 | const DEFAULT_DURATION: u32 = 0x23E383; |
| 244 | const VIDEO: u32 = 0xE0; |
| 245 | const PIXEL_WIDTH: u32 = 0xB0; |
| 246 | const PIXEL_HEIGHT: u32 = 0xBA; |
| 247 | const CLUSTER: u32 = 0x1F43_B675; |
| 248 | const CLUSTER_TIMESTAMP: u32 = 0xE7; |
| 249 | const SIMPLE_BLOCK: u32 = 0xA3; |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | /// A `SimpleBlock` of `track`, `rel` ticks into its cluster; `flags` carries |
| 264 | /// the keyframe bit (0x80). |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | /// One OBU's total length inside a low-overhead stream: the header byte (plus |
| 274 | /// its extension byte, which this fixture format never writes) and the |
| 275 | /// leb128 size that `obu_has_size_field` promises. |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | /// A stream whose GOP structure is broken in a way the container cannot see: |
| 292 | /// the second keyframe-flagged block carries an *inter* frame's bytes, as a |
| 293 | /// remux that trusted the wrong key index would write one. The demuxer opens |
| 294 | /// it, injects the sequence header ahead of it, and `ec-av1` refuses it by |
| 295 | /// name -- an inter frame with no key frame behind it finds no saved CDF state |
| 296 | /// to resume from, one of the live refusals its inventory pins -- and the seat |
| 297 | /// fails the span in words instead of a panic or a garbage picture: the frames |
| 298 | /// decoded so far stand, then the channel closes. |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 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 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | /// The end-to-end user path: opening the file yields pictures, all of them, |
| 380 | /// through the plugin. |
| 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 | /// The picture's flattest 8x8 block, as a standard deviation of its green |
| 411 | /// channel: 0 where the decoder handed back a smooth picture, well above it |
| 412 | /// where every pixel carries synthesized grain. |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | /// The defect none of the fixtures above could see: an AV1 frame that asks for |
| 432 | /// film grain is *displayed* from a second surface, which the driver |
| 433 | /// synthesizes the grain into and which the decoder has to give it. Handing it |
| 434 | /// none gets the picture refused outright -- radeonsi answers `vaEndPicture` |
| 435 | /// with VA_STATUS_ERROR_INVALID_SURFACE -- and that killed a real 1080p AV1 |
| 436 | /// film at frame 49, the first of its pictures with `apply_grain` set. Every |
| 437 | /// fixture beside this one is grainless, and every one of them passed. |
| 438 | /// |
| 439 | /// Ninety frames, all of them: a grainy picture costs two pool buffers rather |
| 440 | /// than one, so this turns the pool over several times and cycles the eight |
| 441 | /// reference slots -- decoding "the first handful" is exactly what let the |
| 442 | /// defect live. |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | /// ...and the 10-bit file through the very call the window's open door makes: a |
| 468 | /// user opens it and the timeline shows a picture, read back off the P010 pool |
| 469 | /// to the same 8-bit BGRA every other frame arrives in. The whole point of the |
| 470 | /// slice, and the half a container test cannot say anything about. |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | /// A seek into the second GOP hands back that very frame, not the keyframe it |
| 500 | /// had to restart from: the demuxer's sync index and the plugin's skip count |
| 501 | /// have to agree, and Matroska is where both are this crate's own doing. |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | /// An mp4 export of a Matroska source carries its sound. |
| 515 | /// |
| 516 | /// Three lives, this one. It used to *succeed* silently and write picture with |
| 517 | /// no sound, because this engine could not read a Matroska file's audio at all. |
| 518 | /// Then the sound became readable and this became a refusal by name, because |
| 519 | /// the mp4 path could only *copy* AAC out of an mp4's own sample table and a |
| 520 | /// Matroska file has none. Now the copy that cannot be made is a decode and a |
| 521 | /// re-encode (`export::copy_audio` -> `encode_audio`), so the export carries the |
| 522 | /// film's sound instead of naming what it cannot do with it. The picture half of |
| 523 | /// the same export is [`an_av1_export_reopens_through_our_own_demuxer`]. |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | /// A short timeline out of the H.264 fixture, which is what the AV1 export tests |
| 556 | /// below write: `rav1e` is built here without its assembly, so the length of the |
| 557 | /// timeline is the length of the test. |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | /// The export half of this slice: AV1 out of the software encoder, into a |
| 606 | /// Matroska file this project's own demuxer walks back. Nothing installed is |
| 607 | /// needed -- the file is *read* as a container here, which is where the |
| 608 | /// hand-written EBML either agrees with the hand-written EBML reader or does not. |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | /// A timeline with sound, exported as AV1 into **both** containers: the file |
| 651 | /// carries the picture *and* the timeline's audio, and this project's own |
| 652 | /// readers are what say so -- the demuxer for the picture, the audio session for |
| 653 | /// the sound. An AV1 export used to be picture only, which is a file whose sound |
| 654 | /// went missing with nobody told. |
| 655 | /// |
| 656 | /// Two frames of 720p: `rav1e` is built here without its assembly, so the length |
| 657 | /// of the timeline is the length of the test, and what is under test is the |
| 658 | /// wiring from the format to the muxer, not the encoder. |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | /// A WebM export is the AV1 picture with Opus sound, and says so in its header: |
| 706 | /// the EBML doc type is `webm`, the tracks are `V_AV1` and `A_OPUS` and no AAC |
| 707 | /// track is written anywhere. Two frames, as above. |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | /// An audio-only timeline is refused an AV1 export by name, exactly as it is |
| 759 | /// refused an mp4: every frame of it is a gap, so the file would be black. |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | /// The whole loop, and the only place it is closed: the file the export wrote is |
| 779 | /// decoded back into pictures, and those pictures are the source's. |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | /// The hardware seat of the same pair, which is opt-in: `VE_HW_AV1=1` is what |
| 815 | /// enters it, because the vendored encoder reset the GPU of the box this was |
| 816 | /// written on (see `export::Enc::open_av1`). Without that variable this measures |
| 817 | /// the software encoder again, which is the honest outcome rather than a |
| 818 | /// failure, so what it asserts is the file. |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | /// 4:4:4, 4:2:2 and 12-bit AV1 open in both containers and decode every frame |
| 836 | /// on the software seat, their chroma averaged down to 4:2:0 and 12 bits |
| 837 | /// narrowed (see `av1_chroma_edith.rs` for the match against ffmpeg). |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | /// 8-bit and 10-bit 4:2:0 |
| 854 | /// open with the right depth and decode every frame on the software seat. |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | /// Monochrome (`gray`, the `av1C` mono flag): the one chroma-less shape edith |
| 878 | /// is still willing to open. It is taken only if the seat decodes it into the |
| 879 | /// I420 planes every converter reads; this asserts it does, frame for frame. |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 |