]> git.sesse.net Git - vlc/blobdiff - modules/demux/real.c
* Don't crash if the hdlr in a mov has no name.
[vlc] / modules / demux / real.c
index b1a785a3f245c262d3fbafea887960029d1fe607..2be24cac4ff00333f93a6de9f566621319e68963 100644 (file)
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -59,6 +59,16 @@ typedef struct
     int         i_frame;
     block_t     *p_frame;
 
+    int         i_subpacket_h;
+    int         i_subpacket_size;
+    int         i_coded_frame_size;
+    int         i_frame_size;
+
+    int         i_subpacket;
+    int         i_subpackets;
+    block_t     **p_subpackets;
+    int         i_out_subpacket;
+
 } real_track_t;
 
 struct demux_sys_t
@@ -146,18 +156,20 @@ static void Close( vlc_object_t *p_this )
     {
         real_track_t *tk = p_sys->track[i];
 
-        if( tk->p_frame )
+        if( tk->p_frame ) block_Release( tk->p_frame );
+        es_format_Clean( &tk->fmt );
+
+        while(  tk->i_subpackets-- )
         {
-            block_Release( tk->p_frame );
+            if( tk->p_subpackets[tk->i_subpackets] )
+                block_Release( tk->p_subpackets[tk->i_subpackets] );
+            if( !tk->i_subpackets ) free( tk->p_subpackets );
         }
-        free( tk );
-    }
 
-    if( p_sys->i_track > 0 )
-    {
-        free( p_sys->track );
+        free( tk );
     }
 
+    if( p_sys->i_track > 0 ) free( p_sys->track );
     free( p_sys );
 }
 
@@ -169,10 +181,8 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     uint8_t     header[18];
-    int         i_size;
-    int         i_id;
+    int         i_size, i_id, i_flags, i;
     int64_t     i_pts;
-    int         i;
     real_track_t *tk = NULL;
     vlc_bool_t  b_selected;
 
@@ -204,8 +214,7 @@ static int Demux( demux_t *p_demux )
     i_id   = GetWBE( &header[4] );
     i_pts  = 1000 * GetDWBE( &header[6] );
     i_pts += 1000; /* Avoid 0 pts */
-
-    /* header[11] -> flags 0x02 -> keyframe */
+    i_flags= header[11]; /* flags 0x02 -> keyframe */
 
 #if 0
     msg_Dbg( p_demux, "packet %d size=%d id=%d pts=%u",
@@ -218,10 +227,7 @@ static int Demux( demux_t *p_demux )
 
     for( i = 0; i < p_sys->i_track; i++ )
     {
-        if( p_sys->track[i]->i_id == i_id )
-        {
-            tk = p_sys->track[i];
-        }
+        if( p_sys->track[i]->i_id == i_id ) tk = p_sys->track[i];
     }
 
     if( tk == NULL )
@@ -482,6 +488,71 @@ 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') )
+        {
+            uint8_t *p_buf = p_sys->buffer;
+            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' ) )
+            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 );
+                memcpy( p_block->p_buffer, p_buf, tk->i_subpacket_size );
+                p_buf += tk->i_subpacket_size;
+
+                i_index = tk->i_subpacket_h * i +
+                    ((tk->i_subpacket_h + 1) / 2) * (y&1) + (y>>1);
+
+                p_block->i_dts = p_block->i_pts = i_pts;
+                tk->p_subpackets[i_index] = p_block;
+                tk->i_subpacket++;
+            }
+
+            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);
+                memcpy( p_block->p_buffer, p_buf, tk->i_coded_frame_size );
+                p_buf += tk->i_coded_frame_size;
+
+                i_index = (i * 2 * tk->i_frame_size) /
+                    tk->i_coded_frame_size + y;
+
+                p_block->i_dts = p_block->i_pts = i_pts;
+                tk->p_subpackets[i_index] = p_block;
+                tk->i_subpacket++;
+            }
+
+            while( tk->i_out_subpacket != tk->i_subpackets &&
+                   tk->p_subpackets[tk->i_out_subpacket] )
+            {
+                block_t *p_block = tk->p_subpackets[tk->i_out_subpacket];
+                tk->p_subpackets[tk->i_out_subpacket] = 0;
+
+                if( tk->i_out_subpacket ) p_block->i_dts = p_block->i_pts = 0;
+                es_out_Send( p_demux->out, tk->p_es, p_block );
+
+                tk->i_out_subpacket++;
+            }
+
+            if( tk->i_subpacket == tk->i_subpackets &&
+                tk->i_out_subpacket != tk->i_subpackets )
+            {
+                msg_Warn( p_demux, "i_subpacket != i_out_subpacket, "
+                          "this shouldn't happen" );
+            }
+
+            if( tk->i_subpacket == tk->i_subpackets )
+            {
+                tk->i_subpacket = 0;
+                tk->i_out_subpacket = 0;
+            }
+        }
         else
         {
             block_t *p_block = block_New( p_demux, i_size );
@@ -504,9 +575,7 @@ static int Demux( demux_t *p_demux )
             {
                 memcpy( p_block->p_buffer, p_sys->buffer, i_size );
             }
-            p_block->i_dts =
-            p_block->i_pts = i_pts;
-
+            p_block->i_dts = p_block->i_pts = i_pts;
             es_out_Send( p_demux->out, tk->p_es, p_block );
         }
     }
