]> git.sesse.net Git - vlc/blobdiff - modules/demux/mpeg/mpga.c
A bit of headers cleanup
[vlc] / modules / demux / mpeg / mpga.c
index e1e3951d6c0a223ea87a94b8781ceb3b0ee6d045..ec5cb291eba88ae1f351ec36892b1aa2591b948f 100644 (file)
@@ -28,9 +28,9 @@
 #include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include "vlc_codec.h"
-#include "vlc_meta.h"
+#include <vlc_demux.h>
+#include <vlc_codec.h>
+#include <vlc_meta.h>
 
 #define MPGA_PACKET_SIZE 1024
 
@@ -157,35 +157,16 @@ static int Open( vlc_object_t * p_this )
         if( !b_ok && !p_demux->b_force ) return VLC_EGENERIC;
     }
 
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    STANDARD_DEMUX_INIT; p_sys = p_demux->p_sys;
     memset( p_sys, 0, sizeof( demux_sys_t ) );
     p_sys->p_es = 0;
-    p_sys->p_packetizer = 0;
     p_sys->b_start = VLC_TRUE;
     p_sys->meta = 0;
-    p_demux->pf_demux   = Demux;
-    p_demux->pf_control = Control;
-
-    /*
-     * Load the mpeg audio packetizer
-     */
-    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_PACKETIZER );
-    p_sys->p_packetizer->pf_decode_audio = NULL;
-    p_sys->p_packetizer->pf_decode_video = NULL;
-    p_sys->p_packetizer->pf_decode_sub = NULL;
-    p_sys->p_packetizer->pf_packetize = NULL;
-    es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES,
-                    VLC_FOURCC( 'm', 'p', 'g', 'a' ) );
-    es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
-    p_sys->p_packetizer->p_module =
-        module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 );
 
-    if( p_sys->p_packetizer->p_module == NULL )
-    {
-        msg_Err( p_demux, "cannot find mpga packetizer" );
-        Close( VLC_OBJECT(p_demux ) );
-        return VLC_EGENERIC;
-    }
+    /* Load the mpeg audio packetizer */
+    INIT_APACKETIZER( p_sys->p_packetizer, 'm', 'p', 'g', 'a' );
+    es_format_Init( &p_sys->p_packetizer->fmt_out, UNKNOWN_ES, 0 );
+    LOAD_PACKETIZER_OR_FAIL( p_sys->p_packetizer, "mpga" );
 
     /* Xing header */
     if( HeaderCheck( header ) )
@@ -281,7 +262,7 @@ static int Open( vlc_object_t * p_this )
     p_sys->p_block_out = p_block_out;
 
     /* Parse possible id3 header */
-    if( ( p_id3 = module_Need( p_demux, "id3", NULL, 0 ) ) )
+    if( ( p_id3 = module_Need( p_demux, "meta reader", NULL, 0 ) ) )
     {
         p_sys->meta = (vlc_meta_t *)p_demux->p_private;
         p_demux->p_private = NULL;
@@ -304,7 +285,9 @@ static int Demux( demux_t *p_demux )
     {
         p_sys->b_start = VLC_FALSE;
         p_block_in = p_sys->p_block_in;
+        p_sys->p_block_in = NULL;
         p_block_out = p_sys->p_block_out;
+        p_sys->p_block_out = NULL;
     }
     else
     {
@@ -354,12 +337,9 @@ static void Close( vlc_object_t * p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
 
+    DESTROY_PACKETIZER( p_sys->p_packetizer );
     if( p_sys->meta ) vlc_meta_Delete( p_sys->meta );
-
-    if( p_sys->p_packetizer && p_sys->p_packetizer->p_module )
-        module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
-    if( p_sys->p_packetizer )
-        vlc_object_destroy( p_sys->p_packetizer );
+    if( p_sys->p_block_out ) block_Release( p_sys->p_block_out );
 
     free( p_sys );
 }
@@ -394,6 +374,22 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             i_ret = demux2_vaControlHelper( p_demux->s, 0, -1,
                                             p_sys->i_bitrate_avg, 1, i_query,
                                             args );
+            /* No bitrate, we can't have it precisely, but we can compute
+             * a raw approximation with time/position */
+            if( i_ret && i_query == DEMUX_GET_LENGTH &&!p_sys->i_bitrate_avg )
+            {
+                float f_pos = (double)( stream_Tell( p_demux->s ) ) /
+                              (double)( stream_Size( p_demux->s ) );
+                /* The first few seconds are guaranteed to be very whacky,
+                 * don't bother trying ... Too bad */
+                if( f_pos < 0.01 ||
+                    (p_sys->i_pts + p_sys->i_time_offset) < 8000000 )
+                    return VLC_EGENERIC;
+
+                pi64 = (int64_t *)va_arg( args, int64_t * );
+                *pi64 = (p_sys->i_pts + p_sys->i_time_offset) / f_pos;
+                return VLC_SUCCESS;
+            }
             if( !i_ret && p_sys->i_bitrate_avg > 0 &&
                 (i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME) )
             {