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 )
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_Read( s, NULL, 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:"
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:"I64Fd" 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_send_duration = GetQWLE( p_peek + 64 );
283 p_fp->i_play_duration = GetQWLE( p_peek + 72 );
284 p_fp->i_preroll = GetDWLE( p_peek + 80 );
285 p_fp->i_unknown = GetDWLE( p_peek + 84 );
286 p_fp->i_flags = GetDWLE( p_peek + 88 );
287 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
288 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
289 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
293 "read \"file properties object\" file_id:" GUID_FMT
294 " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
295 I64Fd" send_duration:"I64Fd" play_duration:"I64Fd" preroll:%d"
296 "unknown:%d flags:%d min_data_packet_size:%d "
297 "max_data_packet_size:%d max_bitrate:%d",
298 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
299 p_fp->i_creation_date, p_fp->i_data_packets_count,
300 p_fp->i_send_duration, p_fp->i_play_duration,
301 p_fp->i_preroll, p_fp->i_unknown, p_fp->i_flags,
302 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
303 p_fp->i_max_bitrate );
309 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
311 asf_object_metadata_t *p_meta =
312 (asf_object_metadata_t *)p_obj;
315 for( i = 0; i < p_meta->i_record_entries_count; i++ )
317 free( p_meta->record[i].psz_name );
318 free( p_meta->record[i].p_data );
320 free( p_meta->record );
323 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
325 asf_object_metadata_t *p_meta =
326 (asf_object_metadata_t *)p_obj;
328 int i_peek, i_entries, i;
329 const uint8_t *p_peek;
334 p_meta->i_record_entries_count = 0;
337 if( stream_Peek( s, &p_peek, p_meta->i_object_size ) <
338 (int)p_meta->i_object_size )
344 i_entries = GetWLE( p_peek + i_peek ); i_peek += 2;
345 for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
347 asf_metadata_record_t record;
348 int i_name, i_data, j;
350 if( GetWLE( p_peek + i_peek ) != 0 )
352 ASF_FreeObject_metadata( p_obj );
357 record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2;
358 i_name = GetWLE( p_peek + i_peek ); i_peek += 2;
359 record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
360 i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
362 if( record.i_type > ASF_METADATA_TYPE_WORD ||
363 i_peek + i_data + i_name > (int)p_meta->i_object_size )
365 ASF_FreeObject_metadata( p_obj );
374 record.psz_name = malloc( i_name/2 + 1 );
375 for( j = 0; j < i_name/2; j++ )
377 record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
379 record.psz_name[j] = 0; /* just to make sure */
382 if( record.i_type == ASF_METADATA_TYPE_STRING )
384 record.p_data = malloc( i_data/2 + 1 );
385 record.i_data = i_data/2;
386 for( j = 0; j < i_data/2; j++ )
388 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
390 record.p_data[j] = 0; /* just to make sure */
392 else if( record.i_type == ASF_METADATA_TYPE_BYTE )
394 record.p_data = malloc( i_data );
395 record.i_data = i_data;
396 memcpy( record.p_data, p_peek + i_peek, i_data );
401 if( record.i_type == ASF_METADATA_TYPE_QWORD )
403 record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
405 else if( record.i_type == ASF_METADATA_TYPE_DWORD )
407 record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
411 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
415 p_meta->i_record_entries_count++;
417 realloc( p_meta->record, p_meta->i_record_entries_count *
418 sizeof(asf_metadata_record_t) );
419 memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
420 &record, sizeof(asf_metadata_record_t) );
425 "read \"metadata object\" %d entries",
426 p_meta->i_record_entries_count );
427 for( j = 0; j < p_meta->i_record_entries_count; j++ )
429 asf_metadata_record_t *p_rec = &p_meta->record[j];
431 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
432 msg_Dbg( s, " - %s=%s",
433 p_rec->psz_name, p_rec->p_data );
434 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
435 msg_Dbg( s, " - %s (%i bytes)",
436 p_rec->psz_name, p_rec->i_data );
438 msg_Dbg( s, " - %s="I64Fd,
439 p_rec->psz_name, p_rec->i_val );
446 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
448 asf_object_header_extension_t *p_he =
449 (asf_object_header_extension_t *)p_obj;
451 const uint8_t *p_peek;
453 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
457 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
458 p_he->i_reserved2 = GetWLE( p_peek + 40 );
459 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
460 if( p_he->i_header_extension_size )
462 p_he->p_header_extension_data =
463 malloc( p_he->i_header_extension_size );
464 memcpy( p_he->p_header_extension_data, p_peek + 46,
465 p_he->i_header_extension_size );
469 p_he->p_header_extension_data = NULL;
474 "read \"header extension object\" reserved1:" GUID_FMT
475 " reserved2:%d header_extension_size:%d",
476 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
477 p_he->i_header_extension_size );
480 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
482 /* Read the extension objects */
483 stream_Read( s, NULL, 46 );
486 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
488 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
494 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
503 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
505 asf_object_header_extension_t *p_he =
506 (asf_object_header_extension_t *)p_obj;
508 FREENULL( p_he->p_header_extension_data );
511 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
513 asf_object_stream_properties_t *p_sp =
514 (asf_object_stream_properties_t*)p_obj;
516 const uint8_t *p_peek;
518 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
523 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
524 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
525 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
526 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
527 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
528 p_sp->i_flags = GetWLE( p_peek + 72 );
529 p_sp->i_stream_number = p_sp->i_flags&0x07f;
530 p_sp->i_reserved = GetDWLE( p_peek + 74 );
533 if( p_sp->i_type_specific_data_length )
535 if( i_peek < p_sp->i_type_specific_data_length )
538 p_sp->p_type_specific_data =
539 malloc( p_sp->i_type_specific_data_length );
540 if( p_sp->p_type_specific_data == NULL )
543 memcpy( p_sp->p_type_specific_data, p_peek + 78,
544 p_sp->i_type_specific_data_length );
545 i_peek -= p_sp->i_type_specific_data_length;
549 p_sp->p_type_specific_data = NULL;
552 if( p_sp->i_error_correction_data_length )
554 if( i_peek < p_sp->i_error_correction_data_length )
556 free( p_sp->p_type_specific_data );
560 p_sp->p_error_correction_data =
561 malloc( p_sp->i_error_correction_data_length );
562 if( p_sp->p_error_correction_data == NULL )
564 free( p_sp->p_type_specific_data );
567 memcpy( p_sp->p_error_correction_data,
568 p_peek + 78 + p_sp->i_type_specific_data_length,
569 p_sp->i_error_correction_data_length );
573 p_sp->p_error_correction_data = NULL;
578 "read \"stream Properties object\" stream_type:" GUID_FMT
579 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
580 " type_specific_data_length:%d error_correction_data_length:%d"
581 " flags:0x%x stream_number:%d",
582 GUID_PRINT( p_sp->i_stream_type ),
583 GUID_PRINT( p_sp->i_error_correction_type ),
585 p_sp->i_type_specific_data_length,
586 p_sp->i_error_correction_data_length,
588 p_sp->i_stream_number );
594 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
596 asf_object_stream_properties_t *p_sp =
597 (asf_object_stream_properties_t*)p_obj;
599 FREENULL( p_sp->p_type_specific_data );
600 FREENULL( p_sp->p_error_correction_data );
604 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
606 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
608 const uint8_t *p_peek, *p_data;
610 unsigned int i_codec;
612 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
617 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
618 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
619 if( p_cl->i_codec_entries_count > 0 )
621 p_cl->codec = calloc( p_cl->i_codec_entries_count,
622 sizeof( asf_codec_entry_t ) );
623 memset( p_cl->codec, 0,
624 p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
626 p_data = p_peek + 44;
627 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
629 #define codec p_cl->codec[i_codec]
632 codec.i_type = GetWLE( p_data ); p_data += 2;
634 i_len = GetWLE( p_data ); p_data += 2;
635 codec.psz_name = calloc( sizeof( char ), i_len + 1);
636 for( i = 0; i < i_len; i++ )
638 codec.psz_name[i] = GetWLE( p_data + 2*i );
640 codec.psz_name[i_len] = '\0';
644 i_len = GetWLE( p_data ); p_data += 2;
645 codec.psz_description = calloc( sizeof( char ), i_len + 1);
646 for( i = 0; i < i_len; i++ )
648 codec.psz_description[i] = GetWLE( p_data + 2*i );
650 codec.psz_description[i_len] = '\0';
653 /* opaque information */
654 codec.i_information_length = GetWLE( p_data ); p_data += 2;
655 if( codec.i_information_length > 0 )
657 codec.p_information = malloc( codec.i_information_length );
658 memcpy( codec.p_information, p_data, codec.i_information_length );
659 p_data += codec.i_information_length;
663 codec.p_information = NULL;
674 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
675 " codec_entries_count:%d",
676 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
678 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
680 #define codec p_cl->codec[i_codec]
681 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
682 "description:\"%s\" information_length:%d",
683 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
684 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
685 "audio" : "unknown" ),
686 codec.psz_name, codec.psz_description,
687 codec.i_information_length );
695 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
697 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
698 unsigned int i_codec;
700 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
702 #define codec p_cl->codec[i_codec]
703 FREENULL( codec.psz_name );
704 FREENULL( codec.psz_description );
705 FREENULL( codec.p_information );
708 FREENULL( p_cl->codec );
711 /* Microsoft should go to hell. This time the length give number of bytes
712 * and for the some others object, length give char16 count ... */
713 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
715 asf_object_content_description_t *p_cd =
716 (asf_object_content_description_t *)p_obj;
717 const uint8_t *p_peek, *p_data;
718 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
719 vlc_iconv_t cd = (vlc_iconv_t)-1;
720 const char *ib = NULL;
722 size_t i_ibl, i_obl, i_len;
724 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
725 if ( cd == (vlc_iconv_t)-1 ) {
726 msg_Err( s, "vlc_iconv_open failed" );
730 /* FIXME i_size*3 is the worst case. */
731 #define GETSTRINGW( psz_str, i_size ) \
732 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
733 ib = (const char *)p_data; \
737 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
740 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
744 p_data = p_peek + 24;
746 i_title = GetWLE( p_data ); p_data += 2;
747 i_artist= GetWLE( p_data ); p_data += 2;
748 i_copyright = GetWLE( p_data ); p_data += 2;
749 i_description = GetWLE( p_data ); p_data += 2;
750 i_rating = GetWLE( p_data ); p_data += 2;
752 GETSTRINGW( p_cd->psz_title, i_title );
753 GETSTRINGW( p_cd->psz_artist, i_artist );
754 GETSTRINGW( p_cd->psz_copyright, i_copyright );
755 GETSTRINGW( p_cd->psz_description, i_description );
756 GETSTRINGW( p_cd->psz_rating, i_rating );
762 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
766 p_cd->psz_description,
774 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
776 asf_object_content_description_t *p_cd =
777 (asf_object_content_description_t *)p_obj;
779 FREENULL( p_cd->psz_title );
780 FREENULL( p_cd->psz_artist );
781 FREENULL( p_cd->psz_copyright );
782 FREENULL( p_cd->psz_description );
783 FREENULL( p_cd->psz_rating );
787 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
789 asf_object_language_list_t *p_ll =
790 (asf_object_language_list_t*)p_obj;
791 const uint8_t *p_peek, *p_data;
795 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
798 p_data = &p_peek[24];
800 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
801 if( p_ll->i_language > 0 )
803 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
805 for( i = 0; i < p_ll->i_language; i++ )
808 int i_size = *p_data++;
811 psz = calloc( i_size/2 + 1, sizeof( char ) );
812 for( i_len = 0; i_len < i_size/2; i_len++ )
814 psz[i_len] = GetWLE( p_data + 2*i_len );
816 psz[i_size/2] = '\0'; \
819 p_ll->ppsz_language[i] = psz;
824 msg_Dbg( s, "read \"language list object\" %d entries",
826 for( i = 0; i < p_ll->i_language; i++ )
827 msg_Dbg( s, " - '%s'",
828 p_ll->ppsz_language[i] );
833 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
835 asf_object_language_list_t *p_ll =
836 (asf_object_language_list_t *)p_obj;
839 for( i = 0; i < p_ll->i_language; i++ )
840 FREENULL( p_ll->ppsz_language[i] );
841 FREENULL( p_ll->ppsz_language );
844 /* Stream bitrate properties */
845 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
848 asf_object_stream_bitrate_properties_t *p_sb =
849 (asf_object_stream_bitrate_properties_t *)p_obj;
850 const uint8_t *p_peek, *p_data;
854 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
857 p_data = &p_peek[24];
859 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
860 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
861 for( i = 0; i < p_sb->i_bitrate; i++ )
863 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
864 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
870 msg_Dbg( s,"read \"stream bitrate properties object\"" );
871 for( i = 0; i < p_sb->i_bitrate; i++ )
873 msg_Dbg( s," - stream=%d bitrate=%d",
874 p_sb->bitrate[i].i_stream_number,
875 p_sb->bitrate[i].i_avg_bitrate );
880 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
884 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
887 asf_object_extended_stream_properties_t *p_esp =
888 (asf_object_extended_stream_properties_t*)p_obj;
889 const uint8_t *p_peek, *p_data;
892 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
895 p_data = &p_peek[24];
897 p_esp->i_start_time = GetQWLE( &p_data[0] );
898 p_esp->i_end_time = GetQWLE( &p_data[8] );
899 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
900 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
901 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
902 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
903 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
904 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
905 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
906 p_esp->i_flags = GetDWLE( &p_data[44] );
907 p_esp->i_stream_number = GetWLE( &p_data[48] );
908 p_esp->i_language_index = GetWLE( &p_data[50] );
909 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
910 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
911 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
915 p_esp->pi_stream_name_language = calloc( sizeof(int),
916 p_esp->i_stream_name_count );
917 p_esp->ppsz_stream_name = calloc( sizeof(char*),
918 p_esp->i_stream_name_count );
919 for( i = 0; i < p_esp->i_stream_name_count; i++ )
925 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
926 i_size = GetWLE( &p_data[2] );
929 psz = calloc( i_size/2 + 1, sizeof( char ) );
930 for( i_len = 0; i_len < i_size/2; i_len++ )
932 psz[i_len] = GetWLE( p_data + 2*i_len );
934 psz[i_size/2] = '\0'; \
937 p_esp->ppsz_stream_name[i] = psz;
940 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
943 int i_size = GetDWLE( &p_data[16 + 2] );
945 p_data += 16+2+4+i_size;
949 if( p_data < &p_peek[i_peek] )
952 /* Cannot fail as peek succeed */
953 stream_Read( s, NULL, p_data - p_peek );
955 p_sp = malloc( sizeof( asf_object_t ) );
957 if( ASF_ReadObject( s, p_sp, NULL ) )
963 /* This p_sp will be inserted by ReadRoot later */
964 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
969 msg_Dbg( s, "read \"extended stream properties object\":" );
970 msg_Dbg( s, " - start="I64Fd" end="I64Fd,
971 p_esp->i_start_time, p_esp->i_end_time );
972 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
973 p_esp->i_data_bitrate,
974 p_esp->i_buffer_size,
975 p_esp->i_initial_buffer_fullness );
976 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
977 p_esp->i_alternate_data_bitrate,
978 p_esp->i_alternate_buffer_size,
979 p_esp->i_alternate_initial_buffer_fullness );
980 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
981 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
982 msg_Dbg( s, " - stream number=%d language=%d",
983 p_esp->i_stream_number, p_esp->i_language_index );
984 msg_Dbg( s, " - average time per frame="I64Fd,
985 p_esp->i_average_time_per_frame );
986 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
987 for( i = 0; i < p_esp->i_stream_name_count; i++ )
988 msg_Dbg( s, " - lang id=%d name=%s",
989 p_esp->pi_stream_name_language[i],
990 p_esp->ppsz_stream_name[i] );
991 msg_Dbg( s, " - payload extension system count=%d",
992 p_esp->i_payload_extension_system_count );
996 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
998 asf_object_extended_stream_properties_t *p_esp =
999 (asf_object_extended_stream_properties_t *)p_obj;
1002 for( i = 0; i < p_esp->i_stream_name_count; i++ )
1003 FREENULL( p_esp->ppsz_stream_name[i] );
1004 FREENULL( p_esp->pi_stream_name_language );
1005 FREENULL( p_esp->ppsz_stream_name );
1009 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
1010 asf_object_t *p_obj)
1012 asf_object_advanced_mutual_exclusion_t *p_ae =
1013 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1014 const uint8_t *p_peek, *p_data;
1018 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1019 return VLC_EGENERIC;
1021 p_data = &p_peek[24];
1023 ASF_GetGUID( &p_ae->type, &p_data[0] );
1024 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1027 p_ae->pi_stream_number = calloc( sizeof(int),
1028 p_ae->i_stream_number_count );
1029 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1031 p_ae->pi_stream_number[i] = GetWLE( p_data );
1036 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1037 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1038 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1042 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1044 asf_object_advanced_mutual_exclusion_t *p_ae =
1045 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1047 FREENULL( p_ae->pi_stream_number );
1051 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1052 asf_object_t *p_obj)
1054 asf_object_stream_prioritization_t *p_sp =
1055 (asf_object_stream_prioritization_t *)p_obj;
1056 const uint8_t *p_peek, *p_data;
1060 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1061 return VLC_EGENERIC;
1063 p_data = &p_peek[24];
1065 p_sp->i_priority_count = GetWLE( &p_data[0] );
1068 p_sp->pi_priority_flag = calloc( sizeof(int), p_sp->i_priority_count );
1069 p_sp->pi_priority_stream_number =
1070 calloc( sizeof(int), p_sp->i_priority_count );
1072 for( i = 0; i < p_sp->i_priority_count; i++ )
1074 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1075 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1078 msg_Dbg( s, "read \"stream prioritization object\"" );
1079 for( i = 0; i < p_sp->i_priority_count; i++ )
1080 msg_Dbg( s, " - Stream:%d flags=0x%x",
1081 p_sp->pi_priority_stream_number[i],
1082 p_sp->pi_priority_flag[i] );
1086 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1088 asf_object_stream_prioritization_t *p_sp =
1089 (asf_object_stream_prioritization_t *)p_obj;
1091 FREENULL( p_sp->pi_priority_stream_number );
1092 FREENULL( p_sp->pi_priority_flag );
1096 static int ASF_ReadObject_extended_content_description( stream_t *s,
1097 asf_object_t *p_obj)
1099 asf_object_extended_content_description_t *p_ec =
1100 (asf_object_extended_content_description_t *)p_obj;
1101 const uint8_t *p_peek, *p_data;
1105 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1106 return VLC_EGENERIC;
1108 p_data = &p_peek[24];
1110 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1111 p_ec->ppsz_name = calloc( sizeof(char*), p_ec->i_count );
1112 p_ec->ppsz_value = calloc( sizeof(char*), p_ec->i_count );
1113 for( i = 0; i < p_ec->i_count; i++ )
1118 #define GETSTRINGW( psz_str, i_size ) \
1119 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1120 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1122 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1124 psz_str[i_size/2] = '\0';
1126 i_size = GetWLE( p_data ); p_data += 2;
1127 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1131 i_type = GetWLE( p_data ); p_data += 2;
1132 i_size = GetWLE( p_data ); p_data += 2;
1135 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1137 else if( i_type == 1 )
1141 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1142 for( j = 0; j < i_size; j++ )
1144 static const char hex[16] = "0123456789ABCDEF";
1145 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1146 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1148 p_ec->ppsz_value[i][2*i_size] = '\0';
1150 else if( i_type == 2 )
1153 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1155 else if( i_type == 3 )
1158 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1160 else if( i_type == 4 )
1163 asprintf( &p_ec->ppsz_value[i], I64Fd, GetQWLE(p_data));
1165 else if( i_type == 5 )
1168 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1171 p_ec->ppsz_value[i] = NULL;
1182 msg_Dbg( s, "read \"extended content description object\"" );
1183 for( i = 0; i < p_ec->i_count; i++ )
1184 msg_Dbg( s, " - '%s' = '%s'",
1186 p_ec->ppsz_value[i] );
1190 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1192 asf_object_extended_content_description_t *p_ec =
1193 (asf_object_extended_content_description_t *)p_obj;
1196 for( i = 0; i < p_ec->i_count; i++ )
1198 FREENULL( p_ec->ppsz_name[i] );
1199 FREENULL( p_ec->ppsz_value[i] );
1201 FREENULL( p_ec->ppsz_name );
1202 FREENULL( p_ec->ppsz_value );
1207 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1209 asf_object_XXX_t *p_XX =
1210 (asf_object_XXX_t *)p_obj;
1211 const uint8_t *p_peek;
1215 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1216 return VLC_EGENERIC;
1218 p_data = &p_peek[24];
1222 "Read \"XXX object\"" );
1226 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1228 asf_object_XXX_t *p_XX =
1229 (asf_object_XXX_t *)p_obj;
1239 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1240 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1242 } ASF_Object_Function [] =
1244 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1245 ASF_ReadObject_Header, ASF_FreeObject_Null },
1246 { &asf_object_data_guid, ASF_OBJECT_DATA,
1247 ASF_ReadObject_Data, ASF_FreeObject_Null },
1248 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1249 ASF_ReadObject_Index, ASF_FreeObject_Index },
1250 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1251 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1252 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1253 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1254 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1255 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1256 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1257 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1258 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1259 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1260 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1261 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1262 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1263 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1264 { &asf_object_language_list, ASF_OBJECT_OTHER,
1265 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1266 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1267 ASF_ReadObject_stream_bitrate_properties,
1268 ASF_FreeObject_stream_bitrate_properties },
1269 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1270 ASF_ReadObject_extended_stream_properties,
1271 ASF_FreeObject_extended_stream_properties },
1272 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1273 ASF_ReadObject_advanced_mutual_exclusion,
1274 ASF_FreeObject_advanced_mutual_exclusion },
1275 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1276 ASF_ReadObject_stream_prioritization,
1277 ASF_FreeObject_stream_prioritization },
1278 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1279 ASF_ReadObject_extended_content_description,
1280 ASF_FreeObject_extended_content_description },
1282 { &asf_object_null_guid, 0, NULL, NULL }
1285 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1286 asf_object_t *p_father )
1294 memset( p_obj, 0, sizeof( p_obj ) );
1296 if( ASF_ReadObjectCommon( s, p_obj ) )
1298 msg_Warn( s, "cannot read one asf object" );
1299 return VLC_EGENERIC;
1301 p_obj->common.p_father = p_father;
1302 p_obj->common.p_first = NULL;
1303 p_obj->common.p_next = NULL;
1304 p_obj->common.p_last = NULL;
1306 if( p_obj->common.i_object_size < 24 )
1308 msg_Warn( s, "found a corrupted asf object (size<24)" );
1309 return VLC_EGENERIC;
1312 /* find this object */
1313 for( i_index = 0; ; i_index++ )
1315 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1316 &p_obj->common.i_object_id ) ||
1317 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1318 &asf_object_null_guid ) )
1323 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1325 /* Now load this object */
1326 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1328 msg_Warn( s, "unknown asf object (not loaded)" );
1329 i_result = VLC_SUCCESS;
1333 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1335 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1338 /* link this object with father */
1339 if( p_father && ! i_result )
1341 if( p_father->common.p_first )
1343 p_father->common.p_last->common.p_next = p_obj;
1347 p_father->common.p_first = p_obj;
1349 p_father->common.p_last = p_obj;
1355 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1358 asf_object_t *p_child;
1360 if( !p_obj ) return;
1362 /* Free all child object */
1363 p_child = p_obj->common.p_first;
1366 asf_object_t *p_next;
1367 p_next = p_child->common.p_next;
1368 ASF_FreeObject( s, p_child );
1372 /* find this object */
1373 for( i_index = 0; ; i_index++ )
1375 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1376 &p_obj->common.i_object_id )||
1377 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1378 &asf_object_null_guid ) )
1384 /* Now free this object */
1385 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1388 "unknown asf object " GUID_FMT,
1389 GUID_PRINT( p_obj->common.i_object_id ) );
1395 "free asf object " GUID_FMT,
1396 GUID_PRINT( p_obj->common.i_object_id ) );
1398 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1404 /*****************************************************************************
1405 * ASF_ObjectDumpDebug:
1406 *****************************************************************************/
1410 const char *psz_name;
1411 } ASF_ObjectDumpDebugInfo[] =
1413 { &asf_object_header_guid, "Header" },
1414 { &asf_object_data_guid, "Data" },
1415 { &asf_object_index_guid, "Index" },
1416 { &asf_object_file_properties_guid, "File Properties" },
1417 { &asf_object_stream_properties_guid, "Stream Properties" },
1418 { &asf_object_content_description_guid, "Content Description" },
1419 { &asf_object_header_extension_guid, "Header Extension" },
1420 { &asf_object_metadata_guid, "Metadata" },
1421 { &asf_object_codec_list_guid, "Codec List" },
1422 { &asf_object_marker_guid, "Marker" },
1423 { &asf_object_stream_type_audio, "Stream Type Audio" },
1424 { &asf_object_stream_type_video, "Stream Type Video" },
1425 { &asf_object_stream_type_command, "Stream Type Command" },
1426 { &asf_object_language_list, "Language List" },
1427 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1428 { &asf_object_padding, "Padding" },
1429 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1430 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1431 { &asf_object_stream_prioritization, "Stream Prioritization" },
1432 { &asf_object_extended_content_description, "Extended content description"},
1434 { NULL, "Unknown" },
1438 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1439 asf_object_common_t *p_node, int i_level )
1443 union asf_object_u *p_child;
1444 const char *psz_name;
1447 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1449 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1450 &p_node->i_object_id ) )
1453 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1455 memset( str, ' ', sizeof( str ) );
1456 for( i = 1; i < i_level; i++ )
1460 snprintf( str + 5*i_level, 1024,
1461 "+ '%s' GUID "GUID_FMT" size:"I64Fu"pos:"I64Fu,
1463 GUID_PRINT( p_node->i_object_id ),
1464 p_node->i_object_size, p_node->i_object_pos );
1466 msg_Dbg( p_obj, "%s", str );
1468 for( p_child = p_node->p_first; p_child != NULL;
1469 p_child = p_child->common.p_next )
1471 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1475 /*****************************************************************************
1476 * ASF_ReadObjetRoot : parse the entire stream/file
1477 *****************************************************************************/
1478 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1480 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1481 asf_object_t *p_obj;
1483 p_root->i_type = ASF_OBJECT_ROOT;
1484 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1485 p_root->i_object_pos = stream_Tell( s );
1486 p_root->i_object_size = 0;
1487 p_root->p_first = NULL;
1488 p_root->p_last = NULL;
1489 p_root->p_next = NULL;
1490 p_root->p_hdr = NULL;
1491 p_root->p_data = NULL;
1492 p_root->p_fp = NULL;
1493 p_root->p_index = NULL;
1494 p_root->p_metadata = NULL;
1498 p_obj = malloc( sizeof( asf_object_t ) );
1500 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1505 switch( p_obj->common.i_type )
1507 case( ASF_OBJECT_HEADER ):
1508 p_root->p_hdr = (asf_object_header_t*)p_obj;
1510 case( ASF_OBJECT_DATA ):
1511 p_root->p_data = (asf_object_data_t*)p_obj;
1513 case( ASF_OBJECT_INDEX ):
1514 p_root->p_index = (asf_object_index_t*)p_obj;
1517 msg_Warn( s, "unknow object found" );
1520 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1521 p_obj->common.i_object_size <= 50 )
1523 /* probably a dump of broadcasted asf */
1526 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1528 /* For unseekable stream it's enough to play */
1532 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1538 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1540 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1541 &asf_object_file_properties_guid, 0 );
1545 asf_object_t *p_hdr_ext =
1546 ASF_FindObject( p_root->p_hdr,
1547 &asf_object_header_extension_guid, 0 );
1553 p_root->p_metadata =
1554 ASF_FindObject( p_hdr_ext,
1555 &asf_object_metadata_guid, 0 );
1556 /* Special case for broken designed file format :( */
1557 i_ext_stream = ASF_CountObject( p_hdr_ext,
1558 &asf_object_extended_stream_properties );
1559 for( i = 0; i < i_ext_stream; i++ )
1561 asf_object_t *p_esp =
1562 ASF_FindObject( p_hdr_ext,
1563 &asf_object_extended_stream_properties, i );
1564 if( p_esp->ext_stream.p_sp )
1566 asf_object_t *p_sp =
1567 (asf_object_t*)p_esp->ext_stream.p_sp;
1569 /* Insert this p_sp */
1570 p_root->p_hdr->p_last->common.p_next = p_sp;
1571 p_root->p_hdr->p_last = p_sp;
1573 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1578 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1579 (asf_object_common_t*)p_root, 0 );
1582 msg_Warn( s, "cannot find file properties object" );
1586 ASF_FreeObjectRoot( s, p_root );
1590 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1592 asf_object_t *p_obj;
1594 p_obj = p_root->p_first;
1597 asf_object_t *p_next;
1598 p_next = p_obj->common.p_next;
1599 ASF_FreeObject( s, p_obj );
1605 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1608 asf_object_t *p_child;
1610 if( !p_obj ) return( 0 );
1613 p_child = p_obj->common.p_first;
1616 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1620 p_child = p_child->common.p_next;
1625 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1628 asf_object_t *p_child;
1630 p_child = p_obj->common.p_first;
1634 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1644 p_child = p_child->common.p_next;