]> git.sesse.net Git - vlc/commitdiff
mpga.c: check/hack to make duration available after preparse
authorSigmund Augdal Helberg <sigmunau@videolan.org>
Sun, 12 Dec 2004 00:04:04 +0000 (00:04 +0000)
committerSigmund Augdal Helberg <sigmunau@videolan.org>
Sun, 12 Dec 2004 00:04:04 +0000 (00:04 +0000)
modules/demux/mpeg/mpga.c

index 2499eff5b4ca080d2af8c9b4feb18a96acc0c9f2..d0448e77515dd7b6425a1f35e7404c3c1e9e6bd2 100644 (file)
@@ -72,6 +72,7 @@ struct demux_sys_t
     int i_xing_bytes;
     int i_xing_bitrate_avg;
     int i_xing_frame_samples;
+    block_t *p_block_in, *p_block_out;
 };
 
 static int HeaderCheck( uint32_t h )
@@ -114,12 +115,13 @@ static int Open( vlc_object_t * p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
-    vlc_bool_t  b_forced = VLC_FALSE;
+    vlc_bool_t   b_forced = VLC_FALSE;
 
     uint32_t     header;
     uint8_t     *p_peek;
     module_t    *p_id3;
     vlc_meta_t  *p_meta = NULL;
+    block_t     *p_block_in, *p_block_out;
 
     if( p_demux->psz_path )
     {
@@ -266,6 +268,30 @@ static int Open( vlc_object_t * p_this )
         }
     }
 
+    if( ( p_block_in = stream_Block( p_demux->s, MPGA_PACKET_SIZE ) ) == NULL )
+    {
+        return VLC_EGENERIC;
+    }
+    p_block_in->i_pts = p_block_in->i_dts = 1;
+    p_block_out = p_sys->p_packetizer->pf_packetize(
+        p_sys->p_packetizer, &p_block_in );
+    
+    p_sys->p_packetizer->fmt_out.b_packetized = VLC_TRUE;
+    p_sys->p_es = es_out_Add( p_demux->out,
+                              &p_sys->p_packetizer->fmt_out);
+    p_sys->i_bitrate_avg = p_sys->p_packetizer->fmt_out.i_bitrate;
+    
+    if( p_sys->i_xing_bytes && p_sys->i_xing_frames &&
+        p_sys->i_xing_frame_samples )
+    {
+        p_sys->i_bitrate_avg = p_sys->i_xing_bytes * I64C(8) *
+            p_sys->p_packetizer->fmt_out.audio.i_rate /
+            p_sys->i_xing_frames / p_sys->i_xing_frame_samples;
+    }
+
+    p_sys->p_block_in = p_block_in;
+    p_sys->p_block_out = p_block_out;
+
     return VLC_SUCCESS;
 }
 
@@ -278,39 +304,31 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     block_t *p_block_in, *p_block_out;
-
-    if( ( p_block_in = stream_Block( p_demux->s, MPGA_PACKET_SIZE ) ) == NULL )
+    if( p_sys->b_start )
     {
-        return 0;
+        p_sys->b_start = VLC_FALSE;
+        p_block_in = p_sys->p_block_in;
+        p_block_out = p_sys->p_block_out;
+    }
+    else
+    {
+        if( ( p_block_in = stream_Block( p_demux->s, MPGA_PACKET_SIZE ) )
+            == NULL )
+        {
+            return 0;
+        }
+        p_block_in->i_pts = p_block_in->i_dts = 0;
+        p_block_out = p_sys->p_packetizer->pf_packetize(
+            p_sys->p_packetizer, &p_block_in );
     }
 
-    p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start ? 1 : 0;
-    p_sys->b_start = VLC_FALSE;
 
-    while( (p_block_out = p_sys->p_packetizer->pf_packetize(
-                                          p_sys->p_packetizer, &p_block_in )) )
+    while( p_block_out )
     {
         while( p_block_out )
         {
             block_t *p_next = p_block_out->p_next;
 
-            if( p_sys->p_es == NULL )
-            {
-                p_sys->p_packetizer->fmt_out.b_packetized = VLC_TRUE;
-                p_sys->p_es = es_out_Add( p_demux->out,
-                                          &p_sys->p_packetizer->fmt_out);
-
-                p_sys->i_bitrate_avg = p_sys->p_packetizer->fmt_out.i_bitrate;
-
-                if( p_sys->i_xing_bytes && p_sys->i_xing_frames &&
-                    p_sys->i_xing_frame_samples )
-                {
-                    p_sys->i_bitrate_avg = p_sys->i_xing_bytes * I64C(8) *
-                        p_sys->p_packetizer->fmt_out.audio.i_rate /
-                        p_sys->i_xing_frames / p_sys->i_xing_frame_samples;
-                }
-            }
-
             es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
 
             p_block_out->p_next = NULL;
@@ -319,6 +337,8 @@ static int Demux( demux_t *p_demux )
 
             p_block_out = p_next;
         }
+        p_block_out = p_sys->p_packetizer->pf_packetize(
+            p_sys->p_packetizer, &p_block_in );
     }
     return 1;
 }