Skip to main content

mkv_element/
master.rs

1use crate::Error;
2use crate::base::*;
3use crate::element::*;
4use crate::frame::ClusterBlock;
5use crate::leaf::*;
6use crate::supplement::*;
7
8use crate::*;
9
10// A helper for generating nested elements.
11/* example:
12nested! {
13    required: [ EbmlMaxIdLength, EbmlMaxSizeLength ],
14    optional: [ EbmlVersion, EbmlReadVersion, DocType, DocTypeVersion, DocTypeReadVersion ],
15    multiple: [ ],
16};
17*/
18macro_rules! nested {
19    (required: [$($required:ident),*$(,)?], optional: [$($optional:ident),*$(,)?], multiple: [$($multiple:ident),*$(,)?],) => {
20        paste::paste! {
21            fn decode_body<B: Buf>(buf: &mut B) -> crate::Result<Self> {
22                let crc32 = if buf.remaining() > 6 && buf.chunk()[0] == 0xBF && buf.chunk()[1] == 0x84 {
23                    Some(Crc32::decode(buf)?)
24                } else {
25                    None
26                };
27
28                $( let mut [<$required:snake>] = None;)*
29                $( let mut [<$optional:snake>] = None;)*
30                $( let mut [<$multiple:snake>] = Vec::new();)*
31                let mut void: Option<Void> = None;
32
33                while let Ok(header) = Header::decode(buf) {
34                    if *header.size > buf.remaining() as u64 {
35                        return Err(Error::try_get_error(*header.size as usize, buf.remaining()));
36                    }
37                    let body_size = *header.size as usize;
38                    match header.id {
39                        $( $required::ID => {
40                            if [<$required:snake>].is_some() {
41                                return Err(Error::DuplicateElement { id: header.id, parent: Self::ID });
42                            } else {
43                                let mut body = &buf.chunk()[..body_size];
44                                [<$required:snake>] = Some($required::decode_body(&mut body)?);
45                                buf.advance(body_size);
46                            }
47                        } )*
48                        $( $optional::ID => {
49                            if [<$optional:snake>].is_some() {
50                                return Err(Error::DuplicateElement { id: header.id, parent: Self::ID });
51                            } else {
52                                let mut body = &buf.chunk()[..body_size];
53                                [<$optional:snake>] = Some($optional::decode_body(&mut body)?);
54                                buf.advance(body_size);
55                            }
56                        } )*
57                        $( $multiple::ID => {
58                            let mut body = &buf.chunk()[..body_size];
59                            [<$multiple:snake>].push($multiple::decode_body(&mut body)?);
60                            buf.advance(body_size);
61                        } )*
62                        Void::ID => {
63                            let mut body = &buf.chunk()[..body_size];
64                            let v = Void::decode_body(&mut body)?;
65                            buf.advance(body_size);
66                            if let Some(previous) = void {
67                                void = Some(Void { size: previous.size + v.size });
68                            } else {
69                                void = Some(v);
70                            }
71                            log::info!("Skipping Void element in Element {}, size: {}B", Self::ID, *header.size);
72                        }
73                        _ => {
74                            buf.advance(*header.size as usize);
75                            log::warn!("Unknown element {}({}b) in Element({})", header.id, *header.size, Self::ID);
76                        }
77                    }
78                }
79
80                if buf.has_remaining() {
81                    return Err(Error::ShortRead);
82                }
83
84                Ok(Self {
85                    crc32,
86                    $( [<$required:snake>]: [<$required:snake>].or(if $required::HAS_DEFAULT_VALUE { Some($required::default()) } else { None }).ok_or(Error::MissingElement($required::ID))?, )*
87                    $( [<$optional:snake>], )*
88                    $( [<$multiple:snake>], )*
89                    void,
90                })
91            }
92            fn encode_body<B: BufMut>(&self, buf: &mut B) -> crate::Result<()> {
93                self.crc32.encode(buf)?;
94
95                $( self.[<$required:snake>].encode(buf)?; )*
96                $( self.[<$optional:snake>].encode(buf)?; )*
97                $( self.[<$multiple:snake>].encode(buf)?; )*
98
99                self.void.encode(buf)?;
100
101                Ok(())
102            }
103        }
104    };
105}
106
107/// EBML element, the first top-level element in a Matroska file.
108#[derive(Debug, Clone, PartialEq, Eq, Default)]
109pub struct Ebml {
110    /// Optional CRC-32 element for integrity checking.
111    pub crc32: Option<Crc32>,
112    /// void element, useful for reserving space during writing.
113    pub void: Option<Void>,
114
115    /// EBMLVersion element, indicates the version of EBML used.
116    pub ebml_version: Option<EbmlVersion>,
117    /// EBMLReadVersion element, indicates the minimum version of EBML required to read the file.
118    pub ebml_read_version: Option<EbmlReadVersion>,
119    /// EBMLMaxIDLength element, indicates the maximum length of an EBML ID in bytes.
120    pub ebml_max_id_length: EbmlMaxIdLength,
121    /// EBMLMaxSizeLength element, indicates the maximum length of an EBML size in bytes.
122    pub ebml_max_size_length: EbmlMaxSizeLength,
123    /// DocType element, indicates the type of document. For Matroska files, this is usually "matroska" or "webm".
124    pub doc_type: Option<DocType>,
125    /// DocTypeVersion element, indicates the version of the document type.
126    pub doc_type_version: Option<DocTypeVersion>,
127    /// DocTypeReadVersion element, indicates the minimum version of the document type required to read the file.
128    pub doc_type_read_version: Option<DocTypeReadVersion>,
129}
130
131impl Element for Ebml {
132    const ID: VInt64 = VInt64::from_encoded(0x1A45_DFA3);
133    nested! {
134        required: [ EbmlMaxIdLength, EbmlMaxSizeLength ],
135        optional: [ EbmlVersion, EbmlReadVersion, DocType, DocTypeVersion, DocTypeReadVersion ],
136        multiple: [ ],
137    }
138}
139
140/// The Root Element that contains all other Top-Level Elements; see data-layout.
141#[derive(Debug, Clone, PartialEq)]
142pub struct Segment {
143    /// Optional CRC-32 element for integrity checking.
144    pub crc32: Option<Crc32>,
145    /// void element, useful for reserving space during writing.
146    pub void: Option<Void>,
147
148    /// Contains seeking information of Top-Level Elements; see data-layout.
149    pub seek_head: Vec<SeekHead>,
150    /// Contains general information about the Segment.
151    pub info: Info,
152    /// The Top-Level Element containing the (monolithic) Block structure.
153    pub cluster: Vec<Cluster>,
154    /// A Top-Level Element of information with many tracks described.
155    pub tracks: Option<Tracks>,
156    /// A Top-Level Element to speed seeking access. All entries are local to the Segment. This Element **SHOULD** be set when the Segment is not transmitted as a live stream (see #livestreaming).
157    pub cues: Option<Cues>,
158    /// Contain attached files.
159    pub attachments: Option<Attachments>,
160    /// A system to define basic menus and partition data. For more detailed information, look at the Chapters explanation in chapters.
161    pub chapters: Option<Chapters>,
162    /// Element containing metadata describing Tracks, Editions, Chapters, Attachments, or the Segment as a whole. A list of valid tags can be found in [Matroska tagging RFC](https://www.matroska.org/technical/tagging.html).
163    pub tags: Vec<Tags>,
164}
165
166impl Element for Segment {
167    const ID: VInt64 = VInt64::from_encoded(0x18538067);
168    nested! {
169      required: [ Info ],
170      optional: [ Tracks, Cues, Attachments, Chapters ],
171      multiple: [ SeekHead, Tags, Cluster ],
172    }
173}
174
175/// Contains seeking information of Top-Level Elements; see data-layout.
176#[derive(Debug, Clone, PartialEq, Eq, Default)]
177pub struct SeekHead {
178    /// Optional CRC-32 element for integrity checking.
179    pub crc32: Option<Crc32>,
180    /// void element, useful for reserving space during writing.
181    pub void: Option<Void>,
182
183    /// Contains a single seek entry to an EBML Element.
184    pub seek: Vec<Seek>,
185}
186
187impl Element for SeekHead {
188    const ID: VInt64 = VInt64::from_encoded(0x114D9B74);
189    nested! {
190      required: [ ],
191      optional: [ ],
192      multiple: [ Seek ],
193    }
194}
195
196/// Contains a single seek entry to an EBML Element.
197#[derive(Debug, Clone, PartialEq, Eq)]
198pub struct Seek {
199    /// Optional CRC-32 element for integrity checking.
200    pub crc32: Option<Crc32>,
201    /// void element, useful for reserving space during writing.
202    pub void: Option<Void>,
203
204    /// The binary EBML ID of a Top-Level Element.
205    pub seek_id: SeekId,
206    /// The Segment Position (segment-position) of a Top-Level Element.
207    pub seek_position: SeekPosition,
208}
209
210impl Element for Seek {
211    const ID: VInt64 = VInt64::from_encoded(0x4DBB);
212    nested! {
213      required: [ SeekId, SeekPosition ],
214      optional: [ ],
215      multiple: [ ],
216    }
217}
218
219/// Contains general information about the Segment.
220#[derive(Debug, Clone, PartialEq, Default)]
221pub struct Info {
222    /// Optional CRC-32 element for integrity checking.
223    pub crc32: Option<Crc32>,
224    /// void element, useful for reserving space during writing.
225    pub void: Option<Void>,
226
227    /// A randomly generated unique ID to identify the Segment amongst many others (128 bits). It is equivalent to a UUID v4 \[@!RFC4122\] with all bits randomly (or pseudo-randomly) chosen. An actual UUID v4 value, where some bits are not random, **MAY** also be used. If the Segment is a part of a Linked Segment, then this Element is **REQUIRED**. The value of the unique ID **MUST** contain at least one bit set to 1.
228    pub segment_uuid: Option<SegmentUuid>,
229    /// A filename corresponding to this Segment.
230    pub segment_filename: Option<SegmentFilename>,
231    /// An ID to identify the previous Segment of a Linked Segment. If the Segment is a part of a Linked Segment that uses Hard Linking (hard-linking), then either the PrevUUID or the NextUUID Element is **REQUIRED**. If a Segment contains a PrevUUID but not a NextUUID, then it **MAY** be considered as the last Segment of the Linked Segment. The PrevUUID **MUST NOT** be equal to the SegmentUUID.
232    pub prev_uuid: Option<PrevUuid>,
233    /// A filename corresponding to the file of the previous Linked Segment. Provision of the previous filename is for display convenience, but PrevUUID **SHOULD** be considered authoritative for identifying the previous Segment in a Linked Segment.
234    pub prev_filename: Option<PrevFilename>,
235    /// An ID to identify the next Segment of a Linked Segment. If the Segment is a part of a Linked Segment that uses Hard Linking (hard-linking), then either the PrevUUID or the NextUUID Element is **REQUIRED**. If a Segment contains a NextUUID but not a PrevUUID, then it **MAY** be considered as the first Segment of the Linked Segment. The NextUUID **MUST NOT** be equal to the SegmentUUID.
236    pub next_uuid: Option<NextUuid>,
237    /// A filename corresponding to the file of the next Linked Segment. Provision of the next filename is for display convenience, but NextUUID **SHOULD** be considered authoritative for identifying the Next Segment.
238    pub next_filename: Option<NextFilename>,
239    /// A unique ID that all Segments of a Linked Segment **MUST** share (128 bits). It is equivalent to a UUID v4 \[@!RFC4122\] with all bits randomly (or pseudo-randomly) chosen. An actual UUID v4 value, where some bits are not random, **MAY** also be used. If the Segment Info contains a `ChapterTranslate` element, this Element is **REQUIRED**.
240    pub segment_family: Vec<SegmentFamily>,
241    /// The mapping between this `Segment` and a segment value in the given Chapter Codec. Chapter Codec may need to address different segments, but they may not know of the way to identify such segment when stored in Matroska. This element and its child elements add a way to map the internal segments known to the Chapter Codec to the Segment IDs in Matroska. This allows remuxing a file with Chapter Codec without changing the content of the codec data, just the Segment mapping.
242    pub chapter_translate: Vec<ChapterTranslate>,
243    /// Base unit for Segment Ticks and Track Ticks, in nanoseconds. A TimestampScale value of 1000000 means scaled timestamps in the Segment are expressed in milliseconds; see timestamps on how to interpret timestamps.
244    pub timestamp_scale: TimestampScale,
245    /// Duration of the Segment, expressed in Segment Ticks which is based on TimestampScale; see timestamp-ticks.
246    pub duration: Option<Duration>,
247    /// The date and time that the Segment was created by the muxing application or library.
248    pub date_utc: Option<DateUtc>,
249    /// General name of the Segment
250    pub title: Option<Title>,
251    /// Muxing application or library (example: "libmatroska-0.4.3"). Include the full name of the application or library followed by the version number.
252    pub muxing_app: MuxingApp,
253    /// Writing application (example: "mkvmerge-0.3.3"). Include the full name of the application followed by the version number.
254    pub writing_app: WritingApp,
255}
256
257impl Element for Info {
258    const ID: VInt64 = VInt64::from_encoded(0x1549A966);
259    nested! {
260      required: [ TimestampScale, MuxingApp, WritingApp ],
261      optional: [ SegmentUuid, SegmentFilename, PrevUuid, PrevFilename, NextUuid, NextFilename, Duration, DateUtc, Title ],
262      multiple: [ SegmentFamily, ChapterTranslate ],
263    }
264}
265
266/// The mapping between this `Segment` and a segment value in the given Chapter Codec. Chapter Codec may need to address different segments, but they may not know of the way to identify such segment when stored in Matroska. This element and its child elements add a way to map the internal segments known to the Chapter Codec to the Segment IDs in Matroska. This allows remuxing a file with Chapter Codec without changing the content of the codec data, just the Segment mapping.
267#[derive(Debug, Clone, PartialEq, Eq)]
268pub struct ChapterTranslate {
269    /// Optional CRC-32 element for integrity checking.
270    pub crc32: Option<Crc32>,
271    /// void element, useful for reserving space during writing.
272    pub void: Option<Void>,
273
274    /// The binary value used to represent this Segment in the chapter codec data. The format depends on the ChapProcessCodecID used; see [ChapProcessCodecID](https://www.matroska.org/technical/elements.html#chapprocesscodecid-element).
275    pub chapter_translate_id: ChapterTranslateId,
276    /// This `ChapterTranslate` applies to this chapter codec of the given chapter edition(s); see ChapProcessCodecID.
277    /// * 0 - Matroska Script,
278    /// * 1 - DVD-menu
279    pub chapter_translate_codec: ChapterTranslateCodec,
280    /// Specify a chapter edition UID on which this `ChapterTranslate` applies. When no `ChapterTranslateEditionUID` is specified in the `ChapterTranslate`, the `ChapterTranslate` applies to all chapter editions found in the Segment using the given `ChapterTranslateCodec`.
281    pub chapter_translate_edition_uid: Vec<ChapterTranslateEditionUid>,
282}
283
284impl Element for ChapterTranslate {
285    const ID: VInt64 = VInt64::from_encoded(0x6924);
286    nested! {
287        required: [ ChapterTranslateId, ChapterTranslateCodec ],
288        optional: [ ],
289        multiple: [ ChapterTranslateEditionUid ],
290    }
291}
292
293/// The Top-Level Element containing the (monolithic) Block structure.
294#[derive(Debug, Clone, PartialEq, Eq, Default)]
295pub struct Cluster {
296    /// Optional CRC-32 element for integrity checking.
297    pub crc32: Option<Crc32>,
298    /// void element, useful for reserving space during writing.
299    pub void: Option<Void>,
300
301    /// Absolute timestamp of the cluster, expressed in Segment Ticks which is based on TimestampScale; see timestamp-ticks. This element **SHOULD** be the first child element of the Cluster it belongs to, or the second if that Cluster contains a CRC-32 element (crc-32).
302    pub timestamp: Timestamp,
303    /// The Segment Position of the Cluster in the Segment (0 in live streams). It might help to resynchronise offset on damaged streams.
304    pub position: Option<Position>,
305    /// Size of the previous Cluster, in octets. Can be useful for backward playing.
306    pub prev_size: Option<PrevSize>,
307    /// One or more blocks of data (see Block and SimpleBlock) and their associated data (see BlockGroup).
308    pub blocks: Vec<ClusterBlock>,
309}
310
311// Here we manually implement Element for Cluster, aggregating both SimpleBlock and BlockGroup into ClusterBlock, preserving their order.
312impl Element for Cluster {
313    const ID: VInt64 = VInt64::from_encoded(0x1F43B675);
314    fn decode_body<B: Buf>(buf: &mut B) -> crate::Result<Self> {
315        let crc32 = if buf.remaining() > 6 && buf.chunk()[0] == 0xBF && buf.chunk()[1] == 0x84 {
316            Some(Crc32::decode(buf)?)
317        } else {
318            None
319        };
320
321        let mut timestamp = None;
322        let mut position = None;
323        let mut prev_size = None;
324        let mut blocks = Vec::new();
325
326        let mut void: Option<Void> = None;
327
328        while let Ok(header) = Header::decode(buf) {
329            if *header.size > buf.remaining() as u64 {
330                return Err(Error::OverDecode(header.id));
331            }
332            let body_size = *header.size as usize;
333            match header.id {
334                Timestamp::ID => {
335                    if timestamp.is_some() {
336                        return Err(Error::DuplicateElement {
337                            id: header.id,
338                            parent: Self::ID,
339                        });
340                    } else {
341                        let mut body = &buf.chunk()[..body_size];
342                        timestamp = Some(Timestamp::decode_body(&mut body)?);
343                        buf.advance(body_size);
344                    }
345                }
346                Position::ID => {
347                    if position.is_some() {
348                        return Err(Error::DuplicateElement {
349                            id: header.id,
350                            parent: Self::ID,
351                        });
352                    } else {
353                        let mut body = &buf.chunk()[..body_size];
354                        position = Some(Position::decode_body(&mut body)?);
355                        buf.advance(body_size);
356                    }
357                }
358                PrevSize::ID => {
359                    if prev_size.is_some() {
360                        return Err(Error::DuplicateElement {
361                            id: header.id,
362                            parent: Self::ID,
363                        });
364                    } else {
365                        let mut body = &buf.chunk()[..body_size];
366                        prev_size = Some(PrevSize::decode_body(&mut body)?);
367                        buf.advance(body_size);
368                    }
369                }
370                SimpleBlock::ID => {
371                    let mut body = &buf.chunk()[..body_size];
372                    blocks.push(SimpleBlock::decode_body(&mut body)?.into());
373                    buf.advance(body_size);
374                }
375                BlockGroup::ID => {
376                    let mut body = &buf.chunk()[..body_size];
377                    blocks.push(BlockGroup::decode_body(&mut body)?.into());
378                    buf.advance(body_size);
379                }
380                Void::ID => {
381                    let mut body = &buf.chunk()[..body_size];
382                    let v = Void::decode_body(&mut body)?;
383                    buf.advance(body_size);
384                    if let Some(previous) = void {
385                        void = Some(Void {
386                            size: previous.size + v.size,
387                        });
388                    } else {
389                        void = Some(v);
390                    }
391                    log::info!(
392                        "Skipping Void element in Element {}, size: {}B",
393                        Self::ID,
394                        *header.size
395                    );
396                }
397                _ => {
398                    buf.advance(*header.size as usize);
399                    log::warn!(
400                        "Unknown element {}({}b) in Element({})",
401                        header.id,
402                        *header.size,
403                        Self::ID
404                    );
405                }
406            }
407        }
408
409        if buf.has_remaining() {
410            return Err(Error::ShortRead);
411        }
412
413        Ok(Self {
414            crc32,
415            timestamp: timestamp.ok_or(Error::MissingElement(Timestamp::ID))?,
416            position,
417            prev_size,
418            blocks,
419            void,
420        })
421    }
422
423    fn encode_body<B: BufMut>(&self, buf: &mut B) -> crate::Result<()> {
424        self.crc32.encode(buf)?;
425        self.timestamp.encode(buf)?;
426        self.position.encode(buf)?;
427        self.prev_size.encode(buf)?;
428        self.blocks.encode(buf)?;
429
430        self.void.encode(buf)?;
431        Ok(())
432    }
433}
434
435/// Basic container of information containing a single Block and information specific to that Block.
436#[derive(Debug, Clone, PartialEq, Eq, Default)]
437pub struct BlockGroup {
438    /// Optional CRC-32 element for integrity checking.
439    pub crc32: Option<Crc32>,
440    /// void element, useful for reserving space during writing.
441    pub void: Option<Void>,
442
443    /// Block containing the actual data to be rendered and a timestamp relative to the Cluster Timestamp; see [basics](https://www.matroska.org/technical/basics.html#block-structure) on Block Structure.
444    pub block: Block,
445    /// Contain additional binary data to complete the main one; see Codec BlockAdditions section of [Matroska codec RFC](https://www.matroska.org/technical/codec_specs.html) for more information. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data.
446    pub block_additions: Option<BlockAdditions>,
447    /// The duration of the Block, expressed in Track Ticks; see timestamp-ticks.
448    /// The BlockDuration Element can be useful at the end of a Track to define the duration of the last frame (as there is no subsequent Block available),
449    /// or when there is a break in a track like for subtitle tracks.
450    /// When not written and with no DefaultDuration, the value is assumed to be the difference between the timestamp of this Block and the timestamp of the next Block in "display" order (not coding order). BlockDuration **MUST** be set if the associated TrackEntry stores a DefaultDuration value.
451    pub block_duration: Option<BlockDuration>,
452    /// This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced.
453    pub reference_priority: ReferencePriority,
454    /// A timestamp value, relative to the timestamp of the Block in this BlockGroup, expressed in Track Ticks; see timestamp-ticks. This is used to reference other frames necessary to decode this frame. The relative value **SHOULD** correspond to a valid `Block` this `Block` depends on. Historically Matroska Writer didn't write the actual `Block(s)` this `Block` depends on, but *some* `Block` in the past. The value "0" **MAY** also be used to signify this `Block` cannot be decoded on its own, but without knownledge of which `Block` is necessary. In this case, other `ReferenceBlock` **MUST NOT** be found in the same `BlockGroup`. If the `BlockGroup` doesn't have any `ReferenceBlock` element, then the `Block` it contains can be decoded without using any other `Block` data.
455    pub reference_block: Vec<ReferenceBlock>,
456    /// The new codec state to use. Data interpretation is private to the codec. This information **SHOULD** always be referenced by a seek entry.
457    pub codec_state: Option<CodecState>,
458    /// Duration of the silent data added to the Block, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks (padding at the end of the Block for positive value, at the beginning of the Block for negative value). The duration of DiscardPadding is not calculated in the duration of the TrackEntry and **SHOULD** be discarded during playback.
459    pub discard_padding: Option<DiscardPadding>,
460}
461
462impl Element for BlockGroup {
463    const ID: VInt64 = VInt64::from_encoded(0xA0);
464    nested! {
465      required: [ Block, ReferencePriority ],
466      optional: [ BlockAdditions, BlockDuration, CodecState, DiscardPadding ],
467      multiple: [ ReferenceBlock ],
468    }
469}
470/// Contain additional binary data to complete the main one; see Codec BlockAdditions section of [Matroska codec RFC](https://www.matroska.org/technical/codec_specs.html) for more information. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data.
471#[derive(Debug, Clone, PartialEq, Eq, Default)]
472pub struct BlockAdditions {
473    /// Optional CRC-32 element for integrity checking.
474    pub crc32: Option<Crc32>,
475    /// void element, useful for reserving space during writing.
476    pub void: Option<Void>,
477
478    /// Contain the BlockAdditional and some parameters.
479    pub block_more: Vec<BlockMore>,
480}
481
482impl Element for BlockAdditions {
483    const ID: VInt64 = VInt64::from_encoded(0x75A1);
484    nested! {
485      required: [ ],
486      optional: [ ],
487      multiple: [ BlockMore ],
488    }
489}
490
491/// Contain the BlockAdditional and some parameters.
492#[derive(Debug, Clone, PartialEq, Eq, Default)]
493pub struct BlockMore {
494    /// Optional CRC-32 element for integrity checking.
495    pub crc32: Option<Crc32>,
496    /// void element, useful for reserving space during writing.
497    pub void: Option<Void>,
498
499    /// Interpreted by the codec as it wishes (using the BlockAddID).
500    pub block_additional: BlockAdditional,
501    /// An ID to identify how to interpret the BlockAdditional data; see Codec BlockAdditions section of [Matroska codec RFC](https://www.matroska.org/technical/codec_specs.html) for more information. A value of 1 indicates that the meaning of the BlockAdditional data is defined by the codec. Any other value indicates the meaning of the BlockAdditional data is found in the BlockAddIDType found in the TrackEntry. Each BlockAddID value **MUST** be unique between all BlockMore elements found in a BlockAdditions.To keep MaxBlockAdditionID as low as possible, small values **SHOULD** be used.
502    pub block_add_id: BlockAddId,
503}
504
505impl Element for BlockMore {
506    const ID: VInt64 = VInt64::from_encoded(0xA6);
507    nested! {
508      required: [ BlockAdditional, BlockAddId ],
509      optional: [ ],
510      multiple: [ ],
511    }
512}
513
514/// A Top-Level Element of information with many tracks described.
515#[derive(Debug, Clone, PartialEq, Default)]
516pub struct Tracks {
517    /// Optional CRC-32 element for integrity checking.
518    pub crc32: Option<Crc32>,
519    /// void element, useful for reserving space during writing.
520    pub void: Option<Void>,
521
522    /// Describes a track with all Elements.
523    pub track_entry: Vec<TrackEntry>,
524}
525
526impl Element for Tracks {
527    const ID: VInt64 = VInt64::from_encoded(0x1654AE6B);
528    nested! {
529      required: [ ],
530      optional: [ ],
531      multiple: [ TrackEntry ],
532    }
533}
534
535/// Describes a track with all Elements.
536#[derive(Debug, Clone, PartialEq, Default)]
537pub struct TrackEntry {
538    /// Optional CRC-32 element for integrity checking.
539    pub crc32: Option<Crc32>,
540    /// void element, useful for reserving space during writing.
541    pub void: Option<Void>,
542
543    /// The track number as used in the Block Header.
544    pub track_number: TrackNumber,
545    /// A unique ID to identify the Track.
546    pub track_uid: TrackUid,
547    /// The `TrackType` defines the type of each frame found in the Track. The value **SHOULD** be stored on 1 octet.
548    /// * 1 - video,
549    /// * 2 - audio,
550    /// * 3 - complex,
551    /// * 16 - logo,
552    /// * 17 - subtitle,
553    /// * 18 - buttons,
554    /// * 32 - control,
555    /// * 33 - metadata
556    pub track_type: TrackType,
557    /// Set to 1 if the track is usable. It is possible to turn a not usable track into a usable track using chapter codecs or control tracks.
558    pub flag_enabled: FlagEnabled,
559    /// Set if that track (audio, video or subs) is eligible for automatic selection by the player; see default-track-selection for more details.
560    pub flag_default: FlagDefault,
561    /// Applies only to subtitles. Set if that track is eligible for automatic selection by the player if it matches the user's language preference, even if the user's preferences would normally not enable subtitles with the selected audio track; this can be used for tracks containing only translations of foreign-language audio or onscreen text. See default-track-selection for more details.
562    pub flag_forced: FlagForced,
563    /// Set to 1 if and only if that track is suitable for users with hearing impairments.
564    pub flag_hearing_impaired: Option<FlagHearingImpaired>,
565    /// Set to 1 if and only if that track is suitable for users with visual impairments.
566    pub flag_visual_impaired: Option<FlagVisualImpaired>,
567    /// Set to 1 if and only if that track contains textual descriptions of video content.
568    pub flag_text_descriptions: Option<FlagTextDescriptions>,
569    /// Set to 1 if and only if that track is in the content's original language.
570    pub flag_original: Option<FlagOriginal>,
571    /// Set to 1 if and only if that track contains commentary.
572    pub flag_commentary: Option<FlagCommentary>,
573    /// Set to 1 if the track **MAY** contain blocks using lacing. When set to 0 all blocks **MUST** have their lacing flags set to No lacing; see block-lacing on Block Lacing.
574    pub flag_lacing: FlagLacing,
575    /// Number of nanoseconds per frame, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks (frame in the Matroska sense -- one Element put into a (Simple)Block).
576    pub default_duration: Option<DefaultDuration>,
577    /// The period between two successive fields at the output of the decoding process, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks. see notes for more information
578    pub default_decoded_field_duration: Option<DefaultDecodedFieldDuration>,
579    /// The maximum value of BlockAddID (BlockAddID). A value 0 means there is no BlockAdditions (BlockAdditions) for this track.
580    pub max_block_addition_id: MaxBlockAdditionId,
581    /// Contains elements that extend the track format, by adding content either to each frame, with BlockAddID (BlockAddID), or to the track as a whole with BlockAddIDExtraData.
582    pub block_addition_mapping: Vec<BlockAdditionMapping>,
583    /// A human-readable track name.
584    pub name: Option<Name>,
585    /// The language of the track, in the Matroska languages form; see basics on language codes. This Element **MUST** be ignored if the LanguageBCP47 Element is used in the same TrackEntry.
586    pub language: Language,
587    /// The language of the track, in the \[@!BCP47\] form; see basics on language codes. If this Element is used, then any Language Elements used in the same TrackEntry **MUST** be ignored.
588    pub language_bcp47: Option<LanguageBcp47>,
589    /// An ID corresponding to the codec, see Matroska codec RFC for more info.
590    pub codec_id: CodecId,
591    /// Private data only known to the codec.
592    pub codec_private: Option<CodecPrivate>,
593    /// A human-readable string specifying the codec.
594    pub codec_name: Option<CodecName>,
595    /// CodecDelay is The codec-built-in delay, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks. It represents the amount of codec samples that will be discarded by the decoder during playback. This timestamp value **MUST** be subtracted from each frame timestamp in order to get the timestamp that will be actually played. The value **SHOULD** be small so the muxing of tracks with the same actual timestamp are in the same Cluster.
596    pub codec_delay: CodecDelay,
597    /// After a discontinuity, SeekPreRoll is the duration of the data the decoder **MUST** decode before the decoded data is valid, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks.
598    pub seek_pre_roll: SeekPreRoll,
599    /// The mapping between this `TrackEntry` and a track value in the given Chapter Codec. Chapter Codec may need to address content in specific track, but they may not know of the way to identify tracks in Matroska. This element and its child elements add a way to map the internal tracks known to the Chapter Codec to the track IDs in Matroska. This allows remuxing a file with Chapter Codec without changing the content of the codec data, just the track mapping.
600    pub track_translate: Vec<TrackTranslate>,
601    /// Video settings.
602    pub video: Option<Video>,
603    /// Audio settings.
604    pub audio: Option<Audio>,
605    /// Operation that needs to be applied on tracks to create this virtual track. For more details look at notes.
606    pub track_operation: Option<TrackOperation>,
607    /// Settings for several content encoding mechanisms like compression or encryption.
608    pub content_encodings: Option<ContentEncodings>,
609}
610
611impl Element for TrackEntry {
612    const ID: VInt64 = VInt64::from_encoded(0xAE);
613    nested! {
614      required: [ TrackNumber, TrackUid, TrackType, FlagEnabled,
615                  FlagDefault, FlagForced, FlagLacing, MaxBlockAdditionId,
616                  Language, CodecId, CodecDelay, SeekPreRoll ],
617      optional: [ FlagHearingImpaired, FlagVisualImpaired, FlagTextDescriptions,
618                  FlagOriginal, FlagCommentary, DefaultDuration,
619                  DefaultDecodedFieldDuration, Name, LanguageBcp47, CodecPrivate,
620                  CodecName, Video, Audio, TrackOperation, ContentEncodings ],
621      multiple: [ BlockAdditionMapping, TrackTranslate ],
622    }
623}
624
625/// Contains elements that extend the track format, by adding content either to each frame, with BlockAddID (BlockAddID), or to the track as a whole with BlockAddIDExtraData.
626#[derive(Debug, Clone, PartialEq, Eq, Default)]
627pub struct BlockAdditionMapping {
628    /// Optional CRC-32 element for integrity checking.
629    pub crc32: Option<Crc32>,
630    /// void element, useful for reserving space during writing.
631    pub void: Option<Void>,
632
633    /// If the track format extension needs content beside frames, the value refers to the BlockAddID (BlockAddID), value being described. To keep MaxBlockAdditionID as low as possible, small values **SHOULD** be used.
634    pub block_add_id_value: Option<BlockAddIdValue>,
635    /// A human-friendly name describing the type of BlockAdditional data, as defined by the associated Block Additional Mapping.
636    pub block_add_id_name: Option<BlockAddIdName>,
637    /// Stores the registered identifier of the Block Additional Mapping to define how the BlockAdditional data should be handled. If BlockAddIDType is 0, the BlockAddIDValue and corresponding BlockAddID values **MUST** be 1.
638    pub block_add_id_type: BlockAddIdType,
639    /// Extra binary data that the BlockAddIDType can use to interpret the BlockAdditional data. The interpretation of the binary data depends on the BlockAddIDType value and the corresponding Block Additional Mapping.
640    pub block_add_id_extra_data: Option<BlockAddIdExtraData>,
641}
642impl Element for BlockAdditionMapping {
643    const ID: VInt64 = VInt64::from_encoded(0x41E4);
644    nested! {
645        required: [ BlockAddIdType ],
646        optional: [ BlockAddIdValue, BlockAddIdName, BlockAddIdExtraData ],
647        multiple: [ ],
648    }
649}
650
651/// The mapping between this `TrackEntry` and a track value in the given Chapter Codec. Chapter Codec may need to address content in specific track, but they may not know of the way to identify tracks in Matroska. This element and its child elements add a way to map the internal tracks known to the Chapter Codec to the track IDs in Matroska. This allows remuxing a file with Chapter Codec without changing the content of the codec data, just the track mapping.
652#[derive(Debug, Clone, PartialEq, Eq, Default)]
653pub struct TrackTranslate {
654    /// Optional CRC-32 element for integrity checking.
655    pub crc32: Option<Crc32>,
656    /// void element, useful for reserving space during writing.
657    pub void: Option<Void>,
658
659    /// The binary value used to represent this `TrackEntry` in the chapter codec data. The format depends on the `ChapProcessCodecID` used; see ChapProcessCodecID.
660    pub track_translate_track_id: TrackTranslateTrackId,
661    /// This `TrackTranslate` applies to this chapter codec of the given chapter edition(s); see ChapProcessCodecID.
662    /// * 0 - Matroska Script,
663    /// * 1 - DVD-menu
664    pub track_translate_codec: TrackTranslateCodec,
665    /// Specify a chapter edition UID on which this `TrackTranslate` applies. When no `TrackTranslateEditionUID` is specified in the `TrackTranslate`, the `TrackTranslate` applies to all chapter editions found in the Segment using the given `TrackTranslateCodec`.
666    pub track_translate_edition_uid: Vec<TrackTranslateEditionUid>,
667}
668
669impl Element for TrackTranslate {
670    const ID: VInt64 = VInt64::from_encoded(0x6624);
671    nested! {
672        required: [ TrackTranslateTrackId, TrackTranslateCodec ],
673        optional: [ ],
674        multiple: [ TrackTranslateEditionUid ],
675    }
676}
677
678/// Video settings.
679#[derive(Debug, Clone, PartialEq, Default)]
680pub struct Video {
681    /// Optional CRC-32 element for integrity checking.
682    pub crc32: Option<Crc32>,
683    /// void element, useful for reserving space during writing.
684    pub void: Option<Void>,
685
686    /// Specify whether the video frames in this track are interlaced.
687    /// * 0 - undetermined,
688    /// * 1 - interlaced,
689    /// * 2 - progressive
690    pub flag_interlaced: FlagInterlaced,
691    /// Specify the field ordering of video frames in this track. If FlagInterlaced is not set to 1, this Element **MUST** be ignored.
692    /// * 0 - progressive,
693    /// * 1 - tff,
694    /// * 2 - undetermined,
695    /// * 6 - bff,
696    /// * 9 - bff(swapped),
697    /// * 14 - tff(swapped)
698    pub field_order: FieldOrder,
699    /// Stereo-3D video mode. There are some more details in notes.
700    /// * 0 - mono,
701    /// * 1 - side by side (left eye first),
702    /// * 2 - top - bottom (right eye is first),
703    /// * 3 - top - bottom (left eye is first),
704    /// * 4 - checkboard (right eye is first),
705    /// * 5 - checkboard (left eye is first),
706    /// * 6 - row interleaved (right eye is first),
707    /// * 7 - row interleaved (left eye is first),
708    /// * 8 - column interleaved (right eye is first),
709    /// * 9 - column interleaved (left eye is first),
710    /// * 10 - anaglyph (cyan/red),
711    /// * 11 - side by side (right eye first),
712    /// * 12 - anaglyph (green/magenta),
713    /// * 13 - both eyes laced in one Block (left eye is first),
714    /// * 14 - both eyes laced in one Block (right eye is first)
715    pub stereo_mode: StereoMode,
716    /// Indicate whether the BlockAdditional Element with BlockAddID of "1" contains Alpha data, as defined by to the Codec Mapping for the `CodecID`. Undefined values **SHOULD NOT** be used as the behavior of known implementations is different (considered either as 0 or 1).
717    /// * 0 - none,
718    /// * 1 - present
719    pub alpha_mode: AlphaMode,
720    /// Width of the encoded video frames in pixels.
721    pub pixel_width: PixelWidth,
722    /// Height of the encoded video frames in pixels.
723    pub pixel_height: PixelHeight,
724    /// The number of video pixels to remove at the bottom of the image.
725    pub pixel_crop_bottom: PixelCropBottom,
726    /// The number of video pixels to remove at the top of the image.
727    pub pixel_crop_top: PixelCropTop,
728    /// The number of video pixels to remove on the left of the image.
729    pub pixel_crop_left: PixelCropLeft,
730    /// The number of video pixels to remove on the right of the image.
731    pub pixel_crop_right: PixelCropRight,
732    /// Width of the video frames to display. Applies to the video frame after cropping (PixelCrop* Elements). If the DisplayUnit of the same TrackEntry is 0, then the default value for DisplayWidth is equal to PixelWidth - PixelCropLeft - PixelCropRight, else there is no default value.
733    pub display_width: Option<DisplayWidth>,
734    /// Height of the video frames to display. Applies to the video frame after cropping (PixelCrop* Elements). If the DisplayUnit of the same TrackEntry is 0, then the default value for DisplayHeight is equal to PixelHeight - PixelCropTop - PixelCropBottom, else there is no default value.
735    pub display_height: Option<DisplayHeight>,
736    /// How DisplayWidth & DisplayHeight are interpreted.
737    /// * 0 - pixels,
738    /// * 1 - centimeters,
739    /// * 2 - inches,
740    /// * 3 - display aspect ratio,
741    /// * 4 - unknown
742    pub display_unit: DisplayUnit,
743    /// Specify the uncompressed pixel format used for the Track's data as a FourCC. This value is similar in scope to the biCompression value of AVI's `BITMAPINFO` \[@?AVIFormat\]. There is no definitive list of FourCC values, nor an official registry. Some common values for YUV pixel formats can be found at \[@?MSYUV8\], \[@?MSYUV16\] and \[@?FourCC-YUV\]. Some common values for uncompressed RGB pixel formats can be found at \[@?MSRGB\] and \[@?FourCC-RGB\]. UncompressedFourCC **MUST** be set in TrackEntry, when the CodecID Element of the TrackEntry is set to "V_UNCOMPRESSED".
744    pub uncompressed_fourcc: Option<UncompressedFourcc>,
745    /// Settings describing the colour format.
746    pub colour: Option<Colour>,
747    /// Describes the video projection details. Used to render spherical, VR videos or flipping videos horizontally/vertically.
748    pub projection: Option<Projection>,
749}
750impl Element for Video {
751    const ID: VInt64 = VInt64::from_encoded(0xE0);
752    nested! {
753      required: [ FlagInterlaced, FieldOrder, StereoMode, AlphaMode,
754                  PixelWidth, PixelHeight, PixelCropBottom, PixelCropTop,
755                  PixelCropLeft, PixelCropRight, DisplayUnit ],
756      optional: [ DisplayWidth, DisplayHeight, UncompressedFourcc,
757                  Colour, Projection ],
758      multiple: [ ],
759    }
760}
761
762/// Settings describing the colour format.
763#[derive(Debug, Clone, PartialEq, Default)]
764pub struct Colour {
765    /// Optional CRC-32 element for integrity checking.
766    pub crc32: Option<Crc32>,
767    /// void element, useful for reserving space during writing.
768    pub void: Option<Void>,
769
770    /// The Matrix Coefficients of the video used to derive luma and chroma values from red, green, and blue color primaries. For clarity, the value and meanings for MatrixCoefficients are adopted from Table 4 of ISO/IEC 23001-8:2016 or ITU-T H.273.
771    /// * 0 - Identity,
772    /// * 1 - ITU-R BT.709,
773    /// * 2 - unspecified,
774    /// * 3 - reserved,
775    /// * 4 - US FCC 73.682,
776    /// * 5 - ITU-R BT.470BG,
777    /// * 6 - SMPTE 170M,
778    /// * 7 - SMPTE 240M,
779    /// * 8 - YCoCg,
780    /// * 9 - BT2020 Non-constant Luminance,
781    /// * 10 - BT2020 Constant Luminance,
782    /// * 11 - SMPTE ST 2085,
783    /// * 12 - Chroma-derived Non-constant Luminance,
784    /// * 13 - Chroma-derived Constant Luminance,
785    /// * 14 - ITU-R BT.2100-0
786    pub matrix_coefficients: MatrixCoefficients,
787    /// Number of decoded bits per channel. A value of 0 indicates that the BitsPerChannel is unspecified.
788    pub bits_per_channel: BitsPerChannel,
789    /// The amount of pixels to remove in the Cr and Cb channels for every pixel not removed horizontally. Example: For video with 4:2:0 chroma subsampling, the ChromaSubsamplingHorz **SHOULD** be set to 1.
790    pub chroma_subsampling_horz: Option<ChromaSubsamplingHorz>,
791    /// The amount of pixels to remove in the Cr and Cb channels for every pixel not removed vertically. Example: For video with 4:2:0 chroma subsampling, the ChromaSubsamplingVert **SHOULD** be set to 1.
792    pub chroma_subsampling_vert: Option<ChromaSubsamplingVert>,
793    /// The amount of pixels to remove in the Cb channel for every pixel not removed horizontally. This is additive with ChromaSubsamplingHorz. Example: For video with 4:2:1 chroma subsampling, the ChromaSubsamplingHorz **SHOULD** be set to 1 and CbSubsamplingHorz **SHOULD** be set to 1.
794    pub cb_subsampling_horz: Option<CbSubsamplingHorz>,
795    /// The amount of pixels to remove in the Cb channel for every pixel not removed vertically. This is additive with ChromaSubsamplingVert.
796    pub cb_subsampling_vert: Option<CbSubsamplingVert>,
797    /// How chroma is subsampled horizontally.
798    /// * 0 - unspecified,
799    /// * 1 - left collocated,
800    /// * 2 - half
801    pub chroma_siting_horz: ChromaSitingHorz,
802    /// How chroma is subsampled vertically.
803    /// * 0 - unspecified,
804    /// * 1 - top collocated,
805    /// * 2 - half
806    pub chroma_siting_vert: ChromaSitingVert,
807    /// Clipping of the color ranges.
808    /// * 0 - unspecified,
809    /// * 1 - broadcast range,
810    /// * 2 - full range (no clipping),
811    /// * 3 - defined by MatrixCoefficients / TransferCharacteristics
812    pub range: Range,
813    /// The transfer characteristics of the video. For clarity, the value and meanings for TransferCharacteristics are adopted from Table 3 of ISO/IEC 23091-4 or ITU-T H.273.
814    /// * 0 - reserved,
815    /// * 1 - ITU-R BT.709,
816    /// * 2 - unspecified,
817    /// * 3 - reserved2,
818    /// * 4 - Gamma 2.2 curve - BT.470M,
819    /// * 5 - Gamma 2.8 curve - BT.470BG,
820    /// * 6 - SMPTE 170M,
821    /// * 7 - SMPTE 240M,
822    /// * 8 - Linear,
823    /// * 9 - Log,
824    /// * 10 - Log Sqrt,
825    /// * 11 - IEC 61966-2-4,
826    /// * 12 - ITU-R BT.1361 Extended Colour Gamut,
827    /// * 13 - IEC 61966-2-1,
828    /// * 14 - ITU-R BT.2020 10 bit,
829    /// * 15 - ITU-R BT.2020 12 bit,
830    /// * 16 - ITU-R BT.2100 Perceptual Quantization,
831    /// * 17 - SMPTE ST 428-1,
832    /// * 18 - ARIB STD-B67 (HLG)
833    pub transfer_characteristics: TransferCharacteristics,
834    /// The colour primaries of the video. For clarity, the value and meanings for Primaries are adopted from Table 2 of ISO/IEC 23091-4 or ITU-T H.273.
835    /// * 0 - reserved,
836    /// * 1 - ITU-R BT.709,
837    /// * 2 - unspecified,
838    /// * 3 - reserved2,
839    /// * 4 - ITU-R BT.470M,
840    /// * 5 - ITU-R BT.470BG - BT.601 625,
841    /// * 6 - ITU-R BT.601 525 - SMPTE 170M,
842    /// * 7 - SMPTE 240M,
843    /// * 8 - FILM,
844    /// * 9 - ITU-R BT.2020,
845    /// * 10 - SMPTE ST 428-1,
846    /// * 11 - SMPTE RP 432-2,
847    /// * 12 - SMPTE EG 432-2,
848    /// * 22 - EBU Tech. 3213-E - JEDEC P22 phosphors
849    pub primaries: Primaries,
850    /// Maximum brightness of a single pixel (Maximum Content Light Level) in candelas per square meter (cd/m^2^).
851    pub max_cll: Option<MaxCll>,
852    /// Maximum brightness of a single full frame (Maximum Frame-Average Light Level) in candelas per square meter (cd/m^2^).
853    pub max_fall: Option<MaxFall>,
854    /// SMPTE 2086 mastering data.
855    pub mastering_metadata: Option<MasteringMetadata>,
856}
857
858impl Element for Colour {
859    const ID: VInt64 = VInt64::from_encoded(0x55B0);
860    nested! {
861      required: [ MatrixCoefficients, BitsPerChannel, ChromaSitingHorz,
862                  ChromaSitingVert, Range, TransferCharacteristics, Primaries ],
863      optional: [ ChromaSubsamplingHorz, ChromaSubsamplingVert,
864                  CbSubsamplingHorz, CbSubsamplingVert, MaxCll,
865                  MaxFall, MasteringMetadata ],
866      multiple: [ ],
867    }
868}
869
870/// SMPTE 2086 mastering data.
871#[derive(Debug, Clone, PartialEq, Default)]
872pub struct MasteringMetadata {
873    /// Optional CRC-32 element for integrity checking.
874    pub crc32: Option<Crc32>,
875    /// void element, useful for reserving space during writing.
876    pub void: Option<Void>,
877
878    /// Red X chromaticity coordinate, as defined by \[@!CIE-1931\].
879    pub primary_r_chromaticity_x: Option<PrimaryRChromaticityX>,
880    /// Red Y chromaticity coordinate, as defined by \[@!CIE-1931\].
881    pub primary_r_chromaticity_y: Option<PrimaryRChromaticityY>,
882    /// Green X chromaticity coordinate, as defined by \[@!CIE-1931\].
883    pub primary_g_chromaticity_x: Option<PrimaryGChromaticityX>,
884    /// Green Y chromaticity coordinate, as defined by \[@!CIE-1931\].
885    pub primary_g_chromaticity_y: Option<PrimaryGChromaticityY>,
886    /// Blue X chromaticity coordinate, as defined by \[@!CIE-1931\].
887    pub primary_b_chromaticity_x: Option<PrimaryBChromaticityX>,
888    /// Blue Y chromaticity coordinate, as defined by \[@!CIE-1931\].
889    pub primary_b_chromaticity_y: Option<PrimaryBChromaticityY>,
890    /// White point X chromaticity coordinate, as defined by \[@!CIE-1931\].
891    pub white_point_chromaticity_x: Option<WhitePointChromaticityX>,
892    /// White point Y chromaticity coordinate, as defined by \[@!CIE-1931\].
893    pub white_point_chromaticity_y: Option<WhitePointChromaticityY>,
894    /// Maximum luminance. Represented in candelas per square meter (cd/m^2^).
895    pub luminance_max: Option<LuminanceMax>,
896    /// Minimum luminance. Represented in candelas per square meter (cd/m^2^).
897    pub luminance_min: Option<LuminanceMin>,
898}
899
900impl Element for MasteringMetadata {
901    const ID: VInt64 = VInt64::from_encoded(0x55D0);
902    nested! {
903      required: [ ],
904      optional: [ PrimaryRChromaticityX, PrimaryRChromaticityY,
905                 PrimaryGChromaticityX, PrimaryGChromaticityY,
906                 PrimaryBChromaticityX, PrimaryBChromaticityY,
907                 WhitePointChromaticityX, WhitePointChromaticityY,
908                 LuminanceMax, LuminanceMin ],
909      multiple: [ ],
910    }
911}
912
913/// Describes the video projection details. Used to render spherical, VR videos or flipping videos horizontally/vertically.
914#[derive(Debug, Clone, PartialEq, Default)]
915pub struct Projection {
916    /// Optional CRC-32 element for integrity checking.
917    pub crc32: Option<Crc32>,
918    /// void element, useful for reserving space during writing.
919    pub void: Option<Void>,
920
921    /// Describes the projection used for this video track.
922    /// * 0 - rectangular,
923    /// * 1 - equirectangular,
924    /// * 2 - cubemap,
925    /// * 3 - mesh
926    pub projection_type: ProjectionType,
927    /// Private data that only applies to a specific projection. * If `ProjectionType` equals 0 (Rectangular), then this element **MUST NOT** be present. * If `ProjectionType` equals 1 (Equirectangular), then this element **MUST** be present and contain the same binary data that would be stored inside an ISOBMFF Equirectangular Projection Box ('equi'). * If `ProjectionType` equals 2 (Cubemap), then this element **MUST** be present and contain the same binary data that would be stored inside an ISOBMFF Cubemap Projection Box ('cbmp'). * If `ProjectionType` equals 3 (Mesh), then this element **MUST** be present and contain the same binary data that would be stored inside an ISOBMFF Mesh Projection Box ('mshp'). ISOBMFF box size and fourcc fields are not included in the binary data, but the FullBox version and flag fields are. This is to avoid redundant framing information while preserving versioning and semantics between the two container formats
928    pub projection_private: Option<ProjectionPrivate>,
929    /// Specifies a yaw rotation to the projection. Value represents a clockwise rotation, in degrees, around the up vector. This rotation must be applied before any `ProjectionPosePitch` or `ProjectionPoseRoll` rotations. The value of this element **MUST** be in the -180 to 180 degree range, both included. Setting `ProjectionPoseYaw` to 180 or -180 degrees, with the `ProjectionPoseRoll` and `ProjectionPosePitch` set to 0 degrees flips the image horizontally.
930    pub projection_pose_yaw: ProjectionPoseYaw,
931    /// Specifies a pitch rotation to the projection. Value represents a counter-clockwise rotation, in degrees, around the right vector. This rotation must be applied after the `ProjectionPoseYaw` rotation and before the `ProjectionPoseRoll` rotation. The value of this element **MUST** be in the -90 to 90 degree range, both included.
932    pub projection_pose_pitch: ProjectionPosePitch,
933    /// Specifies a roll rotation to the projection. Value represents a counter-clockwise rotation, in degrees, around the forward vector. This rotation must be applied after the `ProjectionPoseYaw` and `ProjectionPosePitch` rotations. The value of this element **MUST** be in the -180 to 180 degree range, both included. Setting `ProjectionPoseRoll` to 180 or -180 degrees, the `ProjectionPoseYaw` to 180 or -180 degrees with `ProjectionPosePitch` set to 0 degrees flips the image vertically. Setting `ProjectionPoseRoll` to 180 or -180 degrees, with the `ProjectionPoseYaw` and `ProjectionPosePitch` set to 0 degrees flips the image horizontally and vertically.
934    pub projection_pose_roll: ProjectionPoseRoll,
935}
936
937impl Element for Projection {
938    const ID: VInt64 = VInt64::from_encoded(0x7670);
939    nested! {
940      required: [ ProjectionType, ProjectionPoseYaw, ProjectionPosePitch, ProjectionPoseRoll ],
941      optional: [ ProjectionPrivate ],
942      multiple: [ ],
943    }
944}
945
946/// Audio settings.
947#[derive(Debug, Clone, PartialEq, Default)]
948pub struct Audio {
949    /// Optional CRC-32 element for integrity checking.
950    pub crc32: Option<Crc32>,
951    /// void element, useful for reserving space during writing.
952    pub void: Option<Void>,
953
954    /// Sampling frequency in Hz.
955    pub sampling_frequency: SamplingFrequency,
956    /// Real output sampling frequency in Hz (used for SBR techniques). The default value for OutputSamplingFrequency of the same TrackEntry is equal to the SamplingFrequency.
957    pub output_sampling_frequency: Option<OutputSamplingFrequency>,
958    /// Numbers of channels in the track.
959    pub channels: Channels,
960    /// Bits per sample, mostly used for PCM.
961    pub bit_depth: Option<BitDepth>,
962    /// Audio emphasis applied on audio samples. The player **MUST** apply the inverse emphasis to get the proper audio samples.
963    /// * 0 - No emphasis,
964    /// * 1 - CD audio,
965    /// * 2 - reserved,
966    /// * 3 - CCIT J.17,
967    /// * 4 - FM 50,
968    /// * 5 - FM 75,
969    /// * 10 - Phono RIAA,
970    /// * 11 - Phono IEC N78,
971    /// * 12 - Phono TELDEC,
972    /// * 13 - Phono EMI,
973    /// * 14 - Phono Columbia LP,
974    /// * 15 - Phono LONDON,
975    /// * 16 - Phono NARTB
976    pub emphasis: Emphasis,
977}
978
979impl Element for Audio {
980    const ID: VInt64 = VInt64::from_encoded(0xE1);
981    nested! {
982      required: [ SamplingFrequency, Channels, Emphasis ],
983      optional: [ OutputSamplingFrequency, BitDepth ],
984      multiple: [ ],
985    }
986}
987
988/// Operation that needs to be applied on tracks to create this virtual track. For more details look at notes.
989#[derive(Debug, Clone, PartialEq, Eq, Default)]
990pub struct TrackOperation {
991    /// Optional CRC-32 element for integrity checking.
992    pub crc32: Option<Crc32>,
993    /// void element, useful for reserving space during writing.
994    pub void: Option<Void>,
995
996    /// Contains the list of all video plane tracks that need to be combined to create this 3D track
997    pub track_combine_planes: Option<TrackCombinePlanes>,
998    /// Contains the list of all tracks whose Blocks need to be combined to create this virtual track
999    pub track_join_blocks: Option<TrackJoinBlocks>,
1000}
1001
1002impl Element for TrackOperation {
1003    const ID: VInt64 = VInt64::from_encoded(0xE2);
1004    nested! {
1005      required: [ ],
1006      optional: [ TrackCombinePlanes, TrackJoinBlocks ],
1007      multiple: [ ],
1008    }
1009}
1010
1011/// Contains the list of all video plane tracks that need to be combined to create this 3D track
1012#[derive(Debug, Clone, PartialEq, Eq, Default)]
1013pub struct TrackCombinePlanes {
1014    /// Optional CRC-32 element for integrity checking.
1015    pub crc32: Option<Crc32>,
1016    /// void element, useful for reserving space during writing.
1017    pub void: Option<Void>,
1018
1019    /// Contains a video plane track that need to be combined to create this 3D track
1020    pub track_plane: Vec<TrackPlane>,
1021}
1022
1023impl Element for TrackCombinePlanes {
1024    const ID: VInt64 = VInt64::from_encoded(0xE3);
1025    nested! {
1026        required: [ ],
1027        optional: [ ],
1028        multiple: [ TrackPlane ],
1029    }
1030}
1031
1032/// Contains a video plane track that need to be combined to create this 3D track
1033#[derive(Debug, Clone, PartialEq, Eq, Default)]
1034pub struct TrackPlane {
1035    /// Optional CRC-32 element for integrity checking.
1036    pub crc32: Option<Crc32>,
1037    /// void element, useful for reserving space during writing.
1038    pub void: Option<Void>,
1039
1040    /// The trackUID number of the track representing the plane.
1041    pub track_plane_uid: TrackPlaneUid,
1042    /// The kind of plane this track corresponds to.
1043    /// * 0 - left eye,
1044    /// * 1 - right eye,
1045    /// * 2 - background
1046    pub track_plane_type: TrackPlaneType,
1047}
1048
1049impl Element for TrackPlane {
1050    const ID: VInt64 = VInt64::from_encoded(0xE4);
1051    nested! {
1052        required: [ TrackPlaneUid, TrackPlaneType ],
1053        optional: [ ],
1054        multiple: [ ],
1055    }
1056}
1057
1058/// Contains the list of all tracks whose Blocks need to be combined to create this virtual track
1059#[derive(Debug, Clone, PartialEq, Eq, Default)]
1060pub struct TrackJoinBlocks {
1061    /// Optional CRC-32 element for integrity checking.
1062    pub crc32: Option<Crc32>,
1063    /// void element, useful for reserving space during writing.
1064    pub void: Option<Void>,
1065
1066    /// The trackUID number of a track whose blocks are used to create this virtual track.
1067    pub track_join_uid: Vec<TrackJoinUid>,
1068}
1069
1070impl Element for TrackJoinBlocks {
1071    const ID: VInt64 = VInt64::from_encoded(0xE9);
1072    nested! {
1073        required: [ ],
1074        optional: [ ],
1075        multiple: [ TrackJoinUid ],
1076    }
1077}
1078
1079/// Settings for several content encoding mechanisms like compression or encryption.
1080#[derive(Debug, Clone, PartialEq, Eq, Default)]
1081pub struct ContentEncodings {
1082    /// Optional CRC-32 element for integrity checking.
1083    pub crc32: Option<Crc32>,
1084    /// void element, useful for reserving space during writing.
1085    pub void: Option<Void>,
1086
1087    /// Settings for one content encoding like compression or encryption.
1088    pub content_encoding: Vec<ContentEncoding>,
1089}
1090
1091impl Element for ContentEncodings {
1092    const ID: VInt64 = VInt64::from_encoded(0x6D80);
1093    nested! {
1094        required: [ ],
1095        optional: [ ],
1096        multiple: [ ContentEncoding ],
1097    }
1098}
1099
1100/// Settings for one content encoding like compression or encryption.
1101#[derive(Debug, Clone, PartialEq, Eq, Default)]
1102pub struct ContentEncoding {
1103    /// Optional CRC-32 element for integrity checking.
1104    pub crc32: Option<Crc32>,
1105    /// void element, useful for reserving space during writing.
1106    pub void: Option<Void>,
1107
1108    /// Tell in which order to apply each `ContentEncoding` of the `ContentEncodings`. The decoder/demuxer **MUST** start with the `ContentEncoding` with the highest `ContentEncodingOrder` and work its way down to the `ContentEncoding` with the lowest `ContentEncodingOrder`. This value **MUST** be unique over for each `ContentEncoding` found in the `ContentEncodings` of this `TrackEntry`.
1109    pub content_encoding_order: ContentEncodingOrder,
1110    /// A bit field that describes which Elements have been modified in this way. Values (big-endian) can be OR'ed.
1111    /// * 1 - Block,
1112    /// * 2 - Private,
1113    /// * 4 - Next
1114    pub content_encoding_scope: ContentEncodingScope,
1115    /// A value describing what kind of transformation is applied.
1116    /// * 0 - Compression,
1117    /// * 1 - Encryption
1118    pub content_encoding_type: ContentEncodingType,
1119    /// Settings describing the compression used. This Element **MUST** be present if the value of ContentEncodingType is 0 and absent otherwise. Each block **MUST** be decompressable even if no previous block is available in order not to prevent seeking.
1120    pub content_compression: Option<ContentCompression>,
1121    /// Settings describing the encryption used. This Element **MUST** be present if the value of `ContentEncodingType` is 1 (encryption) and **MUST** be ignored otherwise. A Matroska Player **MAY** support encryption.
1122    pub content_encryption: Option<ContentEncryption>,
1123}
1124
1125impl Element for ContentEncoding {
1126    const ID: VInt64 = VInt64::from_encoded(0x6240);
1127    nested! {
1128        required: [ ContentEncodingOrder, ContentEncodingScope, ContentEncodingType ],
1129        optional: [ ContentCompression, ContentEncryption ],
1130        multiple: [ ],
1131    }
1132}
1133
1134/// Settings describing the compression used. This Element **MUST** be present if the value of ContentEncodingType is 0 and absent otherwise. Each block **MUST** be decompressable even if no previous block is available in order not to prevent seeking.
1135#[derive(Debug, Clone, PartialEq, Eq, Default)]
1136pub struct ContentCompression {
1137    /// Optional CRC-32 element for integrity checking.
1138    pub crc32: Option<Crc32>,
1139    /// void element, useful for reserving space during writing.
1140    pub void: Option<Void>,
1141
1142    /// The compression algorithm used. Compression method "1" (bzlib) and "2" (lzo1x) are lacking proper documentation on the format which limits implementation possibilities. Due to licensing conflicts on commonly available libraries compression methods "2" (lzo1x) does not offer widespread interoperability. A Matroska Writer **SHOULD NOT** use these compression methods by default. A Matroska Reader **MAY** support methods "1" and "2" as possible, and **SHOULD** support other methods.
1143    /// * 0 - zlib,
1144    /// * 1 - bzlib,
1145    /// * 2 - lzo1x,
1146    /// * 3 - Header Stripping
1147    pub content_comp_algo: ContentCompAlgo,
1148
1149    /// Settings that might be needed by the decompressor. For Header Stripping (`ContentCompAlgo`=3), the bytes that were removed from the beginning of each frames of the track.
1150    pub content_comp_settings: Option<ContentCompSettings>,
1151}
1152impl Element for ContentCompression {
1153    const ID: VInt64 = VInt64::from_encoded(0x5034);
1154    nested! {
1155        required: [ ContentCompAlgo ],
1156        optional: [ ContentCompSettings ],
1157        multiple: [ ],
1158    }
1159}
1160
1161/// Settings describing the encryption used. This Element **MUST** be present if the value of `ContentEncodingType` is 1 (encryption) and **MUST** be ignored otherwise. A Matroska Player **MAY** support encryption.
1162#[derive(Debug, Clone, PartialEq, Eq, Default)]
1163pub struct ContentEncryption {
1164    /// Optional CRC-32 element for integrity checking.
1165    pub crc32: Option<Crc32>,
1166    /// void element, useful for reserving space during writing.
1167    pub void: Option<Void>,
1168
1169    /// The encryption algorithm used.
1170    /// * 0 - Not encrypted,
1171    /// * 1 - DES,
1172    /// * 2 - 3DES,
1173    /// * 3 - Twofish,
1174    /// * 4 - Blowfish,
1175    /// * 5 - AES
1176    pub content_enc_algo: ContentEncAlgo,
1177    /// For public key algorithms this is the ID of the public key the the data was encrypted with.
1178    pub content_enc_key_id: Option<ContentEncKeyId>,
1179    /// Settings describing the encryption algorithm used.
1180    pub content_enc_aes_settings: Option<ContentEncAesSettings>,
1181}
1182impl Element for ContentEncryption {
1183    const ID: VInt64 = VInt64::from_encoded(0x5035);
1184    nested! {
1185        required: [ ContentEncAlgo ],
1186        optional: [ ContentEncKeyId, ContentEncAesSettings ],
1187        multiple: [ ],
1188    }
1189}
1190
1191/// Settings describing the encryption algorithm used.
1192#[derive(Debug, Clone, PartialEq, Eq, Default)]
1193pub struct ContentEncAesSettings {
1194    /// Optional CRC-32 element for integrity checking.
1195    pub crc32: Option<Crc32>,
1196    /// void element, useful for reserving space during writing.
1197    pub void: Option<Void>,
1198
1199    /// The AES cipher mode used in the encryption.
1200    /// * 1 - AES-CTR,
1201    /// * 2 - AES-CBC
1202    pub aes_settings_cipher_mode: AesSettingsCipherMode,
1203}
1204
1205impl Element for ContentEncAesSettings {
1206    const ID: VInt64 = VInt64::from_encoded(0x47E7);
1207    nested! {
1208        required: [ AesSettingsCipherMode ],
1209        optional: [ ],
1210        multiple: [ ],
1211    }
1212}
1213
1214/// A Top-Level Element to speed seeking access. All entries are local to the Segment. This Element **SHOULD** be set when the Segment is not transmitted as a live stream (see #livestreaming).
1215#[derive(Debug, Clone, PartialEq, Eq, Default)]
1216pub struct Cues {
1217    /// Optional CRC-32 element for integrity checking.
1218    pub crc32: Option<Crc32>,
1219    /// void element, useful for reserving space during writing.
1220    pub void: Option<Void>,
1221
1222    /// Contains all information relative to a seek point in the Segment.
1223    pub cue_point: Vec<CuePoint>,
1224}
1225
1226impl Element for Cues {
1227    const ID: VInt64 = VInt64::from_encoded(0x1C53BB6B);
1228    nested! {
1229      required: [ ],
1230      optional: [ ],
1231      multiple: [ CuePoint ],
1232    }
1233}
1234
1235/// Contains all information relative to a seek point in the Segment.
1236#[derive(Debug, Clone, PartialEq, Eq, Default)]
1237pub struct CuePoint {
1238    /// Optional CRC-32 element for integrity checking.
1239    pub crc32: Option<Crc32>,
1240    /// void element, useful for reserving space during writing.
1241    pub void: Option<Void>,
1242
1243    /// Absolute timestamp of the seek point, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks.
1244    pub cue_time: CueTime,
1245    /// Contain positions for different tracks corresponding to the timestamp.
1246    pub cue_track_positions: Vec<CueTrackPositions>,
1247}
1248
1249impl Element for CuePoint {
1250    const ID: VInt64 = VInt64::from_encoded(0xBB);
1251    nested! {
1252      required: [ CueTime ],
1253      optional: [ ],
1254      multiple: [ CueTrackPositions ],
1255    }
1256}
1257
1258/// Contain positions for different tracks corresponding to the timestamp.
1259#[derive(Debug, Clone, PartialEq, Eq, Default)]
1260pub struct CueTrackPositions {
1261    /// Optional CRC-32 element for integrity checking.
1262    pub crc32: Option<Crc32>,
1263    /// void element, useful for reserving space during writing.
1264    pub void: Option<Void>,
1265
1266    /// The track for which a position is given.
1267    pub cue_track: CueTrack,
1268    /// The Segment Position (segment-position) of the Cluster containing the associated Block.
1269    pub cue_cluster_position: CueClusterPosition,
1270    /// The relative position inside the Cluster of the referenced SimpleBlock or BlockGroup with 0 being the first possible position for an Element inside that Cluster.
1271    pub cue_relative_position: Option<CueRelativePosition>,
1272    /// The duration of the block, expressed in Segment Ticks which is based on TimestampScale; see timestamp-ticks. If missing, the track's DefaultDuration does not apply and no duration information is available in terms of the cues.
1273    pub cue_duration: Option<CueDuration>,
1274    /// Number of the Block in the specified Cluster.
1275    pub cue_block_number: Option<CueBlockNumber>,
1276    /// The Segment Position (segment-position) of the Codec State corresponding to this Cue Element. 0 means that the data is taken from the initial Track Entry.
1277    pub cue_codec_state: CueCodecState,
1278    /// The Clusters containing the referenced Blocks.
1279    pub cue_reference: Vec<CueReference>,
1280}
1281
1282impl Element for CueTrackPositions {
1283    const ID: VInt64 = VInt64::from_encoded(0xB7);
1284    nested! {
1285      required: [ CueTrack, CueClusterPosition, CueCodecState ],
1286      optional: [ CueRelativePosition, CueDuration, CueBlockNumber ],
1287      multiple: [ CueReference ],
1288    }
1289}
1290
1291/// The Clusters containing the referenced Blocks.
1292#[derive(Debug, Clone, PartialEq, Eq, Default)]
1293pub struct CueReference {
1294    /// Optional CRC-32 element for integrity checking.
1295    pub crc32: Option<Crc32>,
1296    /// void element, useful for reserving space during writing.
1297    pub void: Option<Void>,
1298
1299    /// Timestamp of the referenced Block, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks.
1300    pub cue_ref_time: CueRefTime,
1301}
1302
1303impl Element for CueReference {
1304    const ID: VInt64 = VInt64::from_encoded(0xDB);
1305    nested! {
1306      required: [ CueRefTime ],
1307      optional: [ ],
1308      multiple: [ ],
1309    }
1310}
1311
1312/// Contain attached files.
1313#[derive(Debug, Clone, PartialEq, Eq, Default)]
1314pub struct Attachments {
1315    /// Optional CRC-32 element for integrity checking.
1316    pub crc32: Option<Crc32>,
1317    /// void element, useful for reserving space during writing.
1318    pub void: Option<Void>,
1319
1320    /// An attached file.
1321    pub attached_file: Vec<AttachedFile>,
1322}
1323impl Element for Attachments {
1324    const ID: VInt64 = VInt64::from_encoded(0x1941A469);
1325    nested! {
1326      required: [ ],
1327      optional: [ ],
1328      multiple: [ AttachedFile ],
1329    }
1330}
1331
1332/// An attached file.
1333#[derive(Debug, Clone, PartialEq, Eq, Default)]
1334pub struct AttachedFile {
1335    /// Optional CRC-32 element for integrity checking.
1336    pub crc32: Option<Crc32>,
1337    /// void element, useful for reserving space during writing.
1338    pub void: Option<Void>,
1339
1340    /// A human-friendly name for the attached file.
1341    pub file_description: Option<FileDescription>,
1342    /// Filename of the attached file.
1343    pub file_name: FileName,
1344    /// Media type of the file following the \[@!RFC6838\] format.
1345    pub file_media_type: FileMediaType,
1346    /// The data of the file.
1347    pub file_data: FileData,
1348    /// Unique ID representing the file, as random as possible.
1349    pub file_uid: FileUid,
1350}
1351
1352impl Element for AttachedFile {
1353    const ID: VInt64 = VInt64::from_encoded(0x61A7);
1354    nested! {
1355        required: [ FileName, FileMediaType, FileData, FileUid ],
1356        optional: [ FileDescription ],
1357        multiple: [ ],
1358    }
1359}
1360/// A system to define basic menus and partition data. For more detailed information, look at the Chapters explanation in [chapters](https://www.matroska.org/technical/chapters.html).
1361#[derive(Debug, Clone, PartialEq, Eq, Default)]
1362pub struct Chapters {
1363    /// Optional CRC-32 element for integrity checking.
1364    pub crc32: Option<Crc32>,
1365    /// void element, useful for reserving space during writing.
1366    pub void: Option<Void>,
1367
1368    /// Contains all information about a Segment edition.
1369    pub edition_entry: Vec<EditionEntry>,
1370}
1371
1372impl Element for Chapters {
1373    const ID: VInt64 = VInt64::from_encoded(0x1043A770);
1374    nested! {
1375        required: [ ],
1376        optional: [ ],
1377        multiple: [ EditionEntry ],
1378    }
1379}
1380
1381/// Contains all information about a Segment edition.
1382#[derive(Debug, Clone, PartialEq, Eq, Default)]
1383pub struct EditionEntry {
1384    /// Optional CRC-32 element for integrity checking.
1385    pub crc32: Option<Crc32>,
1386    /// void element, useful for reserving space during writing.
1387    pub void: Option<Void>,
1388
1389    /// A unique ID to identify the edition. It's useful for tagging an edition.
1390    pub edition_uid: Option<EditionUid>,
1391    /// Set to 1 if an edition is hidden. Hidden editions **SHOULD NOT** be available to the user interface (but still to Control Tracks; see [notes](https://www.matroska.org/technical/chapters.html#flags) on Chapter flags).
1392    pub edition_flag_hidden: EditionFlagHidden,
1393    /// Set to 1 if the edition **SHOULD** be used as the default one.
1394    pub edition_flag_default: EditionFlagDefault,
1395    /// Set to 1 if the chapters can be defined multiple times and the order to play them is enforced; see editionflagordered.
1396    pub edition_flag_ordered: EditionFlagOrdered,
1397    /// Contains a possible string to use for the edition display for the given languages.
1398    pub edition_display: Vec<EditionDisplay>,
1399    /// Contains the atom information to use as the chapter atom (apply to all tracks).
1400    pub chapter_atom: Vec<ChapterAtom>,
1401}
1402
1403impl Element for EditionEntry {
1404    const ID: VInt64 = VInt64::from_encoded(0x45B9);
1405    nested! {
1406        required: [ EditionFlagHidden, EditionFlagDefault, EditionFlagOrdered ],
1407        optional: [ EditionUid ],
1408        multiple: [ EditionDisplay, ChapterAtom ],
1409    }
1410}
1411
1412/// Contains a possible string to use for the edition display for the given languages.
1413#[derive(Debug, Clone, PartialEq, Eq, Default)]
1414pub struct EditionDisplay {
1415    /// Optional CRC-32 element for integrity checking.
1416    pub crc32: Option<Crc32>,
1417    /// void element, useful for reserving space during writing.
1418    pub void: Option<Void>,
1419
1420    /// Contains the string to use as the edition name.
1421    pub edition_string: EditionString,
1422    /// One language corresponding to the EditionString, in the \[@!BCP47\] form; see basics on language codes.
1423    pub edition_language_ietf: Vec<EditionLanguageIetf>,
1424}
1425
1426impl Element for EditionDisplay {
1427    const ID: VInt64 = VInt64::from_encoded(0x4520);
1428    nested! {
1429        required: [ EditionString ],
1430        optional: [ ],
1431        multiple: [ EditionLanguageIetf ],
1432    }
1433}
1434
1435/// Contains the atom information to use as the chapter atom (apply to all tracks).
1436#[derive(Debug, Clone, PartialEq, Eq, Default)]
1437pub struct ChapterAtom {
1438    /// Optional CRC-32 element for integrity checking.
1439    pub crc32: Option<Crc32>,
1440    /// void element, useful for reserving space during writing.
1441    pub void: Option<Void>,
1442
1443    /// Contains the atom information to use as the chapter atom (apply to all tracks).
1444    pub chapter_uid: ChapterUid,
1445    /// A unique string ID to identify the Chapter. For example it is used as the storage for \[@?WebVTT\] cue identifier values.
1446    pub chapter_string_uid: Option<ChapterStringUid>,
1447    /// Timestamp of the start of Chapter, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks.
1448    pub chapter_time_start: ChapterTimeStart,
1449    /// Timestamp of the end of Chapter timestamp excluded, expressed in Matroska Ticks -- i.e., in nanoseconds; see timestamp-ticks. The value **MUST** be greater than or equal to the `ChapterTimeStart` of the same `ChapterAtom`. The `ChapterTimeEnd` timestamp value being excluded, it **MUST** take in account the duration of the last frame it includes, especially for the `ChapterAtom` using the last frames of the `Segment`. ChapterTimeEnd **MUST** be set if the Edition is an ordered edition; see (#editionflagordered), unless it's a Parent Chapter; see (#nested-chapters)
1450    pub chapter_time_end: Option<ChapterTimeEnd>,
1451    /// Set to 1 if a chapter is hidden. Hidden chapters **SHOULD NOT** be available to the user interface (but still to Control Tracks; see chapterflaghidden on Chapter flags).
1452    pub chapter_flag_hidden: ChapterFlagHidden,
1453    /// Set to 1 if the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie **SHOULD** skip all the content between the TimeStart and TimeEnd of this chapter; see notes on Chapter flags.
1454    pub chapter_flag_enabled: ChapterFlagEnabled,
1455    /// The SegmentUUID of another Segment to play during this chapter. The value **MUST NOT** be the `SegmentUUID` value of the `Segment` it belongs to. ChapterSegmentUUID **MUST** be set if ChapterSegmentEditionUID is used; see (#medium-linking) on medium-linking Segments.
1456    pub chapter_segment_uuid: Option<ChapterSegmentUuid>,
1457    /// Indicate what type of content the ChapterAtom contains and might be skipped. It can be used to automatically skip content based on the type. If a `ChapterAtom` is inside a `ChapterAtom` that has a `ChapterSkipType` set, it **MUST NOT** have a `ChapterSkipType` or have a `ChapterSkipType` with the same value as it's parent `ChapterAtom`. If the `ChapterAtom` doesn't contain a `ChapterTimeEnd`, the value of the `ChapterSkipType` is only valid until the next `ChapterAtom` with a `ChapterSkipType` value or the end of the file.
1458    /// * 0 - No Skipping,
1459    /// * 1 - Opening Credits,
1460    /// * 2 - End Credits,
1461    /// * 3 - Recap,
1462    /// * 4 - Next Preview,
1463    /// * 5 - Preview,
1464    /// * 6 - Advertisement
1465    pub chapter_skip_type: Option<ChapterSkipType>,
1466    /// The EditionUID to play from the Segment linked in ChapterSegmentUUID. If ChapterSegmentEditionUID is undeclared, then no Edition of the linked Segment is used; see medium-linking on medium-linking Segments.
1467    pub chapter_segment_edition_uid: Option<ChapterSegmentEditionUid>,
1468    /// Specify the physical equivalent of this ChapterAtom like "DVD" (60) or "SIDE" (50); see notes for a complete list of values.
1469    pub chapter_physical_equiv: Option<ChapterPhysicalEquiv>,
1470    /// List of tracks on which the chapter applies. If this Element is not present, all tracks apply
1471    pub chapter_track: Option<ChapterTrack>,
1472    /// Contains all possible strings to use for the chapter display.
1473    pub chapter_display: Vec<ChapterDisplay>,
1474    /// Contains all the commands associated to the Atom.
1475    pub chap_process: Vec<ChapProcess>,
1476
1477    /// Contains nested ChapterAtoms, used when chapter have sub-chapters or sub-sections
1478    pub chapter_atom: Vec<ChapterAtom>,
1479}
1480
1481impl Element for ChapterAtom {
1482    const ID: VInt64 = VInt64::from_encoded(0xB6);
1483    nested! {
1484        required: [ ChapterUid, ChapterTimeStart, ChapterFlagHidden, ChapterFlagEnabled ],
1485        optional: [ ChapterStringUid, ChapterTimeEnd, ChapterSegmentUuid, ChapterSkipType, ChapterSegmentEditionUid, ChapterPhysicalEquiv, ChapterTrack ],
1486        multiple: [ ChapterDisplay, ChapProcess, ChapterAtom ],
1487    }
1488}
1489
1490/// List of tracks on which the chapter applies. If this Element is not present, all tracks apply
1491#[derive(Debug, Clone, PartialEq, Eq, Default)]
1492pub struct ChapterTrack {
1493    /// Optional CRC-32 element for integrity checking.
1494    pub crc32: Option<Crc32>,
1495    /// void element, useful for reserving space during writing.
1496    pub void: Option<Void>,
1497
1498    /// UID of the Track to apply this chapter to. In the absence of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absence of this Element indicates that the Chapter **SHOULD** be applied to any currently used Tracks.
1499    pub chapter_track_uid: Vec<ChapterTrackUid>,
1500}
1501impl Element for ChapterTrack {
1502    const ID: VInt64 = VInt64::from_encoded(0x8F);
1503    nested! {
1504        required: [ ],
1505        optional: [ ],
1506        multiple: [ ChapterTrackUid ],
1507    }
1508}
1509
1510/// Contains all possible strings to use for the chapter display.
1511#[derive(Debug, Clone, PartialEq, Eq, Default)]
1512pub struct ChapterDisplay {
1513    /// Optional CRC-32 element for integrity checking.
1514    pub crc32: Option<Crc32>,
1515    /// void element, useful for reserving space during writing.
1516    pub void: Option<Void>,
1517
1518    /// Contains the string to use as the chapter atom.
1519    pub chap_string: ChapString,
1520    /// A language corresponding to the string, in the Matroska languages form; see basics on language codes. This Element **MUST** be ignored if a ChapLanguageBCP47 Element is used within the same ChapterDisplay Element.
1521    pub chap_language: Vec<ChapLanguage>,
1522    /// A language corresponding to the ChapString, in the \[@!BCP47\] form; see basics on language codes. If a ChapLanguageBCP47 Element is used, then any ChapLanguage and ChapCountry Elements used in the same ChapterDisplay **MUST** be ignored.
1523    pub chap_language_bcp47: Vec<ChapLanguageBcp47>,
1524    /// A country corresponding to the string, in the Matroska countries form; see basics on country codes. This Element **MUST** be ignored if a ChapLanguageBCP47 Element is used within the same ChapterDisplay Element.
1525    pub chap_country: Vec<ChapCountry>,
1526}
1527
1528impl Element for ChapterDisplay {
1529    const ID: VInt64 = VInt64::from_encoded(0x80);
1530    nested! {
1531        required: [ ChapString ],
1532        optional: [ ],
1533        multiple: [ ChapLanguage, ChapLanguageBcp47, ChapCountry ],
1534    }
1535}
1536
1537/// Contains nested ChapterAtoms, used when chapter have sub-chapters or sub-sections
1538#[derive(Debug, Clone, PartialEq, Eq, Default)]
1539pub struct ChapProcess {
1540    /// Optional CRC-32 element for integrity checking.
1541    pub crc32: Option<Crc32>,
1542    /// void element, useful for reserving space during writing.
1543    pub void: Option<Void>,
1544
1545    /// Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used; see menu-features on DVD menus. More codec IDs can be added later.
1546    pub chap_process_codec_id: ChapProcessCodecId,
1547    /// Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the "DVD level" equivalent; see menu-features on DVD menus.
1548    pub chap_process_private: Option<ChapProcessPrivate>,
1549    /// Contains all the commands associated to the Atom.
1550    pub chap_process_command: Vec<ChapProcessCommand>,
1551}
1552
1553impl Element for ChapProcess {
1554    const ID: VInt64 = VInt64::from_encoded(0x6944);
1555    nested! {
1556        required: [ ChapProcessCodecId ],
1557        optional: [ ChapProcessPrivate ],
1558        multiple: [ ChapProcessCommand ],
1559    }
1560}
1561
1562/// Contains all the commands associated to the Atom.
1563#[derive(Debug, Clone, PartialEq, Eq, Default)]
1564pub struct ChapProcessCommand {
1565    /// Optional CRC-32 element for integrity checking.
1566    pub crc32: Option<Crc32>,
1567    /// void element, useful for reserving space during writing.
1568    pub void: Option<Void>,
1569
1570    /// Defines when the process command **SHOULD** be handled
1571    /// * 0 - during the whole chapter,
1572    /// * 1 - before starting playback,
1573    /// * 2 - after playback of the chapter
1574    pub chap_process_time: ChapProcessTime,
1575    /// Contains the command information. The data **SHOULD** be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands; see menu-features on DVD menus.
1576    pub chap_process_data: ChapProcessData,
1577}
1578
1579impl Element for ChapProcessCommand {
1580    const ID: VInt64 = VInt64::from_encoded(0x6911);
1581    nested! {
1582        required: [ ChapProcessTime, ChapProcessData ],
1583        optional: [ ],
1584        multiple: [ ],
1585    }
1586}
1587
1588/// Element containing metadata describing Tracks, Editions, Chapters, Attachments, or the Segment as a whole. A list of valid tags can be found in Matroska tagging RFC.
1589#[derive(Debug, Clone, PartialEq, Eq, Default)]
1590pub struct Tags {
1591    /// Optional CRC-32 element for integrity checking.
1592    pub crc32: Option<Crc32>,
1593    /// void element, useful for reserving space during writing.
1594    pub void: Option<Void>,
1595
1596    /// A single metadata descriptor.
1597    pub tag: Vec<Tag>,
1598}
1599
1600impl Element for Tags {
1601    const ID: VInt64 = VInt64::from_encoded(0x1254C367);
1602    nested! {
1603      required: [ ],
1604      optional: [ ],
1605      multiple: [ Tag ],
1606    }
1607}
1608
1609/// A single metadata descriptor.
1610#[derive(Debug, Clone, PartialEq, Eq, Default)]
1611pub struct Tag {
1612    /// Optional CRC-32 element for integrity checking.
1613    pub crc32: Option<Crc32>,
1614    /// void element, useful for reserving space during writing.
1615    pub void: Option<Void>,
1616
1617    /// Specifies which other elements the metadata represented by the Tag applies to. If empty or omitted, then the Tag describes everything in the Segment.
1618    pub targets: Targets,
1619    /// Contains general information about the target.
1620    pub simple_tag: Vec<SimpleTag>,
1621}
1622
1623impl Element for Tag {
1624    const ID: VInt64 = VInt64::from_encoded(0x7373);
1625    nested! {
1626      required: [ Targets ],
1627      optional: [ ],
1628      multiple: [ SimpleTag ],
1629    }
1630}
1631
1632/// Specifies which other elements the metadata represented by the Tag applies to. If empty or omitted, then the Tag describes everything in the Segment.
1633#[derive(Debug, Clone, PartialEq, Eq, Default)]
1634pub struct Targets {
1635    /// Optional CRC-32 element for integrity checking.
1636    pub crc32: Option<Crc32>,
1637    /// void element, useful for reserving space during writing.
1638    pub void: Option<Void>,
1639
1640    /// A number to indicate the logical level of the target.
1641    /// * 70 - COLLECTION,
1642    /// * 60 - EDITION / ISSUE / VOLUME / OPUS / SEASON / SEQUEL,
1643    /// * 50 - ALBUM / OPERA / CONCERT / MOVIE / EPISODE,
1644    /// * 40 - PART / SESSION,
1645    /// * 30 - TRACK / SONG / CHAPTER,
1646    /// * 20 - SUBTRACK / MOVEMENT / SCENE,
1647    /// * 10 - SHOT
1648    pub target_type_value: TargetTypeValue,
1649    /// An informational string that can be used to display the logical level of the target like "ALBUM", "TRACK", "MOVIE", "CHAPTER", etc. ; see Section 6.4 of Matroska tagging RFC.
1650    /// * COLLECTION - TargetTypeValue 70,
1651    /// * EDITION - TargetTypeValue 60,
1652    /// * ISSUE - TargetTypeValue 60,
1653    /// * VOLUME - TargetTypeValue 60,
1654    /// * OPUS - TargetTypeValue 60,
1655    /// * SEASON - TargetTypeValue 60,
1656    /// * SEQUEL - TargetTypeValue 60,
1657    /// * ALBUM - TargetTypeValue 50,
1658    /// * OPERA - TargetTypeValue 50,
1659    /// * CONCERT - TargetTypeValue 50,
1660    /// * MOVIE - TargetTypeValue 50,
1661    /// * EPISODE - TargetTypeValue 50,
1662    /// * PART - TargetTypeValue 40,
1663    /// * SESSION - TargetTypeValue 40,
1664    /// * TRACK - TargetTypeValue 30,
1665    /// * SONG - TargetTypeValue 30,
1666    /// * CHAPTER - TargetTypeValue 30,
1667    /// * SUBTRACK - TargetTypeValue 20,
1668    /// * MOVEMENT - TargetTypeValue 20,
1669    /// * SCENE - TargetTypeValue 20,
1670    /// * SHOT - TargetTypeValue 10
1671    pub target_type: Option<TargetType>,
1672    /// A unique ID to identify the Track(s) the tags belong to. If the value is 0 at this level, the tags apply to all tracks in the Segment. If set to any other value, it **MUST** match the `TrackUID` value of a track found in this Segment.
1673    pub tag_track_uid: Vec<TagTrackUid>,
1674    /// A unique ID to identify the EditionEntry(s) the tags belong to. If the value is 0 at this level, the tags apply to all editions in the Segment. If set to any other value, it **MUST** match the `EditionUID` value of an edition found in this Segment.
1675    pub tag_edition_uid: Vec<TagEditionUid>,
1676    /// A unique ID to identify the Chapter(s) the tags belong to. If the value is 0 at this level, the tags apply to all chapters in the Segment. If set to any other value, it **MUST** match the `ChapterUID` value of a chapter found in this Segment.
1677    pub tag_chapter_uid: Vec<TagChapterUid>,
1678    /// A unique ID to identify the Attachment(s) the tags belong to. If the value is 0 at this level, the tags apply to all the attachments in the Segment. If set to any other value, it **MUST** match the `FileUID` value of an attachment found in this Segment.
1679    pub tag_attachment_uid: Vec<TagAttachmentUid>,
1680}
1681
1682impl Element for Targets {
1683    const ID: VInt64 = VInt64::from_encoded(0x63C0);
1684    nested! {
1685      required: [ TargetTypeValue ],
1686      optional: [ TargetType ],
1687      multiple: [ TagTrackUid, TagEditionUid, TagChapterUid, TagAttachmentUid ],
1688    }
1689}
1690
1691/// Contains general information about the target.
1692#[derive(Debug, Clone, PartialEq, Eq, Default)]
1693pub struct SimpleTag {
1694    /// Optional CRC-32 element for integrity checking.
1695    pub crc32: Option<Crc32>,
1696    /// void element, useful for reserving space during writing.
1697    pub void: Option<Void>,
1698
1699    /// The name of the Tag that is going to be stored.
1700    pub tag_name: TagName,
1701    /// Specifies the language of the tag specified, in the Matroska languages form; see basics on language codes. This Element **MUST** be ignored if the TagLanguageBCP47 Element is used within the same SimpleTag Element.
1702    pub tag_language: TagLanguage,
1703    /// The language used in the TagString, in the \[@!BCP47\] form; see basics on language codes. If this Element is used, then any TagLanguage Elements used in the same SimpleTag **MUST** be ignored.
1704    pub tag_language_bcp47: Option<TagLanguageBcp47>,
1705    /// A boolean value to indicate if this is the default/original language to use for the given tag.
1706    pub tag_default: TagDefault,
1707    /// The value of the Tag.
1708    pub tag_string: Option<TagString>,
1709    /// The values of the Tag, if it is binary. Note that this cannot be used in the same SimpleTag as TagString.
1710    pub tag_binary: Option<TagBinary>,
1711    /// Nested simple tags, if any.
1712    pub simple_tag: Vec<SimpleTag>,
1713}
1714
1715impl Element for SimpleTag {
1716    const ID: VInt64 = VInt64::from_encoded(0x67C8);
1717    nested! {
1718      required: [ TagName, TagLanguage, TagDefault ],
1719      optional: [ TagLanguageBcp47, TagString, TagBinary ],
1720      multiple: [ SimpleTag ],
1721    }
1722}