]> git.sesse.net Git - vlc/commitdiff
* modules/demux/asf/*: get video aspect ratio from metadata object.
authorGildas Bazin <gbazin@videolan.org>
Fri, 10 Sep 2004 12:43:08 +0000 (12:43 +0000)
committerGildas Bazin <gbazin@videolan.org>
Fri, 10 Sep 2004 12:43:08 +0000 (12:43 +0000)
modules/demux/asf/asf.c
modules/demux/asf/libasf.c
modules/demux/asf/libasf.h

index 19fbd3ba61e68d887684ba7cf277c2a2d1fdfc85..08a8b5fefb9ef0b3712b0b63189f829f2ee5ae27 100644 (file)
@@ -679,25 +679,63 @@ static int DemuxInit( demux_t *p_demux )
             msg_Dbg( p_demux, "added new audio stream(codec:0x%x,ID:%d)",
                     GetWLE( p_data ), p_sp->i_stream_number );
         }
-        else if( ASF_CmpGUID( &p_sp->i_stream_type, &asf_object_stream_type_video ) &&
-                 p_sp->i_type_specific_data_length >= 11 + sizeof( BITMAPINFOHEADER ) )
+        else if( ASF_CmpGUID( &p_sp->i_stream_type,
+                              &asf_object_stream_type_video ) &&
+                 p_sp->i_type_specific_data_length >= 11 +
+                 sizeof( BITMAPINFOHEADER ) )
         {
             es_format_t  fmt;
             uint8_t      *p_data = &p_sp->p_type_specific_data[11];
 
             es_format_Init( &fmt, VIDEO_ES,
-                            VLC_FOURCC( p_data[16], p_data[17], p_data[18], p_data[19] ) );
+                            VLC_FOURCC( p_data[16], p_data[17],
+                                        p_data[18], p_data[19] ) );
             fmt.video.i_width = GetDWLE( p_data + 4 );
             fmt.video.i_height= GetDWLE( p_data + 8 );
 
-            if( p_sp->i_type_specific_data_length > 11 + sizeof( BITMAPINFOHEADER ) )
+            if( p_sp->i_type_specific_data_length > 11 +
+                sizeof( BITMAPINFOHEADER ) )
             {
                 fmt.i_extra = __MIN( GetDWLE( p_data ),
-                                     p_sp->i_type_specific_data_length - 11 - sizeof( BITMAPINFOHEADER ) );
+                                     p_sp->i_type_specific_data_length - 11 -
+                                     sizeof( BITMAPINFOHEADER ) );
                 fmt.p_extra = malloc( fmt.i_extra );
-                memcpy( fmt.p_extra, &p_data[sizeof( BITMAPINFOHEADER )], fmt.i_extra );
+                memcpy( fmt.p_extra, &p_data[sizeof( BITMAPINFOHEADER )],
+                        fmt.i_extra );
             }
 
+            /* Look for an aspect ratio */
+            if( p_sys->p_root->p_metadata )
+            {
+                asf_object_metadata_t *p_meta = p_sys->p_root->p_metadata;
+                int i, i_aspect_x = 0, i_aspect_y = 0;
+
+                for( i = 0; i < p_meta->i_record_entries_count; i++ )
+                {
+                    if( !strcmp( p_meta->record[i].psz_name, "AspectRatioX" ) )
+                    {
+                        if( (!i_aspect_x && !p_meta->record[i].i_stream) ||
+                            p_meta->record[i].i_stream ==
+                            p_sp->i_stream_number )
+                            i_aspect_x = p_meta->record[i].i_val;
+                    }
+                    if( !strcmp( p_meta->record[i].psz_name, "AspectRatioY" ) )
+                    {
+                        if( (!i_aspect_y && !p_meta->record[i].i_stream) ||
+                            p_meta->record[i].i_stream ==
+                            p_sp->i_stream_number )
+                            i_aspect_y = p_meta->record[i].i_val;
+                    }
+                }
+
+                if( i_aspect_x && i_aspect_y )
+                {
+                    fmt.video.i_aspect = i_aspect_x * fmt.video.i_width *
+                        VOUT_ASPECT_FACTOR /
+                        (int64_t)fmt.video.i_height / i_aspect_y;
+               }
+           }
+
             tk->i_cat = VIDEO_ES;
             tk->p_es = es_out_Add( p_demux->out, &fmt );
             es_format_Clean( &fmt );
