From c3cc8d416cea8a1d09b866305dfe97ac8620e2c5 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 26 Apr 2012 22:27:55 +0000 Subject: [PATCH] x264enc: Fix setting latency Fixes setting latency when framerate is dynamic and round up the latency to avoid rounding issues. --- ext/x264/gstx264enc.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ext/x264/gstx264enc.c b/ext/x264/gstx264enc.c index e6b968df9a..d42bbcadb2 100644 --- a/ext/x264/gstx264enc.c +++ b/ext/x264/gstx264enc.c @@ -1371,9 +1371,24 @@ static void gst_x264_enc_set_latency (GstX264Enc * encoder) { GstVideoInfo *info = &encoder->input_state->info; - GstClockTime latency = gst_util_uint64_scale (GST_SECOND * info->fps_d, - x264_encoder_maximum_delayed_frames (encoder->x264enc), info->fps_n); - gst_video_encoder_set_latency (GST_VIDEO_ENCODER (encoder), latency, latency); + + if (info->fps_n) { + GstClockTime latency; + gint max_delayed_frames; + max_delayed_frames = x264_encoder_maximum_delayed_frames (encoder->x264enc); + latency = gst_util_uint64_scale_ceil (GST_SECOND * info->fps_d, + max_delayed_frames, info->fps_n); + + GST_INFO ("Updating latency to %" GST_TIME_FORMAT " (%d frames)", + GST_TIME_ARGS (latency), max_delayed_frames); + + gst_video_encoder_set_latency (GST_VIDEO_ENCODER (encoder), latency, + latency); + } else { + /* We can't do live as we don't know our latency */ + gst_video_encoder_set_latency (GST_VIDEO_ENCODER (encoder), + GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE); + } } static gboolean