From 8e8c1f33567e1f5be45476ab8ee3cf991eeb9833 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 17 Oct 2023 12:24:27 +0200 Subject: [PATCH] lavc audio: fixed TS computation fixes: ``` uv -d decklink:sync -r embedded -t testcard:mode=Hp24 -s embedded -A AAC ``` TS adjustnment was made with input BPS (2 B in example above) but the data len is already converted for codec (4 B for AAC). --- src/audio/codec/libavcodec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/audio/codec/libavcodec.c b/src/audio/codec/libavcodec.c index bf1d25711..85bf61ea8 100644 --- a/src/audio/codec/libavcodec.c +++ b/src/audio/codec/libavcodec.c @@ -494,13 +494,13 @@ process_input(struct libavcodec_codec_state *s, const audio_channel *channel) /// @returns timestamp of the channel minus already buffered frames (in s->tmp) static int64_t -get_in_ts(struct libavcodec_codec_state *s, const audio_channel *channel) +get_in_ts(const audio_channel *channel, int cached_samples) { if (channel->timestamp == -1) { return AV_NOPTS_VALUE; } const int64_t ts = channel->timestamp * channel->sample_rate / kHz90; - return ts - s->tmp.data_len / channel->bps; + return ts - cached_samples; } static void @@ -539,13 +539,14 @@ static audio_channel *libavcodec_compress(void *state, audio_channel * channel) assert(s->codec_ctx->sample_fmt != AV_SAMPLE_FMT_DBL && // not supported yet s->codec_ctx->sample_fmt != AV_SAMPLE_FMT_DBLP); - if (channel != NULL) { - s->av_frame->pts = get_in_ts(s, channel); - } - + const int cached_bytes = s->tmp.data_len; if (!process_input(s, channel)) { return NULL; } + if (channel != NULL) { + s->av_frame->pts = + get_in_ts(channel, cached_bytes / s->output_channel.bps); + } int bps = s->output_channel.bps; int offset = 0;