]> git.sesse.net Git - vlc/blobdiff - modules/demux/asf/libasf.c
ASF: macro removal in ASF_CountObject
[vlc] / modules / demux / asf / libasf.c
index 75229f4a3baa3554dee5c86a29b7b65cf033b709..e91f1956678d175a63a9b8256b8aac5d118d0c3e 100644 (file)
@@ -1,8 +1,7 @@
 /*****************************************************************************
  * libasf.c : asf stream demux module for vlc
  *****************************************************************************
- * Copyright (C) 2001-2003 the VideoLAN team
- * $Id$
+ * Copyright © 2001-2004, 2006-2008 the VideoLAN team
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@videolan.org>
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
 #include <vlc_demux.h>
-#include <vlc_charset.h>
+#include <vlc_charset.h>          /* FromCharset */
 
 #include "libasf.h"
 
 #define ASF_DEBUG 1
 
-#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"
-#define GUID_PRINT( guid )  \
-    (guid).v1,              \
-    (guid).v2,              \
-    (guid).v3,              \
-    (guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3],    \
-    (guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
-
 /* Helpers:
  * They ensure that invalid reads will not create problems.
  * They are expansion safe
@@ -124,29 +114,6 @@ static char *AsfObjectHelperReadString( const uint8_t *p_peek, int i_peek, uint8
  ****************************************************************************/
 static int ASF_ReadObject( stream_t *, asf_object_t *,  asf_object_t * );
 
-/****************************************************************************
- * GUID functions
- ****************************************************************************/
-void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data )
-{
-    p_guid->v1 = GetDWLE( p_data );
-    p_guid->v2 = GetWLE( p_data + 4);
-    p_guid->v3 = GetWLE( p_data + 6);
-    memcpy( p_guid->v4, p_data + 8, 8 );
-}
-
-bool 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 )||
-        (p_guid1->v3 != p_guid2->v3 )||
-        ( memcmp( p_guid1->v4, p_guid2->v4,8 )) )
-    {
-        return false;
-    }
-    return true;
-}
-
 /****************************************************************************
  *
  ****************************************************************************/
@@ -213,10 +180,9 @@ static int  ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_header_t *p_hdr = &p_obj->header;
     asf_object_t        *p_subobj;
-    int                 i_peek;
     const uint8_t       *p_peek;
 
-    if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
+    if( stream_Peek( s, &p_peek, 30 ) < 30 )
        return VLC_EGENERIC;
 
     p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 );
@@ -255,10 +221,9 @@ static int  ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
 static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
 {
     asf_object_data_t *p_data = &p_obj->data;
-    int               i_peek;
     const uint8_t     *p_peek;
 
-    if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
+    if( stream_Peek( s, &p_peek, 50 ) < 50 )
        return VLC_EGENERIC;
 
     ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
@@ -333,10 +298,9 @@ static void ASF_FreeObject_Index( 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 = &p_obj->file_properties;
-    int           i_peek;
     const uint8_t *p_peek;
 
-    if( ( i_peek = stream_Peek( s, &p_peek,  104 ) ) < 104 )
+    if( stream_Peek( s, &p_peek,  104 ) < 104 )
        return VLC_EGENERIC;
 
     ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
@@ -736,6 +700,14 @@ static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
     FREENULL( p_cl->codec );
 }
 
+static inline char *get_wstring( const uint8_t *p_data, size_t i_size )
+{
+    char *psz_str = FromCharset( "UTF-16LE", p_data, i_size );
+    if( psz_str )
+        p_data += i_size;
+    return psz_str;
+}
+
 /* Microsoft should go to hell. This time the length give number of bytes
  * and for the some others object, length give char16 count ... */
 static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
@@ -747,15 +719,8 @@ static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
     if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
        return VLC_EGENERIC;
 
-/* FIXME i_size*3 is the worst case. */
-#define GETSTRINGW( psz_str, i_size ) do { \
-    psz_str = FromCharset( "UTF-16LE", p_data, i_size ); \
-    if( psz_str ) { \
-        p_data += i_size; \
-    } } while(0)
-
     p_data = p_peek + 24;
-    
+
     i_title         = ASF_READ2();
     i_artist        = ASF_READ2();
     i_copyright     = ASF_READ2();
@@ -765,13 +730,11 @@ static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
     if( !ASF_HAVE( i_title+i_artist+i_copyright+i_description+i_rating ) )
         return VLC_EGENERIC;
 
-    GETSTRINGW( p_cd->psz_title, i_title );
-    GETSTRINGW( p_cd->psz_artist, i_artist );
-    GETSTRINGW( p_cd->psz_copyright, i_copyright );
-    GETSTRINGW( p_cd->psz_description, i_description );
-    GETSTRINGW( p_cd->psz_rating, i_rating );
-
-#undef  GETSTRINGW
+    p_cd->psz_title = get_wstring( p_data, i_title );
+    p_cd->psz_artist = get_wstring( p_data, i_artist );
+    p_cd->psz_copyright = get_wstring( p_data, i_copyright );
+    p_cd->psz_description = get_wstring( p_data, i_description );
+    p_cd->psz_rating = get_wstring( p_data, i_rating );
 
 #ifdef ASF_DEBUG
     msg_Dbg( s,
@@ -951,7 +914,7 @@ static int ASF_ReadObject_extended_stream_properties( stream_t *s,
         asf_object_t *p_sp;
         /* Cannot fail as peek succeed */
         stream_Read( s, NULL, p_data - p_peek );
+
         p_sp = malloc( sizeof( asf_object_t ) );
 
         if( !p_sp || ASF_ReadObject( s, p_sp, NULL ) )
@@ -1030,7 +993,7 @@ static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
         p_ae->pi_stream_number[i] = ASF_READ2();
     }
     p_ae->i_stream_number_count = i;
+
 #ifdef ASF_DEBUG
     msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
     for( i = 0; i < p_ae->i_stream_number_count; i++ )
@@ -1258,7 +1221,7 @@ static const struct
       ASF_ReadObject_Header, ASF_FreeObject_Null },
     { &asf_object_data_guid, ASF_OBJECT_DATA,
       ASF_ReadObject_Data, ASF_FreeObject_Null },
