1 /*****************************************************************************
2 * libasf.c : asf stream demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2003 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include <vlc_common.h>
32 #include <vlc_demux.h>
34 #include <vlc_codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
39 #define GUID_FMT "0x%x-0x%x-0x%x-0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x"
40 #define GUID_PRINT( guid ) \
44 (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
45 (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
48 * They ensure that invalid reads will not create problems.
49 * They are expansion safe
50 * They make the following assumptions:
51 * const uint8_t *p_peek exists and points to the start of a buffer
52 * int i_peek gives the size of the buffer pointed by p_peek
53 * const uint8_t *p_data exits and points to the data inside p_peek to be read.
56 * Check that n bytes can be read */
57 static inline bool AsfObjectHelperHave( const uint8_t *p_peek, int i_peek, const uint8_t *p_current, int i_wanted )
59 if( i_wanted < 0 || i_wanted > i_peek )
61 return &p_current[i_wanted] <= &p_peek[i_peek];
63 #define ASF_HAVE(n) AsfObjectHelperHave( p_peek, i_peek, p_data, n )
66 * Skip n bytes if possible */
67 static inline void AsfObjectHelperSkip( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_wanted )
69 if( AsfObjectHelperHave( p_peek, i_peek, *pp_data, i_wanted ) )
72 *pp_data = (uint8_t*)&p_peek[i_peek];
74 #define ASF_SKIP(n) AsfObjectHelperSkip( p_peek, i_peek, (uint8_t**)&p_data, n )
77 * Read X byte if possible, else return 0 */
78 #define ASF_FUNCTION_READ_X(type, x, cmd ) \
79 static inline type AsfObjectHelperRead##x( const uint8_t *p_peek, int i_peek, uint8_t **pp_data ) { \
80 uint8_t *p_data = *pp_data; \
87 ASF_FUNCTION_READ_X( uint8_t, 1, *p_data )
88 ASF_FUNCTION_READ_X( uint16_t, 2, GetWLE(p_data) )
89 ASF_FUNCTION_READ_X( uint32_t, 4, GetDWLE(p_data) )
90 ASF_FUNCTION_READ_X( uint64_t, 8, GetQWLE(p_data) )
91 #define ASF_READ1() AsfObjectHelperRead1( p_peek, i_peek, (uint8_t**)&p_data )
92 #define ASF_READ2() AsfObjectHelperRead2( p_peek, i_peek, (uint8_t**)&p_data )
93 #define ASF_READ4() AsfObjectHelperRead4( p_peek, i_peek, (uint8_t**)&p_data )
94 #define ASF_READ8() AsfObjectHelperRead8( p_peek, i_peek, (uint8_t**)&p_data )
97 * Read a string of n/2 wchar long ie n bytes. Do a stupid conversion (suppose latin1)
98 * Return allocated "" if not possible */
99 static char *AsfObjectHelperReadString( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_size )
101 uint8_t *p_data = *pp_data;
103 if( ASF_HAVE(i_size) )
105 psz_string = calloc( i_size/2 + 1, sizeof( char ) );
109 for( i = 0; i < i_size/2; i++ )
110 psz_string[i] = GetWLE( &p_data[2*i] );
111 psz_string[i_size/2] = '\0'; \
116 psz_string = strdup("");
122 #define ASF_READS(n) AsfObjectHelperReadString( p_peek, i_peek, (uint8_t**)&p_data, n )
124 /****************************************************************************
126 ****************************************************************************/
127 static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * );
129 /****************************************************************************
131 ****************************************************************************/
132 void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data )
134 p_guid->v1 = GetDWLE( p_data );
135 p_guid->v2 = GetWLE( p_data + 4);
136 p_guid->v3 = GetWLE( p_data + 6);
137 memcpy( p_guid->v4, p_data + 8, 8 );
140 bool ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
142 if( (p_guid1->v1 != p_guid2->v1 )||
143 (p_guid1->v2 != p_guid2->v2 )||
144 (p_guid1->v3 != p_guid2->v3 )||
145 ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
152 /****************************************************************************
154 ****************************************************************************/
155 static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
157 asf_object_common_t *p_common = &p_obj->common;
158 const uint8_t *p_peek;
160 if( stream_Peek( s, &p_peek, 24 ) < 24 )
163 ASF_GetGUID( &p_common->i_object_id, p_peek );
164 p_common->i_object_size = GetQWLE( p_peek + 16 );
165 p_common->i_object_pos = stream_Tell( s );
166 p_common->p_next = NULL;
170 "found object guid: " GUID_FMT " size:%"PRId64,
171 GUID_PRINT( p_common->i_object_id ),
172 p_common->i_object_size );
178 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
183 if( ASF_ReadObjectCommon( s, &obj ) )
189 if( p_obj->common.i_object_size <= 0 )
192 if( p_obj->common.p_father &&
193 p_obj->common.p_father->common.i_object_size != 0 )
195 if( p_obj->common.p_father->common.i_object_pos +
196 p_obj->common.p_father->common.i_object_size <
197 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
198 /* 24 is min size of an object */
205 return stream_Seek( s, p_obj->common.i_object_pos +
206 p_obj->common.i_object_size );
209 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
214 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
216 asf_object_header_t *p_hdr = &p_obj->header;
217 asf_object_t *p_subobj;
219 const uint8_t *p_peek;
221 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
224 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
225 p_hdr->i_reserved1 = p_peek[28];
226 p_hdr->i_reserved2 = p_peek[29];
227 p_hdr->p_first = NULL;
228 p_hdr->p_last = NULL;
232 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
233 p_hdr->i_sub_object_count,
235 p_hdr->i_reserved2 );
238 /* Cannot fail as peek succeed */
239 stream_Read( s, NULL, 30 );
241 /* Now load sub object */
244 p_subobj = malloc( sizeof( asf_object_t ) );
246 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
251 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
257 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
259 asf_object_data_t *p_data = &p_obj->data;
261 const uint8_t *p_peek;
263 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
266 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
267 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
268 p_data->i_reserved = GetWLE( p_peek + 48 );
272 "read \"data object\" file_id:" GUID_FMT " total data packet:"
273 "%"PRId64" reserved:%d",
274 GUID_PRINT( p_data->i_file_id ),
275 p_data->i_total_data_packets,
276 p_data->i_reserved );
282 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
284 asf_object_index_t *p_index = &p_obj->index;
285 const uint8_t *p_peek;
288 /* We just ignore error on the index */
289 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
290 __MAX( (int)p_index->i_object_size, 56 ) )
293 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
294 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
295 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
296 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
297 p_index->index_entry = NULL;
301 "read \"index object\" file_id:" GUID_FMT
302 " index_entry_time_interval:%"PRId64" max_packet_count:%d "
303 "index_entry_count:%ld",
304 GUID_PRINT( p_index->i_file_id ),
305 p_index->i_index_entry_time_interval,
306 p_index->i_max_packet_count,
307 (long int)p_index->i_index_entry_count );
310 /* Sanity checking */
311 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
312 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
314 p_index->index_entry = calloc( p_index->i_index_entry_count,
315 sizeof(asf_index_entry_t) );
317 for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
320 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
321 p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
327 static void ASF_FreeObject_Index( asf_object_t *p_obj )
329 asf_object_index_t *p_index = &p_obj->index;
331 FREENULL( p_index->index_entry );
334 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
336 asf_object_file_properties_t *p_fp = &p_obj->file_properties;
338 const uint8_t *p_peek;
340 if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 )
343 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
344 p_fp->i_file_size = GetQWLE( p_peek + 40 );
345 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
346 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
347 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
348 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
349 p_fp->i_preroll = GetQWLE( p_peek + 80 );
350 p_fp->i_flags = GetDWLE( p_peek + 88 );
351 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
352 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
353 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
357 "read \"file properties object\" file_id:" GUID_FMT
358 " file_size:%"PRId64" creation_date:%"PRId64" data_packets_count:"
359 "%"PRId64" play_duration:%"PRId64" send_duration:%"PRId64" preroll:%"PRId64
360 " flags:%d min_data_packet_size:%d "
361 " max_data_packet_size:%d max_bitrate:%d",
362 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
363 p_fp->i_creation_date, p_fp->i_data_packets_count,
364 p_fp->i_play_duration, p_fp->i_send_duration,
365 p_fp->i_preroll, p_fp->i_flags,
366 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
367 p_fp->i_max_bitrate );
373 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
375 asf_object_metadata_t *p_meta = &p_obj->metadata;
378 for( i = 0; i < p_meta->i_record_entries_count; i++ )
380 free( p_meta->record[i].psz_name );
381 free( p_meta->record[i].p_data );
383 free( p_meta->record );
386 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
388 asf_object_metadata_t *p_meta = &p_obj->metadata;
392 const uint8_t *p_peek, *p_data;
397 if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) <
398 __MAX( (int)p_meta->i_object_size, 26 ) )
401 p_meta->i_record_entries_count = GetWLE( p_peek + 24 );
403 p_data = p_peek + 26;
405 p_meta->record = calloc( p_meta->i_record_entries_count,
406 sizeof(asf_metadata_record_t) );
408 for( i = 0; i < p_meta->i_record_entries_count; i++ )
410 asf_metadata_record_t *p_record = &p_meta->record[i];
414 if( !ASF_HAVE( 2+2+2+2+4 ) )
417 if( ASF_READ2() != 0 )
420 p_record->i_stream = ASF_READ2();
421 i_name = ASF_READ2();
422 p_record->i_type = ASF_READ2();
423 i_data = ASF_READ4();
425 if( !ASF_HAVE( i_name + i_data ) )
429 p_record->psz_name = ASF_READS( i_name );
432 if( p_record->i_type == ASF_METADATA_TYPE_STRING )
434 p_record->p_data = ASF_READS( i_data );
435 p_record->i_data = i_data/2; /* FIXME Is that needed ? */
437 else if( p_record->i_type == ASF_METADATA_TYPE_BYTE )
439 p_record->p_data = malloc( i_data );
440 p_record->i_data = i_data;
442 memcpy( p_record->p_data, p_data, i_data );
446 else if( p_record->i_type == ASF_METADATA_TYPE_QWORD )
448 p_record->i_val = ASF_READ8();
450 else if( p_record->i_type == ASF_METADATA_TYPE_DWORD )
452 p_record->i_val = ASF_READ4();
454 else if( p_record->i_type == ASF_METADATA_TYPE_WORD )
456 p_record->i_val = ASF_READ2();
458 else if( p_record->i_type == ASF_METADATA_TYPE_BOOL )
460 p_record->i_val = ASF_READ2();
468 p_meta->i_record_entries_count = i;
472 "read \"metadata object\" %d entries",
473 p_meta->i_record_entries_count );
474 for( j = 0; j < p_meta->i_record_entries_count; j++ )
476 asf_metadata_record_t *p_rec = &p_meta->record[j];
478 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
479 msg_Dbg( s, " - %s=%s",
480 p_rec->psz_name, p_rec->p_data );
481 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
482 msg_Dbg( s, " - %s (%i bytes)",
483 p_rec->psz_name, p_rec->i_data );
485 msg_Dbg( s, " - %s=%"PRId64,
486 p_rec->psz_name, p_rec->i_val );
493 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
495 asf_object_header_extension_t *p_he = &p_obj->header_extension;
497 const uint8_t *p_peek;
499 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
503 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
504 p_he->i_reserved2 = GetWLE( p_peek + 40 );
505 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
506 if( p_he->i_header_extension_size )
508 if( i_peek-46 < (int)p_he->i_header_extension_size )
511 p_he->p_header_extension_data =
512 malloc( p_he->i_header_extension_size );
513 if( !p_he->p_header_extension_data )
516 memcpy( p_he->p_header_extension_data, p_peek + 46,
517 p_he->i_header_extension_size );
521 p_he->p_header_extension_data = NULL;
526 "read \"header extension object\" reserved1:" GUID_FMT
527 " reserved2:%d header_extension_size:%d",
528 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
529 p_he->i_header_extension_size );
532 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
534 /* Read the extension objects */
535 stream_Read( s, NULL, 46 );
538 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
540 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
546 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
555 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
557 asf_object_header_extension_t *p_he = &p_obj->header_extension;
559 FREENULL( p_he->p_header_extension_data );
562 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
564 asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
566 const uint8_t *p_peek;
568 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
571 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
572 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
573 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
574 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
575 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
576 p_sp->i_flags = GetWLE( p_peek + 72 );
577 p_sp->i_stream_number = p_sp->i_flags&0x07f;
578 p_sp->i_reserved = GetDWLE( p_peek + 74 );
581 if( p_sp->i_type_specific_data_length )
583 if( i_peek < p_sp->i_type_specific_data_length )
586 p_sp->p_type_specific_data =
587 malloc( p_sp->i_type_specific_data_length );
588 if( p_sp->p_type_specific_data == NULL )
591 memcpy( p_sp->p_type_specific_data, p_peek + 78,
592 p_sp->i_type_specific_data_length );
593 i_peek -= p_sp->i_type_specific_data_length;
597 p_sp->p_type_specific_data = NULL;
600 if( p_sp->i_error_correction_data_length )
602 if( i_peek < p_sp->i_error_correction_data_length )
604 free( p_sp->p_type_specific_data );
608 p_sp->p_error_correction_data =
609 malloc( p_sp->i_error_correction_data_length );
610 if( p_sp->p_error_correction_data == NULL )
612 free( p_sp->p_type_specific_data );
615 memcpy( p_sp->p_error_correction_data,
616 p_peek + 78 + p_sp->i_type_specific_data_length,
617 p_sp->i_error_correction_data_length );
621 p_sp->p_error_correction_data = NULL;
626 "read \"stream Properties object\" stream_type:" GUID_FMT
627 " error_correction_type:" GUID_FMT " time_offset:%"PRId64
628 " type_specific_data_length:%d error_correction_data_length:%d"
629 " flags:0x%x stream_number:%d",
630 GUID_PRINT( p_sp->i_stream_type ),
631 GUID_PRINT( p_sp->i_error_correction_type ),
633 p_sp->i_type_specific_data_length,
634 p_sp->i_error_correction_data_length,
636 p_sp->i_stream_number );
642 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
644 asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
646 FREENULL( p_sp->p_type_specific_data );
647 FREENULL( p_sp->p_error_correction_data );
651 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
653 asf_object_codec_list_t *p_cl = &p_obj->codec_list;
655 const uint8_t *p_peek, *p_data;
657 unsigned int i_codec;
659 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
662 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
663 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
665 p_data = p_peek + 44;
667 if( p_cl->i_codec_entries_count > 0 )
669 p_cl->codec = calloc( p_cl->i_codec_entries_count,
670 sizeof( asf_codec_entry_t ) );
674 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
676 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
678 if( !ASF_HAVE( 2+2+2 ) )
682 p_codec->i_type = ASF_READ2();
684 /* XXX the length here are the number of *unicode* characters and
685 * not of bytes like nearly every elsewhere */
688 p_codec->psz_name = ASF_READS( 2*ASF_READ2() );
691 p_codec->psz_description = ASF_READS( 2*ASF_READ2() );
693 /* opaque information */
694 p_codec->i_information_length = ASF_READ2();
695 if( p_codec->i_information_length > 0 && ASF_HAVE( p_codec->i_information_length ) )
697 p_codec->p_information = malloc( p_codec->i_information_length );
698 memcpy( p_codec->p_information, p_data, p_codec->i_information_length );
699 p_data += p_codec->i_information_length;
703 p_codec->p_information = NULL;
706 p_cl->i_codec_entries_count = i_codec;
710 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
711 " codec_entries_count:%d",
712 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
714 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
716 const asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
718 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
719 "description:\"%s\" information_length:%d",
720 i_codec, ( p_codec->i_type == ASF_CODEC_TYPE_VIDEO ) ?
721 "video" : ( ( p_codec->i_type == ASF_CODEC_TYPE_AUDIO ) ?
722 "audio" : "unknown" ),
723 p_codec->psz_name, p_codec->psz_description,
724 p_codec->i_information_length );
731 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
733 asf_object_codec_list_t *p_cl = &p_obj->codec_list;
734 unsigned int i_codec;
736 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
738 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
740 FREENULL( p_codec->psz_name );
741 FREENULL( p_codec->psz_description );
742 FREENULL( p_codec->p_information );
744 FREENULL( p_cl->codec );
747 /* Microsoft should go to hell. This time the length give number of bytes
748 * and for the some others object, length give char16 count ... */
749 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
751 asf_object_content_description_t *p_cd = &p_obj->content_description;
752 const uint8_t *p_peek, *p_data;
753 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
754 vlc_iconv_t cd = (vlc_iconv_t)-1;
755 const char *ib = NULL;
757 size_t i_ibl, i_obl, i_len;
759 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
762 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
763 if( cd == (vlc_iconv_t)-1 )
765 msg_Err( s, "vlc_iconv_open failed" );
769 /* FIXME i_size*3 is the worst case. */
770 #define GETSTRINGW( psz_str, i_size ) \
771 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
772 ib = (const char *)p_data; \
776 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
779 p_data = p_peek + 24;
781 i_title = ASF_READ2();
782 i_artist = ASF_READ2();
783 i_copyright = ASF_READ2();
784 i_description = ASF_READ2();
785 i_rating = ASF_READ2();
787 if( !ASF_HAVE( i_title+i_artist+i_copyright+i_description+i_rating ) )
789 vlc_iconv_close( cd );
793 GETSTRINGW( p_cd->psz_title, i_title );
794 GETSTRINGW( p_cd->psz_artist, i_artist );
795 GETSTRINGW( p_cd->psz_copyright, i_copyright );
796 GETSTRINGW( p_cd->psz_description, i_description );
797 GETSTRINGW( p_cd->psz_rating, i_rating );
803 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
807 p_cd->psz_description,
815 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
817 asf_object_content_description_t *p_cd = &p_obj->content_description;
819 FREENULL( p_cd->psz_title );
820 FREENULL( p_cd->psz_artist );
821 FREENULL( p_cd->psz_copyright );
822 FREENULL( p_cd->psz_description );
823 FREENULL( p_cd->psz_rating );
827 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
829 asf_object_language_list_t *p_ll = &p_obj->language_list;
830 const uint8_t *p_peek, *p_data;
834 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
837 p_data = &p_peek[24];
839 p_ll->i_language = ASF_READ2();
840 if( p_ll->i_language > 0 )
842 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
844 for( i = 0; i < p_ll->i_language; i++ )
848 p_ll->ppsz_language[i] = ASF_READS( ASF_READ1() );
850 p_ll->i_language = i;
854 msg_Dbg( s, "read \"language list object\" %d entries",
856 for( i = 0; i < p_ll->i_language; i++ )
857 msg_Dbg( s, " - '%s'",
858 p_ll->ppsz_language[i] );
863 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
865 asf_object_language_list_t *p_ll = &p_obj->language_list;
868 for( i = 0; i < p_ll->i_language; i++ )
869 FREENULL( p_ll->ppsz_language[i] );
870 FREENULL( p_ll->ppsz_language );
873 /* Stream bitrate properties */
874 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
877 asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate;
878 const uint8_t *p_peek, *p_data;
882 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
885 p_data = &p_peek[24];
887 p_sb->i_bitrate = ASF_READ2();
888 if( p_sb->i_bitrate > 127 )
889 p_sb->i_bitrate = 127; /* Buggy ? */
890 for( i = 0; i < p_sb->i_bitrate; i++ )
892 if( !ASF_HAVE(2 + 4) )
894 p_sb->bitrate[i].i_stream_number = ASF_READ2()& 0x7f;
895 p_sb->bitrate[i].i_avg_bitrate = ASF_READ4();
900 msg_Dbg( s,"read \"stream bitrate properties object\"" );
901 for( i = 0; i < p_sb->i_bitrate; i++ )
903 msg_Dbg( s," - stream=%d bitrate=%d",
904 p_sb->bitrate[i].i_stream_number,
905 p_sb->bitrate[i].i_avg_bitrate );
910 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
915 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
918 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
919 const uint8_t *p_peek, *p_data;
922 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
925 p_data = &p_peek[24];
927 p_esp->i_start_time = GetQWLE( &p_data[0] );
928 p_esp->i_end_time = GetQWLE( &p_data[8] );
929 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
930 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
931 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
932 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
933 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
934 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
935 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
936 p_esp->i_flags = GetDWLE( &p_data[44] );
937 p_esp->i_stream_number = GetWLE( &p_data[48] );
938 p_esp->i_language_index = GetWLE( &p_data[50] );
939 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
940 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
941 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
945 p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count,
947 p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
949 for( i = 0; i < p_esp->i_stream_name_count; i++ )
951 if( !ASF_HAVE( 2+2 ) )
953 p_esp->pi_stream_name_language[i] = ASF_READ2();
954 p_esp->ppsz_stream_name[i] = ASF_READS( ASF_READ2() );
956 p_esp->i_stream_name_count = i;
958 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
960 ASF_SKIP( 16 ); // GUID
962 ASF_SKIP( ASF_READ4() );
966 if( p_data < &p_peek[i_peek] )
969 /* Cannot fail as peek succeed */
970 stream_Read( s, NULL, p_data - p_peek );
972 p_sp = malloc( sizeof( asf_object_t ) );
974 if( ASF_ReadObject( s, p_sp, NULL ) )
980 /* This p_sp will be inserted by ReadRoot later */
981 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
986 msg_Dbg( s, "read \"extended stream properties object\":" );
987 msg_Dbg( s, " - start=%"PRId64" end=%"PRId64,
988 p_esp->i_start_time, p_esp->i_end_time );
989 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
990 p_esp->i_data_bitrate,
991 p_esp->i_buffer_size,
992 p_esp->i_initial_buffer_fullness );
993 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
994 p_esp->i_alternate_data_bitrate,
995 p_esp->i_alternate_buffer_size,
996 p_esp->i_alternate_initial_buffer_fullness );
997 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
998 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
999 msg_Dbg( s, " - stream number=%d language=%d",
1000 p_esp->i_stream_number, p_esp->i_language_index );
1001 msg_Dbg( s, " - average time per frame=%"PRId64,
1002 p_esp->i_average_time_per_frame );
1003 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
1004 for( i = 0; i < p_esp->i_stream_name_count; i++ )
1005 msg_Dbg( s, " - lang id=%d name=%s",
1006 p_esp->pi_stream_name_language[i],
1007 p_esp->ppsz_stream_name[i] );
1008 msg_Dbg( s, " - payload extension system count=%d",
1009 p_esp->i_payload_extension_system_count );
1013 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
1015 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
1018 for( i = 0; i < p_esp->i_stream_name_count; i++ )
1019 FREENULL( p_esp->ppsz_stream_name[i] );
1020 FREENULL( p_esp->pi_stream_name_language );
1021 FREENULL( p_esp->ppsz_stream_name );
1025 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
1026 asf_object_t *p_obj)
1028 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
1029 const uint8_t *p_peek, *p_data;
1033 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1034 return VLC_EGENERIC;
1036 p_data = &p_peek[24];
1038 ASF_GetGUID( &p_ae->type, &p_data[0] );
1040 p_ae->i_stream_number_count = ASF_READ2();
1041 p_ae->pi_stream_number = calloc( p_ae->i_stream_number_count, sizeof(int) );
1043 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1047 p_ae->pi_stream_number[i] = ASF_READ2();
1049 p_ae->i_stream_number_count = i;
1052 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1053 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1054 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1058 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1060 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
1062 FREENULL( p_ae->pi_stream_number );
1066 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1067 asf_object_t *p_obj)
1069 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1070 const uint8_t *p_peek, *p_data;
1074 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1075 return VLC_EGENERIC;
1077 p_data = &p_peek[24];
1079 p_sp->i_priority_count = ASF_READ2();
1081 p_sp->pi_priority_flag = calloc( p_sp->i_priority_count, sizeof(int) );
1082 p_sp->pi_priority_stream_number =
1083 calloc( p_sp->i_priority_count, sizeof(int) );
1085 for( i = 0; i < p_sp->i_priority_count; i++ )
1087 if( !ASF_HAVE(2+2) )
1089 p_sp->pi_priority_stream_number[i] = ASF_READ2();
1090 p_sp->pi_priority_flag[i] = ASF_READ2();
1092 p_sp->i_priority_count = i;
1095 msg_Dbg( s, "read \"stream prioritization object\"" );
1096 for( i = 0; i < p_sp->i_priority_count; i++ )
1097 msg_Dbg( s, " - Stream:%d flags=0x%x",
1098 p_sp->pi_priority_stream_number[i],
1099 p_sp->pi_priority_flag[i] );
1103 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1105 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1107 FREENULL( p_sp->pi_priority_stream_number );
1108 FREENULL( p_sp->pi_priority_flag );
1112 static int ASF_ReadObject_extended_content_description( stream_t *s,
1113 asf_object_t *p_obj)
1115 asf_object_extended_content_description_t *p_ec =
1116 &p_obj->extended_content_description;
1117 const uint8_t *p_peek, *p_data;
1121 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1122 return VLC_EGENERIC;
1124 p_data = &p_peek[24];
1126 p_ec->i_count = ASF_READ2();
1127 p_ec->ppsz_name = calloc( p_ec->i_count, sizeof(char*) );
1128 p_ec->ppsz_value = calloc( p_ec->i_count, sizeof(char*) );
1129 if( !p_ec->ppsz_name || !p_ec->ppsz_value )
1131 free( p_ec->ppsz_name );
1132 free( p_ec->ppsz_value );
1135 for( i = 0; i < p_ec->i_count; i++ )
1140 if( !ASF_HAVE(2 + 2+2) )
1143 p_ec->ppsz_name[i] = ASF_READS( ASF_READ2() );
1146 i_type = ASF_READ2();
1147 i_size = ASF_READ2();
1151 p_ec->ppsz_value[i] = ASF_READS( i_size );
1153 else if( i_type == 1 )
1156 static const char hex[16] = "0123456789ABCDEF";
1159 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1160 for( j = 0; j < i_size; j++ )
1162 const uint8_t v = ASF_READ1();
1163 p_ec->ppsz_value[i][2*j+0] = hex[v>>4];
1164 p_ec->ppsz_value[i][2*j+1] = hex[v&0xf];
1166 p_ec->ppsz_value[i][2*i_size] = '\0';
1168 else if( i_type == 2 )
1171 p_ec->ppsz_value[i] = strdup( ASF_READ1() ? "true" : "false" );
1174 else if( i_type == 3 )
1177 asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() );
1179 else if( i_type == 4 )
1182 asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() );
1184 else if( i_type == 5 )
1187 asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() );
1191 p_ec->ppsz_value[i] = NULL;
1198 msg_Dbg( s, "read \"extended content description object\"" );
1199 for( i = 0; i < p_ec->i_count; i++ )
1200 msg_Dbg( s, " - '%s' = '%s'",
1202 p_ec->ppsz_value[i] );
1206 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1208 asf_object_extended_content_description_t *p_ec =
1209 &p_obj->extended_content_description;
1212 for( i = 0; i < p_ec->i_count; i++ )
1214 FREENULL( p_ec->ppsz_name[i] );
1215 FREENULL( p_ec->ppsz_value[i] );
1217 FREENULL( p_ec->ppsz_name );
1218 FREENULL( p_ec->ppsz_value );
1223 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1225 asf_object_XXX_t *p_XX =
1226 (asf_object_XXX_t *)p_obj;
1227 const uint8_t *p_peek;
1231 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1232 return VLC_EGENERIC;
1234 p_data = &p_peek[24];
1238 "Read \"XXX object\"" );
1242 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1244 asf_object_XXX_t *p_XX =
1245 (asf_object_XXX_t *)p_obj;
1255 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1256 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1258 } ASF_Object_Function [] =
1260 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1261 ASF_ReadObject_Header, ASF_FreeObject_Null },
1262 { &asf_object_data_guid, ASF_OBJECT_DATA,
1263 ASF_ReadObject_Data, ASF_FreeObject_Null },
1264 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1265 ASF_ReadObject_Index, ASF_FreeObject_Index },
1266 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1267 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1268 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1269 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1270 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1271 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1272 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1273 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1274 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1275 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1276 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1277 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1278 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1279 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1280 { &asf_object_language_list, ASF_OBJECT_OTHER,
1281 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1282 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1283 ASF_ReadObject_stream_bitrate_properties,
1284 ASF_FreeObject_stream_bitrate_properties },
1285 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1286 ASF_ReadObject_extended_stream_properties,
1287 ASF_FreeObject_extended_stream_properties },
1288 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1289 ASF_ReadObject_advanced_mutual_exclusion,
1290 ASF_FreeObject_advanced_mutual_exclusion },
1291 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1292 ASF_ReadObject_stream_prioritization,
1293 ASF_FreeObject_stream_prioritization },
1294 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1295 ASF_ReadObject_extended_content_description,
1296 ASF_FreeObject_extended_content_description },
1298 { &asf_object_null_guid, 0, NULL, NULL }
1301 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1302 asf_object_t *p_father )
1310 memset( p_obj, 0, sizeof( *p_obj ) );
1312 if( ASF_ReadObjectCommon( s, p_obj ) )
1314 msg_Warn( s, "cannot read one asf object" );
1315 return VLC_EGENERIC;
1317 p_obj->common.p_father = p_father;
1318 p_obj->common.p_first = NULL;
1319 p_obj->common.p_next = NULL;
1320 p_obj->common.p_last = NULL;
1322 if( p_obj->common.i_object_size < 24 )
1324 msg_Warn( s, "found a corrupted asf object (size<24)" );
1325 return VLC_EGENERIC;
1328 /* find this object */
1329 for( i_index = 0; ; i_index++ )
1331 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1332 &p_obj->common.i_object_id ) ||
1333 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1334 &asf_object_null_guid ) )
1339 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1341 /* Now load this object */
1342 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1344 msg_Warn( s, "unknown asf object (not loaded)" );
1345 i_result = VLC_SUCCESS;
1349 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1351 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1354 /* link this object with father */
1355 if( p_father && ! i_result )
1357 if( p_father->common.p_first )
1359 p_father->common.p_last->common.p_next = p_obj;
1363 p_father->common.p_first = p_obj;
1365 p_father->common.p_last = p_obj;
1371 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1374 asf_object_t *p_child;
1379 /* Free all child object */
1380 p_child = p_obj->common.p_first;
1383 asf_object_t *p_next;
1384 p_next = p_child->common.p_next;
1385 ASF_FreeObject( s, p_child );
1389 /* find this object */
1390 for( i_index = 0; ; i_index++ )
1392 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1393 &p_obj->common.i_object_id )||
1394 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1395 &asf_object_null_guid ) )
1401 /* Now free this object */
1402 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1405 "unknown asf object " GUID_FMT,
1406 GUID_PRINT( p_obj->common.i_object_id ) );
1412 "free asf object " GUID_FMT,
1413 GUID_PRINT( p_obj->common.i_object_id ) );
1415 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1420 /*****************************************************************************
1421 * ASF_ObjectDumpDebug:
1422 *****************************************************************************/
1426 const char *psz_name;
1427 } ASF_ObjectDumpDebugInfo[] =
1429 { &asf_object_header_guid, "Header" },
1430 { &asf_object_data_guid, "Data" },
1431 { &asf_object_index_guid, "Index" },
1432 { &asf_object_file_properties_guid, "File Properties" },
1433 { &asf_object_stream_properties_guid, "Stream Properties" },
1434 { &asf_object_content_description_guid, "Content Description" },
1435 { &asf_object_header_extension_guid, "Header Extension" },
1436 { &asf_object_metadata_guid, "Metadata" },
1437 { &asf_object_codec_list_guid, "Codec List" },
1438 { &asf_object_marker_guid, "Marker" },
1439 { &asf_object_stream_type_audio, "Stream Type Audio" },
1440 { &asf_object_stream_type_video, "Stream Type Video" },
1441 { &asf_object_stream_type_command, "Stream Type Command" },
1442 { &asf_object_language_list, "Language List" },
1443 { &asf_object_stream_bitrate_properties, "Stream Bitrate Properties" },
1444 { &asf_object_padding, "Padding" },
1445 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1446 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1447 { &asf_object_stream_prioritization, "Stream Prioritization" },
1448 { &asf_object_extended_content_description, "Extended content description"},
1450 { NULL, "Unknown" },
1454 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1455 asf_object_common_t *p_node, int i_level )
1459 union asf_object_u *p_child;
1460 const char *psz_name;
1463 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1465 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1466 &p_node->i_object_id ) )
1469 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1471 memset( str, ' ', sizeof( str ) );
1472 for( i = 1; i < i_level; i++ )
1476 snprintf( str + 5*i_level, 1024,
1477 "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64,
1479 GUID_PRINT( p_node->i_object_id ),
1480 p_node->i_object_size, p_node->i_object_pos );
1482 msg_Dbg( p_obj, "%s", str );
1484 for( p_child = p_node->p_first; p_child != NULL;
1485 p_child = p_child->common.p_next )
1487 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1491 /*****************************************************************************
1492 * ASF_ReadObjetRoot : parse the entire stream/file
1493 *****************************************************************************/
1494 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1496 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1497 asf_object_t *p_obj;
1499 p_root->i_type = ASF_OBJECT_ROOT;
1500 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1501 p_root->i_object_pos = stream_Tell( s );
1502 p_root->i_object_size = 0;
1503 p_root->p_first = NULL;
1504 p_root->p_last = NULL;
1505 p_root->p_next = NULL;
1506 p_root->p_hdr = NULL;
1507 p_root->p_data = NULL;
1508 p_root->p_fp = NULL;
1509 p_root->p_index = NULL;
1510 p_root->p_metadata = NULL;
1514 p_obj = malloc( sizeof( asf_object_t ) );
1516 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1521 switch( p_obj->common.i_type )
1523 case( ASF_OBJECT_HEADER ):
1524 p_root->p_hdr = (asf_object_header_t*)p_obj;
1526 case( ASF_OBJECT_DATA ):
1527 p_root->p_data = (asf_object_data_t*)p_obj;
1529 case( ASF_OBJECT_INDEX ):
1530 p_root->p_index = (asf_object_index_t*)p_obj;
1533 msg_Warn( s, "unknow object found" );
1536 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1537 p_obj->common.i_object_size <= 50 )
1539 /* probably a dump of broadcasted asf */
1542 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1544 /* For unseekable stream it's enough to play */
1548 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1552 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1554 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1555 &asf_object_file_properties_guid, 0 );
1559 asf_object_t *p_hdr_ext =
1560 ASF_FindObject( p_root->p_hdr,
1561 &asf_object_header_extension_guid, 0 );
1567 p_root->p_metadata =
1568 ASF_FindObject( p_hdr_ext,
1569 &asf_object_metadata_guid, 0 );
1570 /* Special case for broken designed file format :( */
1571 i_ext_stream = ASF_CountObject( p_hdr_ext,
1572 &asf_object_extended_stream_properties );
1573 for( i = 0; i < i_ext_stream; i++ )
1575 asf_object_t *p_esp =
1576 ASF_FindObject( p_hdr_ext,
1577 &asf_object_extended_stream_properties, i );
1578 if( p_esp->ext_stream.p_sp )
1580 asf_object_t *p_sp =
1581 (asf_object_t*)p_esp->ext_stream.p_sp;
1583 /* Insert this p_sp */
1584 p_root->p_hdr->p_last->common.p_next = p_sp;
1585 p_root->p_hdr->p_last = p_sp;
1587 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1592 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1593 (asf_object_common_t*)p_root, 0 );
1596 msg_Warn( s, "cannot find file properties object" );
1600 ASF_FreeObjectRoot( s, p_root );
1604 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1606 asf_object_t *p_obj;
1608 p_obj = p_root->p_first;
1611 asf_object_t *p_next;
1612 p_next = p_obj->common.p_next;
1613 ASF_FreeObject( s, p_obj );
1619 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1622 asf_object_t *p_child;
1628 p_child = p_obj->common.p_first;
1631 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1634 p_child = p_child->common.p_next;
1639 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1642 asf_object_t *p_child;
1644 p_child = p_obj->common.p_first;
1648 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1655 p_child = p_child->common.p_next;