v4l2: Move propose allocation to v4l2object
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 27 Mar 2014 17:20:53 +0000 (13:20 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 8 May 2014 19:56:36 +0000 (15:56 -0400)
sys/v4l2/gstv4l2object.c
sys/v4l2/gstv4l2object.h
sys/v4l2/gstv4l2sink.c

index ab06ebf..16c9474 100644 (file)
@@ -3169,3 +3169,63 @@ pool_failed:
     return FALSE;
   }
 }
+
+gboolean
+gst_v4l2_object_propose_allocation (GstV4l2Object * obj, GstQuery * query)
+{
+  GstBufferPool *pool;
+  guint size = 0;
+  GstCaps *caps;
+  gboolean need_pool;
+
+  gst_query_parse_allocation (query, &caps, &need_pool);
+
+  if (caps == NULL)
+    goto no_caps;
+
+  if ((pool = obj->pool))
+    gst_object_ref (pool);
+
+  if (pool != NULL) {
+    GstCaps *pcaps;
+    GstStructure *config;
+
+    /* we had a pool, check caps */
+    config = gst_buffer_pool_get_config (pool);
+    gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
+
+    GST_DEBUG_OBJECT (obj->element,
+        "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
+    if (!gst_caps_is_equal (caps, pcaps)) {
+      gst_structure_free (config);
+      gst_object_unref (pool);
+      goto different_caps;
+    }
+    gst_structure_free (config);
+  }
+  /* we need at least 2 buffers to operate */
+  gst_query_add_allocation_pool (query, pool, size, 2, 0);
+
+  /* we also support various metadata */
+  /* FIXME should it be set per class ? */
+  gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
+  gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
+
+  if (pool)
+    gst_object_unref (pool);
+
+  return TRUE;
+
+  /* ERRORS */
+no_caps:
+  {
+    GST_DEBUG_OBJECT (obj->element, "no caps specified");
+    return FALSE;
+  }
+different_caps:
+  {
+    /* different caps, we can't use this pool */
+    GST_DEBUG_OBJECT (obj->element, "pool has different caps");
+    return FALSE;
+  }
+}
index 6bea091..39e9b5c 100644 (file)
@@ -268,6 +268,9 @@ gboolean      gst_v4l2_object_set_crop    (GstV4l2Object * obj);
 gboolean      gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
                                                  GstQuery * query);
 
+gboolean      gst_v4l2_object_propose_allocation (GstV4l2Object * obj,
+                                                  GstQuery * query);
+
 GstStructure * gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);
 
 
index 41989d5..458eaba 100644 (file)
@@ -536,61 +536,7 @@ static gboolean
 gst_v4l2sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
 {
   GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink);
-  GstV4l2Object *obj = v4l2sink->v4l2object;
-  GstBufferPool *pool;
-  guint size = 0;
-  GstCaps *caps;
-  gboolean need_pool;
-
-  gst_query_parse_allocation (query, &caps, &need_pool);
-
-  if (caps == NULL)
-    goto no_caps;
-
-  if ((pool = obj->pool))
-    gst_object_ref (pool);
-
-  if (pool != NULL) {
-    GstCaps *pcaps;
-    GstStructure *config;
-
-    /* we had a pool, check caps */
-    config = gst_buffer_pool_get_config (pool);
-    gst_buffer_pool_config_get_params (config, &pcaps, &size, NULL, NULL);
-
-    GST_DEBUG_OBJECT (v4l2sink,
-        "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
-    if (!gst_caps_is_equal (caps, pcaps)) {
-      gst_structure_free (config);
-      gst_object_unref (pool);
-      goto different_caps;
-    }
-    gst_structure_free (config);
-  }
-  /* we need at least 2 buffers to operate */
-  gst_query_add_allocation_pool (query, pool, size, 2, 0);
-
-  /* we also support various metadata */
-  gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
-  gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
-
-  if (pool)
-    gst_object_unref (pool);
-
-  return TRUE;
-
-  /* ERRORS */
-no_caps:
-  {
-    GST_DEBUG_OBJECT (v4l2sink, "no caps specified");
-    return FALSE;
-  }
-different_caps:
-  {
-    /* different caps, we can't use this pool */
-    GST_DEBUG_OBJECT (v4l2sink, "pool has different caps");
-    return FALSE;
-  }
+  return gst_v4l2_object_propose_allocation (v4l2sink->v4l2object, query);
 }
 
 /* called after A/V sync to render frame */