ghostpad: Add a fixed unit test for caps propagation and notify::caps events

This commit is contained in:
Sebastian Dröge 2012-06-08 12:55:51 +02:00
parent d563379085
commit 36b8bee85e

View file

@ -670,6 +670,152 @@ GST_START_TEST (test_ghost_pads_new_no_target_from_template)
GST_END_TEST;
static void
ghost_notify_caps (GObject * object, GParamSpec * pspec, gpointer * user_data)
{
GST_DEBUG ("caps notify called");
(*(gint *) user_data)++;
}
static GstFlowReturn
dummy_chain (GstPad * pad, GstBuffer * buffer)
{
gst_buffer_unref (buffer);
return GST_FLOW_OK;
}
GST_START_TEST (test_ghost_pads_forward_setcaps)
{
GstCaps *templ_caps, *caps1, *caps2, *caps3;
GstPadTemplate *src_template, *sink_template;
GstPad *src, *ghost, *sink;
gint notify_counter = 0;
GstBuffer *buffer;
templ_caps = gst_caps_from_string ("meh; muh");
src_template = gst_pad_template_new ("src", GST_PAD_SRC,
GST_PAD_ALWAYS, templ_caps);
templ_caps = gst_caps_from_string ("muh; meh");
sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
GST_PAD_ALWAYS, templ_caps);
src = gst_pad_new_from_template (src_template, "src");
sink = gst_pad_new_from_template (sink_template, "sink");
gst_pad_set_chain_function (sink, dummy_chain);
gst_pad_set_active (src, TRUE);
gst_pad_set_active (sink, TRUE);
/* ghost source pad, setting caps on the source influences the caps of the
* ghostpad. */
ghost = gst_ghost_pad_new ("ghostsrc", src);
g_signal_connect (ghost, "notify::caps",
G_CALLBACK (ghost_notify_caps), &notify_counter);
gst_pad_set_active (ghost, TRUE);
fail_unless (gst_pad_link (ghost, sink) == GST_PAD_LINK_OK);
caps1 = gst_caps_from_string ("meh");
fail_unless (gst_pad_set_caps (src, caps1));
buffer = gst_buffer_new ();
gst_buffer_set_caps (buffer, caps1);
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
caps2 = GST_PAD_CAPS (ghost);
fail_unless (gst_caps_is_equal (caps1, caps2));
fail_unless_equals_int (notify_counter, 1);
gst_pad_unlink (ghost, sink);
gst_object_unref (ghost);
gst_caps_unref (caps1);
fail_unless (gst_pad_set_caps (src, NULL));
/* source 2, setting the caps on the ghostpad does not influence the caps of
* the target */
notify_counter = 0;
ghost = gst_ghost_pad_new ("ghostsrc", src);
g_signal_connect (ghost, "notify::caps",
G_CALLBACK (ghost_notify_caps), &notify_counter);
gst_pad_set_active (ghost, TRUE);
fail_unless (gst_pad_link (ghost, sink) == GST_PAD_LINK_OK);
caps1 = gst_caps_from_string ("meh");
fail_unless (gst_pad_set_caps (ghost, caps1));
caps2 = GST_PAD_CAPS (src);
fail_unless (caps2 == NULL);
buffer = gst_buffer_new ();
caps3 = gst_caps_from_string ("muh");
gst_buffer_set_caps (buffer, caps3);
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
caps2 = GST_PAD_CAPS (src);
fail_unless (gst_caps_is_equal (caps3, caps2));
fail_unless_equals_int (notify_counter, 2);
gst_pad_unlink (ghost, sink);
gst_object_unref (ghost);
gst_caps_unref (caps1);
gst_caps_unref (caps3);
/* ghost sink pad. Setting caps on the ghostpad will also set those caps on
* the target pad. */
notify_counter = 0;
ghost = gst_ghost_pad_new ("ghostsink", sink);
g_signal_connect (ghost, "notify::caps",
G_CALLBACK (ghost_notify_caps), &notify_counter);
gst_pad_set_active (ghost, TRUE);
fail_unless (gst_pad_link (src, ghost) == GST_PAD_LINK_OK);
caps1 = gst_caps_from_string ("muh");
fail_unless (gst_pad_set_caps (ghost, caps1));
buffer = gst_buffer_new ();
gst_buffer_set_caps (buffer, caps1);
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
caps2 = GST_PAD_CAPS (sink);
fail_unless (gst_caps_is_equal (caps1, caps2));
fail_unless_equals_int (notify_counter, 2);
gst_pad_unlink (src, ghost);
gst_object_unref (ghost);
gst_caps_unref (caps1);
/* sink pad 2, setting caps just on the target pad should not influence the caps
* on the ghostpad. */
notify_counter = 0;
ghost = gst_ghost_pad_new ("ghostsink", sink);
g_signal_connect (ghost, "notify::caps",
G_CALLBACK (ghost_notify_caps), &notify_counter);
gst_pad_set_active (ghost, TRUE);
fail_unless (gst_pad_link (src, ghost) == GST_PAD_LINK_OK);
caps1 = gst_caps_from_string ("muh");
fail_unless (gst_pad_set_caps (sink, caps1));
caps2 = GST_PAD_CAPS (ghost);
fail_unless (caps2 == NULL);
buffer = gst_buffer_new ();
caps3 = gst_caps_from_string ("meh");
gst_buffer_set_caps (buffer, caps3);
fail_unless (gst_pad_push (src, buffer) == GST_FLOW_OK);
caps2 = GST_PAD_CAPS (ghost);
fail_unless (gst_caps_is_equal (caps3, caps2));
fail_unless_equals_int (notify_counter, 2);
gst_pad_unlink (src, ghost);
gst_object_unref (ghost);
gst_caps_unref (caps1);
gst_caps_unref (caps3);
gst_object_unref (src);
gst_object_unref (sink);
gst_object_unref (src_template);
gst_object_unref (sink_template);
}
GST_END_TEST;
static gint linked_count1;
static gint unlinked_count1;
static gint linked_count2;
@ -996,6 +1142,7 @@ gst_ghost_pad_suite (void)
tcase_add_test (tc_chain, test_ghost_pads_probes);
tcase_add_test (tc_chain, test_ghost_pads_new_from_template);
tcase_add_test (tc_chain, test_ghost_pads_new_no_target_from_template);
tcase_add_test (tc_chain, test_ghost_pads_forward_setcaps);
tcase_add_test (tc_chain, test_ghost_pads_sink_link_unlink);
tcase_add_test (tc_chain, test_ghost_pads_src_link_unlink);
tcase_add_test (tc_chain, test_ghost_pads_change_when_linked);