3 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
23 gboolean have_eos = FALSE;
25 /* For ease of programming we use globals to keep refs for our floating
26 * src and sink pads we create; otherwise we always have to do get_pad,
27 * get_peer, and then remove references in every test function */
28 GstPad *mysrcpad, *mysinkpad;
30 #define ECHO_CAPS_STRING \
31 "audio/x-raw-float, " \
32 "channels = (int) 2, " \
33 "rate = (int) 100000, " \
34 "endianness = (int) BYTE_ORDER, " \
37 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
40 GST_STATIC_CAPS ("audio/x-raw-float, "
41 "channels = (int) [ 1, 2 ], "
42 "rate = (int) [ 1, MAX ], "
43 "endianness = (int) BYTE_ORDER, " "width = (int) { 32, 64 }")
45 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
48 GST_STATIC_CAPS ("audio/x-raw-float, "
49 "channels = (int) [ 1, 2 ], "
50 "rate = (int) [ 1, MAX ], "
51 "endianness = (int) BYTE_ORDER, " "width = (int) { 32, 64 }")
59 GST_DEBUG ("setup_echo");
60 echo = gst_check_setup_element ("audioecho");
61 mysrcpad = gst_check_setup_src_pad (echo, &srctemplate, NULL);
62 mysinkpad = gst_check_setup_sink_pad (echo, &sinktemplate, NULL);
63 gst_pad_set_active (mysrcpad, TRUE);
64 gst_pad_set_active (mysinkpad, TRUE);
70 cleanup_echo (GstElement * echo)
72 GST_DEBUG ("cleanup_echo");
74 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
75 g_list_free (buffers);
78 gst_pad_set_active (mysrcpad, FALSE);
79 gst_pad_set_active (mysinkpad, FALSE);
80 gst_check_teardown_src_pad (echo);
81 gst_check_teardown_sink_pad (echo);
82 gst_check_teardown_element (echo);
85 GST_START_TEST (test_passthrough)
88 GstBuffer *inbuffer, *outbuffer;
90 gdouble in[] = { 1.0, -1.0, 0.0, 0.5, -0.5, 0.0 };
94 g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 1, "intensity", 0.0,
95 "feedback", 0.0, NULL);
96 fail_unless (gst_element_set_state (echo,
97 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
98 "could not set to playing");
100 inbuffer = gst_buffer_new_and_alloc (sizeof (in));
101 memcpy (GST_BUFFER_DATA (inbuffer), in, sizeof (in));
102 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, sizeof (in)) == 0);
103 caps = gst_caps_from_string (ECHO_CAPS_STRING);
104 gst_buffer_set_caps (inbuffer, caps);
105 gst_caps_unref (caps);
106 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
108 /* pushing gives away my reference ... */
109 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
110 /* ... but it ends up being collected on the global buffer list */
111 fail_unless_equals_int (g_list_length (buffers), 1);
112 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
114 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
116 ("expected %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf",
117 in[0], in[1], in[2], in[3], in[4], in[5], res[0], res[1], res[2], res[3],
119 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), in, sizeof (in)) == 0);
127 GST_START_TEST (test_echo)
130 GstBuffer *inbuffer, *outbuffer;
132 gdouble in[] = { 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, };
133 gdouble out[] = { 1.0, -1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0 };
136 echo = setup_echo ();
137 g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 20000, "intensity",
138 1.0, "feedback", 0.0, NULL);
139 fail_unless (gst_element_set_state (echo,
140 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
141 "could not set to playing");
143 inbuffer = gst_buffer_new_and_alloc (sizeof (in));
144 memcpy (GST_BUFFER_DATA (inbuffer), in, sizeof (in));
145 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, sizeof (in)) == 0);
146 caps = gst_caps_from_string (ECHO_CAPS_STRING);
147 gst_buffer_set_caps (inbuffer, caps);
148 gst_caps_unref (caps);
149 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
151 /* pushing gives away my reference ... */
152 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
153 /* ... but it ends up being collected on the global buffer list */
154 fail_unless_equals_int (g_list_length (buffers), 1);
155 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
157 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
159 ("expected %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf",
160 out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8],
161 out[9], res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7],
163 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, sizeof (out)) == 0);
171 GST_START_TEST (test_feedback)
174 GstBuffer *inbuffer, *outbuffer;
176 gdouble in[] = { 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, };
177 gdouble out[] = { 1.0, -1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, -1.0 };
180 echo = setup_echo ();
181 g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 20000, "intensity",
182 1.0, "feedback", 1.0, NULL);
183 fail_unless (gst_element_set_state (echo,
184 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
185 "could not set to playing");
187 inbuffer = gst_buffer_new_and_alloc (sizeof (in));
188 memcpy (GST_BUFFER_DATA (inbuffer), in, sizeof (in));
189 fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, sizeof (in)) == 0);
190 caps = gst_caps_from_string (ECHO_CAPS_STRING);
191 gst_buffer_set_caps (inbuffer, caps);
192 gst_caps_unref (caps);
193 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
195 /* pushing gives away my reference ... */
196 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
197 /* ... but it ends up being collected on the global buffer list */
198 fail_unless_equals_int (g_list_length (buffers), 1);
199 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
201 res = (gdouble *) GST_BUFFER_DATA (outbuffer);
203 ("expected %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf",
204 out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8],
205 out[9], res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7],
207 fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, sizeof (out)) == 0);
216 audioecho_suite (void)
218 Suite *s = suite_create ("audioecho");
219 TCase *tc_chain = tcase_create ("general");
221 suite_add_tcase (s, tc_chain);
222 tcase_add_test (tc_chain, test_passthrough);
223 tcase_add_test (tc_chain, test_echo);
224 tcase_add_test (tc_chain, test_feedback);
229 GST_CHECK_MAIN (audioecho);