[longomatch] Improve device listing and handling



commit 26cbf903c68f7901b788186e9afa6ead3527a9c6
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Mar 29 14:33:10 2014 +0100

    Improve device listing and handling

 LongoMatch.Core/Common/CaptureSettings.cs          |    1 +
 LongoMatch.Core/Common/Device.cs                   |   11 +++++
 LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs       |    2 +-
 .../Gui/Component/ProjectDetailsWidget.cs          |   18 +-------
 LongoMatch.Multimedia/Capturer/FakeCapturer.cs     |    2 +-
 .../Capturer/GstCameraCapturer.cs                  |   17 +++-----
 LongoMatch.Multimedia/Interfaces/ICapturer.cs      |    2 +-
 LongoMatch.Multimedia/Utils/VideoDevice.cs         |   38 +++++++----------
 libcesarplayer/gst-camera-capturer.c               |   42 +++++++++++---------
 libcesarplayer/gst-camera-capturer.h               |    6 +-
 libcesarplayer/test-capturer.c                     |    5 +--
 11 files changed, 67 insertions(+), 77 deletions(-)
---
diff --git a/LongoMatch.Core/Common/CaptureSettings.cs b/LongoMatch.Core/Common/CaptureSettings.cs
index cae41b7..a30252a 100644
--- a/LongoMatch.Core/Common/CaptureSettings.cs
+++ b/LongoMatch.Core/Common/CaptureSettings.cs
@@ -25,6 +25,7 @@ namespace LongoMatch.Common
        {
                public CaptureSourceType CaptureSourceType;
                public string DeviceID;
+               public string SourceElement;
                public EncodingSettings EncodingSettings;
 
                public static CaptureSettings DefaultSettings() {
diff --git a/LongoMatch.Core/Common/Device.cs b/LongoMatch.Core/Common/Device.cs
index e227865..babdf04 100644
--- a/LongoMatch.Core/Common/Device.cs
+++ b/LongoMatch.Core/Common/Device.cs
@@ -47,5 +47,16 @@ namespace LongoMatch.Common
                        get;
                        set;
                }
+               
+               public string SourceElement {
+                       get;
+                       set;
+               }
+               
+               public string Desc  {
+                       get {
+                               return String.Format("{0} ({1})", ID, SourceElement);
+                       }
+               }
        }
 }
diff --git a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
index 597201e..9572c43 100644
--- a/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/CapturerBin.cs
@@ -220,7 +220,7 @@ namespace LongoMatch.Gui
                        capturer.SetVideoEncoder(captureProps.EncodingSettings.EncodingProfile.VideoEncoder);
                        capturer.SetAudioEncoder(captureProps.EncodingSettings.EncodingProfile.AudioEncoder);
                        capturer.SetVideoMuxer(muxer);
-                       capturer.SetSource(captureProps.CaptureSourceType);
+                       capturer.SetSource(captureProps.CaptureSourceType, captureProps.SourceElement);
                        capturer.VideoQuality = captureProps.EncodingSettings.EncodingQuality.VideoQuality;
                        capturer.AudioQuality = captureProps.EncodingSettings.EncodingQuality.AudioQuality;
                }
diff --git a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs 
b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
index 2083784..0f38f66 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
@@ -59,8 +59,6 @@ namespace LongoMatch.Gui.Component
                ProjectType useType;
                List<Device> videoDevices;
                ListStore videoStandardList, encProfileList, qualList;
-               private const string DV_SOURCE = "DV Source";
-               private const string GCONF_SOURCE = "GConf Source";
 
 
                public ProjectDetailsWidget()
