4 * unit test for amrparse
6 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
8 * Contact: Stefan Kost <stefan.kost@nokia.com>
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.
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.
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.
26 #include <gst/check/gstcheck.h>
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"
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"
37 #define AMR_FRAME_DURATION (GST_SECOND/50)
39 static GstStaticPadTemplate sinktemplate_nb = GST_STATIC_PAD_TEMPLATE ("sink",
42 GST_STATIC_CAPS (SINK_CAPS_NB)
45 static GstStaticPadTemplate sinktemplate_wb = GST_STATIC_PAD_TEMPLATE ("sink",
48 GST_STATIC_CAPS (SINK_CAPS_WB)
51 static GstStaticPadTemplate srctemplate_nb = GST_STATIC_PAD_TEMPLATE ("src",
54 GST_STATIC_CAPS (SRC_CAPS_NB)
57 static GstStaticPadTemplate srctemplate_wb = GST_STATIC_PAD_TEMPLATE ("src",
60 GST_STATIC_CAPS (SRC_CAPS_WB)
66 static guint8 frame_data_nb[] = {
67 0x0c, 0x56, 0x3c, 0x52, 0xe0, 0x61, 0xbc, 0x45,
68 0x0f, 0x98, 0x2e, 0x01, 0x42, 0x02
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
77 static guint8 frame_hdr_nb[] = {
78 '#', '!', 'A', 'M', 'R', '\n'
81 static guint8 frame_hdr_wb[] = {
82 '#', '!', 'A', 'M', 'R', '-', 'W', 'B', '\n'
85 static guint8 garbage_frame[] = {
86 0xff, 0xff, 0xff, 0xff, 0xff
90 GST_START_TEST (test_parse_nb_normal)
92 gst_parser_test_normal (frame_data_nb, sizeof (frame_data_nb));
98 GST_START_TEST (test_parse_nb_drain_single)
100 gst_parser_test_drain_single (frame_data_nb, sizeof (frame_data_nb));
106 GST_START_TEST (test_parse_nb_drain_garbage)
108 gst_parser_test_drain_garbage (frame_data_nb, sizeof (frame_data_nb),
109 garbage_frame, sizeof (garbage_frame));
115 GST_START_TEST (test_parse_nb_split)
117 gst_parser_test_split (frame_data_nb, sizeof (frame_data_nb));
123 GST_START_TEST (test_parse_nb_skip_garbage)
125 gst_parser_test_skip_garbage (frame_data_nb, sizeof (frame_data_nb),
126 garbage_frame, sizeof (garbage_frame));
132 GST_START_TEST (test_parse_nb_detect_stream)
135 GstCaps *old_ctx_caps;
137 /* no input caps, override ctx */
138 old_ctx_caps = ctx_input_caps;
139 ctx_input_caps = NULL;
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);
153 /* Check that the negotiated caps are as expected */
154 ptest.sink_caps = gst_caps_from_string (SINK_CAPS_NB);
156 gst_parser_test_run (&ptest, NULL);
158 gst_caps_unref (ptest.sink_caps);
160 ctx_input_caps = old_ctx_caps;
166 GST_START_TEST (test_parse_wb_normal)
168 gst_parser_test_normal (frame_data_wb, sizeof (frame_data_wb));
174 GST_START_TEST (test_parse_wb_drain_single)
176 gst_parser_test_drain_single (frame_data_wb, sizeof (frame_data_wb));
182 GST_START_TEST (test_parse_wb_drain_garbage)
184 gst_parser_test_drain_garbage (frame_data_wb, sizeof (frame_data_wb),
185 garbage_frame, sizeof (garbage_frame));
191 GST_START_TEST (test_parse_wb_split)
193 gst_parser_test_split (frame_data_wb, sizeof (frame_data_wb));
199 GST_START_TEST (test_parse_wb_skip_garbage)
201 gst_parser_test_skip_garbage (frame_data_wb, sizeof (frame_data_wb),
202 garbage_frame, sizeof (garbage_frame));
208 GST_START_TEST (test_parse_wb_detect_stream)
211 GstCaps *old_ctx_caps;
213 /* no input caps, override ctx */
214 old_ctx_caps = ctx_input_caps;
215 ctx_input_caps = NULL;
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);
229 /* Check that the negotiated caps are as expected */
230 ptest.sink_caps = gst_caps_from_string (SINK_CAPS_WB);
232 gst_parser_test_run (&ptest, NULL);
234 gst_caps_unref (ptest.sink_caps);
236 ctx_input_caps = old_ctx_caps;
247 amrnb_parse_suite (void)
249 Suite *s = suite_create ("amrwb_parse");
250 TCase *tc_chain = tcase_create ("general");
252 suite_add_tcase (s, tc_chain);
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);
265 amrwb_parse_suite (void)
267 Suite *s = suite_create ("amrnb_parse");
268 TCase *tc_chain = tcase_create ("general");
270 suite_add_tcase (s, tc_chain);
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);
284 * - Both push- and pull-modes need to be tested
289 main (int argc, char **argv)
294 Suite *s = amrnb_parse_suite ();
295 SRunner *sr = srunner_create (s);
297 gst_check_init (&argc, &argv);
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);
305 ctx_input_caps = caps;
307 srunner_run_all (sr, CK_NORMAL);
308 nf = srunner_ntests_failed (sr);
310 gst_caps_unref (caps);
312 s = amrwb_parse_suite ();
313 sr = srunner_create (s);
315 ctx_sink_template = &sinktemplate_wb;
316 ctx_src_template = &srctemplate_wb;
317 caps = gst_caps_from_string (SRC_CAPS_WB);
319 ctx_input_caps = caps;
321 srunner_run_all (sr, CK_NORMAL);
322 nf += srunner_ntests_failed (sr);
324 gst_caps_unref (caps);