audiomixer: Replace racy timeout based tested with drain query

Using the drain query, we can be certain that the buffer has done going
through the aggregator by taking the stream locks.

https://bugzilla.gnome.org/show_bug.cgi?id=742684
This commit is contained in:
Olivier Crête 2015-01-22 17:41:24 -05:00 committed by Thibault Saunier
parent 402c0d4c5c
commit 0955a39a3d

View file

@ -891,36 +891,17 @@ GST_END_TEST;
static GstBuffer *handoff_buffer = NULL;
static gboolean
_quit (GMainLoop * ml)
{
g_main_loop_quit (ml);
return G_SOURCE_REMOVE;
}
static void
handoff_buffer_cb (GstElement * fakesink, GstBuffer * buffer, GstPad * pad,
GstClockTime * wanted_end)
gpointer user_data)
{
GST_DEBUG ("got buffer -- SIZE: %" G_GSIZE_FORMAT
" -- %p DURATION is %" GST_TIME_FORMAT " -- WANTED END %" GST_TIME_FORMAT,
" -- %p DURATION is %" GST_TIME_FORMAT,
gst_buffer_get_size (buffer), buffer,
GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)),
GST_TIME_ARGS (*wanted_end));
GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
gst_buffer_replace (&handoff_buffer, buffer);
/* Buffers we push in will be 'cut' into different smaller buffers,
* we make sure that the last chunck was pushes before we concider the buffer
* we pushed as being done */
if (main_loop && *wanted_end
&& *wanted_end <=
GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)) {
*wanted_end = 0;
g_idle_add ((GSourceFunc) _quit, main_loop);
}
}
/* check if clipping works as expected */
@ -936,14 +917,10 @@ GST_START_TEST (test_clip)
GstEvent *event;
GstBuffer *buffer;
GstCaps *caps;
GMainLoop *local_mainloop;
GstClockTime wanted_end = 0;
GstQuery *drain = gst_query_new_drain ();
GST_INFO ("preparing test");
local_mainloop = g_main_loop_new (NULL, FALSE);
main_loop = NULL;
/* build pipeline */
bin = gst_pipeline_new ("pipeline");
bus = gst_element_get_bus (bin);
@ -957,8 +934,7 @@ GST_START_TEST (test_clip)
audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
sink = gst_element_factory_make ("fakesink", "sink");
g_object_set (sink, "signal-handoffs", TRUE, NULL);
g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb,
&wanted_end);
g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL);
gst_bin_add_many (GST_BIN (bin), audiomixer, sink, NULL);
res = gst_element_link (audiomixer, sink);
@ -999,16 +975,13 @@ GST_START_TEST (test_clip)
buffer,
GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
ret = gst_pad_chain (sinkpad, buffer);
main_loop = local_mainloop;
ck_assert_int_eq (ret, GST_FLOW_OK);
/* The aggregation is done in a dedicated thread, so we can't
* not know when it is actually going to happen, so we just add\
* a 100 ms timeout to be able to then check that the aggregation
* did happen as we do not have much other choice.
* not know when it is actually going to happen, so we use a DRAIN query
* to wait for it to complete.
*/
g_timeout_add (100, (GSourceFunc) _quit, main_loop);
g_main_loop_run (main_loop);
ck_assert_int_eq (ret, GST_FLOW_OK);
gst_pad_query (sinkpad, drain);
fail_unless (handoff_buffer == NULL);
/* should be partially clipped */
@ -1016,15 +989,14 @@ GST_START_TEST (test_clip)
GST_BUFFER_TIMESTAMP (buffer) = 900 * GST_MSECOND;
GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
wanted_end = 135 * GST_MSECOND;
GST_DEBUG ("pushing buffer %p START %" GST_TIME_FORMAT " -- DURATION is %"
GST_TIME_FORMAT, buffer, GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
main_loop = local_mainloop;
ret = gst_pad_chain (sinkpad, buffer);
ck_assert_int_eq (ret, GST_FLOW_OK);
g_main_loop_run (main_loop);
gst_pad_query (sinkpad, drain);
fail_unless (handoff_buffer != NULL);
gst_buffer_replace (&handoff_buffer, NULL);
@ -1033,18 +1005,18 @@ GST_START_TEST (test_clip)
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
wanted_end = 390 * GST_MSECOND;
GST_DEBUG ("pushing buffer %p END is %" GST_TIME_FORMAT,
buffer,
GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
ret = gst_pad_chain (sinkpad, buffer);
ck_assert_int_eq (ret, GST_FLOW_OK);
g_main_loop_run (main_loop);
gst_pad_query (sinkpad, drain);
fail_unless (handoff_buffer != NULL);
gst_buffer_replace (&handoff_buffer, NULL);
fail_unless (handoff_buffer == NULL);
/* should be clipped and ok */
buffer = gst_buffer_new_and_alloc (44100);
GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
@ -1052,9 +1024,8 @@ GST_START_TEST (test_clip)
buffer,
GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
ret = gst_pad_chain (sinkpad, buffer);
g_timeout_add (100, (GSourceFunc) _quit, main_loop);
g_main_loop_run (main_loop);
ck_assert_int_eq (ret, GST_FLOW_OK);
gst_pad_query (sinkpad, drain);
fail_unless (handoff_buffer == NULL);
gst_element_release_request_pad (audiomixer, sinkpad);
@ -1063,6 +1034,7 @@ GST_START_TEST (test_clip)
gst_bus_remove_signal_watch (bus);
gst_object_unref (bus);
gst_object_unref (bin);
gst_query_unref (drain);
}
GST_END_TEST;