1 /*
2    mkvmerge -- utility for splicing together matroska files
3    from component media subtypes
4 
5    Distributed under the GPL v2
6    see the file COPYING for details
7    or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    structs for various Quicktime and MP4 atoms
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #pragma once
15 
16 // 'Movie header' atom
17 #if defined(COMP_MSC)
18 #pragma pack(push,1)
19 #endif
20 struct PACKED_STRUCTURE mvhd_atom_t {
21   uint8_t  version;
22   uint8_t  flags[3];
23   uint32_t creation_time;
24   uint32_t modification_time;
25   uint32_t time_scale;
26   uint32_t duration;
27   uint32_t preferred_rate;
28   uint16_t preferred_volume;
29   uint8_t  reserved[10];
30   uint8_t  matrix_structure[36];
31   uint32_t preview_time;
32   uint32_t preview_duration;
33   uint32_t poster_time;
34   uint32_t selection_time;
35   uint32_t selection_duration;
36   uint32_t current_time;
37   uint32_t next_track_id;
38 };
39 
40 // 'Media header' atom
41 struct PACKED_STRUCTURE mdhd_atom_t {
42   uint8_t  version;              // == 0
43   uint8_t  flags[3];
44   uint32_t creation_time;
45   uint32_t modification_time;
46   uint32_t time_scale;
47   uint32_t duration;
48   uint16_t language;
49   uint16_t quality;
50 };
51 
52 // 'Media header' atom, 64bit version
53 struct PACKED_STRUCTURE mdhd64_atom_t {
54   uint8_t  version;              // == 1
55   uint8_t  flags[3];
56   uint64_t creation_time;
57   uint64_t modification_time;
58   uint32_t time_scale;
59   uint64_t duration;
60   uint16_t language;
61   uint16_t quality;
62 };
63 
64 // 'Handler reference' atom
65 struct PACKED_STRUCTURE hdlr_atom_t {
66   uint8_t  version;
67   uint8_t  flags[3];
68   uint32_t type;
69   uint32_t subtype;
70   uint32_t manufacturer;
71   uint32_t flags2;
72   uint32_t flags_mask;
73 };
74 
75 // Base for all 'sample data description' atoms
76 struct PACKED_STRUCTURE base_stsd_atom_t {
77   uint32_t size;
78   char     fourcc[4];
79   uint8_t  reserved[6];
80   uint16_t data_reference_index;
81 };
82 
83 // 'sound sample description' atom
84 struct PACKED_STRUCTURE sound_v0_stsd_atom_t {
85   base_stsd_atom_t base;
86   uint16_t         version;
87   uint16_t         revision;
88   uint32_t         vendor;
89   uint16_t         channels;
90   uint16_t         sample_size;
91   int16_t          compression_id;
92   uint16_t         packet_size;
93   uint32_t         sample_rate;         // 32bit fixed-point number
94 };
95 
96 // 'sound sample description' atom v1
97 struct PACKED_STRUCTURE sound_v1_stsd_atom_t {
98   sound_v0_stsd_atom_t v0;
99   struct PACKED_STRUCTURE {
100     uint32_t samples_per_packet;
101     uint32_t bytes_per_packet;
102     uint32_t bytes_per_frame;
103     uint32_t bytes_per_sample;
104   } v1;
105 };
106 
107 // 'sound sample description' atom v2
108 struct PACKED_STRUCTURE sound_v2_stsd_atom_t {
109   sound_v0_stsd_atom_t v0;
110   struct PACKED_STRUCTURE {
111     uint32_t v2_struct_size;
112     uint64_t sample_rate;       // 64bit float
113     // uint32_t unknown1;
114     uint32_t channels;
115 
116     // 16
117     uint32_t const1;            // always 0x7f000000
118     uint32_t bits_per_channel;  // for uncompressed audio
119     uint32_t flags;
120     uint32_t bytes_per_frame;   // if constant
121     uint32_t samples_per_frame; // lpcm frames per audio packet if constant
122   } v2;
123 };
124 
125 // 'video sample description' atom
126 struct PACKED_STRUCTURE video_stsd_atom_t {
127   base_stsd_atom_t base;
128   uint16_t         version;
129   uint16_t         revision;
130   uint32_t         vendor;
131   uint32_t         temporal_quality;
132   uint32_t         spatial_quality;
133   uint16_t         width;
134   uint16_t         height;
135   uint32_t         horizontal_resolution; // 32bit fixed-point number
136   uint32_t         vertical_resolution;   // 32bit fixed-point number
137   uint32_t         data_size;
138   uint16_t         frame_count;
139   char             compressor_name[32];
140   uint16_t         depth;
141   uint16_t         color_table_id;
142 };
143 
144 // 'colour information' atom
145 struct PACKED_STRUCTURE colr_atom_t {
146   uint32_t colour_type;
147   uint16_t colour_primaries;
148   uint16_t transfer_characteristics;
149   uint16_t matrix_coefficients;
150 };
151 
152 struct PACKED_STRUCTURE qt_image_description_t {
153   uint32_t size;
154   video_stsd_atom_t id;
155 };
156 #if defined(COMP_MSC)
157 #pragma pack(pop)
158 #endif
159 
160 // MPEG4 esds structure
161 struct esds_t {
162   uint8_t        version{};
163   uint32_t       flags{};
164   uint16_t       esid{};
165   uint8_t        stream_priority{};
166   uint8_t        object_type_id{};
167   uint8_t        stream_type{};
168   uint32_t       buffer_size_db{};
169   uint32_t       max_bitrate{};
170   uint32_t       avg_bitrate{};
171   memory_cptr    decoder_config;
172   memory_cptr    sl_config;
173 };
174