]> git.sesse.net Git - vlc/blobdiff - modules/demux/real.c
lua modules: enforce DIR_SEP instead of /
[vlc] / modules / demux / real.c
index d56706569c691608ba4b973e1f7f65dcdcb6898f..dc145a8eabe586bcaf28484dbde55a735345a646 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * real.c: Real demuxer.
  *****************************************************************************
- * Copyright (C) 2004, 2006 the VideoLAN team
+ * Copyright (C) 2004, 2006-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include <vlc/vlc.h>
+
+#include <stdio.h>
 #include <stdlib.h>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_demux.h>
+#include <vlc_charset.h>
+#include <vlc_meta.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -82,14 +86,17 @@ struct demux_sys_t
     int  i_our_duration;
     int  i_mux_rate;
 
+    char* psz_title;
+    char* psz_artist;
+    char* psz_copyright;
+    char* psz_description;
+
     int          i_track;
     real_track_t **track;
 
     uint8_t buffer[65536];
 
     int64_t     i_pcr;
-    
-    vlc_meta_t *p_meta;
 };
 
 static int Demux( demux_t *p_demux );
@@ -106,10 +113,10 @@ static int Open( vlc_object_t *p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
 
-    uint8_t     *p_peek;
+    const uint8_t *p_peek;
 
     if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 ) return VLC_EGENERIC;
-    if( strncmp( (char *)p_peek, ".RMF", 4 ) ) return VLC_EGENERIC;
+    if( memcmp( p_peek, ".RMF", 4 ) ) return VLC_EGENERIC;
 
     /* Fill p_demux field */
     p_demux->pf_demux = Demux;
@@ -170,11 +177,16 @@ static void Close( vlc_object_t *p_this )
             if( tk->p_subpackets[ j ] )
                 block_Release( tk->p_subpackets[ j ] );
         }
-        if( !tk->i_subpackets ) free( tk->p_subpackets );
+        if( tk->i_subpackets ) free( tk->p_subpackets );
 
         free( tk );
     }
 
+    if( p_sys->psz_title ) free( p_sys->psz_title );
+    if( p_sys->psz_artist ) free( p_sys->psz_artist );
+    if( p_sys->psz_copyright ) free( p_sys->psz_copyright );
+    if( p_sys->psz_description ) free( p_sys->psz_description );
+
     if( p_sys->i_track > 0 ) free( p_sys->track );
     free( p_sys );
 }
@@ -495,16 +507,18 @@ static int Demux( demux_t *p_demux )
             }
         }
         else if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
-                 tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
+                 tk->fmt.i_codec == VLC_FOURCC( 'a', 't', 'r', 'c') ||
+                 tk->fmt.i_codec == VLC_FOURCC( '2', '8', '_', '8') )
         {
             uint8_t *p_buf = p_sys->buffer;
-            int y = tk->i_subpacket / (tk->i_frame_size /tk->i_subpacket_size);
+            int y = tk->i_subpacket / ( tk->i_frame_size /tk->i_subpacket_size);
             int i_index, i;
 
             /* Sanity check */
             if( i_flags & 2 ) y = tk->i_subpacket = 0;
 
-            if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) )
+            if( tk->fmt.i_codec == VLC_FOURCC( 'c', 'o', 'o', 'k' ) ||
+                tk->fmt.i_codec == VLC_FOURCC( 'a', 't', 'r', 'c' ) )
             for( i = 0; i < tk->i_frame_size / tk->i_subpacket_size; i++ )
             {
                 block_t *p_block = block_New( p_demux, tk->i_subpacket_size );
@@ -519,7 +533,7 @@ static int Demux( demux_t *p_demux )
                 tk->i_subpacket++;
             }
 
