]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugins-ugly0-10.git/blob - tests/check/elements/amrnbenc.c
tests/check/elements/amrnbenc.c: Init memory before feeding it to the encoder to...
[glsdk/gst-plugins-ugly0-10.git] / tests / check / elements / amrnbenc.c
1 /*
2  * GStreamer
3  *
4  * unit test for amrnbenc
5  *
6  * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
7  *
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.
12  *
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.
17  *
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.
22  */
24 #include <gst/check/gstcheck.h>
26 #define SRC_CAPS "audio/x-raw-int,width=16,depth=16,channels=1,rate=8000"
27 #define SINK_CAPS "audio/AMR"
29 GList *buffers;
30 GList *current_buf = NULL;
32 GstPad *srcpad, *sinkpad;
34 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
35     GST_PAD_SINK,
36     GST_PAD_ALWAYS,
37     GST_STATIC_CAPS (SINK_CAPS)
38     );
40 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
41     GST_PAD_SRC,
42     GST_PAD_ALWAYS,
43     GST_STATIC_CAPS (SRC_CAPS)
44     );
46 /* takes a copy of the passed buffer data */
47 GstBuffer *
48 buffer_new (const gchar * buffer_data, guint size)
49 {
50   GstBuffer *buffer;
51   GstCaps *caps;
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);
59   return buffer;
60 }
62 static void
63 buffer_unref (void *buffer, void *user_data)
64 {
65   gst_buffer_unref (GST_BUFFER (buffer));
66 }
68 GstElement *
69 setup_amrnbenc ()
70 {
71   GstElement *amrnbenc;
72   GstBus *bus;
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);
81   bus = gst_bus_new ();
82   gst_element_set_bus (amrnbenc, bus);
84   fail_unless (gst_element_set_state (amrnbenc,
85           GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
86       "could not set to playing");
88   buffers = NULL;
89   return amrnbenc;
90 }
92 static void
93 cleanup_amrnbenc (GstElement * amrnbenc)
94 {
95   GstBus *bus;
97   /* free encoded buffers */
98   g_list_foreach (buffers, buffer_unref, NULL);
99   g_list_free (buffers);
100   buffers = NULL;
102   bus = GST_ELEMENT_BUS (amrnbenc);
103   gst_bus_set_flushing (bus, TRUE);
104   gst_object_unref (bus);
106   GST_DEBUG ("cleanup_amrnbenc");
107   gst_check_teardown_src_pad (amrnbenc);
108   gst_check_teardown_sink_pad (amrnbenc);
109   gst_check_teardown_element (amrnbenc);
112 /* push a random block of audio of the given size */
113 static void
114 push_data (gint size, GstFlowReturn expected_return)
116   GstBuffer *buffer;
117   GstFlowReturn res;
118   gchar *data = g_malloc0 (size);
120   buffer = buffer_new (data, size);
121   g_free (data);
122   res = gst_pad_push (srcpad, buffer);
123   fail_unless (res == expected_return,
124       "pushing audio returned %d not %d", res, expected_return);
127 GST_START_TEST (test_enc)
129   GstElement *amrnbenc;
131   amrnbenc = setup_amrnbenc ();
132   push_data (1000, GST_FLOW_OK);
134   cleanup_amrnbenc (amrnbenc);
137 GST_END_TEST;
139 static Suite *
140 amrnbenc_suite ()
142   Suite *s = suite_create ("amrnbenc");
143   TCase *tc_chain = tcase_create ("general");
145   suite_add_tcase (s, tc_chain);
146   tcase_add_test (tc_chain, test_enc);
147   return s;
150 int
151 main (int argc, char **argv)
153   int nf;
155   Suite *s = amrnbenc_suite ();
156   SRunner *sr = srunner_create (s);
158   gst_check_init (&argc, &argv);
160   srunner_run_all (sr, CK_NORMAL);
161   nf = srunner_ntests_failed (sr);
162   srunner_free (sr);
164   return nf;