2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
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>
37 //get rc file for webcam selection
38 gnash::RcInitFile
& rcfile
= gnash::RcInitFile::getDefaultInstance();
53 gint
findAudioDevs(std::vector
<data
*>& audioVect
) {
58 element
= gst_element_factory_make ("audiotestsrc", "audiotestsrc");
60 if (element
== NULL
) {
61 audioVect
.push_back(NULL
);
64 audioVect
.push_back(new data
);
65 audioVect
[numdevs
]->deviceName
= g_strdup_printf("audiotestsrc");
66 audioVect
[numdevs
]->deviceType
= g_strdup_printf("audiotestsrc");
71 GstPropertyProbe
*probe
;
75 element
= gst_element_factory_make ("pulsesrc", "pulsesrc");
76 probe
= GST_PROPERTY_PROBE (element
);
77 devarr
= gst_property_probe_probe_and_get_values_name (probe
, "device");
78 for (size_t i
= 0; devarr
!= NULL
&& i
< devarr
->n_values
; ++i
) {
80 gchar
*dev_name
= NULL
;
82 val
= g_value_array_get_nth (devarr
, i
);
83 g_object_set (element
, "device", g_value_get_string (val
), NULL
);
84 gst_element_set_state (element
, GST_STATE_PLAYING
);
85 g_object_get (element
, "device-name", &dev_name
, NULL
);
86 gst_element_set_state (element
, GST_STATE_NULL
);
87 if (strcmp(dev_name
, "null") == 0) {
88 g_print("no pulse audio sources found\n");
90 else if ((strstr(dev_name
, "Monitor") != NULL
)) {
91 g_print("ignoring monitor (audio output)");
94 audioVect
.push_back(new data
);
95 audioVect
[numdevs
]->deviceType
= g_strdup_printf("pulsesrc");
96 audioVect
[numdevs
]->deviceName
= dev_name
;
101 g_value_array_free (devarr
);
107 //initialize gstreamer to probe for devs
108 gst_init(NULL
, NULL
);
110 std::vector
<data
*> audioVector
;
113 int fromrc
= rcfile
.getAudioInputDevice();
116 g_print("Use this utility to set your desired default microphone device.\n");
117 numdevs
= findAudioDevs(audioVector
);
118 g_print("\nFound %d audio input devices: \n\n", numdevs
);
119 for (i
= 0; i
< numdevs
; ++i
)
121 if (i
== 0 && (audioVector
[i
] != 0)) {
122 g_print("%d. device[%d] = Audio Test Source (audiotestsrc)\n", i
, i
);
123 } else if (i
== 0 && (audioVector
[i
] == 0)) {
124 g_print("no test audio device available\n");
126 g_print("%d. device[%d] = %s (%s)\n", i
, i
, audioVector
[i
]->deviceName
,
127 audioVector
[i
]->deviceType
);
130 //prompt user for device selection
135 g_print("\nChoose the device you would like to use (0-%d): ",
138 if (fromCin
.size() != 1) {
140 } else if (fromCin
[0] == '0') {
143 dev_select
= atoi(fromCin
.c_str());
145 if ((dev_select
< 0) || (dev_select
> (numdevs
- 1))) {
146 g_print("You must make a valid device selection\n");
148 } while ((dev_select
< 0) || (dev_select
> (numdevs
- 1)));
149 g_print("\nTo select this microphone, add this line to your gnashrc file:\n");
150 g_print("set microphoneDevice %d\n", dev_select
);
152 numdevs
= findAudioDevs(audioVector
);
153 if ((size_t)fromrc
< audioVector
.size()) {
154 g_print("\nThe gnashrc file reports default microphone is set to:\n");
155 g_print("%s (%s)\n", audioVector
[fromrc
]->deviceName
,
156 audioVector
[fromrc
]->deviceType
);
157 g_print("To change this setting, delete the 'set microphoneDevice' line\n");
158 g_print("from your gnashrc file and re-run this program.\n\n");
160 g_print("\nYou have an invalid microphone chosen in your gnashrc file.\n");
161 g_print("Try reattaching the device or deleting the value from gnashrc\n");
162 g_print("and running this program again\n");