-            if( tk->fmt.i_codec == VLC_FOURCC('2','8','_','8') )
+            if( tk->fmt.i_codec == VLC_FOURCC( '2', '8', '_', '8' ) )
             for( i = 0; i < tk->i_subpacket_h / 2; i++ )
             {
                 block_t *p_block = block_New( p_demux, tk->i_coded_frame_size);
@@ -659,8 +673,18 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_META:
         {
-            vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
-            *pp_meta = p_sys->p_meta;
+            vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t* );
+
+            /* the core will crash if we provide NULL strings, so check 
+             * every string first */
+            if( p_sys->psz_title )
+                vlc_meta_SetTitle( p_meta, p_sys->psz_title );
+            if( p_sys->psz_artist )
+                vlc_meta_SetArtist( p_meta, p_sys->psz_artist );
+            if( p_sys->psz_copyright )
+                vlc_meta_SetCopyright( p_meta, p_sys->psz_copyright );
+            if( p_sys->psz_description )
+                vlc_meta_SetDescription( p_meta, p_sys->psz_description );
             return VLC_SUCCESS;
         }
 
@@ -684,8 +708,6 @@ static int HeaderRead( demux_t *p_demux )
     uint32_t    i_size;
     int64_t     i_skip;
     int         i_version;
-    
-    p_sys->p_meta = vlc_meta_New();
 
     for( ;; )
     {
@@ -701,7 +723,7 @@ static int HeaderRead( demux_t *p_demux )
         msg_Dbg( p_demux, "object %4.4s size=%d version=%d",
                  (char*)&i_id, i_size, i_version );
 
-        if( i_size < 10 )
+        if( i_size < 10 && i_id != VLC_FOURCC('D','A','T','A') )
         {
             msg_Dbg( p_demux, "invalid size for object %4.4s", (char*)&i_id );
             return VLC_EGENERIC;
@@ -761,7 +783,7 @@ static int HeaderRead( demux_t *p_demux )
 
                 msg_Dbg( p_demux, "    - title=`%s'", psz );
                 EnsureUTF8( psz );
-                vlc_meta_Add( p_sys->p_meta, VLC_META_TITLE, psz );
+                asprintf( &p_sys->psz_title, psz );
                 free( psz );
                 i_skip -= i_len;
             }
@@ -776,7 +798,7 @@ static int HeaderRead( demux_t *p_demux )
 
                 msg_Dbg( p_demux, "    - author=`%s'", psz );
                 EnsureUTF8( psz );
-                vlc_meta_Add( p_sys->p_meta, VLC_META_ARTIST, psz );
+                asprintf( &p_sys->psz_artist, psz );
                 free( psz );
                 i_skip -= i_len;
             }
@@ -791,7 +813,7 @@ static int HeaderRead( demux_t *p_demux )
 
                 msg_Dbg( p_demux, "    - copyright=`%s'", psz );
                 EnsureUTF8( psz );
-                vlc_meta_Add( p_sys->p_meta, VLC_META_COPYRIGHT, psz );
+                asprintf( &p_sys->psz_copyright, psz );
                 free( psz );
                 i_skip -= i_len;
             }
@@ -806,7 +828,7 @@ static int HeaderRead( demux_t *p_demux )
 
                 msg_Dbg( p_demux, "    - comment=`%s'", psz );
                 EnsureUTF8( psz );
-                vlc_meta_Add( p_sys->p_meta, VLC_META_DESCRIPTION, psz );
+                asprintf( &p_sys->psz_description, psz );
                 free( psz );
                 i_skip -= i_len;
             }
@@ -905,12 +927,12 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
     demux_sys_t *p_sys = p_demux->p_sys;
     es_format_t fmt;
     real_track_t *tk;
-    uint8_t *p_peek;
+    const uint8_t *p_peek;
 
     msg_Dbg( p_demux, "    - specific data len=%d", i_len );
     if( stream_Peek(p_demux->s, &p_peek, i_len) < i_len ) return VLC_EGENERIC;
 
-    if( !strncmp( (char *)&p_peek[4], "VIDO", 4 ) )
+    if( ( i_len >= 8 ) && !memcmp( &p_peek[4], "VIDO", 4 ) )
     {
         es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( p_peek[8], p_peek[9],
                         p_peek[10], p_peek[11] ) );
@@ -1039,6 +1061,7 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
             break;
 
         case VLC_FOURCC('c','o','o','k'):
+        case VLC_FOURCC('a','t','r','c'):
             fmt.audio.i_blockalign = i_subpacket_size;
             if( !(fmt.i_extra = GetDWBE( p_peek )) ) break;
             fmt.p_extra = malloc( fmt.i_extra );