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 static inline char *get_wstring( const uint8_t *p_data, size_t i_size )
705 char *psz_str = FromCharset( "UTF-16LE", p_data, i_size );
711 /* Microsoft should go to hell. This time the length give number of bytes
712 * and for the some others object, length give char16 count ... */
713 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
715 asf_object_content_description_t *p_cd = &p_obj->content_description;
716 const uint8_t *p_peek, *p_data;
717 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
719 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
722 p_data = p_peek + 24;
724 i_title = ASF_READ2();
725 i_artist = ASF_READ2();
726 i_copyright = ASF_READ2();
727 i_description = ASF_READ2();
728 i_rating = ASF_READ2();
730 if( !ASF_HAVE( i_title+i_artist+i_copyright+i_description+i_rating ) )
733 p_cd->psz_title = get_wstring( p_data, i_title );
734 p_cd->psz_artist = get_wstring( p_data, i_artist );
735 p_cd->psz_copyright = get_wstring( p_data, i_copyright );
736 p_cd->psz_description = get_wstring( p_data, i_description );
737 p_cd->psz_rating = get_wstring( p_data, i_rating );
741 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
745 p_cd->psz_description,
752 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
754 asf_object_content_description_t *p_cd = &p_obj->content_description;
756 FREENULL( p_cd->psz_title );
757 FREENULL( p_cd->psz_artist );
758 FREENULL( p_cd->psz_copyright );
759 FREENULL( p_cd->psz_description );
760 FREENULL( p_cd->psz_rating );
764 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
766 asf_object_language_list_t *p_ll = &p_obj->language_list;
767 const uint8_t *p_peek, *p_data;
771 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
774 p_data = &p_peek[24];
776 p_ll->i_language = ASF_READ2();
777 if( p_ll->i_language > 0 )
779 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
780 if( !p_ll->ppsz_language )
783 for( i = 0; i < p_ll->i_language; i++ )
787 p_ll->ppsz_language[i] = ASF_READS( ASF_READ1() );
789 p_ll->i_language = i;
793 msg_Dbg( s, "read \"language list object\" %d entries",
795 for( i = 0; i < p_ll->i_language; i++ )
796 msg_Dbg( s, " - '%s'",
797 p_ll->ppsz_language[i] );
802 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
804 asf_object_language_list_t *p_ll = &p_obj->language_list;
807 for( i = 0; i < p_ll->i_language; i++ )
808 FREENULL( p_ll->ppsz_language[i] );
809 FREENULL( p_ll->ppsz_language );
812 /* Stream bitrate properties */
813 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
816 asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate;
817 const uint8_t *p_peek, *p_data;
821 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
824 p_data = &p_peek[24];
826 p_sb->i_bitrate = ASF_READ2();
827 if( p_sb->i_bitrate > 127 )
828 p_sb->i_bitrate = 127; /* Buggy ? */
829 for( i = 0; i < p_sb->i_bitrate; i++ )
831 if( !ASF_HAVE(2 + 4) )
833 p_sb->bitrate[i].i_stream_number = ASF_READ2()& 0x7f;
834 p_sb->bitrate[i].i_avg_bitrate = ASF_READ4();
839 msg_Dbg( s,"read \"stream bitrate properties object\"" );
840 for( i = 0; i < p_sb->i_bitrate; i++ )
842 msg_Dbg( s," - stream=%d bitrate=%d",
843 p_sb->bitrate[i].i_stream_number,
844 p_sb->bitrate[i].i_avg_bitrate );
849 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
854 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
857 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
858 const uint8_t *p_peek, *p_data;
861 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
864 p_data = &p_peek[24];
866 p_esp->i_start_time = GetQWLE( &p_data[0] );
867 p_esp->i_end_time = GetQWLE( &p_data[8] );
868 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
869 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
870 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
871 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
872 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
873 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
874 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
875 p_esp->i_flags = GetDWLE( &p_data[44] );
876 p_esp->i_stream_number = GetWLE( &p_data[48] );
877 p_esp->i_language_index = GetWLE( &p_data[50] );
878 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
879 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
880 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
884 p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count,
886 p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
888 if( !p_esp->pi_stream_name_language ||
889 !p_esp->ppsz_stream_name )
891 free( p_esp->pi_stream_name_language );
892 free( p_esp->ppsz_stream_name );
895 for( i = 0; i < p_esp->i_stream_name_count; i++ )
897 if( !ASF_HAVE( 2+2 ) )
899 p_esp->pi_stream_name_language[i] = ASF_READ2();
900 p_esp->ppsz_stream_name[i] = ASF_READS( ASF_READ2() );
902 p_esp->i_stream_name_count = i;
904 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
906 ASF_SKIP( 16 ); // GUID
908 ASF_SKIP( ASF_READ4() );
912 if( p_data < &p_peek[i_peek] )
915 /* Cannot fail as peek succeed */
916 stream_Read( s, NULL, p_data - p_peek );
918 p_sp = malloc( sizeof( asf_object_t ) );
920 if( !p_sp || ASF_ReadObject( s, p_sp, NULL ) )
926 /* This p_sp will be inserted by ReadRoot later */
927 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
932 msg_Dbg( s, "read \"extended stream properties object\":" );
933 msg_Dbg( s, " - start=%"PRId64" end=%"PRId64,
934 p_esp->i_start_time, p_esp->i_end_time );
935 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
936 p_esp->i_data_bitrate,
937 p_esp->i_buffer_size,
938 p_esp->i_initial_buffer_fullness );
939 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
940 p_esp->i_alternate_data_bitrate,
941 p_esp->i_alternate_buffer_size,
942 p_esp->i_alternate_initial_buffer_fullness );
943 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
944 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
945 msg_Dbg( s, " - stream number=%d language=%d",
946 p_esp->i_stream_number, p_esp->i_language_index );
947 msg_Dbg( s, " - average time per frame=%"PRId64,
948 p_esp->i_average_time_per_frame );
949 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
950 for( i = 0; i < p_esp->i_stream_name_count; i++ )
951 msg_Dbg( s, " - lang id=%d name=%s",
952 p_esp->pi_stream_name_language[i],
953 p_esp->ppsz_stream_name[i] );
954 msg_Dbg( s, " - payload extension system count=%d",
955 p_esp->i_payload_extension_system_count );
959 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
961 asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
964 for( i = 0; i < p_esp->i_stream_name_count; i++ )
965 FREENULL( p_esp->ppsz_stream_name[i] );
966 FREENULL( p_esp->pi_stream_name_language );
967 FREENULL( p_esp->ppsz_stream_name );
971 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
974 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
975 const uint8_t *p_peek, *p_data;
979 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
982 p_data = &p_peek[24];
984 ASF_GetGUID( &p_ae->type, &p_data[0] );
986 p_ae->i_stream_number_count = ASF_READ2();
987 p_ae->pi_stream_number = calloc( p_ae->i_stream_number_count, sizeof(int) );
989 for( i = 0; i < p_ae->i_stream_number_count; i++ )
993 p_ae->pi_stream_number[i] = ASF_READ2();
995 p_ae->i_stream_number_count = i;
998 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
999 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1000 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1004 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1006 asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
1008 FREENULL( p_ae->pi_stream_number );
1012 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1013 asf_object_t *p_obj)
1015 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1016 const uint8_t *p_peek, *p_data;
1020 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1021 return VLC_EGENERIC;
1023 p_data = &p_peek[24];
1025 p_sp->i_priority_count = ASF_READ2();
1027 p_sp->pi_priority_flag = calloc( p_sp->i_priority_count, sizeof(int) );
1028 p_sp->pi_priority_stream_number =
1029 calloc( p_sp->i_priority_count, sizeof(int) );
1031 if( !p_sp->pi_priority_flag || !p_sp->pi_priority_stream_number )
1033 free( p_sp->pi_priority_flag );
1034 free( p_sp->pi_priority_stream_number );
1038 for( i = 0; i < p_sp->i_priority_count; i++ )
1040 if( !ASF_HAVE(2+2) )
1042 p_sp->pi_priority_stream_number[i] = ASF_READ2();
1043 p_sp->pi_priority_flag[i] = ASF_READ2();
1045 p_sp->i_priority_count = i;
1048 msg_Dbg( s, "read \"stream prioritization object\"" );
1049 for( i = 0; i < p_sp->i_priority_count; i++ )
1050 msg_Dbg( s, " - Stream:%d flags=0x%x",
1051 p_sp->pi_priority_stream_number[i],
1052 p_sp->pi_priority_flag[i] );
1056 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1058 asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
1060 FREENULL( p_sp->pi_priority_stream_number );
1061 FREENULL( p_sp->pi_priority_flag );
1065 static int ASF_ReadObject_extended_content_description( stream_t *s,
1066 asf_object_t *p_obj)
1068 asf_object_extended_content_description_t *p_ec =
1069 &p_obj->extended_content_description;
1070 const uint8_t *p_peek, *p_data;
1074 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1075 return VLC_EGENERIC;
1077 p_data = &p_peek[24];
1079 p_ec->i_count = ASF_READ2();
1080 p_ec->ppsz_name = calloc( p_ec->i_count, sizeof(char*) );
1081 p_ec->ppsz_value = calloc( p_ec->i_count, sizeof(char*) );
1082 if( !p_ec->ppsz_name || !p_ec->ppsz_value )
1084 free( p_ec->ppsz_name );
1085 free( p_ec->ppsz_value );
1088 for( i = 0; i < p_ec->i_count; i++ )
1093 if( !ASF_HAVE(2 + 2+2) )
1096 p_ec->ppsz_name[i] = ASF_READS( ASF_READ2() );
1099 i_type = ASF_READ2();
1100 i_size = ASF_READ2();
1104 p_ec->ppsz_value[i] = ASF_READS( i_size );
1106 else if( i_type == 1 )
1109 static const char hex[16] = "0123456789ABCDEF";
1112 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1113 if( p_ec->ppsz_value[i] )
1115 char *psz_value = p_ec->ppsz_value[i];
1116 for( j = 0; j < i_size; j++ )
1118 const uint8_t v = ASF_READ1();
1119 psz_value[2*j+0] = hex[v>>4];
1120 psz_value[2*j+1] = hex[v&0xf];
1122 psz_value[2*i_size] = '\0';
1125 else if( i_type == 2 )
1128 p_ec->ppsz_value[i] = strdup( ASF_READ1() ? "true" : "false" );
1131 else if( i_type == 3 )
1134 if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() ) == -1 )
1135 p_ec->ppsz_value[i] = NULL;
1137 else if( i_type == 4 )
1140 if( asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() ) == -1 )
1141 p_ec->ppsz_value[i] = NULL;
1143 else if( i_type == 5 )
1146 if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() ) == -1 )
1147 p_ec->ppsz_value[i] = NULL;
1151 p_ec->ppsz_value[i] = NULL;
1158 msg_Dbg( s, "read \"extended content description object\"" );
1159 for( i = 0; i < p_ec->i_count; i++ )
1160 msg_Dbg( s, " - '%s' = '%s'",
1162 p_ec->ppsz_value[i] );
1166 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1168 asf_object_extended_content_description_t *p_ec =
1169 &p_obj->extended_content_description;
1172 for( i = 0; i < p_ec->i_count; i++ )
1174 FREENULL( p_ec->ppsz_name[i] );
1175 FREENULL( p_ec->ppsz_value[i] );
1177 FREENULL( p_ec->ppsz_name );
1178 FREENULL( p_ec->ppsz_value );
1183 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1185 asf_object_XXX_t *p_XX =
1186 (asf_object_XXX_t *)p_obj;
1187 const uint8_t *p_peek;
1191 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1192 return VLC_EGENERIC;
1194 p_data = &p_peek[24];
1198 "Read \"XXX object\"" );
1202 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1204 asf_object_XXX_t *p_XX =
1205 (asf_object_XXX_t *)p_obj;
1215 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1216 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1218 } ASF_Object_Function [] =
1220 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1221 ASF_ReadObject_Header, ASF_FreeObject_Null },
1222 { &asf_object_data_guid, ASF_OBJECT_DATA,
1223 ASF_ReadObject_Data, ASF_FreeObject_Null },
1224 { &asf_object_simple_index_guid, ASF_OBJECT_INDEX,
1225 ASF_ReadObject_Index, ASF_FreeObject_Index },
1226 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1227 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1228 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1229 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1230 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1231 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1232 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1233 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1234 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1235 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1236 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1237 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1238 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1239 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1240 { &asf_object_language_list, ASF_OBJECT_OTHER,
1241 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1242 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1243 ASF_ReadObject_stream_bitrate_properties,
1244 ASF_FreeObject_stream_bitrate_properties },
1245 { &asf_object_extended_stream_properties_guid, ASF_OBJECT_OTHER,
1246 ASF_ReadObject_extended_stream_properties,
1247 ASF_FreeObject_extended_stream_properties },
1248 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1249 ASF_ReadObject_advanced_mutual_exclusion,
1250 ASF_FreeObject_advanced_mutual_exclusion },
1251 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1252 ASF_ReadObject_stream_prioritization,
1253 ASF_FreeObject_stream_prioritization },
1254 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1255 ASF_ReadObject_extended_content_description,
1256 ASF_FreeObject_extended_content_description },
1258 { &asf_object_null_guid, 0, NULL, NULL }
1261 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1262 asf_object_t *p_father )
1270 memset( p_obj, 0, sizeof( *p_obj ) );
1272 if( ASF_ReadObjectCommon( s, p_obj ) )
1274 msg_Warn( s, "cannot read one asf object" );
1275 return VLC_EGENERIC;
1277 p_obj->common.p_father = p_father;
1278 p_obj->common.p_first = NULL;
1279 p_obj->common.p_next = NULL;
1280 p_obj->common.p_last = NULL;
1282 if( p_obj->common.i_object_size < 24 )
1284 msg_Warn( s, "found a corrupted asf object (size<24)" );
1285 return VLC_EGENERIC;
1288 /* find this object */
1289 for( i_index = 0; ; i_index++ )
1291 if( guidcmp( ASF_Object_Function[i_index].p_id,
1292 &p_obj->common.i_object_id ) ||
1293 guidcmp( ASF_Object_Function[i_index].p_id,
1294 &asf_object_null_guid ) )
1299 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1301 /* Now load this object */
1302 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1304 msg_Warn( s, "unknown asf object (not loaded)" );
1305 i_result = VLC_SUCCESS;
1309 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1311 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1314 /* link this object with father */
1315 if( p_father && ! i_result )
1317 if( p_father->common.p_first )
1319 p_father->common.p_last->common.p_next = p_obj;
1323 p_father->common.p_first = p_obj;
1325 p_father->common.p_last = p_obj;
1331 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1334 asf_object_t *p_child;
1339 /* Free all child object */
1340 p_child = p_obj->common.p_first;
1343 asf_object_t *p_next;
1344 p_next = p_child->common.p_next;
1345 ASF_FreeObject( s, p_child );
1349 /* find this object */
1350 for( i_index = 0; ; i_index++ )
1352 if( guidcmp( ASF_Object_Function[i_index].p_id,
1353 &p_obj->common.i_object_id )||
1354 guidcmp( ASF_Object_Function[i_index].p_id,
1355 &asf_object_null_guid ) )
1361 /* Now free this object */
1362 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1365 "unknown asf object " GUID_FMT,
1366 GUID_PRINT( p_obj->common.i_object_id ) );
1372 "free asf object " GUID_FMT,
1373 GUID_PRINT( p_obj->common.i_object_id ) );
1375 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1380 /*****************************************************************************
1381 * ASF_ObjectDumpDebug:
1382 *****************************************************************************/
1386 const char *psz_name;
1387 } ASF_ObjectDumpDebugInfo[] =
1389 { &asf_object_header_guid, "Header" },
1390 { &asf_object_data_guid, "Data" },
1391 { &asf_object_index_guid, "Index" },
1392 { &asf_object_simple_index_guid, "Simple Index" },
1393 { &asf_object_file_properties_guid, "File Properties" },
1394 { &asf_object_stream_properties_guid, "Stream Properties" },
1395 { &asf_object_content_description_guid, "Content Description" },
1396 { &asf_object_header_extension_guid, "Header Extension" },
1397 { &asf_object_metadata_guid, "Metadata" },
1398 { &asf_object_codec_list_guid, "Codec List" },
1399 { &asf_object_marker_guid, "Marker" },
1400 { &asf_object_stream_type_audio, "Stream Type Audio" },
1401 { &asf_object_stream_type_video, "Stream Type Video" },
1402 { &asf_object_stream_type_command, "Stream Type Command" },
1403 { &asf_object_language_list, "Language List" },
1404 { &asf_object_stream_bitrate_properties, "Stream Bitrate Properties" },
1405 { &asf_object_padding, "Padding" },
1406 { &asf_object_extended_stream_properties_guid, "Extended Stream Properties" },
1407 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1408 { &asf_object_stream_prioritization, "Stream Prioritization" },
1409 { &asf_object_extended_content_description, "Extended content description"},
1411 { NULL, "Unknown" },
1415 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1416 asf_object_common_t *p_node, unsigned i_level )
1419 union asf_object_u *p_child;
1420 const char *psz_name;
1423 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1425 if( guidcmp( ASF_ObjectDumpDebugInfo[i].p_id,
1426 &p_node->i_object_id ) )
1429 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1432 if( i_level >= (sizeof(str) - 1)/5 )
1435 memset( str, ' ', sizeof( str ) );
1436 for( i = 1; i < i_level; i++ )
1440 snprintf( &str[5*i_level], sizeof(str) - 5*i_level,
1441 "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64,
1443 GUID_PRINT( p_node->i_object_id ),
1444 p_node->i_object_size, p_node->i_object_pos );
1446 msg_Dbg( p_obj, "%s", str );
1448 for( p_child = p_node->p_first; p_child != NULL;
1449 p_child = p_child->common.p_next )
1451 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1455 /*****************************************************************************
1456 * ASF_ReadObjetRoot : parse the entire stream/file
1457 *****************************************************************************/
1458 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1460 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1461 asf_object_t *p_obj;
1466 p_root->i_type = ASF_OBJECT_ROOT;
1467 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1468 p_root->i_object_pos = stream_Tell( s );
1469 p_root->i_object_size = 0;
1470 p_root->p_first = NULL;
1471 p_root->p_last = NULL;
1472 p_root->p_next = NULL;
1473 p_root->p_hdr = NULL;
1474 p_root->p_data = NULL;
1475 p_root->p_fp = NULL;
1476 p_root->p_index = NULL;
1477 p_root->p_metadata = NULL;
1481 p_obj = malloc( sizeof( asf_object_t ) );
1483 if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1488 switch( p_obj->common.i_type )
1490 case( ASF_OBJECT_HEADER ):
1491 p_root->p_hdr = (asf_object_header_t*)p_obj;
1493 case( ASF_OBJECT_DATA ):
1494 p_root->p_data = (asf_object_data_t*)p_obj;
1496 case( ASF_OBJECT_INDEX ):
1497 p_root->p_index = (asf_object_index_t*)p_obj;
1500 msg_Warn( s, "unknow object found" );
1503 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1504 p_obj->common.i_object_size <= 50 )
1506 /* probably a dump of broadcasted asf */
1509 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1511 /* For unseekable stream it's enough to play */
1515 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1519 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1521 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1522 &asf_object_file_properties_guid, 0 );
1526 asf_object_t *p_hdr_ext =
1527 ASF_FindObject( p_root->p_hdr,
1528 &asf_object_header_extension_guid, 0 );
1534 p_root->p_metadata =
1535 ASF_FindObject( p_hdr_ext,
1536 &asf_object_metadata_guid, 0 );
1537 /* Special case for broken designed file format :( */
1538 i_ext_stream = ASF_CountObject( p_hdr_ext,
1539 &asf_object_extended_stream_properties_guid );
1540 for( i = 0; i < i_ext_stream; i++ )
1542 asf_object_t *p_esp =
1543 ASF_FindObject( p_hdr_ext,
1544 &asf_object_extended_stream_properties_guid, i );
1545 if( p_esp->ext_stream.p_sp )
1547 asf_object_t *p_sp =
1548 (asf_object_t*)p_esp->ext_stream.p_sp;
1550 /* Insert this p_sp */
1551 p_root->p_hdr->p_last->common.p_next = p_sp;
1552 p_root->p_hdr->p_last = p_sp;
1554 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1559 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1560 (asf_object_common_t*)p_root, 0 );
1563 msg_Warn( s, "cannot find file properties object" );
1567 ASF_FreeObjectRoot( s, p_root );
1571 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1573 asf_object_t *p_obj;
1575 p_obj = p_root->p_first;
1578 asf_object_t *p_next;
1579 p_next = p_obj->common.p_next;
1580 ASF_FreeObject( s, p_obj );
1586 int ASF_CountObject( void *_p_obj, const guid_t *p_guid )
1589 asf_object_t *p_child, *p_obj;
1591 p_obj = (asf_object_t *)_p_obj;
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( void *_p_obj, const guid_t *p_guid,
1610 asf_object_t *p_child, *p_obj;
1612 p_obj = (asf_object_t *)_p_obj;
1613 p_child = p_obj->common.p_first;
1617 if( guidcmp( &p_child->common.i_object_id, p_guid ) )
1624 p_child = p_child->common.p_next;