edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! EBML: the element grammar Matroska is written in, both directions. |
| 2 | //! |
| 3 | //! An element is an id, a size and a payload, all three of them |
| 4 | //! variable-length. Ids are compared *with* their leading marker bit — that is |
| 5 | //! how the spec writes them and how the constants below are spelled — while a |
| 6 | //! size has the marker stripped, and an all-ones size means "unknown", which is |
| 7 | //! what a muxer writes while it is still recording. |
| 8 | |
| 9 | use ; |
| 10 | |
| 11 | // Element ids, marker bit included. |
| 12 | pub const EBML_HEADER: u32 = 0x1A45_DFA3; |
| 13 | pub const EBML_VERSION: u32 = 0x4286; |
| 14 | pub const EBML_READ_VERSION: u32 = 0x42F7; |
| 15 | pub const EBML_MAX_ID_LENGTH: u32 = 0x42F2; |
| 16 | pub const EBML_MAX_SIZE_LENGTH: u32 = 0x42F3; |
| 17 | pub const DOC_TYPE: u32 = 0x4282; |
| 18 | pub const DOC_TYPE_VERSION: u32 = 0x4287; |
| 19 | pub const DOC_TYPE_READ_VERSION: u32 = 0x4285; |
| 20 | pub const VOID: u32 = 0xEC; |
| 21 | |
| 22 | pub const SEGMENT: u32 = 0x1853_8067; |
| 23 | pub const INFO: u32 = 0x1549_A966; |
| 24 | pub const TIMESTAMP_SCALE: u32 = 0x2AD7B1; |
| 25 | pub const DURATION: u32 = 0x4489; |
| 26 | pub const MUXING_APP: u32 = 0x4D80; |
| 27 | pub const WRITING_APP: u32 = 0x5741; |
| 28 | |
| 29 | pub const TRACKS: u32 = 0x1654_AE6B; |
| 30 | pub const TRACK_ENTRY: u32 = 0xAE; |
| 31 | pub const TRACK_NUMBER: u32 = 0xD7; |
| 32 | pub const TRACK_UID: u32 = 0x73C5; |
| 33 | pub const TRACK_TYPE: u32 = 0x83; |
| 34 | pub const FLAG_LACING: u32 = 0x9C; |
| 35 | pub const FLAG_DEFAULT: u32 = 0x88; |
| 36 | pub const CODEC_ID: u32 = 0x86; |
| 37 | pub const CODEC_PRIVATE: u32 = 0x63A2; |
| 38 | pub const CODEC_DELAY: u32 = 0x56AA; |
| 39 | pub const SEEK_PRE_ROLL: u32 = 0x56BB; |
| 40 | pub const DEFAULT_DURATION: u32 = 0x23E383; |
| 41 | pub const TRACK_NAME: u32 = 0x536E; |
| 42 | pub const TRACK_LANGUAGE: u32 = 0x22B59C; |
| 43 | pub const TRACK_LANGUAGE_BCP47: u32 = 0x22B59D; |
| 44 | |
| 45 | pub const VIDEO: u32 = 0xE0; |
| 46 | pub const FLAG_INTERLACED: u32 = 0x9A; |
| 47 | pub const FIELD_ORDER: u32 = 0x9D; |
| 48 | pub const PIXEL_WIDTH: u32 = 0xB0; |
| 49 | pub const PIXEL_HEIGHT: u32 = 0xBA; |
| 50 | pub const DISPLAY_WIDTH: u32 = 0x54B0; |
| 51 | pub const DISPLAY_HEIGHT: u32 = 0x54BA; |
| 52 | pub const COLOUR: u32 = 0x55B0; |
| 53 | pub const MATRIX_COEFFICIENTS: u32 = 0x55B1; |
| 54 | pub const RANGE: u32 = 0x55B9; |
| 55 | pub const TRANSFER_CHARACTERISTICS: u32 = 0x55BA; |
| 56 | pub const PRIMARIES: u32 = 0x55BB; |
| 57 | pub const MAX_CLL: u32 = 0x55BC; |
| 58 | pub const MAX_FALL: u32 = 0x55BD; |
| 59 | pub const MASTERING_METADATA: u32 = 0x55D0; |
| 60 | pub const PRIMARY_R_X: u32 = 0x55D1; |
| 61 | pub const PRIMARY_R_Y: u32 = 0x55D2; |
| 62 | pub const PRIMARY_G_X: u32 = 0x55D3; |
| 63 | pub const PRIMARY_G_Y: u32 = 0x55D4; |
| 64 | pub const PRIMARY_B_X: u32 = 0x55D5; |
| 65 | pub const PRIMARY_B_Y: u32 = 0x55D6; |
| 66 | pub const WHITE_POINT_X: u32 = 0x55D7; |
| 67 | pub const WHITE_POINT_Y: u32 = 0x55D8; |
| 68 | pub const LUMINANCE_MAX: u32 = 0x55D9; |
| 69 | pub const LUMINANCE_MIN: u32 = 0x55DA; |
| 70 | |
| 71 | pub const AUDIO: u32 = 0xE1; |
| 72 | pub const SAMPLING_FREQUENCY: u32 = 0xB5; |
| 73 | pub const CHANNELS: u32 = 0x9F; |
| 74 | pub const BIT_DEPTH: u32 = 0x6264; |
| 75 | |
| 76 | pub const CONTENT_ENCODINGS: u32 = 0x6D80; |
| 77 | pub const CONTENT_ENCODING: u32 = 0x6240; |
| 78 | pub const CONTENT_ENCODING_SCOPE: u32 = 0x5032; |
| 79 | pub const CONTENT_ENCODING_TYPE: u32 = 0x5033; |
| 80 | pub const CONTENT_COMPRESSION: u32 = 0x5034; |
| 81 | pub const CONTENT_COMP_ALGO: u32 = 0x4254; |
| 82 | pub const CONTENT_COMP_SETTINGS: u32 = 0x4255; |
| 83 | |
| 84 | pub const SEEK_HEAD: u32 = 0x114D_9B74; |
| 85 | pub const SEEK: u32 = 0x4DBB; |
| 86 | pub const SEEK_ID: u32 = 0x53AB; |
| 87 | pub const SEEK_POSITION: u32 = 0x53AC; |
| 88 | pub const CUES: u32 = 0x1C53_BB6B; |
| 89 | pub const CUE_POINT: u32 = 0xBB; |
| 90 | pub const CUE_TIME: u32 = 0xB3; |
| 91 | pub const CUE_TRACK_POSITIONS: u32 = 0xB7; |
| 92 | pub const CUE_TRACK: u32 = 0xF7; |
| 93 | pub const CUE_CLUSTER_POSITION: u32 = 0xF1; |
| 94 | pub const CUE_RELATIVE_POSITION: u32 = 0xF0; |
| 95 | |
| 96 | pub const CLUSTER: u32 = 0x1F43_B675; |
| 97 | pub const CLUSTER_TIMESTAMP: u32 = 0xE7; |
| 98 | pub const SIMPLE_BLOCK: u32 = 0xA3; |
| 99 | pub const BLOCK_GROUP: u32 = 0xA0; |
| 100 | pub const BLOCK: u32 = 0xA1; |
| 101 | pub const BLOCK_DURATION: u32 = 0x9B; |
| 102 | pub const REFERENCE_BLOCK: u32 = 0xFB; |
| 103 | |
| 104 | /// The four bytes a `Cluster` id is written as, which is what a damaged file is |
| 105 | /// resynchronised on. |
| 106 | pub const CLUSTER_MAGIC: = ; |
| 107 | |
| 108 | /// EBML variable-length integer: the leading zeros of the first byte say how |
| 109 | /// many bytes it takes. `strip` clears the marker bit, which is what a *size* |
| 110 | /// wants and an *id* does not — an id is written and compared with it. An |
| 111 | /// all-ones size means unknown length, and comes back as [`u64::MAX`]. |
| 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 | /// Id, size and header length of the element at the head of `buf`. The size is |
| 139 | /// [`None`] for an unknown-length element. |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | /// The children of an element already in memory, as `(id, payload range)`. |
| 149 | /// |
| 150 | /// Iteration stops at the first header that does not fit, which is how a caller |
| 151 | /// bounds a child to its parent: by handing over the parent's bytes. |
| 152 | |
| 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 | /// An unsigned EBML integer, big-endian in as many bytes as it was written |
| 194 | /// with. An absent element is a zero by the spec's own default. |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | /// An EBML float: IEEE big-endian, 4 or 8 bytes wide. Zero for any other width, |
| 200 | /// which is what an absent one is by spec. |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | /// An EBML string, trimmed of the zero padding a muxer may pad it to width with. |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | // ---------------------------------------------------------------- writing --- |
| 218 | |
| 219 | /// An element id, in the bytes it is written as. |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | /// An element size as a variable-length integer, in the fewest bytes that hold |
| 227 | /// it. A value of all ones means *unknown* length, so a size that would land on |
| 228 | /// one takes a byte more. |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | /// A whole element: id, size, payload. |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | /// An unsigned integer element, big-endian in as few bytes as it takes (one at |
| 246 | /// the least: a zero is a byte, not an absence). |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | /// A 64-bit float element. |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | /// How many bytes an element's id and size take, which is what an offset inside |
| 259 | /// a payload has to be moved by to become an offset in the file. |
| 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 |