From bd51c37196e34f7085698ded049d2fad2b01db24 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 19 Dec 2013 15:26:52 -0500 Subject: [PATCH] v4l2videodec: Calculate latency from device information Decoders or other devices that expose a minimum buffers required produce an first output. We use this information to calculate latency. https://bugzilla.gnome.org/show_bug.cgi?id=722128 --- sys/v4l2/gstv4l2object.c | 1 + sys/v4l2/gstv4l2object.h | 4 ++++ sys/v4l2/gstv4l2videodec.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 2b0358af3c..bcca2dd438 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -3296,6 +3296,7 @@ gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query) if (v4l2_ioctl (obj->video_fd, VIDIOC_G_CTRL, &ctl) >= 0) { GST_DEBUG_OBJECT (obj->element, "driver require a minimum of %d buffers", ctl.value); + obj->min_buffers_for_capture = ctl.value; min += ctl.value; } diff --git a/sys/v4l2/gstv4l2object.h b/sys/v4l2/gstv4l2object.h index 9dcc6eca02..5d3b27fc8f 100644 --- a/sys/v4l2/gstv4l2object.h +++ b/sys/v4l2/gstv4l2object.h @@ -137,6 +137,10 @@ struct _GstV4l2Object { */ gboolean prefered_non_contiguous; + /* This will be set if supported in decide_allocation. It can be used to + * calculate the minimum latency of a m2m decoder. */ + guint32 min_buffers_for_capture; + /* wanted mode */ GstV4l2IOMode req_mode; diff --git a/sys/v4l2/gstv4l2videodec.c b/sys/v4l2/gstv4l2videodec.c index 48fb70d380..b5c2cb06b8 100644 --- a/sys/v4l2/gstv4l2videodec.c +++ b/sys/v4l2/gstv4l2videodec.c @@ -520,12 +520,17 @@ gst_v4l2_video_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) { GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder); + GstClockTime latency; gboolean ret = FALSE; if (gst_v4l2_object_decide_allocation (self->v4l2capture, query)) ret = GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder, query); + latency = self->v4l2capture->min_buffers_for_capture * + self->v4l2capture->duration; + gst_video_decoder_set_latency (decoder, latency, latency); + return ret; }