[ekiga/ds-gsettings3] AudioInputCore: Added device auto-selection algorithm.



commit 4dc87560476eda9e0cab012429ad04175488c302
Author: Damien Sandras <dsandras beip be>
Date:   Sat Nov 30 15:39:34 2013 +0100

    AudioInputCore: Added device auto-selection algorithm.
    
    The responsability to choose the best device for the user is now left to
    the Core. The Core will select the best default device in case the
    choosen setting is invalid.
    
    On Linux, we respectively prefer PulseAudio, then ALSA, then the first
    available device if the others are not found.

 lib/engine/audioinput/audioinput-core.cpp |   41 +++++++++++++++++++----------
 lib/engine/audioinput/audioinput-core.h   |   16 +++++++++++
 2 files changed, 43 insertions(+), 14 deletions(-)
---
diff --git a/lib/engine/audioinput/audioinput-core.cpp b/lib/engine/audioinput/audioinput-core.cpp
index c797bba..69e557a 100644
--- a/lib/engine/audioinput/audioinput-core.cpp
+++ b/lib/engine/audioinput/audioinput-core.cpp
@@ -170,37 +170,50 @@ AudioInputCore::set_device (const std::string& device_string)
 
   std::vector<AudioInputDevice> devices;
   AudioInputDevice device;
+  AudioInputDevice device_fallback (AUDIO_INPUT_FALLBACK_DEVICE_TYPE,
+                                    AUDIO_INPUT_FALLBACK_DEVICE_SOURCE,
+                                    AUDIO_INPUT_FALLBACK_DEVICE_NAME);
+  AudioInputDevice device_preferred1 (AUDIO_INPUT_PREFERRED_DEVICE_TYPE1,
+                                      AUDIO_INPUT_PREFERRED_DEVICE_SOURCE1,
+                                      AUDIO_INPUT_PREFERRED_DEVICE_NAME1);
+  AudioInputDevice device_preferred2 (AUDIO_INPUT_PREFERRED_DEVICE_TYPE2,
+                                      AUDIO_INPUT_PREFERRED_DEVICE_SOURCE2,
+                                      AUDIO_INPUT_PREFERRED_DEVICE_NAME2);
   bool found = false;
+  bool found_preferred1 = false;
+  bool found_preferred2 = false;
 
   get_devices (devices);
   for (std::vector<AudioInputDevice>::iterator it = devices.begin ();
        it < devices.end ();
-       it++)
+       it++) {
     if ((*it).GetString () == device_string) {
       found = true;
       break;
     }
+    else if ((*it).GetString () == device_preferred1.GetString ()) {
+      found_preferred1 = true;
+    }
+    else if ((*it).GetString () == device_preferred2.GetString ()) {
+      found_preferred2 = true;
+    }
+  }
 
   if (found)
     device.SetFromString (device_string);
+  else if (found_preferred1)
+    device.SetFromString (device_preferred1.GetString ());
+  else if (found_preferred2)
+    device.SetFromString (device_preferred2.GetString ());
   else if (!devices.empty ())
     device.SetFromString (devices.begin ()->GetString ());
-  std::cout << "FIXME: We should probably fallback to a sane default like Pulseaudio" << std::endl << 
std::flush;
-
-  if (device.type == ""
-      || device.source == ""
-      || device.name == "") {
-    PTRACE(1, "AudioInputCore\tTried to set malformed device");
-    device.type = AUDIO_INPUT_FALLBACK_DEVICE_TYPE;
-    device.source = AUDIO_INPUT_FALLBACK_DEVICE_SOURCE;
-    device.name = AUDIO_INPUT_FALLBACK_DEVICE_NAME;
-    found = false;
-  }
+  else
+    device.SetFromString (device_fallback.GetString ());
 
   if (!found)
     g_settings_set_string (audio_device_settings, "input-device", device.GetString ().c_str ());
-
-  internal_set_device (device);
+  else
+    internal_set_device (device);
 
   PTRACE(4, "AudioInputCore\tSet device to " << device.source << "/" << device.name);
 }
diff --git a/lib/engine/audioinput/audioinput-core.h b/lib/engine/audioinput/audioinput-core.h
index 489eadf..ddaacaf 100644
--- a/lib/engine/audioinput/audioinput-core.h
+++ b/lib/engine/audioinput/audioinput-core.h
@@ -47,6 +47,22 @@
 #include <ptlib.h>
 #include <gio/gio.h>
 
+#ifdef WIN32
+#define AUDIO_INPUT_PREFERRED_DEVICE_TYPE1   "FIXME"
+#define AUDIO_INPUT_PREFERRED_DEVICE_SOURCE1 "FIXME"
+#define AUDIO_INPUT_PREFERRED_DEVICE_NAME1   "FIXME"
+#define AUDIO_INPUT_PREFERRED_DEVICE_TYPE2   "FIXME"
+#define AUDIO_INPUT_PREFERRED_DEVICE_SOURCE2 "FIXME"
+#define AUDIO_INPUT_PREFERRED_DEVICE_NAME2   "FIXME"
+#else
+#define AUDIO_INPUT_PREFERRED_DEVICE_TYPE1   "PTLIB"
+#define AUDIO_INPUT_PREFERRED_DEVICE_SOURCE1 "Pulse"
+#define AUDIO_INPUT_PREFERRED_DEVICE_NAME1   "PulseAudio"
+#define AUDIO_INPUT_PREFERRED_DEVICE_TYPE2   "PTLIB"
+#define AUDIO_INPUT_PREFERRED_DEVICE_SOURCE2 "ALSA"
+#define AUDIO_INPUT_PREFERRED_DEVICE_NAME2   "Default"
+#endif
+
 #define AUDIO_INPUT_FALLBACK_DEVICE_TYPE   "Ekiga"
 #define AUDIO_INPUT_FALLBACK_DEVICE_SOURCE "Ekiga"
 #define AUDIO_INPUT_FALLBACK_DEVICE_NAME   "SILENT"


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