]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegaudioenc.c
libvorbis: use float input instead of s16
[ffmpeg] / libavcodec / mpegaudioenc.c
index 35a52ad571b1be525277c65725bd4644935f63da..9ee7f2cba4cf4fd855c8b6d2b6d867ce47285041 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "avcodec.h"
+#include "internal.h"
 #include "put_bits.h"
 
 #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
@@ -74,7 +75,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
 
     if (channels <= 0 || channels > 2){
         av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels);
-        return -1;
+        return AVERROR(EINVAL);
     }
     bitrate = bitrate / 1000;
     s->nb_channels = channels;
@@ -83,27 +84,27 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
     /* encoding freq */
     s->lsf = 0;
     for(i=0;i<3;i++) {
-        if (ff_mpa_freq_tab[i] == freq)
+        if (avpriv_mpa_freq_tab[i] == freq)
             break;
-        if ((ff_mpa_freq_tab[i] / 2) == freq) {
+        if ((avpriv_mpa_freq_tab[i] / 2) == freq) {
             s->lsf = 1;
             break;
         }
     }
     if (i == 3){
         av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq);
-        return -1;
+        return AVERROR(EINVAL);
     }
     s->freq_index = i;
 
     /* encoding bitrate & frequency */
     for(i=0;i<15;i++) {
-        if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate)
+        if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate)
             break;
     }
     if (i == 15){
         av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate);
-        return -1;
+        return AVERROR(EINVAL);
     }
     s->bitrate_index = i;
 
@@ -180,7 +181,8 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
     }
 
     avctx->coded_frame= avcodec_alloc_frame();
-    avctx->coded_frame->key_frame= 1;
+    if (!avctx->coded_frame)
+        return AVERROR(ENOMEM);
 
     return 0;
 }
@@ -759,16 +761,21 @@ static av_cold int MPA_encode_close(AVCodecContext *avctx)
     return 0;
 }
 
+static const AVCodecDefault mp2_defaults[] = {
+    { "b",    "128k" },
+    { NULL },
+};
+
 AVCodec ff_mp2_encoder = {
-    "mp2",
-    AVMEDIA_TYPE_AUDIO,
-    CODEC_ID_MP2,
-    sizeof(MpegAudioContext),
-    MPA_encode_init,
-    MPA_encode_frame,
-    MPA_encode_close,
-    NULL,
+    .name           = "mp2",
+    .type           = AVMEDIA_TYPE_AUDIO,
+    .id             = CODEC_ID_MP2,
+    .priv_data_size = sizeof(MpegAudioContext),
+    .init           = MPA_encode_init,
+    .encode         = MPA_encode_frame,
+    .close          = MPA_encode_close,
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .supported_samplerates= (const int[]){44100, 48000,  32000, 22050, 24000, 16000, 0},
     .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
+    .defaults       = mp2_defaults,
 };