1 /* GStreamer OSS4 audio tests
2  * Copyright (C) 2007-2008 Tim-Philipp Müller <tim centricular net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
21  * with newer GLib versions (>= 2.31.0) */
22 #define GLIB_DISABLE_DEPRECATION_WARNINGS
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <string.h>
29 #include <stdlib.h>
30 
31 #include <gst/gst.h>
32 
33 static gboolean opt_show_mixer_messages = FALSE;
34 
35 #define WAIT_TIME  60.0         /* in seconds */
36 
37 static void
probe_pad(GstElement * element,const gchar * pad_name)38 probe_pad (GstElement * element, const gchar * pad_name)
39 {
40   GstCaps *caps = NULL;
41   GstPad *pad;
42   guint i;
43 
44   pad = gst_element_get_static_pad (element, pad_name);
45   if (pad == NULL)
46     return;
47 
48   caps = gst_pad_query_caps (pad, NULL);
49   g_return_if_fail (caps != NULL);
50 
51   for (i = 0; i < gst_caps_get_size (caps); ++i) {
52     gchar *s;
53 
54     s = gst_structure_to_string (gst_caps_get_structure (caps, i));
55     g_print ("  %4s[%d]: %s\n", GST_PAD_NAME (pad), i, s);
56     g_free (s);
57   }
58   gst_caps_unref (caps);
59   gst_object_unref (pad);
60 }
61 
62 static void
probe_details(GstElement * element)63 probe_details (GstElement * element)
64 {
65   GstStateChangeReturn ret;
66 
67   ret = gst_element_set_state (element, GST_STATE_READY);
68   if (ret == GST_STATE_CHANGE_FAILURE) {
69     g_print ("Could not set element %s to READY.", GST_ELEMENT_NAME (element));
70     return;
71   }
72 
73   probe_pad (element, "sink");
74   probe_pad (element, "src");
75 
76   gst_element_set_state (element, GST_STATE_NULL);
77 }
78 
79 static void
probe_element(const gchar * name)80 probe_element (const gchar * name)
81 {
82   GstElement *element;
83   gchar *devname = NULL;
84 
85   element = gst_element_factory_make (name, name);
86 
87   /* make sure we don't deadlock on GST_ELEMENT_ERROR or do other silly things
88    * if we try to query the "device-name" property when the device isn't open */
89   g_object_set (element, "device", "/dev/does/not/exist", NULL);
90   g_object_get (element, "device-name", &devname, NULL);
91   GST_LOG ("devname: '%s'", GST_STR_NULL (devname));
92   g_assert (devname == NULL || *devname == '\0');
93 
94   /* and now for real */
95 
96   probe_details (element);
97 
98   gst_object_unref (element);
99 }
100 
101 int
main(int argc,char ** argv)102 main (int argc, char **argv)
103 {
104   GOptionEntry options[] = {
105     {"show-mixer-messages", 'm', 0, G_OPTION_ARG_NONE, &opt_show_mixer_messages,
106         "For mixer elements, wait 60 seconds and show any mixer messages "
107           "(for debugging auto-notifications)", NULL},
108     {NULL,}
109   };
110   GOptionContext *ctx;
111   GError *err = NULL;
112 
113   ctx = g_option_context_new ("");
114   g_option_context_add_main_entries (ctx, options, NULL);
115   g_option_context_add_group (ctx, gst_init_get_option_group ());
116   if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
117     g_print ("Error initializing: %s\n", err->message);
118     g_option_context_free (ctx);
119     g_clear_error (&err);
120     exit (1);
121   }
122   g_option_context_free (ctx);
123 
124   probe_element ("oss4sink");
125   probe_element ("oss4src");
126 
127   return 0;
128 }
129