* asf: clean up + use stream_* (It's not yet well tested)
[vlc.git] / modules / demux / asf / libasf.c
index 37d8f6e..7611253 100644 (file)
@@ -2,7 +2,7 @@
  * libasf.c :
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: libasf.c,v 1.14 2003/08/17 23:42:37 fenrir Exp $
+ * $Id: libasf.c,v 1.15 2003/08/18 19:18:47 fenrir Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
+#include "ninput.h"
 
 #include "codecs.h"                        /* BITMAPINFOHEADER, WAVEFORMATEX */
 #include "libasf.h"
     (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3],    \
     (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
 
+/****************************************************************************
+ *
+ ****************************************************************************/
+static int ASF_ReadObject( stream_t *,
+                           asf_object_t *p_obj,  asf_object_t *p_father );
+
+
+/****************************************************************************
+ * GUID functions
+ ****************************************************************************/
 void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data )
 {
     p_guid->v1 = GetDWLE( p_data );
@@ -51,167 +62,57 @@ void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data )
 
 int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
 {
-    if( (p_guid1->v1 != p_guid2->v1 )||(p_guid1->v2 != p_guid2->v2 )||
+    if( (p_guid1->v1 != p_guid2->v1 )||
+        (p_guid1->v2 != p_guid2->v2 )||
         (p_guid1->v3 != p_guid2->v3 )||
         ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
     {
         return( 0 );
     }
-    else
-    {
-        return( 1 ); /* match */
-    }
-}
-/*****************************************************************************
- * Some basic functions to manipulate stream more easily in vlc
- *
- * ASF_TellAbsolute get file position
- *
- * ASF_SeekAbsolute seek in the file
- *
- * ASF_ReadData read data from the file in a buffer
- *
- *****************************************************************************/
-off_t ASF_TellAbsolute( input_thread_t *p_input )
-{
-    off_t i_pos;
-
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-
-    i_pos= p_input->stream.p_selected_area->i_tell;
-//           - ( p_input->p_last_data - p_input->p_current_data  );
-
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    return( i_pos );
-}
-
-int ASF_SeekAbsolute( input_thread_t *p_input,
-                      off_t i_pos)
-{
-    off_t i_filepos;
-
-    i_filepos = ASF_TellAbsolute( p_input );
-    if( i_pos == i_filepos )
-    {
-        return( 1 );
-    }
-
-    if( !p_input->stream.b_seekable && i_pos < i_filepos )
-    {
-        msg_Err( p_input, "cannot seek" );
-        return( 0 );
-    }
-
-    if( p_input->stream.b_seekable &&
-        ( p_input->stream.i_method == INPUT_METHOD_FILE ||
-          i_pos < i_filepos ||
-          i_pos - i_filepos > 10000 ) )
-    {
-        input_AccessReinit( p_input );
-        p_input->pf_seek( p_input, i_pos );
-        return( 1 );
-    }
-    else if( i_pos > i_filepos )
-    {
-        uint64_t i_size = i_pos - i_filepos;
-        do
-        {
-            data_packet_t *p_data;
-            int i_read;
-
-            i_read =
-                input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
-            if( i_read <= 0 )
-            {
-                return( 0 );
-            }
-            input_DeletePacket( p_input->p_method_data, p_data );
-            i_size -= i_read;
-
-        } while( i_size > 0 );
-    }
-    return( 1 );
-}
-
-/* return 1 if success, 0 if fail */
-int ASF_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size )
-{
-    data_packet_t *p_data;
-
-    int i_read;
-
-
-    if( !i_size )
-    {
-        return( 1 );
-    }
-
-    do
-    {
-        i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
-        if( i_read <= 0 )
-        {
-            return( 0 );
-        }
-        memcpy( p_buff, p_data->p_payload_start, i_read );
-        input_DeletePacket( p_input->p_method_data, p_data );
-
-        p_buff += i_read;
-        i_size -= i_read;
-
-    } while( i_size );
-
-    return( 1 );
-}
-
-int  ASF_SkipBytes( input_thread_t *p_input, int i_count )
-{
-    return( ASF_SeekAbsolute( p_input,
-                              ASF_TellAbsolute( p_input ) + i_count ) );
+    return( 1 ); /* match */
 }
 
-/****************************************************************************/
-int  ASF_ReadObjectCommon( input_thread_t *p_input,
-                           asf_object_t *p_obj )
+/****************************************************************************
+ *
+ ****************************************************************************/
+static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
     uint8_t             *p_peek;
 
-    if( input_Peek( p_input, &p_peek, 24 ) < 24 )
+    if( stream_Peek( s, &p_peek, 24 ) < 24 )
     {
-        return( 0 );
+        return( VLC_EGENERIC );
     }
     ASF_GetGUID( &p_common->i_object_id, p_peek );
     p_common->i_object_size = GetQWLE( p_peek + 16 );
-    p_common->i_object_pos = ASF_TellAbsolute( p_input );
+    stream_Control( s, STREAM_GET_POSITION, &p_common->i_object_pos );
     p_common->p_next = NULL;
 #ifdef ASF_DEBUG
-    msg_Dbg(p_input,
-            "Found Object guid: " GUID_FMT " size:"I64Fd,
-            GUID_PRINT( p_common->i_object_id ),
-            p_common->i_object_size );
+    msg_Dbg( (vlc_object_t*)s,
+             "Found Object guid: " GUID_FMT " size:"I64Fd,
+             GUID_PRINT( p_common->i_object_id ),
+             p_common->i_object_size );
 #endif
 
-    return( 1 );
+    return( VLC_SUCCESS );
 }
 
-int ASF_NextObject( input_thread_t *p_input,
-                    asf_object_t *p_obj )
+static int ASF_NextObject( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_t obj;
-    if( !p_obj )
+    if( p_obj == NULL )
     {
-        if( !ASF_ReadObjectCommon( p_input, &obj ) )
+        if( ASF_ReadObjectCommon( s, &obj ) )
         {
-            return( 0 );
+            return( VLC_EGENERIC );
         }
         p_obj = &obj;
     }
 
-    if( !p_obj->common.i_object_size )
+    if( p_obj->common.i_object_size <= 0 )
     {
-        return( 0 ); /* failed */
+        return( VLC_EGENERIC );
     }
     if( p_obj->common.p_father && p_obj->common.p_father->common.i_object_size != 0 )
     {
@@ -219,109 +120,97 @@ int ASF_NextObject( input_thread_t *p_input,
                 p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
                                 /* 24 is min size of an object */
         {
-            return( 0 );
+            return( VLC_EGENERIC );
         }
 
     }
-    return( ASF_SeekAbsolute( p_input,
-                              p_obj->common.i_object_pos + p_obj->common.i_object_size ) );
-}
 
-int  ASF_GotoObject( input_thread_t *p_input,
-                     asf_object_t *p_obj )
-{
-    if( !p_obj )
-    {
-        return( 0 );
-    }
-    return( ASF_SeekAbsolute( p_input, p_obj->common.i_object_pos ) );
+    return( stream_Control( s, STREAM_SET_POSITION,
+                            p_obj->common.i_object_pos + p_obj->common.i_object_size ) );
 }
 
-
-void ASF_FreeObject_Null( input_thread_t *p_input,
-                            asf_object_t *pp_obj )
+static void ASF_FreeObject_Null( asf_object_t *pp_obj )
 {
-
-
+    return;
 }
 
-int  ASF_ReadObject_Header( input_thread_t *p_input,
-                            asf_object_t *p_obj )
+static int  ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
     asf_object_t        *p_subobj;
     int                 i_peek;
     uint8_t             *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, 30 ) ) < 30 )
