tests: add and remove pads only once
authorWim Taymans <wtaymans@redhat.com>
Fri, 9 May 2014 13:08:48 +0000 (15:08 +0200)
committerWim Taymans <wtaymans@redhat.com>
Fri, 9 May 2014 13:13:54 +0000 (15:13 +0200)
In this test we simulate a dynamic pad by watching the caps event.
Because of renegotiation in the base payloader now, this caps is sent
multiple times but we can only deal with 1 invocation, use a variable to
only 'add and remove' the pad once.

tests/check/gst/media.c

index f2a58ce..c7d680e 100644 (file)
@@ -214,17 +214,24 @@ static void
 on_notify_caps (GstPad * pad, GParamSpec * pspec, GstElement * pay)
 {
   GstCaps *caps;
+  static gboolean have_caps = FALSE;
 
   g_object_get (pad, "caps", &caps, NULL);
 
   GST_DEBUG ("notify %" GST_PTR_FORMAT, caps);
 
   if (caps) {
-    g_signal_emit_by_name (pay, "pad-added", pad);
-    g_signal_emit_by_name (pay, "no-more-pads", NULL);
+    if (!have_caps) {
+      g_signal_emit_by_name (pay, "pad-added", pad);
+      g_signal_emit_by_name (pay, "no-more-pads", NULL);
+      have_caps = TRUE;
+    }
     gst_caps_unref (caps);
   } else {
-    g_signal_emit_by_name (pay, "pad-removed", pad);
+    if (have_caps) {
+      g_signal_emit_by_name (pay, "pad-removed", pad);
+      have_caps = FALSE;
+    }
   }
 }