summaryrefslogtreecommitdiff
path: root/libavcodec/mpegaudioenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-21 23:47:44 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-22 00:40:11 +0100
commit967facb6950549d0cc4e0ba79a056ebc6f93a049 (patch)
tree872266e5d486be0ab8cf9e378bf567c191fba71a /libavcodec/mpegaudioenc.c
parentf1fdd208cc0a1fce7aaaf6b0fe72b013525f49e0 (diff)
parent6aba117f1273c7704312c6d892c9f552fa0661bb (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (26 commits) adxenc: use AVCodec.encode2() adxenc: Use the AVFrame in ADXContext for coded_frame indeo4: fix out-of-bounds function call. configure: Restructure help output. configure: Internal-only components should not be command-line selectable. vorbisenc: use AVCodec.encode2() libvorbis: use AVCodec.encode2() libopencore-amrnbenc: use AVCodec.encode2() ra144enc: use AVCodec.encode2() nellymoserenc: use AVCodec.encode2() roqaudioenc: use AVCodec.encode2() libspeex: use AVCodec.encode2() libvo_amrwbenc: use AVCodec.encode2() libvo_aacenc: use AVCodec.encode2() wmaenc: use AVCodec.encode2() mpegaudioenc: use AVCodec.encode2() libmp3lame: use AVCodec.encode2() libgsmenc: use AVCodec.encode2() libfaac: use AVCodec.encode2() g726enc: use AVCodec.encode2() ... Conflicts: configure libavcodec/Makefile libavcodec/ac3enc.c libavcodec/adxenc.c libavcodec/libgsm.c libavcodec/libvorbis.c libavcodec/vorbisenc.c libavcodec/wmaenc.c tests/ref/acodec/g722 tests/ref/lavf/asf tests/ref/lavf/ffm tests/ref/lavf/mkv tests/ref/lavf/mpg tests/ref/lavf/rm tests/ref/lavf/ts tests/ref/seek/lavf_asf tests/ref/seek/lavf_ffm tests/ref/seek/lavf_mkv tests/ref/seek/lavf_mpg tests/ref/seek/lavf_rm tests/ref/seek/lavf_ts Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegaudioenc.c')
-rw-r--r--libavcodec/mpegaudioenc.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index b3cb0bba59..1f9516d2e9 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -80,6 +80,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
bitrate = bitrate / 1000;
s->nb_channels = channels;
avctx->frame_size = MPA_FRAME_SIZE;
+ avctx->delay = 512 - 32 + 1;
/* encoding freq */
s->lsf = 0;
@@ -180,9 +181,11 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
total_quant_bits[i] = 12 * v;
}
+#if FF_API_OLD_ENCODE_AUDIO
avctx->coded_frame= avcodec_alloc_frame();
if (!avctx->coded_frame)
return AVERROR(ENOMEM);
+#endif
return 0;
}
@@ -726,14 +729,14 @@ static void encode_frame(MpegAudioContext *s,
flush_put_bits(p);
}
-static int MPA_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
+static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+ const AVFrame *frame, int *got_packet_ptr)
{
MpegAudioContext *s = avctx->priv_data;
- const short *samples = data;
+ const int16_t *samples = (const int16_t *)frame->data[0];
short smr[MPA_MAX_CHANNELS][SBLIMIT];
unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
- int padding, i;
+ int padding, i, ret;
for(i=0;i<s->nb_channels;i++) {
filter(s, i, samples + i, s->nb_channels);
@@ -748,16 +751,28 @@ static int MPA_encode_frame(AVCodecContext *avctx,
}
compute_bit_allocation(s, smr, bit_alloc, &padding);
- init_put_bits(&s->pb, frame, MPA_MAX_CODED_FRAME_SIZE);
+ if ((ret = ff_alloc_packet(avpkt, MPA_MAX_CODED_FRAME_SIZE))) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+ return ret;
+ }
+
+ init_put_bits(&s->pb, avpkt->data, avpkt->size);
encode_frame(s, bit_alloc, padding);
- return put_bits_ptr(&s->pb) - s->pb.buf;
+ if (frame->pts != AV_NOPTS_VALUE)
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+
+ avpkt->size = put_bits_count(&s->pb) / 8;
+ *got_packet_ptr = 1;
+ return 0;
}
static av_cold int MPA_encode_close(AVCodecContext *avctx)
{
+#if FF_API_OLD_ENCODE_AUDIO
av_freep(&avctx->coded_frame);
+#endif
return 0;
}
@@ -772,7 +787,7 @@ AVCodec ff_mp2_encoder = {
.id = CODEC_ID_MP2,
.priv_data_size = sizeof(MpegAudioContext),
.init = MPA_encode_init,
- .encode = MPA_encode_frame,
+ .encode2 = 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},