v4l2bufferpool: set v4l2_buffer.field when queuing buffer in an output device
authorAurélien Zanelli <aurelien.zanelli@parrot.com>
Thu, 15 Jan 2015 15:11:53 +0000 (16:11 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Wed, 25 Feb 2015 15:27:30 +0000 (10:27 -0500)
According to the current specification, application must set this field
for an output device.

https://bugzilla.gnome.org/show_bug.cgi?id=743013

sys/v4l2/gstv4l2bufferpool.c

index 11201f9..52df37c 100644 (file)
@@ -1003,6 +1003,7 @@ static GstFlowReturn
 gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf)
 {
   GstV4l2MemoryGroup *group = NULL;
+  const GstV4l2Object *obj = pool->obj;
   gint index;
 
   if (!gst_v4l2_is_buffer_valid (buf, &group)) {
@@ -1021,6 +1022,28 @@ gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf)
   g_atomic_int_inc (&pool->num_queued);
   pool->buffers[index] = buf;
 
+  if (V4L2_TYPE_IS_OUTPUT (obj->type)) {
+    enum v4l2_field field;
+
+    /* Except when field is set to alternate, buffer field is the same as
+     * the one defined in format */
+    if (V4L2_TYPE_IS_MULTIPLANAR (obj->type))
+      field = obj->format.fmt.pix_mp.field;
+    else
+      field = obj->format.fmt.pix.field;
+
+    /* NB: At this moment, we can't have alternate mode because it not handled
+     * yet */
+    if (field == V4L2_FIELD_ALTERNATE) {
+      if (GST_BUFFER_FLAG_IS_SET (buf, GST_VIDEO_FRAME_FLAG_TFF))
+        field = V4L2_FIELD_TOP;
+      else
+        field = V4L2_FIELD_BOTTOM;
+    }
+
+    group->buffer.field = field;
+  }
+
   if (!gst_v4l2_allocator_qbuf (pool->vallocator, group))
     goto queue_failed;