]> git.sesse.net Git - vlc/blobdiff - modules/mux/mpeg/ps.c
Revert "MKV: Always set an i_pts in a lace otherwise it disturbs seeking performance"
[vlc] / modules / mux / mpeg / ps.c
index 724da3c7bd56e848d7cb7f862df0158621d2b546..41d040078f573f0a8825e4fba5d68cd78d980e83 100644 (file)
@@ -2,26 +2,26 @@
  * ps.c: MPEG PS (ISO/IEC 13818-1) / MPEG SYSTEM (ISO/IEC 1172-1)
  *       multiplexer module for vlc
  *****************************************************************************
- * Copyright (C) 2001, 2002 the VideoLAN team
+ * Copyright (C) 2001, 2002 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
  *          Gildas Bazin <gbazin@videolan.org>
  *
- * 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
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -35,7 +35,6 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_sout.h>
-#include <vlc_codecs.h>
 #include <vlc_block.h>
 
 #include "bits.h"
@@ -67,14 +66,12 @@ vlc_module_begin ()
     set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_MUX )
     set_capability( "sout mux", 50 )
-    add_shortcut( "ps" )
-    add_shortcut( "mpeg1" )
-    add_shortcut( "dvd" )
+    add_shortcut( "ps", "mpeg1", "dvd" )
     set_callbacks( Open, Close )
 
