Skip to content

Commit

Permalink
lavc audio: fixed TS computation
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
MartinPulec committed Oct 17, 2023
1 parent 768cc8a commit 8e8c1f3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/audio/codec/libavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e8c1f3

Please sign in to comment.