+    if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
     {
-       return( 0 );
+       return( VLC_EGENERIC );
     }
+
     p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
     p_hdr->i_reserved1 = p_peek[28];
     p_hdr->i_reserved2 = p_peek[29];
     p_hdr->p_first = NULL;
     p_hdr->p_last  = NULL;
 #ifdef ASF_DEBUG
-    msg_Dbg(p_input,
-            "Read \"Header Object\" subobj:%d, reserved1:%d, reserved2:%d",
-            p_hdr->i_sub_object_count,
-            p_hdr->i_reserved1,
-            p_hdr->i_reserved2 );
+    msg_Dbg( (vlc_object_t*)s,
+             "Read \"Header Object\" subobj:%d, reserved1:%d, reserved2:%d",
+             p_hdr->i_sub_object_count,
+             p_hdr->i_reserved1,
+             p_hdr->i_reserved2 );
 #endif
-    ASF_SkipBytes( p_input, 30 );
+    /* Cannot failed as peek succeed */
+    stream_Read( s, NULL, 30 );
+
     /* Now load sub object */
     for( ; ; )
     {
         p_subobj  = malloc( sizeof( asf_object_t ) );
 
-        if( !( ASF_ReadObject( p_input, p_subobj, (asf_object_t*)p_hdr ) ) )
+        if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
         {
             break;
         }
-        if( !ASF_NextObject( p_input, p_subobj ) ) /* Go to the next object */
+        if( ASF_NextObject( s, p_subobj ) ) /* Go to the next object */
         {
             break;
         }
     }
