]> git.sesse.net Git - vlc/commitdiff
* stream_output.h, transrate.c : do not use SOUT_BUFFER_FLAG_GOP anymore
authorLaurent Aimar <fenrir@videolan.org>
Sat, 22 Nov 2003 17:03:57 +0000 (17:03 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 22 Nov 2003 17:03:57 +0000 (17:03 +0000)
 (may be readded later).

 * mpgv.c: new demuxer using the packetizer (allow to stream ES).

configure.ac
include/stream_output.h
modules/demux/mpeg/Modules.am
modules/demux/mpeg/es.c [deleted file]
modules/demux/mpeg/mpgv.c [new file with mode: 0644]
modules/stream_out/transrate/transrate.c

index a1a79c01a7979aa601f07c49cced44536f6ba1f0..f5683a977b61efe2a3d17294f8c3206fd992df8b 100644 (file)
@@ -1,5 +1,5 @@
 dnl Autoconf settings for vlc
-dnl $Id: configure.ac,v 1.115 2003/11/22 15:53:18 sam Exp $
+dnl $Id: configure.ac,v 1.116 2003/11/22 17:03:57 fenrir Exp $
 
 AC_INIT(vlc,0.6.3-cvs)
 
@@ -866,7 +866,7 @@ dnl
 dnl  default modules
 dnl
 AX_ADD_PLUGINS([dummy rc logger gestures memcpy hotkeys])
-AX_ADD_PLUGINS([es mpga m4v mpeg_system ps ts avi asf aac mp4 rawdv])
+AX_ADD_PLUGINS([mpgv mpga m4v mpeg_system ps ts avi asf aac mp4 rawdv])
 AX_ADD_PLUGINS([spudec mpeg_audio lpcm a52 dts cinepak dvbsub])
 AX_ADD_PLUGINS([deinterlace invert adjust wall transform distort clone crop motionblur])
 AX_ADD_PLUGINS([float32tos16 float32tos8 float32tou16 float32tou8 a52tospdif dtstospdif fixed32tofloat32 fixed32tos16 s16tofixed32 s16tofloat32 s16tofloat32swab s8tofloat32 u8tofixed32 u8tofloat32])
index b79dc1857b8622da60d830458cacb2a78a30506f..471f59d954e37dc6aa9ba80d58e7e2b8510d6382 100644 (file)
@@ -2,7 +2,7 @@
  * stream_output.h : stream output module
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: stream_output.h,v 1.16 2003/11/21 15:32:08 fenrir Exp $
+ * $Id: stream_output.h,v 1.17 2003/11/22 17:03:57 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -39,7 +39,6 @@
  *
  */
 #define SOUT_BUFFER_FLAGS_HEADER    0x0001
-#define SOUT_BUFFER_FLAGS_GOP       0x0002
 
 /*
  * Flags for muxer/access private usage.
index 86d6cbfe0315a794f2304ab79b1960ae0e51c7a9..0218f95bd541661554e9751a68859884b694f082 100644 (file)
@@ -1,30 +1,7 @@
-SOURCES_mpeg_system = \
-       system.c \
-       system.h \
-       $(NULL)
-
-SOURCES_es = \
-       es.c \
-       $(NULL)
-
-SOURCES_m4v = \
-       m4v.c \
-       $(NULL)
-
-
-SOURCES_ps = \
-       ps.c \
-       $(NULL)
-
-SOURCES_ts = \
-       ts.c \
-       $(NULL)
-
-SOURCES_ts_dvbpsi = \
-       ts.c \
-       $(NULL)
-
-SOURCES_mpga = \
-       mpga.c \
-       $(NULL)
-
+SOURCES_mpeg_system = system.c system.h
+SOURCES_m4v = m4v.c
+SOURCES_ps = ps.c
+SOURCES_ts = ts.c
+SOURCES_ts_dvbpsi = ts.c
+SOURCES_mpga = mpga.c
+SOURCES_mpgv = mpgv.c
diff --git a/modules/demux/mpeg/es.c b/modules/demux/mpeg/es.c
deleted file mode 100644 (file)
index 960ccdc..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*****************************************************************************
- * mpeg_es.c : Elementary Stream input module for vlc
- *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: es.c,v 1.5 2003/09/10 11:51:00 fenrir Exp $
- *
- * Authors: Christophe Massiot <massiot@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-
-/*****************************************************************************
- * Constants
- *****************************************************************************/
-#define ES_PACKET_SIZE 65536
-#define MAX_PACKETS_IN_FIFO 3
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int  Activate ( vlc_object_t * );
-static int  Demux ( input_thread_t * );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-vlc_module_begin();
-    set_description( _("ISO 13818-1 MPEG Elementary Stream input") );
-    set_capability( "demux", 150 );
-    set_callbacks( Activate, NULL );
-    add_shortcut( "es" );
-vlc_module_end();
-
-/*
- * Data reading functions
- */
-
-/*****************************************************************************
- * Activate: initializes ES structures
- *****************************************************************************/
-static int Activate( vlc_object_t * p_this )
-{
-    input_thread_t *    p_input = (input_thread_t *)p_this;
-    es_descriptor_t *   p_es;
-    byte_t *            p_peek;
-
-    /* Set the demux function */
-    p_input->pf_demux = Demux;
-    p_input->pf_demux_control = demux_vaControlDefault;
-
-    /* Initialize access plug-in structures. */
-    if( p_input->i_mtu == 0 )
-    {
-        /* Improve speed. */
-        p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
-    }
-
-    /* Have a peep at the show. */
-    if( input_Peek( p_input, &p_peek, 4 ) < 4 )
-    {
-        /* Stream shorter than 4 bytes... */
-        msg_Err( p_input, "cannot peek()" );
-        return( -1 );
-    }
-
-    if( *p_peek || *(p_peek + 1) || *(p_peek + 2) != 1 )
-    {
-        if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "es", 3 ) )
-        {
-            /* User forced */
-            msg_Err( p_input, "this doesn't look like an MPEG ES stream, continuing" );
-        }
-        else
-        {
-            msg_Warn( p_input, "ES module discarded (no startcode)" );
-            return( -1 );
-        }
-    }
-    else if( *(p_peek + 3) > 0xb9 )
-    {
-        if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "es", 3 ) )
-        {
-            /* User forced */
-            msg_Err( p_input, "this seems to be a system stream (PS plug-in ?), but continuing" );
-        }
-        else
-        {
-            msg_Warn( p_input, "ES module discarded (system startcode)" );
-            return( -1 );
-        }
-    }
-
-    if( input_InitStream( p_input, 0 ) == -1 )
-    {
-        return( -1 );
-    }
-    input_AddProgram( p_input, 0, 0 );
-    p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    p_es = input_AddES( p_input, p_input->stream.p_selected_program, 0xE0,
-                        VIDEO_ES, NULL, 0 );
-    p_es->i_stream_id = 0xE0;
-    p_es->i_fourcc = VLC_FOURCC('m','p','g','v');
-    input_SelectES( p_input, p_es );
-    p_input->stream.p_selected_area->i_tell = 0;
-    p_input->stream.p_selected_program->b_is_ok = 1;
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    return( 0 );
-}
-
-/*****************************************************************************
- * Demux: reads and demuxes data packets
- *****************************************************************************
- * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
- *****************************************************************************/
-static int Demux( input_thread_t * p_input )
-{
-    ssize_t         i_read;
-    decoder_fifo_t * p_fifo =
-        p_input->stream.p_selected_program->pp_es[0]->p_decoder_fifo;
-    pes_packet_t *  p_pes;
-    data_packet_t * p_data;
-
-    if( p_fifo == NULL )
-    {
-        return -1;
-    }
-
-    i_read = input_SplitBuffer( p_input, &p_data, ES_PACKET_SIZE );
-
-    if ( i_read <= 0 )
-    {
-        return i_read;
-    }
-
-    p_pes = input_NewPES( p_input->p_method_data );
-
-    if( p_pes == NULL )
-    {
-        msg_Err( p_input, "out of memory" );
-        input_DeletePacket( p_input->p_method_data, p_data );
-        return -1;
-    }
-
-    p_pes->i_rate = p_input->stream.control.i_rate;
-    p_pes->p_first = p_pes->p_last = p_data;
-    p_pes->i_nb_data = 1;
-
-    vlc_mutex_lock( &p_fifo->data_lock );
-
-    if( p_fifo->i_depth >= MAX_PACKETS_IN_FIFO )
-    {
-        /* Wait for the decoder. */
-        vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
-    }
-    vlc_mutex_unlock( &p_fifo->data_lock );
-
-    if( (p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT)
-         | (input_ClockManageControl( p_input, 
-                      p_input->stream.p_selected_program,
-                         (mtime_t)0 ) == PAUSE_S) )
-    {
-        msg_Warn( p_input, "synchro reinit" );
-        p_pes->i_pts = mdate() + DEFAULT_PTS_DELAY;
-        p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK;
-    }
-
-    input_DecodePES( p_fifo, p_pes );
-
-    return 1;
-}
-
diff --git a/modules/demux/mpeg/mpgv.c b/modules/demux/mpeg/mpgv.c
new file mode 100644 (file)
index 0000000..276d1b9
--- /dev/null
@@ -0,0 +1,235 @@
+/*****************************************************************************
+ * mpgv.c : MPEG-I/II Video demuxer
+ *****************************************************************************
+ * Copyright (C) 2001 VideoLAN
+ * $Id: mpgv.c,v 1.1 2003/11/22 17:03:57 fenrir Exp $
+ *
+ * Authors: Laurent Aimar <fenrir@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdlib.h>                                      /* malloc(), free() */
+
+#include <vlc/vlc.h>
+#include <vlc/input.h>
+#include "vlc_codec.h"
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  Open    ( vlc_object_t * );
+static void Close  ( vlc_object_t * );
+
+vlc_module_begin();
+    set_description( _("MPEG-I/II Video demuxer" ) );
+    set_capability( "demux", 100 );
+    set_callbacks( Open, Close );
+    add_shortcut( "mpgv" );
+vlc_module_end();
+
+/* TODO:
+ * - free bitrate
+ */
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Demux       ( input_thread_t * );
+
+struct demux_sys_t
+{
+    vlc_bool_t  b_start;
+
+    es_out_id_t *p_es;
+
+    decoder_t *p_packetizer;
+};
+
+#define MPGV_PACKET_SIZE 4096
+
+/*****************************************************************************
+ * Open: initializes demux structures
+ *****************************************************************************/
+static int Open( vlc_object_t * p_this )
+{
+    input_thread_t *p_input = (input_thread_t *)p_this;
+    demux_sys_t    *p_sys;
+    vlc_bool_t     b_forced = VLC_FALSE;
+
+    uint8_t        *p_peek;
+
+    es_format_t    fmt;
+
+    if( stream_Peek( p_input->s, &p_peek, 4 ) < 4 )
+    {
+        msg_Err( p_input, "cannot peek" );
+        return VLC_EGENERIC;
+    }
+
+    if( p_input->psz_demux && !strncmp( p_input->psz_demux, "mpgv", 4 ) )
+    {
+        b_forced = VLC_TRUE;
+    }
+
+    if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 )
+    {
+        if( !b_forced )
+        {
+            msg_Warn( p_input, "ES module discarded (no startcode)" );
+            return VLC_EGENERIC;
+        }
+
+        msg_Err( p_input, "this doesn't look like an MPEG ES stream, continuing" );
+    }
+
+    if( p_peek[3] > 0xb9 )
+    {
+        if( !b_forced )
+        {
+            msg_Warn( p_input, "ES module discarded (system startcode)" );
+            return VLC_EGENERIC;
+        }
+        msg_Err( p_input, "this seems to be a system stream (PS plug-in ?), but continuing" );
+    }
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    if( input_InitStream( p_input, 0 ) == -1)
+    {
+        vlc_mutex_unlock( &p_input->stream.stream_lock );
+        msg_Err( p_input, "cannot init stream" );
+        return VLC_EGENERIC;
+    }
+    p_input->stream.i_mux_rate = 0 / 50;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    p_input->pf_demux  = Demux;
+    p_input->pf_rewind = NULL;
+    p_input->pf_demux_control = demux_vaControlDefault;
+
+    p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
+    p_sys->b_start = VLC_TRUE;
+    p_sys->p_es    = NULL;
+
+    /*
+     * Load the mpegvideo packetizer
+     */
+    p_sys->p_packetizer = vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
+    p_sys->p_packetizer->pf_decode = NULL;
+    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;
+    p_sys->p_packetizer->pf_run = NULL;
+    es_format_Init( &p_sys->p_packetizer->fmt_in,  VIDEO_ES,   VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
+    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 );
+
+    if( p_sys->p_packetizer->p_module == NULL)
+    {
+        vlc_object_destroy( p_sys->p_packetizer );
+        msg_Err( p_input, "cannot find mpgv packetizer" );
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
+
+    /*
+     * create the output
+     */
+    es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC( 'm', 'p', 'g', 'v' ) );
+    p_sys->p_es = es_out_Add( p_input->p_es_out, &fmt );
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close: frees unused data
+ *****************************************************************************/
+static void Close( vlc_object_t * p_this )
+{
+    input_thread_t *p_input = (input_thread_t*)p_this;
+    demux_sys_t    *p_sys = p_input->p_demux_data;
+
+    module_Unneed( p_sys->p_packetizer, p_sys->p_packetizer->p_module );
+    vlc_object_destroy( p_sys->p_packetizer );
+
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Demux: reads and demuxes data packets
+ *****************************************************************************
+ * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
+ *****************************************************************************/
+static int Demux( input_thread_t * p_input )
+{
+    demux_sys_t  *p_sys = p_input->p_demux_data;
+    block_t *p_block_in, *p_block_out;
+
+    if( ( p_block_in = stream_Block( p_input->s, MPGV_PACKET_SIZE ) ) == NULL )
+    {
+        return 0;
+    }
+
+    if( p_sys->b_start )
+    {
+        p_block_in->i_pts =
+        p_block_in->i_dts = 1;
+    }
+    else
+    {
+        p_block_in->i_pts =
+        p_block_in->i_dts = 0;
+    }
+
+    while( (p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in )) )
+    {
+        p_sys->b_start = VLC_FALSE;
+
+        while( p_block_out )
+        {
+            block_t *p_next = p_block_out->p_next;
+
+            input_ClockManageRef( p_input,
+                                  p_input->stream.p_selected_program,
+                                  p_block_out->i_dts * 9 / 100 );
+
+            p_block_out->i_dts =
+                input_ClockGetTS( p_input, p_input->stream.p_selected_program,
+                                  p_block_out->i_dts * 9 / 100 );
+            if( p_block_out->i_pts > 0 )
+            {
+                p_block_out->i_pts =
+                    input_ClockGetTS( p_input, p_input->stream.p_selected_program,
+                                      p_block_out->i_pts * 9 / 100 );
+            }
+            else
+            {
+                p_block_out->i_pts = 0;
+            }
+
+            p_block_out->p_next = NULL;
+            es_out_Send( p_input->p_es_out, p_sys->p_es, p_block_out );
+
+            p_block_out = p_next;
+        }
+    }
+    return 1;
+}
+
index 1121ca471a4580524332b6ff6e6dfecb5eeabaf0..dea41fc20b65736481ea840aa2373668d410af2d 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (C) 2003 Antoine Missout
  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- * $Id: transrate.c,v 1.3 2003/11/21 15:32:08 fenrir Exp $
