Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upipe_avcdec: fix video latency #1042

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/upipe-av/upipe_avcodec_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,17 +366,17 @@ static int upipe_avcdec_get_buffer_pic(struct AVCodecContext *context,
fps.num = context->framerate.num;
fps.den = context->framerate.den;
}
uint64_t latency = 0;
if (fps.num && fps.den) {
urational_simplify(&fps);
UBASE_FATAL(upipe, uref_pic_flow_set_fps(flow_def_attr, fps))

uint64_t latency = upipe_avcdec->input_latency +
context->delay * UCLOCK_FREQ * fps.den / fps.num;
if (context->active_thread_type == FF_THREAD_FRAME &&
context->thread_count != -1)
latency += context->thread_count * UCLOCK_FREQ * fps.den / fps.num;
UBASE_FATAL(upipe, uref_clock_set_latency(flow_def_attr, latency))
latency = (context->delay + context->has_b_frames) *
UCLOCK_FREQ * fps.den / fps.num;
}
UBASE_FATAL(upipe, uref_clock_set_latency(
flow_def_attr, upipe_avcdec->input_latency + latency))

/* set aspect-ratio */
if (frame->sample_aspect_ratio.num) {
struct urational sar;
Expand Down Expand Up @@ -455,6 +455,8 @@ static int upipe_avcdec_get_buffer_pic(struct AVCodecContext *context,
/* flow format changed */
ubuf_mgr_release(upipe_avcdec->ubuf_mgr);
upipe_avcdec->ubuf_mgr = NULL;
upipe_notice_va(upipe, "latency: %" PRIu64 " ms",
1000 * latency / UCLOCK_FREQ);
}

bool use_ubuf_av = upipe_avcdec->uref == NULL ||
Expand Down
Loading