]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/switcher.c
Make Zorglub less unhappy
[vlc] / modules / stream_out / switcher.c
index fd46a9e659640c1acff6551ee9ecf912737c351f..46391110f7e81b9ad46eb64012f14f2edec58065 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>
@@ -84,6 +84,9 @@ static block_t *AudioGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
 #define SIZES_TEXT N_("Sizes")
 #define SIZES_LONGTEXT N_( \
     "List of sizes separated by colons (720x576:480x576)." )
+#define RATIO_TEXT N_("Aspect ratio")
+#define RATIO_LONGTEXT N_( \
+    "Aspect ratio (4:3, 16:9)." )
 #define PORT_TEXT N_("Command UDP port")
 #define PORT_LONGTEXT N_( \
     "UDP port to listen to for commands." )
@@ -95,7 +98,7 @@ static block_t *AudioGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
     "Number of P frames between two I frames." )
 #define QSCALE_TEXT N_("Quantizer scale")
 #define QSCALE_LONGTEXT N_( \
-    "" )
+    "Fixed quantizer scale to use." )
 
 vlc_module_begin();
     set_description( _("MPEG2 video switcher stream output") );
@@ -107,6 +110,8 @@ vlc_module_begin();
                 FILES_LONGTEXT, VLC_FALSE );
     add_string( SOUT_CFG_PREFIX "sizes", "", NULL, SIZES_TEXT,
                 SIZES_LONGTEXT, VLC_FALSE );
+    add_string( SOUT_CFG_PREFIX "aspect-ratio", "4:3", NULL, RATIO_TEXT,
+                RATIO_LONGTEXT, VLC_FALSE );
     add_integer( SOUT_CFG_PREFIX "port", 5001, NULL,
                  PORT_TEXT, PORT_LONGTEXT, VLC_TRUE );
     add_integer( SOUT_CFG_PREFIX "command", 0, NULL,
@@ -118,7 +123,7 @@ vlc_module_begin();
 vlc_module_end();
 
 static const char *ppsz_sout_options[] = {
-    "files", "sizes", "port", "command", "gop", "qscale", NULL
+    "files", "sizes", "aspect-ratio", "port", "command", "gop", "qscale", NULL
 };
 
 struct sout_stream_sys_t
@@ -126,6 +131,7 @@ struct sout_stream_sys_t
     sout_stream_t   *p_out;
     int             i_gop;
     int             i_qscale;
+    int             i_aspect;
     sout_stream_id_t *pp_audio_ids[MAX_AUDIO];
 
     /* Pictures */
@@ -219,6 +225,30 @@ static int Open( vlc_object_t *p_this )
         p_sys->i_nb_pictures++;
     }
 
+    var_Get( p_stream, SOUT_CFG_PREFIX "aspect-ratio", &val );
+    if ( val.psz_string )
+    {
+        char *psz_parser = strchr( val.psz_string, ':' );
+
+        if( psz_parser )
+        {
+            *psz_parser++ = '\0';
+            p_sys->i_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR
+                / atoi( psz_parser );
+        }
+        else
+        {
+            msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
+            p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
+        }
+
+        free( val.psz_string );
+    }
+    else
+    {
+        p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
+    }
+
     var_Get( p_stream, SOUT_CFG_PREFIX "port", &val );
     p_sys->i_fd = net_OpenUDP( p_stream, NULL, val.i_int, NULL, 0 );
     if ( p_sys->i_fd < 0 )
@@ -663,6 +693,8 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
     {
         /* Create a new encoder. */
         int i_ff_codec = CODEC_ID_MPEG2VIDEO;
+        int i_aspect_num, i_aspect_den;
+
         if( i_ff_codec == 0 )
         {
             msg_Err( p_stream, "cannot find encoder" );
@@ -700,9 +732,21 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
 
         id->ff_enc_c->width = p_sys->p_pictures[p_sys->i_cmd-1].format.i_width;
         id->ff_enc_c->height = p_sys->p_pictures[p_sys->i_cmd-1].format.i_height;
-
+        av_reduce( &i_aspect_num, &i_aspect_den,
+                   p_sys->i_aspect,
+                   VOUT_ASPECT_FACTOR, 1 << 30 /* something big */ );
+        av_reduce( &id->ff_enc_c->sample_aspect_ratio.num,
+                   &id->ff_enc_c->sample_aspect_ratio.den,
+                   i_aspect_num * (int64_t)id->ff_enc_c->height,
+                   i_aspect_den * (int64_t)id->ff_enc_c->width, 1 << 30 );
+
+#if LIBAVCODEC_BUILD >= 4754
+        id->ff_enc_c->time_base.num = 1;
+        id->ff_enc_c->time_base.den = 25; /* FIXME */
+#else
         id->ff_enc_c->frame_rate    = 25; /* FIXME */
         id->ff_enc_c->frame_rate_base = 1;
+#endif
 
         id->ff_enc_c->gop_size = 200;
         id->ff_enc_c->max_b_frames = 0;
@@ -712,6 +756,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 ) )
         {
@@ -833,6 +878,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 )
     {
@@ -875,6 +921,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 );