Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / gst / audioconvert / channelmixtest.c
1 /* GStreamer
2  * Copyright (C) 2005 Benjamin Otte <otte@gnome.org>
3  *
4  * channelmixtest.c: simple test of channel mixing
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "gstchannelmix.h"
27 #include "plugin.h"
28
29 int
30 main (gint argc, gchar ** argv)
31 {
32   GstElement *bin, *src, *sink;
33   GstAudioConvert *c;
34   GstCaps *caps;
35   guint i, j, k;
36   struct
37   {
38     gchar *sinkcaps;
39     gchar *srccaps;
40     gfloat matrix[6][6];        /* use a predefined matrix here, makes stuff simpler */
41   } tests[] = {
42     /* stereo => mono */
43     {
44       "audio/x-raw-int, channels=2", "audio/x-raw-int, channels=1", { {
45       0.5,}, {
46     0.5,},}},
47         /* mono => stereo */
48     {
49       "audio/x-raw-int, channels=1", "audio/x-raw-int, channels=2", { {
50     1, 1,},}}
51   };
52
53   gst_init (&argc, &argv);
54
55   for (i = 0; i < G_N_ELEMENTS (tests); i++) {
56     g_print ("running test %u\n", i);
57     bin = gst_element_factory_make ("pipeline", NULL);
58     c = g_object_new (GST_TYPE_AUDIO_CONVERT, NULL);
59     /* avoid gst being braindead */
60     gst_object_set_name (GST_OBJECT (c), "shuddup");
61     src = gst_element_factory_make ("fakesrc", NULL);
62     sink = gst_element_factory_make ("fakesink", NULL);
63     gst_bin_add_many (GST_BIN (bin), src, c, sink, NULL);
64     caps = gst_caps_from_string (tests[i].sinkcaps);
65     g_assert (caps);
66     if (!gst_element_link_filtered (src, GST_ELEMENT (c), caps))
67       g_assert_not_reached ();
68     gst_caps_unref (caps);
69     caps = gst_caps_from_string (tests[i].srccaps);
70     g_assert (caps);
71     if (!gst_element_link_filtered (GST_ELEMENT (c), sink, caps))
72       g_assert_not_reached ();
73     gst_caps_unref (caps);
74     if (!gst_element_set_state (bin, GST_STATE_PLAYING))
75       g_assert_not_reached ();
76     g_assert (c->srccaps.channels <= 6);
77     g_assert (c->sinkcaps.channels <= 6);
78     for (j = 0; j < 6; j++) {
79       for (k = 0; k < 6; k++) {
80         if (j < c->sinkcaps.channels && k < c->srccaps.channels) {
81           if (tests[i].matrix[j][k] != c->matrix[j][k]) {
82             g_printerr ("matrix[j][k] should be %g but is %g\n",
83                 tests[i].matrix[j][k], c->matrix[j][k]);
84             g_assert_not_reached ();
85           }
86         } else {
87           g_assert (tests[i].matrix[j][k] == 0);
88         }
89       }
90     }
91     gst_object_unref (bin);
92   }
93
94   return 0;
95 }