[vlc-commits] demux: h264: use packetizer frame rate when available

Francois Cartegnie git at videolan.org
Thu Dec 24 01:45:17 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 23 17:43:45 2015 +0100| [d789b8849c9876ebf45eed0012e759b9cf7bcdb0] | committer: Francois Cartegnie

demux: h264: use packetizer frame rate when available

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d789b8849c9876ebf45eed0012e759b9cf7bcdb0
---

 modules/demux/mpeg/h264.c |   47 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/modules/demux/mpeg/h264.c b/modules/demux/mpeg/h264.c
index e103f42..e2ea740 100644
--- a/modules/demux/mpeg/h264.c
+++ b/modules/demux/mpeg/h264.c
@@ -50,7 +50,7 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_DEMUX )
     set_description( N_("H264 video demuxer" ) )
     set_capability( "demux", 0 )
-    add_float( "h264-fps", 25.0, FPS_TEXT, FPS_LONGTEXT, true )
+    add_float( "h264-fps", 0.0, FPS_TEXT, FPS_LONGTEXT, true )
     set_callbacks( Open, Close )
     add_shortcut( "h264" )
 vlc_module_end ()
@@ -109,17 +109,18 @@ static int Open( vlc_object_t * p_this )
     p_demux->pf_control= Control;
     p_demux->p_sys     = p_sys = malloc( sizeof( demux_sys_t ) );
     p_sys->p_es        = NULL;
-    p_sys->frame_rate_num = 25000;
-    p_sys->frame_rate_den = 1000;
+    p_sys->frame_rate_num = 0;
+    p_sys->frame_rate_den = 0;
     float f_fps        = var_CreateGetFloat( p_demux, "h264-fps" );
     if( f_fps )
     {
         if ( f_fps < 0.001f ) f_fps = 0.001f;
         p_sys->frame_rate_den = 1000;
         p_sys->frame_rate_num = 1000 * f_fps;
+        date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den );
     }
-    msg_Dbg( p_demux, "using %.2f fps", (double) p_sys->frame_rate_num / p_sys->frame_rate_den );
-    date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den );
+    else
+        date_Init( &p_sys->dts, 25000, 1000 );
     date_Set( &p_sys->dts, VLC_TS_0 );
 
     /* Load the mpegvideo packetizer */
@@ -161,9 +162,6 @@ static int Demux( demux_t *p_demux)
         return 0;
     }
 
-    p_block_in->i_dts = date_Get( &p_sys->dts );
-    p_block_in->i_pts = VLC_TS_INVALID;
-
     while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
     {
         while( p_block_out )
@@ -172,21 +170,44 @@ static int Demux( demux_t *p_demux)
 
             p_block_out->p_next = NULL;
 
+            p_block_in->i_dts = date_Get( &p_sys->dts );
+            p_block_in->i_pts = VLC_TS_INVALID;
+
             if( p_sys->p_es == NULL )
             {
                 p_sys->p_packetizer->fmt_out.b_packetized = true;
-                p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out);
+                p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_out );
+                if( !p_sys->p_es )
+                    return VLC_DEMUXER_EOF;
             }
 
             /* h264 packetizer does merge multiple NAL into AU, but slice flag persists */
-            if( p_block_out->i_flags & BLOCK_FLAG_TYPE_MASK )
+            bool frame = p_block_out->i_flags & BLOCK_FLAG_TYPE_MASK;
+            es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
+            if( frame )
             {
-                es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
+                if( !p_sys->frame_rate_den )
+                {
+                    /* Use packetizer's one */
+                    if( p_sys->p_packetizer->fmt_out.video.i_frame_rate_base )
+                    {
+                        p_sys->frame_rate_num = p_sys->p_packetizer->fmt_out.video.i_frame_rate;
+                        p_sys->frame_rate_den = p_sys->p_packetizer->fmt_out.video.i_frame_rate_base;
+                    }
+                    else
+                    {
+                        p_sys->frame_rate_num = 25000;
+                        p_sys->frame_rate_den = 1000;
+                    }
+                    date_Init( &p_sys->dts, p_sys->frame_rate_num, p_sys->frame_rate_den );
+                    date_Set( &p_sys->dts, VLC_TS_0 );
+                    msg_Dbg( p_demux, "using %.2f fps", (double) p_sys->frame_rate_num / p_sys->frame_rate_den );
+                }
+
+                es_out_Control( p_demux->out, ES_OUT_SET_PCR, date_Get( &p_sys->dts ) );
                 date_Increment( &p_sys->dts, 1 );
             }
 
-            es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
-
             p_block_out = p_next;
         }
     }



More information about the vlc-commits mailing list