-    return( 1 );
+    return VLC_SUCCESS;
 }
 
-int  ASF_ReadObject_Data( input_thread_t *p_input,
-                          asf_object_t *p_obj )
+static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
     int               i_peek;
     uint8_t           *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, 50 ) ) < 50 )
+    if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
     p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
     p_data->i_reserved = GetWLE( p_peek + 48 );
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
-            "Read \"Data Object\" file_id:" GUID_FMT " total data packet:"
-            I64Fd" reserved:%d",
-            GUID_PRINT( p_data->i_file_id ),
-            p_data->i_total_data_packets,
-            p_data->i_reserved );
+    msg_Dbg( (vlc_object_t*)s,
+             "Read \"Data Object\" file_id:" GUID_FMT " total data packet:"
+             I64Fd" reserved:%d",
+             GUID_PRINT( p_data->i_file_id ),
+             p_data->i_total_data_packets,
+             p_data->i_reserved );
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
 
-int  ASF_ReadObject_Index( input_thread_t *p_input,
-                           asf_object_t *p_obj )
+static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
     int                i_peek;
     uint8_t            *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, 56 ) ) < 56 )
+    if( ( i_peek = stream_Peek( s, &p_peek, 56 ) ) < 56 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
     p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
@@ -330,7 +219,7 @@ int  ASF_ReadObject_Index( input_thread_t *p_input,
     p_index->index_entry = NULL; /* FIXME */
 
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
             "Read \"Index Object\" file_id:" GUID_FMT
             " index_entry_time_interval:"I64Fd" max_packet_count:%d "
             "index_entry_count:%ld",
@@ -339,26 +228,24 @@ int  ASF_ReadObject_Index( input_thread_t *p_input,
             p_index->i_max_packet_count,
             (long int)p_index->i_index_entry_count );
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
-void ASF_FreeObject_Index( input_thread_t *p_input,
-                          asf_object_t *p_obj )
+static void ASF_FreeObject_Index( asf_object_t *p_obj )
 {
     asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
 
     FREE( p_index->index_entry );
 }
 
-int  ASF_ReadObject_file_properties( input_thread_t *p_input,
-                                     asf_object_t *p_obj )
+static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
     int      i_peek;
     uint8_t  *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek,  92) ) < 92 )
+    if( ( i_peek = stream_Peek( s, &p_peek,  92) ) < 92 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
     p_fp->i_file_size = GetQWLE( p_peek + 40 );
@@ -373,7 +260,7 @@ int  ASF_ReadObject_file_properties( input_thread_t *p_input,
     p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
 
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
             "Read \"File Properties Object\" file_id:" GUID_FMT
             " file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
             I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
@@ -391,19 +278,18 @@ int  ASF_ReadObject_file_properties( input_thread_t *p_input,
             p_fp->i_max_data_packet_size,
             p_fp->i_max_bitrate );
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
 
-int  ASF_ReadObject_header_extention( input_thread_t *p_input,
-                                      asf_object_t *p_obj )
+static int ASF_ReadObject_header_extention( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj;
     int     i_peek;
     uint8_t *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, p_he->i_object_size ) ) <  46)
