gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11288: added a utility to enumerate


From: Ben Limmer
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11288: added a utility to enumerate attached microphones for use with gnashrc file
Date: Mon, 20 Jul 2009 15:10:47 -0600
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11288
committer: Ben Limmer <address@hidden>
branch nick: trunk
timestamp: Mon 2009-07-20 15:10:47 -0600
message:
  added a utility to enumerate attached microphones for use with gnashrc file
added:
  utilities/findmicrophones.cpp
modified:
  libbase/rc.cpp
  libbase/rc.h
  utilities/Makefile.am
  utilities/findwebcams.cpp
=== modified file 'libbase/rc.cpp'
--- a/libbase/rc.cpp    2009-07-16 18:46:00 +0000
+++ b/libbase/rc.cpp    2009-07-20 21:10:47 +0000
@@ -107,7 +107,8 @@
     _saveLoadedMedia(false),
     _popups(true),
     _useXv(false),
-       _webcamDevice(-1)
+       _webcamDevice(-1),
+    _microphoneDevice(-1)
 {
     expandPath(_solsandbox);
     loadFiles();
@@ -547,6 +548,8 @@
             ||
                                 extractNumber(_webcamDevice, "webcamDevice", 
variable, 
                                                 value)
+            ||
+                 extractNumber(_microphoneDevice, "microphoneDevice", 
variable, value)
                        ||
                  cerr << boost::format(_("Warning: unrecognized directive "
                              "\"%s\" in rcfile %s line %d")) 

=== modified file 'libbase/rc.h'
--- a/libbase/rc.h      2009-07-16 18:46:00 +0000
+++ b/libbase/rc.h      2009-07-20 21:10:47 +0000
@@ -290,6 +290,10 @@
        void setWebcamDevice(int value) {_webcamDevice = value;}
        
        int getWebcamDevice() const {return _webcamDevice;}
+    
+    void setAudioInputDevice(int value) {_microphoneDevice = value;}
+    
+    int getAudioInputDevice() {return _microphoneDevice;}
 
     void dump();    
 
@@ -518,6 +522,8 @@
        ///FIXME: this should probably eventually be changed to a more readable
        ///config option instead of an integer
        int _webcamDevice;
+    
+    int _microphoneDevice;
 
 };
 

=== modified file 'utilities/Makefile.am'
--- a/utilities/Makefile.am     2009-07-18 07:32:58 +0000
+++ b/utilities/Makefile.am     2009-07-20 21:10:47 +0000
@@ -87,6 +87,7 @@
 
 if USE_GST_ENGINE
  bin_PROGRAMS += findwebcams
+ bin_PROGRAMS += findmicrophones
 endif
 
 gprocessor_SOURCES = processor.cpp
@@ -107,6 +108,9 @@
 if USE_GST_ENGINE
  findwebcams_SOURCES = findwebcams.cpp
  findwebcams_LDADD = $(GNASH_LIBS) $(AM_LDFLAGS)
+ 
+ findmicrophones_SOURCES = findmicrophones.cpp
+ findmicrophones_LDADD = $(GNASH_LIBS) $(AM_LDFLAGS)
 endif
 
 # Rebuild with GCC 4.x Mudflap support

