Ticket #4561: snd_detect_openal.patch

File snd_detect_openal.patch, 19.2 KB (added by Itms, 7 years ago)
  • build/premake/premake4.lua

     
    803803    extern_libs = {
    804804        "boost",
    805805        "sdl",
     806        "openal",
    806807        "opengl",
    807808        "libpng",
    808809        "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
     35std::string snd_card;
     36std::string snd_drv_ver;
     37
     38void 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 **/
     35extern std::string snd_card;
     36
     37/**
     38 * sound driver identification and version.
     39 **/
     40extern std::string snd_drv_ver;
     41
     42/**
     43 * detect sound card and set the above information.
     44 **/
     45extern 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 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 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 several
    49 // 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 the
    55 // 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 there
    69             continue;
    70 
    71         wdll_ver_Append(path / name, versionList);
    72     }
    73 }
    74 
    75 
    76 //-----------------------------------------------------------------------------
    77 // DirectSound driver version
    78 
    79 // we've seen audio problems caused by buggy DirectSound drivers (because
    80 // OpenAL can use them in its implementation), so their version should be
    81 // 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 some
    84 // GUID crap as the module name. to avoidc crashing when attempting to get
    85 // 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 calling
    98 
    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 0
    111     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" entries
    132     for(WmiInstances::iterator it = instances.begin(); it != instances.end(); ++it)
    133     {
    134         if((*it)[L"Availability"].intVal != 8)  // not offline
    135             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 uniqueness
    150     (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 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 #ifndef INCLUDED_WSND
    24 #define INCLUDED_WSND
    25 
    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 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/sysdep/snd.h"
    29 
    30 #if OS_WIN
    31 # include "lib/sysdep/os/win/wsnd.h"
    32 #endif
    33 
    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 returns
    41     // OpenAL API version and renderer (e.g. "Software").
    42 
    43 #if OS_WIN
    44     win_get_snd_info();
    45 #else
    46     // At least reset the values for unhandled platforms.
    47     ENSURE(SND_CARD_LEN >= 8 && SND_DRV_VER_LEN >= 8);  // protect strcpy
    48     wcscpy_s(snd_card, ARRAY_SIZE(snd_card), L"Unknown");
    49     wcscpy_s(snd_drv_ver, ARRAY_SIZE(snd_drv_ver), L"Unknown");
    50 #endif
    51 }
  • 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 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 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) 2015 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2020#include "scriptinterface/ScriptInterface.h"
    2121
    2222#include "lib/ogl.h"
     23#include "lib/snd.h"
    2324#include "lib/svn_revision.h"
    2425#include "lib/timer.h"
    2526#include "lib/utf8.h"
     
    3031#include "lib/sysdep/gfx.h"
    3132#include "lib/sysdep/numa.h"
    3233#include "lib/sysdep/os_cpu.h"
    33 #include "lib/sysdep/snd.h"
    3434#if ARCH_X86_X64
    3535# include "lib/sysdep/arch/x86_x64/cache.h"
    3636# include "lib/sysdep/arch/x86_x64/topology.h"
     
    265265    scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName());
    266266    scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo());
    267267
    268     scriptInterface.SetProperty(settings, "snd_card", std::wstring(snd_card));
    269     scriptInterface.SetProperty(settings, "snd_drv_ver", std::wstring(snd_drv_ver));
     268    scriptInterface.SetProperty(settings, "snd_card", snd_card);
     269    scriptInterface.SetProperty(settings, "snd_drv_ver", snd_drv_ver);
    270270
    271271    ReportGLLimits(scriptInterface, settings);
    272272
  • source/ps/Util.cpp

     
    1 /* Copyright (C) 2016 Wildfire Games.
     1/* Copyright (C) 2017 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2121
    2222#include "lib/posix/posix_utsname.h"
    2323#include "lib/ogl.h"
     24#include "lib/snd.h"
    2425#include "lib/timer.h"
    2526#include "lib/bits.h"   // round_up
    2627#include "lib/allocators/shared_ptr.h"
    2728#include "lib/sysdep/sysdep.h"  // sys_OpenFile
    2829#include "lib/sysdep/gfx.h"
    29 #include "lib/sysdep/snd.h"
    3030#include "lib/sysdep/cpu.h"
    3131#include "lib/sysdep/os_cpu.h"
    3232#if ARCH_X86_X64
     
    137137    fprintf(f, "Video Mode     : %dx%d:%d\n", g_VideoMode.GetXRes(), g_VideoMode.GetYRes(), g_VideoMode.GetBPP());
    138138
    139139    // 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());
    142142
    143143    // OpenGL extensions (write them last, since it's a lot of text)
    144144    const char* exts = ogl_ExtensionString();