]> git.sesse.net Git - vlc/blobdiff - modules/mux/mpeg/ts.c
* modules/stream_out/transcode.c: new options
[vlc] / modules / mux / mpeg / ts.c
index a584b3891a0700e4fa9a77ec3066f3275d86cb7a..1a3fb6c6a5e7a81e5a8f4941f299038b5a864009 100644 (file)
@@ -2,7 +2,7 @@
  * ts.c: MPEG-II TS Muxer
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: ts.c,v 1.36 2003/11/20 18:26:44 fenrir Exp $
+ * $Id: ts.c,v 1.41 2003/11/27 22:44:50 massiot Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
@@ -185,9 +185,6 @@ struct sout_mux_sys_t
     int             i_pcr_pid;
     sout_input_t    *p_pcr_input;
 
-    int             i_stream_id_mpga;
-    int             i_stream_id_mpgv;
-
     int             i_audio_bound;
     int             i_video_bound;
 
@@ -269,9 +266,6 @@ static int Open( vlc_object_t *p_this )
 
     srand( (uint32_t)mdate() );
 
-    p_sys->i_stream_id_mpga = 0xc0;
-    p_sys->i_stream_id_mpgv = 0xe0;
-
     p_sys->i_audio_bound = 0;
     p_sys->i_video_bound = 0;
 
@@ -411,8 +405,6 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     sout_mux_sys_t      *p_sys = p_mux->p_sys;
     ts_stream_t         *p_stream;
 
-    msg_Dbg( p_mux, "adding input codec=%4.4s", (char*)&p_input->p_fmt->i_fourcc );
-
     p_input->p_sys = (void*)p_stream = malloc( sizeof( ts_stream_t ) );
 
     /* Init this new stream */
@@ -421,17 +413,18 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     p_stream->i_decoder_specific_info = 0;
     p_stream->p_decoder_specific_info = NULL;
 
+    msg_Dbg( p_mux, "adding input codec=%4.4s pid=%d", (char*)&p_input->p_fmt->i_codec, p_stream->i_pid );
+
     /* All others fields depand on codec */
     switch( p_input->p_fmt->i_cat )
     {
         case VIDEO_ES:
-            switch( p_input->p_fmt->i_fourcc )
+            switch( p_input->p_fmt->i_codec )
             {
                 case VLC_FOURCC( 'm', 'p','g', 'v' ):
                     /* TODO: do we need to check MPEG-I/II ? */
                     p_stream->i_stream_type = 0x02;
-                    p_stream->i_stream_id = p_sys->i_stream_id_mpgv;
-                    p_sys->i_stream_id_mpgv++;
+                    p_stream->i_stream_id = 0xe0;
                     break;
                 case VLC_FOURCC( 'm', 'p','4', 'v' ):
                     p_stream->i_stream_type = 0x10;
@@ -451,9 +444,9 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                 case VLC_FOURCC( 'M', 'J', 'P', 'G' ):
                     p_stream->i_stream_type = 0xa0; // private
                     p_stream->i_stream_id = 0xa0;   // beurk
-                    p_stream->i_bih_codec  = p_input->p_fmt->i_fourcc;
-                    p_stream->i_bih_width  = p_input->p_fmt->i_width;
-                    p_stream->i_bih_height = p_input->p_fmt->i_height;
+                    p_stream->i_bih_codec  = p_input->p_fmt->i_codec;
+                    p_stream->i_bih_width  = p_input->p_fmt->video.i_width;
+                    p_stream->i_bih_height = p_input->p_fmt->video.i_height;
                     break;
                 default:
                     free( p_stream );
@@ -463,17 +456,25 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
             break;
 
         case AUDIO_ES:
-            switch( p_input->p_fmt->i_fourcc )
+            switch( p_input->p_fmt->i_codec )
             {
                 case VLC_FOURCC( 'm', 'p','g', 'a' ):
-                    p_stream->i_stream_type = p_input->p_fmt->i_sample_rate >= 32000 ? 0x03 : 0x04;
-                    p_stream->i_stream_id = p_sys->i_stream_id_mpga;
-                    p_sys->i_stream_id_mpga++;
+                    p_stream->i_stream_type = p_input->p_fmt->audio.i_rate >= 32000 ? 0x03 : 0x04;
+                    p_stream->i_stream_id = 0xc0;
                     break;
                 case VLC_FOURCC( 'a', '5','2', ' ' ):
                     p_stream->i_stream_type = 0x81;
                     p_stream->i_stream_id = 0xbd;
                     break;
+                case VLC_FOURCC( 'l', 'p','c', 'm' ):
+                    p_stream->i_stream_type = 0x83;
+                    p_stream->i_stream_id = 0xbd;
+                    break;
+                case VLC_FOURCC( 'd', 't','s', ' ' ):
+                    p_stream->i_stream_type = 0x85;
+                    p_stream->i_stream_id = 0xbd;
+                    break;
+
                 case VLC_FOURCC( 'm', 'p','4', 'a' ):
                     p_stream->i_stream_type = 0x11;
                     p_stream->i_stream_id = 0xfa;
@@ -488,11 +489,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
             break;
 
         case SPU_ES:
-            switch( p_input->p_fmt->i_fourcc )
+            switch( p_input->p_fmt->i_codec )
             {
                 case VLC_FOURCC( 's', 'p','u', ' ' ):
                     p_stream->i_stream_type = 0x82;
-                    p_stream->i_stream_id = 0x82;
+                    p_stream->i_stream_id = 0xbd;
                     break;
                 default:
                     free( p_stream );
@@ -506,14 +507,14 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     }
 
     /* Copy extra data (VOL for MPEG-4 and extra BitMapInfoHeader for VFW */
-    p_stream->i_decoder_specific_info = p_input->p_fmt->i_extra_data;
+    p_stream->i_decoder_specific_info = p_input->p_fmt->i_extra;
     if( p_stream->i_decoder_specific_info > 0 )
     {
         p_stream->p_decoder_specific_info =
             malloc( p_stream->i_decoder_specific_info );
         memcpy( p_stream->p_decoder_specific_info,
-                p_input->p_fmt->p_extra_data,
-                p_input->p_fmt->i_extra_data );
+                p_input->p_fmt->p_extra,
+                p_input->p_fmt->i_extra );
     }
 
     /* Init pes chain */
@@ -536,6 +537,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
         }
         p_sys->i_pcr_pid   = p_stream->i_pid;
         p_sys->p_pcr_input = p_input;
+
+        msg_Dbg( p_mux, "new PCR PID is %d", p_sys->i_pcr_pid );
     }
 
     return VLC_SUCCESS;
