]> git.sesse.net Git - vlc/blob - modules/demux/asf/libasf.h
Removes trailing spaces. Removes tabs.
[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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 static const guid_t asf_object_extended_stream_header =
123 {0x3afb65e2, 0x47ef, 0x40f2, { 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43}};
124
125 static const guid_t asf_object_extended_stream_type_audio =
126 {0x31178c9d, 0x03e1, 0x4528, { 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03}};
127
128 #define ASF_OBJECT_COMMON          \
129     int          i_type;           \
130     guid_t       i_object_id;      \
131     uint64_t     i_object_size;    \
132     uint64_t     i_object_pos;     \
133     union asf_object_u *p_father;  \
134     union asf_object_u *p_first;   \
135     union asf_object_u *p_last;    \
136     union asf_object_u *p_next;
137
138 typedef struct
139 {
140     ASF_OBJECT_COMMON
141
142 } asf_object_common_t;
143
144 typedef struct
145 {
146     uint32_t i_packet_number;
147     uint16_t i_packet_count;
148
149 } asf_index_entry_t;
150
151 /****************************************************************************
152  * High level asf object
153  ****************************************************************************/
154 /* This is the first header found in an asf file
155  * It's the only object that has subobjects */
156 typedef struct
157 {
158     ASF_OBJECT_COMMON
159     uint32_t i_sub_object_count;
160     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
161     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
162
163 } asf_object_header_t;
164
165 typedef struct
166 {
167     ASF_OBJECT_COMMON
168     guid_t      i_file_id;
169     uint64_t    i_total_data_packets;
170     uint16_t    i_reserved;
171
172 } asf_object_data_t;
173
174
175 typedef struct
176 {
177     ASF_OBJECT_COMMON
178     guid_t      i_file_id;
179     uint64_t    i_index_entry_time_interval;
180     uint32_t    i_max_packet_count;
181     uint32_t    i_index_entry_count;
182
183     asf_index_entry_t *index_entry;
184
185 } asf_object_index_t;
186
187 /****************************************************************************
188  * Sub level asf object
189  ****************************************************************************/
190 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
191 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
192
193 typedef struct
194 {
195     ASF_OBJECT_COMMON
196
197     guid_t  i_file_id;
198     uint64_t     i_file_size;
199     uint64_t     i_creation_date;
200     uint64_t     i_data_packets_count;
201     uint64_t     i_play_duration;
202     uint64_t     i_send_duration;
203     uint64_t     i_preroll;
204     uint32_t     i_flags;
205     uint32_t     i_min_data_packet_size;
206     uint32_t     i_max_data_packet_size;
207     uint32_t     i_max_bitrate;
208
209 } asf_object_file_properties_t;
210
211 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
212 typedef struct
213 {
214     ASF_OBJECT_COMMON
215
216     guid_t  i_stream_type;
217     guid_t  i_error_correction_type;
218     uint64_t     i_time_offset;
219     uint32_t     i_type_specific_data_length;
220     uint32_t     i_error_correction_data_length;
221     uint16_t     i_flags;
222         /* extrated from flags */
223         uint8_t i_stream_number;
224     uint32_t    i_reserved;
225     uint8_t     *p_type_specific_data;
226     uint8_t     *p_error_correction_data;
227 } asf_object_stream_properties_t;
228
229 typedef struct
230 {
231     ASF_OBJECT_COMMON
232
233     guid_t      i_reserved1;
234     uint16_t    i_reserved2;
235     uint32_t    i_header_extension_size;
236     uint8_t     *p_header_extension_data;
237
238 } asf_object_header_extension_t;
239
240 #define ASF_METADATA_TYPE_STRING 0x0000
241 #define ASF_METADATA_TYPE_BYTE   0x0001
242 #define ASF_METADATA_TYPE_BOOL   0x0002
243 #define ASF_METADATA_TYPE_DWORD  0x0003
244 #define ASF_METADATA_TYPE_QWORD  0x0004
245 #define ASF_METADATA_TYPE_WORD   0x0005
246
247 typedef struct
248 {
249     uint16_t    i_stream;
250     uint16_t    i_type;
251     char        *psz_name;
252
253     int64_t i_val;
254     int i_data;
255     uint8_t *p_data;
256
257 } asf_metadata_record_t;
258
259 typedef struct
260 {
261     ASF_OBJECT_COMMON
262
263     uint32_t i_record_entries_count;
264     asf_metadata_record_t *record;
265
266 } asf_object_metadata_t;
267
268 typedef struct
269 {
270     ASF_OBJECT_COMMON
271
272     char *psz_title;
273     char *psz_artist;
274     char *psz_copyright;
275     char *psz_description;
276     char *psz_rating;
277
278 } asf_object_content_description_t;
279
280 typedef struct
281 {
282     uint16_t i_length;
283     uint16_t *i_char;
284
285 } string16_t;
286
287 #define ASF_CODEC_TYPE_VIDEO    0x0001
288 #define ASF_CODEC_TYPE_AUDIO    0x0002
289 #define ASF_CODEC_TYPE_UNKNOW   0xffff
290
291 typedef struct
292 {
293     uint16_t    i_type;
294     char        *psz_name;
295     char        *psz_description;
296
297     uint16_t    i_information_length;
298     uint8_t     *p_information;
299 } asf_codec_entry_t;
300
301 typedef struct
302 {
303     ASF_OBJECT_COMMON
304     guid_t      i_reserved;
305     uint32_t    i_codec_entries_count;
306     asf_codec_entry_t *codec;
307
308 } asf_object_codec_list_t;
309
310 typedef struct
311 {
312     uint64_t     i_offset;
313     uint64_t     i_presentation_time;
314     uint16_t     i_entry_length;
315     uint32_t     i_send_time;
316     uint32_t     i_flags;
317     uint32_t     i_marker_description_length;
318     uint8_t      *i_marker_description;
319
320 } asf_marker_t;
321
322 typedef struct
323 {
324     ASF_OBJECT_COMMON
325     guid_t      i_reserved1;
326     uint32_t    i_count;
327     uint16_t    i_reserved2;
328     string16_t name;
329     asf_marker_t *marker;
330
331 } asf_object_marker_t;
332
333 typedef struct
334 {
335     ASF_OBJECT_COMMON
336     int  i_language;
337     char **ppsz_language;
338
339 } asf_object_language_list_t;
340
341 typedef struct
342 {
343     ASF_OBJECT_COMMON
344
345     int i_bitrate;
346     struct
347     {
348         int      i_stream_number;
349         uint32_t i_avg_bitrate;
350     } bitrate[128];
351 } asf_object_stream_bitrate_properties_t;
352
353 typedef struct
354 {
355     ASF_OBJECT_COMMON
356
357     int64_t i_start_time;
358     int64_t i_end_time;
359     int32_t i_data_bitrate;
360     int32_t i_buffer_size;
361     int32_t i_initial_buffer_fullness;
362     int32_t i_alternate_data_bitrate;
363     int32_t i_alternate_buffer_size;
364     int32_t i_alternate_initial_buffer_fullness;
365     int32_t i_maximum_object_size;
366
367     int32_t i_flags;
368     int16_t i_stream_number;
369     int16_t i_language_index;
370     int64_t i_average_time_per_frame;
371
372     int     i_stream_name_count;
373     int     i_payload_extension_system_count;
374
375     int     *pi_stream_name_language;
376     char    **ppsz_stream_name;
377
378     asf_object_stream_properties_t *p_sp;
379 } asf_object_extended_stream_properties_t;
380
381 typedef struct
382 {
383     ASF_OBJECT_COMMON
384
385     guid_t  type;
386     int16_t i_stream_number_count;
387     int16_t *pi_stream_number;
388
389 } asf_object_advanced_mutual_exclusion_t;
390
391 typedef struct
392 {
393     ASF_OBJECT_COMMON
394
395     int i_priority_count;
396     int *pi_priority_flag;
397     int *pi_priority_stream_number;
398 } asf_object_stream_prioritization_t;
399
400 typedef struct
401 {
402     ASF_OBJECT_COMMON
403
404     int i_count;
405     char **ppsz_name;
406     char **ppsz_value;
407 } asf_object_extended_content_description_t;
408
409 /****************************************************************************
410  * Special Root Object
411  ****************************************************************************/
412 typedef struct
413 {
414     ASF_OBJECT_COMMON
415
416     asf_object_header_t *p_hdr;
417     asf_object_data_t   *p_data;
418     /* could be NULL if !b_seekable or not-present */
419     asf_object_index_t  *p_index;
420
421     /* from asf_object_header_t */
422     asf_object_file_properties_t *p_fp;
423
424     /* from asf_object_header_extension_t */
425     asf_object_metadata_t *p_metadata;
426
427 } asf_object_root_t;
428
429 /****************************************************************************
430  * asf_object_t: union of all objects.
431  ****************************************************************************/
432 typedef union asf_object_u
433 {
434     asf_object_common_t common;
435     asf_object_header_t header;
436     asf_object_data_t   data;
437     asf_object_index_t  index;
438     asf_object_root_t   root;
439     asf_object_file_properties_t    file_properties;
440     asf_object_stream_properties_t  stream_properties;
441     asf_object_header_extension_t   header_extension;
442     asf_object_metadata_t           metadata;
443     asf_object_codec_list_t         codec_list;
444     asf_object_marker_t             marker;
445     asf_object_language_list_t      lang;
446     asf_object_stream_bitrate_properties_t stream_bitrate;
447     asf_object_extended_stream_properties_t ext_stream;
448
449 } asf_object_t;
450
451
452 void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data );
453 int  ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 );
454
455 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
456 void               ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root );
457
458 #define ASF_CountObject( a, b ) __ASF_CountObject( (asf_object_t*)(a), b )
459 int  __ASF_CountObject ( asf_object_t *p_obj, const guid_t *p_guid );
460
461 #define ASF_FindObject( a, b, c )  __ASF_FindObject( (asf_object_t*)(a), b, c )
462 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number );