+    if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) <  46)
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
     p_he->i_reserved2 = GetWLE( p_peek + 40 );
@@ -420,33 +306,31 @@ int  ASF_ReadObject_header_extention( input_thread_t *p_input,
         p_he->p_header_extention_data = NULL;
     }
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
             "Read \"Header Extention Object\" reserved1:" GUID_FMT " reserved2:%d header_extention_size:%d",
             GUID_PRINT( p_he->i_reserved1 ),
             p_he->i_reserved2,
             p_he->i_header_extention_size );
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
-void ASF_FreeObject_header_extention( input_thread_t *p_input,
-                                      asf_object_t *p_obj )
+static void ASF_FreeObject_header_extention( asf_object_t *p_obj )
 {
     asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj;
 
     FREE( p_he->p_header_extention_data );
 }
 
-int  ASF_ReadObject_stream_properties( input_thread_t *p_input,
-                                       asf_object_t *p_obj )
+static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_stream_properties_t *p_sp =
                     (asf_object_stream_properties_t*)p_obj;
     int     i_peek;
     uint8_t *p_peek;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek,  p_sp->i_object_size ) ) < 74 )
+    if( ( i_peek = stream_Peek( s, &p_peek,  p_sp->i_object_size ) ) < 74 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
     ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
@@ -480,7 +364,7 @@ int  ASF_ReadObject_stream_properties( input_thread_t *p_input,
     }
 
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
             "Read \"Stream Properties Object\" stream_type:" GUID_FMT
             " error_correction_type:" GUID_FMT " time_offset:"I64Fd
             " type_specific_data_length:%d error_correction_data_length:%d"
@@ -494,11 +378,10 @@ int  ASF_ReadObject_stream_properties( input_thread_t *p_input,
             p_sp->i_stream_number );
 
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
 
-void ASF_FreeObject_stream_properties( input_thread_t *p_input,
-                                      asf_object_t *p_obj )
+static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
 {
     asf_object_stream_properties_t *p_sp =
                 (asf_object_stream_properties_t*)p_obj;
@@ -508,8 +391,7 @@ void ASF_FreeObject_stream_properties( input_thread_t *p_input,
 }
 
 
-int  ASF_ReadObject_codec_list( input_thread_t *p_input,
-                                asf_object_t *p_obj )
+static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
     int     i_peek;
@@ -517,9 +399,9 @@ int  ASF_ReadObject_codec_list( input_thread_t *p_input,
 
     unsigned int i_codec;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, p_cl->i_object_size ) ) < 44 )
+    if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
 
     ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
