edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The zlib-compressed (`ContentCompAlgo` 0) Matroska subtitle tracks of the |
| 2 | //! owner's own films, against ffprobe. |
| 3 | //! |
| 4 | //! Two keys, both named by `real_library.toml` (gitignored): |
| 5 | //! |
| 6 | //! - `mkv_zlib_pgs`: the `S_HDMV/PGS` tracks. Edith's own Matroska subtitle walk |
| 7 | //! ([`engine::demux::matroska_subtitles`]) reads these, so every payload comes |
| 8 | //! out of `ec_inflate` through the same path the app uses. |
| 9 | //! - `mkv_zlib_vobsub`: the `S_VOBSUB` tracks. Edith's subtitle walk declares |
| 10 | //! them but reads no VobSub payload (see `matroska_subtitles`), so there is no |
| 11 | //! app path for those bytes to take. Their blocks are read here straight out |
| 12 | //! of the file and handed to `ec_inflate` directly, which is the same decoder |
| 13 | //! the app's Matroska demuxer calls. |
| 14 | //! |
| 15 | //! Both sides assert that the track really is zlib-compressed, from a walk of the |
| 16 | //! file's own `ContentEncodings` (never from what edith reports), so the witness |
| 17 | //! cannot pass silently on an uncompressed track. Each packet is compared with |
| 18 | //! `ffprobe -show_packets -show_data_hash MD5` for that stream: packet count, |
| 19 | //! pts in microseconds, duration where edith states one, size, and the MD5 of |
| 20 | //! the decompressed bytes. |
| 21 | //! |
| 22 | //! A key the manifest does not name, or a path not on this machine, skips. |
| 23 | //! Needs ffprobe. |
| 24 | //! |
| 25 | //! ```text |
| 26 | //! cargo test -p engine --test real_library_zlib -- --nocapture |
| 27 | //! ``` |
| 28 | |
| 29 | use cratereallib; |
| 30 | |
| 31 | use Read as _; |
| 32 | use Path; |
| 33 | use Command; |
| 34 | use Instant; |
| 35 | |
| 36 | use ; |
| 37 | use ; |
| 38 | |
| 39 | // The element ids a walk of the file reads, as they are written in it. |
| 40 | const SEGMENT: u32 = 0x1853_8067; |
| 41 | const INFO: u32 = 0x1549_A966; |
| 42 | const TIMESTAMP_SCALE: u32 = 0x2A_D7B1; |
| 43 | const CLUSTER: u32 = 0x1F43_B675; |
| 44 | const CLUSTER_TIMESTAMP: u32 = 0xE7; |
| 45 | const TRACKS: u32 = 0x1654_AE6B; |
| 46 | const TRACK_ENTRY: u32 = 0xAE; |
| 47 | const TRACK_NUMBER: u32 = 0xD7; |
| 48 | const TRACK_TYPE: u32 = 0x83; |
| 49 | const CODEC_ID: u32 = 0x86; |
| 50 | const CONTENT_ENCODINGS: u32 = 0x6D80; |
| 51 | const CONTENT_ENCODING: u32 = 0x6240; |
| 52 | const CONTENT_ENCODING_TYPE: u32 = 0x5033; |
| 53 | const CONTENT_COMPRESSION: u32 = 0x5034; |
| 54 | const CONTENT_COMP_ALGO: u32 = 0x4254; |
| 55 | const BLOCK_GROUP: u32 = 0xA0; |
| 56 | const BLOCK: u32 = 0xA1; |
| 57 | const SIMPLE_BLOCK: u32 = 0xA3; |
| 58 | |
| 59 | /// `TrackType` of a subtitle track. |
| 60 | const SUBTITLE: u64 = 0x11; |
| 61 | /// The Matroska codec id of VobSub bitmaps. |
| 62 | const VOBSUB: &str = "S_VOBSUB"; |
| 63 | /// The same ceiling the app's Matroska demuxer puts on one inflated block. |
| 64 | const LIMIT: usize = 64 << 20; |
| 65 | /// How much of the file the header walk reads. Tracks come before the first |
| 66 | /// cluster, so this is more than enough for the header of any file written here. |
| 67 | const HEAD: usize = 8 << 20; |
| 68 | |
| 69 | /// One `TrackEntry` as the file declares it. |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | /// One block as the file stores it: its track, its absolute timestamp in |
| 91 | /// ticks, its lacing bits and the byte range of its payload in the file. |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | /// What a walk of the file's header and, when asked, its blocks found. |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | /// An EBML variable-length integer at `at`: its value with the length marker |
| 109 | /// dropped (kept for an element id), its length in bytes, and where it ends. |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /// An element header at `at`: its id, its size (`None` for the unknown size a |
| 129 | /// live muxer writes) and where its body starts. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | /// Every header element of `buf`, in file order, descending into the masters |
| 148 | /// this reads and skipping every other body by its size. With `blocks` false the |
| 149 | /// walk stops at the first cluster, which is what a header-only read wants. |
| 150 | /// |
| 151 | /// A block's lacing is recorded, not undone: a laced block is one this witness |
| 152 | /// refuses, so the caller can say so. |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 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 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | /// One packet as edith states it, in microseconds from the start of the file. |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | /// ffprobe's packets of one stream: `-show_packets -show_data_hash MD5`. |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | /// The `time_base` ffprobe states for a stream, as (numerator, denominator). |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | /// Ticks of a stream's time base as microseconds, exactly. |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | /// Compares edith's packets with ffprobe's, packet for packet. Returns the |
| 303 | /// number of disagreements, each named on stderr with the first few. |
| 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 | /// `mkv_zlib_pgs`: every zlib PGS track, its packets read through edith's own |
| 335 | /// Matroska subtitle walk and compared with ffprobe. |
| 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 | |
| 380 | |
| 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 | /// `mkv_zlib_vobsub`: every zlib VobSub track. Blocks are read straight out of |
| 414 | /// the file (the whole file is read: the VobSub titles are tens of megabytes) |
| 415 | /// and inflated with `ec_inflate`, the decoder the Matroska demuxer calls. |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 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 | |
| 468 | |
| 469 | |
| 470 | |
| 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 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 |