]> git.sesse.net Git - vlc/blob - modules/demux/asf/libasf.h
* Stringreview !!!
[vlc] / modules / demux / asf / libasf.h
1 /*****************************************************************************
2  * libasf.h :
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
5  * $Id: libasf.h,v 1.8 2004/01/25 20:05:28 hartman Exp $
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 #define ASF_OBJECT_TYPE_NULL      0x0000
36 #define ASF_OBJECT_TYPE_ROOT      0x0001
37 #define ASF_OBJECT_TYPE_HEADER    0x0002
38 #define ASF_OBJECT_TYPE_DATA      0x0003
39 #define ASF_OBJECT_TYPE_INDEX     0x0004
40 #define ASF_OBJECT_TYPE_FILE_PROPERTIES     0x0005
41 #define ASF_OBJECT_TYPE_STREAM_PROPERTIES   0x0006
42 #define ASF_OBJECT_TYPE_EXTENTION_HEADER    0x0007
43 #define ASF_OBJECT_TYPE_CODEC_LIST          0x0008
44 #define ASF_OBJECT_TYPE_MARKER              0x0009
45 #define ASF_OBJECT_TYPE_CONTENT_DESCRIPTION 0x000a
46
47 static const guid_t asf_object_null_guid =
48 {
49     0x00000000,
50     0x0000,
51     0x0000,
52     { 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00 }
53 };
54
55 static const guid_t asf_object_header_guid =
56 {
57     0x75B22630,
58     0x668E,
59     0x11CF,
60     { 0xA6,0xD9, 0x00,0xAA,0x00,0x62,0xCE,0x6C }
61 };
62
63 static const guid_t asf_object_data_guid =
64 {
65     0x75B22636,
66     0x668E,
67     0x11CF,
68     { 0xA6,0xD9, 0x00,0xAA,0x00,0x62,0xCE,0x6C }
69 };
70
71
72
73 static const guid_t asf_object_index_guid =
74 {
75     0x33000890,
76     0xE5B1,
77     0x11CF,
78     { 0x89,0xF4, 0x00,0xA0,0xC9,0x03,0x49,0xCB }
79 };
80
81 static const guid_t asf_object_file_properties_guid =
82 {
83     0x8cabdca1,
84     0xa947,
85     0x11cf,
86     { 0x8e,0xe4, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
87
88 };
89 static const guid_t asf_object_stream_properties_guid =
90 {
91     0xB7DC0791,
92     0xA9B7,
93     0x11CF,
94     { 0x8E,0xE6, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
95
96 };
97
98 static const guid_t asf_object_content_description_guid =
99 {
100     0x75B22633,
101     0x668E,
102     0x11CF,
103     { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c }
104 };
105
106 static const guid_t asf_object_header_extention_guid =
107 {
108    0x5FBF03B5,
109    0xA92E,
110    0x11CF,
111    { 0x8E,0xE3, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
112 };
113
114 static const guid_t asf_object_codec_list_guid =
115 {
116     0x86D15240,
117     0x311D,
118     0x11D0,
119     { 0xA3,0xA4, 0x00,0xA0,0xC9,0x03,0x48,0xF6 }
120 };
121
122 static const guid_t asf_object_marker_guid =
123 {
124     0xF487CD01,
125     0xA951,
126     0x11CF,
127     { 0x8E,0xE6, 0x00,0xC0,0x0C,0x20,0x53,0x65 }
128
129 };
130
131 static const guid_t asf_object_stream_type_audio =
132 {
133     0xF8699E40,
134     0x5B4D,
135     0x11CF,
136     { 0xA8,0xFD, 0x00,0x80,0x5F,0x5C,0x44,0x2B }
137 };
138
139 static const guid_t asf_object_stream_type_video =
140 {
141     0xbc19efc0,
142     0x5B4D,
143     0x11CF,
144     { 0xA8,0xFD, 0x00,0x80,0x5F,0x5C,0x44,0x2B }
145 };
146
147 static const guid_t asf_object_stream_type_command =
148 {
149     0x59DACFC0,
150     0x59E6,
151     0x11D0,
152     { 0xA3,0xAC, 0x00,0xA0,0xC9,0x03,0x48,0xF6 }
153 };
154
155 #define ASF_OBJECT_COMMON           \
156     int          i_type;            \
157     guid_t       i_object_id;       \
158     uint64_t     i_object_size;     \
159     uint64_t     i_object_pos;      \
160     union asf_object_u *p_father;  \
161     union asf_object_u *p_first;   \
162     union asf_object_u *p_last;    \
163     union asf_object_u *p_next;
164
165 typedef struct asf_object_common_s
166 {
167     ASF_OBJECT_COMMON
168
169 } asf_object_common_t;
170
171 typedef struct asf_index_entry_s
172 {
173     uint32_t i_packet_number;
174     uint16_t i_packet_count;
175
176 } asf_index_entry_t;
177
178 /****************************************************************************
179  * High level asf object
180  ****************************************************************************/
181 /* This is the first header find in a asf file
182  * It's the only object that have subobject */
183 typedef struct asf_object_header_s
184 {
185     ASF_OBJECT_COMMON
186     uint32_t i_sub_object_count;
187     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
188     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
189
190 } asf_object_header_t;
191
192 typedef struct asf_object_data_s
193 {
194     ASF_OBJECT_COMMON
195     guid_t      i_file_id;
196     uint64_t    i_total_data_packets;
197     uint16_t    i_reserved;
198
199 } asf_object_data_t;
200
201
202 typedef struct asf_object_index_s
203 {
204     ASF_OBJECT_COMMON
205     guid_t      i_file_id;
206     uint64_t    i_index_entry_time_interval;
207     uint32_t    i_max_packet_count;
208     uint32_t    i_index_entry_count;
209
210     asf_index_entry_t *index_entry;
211
212 } asf_object_index_t;
213
214 /****************************************************************************
215  * Sub level asf object
216  ****************************************************************************/
217 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
218 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
219
220 typedef struct asf_object_file_properties_s
221 {
222     ASF_OBJECT_COMMON
223
224     guid_t  i_file_id;
225     uint64_t     i_file_size;
226     uint64_t     i_creation_date;
227     uint64_t     i_data_packets_count;
228     uint64_t     i_play_duration;
229     uint64_t     i_send_duration;
230     uint64_t     i_preroll;
231     uint32_t     i_flags;
232     uint32_t     i_min_data_packet_size;
233     uint32_t     i_max_data_packet_size;
234     uint32_t     i_max_bitrate;
235
236 } asf_object_file_properties_t;
237
238 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
239 typedef struct asf_object_stream_properties_s
240 {
241     ASF_OBJECT_COMMON
242
243     guid_t  i_stream_type;
244     guid_t  i_error_correction_type;
245     uint64_t     i_time_offset;
246     uint32_t     i_type_specific_data_length;
247     uint32_t     i_error_correction_data_length;
248     uint16_t     i_flags;
249         /* extrated from flags */
250         uint8_t i_stream_number;
251     uint32_t    i_reserved;
252     uint8_t     *p_type_specific_data;
253     uint8_t     *p_error_correction_data;
254 } asf_object_stream_properties_t;
255
256 typedef struct asf_object_header_extention_s
257 {
258     ASF_OBJECT_COMMON
259
260     guid_t      i_reserved1;
261     uint16_t    i_reserved2;
262     uint32_t    i_header_extention_size;
263     uint8_t     *p_header_extention_data;
264
265 } asf_object_header_extention_t;
266
267 typedef struct asf_objec_content_description_s
268 {
269     ASF_OBJECT_COMMON
270
271     char *psz_title;
272     char *psz_author;
273     char *psz_copyright;
274     char *psz_description;
275     char *psz_rating;
276
277 } asf_object_content_description_t;
278
279 typedef struct string16_s
280 {
281     uint16_t i_length;
282     uint16_t *i_char;
283 } string16_t;
284
285 #define ASF_CODEC_TYPE_VIDEO    0x0001
286 #define ASF_CODEC_TYPE_AUDIO    0x0002
287 #define ASF_CODEC_TYPE_UNKNOW   0xffff
288
289 typedef struct asf_codec_entry_s
290 {
291     uint16_t    i_type;
292     char        *psz_name;
293     char        *psz_description;
294
295     uint16_t    i_information_length;
296     uint8_t     *p_information;
297 } asf_codec_entry_t;
298
299 typedef struct asf_object_codec_list_s
300 {
301     ASF_OBJECT_COMMON
302     guid_t      i_reserved;
303     uint32_t    i_codec_entries_count;
304     asf_codec_entry_t *codec;
305
306 } asf_object_codec_list_t;
307
308 typedef struct asf_marker_s
309 {
310     uint64_t     i_offset;
311     uint64_t     i_presentation_time;
312     uint16_t     i_entry_length;
313     uint32_t     i_send_time;
314     uint32_t     i_flags;
315     uint32_t     i_marker_description_length;
316     uint8_t      *i_marker_description;
317
318 } asf_marker_t;
319
320 typedef struct asf_object_marker_s
321 {
322     ASF_OBJECT_COMMON
323     guid_t      i_reserved1;
324     uint32_t    i_count;
325     uint16_t    i_reserved2;
326     string16_t name;
327     asf_marker_t *marker;
328
329 } asf_object_marker_t;
330
331 /****************************************************************************
332  * Special Root Object
333  ****************************************************************************/
334 typedef struct asf_object_root_s
335 {
336     ASF_OBJECT_COMMON
337
338     asf_object_header_t *p_hdr;
339     asf_object_data_t   *p_data;
340     /* could be NULL if !b_seekable or not-present */
341     asf_object_index_t  *p_index;
342
343     /* from asf_object_header_t */
344     asf_object_file_properties_t *p_fp;
345     
346 } asf_object_root_t;
347
348 /****************************************************************************
349  * asf_object_t: union of all objects.
350  ****************************************************************************/
351 typedef union asf_object_u
352 {
353     asf_object_common_t common;
354     asf_object_header_t header;
355     asf_object_data_t   data;
356     asf_object_index_t  index;
357     asf_object_root_t   root;
358     asf_object_file_properties_t    file_properties;
359     asf_object_stream_properties_t  stream_properties;
360     asf_object_header_extention_t   header_extention;
361     asf_object_codec_list_t         codec_list;
362     asf_object_marker_t             marker;
363
364 } asf_object_t;
365
366
367
368 void ASF_GetGUID         ( guid_t *p_guid, uint8_t *p_data );
369 int  ASF_CmpGUID         ( const guid_t *p_guid1, const guid_t *p_guid2 );
370
371 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
372 void               ASF_FreeObjectRoot  ( stream_t *, asf_object_root_t *p_root );
373
374 #define ASF_CountObject( a, b ) __ASF_CountObject( (asf_object_t*)(a), b )
375 int  __ASF_CountObject   ( asf_object_t *p_obj, const guid_t *p_guid );
376
377 #define ASF_FindObject( a, b, c )  __ASF_FindObject( (asf_object_t*)(a), b, c )
378 void *__ASF_FindObject   ( asf_object_t *p_obj, const guid_t *p_guid, int i_number );
379