@@ -816,6 +885,20 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
         {
             fmt.i_codec = VLC_FOURCC( 'R','V','1','3' );
         }
+        else if( GetDWBE( &p_peek[30] ) == 0x20001000 ||
+                 GetDWBE( &p_peek[30] ) == 0x20100001 ||
+                 GetDWBE( &p_peek[30] ) == 0x20200002 )
+        {
+            fmt.i_codec = VLC_FOURCC( 'R','V','2','0' );
+        }
+        else if( GetDWBE( &p_peek[30] ) == 0x30202002 )
+        {
+            fmt.i_codec = VLC_FOURCC( 'R','V','3','0' );
+        }
+        else if( GetDWBE( &p_peek[30] ) == 0x40000000 )
+        {
+            fmt.i_codec = VLC_FOURCC( 'R','V','4','0' );
+        }
 
         msg_Dbg( p_demux, "    - video %4.4s %dx%d",
                  (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );
@@ -907,16 +990,14 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
             break;
 
         case VLC_FOURCC('c','o','o','k'):
-            fmt.i_extra = GetDWBE( p_peek ); p_peek += 4;
-            fmt.p_extra = malloc( fmt.i_extra + 10 );
-
-            ((short*)(fmt.p_extra))[0] = i_subpacket_size;
-            ((short*)(fmt.p_extra))[1] = i_subpacket_h;
-            ((short*)(fmt.p_extra))[2] = i_flavor;
-            ((short*)(fmt.p_extra))[3] = i_coded_frame_size;
-            ((short*)(fmt.p_extra))[4] = fmt.i_extra;
-            if( fmt.i_extra ) memcpy( fmt.p_extra + 10, p_peek, fmt.i_extra );
-            fmt.i_extra += 10;
+            fmt.audio.i_blockalign = i_subpacket_size;
+            if( !(fmt.i_extra = GetDWBE( p_peek )) ) break;
+            fmt.p_extra = malloc( fmt.i_extra );
+            memcpy( fmt.p_extra, p_peek + 4, fmt.i_extra );
+            break;
+
+        case VLC_FOURCC('2','8','_','8'):
+            fmt.audio.i_blockalign = i_coded_frame_size;
             break;
 
         default:
@@ -927,6 +1008,8 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
 
         if( fmt.i_codec != 0 )
         {
+            int i;
+
             msg_Dbg( p_demux, "        - extra data=%d", fmt.i_extra );
 
             tk = malloc( sizeof( real_track_t ) );
@@ -934,6 +1017,33 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
             tk->fmt = fmt;
             tk->i_frame = 0;
             tk->p_frame = NULL;
+
+            tk->i_subpacket_h = i_subpacket_h;
+            tk->i_subpacket_size = i_subpacket_size;
+            tk->i_coded_frame_size = i_coded_frame_size;
+            tk->i_frame_size = i_frame_size;
+
+            tk->i_out_subpacket = 0;
+            tk->i_subpacket = 0;
+            tk->i_subpackets = 0;
+            tk->p_subpackets = NULL;
+            if( fmt.i_codec == VLC_FOURCC('c','o','o','k') )
+            {
+                tk->i_subpackets =
+                    i_subpacket_h * i_frame_size / tk->i_subpacket_size;
+                tk->p_subpackets =
+                    malloc( tk->i_subpackets * sizeof(block_t *) );
+            }
+            else if( fmt.i_codec == VLC_FOURCC('2','8','_','8') )
+            {
+                tk->i_subpackets =
+                    i_subpacket_h * i_frame_size / tk->i_coded_frame_size;
+                tk->p_subpackets =
+                    malloc( tk->i_subpackets * sizeof(block_t *) );
+            }
+
+            for( i = 0; i < tk->i_subpackets; i++ ) tk->p_subpackets[i] = NULL;
+
             tk->p_es = es_out_Add( p_demux->out, &fmt );
 
             TAB_APPEND( p_sys->i_track, p_sys->track, tk );