]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/switcher.c
stream_out/*: String review (refs #438)
[vlc] / modules / stream_out / switcher.c
index 84b19d6f33e88d153822820f3e9852336742c01c..774f791ad890b1c6a32926c06d0e482708975553 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * switcher.c: MPEG2 video switcher module
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
@@ -18,7 +18,7 @@
  *
  * 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -32,7 +32,8 @@
 #include <vlc/sout.h>
 #include <vlc/vout.h>
 
-#include "network.h"
+#include <charset.h>
+#include <network.h>
 
 #define HAVE_MMX
 #ifdef HAVE_FFMPEG_AVCODEC_H
@@ -48,8 +49,8 @@
 #endif
 
 #define SOUT_CFG_PREFIX "sout-switcher-"
-#define MAX_PICTURES 12
-#define MAX_AUDIO 12
+#define MAX_PICTURES 10
+#define MAX_AUDIO 30
 #define AVCODEC_MAX_VIDEO_FRAME_SIZE (3*1024*1024)
 #define MAX_THRESHOLD 99999999
 
@@ -99,6 +100,9 @@ static block_t *AudioGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
 #define QSCALE_TEXT N_("Quantizer scale")
 #define QSCALE_LONGTEXT N_( \
     "Fixed quantizer scale to use." )
+#define AUDIO_TEXT N_("Mute audio")
+#define AUDIO_LONGTEXT N_( \
+    "Mute audio when command is not 0." )
 
 vlc_module_begin();
     set_description( _("MPEG2 video switcher stream output") );
@@ -120,10 +124,13 @@ vlc_module_begin();
                  GOP_TEXT, GOP_LONGTEXT, VLC_TRUE );
     add_integer( SOUT_CFG_PREFIX "qscale", 5, NULL,
                  QSCALE_TEXT, QSCALE_LONGTEXT, VLC_TRUE );
+    add_bool( SOUT_CFG_PREFIX "mute-audio", 1, NULL,
+              AUDIO_TEXT, AUDIO_LONGTEXT, VLC_TRUE );
 vlc_module_end();
 
 static const char *ppsz_sout_options[] = {
-    "files", "sizes", "aspect-ratio", "port", "command", "gop", "qscale", NULL
+    "files", "sizes", "aspect-ratio", "port", "command", "gop", "qscale",
+    "mute-audio", NULL
 };
 
 struct sout_stream_sys_t
@@ -133,6 +140,7 @@ struct sout_stream_sys_t
     int             i_qscale;
     int             i_aspect;
     sout_stream_id_t *pp_audio_ids[MAX_AUDIO];
+    vlc_bool_t      b_audio;
 
     /* Pictures */
     picture_t       p_pictures[MAX_PICTURES];
@@ -267,6 +275,9 @@ static int Open( vlc_object_t *p_this )
     var_Get( p_stream, SOUT_CFG_PREFIX "qscale", &val );
     p_sys->i_qscale = val.i_int;
 
+    var_Get( p_stream, SOUT_CFG_PREFIX "mute-audio", &val );
+    p_sys->b_audio = val.b_bool;
+
     p_stream->pf_add    = Add;
     p_stream->pf_del    = Del;
     p_stream->pf_send   = Send;
@@ -310,19 +321,20 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         id->b_switcher_video = VLC_TRUE;
         p_fmt->i_codec = VLC_FOURCC('m', 'p', 'g', 'v');
         msg_Dbg( p_stream,
-                 "creating video switcher for fcc=`%4.4s'",
-                 (char*)&p_fmt->i_codec );
+                 "creating video switcher for fcc=`%4.4s' cmd:%d",
+                 (char*)&p_fmt->i_codec, p_sys->i_cmd );
     }
     else if ( p_fmt->i_cat == AUDIO_ES
-               && p_fmt->i_codec == VLC_FOURCC('m', 'p', 'g', 'a') )
+               && p_fmt->i_codec == VLC_FOURCC('m', 'p', 'g', 'a')
+               && p_sys->b_audio )
     {
         int i_ff_codec = CODEC_ID_MP2;
         int i;
 
         id->b_switcher_audio = VLC_TRUE;
         msg_Dbg( p_stream,
-                 "creating audio switcher for fcc=`%4.4s'",
-                 (char*)&p_fmt->i_codec );
+                 "creating audio switcher for fcc=`%4.4s' cmd:%d",
+                 (char*)&p_fmt->i_codec, p_sys->i_cmd );
 
         /* Allocate the encoder right now. */
         if( i_ff_codec == 0 )
@@ -387,7 +399,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         }
         if ( i == MAX_AUDIO )
         {
-            msg_Err( p_stream, "too many audio streams !" );
+            msg_Err( p_stream, "too many audio streams!" );
             free( id );
             return NULL;
         }
@@ -574,7 +586,7 @@ static int UnpackFromFile( sout_stream_t *p_stream, const char *psz_file,
                            picture_t *p_pic )
 {
     int i, j;
-    FILE *p_file = fopen( psz_file, "r" );
+    FILE *p_file = utf8_fopen( psz_file, "r" );
 
     if ( p_file == NULL )
     {
@@ -602,7 +614,7 @@ static int UnpackFromFile( sout_stream_t *p_stream, const char *psz_file,
         uint8_t *p_u = &p_pic->p[1].p_pixels[i/2 * p_pic->p[1].i_pitch];
         uint8_t *p_v = &p_pic->p[2].p_pixels[i/2 * p_pic->p[2].i_pitch];
 
-        if ( fread( p_buffer, 2, i_width, p_file ) != i_width )
+        if ( fread( p_buffer, 2, i_width, p_file ) != (size_t)i_width )
         {
             msg_Err( p_stream, "premature end of file %s", psz_file );
             fclose( p_file );
@@ -652,6 +664,9 @@ static void NetCommand( sout_stream_t *p_stream )
         }
 
         p_sys->i_cmd = i_cmd;
+
+        msg_Dbg( p_stream, "new command: %d old:%d", p_sys->i_cmd,
+                 p_sys->i_old_cmd );
     }
 }
 
@@ -756,6 +771,7 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
                             | CODEC_FLAG_LOW_DELAY;
 
         id->ff_enc_c->mb_decision = FF_MB_DECISION_SIMPLE;
+        id->ff_enc_c->pix_fmt = PIX_FMT_YUV420P;
 
         if( avcodec_open( id->ff_enc_c, id->ff_enc ) )
         {
@@ -877,6 +893,7 @@ static block_t *VideoGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
     p_out->i_length = p_buffer->i_length;
     p_out->i_pts = p_buffer->i_dts;
     p_out->i_dts = p_buffer->i_dts;
+    p_out->i_rate = p_buffer->i_rate;
 
     switch ( id->ff_enc_c->coded_frame->pict_type )
     {
@@ -919,6 +936,7 @@ static block_t *AudioGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
     p_out->i_length = p_buffer->i_length;
     p_out->i_pts = p_buffer->i_dts;
     p_out->i_dts = p_buffer->i_dts;
+    p_out->i_rate = p_buffer->i_rate;
 
     block_Release( p_buffer );