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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc_demux.h>
32 #include <vlc_codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
37 #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"
38 #define GUID_PRINT( guid ) \
42 (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
43 (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
45 /****************************************************************************
47 ****************************************************************************/
48 static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * );
50 /****************************************************************************
52 ****************************************************************************/
53 void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data )
55 p_guid->v1 = GetDWLE( p_data );
56 p_guid->v2 = GetWLE( p_data + 4);
57 p_guid->v3 = GetWLE( p_data + 6);
58 memcpy( p_guid->v4, p_data + 8, 8 );
61 int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
63 if( (p_guid1->v1 != p_guid2->v1 )||
64 (p_guid1->v2 != p_guid2->v2 )||
65 (p_guid1->v3 != p_guid2->v3 )||
66 ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
70 return( 1 ); /* match */
73 /****************************************************************************
75 ****************************************************************************/
76 static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
78 asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
81 if( stream_Peek( s, &p_peek, 24 ) < 24 )
83 return( VLC_EGENERIC );
85 ASF_GetGUID( &p_common->i_object_id, p_peek );
86 p_common->i_object_size = GetQWLE( p_peek + 16 );
87 p_common->i_object_pos = stream_Tell( s );
88 p_common->p_next = NULL;
92 "found object guid: " GUID_FMT " size:"I64Fd,
93 GUID_PRINT( p_common->i_object_id ),
94 p_common->i_object_size );
97 return( VLC_SUCCESS );
100 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
105 if( ASF_ReadObjectCommon( s, &obj ) )
107 return( VLC_EGENERIC );
112 if( p_obj->common.i_object_size <= 0 )
116 if( p_obj->common.p_father &&
117 p_obj->common.p_father->common.i_object_size != 0 )
119 if( p_obj->common.p_father->common.i_object_pos +
120 p_obj->common.p_father->common.i_object_size <
121 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
122 /* 24 is min size of an object */
129 return stream_Seek( s, p_obj->common.i_object_pos +
130 p_obj->common.i_object_size );
133 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
138 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
140 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
141 asf_object_t *p_subobj;
145 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
147 return( VLC_EGENERIC );
150 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
151 p_hdr->i_reserved1 = p_peek[28];
152 p_hdr->i_reserved2 = p_peek[29];
153 p_hdr->p_first = NULL;
154 p_hdr->p_last = NULL;
158 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
159 p_hdr->i_sub_object_count,
161 p_hdr->i_reserved2 );
164 /* Cannot fail as peek succeed */
165 stream_Read( s, NULL, 30 );
167 /* Now load sub object */
170 p_subobj = malloc( sizeof( asf_object_t ) );
172 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
177 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
185 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
187 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
191 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
195 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
196 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
197 p_data->i_reserved = GetWLE( p_peek + 48 );
201 "read \"data object\" file_id:" GUID_FMT " total data packet:"
203 GUID_PRINT( p_data->i_file_id ),
204 p_data->i_total_data_packets,
205 p_data->i_reserved );
211 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
213 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
217 if( ( i_peek = stream_Peek( s, &p_peek, 56 ) ) < 56 )
221 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
222 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
223 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
224 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
225 p_index->index_entry = NULL; /* FIXME */
229 "read \"index object\" file_id:" GUID_FMT
230 " index_entry_time_interval:"I64Fd" max_packet_count:%d "
231 "index_entry_count:%ld",
232 GUID_PRINT( p_index->i_file_id ),
233 p_index->i_index_entry_time_interval,
234 p_index->i_max_packet_count,
235 (long int)p_index->i_index_entry_count );
241 static void ASF_FreeObject_Index( asf_object_t *p_obj )
243 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
245 FREENULL( p_index->index_entry );
248 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
250 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
254 if( ( i_peek = stream_Peek( s, &p_peek, 92) ) < 92 )
258 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
259 p_fp->i_file_size = GetQWLE( p_peek + 40 );
260 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
261 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
262 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
263 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
264 p_fp->i_preroll = GetQWLE( p_peek + 80 );
265 p_fp->i_flags = GetDWLE( p_peek + 88 );
266 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
267 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
268 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
272 "read \"file properties object\" file_id:" GUID_FMT
273 " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
274 I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
275 I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
277 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
278 p_fp->i_creation_date, p_fp->i_data_packets_count,
279 p_fp->i_play_duration, p_fp->i_send_duration,
280 p_fp->i_preroll, p_fp->i_flags,
281 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
282 p_fp->i_max_bitrate );
288 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
290 asf_object_metadata_t *p_meta =
291 (asf_object_metadata_t *)p_obj;
294 for( i = 0; i < p_meta->i_record_entries_count; i++ )
296 if( p_meta->record[i].psz_name ) free( p_meta->record[i].psz_name );
297 if( p_meta->record[i].p_data ) free( p_meta->record[i].p_data );
299 if( p_meta->record ) free( p_meta->record );
302 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
304 asf_object_metadata_t *p_meta =
305 (asf_object_metadata_t *)p_obj;
307 int i_peek, i_entries, i;
313 p_meta->i_record_entries_count = 0;
316 if( stream_Peek( s, &p_peek, p_meta->i_object_size ) <
317 (int)p_meta->i_object_size )
323 i_entries = GetWLE( p_peek + i_peek ); i_peek += 2;
324 for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
326 asf_metadata_record_t record;
327 int i_name, i_data, j;
329 if( GetWLE( p_peek + i_peek ) != 0 )
331 ASF_FreeObject_metadata( p_obj );
336 record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2;
337 i_name = GetWLE( p_peek + i_peek ); i_peek += 2;
338 record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
339 i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
341 if( record.i_type > ASF_METADATA_TYPE_WORD ||
342 i_peek + i_data + i_name > (int)p_meta->i_object_size )
344 ASF_FreeObject_metadata( p_obj );
353 record.psz_name = malloc( i_name/2 + 1 );
354 for( j = 0; j < i_name/2; j++ )
356 record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
358 record.psz_name[j] = 0; /* just to make sure */
361 if( record.i_type == ASF_METADATA_TYPE_STRING )
363 record.p_data = malloc( i_data/2 + 1 );
364 record.i_data = i_data/2;
365 for( j = 0; j < i_data/2; j++ )
367 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
369 record.p_data[j] = 0; /* just to make sure */
371 else if( record.i_type == ASF_METADATA_TYPE_BYTE )
373 record.p_data = malloc( i_data );
374 record.i_data = i_data;
375 memcpy( record.p_data, p_peek + i_peek, i_data );
380 if( record.i_type == ASF_METADATA_TYPE_QWORD )
382 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
384 else if( record.i_type == ASF_METADATA_TYPE_DWORD )
386 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
390 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
394 p_meta->i_record_entries_count++;
396 realloc( p_meta->record, p_meta->i_record_entries_count *
397 sizeof(asf_metadata_record_t) );
398 memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
399 &record, sizeof(asf_metadata_record_t) );
404 "read \"metadata object\" %d entries",
405 p_meta->i_record_entries_count );
406 for( j = 0; j < p_meta->i_record_entries_count; j++ )
408 asf_metadata_record_t *p_rec = &p_meta->record[j];
410 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
411 msg_Dbg( s, " - %s=%s",
412 p_rec->psz_name, p_rec->p_data );
413 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
414 msg_Dbg( s, " - %s (%i bytes)",
415 p_rec->psz_name, p_rec->i_data );
417 msg_Dbg( s, " - %s="I64Fd,
418 p_rec->psz_name, p_rec->i_val );
425 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
427 asf_object_header_extension_t *p_he =
428 (asf_object_header_extension_t *)p_obj;
432 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
436 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
437 p_he->i_reserved2 = GetWLE( p_peek + 40 );
438 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
439 if( p_he->i_header_extension_size )
441 p_he->p_header_extension_data =
442 malloc( p_he->i_header_extension_size );
443 memcpy( p_he->p_header_extension_data, p_peek + 46,
444 p_he->i_header_extension_size );
448 p_he->p_header_extension_data = NULL;
453 "read \"header extension object\" reserved1:" GUID_FMT
454 " reserved2:%d header_extension_size:%d",
455 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
456 p_he->i_header_extension_size );
459 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
461 /* Read the extension objects */
462 stream_Read( s, NULL, 46 );
465 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
467 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
473 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
482 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
484 asf_object_header_extension_t *p_he =
485 (asf_object_header_extension_t *)p_obj;
487 FREENULL( p_he->p_header_extension_data );
490 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
492 asf_object_stream_properties_t *p_sp =
493 (asf_object_stream_properties_t*)p_obj;
497 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 74 )
501 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
502 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
503 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
504 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
505 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
506 p_sp->i_flags = GetWLE( p_peek + 72 );
507 p_sp->i_stream_number = p_sp->i_flags&0x07f;
508 p_sp->i_reserved = GetDWLE( p_peek + 74 );
509 if( p_sp->i_type_specific_data_length )
511 p_sp->p_type_specific_data =
512 malloc( p_sp->i_type_specific_data_length );
513 memcpy( p_sp->p_type_specific_data, p_peek + 78,
514 p_sp->i_type_specific_data_length );
518 p_sp->p_type_specific_data = NULL;
520 if( p_sp->i_error_correction_data_length )
522 p_sp->p_error_correction_data =
523 malloc( p_sp->i_error_correction_data_length );
524 memcpy( p_sp->p_error_correction_data,
525 p_peek + 78 + p_sp->i_type_specific_data_length,
526 p_sp->i_error_correction_data_length );
530 p_sp->p_error_correction_data = NULL;
535 "read \"stream Properties object\" stream_type:" GUID_FMT
536 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
537 " type_specific_data_length:%d error_correction_data_length:%d"
538 " flags:0x%x stream_number:%d",
539 GUID_PRINT( p_sp->i_stream_type ),
540 GUID_PRINT( p_sp->i_error_correction_type ),
542 p_sp->i_type_specific_data_length,
543 p_sp->i_error_correction_data_length,
545 p_sp->i_stream_number );
551 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
553 asf_object_stream_properties_t *p_sp =
554 (asf_object_stream_properties_t*)p_obj;
556 FREENULL( p_sp->p_type_specific_data );
557 FREENULL( p_sp->p_error_correction_data );
561 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
563 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
565 uint8_t *p_peek, *p_data;
567 unsigned int i_codec;
569 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
574 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
575 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
576 if( p_cl->i_codec_entries_count > 0 )
578 p_cl->codec = calloc( p_cl->i_codec_entries_count,
579 sizeof( asf_codec_entry_t ) );
580 memset( p_cl->codec, 0,
581 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
583 p_data = p_peek + 44;
584 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
586 #define codec p_cl->codec[i_codec]
589 codec.i_type = GetWLE( p_data ); p_data += 2;
591 i_len = GetWLE( p_data ); p_data += 2;
592 codec.psz_name = calloc( sizeof( char ), i_len + 1);
593 for( i = 0; i < i_len; i++ )
595 codec.psz_name[i] = GetWLE( p_data + 2*i );
597 codec.psz_name[i_len] = '\0';
601 i_len = GetWLE( p_data ); p_data += 2;
602 codec.psz_description = calloc( sizeof( char ), i_len + 1);
603 for( i = 0; i < i_len; i++ )
605 codec.psz_description[i] = GetWLE( p_data + 2*i );
607 codec.psz_description[i_len] = '\0';
610 /* opaque information */
611 codec.i_information_length = GetWLE( p_data ); p_data += 2;
612 if( codec.i_information_length > 0 )
614 codec.p_information = malloc( codec.i_information_length );
615 memcpy( codec.p_information, p_data, codec.i_information_length );
616 p_data += codec.i_information_length;
620 codec.p_information = NULL;
631 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
632 " codec_entries_count:%d",
633 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
635 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
637 #define codec p_cl->codec[i_codec]
638 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
639 "description:\"%s\" information_length:%d",
640 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
641 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
642 "audio" : "unknown" ),
643 codec.psz_name, codec.psz_description,
644 codec.i_information_length );
652 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
654 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
655 unsigned int i_codec;
657 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
659 #define codec p_cl->codec[i_codec]
660 FREENULL( codec.psz_name );
661 FREENULL( codec.psz_description );
662 FREENULL( codec.p_information );
665 FREENULL( p_cl->codec );
668 /* Microsoft should go to hell. This time the length give number of bytes
669 * and for the some others object, length give char16 count ... */
670 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
672 asf_object_content_description_t *p_cd =
673 (asf_object_content_description_t *)p_obj;
674 uint8_t *p_peek, *p_data;
675 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
676 vlc_iconv_t cd = (vlc_iconv_t)-1;
677 const char *ib = NULL;
679 size_t i_ibl, i_obl, i_len;
681 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
682 if ( cd == (vlc_iconv_t)-1 ) {
683 msg_Err( s, "vlc_iconv_open failed" );
687 /* FIXME i_size*3 is the worst case. */
688 #define GETSTRINGW( psz_str, i_size ) \
689 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
690 ib = (const char *)p_data; \
694 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
697 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
701 p_data = p_peek + 24;
703 i_title = GetWLE( p_data ); p_data += 2;
704 i_artist= GetWLE( p_data ); p_data += 2;
705 i_copyright = GetWLE( p_data ); p_data += 2;
706 i_description = GetWLE( p_data ); p_data += 2;
707 i_rating = GetWLE( p_data ); p_data += 2;
709 GETSTRINGW( p_cd->psz_title, i_title );
710 GETSTRINGW( p_cd->psz_artist, i_artist );
711 GETSTRINGW( p_cd->psz_copyright, i_copyright );
712 GETSTRINGW( p_cd->psz_description, i_description );
713 GETSTRINGW( p_cd->psz_rating, i_rating );
719 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
723 p_cd->psz_description,
731 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
733 asf_object_content_description_t *p_cd =
734 (asf_object_content_description_t *)p_obj;
736 FREENULL( p_cd->psz_title );
737 FREENULL( p_cd->psz_artist );
738 FREENULL( p_cd->psz_copyright );
739 FREENULL( p_cd->psz_description );
740 FREENULL( p_cd->psz_rating );
744 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
746 asf_object_language_list_t *p_ll =
747 (asf_object_language_list_t*)p_obj;
748 uint8_t *p_peek, *p_data;
752 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
755 p_data = &p_peek[24];
757 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
758 if( p_ll->i_language > 0 )
760 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
762 for( i = 0; i < p_ll->i_language; i++ )
765 int i_size = *p_data++;
768 psz = calloc( i_size/2 + 1, sizeof( char ) );
769 for( i_len = 0; i_len < i_size/2; i_len++ )
771 psz[i_len] = GetWLE( p_data + 2*i_len );
773 psz[i_size/2] = '\0'; \
776 p_ll->ppsz_language[i] = psz;
781 msg_Dbg( s, "read \"language list object\" %d entries",
783 for( i = 0; i < p_ll->i_language; i++ )
784 msg_Dbg( s, " - '%s'",
785 p_ll->ppsz_language[i] );
790 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
792 asf_object_language_list_t *p_ll =
793 (asf_object_language_list_t *)p_obj;
796 for( i = 0; i < p_ll->i_language; i++ )
797 FREENULL( p_ll->ppsz_language[i] );
798 FREENULL( p_ll->ppsz_language );
801 /* Stream bitrate properties */
802 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
805 asf_object_stream_bitrate_properties_t *p_sb =
806 (asf_object_stream_bitrate_properties_t *)p_obj;
807 uint8_t *p_peek, *p_data;
811 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
814 p_data = &p_peek[24];
816 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
817 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
818 for( i = 0; i < p_sb->i_bitrate; i++ )
820 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
821 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
827 msg_Dbg( s,"read \"stream bitrate properties object\"" );
828 for( i = 0; i < p_sb->i_bitrate; i++ )
830 msg_Dbg( s," - stream=%d bitrate=%d",
831 p_sb->bitrate[i].i_stream_number,
832 p_sb->bitrate[i].i_avg_bitrate );
837 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
841 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
844 asf_object_extended_stream_properties_t *p_esp =
845 (asf_object_extended_stream_properties_t*)p_obj;
846 uint8_t *p_peek, *p_data;
849 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
852 p_data = &p_peek[24];
854 p_esp->i_start_time = GetQWLE( &p_data[0] );
855 p_esp->i_end_time = GetQWLE( &p_data[8] );
856 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
857 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
858 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
859 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
860 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
861 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
862 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
863 p_esp->i_flags = GetDWLE( &p_data[44] );
864 p_esp->i_stream_number = GetWLE( &p_data[48] );
865 p_esp->i_language_index = GetWLE( &p_data[50] );
866 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
867 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
868 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
872 p_esp->pi_stream_name_language = calloc( sizeof(int),
873 p_esp->i_stream_name_count );
874 p_esp->ppsz_stream_name = calloc( sizeof(char*),
875 p_esp->i_stream_name_count );
876 for( i = 0; i < p_esp->i_stream_name_count; i++ )
882 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
883 i_size = GetWLE( &p_data[2] );
886 psz = calloc( i_size/2 + 1, sizeof( char ) );
887 for( i_len = 0; i_len < i_size/2; i_len++ )
889 psz[i_len] = GetWLE( p_data + 2*i_len );
891 psz[i_size/2] = '\0'; \
894 p_esp->ppsz_stream_name[i] = psz;
897 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
900 int i_size = GetDWLE( &p_data[16 + 2] );
902 p_data += 16+2+4+i_size;
906 if( p_data < &p_peek[i_peek] )
909 /* Cannot fail as peek succeed */
910 stream_Read( s, NULL, p_data - p_peek );
912 p_sp = malloc( sizeof( asf_object_t ) );
914 if( ASF_ReadObject( s, p_sp, NULL ) )
920 /* This p_sp will be inserted by ReadRoot later */
921 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
926 msg_Dbg( s, "read \"extended stream properties object\":" );
927 msg_Dbg( s, " - start="I64Fd" end="I64Fd,
928 p_esp->i_start_time, p_esp->i_end_time );
929 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
930 p_esp->i_data_bitrate,
931 p_esp->i_buffer_size,
932 p_esp->i_initial_buffer_fullness );
933 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
934 p_esp->i_alternate_data_bitrate,
935 p_esp->i_alternate_buffer_size,
936 p_esp->i_alternate_initial_buffer_fullness );
937 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
938 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
939 msg_Dbg( s, " - stream number=%d language=%d",
940 p_esp->i_stream_number, p_esp->i_language_index );
941 msg_Dbg( s, " - average time per frame="I64Fd,
942 p_esp->i_average_time_per_frame );
943 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
944 for( i = 0; i < p_esp->i_stream_name_count; i++ )
945 msg_Dbg( s, " - lang id=%d name=%s",
946 p_esp->pi_stream_name_language[i],
947 p_esp->ppsz_stream_name[i] );
948 msg_Dbg( s, " - payload extension system count=%d",
949 p_esp->i_payload_extension_system_count );
953 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
955 asf_object_extended_stream_properties_t *p_esp =
956 (asf_object_extended_stream_properties_t *)p_obj;
959 for( i = 0; i < p_esp->i_stream_name_count; i++ )
960 FREENULL( p_esp->ppsz_stream_name[i] );
961 FREENULL( p_esp->pi_stream_name_language );
962 FREENULL( p_esp->ppsz_stream_name );
966 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
969 asf_object_advanced_mutual_exclusion_t *p_ae =
970 (asf_object_advanced_mutual_exclusion_t *)p_obj;
971 uint8_t *p_peek, *p_data;
975 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
978 p_data = &p_peek[24];
980 ASF_GetGUID( &p_ae->type, &p_data[0] );
981 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
984 p_ae->pi_stream_number = calloc( sizeof(int),
985 p_ae->i_stream_number_count );
986 for( i = 0; i < p_ae->i_stream_number_count; i++ )
988 p_ae->pi_stream_number[i] = GetWLE( p_data );
993 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
994 for( i = 0; i < p_ae->i_stream_number_count; i++ )
995 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
999 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1001 asf_object_advanced_mutual_exclusion_t *p_ae =
1002 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1004 FREENULL( p_ae->pi_stream_number );
1008 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1009 asf_object_t *p_obj)
1011 asf_object_stream_prioritization_t *p_sp =
1012 (asf_object_stream_prioritization_t *)p_obj;
1013 uint8_t *p_peek, *p_data;
1017 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1018 return VLC_EGENERIC;
1020 p_data = &p_peek[24];
1022 p_sp->i_priority_count = GetWLE( &p_data[0] );
1025 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1026 p_sp->pi_priority_stream_number =
1027 calloc( sizeof(int), p_sp->i_priority_count );
1029 for( i = 0; i < p_sp->i_priority_count; i++ )
1031 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1032 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1035 msg_Dbg( s, "read \"stream prioritization object\"" );
1036 for( i = 0; i < p_sp->i_priority_count; i++ )
1037 msg_Dbg( s, " - Stream:%d flags=0x%x",
1038 p_sp->pi_priority_stream_number[i],
1039 p_sp->pi_priority_flag[i] );
1043 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1045 asf_object_stream_prioritization_t *p_sp =
1046 (asf_object_stream_prioritization_t *)p_obj;
1048 FREENULL( p_sp->pi_priority_stream_number );
1049 FREENULL( p_sp->pi_priority_flag );
1053 static int ASF_ReadObject_extended_content_description( stream_t *s,
1054 asf_object_t *p_obj)
1056 asf_object_extended_content_description_t *p_ec =
1057 (asf_object_extended_content_description_t *)p_obj;
1058 uint8_t *p_peek, *p_data;
1062 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1063 return VLC_EGENERIC;
1065 p_data = &p_peek[24];
1067 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1068 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1069 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1070 for( i = 0; i < p_ec->i_count; i++ )
1075 #define GETSTRINGW( psz_str, i_size ) \
1076 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1077 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1079 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1081 psz_str[i_size/2] = '\0';
1083 i_size = GetWLE( p_data ); p_data += 2;
1084 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1088 i_type = GetWLE( p_data ); p_data += 2;
1089 i_size = GetWLE( p_data ); p_data += 2;
1092 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1094 else if( i_type == 1 )
1098 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1099 for( j = 0; j < i_size; j++ )
1101 static const char hex[16] = "0123456789ABCDEF";
1102 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1103 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1105 p_ec->ppsz_value[i][2*i_size] = '\0';
1107 else if( i_type == 2 )
1110 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1112 else if( i_type == 3 )
1115 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1117 else if( i_type == 4 )
1120 asprintf( &p_ec->ppsz_value[i], I64Fd, GetQWLE(p_data));
1122 else if( i_type == 5 )
1125 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1128 p_ec->ppsz_value[i] = NULL;
1139 msg_Dbg( s, "read \"extended content description object\"" );
1140 for( i = 0; i < p_ec->i_count; i++ )
1141 msg_Dbg( s, " - '%s' = '%s'",
1143 p_ec->ppsz_value[i] );
1147 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1149 asf_object_extended_content_description_t *p_ec =
1150 (asf_object_extended_content_description_t *)p_obj;
1153 for( i = 0; i < p_ec->i_count; i++ )
1155 FREENULL( p_ec->ppsz_name[i] );
1156 FREENULL( p_ec->ppsz_value[i] );
1158 FREENULL( p_ec->ppsz_name );
1159 FREENULL( p_ec->ppsz_value );
1164 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1166 asf_object_XXX_t *p_XX =
1167 (asf_object_XXX_t *)p_obj;
1168 uint8_t *p_peek, *p_data;
1171 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1172 return VLC_EGENERIC;
1174 p_data = &p_peek[24];
1178 "Read \"XXX object\"" );
1182 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1184 asf_object_XXX_t *p_XX =
1185 (asf_object_XXX_t *)p_obj;
1195 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1196 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1198 } ASF_Object_Function [] =
1200 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1201 ASF_ReadObject_Header, ASF_FreeObject_Null },
1202 { &asf_object_data_guid, ASF_OBJECT_DATA,
1203 ASF_ReadObject_Data, ASF_FreeObject_Null },
1204 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1205 ASF_ReadObject_Index, ASF_FreeObject_Index },
1206 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1207 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1208 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1209 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1210 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1211 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1212 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1213 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1214 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1215 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1216 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1217 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1218 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1219 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1220 { &asf_object_language_list, ASF_OBJECT_OTHER,
1221 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1222 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1223 ASF_ReadObject_stream_bitrate_properties,
1224 ASF_FreeObject_stream_bitrate_properties },
1225 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1226 ASF_ReadObject_extended_stream_properties,
1227 ASF_FreeObject_extended_stream_properties },
1228 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1229 ASF_ReadObject_advanced_mutual_exclusion,
1230 ASF_FreeObject_advanced_mutual_exclusion },
1231 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1232 ASF_ReadObject_stream_prioritization,
1233 ASF_FreeObject_stream_prioritization },
1234 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1235 ASF_ReadObject_extended_content_description,
1236 ASF_FreeObject_extended_content_description },
1238 { &asf_object_null_guid, 0, NULL, NULL }
1241 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1242 asf_object_t *p_father )
1250 memset( p_obj, 0, sizeof( p_obj ) );
1252 if( ASF_ReadObjectCommon( s, p_obj ) )
1254 msg_Warn( s, "cannot read one asf object" );
1255 return VLC_EGENERIC;
1257 p_obj->common.p_father = p_father;
1258 p_obj->common.p_first = NULL;
1259 p_obj->common.p_next = NULL;
1260 p_obj->common.p_last = NULL;
1262 if( p_obj->common.i_object_size < 24 )
1264 msg_Warn( s, "found a corrupted asf object (size<24)" );
1265 return VLC_EGENERIC;
1268 /* find this object */
1269 for( i_index = 0; ; i_index++ )
1271 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1272 &p_obj->common.i_object_id ) ||
1273 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1274 &asf_object_null_guid ) )
1279 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1281 /* Now load this object */
1282 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1284 msg_Warn( s, "unknown asf object (not loaded)" );
1285 i_result = VLC_SUCCESS;
1289 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1291 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1294 /* link this object with father */
1297 if( p_father->common.p_first )
1299 p_father->common.p_last->common.p_next = p_obj;
1303 p_father->common.p_first = p_obj;
1305 p_father->common.p_last = p_obj;
1311 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1314 asf_object_t *p_child;
1316 if( !p_obj ) return;
1318 /* Free all child object */
1319 p_child = p_obj->common.p_first;
1322 asf_object_t *p_next;
1323 p_next = p_child->common.p_next;
1324 ASF_FreeObject( s, p_child );
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 ) )
1340 /* Now free this object */
1341 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1344 "unknown asf object " GUID_FMT,
1345 GUID_PRINT( p_obj->common.i_object_id ) );
1351 "free asf object " GUID_FMT,
1352 GUID_PRINT( p_obj->common.i_object_id ) );
1354 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1360 /*****************************************************************************
1361 * ASF_ObjectDumpDebug:
1362 *****************************************************************************/
1367 } ASF_ObjectDumpDebugInfo[] =
1369 { &asf_object_header_guid, "Header" },
1370 { &asf_object_data_guid, "Data" },
1371 { &asf_object_index_guid, "Index" },
1372 { &asf_object_file_properties_guid, "File Properties" },
1373 { &asf_object_stream_properties_guid, "Stream Properties" },
1374 { &asf_object_content_description_guid, "Content Description" },
1375 { &asf_object_header_extension_guid, "Header Extension" },
1376 { &asf_object_metadata_guid, "Metadata" },
1377 { &asf_object_codec_list_guid, "Codec List" },
1378 { &asf_object_marker_guid, "Marker" },
1379 { &asf_object_stream_type_audio, "Stream Type Audio" },
1380 { &asf_object_stream_type_video, "Stream Type Video" },
1381 { &asf_object_stream_type_command, "Stream Type Command" },
1382 { &asf_object_language_list, "Language List" },
1383 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1384 { &asf_object_padding, "Padding" },
1385 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1386 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1387 { &asf_object_stream_prioritization, "Stream Prioritization" },
1388 { &asf_object_extended_content_description, "Extended content description"},
1390 { NULL, "Unknown" },
1394 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1395 asf_object_common_t *p_node, int i_level )
1399 union asf_object_u *p_child;
1403 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1405 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1406 &p_node->i_object_id ) )
1409 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1411 memset( str, ' ', sizeof( str ) );
1412 for( i = 1; i < i_level; i++ )
1416 snprintf( str + 5*i_level, 1024,
1417 "+ '%s' GUID "GUID_FMT" size:"I64Fu"pos:"I64Fu,
1419 GUID_PRINT( p_node->i_object_id ),
1420 p_node->i_object_size, p_node->i_object_pos );
1422 msg_Dbg( p_obj, "%s", str );
1424 for( p_child = p_node->p_first; p_child != NULL;
1425 p_child = p_child->common.p_next )
1427 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1431 /*****************************************************************************
1432 * ASF_ReadObjetRoot : parse the entire stream/file
1433 *****************************************************************************/
1434 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1436 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1437 asf_object_t *p_obj;
1439 p_root->i_type = ASF_OBJECT_ROOT;
1440 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1441 p_root->i_object_pos = stream_Tell( s );
1442 p_root->i_object_size = 0;
1443 p_root->p_first = NULL;
1444 p_root->p_last = NULL;
1445 p_root->p_next = NULL;
1446 p_root->p_hdr = NULL;
1447 p_root->p_data = NULL;
1448 p_root->p_fp = NULL;
1449 p_root->p_index = NULL;
1450 p_root->p_metadata = NULL;
1454 p_obj = malloc( sizeof( asf_object_t ) );
1456 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1461 switch( p_obj->common.i_type )
1463 case( ASF_OBJECT_HEADER ):
1464 p_root->p_hdr = (asf_object_header_t*)p_obj;
1466 case( ASF_OBJECT_DATA ):
1467 p_root->p_data = (asf_object_data_t*)p_obj;
1469 case( ASF_OBJECT_INDEX ):
1470 p_root->p_index = (asf_object_index_t*)p_obj;
1473 msg_Warn( s, "unknow object found" );
1476 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1477 p_obj->common.i_object_size <= 50 )
1479 /* probably a dump of broadcasted asf */
1482 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1484 /* For unseekable stream it's enough to play */
1488 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1494 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1496 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1497 &asf_object_file_properties_guid, 0 );
1501 asf_object_t *p_hdr_ext =
1502 ASF_FindObject( p_root->p_hdr,
1503 &asf_object_header_extension_guid, 0 );
1509 p_root->p_metadata =
1510 ASF_FindObject( p_hdr_ext,
1511 &asf_object_metadata_guid, 0 );
1512 /* Special case for broken designed file format :( */
1513 i_ext_stream = ASF_CountObject( p_hdr_ext,
1514 &asf_object_extended_stream_properties );
1515 for( i = 0; i < i_ext_stream; i++ )
1517 asf_object_t *p_esp =
1518 ASF_FindObject( p_hdr_ext,
1519 &asf_object_extended_stream_properties, i );
1520 if( p_esp->ext_stream.p_sp )
1522 asf_object_t *p_sp =
1523 (asf_object_t*)p_esp->ext_stream.p_sp;
1525 /* Insert this p_sp */
1526 p_root->p_hdr->p_last->common.p_next = p_sp;
1527 p_root->p_hdr->p_last = p_sp;
1529 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1534 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1535 (asf_object_common_t*)p_root, 0 );
1538 msg_Warn( s, "cannot find file properties object" );
1542 ASF_FreeObjectRoot( s, p_root );
1546 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1548 asf_object_t *p_obj;
1550 p_obj = p_root->p_first;
1553 asf_object_t *p_next;
1554 p_next = p_obj->common.p_next;
1555 ASF_FreeObject( s, p_obj );
1561 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1564 asf_object_t *p_child;
1566 if( !p_obj ) return( 0 );
1569 p_child = p_obj->common.p_first;
1572 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1576 p_child = p_child->common.p_next;
1581 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1584 asf_object_t *p_child;
1586 p_child = p_obj->common.p_first;
1590 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1600 p_child = p_child->common.p_next;