mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
valve: don't send sticky events as a direct response to upstream events
Also refactor the existing valve test to actually test the valve, and not just test the EOS mechanism of a pad. https://bugzilla.gnome.org/show_bug.cgi?id=763753
This commit is contained in:
parent
fdd5d22828
commit
1bc8d9f2ea
2 changed files with 50 additions and 70 deletions
|
@ -67,7 +67,7 @@ static void gst_valve_get_property (GObject * object,
|
||||||
|
|
||||||
static GstFlowReturn gst_valve_chain (GstPad * pad, GstObject * parent,
|
static GstFlowReturn gst_valve_chain (GstPad * pad, GstObject * parent,
|
||||||
GstBuffer * buffer);
|
GstBuffer * buffer);
|
||||||
static gboolean gst_valve_event (GstPad * pad, GstObject * parent,
|
static gboolean gst_valve_sink_event (GstPad * pad, GstObject * parent,
|
||||||
GstEvent * event);
|
GstEvent * event);
|
||||||
static gboolean gst_valve_query (GstPad * pad, GstObject * parent,
|
static gboolean gst_valve_query (GstPad * pad, GstObject * parent,
|
||||||
GstQuery * query);
|
GstQuery * query);
|
||||||
|
@ -110,8 +110,6 @@ gst_valve_init (GstValve * valve)
|
||||||
valve->discont = FALSE;
|
valve->discont = FALSE;
|
||||||
|
|
||||||
valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
|
valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
|
||||||
gst_pad_set_event_function (valve->srcpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_event));
|
|
||||||
gst_pad_set_query_function (valve->srcpad,
|
gst_pad_set_query_function (valve->srcpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_query));
|
GST_DEBUG_FUNCPTR (gst_valve_query));
|
||||||
GST_PAD_SET_PROXY_CAPS (valve->srcpad);
|
GST_PAD_SET_PROXY_CAPS (valve->srcpad);
|
||||||
|
@ -121,7 +119,7 @@ gst_valve_init (GstValve * valve)
|
||||||
gst_pad_set_chain_function (valve->sinkpad,
|
gst_pad_set_chain_function (valve->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_chain));
|
GST_DEBUG_FUNCPTR (gst_valve_chain));
|
||||||
gst_pad_set_event_function (valve->sinkpad,
|
gst_pad_set_event_function (valve->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_event));
|
GST_DEBUG_FUNCPTR (gst_valve_sink_event));
|
||||||
gst_pad_set_query_function (valve->sinkpad,
|
gst_pad_set_query_function (valve->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_query));
|
GST_DEBUG_FUNCPTR (gst_valve_query));
|
||||||
GST_PAD_SET_PROXY_CAPS (valve->sinkpad);
|
GST_PAD_SET_PROXY_CAPS (valve->sinkpad);
|
||||||
|
@ -216,7 +214,7 @@ gst_valve_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_valve_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
gst_valve_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||||
{
|
{
|
||||||
GstValve *valve;
|
GstValve *valve;
|
||||||
gboolean is_sticky = GST_EVENT_IS_STICKY (event);
|
gboolean is_sticky = GST_EVENT_IS_STICKY (event);
|
||||||
|
|
|
@ -23,82 +23,62 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gst/check/gstcheck.h>
|
#include <gst/check/gstcheck.h>
|
||||||
|
#include <gst/check/gstharness.h>
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
|
||||||
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
||||||
GST_PAD_SINK,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS ("audio/x-raw"));
|
|
||||||
|
|
||||||
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
||||||
GST_PAD_SRC,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS ("audio/x-raw"));
|
|
||||||
|
|
||||||
gboolean event_received = FALSE;
|
|
||||||
gboolean buffer_allocated = FALSE;
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
event_func (GstPad * pad, GstObject * parent, GstEvent * event)
|
|
||||||
{
|
|
||||||
event_received = TRUE;
|
|
||||||
gst_event_unref (event);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_START_TEST (test_valve_basic)
|
GST_START_TEST (test_valve_basic)
|
||||||
{
|
{
|
||||||
GstElement *valve;
|
GstHarness *h = gst_harness_new ("valve");
|
||||||
GstPad *sink;
|
|
||||||
GstPad *src;
|
|
||||||
GstCaps *caps, *templ_caps;
|
|
||||||
|
|
||||||
valve = gst_check_setup_element ("valve");
|
/* when not dropping, we don't drop buffers.... */
|
||||||
|
g_object_set (h->element, "drop", FALSE, NULL);
|
||||||
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
|
gst_harness_push (h, gst_buffer_new ()));
|
||||||
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
|
gst_harness_push (h, gst_buffer_new ()));
|
||||||
|
fail_unless_equals_int (2, gst_harness_buffers_received (h));
|
||||||
|
|
||||||
sink = gst_check_setup_sink_pad_by_name (valve, &sinktemplate, "src");
|
/* when dropping, the buffers don't make it through */
|
||||||
src = gst_check_setup_src_pad_by_name (valve, &srctemplate, "sink");
|
g_object_set (h->element, "drop", TRUE, NULL);
|
||||||
gst_pad_set_event_function (sink, event_func);
|
fail_unless_equals_int (1, gst_harness_events_received (h));
|
||||||
gst_pad_set_active (src, TRUE);
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
gst_pad_set_active (sink, TRUE);
|
gst_harness_push (h, gst_buffer_new ()));
|
||||||
gst_element_set_state (valve, GST_STATE_PLAYING);
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
|
gst_harness_push (h, gst_buffer_new ()));
|
||||||
|
fail_unless_equals_int (2, gst_harness_buffers_received (h));
|
||||||
|
|
||||||
g_object_set (valve, "drop", FALSE, NULL);
|
gst_harness_teardown (h);
|
||||||
|
}
|
||||||
|
|
||||||
fail_unless (gst_pad_push_event (src, gst_event_new_eos ()) == TRUE);
|
GST_END_TEST;
|
||||||
fail_unless (event_received == TRUE);
|
|
||||||
fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_EOS);
|
|
||||||
fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_EOS);
|
|
||||||
fail_unless (buffers == NULL);
|
|
||||||
caps = gst_pad_query_caps (src, NULL);
|
|
||||||
templ_caps = gst_pad_get_pad_template_caps (src);
|
|
||||||
fail_unless (caps && gst_caps_is_equal (caps, templ_caps));
|
|
||||||
gst_caps_unref (templ_caps);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
gst_check_drop_buffers ();
|
GST_START_TEST (test_valve_upstream_events_dont_send_sticky)
|
||||||
fail_unless (gst_pad_push_event (src, gst_event_new_flush_start ()) == TRUE);
|
{
|
||||||
fail_unless (gst_pad_push_event (src,
|
GstHarness *h = gst_harness_new ("valve");
|
||||||
gst_event_new_flush_stop (TRUE)) == TRUE);
|
|
||||||
event_received = buffer_allocated = FALSE;
|
|
||||||
|
|
||||||
g_object_set (valve, "drop", TRUE, NULL);
|
/* set to drop */
|
||||||
fail_unless (gst_pad_push_event (src, gst_event_new_eos ()) == TRUE);
|
g_object_set (h->element, "drop", TRUE, NULL);
|
||||||
fail_unless (event_received == FALSE);
|
|
||||||
fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_EOS);
|
|
||||||
fail_unless (gst_pad_push (src, gst_buffer_new ()) == GST_FLOW_EOS);
|
|
||||||
fail_unless (buffers == NULL);
|
|
||||||
caps = gst_pad_query_caps (src, NULL);
|
|
||||||
templ_caps = gst_pad_get_pad_template_caps (src);
|
|
||||||
fail_unless (caps && gst_caps_is_equal (caps, templ_caps));
|
|
||||||
gst_caps_unref (templ_caps);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
gst_pad_set_active (src, FALSE);
|
/* set caps to trigger sticky-events being pushed to valve */
|
||||||
gst_pad_set_active (sink, FALSE);
|
gst_harness_set_src_caps_str (h, "mycaps");
|
||||||
gst_check_teardown_src_pad (valve);
|
|
||||||
gst_check_teardown_sink_pad (valve);
|
/* verify no events have made it through yet */
|
||||||
gst_check_teardown_element (valve);
|
fail_unless_equals_int (0, gst_harness_events_received (h));
|
||||||
|
|
||||||
|
/* stop dropping */
|
||||||
|
g_object_set (h->element, "drop", FALSE, NULL);
|
||||||
|
|
||||||
|
/* send an upstream event and verify that no
|
||||||
|
downstream events was pushed as a result of this */
|
||||||
|
gst_harness_push_upstream_event (h, gst_event_new_reconfigure ());
|
||||||
|
fail_unless_equals_int (0, gst_harness_events_received (h));
|
||||||
|
|
||||||
|
/* push a buffer, and verify this pushes the sticky events */
|
||||||
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
|
gst_harness_push (h, gst_buffer_new ()));
|
||||||
|
fail_unless_equals_int (3, gst_harness_events_received (h));
|
||||||
|
|
||||||
|
gst_harness_teardown (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
@ -111,6 +91,8 @@ valve_suite (void)
|
||||||
|
|
||||||
tc_chain = tcase_create ("valve_basic");
|
tc_chain = tcase_create ("valve_basic");
|
||||||
tcase_add_test (tc_chain, test_valve_basic);
|
tcase_add_test (tc_chain, test_valve_basic);
|
||||||
|
tcase_add_test (tc_chain, test_valve_upstream_events_dont_send_sticky);
|
||||||
|
|
||||||
suite_add_tcase (s, tc_chain);
|
suite_add_tcase (s, tc_chain);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in a new issue