• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer WavParse unit tests
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  */
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <gst/check/gstcheck.h>
23 
24 #define SIMPLE_WAV_PATH GST_TEST_FILES_PATH G_DIR_SEPARATOR_S "audiotestsrc.wav"
25 
26 static GstElement *
create_pipeline(GstPadMode mode)27 create_pipeline (GstPadMode mode)
28 {
29   GstElement *pipeline;
30   GstElement *src, *q = NULL;
31   GstElement *wavparse;
32   GstElement *fakesink;
33 
34   pipeline = gst_pipeline_new ("testpipe");
35   src = gst_element_factory_make ("filesrc", "filesrc");
36   fail_if (src == NULL);
37   if (mode == GST_PAD_MODE_PUSH)
38     q = gst_element_factory_make ("queue", "queue");
39   wavparse = gst_element_factory_make ("wavparse", "wavparse");
40   fail_if (wavparse == NULL);
41   fakesink = gst_element_factory_make ("fakesink", "fakesink");
42   fail_if (fakesink == NULL);
43 
44   gst_bin_add_many (GST_BIN (pipeline), src, wavparse, fakesink, q, NULL);
45 
46   g_object_set (src, "location", SIMPLE_WAV_PATH, NULL);
47 
48   if (mode == GST_PAD_MODE_PUSH)
49     fail_unless (gst_element_link_many (src, q, wavparse, fakesink, NULL));
50   else
51     fail_unless (gst_element_link_many (src, wavparse, fakesink, NULL));
52 
53   return pipeline;
54 }
55 
56 static void
do_test_simple_file(GstPadMode mode)57 do_test_simple_file (GstPadMode mode)
58 {
59   GstStateChangeReturn ret;
60   GstElement *pipeline;
61   GstMessage *msg;
62 
63   pipeline = create_pipeline (mode);
64 
65   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
66   fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
67 
68   ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
69   fail_unless_equals_int (ret, GST_STATE_CHANGE_SUCCESS);
70 
71   msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline),
72       GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
73 
74   fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "eos");
75 
76   gst_message_unref (msg);
77   gst_element_set_state (pipeline, GST_STATE_NULL);
78   gst_object_unref (pipeline);
79 }
80 
GST_START_TEST(test_simple_file_pull)81 GST_START_TEST (test_simple_file_pull)
82 {
83   do_test_simple_file (TRUE);
84 }
85 
86 GST_END_TEST;
87 
GST_START_TEST(test_simple_file_push)88 GST_START_TEST (test_simple_file_push)
89 {
90   do_test_simple_file (FALSE);
91 }
92 
93 GST_END_TEST;
94 
95 static void
do_test_empty_file(gboolean can_activate_pull)96 do_test_empty_file (gboolean can_activate_pull)
97 {
98   GstStateChangeReturn ret1, ret2;
99   GstElement *pipeline;
100   GstElement *src;
101   GstElement *wavparse;
102   GstElement *fakesink;
103 
104   /* Pull mode */
105   pipeline = gst_pipeline_new ("testpipe");
106   src = gst_element_factory_make ("fakesrc", NULL);
107   fail_if (src == NULL);
108   wavparse = gst_element_factory_make ("wavparse", NULL);
109   fail_if (wavparse == NULL);
110   fakesink = gst_element_factory_make ("fakesink", NULL);
111   fail_if (fakesink == NULL);
112 
113   gst_bin_add_many (GST_BIN (pipeline), src, wavparse, fakesink, NULL);
114   g_object_set (src, "num-buffers", 0, "can-activate-pull", can_activate_pull,
115       NULL);
116 
117   fail_unless (gst_element_link_many (src, wavparse, fakesink, NULL));
118 
119   ret1 = gst_element_set_state (pipeline, GST_STATE_PLAYING);
120   if (ret1 == GST_STATE_CHANGE_ASYNC)
121     ret2 = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
122   else
123     ret2 = ret1;
124 
125   /* should have gotten an error on the bus, no output to fakesink */
126   fail_unless_equals_int (ret2, GST_STATE_CHANGE_FAILURE);
127 
128   gst_element_set_state (pipeline, GST_STATE_NULL);
129   gst_object_unref (pipeline);
130 }
131 
GST_START_TEST(test_empty_file_pull)132 GST_START_TEST (test_empty_file_pull)
133 {
134   do_test_empty_file (TRUE);
135 }
136 
137 GST_END_TEST;
138 
GST_START_TEST(test_empty_file_push)139 GST_START_TEST (test_empty_file_push)
140 {
141   do_test_empty_file (FALSE);
142 }
143 
144 GST_END_TEST;
145 
146 static GstPadProbeReturn
fakesink_buffer_cb(GstPad * sink,GstPadProbeInfo * info,gpointer user_data)147 fakesink_buffer_cb (GstPad * sink, GstPadProbeInfo * info, gpointer user_data)
148 {
149   GstClockTime *ts = user_data;
150   GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
151 
152   fail_unless (buf);
153   if (!GST_CLOCK_TIME_IS_VALID (*ts))
154     *ts = GST_BUFFER_PTS (buf);
155 
156   return GST_PAD_PROBE_OK;
157 }
158 
GST_START_TEST(test_seek)159 GST_START_TEST (test_seek)
160 {
161   GstStateChangeReturn ret;
162   GstElement *pipeline;
163   GstMessage *msg;
164   GstElement *wavparse, *fakesink;
165   GstPad *pad;
166   GstClockTime seek_position = (20 * GST_MSECOND);
167   GstClockTime first_ts = GST_CLOCK_TIME_NONE;
168 
169   pipeline = create_pipeline (GST_PAD_MODE_PULL);
170   wavparse = gst_bin_get_by_name (GST_BIN (pipeline), "wavparse");
171   fail_unless (wavparse);
172   fakesink = gst_bin_get_by_name (GST_BIN (pipeline), "fakesink");
173   fail_unless (fakesink);
174 
175   pad = gst_element_get_static_pad (fakesink, "sink");
176   fail_unless (pad);
177   gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, fakesink_buffer_cb,
178       &first_ts, NULL);
179   gst_object_unref (pad);
180 
181   /* wavparse is able to seek in the READY state */
182   ret = gst_element_set_state (pipeline, GST_STATE_READY);
183   fail_unless_equals_int (ret, GST_STATE_CHANGE_SUCCESS);
184 
185   fail_unless (gst_element_seek_simple (wavparse, GST_FORMAT_TIME,
186           GST_SEEK_FLAG_FLUSH, seek_position));
187 
188   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
189   fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
190 
191   ret = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
192   fail_unless_equals_int (ret, GST_STATE_CHANGE_SUCCESS);
193 
194   msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline),
195       GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
196 
197   /* check that the first buffer produced by wavparse matches the seek
198      position we requested */
199   fail_unless_equals_clocktime (first_ts, seek_position);
200 
201   fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "eos");
202 
203   gst_message_unref (msg);
204   gst_element_set_state (pipeline, GST_STATE_NULL);
205   gst_object_unref (wavparse);
206   gst_object_unref (fakesink);
207   gst_object_unref (pipeline);
208 }
209 
210 GST_END_TEST;
211 
GST_START_TEST(test_query_uri)212 GST_START_TEST (test_query_uri)
213 {
214   GstElement *pipeline, *filesrc, *wavparse, *fakesink;
215   GstQuery *query;
216   gchar *uri;
217   fail_unless ((pipeline = gst_pipeline_new (NULL)) != NULL,
218       "Could not create pipeline");
219   fail_unless ((filesrc = gst_element_factory_make ("filesrc", NULL)) != NULL,
220       "Could not create filesrc");
221   fail_unless ((wavparse = gst_element_factory_make ("wavparse", NULL)) != NULL,
222       "Could not create wavparse");
223   fail_unless ((fakesink = gst_element_factory_make ("fakesink", NULL)) != NULL,
224       "Could not create fakesink");
225   gst_bin_add_many (GST_BIN (pipeline), filesrc, wavparse, fakesink, NULL);
226   gst_element_link_many (filesrc, wavparse, fakesink, NULL);
227   g_object_set (G_OBJECT (filesrc), "location", "my_test_file", NULL);
228   fail_unless ((query = gst_query_new_uri ()) != NULL,
229       "Could not prepare uri query");
230   fail_unless (gst_element_query (GST_ELEMENT (wavparse), query),
231       "Could not query uri");
232   gst_query_parse_uri (query, &uri);
233   fail_unless (uri != NULL);
234 
235   g_free (uri);
236   gst_query_unref (query);
237   gst_object_unref (pipeline);
238 }
239 
240 GST_END_TEST;
241 
242 static Suite *
wavparse_suite(void)243 wavparse_suite (void)
244 {
245   Suite *s = suite_create ("wavparse");
246   TCase *tc_chain = tcase_create ("wavparse");
247 
248   suite_add_tcase (s, tc_chain);
249   tcase_add_test (tc_chain, test_empty_file_pull);
250   tcase_add_test (tc_chain, test_empty_file_push);
251   tcase_add_test (tc_chain, test_simple_file_pull);
252   tcase_add_test (tc_chain, test_simple_file_push);
253   tcase_add_test (tc_chain, test_seek);
254   tcase_add_test (tc_chain, test_query_uri);
255   return s;
256 }
257 
258 GST_CHECK_MAIN (wavparse)
259