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 *****************************************************************************/
29 #include <vlc_common.h>
32 #include <vlc_demux.h>
34 #include <vlc_codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
39 #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"
40 #define GUID_PRINT( guid ) \
44 (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
45 (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
47 /****************************************************************************
49 ****************************************************************************/
50 static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * );
52 /****************************************************************************
54 ****************************************************************************/
55 void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data )
57 p_guid->v1 = GetDWLE( p_data );
58 p_guid->v2 = GetWLE( p_data + 4);
59 p_guid->v3 = GetWLE( p_data + 6);
60 memcpy( p_guid->v4, p_data + 8, 8 );
63 int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
65 if( (p_guid1->v1 != p_guid2->v1 )||
66 (p_guid1->v2 != p_guid2->v2 )||
67 (p_guid1->v3 != p_guid2->v3 )||
68 ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
72 return( 1 ); /* match */
75 /****************************************************************************
77 ****************************************************************************/
78 static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
80 asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
81 const uint8_t *p_peek;
83 if( stream_Peek( s, &p_peek, 24 ) < 24 )
85 return( VLC_EGENERIC );
87 ASF_GetGUID( &p_common->i_object_id, p_peek );
88 p_common->i_object_size = GetQWLE( p_peek + 16 );
89 p_common->i_object_pos = stream_Tell( s );
90 p_common->p_next = NULL;
94 "found object guid: " GUID_FMT " size:%"PRId64,
95 GUID_PRINT( p_common->i_object_id ),
96 p_common->i_object_size );
99 return( VLC_SUCCESS );
102 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
107 if( ASF_ReadObjectCommon( s, &obj ) )
109 return( VLC_EGENERIC );
114 if( p_obj->common.i_object_size <= 0 )
118 if( p_obj->common.p_father &&
119 p_obj->common.p_father->common.i_object_size != 0 )
121 if( p_obj->common.p_father->common.i_object_pos +
122 p_obj->common.p_father->common.i_object_size <
123 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
124 /* 24 is min size of an object */
131 return stream_Seek( s, p_obj->common.i_object_pos +
132 p_obj->common.i_object_size );
135 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
141 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
143 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
144 asf_object_t *p_subobj;
146 const uint8_t *p_peek;
148 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
150 return( VLC_EGENERIC );
153 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
154 p_hdr->i_reserved1 = p_peek[28];
155 p_hdr->i_reserved2 = p_peek[29];
156 p_hdr->p_first = NULL;
157 p_hdr->p_last = NULL;
161 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
162 p_hdr->i_sub_object_count,
164 p_hdr->i_reserved2 );
167 /* Cannot fail as peek succeed */
168 stream_Seek( s, stream_Tell( s ) + 30 );
170 /* Now load sub object */
173 p_subobj = malloc( sizeof( asf_object_t ) );
175 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
180 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
188 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
190 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
192 const uint8_t *p_peek;
194 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
198 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
199 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
200 p_data->i_reserved = GetWLE( p_peek + 48 );
204 "read \"data object\" file_id:" GUID_FMT " total data packet:"
205 "%"PRId64" reserved:%d",
206 GUID_PRINT( p_data->i_file_id ),
207 p_data->i_total_data_packets,
208 p_data->i_reserved );
214 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
216 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
217 const uint8_t *p_peek;
220 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
221 (int)p_index->i_object_size )
227 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
228 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
229 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
230 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
231 p_index->index_entry = NULL;
235 "read \"index object\" file_id:" GUID_FMT
236 " index_entry_time_interval:%"PRId64" max_packet_count:%d "
237 "index_entry_count:%ld",
238 GUID_PRINT( p_index->i_file_id ),
239 p_index->i_index_entry_time_interval,
240 p_index->i_max_packet_count,
241 (long int)p_index->i_index_entry_count );
244 /* Sanity checking */
245 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
246 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
248 p_index->index_entry = malloc( sizeof(asf_index_entry_t) *
249 p_index->i_index_entry_count );
251 for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
254 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
255 p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
261 static void ASF_FreeObject_Index( asf_object_t *p_obj )
263 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
265 FREENULL( p_index->index_entry );
268 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
270 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
272 const uint8_t *p_peek;
274 if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 )
278 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
279 p_fp->i_file_size = GetQWLE( p_peek + 40 );
280 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
281 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
282 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
283 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
284 p_fp->i_preroll = GetQWLE( p_peek + 80 );
285 p_fp->i_flags = GetDWLE( p_peek + 88 );
286 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
287 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
288 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
292 "read \"file properties object\" file_id:" GUID_FMT
293 " file_size:%"PRId64" creation_date:%"PRId64" data_packets_count:"
294 "%"PRId64" play_duration:%"PRId64" send_duration:%"PRId64" preroll:%"PRId64
295 " flags:%d min_data_packet_size:%d "
296 " max_data_packet_size:%d max_bitrate:%d",
297 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
298 p_fp->i_creation_date, p_fp->i_data_packets_count,
299 p_fp->i_play_duration, p_fp->i_send_duration,
300 p_fp->i_preroll, p_fp->i_flags,
301 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
302 p_fp->i_max_bitrate );
308 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
310 asf_object_metadata_t *p_meta =
311 (asf_object_metadata_t *)p_obj;
314 for( i = 0; i < p_meta->i_record_entries_count; i++ )
316 free( p_meta->record[i].psz_name );
317 free( p_meta->record[i].p_data );
319 free( p_meta->record );
322 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
324 asf_object_metadata_t *p_meta =
325 (asf_object_metadata_t *)p_obj;
327 int i_peek, i_entries, i;
328 const uint8_t *p_peek;
333 p_meta->i_record_entries_count = 0;
336 if( stream_Peek( s, &p_peek, p_meta->i_object_size ) <
337 (int)p_meta->i_object_size )
343 i_entries = GetWLE( p_peek + i_peek ); i_peek += 2;
344 for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
346 asf_metadata_record_t record;
347 int i_name, i_data, j;
349 if( GetWLE( p_peek + i_peek ) != 0 )
351 ASF_FreeObject_metadata( p_obj );
356 record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2;
357 i_name = GetWLE( p_peek + i_peek ); i_peek += 2;
358 record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
359 i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
361 if( record.i_type > ASF_METADATA_TYPE_WORD ||
362 i_peek + i_data + i_name > (int)p_meta->i_object_size )
364 ASF_FreeObject_metadata( p_obj );
373 record.psz_name = malloc( i_name/2 + 1 );
374 for( j = 0; j < i_name/2; j++ )
376 record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
378 record.psz_name[j] = 0; /* just to make sure */
381 if( record.i_type == ASF_METADATA_TYPE_STRING )
383 record.p_data = malloc( i_data/2 + 1 );
384 record.i_data = i_data/2;
385 for( j = 0; j < i_data/2; j++ )
387 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
389 record.p_data[j] = 0; /* just to make sure */
391 else if( record.i_type == ASF_METADATA_TYPE_BYTE )
393 record.p_data = malloc( i_data );
394 record.i_data = i_data;
395 memcpy( record.p_data, p_peek + i_peek, i_data );
400 if( record.i_type == ASF_METADATA_TYPE_QWORD )
402 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
404 else if( record.i_type == ASF_METADATA_TYPE_DWORD )
406 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
410 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
414 p_meta->i_record_entries_count++;
416 realloc( p_meta->record, p_meta->i_record_entries_count *
417 sizeof(asf_metadata_record_t) );
418 memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
419 &record, sizeof(asf_metadata_record_t) );
424 "read \"metadata object\" %d entries",
425 p_meta->i_record_entries_count );
426 for( j = 0; j < p_meta->i_record_entries_count; j++ )
428 asf_metadata_record_t *p_rec = &p_meta->record[j];
430 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
431 msg_Dbg( s, " - %s=%s",
432 p_rec->psz_name, p_rec->p_data );
433 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
434 msg_Dbg( s, " - %s (%i bytes)",
435 p_rec->psz_name, p_rec->i_data );
437 msg_Dbg( s, " - %s=%"PRId64,
438 p_rec->psz_name, p_rec->i_val );
445 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
447 asf_object_header_extension_t *p_he =
448 (asf_object_header_extension_t *)p_obj;
450 const uint8_t *p_peek;
452 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
456 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
457 p_he->i_reserved2 = GetWLE( p_peek + 40 );
458 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
459 if( p_he->i_header_extension_size )
461 p_he->p_header_extension_data =
462 malloc( p_he->i_header_extension_size );
463 memcpy( p_he->p_header_extension_data, p_peek + 46,
464 p_he->i_header_extension_size );
468 p_he->p_header_extension_data = NULL;
473 "read \"header extension object\" reserved1:" GUID_FMT
474 " reserved2:%d header_extension_size:%d",
475 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
476 p_he->i_header_extension_size );
479 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
481 /* Read the extension objects */
482 stream_Read( s, NULL, 46 );
485 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
487 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
493 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
502 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
504 asf_object_header_extension_t *p_he =
505 (asf_object_header_extension_t *)p_obj;
507 FREENULL( p_he->p_header_extension_data );
510 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
512 asf_object_stream_properties_t *p_sp =
513 (asf_object_stream_properties_t*)p_obj;
515 const uint8_t *p_peek;
517 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
522 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
523 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
524 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
525 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
526 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
527 p_sp->i_flags = GetWLE( p_peek + 72 );
528 p_sp->i_stream_number = p_sp->i_flags&0x07f;
529 p_sp->i_reserved = GetDWLE( p_peek + 74 );
532 if( p_sp->i_type_specific_data_length )
534 if( i_peek < p_sp->i_type_specific_data_length )
537 p_sp->p_type_specific_data =
538 malloc( p_sp->i_type_specific_data_length );
539 if( p_sp->p_type_specific_data == NULL )
542 memcpy( p_sp->p_type_specific_data, p_peek + 78,
543 p_sp->i_type_specific_data_length );
544 i_peek -= p_sp->i_type_specific_data_length;
548 p_sp->p_type_specific_data = NULL;
551 if( p_sp->i_error_correction_data_length )
553 if( i_peek < p_sp->i_error_correction_data_length )
555 free( p_sp->p_type_specific_data );
559 p_sp->p_error_correction_data =
560 malloc( p_sp->i_error_correction_data_length );
561 if( p_sp->p_error_correction_data == NULL )
563 free( p_sp->p_type_specific_data );
566 memcpy( p_sp->p_error_correction_data,
567 p_peek + 78 + p_sp->i_type_specific_data_length,
568 p_sp->i_error_correction_data_length );
572 p_sp->p_error_correction_data = NULL;
577 "read \"stream Properties object\" stream_type:" GUID_FMT
578 " error_correction_type:" GUID_FMT " time_offset:%"PRId64
579 " type_specific_data_length:%d error_correction_data_length:%d"
580 " flags:0x%x stream_number:%d",
581 GUID_PRINT( p_sp->i_stream_type ),
582 GUID_PRINT( p_sp->i_error_correction_type ),
584 p_sp->i_type_specific_data_length,
585 p_sp->i_error_correction_data_length,
587 p_sp->i_stream_number );
593 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
595 asf_object_stream_properties_t *p_sp =
596 (asf_object_stream_properties_t*)p_obj;
598 FREENULL( p_sp->p_type_specific_data );
599 FREENULL( p_sp->p_error_correction_data );
603 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
605 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
607 const uint8_t *p_peek, *p_data;
609 unsigned int i_codec;
611 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
616 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
617 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
618 if( p_cl->i_codec_entries_count > 0 )
620 p_cl->codec = calloc( p_cl->i_codec_entries_count,
621 sizeof( asf_codec_entry_t ) );
622 memset( p_cl->codec, 0,
623 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
625 p_data = p_peek + 44;
626 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
628 #define codec p_cl->codec[i_codec]
631 codec.i_type = GetWLE( p_data ); p_data += 2;
633 i_len = GetWLE( p_data ); p_data += 2;
634 codec.psz_name = calloc( sizeof( char ), i_len + 1);
635 for( i = 0; i < i_len; i++ )
637 codec.psz_name[i] = GetWLE( p_data + 2*i );
639 codec.psz_name[i_len] = '\0';
643 i_len = GetWLE( p_data ); p_data += 2;
644 codec.psz_description = calloc( sizeof( char ), i_len + 1);
645 for( i = 0; i < i_len; i++ )
647 codec.psz_description[i] = GetWLE( p_data + 2*i );
649 codec.psz_description[i_len] = '\0';
652 /* opaque information */
653 codec.i_information_length = GetWLE( p_data ); p_data += 2;
654 if( codec.i_information_length > 0 )
656 codec.p_information = malloc( codec.i_information_length );
657 memcpy( codec.p_information, p_data, codec.i_information_length );
658 p_data += codec.i_information_length;
662 codec.p_information = NULL;
673 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
674 " codec_entries_count:%d",
675 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
677 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
679 #define codec p_cl->codec[i_codec]
680 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
681 "description:\"%s\" information_length:%d",
682 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
683 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
684 "audio" : "unknown" ),
685 codec.psz_name, codec.psz_description,
686 codec.i_information_length );
694 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
696 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
697 unsigned int i_codec;
699 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
701 #define codec p_cl->codec[i_codec]
702 FREENULL( codec.psz_name );
703 FREENULL( codec.psz_description );
704 FREENULL( codec.p_information );
707 FREENULL( p_cl->codec );
710 /* Microsoft should go to hell. This time the length give number of bytes
711 * and for the some others object, length give char16 count ... */
712 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
714 asf_object_content_description_t *p_cd =
715 (asf_object_content_description_t *)p_obj;
716 const uint8_t *p_peek, *p_data;
717 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
718 vlc_iconv_t cd = (vlc_iconv_t)-1;
719 const char *ib = NULL;
721 size_t i_ibl, i_obl, i_len;
723 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
724 if ( cd == (vlc_iconv_t)-1 ) {
725 msg_Err( s, "vlc_iconv_open failed" );
729 /* FIXME i_size*3 is the worst case. */
730 #define GETSTRINGW( psz_str, i_size ) \
731 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
732 ib = (const char *)p_data; \
736 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
739 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
743 p_data = p_peek + 24;
745 i_title = GetWLE( p_data ); p_data += 2;
746 i_artist= GetWLE( p_data ); p_data += 2;
747 i_copyright = GetWLE( p_data ); p_data += 2;
748 i_description = GetWLE( p_data ); p_data += 2;
749 i_rating = GetWLE( p_data ); p_data += 2;
751 GETSTRINGW( p_cd->psz_title, i_title );
752 GETSTRINGW( p_cd->psz_artist, i_artist );
753 GETSTRINGW( p_cd->psz_copyright, i_copyright );
754 GETSTRINGW( p_cd->psz_description, i_description );
755 GETSTRINGW( p_cd->psz_rating, i_rating );
761 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
765 p_cd->psz_description,
773 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
775 asf_object_content_description_t *p_cd =
776 (asf_object_content_description_t *)p_obj;
778 FREENULL( p_cd->psz_title );
779 FREENULL( p_cd->psz_artist );
780 FREENULL( p_cd->psz_copyright );
781 FREENULL( p_cd->psz_description );
782 FREENULL( p_cd->psz_rating );
786 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
788 asf_object_language_list_t *p_ll =
789 (asf_object_language_list_t*)p_obj;
790 const uint8_t *p_peek, *p_data;
794 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
797 p_data = &p_peek[24];
799 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
800 if( p_ll->i_language > 0 )
802 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
804 for( i = 0; i < p_ll->i_language; i++ )
807 int i_size = *p_data++;
810 psz = calloc( i_size/2 + 1, sizeof( char ) );
811 for( i_len = 0; i_len < i_size/2; i_len++ )
813 psz[i_len] = GetWLE( p_data + 2*i_len );
815 psz[i_size/2] = '\0'; \
818 p_ll->ppsz_language[i] = psz;
823 msg_Dbg( s, "read \"language list object\" %d entries",
825 for( i = 0; i < p_ll->i_language; i++ )
826 msg_Dbg( s, " - '%s'",
827 p_ll->ppsz_language[i] );
832 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
834 asf_object_language_list_t *p_ll =
835 (asf_object_language_list_t *)p_obj;
838 for( i = 0; i < p_ll->i_language; i++ )
839 FREENULL( p_ll->ppsz_language[i] );
840 FREENULL( p_ll->ppsz_language );
843 /* Stream bitrate properties */
844 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
847 asf_object_stream_bitrate_properties_t *p_sb =
848 (asf_object_stream_bitrate_properties_t *)p_obj;
849 const uint8_t *p_peek, *p_data;
853 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
856 p_data = &p_peek[24];
858 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
859 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
860 for( i = 0; i < p_sb->i_bitrate; i++ )
862 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
863 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
869 msg_Dbg( s,"read \"stream bitrate properties object\"" );
870 for( i = 0; i < p_sb->i_bitrate; i++ )
872 msg_Dbg( s," - stream=%d bitrate=%d",
873 p_sb->bitrate[i].i_stream_number,
874 p_sb->bitrate[i].i_avg_bitrate );
879 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
883 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
886 asf_object_extended_stream_properties_t *p_esp =
887 (asf_object_extended_stream_properties_t*)p_obj;
888 const uint8_t *p_peek, *p_data;
891 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
894 p_data = &p_peek[24];
896 p_esp->i_start_time = GetQWLE( &p_data[0] );
897 p_esp->i_end_time = GetQWLE( &p_data[8] );
898 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
899 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
900 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
901 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
902 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
903 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
904 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
905 p_esp->i_flags = GetDWLE( &p_data[44] );
906 p_esp->i_stream_number = GetWLE( &p_data[48] );
907 p_esp->i_language_index = GetWLE( &p_data[50] );
908 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
909 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
910 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
914 p_esp->pi_stream_name_language = calloc( sizeof(int),
915 p_esp->i_stream_name_count );
916 p_esp->ppsz_stream_name = calloc( sizeof(char*),
917 p_esp->i_stream_name_count );
918 for( i = 0; i < p_esp->i_stream_name_count; i++ )
924 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
925 i_size = GetWLE( &p_data[2] );
928 psz = calloc( i_size/2 + 1, sizeof( char ) );
929 for( i_len = 0; i_len < i_size/2; i_len++ )
931 psz[i_len] = GetWLE( p_data + 2*i_len );
933 psz[i_size/2] = '\0'; \
936 p_esp->ppsz_stream_name[i] = psz;
939 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
942 int i_size = GetDWLE( &p_data[16 + 2] );
944 p_data += 16+2+4+i_size;
948 if( p_data < &p_peek[i_peek] )
951 /* Cannot fail as peek succeed */
952 stream_Read( s, NULL, p_data - p_peek );
954 p_sp = malloc( sizeof( asf_object_t ) );
956 if( ASF_ReadObject( s, p_sp, NULL ) )
962 /* This p_sp will be inserted by ReadRoot later */
963 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
968 msg_Dbg( s, "read \"extended stream properties object\":" );
969 msg_Dbg( s, " - start=%"PRId64" end=%"PRId64,
970 p_esp->i_start_time, p_esp->i_end_time );
971 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
972 p_esp->i_data_bitrate,
973 p_esp->i_buffer_size,
974 p_esp->i_initial_buffer_fullness );
975 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
976 p_esp->i_alternate_data_bitrate,
977 p_esp->i_alternate_buffer_size,
978 p_esp->i_alternate_initial_buffer_fullness );
979 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
980 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
981 msg_Dbg( s, " - stream number=%d language=%d",
982 p_esp->i_stream_number, p_esp->i_language_index );
983 msg_Dbg( s, " - average time per frame=%"PRId64,
984 p_esp->i_average_time_per_frame );
985 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
986 for( i = 0; i < p_esp->i_stream_name_count; i++ )
987 msg_Dbg( s, " - lang id=%d name=%s",
988 p_esp->pi_stream_name_language[i],
989 p_esp->ppsz_stream_name[i] );
990 msg_Dbg( s, " - payload extension system count=%d",
991 p_esp->i_payload_extension_system_count );
995 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
997 asf_object_extended_stream_properties_t *p_esp =
998 (asf_object_extended_stream_properties_t *)p_obj;
1001 for( i = 0; i < p_esp->i_stream_name_count; i++ )
1002 FREENULL( p_esp->ppsz_stream_name[i] );
1003 FREENULL( p_esp->pi_stream_name_language );
1004 FREENULL( p_esp->ppsz_stream_name );
1008 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
1009 asf_object_t *p_obj)
1011 asf_object_advanced_mutual_exclusion_t *p_ae =
1012 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1013 const uint8_t *p_peek, *p_data;
1017 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1018 return VLC_EGENERIC;
1020 p_data = &p_peek[24];
1022 ASF_GetGUID( &p_ae->type, &p_data[0] );
1023 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1026 p_ae->pi_stream_number = calloc( sizeof(int),
1027 p_ae->i_stream_number_count );
1028 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1030 p_ae->pi_stream_number[i] = GetWLE( p_data );
1035 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1036 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1037 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1041 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1043 asf_object_advanced_mutual_exclusion_t *p_ae =
1044 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1046 FREENULL( p_ae->pi_stream_number );
1050 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1051 asf_object_t *p_obj)
1053 asf_object_stream_prioritization_t *p_sp =
1054 (asf_object_stream_prioritization_t *)p_obj;
1055 const uint8_t *p_peek, *p_data;
1059 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1060 return VLC_EGENERIC;
1062 p_data = &p_peek[24];
1064 p_sp->i_priority_count = GetWLE( &p_data[0] );
1067 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1068 p_sp->pi_priority_stream_number =
1069 calloc( sizeof(int), p_sp->i_priority_count );
1071 for( i = 0; i < p_sp->i_priority_count; i++ )
1073 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1074 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1077 msg_Dbg( s, "read \"stream prioritization object\"" );
1078 for( i = 0; i < p_sp->i_priority_count; i++ )
1079 msg_Dbg( s, " - Stream:%d flags=0x%x",
1080 p_sp->pi_priority_stream_number[i],
1081 p_sp->pi_priority_flag[i] );
1085 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1087 asf_object_stream_prioritization_t *p_sp =
1088 (asf_object_stream_prioritization_t *)p_obj;
1090 FREENULL( p_sp->pi_priority_stream_number );
1091 FREENULL( p_sp->pi_priority_flag );
1095 static int ASF_ReadObject_extended_content_description( stream_t *s,
1096 asf_object_t *p_obj)
1098 asf_object_extended_content_description_t *p_ec =
1099 (asf_object_extended_content_description_t *)p_obj;
1100 const uint8_t *p_peek, *p_data;
1104 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1105 return VLC_EGENERIC;
1107 p_data = &p_peek[24];
1109 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1110 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1111 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1112 for( i = 0; i < p_ec->i_count; i++ )
1117 #define GETSTRINGW( psz_str, i_size ) \
1118 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1119 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1121 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1123 psz_str[i_size/2] = '\0';
1125 i_size = GetWLE( p_data ); p_data += 2;
1126 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1130 i_type = GetWLE( p_data ); p_data += 2;
1131 i_size = GetWLE( p_data ); p_data += 2;
1134 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1136 else if( i_type == 1 )
1140 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1141 for( j = 0; j < i_size; j++ )
1143 static const char hex[16] = "0123456789ABCDEF";
1144 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1145 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1147 p_ec->ppsz_value[i][2*i_size] = '\0';
1149 else if( i_type == 2 )
1152 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1154 else if( i_type == 3 )
1157 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1159 else if( i_type == 4 )
1162 asprintf( &p_ec->ppsz_value[i], "%"PRId64, GetQWLE(p_data));
1164 else if( i_type == 5 )
1167 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1170 p_ec->ppsz_value[i] = NULL;
1181 msg_Dbg( s, "read \"extended content description object\"" );
1182 for( i = 0; i < p_ec->i_count; i++ )
1183 msg_Dbg( s, " - '%s' = '%s'",
1185 p_ec->ppsz_value[i] );
1189 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1191 asf_object_extended_content_description_t *p_ec =
1192 (asf_object_extended_content_description_t *)p_obj;
1195 for( i = 0; i < p_ec->i_count; i++ )
1197 FREENULL( p_ec->ppsz_name[i] );
1198 FREENULL( p_ec->ppsz_value[i] );
1200 FREENULL( p_ec->ppsz_name );
1201 FREENULL( p_ec->ppsz_value );
1206 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1208 asf_object_XXX_t *p_XX =
1209 (asf_object_XXX_t *)p_obj;
1210 const uint8_t *p_peek;
1214 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1215 return VLC_EGENERIC;
1217 p_data = &p_peek[24];
1221 "Read \"XXX object\"" );
1225 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1227 asf_object_XXX_t *p_XX =
1228 (asf_object_XXX_t *)p_obj;
1238 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1239 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1241 } ASF_Object_Function [] =
1243 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1244 ASF_ReadObject_Header, ASF_FreeObject_Null },
1245 { &asf_object_data_guid, ASF_OBJECT_DATA,
1246 ASF_ReadObject_Data, ASF_FreeObject_Null },
1247 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1248 ASF_ReadObject_Index, ASF_FreeObject_Index },
1249 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1250 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1251 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1252 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1253 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1254 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1255 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1256 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1257 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1258 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1259 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1260 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1261 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1262 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1263 { &asf_object_language_list, ASF_OBJECT_OTHER,
1264 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1265 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1266 ASF_ReadObject_stream_bitrate_properties,
1267 ASF_FreeObject_stream_bitrate_properties },
1268 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1269 ASF_ReadObject_extended_stream_properties,
1270 ASF_FreeObject_extended_stream_properties },
1271 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1272 ASF_ReadObject_advanced_mutual_exclusion,
1273 ASF_FreeObject_advanced_mutual_exclusion },
1274 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1275 ASF_ReadObject_stream_prioritization,
1276 ASF_FreeObject_stream_prioritization },
1277 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1278 ASF_ReadObject_extended_content_description,
1279 ASF_FreeObject_extended_content_description },
1281 { &asf_object_null_guid, 0, NULL, NULL }
1284 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1285 asf_object_t *p_father )
1293 memset( p_obj, 0, sizeof( p_obj ) );
1295 if( ASF_ReadObjectCommon( s, p_obj ) )
1297 msg_Warn( s, "cannot read one asf object" );
1298 return VLC_EGENERIC;
1300 p_obj->common.p_father = p_father;
1301 p_obj->common.p_first = NULL;
1302 p_obj->common.p_next = NULL;
1303 p_obj->common.p_last = NULL;
1305 if( p_obj->common.i_object_size < 24 )
1307 msg_Warn( s, "found a corrupted asf object (size<24)" );
1308 return VLC_EGENERIC;
1311 /* find this object */
1312 for( i_index = 0; ; i_index++ )
1314 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1315 &p_obj->common.i_object_id ) ||
1316 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1317 &asf_object_null_guid ) )
1322 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1324 /* Now load this object */
1325 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1327 msg_Warn( s, "unknown asf object (not loaded)" );
1328 i_result = VLC_SUCCESS;
1332 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1334 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1337 /* link this object with father */
1338 if( p_father && ! i_result )
1340 if( p_father->common.p_first )
1342 p_father->common.p_last->common.p_next = p_obj;
1346 p_father->common.p_first = p_obj;
1348 p_father->common.p_last = p_obj;
1354 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1357 asf_object_t *p_child;
1359 if( !p_obj ) return;
1361 /* Free all child object */
1362 p_child = p_obj->common.p_first;
1365 asf_object_t *p_next;
1366 p_next = p_child->common.p_next;
1367 ASF_FreeObject( s, p_child );
1371 /* find this object */
1372 for( i_index = 0; ; i_index++ )
1374 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1375 &p_obj->common.i_object_id )||
1376 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1377 &asf_object_null_guid ) )
1383 /* Now free this object */
1384 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1387 "unknown asf object " GUID_FMT,
1388 GUID_PRINT( p_obj->common.i_object_id ) );
1394 "free asf object " GUID_FMT,
1395 GUID_PRINT( p_obj->common.i_object_id ) );
1397 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1403 /*****************************************************************************
1404 * ASF_ObjectDumpDebug:
1405 *****************************************************************************/
1409 const char *psz_name;
1410 } ASF_ObjectDumpDebugInfo[] =
1412 { &asf_object_header_guid, "Header" },
1413 { &asf_object_data_guid, "Data" },
1414 { &asf_object_index_guid, "Index" },
1415 { &asf_object_file_properties_guid, "File Properties" },
1416 { &asf_object_stream_properties_guid, "Stream Properties" },
1417 { &asf_object_content_description_guid, "Content Description" },
1418 { &asf_object_header_extension_guid, "Header Extension" },
1419 { &asf_object_metadata_guid, "Metadata" },
1420 { &asf_object_codec_list_guid, "Codec List" },
1421 { &asf_object_marker_guid, "Marker" },
1422 { &asf_object_stream_type_audio, "Stream Type Audio" },
1423 { &asf_object_stream_type_video, "Stream Type Video" },
1424 { &asf_object_stream_type_command, "Stream Type Command" },
1425 { &asf_object_language_list, "Language List" },
1426 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1427 { &asf_object_padding, "Padding" },
1428 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1429 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1430 { &asf_object_stream_prioritization, "Stream Prioritization" },
1431 { &asf_object_extended_content_description, "Extended content description"},
1433 { NULL, "Unknown" },
1437 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1438 asf_object_common_t *p_node, int i_level )
1442 union asf_object_u *p_child;
1443 const char *psz_name;
1446 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1448 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1449 &p_node->i_object_id ) )
1452 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1454 memset( str, ' ', sizeof( str ) );
1455 for( i = 1; i < i_level; i++ )
1459 snprintf( str + 5*i_level, 1024,
1460 "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64,
1462 GUID_PRINT( p_node->i_object_id ),
1463 p_node->i_object_size, p_node->i_object_pos );
1465 msg_Dbg( p_obj, "%s", str );
1467 for( p_child = p_node->p_first; p_child != NULL;
1468 p_child = p_child->common.p_next )
1470 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1474 /*****************************************************************************
1475 * ASF_ReadObjetRoot : parse the entire stream/file
1476 *****************************************************************************/
1477 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1479 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1480 asf_object_t *p_obj;
1482 p_root->i_type = ASF_OBJECT_ROOT;
1483 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1484 p_root->i_object_pos = stream_Tell( s );
1485 p_root->i_object_size = 0;
1486 p_root->p_first = NULL;
1487 p_root->p_last = NULL;
1488 p_root->p_next = NULL;
1489 p_root->p_hdr = NULL;
1490 p_root->p_data = NULL;
1491 p_root->p_fp = NULL;
1492 p_root->p_index = NULL;
1493 p_root->p_metadata = NULL;
1497 p_obj = malloc( sizeof( asf_object_t ) );
1499 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1504 switch( p_obj->common.i_type )
1506 case( ASF_OBJECT_HEADER ):
1507 p_root->p_hdr = (asf_object_header_t*)p_obj;
1509 case( ASF_OBJECT_DATA ):
1510 p_root->p_data = (asf_object_data_t*)p_obj;
1512 case( ASF_OBJECT_INDEX ):
1513 p_root->p_index = (asf_object_index_t*)p_obj;
1516 msg_Warn( s, "unknow object found" );
1519 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1520 p_obj->common.i_object_size <= 50 )
1522 /* probably a dump of broadcasted asf */
1525 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1527 /* For unseekable stream it's enough to play */
1531 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1537 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1539 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1540 &asf_object_file_properties_guid, 0 );
1544 asf_object_t *p_hdr_ext =
1545 ASF_FindObject( p_root->p_hdr,
1546 &asf_object_header_extension_guid, 0 );
1552 p_root->p_metadata =
1553 ASF_FindObject( p_hdr_ext,
1554 &asf_object_metadata_guid, 0 );
1555 /* Special case for broken designed file format :( */
1556 i_ext_stream = ASF_CountObject( p_hdr_ext,
1557 &asf_object_extended_stream_properties );
1558 for( i = 0; i < i_ext_stream; i++ )
1560 asf_object_t *p_esp =
1561 ASF_FindObject( p_hdr_ext,
1562 &asf_object_extended_stream_properties, i );
1563 if( p_esp->ext_stream.p_sp )
1565 asf_object_t *p_sp =
1566 (asf_object_t*)p_esp->ext_stream.p_sp;
1568 /* Insert this p_sp */
1569 p_root->p_hdr->p_last->common.p_next = p_sp;
1570 p_root->p_hdr->p_last = p_sp;
1572 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1577 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1578 (asf_object_common_t*)p_root, 0 );
1581 msg_Warn( s, "cannot find file properties object" );
1585 ASF_FreeObjectRoot( s, p_root );
1589 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1591 asf_object_t *p_obj;
1593 p_obj = p_root->p_first;
1596 asf_object_t *p_next;
1597 p_next = p_obj->common.p_next;
1598 ASF_FreeObject( s, p_obj );
1604 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1607 asf_object_t *p_child;
1609 if( !p_obj ) return( 0 );
1612 p_child = p_obj->common.p_first;
1615 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1619 p_child = p_child->common.p_next;
1624 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1627 asf_object_t *p_child;
1629 p_child = p_obj->common.p_first;
1633 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1643 p_child = p_child->common.p_next;