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 *****************************************************************************/
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:"I64Fd,
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 )
140 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
142 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
143 asf_object_t *p_subobj;
145 const uint8_t *p_peek;
147 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
149 return( VLC_EGENERIC );
152 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
153 p_hdr->i_reserved1 = p_peek[28];
154 p_hdr->i_reserved2 = p_peek[29];
155 p_hdr->p_first = NULL;
156 p_hdr->p_last = NULL;
160 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
161 p_hdr->i_sub_object_count,
163 p_hdr->i_reserved2 );
166 /* Cannot fail as peek succeed */
167 stream_Read( s, NULL, 30 );
169 /* Now load sub object */
172 p_subobj = malloc( sizeof( asf_object_t ) );
174 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
179 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
187 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
189 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
191 const uint8_t *p_peek;
193 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
197 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
198 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
199 p_data->i_reserved = GetWLE( p_peek + 48 );
203 "read \"data object\" file_id:" GUID_FMT " total data packet:"
205 GUID_PRINT( p_data->i_file_id ),
206 p_data->i_total_data_packets,
207 p_data->i_reserved );
213 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
215 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
216 const uint8_t *p_peek;
219 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
220 (int)p_index->i_object_size )
226 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
227 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
228 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
229 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
230 p_index->index_entry = NULL;
234 "read \"index object\" file_id:" GUID_FMT
235 " index_entry_time_interval:"I64Fd" max_packet_count:%d "
236 "index_entry_count:%ld",
237 GUID_PRINT( p_index->i_file_id ),
238 p_index->i_index_entry_time_interval,
239 p_index->i_max_packet_count,
240 (long int)p_index->i_index_entry_count );
243 /* Sanity checking */
244 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
245 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
247 p_index->index_entry = malloc( sizeof(asf_index_entry_t) *
248 p_index->i_index_entry_count );
250 for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
253 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
254 p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
260 static void ASF_FreeObject_Index( asf_object_t *p_obj )
262 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
264 FREENULL( p_index->index_entry );
267 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
269 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
271 const uint8_t *p_peek;
273 if( ( i_peek = stream_Peek( s, &p_peek, 104) ) < 104 )
277 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
278 p_fp->i_file_size = GetQWLE( p_peek + 40 );
279 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
280 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
281 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
282 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
283 p_fp->i_preroll = GetQWLE( p_peek + 80 );
284 p_fp->i_flags = GetDWLE( p_peek + 88 );
285 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
286 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
287 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
291 "read \"file properties object\" file_id:" GUID_FMT
292 " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
293 I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
294 I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
296 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
297 p_fp->i_creation_date, p_fp->i_data_packets_count,
298 p_fp->i_play_duration, p_fp->i_send_duration,
299 p_fp->i_preroll, p_fp->i_flags,
300 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
301 p_fp->i_max_bitrate );
307 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
309 asf_object_metadata_t *p_meta =
310 (asf_object_metadata_t *)p_obj;
313 for( i = 0; i < p_meta->i_record_entries_count; i++ )
315 if( p_meta->record[i].psz_name ) free( p_meta->record[i].psz_name );
316 if( p_meta->record[i].p_data ) free( p_meta->record[i].p_data );
318 if( p_meta->record ) free( p_meta->record );
321 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
323 asf_object_metadata_t *p_meta =
324 (asf_object_metadata_t *)p_obj;
326 int i_peek, i_entries, i;
327 const uint8_t *p_peek;
332 p_meta->i_record_entries_count = 0;
335 if( stream_Peek( s, &p_peek, p_meta->i_object_size ) <
336 (int)p_meta->i_object_size )
342 i_entries = GetWLE( p_peek + i_peek ); i_peek += 2;
343 for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
345 asf_metadata_record_t record;
346 int i_name, i_data, j;
348 if( GetWLE( p_peek + i_peek ) != 0 )
350 ASF_FreeObject_metadata( p_obj );
355 record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2;
356 i_name = GetWLE( p_peek + i_peek ); i_peek += 2;
357 record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
358 i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
360 if( record.i_type > ASF_METADATA_TYPE_WORD ||
361 i_peek + i_data + i_name > (int)p_meta->i_object_size )
363 ASF_FreeObject_metadata( p_obj );
372 record.psz_name = malloc( i_name/2 + 1 );
373 for( j = 0; j < i_name/2; j++ )
375 record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
377 record.psz_name[j] = 0; /* just to make sure */
380 if( record.i_type == ASF_METADATA_TYPE_STRING )
382 record.p_data = malloc( i_data/2 + 1 );
383 record.i_data = i_data/2;
384 for( j = 0; j < i_data/2; j++ )
386 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
388 record.p_data[j] = 0; /* just to make sure */
390 else if( record.i_type == ASF_METADATA_TYPE_BYTE )
392 record.p_data = malloc( i_data );
393 record.i_data = i_data;
394 memcpy( record.p_data, p_peek + i_peek, i_data );
399 if( record.i_type == ASF_METADATA_TYPE_QWORD )
401 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
403 else if( record.i_type == ASF_METADATA_TYPE_DWORD )
405 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
409 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
413 p_meta->i_record_entries_count++;
415 realloc( p_meta->record, p_meta->i_record_entries_count *
416 sizeof(asf_metadata_record_t) );
417 memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
418 &record, sizeof(asf_metadata_record_t) );
423 "read \"metadata object\" %d entries",
424 p_meta->i_record_entries_count );
425 for( j = 0; j < p_meta->i_record_entries_count; j++ )
427 asf_metadata_record_t *p_rec = &p_meta->record[j];
429 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
430 msg_Dbg( s, " - %s=%s",
431 p_rec->psz_name, p_rec->p_data );
432 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
433 msg_Dbg( s, " - %s (%i bytes)",
434 p_rec->psz_name, p_rec->i_data );
436 msg_Dbg( s, " - %s="I64Fd,
437 p_rec->psz_name, p_rec->i_val );
444 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
446 asf_object_header_extension_t *p_he =
447 (asf_object_header_extension_t *)p_obj;
449 const uint8_t *p_peek;
451 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
455 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
456 p_he->i_reserved2 = GetWLE( p_peek + 40 );
457 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
458 if( p_he->i_header_extension_size )
460 p_he->p_header_extension_data =
461 malloc( p_he->i_header_extension_size );
462 memcpy( p_he->p_header_extension_data, p_peek + 46,
463 p_he->i_header_extension_size );
467 p_he->p_header_extension_data = NULL;
472 "read \"header extension object\" reserved1:" GUID_FMT
473 " reserved2:%d header_extension_size:%d",
474 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
475 p_he->i_header_extension_size );
478 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
480 /* Read the extension objects */
481 stream_Read( s, NULL, 46 );
484 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
486 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
492 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
501 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
503 asf_object_header_extension_t *p_he =
504 (asf_object_header_extension_t *)p_obj;
506 FREENULL( p_he->p_header_extension_data );
509 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
511 asf_object_stream_properties_t *p_sp =
512 (asf_object_stream_properties_t*)p_obj;
514 const uint8_t *p_peek;
516 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
521 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
522 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
523 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
524 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
525 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
526 p_sp->i_flags = GetWLE( p_peek + 72 );
527 p_sp->i_stream_number = p_sp->i_flags&0x07f;
528 p_sp->i_reserved = GetDWLE( p_peek + 74 );
531 if( p_sp->i_type_specific_data_length )
533 if( i_peek < p_sp->i_type_specific_data_length )
536 p_sp->p_type_specific_data =
537 malloc( p_sp->i_type_specific_data_length );
538 if( p_sp->p_type_specific_data == NULL )
541 memcpy( p_sp->p_type_specific_data, p_peek + 78,
542 p_sp->i_type_specific_data_length );
543 i_peek -= p_sp->i_type_specific_data_length;
547 p_sp->p_type_specific_data = NULL;
550 if( p_sp->i_error_correction_data_length )
552 if( i_peek < p_sp->i_error_correction_data_length )
554 free( p_sp->p_type_specific_data );
558 p_sp->p_error_correction_data =
559 malloc( p_sp->i_error_correction_data_length );
560 if( p_sp->p_error_correction_data == NULL )
562 free( p_sp->p_type_specific_data );
565 memcpy( p_sp->p_error_correction_data,
566 p_peek + 78 + p_sp->i_type_specific_data_length,
567 p_sp->i_error_correction_data_length );
571 p_sp->p_error_correction_data = NULL;
576 "read \"stream Properties object\" stream_type:" GUID_FMT
577 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
578 " type_specific_data_length:%d error_correction_data_length:%d"
579 " flags:0x%x stream_number:%d",
580 GUID_PRINT( p_sp->i_stream_type ),
581 GUID_PRINT( p_sp->i_error_correction_type ),
583 p_sp->i_type_specific_data_length,
584 p_sp->i_error_correction_data_length,
586 p_sp->i_stream_number );
592 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
594 asf_object_stream_properties_t *p_sp =
595 (asf_object_stream_properties_t*)p_obj;
597 FREENULL( p_sp->p_type_specific_data );
598 FREENULL( p_sp->p_error_correction_data );
602 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
604 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
606 const uint8_t *p_peek, *p_data;
608 unsigned int i_codec;
610 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
615 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
616 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
617 if( p_cl->i_codec_entries_count > 0 )
619 p_cl->codec = calloc( p_cl->i_codec_entries_count,
620 sizeof( asf_codec_entry_t ) );
621 memset( p_cl->codec, 0,
622 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
624 p_data = p_peek + 44;
625 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
627 #define codec p_cl->codec[i_codec]
630 codec.i_type = GetWLE( p_data ); p_data += 2;
632 i_len = GetWLE( p_data ); p_data += 2;
633 codec.psz_name = calloc( sizeof( char ), i_len + 1);
634 for( i = 0; i < i_len; i++ )
636 codec.psz_name[i] = GetWLE( p_data + 2*i );
638 codec.psz_name[i_len] = '\0';
642 i_len = GetWLE( p_data ); p_data += 2;
643 codec.psz_description = calloc( sizeof( char ), i_len + 1);
644 for( i = 0; i < i_len; i++ )
646 codec.psz_description[i] = GetWLE( p_data + 2*i );
648 codec.psz_description[i_len] = '\0';
651 /* opaque information */
652 codec.i_information_length = GetWLE( p_data ); p_data += 2;
653 if( codec.i_information_length > 0 )
655 codec.p_information = malloc( codec.i_information_length );
656 memcpy( codec.p_information, p_data, codec.i_information_length );
657 p_data += codec.i_information_length;
661 codec.p_information = NULL;
672 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
673 " codec_entries_count:%d",
674 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
676 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
678 #define codec p_cl->codec[i_codec]
679 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
680 "description:\"%s\" information_length:%d",
681 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
682 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
683 "audio" : "unknown" ),
684 codec.psz_name, codec.psz_description,
685 codec.i_information_length );
693 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
695 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
696 unsigned int i_codec;
698 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
700 #define codec p_cl->codec[i_codec]
701 FREENULL( codec.psz_name );
702 FREENULL( codec.psz_description );
703 FREENULL( codec.p_information );
706 FREENULL( p_cl->codec );
709 /* Microsoft should go to hell. This time the length give number of bytes
710 * and for the some others object, length give char16 count ... */
711 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
713 asf_object_content_description_t *p_cd =
714 (asf_object_content_description_t *)p_obj;
715 const uint8_t *p_peek, *p_data;
716 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
717 vlc_iconv_t cd = (vlc_iconv_t)-1;
718 const char *ib = NULL;
720 size_t i_ibl, i_obl, i_len;
722 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
723 if ( cd == (vlc_iconv_t)-1 ) {
724 msg_Err( s, "vlc_iconv_open failed" );
728 /* FIXME i_size*3 is the worst case. */
729 #define GETSTRINGW( psz_str, i_size ) \
730 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
731 ib = (const char *)p_data; \
735 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
738 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
742 p_data = p_peek + 24;
744 i_title = GetWLE( p_data ); p_data += 2;
745 i_artist= GetWLE( p_data ); p_data += 2;
746 i_copyright = GetWLE( p_data ); p_data += 2;
747 i_description = GetWLE( p_data ); p_data += 2;
748 i_rating = GetWLE( p_data ); p_data += 2;
750 GETSTRINGW( p_cd->psz_title, i_title );
751 GETSTRINGW( p_cd->psz_artist, i_artist );
752 GETSTRINGW( p_cd->psz_copyright, i_copyright );
753 GETSTRINGW( p_cd->psz_description, i_description );
754 GETSTRINGW( p_cd->psz_rating, i_rating );
760 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
764 p_cd->psz_description,
772 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
774 asf_object_content_description_t *p_cd =
775 (asf_object_content_description_t *)p_obj;
777 FREENULL( p_cd->psz_title );
778 FREENULL( p_cd->psz_artist );
779 FREENULL( p_cd->psz_copyright );
780 FREENULL( p_cd->psz_description );
781 FREENULL( p_cd->psz_rating );
785 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
787 asf_object_language_list_t *p_ll =
788 (asf_object_language_list_t*)p_obj;
789 const uint8_t *p_peek, *p_data;
793 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
796 p_data = &p_peek[24];
798 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
799 if( p_ll->i_language > 0 )
801 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
803 for( i = 0; i < p_ll->i_language; i++ )
806 int i_size = *p_data++;
809 psz = calloc( i_size/2 + 1, sizeof( char ) );
810 for( i_len = 0; i_len < i_size/2; i_len++ )
812 psz[i_len] = GetWLE( p_data + 2*i_len );
814 psz[i_size/2] = '\0'; \
817 p_ll->ppsz_language[i] = psz;
822 msg_Dbg( s, "read \"language list object\" %d entries",
824 for( i = 0; i < p_ll->i_language; i++ )
825 msg_Dbg( s, " - '%s'",
826 p_ll->ppsz_language[i] );
831 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
833 asf_object_language_list_t *p_ll =
834 (asf_object_language_list_t *)p_obj;
837 for( i = 0; i < p_ll->i_language; i++ )
838 FREENULL( p_ll->ppsz_language[i] );
839 FREENULL( p_ll->ppsz_language );
842 /* Stream bitrate properties */
843 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
846 asf_object_stream_bitrate_properties_t *p_sb =
847 (asf_object_stream_bitrate_properties_t *)p_obj;
848 const uint8_t *p_peek, *p_data;
852 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
855 p_data = &p_peek[24];
857 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
858 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
859 for( i = 0; i < p_sb->i_bitrate; i++ )
861 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
862 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
868 msg_Dbg( s,"read \"stream bitrate properties object\"" );
869 for( i = 0; i < p_sb->i_bitrate; i++ )
871 msg_Dbg( s," - stream=%d bitrate=%d",
872 p_sb->bitrate[i].i_stream_number,
873 p_sb->bitrate[i].i_avg_bitrate );
878 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
882 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
885 asf_object_extended_stream_properties_t *p_esp =
886 (asf_object_extended_stream_properties_t*)p_obj;
887 const uint8_t *p_peek, *p_data;
890 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
893 p_data = &p_peek[24];
895 p_esp->i_start_time = GetQWLE( &p_data[0] );
896 p_esp->i_end_time = GetQWLE( &p_data[8] );
897 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
898 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
899 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
900 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
901 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
902 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
903 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
904 p_esp->i_flags = GetDWLE( &p_data[44] );
905 p_esp->i_stream_number = GetWLE( &p_data[48] );
906 p_esp->i_language_index = GetWLE( &p_data[50] );
907 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
908 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
909 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
913 p_esp->pi_stream_name_language = calloc( sizeof(int),
914 p_esp->i_stream_name_count );
915 p_esp->ppsz_stream_name = calloc( sizeof(char*),
916 p_esp->i_stream_name_count );
917 for( i = 0; i < p_esp->i_stream_name_count; i++ )
923 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
924 i_size = GetWLE( &p_data[2] );
927 psz = calloc( i_size/2 + 1, sizeof( char ) );
928 for( i_len = 0; i_len < i_size/2; i_len++ )
930 psz[i_len] = GetWLE( p_data + 2*i_len );
932 psz[i_size/2] = '\0'; \
935 p_esp->ppsz_stream_name[i] = psz;
938 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
941 int i_size = GetDWLE( &p_data[16 + 2] );
943 p_data += 16+2+4+i_size;
947 if( p_data < &p_peek[i_peek] )
950 /* Cannot fail as peek succeed */
951 stream_Read( s, NULL, p_data - p_peek );
953 p_sp = malloc( sizeof( asf_object_t ) );
955 if( ASF_ReadObject( s, p_sp, NULL ) )
961 /* This p_sp will be inserted by ReadRoot later */
962 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
967 msg_Dbg( s, "read \"extended stream properties object\":" );
968 msg_Dbg( s, " - start="I64Fd" end="I64Fd,
969 p_esp->i_start_time, p_esp->i_end_time );
970 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
971 p_esp->i_data_bitrate,
972 p_esp->i_buffer_size,
973 p_esp->i_initial_buffer_fullness );
974 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
975 p_esp->i_alternate_data_bitrate,
976 p_esp->i_alternate_buffer_size,
977 p_esp->i_alternate_initial_buffer_fullness );
978 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
979 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
980 msg_Dbg( s, " - stream number=%d language=%d",
981 p_esp->i_stream_number, p_esp->i_language_index );
982 msg_Dbg( s, " - average time per frame="I64Fd,
983 p_esp->i_average_time_per_frame );
984 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
985 for( i = 0; i < p_esp->i_stream_name_count; i++ )
986 msg_Dbg( s, " - lang id=%d name=%s",
987 p_esp->pi_stream_name_language[i],
988 p_esp->ppsz_stream_name[i] );
989 msg_Dbg( s, " - payload extension system count=%d",
990 p_esp->i_payload_extension_system_count );
994 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
996 asf_object_extended_stream_properties_t *p_esp =
997 (asf_object_extended_stream_properties_t *)p_obj;
1000 for( i = 0; i < p_esp->i_stream_name_count; i++ )
1001 FREENULL( p_esp->ppsz_stream_name[i] );
1002 FREENULL( p_esp->pi_stream_name_language );
1003 FREENULL( p_esp->ppsz_stream_name );
1007 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
1008 asf_object_t *p_obj)
1010 asf_object_advanced_mutual_exclusion_t *p_ae =
1011 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1012 const uint8_t *p_peek, *p_data;
1016 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1017 return VLC_EGENERIC;
1019 p_data = &p_peek[24];
1021 ASF_GetGUID( &p_ae->type, &p_data[0] );
1022 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1025 p_ae->pi_stream_number = calloc( sizeof(int),
1026 p_ae->i_stream_number_count );
1027 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1029 p_ae->pi_stream_number[i] = GetWLE( p_data );
1034 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1035 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1036 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1040 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1042 asf_object_advanced_mutual_exclusion_t *p_ae =
1043 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1045 FREENULL( p_ae->pi_stream_number );
1049 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1050 asf_object_t *p_obj)
1052 asf_object_stream_prioritization_t *p_sp =
1053 (asf_object_stream_prioritization_t *)p_obj;
1054 const uint8_t *p_peek, *p_data;
1058 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1059 return VLC_EGENERIC;
1061 p_data = &p_peek[24];
1063 p_sp->i_priority_count = GetWLE( &p_data[0] );
1066 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1067 p_sp->pi_priority_stream_number =
1068 calloc( sizeof(int), p_sp->i_priority_count );
1070 for( i = 0; i < p_sp->i_priority_count; i++ )
1072 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1073 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1076 msg_Dbg( s, "read \"stream prioritization object\"" );
1077 for( i = 0; i < p_sp->i_priority_count; i++ )
1078 msg_Dbg( s, " - Stream:%d flags=0x%x",
1079 p_sp->pi_priority_stream_number[i],
1080 p_sp->pi_priority_flag[i] );
1084 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1086 asf_object_stream_prioritization_t *p_sp =
1087 (asf_object_stream_prioritization_t *)p_obj;
1089 FREENULL( p_sp->pi_priority_stream_number );
1090 FREENULL( p_sp->pi_priority_flag );
1094 static int ASF_ReadObject_extended_content_description( stream_t *s,
1095 asf_object_t *p_obj)
1097 asf_object_extended_content_description_t *p_ec =
1098 (asf_object_extended_content_description_t *)p_obj;
1099 const uint8_t *p_peek, *p_data;
1103 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1104 return VLC_EGENERIC;
1106 p_data = &p_peek[24];
1108 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1109 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1110 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1111 for( i = 0; i < p_ec->i_count; i++ )
1116 #define GETSTRINGW( psz_str, i_size ) \
1117 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1118 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1120 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1122 psz_str[i_size/2] = '\0';
1124 i_size = GetWLE( p_data ); p_data += 2;
1125 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1129 i_type = GetWLE( p_data ); p_data += 2;
1130 i_size = GetWLE( p_data ); p_data += 2;
1133 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1135 else if( i_type == 1 )
1139 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1140 for( j = 0; j < i_size; j++ )
1142 static const char hex[16] = "0123456789ABCDEF";
1143 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1144 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1146 p_ec->ppsz_value[i][2*i_size] = '\0';
1148 else if( i_type == 2 )
1151 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1153 else if( i_type == 3 )
1156 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1158 else if( i_type == 4 )
1161 asprintf( &p_ec->ppsz_value[i], I64Fd, GetQWLE(p_data));
1163 else if( i_type == 5 )
1166 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1169 p_ec->ppsz_value[i] = NULL;
1180 msg_Dbg( s, "read \"extended content description object\"" );
1181 for( i = 0; i < p_ec->i_count; i++ )
1182 msg_Dbg( s, " - '%s' = '%s'",
1184 p_ec->ppsz_value[i] );
1188 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1190 asf_object_extended_content_description_t *p_ec =
1191 (asf_object_extended_content_description_t *)p_obj;
1194 for( i = 0; i < p_ec->i_count; i++ )
1196 FREENULL( p_ec->ppsz_name[i] );
1197 FREENULL( p_ec->ppsz_value[i] );
1199 FREENULL( p_ec->ppsz_name );
1200 FREENULL( p_ec->ppsz_value );
1205 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1207 asf_object_XXX_t *p_XX =
1208 (asf_object_XXX_t *)p_obj;
1209 const uint8_t *p_peek;
1213 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1214 return VLC_EGENERIC;
1216 p_data = &p_peek[24];
1220 "Read \"XXX object\"" );
1224 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1226 asf_object_XXX_t *p_XX =
1227 (asf_object_XXX_t *)p_obj;
1237 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1238 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1240 } ASF_Object_Function [] =
1242 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1243 ASF_ReadObject_Header, ASF_FreeObject_Null },
1244 { &asf_object_data_guid, ASF_OBJECT_DATA,
1245 ASF_ReadObject_Data, ASF_FreeObject_Null },
1246 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1247 ASF_ReadObject_Index, ASF_FreeObject_Index },
1248 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1249 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1250 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1251 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1252 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1253 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1254 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1255 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1256 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1257 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1258 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1259 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1260 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1261 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1262 { &asf_object_language_list, ASF_OBJECT_OTHER,
1263 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1264 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1265 ASF_ReadObject_stream_bitrate_properties,
1266 ASF_FreeObject_stream_bitrate_properties },
1267 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1268 ASF_ReadObject_extended_stream_properties,
1269 ASF_FreeObject_extended_stream_properties },
1270 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1271 ASF_ReadObject_advanced_mutual_exclusion,
1272 ASF_FreeObject_advanced_mutual_exclusion },
1273 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1274 ASF_ReadObject_stream_prioritization,
1275 ASF_FreeObject_stream_prioritization },
1276 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1277 ASF_ReadObject_extended_content_description,
1278 ASF_FreeObject_extended_content_description },
1280 { &asf_object_null_guid, 0, NULL, NULL }
1283 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1284 asf_object_t *p_father )
1292 memset( p_obj, 0, sizeof( p_obj ) );
1294 if( ASF_ReadObjectCommon( s, p_obj ) )
1296 msg_Warn( s, "cannot read one asf object" );
1297 return VLC_EGENERIC;
1299 p_obj->common.p_father = p_father;
1300 p_obj->common.p_first = NULL;
1301 p_obj->common.p_next = NULL;
1302 p_obj->common.p_last = NULL;
1304 if( p_obj->common.i_object_size < 24 )
1306 msg_Warn( s, "found a corrupted asf object (size<24)" );
1307 return VLC_EGENERIC;
1310 /* find this object */
1311 for( i_index = 0; ; i_index++ )
1313 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1314 &p_obj->common.i_object_id ) ||
1315 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1316 &asf_object_null_guid ) )
1321 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1323 /* Now load this object */
1324 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1326 msg_Warn( s, "unknown asf object (not loaded)" );
1327 i_result = VLC_SUCCESS;
1331 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1333 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1336 /* link this object with father */
1337 if( p_father && ! i_result )
1339 if( p_father->common.p_first )
1341 p_father->common.p_last->common.p_next = p_obj;
1345 p_father->common.p_first = p_obj;
1347 p_father->common.p_last = p_obj;
1353 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1356 asf_object_t *p_child;
1358 if( !p_obj ) return;
1360 /* Free all child object */
1361 p_child = p_obj->common.p_first;
1364 asf_object_t *p_next;
1365 p_next = p_child->common.p_next;
1366 ASF_FreeObject( s, p_child );
1370 /* find this object */
1371 for( i_index = 0; ; i_index++ )
1373 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1374 &p_obj->common.i_object_id )||
1375 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1376 &asf_object_null_guid ) )
1382 /* Now free this object */
1383 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1386 "unknown asf object " GUID_FMT,
1387 GUID_PRINT( p_obj->common.i_object_id ) );
1393 "free asf object " GUID_FMT,
1394 GUID_PRINT( p_obj->common.i_object_id ) );
1396 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1402 /*****************************************************************************
1403 * ASF_ObjectDumpDebug:
1404 *****************************************************************************/
1408 const char *psz_name;
1409 } ASF_ObjectDumpDebugInfo[] =
1411 { &asf_object_header_guid, "Header" },
1412 { &asf_object_data_guid, "Data" },
1413 { &asf_object_index_guid, "Index" },
1414 { &asf_object_file_properties_guid, "File Properties" },
1415 { &asf_object_stream_properties_guid, "Stream Properties" },
1416 { &asf_object_content_description_guid, "Content Description" },
1417 { &asf_object_header_extension_guid, "Header Extension" },
1418 { &asf_object_metadata_guid, "Metadata" },
1419 { &asf_object_codec_list_guid, "Codec List" },
1420 { &asf_object_marker_guid, "Marker" },
1421 { &asf_object_stream_type_audio, "Stream Type Audio" },
1422 { &asf_object_stream_type_video, "Stream Type Video" },
1423 { &asf_object_stream_type_command, "Stream Type Command" },
1424 { &asf_object_language_list, "Language List" },
1425 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1426 { &asf_object_padding, "Padding" },
1427 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1428 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1429 { &asf_object_stream_prioritization, "Stream Prioritization" },
1430 { &asf_object_extended_content_description, "Extended content description"},
1432 { NULL, "Unknown" },
1436 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1437 asf_object_common_t *p_node, int i_level )
1441 union asf_object_u *p_child;
1442 const char *psz_name;
1445 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1447 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1448 &p_node->i_object_id ) )
1451 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1453 memset( str, ' ', sizeof( str ) );
1454 for( i = 1; i < i_level; i++ )
1458 snprintf( str + 5*i_level, 1024,
1459 "+ '%s' GUID "GUID_FMT" size:"I64Fu"pos:"I64Fu,
1461 GUID_PRINT( p_node->i_object_id ),
1462 p_node->i_object_size, p_node->i_object_pos );
1464 msg_Dbg( p_obj, "%s", str );
1466 for( p_child = p_node->p_first; p_child != NULL;
1467 p_child = p_child->common.p_next )
1469 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1473 /*****************************************************************************
1474 * ASF_ReadObjetRoot : parse the entire stream/file
1475 *****************************************************************************/
1476 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1478 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1479 asf_object_t *p_obj;
1481 p_root->i_type = ASF_OBJECT_ROOT;
1482 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1483 p_root->i_object_pos = stream_Tell( s );
1484 p_root->i_object_size = 0;
1485 p_root->p_first = NULL;
1486 p_root->p_last = NULL;
1487 p_root->p_next = NULL;
1488 p_root->p_hdr = NULL;
1489 p_root->p_data = NULL;
1490 p_root->p_fp = NULL;
1491 p_root->p_index = NULL;
1492 p_root->p_metadata = NULL;
1496 p_obj = malloc( sizeof( asf_object_t ) );
1498 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1503 switch( p_obj->common.i_type )
1505 case( ASF_OBJECT_HEADER ):
1506 p_root->p_hdr = (asf_object_header_t*)p_obj;
1508 case( ASF_OBJECT_DATA ):
1509 p_root->p_data = (asf_object_data_t*)p_obj;
1511 case( ASF_OBJECT_INDEX ):
1512 p_root->p_index = (asf_object_index_t*)p_obj;
1515 msg_Warn( s, "unknow object found" );
1518 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1519 p_obj->common.i_object_size <= 50 )
1521 /* probably a dump of broadcasted asf */
1524 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1526 /* For unseekable stream it's enough to play */
1530 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1536 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1538 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1539 &asf_object_file_properties_guid, 0 );
1543 asf_object_t *p_hdr_ext =
1544 ASF_FindObject( p_root->p_hdr,
1545 &asf_object_header_extension_guid, 0 );
1551 p_root->p_metadata =
1552 ASF_FindObject( p_hdr_ext,
1553 &asf_object_metadata_guid, 0 );
1554 /* Special case for broken designed file format :( */
1555 i_ext_stream = ASF_CountObject( p_hdr_ext,
1556 &asf_object_extended_stream_properties );
1557 for( i = 0; i < i_ext_stream; i++ )
1559 asf_object_t *p_esp =
1560 ASF_FindObject( p_hdr_ext,
1561 &asf_object_extended_stream_properties, i );
1562 if( p_esp->ext_stream.p_sp )
1564 asf_object_t *p_sp =
1565 (asf_object_t*)p_esp->ext_stream.p_sp;
1567 /* Insert this p_sp */
1568 p_root->p_hdr->p_last->common.p_next = p_sp;
1569 p_root->p_hdr->p_last = p_sp;
1571 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1576 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1577 (asf_object_common_t*)p_root, 0 );
1580 msg_Warn( s, "cannot find file properties object" );
1584 ASF_FreeObjectRoot( s, p_root );
1588 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1590 asf_object_t *p_obj;
1592 p_obj = p_root->p_first;
1595 asf_object_t *p_next;
1596 p_next = p_obj->common.p_next;
1597 ASF_FreeObject( s, p_obj );
1603 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1606 asf_object_t *p_child;
1608 if( !p_obj ) return( 0 );
1611 p_child = p_obj->common.p_first;
1614 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1618 p_child = p_child->common.p_next;
1623 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1626 asf_object_t *p_child;
1628 p_child = p_obj->common.p_first;
1632 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1642 p_child = p_child->common.p_next;