]> git.sesse.net Git - vlc/blob - modules/demux/asf/libasf.h
demux: libasf: fix tons of signedness
[vlc] / modules / demux / asf / libasf.h
1 /*****************************************************************************
2  * libasf.h :
3  *****************************************************************************
4  * Copyright © 2001-2004, 2011 VLC authors and VideoLAN
5  *
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23
24 /*****************************************************************************
25  * Structure needed for decoder
26  *****************************************************************************/
27
28 #include "libasf_guid.h"
29
30 #define ASF_OBJECT_COMMON          \
31     int          i_type;           \
32     guid_t       i_object_id;      \
33     uint64_t     i_object_size;    \
34     uint64_t     i_object_pos;     \
35     union asf_object_u *p_father;  \
36     union asf_object_u *p_first;   \
37     union asf_object_u *p_last;    \
38     union asf_object_u *p_next;
39
40 typedef struct
41 {
42     ASF_OBJECT_COMMON
43
44 } asf_object_common_t;
45
46 typedef struct
47 {
48     uint32_t i_packet_number;
49     uint16_t i_packet_count;
50
51 } asf_index_entry_t;
52
53 /****************************************************************************
54  * High level asf object
55  ****************************************************************************/
56 /* This is the first header found in an asf file
57  * It's the only object that has subobjects */
58 typedef struct
59 {
60     ASF_OBJECT_COMMON
61     uint32_t i_sub_object_count;
62     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
63     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
64
65 } asf_object_header_t;
66
67 typedef struct
68 {
69     ASF_OBJECT_COMMON
70     guid_t      i_file_id;
71     uint64_t    i_total_data_packets;
72     uint16_t    i_reserved;
73
74 } asf_object_data_t;
75
76
77 typedef struct
78 {
79     ASF_OBJECT_COMMON
80     guid_t      i_file_id;
81     uint64_t    i_index_entry_time_interval;
82     uint32_t    i_max_packet_count;
83     uint32_t    i_index_entry_count;
84
85     asf_index_entry_t *index_entry;
86
87 } asf_object_index_t;
88
89 /****************************************************************************
90  * Sub level asf object
91  ****************************************************************************/
92 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
93 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
94
95 typedef struct
96 {
97     ASF_OBJECT_COMMON
98
99     guid_t  i_file_id;
100     uint64_t     i_file_size;
101     uint64_t     i_creation_date;
102     uint64_t     i_data_packets_count;
103     uint64_t     i_play_duration;
104     uint64_t     i_send_duration;
105     uint64_t     i_preroll;
106     uint32_t     i_flags;
107     uint32_t     i_min_data_packet_size;
108     uint32_t     i_max_data_packet_size;
109     uint32_t     i_max_bitrate;
110
111 } asf_object_file_properties_t;
112
113 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
114 typedef struct
115 {
116     ASF_OBJECT_COMMON
117
118     guid_t  i_stream_type;
119     guid_t  i_error_correction_type;
120     uint64_t     i_time_offset;
121     uint32_t     i_type_specific_data_length;
122     uint32_t     i_error_correction_data_length;
123     uint16_t     i_flags;
124         /* extrated from flags */
125         uint8_t i_stream_number;
126     uint32_t    i_reserved;
127     uint8_t     *p_type_specific_data;
128     uint8_t     *p_error_correction_data;
129 } asf_object_stream_properties_t;
130
131 typedef struct
132 {
133     ASF_OBJECT_COMMON
134
135     guid_t      i_reserved1;
136     uint16_t    i_reserved2;
137     uint32_t    i_header_extension_size;
138     uint8_t     *p_header_extension_data;
139
140 } asf_object_header_extension_t;
141
142 enum {
143     ASF_METADATA_TYPE_STRING,
144     ASF_METADATA_TYPE_BYTE,
145     ASF_METADATA_TYPE_BOOL,
146     ASF_METADATA_TYPE_DWORD,
147     ASF_METADATA_TYPE_QWORD,
148     ASF_METADATA_TYPE_WORD,
149 };
150
151 typedef struct
152 {
153     uint16_t    i_stream;
154     uint16_t    i_type;
155     char        *psz_name;
156
157     uint64_t i_val;
158     uint16_t i_data;
159     uint8_t *p_data;
160
161 } asf_metadata_record_t;
162
163 typedef struct
164 {
165     ASF_OBJECT_COMMON
166
167     uint32_t i_record_entries_count;
168     asf_metadata_record_t *record;
169
170 } asf_object_metadata_t;
171
172 typedef struct
173 {
174     ASF_OBJECT_COMMON
175
176     char *psz_title;
177     char *psz_artist;
178     char *psz_copyright;
179     char *psz_description;
180     char *psz_rating;
181
182 } asf_object_content_description_t;
183
184 #define ASF_CODEC_TYPE_VIDEO    0x0001
185 #define ASF_CODEC_TYPE_AUDIO    0x0002
186 #define ASF_CODEC_TYPE_UNKNOWN  0xffff
187
188 typedef struct
189 {
190     uint16_t    i_type;
191     char        *psz_name;
192     char        *psz_description;
193
194     uint16_t    i_information_length;
195     uint8_t     *p_information;
196 } asf_codec_entry_t;
197
198 typedef struct
199 {
200     ASF_OBJECT_COMMON
201     guid_t      i_reserved;
202     uint32_t    i_codec_entries_count;
203     asf_codec_entry_t *codec;
204
205 } asf_object_codec_list_t;
206
207 typedef struct
208 {
209     uint64_t     i_offset;
210     uint64_t     i_presentation_time;
211     uint16_t     i_entry_length;
212     uint32_t     i_send_time;
213     uint32_t     i_flags;
214     uint32_t     i_marker_description_length;
215     char         *p_marker_description;
216
217 } asf_marker_t;
218
219 typedef struct
220 {
221     ASF_OBJECT_COMMON
222     guid_t      i_reserved1;
223     uint32_t    i_count;
224     uint16_t    i_reserved2;
225     char        *name;
226     asf_marker_t *marker;
227
228 } asf_object_marker_t;
229
230 typedef struct
231 {
232     ASF_OBJECT_COMMON
233     uint16_t  i_language;
234     char **ppsz_language;
235
236 } asf_object_language_list_t;
237
238 typedef struct
239 {
240     ASF_OBJECT_COMMON
241
242     uint16_t i_bitrate;
243     struct
244     {
245         uint8_t  i_stream_number;
246         uint32_t i_avg_bitrate;
247     } bitrate[128];
248 } asf_object_stream_bitrate_properties_t;
249
250
251 typedef struct
252 {
253     guid_t   i_extension_id;
254     uint16_t i_data_size;
255     uint32_t i_info_length;
256     char     *pi_info;
257 } asf_payload_extension_system_t;
258 #define ASF_EXTENSION_VIDEOFRAME_NEWFRAME  0x08
259 #define ASF_EXTENSION_VIDEOFRAME_IFRAME    0x01
260 #define ASF_EXTENSION_VIDEOFRAME_TYPE_MASK 0x07
261
262 typedef struct
263 {
264     ASF_OBJECT_COMMON
265
266     uint64_t i_start_time;
267     uint64_t i_end_time;
268     uint32_t i_data_bitrate;
269     uint32_t i_buffer_size;
270     uint32_t i_initial_buffer_fullness;
271     uint32_t i_alternate_data_bitrate;
272     uint32_t i_alternate_buffer_size;
273     uint32_t i_alternate_initial_buffer_fullness;
274     uint32_t i_maximum_object_size;
275
276     uint32_t i_flags;
277     uint16_t i_stream_number;
278     uint16_t i_language_index;
279     uint64_t i_average_time_per_frame;
280
281     uint16_t i_stream_name_count;
282
283     uint16_t i_payload_extension_system_count;
284     asf_payload_extension_system_t *p_ext;
285
286     uint16_t *pi_stream_name_language;
287     char    **ppsz_stream_name;
288
289     asf_object_stream_properties_t *p_sp;
290 } asf_object_extended_stream_properties_t;
291
292 #define ASF_MAX_EXCLUSION_TYPE 2
293 typedef enum
294 {
295     LANGUAGE = ASF_MAX_EXCLUSION_TYPE,
296     BITRATE = 1,
297     UNKNOWN = 0
298 } asf_exclusion_type_t;
299
300 typedef struct
301 {
302     ASF_OBJECT_COMMON
303
304     asf_exclusion_type_t exclusion_type;
305     uint16_t i_stream_number_count;
306     uint16_t *pi_stream_number;
307
308 } asf_object_advanced_mutual_exclusion_t;
309
310 typedef struct
311 {
312     ASF_OBJECT_COMMON
313
314     uint16_t i_priority_count;
315     uint16_t *pi_priority_flag;
316     uint16_t *pi_priority_stream_number;
317 } asf_object_stream_prioritization_t;
318
319 typedef struct
320 {
321     ASF_OBJECT_COMMON
322
323     asf_exclusion_type_t exclusion_type;
324     uint16_t i_stream_number_count;
325     uint16_t *pi_stream_numbers;
326 } asf_object_bitrate_mutual_exclusion_t;
327
328 typedef struct
329 {
330     ASF_OBJECT_COMMON
331
332     uint16_t i_count;
333     char **ppsz_name;
334     char **ppsz_value;
335 } asf_object_extended_content_description_t;
336
337 /****************************************************************************
338  * Special Root Object
339  ****************************************************************************/
340 typedef struct
341 {
342     ASF_OBJECT_COMMON
343
344     asf_object_header_t *p_hdr;
345     asf_object_data_t   *p_data;
346     /* could be NULL if !b_seekable or not-present */
347     asf_object_index_t  *p_index;
348
349     /* from asf_object_header_t */
350     asf_object_file_properties_t *p_fp;
351
352     /* from asf_object_header_extension_t */
353     asf_object_metadata_t *p_metadata;
354
355 } asf_object_root_t;
356
357 /****************************************************************************
358  * asf_object_t: union of all objects.
359  ****************************************************************************/
360 typedef union asf_object_u
361 {
362     asf_object_common_t common;
363     asf_object_header_t header;
364     asf_object_data_t   data;
365     asf_object_index_t  index;
366     asf_object_root_t   root;
367     asf_object_file_properties_t    file_properties;
368     asf_object_stream_properties_t  stream_properties;
369     asf_object_header_extension_t   header_extension;
370     asf_object_metadata_t           metadata;
371     asf_object_codec_list_t         codec_list;
372     asf_object_marker_t             marker;
373     asf_object_language_list_t      language_list;
374     asf_object_stream_bitrate_properties_t stream_bitrate;
375     asf_object_extended_stream_properties_t ext_stream;
376     asf_object_content_description_t content_description;
377     asf_object_advanced_mutual_exclusion_t advanced_mutual_exclusion;
378     asf_object_stream_prioritization_t stream_prioritization;
379     asf_object_bitrate_mutual_exclusion_t bitrate_mutual_exclusion;
380     asf_object_extended_content_description_t extended_content_description;
381
382 } asf_object_t;
383
384 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
385 void               ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root );
386
387 int ASF_CountObject ( void *p_obj, const guid_t *p_guid );
388
389 void *ASF_FindObject( void *p_obj, const guid_t *p_guid, int i_number );