mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
ao_lavc: Fix design of audio pts handling.
There was confusion about what should go into audio pts calculation and what not (mainly due to the audio push thread). This has been fixed by using the playing - not written - audio pts (which properly takes into account the ao's buffer), and incrementing the samples count only by the amount of samples actually taken from the buffer (unfortunately this now forces us to keep the lock too long for my taste).
This commit is contained in:
parent
e257cbfdbb
commit
073b2becfe
@ -343,7 +343,6 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
||||
|
||||
double pts = ectx->last_audio_in_pts;
|
||||
pts += ectx->samples_since_last_pts / (double)ao->samplerate;
|
||||
ectx->samples_since_last_pts += samples;
|
||||
|
||||
size_t num_planes = af_fmt_is_planar(ao->format) ? ao->channels.num : 1;
|
||||
|
||||
@ -451,6 +450,10 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
||||
}
|
||||
|
||||
talloc_free(tempdata);
|
||||
|
||||
int taken = FFMIN(bufpos, orig_samples);
|
||||
ectx->samples_since_last_pts += taken;
|
||||
|
||||
pthread_mutex_unlock(&ectx->lock);
|
||||
|
||||
if (flags & AOPLAY_FINAL_CHUNK) {
|
||||
@ -463,7 +466,7 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
return FFMIN(bufpos, orig_samples);
|
||||
return taken;
|
||||
}
|
||||
|
||||
static void drain(struct ao *ao)
|
||||
|
@ -264,7 +264,7 @@ static int write_to_ao(struct MPContext *mpctx, struct mp_audio *data, int flags
|
||||
ao_get_format(ao, &out_format);
|
||||
mpctx->ao_pts = pts;
|
||||
#if HAVE_ENCODING
|
||||
encode_lavc_set_audio_pts(mpctx->encode_lavc_ctx, mpctx->ao_pts);
|
||||
encode_lavc_set_audio_pts(mpctx->encode_lavc_ctx, playing_audio_pts(mpctx));
|
||||
#endif
|
||||
if (data->samples == 0)
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user