1 /*
2 * GStreamer
3 *
4 * unit test for aacparse
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_TMPL "audio/mpeg, parsed=(boolean)false, mpegversion=(int)1"
30 #define SINK_CAPS_TMPL "audio/mpeg, parsed=(boolean)true, mpegversion=(int)1"
31
32 GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33 GST_PAD_SINK,
34 GST_PAD_ALWAYS,
35 GST_STATIC_CAPS (SINK_CAPS_TMPL)
36 );
37
38 GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
39 GST_PAD_SRC,
40 GST_PAD_ALWAYS,
41 GST_STATIC_CAPS (SRC_CAPS_TMPL)
42 );
43
44 /* some data */
45 static guint8 mp3_frame[384] = {
46 0xff, 0xfb, 0x94, 0xc4, 0xff, 0x83, 0xc0, 0x00,
47 0x01, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
48 0x34, 0x80, 0x00, 0x00, 0x04, 0x00,
49 };
50
51 static guint8 garbage_frame[] = {
52 0xff, 0xff, 0xff, 0xff, 0xff
53 };
54
55
GST_START_TEST(test_parse_normal)56 GST_START_TEST (test_parse_normal)
57 {
58 gst_parser_test_normal (mp3_frame, sizeof (mp3_frame));
59 }
60
61 GST_END_TEST;
62
63
GST_START_TEST(test_parse_drain_single)64 GST_START_TEST (test_parse_drain_single)
65 {
66 gst_parser_test_drain_single (mp3_frame, sizeof (mp3_frame));
67 }
68
69 GST_END_TEST;
70
71
GST_START_TEST(test_parse_drain_garbage)72 GST_START_TEST (test_parse_drain_garbage)
73 {
74 gst_parser_test_drain_garbage (mp3_frame, sizeof (mp3_frame),
75 garbage_frame, sizeof (garbage_frame));
76 }
77
78 GST_END_TEST;
79
80
GST_START_TEST(test_parse_split)81 GST_START_TEST (test_parse_split)
82 {
83 gst_parser_test_split (mp3_frame, sizeof (mp3_frame));
84 }
85
86 GST_END_TEST;
87
88
GST_START_TEST(test_parse_skip_garbage)89 GST_START_TEST (test_parse_skip_garbage)
90 {
91 gst_parser_test_skip_garbage (mp3_frame, sizeof (mp3_frame),
92 garbage_frame, sizeof (garbage_frame));
93 }
94
95 GST_END_TEST;
96
97
98 #define structure_get_int(s,f) \
99 (g_value_get_int(gst_structure_get_value(s,f)))
100 #define fail_unless_structure_field_int_equals(s,field,num) \
101 fail_unless_equals_int (structure_get_int(s,field), num)
102
GST_START_TEST(test_parse_detect_stream)103 GST_START_TEST (test_parse_detect_stream)
104 {
105 GstStructure *s;
106 GstCaps *caps;
107
108 caps = gst_parser_test_get_output_caps (mp3_frame, sizeof (mp3_frame), NULL);
109
110 fail_unless (caps != NULL);
111
112 GST_LOG ("mpegaudio output caps: %" GST_PTR_FORMAT, caps);
113 s = gst_caps_get_structure (caps, 0);
114 fail_unless (gst_structure_has_name (s, "audio/mpeg"));
115 fail_unless_structure_field_int_equals (s, "mpegversion", 1);
116 fail_unless_structure_field_int_equals (s, "layer", 3);
117 fail_unless_structure_field_int_equals (s, "channels", 1);
118 fail_unless_structure_field_int_equals (s, "rate", 48000);
119
120 gst_caps_unref (caps);
121 }
122
123 GST_END_TEST;
124
125
126 static Suite *
mpegaudioparse_suite(void)127 mpegaudioparse_suite (void)
128 {
129 Suite *s = suite_create ("mpegaudioparse");
130 TCase *tc_chain = tcase_create ("general");
131
132
133 /* init test context */
134 ctx_factory = "mpegaudioparse";
135 ctx_sink_template = &sinktemplate;
136 ctx_src_template = &srctemplate;
137
138 suite_add_tcase (s, tc_chain);
139 tcase_add_test (tc_chain, test_parse_normal);
140 tcase_add_test (tc_chain, test_parse_drain_single);
141 tcase_add_test (tc_chain, test_parse_drain_garbage);
142 tcase_add_test (tc_chain, test_parse_split);
143 tcase_add_test (tc_chain, test_parse_skip_garbage);
144 tcase_add_test (tc_chain, test_parse_detect_stream);
145
146 return s;
147 }
148
149
150 /*
151 * TODO:
152 * - Both push- and pull-modes need to be tested
153 * * Pull-mode & EOS
154 */
155 GST_CHECK_MAIN (mpegaudioparse);
156