]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/switcher.c
Make Zorglub less unhappy
[vlc] / modules / stream_out / switcher.c
index 0832008b72c8ae9b7aba1d334f5257fe01e178b1..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>
@@ -131,7 +131,7 @@ struct sout_stream_sys_t
     sout_stream_t   *p_out;
     int             i_gop;
     int             i_qscale;
-    AVRational      sample_aspect_ratio;
+    int             i_aspect;
     sout_stream_id_t *pp_audio_ids[MAX_AUDIO];
 
     /* Pictures */
@@ -233,22 +233,20 @@ static int Open( vlc_object_t *p_this )
         if( psz_parser )
         {
             *psz_parser++ = '\0';
-            p_sys->sample_aspect_ratio.num = atoi( val.psz_string );
-            p_sys->sample_aspect_ratio.den = atoi( psz_parser );
+            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->sample_aspect_ratio.num = 4;
-            p_sys->sample_aspect_ratio.den = 3;
+            p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
         }
 
         free( val.psz_string );
     }
     else
     {
-        p_sys->sample_aspect_ratio.num = 4;
-        p_sys->sample_aspect_ratio.den = 3;
+        p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
     }
 
     var_Get( p_stream, SOUT_CFG_PREFIX "port", &val );
@@ -695,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" );
@@ -732,11 +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;
-        memcpy( &id->ff_enc_c->sample_aspect_ratio, &p_sys->sample_aspect_ratio,
-                sizeof(AVRational) );
+#endif
 
         id->ff_enc_c->gop_size = 200;
         id->ff_enc_c->max_b_frames = 0;
@@ -746,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 ) )
         {
@@ -867,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 )
     {
@@ -909,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 );