Commit 9c05025e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

DirectSound: use device GUID instead of device name (fixes #7102)

parent eeb201b9
...@@ -63,7 +63,7 @@ endif ...@@ -63,7 +63,7 @@ endif
libdirectsound_plugin_la_SOURCES = directx.c windows_audio_common.h packet.c libdirectsound_plugin_la_SOURCES = directx.c windows_audio_common.h packet.c
libdirectsound_plugin_la_CFLAGS = $(AM_CFLAGS) libdirectsound_plugin_la_CFLAGS = $(AM_CFLAGS)
libdirectsound_plugin_la_LIBADD = $(AM_LIBADD) libdirectsound_plugin_la_LIBADD = $(AM_LIBADD) -lole32
if HAVE_DIRECTX if HAVE_DIRECTX
libvlc_LTLIBRARIES += libdirectsound_plugin.la libvlc_LTLIBRARIES += libdirectsound_plugin.la
endif endif
......
...@@ -66,9 +66,6 @@ struct aout_sys_t ...@@ -66,9 +66,6 @@ struct aout_sys_t
aout_packet_t packet; aout_packet_t packet;
HINSTANCE hdsound_dll; /* handle of the opened dsound dll */ HINSTANCE hdsound_dll; /* handle of the opened dsound dll */
char * psz_device; /* user defined device name */
LPGUID p_device_guid;
LPDIRECTSOUND p_dsobject; /* main Direct Sound object */ LPDIRECTSOUND p_dsobject; /* main Direct Sound object */
LPDIRECTSOUNDBUFFER p_dsbuffer; /* the sound buffer we use (direct sound LPDIRECTSOUNDBUFFER p_dsbuffer; /* the sound buffer we use (direct sound
* takes care of mixing all the * takes care of mixing all the
...@@ -140,7 +137,7 @@ vlc_module_begin () ...@@ -140,7 +137,7 @@ vlc_module_begin ()
set_subcategory( SUBCAT_AUDIO_AOUT ) set_subcategory( SUBCAT_AUDIO_AOUT )
add_shortcut( "directx", "aout_directx" ) add_shortcut( "directx", "aout_directx" )
add_string( "directx-audio-device", "default", add_string( "directx-audio-device", NULL,
DEVICE_TEXT, DEVICE_LONGTEXT, false ) DEVICE_TEXT, DEVICE_LONGTEXT, false )
change_string_cb( ReloadDirectXDevices ) change_string_cb( ReloadDirectXDevices )
add_obsolete_string( "directx-audio-device-name") add_obsolete_string( "directx-audio-device-name")
...@@ -601,45 +598,6 @@ static void Stop( audio_output_t *p_aout ) ...@@ -601,45 +598,6 @@ static void Stop( audio_output_t *p_aout )
/* finally release the DirectSound object */ /* finally release the DirectSound object */
if( p_sys->p_dsobject ) IDirectSound_Release( p_sys->p_dsobject ); if( p_sys->p_dsobject ) IDirectSound_Release( p_sys->p_dsobject );
free( p_aout->sys->p_device_guid );
}
/*****************************************************************************
* CallBackDirectSoundEnum: callback to enumerate available devices
*****************************************************************************/
static int CALLBACK CallBackDirectSoundEnum( LPGUID p_guid, LPCWSTR psz_desc,
LPCWSTR psz_mod, LPVOID _p_aout )
{
VLC_UNUSED( psz_mod );
audio_output_t *p_aout = (audio_output_t *)_p_aout;
char *psz_device = FromWide( psz_desc );
msg_Dbg( p_aout, "found device: %s", psz_device );
if( p_aout->sys->psz_device &&
!strcmp(p_aout->sys->psz_device, psz_device) && p_guid )
{
/* Use the device corresponding to psz_device */
p_aout->sys->p_device_guid = malloc( sizeof( GUID ) );
*p_aout->sys->p_device_guid = *p_guid;
msg_Dbg( p_aout, "using device: %s", psz_device );
}
else
{
/* If no default device has been selected, chose the first one */
if( !p_aout->sys->psz_device && p_guid )
{
p_aout->sys->psz_device = strdup( psz_device );
p_aout->sys->p_device_guid = malloc( sizeof( GUID ) );
*p_aout->sys->p_device_guid = *p_guid;
msg_Dbg( p_aout, "using device: %s", psz_device );
}
}
free( psz_device );
return true;
} }
/***************************************************************************** /*****************************************************************************
...@@ -647,8 +605,9 @@ static int CALLBACK CallBackDirectSoundEnum( LPGUID p_guid, LPCWSTR psz_desc, ...@@ -647,8 +605,9 @@ static int CALLBACK CallBackDirectSoundEnum( LPGUID p_guid, LPCWSTR psz_desc,
*****************************************************************************/ *****************************************************************************/
static int InitDirectSound( audio_output_t *p_aout ) static int InitDirectSound( audio_output_t *p_aout )
{ {
aout_sys_t *sys = p_aout->sys;
GUID guid, *p_guid = NULL;
HRESULT (WINAPI *OurDirectSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN); HRESULT (WINAPI *OurDirectSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
HRESULT (WINAPI *OurDirectSoundEnumerate)(LPDSENUMCALLBACKW, LPVOID);
OurDirectSoundCreate = (void *) OurDirectSoundCreate = (void *)
GetProcAddress( p_aout->sys->hdsound_dll, GetProcAddress( p_aout->sys->hdsound_dll,
...@@ -659,25 +618,21 @@ static int InitDirectSound( audio_output_t *p_aout ) ...@@ -659,25 +618,21 @@ static int InitDirectSound( audio_output_t *p_aout )
goto error; goto error;
} }
/* Get DirectSoundEnumerate */ char *dev = var_InheritString( p_aout, "directx-audio-device" );
OurDirectSoundEnumerate = (void *) if( dev != NULL )
GetProcAddress( p_aout->sys->hdsound_dll,
"DirectSoundEnumerateW" );
if( OurDirectSoundEnumerate )
{ {
p_aout->sys->psz_device = var_InheritString(p_aout, "directx-audio-device"); LPOLESTR lpsz = ToWide( dev );
/* Attempt enumeration */
if( FAILED( OurDirectSoundEnumerate( CallBackDirectSoundEnum, if( SUCCEEDED( IIDFromString( lpsz, &guid ) ) )
p_aout ) ) ) p_guid = &guid;
{ else
msg_Dbg( p_aout, "enumeration of DirectSound devices failed" ); msg_Err( p_aout, "bad device GUID: %ls", lpsz );
} free( lpsz );
free( dev );
} }
/* Create the direct sound object */ /* Create the direct sound object */
if FAILED( OurDirectSoundCreate( p_aout->sys->p_device_guid, if FAILED( OurDirectSoundCreate( p_guid, &sys->p_dsobject, NULL ) )
&p_aout->sys->p_dsobject,
NULL ) )
{ {
msg_Warn( p_aout, "cannot create a direct sound device" ); msg_Warn( p_aout, "cannot create a direct sound device" );
goto error; goto error;
...@@ -699,11 +654,10 @@ static int InitDirectSound( audio_output_t *p_aout ) ...@@ -699,11 +654,10 @@ static int InitDirectSound( audio_output_t *p_aout )
{ {
msg_Warn( p_aout, "cannot set direct sound cooperative level" ); msg_Warn( p_aout, "cannot set direct sound cooperative level" );
} }
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
p_aout->sys->p_dsobject = NULL; sys->p_dsobject = NULL;
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -1075,32 +1029,30 @@ static void* DirectSoundThread( void *data ) ...@@ -1075,32 +1029,30 @@ static void* DirectSoundThread( void *data )
return NULL; return NULL;
} }
/***************************************************************************** typedef struct
* CallBackConfigNBEnum: callback to get the number of available devices
*****************************************************************************/
static int CALLBACK CallBackConfigNBEnum( LPGUID p_guid, LPCWSTR psz_desc,
LPCWSTR psz_mod, LPVOID data )
{ {
int *p_nb = data; unsigned count;
char **ids;
char **names;
} ds_list_t;
(*p_nb)++; static int CALLBACK DeviceEnumCallback( LPGUID guid, LPCWSTR desc,
VLC_UNUSED( psz_mod ); VLC_UNUSED( psz_desc ); VLC_UNUSED( p_guid ); LPCWSTR mod, LPVOID data )
return true;
}
/*****************************************************************************
* CallBackConfigEnum: callback to add available devices to the preferences list
*****************************************************************************/
static int CALLBACK CallBackConfigEnum( LPGUID p_guid, LPCWSTR psz_desc,
LPCWSTR psz_mod, LPVOID data )
{ {
char **values = data; ds_list_t *list = data;
OLECHAR buf[48];
StringFromGUID2( guid, buf, 48 );
while( *values != NULL ) list->count++;
values++; list->ids = xrealloc( list->ids, list->count * sizeof(char *) );
*values = FromWide( psz_desc ); list->names = xrealloc( list->names, list->count * sizeof(char *) );
list->ids[list->count - 1] = FromWide( buf );
list->names[list->count - 1] = FromWide( desc );
if( list->ids == NULL || list->names == NULL )
abort();
VLC_UNUSED( psz_mod ); VLC_UNUSED( p_guid ); (void) mod;
return true; return true;
} }
...@@ -1110,7 +1062,7 @@ static int CALLBACK CallBackConfigEnum( LPGUID p_guid, LPCWSTR psz_desc, ...@@ -1110,7 +1062,7 @@ static int CALLBACK CallBackConfigEnum( LPGUID p_guid, LPCWSTR psz_desc,
static int ReloadDirectXDevices( vlc_object_t *p_this, char const *psz_name, static int ReloadDirectXDevices( vlc_object_t *p_this, char const *psz_name,
char ***values, char ***descs ) char ***values, char ***descs )
{ {
int nb_devices = 0; ds_list_t list = { 0, NULL, NULL };
(void) psz_name; (void) psz_name;
...@@ -1118,25 +1070,23 @@ static int ReloadDirectXDevices( vlc_object_t *p_this, char const *psz_name, ...@@ -1118,25 +1070,23 @@ static int ReloadDirectXDevices( vlc_object_t *p_this, char const *psz_name,
if( hdsound_dll == NULL ) if( hdsound_dll == NULL )
{ {
msg_Warn( p_this, "cannot open DSOUND.DLL" ); msg_Warn( p_this, "cannot open DSOUND.DLL" );
goto error; goto out;
} }
/* Get DirectSoundEnumerate */ /* Get DirectSoundEnumerate */
HRESULT (WINAPI *OurDirectSoundEnumerate)(LPDSENUMCALLBACKW, LPVOID) = HRESULT (WINAPI *OurDirectSoundEnumerate)(LPDSENUMCALLBACKW, LPVOID) =
(void *)GetProcAddress( hdsound_dll, _T("DirectSoundEnumerateW") ); (void *)GetProcAddress( hdsound_dll, _T("DirectSoundEnumerateW") );
if( OurDirectSoundEnumerate == NULL ) if( OurDirectSoundEnumerate != NULL )
goto error; {
OurDirectSoundEnumerate( DeviceEnumCallback, &list );
OurDirectSoundEnumerate(CallBackConfigNBEnum, &nb_devices); msg_Dbg( p_this, "found %u devices", list.count );
msg_Dbg(p_this, "found %d devices", nb_devices); }
*values = xcalloc( nb_devices, sizeof(char *) );
OurDirectSoundEnumerate(CallBackConfigEnum, *values);
*descs = xcalloc( nb_devices, sizeof(char *) );
OurDirectSoundEnumerate(CallBackConfigEnum, *descs);
error:
FreeLibrary(hdsound_dll); FreeLibrary(hdsound_dll);
return nb_devices;
out:
*values = list.ids;
*descs = list.names;
return list.count;
} }
static int Open(vlc_object_t *obj) static int Open(vlc_object_t *obj)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment