]> git.sesse.net Git - vlc/blobdiff - modules/codec/avcodec/encoder.c
aout_buffer_t.start_data -> aout_buffer_t.i_pts
[vlc] / modules / codec / avcodec / encoder.c
index 389475573aa26be5061df50b2549d56e3fed5405..42c1e9dec4debbf36c5ba1e0e27bc310418eb41d 100644 (file)
 #endif
 
 #include <vlc_common.h>
-#include <vlc_vout.h>
 #include <vlc_aout.h>
 #include <vlc_sout.h>
 #include <vlc_codec.h>
 #include <vlc_dialog.h>
 #include <vlc_avcodec.h>
+#include <vlc_cpu.h>
 
 /* ffmpeg header */
 #define HAVE_MMX 1
@@ -142,9 +142,7 @@ struct encoder_sys_t
     int        i_quality; /* for VBR */
     float      f_lumi_masking, f_dark_masking, f_p_masking, f_border_masking;
     int        i_luma_elim, i_chroma_elim;
-#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(40<<8)+4)
     int        i_aac_profile; /* AAC profile to use.*/
-#endif
     /* Used to work around stupid timestamping behaviour in libavcodec */
     uint64_t i_framenum;
     mtime_t  pi_delay_pts[MAX_FRAME_DELAY];
@@ -157,9 +155,7 @@ static const char *const ppsz_enc_options[] = {
     "trellis", "qscale", "strict", "lumi-masking", "dark-masking",
     "p-masking", "border-masking", "luma-elim-threshold",
     "chroma-elim-threshold",
-#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(40<<8)+4)
      "aac-profile",
-#endif
      NULL
 };
 
@@ -201,7 +197,7 @@ static const uint16_t mpeg4_default_non_intra_matrix[64] = {
 int OpenEncoder( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t *)p_this;
-    encoder_sys_t *p_sys = p_enc->p_sys;
+    encoder_sys_t *p_sys;
     AVCodecContext *p_context;
     AVCodec *p_codec;
     int i_codec_id, i_cat;
@@ -237,6 +233,12 @@ int OpenEncoder( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+    if( p_enc->fmt_out.i_cat == SPU_ES )
+    {
+        /* We don't support subtitle encoding */
+        return VLC_EGENERIC;
+    }
+
     /* Initialization must be done before avcodec_find_encoder() */
     InitLibavcodec( p_this );
 
@@ -388,7 +390,6 @@ int OpenEncoder( vlc_object_t *p_this )
     var_Get( p_enc, ENC_CFG_PREFIX "chroma-elim-threshold", &val );
     p_sys->i_chroma_elim = val.i_int;
 
-#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(40<<8)+4)
     var_Get( p_enc, ENC_CFG_PREFIX "aac-profile", &val );
     /* ffmpeg uses faac encoder atm, and it has issues with
      * other than low-complexity profile, so default to that */
@@ -412,7 +413,6 @@ int OpenEncoder( vlc_object_t *p_this )
         }
     }
     free( val.psz_string );
-#endif
 
     if( p_enc->fmt_in.i_cat == VIDEO_ES )
     {
@@ -453,7 +453,8 @@ int OpenEncoder( vlc_object_t *p_this )
             __MAX( __MIN( p_sys->i_b_frames, FF_MAX_B_FRAMES ), 0 );
         p_context->b_frame_strategy = 0;
         if( !p_context->max_b_frames  &&
-            (  p_enc->fmt_out.i_codec == VLC_CODEC_MP2V ||
+            (  p_enc->fmt_out.i_codec == VLC_CODEC_MPGV ||
+               p_enc->fmt_out.i_codec == VLC_CODEC_MP2V ||
                p_enc->fmt_out.i_codec == VLC_CODEC_MP1V ) )
             p_context->flags |= CODEC_FLAG_LOW_DELAY;
 
@@ -521,7 +522,7 @@ int OpenEncoder( vlc_object_t *p_this )
             }
         }
 
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 0, 0 )
         if ( p_sys->b_trellis )
             p_context->flags |= CODEC_FLAG_TRELLIS_QUANT;
 #else
@@ -583,7 +584,7 @@ int OpenEncoder( vlc_object_t *p_this )
         if( i_codec_id == CODEC_ID_MP3 && p_enc->fmt_in.audio.i_channels > 2 )
             p_enc->fmt_in.audio.i_channels = 2;
 
-        p_enc->fmt_in.i_codec  = AOUT_FMT_S16_NE;
+        p_enc->fmt_in.i_codec  = VLC_CODEC_S16N;
         p_context->sample_rate = p_enc->fmt_out.audio.i_rate;
         p_context->channels    = p_enc->fmt_out.audio.i_channels;
 
@@ -592,11 +593,9 @@ int OpenEncoder( vlc_object_t *p_this )
             /* XXX: FAAC does resample only when setting the INPUT samplerate
              * to the desired value (-R option of the faac frontend)
             p_enc->fmt_in.audio.i_rate = p_context->sample_rate;*/
-#if LIBAVCODEC_VERSION_INT >= ((51<<16)+(40<<8)+4)
             /* vlc should default to low-complexity profile, faac encoder
              * has bug and aac audio has issues otherwise atm */
             p_context->profile = p_sys->i_aac_profile;
-#endif
         }
     }
 
@@ -678,7 +677,7 @@ int OpenEncoder( vlc_object_t *p_this )
                 msg_Err( p_enc, "cannot open encoder" );
                 dialog_Fatal( p_enc,
                                 _("Streaming / Transcoding failed"),
-                                _("VLC could not open the encoder.") );
+                                "%s", _("VLC could not open the encoder.") );
                 free( p_sys );
                 return VLC_EGENERIC;
             }
@@ -687,7 +686,7 @@ int OpenEncoder( vlc_object_t *p_this )
         {
             msg_Err( p_enc, "cannot open encoder" );
             dialog_Fatal( p_enc, _("Streaming / Transcoding failed"),
-                            _("VLC could not open the encoder.") );
+                            "%s", _("VLC could not open the encoder.") );
             free( p_sys );
             return VLC_EGENERIC;
         }
@@ -883,7 +882,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
             if ( current_date + HURRY_UP_GUARD3 > frame.pts )
             {
                 p_sys->p_context->mb_decision = FF_MB_DECISION_SIMPLE;
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 0, 0 )
                 p_sys->p_context->flags &= ~CODEC_FLAG_TRELLIS_QUANT;
 #else
                 p_sys->p_context->trellis = 0;
@@ -896,7 +895,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
 
                 if ( current_date + HURRY_UP_GUARD2 > frame.pts )
                 {
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 0, 0 )
                     p_sys->p_context->flags &= ~CODEC_FLAG_TRELLIS_QUANT;
 #else
                     p_sys->p_context->trellis = 0;
@@ -907,7 +906,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
                 }
                 else
                 {
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 52, 0, 0 )
                     if ( p_sys->b_trellis )
                         p_sys->p_context->flags |= CODEC_FLAG_TRELLIS_QUANT;
 #else
@@ -1056,7 +1055,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
     int i_samples = p_aout_buf->i_nb_samples;
     int i_samples_delay = p_sys->i_samples_delay;
 
-    p_sys->i_pts = p_aout_buf->start_date -
+    p_sys->i_pts = p_aout_buf->i_pts -
                 (mtime_t)1000000 * (mtime_t)p_sys->i_samples_delay /
                 (mtime_t)p_enc->fmt_in.audio.i_rate;