Improve stats counter to show hit/skips
[gnash.git] / utilities / findmicrophones.cpp
blobe368b5c654dcb239a9dde081ef0d723851c34381
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
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.
9 //
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.
14 //
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
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
23 #include "rc.h"
24 #ifdef HAVE_GST_GST_H
25 #include "gst/gst.h"
26 #endif
28 #ifdef HAVE_GST_INTERFACES_PROBEPROBE_H
29 #include <gst/interfaces/propertyprobe.h>
30 #endif
32 #include <vector>
33 #include <string>
35 namespace {
36 //get rc file for webcam selection
37 gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
40 class data {
41 public:
42 data();
43 gchar* deviceName;
44 gchar* deviceType;
47 data::data() {
48 deviceName = NULL;
49 deviceType = NULL;
52 gint findAudioDevs(std::vector<data*>& audioVect) {
53 gint numdevs = 0;
55 //vid test source
56 GstElement *element;
57 element = gst_element_factory_make ("audiotestsrc", "audiotestsrc");
59 if (element == NULL) {
60 audioVect.push_back(NULL);
61 numdevs += 1;
62 } else {
63 audioVect.push_back(new data);
64 audioVect[numdevs]->deviceName = g_strdup_printf("audiotestsrc");
65 audioVect[numdevs]->deviceType = g_strdup_printf("audiotestsrc");
66 numdevs += 1;
69 //pulseaudio src
70 GstPropertyProbe *probe;
71 GValueArray *devarr;
72 element = NULL;
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) {
78 GValue *val;
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)");
92 else {
93 audioVect.push_back(new data);
94 audioVect[numdevs]->deviceType = g_strdup_printf("pulsesrc");
95 audioVect[numdevs]->deviceName = dev_name;
96 numdevs += 1;
99 if (devarr) {
100 g_value_array_free (devarr);
102 return numdevs;
105 int main () {
106 //initialize gstreamer to probe for devs
107 gst_init(NULL, NULL);
108 gint numdevs = 0;
109 std::vector<data*> audioVector;
110 gint i;
112 int fromrc = rcfile.getAudioInputDevice();
114 if (fromrc == -1) {
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");
124 } else {
125 g_print("%d. device[%d] = %s (%s)\n", i, i, audioVector[i]->deviceName,
126 audioVector[i]->deviceType);
129 //prompt user for device selection
130 int dev_select = -1;
131 std::string fromCin;
132 do {
133 dev_select = -1;
134 g_print("\nChoose the device you would like to use (0-%d): ",
135 (numdevs - 1));
136 std::cin >> fromCin;
137 if (fromCin.size() != 1) {
138 dev_select = -1;
139 } else if (fromCin[0] == '0') {
140 dev_select = 0;
141 } else {
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);
150 } else {
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");
158 } else {
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");
164 return 1;