directsoundsrc: Add 'device-name' property for selecting a audio device

https://bugzilla.gnome.org/show_bug.cgi?id=706574
This commit is contained in:
Kishore Arepalli 2013-08-22 13:45:59 +02:00 committed by Sebastian Dröge
parent e9581919ff
commit 9df9ee426e
2 changed files with 74 additions and 26 deletions

View file

@ -84,7 +84,7 @@ GST_DEBUG_CATEGORY_STATIC (directsoundsrc_debug);
enum enum
{ {
PROP_0, PROP_0,
PROP_DEVICE PROP_DEVICE_NAME
}; };
static HRESULT (WINAPI * pDSoundCaptureCreate) (LPGUID, static HRESULT (WINAPI * pDSoundCaptureCreate) (LPGUID,
@ -139,6 +139,9 @@ gst_directsound_src_finalize (GObject * object)
g_mutex_clear (&dsoundsrc->dsound_lock); g_mutex_clear (&dsoundsrc->dsound_lock);
g_free(dsoundsrc->device_name);
g_free(dsoundsrc->device_guid);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -185,6 +188,12 @@ gst_directsound_src_class_init (GstDirectSoundSrcClass * klass)
gst_element_class_add_pad_template (gstelement_class, gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&directsound_src_src_factory)); gst_static_pad_template_get (&directsound_src_src_factory));
g_object_class_install_property
(gobject_class, PROP_DEVICE_NAME,
g_param_spec_string ("device-name", "Device name",
"Human-readable name of the sound device", NULL,
G_PARAM_READWRITE));
} }
static GstCaps * static GstCaps *
@ -202,16 +211,20 @@ static void
gst_directsound_src_set_property (GObject * object, guint prop_id, gst_directsound_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
// GstDirectSoundSrc *src = GST_DIRECTSOUND_SRC (object); GstDirectSoundSrc *src = GST_DIRECTSOUND_SRC (object);
GST_DEBUG ("set property"); GST_DEBUG ("set property");
switch (prop_id) { switch (prop_id) {
#if 0 case PROP_DEVICE_NAME:
/* FIXME */ if (src->device_name) {
case PROP_DEVICE: g_free (src->device_name);
src->device = g_value_get_uint (value); src->device_name = NULL;
}
if (g_value_get_string (value)) {
src->device_name = g_strdup (g_value_get_string (value));
}
break; break;
#endif
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -222,19 +235,14 @@ static void
gst_directsound_src_get_property (GObject * object, guint prop_id, gst_directsound_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec) GValue * value, GParamSpec * pspec)
{ {
#if 0
GstDirectSoundSrc *src = GST_DIRECTSOUND_SRC (object); GstDirectSoundSrc *src = GST_DIRECTSOUND_SRC (object);
#endif
GST_DEBUG ("get property"); GST_DEBUG ("get property");
switch (prop_id) { switch (prop_id) {
#if 0 case PROP_DEVICE_NAME:
/* FIXME */ g_value_set_string (value, src->device_name);
case PROP_DEVICE:
g_value_set_uint (value, src->device);
break; break;
#endif
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -252,6 +260,34 @@ gst_directsound_src_init (GstDirectSoundSrc * src)
{ {
GST_DEBUG_OBJECT (src, "initializing directsoundsrc"); GST_DEBUG_OBJECT (src, "initializing directsoundsrc");
g_mutex_init (&src->dsound_lock); g_mutex_init (&src->dsound_lock);
src->device_guid = NULL;
src->device_name = NULL;
}
/* Enumeration callback called by DirectSoundCaptureEnumerate.
* Gets the GUID of request audio device
*/
static BOOL CALLBACK
gst_directsound_enum_callback( GUID* pGUID, TCHAR* strDesc, TCHAR* strDrvName,
VOID* pContext )
{
GstDirectSoundSrc *dsoundsrc = GST_DIRECTSOUND_SRC (pContext);
if ( pGUID && dsoundsrc && dsoundsrc->device_name &&
!g_strcmp0(dsoundsrc->device_name, strDesc)) {
g_free(dsoundsrc->device_guid);
dsoundsrc->device_guid = (GUID *) g_malloc0(sizeof(GUID));
memcpy( dsoundsrc->device_guid, pGUID, sizeof(GUID));
GST_INFO_OBJECT(dsoundsrc, "found the requested audio device :%s",
dsoundsrc->device_name);
return FALSE;
}
GST_INFO_OBJECT(dsoundsrc, "sound device names: %s, %s, requested device:%s",
strDesc, strDrvName, dsoundsrc->device_name);
return TRUE;
} }
static gboolean static gboolean
@ -259,6 +295,7 @@ gst_directsound_src_open (GstAudioSrc * asrc)
{ {
GstDirectSoundSrc *dsoundsrc; GstDirectSoundSrc *dsoundsrc;
HRESULT hRes; /* Result for windows functions */ HRESULT hRes; /* Result for windows functions */
LPGUID guid;
GST_DEBUG_OBJECT (asrc, "opening directsoundsrc"); GST_DEBUG_OBJECT (asrc, "opening directsoundsrc");
@ -280,9 +317,15 @@ gst_directsound_src_open (GstAudioSrc * asrc)
goto capture_function; goto capture_function;
} }
/* FIXME: add here device selection */ hRes =
DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)gst_directsound_enum_callback,
(VOID*)dsoundsrc);
if (FAILED (hRes)) {
goto capture_enumerate;
}
/* Create capture object */ /* Create capture object */
hRes = pDSoundCaptureCreate (NULL, &dsoundsrc->pDSC, NULL); hRes = pDSoundCaptureCreate (dsoundsrc->device_guid, &dsoundsrc->pDSC, NULL);
if (FAILED (hRes)) { if (FAILED (hRes)) {
goto capture_object; goto capture_object;
} }
@ -296,6 +339,13 @@ capture_function:
("Unable to get capturecreate function"), (NULL)); ("Unable to get capturecreate function"), (NULL));
return FALSE; return FALSE;
} }
capture_enumerate:
{
FreeLibrary (dsoundsrc->DSoundDLL);
GST_ELEMENT_ERROR (dsoundsrc, RESOURCE, OPEN_READ,
("Unable to enumerate audio capture devices"), (NULL));
return FALSE;
}
capture_object: capture_object:
{ {
FreeLibrary (dsoundsrc->DSoundDLL); FreeLibrary (dsoundsrc->DSoundDLL);

View file

@ -45,13 +45,12 @@
*/ */
#ifndef __GST_DIRECTSOUNDSRC_H__ #ifndef __GST_DIRECTSOUNDSRC_H__
#define __GST_DIRECTSOUNDSRC_H__ #define __GST_DIRECTSOUNDSRC_H__
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/audio/audio.h> #include <gst/audio/audio.h>
#include <gst/audio/gstaudiosrc.h> #include <gst/audio/gstaudiosrc.h>
#include <windows.h>
#include <windows.h>
#include <dsound.h> #include <dsound.h>
/* add here some headers if needed */ /* add here some headers if needed */
@ -93,9 +92,8 @@ struct _GstDirectSoundSrc
guint latency_time; guint latency_time;
#if 0 GUID *device_guid;
guint device; char *device_name;
#endif
GMutex dsound_lock; GMutex dsound_lock;