]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/mpeg4video.c
* modules/gui/wxwidgets/playlist.cpp: Fixed segfault. Patch by Brian Robb (vascy...
[vlc] / modules / packetizer / mpeg4video.c
index ad56ef54936a6694678b67c96bea6ca5e1ae6803..df725ddb0fdd7c07f2d7cfc664223ceb160ef814 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mpeg4video.c: mpeg 4 video packetizer
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
+ * Copyright (C) 2001, 2002 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -31,6 +31,7 @@
 #include <vlc/vlc.h>
 #include <vlc/decoder.h>
 #include <vlc/sout.h>
+#include <vlc/input.h>                  /* hmmm, just for INPUT_RATE_DEFAULT */
 
 #include "vlc_bits.h"
 
@@ -120,6 +121,7 @@ static int Open( vlc_object_t *p_this )
         case VLC_FOURCC( 'm', 'p', '4', 's'):
         case VLC_FOURCC( 'M', 'P', '4', 'S'):
         case VLC_FOURCC( 'm', 'p', '4', 'v'):
+        case VLC_FOURCC( 'M', 'P', '4', 'V'):
         case VLC_FOURCC( 'D', 'I', 'V', 'X'):
         case VLC_FOURCC( 'd', 'i', 'v', 'x'):
         case VLC_FOURCC( 'X', 'V', 'I', 'D'):
@@ -213,7 +215,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 
     if( p_sys->i_buffer > 10*1000000 )
     {
-        msg_Err( p_dec, "mmh reseting context" );
+        msg_Warn( p_dec, "reseting context" );
         p_sys->i_buffer = 0;
     }
 
@@ -235,13 +237,23 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 
         if( p_vol )
         {
-            /* Copy the complete VOL */
-            p_dec->fmt_out.i_extra = p_start - p_vol;
-            p_dec->fmt_out.p_extra =
-                realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );
-            memcpy( p_dec->fmt_out.p_extra, p_vol, p_dec->fmt_out.i_extra );
-            m4v_VOLParse( p_dec, &p_dec->fmt_out,
-                          p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );
+            if( !p_dec->fmt_out.i_extra )
+            {
+                /* Copy the complete VOL */
+                p_dec->fmt_out.i_extra = p_start - p_vol;
+                p_dec->fmt_out.p_extra =
+                    realloc( p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );
+                memcpy( p_dec->fmt_out.p_extra, p_vol,
+                        p_dec->fmt_out.i_extra );
+                m4v_VOLParse( p_dec, &p_dec->fmt_out,
+                              p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );
+            }
+
+            /* Remove VOL from the original stream */
+            memmove( p_vol, p_start,
+                     p_sys->i_buffer - (p_start - p_sys->p_buffer) );
+            p_sys->i_buffer -= p_dec->fmt_out.i_extra;
+            p_start = p_vol;
 
             p_vol = NULL;
         }
@@ -345,10 +357,21 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
                     (i_modulo_time_base * p_dec->p_sys->i_fps_num);
             }
 
-            p_sys->i_interpolated_pts +=
-                ( (i_time_ref + i_time_increment -
-                   p_sys->i_last_time - p_sys->i_last_timeincr) *
-                  I64C(1000000) / p_dec->p_sys->i_fps_num );
+            if( p_dec->p_sys->i_fps_num < 5 && /* Work-around buggy streams */
+                p_dec->fmt_in.video.i_frame_rate > 0 &&
+                p_dec->fmt_in.video.i_frame_rate_base > 0 )
+            {
+                p_sys->i_interpolated_pts += I64C(1000000) *
+                    p_dec->fmt_in.video.i_frame_rate_base *
+                    p_block->i_rate / INPUT_RATE_DEFAULT /
+                    p_dec->fmt_in.video.i_frame_rate;
+            }
+            else if( p_dec->p_sys->i_fps_num )
+                p_sys->i_interpolated_pts +=
+                    ( I64C(1000000) * (i_time_ref + i_time_increment -
+                       p_sys->i_last_time - p_sys->i_last_timeincr) *
+                      p_block->i_rate / INPUT_RATE_DEFAULT /
+                      p_dec->p_sys->i_fps_num );
 
             p_sys->i_last_time = i_time_ref;
             p_sys->i_last_timeincr = i_time_increment;
@@ -367,6 +390,8 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 
                 if( p_block->i_pts > 0 )
                     p_sys->i_interpolated_dts = p_block->i_pts;
+                if( p_block->i_dts > 0 )
+                    p_sys->i_interpolated_dts = p_block->i_dts;
 
                 p_sys->i_interpolated_pts = p_sys->i_interpolated_dts;
             }