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 <vlc_demux.h>
30 #include <vlc_codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
35 #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"
36 #define GUID_PRINT( guid ) \
40 (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
41 (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
43 /****************************************************************************
45 ****************************************************************************/
46 static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * );
48 /****************************************************************************
50 ****************************************************************************/
51 void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data )
53 p_guid->v1 = GetDWLE( p_data );
54 p_guid->v2 = GetWLE( p_data + 4);
55 p_guid->v3 = GetWLE( p_data + 6);
56 memcpy( p_guid->v4, p_data + 8, 8 );
59 int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
61 if( (p_guid1->v1 != p_guid2->v1 )||
62 (p_guid1->v2 != p_guid2->v2 )||
63 (p_guid1->v3 != p_guid2->v3 )||
64 ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
68 return( 1 ); /* match */
71 /****************************************************************************
73 ****************************************************************************/
74 static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
76 asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
77 const uint8_t *p_peek;
79 if( stream_Peek( s, &p_peek, 24 ) < 24 )
81 return( VLC_EGENERIC );
83 ASF_GetGUID( &p_common->i_object_id, p_peek );
84 p_common->i_object_size = GetQWLE( p_peek + 16 );
85 p_common->i_object_pos = stream_Tell( s );
86 p_common->p_next = NULL;
90 "found object guid: " GUID_FMT " size:"I64Fd,
91 GUID_PRINT( p_common->i_object_id ),
92 p_common->i_object_size );
95 return( VLC_SUCCESS );
98 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
103 if( ASF_ReadObjectCommon( s, &obj ) )
105 return( VLC_EGENERIC );
110 if( p_obj->common.i_object_size <= 0 )
114 if( p_obj->common.p_father &&
115 p_obj->common.p_father->common.i_object_size != 0 )
117 if( p_obj->common.p_father->common.i_object_pos +
118 p_obj->common.p_father->common.i_object_size <
119 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
120 /* 24 is min size of an object */
127 return stream_Seek( s, p_obj->common.i_object_pos +
128 p_obj->common.i_object_size );
131 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
136 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
138 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
139 asf_object_t *p_subobj;
141 const uint8_t *p_peek;
143 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
145 return( VLC_EGENERIC );
148 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
149 p_hdr->i_reserved1 = p_peek[28];
150 p_hdr->i_reserved2 = p_peek[29];
151 p_hdr->p_first = NULL;
152 p_hdr->p_last = NULL;
156 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
157 p_hdr->i_sub_object_count,
159 p_hdr->i_reserved2 );
162 /* Cannot fail as peek succeed */
163 stream_Read( s, NULL, 30 );
165 /* Now load sub object */
168 p_subobj = malloc( sizeof( asf_object_t ) );
170 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
175 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
183 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
185 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
187 const uint8_t *p_peek;
189 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
193 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
194 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
195 p_data->i_reserved = GetWLE( p_peek + 48 );
199 "read \"data object\" file_id:" GUID_FMT " total data packet:"
201 GUID_PRINT( p_data->i_file_id ),
202 p_data->i_total_data_packets,
203 p_data->i_reserved );
209 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
211 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
212 const uint8_t *p_peek;
215 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
216 (int)p_index->i_object_size )
222 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
223 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
224 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
225 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
226 p_index->index_entry = NULL;
230 "read \"index object\" file_id:" GUID_FMT
231 " index_entry_time_interval:"I64Fd" max_packet_count:%d "
232 "index_entry_count:%ld",
233 GUID_PRINT( p_index->i_file_id ),
234 p_index->i_index_entry_time_interval,
235 p_index->i_max_packet_count,
236 (long int)p_index->i_index_entry_count );
239 /* Sanity checking */
240 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
241 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
243 p_index->index_entry = malloc( sizeof(asf_index_entry_t) *
244 p_index->i_index_entry_count );
246 for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
249 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
250 p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
256 static void ASF_FreeObject_Index( asf_object_t *p_obj )
258 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
260 FREENULL( p_index->index_entry );
263 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
265 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
267 const uint8_t *p_peek;
269 if( ( i_peek = stream_Peek( s, &p_peek, 104) ) < 104 )
273 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
274 p_fp->i_file_size = GetQWLE( p_peek + 40 );
275 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
276 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
277 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
278 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
279 p_fp->i_preroll = GetQWLE( p_peek + 80 );
280 p_fp->i_flags = GetDWLE( p_peek + 88 );
281 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
282 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
283 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
287 "read \"file properties object\" file_id:" GUID_FMT
288 " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
289 I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
290 I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
292 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
293 p_fp->i_creation_date, p_fp->i_data_packets_count,
294 p_fp->i_play_duration, p_fp->i_send_duration,
295 p_fp->i_preroll, p_fp->i_flags,
296 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
297 p_fp->i_max_bitrate );
303 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
305 asf_object_metadata_t *p_meta =
306 (asf_object_metadata_t *)p_obj;
309 for( i = 0; i < p_meta->i_record_entries_count; i++ )
311 if( p_meta->record[i].psz_name ) free( p_meta->record[i].psz_name );
312 if( p_meta->record[i].p_data ) free( p_meta->record[i].p_data );
314 if( p_meta->record ) free( p_meta->record );
317 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
319 asf_object_metadata_t *p_meta =
320 (asf_object_metadata_t *)p_obj;
322 int i_peek, i_entries, i;
323 const uint8_t *p_peek;
328 p_meta->i_record_entries_count = 0;
331 if( stream_Peek( s, &p_peek, p_meta->i_object_size ) <
332 (int)p_meta->i_object_size )
338 i_entries = GetWLE( p_peek + i_peek ); i_peek += 2;
339 for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
341 asf_metadata_record_t record;
342 int i_name, i_data, j;
344 if( GetWLE( p_peek + i_peek ) != 0 )
346 ASF_FreeObject_metadata( p_obj );
351 record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2;
352 i_name = GetWLE( p_peek + i_peek ); i_peek += 2;
353 record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
354 i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
356 if( record.i_type > ASF_METADATA_TYPE_WORD ||
357 i_peek + i_data + i_name > (int)p_meta->i_object_size )
359 ASF_FreeObject_metadata( p_obj );
368 record.psz_name = malloc( i_name/2 + 1 );
369 for( j = 0; j < i_name/2; j++ )
371 record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
373 record.psz_name[j] = 0; /* just to make sure */
376 if( record.i_type == ASF_METADATA_TYPE_STRING )
378 record.p_data = malloc( i_data/2 + 1 );
379 record.i_data = i_data/2;
380 for( j = 0; j < i_data/2; j++ )
382 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
384 record.p_data[j] = 0; /* just to make sure */
386 else if( record.i_type == ASF_METADATA_TYPE_BYTE )
388 record.p_data = malloc( i_data );
389 record.i_data = i_data;
390 memcpy( record.p_data, p_peek + i_peek, i_data );
395 if( record.i_type == ASF_METADATA_TYPE_QWORD )
397 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
399 else if( record.i_type == ASF_METADATA_TYPE_DWORD )
401 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
405 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
409 p_meta->i_record_entries_count++;
411 realloc( p_meta->record, p_meta->i_record_entries_count *
412 sizeof(asf_metadata_record_t) );
413 memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
414 &record, sizeof(asf_metadata_record_t) );
419 "read \"metadata object\" %d entries",
420 p_meta->i_record_entries_count );
421 for( j = 0; j < p_meta->i_record_entries_count; j++ )
423 asf_metadata_record_t *p_rec = &p_meta->record[j];
425 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
426 msg_Dbg( s, " - %s=%s",
427 p_rec->psz_name, p_rec->p_data );
428 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
429 msg_Dbg( s, " - %s (%i bytes)",
430 p_rec->psz_name, p_rec->i_data );
432 msg_Dbg( s, " - %s="I64Fd,
433 p_rec->psz_name, p_rec->i_val );
440 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
442 asf_object_header_extension_t *p_he =
443 (asf_object_header_extension_t *)p_obj;
445 const uint8_t *p_peek;
447 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
451 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
452 p_he->i_reserved2 = GetWLE( p_peek + 40 );
453 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
454 if( p_he->i_header_extension_size )
456 p_he->p_header_extension_data =
457 malloc( p_he->i_header_extension_size );
458 memcpy( p_he->p_header_extension_data, p_peek + 46,
459 p_he->i_header_extension_size );
463 p_he->p_header_extension_data = NULL;
468 "read \"header extension object\" reserved1:" GUID_FMT
469 " reserved2:%d header_extension_size:%d",
470 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
471 p_he->i_header_extension_size );
474 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
476 /* Read the extension objects */
477 stream_Read( s, NULL, 46 );
480 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
482 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
488 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
497 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
499 asf_object_header_extension_t *p_he =
500 (asf_object_header_extension_t *)p_obj;
502 FREENULL( p_he->p_header_extension_data );
505 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
507 asf_object_stream_properties_t *p_sp =
508 (asf_object_stream_properties_t*)p_obj;
510 const uint8_t *p_peek;
512 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
517 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
518 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
519 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
520 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
521 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
522 p_sp->i_flags = GetWLE( p_peek + 72 );
523 p_sp->i_stream_number = p_sp->i_flags&0x07f;
524 p_sp->i_reserved = GetDWLE( p_peek + 74 );
527 if( p_sp->i_type_specific_data_length )
529 if( i_peek < p_sp->i_type_specific_data_length )
532 p_sp->p_type_specific_data =
533 malloc( p_sp->i_type_specific_data_length );
534 if( p_sp->p_type_specific_data == NULL )
537 memcpy( p_sp->p_type_specific_data, p_peek + 78,
538 p_sp->i_type_specific_data_length );
539 i_peek -= p_sp->i_type_specific_data_length;
543 p_sp->p_type_specific_data = NULL;
546 if( p_sp->i_error_correction_data_length )
548 if( i_peek < p_sp->i_error_correction_data_length )
550 free( p_sp->p_type_specific_data );
554 p_sp->p_error_correction_data =
555 malloc( p_sp->i_error_correction_data_length );
556 if( p_sp->p_error_correction_data == NULL )
558 free( p_sp->p_type_specific_data );
561 memcpy( p_sp->p_error_correction_data,
562 p_peek + 78 + p_sp->i_type_specific_data_length,
563 p_sp->i_error_correction_data_length );
567 p_sp->p_error_correction_data = NULL;
572 "read \"stream Properties object\" stream_type:" GUID_FMT
573 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
574 " type_specific_data_length:%d error_correction_data_length:%d"
575 " flags:0x%x stream_number:%d",
576 GUID_PRINT( p_sp->i_stream_type ),
577 GUID_PRINT( p_sp->i_error_correction_type ),
579 p_sp->i_type_specific_data_length,
580 p_sp->i_error_correction_data_length,
582 p_sp->i_stream_number );
588 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
590 asf_object_stream_properties_t *p_sp =
591 (asf_object_stream_properties_t*)p_obj;
593 FREENULL( p_sp->p_type_specific_data );
594 FREENULL( p_sp->p_error_correction_data );
598 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
600 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
602 const uint8_t *p_peek, *p_data;
604 unsigned int i_codec;
606 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
611 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
612 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
613 if( p_cl->i_codec_entries_count > 0 )
615 p_cl->codec = calloc( p_cl->i_codec_entries_count,
616 sizeof( asf_codec_entry_t ) );
617 memset( p_cl->codec, 0,
618 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
620 p_data = p_peek + 44;
621 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
623 #define codec p_cl->codec[i_codec]
626 codec.i_type = GetWLE( p_data ); p_data += 2;
628 i_len = GetWLE( p_data ); p_data += 2;
629 codec.psz_name = calloc( sizeof( char ), i_len + 1);
630 for( i = 0; i < i_len; i++ )
632 codec.psz_name[i] = GetWLE( p_data + 2*i );
634 codec.psz_name[i_len] = '\0';
638 i_len = GetWLE( p_data ); p_data += 2;
639 codec.psz_description = calloc( sizeof( char ), i_len + 1);
640 for( i = 0; i < i_len; i++ )
642 codec.psz_description[i] = GetWLE( p_data + 2*i );
644 codec.psz_description[i_len] = '\0';
647 /* opaque information */
648 codec.i_information_length = GetWLE( p_data ); p_data += 2;
649 if( codec.i_information_length > 0 )
651 codec.p_information = malloc( codec.i_information_length );
652 memcpy( codec.p_information, p_data, codec.i_information_length );
653 p_data += codec.i_information_length;
657 codec.p_information = NULL;
668 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
669 " codec_entries_count:%d",
670 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
672 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
674 #define codec p_cl->codec[i_codec]
675 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
676 "description:\"%s\" information_length:%d",
677 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
678 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
679 "audio" : "unknown" ),
680 codec.psz_name, codec.psz_description,
681 codec.i_information_length );
689 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
691 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
692 unsigned int i_codec;
694 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
696 #define codec p_cl->codec[i_codec]
697 FREENULL( codec.psz_name );
698 FREENULL( codec.psz_description );
699 FREENULL( codec.p_information );
702 FREENULL( p_cl->codec );
705 /* Microsoft should go to hell. This time the length give number of bytes
706 * and for the some others object, length give char16 count ... */
707 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
709 asf_object_content_description_t *p_cd =
710 (asf_object_content_description_t *)p_obj;
711 const uint8_t *p_peek, *p_data;
712 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
713 vlc_iconv_t cd = (vlc_iconv_t)-1;
714 const char *ib = NULL;
716 size_t i_ibl, i_obl, i_len;
718 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
719 if ( cd == (vlc_iconv_t)-1 ) {
720 msg_Err( s, "vlc_iconv_open failed" );
724 /* FIXME i_size*3 is the worst case. */
725 #define GETSTRINGW( psz_str, i_size ) \
726 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
727 ib = (const char *)p_data; \
731 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
734 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
738 p_data = p_peek + 24;
740 i_title = GetWLE( p_data ); p_data += 2;
741 i_artist= GetWLE( p_data ); p_data += 2;
742 i_copyright = GetWLE( p_data ); p_data += 2;
743 i_description = GetWLE( p_data ); p_data += 2;
744 i_rating = GetWLE( p_data ); p_data += 2;
746 GETSTRINGW( p_cd->psz_title, i_title );
747 GETSTRINGW( p_cd->psz_artist, i_artist );
748 GETSTRINGW( p_cd->psz_copyright, i_copyright );
749 GETSTRINGW( p_cd->psz_description, i_description );
750 GETSTRINGW( p_cd->psz_rating, i_rating );
756 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
760 p_cd->psz_description,
768 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
770 asf_object_content_description_t *p_cd =
771 (asf_object_content_description_t *)p_obj;
773 FREENULL( p_cd->psz_title );
774 FREENULL( p_cd->psz_artist );
775 FREENULL( p_cd->psz_copyright );
776 FREENULL( p_cd->psz_description );
777 FREENULL( p_cd->psz_rating );
781 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
783 asf_object_language_list_t *p_ll =
784 (asf_object_language_list_t*)p_obj;
785 const uint8_t *p_peek, *p_data;
789 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
792 p_data = &p_peek[24];
794 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
795 if( p_ll->i_language > 0 )
797 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
799 for( i = 0; i < p_ll->i_language; i++ )
802 int i_size = *p_data++;
805 psz = calloc( i_size/2 + 1, sizeof( char ) );
806 for( i_len = 0; i_len < i_size/2; i_len++ )
808 psz[i_len] = GetWLE( p_data + 2*i_len );
810 psz[i_size/2] = '\0'; \
813 p_ll->ppsz_language[i] = psz;
818 msg_Dbg( s, "read \"language list object\" %d entries",
820 for( i = 0; i < p_ll->i_language; i++ )
821 msg_Dbg( s, " - '%s'",
822 p_ll->ppsz_language[i] );
827 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
829 asf_object_language_list_t *p_ll =
830 (asf_object_language_list_t *)p_obj;
833 for( i = 0; i < p_ll->i_language; i++ )
834 FREENULL( p_ll->ppsz_language[i] );
835 FREENULL( p_ll->ppsz_language );
838 /* Stream bitrate properties */
839 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
842 asf_object_stream_bitrate_properties_t *p_sb =
843 (asf_object_stream_bitrate_properties_t *)p_obj;
844 const uint8_t *p_peek, *p_data;
848 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
851 p_data = &p_peek[24];
853 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
854 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
855 for( i = 0; i < p_sb->i_bitrate; i++ )
857 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
858 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
864 msg_Dbg( s,"read \"stream bitrate properties object\"" );
865 for( i = 0; i < p_sb->i_bitrate; i++ )
867 msg_Dbg( s," - stream=%d bitrate=%d",
868 p_sb->bitrate[i].i_stream_number,
869 p_sb->bitrate[i].i_avg_bitrate );
874 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
878 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
881 asf_object_extended_stream_properties_t *p_esp =
882 (asf_object_extended_stream_properties_t*)p_obj;
883 const uint8_t *p_peek, *p_data;
886 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
889 p_data = &p_peek[24];
891 p_esp->i_start_time = GetQWLE( &p_data[0] );
892 p_esp->i_end_time = GetQWLE( &p_data[8] );
893 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
894 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
895 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
896 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
897 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
898 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
899 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
900 p_esp->i_flags = GetDWLE( &p_data[44] );
901 p_esp->i_stream_number = GetWLE( &p_data[48] );
902 p_esp->i_language_index = GetWLE( &p_data[50] );
903 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
904 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
905 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
909 p_esp->pi_stream_name_language = calloc( sizeof(int),
910 p_esp->i_stream_name_count );
911 p_esp->ppsz_stream_name = calloc( sizeof(char*),
912 p_esp->i_stream_name_count );
913 for( i = 0; i < p_esp->i_stream_name_count; i++ )
919 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
920 i_size = GetWLE( &p_data[2] );
923 psz = calloc( i_size/2 + 1, sizeof( char ) );
924 for( i_len = 0; i_len < i_size/2; i_len++ )
926 psz[i_len] = GetWLE( p_data + 2*i_len );
928 psz[i_size/2] = '\0'; \
931 p_esp->ppsz_stream_name[i] = psz;
934 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
937 int i_size = GetDWLE( &p_data[16 + 2] );
939 p_data += 16+2+4+i_size;
943 if( p_data < &p_peek[i_peek] )
946 /* Cannot fail as peek succeed */
947 stream_Read( s, NULL, p_data - p_peek );
949 p_sp = malloc( sizeof( asf_object_t ) );
951 if( ASF_ReadObject( s, p_sp, NULL ) )
957 /* This p_sp will be inserted by ReadRoot later */
958 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
963 msg_Dbg( s, "read \"extended stream properties object\":" );
964 msg_Dbg( s, " - start="I64Fd" end="I64Fd,
965 p_esp->i_start_time, p_esp->i_end_time );
966 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
967 p_esp->i_data_bitrate,
968 p_esp->i_buffer_size,
969 p_esp->i_initial_buffer_fullness );
970 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
971 p_esp->i_alternate_data_bitrate,
972 p_esp->i_alternate_buffer_size,
973 p_esp->i_alternate_initial_buffer_fullness );
974 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
975 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
976 msg_Dbg( s, " - stream number=%d language=%d",
977 p_esp->i_stream_number, p_esp->i_language_index );
978 msg_Dbg( s, " - average time per frame="I64Fd,
979 p_esp->i_average_time_per_frame );
980 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
981 for( i = 0; i < p_esp->i_stream_name_count; i++ )
982 msg_Dbg( s, " - lang id=%d name=%s",
983 p_esp->pi_stream_name_language[i],
984 p_esp->ppsz_stream_name[i] );
985 msg_Dbg( s, " - payload extension system count=%d",
986 p_esp->i_payload_extension_system_count );
990 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
992 asf_object_extended_stream_properties_t *p_esp =
993 (asf_object_extended_stream_properties_t *)p_obj;
996 for( i = 0; i < p_esp->i_stream_name_count; i++ )
997 FREENULL( p_esp->ppsz_stream_name[i] );
998 FREENULL( p_esp->pi_stream_name_language );
999 FREENULL( p_esp->ppsz_stream_name );
1003 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
1004 asf_object_t *p_obj)
1006 asf_object_advanced_mutual_exclusion_t *p_ae =
1007 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1008 const uint8_t *p_peek, *p_data;
1012 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1013 return VLC_EGENERIC;
1015 p_data = &p_peek[24];
1017 ASF_GetGUID( &p_ae->type, &p_data[0] );
1018 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1021 p_ae->pi_stream_number = calloc( sizeof(int),
1022 p_ae->i_stream_number_count );
1023 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1025 p_ae->pi_stream_number[i] = GetWLE( p_data );
1030 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1031 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1032 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1036 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1038 asf_object_advanced_mutual_exclusion_t *p_ae =
1039 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1041 FREENULL( p_ae->pi_stream_number );
1045 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1046 asf_object_t *p_obj)
1048 asf_object_stream_prioritization_t *p_sp =
1049 (asf_object_stream_prioritization_t *)p_obj;
1050 const uint8_t *p_peek, *p_data;
1054 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1055 return VLC_EGENERIC;
1057 p_data = &p_peek[24];
1059 p_sp->i_priority_count = GetWLE( &p_data[0] );
1062 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1063 p_sp->pi_priority_stream_number =
1064 calloc( sizeof(int), p_sp->i_priority_count );
1066 for( i = 0; i < p_sp->i_priority_count; i++ )
1068 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1069 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1072 msg_Dbg( s, "read \"stream prioritization object\"" );
1073 for( i = 0; i < p_sp->i_priority_count; i++ )
1074 msg_Dbg( s, " - Stream:%d flags=0x%x",
1075 p_sp->pi_priority_stream_number[i],
1076 p_sp->pi_priority_flag[i] );
1080 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1082 asf_object_stream_prioritization_t *p_sp =
1083 (asf_object_stream_prioritization_t *)p_obj;
1085 FREENULL( p_sp->pi_priority_stream_number );
1086 FREENULL( p_sp->pi_priority_flag );
1090 static int ASF_ReadObject_extended_content_description( stream_t *s,
1091 asf_object_t *p_obj)
1093 asf_object_extended_content_description_t *p_ec =
1094 (asf_object_extended_content_description_t *)p_obj;
1095 const uint8_t *p_peek, *p_data;
1099 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1100 return VLC_EGENERIC;
1102 p_data = &p_peek[24];
1104 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1105 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1106 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1107 for( i = 0; i < p_ec->i_count; i++ )
1112 #define GETSTRINGW( psz_str, i_size ) \
1113 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1114 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1116 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1118 psz_str[i_size/2] = '\0';
1120 i_size = GetWLE( p_data ); p_data += 2;
1121 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1125 i_type = GetWLE( p_data ); p_data += 2;
1126 i_size = GetWLE( p_data ); p_data += 2;
1129 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1131 else if( i_type == 1 )
1135 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1136 for( j = 0; j < i_size; j++ )
1138 static const char hex[16] = "0123456789ABCDEF";
1139 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1140 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1142 p_ec->ppsz_value[i][2*i_size] = '\0';
1144 else if( i_type == 2 )
1147 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1149 else if( i_type == 3 )
1152 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1154 else if( i_type == 4 )
1157 asprintf( &p_ec->ppsz_value[i], I64Fd, GetQWLE(p_data));
1159 else if( i_type == 5 )
1162 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1165 p_ec->ppsz_value[i] = NULL;
1176 msg_Dbg( s, "read \"extended content description object\"" );
1177 for( i = 0; i < p_ec->i_count; i++ )
1178 msg_Dbg( s, " - '%s' = '%s'",
1180 p_ec->ppsz_value[i] );
1184 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1186 asf_object_extended_content_description_t *p_ec =
1187 (asf_object_extended_content_description_t *)p_obj;
1190 for( i = 0; i < p_ec->i_count; i++ )
1192 FREENULL( p_ec->ppsz_name[i] );
1193 FREENULL( p_ec->ppsz_value[i] );
1195 FREENULL( p_ec->ppsz_name );
1196 FREENULL( p_ec->ppsz_value );
1201 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1203 asf_object_XXX_t *p_XX =
1204 (asf_object_XXX_t *)p_obj;
1205 const uint8_t *p_peek;
1209 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1210 return VLC_EGENERIC;
1212 p_data = &p_peek[24];
1216 "Read \"XXX object\"" );
1220 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1222 asf_object_XXX_t *p_XX =
1223 (asf_object_XXX_t *)p_obj;
1233 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1234 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1236 } ASF_Object_Function [] =
1238 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1239 ASF_ReadObject_Header, ASF_FreeObject_Null },
1240 { &asf_object_data_guid, ASF_OBJECT_DATA,
1241 ASF_ReadObject_Data, ASF_FreeObject_Null },
1242 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1243 ASF_ReadObject_Index, ASF_FreeObject_Index },
1244 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1245 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1246 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1247 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1248 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1249 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1250 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1251 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1252 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1253 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1254 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1255 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1256 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1257 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1258 { &asf_object_language_list, ASF_OBJECT_OTHER,
1259 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1260 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1261 ASF_ReadObject_stream_bitrate_properties,
1262 ASF_FreeObject_stream_bitrate_properties },
1263 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1264 ASF_ReadObject_extended_stream_properties,
1265 ASF_FreeObject_extended_stream_properties },
1266 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1267 ASF_ReadObject_advanced_mutual_exclusion,
1268 ASF_FreeObject_advanced_mutual_exclusion },
1269 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1270 ASF_ReadObject_stream_prioritization,
1271 ASF_FreeObject_stream_prioritization },
1272 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1273 ASF_ReadObject_extended_content_description,
1274 ASF_FreeObject_extended_content_description },
1276 { &asf_object_null_guid, 0, NULL, NULL }
1279 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1280 asf_object_t *p_father )
1288 memset( p_obj, 0, sizeof( p_obj ) );
1290 if( ASF_ReadObjectCommon( s, p_obj ) )
1292 msg_Warn( s, "cannot read one asf object" );
1293 return VLC_EGENERIC;
1295 p_obj->common.p_father = p_father;
1296 p_obj->common.p_first = NULL;
1297 p_obj->common.p_next = NULL;
1298 p_obj->common.p_last = NULL;
1300 if( p_obj->common.i_object_size < 24 )
1302 msg_Warn( s, "found a corrupted asf object (size<24)" );
1303 return VLC_EGENERIC;
1306 /* find this object */
1307 for( i_index = 0; ; i_index++ )
1309 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1310 &p_obj->common.i_object_id ) ||
1311 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1312 &asf_object_null_guid ) )
1317 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1319 /* Now load this object */
1320 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1322 msg_Warn( s, "unknown asf object (not loaded)" );
1323 i_result = VLC_SUCCESS;
1327 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1329 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1332 /* link this object with father */
1333 if( p_father && ! i_result )
1335 if( p_father->common.p_first )
1337 p_father->common.p_last->common.p_next = p_obj;
1341 p_father->common.p_first = p_obj;
1343 p_father->common.p_last = p_obj;
1349 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1352 asf_object_t *p_child;
1354 if( !p_obj ) return;
1356 /* Free all child object */
1357 p_child = p_obj->common.p_first;
1360 asf_object_t *p_next;
1361 p_next = p_child->common.p_next;
1362 ASF_FreeObject( s, p_child );
1366 /* find this object */
1367 for( i_index = 0; ; i_index++ )
1369 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1370 &p_obj->common.i_object_id )||
1371 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1372 &asf_object_null_guid ) )
1378 /* Now free this object */
1379 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1382 "unknown asf object " GUID_FMT,
1383 GUID_PRINT( p_obj->common.i_object_id ) );
1389 "free asf object " GUID_FMT,
1390 GUID_PRINT( p_obj->common.i_object_id ) );
1392 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1398 /*****************************************************************************
1399 * ASF_ObjectDumpDebug:
1400 *****************************************************************************/
1404 const char *psz_name;
1405 } ASF_ObjectDumpDebugInfo[] =
1407 { &asf_object_header_guid, "Header" },
1408 { &asf_object_data_guid, "Data" },
1409 { &asf_object_index_guid, "Index" },
1410 { &asf_object_file_properties_guid, "File Properties" },
1411 { &asf_object_stream_properties_guid, "Stream Properties" },
1412 { &asf_object_content_description_guid, "Content Description" },
1413 { &asf_object_header_extension_guid, "Header Extension" },
1414 { &asf_object_metadata_guid, "Metadata" },
1415 { &asf_object_codec_list_guid, "Codec List" },
1416 { &asf_object_marker_guid, "Marker" },
1417 { &asf_object_stream_type_audio, "Stream Type Audio" },
1418 { &asf_object_stream_type_video, "Stream Type Video" },
1419 { &asf_object_stream_type_command, "Stream Type Command" },
1420 { &asf_object_language_list, "Language List" },
1421 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1422 { &asf_object_padding, "Padding" },
1423 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1424 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1425 { &asf_object_stream_prioritization, "Stream Prioritization" },
1426 { &asf_object_extended_content_description, "Extended content description"},
1428 { NULL, "Unknown" },
1432 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1433 asf_object_common_t *p_node, int i_level )
1437 union asf_object_u *p_child;
1438 const char *psz_name;
1441 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1443 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1444 &p_node->i_object_id ) )
1447 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1449 memset( str, ' ', sizeof( str ) );
1450 for( i = 1; i < i_level; i++ )
1454 snprintf( str + 5*i_level, 1024,
1455 "+ '%s' GUID "GUID_FMT" size:"I64Fu"pos:"I64Fu,
1457 GUID_PRINT( p_node->i_object_id ),
1458 p_node->i_object_size, p_node->i_object_pos );
1460 msg_Dbg( p_obj, "%s", str );
1462 for( p_child = p_node->p_first; p_child != NULL;
1463 p_child = p_child->common.p_next )
1465 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1469 /*****************************************************************************
1470 * ASF_ReadObjetRoot : parse the entire stream/file
1471 *****************************************************************************/
1472 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1474 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1475 asf_object_t *p_obj;
1477 p_root->i_type = ASF_OBJECT_ROOT;
1478 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1479 p_root->i_object_pos = stream_Tell( s );
1480 p_root->i_object_size = 0;
1481 p_root->p_first = NULL;
1482 p_root->p_last = NULL;
1483 p_root->p_next = NULL;
1484 p_root->p_hdr = NULL;
1485 p_root->p_data = NULL;
1486 p_root->p_fp = NULL;
1487 p_root->p_index = NULL;
1488 p_root->p_metadata = NULL;
1492 p_obj = malloc( sizeof( asf_object_t ) );
1494 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1499 switch( p_obj->common.i_type )
1501 case( ASF_OBJECT_HEADER ):
1502 p_root->p_hdr = (asf_object_header_t*)p_obj;
1504 case( ASF_OBJECT_DATA ):
1505 p_root->p_data = (asf_object_data_t*)p_obj;
1507 case( ASF_OBJECT_INDEX ):
1508 p_root->p_index = (asf_object_index_t*)p_obj;
1511 msg_Warn( s, "unknow object found" );
1514 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1515 p_obj->common.i_object_size <= 50 )
1517 /* probably a dump of broadcasted asf */
1520 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1522 /* For unseekable stream it's enough to play */
1526 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1532 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1534 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1535 &asf_object_file_properties_guid, 0 );
1539 asf_object_t *p_hdr_ext =
1540 ASF_FindObject( p_root->p_hdr,
1541 &asf_object_header_extension_guid, 0 );
1547 p_root->p_metadata =
1548 ASF_FindObject( p_hdr_ext,
1549 &asf_object_metadata_guid, 0 );
1550 /* Special case for broken designed file format :( */
1551 i_ext_stream = ASF_CountObject( p_hdr_ext,
1552 &asf_object_extended_stream_properties );
1553 for( i = 0; i < i_ext_stream; i++ )
1555 asf_object_t *p_esp =
1556 ASF_FindObject( p_hdr_ext,
1557 &asf_object_extended_stream_properties, i );
1558 if( p_esp->ext_stream.p_sp )
1560 asf_object_t *p_sp =
1561 (asf_object_t*)p_esp->ext_stream.p_sp;
1563 /* Insert this p_sp */
1564 p_root->p_hdr->p_last->common.p_next = p_sp;
1565 p_root->p_hdr->p_last = p_sp;
1567 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1572 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1573 (asf_object_common_t*)p_root, 0 );
1576 msg_Warn( s, "cannot find file properties object" );
1580 ASF_FreeObjectRoot( s, p_root );
1584 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1586 asf_object_t *p_obj;
1588 p_obj = p_root->p_first;
1591 asf_object_t *p_next;
1592 p_next = p_obj->common.p_next;
1593 ASF_FreeObject( s, p_obj );
1599 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1602 asf_object_t *p_child;
1604 if( !p_obj ) return( 0 );
1607 p_child = p_obj->common.p_first;
1610 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1614 p_child = p_child->common.p_next;
1619 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1622 asf_object_t *p_child;
1624 p_child = p_obj->common.p_first;
1628 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1638 p_child = p_child->common.p_next;