1 /*****************************************************************************
2 * libasf.c : asf stream demux module for vlc
3 *****************************************************************************
4 * Copyright © 2001-2004, 2006-2008 the VideoLAN team
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 * Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <vlc_demux.h>
29 #include <vlc_charset.h> /* FromCharset */
36 * They ensure that invalid reads will not create problems.
37 * They are expansion safe
38 * They make the following assumptions:
39 * const uint8_t *p_peek exists and points to the start of a buffer
40 * int i_peek gives the size of the buffer pointed by p_peek
41 * const uint8_t *p_data exits and points to the data inside p_peek to be read.
44 * Check that n bytes can be read */
45 static inline bool AsfObjectHelperHave( const uint8_t *p_peek, int i_peek, const uint8_t *p_current, int i_wanted )
47 if( i_wanted < 0 || i_wanted > i_peek )
49 return &p_current[i_wanted] <= &p_peek[i_peek];
51 #define ASF_HAVE(n) AsfObjectHelperHave( p_peek, i_peek, p_data, n )
54 * Skip n bytes if possible */
55 static inline void AsfObjectHelperSkip( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_wanted )
57 if( AsfObjectHelperHave( p_peek, i_peek, *pp_data, i_wanted ) )
60 *pp_data = (uint8_t*)&p_peek[i_peek];
62 #define ASF_SKIP(n) AsfObjectHelperSkip( p_peek, i_peek, (uint8_t**)&p_data, n )
65 * Read X byte if possible, else return 0 */
66 #define ASF_FUNCTION_READ_X(type, x, cmd ) \
67 static inline type AsfObjectHelperRead##x( const uint8_t *p_peek, int i_peek, uint8_t **pp_data ) { \
68 uint8_t *p_data = *pp_data; \
75 ASF_FUNCTION_READ_X( uint8_t, 1, *p_data )
76 ASF_FUNCTION_READ_X( uint16_t, 2, GetWLE(p_data) )
77 ASF_FUNCTION_READ_X( uint32_t, 4, GetDWLE(p_data) )
78 ASF_FUNCTION_READ_X( uint64_t, 8, GetQWLE(p_data) )
79 #define ASF_READ1() AsfObjectHelperRead1( p_peek, i_peek, (uint8_t**)&p_data )
80 #define ASF_READ2() AsfObjectHelperRead2( p_peek, i_peek, (uint8_t**)&p_data )
81 #define ASF_READ4() AsfObjectHelperRead4( p_peek, i_peek, (uint8_t**)&p_data )
82 #define ASF_READ8() AsfObjectHelperRead8( p_peek, i_peek, (uint8_t**)&p_data )
85 * Read a string of n/2 wchar long ie n bytes. Do a stupid conversion (suppose latin1)
86 * Return allocated "" if not possible */
87 static char *AsfObjectHelperReadString( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_size )
89 uint8_t *p_data = *pp_data;
91 if( ASF_HAVE(i_size) )
93 psz_string = calloc( i_size/2 + 1, sizeof( char ) );
97 for( i = 0; i < i_size/2; i++ )
98 psz_string[i] = GetWLE( &p_data[2*i] );
99 psz_string[i_size/2] = '\0';
104 psz_string = strdup("");
110 #define ASF_READS(n) AsfObjectHelperReadString( p_peek, i_peek, (uint8_t**)&p_data, n )
112 /****************************************************************************
114 ****************************************************************************/
115 static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * );
117 /****************************************************************************
119 ****************************************************************************/
120 static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
122 asf_object_common_t *p_common = &p_obj->common;
123 const uint8_t *p_peek;
125 if( stream_Peek( s, &p_peek, 24 ) < 24 )
128 ASF_GetGUID( &p_common->i_object_id, p_peek );
129 p_common->i_object_size = GetQWLE( p_peek + 16 );
130 p_common->i_object_pos = stream_Tell( s );
131 p_common->p_next = NULL;
135 "found object guid: " GUID_FMT " size:%"PRId64,
136 GUID_PRINT( p_common->i_object_id ),
137 p_common->i_object_size );
143 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
148 if( ASF_ReadObjectCommon( s, &obj ) )
154 if( p_obj->common.i_object_size <= 0 )
157 if( p_obj->common.p_father &&
158 p_obj->common.p_father->common.i_object_size != 0 )
160 if( p_obj->common.p_father->common.i_object_pos +
161 p_obj->common.p_father->common.i_object_size <
162 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
163 /* 24 is min size of an object */
170 return stream_Seek( s, p_obj->common.i_object_pos +
171 p_obj->common.i_object_size );
174 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
179 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
181 asf_object_header_t *p_hdr = &p_obj->header;
182 asf_object_t *p_subobj;
183 const uint8_t *p_peek;
185 if( stream_Peek( s, &p_peek, 30 ) < 30 )
188 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
189 p_hdr->i_reserved1 = p_peek[28];
190 p_hdr->i_reserved2 = p_peek[29];
191 p_hdr->p_first = NULL;
192 p_hdr->p_last = NULL;
196 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
197 p_hdr->i_sub_object_count,
199 p_hdr->i_reserved2 );
202 /* Cannot fail as peek succeed */
203 stream_Read( s, NULL, 30 );
205 /* Now load sub object */
208 p_subobj = malloc( sizeof( asf_object_t ) );
210 if( !p_subobj || ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
215 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
221 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
223 asf_object_data_t *p_data = &p_obj->data;
224 const uint8_t *p_peek;
226 if( stream_Peek( s, &p_peek, 50 ) < 50 )
229 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
230 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
231 p_data->i_reserved = GetWLE( p_peek + 48 );
235 "read \"data object\" file_id:" GUID_FMT " total data packet:"
236 "%"PRId64" reserved:%d",
237 GUID_PRINT( p_data->i_file_id ),
238 p_data->i_total_data_packets,
239 p_data->i_reserved );
245 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
247 asf_object_index_t *p_index = &p_obj->index;
248 const uint8_t *p_peek;
251 /* We just ignore error on the index */
252 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
253 __MAX( (int64_t)p_index->i_object_size, 56 ) )
256 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
257 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
258 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
259 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
260 p_index->index_entry = NULL;
264 "read \"index object\" file_id:" GUID_FMT
265 " index_entry_time_interval:%"PRId64" max_packet_count:%d "
266 "index_entry_count:%ld",
267 GUID_PRINT( p_index->i_file_id ),
268 p_index->i_index_entry_time_interval,
269 p_index->i_max_packet_count,
270 (long int)p_index->i_index_entry_count );
273 /* Sanity checking */
274 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
275 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
277 p_index->index_entry = calloc( p_index->i_index_entry_count,
278 sizeof(asf_index_entry_t) );
279 if( !p_index->index_entry )
282 for( i = 0, p_peek += 56; i < p_index->i_index_entry_count; i++, p_peek += 6 )
284 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
285 p_index->index_entry[i].i_packet_count = GetWLE( p_peek + 4 );
291 static void ASF_FreeObject_Index( asf_object_t *p_obj )
293 asf_object_index_t *p_index = &p_obj->index;
295 FREENULL( p_index->index_entry );
298 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
300 asf_object_file_properties_t *p_fp = &p_obj->file_properties;
301 const uint8_t *p_peek;
303 if( stream_Peek( s, &p_peek, 104 ) < 104 )
306 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
307 p_fp->i_file_size = GetQWLE( p_peek + 40 );
308 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
309 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
310 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
311 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
312 p_fp->i_preroll = GetQWLE( p_peek + 80 );
313 p_fp->i_flags = GetDWLE( p_peek + 88 );
314 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
315 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
316 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
320 "read \"file properties object\" file_id:" GUID_FMT
321 " file_size:%"PRId64" creation_date:%"PRId64" data_packets_count:"
322 "%"PRId64" play_duration:%"PRId64" send_duration:%"PRId64" preroll:%"PRId64
323 " flags:%d min_data_packet_size:%d "
324 " max_data_packet_size:%d max_bitrate:%d",
325 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
326 p_fp->i_creation_date, p_fp->i_data_packets_count,
327 p_fp->i_play_duration, p_fp->i_send_duration,
328 p_fp->i_preroll, p_fp->i_flags,
329 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
330 p_fp->i_max_bitrate );
336 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
338 asf_object_metadata_t *p_meta = &p_obj->metadata;
341 for( i = 0; i < p_meta->i_record_entries_count; i++ )
343 free( p_meta->record[i].psz_name );
344 free( p_meta->record[i].p_data );
346 free( p_meta->record );
349 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
351 asf_object_metadata_t *p_meta = &p_obj->metadata;
355 const uint8_t *p_peek, *p_data;
360 if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) <
361 __MAX( (int64_t)p_meta->i_object_size, 26 ) )
364 p_meta->i_record_entries_count = GetWLE( p_peek + 24 );
366 p_data = p_peek + 26;
368 p_meta->record = calloc( p_meta->i_record_entries_count,
369 sizeof(asf_metadata_record_t) );
370 if( !p_meta->record )
373 for( i = 0; i < p_meta->i_record_entries_count; i++ )
375 asf_metadata_record_t *p_record = &p_meta->record[i];
379 if( !ASF_HAVE( 2+2+2+2+4 ) )
382 if( ASF_READ2() != 0 )
385 p_record->i_stream = ASF_READ2();
386 i_name = ASF_READ2();
387 p_record->i_type = ASF_READ2();
388 i_data = ASF_READ4();
390 if( !ASF_HAVE( i_name + i_data ) )
394 p_record->psz_name = ASF_READS( i_name );
397 if( p_record->i_type == ASF_METADATA_TYPE_STRING )
399 p_record->p_data = (uint8_t *)ASF_READS( i_data );
400 p_record->i_data = i_data/2; /* FIXME Is that needed ? */
402 else if( p_record->i_type == ASF_METADATA_TYPE_BYTE )
404 p_record->p_data = malloc( i_data );
405 p_record->i_data = i_data;
406 if( p_record->p_data && i_data > 0 )
407 memcpy( p_record->p_data, p_data, i_data );
411 else if( p_record->i_type == ASF_METADATA_TYPE_QWORD )
413 p_record->i_val = ASF_READ8();
415 else if( p_record->i_type == ASF_METADATA_TYPE_DWORD )
417 p_record->i_val = ASF_READ4();
419 else if( p_record->i_type == ASF_METADATA_TYPE_WORD )
421 p_record->i_val = ASF_READ2();
423 else if( p_record->i_type == ASF_METADATA_TYPE_BOOL )
425 p_record->i_val = ASF_READ2();
433 p_meta->i_record_entries_count = i;
437 "read \"metadata object\" %d entries",
438 p_meta->i_record_entries_count );
439 for( j = 0; j < p_meta->i_record_entries_count; j++ )
441 asf_metadata_record_t *p_rec = &p_meta->record[j];
443 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
444 msg_Dbg( s, " - %s=%s",
445 p_rec->psz_name, p_rec->p_data );
446 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
447 msg_Dbg( s, " - %s (%i bytes)",
448 p_rec->psz_name, p_rec->i_data );
450 msg_Dbg( s, " - %s=%"PRId64,
451 p_rec->psz_name, p_rec->i_val );
458 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
460 asf_object_header_extension_t *p_he = &p_obj->header_extension;
462 const uint8_t *p_peek;
464 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
468 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
469 p_he->i_reserved2 = GetWLE( p_peek + 40 );
470 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
471 if( p_he->i_header_extension_size )
473 if( (unsigned int)(i_peek-46) < p_he->i_header_extension_size )
476 p_he->p_header_extension_data =
477 malloc( p_he->i_header_extension_size );
478 if( !p_he->p_header_extension_data )
481 memcpy( p_he->p_header_extension_data, p_peek + 46,
482 p_he->i_header_extension_size );
486 p_he->p_header_extension_data = NULL;
491 "read \"header extension object\" reserved1:" GUID_FMT
492 " reserved2:%d header_extension_size:%d",
493 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
494 p_he->i_header_extension_size );
497 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
499 /* Read the extension objects */
500 stream_Read( s, NULL, 46 );
503 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
505 if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
511 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
520 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
522 asf_object_header_extension_t *p_he = &p_obj->header_extension;
524 FREENULL( p_he->p_header_extension_data );
527 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
529 asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
531 const uint8_t *p_peek;
533 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
536 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
537 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
538 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
539 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
540 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
541 p_sp->i_flags = GetWLE( p_peek + 72 );
542 p_sp->i_stream_number = p_sp->i_flags&0x07f;
543 p_sp->i_reserved = GetDWLE( p_peek + 74 );
546 if( p_sp->i_type_specific_data_length )
548 if( i_peek < p_sp->i_type_specific_data_length )
551 p_sp->p_type_specific_data =
552 malloc( p_sp->i_type_specific_data_length );
553 if( !p_sp->p_type_specific_data )
556 memcpy( p_sp->p_type_specific_data, p_peek + 78,
557 p_sp->i_type_specific_data_length );
558 i_peek -= p_sp->i_type_specific_data_length;
561 if( p_sp->i_error_correction_data_length )
563 if( i_peek < p_sp->i_error_correction_data_length )
565 free( p_sp->p_type_specific_data );
569 p_sp->p_error_correction_data =
570 malloc( p_sp->i_error_correction_data_length );
571 if( !p_sp->p_error_correction_data )
573 free( p_sp->p_type_specific_data );
576 memcpy( p_sp->p_error_correction_data,
577 p_peek + 78 + p_sp->i_type_specific_data_length,
578 p_sp->i_error_correction_data_length );
583 "read \"stream Properties object\" stream_type:" GUID_FMT
584 " error_correction_type:" GUID_FMT " time_offset:%"PRId64
585 " type_specific_data_length:%d error_correction_data_length:%d"
586 " flags:0x%x stream_number:%d",
587 GUID_PRINT( p_sp->i_stream_type ),
588 GUID_PRINT( p_sp->i_error_correction_type ),
590 p_sp->i_type_specific_data_length,
591 p_sp->i_error_correction_data_length,
593 p_sp->i_stream_number );
599 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
601 asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
603 FREENULL( p_sp->p_type_specific_data );
604 FREENULL( p_sp->p_error_correction_data );
608 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
610 asf_object_codec_list_t *p_cl = &p_obj->codec_list;
612 const uint8_t *p_peek, *p_data;
614 unsigned int i_codec;
616 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
619 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
620 p_cl->i_codec_entries_count = GetDWLE( p_peek + 40 );
622 p_data = p_peek + 44;
624 if( p_cl->i_codec_entries_count > 0 )
626 p_cl->codec = calloc( p_cl->i_codec_entries_count,
627 sizeof( asf_codec_entry_t ) );
631 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
633 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
635 if( !ASF_HAVE( 2+2+2 ) )
639 p_codec->i_type = ASF_READ2();
641 /* XXX the length here are the number of *unicode* characters and
642 * not of bytes like nearly every elsewhere */
645 p_codec->psz_name = ASF_READS( 2*ASF_READ2() );
648 p_codec->psz_description = ASF_READS( 2*ASF_READ2() );
650 /* opaque information */
651 p_codec->i_information_length = ASF_READ2();
652 if( p_codec->i_information_length > 0 && ASF_HAVE( p_codec->i_information_length ) )
654 p_codec->p_information = malloc( p_codec->i_information_length );
655 if( p_codec->p_information )
656 memcpy( p_codec->p_information, p_data, p_codec->i_information_length );
658 p_codec->i_information_length = 0;
659 p_data += p_codec->i_information_length;
662 p_cl->i_codec_entries_count = i_codec;
666 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
667 " codec_entries_count:%d",
668 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
670 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
672 const asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
674 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
675 "description:\"%s\" information_length:%d",
676 i_codec, ( p_codec->i_type == ASF_CODEC_TYPE_VIDEO ) ?
677 "video" : ( ( p_codec->i_type == ASF_CODEC_TYPE_AUDIO ) ?
678 "audio" : "unknown" ),
679 p_codec->psz_name, p_codec->psz_description,
680 p_codec->i_information_length );
687 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
689 asf_object_codec_list_t *p_cl = &p_obj->codec_list;
690 unsigned int i_codec;
692 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
694 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
696 FREENULL( p_codec->psz_name );
697 FREENULL( p_codec->psz_description );
698 FREENULL( p_codec->p_information );
700 FREENULL( p_cl->codec );
703 /* Microsoft should go to hell. This time the length give number of bytes
704 * and for the some others object, length give char16 count ... */
705 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
707 asf_object_content_description_t *p_cd = &p_obj->content_description;
708 const uint8_t *p_peek, *p_data;
709 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
711 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
714 /* FIXME i_size*3 is the worst case. */
715 #define GETSTRINGW( psz_str, i_size ) do { \
716 psz_str = FromCharset( "UTF-16LE", p_data, i_size ); \
721 p_data = p_peek + 24;
723 i_title = ASF_READ2();
724 i_artist = ASF_READ2();
725 i_copyright = ASF_READ2();
726 i_description = ASF_READ2();
727 i_rating = ASF_READ2();
729 if( !ASF_HAVE( i_title+i_artist+i_copyright+i_description+i_rating ) )
732 GETSTRINGW( p_cd->psz_title, i_title );
733 GETSTRINGW( p_cd->psz_artist, i_artist );
734 GETSTRINGW( p_cd->psz_copyright, i_copyright );
735 GETSTRINGW( p_cd->psz_description, i_description );
736 GETSTRINGW( p_cd->psz_rating, i_rating );
742 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
746 p_cd->psz_description,
753 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
755 asf_object_content_description_t *p_cd = &p_obj->content_description;
757 FREENULL( p_cd->psz_title );
758 FREENULL( p_cd->psz_artist );
759 FREENULL( p_cd->psz_copyright );
760 FREENULL( p_cd->psz_description );
761 FREENULL( p_cd->psz_rating );
765 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
767 asf_object_language_list_t *p_ll = &p_obj->language_list;
768 const uint8_t *p_peek, *p_data;
772 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
775 p_data = &p_peek[24];
777 p_ll->i_language = ASF_READ2();
778 if( p_ll->i_language > 0 )
780 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
781 if( !p_ll->ppsz_language )
784 for( i = 0; i < p_ll->i_language; i++ )
788 p_ll->ppsz_language[i] = ASF_READS( ASF_READ1() );
790 p_ll->i_language = i;
794 msg_Dbg( s, "read \"language list object\" %d entries",
796 for( i = 0; i < p_ll->i_language; i++ )
797 msg_Dbg( s, " - '%s'",
798 p_ll->ppsz_language[i] );
803 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
805 asf_object_language_list_t *p_ll = &p_obj->language_list;
808 for( i = 0; i < p_ll->i_language; i++ )
809 FREENULL( p_ll->ppsz_language[i] );
810 FREENULL( p_ll->ppsz_language );
813 /* Stream bitrate properties */
814 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
817 asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate;
818 const uint8_t *p_peek, *p_data;
822 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
825 p_data = &p_peek[24];
827 p_sb->i_bitrate = ASF_READ2();
828 if( p_sb->i_bitrate > 127 )
829 p_sb->i_bitrate = 127; /* Buggy ? */
830 for( i = 0; i < p_sb->i_bitrate; i++ )
832 if( !ASF_HAVE(2 + 4) )
834 p_sb->bitrate[i].i_stream_number = ASF_READ2()& 0x7f;
835 p_sb->bitrate[i].i_avg_bitrate = ASF_READ4();
840 msg_Dbg( s,"read \"stream bitrate properties object\"" );
841 for( i = 0; i < p_sb->i_bitrate; i++ )
843 msg_Dbg( s," - stream=%d bitrate=%d",
844 p_sb->bitrate[i].i_stream_number,
845 p_sb->bitrate[i].i_avg_bitrate );
850 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
855 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
858 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
859 const uint8_t *p_peek, *p_data;
862 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
865 p_data = &p_peek[24];
867 p_esp->i_start_time = GetQWLE( &p_data[0] );
868 p_esp->i_end_time = GetQWLE( &p_data[8] );
869 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
870 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
871 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
872 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
873 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
874 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
875 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
876 p_esp->i_flags = GetDWLE( &p_data[44] );
877 p_esp->i_stream_number = GetWLE( &p_data[48] );
878 p_esp->i_language_index = GetWLE( &p_data[50] );
879 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
880 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
881 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
885 p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count,
887 p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
889 if( !p_esp->pi_stream_name_language ||
890 !p_esp->ppsz_stream_name )
892 free( p_esp->pi_stream_name_language );
893 free( p_esp->ppsz_stream_name );
896 for( i = 0; i < p_esp->i_stream_name_count; i++ )
898 if( !ASF_HAVE( 2+2 ) )
900 p_esp->pi_stream_name_language[i] = ASF_READ2();
901 p_esp->ppsz_stream_name[i] = ASF_READS( ASF_READ2() );
903 p_esp->i_stream_name_count = i;
905 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
907 ASF_SKIP( 16 ); // GUID
909 ASF_SKIP( ASF_READ4() );
913 if( p_data < &p_peek[i_peek] )
916 /* Cannot fail as peek succeed */
917 stream_Read( s, NULL, p_data - p_peek );
919 p_sp = malloc( sizeof( asf_object_t ) );
921 if( !p_sp || ASF_ReadObject( s, p_sp, NULL ) )
927 /* This p_sp will be inserted by ReadRoot later */
928 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
933 msg_Dbg( s, "read \"extended stream properties object\":" );
934 msg_Dbg( s, " - start=%"PRId64" end=%"PRId64,
935 p_esp->i_start_time, p_esp->i_end_time );
936 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
937 p_esp->i_data_bitrate,
938 p_esp->i_buffer_size,
939 p_esp->i_initial_buffer_fullness );
940 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
941 p_esp->i_alternate_data_bitrate,
942 p_esp->i_alternate_buffer_size,
943 p_esp->i_alternate_initial_buffer_fullness );
944 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
945 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
946 msg_Dbg( s, " - stream number=%d language=%d",
947 p_esp->i_stream_number, p_esp->i_language_index );
948 msg_Dbg( s, " - average time per frame=%"PRId64,
949 p_esp->i_average_time_per_frame );
950 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
951 for( i = 0; i < p_esp->i_stream_name_count; i++ )
952 msg_Dbg( s, " - lang id=%d name=%s",
953 p_esp->pi_stream_name_language[i],
954 p_esp->ppsz_stream_name[i] );
955 msg_Dbg( s, " - payload extension system count=%d",
956 p_esp->i_payload_extension_system_count );
960 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
962 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
965 for( i = 0; i < p_esp->i_stream_name_count; i++ )
966 FREENULL( p_esp->ppsz_stream_name[i] );
967 FREENULL( p_esp->pi_stream_name_language );
968 FREENULL( p_esp->ppsz_stream_name );
972 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
975 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
976 const uint8_t *p_peek, *p_data;
980 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
983 p_data = &p_peek[24];
985 ASF_GetGUID( &p_ae->type, &p_data[0] );
987 p_ae->i_stream_number_count = ASF_READ2();
988 p_ae->pi_stream_number = calloc( p_ae->i_stream_number_count, sizeof(int) );
990 for( i = 0; i < p_ae->i_stream_number_count; i++ )
994 p_ae->pi_stream_number[i] = ASF_READ2();
996 p_ae->i_stream_number_count = i;
999 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1000 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1001 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1005 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1007 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
1009 FREENULL( p_ae->pi_stream_number );
1013 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1014 asf_object_t *p_obj)
1016 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1017 const uint8_t *p_peek, *p_data;
1021 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1022 return VLC_EGENERIC;
1024 p_data = &p_peek[24];
1026 p_sp->i_priority_count = ASF_READ2();
1028 p_sp->pi_priority_flag = calloc( p_sp->i_priority_count, sizeof(int) );
1029 p_sp->pi_priority_stream_number =
1030 calloc( p_sp->i_priority_count, sizeof(int) );
1032 if( !p_sp->pi_priority_flag || !p_sp->pi_priority_stream_number )
1034 free( p_sp->pi_priority_flag );
1035 free( p_sp->pi_priority_stream_number );
1039 for( i = 0; i < p_sp->i_priority_count; i++ )
1041 if( !ASF_HAVE(2+2) )
1043 p_sp->pi_priority_stream_number[i] = ASF_READ2();
1044 p_sp->pi_priority_flag[i] = ASF_READ2();
1046 p_sp->i_priority_count = i;
1049 msg_Dbg( s, "read \"stream prioritization object\"" );
1050 for( i = 0; i < p_sp->i_priority_count; i++ )
1051 msg_Dbg( s, " - Stream:%d flags=0x%x",
1052 p_sp->pi_priority_stream_number[i],
1053 p_sp->pi_priority_flag[i] );
1057 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1059 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1061 FREENULL( p_sp->pi_priority_stream_number );
1062 FREENULL( p_sp->pi_priority_flag );
1066 static int ASF_ReadObject_extended_content_description( stream_t *s,
1067 asf_object_t *p_obj)
1069 asf_object_extended_content_description_t *p_ec =
1070 &p_obj->extended_content_description;
1071 const uint8_t *p_peek, *p_data;
1075 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1076 return VLC_EGENERIC;
1078 p_data = &p_peek[24];
1080 p_ec->i_count = ASF_READ2();
1081 p_ec->ppsz_name = calloc( p_ec->i_count, sizeof(char*) );
1082 p_ec->ppsz_value = calloc( p_ec->i_count, sizeof(char*) );
1083 if( !p_ec->ppsz_name || !p_ec->ppsz_value )
1085 free( p_ec->ppsz_name );
1086 free( p_ec->ppsz_value );
1089 for( i = 0; i < p_ec->i_count; i++ )
1094 if( !ASF_HAVE(2 + 2+2) )
1097 p_ec->ppsz_name[i] = ASF_READS( ASF_READ2() );
1100 i_type = ASF_READ2();
1101 i_size = ASF_READ2();
1105 p_ec->ppsz_value[i] = ASF_READS( i_size );
1107 else if( i_type == 1 )
1110 static const char hex[16] = "0123456789ABCDEF";
1113 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1114 if( p_ec->ppsz_value[i] )
1116 char *psz_value = p_ec->ppsz_value[i];
1117 for( j = 0; j < i_size; j++ )
1119 const uint8_t v = ASF_READ1();
1120 psz_value[2*j+0] = hex[v>>4];
1121 psz_value[2*j+1] = hex[v&0xf];
1123 psz_value[2*i_size] = '\0';
1126 else if( i_type == 2 )
1129 p_ec->ppsz_value[i] = strdup( ASF_READ1() ? "true" : "false" );
1132 else if( i_type == 3 )
1135 if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() ) == -1 )
1136 p_ec->ppsz_value[i] = NULL;
1138 else if( i_type == 4 )
1141 if( asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() ) == -1 )
1142 p_ec->ppsz_value[i] = NULL;
1144 else if( i_type == 5 )
1147 if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() ) == -1 )
1148 p_ec->ppsz_value[i] = NULL;
1152 p_ec->ppsz_value[i] = NULL;
1159 msg_Dbg( s, "read \"extended content description object\"" );
1160 for( i = 0; i < p_ec->i_count; i++ )
1161 msg_Dbg( s, " - '%s' = '%s'",
1163 p_ec->ppsz_value[i] );
1167 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1169 asf_object_extended_content_description_t *p_ec =
1170 &p_obj->extended_content_description;
1173 for( i = 0; i < p_ec->i_count; i++ )
1175 FREENULL( p_ec->ppsz_name[i] );
1176 FREENULL( p_ec->ppsz_value[i] );
1178 FREENULL( p_ec->ppsz_name );
1179 FREENULL( p_ec->ppsz_value );
1184 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1186 asf_object_XXX_t *p_XX =
1187 (asf_object_XXX_t *)p_obj;
1188 const uint8_t *p_peek;
1192 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1193 return VLC_EGENERIC;
1195 p_data = &p_peek[24];
1199 "Read \"XXX object\"" );
1203 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1205 asf_object_XXX_t *p_XX =
1206 (asf_object_XXX_t *)p_obj;
1216 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1217 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1219 } ASF_Object_Function [] =
1221 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1222 ASF_ReadObject_Header, ASF_FreeObject_Null },
1223 { &asf_object_data_guid, ASF_OBJECT_DATA,
1224 ASF_ReadObject_Data, ASF_FreeObject_Null },
1225 { &asf_object_simple_index_guid, ASF_OBJECT_INDEX,
1226 ASF_ReadObject_Index, ASF_FreeObject_Index },
1227 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1228 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1229 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1230 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1231 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1232 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1233 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1234 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1235 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1236 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1237 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1238 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1239 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1240 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1241 { &asf_object_language_list, ASF_OBJECT_OTHER,
1242 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1243 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1244 ASF_ReadObject_stream_bitrate_properties,
1245 ASF_FreeObject_stream_bitrate_properties },
1246 { &asf_object_extended_stream_properties_guid, ASF_OBJECT_OTHER,
1247 ASF_ReadObject_extended_stream_properties,
1248 ASF_FreeObject_extended_stream_properties },
1249 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1250 ASF_ReadObject_advanced_mutual_exclusion,
1251 ASF_FreeObject_advanced_mutual_exclusion },
1252 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1253 ASF_ReadObject_stream_prioritization,
1254 ASF_FreeObject_stream_prioritization },
1255 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1256 ASF_ReadObject_extended_content_description,
1257 ASF_FreeObject_extended_content_description },
1259 { &asf_object_null_guid, 0, NULL, NULL }
1262 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1263 asf_object_t *p_father )
1271 memset( p_obj, 0, sizeof( *p_obj ) );
1273 if( ASF_ReadObjectCommon( s, p_obj ) )
1275 msg_Warn( s, "cannot read one asf object" );
1276 return VLC_EGENERIC;
1278 p_obj->common.p_father = p_father;
1279 p_obj->common.p_first = NULL;
1280 p_obj->common.p_next = NULL;
1281 p_obj->common.p_last = NULL;
1283 if( p_obj->common.i_object_size < 24 )
1285 msg_Warn( s, "found a corrupted asf object (size<24)" );
1286 return VLC_EGENERIC;
1289 /* find this object */
1290 for( i_index = 0; ; i_index++ )
1292 if( guidcmp( ASF_Object_Function[i_index].p_id,
1293 &p_obj->common.i_object_id ) ||
1294 guidcmp( ASF_Object_Function[i_index].p_id,
1295 &asf_object_null_guid ) )
1300 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1302 /* Now load this object */
1303 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1305 msg_Warn( s, "unknown asf object (not loaded)" );
1306 i_result = VLC_SUCCESS;
1310 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1312 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1315 /* link this object with father */
1316 if( p_father && ! i_result )
1318 if( p_father->common.p_first )
1320 p_father->common.p_last->common.p_next = p_obj;
1324 p_father->common.p_first = p_obj;
1326 p_father->common.p_last = p_obj;
1332 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1335 asf_object_t *p_child;
1340 /* Free all child object */
1341 p_child = p_obj->common.p_first;
1344 asf_object_t *p_next;
1345 p_next = p_child->common.p_next;
1346 ASF_FreeObject( s, p_child );
1350 /* find this object */
1351 for( i_index = 0; ; i_index++ )
1353 if( guidcmp( ASF_Object_Function[i_index].p_id,
1354 &p_obj->common.i_object_id )||
1355 guidcmp( ASF_Object_Function[i_index].p_id,
1356 &asf_object_null_guid ) )
1362 /* Now free this object */
1363 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1366 "unknown asf object " GUID_FMT,
1367 GUID_PRINT( p_obj->common.i_object_id ) );
1373 "free asf object " GUID_FMT,
1374 GUID_PRINT( p_obj->common.i_object_id ) );
1376 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1381 /*****************************************************************************
1382 * ASF_ObjectDumpDebug:
1383 *****************************************************************************/
1387 const char *psz_name;
1388 } ASF_ObjectDumpDebugInfo[] =
1390 { &asf_object_header_guid, "Header" },
1391 { &asf_object_data_guid, "Data" },
1392 { &asf_object_index_guid, "Index" },
1393 { &asf_object_simple_index_guid, "Simple Index" },
1394 { &asf_object_file_properties_guid, "File Properties" },
1395 { &asf_object_stream_properties_guid, "Stream Properties" },
1396 { &asf_object_content_description_guid, "Content Description" },
1397 { &asf_object_header_extension_guid, "Header Extension" },
1398 { &asf_object_metadata_guid, "Metadata" },
1399 { &asf_object_codec_list_guid, "Codec List" },
1400 { &asf_object_marker_guid, "Marker" },
1401 { &asf_object_stream_type_audio, "Stream Type Audio" },
1402 { &asf_object_stream_type_video, "Stream Type Video" },
1403 { &asf_object_stream_type_command, "Stream Type Command" },
1404 { &asf_object_language_list, "Language List" },
1405 { &asf_object_stream_bitrate_properties, "Stream Bitrate Properties" },
1406 { &asf_object_padding, "Padding" },
1407 { &asf_object_extended_stream_properties_guid, "Extended Stream Properties" },
1408 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1409 { &asf_object_stream_prioritization, "Stream Prioritization" },
1410 { &asf_object_extended_content_description, "Extended content description"},
1412 { NULL, "Unknown" },
1416 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1417 asf_object_common_t *p_node, unsigned i_level )
1420 union asf_object_u *p_child;
1421 const char *psz_name;
1424 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1426 if( guidcmp( ASF_ObjectDumpDebugInfo[i].p_id,
1427 &p_node->i_object_id ) )
1430 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1433 if( i_level >= (sizeof(str) - 1)/5 )
1436 memset( str, ' ', sizeof( str ) );
1437 for( i = 1; i < i_level; i++ )
1441 snprintf( &str[5*i_level], sizeof(str) - 5*i_level,
1442 "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64,
1444 GUID_PRINT( p_node->i_object_id ),
1445 p_node->i_object_size, p_node->i_object_pos );
1447 msg_Dbg( p_obj, "%s", str );
1449 for( p_child = p_node->p_first; p_child != NULL;
1450 p_child = p_child->common.p_next )
1452 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1456 /*****************************************************************************
1457 * ASF_ReadObjetRoot : parse the entire stream/file
1458 *****************************************************************************/
1459 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1461 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1462 asf_object_t *p_obj;
1467 p_root->i_type = ASF_OBJECT_ROOT;
1468 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1469 p_root->i_object_pos = stream_Tell( s );
1470 p_root->i_object_size = 0;
1471 p_root->p_first = NULL;
1472 p_root->p_last = NULL;
1473 p_root->p_next = NULL;
1474 p_root->p_hdr = NULL;
1475 p_root->p_data = NULL;
1476 p_root->p_fp = NULL;
1477 p_root->p_index = NULL;
1478 p_root->p_metadata = NULL;
1482 p_obj = malloc( sizeof( asf_object_t ) );
1484 if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1489 switch( p_obj->common.i_type )
1491 case( ASF_OBJECT_HEADER ):
1492 p_root->p_hdr = (asf_object_header_t*)p_obj;
1494 case( ASF_OBJECT_DATA ):
1495 p_root->p_data = (asf_object_data_t*)p_obj;
1497 case( ASF_OBJECT_INDEX ):
1498 p_root->p_index = (asf_object_index_t*)p_obj;
1501 msg_Warn( s, "unknow object found" );
1504 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1505 p_obj->common.i_object_size <= 50 )
1507 /* probably a dump of broadcasted asf */
1510 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1512 /* For unseekable stream it's enough to play */
1516 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1520 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1522 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1523 &asf_object_file_properties_guid, 0 );
1527 asf_object_t *p_hdr_ext =
1528 ASF_FindObject( p_root->p_hdr,
1529 &asf_object_header_extension_guid, 0 );
1535 p_root->p_metadata =
1536 ASF_FindObject( p_hdr_ext,
1537 &asf_object_metadata_guid, 0 );
1538 /* Special case for broken designed file format :( */
1539 i_ext_stream = ASF_CountObject( p_hdr_ext,
1540 &asf_object_extended_stream_properties_guid );
1541 for( i = 0; i < i_ext_stream; i++ )
1543 asf_object_t *p_esp =
1544 ASF_FindObject( p_hdr_ext,
1545 &asf_object_extended_stream_properties_guid, i );
1546 if( p_esp->ext_stream.p_sp )
1548 asf_object_t *p_sp =
1549 (asf_object_t*)p_esp->ext_stream.p_sp;
1551 /* Insert this p_sp */
1552 p_root->p_hdr->p_last->common.p_next = p_sp;
1553 p_root->p_hdr->p_last = p_sp;
1555 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1560 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1561 (asf_object_common_t*)p_root, 0 );
1564 msg_Warn( s, "cannot find file properties object" );
1568 ASF_FreeObjectRoot( s, p_root );
1572 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1574 asf_object_t *p_obj;
1576 p_obj = p_root->p_first;
1579 asf_object_t *p_next;
1580 p_next = p_obj->common.p_next;
1581 ASF_FreeObject( s, p_obj );
1587 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1590 asf_object_t *p_child;
1596 p_child = p_obj->common.p_first;
1599 if( guidcmp( &p_child->common.i_object_id, p_guid ) )
1602 p_child = p_child->common.p_next;
1607 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1610 asf_object_t *p_child;
1612 p_child = p_obj->common.p_first;
1616 if( guidcmp( &p_child->common.i_object_id, p_guid ) )
1623 p_child = p_child->common.p_next;