[ekiga] Use a correct video input device by default



commit aef4ab6df658c0da37e211a785dcffa84e213896
Author: Eugen Dedu <eugen dedu univ-fcomte fr>
Date:   Sun Apr 26 12:31:01 2015 +0200

    Use a correct video input device by default
    
    If several PTLIB/V4L2 devices exist (for ex. when several cameras are
    attached), the first one in alphabetical order is chosen.

 lib/Makefile.am                                    |    2 -
 lib/engine/audioinput/audioinput-core.cpp          |   16 ++--
 lib/engine/audiooutput/audiooutput-core.cpp        |   28 ++++----
 lib/engine/gui/gtk-frontend/assistant-window.cpp   |    1 -
 lib/engine/gui/gtk-frontend/default_devices.cpp    |   69 ------------------
 lib/engine/gui/gtk-frontend/default_devices.h      |   55 --------------
 lib/engine/gui/gtk-frontend/preferences-window.cpp |    1 -
 lib/engine/videoinput/videoinput-core.cpp          |   45 +++++++-----
 lib/engine/videoinput/videoinput-core.h            |   75 ++++++++++++--------
 lib/engine/videooutput/videooutput-core.h          |    2 +-
 10 files changed, 95 insertions(+), 199 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f2b6644..d85767a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -365,8 +365,6 @@ libekiga_la_SOURCES += \
        engine/gui/gtk-frontend/roster-view-gtk.cpp \
        engine/gui/gtk-frontend/call-history-view-gtk.h \
        engine/gui/gtk-frontend/call-history-view-gtk.cpp \
-       engine/gui/gtk-frontend/default_devices.cpp \
-       engine/gui/gtk-frontend/default_devices.h \
        engine/gui/gtk-frontend/chat-area.h \
        engine/gui/gtk-frontend/chat-area.cpp \
        engine/gui/gtk-frontend/conversation-page.h \
diff --git a/lib/engine/audioinput/audioinput-core.cpp b/lib/engine/audioinput/audioinput-core.cpp
index 0b91143..881a349 100644
--- a/lib/engine/audioinput/audioinput-core.cpp
+++ b/lib/engine/audioinput/audioinput-core.cpp
@@ -216,11 +216,11 @@ AudioInputCore::set_device (const std::string& device_string)
       found = true;
       break;
     }
-    else if ((*it).GetString () == device_preferred1.GetString ()) {
+    else if (*it == device_preferred1) {
 
       found_preferred1 = true;
     }
-    else if ((*it).GetString () == device_preferred2.GetString ()) {
+    else if (*it == device_preferred2) {
 
       found_preferred2 = true;
     }
@@ -229,13 +229,13 @@ AudioInputCore::set_device (const std::string& device_string)
   if (found)
     device.SetFromString (device_string);
   else if (found_preferred1)
-    device.SetFromString (device_preferred1.GetString ());
+    device = device_preferred1);
   else if (found_preferred2)
-    device.SetFromString (device_preferred2.GetString ());
+    device = device_preferred2);
   else if (!devices.empty ())
-    device.SetFromString (devices.begin ()->GetString ());
+    device = *devices.begin ();
   else
-    device.SetFromString (device_fallback.GetString ());
+    device = device_fallback;
 
   if (!found)
     g_settings_set_string (audio_device_settings, "input-device", device.GetString ().c_str ());
