isobmff/boxes/sub_tracks.rs
1use crate::{FullBoxHeader, IsoBox};
2
3/// Sub track box
4///
5/// ISO/IEC 14496-12 - 8.14.3
6#[derive(IsoBox, Debug, PartialEq, Eq)]
7#[iso_box(box_type = b"strk", crate_path = crate)]
8pub struct SubTrackBox {
9 /// The contained [`SubTrackInformationBox`]. (mandatory)
10 #[iso_box(nested_box)]
11 pub stri: SubTrackInformationBox,
12 /// The contained [`SubTrackDefinitionBox`]. (optional)
13 ///
14 /// According to the official specification this is mandatory, but
15 /// there is one official sample file in which it is not present.
16 /// See <https://github.com/MPEGGroup/FileFormatConformance/issues/155>.
17 #[iso_box(nested_box(collect))]
18 pub strd: Option<SubTrackDefinitionBox>,
19}
20
21/// Sub track information box
22///
23/// ISO/IEC 14496-12 - 8.14.4
24#[derive(IsoBox, Debug, PartialEq, Eq)]
25#[iso_box(box_type = b"stri", crate_path = crate)]
26pub struct SubTrackInformationBox {
27 /// The full box header.
28 pub full_header: FullBoxHeader,
29 /// An integer that specifies a group or collection of tracks and/or sub tracks. If this field
30 /// is 0 (default value), then there is no information on whether the sub track can be used for switching
31 /// during playing or streaming. If this integer is not 0 it shall be the same for tracks and/or sub tracks
32 /// that can be used for switching between each other. Tracks that belong to the same switch group
33 /// shall belong to the same alternate group. A switch group may have only one member.
34 pub switch_group: i16,
35 /// An integer that specifies a group or collection of tracks and/or sub tracks. If this
36 /// field is 0 (default value), then there is no information on possible relations to other tracks/sub-
37 /// tracks. If this field is not 0, it should be the same for tracks/sub-tracks that contain alternate data
38 /// for one another and different for tracks/sub-tracks belonging to different such groups. Only one
39 /// track/sub-track within an alternate group should be played or streamed at any one time.
40 pub alternate_group: i16,
41 /// An integer. A non-zero value uniquely identifies the sub track locally within the track.
42 /// A zero value (default) means that sub_track_ID is not assigned.
43 pub sub_track_id: u32,
44 /// A list, to the end of the box, of attributes. The attributes in this list should be used as
45 /// descriptions of sub tracks or differentiating criteria for tracks and sub tracks in the same alternate
46 /// or switch group.
47 #[iso_box(repeated)]
48 pub attribute_list: Vec<u32>,
49}
50
51/// Sub track definition box
52///
53/// ISO/IEC 14496-12 - 8.14.5
54#[derive(IsoBox, Debug, PartialEq, Eq)]
55#[iso_box(box_type = b"strd", crate_path = crate)]
56pub struct SubTrackDefinitionBox {
57 /// The contained [`SubTrackSampleGroupBox`]es. (any quantity)
58 #[iso_box(nested_box(collect))]
59 pub stsg: Vec<SubTrackSampleGroupBox>,
60}
61
62/// Sub track sample group box
63///
64/// ISO/IEC 14496-12 - 8.14.6
65#[derive(IsoBox, Debug, PartialEq, Eq)]
66#[iso_box(box_type = b"stsg", crate_path = crate)]
67pub struct SubTrackSampleGroupBox {
68 /// The full box header.
69 pub full_header: FullBoxHeader,
70 /// An integer that identifies the sample grouping. The value shall be the same as in the
71 /// corresponding SampleToGroupBox and [`SampleGroupDescriptionBox`](super::SampleGroupDescriptionBox).
72 pub grouping_type: [u8; 4],
73 /// Counts the number of sample groups listed in this box.
74 pub item_count: u16,
75 /// An integer that gives the index of the sample group entry which describes
76 /// the samples in the group.
77 #[iso_box(repeated)]
78 pub group_description_index: Vec<u32>,
79}