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