mkv_element/
master.rs

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