]> git.sesse.net Git - vlc/blobdiff - modules/demux/real.c
Fixes malloc's parameter
[vlc] / modules / demux / real.c
index ae2e19d40d4c1b4268f9af61d9cd128e5eab0a15..94e0b4273b040e67eca3571a01ff872e1d64077a 100644 (file)
@@ -2,7 +2,7 @@
  * real.c: Real demuxer.
  *****************************************************************************
  * Copyright (C) 2004 VideoLAN
- * $Id: real.c,v 1.1 2004/01/04 14:35:12 fenrir Exp $
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -37,7 +37,7 @@ static void Close  ( vlc_object_t * );
 
 vlc_module_begin();
     set_description( _("Real demuxer" ) );
-    set_capability( "demux2", 1);
+    set_capability( "demux2", 1);
     set_callbacks( Open, Close );
     add_shortcut( "real" );
     add_shortcut( "rm" );
@@ -90,8 +90,6 @@ static int Open( vlc_object_t *p_this )
 
     uint8_t     *p_peek;
 
-    int         i;
-
     if( stream_Peek( p_demux->s, &p_peek, 10 ) < 10 )
     {
         msg_Err( p_demux, "cannot peek" );
@@ -110,14 +108,14 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_data_offset = 0;
     p_sys->i_track = 0;
     p_sys->track   = NULL;
-    p_sys->i_pcr   = 0;
+    p_sys->i_pcr   = 1;
 
 
     /* Parse the headers */
     if( HeaderRead( p_demux ) )
     {
         int i;
-        msg_Err( p_demux, "Invalid header" );
+        msg_Err( p_demux, "invalid header" );
         for( i = 0; i < p_sys->i_track; i++ )
         {
             real_track_t *tk = p_sys->track[i];
@@ -314,7 +312,7 @@ static int Demux( demux_t *p_demux )
                 {
                     p_sys->i_pcr = tk->p_frame->i_dts;
 
-                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int)0, (int64_t)p_sys->i_pcr );
+                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_pcr );
                 }
                 es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
 
@@ -383,7 +381,7 @@ static int Demux( demux_t *p_demux )
                     if( p_sys->i_pcr < tk->p_frame->i_dts )
                     {
                         p_sys->i_pcr = tk->p_frame->i_dts;
-                        es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int)0, (int64_t)p_sys->i_pcr );
+                        es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_pcr );
                     }
                     es_out_Send( p_demux->out, tk->p_es, tk->p_frame );
 
@@ -420,7 +418,7 @@ static int Demux( demux_t *p_demux )
                 if( p_sys->i_pcr < p_frame->i_dts )
                 {
                     p_sys->i_pcr = p_frame->i_dts;
-                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int)0, (int64_t)p_sys->i_pcr );
+                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_pcr );
                 }
                 es_out_Send( p_demux->out, tk->p_es, p_frame );
             }
@@ -448,36 +446,62 @@ static int Demux( demux_t *p_demux )
     }
     else if( tk->fmt.i_cat == AUDIO_ES && b_selected )
     {
-        block_t *p_block = block_New( p_demux, i_size );
+        /* Set PCR */
+        if( p_sys->i_pcr < i_pts )
+        {
+            p_sys->i_pcr = i_pts;
+            es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int64_t)p_sys->i_pcr );
+        }
 
-        if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
+        if( tk->fmt.i_codec == VLC_FOURCC( 'm', 'p', '4', 'a' ) )
         {
-            uint8_t *src = p_sys->buffer;
-            uint8_t *dst = p_block->p_buffer;
+            int     i_sub = (p_sys->buffer[1] >> 4)&0x0f;
+            uint8_t *p_sub = &p_sys->buffer[2+2*i_sub];
 
-            /* byte swap data */
-            while( dst < &p_block->p_buffer[i_size- 1])
+            int i;
+            for( i = 0; i < i_sub; i++ )
             {
-                *dst++ = src[1];
-                *dst++ = src[0];
+                int i_sub_size = GetWBE( &p_sys->buffer[2+i*2]);
+                block_t *p_block = block_New( p_demux, i_sub_size );
+                if( p_block )
+                {
+                    memcpy( p_block->p_buffer, p_sub, i_sub_size );
+                    p_sub += i_sub_size;
+
+                    p_block->i_dts =
+                    p_block->i_pts = ( i == 0 ? i_pts : 0 );
 
-                src += 2;
+                    es_out_Send( p_demux->out, tk->p_es, p_block );
+                }
             }
         }
         else
         {
-            memcpy( p_block->p_buffer, p_sys->buffer, i_size );
-        }
-        p_block->i_dts =
-        p_block->i_pts = i_pts;
+            block_t *p_block = block_New( p_demux, i_size );
 