-    { &asf_object_index_guid, ASF_OBJECT_INDEX,
+    { &asf_object_simple_index_guid, ASF_OBJECT_INDEX,
       ASF_ReadObject_Index, ASF_FreeObject_Index },
     { &asf_object_file_properties_guid, ASF_OBJECT_FILE_PROPERTIES,
       ASF_ReadObject_file_properties, ASF_FreeObject_Null },
@@ -1279,7 +1242,7 @@ static const struct
     { &asf_object_stream_bitrate_properties, ASF_OBJECT_OTHER,
       ASF_ReadObject_stream_bitrate_properties,
       ASF_FreeObject_stream_bitrate_properties },
-    { &asf_object_extended_stream_properties, ASF_OBJECT_OTHER,
+    { &asf_object_extended_stream_properties_guid, ASF_OBJECT_OTHER,
       ASF_ReadObject_extended_stream_properties,
       ASF_FreeObject_extended_stream_properties },
     { &asf_object_advanced_mutual_exclusion, ASF_OBJECT_OTHER,
@@ -1325,9 +1288,9 @@ static int ASF_ReadObject( stream_t *s, asf_object_t *p_obj,
     /* find this object */
     for( i_index = 0; ; i_index++ )
     {
-        if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
+        if( guidcmp( ASF_Object_Function[i_index].p_id,
                          &p_obj->common.i_object_id ) ||
-            ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
+            guidcmp( ASF_Object_Function[i_index].p_id,
                          &asf_object_null_guid ) )
         {
             break;
@@ -1386,9 +1349,9 @@ static void ASF_FreeObject( stream_t *s, asf_object_t *p_obj )
     /* find this object */
     for( i_index = 0; ; i_index++ )
     {
-        if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
+        if( guidcmp( ASF_Object_Function[i_index].p_id,
                      &p_obj->common.i_object_id )||
-            ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
+            guidcmp( ASF_Object_Function[i_index].p_id,
                      &asf_object_null_guid ) )
         {
             break;
@@ -1426,6 +1389,7 @@ static const struct
     { &asf_object_header_guid, "Header" },
     { &asf_object_data_guid, "Data" },
     { &asf_object_index_guid, "Index" },
+    { &asf_object_simple_index_guid, "Simple Index" },
     { &asf_object_file_properties_guid, "File Properties" },
     { &asf_object_stream_properties_guid, "Stream Properties" },
     { &asf_object_content_description_guid, "Content Description" },
@@ -1439,7 +1403,7 @@ static const struct
     { &asf_object_language_list, "Language List" },
     { &asf_object_stream_bitrate_properties, "Stream Bitrate Properties" },
     { &asf_object_padding, "Padding" },
-    { &asf_object_extended_stream_properties, "Extended Stream Properties" },
+    { &asf_object_extended_stream_properties_guid, "Extended Stream Properties" },
     { &asf_object_advanced_mutual_exclusion, "Advanced Mutual Exclusion" },
     { &asf_object_stream_prioritization, "Stream Prioritization" },
     { &asf_object_extended_content_description, "Extended content description"},
@@ -1458,7 +1422,7 @@ static void ASF_ObjectDumpDebug( vlc_object_t *p_obj,
     /* Find the name */
     for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )
     {
-        if( ASF_CmpGUID( ASF_ObjectDumpDebugInfo[i].p_id,
+        if( guidcmp( ASF_ObjectDumpDebugInfo[i].p_id,
                           &p_node->i_object_id ) )
             break;
     }
@@ -1572,12 +1536,12 @@ asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
                                     &asf_object_metadata_guid, 0 );
                 /* Special case for broken designed file format :( */
                 i_ext_stream = ASF_CountObject( p_hdr_ext,
-                                    &asf_object_extended_stream_properties );
+                                    &asf_object_extended_stream_properties_guid );
                 for( i = 0; i < i_ext_stream; i++ )
                 {
                     asf_object_t *p_esp =
                         ASF_FindObject( p_hdr_ext,
-                                   &asf_object_extended_stream_properties, i );
+                                   &asf_object_extended_stream_properties_guid, i );
                     if( p_esp->ext_stream.p_sp )
                     {
                         asf_object_t *p_sp =
@@ -1619,11 +1583,12 @@ void ASF_FreeObjectRoot( stream_t *s, asf_object_root_t *p_root )
     free( p_root );
 }
 
-int  __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
+int ASF_CountObject( void *_p_obj, const guid_t *p_guid )
 {
     int i_count;
-    asf_object_t *p_child;
+    asf_object_t *p_child, *p_obj;
 
+    p_obj = (asf_object_t *)_p_obj;
     if( !p_obj )
         return 0;
 
@@ -1631,7 +1596,7 @@ int  __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
     p_child = p_obj->common.p_first;
     while( p_child )
     {
-        if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
+        if( guidcmp( &p_child->common.i_object_id, p_guid ) )
             i_count++;
 
         p_child = p_child->common.p_next;
@@ -1648,7 +1613,7 @@ void *__ASF_FindObject( asf_object_t *p_obj, const guid_t *p_guid,
 
     while( p_child )
     {
-        if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
+        if( guidcmp( &p_child->common.i_object_id, p_guid ) )
         {
             if( i_number == 0 )
                 return p_child;