1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: libasf.c,v 1.6 2002/11/14 16:17:47 fenrir Exp $
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 #include <stdlib.h> /* malloc(), free() */
24 #include <string.h> /* strdup() */
26 #include <sys/types.h>
29 #include <vlc/input.h>
36 if( p ) {free( p ); p = NULL; }
38 #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"
39 #define GUID_PRINT( guid ) \
43 (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
44 (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
46 /* Some functions to manipulate memory */
47 static uint16_t GetWLE( uint8_t *p_buff )
49 return( (p_buff[0]) + ( p_buff[1] <<8 ) );
52 static uint32_t GetDWLE( uint8_t *p_buff )
54 return( p_buff[0] + ( p_buff[1] <<8 ) +
55 ( p_buff[2] <<16 ) + ( p_buff[3] <<24 ) );
58 static uint64_t GetQWLE( uint8_t *p_buff )
60 return( ( (uint64_t)GetDWLE( p_buff ) )|
61 ( (uint64_t)GetDWLE( p_buff + 4 ) << 32) );
64 void GetGUID( guid_t *p_guid, uint8_t *p_data )
66 p_guid->v1 = GetDWLE( p_data );
67 p_guid->v2 = GetWLE( p_data + 4);
68 p_guid->v3 = GetWLE( p_data + 6);
69 memcpy( p_guid->v4, p_data + 8, 8 );
72 int CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
74 if( (p_guid1->v1 != p_guid2->v1 )||(p_guid1->v2 != p_guid2->v2 )||
75 (p_guid1->v3 != p_guid2->v3 )||
76 ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
82 return( 1 ); /* match */
85 /*****************************************************************************
86 * Some basic functions to manipulate stream more easily in vlc
88 * ASF_TellAbsolute get file position
90 * ASF_SeekAbsolute seek in the file
92 * ASF_ReadData read data from the file in a buffer
94 *****************************************************************************/
95 off_t ASF_TellAbsolute( input_thread_t *p_input )
99 vlc_mutex_lock( &p_input->stream.stream_lock );
101 i_pos= p_input->stream.p_selected_area->i_tell;
102 // - ( p_input->p_last_data - p_input->p_current_data );
104 vlc_mutex_unlock( &p_input->stream.stream_lock );
109 int ASF_SeekAbsolute( input_thread_t *p_input,
114 i_filepos = ASF_TellAbsolute( p_input );
115 if( i_pos == i_filepos )
120 if( p_input->stream.b_seekable &&
121 p_input->stream.i_method != INPUT_METHOD_NETWORK )
123 p_input->pf_seek( p_input, i_pos );
124 input_AccessReinit( p_input );
127 else if( i_pos > i_filepos )
129 uint64_t i_size = i_pos - i_filepos;
132 data_packet_t *p_data;
136 input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
141 input_DeletePacket( p_input->p_method_data, p_data );
144 } while( i_size > 0 );
150 msg_Err( p_input, "cannot seek" );
155 /* return 1 if success, 0 if fail */
156 int ASF_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size )
158 data_packet_t *p_data;
170 i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
175 memcpy( p_buff, p_data->p_payload_start, i_read );
176 input_DeletePacket( p_input->p_method_data, p_data );
186 int ASF_SkipBytes( input_thread_t *p_input, int i_count )
188 return( ASF_SeekAbsolute( p_input,
189 ASF_TellAbsolute( p_input ) + i_count ) );
192 /****************************************************************************/
193 int ASF_ReadObjectCommon( input_thread_t *p_input,
194 asf_object_t *p_obj )
196 asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
199 if( input_Peek( p_input, &p_peek, 24 ) < 24 )
203 GetGUID( &p_common->i_object_id, p_peek );
204 p_common->i_object_size = GetQWLE( p_peek + 16 );
205 p_common->i_object_pos = ASF_TellAbsolute( p_input );
206 p_common->p_next = NULL;
209 "Found Object guid: " GUID_FMT " size:"I64Fd,
210 GUID_PRINT( p_common->i_object_id ),
211 p_common->i_object_size );
217 int ASF_NextObject( input_thread_t *p_input,
218 asf_object_t *p_obj )
223 if( !ASF_ReadObjectCommon( p_input, &obj ) )
230 if( !p_obj->common.i_object_size )
232 return( 0 ); /* failed */
234 if( p_obj->common.p_father && p_obj->common.p_father->common.i_object_size != 0 )
236 if( p_obj->common.p_father->common.i_object_pos + p_obj->common.p_father->common.i_object_size <
237 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
238 /* 24 is min size of an object */
244 return( ASF_SeekAbsolute( p_input,
245 p_obj->common.i_object_pos + p_obj->common.i_object_size ) );
248 int ASF_GotoObject( input_thread_t *p_input,
249 asf_object_t *p_obj )
255 return( ASF_SeekAbsolute( p_input, p_obj->common.i_object_pos ) );
259 void ASF_FreeObject_Null( input_thread_t *p_input,
260 asf_object_t *pp_obj )
266 int ASF_ReadObject_Header( input_thread_t *p_input,
267 asf_object_t *p_obj )
269 asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
270 asf_object_t *p_subobj;
274 if( ( i_peek = input_Peek( p_input, &p_peek, 30 ) ) < 30 )
278 p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
279 p_hdr->i_reserved1 = p_peek[28];
280 p_hdr->i_reserved2 = p_peek[29];
281 p_hdr->p_first = NULL;
282 p_hdr->p_last = NULL;
285 "Read \"Header Object\" subobj:%d, reserved1:%d, reserved2:%d",
286 p_hdr->i_sub_object_count,
288 p_hdr->i_reserved2 );
290 ASF_SkipBytes( p_input, 30 );
291 /* Now load sub object */
294 p_subobj = malloc( sizeof( asf_object_t ) );
296 if( !( ASF_ReadObject( p_input, p_subobj, (asf_object_t*)p_hdr ) ) )
300 if( !ASF_NextObject( p_input, p_subobj ) ) /* Go to the next object */
308 int ASF_ReadObject_Data( input_thread_t *p_input,
309 asf_object_t *p_obj )
311 asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
315 if( ( i_peek = input_Peek( p_input, &p_peek, 50 ) ) < 50 )
319 GetGUID( &p_data->i_file_id, p_peek + 24 );
320 p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
321 p_data->i_reserved = GetWLE( p_peek + 48 );
324 "Read \"Data Object\" file_id:" GUID_FMT " total data packet:"
326 GUID_PRINT( p_data->i_file_id ),
327 p_data->i_total_data_packets,
328 p_data->i_reserved );
333 int ASF_ReadObject_Index( input_thread_t *p_input,
334 asf_object_t *p_obj )
336 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
340 if( ( i_peek = input_Peek( p_input, &p_peek, 56 ) ) < 56 )
344 GetGUID( &p_index->i_file_id, p_peek + 24 );
345 p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
346 p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
347 p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
348 p_index->index_entry = NULL; /* FIXME */
352 "Read \"Index Object\" file_id:" GUID_FMT
353 " index_entry_time_interval:"I64Fd" max_packet_count:%d "
354 "index_entry_count:%d",
355 GUID_PRINT( p_index->i_file_id ),
356 p_index->i_max_packet_count,
357 p_index->i_index_entry_count );
361 void ASF_FreeObject_Index( input_thread_t *p_input,
362 asf_object_t *p_obj )
364 asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
366 FREE( p_index->index_entry );
369 int ASF_ReadObject_file_properties( input_thread_t *p_input,
370 asf_object_t *p_obj )
372 asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
376 if( ( i_peek = input_Peek( p_input, &p_peek, 92) ) < 92 )
380 GetGUID( &p_fp->i_file_id, p_peek + 24 );
381 p_fp->i_file_size = GetQWLE( p_peek + 40 );
382 p_fp->i_creation_date = GetQWLE( p_peek + 48 );
383 p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
384 p_fp->i_play_duration = GetQWLE( p_peek + 64 );
385 p_fp->i_send_duration = GetQWLE( p_peek + 72 );
386 p_fp->i_preroll = GetQWLE( p_peek + 80 );
387 p_fp->i_flags = GetDWLE( p_peek + 88 );
388 p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
389 p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
390 p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
394 "Read \"File Properties Object\" file_id:" GUID_FMT
395 " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
396 I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
397 I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
399 GUID_PRINT( p_fp->i_file_id ),
401 p_fp->i_creation_date,
402 p_fp->i_data_packets_count,
403 p_fp->i_play_duration,
404 p_fp->i_send_duration,
407 p_fp->i_min_data_packet_size,
408 p_fp->i_max_data_packet_size,
409 p_fp->i_max_bitrate );
414 int ASF_ReadObject_header_extention( input_thread_t *p_input,
415 asf_object_t *p_obj )
417 asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj;
421 if( ( i_peek = input_Peek( p_input, &p_peek, p_he->i_object_size ) ) < 46)
425 GetGUID( &p_he->i_reserved1, p_peek + 24 );
426 p_he->i_reserved2 = GetWLE( p_peek + 40 );
427 p_he->i_header_extention_size = GetDWLE( p_peek + 42 );
428 if( p_he->i_header_extention_size )
430 p_he->p_header_extention_data = malloc( p_he->i_header_extention_size );
431 memcpy( p_he->p_header_extention_data,
433 p_he->i_header_extention_size );
437 p_he->p_header_extention_data = NULL;
441 "Read \"Header Extention Object\" reserved1:" GUID_FMT " reserved2:%d header_extention_size:%d",
442 GUID_PRINT( p_he->i_reserved1 ),
444 p_he->i_header_extention_size );
448 void ASF_FreeObject_header_extention( input_thread_t *p_input,
449 asf_object_t *p_obj )
451 asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj;
453 FREE( p_he->p_header_extention_data );
456 int ASF_ReadObject_stream_properties( input_thread_t *p_input,
457 asf_object_t *p_obj )
459 asf_object_stream_properties_t *p_sp =
460 (asf_object_stream_properties_t*)p_obj;
464 if( ( i_peek = input_Peek( p_input, &p_peek, p_sp->i_object_size ) ) < 74 )
468 GetGUID( &p_sp->i_stream_type, p_peek + 24 );
469 GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
470 p_sp->i_time_offset = GetQWLE( p_peek + 56 );
471 p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
472 p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
473 p_sp->i_flags = GetWLE( p_peek + 72 );
474 p_sp->i_stream_number = p_sp->i_flags&0x07f;
475 p_sp->i_reserved = GetDWLE( p_peek + 74 );
476 if( p_sp->i_type_specific_data_length )
478 p_sp->p_type_specific_data = malloc( p_sp->i_type_specific_data_length );
479 memcpy( p_sp->p_type_specific_data,
481 p_sp->i_type_specific_data_length );
485 p_sp->p_type_specific_data = NULL;
487 if( p_sp->i_error_correction_data_length )
489 p_sp->p_error_correction_data = malloc( p_sp->i_error_correction_data_length );
490 memcpy( p_sp->p_error_correction_data,
491 p_peek + 78 + p_sp->i_type_specific_data_length,
492 p_sp->i_error_correction_data_length );
496 p_sp->p_error_correction_data = NULL;
501 "Read \"Stream Properties Object\" stream_type:" GUID_FMT
502 " error_correction_type:" GUID_FMT " time_offset:"I64Fd
503 " type_specific_data_length:%d error_correction_data_length:%d"
504 " flags:0x%x stream_number:%d",
505 GUID_PRINT( p_sp->i_stream_type ),
506 GUID_PRINT( p_sp->i_error_correction_type ),
508 p_sp->i_type_specific_data_length,
509 p_sp->i_error_correction_data_length,
511 p_sp->i_stream_number );
517 void ASF_FreeObject_stream_properties( input_thread_t *p_input,
518 asf_object_t *p_obj )
520 asf_object_stream_properties_t *p_sp =
521 (asf_object_stream_properties_t*)p_obj;
523 FREE( p_sp->p_type_specific_data );
524 FREE( p_sp->p_error_correction_data );
528 int ASF_ReadObject_codec_list( input_thread_t *p_input,
529 asf_object_t *p_obj )
531 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
533 uint8_t *p_peek, *p_data;
537 if( ( i_peek = input_Peek( p_input, &p_peek, p_cl->i_object_size ) ) < 44 )
542 GetGUID( &p_cl->i_reserved, p_peek + 24 );
543 p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
544 if( p_cl->i_codec_entries_count > 0 )
547 p_cl->codec = calloc( p_cl->i_codec_entries_count, sizeof( asf_codec_entry_t ) );
548 memset( p_cl->codec, 0, p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
550 p_data = p_peek + 44;
551 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
553 #define codec p_cl->codec[i_codec]
556 codec.i_type = GetWLE( p_data ); p_data += 2;
558 i_len = GetWLE( p_data ); p_data += 2;
559 codec.psz_name = calloc( sizeof( char ), i_len + 1);
560 for( i = 0; i < i_len; i++ )
562 codec.psz_name[i] = GetWLE( p_data + 2*i );
564 codec.psz_name[i_len] = '\0';
568 i_len = GetWLE( p_data ); p_data += 2;
569 codec.psz_description = calloc( sizeof( char ), i_len + 1);
570 for( i = 0; i < i_len; i++ )
572 codec.psz_description[i] = GetWLE( p_data + 2*i );
574 codec.psz_description[i_len] = '\0';
577 /* opaque information */
578 codec.i_information_length = GetWLE( p_data ); p_data += 2;
579 if( codec.i_information_length > 0 )
581 codec.p_information = malloc( codec.i_information_length );
582 memcpy( codec.p_information, p_data, codec.i_information_length );
583 p_data += codec.i_information_length;
587 codec.p_information = NULL;
600 "Read \"Codec List Object\" reserved_guid:" GUID_FMT " codec_entries_count:%d",
601 GUID_PRINT( p_cl->i_reserved ),
602 p_cl->i_codec_entries_count );
603 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
605 #define codec p_cl->codec[i_codec]
607 "Read \"Codec List Object\" codec[%d] %s name:\"%s\" description:\"%s\" information_length:%d",
609 ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ? "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ? "audio" : "unknown" ),
611 codec.psz_description,
612 codec.i_information_length );
619 void ASF_FreeObject_codec_list( input_thread_t *p_input,
620 asf_object_t *p_obj )
622 asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
625 for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
627 #define codec p_cl->codec[i_codec]
628 FREE( codec.psz_name );
629 FREE( codec.psz_description );
630 FREE( codec.p_information );
637 /* Microsoft should qo to hell. This time the length give number of bytes
638 * and for the some others object, length give char16 count ... */
639 int ASF_ReadObject_content_description( input_thread_t *p_input,
640 asf_object_t *p_obj )
642 asf_object_content_description_t *p_cd =
643 (asf_object_content_description_t*)p_obj;
645 uint8_t *p_peek, *p_data;
654 #define GETSTRINGW( psz_str, i_size ) \
655 psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
656 for( i_len = 0; i_len < i_size/2; i_len++ ) \
658 psz_str[i_len] = GetWLE( p_data + 2*i_len ); \
660 psz_str[i_size/2] = '\0'; \
663 if( ( i_peek = input_Peek( p_input, &p_peek, p_cd->i_object_size ) ) < 34 )
667 p_data = p_peek + 24;
669 i_title = GetWLE( p_data ); p_data += 2;
670 i_author= GetWLE( p_data ); p_data += 2;
671 i_copyright = GetWLE( p_data ); p_data += 2;
672 i_description = GetWLE( p_data ); p_data += 2;
673 i_rating = GetWLE( p_data ); p_data += 2;
675 GETSTRINGW( p_cd->psz_title, i_title );
676 GETSTRINGW( p_cd->psz_author, i_author );
677 GETSTRINGW( p_cd->psz_copyright, i_copyright );
678 GETSTRINGW( p_cd->psz_description, i_description );
679 GETSTRINGW( p_cd->psz_rating, i_rating );
685 "Read \"Content Description Object\" title:\"%s\" author:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
689 p_cd->psz_description,
695 void ASF_FreeObject_content_description( input_thread_t *p_input,
696 asf_object_t *p_obj )
698 asf_object_content_description_t *p_cd = (asf_object_content_description_t*)p_obj;
700 FREE( p_cd->psz_title );
701 FREE( p_cd->psz_author );
702 FREE( p_cd->psz_copyright );
703 FREE( p_cd->psz_description );
704 FREE( p_cd->psz_rating );
711 int (*ASF_ReadObject_function)( input_thread_t *p_input,
712 asf_object_t *p_obj );
713 void (*ASF_FreeObject_function)( input_thread_t *p_input,
714 asf_object_t *p_obj );
715 } ASF_Object_Function [] =
717 { &asf_object_header_guid, ASF_OBJECT_TYPE_HEADER, ASF_ReadObject_Header, ASF_FreeObject_Null },
718 { &asf_object_data_guid, ASF_OBJECT_TYPE_DATA, ASF_ReadObject_Data, ASF_FreeObject_Null },
719 { &asf_object_index_guid, ASF_OBJECT_TYPE_INDEX, ASF_ReadObject_Index, ASF_FreeObject_Index },
720 { &asf_object_file_properties_guid, ASF_OBJECT_TYPE_FILE_PROPERTIES, ASF_ReadObject_file_properties, ASF_FreeObject_Null },
721 { &asf_object_stream_properties_guid, ASF_OBJECT_TYPE_STREAM_PROPERTIES, ASF_ReadObject_stream_properties,ASF_FreeObject_stream_properties },
722 { &asf_object_header_extention_guid, ASF_OBJECT_TYPE_EXTENTION_HEADER, ASF_ReadObject_header_extention, ASF_FreeObject_header_extention},
723 { &asf_object_codec_list_guid, ASF_OBJECT_TYPE_CODEC_LIST, ASF_ReadObject_codec_list, ASF_FreeObject_codec_list },
724 { &asf_object_marker_guid, ASF_OBJECT_TYPE_MARKER, NULL, NULL },
725 { &asf_object_content_description_guid, ASF_OBJECT_TYPE_CONTENT_DESCRIPTION, ASF_ReadObject_content_description, ASF_FreeObject_content_description },
727 { &asf_object_null_guid, 0, NULL, NULL }
730 int ASF_ReadObject( input_thread_t *p_input,
732 asf_object_t *p_father )
741 if( !ASF_ReadObjectCommon( p_input, p_obj ) )
743 msg_Warn( p_input, "Cannot read one asf object" );
746 p_obj->common.p_father = p_father;
747 p_obj->common.p_first = NULL;
748 p_obj->common.p_next = NULL;
749 p_obj->common.p_last = NULL;
752 if( p_obj->common.i_object_size < 24 )
754 msg_Warn( p_input, "Found a corrupted asf object (size<24)" );
757 /* find this object */
758 for( i_index = 0; ; i_index++ )
760 if( CmpGUID( ASF_Object_Function[i_index].p_id,
761 &p_obj->common.i_object_id )||
762 CmpGUID( ASF_Object_Function[i_index].p_id,
763 &asf_object_null_guid ) )
768 p_obj->common.i_type = ASF_Object_Function[i_index].i_type;
770 /* Now load this object */
771 if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
773 msg_Warn( p_input, "Unknown asf object (not loaded)" );
778 /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
780 (ASF_Object_Function[i_index].ASF_ReadObject_function)( p_input,
784 /* link this object with father */
787 if( p_father->common.p_first )
789 p_father->common.p_last->common.p_next = p_obj;
793 p_father->common.p_first = p_obj;
795 p_father->common.p_last = p_obj;
801 void ASF_FreeObject( input_thread_t *p_input,
802 asf_object_t *p_obj )
805 asf_object_t *p_child;
812 /* Free all child object */
813 p_child = p_obj->common.p_first;
816 asf_object_t *p_next;
817 p_next = p_child->common.p_next;
818 ASF_FreeObject( p_input, p_child );
822 /* find this object */
823 for( i_index = 0; ; i_index++ )
825 if( CmpGUID( ASF_Object_Function[i_index].p_id,
826 &p_obj->common.i_object_id )||
827 CmpGUID( ASF_Object_Function[i_index].p_id,
828 &asf_object_null_guid ) )
834 /* Now free this object */
835 if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
838 "Unknown asf object " GUID_FMT,
839 GUID_PRINT( p_obj->common.i_object_id ) );
845 "Free asf object " GUID_FMT,
846 GUID_PRINT( p_obj->common.i_object_id ) );
848 (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_input,
855 /*****************************************************************************
856 * ASF_ReadObjetRoot : parse the entire stream/file
857 *****************************************************************************/
858 int ASF_ReadObjectRoot( input_thread_t *p_input,
859 asf_object_root_t *p_root,
864 p_root->i_type = ASF_OBJECT_TYPE_ROOT;
865 memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
866 p_root->i_object_pos = 0;
867 p_root->i_object_size = p_input->stream.p_selected_area->i_size;
868 p_root->p_first = NULL;
869 p_root->p_last = NULL;
870 p_root->p_next = NULL;
871 p_root->p_hdr = NULL;
872 p_root->p_data = NULL;
873 p_root->p_index = NULL;
877 p_obj = malloc( sizeof( asf_object_t ) );
879 if( !( ASF_ReadObject( p_input, p_obj, (asf_object_t*)p_root ) ) )
883 switch( p_obj->common.i_type )
885 case( ASF_OBJECT_TYPE_HEADER ):
886 p_root->p_hdr = (asf_object_header_t*)p_obj;
888 case( ASF_OBJECT_TYPE_DATA ):
889 p_root->p_data = (asf_object_data_t*)p_obj;
891 case( ASF_OBJECT_TYPE_INDEX ):
892 p_root->p_index = (asf_object_index_t*)p_obj;
895 msg_Warn( p_input, "Unknow Object found" );
898 if( !b_seekable && ( p_root->p_hdr && p_root->p_data ) )
900 /* For unseekable stream it's enouth to play */
904 if( !ASF_NextObject( p_input, p_obj ) ) /* Go to the next object */
911 void ASF_FreeObjectRoot( input_thread_t *p_input,
912 asf_object_root_t *p_root )
916 p_obj = p_root->p_first;
919 asf_object_t *p_next;
920 p_next = p_obj->common.p_next;
921 ASF_FreeObject( p_input, p_obj );
924 p_root->p_first = NULL;
925 p_root->p_last = NULL;
926 p_root->p_next = NULL;
928 p_root->p_hdr = NULL;
929 p_root->p_data = NULL;
930 p_root->p_index = NULL;
934 int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
937 asf_object_t *p_child;
945 p_child = p_obj->common.p_first;
948 if( CmpGUID( &p_child->common.i_object_id, p_guid ) )
952 p_child = p_child->common.p_next;
957 void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number )
959 asf_object_t *p_child;
961 p_child = p_obj->common.p_first;
965 if( CmpGUID( &p_child->common.i_object_id, p_guid ) )
975 p_child = p_child->common.p_next;