@@ -550,8 +553,8 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
     ts_stream_t     *p_stream;
     char            *val;
 
-    msg_Dbg( p_mux, "removing input" );
     p_stream = (ts_stream_t*)p_input->p_sys;
+    msg_Dbg( p_mux, "removing input pid=%d", p_stream->i_pid );
 
     if( p_sys->i_pcr_pid == p_stream->i_pid )
     {
@@ -587,6 +590,7 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
             /* Empty TS buffer */
             /* FIXME */
         }
+        msg_Dbg( p_mux, "new PCR PID is %d", p_sys->i_pcr_pid );
     }
 
     /* Empty all data in chain_pes */
@@ -606,6 +610,7 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
         if ( i_pid_video == p_stream->i_pid )
         {
             p_sys->i_pid_video = i_pid_video;
+            msg_Dbg( p_mux, "freeing video PID %d", i_pid_video );
         }
     }
     if( ( val = sout_cfg_find_value( p_mux->p_cfg, "pid-audio" ) ) )
@@ -614,6 +619,7 @@ static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input )
         if ( i_pid_audio == p_stream->i_pid )
         {
             p_sys->i_pid_audio = i_pid_audio;
+            msg_Dbg( p_mux, "freeing audio PID %d", i_pid_audio );
         }
     }
     free( p_stream );
@@ -664,7 +670,7 @@ static int Mux( sout_mux_t *p_mux )
                 sout_input_t *p_input = p_mux->pp_inputs[i];
                 ts_stream_t *p_stream = (ts_stream_t*)p_input->p_sys;
 
-                if( p_stream->i_pes_length <= p_sys->i_caching_delay ||
+                if( ( p_stream == p_pcr_stream && p_stream->i_pes_length <= p_sys->i_caching_delay ) ||
                     p_stream->i_pes_dts + p_stream->i_pes_length < p_pcr_stream->i_pes_dts + p_pcr_stream->i_pes_length )
                 {
                     /* Need more data */
@@ -685,6 +691,12 @@ static int Mux( sout_mux_t *p_mux )
                     b_ok = VLC_FALSE;
 
                     p_data = sout_FifoGet( p_input->p_fifo );
+                    if( p_input->p_fifo->i_depth > 0 )
+                    {
+                        sout_buffer_t *p_next = sout_FifoShow( p_input->p_fifo );
+
+                        p_data->i_length = p_next->i_dts - p_data->i_dts;
+                    }
 
                     if( ( p_pcr_stream->i_pes_dts > 0 && p_data->i_dts - 2000000 > p_pcr_stream->i_pes_dts + p_pcr_stream->i_pes_length ) ||
                         p_data->i_dts < p_stream->i_pes_dts ||