v4l2videodec: Calculate latency from device information
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 19 Dec 2013 20:26:52 +0000 (15:26 -0500)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 25 Feb 2014 19:29:10 +0000 (14:29 -0500)
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
sys/v4l2/gstv4l2object.h
sys/v4l2/gstv4l2videodec.c

index 2b0358a..bcca2dd 100644 (file)
@@ -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;
   }
 
index 9dcc6ec..5d3b27f 100644 (file)
@@ -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;
 
index 48fb70d..b5c2cb0 100644 (file)
@@ -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;
 }