edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! Atmos backward compatibility, tested on a synthetic 4-substream stream. |
| 2 | //! |
| 3 | //! No real Atmos TrueHD stream is available to this build, so the stream is |
| 4 | //! built from the real 7.1 Blu-ray remux's own access units (the first |
| 5 | //! [`AUS`] of its TrueHD track, 3 substreams each). For every access unit, |
| 6 | //! [`with_object_substream`] rebuilds it with a 4th directory entry: the |
| 7 | //! object-audio substream, here a run of [`FILLER_WORDS`] stand-in words |
| 8 | //! appended after substream 2's coded data. The rebuilt access unit is: |
| 9 | //! |
| 10 | //! - header: length word (new word count, parity nibble recomputed) and the |
| 11 | //! original input timing; |
| 12 | //! - major sync, when the original has one: `num_substreams` (top nibble of |
| 13 | //! byte 16) set to 4, and the major sync's own CRC-16 (bytes 26..28) |
| 14 | //! recomputed; |
| 15 | //! - directory: the original three entries unchanged (their cumulative end |
| 16 | //! pointers are relative to the directory end, so the coded data they name |
| 17 | //! does not move relative to it), then a fourth entry whose end pointer is |
| 18 | //! the old last pointer plus the filler length; |
| 19 | //! - substream data: the original substreams 0..2 bytes verbatim, then the |
| 20 | //! filler. |
| 21 | //! |
| 22 | //! Decoding the synthetic stream must therefore equal decoding the original |
| 23 | //! bit-exactly: the 8-channel (7.1) presentation is the one decoded and |
| 24 | //! output, substream 3 is skipped via its end pointer, and the parity and |
| 25 | //! checksum of substreams 0..2 are still checked. Object audio itself is out |
| 26 | //! of scope and never decoded, so the filler's contents must not matter; a |
| 27 | //! second test checks that. |
| 28 | //! |
| 29 | //! Optional cross-check: with `EC_ATMOS_SYNTH_OUT=<path>` set, the synthetic |
| 30 | //! access units are also written there as a raw TrueHD elementary stream, so |
| 31 | //! `ffmpeg -f truehd -i <path> -f s32le` can be compared against this |
| 32 | //! decoder's output (ffmpeg decodes the same 8-channel presentation). |
| 33 | //! |
| 34 | //! Needs the 7.1 remux under `~/Downloads`. Absent, the tests skip loudly; with |
| 35 | //! `EC_REQUIRE_FIXTURES=1` an absent remux is a hard failure. |
| 36 | |
| 37 | use File; |
| 38 | use BufReader; |
| 39 | use ; |
| 40 | |
| 41 | use CodecId; |
| 42 | use Demuxer; |
| 43 | use ChannelLayout; |
| 44 | use MatroskaDemuxer; |
| 45 | use TrueHdDecoder; |
| 46 | use AccessUnitHeader; |
| 47 | |
| 48 | /// Access units taken from the start of the remux: 1 s of 48 kHz audio, one |
| 49 | /// major sync among them. |
| 50 | const AUS: usize = 1200; |
| 51 | /// Length of the object-audio stand-in, in 16-bit words. |
| 52 | const FILLER_WORDS: u16 = 4; |
| 53 | /// The 12-bit access-unit length word's maximum, in 16-bit words. |
| 54 | const MAX_AU_WORDS: usize = 0x0FFF; |
| 55 | const MAJOR_SYNC_LEN: usize = 28; |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | /// The first [`AUS`] access units of the remux's TrueHD track, or `None` |
| 82 | /// (after a loud skip, or a hard failure under `EC_REQUIRE_FIXTURES`). |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// The major sync's CRC-16 (poly `0x002D`, MSB-first table form), the same |
| 120 | /// one the crate's encoder writes and ffmpeg checks. |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | /// The major sync's checksum field value: CRC-16 over bytes `0..24`, XORed |
| 135 | /// with the little-endian word at `24..26`, stored little-endian at `26..28`. |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | /// The access-unit header's parity fold: the 4 header bytes and every |
| 146 | /// directory byte, XORed together, must leave a nibble pair that is bitwise |
| 147 | /// complementary (`((p >> 4) ^ p) & 0xF == 0xF`). |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | /// Rebuilds one access unit of the 7.1 remux with a 4th (object-audio) |
| 154 | /// directory entry whose coded data is `FILLER_WORDS` words of `filler`. |
| 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 | /// One decoded frame: its layout and its planes. |
| 231 | type Decoded = ; |
| 232 | |
| 233 | /// Decodes `aus` with a fresh decoder and returns every output frame's planes |
| 234 | /// plus the decoder's self-check tallies. |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 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 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 |