History

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

Michael Niedermayer committed 12 years ago

Commit da218952 parents 1f20fa2 2df0c3222 files · +63 −41Browse files

Unified · Split

22 files
  1. doc/APIchanges +4 −0
  2. libavcodec/aacenc.c +1 −1
  3. libavcodec/ac3enc.c +1 −1
  4. libavcodec/audio_frame_queue.c +2 −2
  5. libavcodec/avcodec.h +18 −10
  6. libavcodec/g722enc.c +2 −2
  7. libavcodec/libfaac.c +1 −1
  8. libavcodec/libfdk-aacenc.c +1 −1
  9. libavcodec/libmp3lame.c +1 −1
  10. libavcodec/libopencore-amr.c +2 −2
  11. libavcodec/libopusenc.c +2 −2
  12. libavcodec/libspeexenc.c +1 −1
  13. libavcodec/libtwolame.c +2 −2
  14. libavcodec/libvo-aacenc.c +1 −1
  15. libavcodec/libvo-amrwbenc.c +2 −2
  16. libavcodec/libvorbisenc.c +2 −2
  17. libavcodec/mpegaudioenc_template.c +2 −2
  18. libavcodec/nellymoserenc.c +1 −1
  19. libavcodec/ra144enc.c +1 −1
  20. libavcodec/utils.c +9 −0
  21. libavcodec/version.h +5 −2
  22. libavcodec/wmaenc.c +2 −4
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2014-08-09 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2014-10-13 - xxxxxxx - lavc 55.03.0 - avcodec.h
19+ Add AVCodecContext.initial_padding. Deprecate the use of AVCodecContext.delay
20+ for audio encoding.
21+
1822 2014-09-xx - xxxxxxx - lavu 54.04.0 - pixdesc.h
1923 Add API to return the name of frame and context color properties.
2024
libavcodec/aacenc.c+1−1
@@ -776,7 +776,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) · 775 unmodified lines
776776 for (i = 0; i < 428; i++)
777777 ff_aac_pow34sf_tab[i] = sqrt(ff_aac_pow2sf_tab[i] * sqrt(ff_aac_pow2sf_tab[i]));
778778
779− avctx->delay = 1024;
779+ avctx->initial_padding = 1024;
780780 ff_af_queue_init(avctx, &s->afq);
781781
782782 return 0;
libavcodec/ac3enc.c+1−1
@@ -2434,7 +2434,7 @@ av_cold int ff_ac3_encode_init(AVCodecContext *avctx) · 2433 unmodified lines
24342434 return ret;
24352435
24362436 avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
2437− avctx->delay = AC3_BLOCK_SIZE;
2437+ avctx->initial_padding = AC3_BLOCK_SIZE;
24382438
24392439 s->bitstream_mode = avctx->audio_service_type;
24402440 if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
libavcodec/audio_frame_queue.c+2−2
@@ -28,8 +28,8 @@ · 27 unmodified lines
2828 av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
2929 {
3030 afq->avctx = avctx;
31− afq->remaining_delay = avctx->delay;
32− afq->remaining_samples = avctx->delay;
31+ afq->remaining_delay = avctx->initial_padding;
32+ afq->remaining_samples = avctx->initial_padding;
3333 afq->frame_count = 0;
3434 }
3535
libavcodec/avcodec.h+18−10
@@ -1373,16 +1373,7 @@ typedef struct AVCodecContext { · 1372 unmodified lines
13731373 * encoded input.
13741374 *
13751375 * Audio:
1376− * For encoding, this is the number of "priming" samples added by the
1377− * encoder to the beginning of the stream. The decoded output will be
1378− * delayed by this many samples relative to the input to the encoder (or
1379− * more, if the decoder adds its own padding).
1380− * The timestamps on the output packets are adjusted by the encoder so
1381− * that they always refer to the first sample of the data actually
1382− * contained in the packet, including any added padding.
1383− * E.g. if the timebase is 1/samplerate and the timestamp of the first
1384− * input sample is 0, the timestamp of the first output packet will be
1385− * -delay.
1376+ * For encoding, this field is unused (see initial_padding).
13861377 *
13871378 * For decoding, this is the number of samples the decoder needs to
13881379 * output before the decoder's output is valid. When seeking, you should
@@ -2980,6 +2971,23 @@ typedef struct AVCodecContext { · 1591 unmodified lines
29802971 */
29812972 int side_data_only_packets;
29822973
2974+ /**
2975+ * Audio only. The number of "priming" samples (padding) inserted by the
2976+ * encoder at the beginning of the audio. I.e. this number of leading
2977+ * decoded samples must be discarded by the caller to get the original audio
2978+ * without leading padding.
2979+ *
2980+ * - decoding: unused
2981+ * - encoding: Set by libavcodec. The timestamps on the output packets are
2982+ * adjusted by the encoder so that they always refer to the
2983+ * first sample of the data actually contained in the packet,
2984+ * including any added padding. E.g. if the timebase is
2985+ * 1/samplerate and the timestamp of the first input sample is
2986+ * 0, the timestamp of the first output packet will be
2987+ * -initial_padding.
2988+ */
2989+ int initial_padding;
2990+
29832991 /**
29842992 * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
29852993 * Code outside libavcodec should access this field using:
libavcodec/g722enc.c+2−2
@@ -107,7 +107,7 @@ static av_cold int g722_encode_init(AVCodecContext * avctx) · 106 unmodified lines
107107 a common packet size for VoIP applications */
108108 avctx->frame_size = 320;
109109 }
110− avctx->delay = 22;
110+ avctx->initial_padding = 22;
111111
112112 if (avctx->trellis) {
113113 /* validate trellis */
@@ -374,7 +374,7 @@ static int g722_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 260 unmodified lines
374374 }
375375
376376 if (frame->pts != AV_NOPTS_VALUE)
377− avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
377+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
378378 *got_packet_ptr = 1;
379379 return 0;
380380 }
libavcodec/libfaac.c+1−1
@@ -167,7 +167,7 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx) · 166 unmodified lines
167167 }
168168 }
169169
170− avctx->delay = FAAC_DELAY_SAMPLES;
170+ avctx->initial_padding = FAAC_DELAY_SAMPLES;
171171 ff_af_queue_init(avctx, &s->afq);
172172
173173 return 0;
libavcodec/libfdk-aacenc.c+1−1
@@ -286,7 +286,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) · 285 unmodified lines
286286 }
287287
288288 avctx->frame_size = info.frameLength;
289− avctx->delay = info.encoderDelay;
289+ avctx->initial_padding = info.encoderDelay;
290290 ff_af_queue_init(avctx, &s->afq);
291291
292292 if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
libavcodec/libmp3lame.c+1−1
@@ -138,7 +138,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx) · 137 unmodified lines
138138 }
139139
140140 /* get encoder delay */
141− avctx->delay = lame_get_encoder_delay(s->gfp) + 528 + 1;
141+ avctx->initial_padding = lame_get_encoder_delay(s->gfp) + 528 + 1;
142142 ff_af_queue_init(avctx, &s->afq);
143143
144144 avctx->frame_size = lame_get_framesize(s->gfp);
libavcodec/libopencore-amr.c+2−2
@@ -199,7 +199,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx) · 198 unmodified lines
199199 }
200200
201201 avctx->frame_size = 160;
202− avctx->delay = 50;
202+ avctx->initial_padding = 50;
203203 ff_af_queue_init(avctx, &s->afq);
204204
205205 s->enc_state = Encoder_Interface_init(s->enc_dtx);
@@ -246,7 +246,7 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 40 unmodified lines
246246 return AVERROR(ENOMEM);
247247 memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));
248248 samples = flush_buf;
249− if (frame->nb_samples < avctx->frame_size - avctx->delay)
249+ if (frame->nb_samples < avctx->frame_size - avctx->initial_padding)
250250 s->enc_last_frame = -1;
251251 }
252252 if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) {
libavcodec/libopusenc.c+2−2
@@ -87,7 +87,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count, · 86 unmodified lines
8787 bytestream_put_buffer(&p, "OpusHead", 8);
8888 bytestream_put_byte(&p, 1); /* Version */
8989 bytestream_put_byte(&p, channels);
90− bytestream_put_le16(&p, avctx->delay); /* Lookahead samples at 48kHz */
90+ bytestream_put_le16(&p, avctx->initial_padding); /* Lookahead samples at 48kHz */
9191 bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */
9292 bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */
9393
@@ -284,7 +284,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx) · 190 unmodified lines
284284 goto fail;
285285 }
286286
287− ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->delay));
287+ ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
288288 if (ret != OPUS_OK)
289289 av_log(avctx, AV_LOG_WARNING,
290290 "Unable to get number of lookahead samples: %s\n",
libavcodec/libspeexenc.c+1−1
@@ -236,7 +236,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 235 unmodified lines
236236 s->header.frames_per_packet = s->frames_per_packet;
237237
238238 /* set encoding delay */
239− speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->delay);
239+ speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &avctx->initial_padding);
240240 ff_af_queue_init(avctx, &s->afq);
241241
242242 /* create header packet bytes from header struct */
libavcodec/libtwolame.c+2−2
@@ -60,7 +60,7 @@ static av_cold int twolame_encode_init(AVCodecContext *avctx) · 59 unmodified lines
6060 int ret;
6161
6262 avctx->frame_size = TWOLAME_SAMPLES_PER_FRAME;
63− avctx->delay = 512 - 32 + 1;
63+ avctx->initial_padding = 512 - 32 + 1;
6464
6565 s->glopts = twolame_init();
6666 if (!s->glopts)
@@ -155,7 +155,7 @@ static int twolame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 88 unmodified lines
155155 if (frame) {
156156 avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples);
157157 if (frame->pts != AV_NOPTS_VALUE)
158− avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
158+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
159159 } else {
160160 avpkt->pts = s->next_pts;
161161 }
libavcodec/libvo-aacenc.c+1−1
@@ -61,7 +61,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) · 60 unmodified lines
6161 int index, ret;
6262
6363 avctx->frame_size = FRAME_SIZE;
64− avctx->delay = ENC_DELAY;
64+ avctx->initial_padding = ENC_DELAY;
6565 s->last_frame = 2;
6666 ff_af_queue_init(avctx, &s->afq);
6767
libavcodec/libvo-amrwbenc.c+2−2
@@ -93,7 +93,7 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx) · 92 unmodified lines
9393 s->last_bitrate = avctx->bit_rate;
9494
9595 avctx->frame_size = 320;
96− avctx->delay = 80;
96+ avctx->initial_padding = 80;
9797
9898 s->state = E_IF_init();
9999
@@ -129,7 +129,7 @@ static int amr_wb_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 29 unmodified lines
129129 }
130130
131131 if (frame->pts != AV_NOPTS_VALUE)
132− avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
132+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
133133
134134 avpkt->size = size;
135135 *got_packet_ptr = 1;
libavcodec/libvorbisenc.c+2−2
@@ -345,8 +345,8 @@ static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 344 unmodified lines
345345 if (duration > 0) {
346346 /* we do not know encoder delay until we get the first packet from
347347 * libvorbis, so we have to update the AudioFrameQueue counts */
348− if (!avctx->delay && s->afq.frames) {
349− avctx->delay = duration;
348+ if (!avctx->initial_padding && s->afq.frames) {
349+ avctx->initial_padding = duration;
350350 av_assert0(!s->afq.remaining_delay);
351351 s->afq.frames->duration += duration;
352352 if (s->afq.frames->pts != AV_NOPTS_VALUE)
libavcodec/mpegaudioenc_template.c+2−2
@@ -89,7 +89,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx) · 88 unmodified lines
8989 bitrate = bitrate / 1000;
9090 s->nb_channels = channels;
9191 avctx->frame_size = MPA_FRAME_SIZE;
92− avctx->delay = 512 - 32 + 1;
92+ avctx->initial_padding = 512 - 32 + 1;
9393
9494 /* encoding freq */
9595 s->lsf = 0;
@@ -771,7 +771,7 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 675 unmodified lines
771771 encode_frame(s, bit_alloc, padding);
772772
773773 if (frame->pts != AV_NOPTS_VALUE)
774− avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
774+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
775775
776776 avpkt->size = put_bits_count(&s->pb) / 8;
777777 *got_packet_ptr = 1;
libavcodec/nellymoserenc.c+1−1
@@ -165,7 +165,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 164 unmodified lines
165165 }
166166
167167 avctx->frame_size = NELLY_SAMPLES;
168− avctx->delay = NELLY_BUF_LEN;
168+ avctx->initial_padding = NELLY_BUF_LEN;
169169 ff_af_queue_init(avctx, &s->afq);
170170 s->avctx = avctx;
171171 if ((ret = ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0)) < 0)
libavcodec/ra144enc.c+1−1
@@ -55,7 +55,7 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx) · 54 unmodified lines
5555 return -1;
5656 }
5757 avctx->frame_size = NBLOCKS * BLOCKSIZE;
58− avctx->delay = avctx->frame_size;
58+ avctx->initial_padding = avctx->frame_size;
5959 avctx->bit_rate = 8000;
6060 ractx = avctx->priv_data;
6161 ractx->lpc_coef[0] = ractx->lpc_tables[0];
libavcodec/utils.c+9−0
@@ -1609,6 +1609,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 1608 unmodified lines
16091609
16101610 ret=0;
16111611
1612+#if FF_API_AUDIOENC_DELAY
1613+ if (av_codec_is_encoder(avctx->codec))
1614+ avctx->delay = avctx->initial_padding;
1615+#endif
1616+
16121617 if (av_codec_is_decoder(avctx->codec)) {
16131618 if (!avctx->bit_rate)
16141619 avctx->bit_rate = get_bit_rate(avctx);
@@ -1921,6 +1926,10 @@ end: · 306 unmodified lines
19211926 av_frame_free(&padded_frame);
19221927 av_free(extended_frame);
19231928
1929+#if FF_API_AUDIOENC_DELAY
1930+ avctx->delay = avctx->initial_padding;
1931+#endif
1932+
19241933 return ret;
19251934 }
19261935
libavcodec/version.h+5−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929 #include "libavutil/version.h"
3030
3131 #define LIBAVCODEC_VERSION_MAJOR 56
32−#define LIBAVCODEC_VERSION_MINOR 4
33−#define LIBAVCODEC_VERSION_MICRO 101
32+#define LIBAVCODEC_VERSION_MINOR 5
33+#define LIBAVCODEC_VERSION_MICRO 100
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636 LIBAVCODEC_VERSION_MINOR, \
@@ -175,5 +175,8 @@ · 138 unmodified lines
175175 #ifndef FF_API_DV_FRAME_PROFILE
176176 #define FF_API_DV_FRAME_PROFILE (LIBAVCODEC_VERSION_MAJOR < 57)
177177 #endif
178+#ifndef FF_API_AUDIOENC_DELAY
179+#define FF_API_AUDIOENC_DELAY (LIBAVCODEC_VERSION_MAJOR < 58)
180+#endif
178181
179182 #endif /* AVCODEC_VERSION_H */
libavcodec/wmaenc.c+2−4
@@ -88,9 +88,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 87 unmodified lines
8888 (avctx->sample_rate * 8);
8989 block_align = FFMIN(block_align, MAX_CODED_SUPERFRAME_SIZE);
9090 avctx->block_align = block_align;
91−
92− avctx->frame_size =
93− avctx->delay = s->frame_len;
91+ avctx->frame_size = avctx->initial_padding = s->frame_len;
9492
9593 return 0;
9694 }
@@ -403,7 +401,7 @@ static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, · 306 unmodified lines
403401 av_assert0(put_bits_ptr(&s->pb) - s->pb.buf == avctx->block_align);
404402
405403 if (frame->pts != AV_NOPTS_VALUE)
406− avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay);
404+ avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
407405
408406 avpkt->size = avctx->block_align;
409407 *got_packet_ptr = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t