imagefreeze: Add test for bufferalloc passthrough

This commit is contained in:
Sebastian Dröge 2010-08-20 11:38:09 +02:00
parent 5cd240952e
commit 6b705ba6f5

View file

@ -66,25 +66,27 @@ setup_imagefreeze (const GstCaps * caps1, const GstCaps * caps2,
pipeline = gst_pipeline_new ("pipeline"); pipeline = gst_pipeline_new ("pipeline");
fail_unless (pipeline != NULL); fail_unless (pipeline != NULL);
videotestsrc = gst_element_factory_make ("videotestsrc", NULL); videotestsrc = gst_element_factory_make ("videotestsrc", "src");
fail_unless (videotestsrc != NULL); fail_unless (videotestsrc != NULL);
g_object_set (videotestsrc, "num-buffers", 1, NULL); g_object_set (videotestsrc, "num-buffers", 1, NULL);
capsfilter1 = gst_element_factory_make ("capsfilter", NULL); capsfilter1 = gst_element_factory_make ("capsfilter", "filter1");
fail_unless (capsfilter1 != NULL); fail_unless (capsfilter1 != NULL);
g_object_set (capsfilter1, "caps", caps1, NULL); g_object_set (capsfilter1, "caps", caps1, NULL);
imagefreeze = gst_element_factory_make ("imagefreeze", NULL); imagefreeze = gst_element_factory_make ("imagefreeze", "freeze");
fail_unless (imagefreeze != NULL); fail_unless (imagefreeze != NULL);
capsfilter2 = gst_element_factory_make ("capsfilter", NULL); capsfilter2 = gst_element_factory_make ("capsfilter", "filter2");
fail_unless (capsfilter2 != NULL); fail_unless (capsfilter2 != NULL);
g_object_set (capsfilter2, "caps", caps2, NULL); g_object_set (capsfilter2, "caps", caps2, NULL);
fakesink = gst_element_factory_make ("fakesink", NULL); fakesink = gst_element_factory_make ("fakesink", "sink");
fail_unless (fakesink != NULL); fail_unless (fakesink != NULL);
g_object_set (fakesink, "signal-handoffs", TRUE, "async", FALSE, NULL); g_object_set (fakesink, "signal-handoffs", TRUE, "async", FALSE, NULL);
g_signal_connect (fakesink, "handoff", sink_handoff, sink_handoff_data);
if (sink_handoff)
g_signal_connect (fakesink, "handoff", sink_handoff, sink_handoff_data);
gst_bin_add_many (GST_BIN (pipeline), videotestsrc, capsfilter1, imagefreeze, gst_bin_add_many (GST_BIN (pipeline), videotestsrc, capsfilter1, imagefreeze,
capsfilter2, fakesink, NULL); capsfilter2, fakesink, NULL);
@ -448,6 +450,102 @@ GST_START_TEST (test_imagefreeze_25_1_220ms_380ms)
GST_END_TEST; GST_END_TEST;
static GstBuffer *test_buffer = NULL;
static GstFlowReturn
test_bufferalloc (GstPad * pad, guint64 offset, guint size, GstCaps * caps,
GstBuffer ** buf)
{
fail_if (test_buffer != NULL);
test_buffer = gst_buffer_new_and_alloc (size);
gst_buffer_set_caps (test_buffer, caps);
*buf = gst_buffer_ref (test_buffer);
return GST_FLOW_OK;
}
static void
sink_handoff_cb_bufferalloc (GstElement * object, GstBuffer * buffer,
GstPad * pad, gpointer user_data)
{
guint *n_buffers = (guint *) user_data;
if (*n_buffers == G_MAXUINT)
return;
fail_unless (buffer->parent != NULL);
fail_unless (test_buffer != NULL);
fail_unless (buffer->parent == test_buffer);
*n_buffers = *n_buffers + 1;
}
GST_START_TEST (test_imagefreeze_bufferalloc)
{
GstElement *pipeline;
GstElement *sink;
GstPad *sinkpad;
GstCaps *caps1, *caps2;
GstBus *bus;
GMainLoop *loop;
guint n_buffers = G_MAXUINT;
caps1 =
gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
caps2 =
gst_video_format_new_caps (GST_VIDEO_FORMAT_xRGB, 640, 480, 25, 1, 1, 1);
pipeline =
setup_imagefreeze (caps1, caps2, G_CALLBACK (sink_handoff_cb_bufferalloc),
&n_buffers);
sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
fail_unless (sink != NULL);
sinkpad = gst_element_get_static_pad (sink, "sink");
fail_unless (sinkpad != NULL);
gst_pad_set_bufferalloc_function (sinkpad, test_bufferalloc);
gst_object_unref (sinkpad);
gst_object_unref (sink);
loop = g_main_loop_new (NULL, TRUE);
fail_unless (loop != NULL);
bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL);
gst_bus_add_watch (bus, bus_handler, loop);
gst_object_unref (bus);
fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PAUSED),
GST_STATE_CHANGE_SUCCESS);
fail_unless (gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET,
400 * GST_MSECOND));
n_buffers = 0;
fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
GST_STATE_CHANGE_SUCCESS);
g_main_loop_run (loop);
fail_unless (test_buffer != NULL);
fail_unless (n_buffers >= 1);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_buffer_unref (test_buffer);
test_buffer = NULL;
g_object_unref (pipeline);
g_main_loop_unref (loop);
gst_caps_unref (caps1);
gst_caps_unref (caps2);
}
GST_END_TEST;
static Suite * static Suite *
imagefreeze_suite (void) imagefreeze_suite (void)
{ {
@ -464,6 +562,8 @@ imagefreeze_suite (void)
tcase_add_test (tc_chain, test_imagefreeze_25_1_400ms_0ms); tcase_add_test (tc_chain, test_imagefreeze_25_1_400ms_0ms);
tcase_add_test (tc_chain, test_imagefreeze_25_1_220ms_380ms); tcase_add_test (tc_chain, test_imagefreeze_25_1_220ms_380ms);
tcase_add_test (tc_chain, test_imagefreeze_bufferalloc);
return s; return s;
} }