Ticket #4561: snd_detect_openal.patch
File snd_detect_openal.patch, 19.2 KB (added by , 7 years ago) |
---|
-
build/premake/premake4.lua
803 803 extern_libs = { 804 804 "boost", 805 805 "sdl", 806 "openal", 806 807 "opengl", 807 808 "libpng", 808 809 "zlib", -
source/lib/snd.cpp
1 /* Copyright (c) 2017 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 /* 24 * sound card detection. 25 */ 26 27 #include "precompiled.h" 28 #include "lib/snd.h" 29 30 #include <stdio.h> 31 #include <stdlib.h> 32 33 #include "lib/external_libraries/openal.h" 34 35 std::string snd_card; 36 std::string snd_drv_ver; 37 38 void snd_detect() 39 { 40 // OpenAL alGetString might not return anything interesting on certain platforms 41 // (see https://stackoverflow.com/questions/28960638 for an example). 42 // However our previous code supported only Windows, and alGetString does work on 43 // Windows, so this is an improvement. 44 45 // Sound cards 46 47 const ALCchar* devices = NULL; 48 if (alcIsExtensionPresent(NULL, "ALC_enumeration_EXT") == AL_TRUE) 49 { 50 if (alcIsExtensionPresent(NULL, "ALC_enumerate_all_EXT") == AL_TRUE) 51 devices = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); 52 else 53 devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER); 54 } 55 WARN_IF_FALSE(devices); 56 57 snd_card.clear(); 58 do { 59 snd_card += devices; 60 devices += strlen(devices) + 1; 61 snd_card += "; "; 62 } while (*devices); 63 64 // Driver version 65 snd_drv_ver = alGetString(AL_VERSION); 66 } -
source/lib/snd.h
Property changes on: source/lib/snd.cpp ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 /* Copyright (c) 2017 Wildfire Games 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining 4 * a copy of this software and associated documentation files (the 5 * "Software"), to deal in the Software without restriction, including 6 * without limitation the rights to use, copy, modify, merge, publish, 7 * distribute, sublicense, and/or sell copies of the Software, and to 8 * permit persons to whom the Software is furnished to do so, subject to 9 * the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 23 /* 24 * sound card detection. 25 */ 26 27 #ifndef INCLUDED_SND 28 #define INCLUDED_SND 29 30 #include <string> 31 32 /** 33 * description of sound card. 34 **/ 35 extern std::string snd_card; 36 37 /** 38 * sound driver identification and version. 39 **/ 40 extern std::string snd_drv_ver; 41 42 /** 43 * detect sound card and set the above information. 44 **/ 45 extern void snd_detect(); 46 47 #endif // #ifndef INCLUDED_SND -
source/lib/sysdep/os/win/wsnd.cpp
Property changes on: source/lib/snd.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 /* Copyright (c) 2010 Wildfire Games2 *3 * Permission is hereby granted, free of charge, to any person obtaining4 * a copy of this software and associated documentation files (the5 * "Software"), to deal in the Software without restriction, including6 * without limitation the rights to use, copy, modify, merge, publish,7 * distribute, sublicense, and/or sell copies of the Software, and to8 * permit persons to whom the Software is furnished to do so, subject to9 * the following conditions:10 *11 * The above copyright notice and this permission notice shall be included12 * in all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21 */22 23 /*24 * sound card detection on Windows.25 */26 27 #include "precompiled.h"28 #include "lib/sysdep/snd.h"29 30 #include <stdio.h>31 #include <stdlib.h>32 #include <string>33 #include <set>34 35 #include "lib/file/file_system.h"36 #include "lib/sysdep/os/win/wdll_ver.h"37 #include "lib/sysdep/os/win/wversion.h"38 #include "lib/sysdep/os/win/wutil.h"39 #include "lib/sysdep/os/win/wmi.h"40 41 42 static bool IsOpenAlDllName(const Path::String& name)43 {44 // (matches "*oal.dll" and "*OpenAL*", as with OpenAL router's search)45 return name.find(L"oal.dll") != Path::String::npos || name.find(L"OpenAL") != Path::String::npos;46 }47 48 // ensures each OpenAL DLL is only listed once (even if present in several49 // directories on our search path).50 typedef std::set<Path::String> StringSet;51 52 // find all OpenAL DLLs in a dir.53 // call in library search order (exe dir, then win sys dir); otherwise,54 // DLLs in the executable's starting directory hide those of the55 // same name in the system directory.56 static void add_oal_dlls_in_dir(const OsPath& path, StringSet& dlls, VersionList& versionList)57 {58 CFileInfos files;59 (void)GetDirectoryEntries(path, &files, 0);60 for(size_t i = 0; i < files.size(); i++)61 {62 const Path::String name = files[i].Name().string();63 if(!IsOpenAlDllName(name))64 continue;65 66 // already in StringSet (i.e. has already been wdll_ver_list_add-ed)67 std::pair<StringSet::iterator, bool> ret = dlls.insert(name);68 if(!ret.second) // insert failed - element already there69 continue;70 71 wdll_ver_Append(path / name, versionList);72 }73 }74 75 76 //-----------------------------------------------------------------------------77 // DirectSound driver version78 79 // we've seen audio problems caused by buggy DirectSound drivers (because80 // OpenAL can use them in its implementation), so their version should be81 // retrieved as well. the only way I know of is to enumerate all DS devices.82 //83 // unfortunately this fails with Vista's DS emulation - it returns some84 // GUID crap as the module name. to avoidc crashing when attempting to get85 // the version info for that bogus driver path, we'll skip this code there.86 // (delay-loading dsound.dll eliminates any overhead)87 88 static OsPath directSoundDriverPath;89 90 // store sound card name and path to DirectSound driver.91 // called for each DirectSound driver, but aborts after first valid driver.92 static BOOL CALLBACK DirectSoundCallback(void* guid, const wchar_t* UNUSED(description),93 const wchar_t* module, void* UNUSED(cbData))94 {95 // skip first dummy entry (description == "Primary Sound Driver")96 if(guid == NULL)97 return TRUE; // continue calling98 99 // note: $system\\drivers is not in LoadLibrary's search list,100 // so we have to give the full pathname.101 directSoundDriverPath = wutil_SystemPath()/"drivers" / module;102 103 // we assume the first "driver name" (sound card) is the one we want;104 // stick with that and stop calling.105 return FALSE;106 }107 108 static const OsPath& GetDirectSoundDriverPath()109 {110 #define DS_OK 0111 typedef BOOL (CALLBACK* LPDSENUMCALLBACKW)(void*, const wchar_t*, const wchar_t*, void*);112 HMODULE hDsoundDll = LoadLibraryW(L"dsound.dll");113 WUTIL_FUNC(pDirectSoundEnumerateW, HRESULT, (LPDSENUMCALLBACKW, void*));114 WUTIL_IMPORT(hDsoundDll, DirectSoundEnumerateW, pDirectSoundEnumerateW);115 if(pDirectSoundEnumerateW)116 {117 HRESULT ret = pDirectSoundEnumerateW(DirectSoundCallback, (void*)0);118 ENSURE(ret == DS_OK);119 }120 FreeLibrary(hDsoundDll);121 122 return directSoundDriverPath;123 }124 125 //-----------------------------------------------------------------------------126 127 Status win_get_snd_info()128 {129 WmiInstances instances;130 RETURN_STATUS_IF_ERR(wmi_GetClassInstances(L"Win32_SoundDevice", instances));131 std::set<std::wstring> names; // get rid of duplicate "High Definition Audio Device" entries132 for(WmiInstances::iterator it = instances.begin(); it != instances.end(); ++it)133 {134 if((*it)[L"Availability"].intVal != 8) // not offline135 names.insert(std::wstring((*it)[L"ProductName"].bstrVal));136 }137 wchar_t* pos = snd_card;138 for(std::set<std::wstring>::const_iterator it = names.begin(); it != names.end(); ++it)139 {140 const int ret = swprintf_s(pos, SND_CARD_LEN-(pos-snd_card), L"%ls; ", it->c_str());141 if(ret > 0)142 pos += ret;143 }144 145 // find all DLLs related to OpenAL and retrieve their versions.146 VersionList versionList;147 if(wversion_Number() < WVERSION_VISTA)148 wdll_ver_Append(GetDirectSoundDriverPath(), versionList);149 StringSet dlls; // ensures uniqueness150 (void)add_oal_dlls_in_dir(wutil_ExecutablePath(), dlls, versionList);151 (void)add_oal_dlls_in_dir(wutil_SystemPath(), dlls, versionList);152 wcscpy_s(snd_drv_ver, SND_DRV_VER_LEN, versionList.c_str());153 154 return INFO::OK;155 } -
source/lib/sysdep/os/win/wsnd.h
Property changes on: source/lib/sysdep/os/win/wsnd.cpp ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property
1 /* Copyright (c) 2010 Wildfire Games2 *3 * Permission is hereby granted, free of charge, to any person obtaining4 * a copy of this software and associated documentation files (the5 * "Software"), to deal in the Software without restriction, including6 * without limitation the rights to use, copy, modify, merge, publish,7 * distribute, sublicense, and/or sell copies of the Software, and to8 * permit persons to whom the Software is furnished to do so, subject to9 * the following conditions:10 *11 * The above copyright notice and this permission notice shall be included12 * in all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21 */22 23 #ifndef INCLUDED_WSND24 #define INCLUDED_WSND25 26 extern Status win_get_snd_info();27 28 #endif // #ifndef INCLUDED_WSND -
source/lib/sysdep/snd.cpp
Property changes on: source/lib/sysdep/os/win/wsnd.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property
1 /* Copyright (c) 2010 Wildfire Games2 *3 * Permission is hereby granted, free of charge, to any person obtaining4 * a copy of this software and associated documentation files (the5 * "Software"), to deal in the Software without restriction, including6 * without limitation the rights to use, copy, modify, merge, publish,7 * distribute, sublicense, and/or sell copies of the Software, and to8 * permit persons to whom the Software is furnished to do so, subject to9 * the following conditions:10 *11 * The above copyright notice and this permission notice shall be included12 * in all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21 */22 23 /*24 * sound card detection.25 */26 27 #include "precompiled.h"28 #include "lib/sysdep/snd.h"29 30 #if OS_WIN31 # include "lib/sysdep/os/win/wsnd.h"32 #endif33 34 35 wchar_t snd_card[SND_CARD_LEN];36 wchar_t snd_drv_ver[SND_DRV_VER_LEN];37 38 void snd_detect()39 {40 // note: OpenAL alGetString is worthless: it only returns41 // OpenAL API version and renderer (e.g. "Software").42 43 #if OS_WIN44 win_get_snd_info();45 #else46 // At least reset the values for unhandled platforms.47 ENSURE(SND_CARD_LEN >= 8 && SND_DRV_VER_LEN >= 8); // protect strcpy48 wcscpy_s(snd_card, ARRAY_SIZE(snd_card), L"Unknown");49 wcscpy_s(snd_drv_ver, ARRAY_SIZE(snd_drv_ver), L"Unknown");50 #endif51 } -
source/lib/sysdep/snd.h
Property changes on: source/lib/sysdep/snd.cpp ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property
1 /* Copyright (c) 2015 Wildfire Games2 *3 * Permission is hereby granted, free of charge, to any person obtaining4 * a copy of this software and associated documentation files (the5 * "Software"), to deal in the Software without restriction, including6 * without limitation the rights to use, copy, modify, merge, publish,7 * distribute, sublicense, and/or sell copies of the Software, and to8 * permit persons to whom the Software is furnished to do so, subject to9 * the following conditions:10 *11 * The above copyright notice and this permission notice shall be included12 * in all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21 */22 23 /*24 * sound card detection.25 */26 27 #ifndef INCLUDED_SND28 #define INCLUDED_SND29 30 const size_t SND_CARD_LEN = 512;31 /**32 * description of sound card.33 **/34 extern wchar_t snd_card[SND_CARD_LEN];35 36 const size_t SND_DRV_VER_LEN = 512;37 /**38 * sound driver identification and version.39 **/40 extern wchar_t snd_drv_ver[SND_DRV_VER_LEN];41 42 /**43 * detect sound card and set the above information.44 **/45 extern void snd_detect();46 47 #endif // #ifndef INCLUDED_SND -
source/ps/GameSetup/HWDetect.cpp
Property changes on: source/lib/sysdep/snd.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2017 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 20 20 #include "scriptinterface/ScriptInterface.h" 21 21 22 22 #include "lib/ogl.h" 23 #include "lib/snd.h" 23 24 #include "lib/svn_revision.h" 24 25 #include "lib/timer.h" 25 26 #include "lib/utf8.h" … … 30 31 #include "lib/sysdep/gfx.h" 31 32 #include "lib/sysdep/numa.h" 32 33 #include "lib/sysdep/os_cpu.h" 33 #include "lib/sysdep/snd.h"34 34 #if ARCH_X86_X64 35 35 # include "lib/sysdep/arch/x86_x64/cache.h" 36 36 # include "lib/sysdep/arch/x86_x64/topology.h" … … 265 265 scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName()); 266 266 scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo()); 267 267 268 scriptInterface.SetProperty(settings, "snd_card", s td::wstring(snd_card));269 scriptInterface.SetProperty(settings, "snd_drv_ver", s td::wstring(snd_drv_ver));268 scriptInterface.SetProperty(settings, "snd_card", snd_card); 269 scriptInterface.SetProperty(settings, "snd_drv_ver", snd_drv_ver); 270 270 271 271 ReportGLLimits(scriptInterface, settings); 272 272 -
source/ps/Util.cpp
1 /* Copyright (C) 201 6Wildfire Games.1 /* Copyright (C) 2017 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 21 21 22 22 #include "lib/posix/posix_utsname.h" 23 23 #include "lib/ogl.h" 24 #include "lib/snd.h" 24 25 #include "lib/timer.h" 25 26 #include "lib/bits.h" // round_up 26 27 #include "lib/allocators/shared_ptr.h" 27 28 #include "lib/sysdep/sysdep.h" // sys_OpenFile 28 29 #include "lib/sysdep/gfx.h" 29 #include "lib/sysdep/snd.h"30 30 #include "lib/sysdep/cpu.h" 31 31 #include "lib/sysdep/os_cpu.h" 32 32 #if ARCH_X86_X64 … … 137 137 fprintf(f, "Video Mode : %dx%d:%d\n", g_VideoMode.GetXRes(), g_VideoMode.GetYRes(), g_VideoMode.GetBPP()); 138 138 139 139 // sound 140 fprintf(f, "Sound Card : % ls\n", snd_card);141 fprintf(f, "Sound Drivers : % ls\n", snd_drv_ver);140 fprintf(f, "Sound Card : %s\n", snd_card.c_str()); 141 fprintf(f, "Sound Drivers : %s\n", snd_drv_ver.c_str()); 142 142 143 143 // OpenGL extensions (write them last, since it's a lot of text) 144 144 const char* exts = ogl_ExtensionString();