@@ -527,8 +409,10 @@ int  ASF_ReadObject_codec_list( input_thread_t *p_input,
     if( p_cl->i_codec_entries_count > 0 )
     {
 
-        p_cl->codec = calloc( p_cl->i_codec_entries_count, sizeof( asf_codec_entry_t ) );
-        memset( p_cl->codec, 0, p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
+        p_cl->codec = calloc( p_cl->i_codec_entries_count,
+                              sizeof( asf_codec_entry_t ) );
+        memset( p_cl->codec, 0,
+                p_cl->i_codec_entries_count * sizeof( asf_codec_entry_t ) );
 
         p_data = p_peek + 44;
         for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
@@ -571,7 +455,6 @@ int  ASF_ReadObject_codec_list( input_thread_t *p_input,
             }
 #undef  codec
         }
-
     }
     else
     {
@@ -579,35 +462,27 @@ int  ASF_ReadObject_codec_list( input_thread_t *p_input,
     }
 
 #ifdef ASF_DEBUG
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
             "Read \"Codec List Object\" reserved_guid:" GUID_FMT " codec_entries_count:%d",
             GUID_PRINT( p_cl->i_reserved ),
             p_cl->i_codec_entries_count );
+
     for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
     {
-        char psz_cat[sizeof("Stream ")+10];
-        input_info_category_t *p_cat;
-        sprintf( psz_cat, "Stream %d", i_codec );
-        p_cat = input_InfoCategory( p_input, psz_cat);
-
 #define codec p_cl->codec[i_codec]
-        input_AddInfo( p_cat, _("Codec name"), codec.psz_name );
-        input_AddInfo( p_cat, _("Codec description"), codec.psz_description );
-        msg_Dbg( p_input,
+        msg_Dbg( (vlc_object_t*)s,
                  "Read \"Codec List Object\" codec[%d] %s name:\"%s\" description:\"%s\" information_length:%d",
                  i_codec,
                  ( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ? "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ? "audio" : "unknown" ),
                  codec.psz_name,
                  codec.psz_description,
                  codec.i_information_length );
-
-#undef  codec
     }
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
-void ASF_FreeObject_codec_list( input_thread_t *p_input,
-                                asf_object_t *p_obj )
+
+static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
 {
     asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
     unsigned int i_codec;
@@ -624,10 +499,9 @@ void ASF_FreeObject_codec_list( input_thread_t *p_input,
     FREE( p_cl->codec );
 }
 
-/* Microsoft should qo to hell. This time the length give number of bytes
+/* Microsoft should go to hell. This time the length give number of bytes
  * and for the some others object, length give char16 count ... */
-int  ASF_ReadObject_content_description( input_thread_t *p_input,
-                                         asf_object_t *p_obj )
+static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
 {
     asf_object_content_description_t *p_cd =
                                     (asf_object_content_description_t*)p_obj;
@@ -650,9 +524,9 @@ int  ASF_ReadObject_content_description( input_thread_t *p_input,
    psz_str[i_size/2] = '\0'; \
    p_data += i_size;
 
-    if( ( i_peek = input_Peek( p_input, &p_peek, p_cd->i_object_size ) ) < 34 )
+    if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
     {
-       return( 0 );
+       return VLC_EGENERIC;
     }
     p_data = p_peek + 24;
 
@@ -671,15 +545,7 @@ int  ASF_ReadObject_content_description( input_thread_t *p_input,
 #undef  GETSTRINGW
 
 #ifdef ASF_DEBUG
-    {
-        input_info_category_t *p_cat = input_InfoCategory( p_input, _("Asf") );
-        input_AddInfo( p_cat, _("Title"), p_cd->psz_title );
-        input_AddInfo( p_cat, _("Author"), p_cd->psz_author );
-        input_AddInfo( p_cat, _("Copyright"), p_cd->psz_copyright );
-        input_AddInfo( p_cat, _("Description"), p_cd->psz_description );
-        input_AddInfo( p_cat, _("Rating"), p_cd->psz_rating );
-    }
-    msg_Dbg( p_input,
+    msg_Dbg( (vlc_object_t*)s,
              "Read \"Content Description Object\" title:\"%s\" author:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
              p_cd->psz_title,
              p_cd->psz_author,
@@ -687,13 +553,13 @@ int  ASF_ReadObject_content_description( input_thread_t *p_input,
              p_cd->psz_description,
              p_cd->psz_rating );
 #endif
-    return( 1 );
+    return VLC_SUCCESS;
 }
 
-void ASF_FreeObject_content_description( input_thread_t *p_input,
-                                         asf_object_t *p_obj )
+static void ASF_FreeObject_content_description( asf_object_t *p_obj)
 {
-    asf_object_content_description_t *p_cd = (asf_object_content_description_t*)p_obj;
+    asf_object_content_description_t *p_cd =
+                                    (asf_object_content_description_t*)p_obj;
 
     FREE( p_cd->psz_title );
     FREE( p_cd->psz_author );
@@ -706,10 +572,8 @@ static struct
 {
     const guid_t  *p_id;
     int     i_type;
-    int     (*ASF_ReadObject_function)( input_thread_t *p_input,
-                                        asf_object_t *p_obj );
-    void    (*ASF_FreeObject_function)( input_thread_t *p_input,
-                                        asf_object_t *p_obj );
+    int     (*ASF_ReadObject_function)( stream_t *, asf_object_t *p_obj );
+    void    (*ASF_FreeObject_function)( asf_object_t *p_obj );
 } ASF_Object_Function [] =
 {
     { &asf_object_header_guid,            ASF_OBJECT_TYPE_HEADER,             ASF_ReadObject_Header, ASF_FreeObject_Null },
@@ -725,9 +589,8 @@ static struct
     { &asf_object_null_guid,   0,                      NULL,                  NULL }
 };
 
-int  ASF_ReadObject( input_thread_t *p_input,
-                     asf_object_t *p_obj,
-                     asf_object_t *p_father )
+static int ASF_ReadObject( stream_t *s,
+                           asf_object_t *p_obj, asf_object_t *p_father )
 {
     int i_result;
     int i_index;
@@ -736,10 +599,10 @@ int  ASF_ReadObject( input_thread_t *p_input,
     {
         return( 0 );
     }
-    if( !ASF_ReadObjectCommon( p_input, p_obj ) )
+    if( ASF_ReadObjectCommon( s, p_obj ) )
     {
-        msg_Warn( p_input, "Cannot read one asf object" );
-        return( 0 );
+        msg_Warn( (vlc_object_t*)s, "Cannot read one asf object" );
+        return VLC_EGENERIC;
     }
     p_obj->common.p_father = p_father;
     p_obj->common.p_first = NULL;
@@ -749,8 +612,8 @@ int  ASF_ReadObject( input_thread_t *p_input,
 
     if( p_obj->common.i_object_size < 24 )
     {
-        msg_Warn( p_input, "Found a corrupted asf object (size<24)" );
-        return( 0 );
+        msg_Warn( (vlc_object_t*)s, "Found a corrupted asf object (size<24)" );
+        return VLC_EGENERIC;
     }
     /* find this object */
     for( i_index = 0; ; i_index++ )
@@ -768,15 +631,14 @@ int  ASF_ReadObject( input_thread_t *p_input,
     /* Now load this object */
     if( ASF_Object_Function[i_index].ASF_ReadObject_function == NULL )
     {
-        msg_Warn( p_input, "Unknown asf object (not loaded)" );
-        i_result = 1;
+        msg_Warn( (vlc_object_t*)s, "Unknown asf object (not loaded)" );
+        i_result = VLC_SUCCESS;
     }
     else
     {
         /* XXX ASF_ReadObject_function realloc *pp_obj XXX */
         i_result =
-            (ASF_Object_Function[i_index].ASF_ReadObject_function)( p_input,
-                                                                    p_obj );
+          (ASF_Object_Function[i_index].ASF_ReadObject_function)( s, p_obj );
     }
 
     /* link this object with father */
@@ -796,8 +658,7 @@ int  ASF_ReadObject( input_thread_t *p_input,
     return( i_result );
 }
 
-void ASF_FreeObject( input_thread_t *p_input,
-                     asf_object_t *p_obj )
+static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
 {
     int i_index;
     asf_object_t *p_child;
@@ -813,7 +674,7 @@ void ASF_FreeObject( input_thread_t *p_input,
     {
         asf_object_t *p_next;
         p_next = p_child->common.p_next;
-        ASF_FreeObject( p_input, p_child );
+        ASF_FreeObject( s, p_child );
         p_child = p_next;
     }
 
@@ -832,19 +693,18 @@ void ASF_FreeObject( input_thread_t *p_input,
     /* Now free this object */
     if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
     {
-        msg_Warn( p_input,
+        msg_Warn( (vlc_object_t*)s,
                   "Unknown asf object " GUID_FMT,
                   GUID_PRINT( p_obj->common.i_object_id ) );
     }
     else
     {
 #ifdef ASF_DEBUG
-        msg_Dbg( p_input,
+        msg_Dbg( (vlc_object_t*)s,
                   "Free asf object " GUID_FMT,
                   GUID_PRINT( p_obj->common.i_object_id ) );
 #endif
-        (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_input,
-                                                                p_obj );
+        (ASF_Object_Function[i_index].ASF_FreeObject_function)( p_obj );
     }
     free( p_obj );
     return;
@@ -853,30 +713,30 @@ void ASF_FreeObject( input_thread_t *p_input,
 /*****************************************************************************
  * ASF_ReadObjetRoot : parse the entire stream/file
  *****************************************************************************/
-int ASF_ReadObjectRoot( input_thread_t *p_input,
-                        asf_object_root_t *p_root,
-                        int b_seekable )
+asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
 {
+    asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
     asf_object_t *p_obj;
 
     p_root->i_type = ASF_OBJECT_TYPE_ROOT;
     memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
     p_root->i_object_pos = 0;
-    p_root->i_object_size = p_input->stream.p_selected_area->i_size;
+    stream_Control( s, STREAM_GET_SIZE, &p_root->i_object_size );
     p_root->p_first = NULL;
-    p_root->p_last = NULL;
-    p_root->p_next = NULL;
-    p_root->p_hdr = NULL;
-    p_root->p_data = NULL;
+    p_root->p_last  = NULL;
+    p_root->p_next  = NULL;
+    p_root->p_hdr   = NULL;
+    p_root->p_data  = NULL;
+    p_root->p_fp    = NULL;
     p_root->p_index = NULL;
 
     for( ; ; )
     {
         p_obj  = malloc( sizeof( asf_object_t ) );
 
-        if( !( ASF_ReadObject( p_input, p_obj, (asf_object_t*)p_root ) ) )
+        if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
         {
-            return( 1 );
+            break;
         }
         switch( p_obj->common.i_type )
         {
@@ -890,24 +750,39 @@ int ASF_ReadObjectRoot( input_thread_t *p_input,
                 p_root->p_index = (asf_object_index_t*)p_obj;
                 break;
             default:
-                msg_Warn( p_input, "Unknow Object found" );
+                msg_Warn( (vlc_object_t*)s, "Unknow Object found" );
                 break;
         }
-        if( !b_seekable && ( p_root->p_hdr && p_root->p_data ) )
+        if( !b_seekable && p_root->p_hdr && p_root->p_data )
         {
             /* For unseekable stream it's enouth to play */
-            return( 1 );
+            break;
+        }
+
+        if( ASF_NextObject( s, p_obj ) ) /* Go to the next object */
+        {
+            break;
         }
+    }
+
+    if( p_root->p_hdr != NULL && p_root->p_data != NULL )
+    {
+        p_root->p_fp = ASF_FindObject( p_root->p_hdr,
+                                       &asf_object_file_properties_guid, 0 );
 
-        if( !ASF_NextObject( p_input, p_obj ) ) /* Go to the next object */
+        if( p_root->p_fp )
         {
-            return( 1 );
+            return p_root;
         }
+        msg_Warn( (vlc_object_t*)s, "cannot fine file properties object" );
     }
+
+    /* Invalid file */
+    ASF_FreeObjectRoot( s, p_root );
+    return NULL;
 }
 
-void ASF_FreeObjectRoot( input_thread_t *p_input,
-                         asf_object_root_t *p_root )
+void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
 {
     asf_object_t *p_obj;
 
@@ -916,17 +791,10 @@ void ASF_FreeObjectRoot( input_thread_t *p_input,
     {
         asf_object_t *p_next;
         p_next = p_obj->common.p_next;
-        ASF_FreeObject( p_input, p_obj );
+        ASF_FreeObject( s, p_obj );
         p_obj = p_next;
     }
-    p_root->p_first = NULL;
-    p_root->p_last = NULL;
-    p_root->p_next = NULL;
-
-    p_root->p_hdr = NULL;
-    p_root->p_data = NULL;
-    p_root->p_index = NULL;
-
+    free( p_root );
 }
 
 int  __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
@@ -975,4 +843,3 @@ void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid, int i_number
     return( NULL );
 }
 
-