-        if( p_sys->i_pcr < i_pts )
-        {
-            p_sys->i_pcr = i_pts;
+            if( tk->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', ' ' ) )
+            {
+                uint8_t *src = p_sys->buffer;
+                uint8_t *dst = p_block->p_buffer;
+
+                /* byte swap data */
+                while( dst < &p_block->p_buffer[i_size- 1])
+                {
+                    *dst++ = src[1];
+                    *dst++ = src[0];
 
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, (int)0, (int64_t)p_sys->i_pcr );
+                    src += 2;
+                }
+            }
+            else
+            {
+                memcpy( p_block->p_buffer, p_sys->buffer, i_size );
+            }
+            p_block->i_dts =
+            p_block->i_pts = i_pts;
+
+            es_out_Send( p_demux->out, tk->p_es, p_block );
         }
-        es_out_Send( p_demux->out, tk->p_es, p_block );
     }
 
 
@@ -489,11 +513,11 @@ static int Demux( demux_t *p_demux )
  *****************************************************************************/
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
+#if 0
     demux_sys_t *p_sys = p_demux->p_sys;
     double f, *pf;
     int64_t i64, *pi64;
 
-#if 0
     switch( i_query )
     {
         case DEMUX_GET_POSITION:
@@ -569,7 +593,7 @@ static int HeaderRead( demux_t *p_demux )
         i_size      = GetDWBE( &header[4] );
         i_version   = GetWBE( &header[8] );
 
-        msg_Dbg( p_demux, "Object %4.4s size=%d version=%d",
+        msg_Dbg( p_demux, "object %4.4s size=%d version=%d",
                  (char*)&i_id, i_size, i_version );
 
         if( i_size < 10 )
@@ -765,7 +789,8 @@ static int HeaderRead( demux_t *p_demux )
                     }
                     else if( !strncmp( p_peek, ".ra\xfd", 4 ) )
                     {
-                        int i_version = GetWBE( &p_peek[4] );
+                        int     i_version = GetWBE( &p_peek[4] );
+                        uint8_t *p_extra = NULL;
                         msg_Dbg( p_demux, "    - audio version=%d", i_version );
 
                         es_format_Init( &fmt, AUDIO_ES, 0 );
@@ -781,6 +806,7 @@ static int HeaderRead( demux_t *p_demux )
                                 {
                                     memcpy( &fmt.i_codec, &p_peek[57 + p_peek[56] + 1], 4 );
                                 }
+                                p_extra = &p_peek[57 + p_peek[56] + 1+ 4 + 3];
                             }
                         }
                         else if( i_version == 5 && stream_Peek( p_demux->s, &p_peek, 70 ) >= 70 )
@@ -788,15 +814,44 @@ static int HeaderRead( demux_t *p_demux )
                             memcpy( &fmt.i_codec, &p_peek[66], 4 );
                             fmt.audio.i_channels = GetWBE( &p_peek[60] );
                             fmt.audio.i_rate = GetWBE( &p_peek[54] );
+
+                            p_extra = &p_peek[66+4+3+1];
                         }
                         msg_Dbg( p_demux, "    - audio codec=%4.4s channels=%d rate=%dHz",
                                 (char*)&fmt.i_codec,
                                 fmt.audio.i_channels, fmt.audio.i_rate );
 
-                        if( !strncasecmp( (char*)&fmt.i_codec, "dnet", 4 ) )
+                        if( fmt.i_codec == VLC_FOURCC( 'd', 'n', 'e', 't' ) )
                         {
                             fmt.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
                         }
+                        else if( fmt.i_codec == VLC_FOURCC( 'r', 'a', 'a', 'c' ) ||
+                                 fmt.i_codec == VLC_FOURCC( 'r', 'a', 'c', 'p' ) )
+                        {
+                            int i_peek = p_extra - p_peek;
+                            if( stream_Peek( p_demux->s, &p_peek, i_peek + 4 ) >= i_peek + 4 )
+                            {
+                                int i_extra = GetDWBE( &p_peek[i_peek] );
+
+                                if( i_extra > 1 && i_peek + 4 + i_extra <= i_len &&
+                                    stream_Peek( p_demux->s, &p_peek, i_peek + 4 + i_extra ) >= i_peek + 4 + i_extra )
+                                {
+                                    fmt.i_extra = i_extra - 1;
+                                    fmt.p_extra = malloc ( i_extra - 1 );
+                                    memcpy( fmt.p_extra, &p_peek[i_peek+4+1], i_extra - 1 );
+
+                                    msg_Dbg( p_demux, "        - extra data=%d", i_extra );
+                                    {
+                                        int i;
+                                        for( i = 0; i < fmt.i_extra; i++ )
+                                        {
+                                            msg_Dbg( p_demux, "          data[%d] = 0x%x", i,((uint8_t*)fmt.p_extra)[i] );
+                                        }
+                                    }
+                                }
+                            }
+                            fmt.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
+                        }
 
                         if( fmt.i_codec != 0 )
                         {