• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301, 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 static GstCaps *input_caps = NULL;
64 
65 /* some data */
66 
67 static guint8 frame_data_nb[] = {
68   0x0c, 0x56, 0x3c, 0x52, 0xe0, 0x61, 0xbc, 0x45,
69   0x0f, 0x98, 0x2e, 0x01, 0x42, 0x02
70 };
71 
72 static guint8 frame_data_wb[] = {
73   0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
74   0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
75   0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
76 };
77 
78 static guint8 frame_hdr_nb[] = {
79   '#', '!', 'A', 'M', 'R', '\n'
80 };
81 
82 static guint8 frame_hdr_wb[] = {
83   '#', '!', 'A', 'M', 'R', '-', 'W', 'B', '\n'
84 };
85 
86 static guint8 garbage_frame[] = {
87   0xff, 0xff, 0xff, 0xff, 0xff
88 };
89 
90 static void
setup_amrnb(void)91 setup_amrnb (void)
92 {
93   ctx_factory = "amrparse";
94   ctx_sink_template = &sinktemplate_nb;
95   ctx_src_template = &srctemplate_nb;
96   input_caps = gst_caps_from_string (SRC_CAPS_NB);
97   g_assert (input_caps);
98   ctx_input_caps = input_caps;
99 }
100 
101 static void
setup_amrwb(void)102 setup_amrwb (void)
103 {
104   ctx_factory = "amrparse";
105   ctx_sink_template = &sinktemplate_wb;
106   ctx_src_template = &srctemplate_wb;
107   input_caps = gst_caps_from_string (SRC_CAPS_WB);
108   g_assert (input_caps);
109   ctx_input_caps = input_caps;
110 }
111 
112 static void
teardown(void)113 teardown (void)
114 {
115   gst_caps_unref (input_caps);
116 }
117 
GST_START_TEST(test_parse_nb_normal)118 GST_START_TEST (test_parse_nb_normal)
119 {
120   gst_parser_test_normal (frame_data_nb, sizeof (frame_data_nb));
121 }
122 
123 GST_END_TEST;
124 
125 
GST_START_TEST(test_parse_nb_drain_single)126 GST_START_TEST (test_parse_nb_drain_single)
127 {
128   gst_parser_test_drain_single (frame_data_nb, sizeof (frame_data_nb));
129 }
130 
131 GST_END_TEST;
132 
133 
GST_START_TEST(test_parse_nb_drain_garbage)134 GST_START_TEST (test_parse_nb_drain_garbage)
135 {
136   gst_parser_test_drain_garbage (frame_data_nb, sizeof (frame_data_nb),
137       garbage_frame, sizeof (garbage_frame));
138 }
139 
140 GST_END_TEST;
141 
142 
GST_START_TEST(test_parse_nb_split)143 GST_START_TEST (test_parse_nb_split)
144 {
145   gst_parser_test_split (frame_data_nb, sizeof (frame_data_nb));
146 }
147 
148 GST_END_TEST;
149 
150 
GST_START_TEST(test_parse_nb_skip_garbage)151 GST_START_TEST (test_parse_nb_skip_garbage)
152 {
153   gst_parser_test_skip_garbage (frame_data_nb, sizeof (frame_data_nb),
154       garbage_frame, sizeof (garbage_frame));
155 }
156 
157 GST_END_TEST;
158 
159 
GST_START_TEST(test_parse_nb_detect_stream)160 GST_START_TEST (test_parse_nb_detect_stream)
161 {
162   GstParserTest ptest;
163   GstCaps *old_ctx_caps;
164 
165   /* no input caps, override ctx */
166   old_ctx_caps = ctx_input_caps;
167   ctx_input_caps = NULL;
168 
169   /* AMR-NB header */
170   gst_parser_test_init (&ptest, frame_hdr_nb, sizeof (frame_hdr_nb), 1);
171   /* well, no garbage, followed by real data */
172   ptest.series[2].data = frame_data_nb;
173   ptest.series[2].size = sizeof (frame_data_nb);
174   ptest.series[2].num = 10;
175   /* header gets dropped, so ... */
176   /* buffer count will not match */
177   ptest.framed = FALSE;
178   /* total size a bit less */
179   ptest.dropped = sizeof (frame_hdr_nb);
180 
181   /* Check that the negotiated caps are as expected */
182   ptest.sink_caps = gst_caps_from_string (SINK_CAPS_NB);
183 
184   gst_parser_test_run (&ptest, NULL);
185 
186   gst_caps_unref (ptest.sink_caps);
187 
188   ctx_input_caps = old_ctx_caps;
189 }
190 
191 GST_END_TEST;
192 
193 
GST_START_TEST(test_parse_wb_normal)194 GST_START_TEST (test_parse_wb_normal)
195 {
196   gst_parser_test_normal (frame_data_wb, sizeof (frame_data_wb));
197 }
198 
199 GST_END_TEST;
200 
201 
GST_START_TEST(test_parse_wb_drain_single)202 GST_START_TEST (test_parse_wb_drain_single)
203 {
204   gst_parser_test_drain_single (frame_data_wb, sizeof (frame_data_wb));
205 }
206 
207 GST_END_TEST;
208 
209 
GST_START_TEST(test_parse_wb_drain_garbage)210 GST_START_TEST (test_parse_wb_drain_garbage)
211 {
212   gst_parser_test_drain_garbage (frame_data_wb, sizeof (frame_data_wb),
213       garbage_frame, sizeof (garbage_frame));
214 }
215 
216 GST_END_TEST;
217 
218 
GST_START_TEST(test_parse_wb_split)219 GST_START_TEST (test_parse_wb_split)
220 {
221   gst_parser_test_split (frame_data_wb, sizeof (frame_data_wb));
222 }
223 
224 GST_END_TEST;
225 
226 
GST_START_TEST(test_parse_wb_skip_garbage)227 GST_START_TEST (test_parse_wb_skip_garbage)
228 {
229   gst_parser_test_skip_garbage (frame_data_wb, sizeof (frame_data_wb),
230       garbage_frame, sizeof (garbage_frame));
231 }
232 
233 GST_END_TEST;
234 
235 
GST_START_TEST(test_parse_wb_detect_stream)236 GST_START_TEST (test_parse_wb_detect_stream)
237 {
238   GstParserTest ptest;
239   GstCaps *old_ctx_caps;
240 
241   /* no input caps, override ctx */
242   old_ctx_caps = ctx_input_caps;
243   ctx_input_caps = NULL;
244 
245   /* AMR-WB header */
246   gst_parser_test_init (&ptest, frame_hdr_wb, sizeof (frame_hdr_wb), 1);
247   /* well, no garbage, followed by real data */
248   ptest.series[2].data = frame_data_wb;
249   ptest.series[2].size = sizeof (frame_data_wb);
250   ptest.series[2].num = 10;
251   /* header gets dropped, so ... */
252   /* buffer count will not match */
253   ptest.framed = FALSE;
254   /* total size a bit less */
255   ptest.dropped = sizeof (frame_hdr_wb);
256 
257   /* Check that the negotiated caps are as expected */
258   ptest.sink_caps = gst_caps_from_string (SINK_CAPS_WB);
259 
260   gst_parser_test_run (&ptest, NULL);
261 
262   gst_caps_unref (ptest.sink_caps);
263 
264   ctx_input_caps = old_ctx_caps;
265 }
266 
267 GST_END_TEST;
268 
269 /*
270  * TODO:
271  *   - Both push- and pull-modes need to be tested
272  *      * Pull-mode & EOS
273  */
274 
275 static Suite *
amrparse_suite(void)276 amrparse_suite (void)
277 {
278   Suite *s = suite_create ("amrparse");
279   TCase *tc_chain;
280 
281   /* AMR-NB tests */
282   tc_chain = tcase_create ("amrnb");
283   tcase_add_checked_fixture (tc_chain, setup_amrnb, teardown);
284   tcase_add_test (tc_chain, test_parse_nb_normal);
285   tcase_add_test (tc_chain, test_parse_nb_drain_single);
286   tcase_add_test (tc_chain, test_parse_nb_drain_garbage);
287   tcase_add_test (tc_chain, test_parse_nb_split);
288   tcase_add_test (tc_chain, test_parse_nb_detect_stream);
289   tcase_add_test (tc_chain, test_parse_nb_skip_garbage);
290   suite_add_tcase (s, tc_chain);
291 
292   /* AMR-WB tests */
293   tc_chain = tcase_create ("amrwb");
294   tcase_add_checked_fixture (tc_chain, setup_amrwb, teardown);
295   tcase_add_test (tc_chain, test_parse_wb_normal);
296   tcase_add_test (tc_chain, test_parse_wb_drain_single);
297   tcase_add_test (tc_chain, test_parse_wb_drain_garbage);
298   tcase_add_test (tc_chain, test_parse_wb_split);
299   tcase_add_test (tc_chain, test_parse_wb_detect_stream);
300   tcase_add_test (tc_chain, test_parse_wb_skip_garbage);
301   suite_add_tcase (s, tc_chain);
302 
303   return s;
304 }
305 
306 GST_CHECK_MAIN (amrparse)
307