upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / pipelines / wavenc.c
1 /* GStreamer
2  *
3  * unit test for wavenc
4  *
5  * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/multichannel.h>
25
26 static gboolean
27 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
28 {
29   GMainLoop *loop = (GMainLoop *) data;
30
31   switch (message->type) {
32     case GST_MESSAGE_EOS:
33       g_main_loop_quit (loop);
34       break;
35     case GST_MESSAGE_WARNING:
36     case GST_MESSAGE_ERROR:{
37       GError *gerror;
38       gchar *debug;
39
40       gst_message_parse_error (message, &gerror, &debug);
41       gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
42       gst_message_unref (message);
43       g_error_free (gerror);
44       g_free (debug);
45       g_main_loop_quit (loop);
46       break;
47     }
48     default:
49       break;
50   }
51
52   return TRUE;
53 }
54
55 /*
56  * gst-launch \
57  * audiotestsrc freq=440 num-buffers=100 ! interleave name=i ! wavenc ! filesink location=/tmp/mc.wav \
58  * audiotestsrc freq=880 num-buffers=100 ! i.
59  * ...
60  *
61  * http://www.microsoft.com/whdc/device/audio/multichaud.mspx
62  */
63
64 static void
65 make_n_channel_wav (const gint channels, const GValueArray * arr)
66 {
67   GstElement *pipeline;
68   GstElement **audiotestsrc, *interleave, *wavenc, *fakesink;
69   GstBus *bus;
70   GMainLoop *loop;
71   guint i;
72   guint bus_watch = 0;
73
74   audiotestsrc = g_new0 (GstElement *, channels);
75
76   pipeline = gst_pipeline_new ("pipeline");
77   fail_unless (pipeline != NULL);
78
79   interleave = gst_element_factory_make ("interleave", NULL);
80   fail_unless (interleave != NULL);
81   g_object_set (interleave, "channel-positions", arr, NULL);
82   gst_bin_add (GST_BIN (pipeline), interleave);
83
84   wavenc = gst_element_factory_make ("wavenc", NULL);
85   fail_unless (wavenc != NULL);
86   gst_bin_add (GST_BIN (pipeline), wavenc);
87   fail_unless (gst_element_link (interleave, wavenc));
88
89   fakesink = gst_element_factory_make ("fakesink", NULL);
90   fail_unless (fakesink != NULL);
91   gst_bin_add (GST_BIN (pipeline), fakesink);
92   fail_unless (gst_element_link (wavenc, fakesink));
93
94   for (i = 0; i < channels; i++) {
95     audiotestsrc[i] = gst_element_factory_make ("audiotestsrc", NULL);
96     fail_unless (audiotestsrc[i] != NULL);
97     g_object_set (G_OBJECT (audiotestsrc[i]), "wave", 0, "freq", 440.0 * i,
98         "num-buffers", 100, NULL);
99     gst_bin_add (GST_BIN (pipeline), audiotestsrc[i]);
100     fail_unless (gst_element_link (audiotestsrc[i], interleave));
101   }
102
103   loop = g_main_loop_new (NULL, TRUE);
104   fail_unless (loop != NULL);
105
106   bus = gst_element_get_bus (pipeline);
107   fail_unless (bus != NULL);
108   bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
109   gst_object_unref (bus);
110
111   gst_element_set_state (pipeline, GST_STATE_PLAYING);
112   g_main_loop_run (loop);
113   gst_element_set_state (pipeline, GST_STATE_NULL);
114
115   gst_object_unref (pipeline);
116   g_free (audiotestsrc);
117
118   g_main_loop_unref (loop);
119   g_source_remove (bus_watch);
120 }
121
122 GST_START_TEST (test_encode_stereo)
123 {
124   GValueArray *arr;
125   GValue val = { 0, };
126
127   arr = g_value_array_new (2);
128   g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
129   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
130   g_value_array_append (arr, &val);
131   g_value_reset (&val);
132   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
133   g_value_array_append (arr, &val);
134   g_value_unset (&val);
135
136   make_n_channel_wav (2, arr);
137   g_value_array_free (arr);
138 }
139
140 GST_END_TEST;
141
142 #if 0
143 GST_START_TEST (test_encode_multichannel)
144 {
145   GValueArray *arr;
146   GValue val = { 0, };
147
148   arr = g_value_array_new (6);
149   g_value_init (&val, GST_TYPE_AUDIO_CHANNEL_POSITION);
150   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT);
151   g_value_array_append (arr, &val);
152   g_value_reset (&val);
153   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT);
154   g_value_array_append (arr, &val);
155   g_value_reset (&val);
156   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER);
157   g_value_array_append (arr, &val);
158   g_value_reset (&val);
159   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_LFE);
160   g_value_array_append (arr, &val);
161   g_value_reset (&val);
162   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT);
163   g_value_array_append (arr, &val);
164   g_value_reset (&val);
165   g_value_set_enum (&val, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT);
166   g_value_array_append (arr, &val);
167   g_value_unset (&val);
168
169   make_n_channel_wav (6);
170 }
171
172 GST_END_TEST;
173 #endif
174
175 static Suite *
176 wavenc_suite (void)
177 {
178   Suite *s = suite_create ("wavenc");
179   TCase *tc_chain = tcase_create ("general");
180
181   suite_add_tcase (s, tc_chain);
182   tcase_add_test (tc_chain, test_encode_stereo);
183   /* FIXME: improve wavenc
184      tcase_add_test (tc_chain, test_encode_multichannel);
185    */
186
187   return s;
188 }
189
190 GST_CHECK_MAIN (wavenc);