4 * unit test for amrnbenc
6 * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include <gst/check/gstcheck.h>
26 #define SRC_CAPS "audio/x-raw-int,width=16,depth=16,channels=1,rate=8000,signed=true,endianness=BYTE_ORDER"
27 #define SINK_CAPS "audio/AMR"
30 GList *current_buf = NULL;
32 GstPad *srcpad, *sinkpad;
34 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
37 GST_STATIC_CAPS (SINK_CAPS)
40 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
43 GST_STATIC_CAPS (SRC_CAPS)
46 /* takes a copy of the passed buffer data */
48 buffer_new (const gchar * buffer_data, guint size)
53 buffer = gst_buffer_new_and_alloc (size);
54 memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
55 caps = gst_caps_from_string (SRC_CAPS);
56 gst_buffer_set_caps (buffer, caps);
57 gst_caps_unref (caps);
63 buffer_unref (void *buffer, void *user_data)
65 gst_buffer_unref (GST_BUFFER (buffer));
73 guint64 granulerate_n, granulerate_d;
75 GST_DEBUG ("setup_amrnbenc");
77 amrnbenc = gst_check_setup_element ("amrnbenc");
78 srcpad = gst_check_setup_src_pad (amrnbenc, &srctemplate, NULL);
79 sinkpad = gst_check_setup_sink_pad (amrnbenc, &sinktemplate, NULL);
80 gst_pad_set_active (srcpad, TRUE);
81 gst_pad_set_active (sinkpad, TRUE);
84 gst_element_set_bus (amrnbenc, bus);
86 fail_unless (gst_element_set_state (amrnbenc,
87 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
88 "could not set to playing");
95 cleanup_amrnbenc (GstElement * amrnbenc)
99 /* free encoded buffers */
100 g_list_foreach (buffers, buffer_unref, NULL);
101 g_list_free (buffers);
104 bus = GST_ELEMENT_BUS (amrnbenc);
105 gst_bus_set_flushing (bus, TRUE);
106 gst_object_unref (bus);
108 GST_DEBUG ("cleanup_amrnbenc");
109 gst_pad_set_active (srcpad, FALSE);
110 gst_pad_set_active (sinkpad, FALSE);
111 gst_check_teardown_src_pad (amrnbenc);
112 gst_check_teardown_sink_pad (amrnbenc);
113 gst_check_teardown_element (amrnbenc);
116 /* push a random block of audio of the given size */
118 push_data (gint size, GstFlowReturn expected_return)
122 gchar *data = g_malloc0 (size);
124 buffer = buffer_new (data, size);
126 res = gst_pad_push (srcpad, buffer);
127 fail_unless (res == expected_return,
128 "pushing audio returned %d not %d", res, expected_return);
131 GST_START_TEST (test_enc)
133 GstElement *amrnbenc;
135 amrnbenc = setup_amrnbenc ();
136 push_data (1000, GST_FLOW_OK);
138 cleanup_amrnbenc (amrnbenc);
146 Suite *s = suite_create ("amrnbenc");
147 TCase *tc_chain = tcase_create ("general");
149 suite_add_tcase (s, tc_chain);
150 tcase_add_test (tc_chain, test_enc);
155 main (int argc, char **argv)
159 Suite *s = amrnbenc_suite ();
160 SRunner *sr = srunner_create (s);
162 gst_check_init (&argc, &argv);
164 srunner_run_all (sr, CK_NORMAL);
165 nf = srunner_ntests_failed (sr);