Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / amrparse.c
1 /*
2  * GStreamer
3  *
4  * unit test for amrparse
5  *
6  * Copyright (C) 2008 Nokia Corporation. All rights reserved.
7  *
8  * Contact: Stefan Kost <stefan.kost@nokia.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #include <gst/check/gstcheck.h>
27 #include "parser.h"
28
29 #define SRC_CAPS_NB  "audio/x-amr-nb-sh"
30 #define SRC_CAPS_WB  "audio/x-amr-wb-sh"
31 #define SRC_CAPS_ANY "ANY"
32
33 #define SINK_CAPS_NB  "audio/AMR, rate=8000 , channels=1"
34 #define SINK_CAPS_WB  "audio/AMR-WB, rate=16000 , channels=1"
35 #define SINK_CAPS_ANY "ANY"
36
37 #define AMR_FRAME_DURATION (GST_SECOND/50)
38
39 static GstStaticPadTemplate sinktemplate_nb = GST_STATIC_PAD_TEMPLATE ("sink",
40     GST_PAD_SINK,
41     GST_PAD_ALWAYS,
42     GST_STATIC_CAPS (SINK_CAPS_NB)
43     );
44
45 static GstStaticPadTemplate sinktemplate_wb = GST_STATIC_PAD_TEMPLATE ("sink",
46     GST_PAD_SINK,
47     GST_PAD_ALWAYS,
48     GST_STATIC_CAPS (SINK_CAPS_WB)
49     );
50
51 static GstStaticPadTemplate srctemplate_nb = GST_STATIC_PAD_TEMPLATE ("src",
52     GST_PAD_SRC,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS (SRC_CAPS_NB)
55     );
56
57 static GstStaticPadTemplate srctemplate_wb = GST_STATIC_PAD_TEMPLATE ("src",
58     GST_PAD_SRC,
59     GST_PAD_ALWAYS,
60     GST_STATIC_CAPS (SRC_CAPS_WB)
61     );
62
63
64 /* some data */
65
66 static guint8 frame_data_nb[] = {
67   0x0c, 0x56, 0x3c, 0x52, 0xe0, 0x61, 0xbc, 0x45,
68   0x0f, 0x98, 0x2e, 0x01, 0x42, 0x02
69 };
70
71 static guint8 frame_data_wb[] = {
72   0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
73   0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
74   0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
75 };
76
77 static guint8 frame_hdr_nb[] = {
78   '#', '!', 'A', 'M', 'R', '\n'
79 };
80
81 static guint8 frame_hdr_wb[] = {
82   '#', '!', 'A', 'M', 'R', '-', 'W', 'B', '\n'
83 };
84
85 static guint8 garbage_frame[] = {
86   0xff, 0xff, 0xff, 0xff, 0xff
87 };
88
89
90 GST_START_TEST (test_parse_nb_normal)
91 {
92   gst_parser_test_normal (frame_data_nb, sizeof (frame_data_nb));
93 }
94
95 GST_END_TEST;
96
97
98 GST_START_TEST (test_parse_nb_drain_single)
99 {
100   gst_parser_test_drain_single (frame_data_nb, sizeof (frame_data_nb));
101 }
102
103 GST_END_TEST;
104
105
106 GST_START_TEST (test_parse_nb_drain_garbage)
107 {
108   gst_parser_test_drain_garbage (frame_data_nb, sizeof (frame_data_nb),
109       garbage_frame, sizeof (garbage_frame));
110 }
111
112 GST_END_TEST;
113
114
115 GST_START_TEST (test_parse_nb_split)
116 {
117   gst_parser_test_split (frame_data_nb, sizeof (frame_data_nb));
118 }
119
120 GST_END_TEST;
121
122
123 GST_START_TEST (test_parse_nb_skip_garbage)
124 {
125   gst_parser_test_skip_garbage (frame_data_nb, sizeof (frame_data_nb),
126       garbage_frame, sizeof (garbage_frame));
127 }
128
129 GST_END_TEST;
130
131
132 GST_START_TEST (test_parse_nb_detect_stream)
133 {
134   GstParserTest ptest;
135   GstCaps *old_ctx_caps;
136
137   /* no input caps, override ctx */
138   old_ctx_caps = ctx_input_caps;
139   ctx_input_caps = NULL;
140
141   /* AMR-NB header */
142   gst_parser_test_init (&ptest, frame_hdr_nb, sizeof (frame_hdr_nb), 1);
143   /* well, no garbage, followed by real data */
144   ptest.series[2].data = frame_data_nb;
145   ptest.series[2].size = sizeof (frame_data_nb);
146   ptest.series[2].num = 10;
147   /* header gets dropped, so ... */
148   /* buffer count will not match */
149   ptest.framed = FALSE;
150   /* total size a bit less */
151   ptest.dropped = sizeof (frame_hdr_nb);
152
153   /* Check that the negotiated caps are as expected */
154   ptest.sink_caps = gst_caps_from_string (SINK_CAPS_NB);
155
156   gst_parser_test_run (&ptest, NULL);
157
158   gst_caps_unref (ptest.sink_caps);
159
160   ctx_input_caps = old_ctx_caps;
161 }
162
163 GST_END_TEST;
164
165
166 GST_START_TEST (test_parse_wb_normal)
167 {
168   gst_parser_test_normal (frame_data_wb, sizeof (frame_data_wb));
169 }
170
171 GST_END_TEST;
172
173
174 GST_START_TEST (test_parse_wb_drain_single)
175 {
176   gst_parser_test_drain_single (frame_data_wb, sizeof (frame_data_wb));
177 }
178
179 GST_END_TEST;
180
181
182 GST_START_TEST (test_parse_wb_drain_garbage)
183 {
184   gst_parser_test_drain_garbage (frame_data_wb, sizeof (frame_data_wb),
185       garbage_frame, sizeof (garbage_frame));
186 }
187
188 GST_END_TEST;
189
190
191 GST_START_TEST (test_parse_wb_split)
192 {
193   gst_parser_test_split (frame_data_wb, sizeof (frame_data_wb));
194 }
195
196 GST_END_TEST;
197
198
199 GST_START_TEST (test_parse_wb_skip_garbage)
200 {
201   gst_parser_test_skip_garbage (frame_data_wb, sizeof (frame_data_wb),
202       garbage_frame, sizeof (garbage_frame));
203 }
204
205 GST_END_TEST;
206
207
208 GST_START_TEST (test_parse_wb_detect_stream)
209 {
210   GstParserTest ptest;
211   GstCaps *old_ctx_caps;
212
213   /* no input caps, override ctx */
214   old_ctx_caps = ctx_input_caps;
215   ctx_input_caps = NULL;
216
217   /* AMR-WB header */
218   gst_parser_test_init (&ptest, frame_hdr_wb, sizeof (frame_hdr_wb), 1);
219   /* well, no garbage, followed by real data */
220   ptest.series[2].data = frame_data_wb;
221   ptest.series[2].size = sizeof (frame_data_wb);
222   ptest.series[2].num = 10;
223   /* header gets dropped, so ... */
224   /* buffer count will not match */
225   ptest.framed = FALSE;
226   /* total size a bit less */
227   ptest.dropped = sizeof (frame_hdr_wb);
228
229   /* Check that the negotiated caps are as expected */
230   ptest.sink_caps = gst_caps_from_string (SINK_CAPS_WB);
231
232   gst_parser_test_run (&ptest, NULL);
233
234   gst_caps_unref (ptest.sink_caps);
235
236   ctx_input_caps = old_ctx_caps;
237 }
238
239 GST_END_TEST;
240
241
242
243 /*
244  * Create test suite.
245  */
246 static Suite *
247 amrnb_parse_suite (void)
248 {
249   Suite *s = suite_create ("amrwb_parse");
250   TCase *tc_chain = tcase_create ("general");
251
252   suite_add_tcase (s, tc_chain);
253   /* AMR-NB tests */
254   tcase_add_test (tc_chain, test_parse_nb_normal);
255   tcase_add_test (tc_chain, test_parse_nb_drain_single);
256   tcase_add_test (tc_chain, test_parse_nb_drain_garbage);
257   tcase_add_test (tc_chain, test_parse_nb_split);
258   tcase_add_test (tc_chain, test_parse_nb_detect_stream);
259   tcase_add_test (tc_chain, test_parse_nb_skip_garbage);
260
261   return s;
262 }
263
264 static Suite *
265 amrwb_parse_suite (void)
266 {
267   Suite *s = suite_create ("amrnb_parse");
268   TCase *tc_chain = tcase_create ("general");
269
270   suite_add_tcase (s, tc_chain);
271   /* AMR-WB tests */
272   tcase_add_test (tc_chain, test_parse_wb_normal);
273   tcase_add_test (tc_chain, test_parse_wb_drain_single);
274   tcase_add_test (tc_chain, test_parse_wb_drain_garbage);
275   tcase_add_test (tc_chain, test_parse_wb_split);
276   tcase_add_test (tc_chain, test_parse_wb_detect_stream);
277   tcase_add_test (tc_chain, test_parse_wb_skip_garbage);
278
279   return s;
280 }
281
282 /*
283  * TODO:
284  *   - Both push- and pull-modes need to be tested
285  *      * Pull-mode & EOS
286  */
287
288 int
289 main (int argc, char **argv)
290 {
291   int nf;
292   GstCaps *caps;
293
294   Suite *s = amrnb_parse_suite ();
295   SRunner *sr = srunner_create (s);
296
297   gst_check_init (&argc, &argv);
298
299   /* init test context */
300   ctx_factory = "amrparse";
301   ctx_sink_template = &sinktemplate_nb;
302   ctx_src_template = &srctemplate_nb;
303   caps = gst_caps_from_string (SRC_CAPS_NB);
304   g_assert (caps);
305   ctx_input_caps = caps;
306
307   srunner_run_all (sr, CK_NORMAL);
308   nf = srunner_ntests_failed (sr);
309   srunner_free (sr);
310   gst_caps_unref (caps);
311
312   s = amrwb_parse_suite ();
313   sr = srunner_create (s);
314
315   ctx_sink_template = &sinktemplate_wb;
316   ctx_src_template = &srctemplate_wb;
317   caps = gst_caps_from_string (SRC_CAPS_WB);
318   g_assert (caps);
319   ctx_input_caps = caps;
320
321   srunner_run_all (sr, CK_NORMAL);
322   nf += srunner_ntests_failed (sr);
323   srunner_free (sr);
324   gst_caps_unref (caps);
325
326   return nf;
327 }