mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 09:32:40 +00:00
ad_lavc: interpolate missing timestamps
This is actually already done by dec_audio.c. But if AV_FRAME_DATA_SKIP_SAMPLES is applied, this happens too late here. The problem is that this will slice off samples, and make it impossible for later code to reconstruct the timestamp properly. Missing timestamps can still happen with some demuxers, e.g. demux_mkv.c with Opus tracks. (Although libavformat interpolates these itself.)
This commit is contained in:
parent
1bb1543a88
commit
65b858f7d3
@ -43,6 +43,7 @@ struct priv {
|
||||
struct mp_audio frame;
|
||||
bool force_channel_map;
|
||||
uint32_t skip_samples;
|
||||
double next_pts;
|
||||
};
|
||||
|
||||
static void uninit(struct dec_audio *da);
|
||||
@ -138,6 +139,8 @@ static int init(struct dec_audio *da, const char *decoder)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx->next_pts = MP_NOPTS_VALUE;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -164,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->next_pts = MP_NOPTS_VALUE;
|
||||
return CONTROL_TRUE;
|
||||
}
|
||||
return CONTROL_UNKNOWN;
|
||||
@ -222,6 +226,11 @@ static int decode_packet(struct dec_audio *da, struct demux_packet *mpkt,
|
||||
|
||||
mpframe->pts = out_pts;
|
||||
|
||||
if (mpframe->pts == MP_NOPTS_VALUE)
|
||||
mpframe->pts = priv->next_pts;
|
||||
if (mpframe->pts != MP_NOPTS_VALUE)
|
||||
priv->next_pts = mpframe->pts + mpframe->samples / (double)mpframe->rate;
|
||||
|
||||
#if HAVE_AVFRAME_SKIP_SAMPLES
|
||||
AVFrameSideData *sd =
|
||||
av_frame_get_side_data(priv->avframe, AV_FRAME_DATA_SKIP_SAMPLES);
|
||||
|
Loading…
Reference in New Issue
Block a user