=== added file 'utilities/findmicrophones.cpp'
--- a/utilities/findmicrophones.cpp     1970-01-01 00:00:00 +0000
+++ b/utilities/findmicrophones.cpp     2009-07-20 21:10:47 +0000
@@ -0,0 +1,151 @@
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+#ifdef HAVE_CONFIG_H
+#include "gnashconfig.h"
+#endif
+
+#include "rc.h"
+#include "gst/gst.h"
+#include <gst/interfaces/propertyprobe.h>
+
+#include <vector>
+#include <string>
+
+namespace {
+    //get rc file for webcam selection
+    gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
+}
+
+class data {
+    public:
+        data();
+        gchar* deviceName;
+        gchar* deviceType;
+};
+
+data::data() {
+    deviceName = NULL;
+    deviceType = NULL;
+};
+
+gint findAudioDevs(std::vector<data*>& audioVect) {
+    gint numdevs = 0;
+    
+    //vid test source
+    GstElement *element;
+    element = gst_element_factory_make ("audiotestsrc", "audiotestsrc");
+    
+    if (element == NULL) {
+        audioVect.push_back(NULL);
+        numdevs += 1;
+    } else {
+        audioVect.push_back(new data);
+        audioVect[numdevs]->deviceName = g_strdup_printf("audiotestsrc");
+        audioVect[numdevs]->deviceType = g_strdup_printf("audiotestsrc");
+        numdevs += 1;
+    }
+    
+    //pulseaudio src
+    GstPropertyProbe *probe;
+    GValueArray *devarr;
+    element = NULL;
+    gint i;
+    
+    element = gst_element_factory_make ("pulsesrc", "pulsesrc");
+    probe = GST_PROPERTY_PROBE (element);
+    devarr = gst_property_probe_probe_and_get_values_name (probe, "device");
+    for (i = 0; devarr != NULL && i < devarr->n_values; ++i) {
+        GValue *val;
+        gchar *dev_name = NULL;
+        
+        val = g_value_array_get_nth (devarr, i);
+        g_object_set (element, "device", g_value_get_string (val), NULL);
+        gst_element_set_state (element, GST_STATE_PLAYING);
+        g_object_get (element, "device-name", &dev_name, NULL);
+        gst_element_set_state (element, GST_STATE_NULL);
+        if (dev_name == "null") {
+            g_print("no pulse audio sources found\n");
+        }
+        else { 
+            audioVect.push_back(new data);
+            audioVect[numdevs]->deviceType = g_strdup_printf("pulsesrc");
+            audioVect[numdevs]->deviceName = dev_name;
+            numdevs += 1;
+        }
+    }
+    if (devarr) {
+        g_value_array_free (devarr);
+    }
+    return numdevs;
+}
+
+int main () {
+    //initialize gstreamer to probe for devs
+    gst_init(NULL, NULL);
+    gint numdevs = 0;
+    std::vector<data*> audioVector;
+    gint i;
+    
+    int fromrc = rcfile.getAudioInputDevice();
+    
+    if (fromrc == -1) {
+        g_print("Use this utility to set your desired default microphone 
device.\n");
+        numdevs = findAudioDevs(audioVector);
+        g_print("\nFound %d audio input devices: \n\n", numdevs);
+        for (i = 0; i < numdevs; ++i)
+        {
+            if (i == 0 && (audioVector[i] != 0)) {
+                g_print("%d. device[%d] = Audio Test Source (audiotestsrc)\n", 
i, i);
+            } else if (i == 0 && (audioVector[i] == 0)) {
+                g_print("no test audio device available\n");
+            } else {
+                g_print("%d. device[%d] = %s (%s)\n", i, i, 
audioVector[i]->deviceName,
+                        audioVector[i]->deviceType);
+            }
+        }
+        //prompt user for device selection
+        int dev_select = -1;
+        std::string fromCin;
+        do {
+            dev_select = -1;
+            g_print("\nChoose the device you would like to use (0-%d): ",
+                (numdevs - 1));
+            std::cin >> fromCin;
+            if (fromCin.size() != 1) {
+                dev_select = -1;
+            } else if (fromCin[0] == '0') {
+                dev_select = 0;
+            } else {
+                dev_select = atoi(fromCin.c_str());
+            }
+            if ((dev_select < 0) || (dev_select > (numdevs - 1))) {
+                g_print("You must make a valid device selection\n");
+            }
+        } while ((dev_select < 0) || (dev_select > (numdevs - 1)));
+        g_print("\nTo select this microphone, add this line to your gnashrc 
file:\n");
+        g_print("set microphoneDevice %d\n", dev_select);
+    } else {
+        numdevs = findAudioDevs(audioVector);
+        g_print("\nThe gnashrc file reports default microphone is set to:\n");
+        g_print("%s (%s)\n", audioVector[fromrc]->deviceName,
+            audioVector[fromrc]->deviceType);
+        g_print("To change this setting, delete the 'set microphoneDevice' 
line\n");
+        g_print("from your gnashrc file and re-run this program.\n\n");
+    }
+    return 1;
+}

=== modified file 'utilities/findwebcams.cpp'
--- a/utilities/findwebcams.cpp 2009-07-17 21:38:26 +0000
+++ b/utilities/findwebcams.cpp 2009-07-20 21:10:47 +0000
@@ -24,6 +24,7 @@
 #include <gst/interfaces/propertyprobe.h>
 
 #include <vector>
+#include <string>
 
 namespace {
     //get rc file for webcam selection
@@ -153,11 +154,19 @@
         }
         //prompt user for device selection
         int dev_select = -1;
+        std::string fromCin;
         do {
             dev_select = -1;
             g_print("\nChoose the device you would like to use (0-%d): ",
                 (numdevs - 1));
-            std::cin >> dev_select;
+            std::cin >> fromCin;
+            if (fromCin.size() != 1) {
+                dev_select = -1;
+            } else if (fromCin[0] == '0') {
+                dev_select = 0;
+            } else {
+                dev_select = atoi(fromCin.c_str());
+            }
             if ((dev_select < 0) || (dev_select > (numdevs - 1))) {
                 g_print("You must make a valid device selection\n");
             }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]