+ * $Id: transrate.c,v 1.4 2003/11/22 17:03:57 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -1957,12 +1957,37 @@ static void process_frame( sout_stream_t *p_stream,
 static int transrate_video_process( sout_stream_t *p_stream,
                sout_stream_id_t *id, sout_buffer_t *in, sout_buffer_t **out )
 {
-    transrate_t *tr = &id->tr;
+    transrate_t    *tr = &id->tr;
     bs_transrate_t *bs = &tr->bs;
+    vlc_bool_t     b_gop = VLC_FALSE;
 
     *out = NULL;
 
-    if ( in->i_flags & SOUT_BUFFER_FLAGS_GOP )
+    if( GetDWBE( in->p_buffer ) != 0x100 )
+    {
+        uint8_t *p = in->p_buffer;
+        uint8_t *p_end = &in->p_buffer[in->i_buffer];
+        uint32_t code = GetDWBE( p );
+
+        /* We may have a GOP */
+        while( p < p_end - 4 )
+        {
+            if( code == 0x1b8 )
+            {
+                b_gop = VLC_TRUE;
+                break;
+            }
+            else if( code == 0x100 )
+            {
+                break;
+            }
+            code = ( code << 8 )|p[4];
+            p++;
+        }
+    }
+
+
+    if( b_gop )
     {
         while ( id->p_current_buffer != NULL )
         {