@@ -245,6 +243,7 @@ namespace LongoMatch.Gui.Component
                                if (useType == ProjectType.CaptureProject) {
                                        s.CaptureSourceType = videoDevices[devicecombobox.Active].DeviceType;
                                        s.DeviceID = videoDevices[devicecombobox.Active].ID;
+                                       s.SourceElement = videoDevices[devicecombobox.Active].SourceElement;
                                } else if (useType == ProjectType.URICaptureProject) {
                                        s.CaptureSourceType = CaptureSourceType.URI;
                                        s.DeviceID = urientry.Text;
@@ -369,20 +368,7 @@ namespace LongoMatch.Gui.Component
                        videoDevices = devices;
 
                        foreach(Device device in devices) {
-                               string deviceElement;
-                               string deviceName;
-                               if(Environment.OSVersion.Platform == PlatformID.MacOSX) {
-                                       deviceElement = Catalog.GetString("OS X Source");
-                               } else if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
-                                       deviceElement = Catalog.GetString("DirectShow Source");
-                               } else {
-                                       if(device.DeviceType == CaptureSourceType.DV)
-                                               deviceElement = Catalog.GetString(DV_SOURCE);
-                                       else
-                                               deviceElement = Catalog.GetString(GCONF_SOURCE);
-                               }
-                               deviceName = (device.ID == "") ? Catalog.GetString("Unknown"): device.ID;
-                               devicecombobox.AppendText(deviceName + " ("+deviceElement+")");
+                               devicecombobox.AppendText(device.Desc);
                                devicecombobox.Active = 0;
                        }
                }
diff --git a/LongoMatch.Multimedia/Capturer/FakeCapturer.cs b/LongoMatch.Multimedia/Capturer/FakeCapturer.cs
index 2542af4..88a12c1 100644
--- a/LongoMatch.Multimedia/Capturer/FakeCapturer.cs
+++ b/LongoMatch.Multimedia/Capturer/FakeCapturer.cs
@@ -129,7 +129,7 @@ namespace LongoMatch.Video.Capturer
                        return true;
                }
 
-               public bool SetSource(CaptureSourceType type) {
+               public bool SetSource(CaptureSourceType type, string sourceElement) {
                        return true;
                }
        }
diff --git a/LongoMatch.Multimedia/Capturer/GstCameraCapturer.cs 
b/LongoMatch.Multimedia/Capturer/GstCameraCapturer.cs
index 453d3a1..6b659a0 100644
--- a/LongoMatch.Multimedia/Capturer/GstCameraCapturer.cs
+++ b/LongoMatch.Multimedia/Capturer/GstCameraCapturer.cs
@@ -426,11 +426,11 @@ namespace LongoMatch.Video.Capturer {
                }
 
                [DllImport("libcesarplayer.dll")]
-               static extern bool gst_camera_capturer_set_source(IntPtr raw, int type, out IntPtr error);
+               static extern bool gst_camera_capturer_set_source(IntPtr raw, int type, string element, out 
IntPtr error);
 
