3 * unit test for videofilter elements
5 * Copyright (C) <2006> Mark Nauwelaerts <manauw@skynet.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
26 #include <gst/video/video.h>
27 #include <gst/check/gstcheck.h>
29 gboolean have_eos = FALSE;
31 /* For ease of programming we use globals to keep refs for our floating
32 * src and sink pads we create; otherwise we always have to do get_pad,
33 * get_peer, and then remove references in every test function */
34 GstPad *mysrcpad, *mysinkpad;
36 #define VIDEO_CAPS_TEMPLATE_STRING \
37 GST_VIDEO_CAPS_YUV ("I420") ";" \
38 GST_VIDEO_CAPS_YUV ("AYUV") ";" \
39 GST_VIDEO_CAPS_YUV ("YUY2") ";" \
40 GST_VIDEO_CAPS_YUV ("UYVY") ";" \
41 GST_VIDEO_CAPS_YUV ("YVYU") ";" \
44 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
47 GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING)
49 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
52 GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING)
55 /* takes over reference for outcaps */
57 setup_filter (const gchar * name, const gchar * prop, va_list var_args)
61 GST_DEBUG ("setup_element");
62 element = gst_check_setup_element (name);
63 g_object_set_valist (G_OBJECT (element), prop, var_args);
64 mysrcpad = gst_check_setup_src_pad (element, &srctemplate, NULL);
65 gst_pad_set_active (mysrcpad, TRUE);
66 mysinkpad = gst_check_setup_sink_pad (element, &sinktemplate, NULL);
67 gst_pad_set_active (mysinkpad, TRUE);
73 cleanup_filter (GstElement * filter)
75 GST_DEBUG ("cleanup_element");
77 gst_check_teardown_src_pad (filter);
78 gst_check_teardown_sink_pad (filter);
79 gst_check_teardown_element (filter);
83 check_filter_caps (const gchar * name, GstCaps * caps, gint size,
84 gint num_buffers, const gchar * prop, va_list varargs)
87 GstBuffer *inbuffer, *outbuffer;
90 filter = setup_filter (name, prop, varargs);
91 fail_unless (gst_element_set_state (filter,
92 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
93 "could not set to playing");
95 for (i = 0; i < num_buffers; ++i) {
96 inbuffer = gst_buffer_new_and_alloc (size);
97 /* makes valgrind's memcheck happier */
98 memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
99 gst_buffer_set_caps (inbuffer, caps);
100 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
101 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
102 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
105 fail_unless (g_list_length (buffers) == num_buffers);
107 /* clean up buffers */
108 for (i = 0; i < num_buffers; ++i) {
109 outbuffer = GST_BUFFER (buffers->data);
110 fail_if (outbuffer == NULL);
114 fail_unless (GST_BUFFER_SIZE (outbuffer) == size);
115 /* no check on filter operation itself */
120 buffers = g_list_remove (buffers, outbuffer);
122 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
123 gst_buffer_unref (outbuffer);
127 cleanup_filter (filter);
128 g_list_free (buffers);
133 check_filter (const gchar * name, gint num_buffers, const gchar * prop, ...)
137 const int width, height;
138 } resolutions[] = { {
143 GstVideoFormat format;
145 GstCaps *templ = gst_caps_from_string (VIDEO_CAPS_TEMPLATE_STRING);
148 n = gst_caps_get_size (templ);
150 for (i = 0; i < n; i++) {
151 GstStructure *s = gst_caps_get_structure (templ, i);
152 GstCaps *caps = gst_caps_new_empty ();
154 gst_caps_append_structure (caps, gst_structure_copy (s));
156 /* try various resolutions */
157 for (r = 0; r < G_N_ELEMENTS (resolutions); ++r) {
158 caps = gst_caps_make_writable (caps);
159 gst_caps_set_simple (caps, "width", G_TYPE_INT, resolutions[r].width,
160 "height", G_TYPE_INT, resolutions[r].height,
161 "framerate", GST_TYPE_FRACTION, 25, 1, NULL);
163 GST_DEBUG ("Testing with caps: %" GST_PTR_FORMAT, caps);
164 gst_video_format_parse_caps (caps, &format, NULL, NULL);
165 size = gst_video_format_get_size (format, resolutions[r].width,
166 resolutions[r].height);
168 va_start (varargs, prop);
169 check_filter_caps (name, caps, size, num_buffers, prop, varargs);
173 gst_caps_unref (caps);
176 gst_caps_unref (templ);
179 GST_START_TEST (test_videobalance)
181 check_filter ("videobalance", 2, NULL);
182 check_filter ("videobalance", 2, "saturation", 0.5, "hue", 0.8, NULL);
188 GST_START_TEST (test_videoflip)
190 /* these we can handle with the caps */
191 check_filter ("videoflip", 2, "method", 0, NULL);
192 check_filter ("videoflip", 2, "method", 2, NULL);
193 check_filter ("videoflip", 2, "method", 4, NULL);
194 check_filter ("videoflip", 2, "method", 5, NULL);
199 GST_START_TEST (test_gamma)
201 check_filter ("gamma", 2, NULL);
202 check_filter ("gamma", 2, "gamma", 2.0, NULL);
209 videofilter_suite (void)
211 Suite *s = suite_create ("videofilter");
212 TCase *tc_chain = tcase_create ("general");
214 suite_add_tcase (s, tc_chain);
215 tcase_add_test (tc_chain, test_videobalance);
216 tcase_add_test (tc_chain, test_videoflip);
217 tcase_add_test (tc_chain, test_gamma);
223 main (int argc, char **argv)
227 Suite *s = videofilter_suite ();
228 SRunner *sr = srunner_create (s);
230 gst_check_init (&argc, &argv);
232 srunner_run_all (sr, CK_NORMAL);
233 nf = srunner_ntests_failed (sr);