1 /* GStreamer
2 *
3 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 */
20
21 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
22 * with newer GLib versions (>= 2.31.0) */
23 #define GLIB_DISABLE_DEPRECATION_WARNINGS
24
25 #include <gst/gst.h>
26 #include <gst/check/gstcheck.h>
27
28 static gboolean have_eos = FALSE;
29
30 static gboolean
on_message(GstBus * bus,GstMessage * message,gpointer user_data)31 on_message (GstBus * bus, GstMessage * message, gpointer user_data)
32 {
33 GMainLoop *loop = (GMainLoop *) user_data;
34
35 switch (GST_MESSAGE_TYPE (message)) {
36 case GST_MESSAGE_ERROR:
37 case GST_MESSAGE_WARNING:
38 g_assert_not_reached ();
39 g_main_loop_quit (loop);
40 break;
41
42 case GST_MESSAGE_EOS:
43 have_eos = TRUE;
44 g_main_loop_quit (loop);
45 break;
46 default:
47 break;
48 }
49
50 return TRUE;
51 }
52
53 static void
on_rate_changed(GstElement * element,gint rate,gpointer user_data)54 on_rate_changed (GstElement * element, gint rate, gpointer user_data)
55 {
56 GValueArray *va;
57 GValue v = { 0, };
58
59 fail_unless (rate > 0);
60
61 va = g_value_array_new (6);
62
63 g_value_init (&v, G_TYPE_DOUBLE);
64 g_value_set_double (&v, 0.0);
65 g_value_array_append (va, &v);
66 g_value_reset (&v);
67 g_value_set_double (&v, 0.0);
68 g_value_array_append (va, &v);
69 g_value_reset (&v);
70 g_value_set_double (&v, 0.0);
71 g_value_array_append (va, &v);
72 g_value_reset (&v);
73 g_value_set_double (&v, 0.0);
74 g_value_array_append (va, &v);
75 g_value_reset (&v);
76 g_value_set_double (&v, 0.0);
77 g_value_array_append (va, &v);
78 g_value_reset (&v);
79 g_value_set_double (&v, 1.0);
80 g_value_array_append (va, &v);
81 g_value_reset (&v);
82
83 g_object_set (G_OBJECT (element), "b", va, NULL);
84
85 g_value_array_free (va);
86
87 va = g_value_array_new (6);
88
89 g_value_set_double (&v, 1.0);
90 g_value_array_append (va, &v);
91 g_value_reset (&v);
92
93 g_object_set (G_OBJECT (element), "a", va, NULL);
94
95 g_value_array_free (va);
96 }
97
98 static gboolean have_data = FALSE;
99
100 static void
on_handoff(GstElement * object,GstBuffer * buffer,GstPad * pad,gpointer user_data)101 on_handoff (GstElement * object, GstBuffer * buffer, GstPad * pad,
102 gpointer user_data)
103 {
104 if (!have_data) {
105 GstMapInfo map;
106 gfloat *data;
107
108 fail_unless (gst_buffer_map (buffer, &map, GST_MAP_READ));
109 data = (gfloat *) map.data;
110
111 fail_unless (map.size > 5 * sizeof (gdouble));
112 fail_unless (data[0] == 0.0);
113 fail_unless (data[1] == 0.0);
114 fail_unless (data[2] == 0.0);
115 fail_unless (data[3] == 0.0);
116 fail_unless (data[4] == 0.0);
117 fail_unless (data[5] != 0.0);
118
119 gst_buffer_unmap (buffer, &map);
120 have_data = TRUE;
121 }
122 }
123
GST_START_TEST(test_pipeline)124 GST_START_TEST (test_pipeline)
125 {
126 GstElement *pipeline, *src, *filter, *sink;
127 GstBus *bus;
128 GMainLoop *loop;
129
130 have_data = FALSE;
131 have_eos = FALSE;
132
133 pipeline = gst_element_factory_make ("pipeline", NULL);
134 fail_unless (pipeline != NULL);
135
136 src = gst_element_factory_make ("audiotestsrc", NULL);
137 fail_unless (src != NULL);
138 g_object_set (G_OBJECT (src), "num-buffers", 1000, NULL);
139
140 filter = gst_element_factory_make ("audioiirfilter", NULL);
141 fail_unless (filter != NULL);
142 g_signal_connect (G_OBJECT (filter), "rate-changed",
143 G_CALLBACK (on_rate_changed), NULL);
144
145 sink = gst_element_factory_make ("fakesink", NULL);
146 fail_unless (sink != NULL);
147 g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
148 g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (on_handoff), NULL);
149
150 gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL);
151 fail_unless (gst_element_link_many (src, filter, sink, NULL));
152
153 loop = g_main_loop_new (NULL, FALSE);
154
155 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
156 gst_bus_add_signal_watch (bus);
157 g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
158
159 fail_if (gst_element_set_state (pipeline,
160 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
161
162 g_main_loop_run (loop);
163
164 fail_unless (have_data);
165 fail_unless (have_eos);
166
167 fail_unless (gst_element_set_state (pipeline,
168 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
169
170 gst_bus_remove_signal_watch (bus);
171 gst_object_unref (GST_OBJECT (bus));
172 g_main_loop_unref (loop);
173 gst_object_unref (pipeline);
174 }
175
176 GST_END_TEST;
177
178 static Suite *
audioiirfilter_suite(void)179 audioiirfilter_suite (void)
180 {
181 Suite *s = suite_create ("audioiirfilter");
182 TCase *tc_chain = tcase_create ("general");
183
184 suite_add_tcase (s, tc_chain);
185 tcase_add_test (tc_chain, test_pipeline);
186
187 return s;
188 }
189
190 GST_CHECK_MAIN (audioiirfilter);
191