-               public bool SetSource(CaptureSourceType type) {
+               public bool SetSource(CaptureSourceType type, string sourceElement) {
                        IntPtr error = IntPtr.Zero;
-                       bool raw_ret = gst_camera_capturer_set_source(Handle, (int) type, out error);
+                       bool raw_ret = gst_camera_capturer_set_source(Handle, (int) type, sourceElement, out 
error);
                        if(error != IntPtr.Zero) throw new GLib.GException(error);
                        bool ret = raw_ret;
                        return ret;
@@ -458,16 +458,13 @@ namespace LongoMatch.Video.Capturer {
                }
 
                [DllImport("libcesarplayer.dll")]
-               static extern IntPtr gst_camera_capturer_enum_video_devices();
+               static extern IntPtr gst_camera_capturer_enum_video_devices(string devname);
 
-               public static string[] VideoDevices {
-                       get {
-                               IntPtr raw_ret = gst_camera_capturer_enum_video_devices();
-                               return (string[])GLib.Marshaller.ListPtrToArray(raw_ret, typeof(GLib.List),  
true, false, typeof(String));
-                       }
+               public static string[] ListVideoDevices (string devname) {
+                       IntPtr raw_ret = gst_camera_capturer_enum_video_devices(devname);
+                       return (string[])GLib.Marshaller.ListPtrToArray(raw_ret, typeof(GLib.List),  true, 
false, typeof(String));
                }
 
-
                [DllImport("libcesarplayer.dll")]
                static extern IntPtr gst_camera_capturer_get_current_frame(IntPtr raw);
                [DllImport("libcesarplayer.dll")]
diff --git a/LongoMatch.Multimedia/Interfaces/ICapturer.cs b/LongoMatch.Multimedia/Interfaces/ICapturer.cs
index 4c49bcc..0c2535b 100644
--- a/LongoMatch.Multimedia/Interfaces/ICapturer.cs
+++ b/LongoMatch.Multimedia/Interfaces/ICapturer.cs
@@ -77,7 +77,7 @@ namespace LongoMatch.Multimedia.Interfaces
 
                bool SetVideoMuxer(VideoMuxerType type);
 
-               bool SetSource(CaptureSourceType type);
+               bool SetSource(CaptureSourceType type, string sourceElement);
 
                void TogglePause();
 
diff --git a/LongoMatch.Multimedia/Utils/VideoDevice.cs b/LongoMatch.Multimedia/Utils/VideoDevice.cs
index 5a208f8..c74e05d 100644
--- a/LongoMatch.Multimedia/Utils/VideoDevice.cs
+++ b/LongoMatch.Multimedia/Utils/VideoDevice.cs
@@ -27,31 +27,25 @@ namespace LongoMatch.Multimedia.Utils
 {
        public class VideoDevice
        {
-               
+#if OSTYPE_DARWIN
+               static string[] devices = new string[1] {"osxvideosrc"};         
+#elif OSTYPE_WINDOWS
+               static string[] devices = new string[2] {"dshowvideosrc", "ksvideosrc"};         
+#else 
+               static string[] devices = new string[2] {"v4l2src", "dv1394src"};        
+#endif
+
                static public List<Device> ListVideoDevices() {
                        List<Device> devicesList  = new List<Device>();
 
-                       /* Generate the list of devices, on the supported platforms
-                        * and extra DV device for the dv1394src element and the default
-                        * OS source for all of them */
-                       foreach(string devName in GstCameraCapturer.VideoDevices) {
-                               CaptureSourceType source;
-
-                               if(Environment.OSVersion.Platform == PlatformID.Unix)
-                                       source = CaptureSourceType.DV;
-                               else
-                                       source = CaptureSourceType.System;
-
-                               devicesList.Add(new Device {
-                                       ID = devName,
-                                       DeviceType = source,
-                               });
-                       }
-                       if(Environment.OSVersion.Platform != PlatformID.Win32NT) {
-                               devicesList.Add(new Device {
-                                       ID = Catalog.GetString("Default device"),
-                                       DeviceType = CaptureSourceType.System
-                               });
+                       foreach (string source in devices) {
+                               foreach (string devname in GstCameraCapturer.ListVideoDevices (source)) {
+                                       devicesList.Add(new Device {
+                                               ID = devname,
+                                               DeviceType = CaptureSourceType.System,
+                                               SourceElement = source,
+                                       });
+                               }
                        }
                        return devicesList;
                }
diff --git a/libcesarplayer/gst-camera-capturer.c b/libcesarplayer/gst-camera-capturer.c
index 725f25b..2b2fd64 100644
--- a/libcesarplayer/gst-camera-capturer.c
+++ b/libcesarplayer/gst-camera-capturer.c
@@ -89,6 +89,7 @@ struct GstCameraCapturerPrivate
   AudioEncoderType audio_encoder_type;
   VideoMuxerType video_muxer_type;
   CaptureSourceType source_type;
+  gchar *source_element_name;
 
   /*Video input info */
   gint video_width;             /* Movie width */
@@ -119,7 +120,6 @@ struct GstCameraCapturerPrivate
   GstElement *filesink;
   GstElement* video_appsrc;
   GstElement* audio_appsrc;
-  const gchar *source_element_name;
 
   /* Recording */
   gboolean is_recording;
@@ -378,6 +378,7 @@ gst_camera_capturer_init (GstCameraCapturer * object)
   priv->audio_encoder_type = AUDIO_ENCODER_VORBIS;
   priv->video_muxer_type = VIDEO_MUXER_WEBM;
   priv->source_type = CAPTURE_SOURCE_TYPE_SYSTEM;
+  priv->source_element_name = SYSVIDEOSRC;
 
   gtk_widget_add_events (GTK_WIDGET (object),
       GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
@@ -413,6 +414,11 @@ gst_camera_capturer_finalize (GObject * object)
     gcc->priv->output_file = NULL;
   }
 
+  if (gcc->priv->source_element_name) {
+    g_free (gcc->priv->source_element_name);
+    gcc->priv->source_element_name = NULL;
+  }
+
   if (gcc->priv->device_id) {
     g_free (gcc->priv->device_id);
     gcc->priv->device_id = NULL;
@@ -1356,7 +1362,6 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
     CaptureSourceType type, GError ** err)
 {
   GstElement *typefind;
-  const gchar *source_desc = "";
   gchar *source_str;
   gchar *filter = "";
 
@@ -1366,13 +1371,9 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
   switch (type) {
     case CAPTURE_SOURCE_TYPE_DV:
       GST_INFO_OBJECT(gcc, "Creating dv video source");
-      source_desc = DVVIDEOSRC;
-      gcc->priv->source_element_name = source_desc;
       break;
     case CAPTURE_SOURCE_TYPE_SYSTEM:
       GST_INFO_OBJECT(gcc, "Creating system video source");
-      source_desc = SYSVIDEOSRC;
-      gcc->priv->source_element_name = source_desc;
       break;
     case CAPTURE_SOURCE_TYPE_URI:
       /* We don't use any source element for URI's, just a uridecodebin element
@@ -1384,8 +1385,7 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
       return TRUE;
     case CAPTURE_SOURCE_TYPE_FILE:
       GST_INFO_OBJECT(gcc, "Creating file video source");
-      source_desc = "filesrc";
-      gcc->priv->source_element_name = source_desc;
+      gcc->priv->source_element_name = g_strdup ("filesrc");
       break;
     default:
       g_assert_not_reached();
@@ -1397,10 +1397,11 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
     source_str = g_strdup_printf("%s device-name=\"%s\" name=source ! "
         "video/x-raw-yuv; video/x-raw-rgb; "
         "video/x-dv, systemstream=(boolean)True "
-        "! typefind name=typefind", source_desc, gcc->priv->device_id);
+        "! typefind name=typefind", gcc->priv->source_element_name,
+        gcc->priv->device_id);
   } else {
     source_str = g_strdup_printf("%s name=source %s ! typefind name=typefind",
-        source_desc, filter);
+        gcc->priv->source_element_name, filter);
   }
 
   GST_INFO_OBJECT(gcc, "Created video source %s", source_str);
@@ -1411,7 +1412,8 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
         GCC_ERROR,
         GST_ERROR_PLUGIN_LOAD,
         "Failed to create the %s element. "
-        "Please check your GStreamer installation.", source_desc);
+        "Please check your GStreamer installation.",
+        gcc->priv->source_element_name);
     return FALSE;
   }
 
@@ -1422,7 +1424,7 @@ gst_camera_capturer_create_video_source (GstCameraCapturer * gcc,
 
   gst_camera_capturer_update_device_id(gcc);
 
-  GST_INFO_OBJECT(gcc, "Created video source %s", source_desc);
+  GST_INFO_OBJECT(gcc, "Created video source %s", gcc->priv->source_element_name);
 
   gst_object_unref (gcc->priv->source);
   gst_object_unref (typefind);
@@ -1717,7 +1719,7 @@ gcc_get_video_stream_info (GstCameraCapturer * gcc)
  * **************************************************/
 
 GList *
-gst_camera_capturer_enum_devices (gchar * device_name)
+gst_camera_capturer_enum_devices (const gchar * device_name)
 {
   GstElement *device;
   GstPropertyProbe *probe;
@@ -1743,7 +1745,7 @@ gst_camera_capturer_enum_devices (gchar * device_name)
   else
     prop_name = "device-name";
 
-  va = gst_property_probe_get_values_name (probe, prop_name);
+  va = gst_property_probe_probe_and_get_values_name (probe, prop_name);
   if (!va)
     goto finish;
 
@@ -1768,15 +1770,15 @@ finish:
 }
 
 GList *
-gst_camera_capturer_enum_video_devices (void)
+gst_camera_capturer_enum_video_devices (const gchar *device)
 {
-  return gst_camera_capturer_enum_devices (DVVIDEOSRC);
+  return gst_camera_capturer_enum_devices (device);
 }
 
 GList *
-gst_camera_capturer_enum_audio_devices (void)
+gst_camera_capturer_enum_audio_devices (const gchar *device)
 {
-  return gst_camera_capturer_enum_devices (AUDIOSRC);
+  return gst_camera_capturer_enum_devices (device);
 }
 
 /*******************************************
@@ -1841,12 +1843,14 @@ gst_camera_capturer_toggle_pause (GstCameraCapturer * gcc)
 }
 
 void
-gst_camera_capturer_set_source (GstCameraCapturer * gcc, CaptureSourceType source)
+gst_camera_capturer_set_source (GstCameraCapturer * gcc, CaptureSourceType source,
+    const gchar *source_element_name)
 {
   g_return_if_fail (gcc != NULL);
   g_return_if_fail (GST_IS_CAMERA_CAPTURER (gcc));
 
   gcc->priv->source_type = source;
+  gcc->priv->source_element_name = g_strdup (source_element_name);
 }
 
 void
diff --git a/libcesarplayer/gst-camera-capturer.h b/libcesarplayer/gst-camera-capturer.h
index b88982b..704ca83 100644
--- a/libcesarplayer/gst-camera-capturer.h
+++ b/libcesarplayer/gst-camera-capturer.h
@@ -73,12 +73,12 @@ EXPORT void gst_camera_capturer_close (GstCameraCapturer * gcc);
 EXPORT void gst_camera_capturer_start (GstCameraCapturer * gcc);
 EXPORT void gst_camera_capturer_toggle_pause (GstCameraCapturer * gcc);
 EXPORT void gst_camera_capturer_stop (GstCameraCapturer * gcc);
-EXPORT void gst_camera_capturer_set_source (GstCameraCapturer * gcc, CaptureSourceType source);
+EXPORT void gst_camera_capturer_set_source (GstCameraCapturer * gcc, CaptureSourceType source, const gchar 
*source_element);
 EXPORT void gst_camera_capturer_set_video_encoder (GstCameraCapturer * gcc, VideoEncoderType encoder);
 EXPORT void gst_camera_capturer_set_audio_encoder (GstCameraCapturer * gcc, AudioEncoderType encoder);
 EXPORT void gst_camera_capturer_set_video_muxer (GstCameraCapturer * gcc, VideoMuxerType muxer);
-EXPORT GList *gst_camera_capturer_enum_audio_devices (void);
-EXPORT GList *gst_camera_capturer_enum_video_devices (void);
+EXPORT GList *gst_camera_capturer_enum_audio_devices (const gchar *device);
+EXPORT GList *gst_camera_capturer_enum_video_devices (const gchar *device);
 EXPORT GdkPixbuf *gst_camera_capturer_get_current_frame (GstCameraCapturer
     * gcc);
 EXPORT void gst_camera_capturer_unref_pixbuf (GdkPixbuf * pixbuf);
diff --git a/libcesarplayer/test-capturer.c b/libcesarplayer/test-capturer.c
index c4d5b70..3b2ad5e 100644
--- a/libcesarplayer/test-capturer.c
+++ b/libcesarplayer/test-capturer.c
@@ -78,10 +78,7 @@ main (int argc, char *argv[])
   gst_camera_capturer_init_backend (&argc, &argv);
   gvc = gst_camera_capturer_new ("test", &error);
 
-  g_print("JANDER             %d\n", atoi(argv[2]));
-  g_print("JANDER             %d\n", atoi(argv[3]));
-  g_print("JANDER             %d\n", atoi(argv[1]));
-  gst_camera_capturer_set_source (gvc, atoi(argv[2]));
+  gst_camera_capturer_set_source (gvc, atoi(argv[2]), SYSVIDEOSRC);
   gst_camera_capturer_set_video_encoder (gvc, VIDEO_ENCODER_H264);
   gst_camera_capturer_set_audio_encoder (gvc, AUDIO_ENCODER_AAC);
   gst_camera_capturer_set_video_muxer (gvc, VIDEO_MUXER_MP4);


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