diff mbox series

[FFmpeg-devel,1/3] libfdk-aacdec: Apply the decoder's output delay on timestamps

Message ID 20200205110708.64282-1-martin@martin.st
State Accepted
Headers show
Series [FFmpeg-devel,1/3] libfdk-aacdec: Apply the decoder's output delay on timestamps | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Martin Storsjö Feb. 5, 2020, 11:07 a.m. UTC
The delay is normally zero when the level limiter is disabled,
but if enabled, there's a small delay.
---
 libavcodec/libfdk-aacdec.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Martin Storsjö Feb. 10, 2020, 9:02 p.m. UTC | #1
On Wed, 5 Feb 2020, Martin Storsjö wrote:

> The delay is normally zero when the level limiter is disabled,
> but if enabled, there's a small delay.
> ---
> libavcodec/libfdk-aacdec.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
> index 1abe1d8438..d9b080cf3e 100644
> --- a/libavcodec/libfdk-aacdec.c
> +++ b/libavcodec/libfdk-aacdec.c
> @@ -57,6 +57,7 @@ typedef struct FDKAACDecContext {
>     int drc_effect;
>     int drc_cut;
>     int level_limit;
> +    int output_delay;
> } FDKAACDecContext;
> 
> 
> @@ -115,6 +116,9 @@ static int get_stream_info(AVCodecContext *avctx)
>     }
>     avctx->sample_rate = info->sampleRate;
>     avctx->frame_size  = info->frameSize;
> +#if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
> +    s->output_delay    = info->outputDelay;
> +#endif
>
>     for (i = 0; i < info->numChannels; i++) {
>         AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
> @@ -367,6 +371,11 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
>     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
>         goto end;
> 
> +    if (frame->pts != AV_NOPTS_VALUE)
> +        frame->pts -= av_rescale_q(s->output_delay,
> +                                   (AVRational){1, avctx->sample_rate},
> +                                   avctx->time_base);
> +
>     memcpy(frame->extended_data[0], s->decoder_buffer,
>            avctx->channels * avctx->frame_size *
>            av_get_bytes_per_sample(avctx->sample_fmt));
> -- 
> 2.21.1 (Apple Git-122.3)

OK'd by James on irc.

// Martin
diff mbox series

Patch

diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index 1abe1d8438..d9b080cf3e 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -57,6 +57,7 @@  typedef struct FDKAACDecContext {
     int drc_effect;
     int drc_cut;
     int level_limit;
+    int output_delay;
 } FDKAACDecContext;
 
 
@@ -115,6 +116,9 @@  static int get_stream_info(AVCodecContext *avctx)
     }
     avctx->sample_rate = info->sampleRate;
     avctx->frame_size  = info->frameSize;
+#if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
+    s->output_delay    = info->outputDelay;
+#endif
 
     for (i = 0; i < info->numChannels; i++) {
         AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
@@ -367,6 +371,11 @@  static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         goto end;
 
+    if (frame->pts != AV_NOPTS_VALUE)
+        frame->pts -= av_rescale_q(s->output_delay,
+                                   (AVRational){1, avctx->sample_rate},
+                                   avctx->time_base);
+
     memcpy(frame->extended_data[0], s->decoder_buffer,
            avctx->channels * avctx->frame_size *
            av_get_bytes_per_sample(avctx->sample_fmt));