]> git.sesse.net Git - vlc/blob - modules/demux/asf/libasf.h
demux: asf: split packet parsing for reuse
[vlc] / modules / demux / asf / libasf.h
1 /*****************************************************************************
2  * libasf.h :
3  *****************************************************************************
4  * Copyright © 2001-2004, 2011 VLC authors and VideoLAN
5  *
6  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22 #ifndef _VLC_LIBASF_H
23 #define _VLC_LIBASF_H
24
25 #define ASF_MAX_STREAMNUMBER 127
26
27 /*****************************************************************************
28  * Structure needed for decoder
29  *****************************************************************************/
30
31 #include "libasf_guid.h"
32
33 #define ASF_OBJECT_COMMON          \
34     int          i_type;           \
35     guid_t       i_object_id;      \
36     uint64_t     i_object_size;    \
37     uint64_t     i_object_pos;     \
38     union asf_object_u *p_father;  \
39     union asf_object_u *p_first;   \
40     union asf_object_u *p_last;    \
41     union asf_object_u *p_next;
42
43 typedef struct
44 {
45     ASF_OBJECT_COMMON
46
47 } asf_object_common_t;
48
49 typedef struct
50 {
51     uint32_t i_packet_number;
52     uint16_t i_packet_count;
53
54 } asf_index_entry_t;
55
56 /****************************************************************************
57  * High level asf object
58  ****************************************************************************/
59 /* This is the first header found in an asf file
60  * It's the only object that has subobjects */
61 typedef struct
62 {
63     ASF_OBJECT_COMMON
64     uint32_t i_sub_object_count;
65     uint8_t  i_reserved1; /* 0x01, but could be safely ignored */
66     uint8_t  i_reserved2; /* 0x02, if not must failed to source the contain */
67
68 } asf_object_header_t;
69
70 typedef struct
71 {
72     ASF_OBJECT_COMMON
73     guid_t      i_file_id;
74     uint64_t    i_total_data_packets;
75     uint16_t    i_reserved;
76
77 } asf_object_data_t;
78
79
80 typedef struct
81 {
82     ASF_OBJECT_COMMON
83     guid_t      i_file_id;
84     uint64_t    i_index_entry_time_interval;
85     uint32_t    i_max_packet_count;
86     uint32_t    i_index_entry_count;
87
88     asf_index_entry_t *index_entry;
89
90 } asf_object_index_t;
91
92 /****************************************************************************
93  * Sub level asf object
94  ****************************************************************************/
95 #define ASF_FILE_PROPERTIES_BROADCAST   0x01
96 #define ASF_FILE_PROPERTIES_SEEKABLE    0x02
97
98 typedef struct
99 {
100     ASF_OBJECT_COMMON
101
102     guid_t  i_file_id;
103     uint64_t     i_file_size;
104     uint64_t     i_creation_date;
105     uint64_t     i_data_packets_count;
106     uint64_t     i_play_duration;
107     uint64_t     i_send_duration;
108     uint64_t     i_preroll;
109     uint32_t     i_flags;
110     uint32_t     i_min_data_packet_size;
111     uint32_t     i_max_data_packet_size;
112     uint32_t     i_max_bitrate;
113
114 } asf_object_file_properties_t;
115
116 #define ASF_STREAM_PROPERTIES_ENCRYPTED 0x8000
117 typedef struct
118 {
119     ASF_OBJECT_COMMON
120
121     guid_t  i_stream_type;
122     guid_t  i_error_correction_type;
123     uint64_t     i_time_offset;
124     uint32_t     i_type_specific_data_length;
125     uint32_t     i_error_correction_data_length;
126     uint16_t     i_flags;
127         /* extrated from flags */
128         uint8_t i_stream_number;
129     uint32_t    i_reserved;
130     uint8_t     *p_type_specific_data;
131     uint8_t     *p_error_correction_data;
132 } asf_object_stream_properties_t;
133
134 typedef struct
135 {
136     ASF_OBJECT_COMMON
137
138     guid_t      i_reserved1;
139     uint16_t    i_reserved2;
140     uint32_t    i_header_extension_size;
141     uint8_t     *p_header_extension_data;
142
143 } asf_object_header_extension_t;
144
145 enum {
146     ASF_METADATA_TYPE_STRING,
147     ASF_METADATA_TYPE_BYTE,
148     ASF_METADATA_TYPE_BOOL,
149     ASF_METADATA_TYPE_DWORD,
150     ASF_METADATA_TYPE_QWORD,
151     ASF_METADATA_TYPE_WORD,
152 };
153
154 typedef struct
155 {
156     uint16_t    i_stream;
157     uint16_t    i_type;
158     char        *psz_name;
159
160     uint64_t i_val;
161     uint16_t i_data;
162     uint8_t *p_data;
163
164 } asf_metadata_record_t;
165
166 typedef struct
167 {
168     ASF_OBJECT_COMMON
169
170     uint32_t i_record_entries_count;
171     asf_metadata_record_t *record;
172
173 } asf_object_metadata_t;
174
175 typedef struct
176 {
177     ASF_OBJECT_COMMON
178
179     char *psz_title;
180     char *psz_artist;
181     char *psz_copyright;
182     char *psz_description;
183     char *psz_rating;
184
185 } asf_object_content_description_t;
186
187 #define ASF_CODEC_TYPE_VIDEO    0x0001
188 #define ASF_CODEC_TYPE_AUDIO    0x0002
189 #define ASF_CODEC_TYPE_UNKNOWN  0xffff
190
191 typedef struct
192 {
193     uint16_t    i_type;
194     char        *psz_name;
195     char        *psz_description;
196
197     uint16_t    i_information_length;
198     uint8_t     *p_information;
199 } asf_codec_entry_t;
200
201 typedef struct
202 {
203     ASF_OBJECT_COMMON
204     guid_t      i_reserved;
205     uint32_t    i_codec_entries_count;
206     asf_codec_entry_t *codec;
207
208 } asf_object_codec_list_t;
209
210 typedef struct
211 {
212     uint64_t     i_offset;
213     uint64_t     i_presentation_time;
214     uint16_t     i_entry_length;
215     uint32_t     i_send_time;
216     uint32_t     i_flags;
217     uint32_t     i_marker_description_length;
218     char         *p_marker_description;
219
220 } asf_marker_t;
221
222 typedef struct
223 {
224     ASF_OBJECT_COMMON
225     guid_t      i_reserved1;
226     uint32_t    i_count;
227     uint16_t    i_reserved2;
228     char        *name;
229     asf_marker_t *marker;
230
231 } asf_object_marker_t;
232
233 typedef struct
234 {
235     ASF_OBJECT_COMMON
236     uint16_t  i_language;
237     char **ppsz_language;
238
239 } asf_object_language_list_t;
240
241 typedef struct
242 {
243     ASF_OBJECT_COMMON
244
245     uint16_t i_bitrate;
246     struct
247     {
248         uint8_t  i_stream_number;
249         uint32_t i_avg_bitrate;
250     } bitrate[ASF_MAX_STREAMNUMBER + 1];
251 } asf_object_stream_bitrate_properties_t;
252
253
254 typedef struct
255 {
256     guid_t   i_extension_id;
257     uint16_t i_data_size;
258     uint32_t i_info_length;
259     char     *pi_info;
260 } asf_payload_extension_system_t;
261 #define ASF_EXTENSION_VIDEOFRAME_NEWFRAME  0x08
262 #define ASF_EXTENSION_VIDEOFRAME_IFRAME    0x01
263 #define ASF_EXTENSION_VIDEOFRAME_TYPE_MASK 0x07
264
265 typedef struct
266 {
267     ASF_OBJECT_COMMON
268
269     uint64_t i_start_time;
270     uint64_t i_end_time;
271     uint32_t i_data_bitrate;
272     uint32_t i_buffer_size;
273     uint32_t i_initial_buffer_fullness;
274     uint32_t i_alternate_data_bitrate;
275     uint32_t i_alternate_buffer_size;
276     uint32_t i_alternate_initial_buffer_fullness;
277     uint32_t i_maximum_object_size;
278
279     uint32_t i_flags;
280     uint16_t i_stream_number;
281     uint16_t i_language_index;
282     uint64_t i_average_time_per_frame;
283
284     uint16_t i_stream_name_count;
285
286     uint16_t i_payload_extension_system_count;
287     asf_payload_extension_system_t *p_ext;
288
289     uint16_t *pi_stream_name_language;
290     char    **ppsz_stream_name;
291
292     asf_object_stream_properties_t *p_sp;
293 } asf_object_extended_stream_properties_t;
294
295 #define ASF_MAX_EXCLUSION_TYPE 2
296 typedef enum
297 {
298     LANGUAGE = ASF_MAX_EXCLUSION_TYPE,
299     BITRATE = 1,
300     UNKNOWN = 0
301 } asf_exclusion_type_t;
302
303 typedef struct
304 {
305     ASF_OBJECT_COMMON
306
307     asf_exclusion_type_t exclusion_type;
308     uint16_t i_stream_number_count;
309     uint16_t *pi_stream_number;
310
311 } asf_object_advanced_mutual_exclusion_t;
312
313 typedef struct
314 {
315     ASF_OBJECT_COMMON
316
317     uint16_t i_priority_count;
318     uint16_t *pi_priority_flag;
319     uint16_t *pi_priority_stream_number;
320 } asf_object_stream_prioritization_t;
321
322 typedef struct
323 {
324     ASF_OBJECT_COMMON
325
326     asf_exclusion_type_t exclusion_type;
327     uint16_t i_stream_number_count;
328     uint16_t *pi_stream_numbers;
329 } asf_object_bitrate_mutual_exclusion_t;
330
331 typedef struct
332 {
333     ASF_OBJECT_COMMON
334
335     uint16_t i_count;
336     char **ppsz_name;
337     char **ppsz_value;
338 } asf_object_extended_content_description_t;
339
340 /****************************************************************************
341  * Special Root Object
342  ****************************************************************************/
343 typedef struct
344 {
345     ASF_OBJECT_COMMON
346
347     asf_object_header_t *p_hdr;
348     asf_object_data_t   *p_data;
349     /* could be NULL if !b_seekable or not-present */
350     asf_object_index_t  *p_index;
351
352     /* from asf_object_header_t */
353     asf_object_file_properties_t *p_fp;
354
355     /* from asf_object_header_extension_t */
356     asf_object_metadata_t *p_metadata;
357
358 } asf_object_root_t;
359
360 /****************************************************************************
361  * asf_object_t: union of all objects.
362  ****************************************************************************/
363 typedef union asf_object_u
364 {
365     asf_object_common_t common;
366     asf_object_header_t header;
367     asf_object_data_t   data;
368     asf_object_index_t  index;
369     asf_object_root_t   root;
370     asf_object_file_properties_t    file_properties;
371     asf_object_stream_properties_t  stream_properties;
372     asf_object_header_extension_t   header_extension;
373     asf_object_metadata_t           metadata;
374     asf_object_codec_list_t         codec_list;
375     asf_object_marker_t             marker;
376     asf_object_language_list_t      language_list;
377     asf_object_stream_bitrate_properties_t stream_bitrate;
378     asf_object_extended_stream_properties_t ext_stream;
379     asf_object_content_description_t content_description;
380     asf_object_advanced_mutual_exclusion_t advanced_mutual_exclusion;
381     asf_object_stream_prioritization_t stream_prioritization;
382     asf_object_bitrate_mutual_exclusion_t bitrate_mutual_exclusion;
383     asf_object_extended_content_description_t extended_content_description;
384
385 } asf_object_t;
386
387 asf_object_root_t *ASF_ReadObjectRoot( stream_t *, int b_seekable );
388 void               ASF_FreeObjectRoot( stream_t *, asf_object_root_t *p_root );
389
390 int ASF_CountObject ( void *p_obj, const guid_t *p_guid );
391
392 void *ASF_FindObject( void *p_obj, const guid_t *p_guid, int i_number );
393 #endif