Skip to content

Commit 4f2aa2d

Browse files
ntocmassiot
authored andcommitted
upipe_avcdec: fix video latency
1 parent 3e7cb15 commit 4f2aa2d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/upipe-av/upipe_avcodec_decode.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,17 @@ static int upipe_avcdec_get_buffer_pic(struct AVCodecContext *context,
366366
fps.num = context->framerate.num;
367367
fps.den = context->framerate.den;
368368
}
369+
uint64_t latency = 0;
369370
if (fps.num && fps.den) {
370371
urational_simplify(&fps);
371372
UBASE_FATAL(upipe, uref_pic_flow_set_fps(flow_def_attr, fps))
372373

373-
uint64_t latency = upipe_avcdec->input_latency +
374-
context->delay * UCLOCK_FREQ * fps.den / fps.num;
375-
if (context->active_thread_type == FF_THREAD_FRAME &&
376-
context->thread_count != -1)
377-
latency += context->thread_count * UCLOCK_FREQ * fps.den / fps.num;
378-
UBASE_FATAL(upipe, uref_clock_set_latency(flow_def_attr, latency))
374+
latency = (context->delay + context->has_b_frames) *
375+
UCLOCK_FREQ * fps.den / fps.num;
379376
}
377+
UBASE_FATAL(upipe, uref_clock_set_latency(
378+
flow_def_attr, upipe_avcdec->input_latency + latency))
379+
380380
/* set aspect-ratio */
381381
if (frame->sample_aspect_ratio.num) {
382382
struct urational sar;
@@ -455,6 +455,8 @@ static int upipe_avcdec_get_buffer_pic(struct AVCodecContext *context,
455455
/* flow format changed */
456456
ubuf_mgr_release(upipe_avcdec->ubuf_mgr);
457457
upipe_avcdec->ubuf_mgr = NULL;
458+
upipe_notice_va(upipe, "latency: %" PRIu64 " ms",
459+
1000 * latency / UCLOCK_FREQ);
458460
}
459461

460462
bool use_ubuf_av = upipe_avcdec->uref == NULL ||

0 commit comments

Comments
 (0)