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 ) ) < 78 )
502 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
503 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
504 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
505 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
506 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
507 p_sp->i_flags = GetWLE( p_peek + 72 );
508 p_sp->i_stream_number = p_sp->i_flags&0x07f;
509 p_sp->i_reserved = GetDWLE( p_peek + 74 );
512 if( p_sp->i_type_specific_data_length )
514 if( i_peek < p_sp->i_type_specific_data_length )
517 p_sp->p_type_specific_data =
518 malloc( p_sp->i_type_specific_data_length );
519 if( p_sp->p_type_specific_data == NULL )
522 memcpy( p_sp->p_type_specific_data, p_peek + 78,
523 p_sp->i_type_specific_data_length );
524 i_peek -= p_sp->i_type_specific_data_length;
528 p_sp->p_type_specific_data = NULL;
531 if( p_sp->i_error_correction_data_length )
533 if( i_peek < p_sp->i_error_correction_data_length )
535 free( p_sp->p_type_specific_data );
539 p_sp->p_error_correction_data =
540 malloc( p_sp->i_error_correction_data_length );
541 if( p_sp->p_error_correction_data == NULL )
543 free( p_sp->p_type_specific_data );
546 memcpy( p_sp->p_error_correction_data,
547 p_peek + 78 + p_sp->i_type_specific_data_length,
548 p_sp->i_error_correction_data_length );
552 p_sp->p_error_correction_data = NULL;
557 "read \"stream Properties object\" stream_type:" GUID_FMT
558 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
559 " type_specific_data_length:%d error_correction_data_length:%d"
560 " flags:0x%x stream_number:%d",
561 GUID_PRINT( p_sp->i_stream_type ),
562 GUID_PRINT( p_sp->i_error_correction_type ),
564 p_sp->i_type_specific_data_length,
565 p_sp->i_error_correction_data_length,
567 p_sp->i_stream_number );
573 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
575 asf_object_stream_properties_t *p_sp =
576 (asf_object_stream_properties_t*)p_obj;
578 FREENULL( p_sp->p_type_specific_data );
579 FREENULL( p_sp->p_error_correction_data );
583 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
585 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
587 uint8_t *p_peek, *p_data;
589 unsigned int i_codec;
591 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
596 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
597 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
598 if( p_cl->i_codec_entries_count > 0 )
600 p_cl->codec = calloc( p_cl->i_codec_entries_count,
601 sizeof( asf_codec_entry_t ) );
602 memset( p_cl->codec, 0,
603 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
605 p_data = p_peek + 44;
606 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
608 #define codec p_cl->codec[i_codec]
611 codec.i_type = GetWLE( p_data ); p_data += 2;
613 i_len = GetWLE( p_data ); p_data += 2;
614 codec.psz_name = calloc( sizeof( char ), i_len + 1);
615 for( i = 0; i < i_len; i++ )
617 codec.psz_name[i] = GetWLE( p_data + 2*i );
619 codec.psz_name[i_len] = '\0';
623 i_len = GetWLE( p_data ); p_data += 2;
624 codec.psz_description = calloc( sizeof( char ), i_len + 1);
625 for( i = 0; i < i_len; i++ )
627 codec.psz_description[i] = GetWLE( p_data + 2*i );
629 codec.psz_description[i_len] = '\0';
632 /* opaque information */
633 codec.i_information_length = GetWLE( p_data ); p_data += 2;
634 if( codec.i_information_length > 0 )
636 codec.p_information = malloc( codec.i_information_length );
637 memcpy( codec.p_information, p_data, codec.i_information_length );
638 p_data += codec.i_information_length;
642 codec.p_information = NULL;
653 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
654 " codec_entries_count:%d",
655 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
657 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
659 #define codec p_cl->codec[i_codec]
660 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
661 "description:\"%s\" information_length:%d",
662 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
663 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
664 "audio" : "unknown" ),
665 codec.psz_name, codec.psz_description,
666 codec.i_information_length );
674 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
676 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
677 unsigned int i_codec;
679 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
681 #define codec p_cl->codec[i_codec]
682 FREENULL( codec.psz_name );
683 FREENULL( codec.psz_description );
684 FREENULL( codec.p_information );
687 FREENULL( p_cl->codec );
690 /* Microsoft should go to hell. This time the length give number of bytes
691 * and for the some others object, length give char16 count ... */
692 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
694 asf_object_content_description_t *p_cd =
695 (asf_object_content_description_t *)p_obj;
696 uint8_t *p_peek, *p_data;
697 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
698 vlc_iconv_t cd = (vlc_iconv_t)-1;
699 const char *ib = NULL;
701 size_t i_ibl, i_obl, i_len;
703 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
704 if ( cd == (vlc_iconv_t)-1 ) {
705 msg_Err( s, "vlc_iconv_open failed" );
709 /* FIXME i_size*3 is the worst case. */
710 #define GETSTRINGW( psz_str, i_size ) \
711 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
712 ib = (const char *)p_data; \
716 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
719 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
723 p_data = p_peek + 24;
725 i_title = GetWLE( p_data ); p_data += 2;
726 i_artist= GetWLE( p_data ); p_data += 2;
727 i_copyright = GetWLE( p_data ); p_data += 2;
728 i_description = GetWLE( p_data ); p_data += 2;
729 i_rating = GetWLE( p_data ); p_data += 2;
731 GETSTRINGW( p_cd->psz_title, i_title );
732 GETSTRINGW( p_cd->psz_artist, i_artist );
733 GETSTRINGW( p_cd->psz_copyright, i_copyright );
734 GETSTRINGW( p_cd->psz_description, i_description );
735 GETSTRINGW( p_cd->psz_rating, i_rating );
741 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
745 p_cd->psz_description,
753 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
755 asf_object_content_description_t *p_cd =
756 (asf_object_content_description_t *)p_obj;
758 FREENULL( p_cd->psz_title );
759 FREENULL( p_cd->psz_artist );
760 FREENULL( p_cd->psz_copyright );
761 FREENULL( p_cd->psz_description );
762 FREENULL( p_cd->psz_rating );
766 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
768 asf_object_language_list_t *p_ll =
769 (asf_object_language_list_t*)p_obj;
770 uint8_t *p_peek, *p_data;
774 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
777 p_data = &p_peek[24];
779 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
780 if( p_ll->i_language > 0 )
782 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
784 for( i = 0; i < p_ll->i_language; i++ )
787 int i_size = *p_data++;
790 psz = calloc( i_size/2 + 1, sizeof( char ) );
791 for( i_len = 0; i_len < i_size/2; i_len++ )
793 psz[i_len] = GetWLE( p_data + 2*i_len );
795 psz[i_size/2] = '\0'; \
798 p_ll->ppsz_language[i] = psz;
803 msg_Dbg( s, "read \"language list object\" %d entries",
805 for( i = 0; i < p_ll->i_language; i++ )
806 msg_Dbg( s, " - '%s'",
807 p_ll->ppsz_language[i] );
812 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
814 asf_object_language_list_t *p_ll =
815 (asf_object_language_list_t *)p_obj;
818 for( i = 0; i < p_ll->i_language; i++ )
819 FREENULL( p_ll->ppsz_language[i] );
820 FREENULL( p_ll->ppsz_language );
823 /* Stream bitrate properties */
824 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
827 asf_object_stream_bitrate_properties_t *p_sb =
828 (asf_object_stream_bitrate_properties_t *)p_obj;
829 uint8_t *p_peek, *p_data;
833 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
836 p_data = &p_peek[24];
838 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
839 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
840 for( i = 0; i < p_sb->i_bitrate; i++ )
842 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
843 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
849 msg_Dbg( s,"read \"stream bitrate properties object\"" );
850 for( i = 0; i < p_sb->i_bitrate; i++ )
852 msg_Dbg( s," - stream=%d bitrate=%d",
853 p_sb->bitrate[i].i_stream_number,
854 p_sb->bitrate[i].i_avg_bitrate );
859 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
863 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
866 asf_object_extended_stream_properties_t *p_esp =
867 (asf_object_extended_stream_properties_t*)p_obj;
868 uint8_t *p_peek, *p_data;
871 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
874 p_data = &p_peek[24];
876 p_esp->i_start_time = GetQWLE( &p_data[0] );
877 p_esp->i_end_time = GetQWLE( &p_data[8] );
878 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
879 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
880 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
881 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
882 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
883 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
884 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
885 p_esp->i_flags = GetDWLE( &p_data[44] );
886 p_esp->i_stream_number = GetWLE( &p_data[48] );
887 p_esp->i_language_index = GetWLE( &p_data[50] );
888 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
889 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
890 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
894 p_esp->pi_stream_name_language = calloc( sizeof(int),
895 p_esp->i_stream_name_count );
896 p_esp->ppsz_stream_name = calloc( sizeof(char*),
897 p_esp->i_stream_name_count );
898 for( i = 0; i < p_esp->i_stream_name_count; i++ )
904 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
905 i_size = GetWLE( &p_data[2] );
908 psz = calloc( i_size/2 + 1, sizeof( char ) );
909 for( i_len = 0; i_len < i_size/2; i_len++ )
911 psz[i_len] = GetWLE( p_data + 2*i_len );
913 psz[i_size/2] = '\0'; \
916 p_esp->ppsz_stream_name[i] = psz;
919 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
922 int i_size = GetDWLE( &p_data[16 + 2] );
924 p_data += 16+2+4+i_size;
928 if( p_data < &p_peek[i_peek] )
931 /* Cannot fail as peek succeed */
932 stream_Read( s, NULL, p_data - p_peek );
934 p_sp = malloc( sizeof( asf_object_t ) );
936 if( ASF_ReadObject( s, p_sp, NULL ) )
942 /* This p_sp will be inserted by ReadRoot later */
943 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
948 msg_Dbg( s, "read \"extended stream properties object\":" );
949 msg_Dbg( s, " - start="I64Fd" end="I64Fd,
950 p_esp->i_start_time, p_esp->i_end_time );
951 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
952 p_esp->i_data_bitrate,
953 p_esp->i_buffer_size,
954 p_esp->i_initial_buffer_fullness );
955 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
956 p_esp->i_alternate_data_bitrate,
957 p_esp->i_alternate_buffer_size,
958 p_esp->i_alternate_initial_buffer_fullness );
959 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
960 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
961 msg_Dbg( s, " - stream number=%d language=%d",
962 p_esp->i_stream_number, p_esp->i_language_index );
963 msg_Dbg( s, " - average time per frame="I64Fd,
964 p_esp->i_average_time_per_frame );
965 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
966 for( i = 0; i < p_esp->i_stream_name_count; i++ )
967 msg_Dbg( s, " - lang id=%d name=%s",
968 p_esp->pi_stream_name_language[i],
969 p_esp->ppsz_stream_name[i] );
970 msg_Dbg( s, " - payload extension system count=%d",
971 p_esp->i_payload_extension_system_count );
975 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
977 asf_object_extended_stream_properties_t *p_esp =
978 (asf_object_extended_stream_properties_t *)p_obj;
981 for( i = 0; i < p_esp->i_stream_name_count; i++ )
982 FREENULL( p_esp->ppsz_stream_name[i] );
983 FREENULL( p_esp->pi_stream_name_language );
984 FREENULL( p_esp->ppsz_stream_name );
988 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
991 asf_object_advanced_mutual_exclusion_t *p_ae =
992 (asf_object_advanced_mutual_exclusion_t *)p_obj;
993 uint8_t *p_peek, *p_data;
997 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1000 p_data = &p_peek[24];
1002 ASF_GetGUID( &p_ae->type, &p_data[0] );
1003 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1006 p_ae->pi_stream_number = calloc( sizeof(int),
1007 p_ae->i_stream_number_count );
1008 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1010 p_ae->pi_stream_number[i] = GetWLE( p_data );
1015 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1016 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1017 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1021 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1023 asf_object_advanced_mutual_exclusion_t *p_ae =
1024 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1026 FREENULL( p_ae->pi_stream_number );
1030 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1031 asf_object_t *p_obj)
1033 asf_object_stream_prioritization_t *p_sp =
1034 (asf_object_stream_prioritization_t *)p_obj;
1035 uint8_t *p_peek, *p_data;
1039 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1040 return VLC_EGENERIC;
1042 p_data = &p_peek[24];
1044 p_sp->i_priority_count = GetWLE( &p_data[0] );
1047 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1048 p_sp->pi_priority_stream_number =
1049 calloc( sizeof(int), p_sp->i_priority_count );
1051 for( i = 0; i < p_sp->i_priority_count; i++ )
1053 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1054 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1057 msg_Dbg( s, "read \"stream prioritization object\"" );
1058 for( i = 0; i < p_sp->i_priority_count; i++ )
1059 msg_Dbg( s, " - Stream:%d flags=0x%x",
1060 p_sp->pi_priority_stream_number[i],
1061 p_sp->pi_priority_flag[i] );
1065 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1067 asf_object_stream_prioritization_t *p_sp =
1068 (asf_object_stream_prioritization_t *)p_obj;
1070 FREENULL( p_sp->pi_priority_stream_number );
1071 FREENULL( p_sp->pi_priority_flag );
1075 static int ASF_ReadObject_extended_content_description( stream_t *s,
1076 asf_object_t *p_obj)
1078 asf_object_extended_content_description_t *p_ec =
1079 (asf_object_extended_content_description_t *)p_obj;
1080 uint8_t *p_peek, *p_data;
1084 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1085 return VLC_EGENERIC;
1087 p_data = &p_peek[24];
1089 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1090 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1091 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1092 for( i = 0; i < p_ec->i_count; i++ )
1097 #define GETSTRINGW( psz_str, i_size ) \
1098 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1099 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1101 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1103 psz_str[i_size/2] = '\0';
1105 i_size = GetWLE( p_data ); p_data += 2;
1106 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1110 i_type = GetWLE( p_data ); p_data += 2;
1111 i_size = GetWLE( p_data ); p_data += 2;
1114 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1116 else if( i_type == 1 )
1120 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1121 for( j = 0; j < i_size; j++ )
1123 static const char hex[16] = "0123456789ABCDEF";
1124 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1125 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1127 p_ec->ppsz_value[i][2*i_size] = '\0';
1129 else if( i_type == 2 )
1132 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1134 else if( i_type == 3 )
1137 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1139 else if( i_type == 4 )
1142 asprintf( &p_ec->ppsz_value[i], I64Fd, GetQWLE(p_data));
1144 else if( i_type == 5 )
1147 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1150 p_ec->ppsz_value[i] = NULL;
1161 msg_Dbg( s, "read \"extended content description object\"" );
1162 for( i = 0; i < p_ec->i_count; i++ )
1163 msg_Dbg( s, " - '%s' = '%s'",
1165 p_ec->ppsz_value[i] );
1169 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1171 asf_object_extended_content_description_t *p_ec =
1172 (asf_object_extended_content_description_t *)p_obj;
1175 for( i = 0; i < p_ec->i_count; i++ )
1177 FREENULL( p_ec->ppsz_name[i] );
1178 FREENULL( p_ec->ppsz_value[i] );
1180 FREENULL( p_ec->ppsz_name );
1181 FREENULL( p_ec->ppsz_value );
1186 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1188 asf_object_XXX_t *p_XX =
1189 (asf_object_XXX_t *)p_obj;
1190 uint8_t *p_peek, *p_data;
1193 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1194 return VLC_EGENERIC;
1196 p_data = &p_peek[24];
1200 "Read \"XXX object\"" );
1204 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1206 asf_object_XXX_t *p_XX =
1207 (asf_object_XXX_t *)p_obj;
1217 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1218 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1220 } ASF_Object_Function [] =
1222 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1223 ASF_ReadObject_Header, ASF_FreeObject_Null },
1224 { &asf_object_data_guid, ASF_OBJECT_DATA,
1225 ASF_ReadObject_Data, ASF_FreeObject_Null },
1226 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1227 ASF_ReadObject_Index, ASF_FreeObject_Index },
1228 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1229 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1230 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1231 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1232 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1233 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1234 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1235 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1236 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1237 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1238 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1239 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1240 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1241 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1242 { &asf_object_language_list, ASF_OBJECT_OTHER,
1243 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1244 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1245 ASF_ReadObject_stream_bitrate_properties,
1246 ASF_FreeObject_stream_bitrate_properties },
1247 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1248 ASF_ReadObject_extended_stream_properties,
1249 ASF_FreeObject_extended_stream_properties },
1250 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1251 ASF_ReadObject_advanced_mutual_exclusion,
1252 ASF_FreeObject_advanced_mutual_exclusion },
1253 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1254 ASF_ReadObject_stream_prioritization,
1255 ASF_FreeObject_stream_prioritization },
1256 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1257 ASF_ReadObject_extended_content_description,
1258 ASF_FreeObject_extended_content_description },
1260 { &asf_object_null_guid, 0, NULL, NULL }
1263 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1264 asf_object_t *p_father )
1272 memset( p_obj, 0, sizeof( p_obj ) );
1274 if( ASF_ReadObjectCommon( s, p_obj ) )
1276 msg_Warn( s, "cannot read one asf object" );
1277 return VLC_EGENERIC;
1279 p_obj->common.p_father = p_father;
1280 p_obj->common.p_first = NULL;
1281 p_obj->common.p_next = NULL;
1282 p_obj->common.p_last = NULL;
1284 if( p_obj->common.i_object_size < 24 )
1286 msg_Warn( s, "found a corrupted asf object (size<24)" );
1287 return VLC_EGENERIC;
1290 /* find this object */
1291 for( i_index = 0; ; i_index++ )
1293 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1294 &p_obj->common.i_object_id ) ||
1295 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1296 &asf_object_null_guid ) )
1301 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1303 /* Now load this object */
1304 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1306 msg_Warn( s, "unknown asf object (not loaded)" );
1307 i_result = VLC_SUCCESS;
1311 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1313 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1316 /* link this object with father */
1317 if( p_father && ! i_result )
1319 if( p_father->common.p_first )
1321 p_father->common.p_last->common.p_next = p_obj;
1325 p_father->common.p_first = p_obj;
1327 p_father->common.p_last = p_obj;
1333 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1336 asf_object_t *p_child;
1338 if( !p_obj ) return;
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( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1354 &p_obj->common.i_object_id )||
1355 ASF_CmpGUID( 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 );
1382 /*****************************************************************************
1383 * ASF_ObjectDumpDebug:
1384 *****************************************************************************/
1388 const char *psz_name;
1389 } ASF_ObjectDumpDebugInfo[] =
1391 { &asf_object_header_guid, "Header" },
1392 { &asf_object_data_guid, "Data" },
1393 { &asf_object_index_guid, "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 Propoerties" },
1406 { &asf_object_padding, "Padding" },
1407 { &asf_object_extended_stream_properties, "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, int i_level )
1421 union asf_object_u *p_child;
1422 const char *psz_name;
1425 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1427 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1428 &p_node->i_object_id ) )
1431 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1433 memset( str, ' ', sizeof( str ) );
1434 for( i = 1; i < i_level; i++ )
1438 snprintf( str + 5*i_level, 1024,
1439 "+ '%s' GUID "GUID_FMT" size:"I64Fu"pos:"I64Fu,
1441 GUID_PRINT( p_node->i_object_id ),
1442 p_node->i_object_size, p_node->i_object_pos );
1444 msg_Dbg( p_obj, "%s", str );
1446 for( p_child = p_node->p_first; p_child != NULL;
1447 p_child = p_child->common.p_next )
1449 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1453 /*****************************************************************************
1454 * ASF_ReadObjetRoot : parse the entire stream/file
1455 *****************************************************************************/
1456 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1458 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1459 asf_object_t *p_obj;
1461 p_root->i_type = ASF_OBJECT_ROOT;
1462 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1463 p_root->i_object_pos = stream_Tell( s );
1464 p_root->i_object_size = 0;
1465 p_root->p_first = NULL;
1466 p_root->p_last = NULL;
1467 p_root->p_next = NULL;
1468 p_root->p_hdr = NULL;
1469 p_root->p_data = NULL;
1470 p_root->p_fp = NULL;
1471 p_root->p_index = NULL;
1472 p_root->p_metadata = NULL;
1476 p_obj = malloc( sizeof( asf_object_t ) );
1478 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1483 switch( p_obj->common.i_type )
1485 case( ASF_OBJECT_HEADER ):
1486 p_root->p_hdr = (asf_object_header_t*)p_obj;
1488 case( ASF_OBJECT_DATA ):
1489 p_root->p_data = (asf_object_data_t*)p_obj;
1491 case( ASF_OBJECT_INDEX ):
1492 p_root->p_index = (asf_object_index_t*)p_obj;
1495 msg_Warn( s, "unknow object found" );
1498 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1499 p_obj->common.i_object_size <= 50 )
1501 /* probably a dump of broadcasted asf */
1504 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1506 /* For unseekable stream it's enough to play */
1510 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1516 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1518 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1519 &asf_object_file_properties_guid, 0 );
1523 asf_object_t *p_hdr_ext =
1524 ASF_FindObject( p_root->p_hdr,
1525 &asf_object_header_extension_guid, 0 );
1531 p_root->p_metadata =
1532 ASF_FindObject( p_hdr_ext,
1533 &asf_object_metadata_guid, 0 );
1534 /* Special case for broken designed file format :( */
1535 i_ext_stream = ASF_CountObject( p_hdr_ext,
1536 &asf_object_extended_stream_properties );
1537 for( i = 0; i < i_ext_stream; i++ )
1539 asf_object_t *p_esp =
1540 ASF_FindObject( p_hdr_ext,
1541 &asf_object_extended_stream_properties, i );
1542 if( p_esp->ext_stream.p_sp )
1544 asf_object_t *p_sp =
1545 (asf_object_t*)p_esp->ext_stream.p_sp;
1547 /* Insert this p_sp */
1548 p_root->p_hdr->p_last->common.p_next = p_sp;
1549 p_root->p_hdr->p_last = p_sp;
1551 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1556 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1557 (asf_object_common_t*)p_root, 0 );
1560 msg_Warn( s, "cannot find file properties object" );
1564 ASF_FreeObjectRoot( s, p_root );
1568 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1570 asf_object_t *p_obj;
1572 p_obj = p_root->p_first;
1575 asf_object_t *p_next;
1576 p_next = p_obj->common.p_next;
1577 ASF_FreeObject( s, p_obj );
1583 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1586 asf_object_t *p_child;
1588 if( !p_obj ) return( 0 );
1591 p_child = p_obj->common.p_first;
1594 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1598 p_child = p_child->common.p_next;
1603 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1606 asf_object_t *p_child;
1608 p_child = p_obj->common.p_first;
1612 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1622 p_child = p_child->common.p_next;