index 94f625aaa83a9e5096ec08e344c320f6dbaa6c0f..bf8e07c493c63c6fa84b73241cd19ebb1c169078 100644 (file)
@@ -348,23 +348,27 @@ static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
         record.p_data = 0;
 
         /* get name */
-        record.psz_name = malloc( i_name/2 );
+        record.psz_name = malloc( i_name/2 + 1 );
         for( j = 0; j < i_name/2; j++ )
         {
             record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
         }
+        record.psz_name[j] = 0; /* just to make sure */
 
         /* get data */
         if( record.i_type == ASF_METADATA_TYPE_STRING )
         {
-            record.p_data = malloc( i_data/2 );
+            record.p_data = malloc( i_data/2 + 1 );
             record.i_data = i_data/2;
             for( j = 0; j < i_data/2; j++ )
             {
                 record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2;
             }
+            record.p_data[j] = 0; /* just to make sure */
 
+#ifdef ASF_DEBUG
             msg_Dbg( s, "metadata: %s=%s", record.psz_name, record.p_data );
+#endif
         }
         else if( record.i_type == ASF_METADATA_TYPE_BYTE )
         {
@@ -373,8 +377,10 @@ static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
             memcpy( record.p_data, p_peek + i_peek, i_data );
             p_peek += i_data;
 
+#ifdef ASF_DEBUG
             msg_Dbg( s, "metadata: %s (%i bytes)", record.psz_name,
                      record.i_data );
+#endif
         }
         else
         {
@@ -391,7 +397,9 @@ static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
                 record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
             }
 
+#ifdef ASF_DEBUG
             msg_Dbg( s, "metadata: %s=%i", record.psz_name, record.i_val );
+#endif
         }
 
         p_meta->i_record_entries_count++;
@@ -880,7 +888,6 @@ asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
     p_root->p_data  = NULL;
     p_root->p_fp    = NULL;
     p_root->p_index = NULL;
-    p_root->p_hdr_ext = NULL;
     p_root->p_metadata = NULL;
 
     for( ; ; )
@@ -903,9 +910,6 @@ asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
             case( ASF_OBJECT_TYPE_INDEX ):
                 p_root->p_index = (asf_object_index_t*)p_obj;
                 break;
-            case( ASF_OBJECT_TYPE_HEADER_EXTENSION ):
-                p_root->p_hdr_ext = (asf_object_header_extension_t*)p_obj;
-                break;
             default:
                 msg_Warn( (vlc_object_t*)s, "unknow object found" );
                 break;
@@ -935,17 +939,19 @@ asf_object_root_t *ASF_ReadObjectRoot( stream_t *s, int b_seekable )
 
         if( p_root->p_fp )
         {
-
-            if( p_root->p_hdr_ext != NULL )
+            asf_object_t *p_hdr_ext =
+                ASF_FindObject( p_root->p_hdr,
+                                &asf_object_header_extension_guid, 0 );
+            if( p_hdr_ext )
             {
                 p_root->p_metadata =
-                    ASF_FindObject( p_root->p_hdr_ext,
+                    ASF_FindObject( p_hdr_ext,
                                     &asf_object_metadata_guid, 0 );
             }
 
             return p_root;
         }
-        msg_Warn( (vlc_object_t*)s, "cannot find file properties object" );
+        msg_Warn( s, "cannot find file properties object" );
     }
 
     /* Invalid file */
index 2161b2b6a57d51f3032ba4f8767a30ac345dee9b..41e7ff57e10798db578c8eb9ba30c0f1d9486430 100644 (file)
@@ -308,7 +308,6 @@ typedef struct asf_object_root_s
     asf_object_data_t   *p_data;
     /* could be NULL if !b_seekable or not-present */
     asf_object_index_t  *p_index;
-    asf_object_header_extension_t *p_hdr_ext;
 
     /* from asf_object_header_t */
     asf_object_file_properties_t *p_fp;