diff options
author | wm4 <wm4@nowhere> | 2016-02-22 19:58:11 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-02-22 19:58:11 +0100 |
commit | 289edadb8d28a3a73bf6930306dd2cb9a6777470 (patch) | |
tree | de97b08e4916cea0eaf32dbfb392494ead00db3f | |
parent | d52b2981c0cdc88c6679262f26dd097c2eb4df83 (diff) | |
download | mpv-289edadb8d28a3a73bf6930306dd2cb9a6777470.tar.bz2 mpv-289edadb8d28a3a73bf6930306dd2cb9a6777470.tar.xz |
ad_lavc: make sample trimming symmetric to skipping
I'm not quite sure what the FFmpeg AV_FRAME_DATA_SKIP_SAMPLES API
demands here. The code so far assumed that skipping can be more than a
frame, but not trimming. Extend it to trimming too.
-rw-r--r-- | audio/decode/ad_lavc.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 96625cae2f..93c297b009 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -42,7 +42,7 @@ struct priv { AVFrame *avframe; struct mp_audio frame; bool force_channel_map; - uint32_t skip_samples; + uint32_t skip_samples, trim_samples; double next_pts; }; @@ -167,6 +167,7 @@ static int control(struct dec_audio *da, int cmd, void *arg) case ADCTRL_RESET: avcodec_flush_buffers(ctx->avctx); ctx->skip_samples = 0; + ctx->trim_samples = 0; ctx->next_pts = MP_NOPTS_VALUE; return CONTROL_TRUE; } @@ -231,15 +232,13 @@ static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt, if (mpframe->pts != MP_NOPTS_VALUE) priv->next_pts = mpframe->pts + mpframe->samples / (double)mpframe->rate; - uint32_t pad = 0; - #if HAVE_AVFRAME_SKIP_SAMPLES AVFrameSideData *sd = av_frame_get_side_data(priv->avframe, AV_FRAME_DATA_SKIP_SAMPLES); if (sd && sd->size >= 10) { char *d = sd->data; priv->skip_samples += AV_RL32(d + 0); - pad = AV_RL32(d + 4); + priv->trim_samples += AV_RL32(d + 4); } #endif @@ -250,8 +249,11 @@ static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt, mpframe->pts += skip / (double)mpframe->rate; priv->skip_samples -= skip; } - if (pad <= mpframe->samples) - mpframe->samples -= pad; + uint32_t trim = MPMIN(priv->trim_samples, mpframe->samples); + if (trim) { + mpframe->samples -= trim; + priv->trim_samples -= trim; + } *out = mpframe; |