2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "gnashconfig.h"
28 #ifdef HAVE_GST_INTERFACES_PROBEPROBE_H
29 #include <gst/interfaces/propertyprobe.h>
36 //get rc file for webcam selection
37 gnash::RcInitFile
& rcfile
= gnash::RcInitFile::getDefaultInstance();
52 gint
findAudioDevs(std::vector
<data
*>& audioVect
) {
57 element
= gst_element_factory_make ("audiotestsrc", "audiotestsrc");
59 if (element
== NULL
) {
60 audioVect
.push_back(NULL
);
63 audioVect
.push_back(new data
);
64 audioVect
[numdevs
]->deviceName
= g_strdup_printf("audiotestsrc");
65 audioVect
[numdevs
]->deviceType
= g_strdup_printf("audiotestsrc");
70 GstPropertyProbe
*probe
;
74 element
= gst_element_factory_make ("pulsesrc", "pulsesrc");
75 probe
= GST_PROPERTY_PROBE (element
);
76 devarr
= gst_property_probe_probe_and_get_values_name (probe
, "device");
77 for (size_t i
= 0; devarr
!= NULL
&& i
< devarr
->n_values
; ++i
) {
79 gchar
*dev_name
= NULL
;
81 val
= g_value_array_get_nth (devarr
, i
);
82 g_object_set (element
, "device", g_value_get_string (val
), NULL
);
83 gst_element_set_state (element
, GST_STATE_PLAYING
);
84 g_object_get (element
, "device-name", &dev_name
, NULL
);
85 gst_element_set_state (element
, GST_STATE_NULL
);
86 if (strcmp(dev_name
, "null") == 0) {
87 g_print("no pulse audio sources found\n");
89 else if ((strstr(dev_name
, "Monitor") != NULL
)) {
90 g_print("ignoring monitor (audio output)");
93 audioVect
.push_back(new data
);
94 audioVect
[numdevs
]->deviceType
= g_strdup_printf("pulsesrc");
95 audioVect
[numdevs
]->deviceName
= dev_name
;
100 g_value_array_free (devarr
);
106 //initialize gstreamer to probe for devs
107 gst_init(NULL
, NULL
);
109 std::vector
<data
*> audioVector
;
112 int fromrc
= rcfile
.getAudioInputDevice();
115 g_print("Use this utility to set your desired default microphone device.\n");
116 numdevs
= findAudioDevs(audioVector
);
117 g_print("\nFound %d audio input devices: \n\n", numdevs
);
118 for (i
= 0; i
< numdevs
; ++i
)
120 if (i
== 0 && (audioVector
[i
] != 0)) {
121 g_print("%d. device[%d] = Audio Test Source (audiotestsrc)\n", i
, i
);
122 } else if (i
== 0 && (audioVector
[i
] == 0)) {
123 g_print("no test audio device available\n");
125 g_print("%d. device[%d] = %s (%s)\n", i
, i
, audioVector
[i
]->deviceName
,
126 audioVector
[i
]->deviceType
);
129 //prompt user for device selection
134 g_print("\nChoose the device you would like to use (0-%d): ",
137 if (fromCin
.size() != 1) {
139 } else if (fromCin
[0] == '0') {
142 dev_select
= atoi(fromCin
.c_str());
144 if ((dev_select
< 0) || (dev_select
> (numdevs
- 1))) {
145 g_print("You must make a valid device selection\n");
147 } while ((dev_select
< 0) || (dev_select
> (numdevs
- 1)));
148 g_print("\nTo select this microphone, add this line to your gnashrc file:\n");
149 g_print("set microphoneDevice %d\n", dev_select
);
151 numdevs
= findAudioDevs(audioVector
);
152 if (fromrc
<= (audioVector
.size() - 1)) {
153 g_print("\nThe gnashrc file reports default microphone is set to:\n");
154 g_print("%s (%s)\n", audioVector
[fromrc
]->deviceName
,
155 audioVector
[fromrc
]->deviceType
);
156 g_print("To change this setting, delete the 'set microphoneDevice' line\n");
157 g_print("from your gnashrc file and re-run this program.\n\n");
159 g_print("\nYou have an invalid microphone chosen in your gnashrc file.\n");
160 g_print("Try reattaching the device or deleting the value from gnashrc\n");
161 g_print("and running this program again\n");