-    add_integer( SOUT_CFG_PREFIX "dts-delay", 200, NULL, DTS_TEXT,
+    add_integer( SOUT_CFG_PREFIX "dts-delay", 200, DTS_TEXT,
                  DTS_LONGTEXT, true )
-    add_integer( SOUT_CFG_PREFIX "pes-max-size", PES_PAYLOAD_SIZE_MAX, NULL,
+    add_integer( SOUT_CFG_PREFIX "pes-max-size", PES_PAYLOAD_SIZE_MAX,
                  PES_SIZE_TEXT, PES_SIZE_LONGTEXT, true )
 vlc_module_end ()
 
@@ -83,13 +80,12 @@ vlc_module_end ()
  *****************************************************************************/
 static int Control  ( sout_mux_t *, int, va_list );
 static int AddStream( sout_mux_t *, sout_input_t * );
-static int DelStream( sout_mux_t *, sout_input_t * );
+static void DelStream( sout_mux_t *, sout_input_t * );
 static int Mux      ( sout_mux_t * );
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  MuxGetStream        ( sout_mux_t *, int *, mtime_t * );
 
 static void MuxWritePackHeader  ( sout_mux_t *, block_t **, mtime_t );
 static void MuxWriteSystemHeader( sout_mux_t *, block_t **, mtime_t );
@@ -218,7 +214,7 @@ static void Close( vlc_object_t * p_this )
 
     msg_Info( p_mux, "Close" );
 
-    p_end = block_New( p_mux, 4 );
+    p_end = block_Alloc( 4 );
     p_end->p_buffer[0] = 0x00; p_end->p_buffer[1] = 0x00;
     p_end->p_buffer[2] = 0x01; p_end->p_buffer[3] = 0xb9;
 
@@ -276,13 +272,9 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     /* Init this new stream */
     switch( p_input->p_fmt->i_codec )
     {
-        case VLC_CODEC_MP1V:
-            p_stream->i_stream_id =
-                StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef );
-            p_stream->i_stream_type = 0x01; /* ISO/IEC 11172 Video */
-            break;
-        case VLC_CODEC_MP2V:
         case VLC_CODEC_MPGV:
+        case VLC_CODEC_MP2V:
+        case VLC_CODEC_MP1V:
             p_stream->i_stream_id =
                 StreamIdGet( p_sys->stream_id_mpgv, 0xe0, 0xef );
             p_stream->i_stream_type = 0x02; /* ISO/IEC 13818 Video */
@@ -391,7 +383,7 @@ error:
 /*****************************************************************************
  * DelStream:
  *****************************************************************************/
-static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
+static void DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
 {
     sout_mux_sys_t *p_sys = p_mux->p_sys;
     ps_stream_t *p_stream =(ps_stream_t*)p_input->p_sys;
@@ -445,7 +437,6 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
     p_sys->i_psm_version++;
 
     free( p_stream );
-    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -463,10 +454,10 @@ static int Mux( sout_mux_t *p_mux )
         block_t *p_ps, *p_data;
 
         mtime_t        i_dts;
-        int            i_stream;
 
         /* Choose which stream to mux */
-        if( MuxGetStream( p_mux, &i_stream, &i_dts ) )
+        int i_stream = sout_MuxGetStream( p_mux, 1, &i_dts );
+        if( i_stream < 0 )
         {
             return VLC_SUCCESS;
         }
@@ -521,9 +512,8 @@ static int Mux( sout_mux_t *p_mux )
 
         /* Get and mux a packet */
         p_data = block_FifoGet( p_input->p_fifo );
-         EStoPES ( p_mux->p_sout, &p_data, p_data,
-                       p_input->p_fmt, p_stream->i_stream_id,
-                       p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size );
+        EStoPES ( &p_data, p_input->p_fmt, p_stream->i_stream_id,
+                       p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size, 0 );
 
         block_ChainAppend( &p_ps, p_data );
 
@@ -585,7 +575,7 @@ static void MuxWritePackHeader( sout_mux_t *p_mux, block_t **p_buf,
 
     i_scr = (i_dts - p_sys->i_dts_delay) * 9 / 100;
 
-    p_hdr = block_New( p_mux, 18 );
+    p_hdr = block_Alloc( 18 );
     p_hdr->i_pts = p_hdr->i_dts = i_dts;
     bits_initwrite( &bits, 14, p_hdr->p_buffer );
     bits_write( &bits, 32, 0x01ba );
@@ -659,7 +649,7 @@ static void MuxWriteSystemHeader( sout_mux_t *p_mux, block_t **p_buf,
     i_nb_stream = p_mux->i_nb_inputs -
         ( i_nb_private > 0 ? i_nb_private - 1 : 0 );
 
-    p_hdr = block_New( p_mux, 12 + i_nb_stream * 3 );
+    p_hdr = block_Alloc(  12 + i_nb_stream * 3 );
     p_hdr->i_dts = p_hdr->i_pts = i_dts;
 
     /* The spec specifies that the reported rate_bound must be upper limit */
@@ -749,7 +739,7 @@ static void MuxWritePSM( sout_mux_t *p_mux, block_t **p_buf, mtime_t i_dts )
 
     i_psm_size += i_es_map_size;
 
-    p_hdr = block_New( p_mux, i_psm_size );
+    p_hdr = block_Alloc( i_psm_size );
     p_hdr->i_dts = p_hdr->i_pts = i_dts;
 
     memset( p_hdr->p_buffer, 0, p_hdr->i_buffer );
@@ -805,43 +795,3 @@ static void MuxWritePSM( sout_mux_t *p_mux, block_t **p_buf, mtime_t i_dts )
 
     block_ChainAppend( p_buf, p_hdr );
 }
-
-/*
- * Find stream to be muxed.
- */
-static int MuxGetStream( sout_mux_t *p_mux, int *pi_stream, mtime_t *pi_dts )
-{
-    mtime_t i_dts;
-    int     i_stream, i;
-
-    for( i = 0, i_dts = 0, i_stream = -1; i < p_mux->i_nb_inputs; i++ )
-    {
-        sout_input_t *p_input = p_mux->pp_inputs[i];
-        block_t *p_data;
-
-        if( block_FifoCount( p_input->p_fifo ) <= 0 )
-        {
-            if( p_input->p_fmt->i_cat == AUDIO_ES ||
-                p_input->p_fmt->i_cat == VIDEO_ES )
-            {
-                /* We need that audio+video fifo contain at least 1 packet */
-                return VLC_EGENERIC;
-            }
-
-            /* SPU */
-            continue;
-        }
-
-        p_data = block_FifoShow( p_input->p_fifo );
-        if( i_stream == -1 || p_data->i_dts < i_dts )
-        {
-            i_stream = i;
-            i_dts    = p_data->i_dts;
-        }
-    }
-
-    *pi_stream = i_stream;
-    *pi_dts = i_dts;
-
-    return VLC_SUCCESS;
-}