5 * Copyright (C) <2009> Mark Nauwelaerts <mnauw@users.sf.net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
27 /* For ease of programming we use globals to keep refs for our floating
28 * src and sink pads we create; otherwise we always have to do get_pad,
29 * get_peer, and then remove references in every test function */
30 static GstPad *mysrcpad, *mysinkpad;
32 #define AUDIO_CAPS_STRING "audio/x-raw-int, " \
33 "rate = (int) 48000, " \
34 "channels = (int) 2, " \
35 "width = (int) 16, " \
36 "depth = (int) 16, " \
37 "signed = (boolean) true, " \
38 "endianness = (int) BYTE_ORDER "
40 #define AAC_RAW_CAPS_STRING "audio/mpeg, " \
41 "mpegversion = (int) 4, " \
42 "rate = (int) 48000, " \
43 "channels = (int) 2, " \
44 "stream-format = \"raw\""
46 #define AAC_ADTS_CAPS_STRING "audio/mpeg, " \
47 "mpegversion = (int) 4, " \
48 "rate = (int) 48000, " \
49 "channels = (int) 2, " \
50 "stream-format = \"adts\""
52 static GstStaticPadTemplate sinktemplate_adts = GST_STATIC_PAD_TEMPLATE ("sink",
55 GST_STATIC_CAPS (AAC_ADTS_CAPS_STRING));
57 static GstStaticPadTemplate sinktemplate_raw = GST_STATIC_PAD_TEMPLATE ("sink",
60 GST_STATIC_CAPS (AAC_RAW_CAPS_STRING));
62 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
65 GST_STATIC_CAPS (AUDIO_CAPS_STRING));
69 setup_faac (gboolean adts)
73 GST_DEBUG ("setup_faac");
74 faac = gst_check_setup_element ("faac");
75 g_object_set (faac, "profile", 2, NULL);
76 mysrcpad = gst_check_setup_src_pad (faac, &srctemplate, NULL);
79 mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_adts, NULL);
81 mysinkpad = gst_check_setup_sink_pad (faac, &sinktemplate_raw, NULL);
83 gst_pad_set_active (mysrcpad, TRUE);
84 gst_pad_set_active (mysinkpad, TRUE);
90 cleanup_faac (GstElement * faac)
92 GST_DEBUG ("cleanup_faac");
93 gst_element_set_state (faac, GST_STATE_NULL);
95 gst_pad_set_active (mysrcpad, FALSE);
96 gst_pad_set_active (mysinkpad, FALSE);
97 gst_check_teardown_src_pad (faac);
98 gst_check_teardown_sink_pad (faac);
99 gst_check_teardown_element (faac);
103 do_test (gboolean adts)
106 GstBuffer *inbuffer, *outbuffer;
109 const gint nbuffers = 10;
111 faac = setup_faac (adts);
112 fail_unless (gst_element_set_state (faac,
113 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
114 "could not set to playing");
116 /* corresponds to audio buffer mentioned in the caps */
117 inbuffer = gst_buffer_new_and_alloc (1024 * nbuffers * 2 * 2);
118 /* makes valgrind's memcheck happier */
119 memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
120 caps = gst_caps_from_string (AUDIO_CAPS_STRING);
121 gst_buffer_set_caps (inbuffer, caps);
122 gst_caps_unref (caps);
123 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
124 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
125 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
127 /* send eos to have all flushed if needed */
128 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
130 num_buffers = g_list_length (buffers);
131 fail_unless_equals_int (num_buffers, nbuffers + 1);
133 /* clean up buffers */
134 for (i = 0; i < num_buffers; ++i) {
135 gint size, header = 0, id;
138 outbuffer = GST_BUFFER (buffers->data);
139 fail_if (outbuffer == NULL);
141 data = GST_BUFFER_DATA (outbuffer);
142 size = GST_BUFFER_SIZE (outbuffer);
149 protection = !(data[1] & 0x1);
150 /* expect only 1 raw data block */
151 k = (data[6] & 0x3) + 1;
156 header += (k - 1) * 2 + 2;
159 k = GST_READ_UINT16_BE (data) & 0xFFF6;
161 fail_unless (k == 0xFFF0);
164 fail_unless ((k >> 6) == 0x1);
166 fail_unless (((k >> 2) & 0xF) == 0x3);
168 fail_unless ((k & 0x1) == 0);
170 fail_unless ((k >> 6) == 0x2);
178 caps = gst_buffer_get_caps (outbuffer);
179 fail_if (caps == NULL);
180 s = gst_caps_get_structure (caps, 0);
182 value = gst_structure_get_value (s, "codec_data");
183 fail_if (value == NULL);
184 buf = gst_value_get_buffer (value);
185 fail_if (buf == NULL);
186 data = GST_BUFFER_DATA (buf);
187 size = GST_BUFFER_SIZE (buf);
189 k = GST_READ_UINT16_BE (data);
190 /* profile, rate, channels */
191 fail_unless ((k & 0xFFF8) == ((0x02 << 11) | (0x3 << 7) | (0x02 << 3)));
192 gst_caps_unref (caps);
195 fail_if (size <= header);
196 id = data[header] & (0x7 << 5);
197 /* allow all but ID_END or ID_LFE */
198 fail_if (id == 7 || id == 3);
200 buffers = g_list_remove (buffers, outbuffer);
202 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
203 gst_buffer_unref (outbuffer);
208 g_list_free (buffers);
212 GST_START_TEST (test_adts)
219 GST_START_TEST (test_raw)
229 Suite *s = suite_create ("faac");
230 TCase *tc_chain = tcase_create ("general");
232 suite_add_tcase (s, tc_chain);
233 tcase_add_test (tc_chain, test_adts);
234 tcase_add_test (tc_chain, test_raw);
240 main (int argc, char **argv)
244 Suite *s = faac_suite ();
245 SRunner *sr = srunner_create (s);
247 gst_check_init (&argc, &argv);
249 srunner_run_all (sr, CK_NORMAL);
250 nf = srunner_ntests_failed (sr);