harness: Add API for proposing meta APIs from the allocation query
authorSebastian Dröge <sebastian@centricular.com>
Sun, 28 Oct 2018 15:19:38 +0000 (15:19 +0000)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 28 Oct 2018 17:05:27 +0000 (17:05 +0000)
https://bugzilla.gnome.org/show_bug.cgi?id=797350

docs/libs/gstreamer-libs-sections.txt
libs/gst/check/Makefile.am
libs/gst/check/gstharness.c
libs/gst/check/gstharness.h

index 2d6081d..853dcae 100644 (file)
@@ -1347,6 +1347,8 @@ gst_harness_set_upstream_latency
 gst_harness_set_propose_allocator
 gst_harness_get_allocator
 
+gst_harness_add_propose_allocation_meta
+
 gst_harness_add_src
 gst_harness_add_src_harness
 gst_harness_add_src_parse
index f84cecd..335f5ad 100644 (file)
@@ -107,6 +107,7 @@ LIBGSTCHECK_EXPORTED_FUNCS = \
        gst_harness_add_element_sink_pad \
        gst_harness_add_parse \
        gst_harness_add_probe \
+       gst_harness_add_propose_allocation_meta \
        gst_harness_add_sink \
        gst_harness_add_sink_harness \
        gst_harness_add_sink_parse \
index b276c39..893d772 100644 (file)
@@ -147,6 +147,19 @@ static GstStaticPadTemplate hsinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS_ANY);
 
+typedef struct
+{
+  GType api;
+  GstStructure *params;
+} ProposeMeta;
+
+static void
+propose_meta_clear (ProposeMeta * meta)
+{
+  if (meta->params)
+    gst_structure_free (meta->params);
+}
+
 struct _GstHarnessPrivate
 {
   gchar *element_sinkpad_name;
@@ -179,6 +192,8 @@ struct _GstHarnessPrivate
   GstAllocator *propose_allocator;
   GstAllocationParams propose_allocation_params;
 
+  GArray *propose_allocation_metas;
+
   gboolean blocking_push_mode;
   GCond blocking_push_cond;
   GMutex blocking_push_mutex;
@@ -390,6 +405,15 @@ gst_harness_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
         gst_query_add_allocation_param (query,
             priv->propose_allocator, &priv->propose_allocation_params);
 
+        if (priv->propose_allocation_metas) {
+          guint i;
+          for (i = 0; i < priv->propose_allocation_metas->len; i++) {
+            ProposeMeta *meta =
+                &g_array_index (priv->propose_allocation_metas, ProposeMeta, i);
+            gst_query_add_allocation_meta (query, meta->api, meta->params);
+          }
+        }
+
         GST_DEBUG_OBJECT (pad, "proposing allocation %" GST_PTR_FORMAT,
             priv->propose_allocator);
       }
@@ -1052,6 +1076,9 @@ gst_harness_teardown (GstHarness * h)
   gst_object_replace ((GstObject **) & priv->allocator, NULL);
   gst_object_replace ((GstObject **) & priv->pool, NULL);
 
+  if (priv->propose_allocation_metas)
+    g_array_unref (priv->propose_allocation_metas);
+
   /* if we hold the last ref, set to NULL */
   if (gst_harness_element_unref (h) == 0) {
     gboolean state_change;
@@ -2162,6 +2189,38 @@ gst_harness_set_propose_allocator (GstHarness * h, GstAllocator * allocator,
 }
 
 /**
+ * gst_harness_add_propose_allocation_meta:
+ * @h: a #GstHarness
+ * @api: a metadata API
+ * @params: (allow-none) (transfer none): API specific parameters
+ *
+ * Add api with params as one of the supported metadata API to propose when
+ * receiving an allocation query.
+ *
+ * MT safe.
+ *
+ * Since: 1.16
+ */
+void
+gst_harness_add_propose_allocation_meta (GstHarness * h, GType api,
+    const GstStructure * params)
+{
+  GstHarnessPrivate *priv = h->priv;
+  ProposeMeta meta;
+
+  meta.api = api;
+  meta.params = params ? gst_structure_copy (params) : NULL;
+
+  if (!priv->propose_allocation_metas) {
+    priv->propose_allocation_metas =
+        g_array_new (FALSE, FALSE, sizeof (ProposeMeta));
+    g_array_set_clear_func (priv->propose_allocation_metas,
+        (GDestroyNotify) propose_meta_clear);
+  }
+  g_array_append_val (priv->propose_allocation_metas, meta);
+}
+
+/**
  * gst_harness_add_src_harness:
  * @h: a #GstHarness
  * @src_harness: (transfer full): a #GstHarness to be added as a src-harness.
index 5a81fe0..416d472 100644 (file)
@@ -257,7 +257,7 @@ GstClockTime gst_harness_query_latency (GstHarness * h);
 GST_CHECK_API
 void         gst_harness_set_upstream_latency (GstHarness * h, GstClockTime latency);
 
-/* allocator and allocation params */
+/* allocation query parameters */
 
 GST_CHECK_API
 void         gst_harness_set_propose_allocator (GstHarness                * h,
@@ -269,6 +269,11 @@ void         gst_harness_get_allocator         (GstHarness          * h,
                                                 GstAllocator       ** allocator,
                                                 GstAllocationParams * params);
 
+GST_CHECK_API
+void         gst_harness_add_propose_allocation_meta (GstHarness                * h,
+                                                      GType                       api,
+                                                      const GstStructure        * params);
+
 /* src-harness */
 
 GST_CHECK_API