summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-10-14 02:16:16 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-10-14 02:16:16 +0200
commitda2189596d9a339d2e6eb2f14137de93b15b354f (patch)
treea11e6ed2e8f0715fc2d468aa0937ccdf2041fd8a /libavcodec
parent1f20fa2da83922cd73b090b7f336ba51e25b1fb3 (diff)
parent2df0c32ea12ddfa72ba88309812bfb13b674130f (diff)
Merge commit '2df0c32ea12ddfa72ba88309812bfb13b674130f'
* commit '2df0c32ea12ddfa72ba88309812bfb13b674130f': lavc: use a separate field for exporting audio encoder padding Conflicts: libavcodec/audio_frame_queue.c libavcodec/avcodec.h libavcodec/libvorbisenc.c libavcodec/utils.c libavcodec/version.h libavcodec/wmaenc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/aacenc.c2
-rw-r--r--libavcodec/ac3enc.c2
-rw-r--r--libavcodec/audio_frame_queue.c4
-rw-r--r--libavcodec/avcodec.h28
-rw-r--r--libavcodec/g722enc.c4
-rw-r--r--libavcodec/libfaac.c2
-rw-r--r--libavcodec/libfdk-aacenc.c2
-rw-r--r--libavcodec/libmp3lame.c2
-rw-r--r--libavcodec/libopencore-amr.c4
-rw-r--r--libavcodec/libopusenc.c4
-rw-r--r--libavcodec/libspeexenc.c2
-rw-r--r--libavcodec/libtwolame.c4
-rw-r--r--libavcodec/libvo-aacenc.c2
-rw-r--r--libavcodec/libvo-amrwbenc.c4
-rw-r--r--libavcodec/libvorbisenc.c4
-rw-r--r--libavcodec/mpegaudioenc_template.c4
-rw-r--r--libavcodec/nellymoserenc.c2
-rw-r--r--libavcodec/ra144enc.c2
-rw-r--r--libavcodec/utils.c9
-rw-r--r--libavcodec/version.h7
-rw-r--r--libavcodec/wmaenc.c6
21 files changed, 59 insertions, 41 deletions
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 0378f0da1a..464e4dcb0a 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -776,7 +776,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
for (i = 0; i < 428; i++)
ff_aac_pow34sf_tab[i] = sqrt(ff_aac_pow2sf_tab[i] * sqrt(ff_aac_pow2sf_tab[i]));
- avctx->delay = 1024;
+ avctx->initial_padding = 1024;
ff_af_queue_init(avctx, &s->afq);
return 0;
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index ce5cde8326..8fc9952e66 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2434,7 +2434,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
return ret;
avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
- avctx->delay = AC3_BLOCK_SIZE;
+ avctx->initial_padding = AC3_BLOCK_SIZE;
s->bitstream_mode = avctx->audio_service_type;
if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
diff --git a/libavcodec/audio_frame_queue.c b/libavcodec/audio_frame_queue.c
index 12203450ba..4f6bccce36 100644
--- a/libavcodec/audio_frame_queue.c
+++ b/libavcodec/audio_frame_queue.c
@@ -28,8 +28,8 @@
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
{
afq->avctx = avctx;
- afq->remaining_delay = avctx->delay;
- afq->remaining_samples = avctx->delay;
+ afq->remaining_delay = avctx->initial_padding;
+ afq->remaining_samples = avctx->initial_padding;
afq->frame_count = 0;
}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a5a651a635..f9ab7c2da9 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1373,16 +1373,7 @@ typedef struct AVCodecContext {
* encoded input.
*
* Audio:
- * For encoding, this is the number of "priming" samples added by the
- * encoder to the beginning of the stream. The decoded output will be
- * delayed by this many samples relative to the input to the encoder (or
- * more, if the decoder adds its own padding).
- * The timestamps on the output packets are adjusted by the encoder so
- * that they always refer to the first sample of the data actually
- * contained in the packet, including any added padding.
- * E.g. if the timebase is 1/samplerate and the timestamp of the first
- * input sample is 0, the timestamp of the first output packet will be
- * -delay.
+ * For encoding, this field is unused (see initial_padding).
*
* For decoding, this is the number of samples the decoder needs to
* output before the decoder's output is valid. When seeking, you should
@@ -2981,6 +2972,23 @@ typedef struct AVCodecContext {
int side_data_only_packets;
/**
+ * Audio only. The number of "priming" samples (padding) inserted by the
+ * encoder at the beginning of the audio. I.e. this number of leading
+ * decoded samples must be discarded by the caller to get the original audio
+ * without leading padding.
+ *
+ * - decoding: unused
+ * - encoding: Set by libavcodec. The timestamps on the output packets are
+ * adjusted by the encoder so that they always refer to the
+ * first sample of the data actually contained in the packet,
+ * including any added padding. E.g. if the timebase is
+ * 1/samplerate and the timestamp of the first input sample is
+ * 0, the timestamp of the first output packet will be
+ * -initial_padding.
+ */
+ int initial_padding;
+
+ /**
* Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
* Code outside libavcodec should access this field using:
* av_codec_{get,set}_pkt_timebase(avctx)
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index c4d6c7b853..dac7c87768 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -107,7 +107,7 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
a common packet size for VoIP applications */
avctx->frame_size = 320;
}
- avctx->delay = 22;
+ avctx->initial_padding = 22;
if (avctx->trellis) {
/* validate trellis */
@@ -374,7 +374,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
if (frame->pts != AV_NOPTS_VALUE)
- avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
*got_packet_ptr = 1;
return 0;
}
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index 477669a812..69c186b11a 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -167,7 +167,7 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
}
}
- avctx->delay = FAAC_DELAY_SAMPLES;
+ avctx->initial_padding = FAAC_DELAY_SAMPLES;
ff_af_queue_init(avctx, &s->afq);
return 0;
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index b9c9a132bd..3eadb36b83 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -286,7 +286,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
}
avctx->frame_size = info.frameLength;
- avctx->delay = info.encoderDelay;
+ avctx->initial_padding = info.encoderDelay;
ff_af_queue_init(avctx, &s->afq);
if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 1ac79a2ed9..661d1c05e4 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -138,7 +138,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
}
/* get encoder delay */
- avctx->delay = lame_get_encoder_delay(s->gfp) + 528 + 1;
+ avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1;
ff_af_queue_init(avctx, &s->afq);
avctx->frame_size = lame_get_framesize(s->gfp);
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 827bdedc00..b2ad839211 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -199,7 +199,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
}
avctx->frame_size = 160;
- avctx->delay = 50;
+ avctx->initial_padding = 50;
ff_af_queue_init(avctx, &s->afq);
s->enc_state = Encoder_Interface_init(s->enc_dtx);
@@ -246,7 +246,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
return AVERROR(ENOMEM);
memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));
samples = flush_buf;
- if (frame->nb_samples < avctx->frame_size - avctx->delay)
+ if (frame->nb_samples < avctx->frame_size - avctx->initial_padding)
s->enc_last_frame = -1;
}
if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) {
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 75e82dac0d..5203729a38 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -87,7 +87,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count,
bytestream_put_buffer(&p, "OpusHead", 8);
bytestream_put_byte(&p, 1); /* Version */
bytestream_put_byte(&p, channels);
- bytestream_put_le16(&p, avctx->delay); /* Lookahead samples at 48kHz */
+ bytestream_put_le16(&p, avctx->initial_padding); /* Lookahead samples at 48kHz */
bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */
@@ -284,7 +284,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
goto fail;
}
- ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->delay));
+ ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
if (ret != OPUS_OK)
av_log(avctx, AV_LOG_WARNING,
"Unable to get number of lookahead samples: %s\n",
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index aba4618f66..21238aa122 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -236,7 +236,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->header.frames_per_packet = s->frames_per_packet;
/* set encoding delay */
- speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->delay);
+ speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->initial_padding);
ff_af_queue_init(avctx, &s->afq);
/* create header packet bytes from header struct */
diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index 098196b0c1..dc188575b5 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -60,7 +60,7 @@ static av_cold int twolame_encode_init(AVCodecContext *avctx)
int ret;
avctx->frame_size = TWOLAME_SAMPLES_PER_FRAME;
- avctx->delay = 512 - 32 + 1;
+ avctx->initial_padding = 512 - 32 + 1;
s->glopts = twolame_init();
if (!s->glopts)
@@ -155,7 +155,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (frame) {
avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
if (frame->pts != AV_NOPTS_VALUE)
- avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
} else {
avpkt->pts = s->next_pts;
}
diff --git a/libavcodec/libvo-aacenc.c b/libavcodec/libvo-aacenc.c
index 04f9902e91..7b38d518a2 100644
--- a/libavcodec/libvo-aacenc.c
+++ b/libavcodec/libvo-aacenc.c
@@ -61,7 +61,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
int index, ret;
avctx->frame_size = FRAME_SIZE;
- avctx->delay = ENC_DELAY;
+ avctx->initial_padding = ENC_DELAY;
s->last_frame = 2;
ff_af_queue_init(avctx, &s->afq);
diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index f14d61fecf..fe19e71156 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -93,7 +93,7 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
s->last_bitrate = avctx->bit_rate;
avctx->frame_size = 320;
- avctx->delay = 80;
+ avctx->initial_padding = 80;
s->state = E_IF_init();
@@ -129,7 +129,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
if (frame->pts != AV_NOPTS_VALUE)
- avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
avpkt->size = size;
*got_packet_ptr = 1;
diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index ed6baa90d3..96af53614b 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -345,8 +345,8 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (duration > 0) {
/* we do not know encoder delay until we get the first packet from
* libvorbis, so we have to update the AudioFrameQueue counts */
- if (!avctx->delay && s->afq.frames) {
- avctx->delay = duration;
+ if (!avctx->initial_padding && s->afq.frames) {
+ avctx->initial_padding = duration;
av_assert0(!s->afq.remaining_delay);
s->afq.frames->duration += duration;
if (s->afq.frames->pts != AV_NOPTS_VALUE)
diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index e9571d83c7..1bf9471ffe 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -89,7 +89,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;
+ avctx->initial_padding = 512 - 32 + 1;
/* encoding freq */
s->lsf = 0;
@@ -771,7 +771,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
encode_frame(s, bit_alloc, padding);
if (frame->pts != AV_NOPTS_VALUE)
- avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
avpkt->size = put_bits_count(&s->pb) / 8;
*got_packet_ptr = 1;
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 98e33f0e2e..4f511c292b 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -165,7 +165,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
avctx->frame_size = NELLY_SAMPLES;
- avctx->delay = NELLY_BUF_LEN;
+ avctx->initial_padding = NELLY_BUF_LEN;
ff_af_queue_init(avctx, &s->afq);
s->avctx = avctx;
if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0)
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 499c41a038..3ad3f4ea96 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -55,7 +55,7 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx)
return -1;
}
avctx->frame_size = NBLOCKS * BLOCKSIZE;
- avctx->delay = avctx->frame_size;
+ avctx->initial_padding = avctx->frame_size;
avctx->bit_rate = 8000;
ractx = avctx->priv_data;
ractx->lpc_coef[0] = ractx->lpc_tables[0];
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 3bab3ea3a7..1b5e3e01d6 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1609,6 +1609,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
ret=0;
+#if FF_API_AUDIOENC_DELAY
+ if (av_codec_is_encoder(avctx->codec))
+ avctx->delay = avctx->initial_padding;
+#endif
+
if (av_codec_is_decoder(avctx->codec)) {
if (!avctx->bit_rate)
avctx->bit_rate = get_bit_rate(avctx);
@@ -1921,6 +1926,10 @@ end:
av_frame_free(&padded_frame);
av_free(extended_frame);
+#if FF_API_AUDIOENC_DELAY
+ avctx->delay = avctx->initial_padding;
+#endif
+
return ret;
}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index adea884dae..30ce7947fc 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 56
-#define LIBAVCODEC_VERSION_MINOR 4
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR 5
+#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
@@ -175,5 +175,8 @@
#ifndef FF_API_DV_FRAME_PROFILE
#define FF_API_DV_FRAME_PROFILE (LIBAVCODEC_VERSION_MAJOR < 57)
#endif
+#ifndef FF_API_AUDIOENC_DELAY
+#define FF_API_AUDIOENC_DELAY (LIBAVCODEC_VERSION_MAJOR < 58)
+#endif
#endif /* AVCODEC_VERSION_H */
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index dfa4ad9484..6337779fa3 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -88,9 +88,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
(avctx->sample_rate * 8);
block_align = FFMIN(block_align, MAX_CODED_SUPERFRAME_SIZE);
avctx->block_align = block_align;
-
- avctx->frame_size =
- avctx->delay = s->frame_len;
+ avctx->frame_size = avctx->initial_padding = s->frame_len;
return 0;
}
@@ -403,7 +401,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
av_assert0(put_bits_ptr(&s->pb) - s->pb.buf == avctx->block_align);
if (frame->pts != AV_NOPTS_VALUE)
- avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
avpkt->size = avctx->block_align;
*got_packet_ptr = 1;