@@ -250,7 +250,7 @@ AudioInputCore::add_device (const std::string& source,
                            const std::string& device_name,
                            HalManager* /*manager*/)
 {
-  PTRACE(4, "AudioInputCore\tAdding Device " << device_name);
+  PTRACE(4, "AudioInputCore\tAdding device " << device_name);
   yield = true;
   PWaitAndSignal m(core_mutex);
 
@@ -277,7 +277,7 @@ AudioInputCore::remove_device (const std::string& source,
                               const std::string& device_name,
                               HalManager* /*manager*/)
 {
-  PTRACE(4, "AudioInputCore\tRemoving Device " << device_name);
+  PTRACE(4, "AudioInputCore\tRemoving device " << device_name);
   yield = true;
   PWaitAndSignal m(core_mutex);
 
diff --git a/lib/engine/audiooutput/audiooutput-core.cpp b/lib/engine/audiooutput/audiooutput-core.cpp
index 0bf9cbf..27d05b4 100644
--- a/lib/engine/audiooutput/audiooutput-core.cpp
+++ b/lib/engine/audiooutput/audiooutput-core.cpp
@@ -182,11 +182,11 @@ AudioOutputCore::setup_audio_device (AudioOutputPS device_idx)
         found = true;
         break;
       }
-      else if ((*it).GetString () == device_preferred1.GetString ()) {
+      else if (*it == device_preferred1) {
 
         found_preferred1 = true;
       }
-      else if ((*it).GetString () == device_preferred2.GetString ()) {
+      else if (*it == device_preferred2) {
 
         found_preferred2 = true;
       }
@@ -196,13 +196,13 @@ AudioOutputCore::setup_audio_device (AudioOutputPS device_idx)
   if (found)
     device.SetFromString (audio_device);
   else if (found_preferred1)
-    device.SetFromString (device_preferred1.GetString ());
+    device = device_preferred1;
   else if (found_preferred2)
-    device.SetFromString (device_preferred2.GetString ());
+    device = device_preferred2;
   else if (!devices.empty ())
-    device.SetFromString (devices.begin ()->GetString ());
+    device = *devices.begin ();
   else
-    device.SetFromString (device_fallback.GetString ());
+    device = device_fallback;
 
   if (!found)
     g_settings_set_string ((device_idx == primary)?audio_device_settings:sound_events_settings,
@@ -304,7 +304,7 @@ AudioOutputCore::visit_managers (boost::function1<bool, AudioOutputManager&> vis
   PWaitAndSignal m_pri(core_mutex[primary]);
   PWaitAndSignal m_sec(core_mutex[secondary]);
   bool go_on = true;
-  
+
   for (std::set<AudioOutputManager *>::const_iterator iter = managers.begin ();
        iter != managers.end () && go_on;
        ++iter)
@@ -379,7 +379,7 @@ AudioOutputCore::get_devices (std::vector <AudioOutputDevice>& devices)
   for (std::vector<AudioOutputDevice>::const_iterator iter = devices.begin ();
        iter != devices.end ();
        ++iter) {
-    PTRACE(4, "AudioOutputCore\tDetected Device: " << *iter);
+    PTRACE(4, "AudioOutputCore\tDetected device: " << *iter);
   }
 #endif
 
@@ -426,7 +426,7 @@ AudioOutputCore::add_device (const std::string& sink,
                             const std::string& device_name,
                             HalManager* /*manager*/)
 {
-  PTRACE(4, "AudioOutputCore\tAdding Device " << device_name);
+  PTRACE(4, "AudioOutputCore\tAdding device " << device_name);
   yield = true;
   PWaitAndSignal m_pri(core_mutex[primary]);
 
@@ -454,7 +454,7 @@ AudioOutputCore::remove_device (const std::string& sink,
                                const std::string& device_name,
                                HalManager* /*manager*/)
 {
-  PTRACE(4, "AudioOutputCore\tRemoving Device " << device_name);
+  PTRACE(4, "AudioOutputCore\tRemoving device " << device_name);
   yield = true;
   PWaitAndSignal m_pri(core_mutex[primary]);
 
@@ -565,7 +565,7 @@ AudioOutputCore::set_frame_data (const char* data,
     }
   }
 
-  if (calculate_average) 
+  if (calculate_average)
     calculate_average_level((const short*) data, bytes_written);
 }
 
@@ -612,7 +612,7 @@ AudioOutputCore::play_buffer(AudioOutputPS ps,
 
     case secondary:
         core_mutex[secondary].Wait();
- 
+
         if (current_manager[secondary]) {
 
          internal_play(secondary, buffer, len, channels, sample_rate, bps);
@@ -781,7 +781,7 @@ AudioOutputCore::calculate_average_level (const short*buffer,
 {
   int sum = 0;
   unsigned csize = 0;
-  
+
   while (csize < (size>>1) ) {
 
     if (*buffer < 0)
@@ -791,6 +791,6 @@ AudioOutputCore::calculate_average_level (const short*buffer,
 
     csize++;
   }
-         
+
   average_level = log10 (9.0*sum/size/32767+1)*1.0;
 }
diff --git a/lib/engine/gui/gtk-frontend/assistant-window.cpp 
b/lib/engine/gui/gtk-frontend/assistant-window.cpp
index 7a21cef..e5c0535 100644
--- a/lib/engine/gui/gtk-frontend/assistant-window.cpp
+++ b/lib/engine/gui/gtk-frontend/assistant-window.cpp
@@ -43,7 +43,6 @@
 #include "gm-entry.h"
 #include "platform.h"
 #include "assistant-window.h"
-#include "default_devices.h"
 #include "ekiga-app.h"
 #include "opal-bank.h"
 
diff --git a/lib/engine/gui/gtk-frontend/preferences-window.cpp 
b/lib/engine/gui/gtk-frontend/preferences-window.cpp
index de54f94..1713fa2 100644
--- a/lib/engine/gui/gtk-frontend/preferences-window.cpp
+++ b/lib/engine/gui/gtk-frontend/preferences-window.cpp
@@ -45,7 +45,6 @@
 #include "ekiga-settings.h"
 
 #include "preferences-window.h"
-#include "default_devices.h"
 
 #include "scoped-connections.h"
 #include "form-request-simple.h"
diff --git a/lib/engine/videoinput/videoinput-core.cpp b/lib/engine/videoinput/videoinput-core.cpp
index 57a81ed..3fa13e6 100644
--- a/lib/engine/videoinput/videoinput-core.cpp
+++ b/lib/engine/videoinput/videoinput-core.cpp
@@ -304,39 +304,50 @@ void VideoInputCore::set_device(const VideoInputDevice & _device, int channel, V
 {
   PWaitAndSignal m(core_mutex);
   GSettings* settings = device_settings->get_g_settings ();
-  VideoInputDevice device;
+  VideoInputDevice device, device1, device2;
 
   /* Check if device exists */
   std::vector <VideoInputDevice> devices;
   bool found = false;
+  bool found_preferred1 = false;
+  bool found_preferred2 = false;
+
   get_devices (devices);
   for (std::vector<VideoInputDevice>::iterator it = devices.begin ();
        it < devices.end ();
        it++) {
-    if ((*it).GetString () == _device.GetString ()) {
+    if (*it == _device) {
       found = true;
       break;
+    } else if (it->GetString ().find (VIDEO_INPUT_PREFERRED_DEVICE_TYPE1) != string::npos
+               && it->GetString ().find (VIDEO_INPUT_PREFERRED_DEVICE_SOURCE1) != string::npos) {
+      found_preferred1 = true;
+      device1 = *it;  // do not break, we still hope to find _device
+    } else if (it->GetString ().find (VIDEO_INPUT_PREFERRED_DEVICE_TYPE2) != string::npos
+               && it->GetString ().find (VIDEO_INPUT_PREFERRED_DEVICE_SOURCE2) != string::npos) {
+      found_preferred2 = true;
+      device2 = *it;  // do not break, we still hope to find _device or preferred1
     }
   }
-  PTRACE(4, "VidInputCoreConf\tUpdating device");
 
   if (found)
     device = _device;
-  else
-    device.SetFromString (devices.begin ()->GetString ());
-
-  if ( (device.type == "" )   ||
-       (device.source == "")  ||
-       (device.name == "" ) ) {
-    PTRACE(1, "VidinputCore\tTried to set malformed device");
+  else if (found_preferred1)
+    device = device1;
+  else if (found_preferred2)
+    device = device2;
+  else if (!devices.empty ())
+    device = *devices.begin();
+  else {
     device.type = VIDEO_INPUT_FALLBACK_DEVICE_TYPE;
     device.source = VIDEO_INPUT_FALLBACK_DEVICE_SOURCE;
     device.name = VIDEO_INPUT_FALLBACK_DEVICE_NAME;
-    found = false;
   }
 
+  PTRACE(4, "VidInputCoreConf\tSet video input device to " << device);
+
   if (format >= VI_FORMAT_MAX) {
-    PTRACE(1, "VidInputCoreConf\tformat out of range, ajusting to 3");
+    PTRACE(1, "VidInputCoreConf\tformat out of range, adjusting to 3");
     format = (VideoInputFormat) 3;
   }
 
@@ -348,7 +359,7 @@ void VideoInputCore::set_device(const VideoInputDevice & _device, int channel, V
 
 void VideoInputCore::add_device (const std::string & source, const std::string & device_name, unsigned 
capabilities, HalManager* /*manager*/)
 {
-  PTRACE(4, "VidInputCore\tAdding Device " << device_name);
+  PTRACE(4, "VidInputCore\tAdding device " << device_name);
   PWaitAndSignal m(core_mutex);
 
   VideoInputDevice device;
@@ -367,7 +378,7 @@ void VideoInputCore::add_device (const std::string & source, const std::string &
 
 void VideoInputCore::remove_device (const std::string & source, const std::string & device_name, unsigned 
capabilities, HalManager* /*manager*/)
 {
-  PTRACE(4, "VidInputCore\tRemoving Device " << device_name);
+  PTRACE(4, "VidInputCore\tRemoving device " << device_name);
   PWaitAndSignal m(core_mutex);
 
   VideoInputDevice device;
@@ -455,7 +466,7 @@ void VideoInputCore::set_stream_config (unsigned width, unsigned height, unsigne
 
   // We do not support switching of framerate or resolution within a stream
   // since many endpoints will probably have problems with that. Also, it would add
-  // a lot of complexity due to the capabilities exchange. Thus these values will 
+  // a lot of complexity due to the capabilities exchange. Thus these values will
   // not be used until the next start_stream.
 
   if (!stream_config.active)
@@ -469,7 +480,7 @@ void VideoInputCore::start_stream ()
   PTRACE(4, "VidInputCore\tStarting stream " << stream_config);
   if (preview_config.active && !stream_config.active) {
     preview_manager->stop();
-    if ( preview_config != stream_config ) 
+    if ( preview_config != stream_config )
     {
       internal_close();
       internal_open(stream_config.width, stream_config.height, stream_config.fps);
@@ -489,7 +500,7 @@ void VideoInputCore::stop_stream ()
 
   PTRACE(4, "VidInputCore\tStopping Stream");
   if (preview_config.active && stream_config.active) {
-    if ( preview_config != stream_config ) 
+    if ( preview_config != stream_config )
     {
       internal_close();
       internal_open(preview_config.width, preview_config.height, preview_config.fps);
diff --git a/lib/engine/videoinput/videoinput-core.h b/lib/engine/videoinput/videoinput-core.h
index 18a4cbc..4027ad0 100644
--- a/lib/engine/videoinput/videoinput-core.h
+++ b/lib/engine/videoinput/videoinput-core.h
@@ -52,6 +52,19 @@
 
 #include "ekiga-settings.h"
 
+#ifdef WIN32
+#define VIDEO_INPUT_PREFERRED_DEVICE_TYPE1   "PTLIB"
+#define VIDEO_INPUT_PREFERRED_DEVICE_SOURCE1 "DirectShow"
+#define VIDEO_INPUT_PREFERRED_DEVICE_TYPE2   "PTLIB"
+#define VIDEO_INPUT_PREFERRED_DEVICE_SOURCE2 "DirectShow"
+#else
+#define VIDEO_INPUT_PREFERRED_DEVICE_TYPE1   "PTLIB"
+#define VIDEO_INPUT_PREFERRED_DEVICE_SOURCE1 "V4L2"
+#define VIDEO_INPUT_PREFERRED_DEVICE_TYPE2   "PTLIB"
+// V4L is still used in FreeBSD
+#define VIDEO_INPUT_PREFERRED_DEVICE_SOURCE2 "V4L"
+#endif
+
 #define VIDEO_INPUT_FALLBACK_DEVICE_TYPE   "Moving Logo"
 #define VIDEO_INPUT_FALLBACK_DEVICE_SOURCE "Moving Logo"
 #define VIDEO_INPUT_FALLBACK_DEVICE_NAME   "Moving Logo"
@@ -66,27 +79,27 @@ namespace Ekiga
   /** Core object for the video input support
    * The video input core abstracts all functionality related to video input
    * in a thread safe manner. Typically, most of the functions except start_stream(),
-   * stop_stream(), and get_frame_data() will be called from 
+   * stop_stream(), and get_frame_data() will be called from
    * a UI thread, while the three mentioned funtions will be used by a video
    * streaming thread.
-   * 
-   * The video output core abstracts different video input managers, which can 
-   * represent different backends like PTLIB, from the application and can 
+   *
+   * The video output core abstracts different video input managers, which can
+   * represent different backends like PTLIB, from the application and can
    * switch the output device transparently for the video streaming thread,
    * even while capturing is in progress.
    *
    * If the removal of an video input device is detected by a failed
-   * read or by a message from the HalCore, the video input core will 
+   * read or by a message from the HalCore, the video input core will
    * determine the responsible video input manager and send a signal to the UI,
-   * which can be used to update device lists. Also, if the removed device was the 
+   * which can be used to update device lists. Also, if the removed device was the
    * currently used one, the core falls back to the backup device.
-   * 
-   * A similar procedure is performed on the addition of a device. In case we fell 
+   *
+   * A similar procedure is performed on the addition of a device. In case we fell
    * back due to a removed device, and the respective device is re-added to the system,
    * it will be automatically activated.
    *
    * The video input core can also be used in a preview mode, where it starts a separate
-   * thread (represented by the VideoPreviewManager), which grabs frames from the video 
+   * thread (represented by the VideoPreviewManager), which grabs frames from the video
    * input core and passes them to the video output core. This can be used for displaying
    * the local camera signal while not being in a call. If the preview is active and them
    * and the stream is started, the core will automatically determined if the device needs
@@ -159,7 +172,7 @@ namespace Ekiga
       /** Set a specific device
        * This function sets the current video input device. This function can
        * also be used while in a stream or in preview mode. In that case the old
-       * device is closed and the new device opened automatically. 
+       * device is closed and the new device opened automatically.
        * @param device the new device to be used.
        * @param channel the new channel to be used.
        * @param format the new format to be used.
@@ -168,9 +181,9 @@ namespace Ekiga
 
       /** Inform the core of an added videoinput device
        * This function is called by the HalCore when a video device is added.
-       * It determines responsible managers for that specific device and informs the 
-       * GUI about the device that was added (via device_added signal). 
-       * In case the added device was the desired device and we fell back, 
+       * It determines responsible managers for that specific device and informs the
+       * GUI about the device that was added (via device_added signal).
+       * In case the added device was the desired device and we fell back,
        * we will reactivate it. MUST be called from main thread.
        * @param source the device source (e.g. video4linux).
        * @param device_name the name of the added device.
@@ -181,8 +194,8 @@ namespace Ekiga
 
       /** Inform the core of a removed videoinput device
        * This function is called by the HalCore when a video device is removed.
-       * It determines responsible managers for that specific device and informs the 
-       * GUI about the device that was removed (via device_removed signal). 
+       * It determines responsible managers for that specific device and informs the
+       * GUI about the device that was removed (via device_removed signal).
        * In case the removed device was the current device we fall back to the
        * fallback device. MUST be called from main thread.
        * @param source the device source (e.g. video4linux).
@@ -193,8 +206,8 @@ namespace Ekiga
       void remove_device (const std::string & source, const std::string & device_name, unsigned 
capabilities, HalManager* manager);
 
       /** Set still image data
-       * In case there is a manager that allows trasmitting a still image, 
-       * this function can be used to set the actual image data. All other 
+       * In case there is a manager that allows trasmitting a still image,
+       * this function can be used to set the actual image data. All other
        * managers can safely ignore this function.
        * @param width the width of the image in pixels.
        * @param height the height of the image in pixels.
@@ -207,8 +220,8 @@ namespace Ekiga
 
       /** Set the preview configuration
        * This function sets the resolution and framerate for the preview mode. In case
-       * preview is not active (due to active stream or because it is simply off), it will 
-       * be applied the next time it is (re)started. In case preview is active, 
+       * preview is not active (due to active stream or because it is simply off), it will
+       * be applied the next time it is (re)started. In case preview is active,
        * the new configuration will be applied immediately by closing and reopening the device.
        * @param width the frame width.
        * @param height the frame height.
@@ -217,7 +230,7 @@ namespace Ekiga
       void set_preview_config (unsigned width, unsigned height, unsigned fps);
 
       /** Start the preview mode
-       * Start the preview thread implemented in the PreviewManager. 
+       * Start the preview thread implemented in the PreviewManager.
        * In case a stream is active, this will not have an effect until the stream is stopped.
        */
       void start_preview ();
@@ -228,9 +241,9 @@ namespace Ekiga
 
 
       /** Set the stream configuration
-       * This function sets the resolution and framerate for the stream mode, which 
-       * can be different from the preview configuration due to negotiated capabilities. 
-       * The configuration will be applied on the next call of start_stream(), in order 
+       * This function sets the resolution and framerate for the stream mode, which
+       * can be different from the preview configuration due to negotiated capabilities.
+       * The configuration will be applied on the next call of start_stream(), in order
        * not to confuse simple endpoints that do not support switching of the resolution in
        * mid-stream.
        * @param width the frame width.
@@ -254,7 +267,7 @@ namespace Ekiga
 
       /** Get one video frame buffer from the current manager.
        * This function will block until the buffer is completely filled.
-       * Requires the stream or the preview (when being called from the 
+       * Requires the stream or the preview (when being called from the
        * VideoPreviewManager) to be started.
        * In case the device returns an error reading the frame, get_frame_data()
        * falls back to the fallback device and reads the frame from there. Thus
@@ -297,8 +310,8 @@ namespace Ekiga
 
   private:
       void on_set_device (const VideoInputDevice & device);
-      void on_device_opened (VideoInputDevice device,  
-                             VideoInputSettings settings, 
+      void on_device_opened (VideoInputDevice device,
+                             VideoInputSettings settings,
                              VideoInputManager *manager);
       void on_device_closed (VideoInputDevice device, VideoInputManager *manager);
       void on_device_error  (VideoInputDevice device, VideoInputErrorCodes error_code, VideoInputManager 
*manager);
@@ -315,9 +328,9 @@ namespace Ekiga
 private:
       /** VideoPreviewManager thread.
         *
-        * VideoPreviewManager represents a thread that gets frames from the 
-        * video input core and passes them to the video output core. This is 
-        * used for displaying the preview video. This thread will run only 
+        * VideoPreviewManager represents a thread that gets frames from the
+        * video input core and passes them to the video output core. This is
+        * used for displaying the preview video. This thread will run only
         * while preview is active. It is called from the VideoInputCore, which
         * has the interface to the application for enabling and disabling the preview.
         */
@@ -373,7 +386,7 @@ private:
         *
         * This class is used for storing the device configuration when
         * streaming video or when in preview mode. The device configuration
-        * consists of width, height and framerate. This class can be used to 
+        * consists of width, height and framerate. This class can be used to
         * check whether stream and preview configuration is different and
         * thus if a device needs to be reopened when switching between stream
         * and preview mode.
@@ -408,7 +421,7 @@ private:
 
         bool operator==( const VideoDeviceConfig & rhs ) const
         {
-          if ( (width  == rhs.width)   && 
+          if ( (width  == rhs.width)   &&
                (height == rhs.height)  &&
                (fps    == rhs.fps)     )
           return true;
diff --git a/lib/engine/videooutput/videooutput-core.h b/lib/engine/videooutput/videooutput-core.h
index 0c7af60..6151ea2 100644
--- a/lib/engine/videooutput/videooutput-core.h
+++ b/lib/engine/videooutput/videooutput-core.h
@@ -57,7 +57,7 @@ namespace Ekiga
 
   /** Core object for the video display support
    *
-   * The VideoOutputCore will control the different VideoOutputManagers and pass pointers to 
+   * The VideoOutputCore will control the different VideoOutputManagers and pass pointers to
    * the frames to all of them.
    * Before passing the first frame, start() has to be called. In order to close the video,
    * stop() has to be called. The video output core interacts with the GUI when switching to fullscreen,


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