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 bool 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 )) )
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 )
86 ASF_GetGUID( &p_common->i_object_id, p_peek );
87 p_common->i_object_size = GetQWLE( p_peek + 16 );
88 p_common->i_object_pos = stream_Tell( s );
89 p_common->p_next = NULL;
93 "found object guid: " GUID_FMT " size:%"PRId64,
94 GUID_PRINT( p_common->i_object_id ),
95 p_common->i_object_size );
101 static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
106 if( ASF_ReadObjectCommon( s, &obj ) )
112 if( p_obj->common.i_object_size <= 0 )
115 if( p_obj->common.p_father &&
116 p_obj->common.p_father->common.i_object_size != 0 )
118 if( p_obj->common.p_father->common.i_object_pos +
119 p_obj->common.p_father->common.i_object_size <
120 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
121 /* 24 is min size of an object */
128 return stream_Seek( s, p_obj->common.i_object_pos +
129 p_obj->common.i_object_size );
132 static void ASF_FreeObject_Null( asf_object_t *pp_obj )
137 static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
139 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
140 asf_object_t *p_subobj;
142 const uint8_t *p_peek;
144 if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
147 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
148 p_hdr->i_reserved1 = p_peek[28];
149 p_hdr->i_reserved2 = p_peek[29];
150 p_hdr->p_first = NULL;
151 p_hdr->p_last = NULL;
155 "read \"header object\" subobj:%d, reserved1:%d, reserved2:%d",
156 p_hdr->i_sub_object_count,
158 p_hdr->i_reserved2 );
161 /* Cannot fail as peek succeed */
162 stream_Read( s, NULL, 30 );
164 /* Now load sub object */
167 p_subobj = malloc( sizeof( asf_object_t ) );
169 if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
174 if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
180 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
182 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
184 const uint8_t *p_peek;
186 if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
189 ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
190 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
191 p_data->i_reserved = GetWLE( p_peek + 48 );
195 "read \"data object\" file_id:" GUID_FMT " total data packet:"
196 "%"PRId64" reserved:%d",
197 GUID_PRINT( p_data->i_file_id ),
198 p_data->i_total_data_packets,
199 p_data->i_reserved );
205 static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
207 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
208 const uint8_t *p_peek;
211 /* We just ignore error on the index */
212 if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
213 __MAX( (int)p_index->i_object_size, 56 ) )
216 ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
217 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
218 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
219 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
220 p_index->index_entry = NULL;
224 "read \"index object\" file_id:" GUID_FMT
225 " index_entry_time_interval:%"PRId64" max_packet_count:%d "
226 "index_entry_count:%ld",
227 GUID_PRINT( p_index->i_file_id ),
228 p_index->i_index_entry_time_interval,
229 p_index->i_max_packet_count,
230 (long int)p_index->i_index_entry_count );
233 /* Sanity checking */
234 if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
235 p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
237 p_index->index_entry = calloc( p_index->i_index_entry_count,
238 sizeof(asf_index_entry_t) );
240 for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
243 p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
244 p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
250 static void ASF_FreeObject_Index( asf_object_t *p_obj )
252 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
254 FREENULL( p_index->index_entry );
257 static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
259 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
261 const uint8_t *p_peek;
263 if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 )
266 ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
267 p_fp->i_file_size = GetQWLE( p_peek + 40 );
268 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
269 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
270 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
271 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
272 p_fp->i_preroll = GetQWLE( p_peek + 80 );
273 p_fp->i_flags = GetDWLE( p_peek + 88 );
274 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
275 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
276 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
280 "read \"file properties object\" file_id:" GUID_FMT
281 " file_size:%"PRId64" creation_date:%"PRId64" data_packets_count:"
282 "%"PRId64" play_duration:%"PRId64" send_duration:%"PRId64" preroll:%"PRId64
283 " flags:%d min_data_packet_size:%d "
284 " max_data_packet_size:%d max_bitrate:%d",
285 GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
286 p_fp->i_creation_date, p_fp->i_data_packets_count,
287 p_fp->i_play_duration, p_fp->i_send_duration,
288 p_fp->i_preroll, p_fp->i_flags,
289 p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
290 p_fp->i_max_bitrate );
296 static void ASF_FreeObject_metadata( asf_object_t *p_obj )
298 asf_object_metadata_t *p_meta =
299 (asf_object_metadata_t *)p_obj;
302 for( i = 0; i < p_meta->i_record_entries_count; i++ )
304 free( p_meta->record[i].psz_name );
305 free( p_meta->record[i].p_data );
307 free( p_meta->record );
310 static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
312 asf_object_metadata_t *p_meta =
313 (asf_object_metadata_t *)p_obj;
317 const uint8_t *p_peek, *p_data;
322 if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) <
323 __MAX( (int)p_meta->i_object_size, 26 ) )
326 p_meta->i_record_entries_count = GetWLE( p_peek + 24 );
328 p_data = p_peek + 26;
330 p_meta->record = calloc( p_meta->i_record_entries_count,
331 sizeof(asf_metadata_record_t) );
333 for( i = 0; i < p_meta->i_record_entries_count; i++ )
335 asf_metadata_record_t *p_record = &p_meta->record[i];
340 if( &p_data[2+2+2+2+4] > &p_peek[i_peek] )
343 if( GetWLE( p_data ) != 0 )
347 p_record->i_stream = GetWLE( p_data ); p_data += 2;
348 i_name = GetWLE( p_data ); p_data += 2;
349 p_record->i_type = GetWLE( p_data ); p_data += 2;
350 i_data = GetDWLE( p_data ); p_data += 4;
352 if( &p_data[i_name+i_data] > &p_peek[i_peek] )
356 p_record->psz_name = malloc( i_name/2 + 1 );
357 for( j = 0; j < i_name/2; j++ )
359 p_record->psz_name[j] = GetWLE( p_data ); p_data += 2;
361 p_record->psz_name[j] = 0;
364 if( p_record->i_type == ASF_METADATA_TYPE_STRING )
366 p_record->p_data = malloc( i_data/2 + 1 );
367 p_record->i_data = i_data/2; /* FIXME Is that needed ? */
368 for( j = 0; j < i_data/2; j++ )
370 p_record->p_data[j] = GetWLE( &p_data[2*j] );
372 p_record->p_data[j] = 0; /* just to make sure */
376 else if( p_record->i_type == ASF_METADATA_TYPE_BYTE )
378 p_record->p_data = malloc( i_data );
379 p_record->i_data = i_data;
381 memcpy( p_record->p_data, p_data, i_data );
385 else if( p_record->i_type == ASF_METADATA_TYPE_QWORD )
387 p_record->i_val = GetQWLE( p_data ); p_data += 8;
389 else if( p_record->i_type == ASF_METADATA_TYPE_DWORD )
391 p_record->i_val = GetDWLE( p_data ); p_data += 4;
393 else if( p_record->i_type == ASF_METADATA_TYPE_WORD )
395 p_record->i_val = GetWLE( p_data ); p_data += 2;
397 else if( p_record->i_type == ASF_METADATA_TYPE_BOOL )
399 p_record->i_val = GetWLE( p_data ); p_data += 2;
407 p_meta->i_record_entries_count = i;
411 "read \"metadata object\" %d entries",
412 p_meta->i_record_entries_count );
413 for( j = 0; j < p_meta->i_record_entries_count; j++ )
415 asf_metadata_record_t *p_rec = &p_meta->record[j];
417 if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
418 msg_Dbg( s, " - %s=%s",
419 p_rec->psz_name, p_rec->p_data );
420 else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE )
421 msg_Dbg( s, " - %s (%i bytes)",
422 p_rec->psz_name, p_rec->i_data );
424 msg_Dbg( s, " - %s=%"PRId64,
425 p_rec->psz_name, p_rec->i_val );
432 static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
434 asf_object_header_extension_t *p_he =
435 (asf_object_header_extension_t *)p_obj;
437 const uint8_t *p_peek;
439 if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
443 ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
444 p_he->i_reserved2 = GetWLE( p_peek + 40 );
445 p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
446 if( p_he->i_header_extension_size )
448 p_he->p_header_extension_data =
449 malloc( p_he->i_header_extension_size );
450 memcpy( p_he->p_header_extension_data, p_peek + 46,
451 p_he->i_header_extension_size );
455 p_he->p_header_extension_data = NULL;
460 "read \"header extension object\" reserved1:" GUID_FMT
461 " reserved2:%d header_extension_size:%d",
462 GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2,
463 p_he->i_header_extension_size );
466 if( !p_he->i_header_extension_size ) return VLC_SUCCESS;
468 /* Read the extension objects */
469 stream_Read( s, NULL, 46 );
472 asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
474 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
480 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
489 static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
491 asf_object_header_extension_t *p_he =
492 (asf_object_header_extension_t *)p_obj;
494 FREENULL( p_he->p_header_extension_data );
497 static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
499 asf_object_stream_properties_t *p_sp =
500 (asf_object_stream_properties_t*)p_obj;
502 const uint8_t *p_peek;
504 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
507 ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
508 ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
509 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
510 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
511 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
512 p_sp->i_flags = GetWLE( p_peek + 72 );
513 p_sp->i_stream_number = p_sp->i_flags&0x07f;
514 p_sp->i_reserved = GetDWLE( p_peek + 74 );
517 if( p_sp->i_type_specific_data_length )
519 if( i_peek < p_sp->i_type_specific_data_length )
522 p_sp->p_type_specific_data =
523 malloc( p_sp->i_type_specific_data_length );
524 if( p_sp->p_type_specific_data == NULL )
527 memcpy( p_sp->p_type_specific_data, p_peek + 78,
528 p_sp->i_type_specific_data_length );
529 i_peek -= p_sp->i_type_specific_data_length;
533 p_sp->p_type_specific_data = NULL;
536 if( p_sp->i_error_correction_data_length )
538 if( i_peek < p_sp->i_error_correction_data_length )
540 free( p_sp->p_type_specific_data );
544 p_sp->p_error_correction_data =
545 malloc( p_sp->i_error_correction_data_length );
546 if( p_sp->p_error_correction_data == NULL )
548 free( p_sp->p_type_specific_data );
551 memcpy( p_sp->p_error_correction_data,
552 p_peek + 78 + p_sp->i_type_specific_data_length,
553 p_sp->i_error_correction_data_length );
557 p_sp->p_error_correction_data = NULL;
562 "read \"stream Properties object\" stream_type:" GUID_FMT
563 " error_correction_type:" GUID_FMT " time_offset:%"PRId64
564 " type_specific_data_length:%d error_correction_data_length:%d"
565 " flags:0x%x stream_number:%d",
566 GUID_PRINT( p_sp->i_stream_type ),
567 GUID_PRINT( p_sp->i_error_correction_type ),
569 p_sp->i_type_specific_data_length,
570 p_sp->i_error_correction_data_length,
572 p_sp->i_stream_number );
578 static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
580 asf_object_stream_properties_t *p_sp =
581 (asf_object_stream_properties_t*)p_obj;
583 FREENULL( p_sp->p_type_specific_data );
584 FREENULL( p_sp->p_error_correction_data );
588 static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
590 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
592 const uint8_t *p_peek, *p_data;
594 unsigned int i_codec;
596 if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
599 ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
600 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
602 p_data = p_peek + 44;
604 if( p_cl->i_codec_entries_count > 0 )
606 p_cl->codec = calloc( p_cl->i_codec_entries_count,
607 sizeof( asf_codec_entry_t ) );
609 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
611 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
614 p_codec->i_type = GetWLE( p_data ); p_data += 2;
616 i_len = GetWLE( p_data ); p_data += 2;
617 p_codec->psz_name = calloc( i_len + 1, sizeof(char) );
618 for( i = 0; i < i_len; i++ )
620 p_codec->psz_name[i] = GetWLE( p_data + 2*i );
622 p_codec->psz_name[i_len] = '\0';
626 i_len = GetWLE( p_data ); p_data += 2;
627 p_codec->psz_description = calloc( i_len + 1, sizeof(char) );
628 for( i = 0; i < i_len; i++ )
630 p_codec->psz_description[i] = GetWLE( p_data + 2*i );
632 p_codec->psz_description[i_len] = '\0';
635 /* opaque information */
636 p_codec->i_information_length = GetWLE( p_data ); p_data += 2;
637 if( p_codec->i_information_length > 0 )
639 p_codec->p_information = malloc( p_codec->i_information_length );
640 memcpy( p_codec->p_information, p_data, p_codec->i_information_length );
641 p_data += p_codec->i_information_length;
645 p_codec->p_information = NULL;
655 msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT
656 " codec_entries_count:%d",
657 GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count );
659 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
661 #define codec p_cl->codec[i_codec]
662 msg_Dbg( s, " - codec[%d] %s name:\"%s\" "
663 "description:\"%s\" information_length:%d",
664 i_codec, ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ?
665 "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ?
666 "audio" : "unknown" ),
667 codec.psz_name, codec.psz_description,
668 codec.i_information_length );
676 static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
678 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
679 unsigned int i_codec;
681 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
683 asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
685 FREENULL( p_codec->psz_name );
686 FREENULL( p_codec->psz_description );
687 FREENULL( p_codec->p_information );
689 FREENULL( p_cl->codec );
692 /* Microsoft should go to hell. This time the length give number of bytes
693 * and for the some others object, length give char16 count ... */
694 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
696 asf_object_content_description_t *p_cd =
697 (asf_object_content_description_t *)p_obj;
698 const uint8_t *p_peek, *p_data;
699 int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
700 vlc_iconv_t cd = (vlc_iconv_t)-1;
701 const char *ib = NULL;
703 size_t i_ibl, i_obl, i_len;
705 if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
708 cd = vlc_iconv_open("UTF-8", "UTF-16LE");
709 if( cd == (vlc_iconv_t)-1 )
711 msg_Err( s, "vlc_iconv_open failed" );
715 /* FIXME i_size*3 is the worst case. */
716 #define GETSTRINGW( psz_str, i_size ) \
717 psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
718 ib = (const char *)p_data; \
722 i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
725 p_data = p_peek + 24;
727 i_title = GetWLE( p_data ); p_data += 2;
728 i_artist= GetWLE( p_data ); p_data += 2;
729 i_copyright = GetWLE( p_data ); p_data += 2;
730 i_description = GetWLE( p_data ); p_data += 2;
731 i_rating = GetWLE( p_data ); p_data += 2;
733 GETSTRINGW( p_cd->psz_title, i_title );
734 GETSTRINGW( p_cd->psz_artist, i_artist );
735 GETSTRINGW( p_cd->psz_copyright, i_copyright );
736 GETSTRINGW( p_cd->psz_description, i_description );
737 GETSTRINGW( p_cd->psz_rating, i_rating );
743 "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
747 p_cd->psz_description,
755 static void ASF_FreeObject_content_description( asf_object_t *p_obj)
757 asf_object_content_description_t *p_cd =
758 (asf_object_content_description_t *)p_obj;
760 FREENULL( p_cd->psz_title );
761 FREENULL( p_cd->psz_artist );
762 FREENULL( p_cd->psz_copyright );
763 FREENULL( p_cd->psz_description );
764 FREENULL( p_cd->psz_rating );
768 static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
770 asf_object_language_list_t *p_ll =
771 (asf_object_language_list_t*)p_obj;
772 const uint8_t *p_peek, *p_data;
776 if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
779 p_data = &p_peek[24];
781 p_ll->i_language = GetWLE( &p_data[0] ); p_data += 2;
782 if( p_ll->i_language > 0 )
784 p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
786 for( i = 0; i < p_ll->i_language; i++ )
789 int i_size = *p_data++;
792 psz = calloc( i_size/2 + 1, sizeof(char) );
793 for( i_len = 0; i_len < i_size/2; i_len++ )
795 psz[i_len] = GetWLE( p_data + 2*i_len );
797 psz[i_size/2] = '\0'; \
800 p_ll->ppsz_language[i] = psz;
805 msg_Dbg( s, "read \"language list object\" %d entries",
807 for( i = 0; i < p_ll->i_language; i++ )
808 msg_Dbg( s, " - '%s'",
809 p_ll->ppsz_language[i] );
814 static void ASF_FreeObject_language_list( asf_object_t *p_obj)
816 asf_object_language_list_t *p_ll =
817 (asf_object_language_list_t *)p_obj;
820 for( i = 0; i < p_ll->i_language; i++ )
821 FREENULL( p_ll->ppsz_language[i] );
822 FREENULL( p_ll->ppsz_language );
825 /* Stream bitrate properties */
826 static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
829 asf_object_stream_bitrate_properties_t *p_sb =
830 (asf_object_stream_bitrate_properties_t *)p_obj;
831 const uint8_t *p_peek, *p_data;
835 if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
838 p_data = &p_peek[24];
840 p_sb->i_bitrate = GetWLE( &p_data[0] ); p_data += 2;
841 if( p_sb->i_bitrate > 127 ) p_sb->i_bitrate = 127; /* Buggy ? */
842 for( i = 0; i < p_sb->i_bitrate; i++ )
844 p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
845 p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
851 msg_Dbg( s,"read \"stream bitrate properties object\"" );
852 for( i = 0; i < p_sb->i_bitrate; i++ )
854 msg_Dbg( s," - stream=%d bitrate=%d",
855 p_sb->bitrate[i].i_stream_number,
856 p_sb->bitrate[i].i_avg_bitrate );
861 static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
866 static int ASF_ReadObject_extended_stream_properties( stream_t *s,
869 asf_object_extended_stream_properties_t *p_esp =
870 (asf_object_extended_stream_properties_t*)p_obj;
871 const uint8_t *p_peek, *p_data;
874 if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
877 p_data = &p_peek[24];
879 p_esp->i_start_time = GetQWLE( &p_data[0] );
880 p_esp->i_end_time = GetQWLE( &p_data[8] );
881 p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
882 p_esp->i_buffer_size = GetDWLE( &p_data[20] );
883 p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
884 p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
885 p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
886 p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
887 p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
888 p_esp->i_flags = GetDWLE( &p_data[44] );
889 p_esp->i_stream_number = GetWLE( &p_data[48] );
890 p_esp->i_language_index = GetWLE( &p_data[50] );
891 p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
892 p_esp->i_stream_name_count = GetWLE( &p_data[60] );
893 p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
897 p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count,
899 p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
901 for( i = 0; i < p_esp->i_stream_name_count; i++ )
907 p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
908 i_size = GetWLE( &p_data[2] );
911 psz = calloc( i_size/2 + 1, sizeof(char) );
912 for( i_len = 0; i_len < i_size/2; i_len++ )
914 psz[i_len] = GetWLE( p_data + 2*i_len );
916 psz[i_size/2] = '\0'; \
919 p_esp->ppsz_stream_name[i] = psz;
922 for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
925 int i_size = GetDWLE( &p_data[16 + 2] );
927 p_data += 16+2+4+i_size;
931 if( p_data < &p_peek[i_peek] )
934 /* Cannot fail as peek succeed */
935 stream_Read( s, NULL, p_data - p_peek );
937 p_sp = malloc( sizeof( asf_object_t ) );
939 if( ASF_ReadObject( s, p_sp, NULL ) )
945 /* This p_sp will be inserted by ReadRoot later */
946 p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
951 msg_Dbg( s, "read \"extended stream properties object\":" );
952 msg_Dbg( s, " - start=%"PRId64" end=%"PRId64,
953 p_esp->i_start_time, p_esp->i_end_time );
954 msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
955 p_esp->i_data_bitrate,
956 p_esp->i_buffer_size,
957 p_esp->i_initial_buffer_fullness );
958 msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
959 p_esp->i_alternate_data_bitrate,
960 p_esp->i_alternate_buffer_size,
961 p_esp->i_alternate_initial_buffer_fullness );
962 msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
963 msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
964 msg_Dbg( s, " - stream number=%d language=%d",
965 p_esp->i_stream_number, p_esp->i_language_index );
966 msg_Dbg( s, " - average time per frame=%"PRId64,
967 p_esp->i_average_time_per_frame );
968 msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
969 for( i = 0; i < p_esp->i_stream_name_count; i++ )
970 msg_Dbg( s, " - lang id=%d name=%s",
971 p_esp->pi_stream_name_language[i],
972 p_esp->ppsz_stream_name[i] );
973 msg_Dbg( s, " - payload extension system count=%d",
974 p_esp->i_payload_extension_system_count );
978 static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
980 asf_object_extended_stream_properties_t *p_esp =
981 (asf_object_extended_stream_properties_t *)p_obj;
984 for( i = 0; i < p_esp->i_stream_name_count; i++ )
985 FREENULL( p_esp->ppsz_stream_name[i] );
986 FREENULL( p_esp->pi_stream_name_language );
987 FREENULL( p_esp->ppsz_stream_name );
991 static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
994 asf_object_advanced_mutual_exclusion_t *p_ae =
995 (asf_object_advanced_mutual_exclusion_t *)p_obj;
996 const uint8_t *p_peek, *p_data;
1000 if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
1001 return VLC_EGENERIC;
1003 p_data = &p_peek[24];
1005 ASF_GetGUID( &p_ae->type, &p_data[0] );
1006 p_ae->i_stream_number_count = GetWLE( &p_data[16] );
1009 p_ae->pi_stream_number = calloc( p_ae->i_stream_number_count,
1011 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1013 p_ae->pi_stream_number[i] = GetWLE( p_data );
1018 msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
1019 for( i = 0; i < p_ae->i_stream_number_count; i++ )
1020 msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
1024 static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
1026 asf_object_advanced_mutual_exclusion_t *p_ae =
1027 (asf_object_advanced_mutual_exclusion_t *)p_obj;
1029 FREENULL( p_ae->pi_stream_number );
1033 static int ASF_ReadObject_stream_prioritization( stream_t *s,
1034 asf_object_t *p_obj)
1036 asf_object_stream_prioritization_t *p_sp =
1037 (asf_object_stream_prioritization_t *)p_obj;
1038 const uint8_t *p_peek, *p_data;
1042 if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
1043 return VLC_EGENERIC;
1045 p_data = &p_peek[24];
1047 p_sp->i_priority_count = GetWLE( &p_data[0] );
1050 p_sp->pi_priority_flag = calloc( p_sp->i_priority_count, sizeof(int) );
1051 p_sp->pi_priority_stream_number =
1052 calloc( p_sp->i_priority_count, sizeof(int) );
1054 for( i = 0; i < p_sp->i_priority_count; i++ )
1056 p_sp->pi_priority_stream_number[i] = GetWLE( p_data ); p_data += 2;
1057 p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
1060 msg_Dbg( s, "read \"stream prioritization object\"" );
1061 for( i = 0; i < p_sp->i_priority_count; i++ )
1062 msg_Dbg( s, " - Stream:%d flags=0x%x",
1063 p_sp->pi_priority_stream_number[i],
1064 p_sp->pi_priority_flag[i] );
1068 static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
1070 asf_object_stream_prioritization_t *p_sp =
1071 (asf_object_stream_prioritization_t *)p_obj;
1073 FREENULL( p_sp->pi_priority_stream_number );
1074 FREENULL( p_sp->pi_priority_flag );
1078 static int ASF_ReadObject_extended_content_description( stream_t *s,
1079 asf_object_t *p_obj)
1081 asf_object_extended_content_description_t *p_ec =
1082 (asf_object_extended_content_description_t *)p_obj;
1083 const uint8_t *p_peek, *p_data;
1087 if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
1088 return VLC_EGENERIC;
1090 p_data = &p_peek[24];
1092 p_ec->i_count = GetWLE( p_data ); p_data += 2;
1093 p_ec->ppsz_name = calloc( p_ec->i_count, sizeof(char*) );
1094 p_ec->ppsz_value = calloc( p_ec->i_count, sizeof(char*) );
1095 for( i = 0; i < p_ec->i_count; i++ )
1100 #define GETSTRINGW( psz_str, i_size ) \
1101 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
1102 for( i_len = 0; i_len < i_size/2; i_len++ ) \
1104 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
1106 psz_str[i_size/2] = '\0';
1108 i_size = GetWLE( p_data ); p_data += 2;
1109 GETSTRINGW( p_ec->ppsz_name[i], i_size );
1113 i_type = GetWLE( p_data ); p_data += 2;
1114 i_size = GetWLE( p_data ); p_data += 2;
1117 GETSTRINGW( p_ec->ppsz_value[i], i_size );
1119 else if( i_type == 1 )
1123 p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
1124 for( j = 0; j < i_size; j++ )
1126 static const char hex[16] = "0123456789ABCDEF";
1127 p_ec->ppsz_value[i][2*j+0] = hex[p_data[0]>>4];
1128 p_ec->ppsz_value[i][2*j+1] = hex[p_data[0]&0xf];
1130 p_ec->ppsz_value[i][2*i_size] = '\0';
1132 else if( i_type == 2 )
1135 p_ec->ppsz_value[i] = strdup( *p_data ? "true" : "false" );
1137 else if( i_type == 3 )
1140 asprintf( &p_ec->ppsz_value[i], "%d", GetDWLE(p_data));
1142 else if( i_type == 4 )
1145 asprintf( &p_ec->ppsz_value[i], "%"PRId64, GetQWLE(p_data));
1147 else if( i_type == 5 )
1150 asprintf( &p_ec->ppsz_value[i], "%d", GetWLE(p_data));
1153 p_ec->ppsz_value[i] = NULL;
1164 msg_Dbg( s, "read \"extended content description object\"" );
1165 for( i = 0; i < p_ec->i_count; i++ )
1166 msg_Dbg( s, " - '%s' = '%s'",
1168 p_ec->ppsz_value[i] );
1172 static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
1174 asf_object_extended_content_description_t *p_ec =
1175 (asf_object_extended_content_description_t *)p_obj;
1178 for( i = 0; i < p_ec->i_count; i++ )
1180 FREENULL( p_ec->ppsz_name[i] );
1181 FREENULL( p_ec->ppsz_value[i] );
1183 FREENULL( p_ec->ppsz_name );
1184 FREENULL( p_ec->ppsz_value );
1189 static int ASF_ReadObject_XXX(stream_t *s, asf_object_t *p_obj)
1191 asf_object_XXX_t *p_XX =
1192 (asf_object_XXX_t *)p_obj;
1193 const uint8_t *p_peek;
1197 if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
1198 return VLC_EGENERIC;
1200 p_data = &p_peek[24];
1204 "Read \"XXX object\"" );
1208 static void ASF_FreeObject_XXX( asf_object_t *p_obj)
1210 asf_object_XXX_t *p_XX =
1211 (asf_object_XXX_t *)p_obj;
1221 int (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
1222 void (*ASF_FreeObject_function)( asf_object_t *p_obj );
1224 } ASF_Object_Function [] =
1226 { &asf_object_header_guid, ASF_OBJECT_HEADER,
1227 ASF_ReadObject_Header, ASF_FreeObject_Null },
1228 { &asf_object_data_guid, ASF_OBJECT_DATA,
1229 ASF_ReadObject_Data, ASF_FreeObject_Null },
1230 { &asf_object_index_guid, ASF_OBJECT_INDEX,
1231 ASF_ReadObject_Index, ASF_FreeObject_Index },
1232 { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
1233 ASF_ReadObject_file_properties, ASF_FreeObject_Null },
1234 { &asf_object_stream_properties_guid, ASF_OBJECT_STREAM_PROPERTIES,
1235 ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
1236 { &asf_object_header_extension_guid, ASF_OBJECT_HEADER_EXTENSION,
1237 ASF_ReadObject_header_extension, ASF_FreeObject_header_extension},
1238 { &asf_object_metadata_guid, ASF_OBJECT_METADATA,
1239 ASF_ReadObject_metadata, ASF_FreeObject_metadata},
1240 { &asf_object_codec_list_guid, ASF_OBJECT_CODEC_LIST,
1241 ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
1242 { &asf_object_marker_guid, ASF_OBJECT_MARKER, NULL, NULL },
1243 { &asf_object_padding, ASF_OBJECT_PADDING, NULL, NULL },
1244 { &asf_object_content_description_guid, ASF_OBJECT_CONTENT_DESCRIPTION,
1245 ASF_ReadObject_content_description, ASF_FreeObject_content_description },
1246 { &asf_object_language_list, ASF_OBJECT_OTHER,
1247 ASF_ReadObject_language_list, ASF_FreeObject_language_list },
1248 { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
1249 ASF_ReadObject_stream_bitrate_properties,
1250 ASF_FreeObject_stream_bitrate_properties },
1251 { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
1252 ASF_ReadObject_extended_stream_properties,
1253 ASF_FreeObject_extended_stream_properties },
1254 { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
1255 ASF_ReadObject_advanced_mutual_exclusion,
1256 ASF_FreeObject_advanced_mutual_exclusion },
1257 { &asf_object_stream_prioritization, ASF_OBJECT_OTHER,
1258 ASF_ReadObject_stream_prioritization,
1259 ASF_FreeObject_stream_prioritization },
1260 { &asf_object_extended_content_description, ASF_OBJECT_OTHER,
1261 ASF_ReadObject_extended_content_description,
1262 ASF_FreeObject_extended_content_description },
1264 { &asf_object_null_guid, 0, NULL, NULL }
1267 static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
1268 asf_object_t *p_father )
1276 memset( p_obj, 0, sizeof( *p_obj ) );
1278 if( ASF_ReadObjectCommon( s, p_obj ) )
1280 msg_Warn( s, "cannot read one asf object" );
1281 return VLC_EGENERIC;
1283 p_obj->common.p_father = p_father;
1284 p_obj->common.p_first = NULL;
1285 p_obj->common.p_next = NULL;
1286 p_obj->common.p_last = NULL;
1288 if( p_obj->common.i_object_size < 24 )
1290 msg_Warn( s, "found a corrupted asf object (size<24)" );
1291 return VLC_EGENERIC;
1294 /* find this object */
1295 for( i_index = 0; ; i_index++ )
1297 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1298 &p_obj->common.i_object_id ) ||
1299 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1300 &asf_object_null_guid ) )
1305 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
1307 /* Now load this object */
1308 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
1310 msg_Warn( s, "unknown asf object (not loaded)" );
1311 i_result = VLC_SUCCESS;
1315 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
1317 (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
1320 /* link this object with father */
1321 if( p_father && ! i_result )
1323 if( p_father->common.p_first )
1325 p_father->common.p_last->common.p_next = p_obj;
1329 p_father->common.p_first = p_obj;
1331 p_father->common.p_last = p_obj;
1337 static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
1340 asf_object_t *p_child;
1345 /* Free all child object */
1346 p_child = p_obj->common.p_first;
1349 asf_object_t *p_next;
1350 p_next = p_child->common.p_next;
1351 ASF_FreeObject( s, p_child );
1355 /* find this object */
1356 for( i_index = 0; ; i_index++ )
1358 if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1359 &p_obj->common.i_object_id )||
1360 ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
1361 &asf_object_null_guid ) )
1367 /* Now free this object */
1368 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
1371 "unknown asf object " GUID_FMT,
1372 GUID_PRINT( p_obj->common.i_object_id ) );
1378 "free asf object " GUID_FMT,
1379 GUID_PRINT( p_obj->common.i_object_id ) );
1381 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
1386 /*****************************************************************************
1387 * ASF_ObjectDumpDebug:
1388 *****************************************************************************/
1392 const char *psz_name;
1393 } ASF_ObjectDumpDebugInfo[] =
1395 { &asf_object_header_guid, "Header" },
1396 { &asf_object_data_guid, "Data" },
1397 { &asf_object_index_guid, "Index" },
1398 { &asf_object_file_properties_guid, "File Properties" },
1399 { &asf_object_stream_properties_guid, "Stream Properties" },
1400 { &asf_object_content_description_guid, "Content Description" },
1401 { &asf_object_header_extension_guid, "Header Extension" },
1402 { &asf_object_metadata_guid, "Metadata" },
1403 { &asf_object_codec_list_guid, "Codec List" },
1404 { &asf_object_marker_guid, "Marker" },
1405 { &asf_object_stream_type_audio, "Stream Type Audio" },
1406 { &asf_object_stream_type_video, "Stream Type Video" },
1407 { &asf_object_stream_type_command, "Stream Type Command" },
1408 { &asf_object_language_list, "Language List" },
1409 { &asf_object_stream_bitrate_properties, "Stream Bitrate Propoerties" },
1410 { &asf_object_padding, "Padding" },
1411 { &asf_object_extended_stream_properties, "Extended Stream Properties" },
1412 { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
1413 { &asf_object_stream_prioritization, "Stream Prioritization" },
1414 { &asf_object_extended_content_description, "Extended content description"},
1416 { NULL, "Unknown" },
1420 static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
1421 asf_object_common_t *p_node, int i_level )
1425 union asf_object_u *p_child;
1426 const char *psz_name;
1429 for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
1431 if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
1432 &p_node->i_object_id ) )
1435 psz_name = ASF_ObjectDumpDebugInfo[i].psz_name;
1437 memset( str, ' ', sizeof( str ) );
1438 for( i = 1; i < i_level; i++ )
1442 snprintf( str + 5*i_level, 1024,
1443 "+ '%s' GUID "GUID_FMT" size:%"PRIu64"pos:%"PRIu64,
1445 GUID_PRINT( p_node->i_object_id ),
1446 p_node->i_object_size, p_node->i_object_pos );
1448 msg_Dbg( p_obj, "%s", str );
1450 for( p_child = p_node->p_first; p_child != NULL;
1451 p_child = p_child->common.p_next )
1453 ASF_ObjectDumpDebug( p_obj, &p_child->common, i_level + 1 );
1457 /*****************************************************************************
1458 * ASF_ReadObjetRoot : parse the entire stream/file
1459 *****************************************************************************/
1460 asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
1462 asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
1463 asf_object_t *p_obj;
1465 p_root->i_type = ASF_OBJECT_ROOT;
1466 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
1467 p_root->i_object_pos = stream_Tell( s );
1468 p_root->i_object_size = 0;
1469 p_root->p_first = NULL;
1470 p_root->p_last = NULL;
1471 p_root->p_next = NULL;
1472 p_root->p_hdr = NULL;
1473 p_root->p_data = NULL;
1474 p_root->p_fp = NULL;
1475 p_root->p_index = NULL;
1476 p_root->p_metadata = NULL;
1480 p_obj = malloc( sizeof( asf_object_t ) );
1482 if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
1487 switch( p_obj->common.i_type )
1489 case( ASF_OBJECT_HEADER ):
1490 p_root->p_hdr = (asf_object_header_t*)p_obj;
1492 case( ASF_OBJECT_DATA ):
1493 p_root->p_data = (asf_object_data_t*)p_obj;
1495 case( ASF_OBJECT_INDEX ):
1496 p_root->p_index = (asf_object_index_t*)p_obj;
1499 msg_Warn( s, "unknow object found" );
1502 if( p_obj->common.i_type == ASF_OBJECT_DATA &&
1503 p_obj->common.i_object_size <= 50 )
1505 /* probably a dump of broadcasted asf */
1508 if( !b_seekable && p_root->p_hdr && p_root->p_data )
1510 /* For unseekable stream it's enough to play */
1514 if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
1518 if( p_root->p_hdr != NULL && p_root->p_data != NULL )
1520 p_root->p_fp = ASF_FindObject( p_root->p_hdr,
1521 &asf_object_file_properties_guid, 0 );
1525 asf_object_t *p_hdr_ext =
1526 ASF_FindObject( p_root->p_hdr,
1527 &asf_object_header_extension_guid, 0 );
1533 p_root->p_metadata =
1534 ASF_FindObject( p_hdr_ext,
1535 &asf_object_metadata_guid, 0 );
1536 /* Special case for broken designed file format :( */
1537 i_ext_stream = ASF_CountObject( p_hdr_ext,
1538 &asf_object_extended_stream_properties );
1539 for( i = 0; i < i_ext_stream; i++ )
1541 asf_object_t *p_esp =
1542 ASF_FindObject( p_hdr_ext,
1543 &asf_object_extended_stream_properties, i );
1544 if( p_esp->ext_stream.p_sp )
1546 asf_object_t *p_sp =
1547 (asf_object_t*)p_esp->ext_stream.p_sp;
1549 /* Insert this p_sp */
1550 p_root->p_hdr->p_last->common.p_next = p_sp;
1551 p_root->p_hdr->p_last = p_sp;
1553 p_sp->common.p_father = (asf_object_t*)p_root->p_hdr;
1558 ASF_ObjectDumpDebug( VLC_OBJECT(s),
1559 (asf_object_common_t*)p_root, 0 );
1562 msg_Warn( s, "cannot find file properties object" );
1566 ASF_FreeObjectRoot( s, p_root );
1570 void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
1572 asf_object_t *p_obj;
1574 p_obj = p_root->p_first;
1577 asf_object_t *p_next;
1578 p_next = p_obj->common.p_next;
1579 ASF_FreeObject( s, p_obj );
1585 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
1588 asf_object_t *p_child;
1594 p_child = p_obj->common.p_first;
1597 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1600 p_child = p_child->common.p_next;
1605 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
1608 asf_object_t *p_child;
1610 p_child = p_obj->common.p_first;
1614 if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
1621 p_child = p_child->common.p_next;