From c3214e8deb6ced65ce5fc4a2941919011dc0e9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 28 Oct 2018 15:19:38 +0000 Subject: [PATCH] harness: Add API for proposing meta APIs from the allocation query https://bugzilla.gnome.org/show_bug.cgi?id=797350 --- docs/libs/gstreamer-libs-sections.txt | 2 + libs/gst/check/Makefile.am | 1 + libs/gst/check/gstharness.c | 59 +++++++++++++++++++++++++++ libs/gst/check/gstharness.h | 7 +++- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 2d6081d5c0..853dcaeaae 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -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 diff --git a/libs/gst/check/Makefile.am b/libs/gst/check/Makefile.am index f84cecd1aa..335f5ad334 100644 --- a/libs/gst/check/Makefile.am +++ b/libs/gst/check/Makefile.am @@ -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 \ diff --git a/libs/gst/check/gstharness.c b/libs/gst/check/gstharness.c index b276c39617..893d772581 100644 --- a/libs/gst/check/gstharness.c +++ b/libs/gst/check/gstharness.c @@ -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; @@ -2161,6 +2188,38 @@ gst_harness_set_propose_allocator (GstHarness * h, GstAllocator * allocator, priv->propose_allocation_params = *params; } +/** + * 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 diff --git a/libs/gst/check/gstharness.h b/libs/gst/check/gstharness.h index 5a81fe0a91..416d472da8 100644 --- a/libs/gst/check/gstharness.h +++ b/libs/gst/check/gstharness.h @@ -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