]> git.sesse.net Git - vlc/blob - modules/demux/asf/libasf.h
Make Zorglub less unhappy
[vlc] / modules / demux / asf / libasf.h
1 /*****************************************************************************
2  * libasf.h :
3  *****************************************************************************
4  * Copyright (C) 2001-2003 the VideoLAN team
5  * $Id$
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 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 General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23
24 /*****************************************************************************
25  * Structure needed for decoder
26  *****************************************************************************/
27 typedef struct guid_s
28 {
29     uint32_t v1; /* le */
30     uint16_t v2; /* le */
31     uint16_t v3; /* le */
32     uint8_t  v4[8];
33 } guid_t;
34
35 enum
36 {
37     ASF_OBJECT_NULL = 0,
38     ASF_OBJECT_ROOT,
39     ASF_OBJECT_HEADER,
40     ASF_OBJECT_DATA,
41     ASF_OBJECT_INDEX,
42     ASF_OBJECT_FILE_PROPERTIES,
43     ASF_OBJECT_STREAM_PROPERTIES,
44     ASF_OBJECT_HEADER_EXTENSION,
45     ASF_OBJECT_CODEC_LIST,
46     ASF_OBJECT_MARKER,
47     ASF_OBJECT_CONTENT_DESCRIPTION,
48     ASF_OBJECT_METADATA,
49     ASF_OBJECT_PADDING,
50     ASF_OBJECT_OTHER,
51 };
52
53 static const guid_t asf_object_null_guid =
54 {
55     0x00000000,
56     0x0000,
57     0x0000,
58     { 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00 }
59 };
60
61 static const guid_t asf_object_header_guid =
62 {0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
63
64 static const guid_t asf_object_data_guid =
65 {0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}};
66
67 static const guid_t asf_object_index_guid =
68 {0x33000890, 0xE5B1, 0x11CF, {0x89, 0xF4, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}};
69
70 static const guid_t asf_object_file_properties_guid =
71 {0x8cabdca1, 0xa947, 0x11cf, {0x8e, 0xe4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
72
73 static const guid_t asf_object_stream_properties_guid =
74 {0xB7DC0791, 0xA9B7, 0x11CF, {0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
75
76 static const guid_t asf_object_content_description_guid =
77 {0x75B22633, 0x668E, 0x11CF, {0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}};
78
79 static const guid_t asf_object_header_extension_guid =
80 {0x5FBF03B5, 0xA92E, 0x11CF, {0x8E, 0xE3, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
81
82 static const guid_t asf_object_metadata_guid =
83 {0xC5F8CBEA, 0x5BAF, 0x4877, {0x84, 0x67, 0xAA, 0x8C, 0x44, 0xFA, 0x4C, 0xCA}};
84
85 static const guid_t asf_object_codec_list_guid =
86 {0x86D15240, 0x311D, 0x11D0, {0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
87
88 static const guid_t asf_object_marker_guid =
89 {0xF487CD01, 0xA951, 0x11CF, {0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65}};
90
91 static const guid_t asf_object_stream_type_audio =
92 {0xF8699E40, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
93
94 static const guid_t asf_object_stream_type_video =
95 {0xbc19efc0, 0x5B4D, 0x11CF, {0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B}};
96
97 static const guid_t asf_object_stream_type_command =
98 {0x59DACFC0, 0x59E6, 0x11D0, {0xA3, 0xAC, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}};
99
100 /* TODO */
101 static const guid_t asf_object_stream_bitrate_properties =
102 {0x7BF875CE, 0x468D, 0x11D1, {0x8D, 0x82, 0x00, 0x60, 0x97, 0xC9, 0xA2, 0xB2}};
103
104 static const guid_t asf_object_language_list =
105 {0x7C4346A9, 0xEFE0, 0x4BFC, {0xB2, 0x29, 0x39, 0x3E, 0xDE, 0x41, 0x5C, 0x85}};
106
107 static const guid_t asf_object_extended_stream_properties =
108 {0x14E6A5CB, 0xC672, 0x4332, {0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A}};
109
110 static const guid_t asf_object_advanced_mutual_exclusion =
111 {0xA08649CF, 0x4775, 0x4670, {0x8A, 0x16, 0x6E, 0x35, 0x35, 0x75, 0x66, 0xCD}};
112
113 static const guid_t asf_object_padding =
114 {0x1806D474, 0xCADF, 0x4509, {0xA4, 0xBA, 0x9A, 0xAB, 0xCB, 0x96, 0xAA, 0xE8}};
115
116 static const guid_t asf_object_stream_prioritization =
117 {0xD4FED15B, 0x88D3, 0x454F, {0x81, 0xF0, 0xED, 0x5C, 0x45, 0x99, 0x9E, 0x24}};
118
119 static const guid_t asf_object_extended_content_description =
120 {0xD2D0A440, 0xE307, 0x11D2, {0x97, 0xF0, 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50}};
121
122 #define ASF_OBJECT_COMMON          \
123     int          i_type;           \
124     guid_t       i_object_id;      \
125     uint64_t     i_object_size;    \
126     uint64_t     i_object_pos;     \
127     union asf_object_u *p_father;  \
128     union asf_object_u *p_first;   \
129     union asf_object_u *p_last;    \
130     union asf_object_u *p_next;
131
132 typedef struct
133 {
134     ASF_OBJECT_COMMON
135
136 } asf_object_common_t;
137
138 typedef struct
139 {
140     uint32_t i_packet_number;
141     uint16_t i_packet_count;
142
143 } asf_index_entry_t;
144
145 /****************************************************************************
146  * High level asf object
147  ****************************************************************************/
148 /* This is the first header find in a asf file
149  * It's the only object that have subobject */
150 typedef struct
151 {
152     ASF_OBJECT_COMMON
153     uint32_t i_sub_object_count;
154     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
155     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
156
157 } asf_object_header_t;
158
159 typedef struct
160 {
161     ASF_OBJECT_COMMON
162     guid_t      i_file_id;
163     uint64_t    i_total_data_packets;
164     uint16_t    i_reserved;
165
166 } asf_object_data_t;
167
168
169 typedef struct
170 {
171     ASF_OBJECT_COMMON
172     guid_t      i_file_id;
173     uint64_t    i_index_entry_time_interval;
174     uint32_t    i_max_packet_count;
175     uint32_t    i_index_entry_count;
176
177     asf_index_entry_t *index_entry;
178
179 } asf_object_index_t;
180
181 /****************************************************************************
182  * Sub level asf object
183  ****************************************************************************/
184 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
185 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
186
187 typedef struct
188 {
189     ASF_OBJECT_COMMON
190
191     guid_t  i_file_id;
192     uint64_t     i_file_size;
193     uint64_t     i_creation_date;
194     uint64_t     i_data_packets_count;
195     uint64_t     i_play_duration;
196     uint64_t     i_send_duration;
197     uint64_t     i_preroll;
198     uint32_t     i_flags;
199     uint32_t     i_min_data_packet_size;
200     uint32_t     i_max_data_packet_size;
201     uint32_t     i_max_bitrate;
202
203 } asf_object_file_properties_t;
204
205 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
206 typedef struct
207 {
208     ASF_OBJECT_COMMON
209
210     guid_t  i_stream_type;
211     guid_t  i_error_correction_type;
212     uint64_t     i_time_offset;
213     uint32_t     i_type_specific_data_length;
214     uint32_t     i_error_correction_data_length;
215     uint16_t     i_flags;
216         /* extrated from flags */
217         uint8_t i_stream_number;
218     uint32_t    i_reserved;
219     uint8_t     *p_type_specific_data;
220     uint8_t     *p_error_correction_data;
221 } asf_object_stream_properties_t;
222
223 typedef struct
224 {
225     ASF_OBJECT_COMMON
226
227     guid_t      i_reserved1;
228     uint16_t    i_reserved2;
229     uint32_t    i_header_extension_size;
230     uint8_t     *p_header_extension_data;
231
232 } asf_object_header_extension_t;
233
234 #define ASF_METADATA_TYPE_STRING 0x0000
235 #define ASF_METADATA_TYPE_BYTE   0x0001
236 #define ASF_METADATA_TYPE_BOOL   0x0002
237 #define ASF_METADATA_TYPE_DWORD  0x0003
238 #define ASF_METADATA_TYPE_QWORD  0x0004
239 #define ASF_METADATA_TYPE_WORD   0x0005
240
241 typedef struct
242 {
243     uint16_t    i_stream;
244     uint16_t    i_type;
245     char        *psz_name;
246
247     int64_t i_val;
248     int i_data;
249     uint8_t *p_data;
250
251 } asf_metadata_record_t;
252
253 typedef struct
254 {
255     ASF_OBJECT_COMMON
256
257     uint32_t i_record_entries_count;
258     asf_metadata_record_t *record;
259
260 } asf_object_metadata_t;
261
262 typedef struct
263 {
264     ASF_OBJECT_COMMON
265
266     char *psz_title;
267     char *psz_author;
268     char *psz_copyright;
269     char *psz_description;
270     char *psz_rating;
271
272 } asf_object_content_description_t;
273
274 typedef struct
275 {
276     uint16_t i_length;
277     uint16_t *i_char;
278
279 } string16_t;
280
281 #define ASF_CODEC_TYPE_VIDEO    0x0001
282 #define ASF_CODEC_TYPE_AUDIO    0x0002
283 #define ASF_CODEC_TYPE_UNKNOW   0xffff
284
285 typedef struct
286 {
287     uint16_t    i_type;
288     char        *psz_name;
289     char        *psz_description;
290
291     uint16_t    i_information_length;
292     uint8_t     *p_information;
293 } asf_codec_entry_t;
294
295 typedef struct
296 {
297     ASF_OBJECT_COMMON
298     guid_t      i_reserved;
299     uint32_t    i_codec_entries_count;
300     asf_codec_entry_t *codec;
301
302 } asf_object_codec_list_t;
303
304 typedef struct
305 {
306     uint64_t     i_offset;
307     uint64_t     i_presentation_time;
308     uint16_t     i_entry_length;
309     uint32_t     i_send_time;
310     uint32_t     i_flags;
311     uint32_t     i_marker_description_length;
312     uint8_t      *i_marker_description;
313
314 } asf_marker_t;
315
316 typedef struct
317 {
318     ASF_OBJECT_COMMON
319     guid_t      i_reserved1;
320     uint32_t    i_count;
321     uint16_t    i_reserved2;
322     string16_t name;
323     asf_marker_t *marker;
324
325 } asf_object_marker_t;
326
327 typedef struct
328 {
329     ASF_OBJECT_COMMON
330     int  i_language;
331     char **ppsz_language;
332
333 } asf_object_language_list_t;
334
335 typedef struct
336 {
337     ASF_OBJECT_COMMON
338
339     int i_bitrate;
340     struct
341     {
342         int      i_stream_number;
343         uint32_t i_avg_bitrate;
344     } bitrate[128];
345 } asf_object_stream_bitrate_properties_t;
346
347 typedef struct
348 {
349     ASF_OBJECT_COMMON
350
351     int64_t i_start_time;
352     int64_t i_end_time;
353     int32_t i_data_bitrate;
354     int32_t i_buffer_size;
355     int32_t i_initial_buffer_fullness;
356     int32_t i_alternate_data_bitrate;
357     int32_t i_alternate_buffer_size;
358     int32_t i_alternate_initial_buffer_fullness;
359     int32_t i_maximum_object_size;
360
361     int32_t i_flags;
362     int16_t i_stream_number;
363     int16_t i_language_index;
364     int64_t i_average_time_per_frame;
365
366     int     i_stream_name_count;
367     int     i_payload_extention_system_count;
368
369     int     *pi_stream_name_language;
370     char    **ppsz_stream_name;
371
372     asf_object_stream_properties_t *p_sp;
373 } asf_object_extended_stream_properties_t;
374
375 typedef struct
376 {
377     ASF_OBJECT_COMMON
378
379     guid_t  type;
380     int16_t i_stream_number_count;
381     int16_t *pi_stream_number;
382
383 } asf_object_advanced_mutual_exclusion_t;
384
385 typedef struct
386 {
387     ASF_OBJECT_COMMON
388
389     int i_priority_count;
390     int *pi_priority_flag;
391     int *pi_priority_stream_number;
392 } asf_object_stream_prioritization_t;
393
394 typedef struct
395 {
396     ASF_OBJECT_COMMON
397
398     int i_count;
399     char **ppsz_name;
400     char **ppsz_value;
401 } asf_object_extended_content_description_t;
402
403 /****************************************************************************
404  * Special Root Object
405  ****************************************************************************/
406 typedef struct
407 {
408     ASF_OBJECT_COMMON
409
410     asf_object_header_t *p_hdr;
411     asf_object_data_t   *p_data;
412     /* could be NULL if !b_seekable or not-present */
413     asf_object_index_t  *p_index;
414
415     /* from asf_object_header_t */
416     asf_object_file_properties_t *p_fp;
417
418     /* from asf_object_header_extension_t */
419     asf_object_metadata_t *p_metadata;
420
421 } asf_object_root_t;
422
423 /****************************************************************************
424  * asf_object_t: union of all objects.
425  ****************************************************************************/
426 typedef union asf_object_u
427 {
428     asf_object_common_t common;
429     asf_object_header_t header;
430     asf_object_data_t   data;
431     asf_object_index_t  index;
432     asf_object_root_t   root;
433     asf_object_file_properties_t    file_properties;
434     asf_object_stream_properties_t  stream_properties;
435     asf_object_header_extension_t   header_extension;
436     asf_object_metadata_t           metadata;
437     asf_object_codec_list_t         codec_list;
438     asf_object_marker_t             marker;
439     asf_object_language_list_t      lang;
440     asf_object_stream_bitrate_properties_t stream_bitrate;
441     asf_object_extended_stream_properties_t ext_stream;
442
443 } asf_object_t;
444
445
446 void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data );
447 int  ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 );
448
449 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
450 void               ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root );
451
452 #define ASF_CountObject( a, b ) __ASF_CountObject( (asf_object_t*)(a), b )
453 int  __ASF_CountObject ( asf_object_t *p_obj, const guid_t *p_guid );
454
455 #define ASF_FindObject( a, b, c )  __ASF_FindObject( (asf_object_t*)(a), b, c )
456 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number );