5b9e6a5bc9e681aeaf1ddc1d58fcdab14941ecba
[vlc.git] / modules / demux / asf / libasf.h
1 /*****************************************************************************
2  * libasf.h :
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: libasf.h,v 1.6 2003/08/17 23:42:37 fenrir 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 typedef struct asf_object_root_s
215 {
216     ASF_OBJECT_COMMON
217
218     asf_object_header_t *p_hdr;
219     asf_object_data_t   *p_data;
220     asf_object_index_t  *p_index;
221
222 } asf_object_root_t;
223
224 /****************************************************************************
225  * Sub level asf object
226  ****************************************************************************/
227 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
228 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
229
230 typedef struct asf_object_file_properties_s
231 {
232     ASF_OBJECT_COMMON
233
234     guid_t  i_file_id;
235     uint64_t     i_file_size;
236     uint64_t     i_creation_date;
237     uint64_t     i_data_packets_count;
238     uint64_t     i_play_duration;
239     uint64_t     i_send_duration;
240     uint64_t     i_preroll;
241     uint32_t     i_flags;
242     uint32_t     i_min_data_packet_size;
243     uint32_t     i_max_data_packet_size;
244     uint32_t     i_max_bitrate;
245
246 } asf_object_file_properties_t;
247
248 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
249 typedef struct asf_object_stream_properties_s
250 {
251     ASF_OBJECT_COMMON
252
253     guid_t  i_stream_type;
254     guid_t  i_error_correction_type;
255     uint64_t     i_time_offset;
256     uint32_t     i_type_specific_data_length;
257     uint32_t     i_error_correction_data_length;
258     uint16_t     i_flags;
259         /* extrated from flags */
260         uint8_t i_stream_number;
261     uint32_t    i_reserved;
262     uint8_t     *p_type_specific_data;
263     uint8_t     *p_error_correction_data;
264 } asf_object_stream_properties_t;
265
266 typedef struct asf_object_header_extention_s
267 {
268     ASF_OBJECT_COMMON
269
270     guid_t      i_reserved1;
271     uint16_t    i_reserved2;
272     uint32_t    i_header_extention_size;
273     uint8_t     *p_header_extention_data;
274
275 } asf_object_header_extention_t;
276
277 typedef struct asf_objec_content_description_s
278 {
279     ASF_OBJECT_COMMON
280
281     char *psz_title;
282     char *psz_author;
283     char *psz_copyright;
284     char *psz_description;
285     char *psz_rating;
286
287 } asf_object_content_description_t;
288
289 typedef struct string16_s
290 {
291     uint16_t i_length;
292     uint16_t *i_char;
293 } string16_t;
294
295 #define ASF_CODEC_TYPE_VIDEO    0x0001
296 #define ASF_CODEC_TYPE_AUDIO    0x0002
297 #define ASF_CODEC_TYPE_UNKNOW   0xffff
298
299 typedef struct asf_codec_entry_s
300 {
301     uint16_t    i_type;
302     char        *psz_name;
303     char        *psz_description;
304
305     uint16_t    i_information_length;
306     uint8_t     *p_information;
307 } asf_codec_entry_t;
308
309 typedef struct asf_object_codec_list_s
310 {
311     ASF_OBJECT_COMMON
312     guid_t      i_reserved;
313     uint32_t    i_codec_entries_count;
314     asf_codec_entry_t *codec;
315
316 } asf_object_codec_list_t;
317
318 typedef struct asf_marker_s
319 {
320     uint64_t     i_offset;
321     uint64_t     i_presentation_time;
322     uint16_t     i_entry_length;
323     uint32_t     i_send_time;
324     uint32_t     i_flags;
325     uint32_t     i_marker_description_length;
326     uint8_t      *i_marker_description;
327
328 } asf_marker_t;
329
330 typedef struct asf_object_marker_s
331 {
332     ASF_OBJECT_COMMON
333     guid_t      i_reserved1;
334     uint32_t    i_count;
335     uint16_t    i_reserved2;
336     string16_t name;
337     asf_marker_t *marker;
338
339 } asf_object_marker_t;
340
341 typedef union asf_object_u
342 {
343     asf_object_common_t common;
344     asf_object_header_t header;
345     asf_object_data_t   data;
346     asf_object_index_t  index;
347     asf_object_root_t   root;
348     asf_object_file_properties_t    file_properties;
349     asf_object_stream_properties_t  stream_properties;
350     asf_object_header_extention_t   header_extention;
351     asf_object_codec_list_t         codec_list;
352     asf_object_marker_t             marker;
353
354 } asf_object_t;
355
356
357 off_t   ASF_TellAbsolute( input_thread_t *p_input );
358 int     ASF_SeekAbsolute( input_thread_t *p_input, off_t i_pos);
359 int     ASF_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size );
360 int     ASF_SkipBytes( input_thread_t *p_input, int i_count );
361
362 void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data );
363 int  ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 );
364
365 int  ASF_ReadObjectCommon( input_thread_t *p_input,
366                            asf_object_t *p_obj );
367 int  ASF_NextObject( input_thread_t *p_input,
368                      asf_object_t *p_obj );
369 int  ASF_GotoObject( input_thread_t *p_input,
370                      asf_object_t *p_obj );
371
372 int  ASF_ReadObject( input_thread_t *p_input,
373                      asf_object_t *p_obj,
374                      asf_object_t *p_father );
375 void ASF_FreeObject( input_thread_t *p_input,
376                      asf_object_t *p_obj );
377 int  ASF_ReadObjectRoot( input_thread_t *p_input,
378                          asf_object_root_t *p_root,
379                          int b_seekable );
380 void ASF_FreeObjectRoot( input_thread_t *p_input,
381                          asf_object_root_t *p_root );
382 #define ASF_CountObject( a, b ) __ASF_CountObject( (asf_object_t*)(a), b )
383 int  __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid );
384
385 #define ASF_FindObject( a, b, c )  __ASF_FindObject( (asf_object_t*)(a), b, c )
386 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number );
387
388