From 9ee340c3af5c23c2ac877b6559e11bd70c3052ac Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 22 Feb 2016 20:10:38 +0100 Subject: ad_lavc: skip AVCodecContext.delay samples at beginning Fixes correctness_trimming_nobeeps.opus. One nasty thing is that this mechanism interferes with the container-signalled mechanism with AV_FRAME_DATA_SKIP_SAMPLES. So apply it only if that is apparently not present. It's a mess, and it's still broken in FFmpeg CLI, so I'm sure this will get fucked up later again. --- audio/decode/ad_lavc.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'audio') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 93c297b009..64095b0018 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -43,6 +43,7 @@ struct priv { struct mp_audio frame; bool force_channel_map; uint32_t skip_samples, trim_samples; + bool preroll_done; double next_pts; }; @@ -168,6 +169,7 @@ static int control(struct dec_audio *da, int cmd, void *arg) avcodec_flush_buffers(ctx->avctx); ctx->skip_samples = 0; ctx->trim_samples = 0; + ctx->preroll_done = false; ctx->next_pts = MP_NOPTS_VALUE; return CONTROL_TRUE; } @@ -242,6 +244,13 @@ static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt, } #endif + if (!priv->preroll_done) { + // Skip only if this isn't already handled by AV_FRAME_DATA_SKIP_SAMPLES. + if (!priv->skip_samples) + priv->skip_samples = avctx->delay; + priv->preroll_done = true; + } + uint32_t skip = MPMIN(priv->skip_samples, mpframe->samples); if (skip) { mp_audio_skip_samples(mpframe, skip); -- cgit v1.2.3