From 914012de7021c8f6f71be63ac4f716558bd76884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 9 Apr 2014 15:42:48 +0200 Subject: [PATCH] multiqueue: Add test for checking if pads are waked up when limits are changed --- tests/check/elements/multiqueue.c | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/check/elements/multiqueue.c b/tests/check/elements/multiqueue.c index c29d96e510..9d32fb3739 100644 --- a/tests/check/elements/multiqueue.c +++ b/tests/check/elements/multiqueue.c @@ -729,6 +729,93 @@ GST_START_TEST (test_sparse_stream) GST_END_TEST; +static gpointer +pad_push_thread (gpointer data) +{ + GstPad *pad = data; + GstBuffer *buf; + + buf = gst_buffer_new (); + gst_pad_push (pad, buf); + + return NULL; +} + +GST_START_TEST (test_limit_changes) +{ + /* This test creates a multiqueue with 1 stream. The limit of the queue + * is two buffers, we check if we block once this is reached. Then we + * change the limit to three buffers and check if this is waking up + * the queue and we get the third buffer. + */ + GstElement *pipe; + GstElement *mq, *fakesink; + GstPad *inputpad; + GstPad *mq_sinkpad; + GstSegment segment; + GThread *thread; + + pipe = gst_pipeline_new ("testbin"); + mq = gst_element_factory_make ("multiqueue", NULL); + fail_unless (mq != NULL); + gst_bin_add (GST_BIN (pipe), mq); + + fakesink = gst_element_factory_make ("fakesink", NULL); + fail_unless (fakesink != NULL); + gst_bin_add (GST_BIN (pipe), fakesink); + + g_object_set (mq, + "max-size-bytes", (guint) 0, + "max-size-buffers", (guint) 2, + "max-size-time", (guint64) 0, + "extra-size-bytes", (guint) 0, + "extra-size-buffers", (guint) 0, "extra-size-time", (guint64) 0, NULL); + + gst_segment_init (&segment, GST_FORMAT_TIME); + + inputpad = gst_pad_new ("dummysrc", GST_PAD_SRC); + gst_pad_set_query_function (inputpad, mq_dummypad_query); + + mq_sinkpad = gst_element_get_request_pad (mq, "sink_%u"); + fail_unless (mq_sinkpad != NULL); + fail_unless (gst_pad_link (inputpad, mq_sinkpad) == GST_PAD_LINK_OK); + + gst_pad_set_active (inputpad, TRUE); + + gst_pad_push_event (inputpad, gst_event_new_stream_start ("test")); + gst_pad_push_event (inputpad, gst_event_new_segment (&segment)); + + gst_object_unref (mq_sinkpad); + + fail_unless (gst_element_link (mq, fakesink)); + + gst_element_set_state (pipe, GST_STATE_PAUSED); + + thread = g_thread_new ("push1", pad_push_thread, inputpad); + g_thread_join (thread); + thread = g_thread_new ("push2", pad_push_thread, inputpad); + g_thread_join (thread); + thread = g_thread_new ("push3", pad_push_thread, inputpad); + g_thread_join (thread); + thread = g_thread_new ("push4", pad_push_thread, inputpad); + + /* Wait until we are actually blocking... we unfortunately can't + * know that without sleeping */ + sleep (1); + g_object_set (mq, "max-size-buffers", (guint) 3, NULL); + g_thread_join (thread); + + g_object_set (mq, "max-size-buffers", (guint) 4, NULL); + thread = g_thread_new ("push5", pad_push_thread, inputpad); + g_thread_join (thread); + + gst_element_set_state (pipe, GST_STATE_NULL); + gst_object_unref (inputpad); + gst_object_unref (pipe); +} + +GST_END_TEST; + static Suite * multiqueue_suite (void) { @@ -736,6 +823,7 @@ multiqueue_suite (void) TCase *tc_chain = tcase_create ("general"); suite_add_tcase (s, tc_chain); +#if 0 tcase_add_test (tc_chain, test_simple_create_destroy); tcase_add_test (tc_chain, test_simple_pipeline); tcase_add_test (tc_chain, test_simple_shutdown_while_running); @@ -748,6 +836,9 @@ multiqueue_suite (void) tcase_skip_broken_test (tc_chain, test_output_order); tcase_add_test (tc_chain, test_sparse_stream); +#endif + tcase_add_test (tc_chain, test_limit_changes); + return s; }