harness: Add event stress test functions with callback
authorStian Selnes <stian@pexip.com>
Thu, 21 Jan 2016 12:28:23 +0000 (13:28 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 12 Feb 2016 19:32:29 +0000 (19:32 +0000)
Similar to the stress test functions for buffers that has a callback to
create the buffer to be pushed, it's useful to have functions that use a
callback to create the event to be pushed.

API: gst_harness_stress_push_event_with_cb_start()
API: gst_harness_stress_push_event_with_cb_start_full()
API: gst_harness_stress_send_upstream_event_with_cb_start()
API: gst_harness_stress_push_upstream_event_with_cb_start_full()

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

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

index 48c65fc..09d0b11 100644 (file)
@@ -1313,9 +1313,16 @@ gst_harness_stress_push_buffer_with_cb_start_full
 gst_harness_stress_push_event_start
 gst_harness_stress_push_event_start_full
 
+GstHarnessPrepareEventFunc
+gst_harness_stress_push_event_with_cb_start
+gst_harness_stress_push_event_with_cb_start_full
+
 gst_harness_stress_send_upstream_event_start
 gst_harness_stress_push_upstream_event_start_full
 
+gst_harness_stress_send_upstream_event_with_cb_start
+gst_harness_stress_push_upstream_event_with_cb_start_full
+
 gst_harness_stress_property_start
 gst_harness_stress_property_start_full
 
index 5333963..62fcb78 100644 (file)
@@ -158,7 +158,9 @@ LIBGSTCHECK_EXPORTED_FUNCS = \
        gst_harness_stress_push_buffer_start_full \
        gst_harness_stress_push_buffer_with_cb_start_full \
        gst_harness_stress_push_event_start_full \
+       gst_harness_stress_push_event_with_cb_start_full \
        gst_harness_stress_push_upstream_event_start_full \
+       gst_harness_stress_push_upstream_event_with_cb_start_full \
        gst_harness_stress_requestpad_start_full \
        gst_harness_stress_statechange_start_full \
        gst_harness_stress_thread_stop \
index e9b033c..9f923c1 100644 (file)
@@ -2543,7 +2543,9 @@ typedef struct
 {
   GstHarnessThread t;
 
-  GstEvent *event;
+  GstHarnessPrepareEventFunc func;
+  gpointer data;
+  GDestroyNotify notify;
 } GstHarnessPushEventThread;
 
 typedef struct
@@ -2604,7 +2606,8 @@ static void
 gst_harness_push_event_thread_free (GstHarnessPushEventThread * t)
 {
   if (t != NULL) {
-    gst_event_replace (&t->event, NULL);
+    if (t->notify != NULL)
+      t->notify (t->data);
     g_slice_free (GstHarnessPushEventThread, t);
   }
 }
@@ -2775,7 +2778,7 @@ gst_harness_stress_event_func (GstHarnessThread * t)
   guint count = 0;
 
   while (t->running) {
-    gst_harness_push_event (t->h, gst_event_ref (pet->event));
+    gst_harness_push_event (t->h, pet->func (t->h, pet->data));
 
     count++;
     g_usleep (t->sleep);
@@ -2790,7 +2793,7 @@ gst_harness_stress_upstream_event_func (GstHarnessThread * t)
   guint count = 0;
 
   while (t->running) {
-    gst_harness_push_upstream_event (t->h, gst_event_ref (pet->event));
+    gst_harness_push_upstream_event (t->h, pet->func (t->h, pet->data));
 
     count++;
     g_usleep (t->sleep);
@@ -2934,6 +2937,13 @@ gst_harness_ref_buffer (GstHarness * h, gpointer data)
   return gst_buffer_ref (GST_BUFFER_CAST (data));
 }
 
+static GstEvent *
+gst_harness_ref_event (GstHarness * h, gpointer data)
+{
+  (void) h;
+  return gst_event_ref (GST_EVENT_CAST (data));
+}
+
 /**
  * gst_harness_stress_push_buffer_start_full: (skip)
  * @h: a #GstHarness
@@ -3020,11 +3030,43 @@ GstHarnessThread *
 gst_harness_stress_push_event_start_full (GstHarness * h,
     GstEvent * event, gulong sleep)
 {
+  return gst_harness_stress_push_event_with_cb_start_full (h,
+      gst_harness_ref_event, gst_event_ref (event),
+      (GDestroyNotify) gst_event_unref, sleep);
+}
+
+/**
+ * gst_harness_stress_push_event_with_cb_start_full: (skip)
+ * @h: a #GstHarness
+ * @func: a #GstHarnessPrepareEventFunc function called before every iteration
+ * to prepare / create a #GstEvent for pushing
+ * @data: a #gpointer with data to the #GstHarnessPrepareEventFunc function
+ * @notify: a #GDestroyNotify that is called when thread is stopped
+ * @sleep: a #gulong specifying how long to sleep in (microseconds) for
+ * each call to gst_pad_push
+ *
+ * Push a #GstEvent returned by @func onto the harnessed #GstElement sinkpad
+ * in intervals of @sleep microseconds.
+ *
+ * MT safe.
+ *
+ * Returns: a #GstHarnessThread
+ *
+ * Since: 1.8
+ */
+GstHarnessThread *
+gst_harness_stress_push_event_with_cb_start_full (GstHarness * h,
+      GstHarnessPrepareEventFunc func, gpointer data, GDestroyNotify notify,
+      gulong sleep)
+{
   GstHarnessPushEventThread *t = g_slice_new0 (GstHarnessPushEventThread);
   gst_harness_thread_init (&t->t,
       (GDestroyNotify) gst_harness_push_event_thread_free, h, sleep);
 
-  t->event = gst_event_ref (event);
+  t->func = func;
+  t->data = data;
+  t->notify = notify;
+
   GST_HARNESS_THREAD_START (event, t);
   return &t->t;
 }
@@ -3049,11 +3091,43 @@ GstHarnessThread *
 gst_harness_stress_push_upstream_event_start_full (GstHarness * h,
     GstEvent * event, gulong sleep)
 {
+  return gst_harness_stress_push_upstream_event_with_cb_start_full (h,
+      gst_harness_ref_event, gst_event_ref (event),
+      (GDestroyNotify) gst_event_unref, sleep);
+}
+
+/**
+ * gst_harness_stress_push_upstream_event_with_cb_start_full: (skip)
+ * @h: a #GstHarness
+ * @func: a #GstHarnessPrepareEventFunc function called before every iteration
+ * to prepare / create a #GstEvent for pushing
+ * @data: a #gpointer with data to the #GstHarnessPrepareEventFunc function
+ * @notify: a #GDestroyNotify that is called when thread is stopped
+ * @sleep: a #gulong specifying how long to sleep in (microseconds) for
+ * each call to gst_pad_push
+ *
+ * Push a #GstEvent returned by @func onto the harnessed #GstElement srcpad
+ * in intervals of @sleep microseconds.
+ *
+ * MT safe.
+ *
+ * Returns: a #GstHarnessThread
+ *
+ * Since: 1.8
+ */
+GstHarnessThread *
+gst_harness_stress_push_upstream_event_with_cb_start_full (GstHarness * h,
+    GstHarnessPrepareEventFunc func, gpointer data, GDestroyNotify notify,
+    gulong sleep)
+{
   GstHarnessPushEventThread *t = g_slice_new0 (GstHarnessPushEventThread);
   gst_harness_thread_init (&t->t,
       (GDestroyNotify) gst_harness_push_event_thread_free, h, sleep);
 
-  t->event = gst_event_ref (event);
+  t->func = func;
+  t->data = data;
+  t->notify = notify;
+
   GST_HARNESS_THREAD_START (upstream_event, t);
   return &t->t;
 }
index 3c39f03..0937ba7 100644 (file)
@@ -316,6 +316,24 @@ GstHarnessThread * gst_harness_stress_push_event_start_full (GstHarness * h,
                                                              GstEvent   * event,
                                                              gulong       sleep);
 
+/**
+ * GstHarnessPrepareEventFunc:
+ * @h: a #GstHarness
+ * @data: user data
+ *
+ * Since: 1.8
+ */
+typedef GstEvent * (*GstHarnessPrepareEventFunc) (GstHarness * h, gpointer data);
+
+#define gst_harness_stress_push_event_with_cb_start(h, f, d, n)                \
+  gst_harness_stress_push_event_with_cb_start_full (h, f, d, n, 0)
+
+GstHarnessThread * gst_harness_stress_push_event_with_cb_start_full (GstHarness   * h,
+                                                                     GstHarnessPrepareEventFunc func,
+                                                                     gpointer       data,
+                                                                     GDestroyNotify notify,
+                                                                     gulong         sleep);
+
 #define gst_harness_stress_send_upstream_event_start(h, e)                     \
   gst_harness_stress_push_upstream_event_start_full (h, e, 0)
 
@@ -323,6 +341,16 @@ GstHarnessThread * gst_harness_stress_push_upstream_event_start_full (GstHarness
                                                                       GstEvent   * event,
                                                                       gulong       sleep);
 
+#define gst_harness_stress_send_upstream_event_with_cb_start(h, f, d, n)       \
+  gst_harness_stress_push_upstream_event_with_cb_start_full (h, f, d, n, 0)
+
+GstHarnessThread * gst_harness_stress_push_upstream_event_with_cb_start_full (GstHarness   * h,
+                                                                              GstHarnessPrepareEventFunc func,
+                                                                              gpointer       data,
+                                                                              GDestroyNotify notify,
+                                                                              gulong         sleep);
+
+
 #define gst_harness_stress_property_start(h, n, v)                             \
   gst_harness_stress_property_start_full (h, n, v, G_USEC_PER_SEC / 1000)