3 * unit test for voamrwbenc
5 * Copyright (C) <2011> Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
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) 16000, " \
34 "channels = (int) 1, " \
35 "width = (int) 16, " \
36 "depth = (int) 16, " \
37 "signed = (boolean) true, " \
38 "endianness = (int) BYTE_ORDER "
40 #define AMRWB_CAPS_STRING "audio/AMR-WB"
43 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_STATIC_CAPS (AMRWB_CAPS_STRING));
49 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
52 GST_STATIC_CAPS (AUDIO_CAPS_STRING));
56 setup_voamrwbenc (void)
58 GstElement *voamrwbenc;
60 GST_DEBUG ("setup_voamrwbenc");
61 voamrwbenc = gst_check_setup_element ("voamrwbenc");
62 /* ensure mode as expected */
63 g_object_set (voamrwbenc, "band-mode", 0, NULL);
64 mysrcpad = gst_check_setup_src_pad (voamrwbenc, &srctemplate, NULL);
65 mysinkpad = gst_check_setup_sink_pad (voamrwbenc, &sinktemplate, NULL);
66 gst_pad_set_active (mysrcpad, TRUE);
67 gst_pad_set_active (mysinkpad, TRUE);
73 cleanup_voamrwbenc (GstElement * voamrwbenc)
75 GST_DEBUG ("cleanup_aacenc");
76 gst_element_set_state (voamrwbenc, GST_STATE_NULL);
78 gst_pad_set_active (mysrcpad, FALSE);
79 gst_pad_set_active (mysinkpad, FALSE);
80 gst_check_teardown_src_pad (voamrwbenc);
81 gst_check_teardown_sink_pad (voamrwbenc);
82 gst_check_teardown_element (voamrwbenc);
88 GstElement *voamrwbenc;
89 GstBuffer *inbuffer, *outbuffer;
92 const gint nbuffers = 10;
94 voamrwbenc = setup_voamrwbenc ();
95 fail_unless (gst_element_set_state (voamrwbenc,
96 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
97 "could not set to playing");
99 /* corresponds to audio buffer mentioned in the caps */
100 inbuffer = gst_buffer_new_and_alloc (320 * nbuffers * 2);
101 /* makes valgrind's memcheck happier */
102 memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer));
103 caps = gst_caps_from_string (AUDIO_CAPS_STRING);
105 gst_buffer_set_caps (inbuffer, caps);
106 gst_caps_unref (caps);
107 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
108 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
109 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
111 /* send eos to have all flushed if needed */
112 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
114 num_buffers = g_list_length (buffers);
115 fail_unless_equals_int (num_buffers, nbuffers);
117 /* clean up buffers */
118 for (i = 0; i < num_buffers; ++i) {
121 GstClockTime time, dur;
123 outbuffer = GST_BUFFER (buffers->data);
124 fail_if (outbuffer == NULL);
126 data = GST_BUFFER_DATA (outbuffer);
127 size = GST_BUFFER_SIZE (outbuffer);
129 /* at least for mode 0 */
130 fail_unless (size == 18);
131 fail_unless ((data[0] & 0x83) == 0);
132 fail_unless (((data[0] >> 3) & 0xF) == 0);
134 time = GST_BUFFER_TIMESTAMP (outbuffer);
135 dur = GST_BUFFER_DURATION (outbuffer);
136 fail_unless (time == 20 * GST_MSECOND * i);
137 fail_unless (dur == 20 * GST_MSECOND);
139 buffers = g_list_remove (buffers, outbuffer);
141 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
142 gst_buffer_unref (outbuffer);
146 cleanup_voamrwbenc (voamrwbenc);
147 g_list_free (buffers);
151 GST_START_TEST (test_enc)
160 voamrwbenc_suite (void)
162 Suite *s = suite_create ("voamrwbenc");
163 TCase *tc_chain = tcase_create ("general");
165 suite_add_tcase (s, tc_chain);
166 tcase_add_test (tc_chain, test_enc);
172 main (int argc, char **argv)
176 Suite *s = voamrwbenc_suite ();
177 SRunner *sr = srunner_create (s);
179 gst_check_init (&argc, &argv);
181 srunner_run_all (sr, CK_NORMAL);
182 nf = srunner_ntests_failed (sr);