2006-04-24 01:14:18 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : wsdl.cpp
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : sound card detection on Windows.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
// license: GPL; see lib/license.txt
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include "precompiled.h"
|
2007-01-01 22:25:47 +01:00
|
|
|
#include "lib/sysdep/snd.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-01-01 22:25:47 +01:00
|
|
|
#include <string>
|
|
|
|
#include <set>
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include "lib/path_util.h"
|
2007-01-01 22:25:47 +01:00
|
|
|
#include "lib/res/file/file.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "dll_ver.h" // dll_list_*
|
2007-05-08 17:11:53 +02:00
|
|
|
#include "win.h"
|
2007-05-04 19:30:32 +02:00
|
|
|
#include "wutil.h"
|
2007-01-01 22:25:47 +01:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
// indicate if this directory entry is an OpenAL DLL.
|
2006-04-24 01:14:18 +02:00
|
|
|
// (matches "*oal.dll" and "*OpenAL*", as with OpenAL router's search)
|
2007-05-24 14:31:16 +02:00
|
|
|
static LibError IsOpenAlDll(const DirEnt* ent)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-24 14:31:16 +02:00
|
|
|
// not a file
|
2006-04-24 01:14:18 +02:00
|
|
|
if(!DIRENT_IS_DIR(ent))
|
2007-05-24 14:31:16 +02:00
|
|
|
return false;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
// name doesn't match
|
|
|
|
const size_t len = strlen(ent->name);
|
|
|
|
const bool oal = len >= 7 && !strcasecmp(ent->name+len-7, "oal.dll");
|
|
|
|
const bool openal = strstr(ent->name, "OpenAL") != 0;
|
2006-04-24 01:14:18 +02:00
|
|
|
if(!oal && !openal)
|
2007-05-24 14:31:16 +02:00
|
|
|
return false;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
return true;
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
// ensures each OpenAL DLL is only listed once (even if present in several
|
|
|
|
// directories on our search path).
|
|
|
|
typedef std::set<std::string> StringSet;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
// find all OpenAL DLLs in a dir (via file_enum and IsOpenAlDll).
|
2006-04-24 01:14:18 +02:00
|
|
|
// call in library search order (exe dir, then win sys dir); otherwise,
|
|
|
|
// DLLs in the executable's starting directory hide those of the
|
|
|
|
// same name in the system directory.
|
|
|
|
//
|
|
|
|
// <dir>: no trailing.
|
|
|
|
static LibError add_oal_dlls_in_dir(const char* dir, StringSet* dlls)
|
|
|
|
{
|
2007-05-24 14:31:16 +02:00
|
|
|
// note: dll_list_add requires the full DLL path but DirEnt only gives us
|
|
|
|
// the name. for efficiency, we append this via PathPackage.
|
2006-04-24 01:14:18 +02:00
|
|
|
PathPackage pp;
|
|
|
|
RETURN_ERR(path_package_set_dir(&pp, dir));
|
|
|
|
|
|
|
|
DirIterator d;
|
|
|
|
RETURN_ERR(dir_open(dir, &d));
|
|
|
|
|
|
|
|
for(;;) // instead of while to avoid warning
|
|
|
|
{
|
2007-05-24 14:31:16 +02:00
|
|
|
DirEnt ent;
|
2006-04-24 01:14:18 +02:00
|
|
|
LibError err = dir_next_ent(&d, &ent);
|
2006-09-22 15:19:40 +02:00
|
|
|
if(err != INFO::OK)
|
2006-04-24 01:14:18 +02:00
|
|
|
break;
|
2007-05-24 14:31:16 +02:00
|
|
|
|
|
|
|
if(!IsOpenAlDll(&ent))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// already in StringSet (i.e. has already been dll_list_add-ed)
|
|
|
|
std::pair<StringSet::iterator, bool> ret = dlls->insert(ent.name);
|
|
|
|
if(!ret.second) // insert failed - element already there
|
|
|
|
continue;
|
|
|
|
|
|
|
|
(void)path_package_append_file(&pp, ent.name);
|
|
|
|
(void)dll_list_add(pp.path);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(void)dir_close(&d);
|
2006-09-22 15:19:40 +02:00
|
|
|
return INFO::OK;
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-26 17:34:10 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// DirectSound driver version
|
|
|
|
|
|
|
|
// we've seen audio problems caused by buggy DirectSound drivers (because
|
|
|
|
// OpenAL can use them in its implementation), so their version should be
|
|
|
|
// retrieved as well. the only way I know of is to enumerate all DS devices.
|
|
|
|
//
|
|
|
|
// unfortunately this fails with Vista's DS emulation - it returns some
|
|
|
|
// GUID crap as the module name. to avoid crashing when attempting to get
|
|
|
|
// the version info for that bogus driver path, we'll skip this code there.
|
|
|
|
// (delay-loading dsound.dll eliminates any overhead)
|
|
|
|
|
|
|
|
static char directSoundDriverPath[MAX_PATH+1];
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// store sound card name and path to DirectSound driver.
|
|
|
|
// called for each DirectSound driver, but aborts after first valid driver.
|
2007-05-26 17:34:10 +02:00
|
|
|
static BOOL CALLBACK DirectSoundCallback(void* guid, const char* UNUSED(description),
|
2007-05-16 17:56:47 +02:00
|
|
|
const char* module, void* UNUSED(ctx))
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-24 14:31:16 +02:00
|
|
|
// skip first dummy entry (description == "Primary Sound Driver")
|
|
|
|
if(guid == NULL)
|
2006-04-24 01:14:18 +02:00
|
|
|
return TRUE; // continue calling
|
|
|
|
|
2007-05-24 14:31:16 +02:00
|
|
|
// note: $system\\drivers is not in LoadLibrary's search list,
|
2006-04-24 01:14:18 +02:00
|
|
|
// so we have to give the full pathname.
|
2007-05-26 17:34:10 +02:00
|
|
|
snprintf(directSoundDriverPath, ARRAY_SIZE(directSoundDriverPath), "%s\\drivers\\%s", win_sys_dir, module);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// we assume the first "driver name" (sound card) is the one we want;
|
|
|
|
// stick with that and stop calling.
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-05-26 17:34:10 +02:00
|
|
|
static const char* GetDirectSoundDriverPath()
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-26 17:34:10 +02:00
|
|
|
#define DS_OK 0
|
|
|
|
typedef BOOL (CALLBACK* LPDSENUMCALLBACKA)(void*, const char*, const char*, void*);
|
|
|
|
HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA, void*);
|
|
|
|
HMODULE hDsoundDll = LoadLibrary("dsound.dll");
|
|
|
|
*(void**)&pDirectSoundEnumerateA = GetProcAddress(hDsoundDll, "DirectSoundEnumerateA");
|
|
|
|
if(pDirectSoundEnumerateA)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-26 17:45:34 +02:00
|
|
|
if(pDirectSoundEnumerateA(DirectSoundCallback, (void*)0) != DS_OK)
|
2007-05-26 17:34:10 +02:00
|
|
|
debug_warn("DirectSoundEnumerate failed");
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
2007-05-26 17:34:10 +02:00
|
|
|
FreeLibrary(hDsoundDll);
|
|
|
|
|
|
|
|
return directSoundDriverPath;
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-26 17:34:10 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
LibError win_get_snd_info()
|
|
|
|
{
|
2006-04-24 01:14:18 +02:00
|
|
|
// find all DLLs related to OpenAL, retrieve their versions,
|
|
|
|
// and store in snd_drv_ver string.
|
|
|
|
dll_list_init(snd_drv_ver, SND_DRV_VER_LEN);
|
2007-05-26 17:34:10 +02:00
|
|
|
if(!wutil_IsVista())
|
|
|
|
(void)dll_list_add(GetDirectSoundDriverPath());
|
2006-04-24 01:14:18 +02:00
|
|
|
StringSet dlls; // ensures uniqueness
|
|
|
|
(void)add_oal_dlls_in_dir(win_exe_dir, &dlls);
|
|
|
|
(void)add_oal_dlls_in_dir(win_sys_dir, &dlls);
|
2006-09-22 15:19:40 +02:00
|
|
|
return INFO::OK;
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|