mirror of https://github.com/mpv-player/mpv
encode: don't access ao->pts
This field will be moved out of the ao struct. The encoding code was basically using an invalid way of accessing this field. Since the AO will be moved into its own thread too and will do its own buffering, the AO and the playback core might not even agree which sample a PTS timestamp belongs to. Add some extrapolation code to handle this case.
This commit is contained in:
parent
4579d9ca58
commit
74b7001500
|
@ -320,7 +320,6 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
|||
struct encode_lavc_context *ectx = ao->encode_lavc_ctx;
|
||||
int bufpos = 0;
|
||||
double nextpts;
|
||||
double pts = ao->pts;
|
||||
double outpts;
|
||||
|
||||
if (!encode_lavc_start(ectx)) {
|
||||
|
@ -328,6 +327,10 @@ static int play(struct ao *ao, void **data, int samples, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
double pts = ectx->last_audio_in_pts;
|
||||
pts += ectx->samples_since_last_pts / ao->samplerate;
|
||||
ectx->samples_since_last_pts += samples;
|
||||
|
||||
size_t num_planes = af_fmt_is_planar(ao->format) ? ao->channels.num : 1;
|
||||
|
||||
if (flags & AOPLAY_FINAL_CHUNK) {
|
||||
|
|
|
@ -18,6 +18,7 @@ bool encode_lavc_showhelp(struct mp_log *log, struct encode_output_conf *options
|
|||
int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position);
|
||||
void encode_lavc_expect_stream(struct encode_lavc_context *ctx, int mt);
|
||||
void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps);
|
||||
void encode_lavc_set_audio_pts(struct encode_lavc_context *ctx, double pts);
|
||||
bool encode_lavc_didfail(struct encode_lavc_context *ctx); // check if encoding failed
|
||||
|
||||
#endif
|
||||
|
|
|
@ -386,6 +386,14 @@ void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps)
|
|||
ctx->vo_fps = fps;
|
||||
}
|
||||
|
||||
void encode_lavc_set_audio_pts(struct encode_lavc_context *ctx, double pts)
|
||||
{
|
||||
if (ctx) {
|
||||
ctx->last_audio_in_pts = pts;
|
||||
ctx->samples_since_last_pts = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void encode_2pass_prepare(struct encode_lavc_context *ctx,
|
||||
AVDictionary **dictp,
|
||||
AVStream *stream, struct stream **bytebuf,
|
||||
|
|
|
@ -55,6 +55,9 @@ struct encode_lavc_context {
|
|||
double audio_pts_offset;
|
||||
double last_video_in_pts;
|
||||
|
||||
double last_audio_in_pts;
|
||||
int64_t samples_since_last_pts;
|
||||
|
||||
// anti discontinuity mode
|
||||
double next_in_pts;
|
||||
double discontinuity_pts_offset;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "talloc.h"
|
||||
|
||||
#include "common/msg.h"
|
||||
#include "common/encode.h"
|
||||
#include "options/options.h"
|
||||
#include "common/common.h"
|
||||
|
||||
|
@ -252,6 +253,9 @@ static int write_to_ao(struct MPContext *mpctx, struct mp_audio *data, int flags
|
|||
return 0;
|
||||
struct ao *ao = mpctx->ao;
|
||||
ao->pts = pts;
|
||||
#if HAVE_ENCODING
|
||||
encode_lavc_set_audio_pts(mpctx->encode_lavc_ctx, ao->pts);
|
||||
#endif
|
||||
double real_samplerate = ao->samplerate / mpctx->opts->playback_speed;
|
||||
int played = ao_play(mpctx->ao, data->planes, data->samples, flags);
|
||||
assert(played <= data->samples);
|
||||
|
|
Loading…
Reference in New Issue