harness: move creating of buffer and event queues to harness itself
authorHavard Graff <havard.graff@gmail.com>
Wed, 22 May 2019 08:09:47 +0000 (10:09 +0200)
committerHavard Graff <havard.graff@gmail.com>
Thu, 13 Jun 2019 07:45:03 +0000 (09:45 +0200)
By only having it on sinkpad-creation, it is racy to write a test
with a sometimes-pad (like a demuxer) that you want to pull from, having
the pull wait until the pad arrives and the buffer can be produced.

libs/gst/check/gstharness.c

index b1f734e34957345b039e5f3c7b487d6870c2ca20..be4c228eef5510b662eadea8e4cdc9ac370cf1d7 100644 (file)
@@ -540,13 +540,9 @@ static void
 gst_harness_setup_src_pad (GstHarness * h,
     GstStaticPadTemplate * src_tmpl, const gchar * element_sinkpad_name)
 {
-  GstHarnessPrivate *priv = h->priv;
   g_assert (src_tmpl);
   g_assert (h->srcpad == NULL);
 
-  priv->src_event_queue =
-      g_async_queue_new_full ((GDestroyNotify) gst_event_unref);
-
   /* sending pad */
   h->srcpad = gst_pad_new_from_static_template (src_tmpl, "src");
   g_assert (h->srcpad);
@@ -565,15 +561,9 @@ static void
 gst_harness_setup_sink_pad (GstHarness * h,
     GstStaticPadTemplate * sink_tmpl, const gchar * element_srcpad_name)
 {
-  GstHarnessPrivate *priv = h->priv;
   g_assert (sink_tmpl);
   g_assert (h->sinkpad == NULL);
 
-  priv->buffer_queue = g_async_queue_new_full (
-      (GDestroyNotify) gst_buffer_unref);
-  priv->sink_event_queue = g_async_queue_new_full (
-      (GDestroyNotify) gst_event_unref);
-
   /* receiving pad */
   h->sinkpad = gst_pad_new_from_static_template (sink_tmpl, "sink");
   g_assert (h->sinkpad);
@@ -668,6 +658,13 @@ gst_harness_new_empty (void)
   priv->drop_buffers = FALSE;
   priv->testclock = GST_TEST_CLOCK_CAST (gst_test_clock_new ());
 
+  priv->buffer_queue = g_async_queue_new_full (
+      (GDestroyNotify) gst_buffer_unref);
+  priv->src_event_queue = g_async_queue_new_full (
+      (GDestroyNotify) gst_event_unref);
+  priv->sink_event_queue = g_async_queue_new_full (
+      (GDestroyNotify) gst_event_unref);
+
   priv->propose_allocator = NULL;
   gst_allocation_params_init (&priv->propose_allocation_params);
 
@@ -1067,8 +1064,6 @@ gst_harness_teardown (GstHarness * h)
     GST_PAD_STREAM_UNLOCK (h->srcpad);
 
     gst_object_unref (h->srcpad);
-
-    g_async_queue_unref (priv->src_event_queue);
   }
 
   if (h->sinkpad) {
@@ -1087,9 +1082,6 @@ gst_harness_teardown (GstHarness * h)
     GST_PAD_STREAM_UNLOCK (h->sinkpad);
 
     gst_object_unref (h->sinkpad);
-
-    g_async_queue_unref (priv->buffer_queue);
-    g_async_queue_unref (priv->sink_event_queue);
   }
 
   gst_object_replace ((GstObject **) & priv->propose_allocator, NULL);
@@ -1114,6 +1106,10 @@ gst_harness_teardown (GstHarness * h)
   g_mutex_clear (&priv->blocking_push_mutex);
   g_mutex_clear (&priv->priv_mutex);
 
+  g_async_queue_unref (priv->buffer_queue);
+  g_async_queue_unref (priv->src_event_queue);
+  g_async_queue_unref (priv->sink_event_queue);
+
   g_ptr_array_unref (priv->stress);
 
   gst_object_unref (h->element);