From: <man...@us...> - 2013-12-31 17:36:43
|
Revision: 3535 http://sourceforge.net/p/modplug/code/3535 Author: manxorist Date: 2013-12-31 17:36:35 +0000 (Tue, 31 Dec 2013) Log Message: ----------- [Ref] Add mpt::Windows::GetWinNTVersion() . [Ref] Make CPriorityBooster independent from CAudioThread . Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevices.h Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-12-31 16:46:21 UTC (rev 3534) +++ trunk/OpenMPT/common/misc_util.h 2013-12-31 17:36:35 UTC (rev 3535) @@ -649,3 +649,28 @@ std::vector<char> HexToBin(const std::wstring &src); } // namespace Util + +namespace mpt +{ + +#if defined(WIN32) + +namespace Windows +{ + +// returns version in the form of the _WIN32_WINNT_* macros +static inline uint32 GetWinNTVersion() +//------------------------------------ +{ + OSVERSIONINFO versioninfo; + MemsetZero(versioninfo); + versioninfo.dwOSVersionInfoSize = sizeof(versioninfo); + GetVersionEx(&versioninfo); + return ((uint32)mpt::saturate_cast<uint8>(versioninfo.dwMajorVersion) << 8) | (uint32)mpt::saturate_cast<uint8>(versioninfo.dwMinorVersion); +} + +} // namespace Windows + +#endif // WIN32 + +} // namespace mpt Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-12-31 16:46:21 UTC (rev 3534) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-12-31 17:36:35 UTC (rev 3535) @@ -388,15 +388,9 @@ //------------------------------------------------------------------------------------------ { - OSVERSIONINFO versioninfo; - MemsetZero(versioninfo); - versioninfo.dwOSVersionInfoSize = sizeof(versioninfo); - GetVersionEx(&versioninfo); - m_HasXP = versioninfo.dwMajorVersion >= 6 || (versioninfo.dwMajorVersion == 5 && versioninfo.dwMinorVersion >= 1); - m_HasVista = versioninfo.dwMajorVersion >= 6; + m_HasXP = (mpt::Windows::GetWinNTVersion() >= _WIN32_WINNT_WINXP); m_hKernel32DLL = NULL; - m_hAvRtDLL = NULL; pCreateWaitableTimer = nullptr; pSetWaitableTimer = nullptr; @@ -420,22 +414,6 @@ } #endif - pAvSetMmThreadCharacteristics = nullptr; - pAvRevertMmThreadCharacteristics = nullptr; - if(m_HasVista) - { - m_hAvRtDLL = LoadLibrary(TEXT("avrt.dll")); - if(m_hAvRtDLL) - { - pAvSetMmThreadCharacteristics = (FAvSetMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvSetMmThreadCharacteristicsA"); - pAvRevertMmThreadCharacteristics = (FAvRevertMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvRevertMmThreadCharacteristics"); - } - if(!pAvSetMmThreadCharacteristics || !pAvRevertMmThreadCharacteristics) - { - m_HasVista = false; - } - } - m_WakeupInterval = 0.0; m_hPlayThread = NULL; m_dwPlayThreadId = 0; @@ -477,18 +455,10 @@ m_hAudioWakeUp = NULL; } - pAvRevertMmThreadCharacteristics = nullptr; - pAvSetMmThreadCharacteristics = nullptr; pCreateWaitableTimer = nullptr; pSetWaitableTimer = nullptr; pCancelWaitableTimer = nullptr; - if(m_hAvRtDLL) - { - FreeLibrary(m_hAvRtDLL); - m_hAvRtDLL = NULL; - } - if(m_hKernel32DLL) { FreeLibrary(m_hKernel32DLL); @@ -498,58 +468,78 @@ } -class CPriorityBooster +CPriorityBooster::CPriorityBooster(bool boostPriority) +//---------------------------------------------------- + : m_HasVista(false) + , m_hAvRtDLL(NULL) + , pAvSetMmThreadCharacteristics(nullptr) + , pAvRevertMmThreadCharacteristics(nullptr) + , m_BoostPriority(boostPriority) + , task_idx(0) + , hTask(NULL) { -private: - CAudioThread &self; - bool m_BoostPriority; - DWORD task_idx; - HANDLE hTask; -public: - CPriorityBooster(CAudioThread &self_, bool boostPriority) : self(self_), m_BoostPriority(boostPriority) - //----------------------------------------------------------------------------------------------------- + m_HasVista = (mpt::Windows::GetWinNTVersion() >= _WIN32_WINNT_VISTA); + + if(m_HasVista) { - #ifdef _DEBUG - m_BoostPriority = false; - #endif + m_hAvRtDLL = LoadLibrary(TEXT("avrt.dll")); + if(m_hAvRtDLL && m_hAvRtDLL != INVALID_HANDLE_VALUE) + { + pAvSetMmThreadCharacteristics = (FAvSetMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvSetMmThreadCharacteristicsA"); + pAvRevertMmThreadCharacteristics = (FAvRevertMmThreadCharacteristics)GetProcAddress(m_hAvRtDLL, "AvRevertMmThreadCharacteristics"); + } + if(!pAvSetMmThreadCharacteristics || !pAvRevertMmThreadCharacteristics) + { + m_HasVista = false; + } + } - task_idx = 0; - hTask = NULL; + #ifdef _DEBUG + m_BoostPriority = false; + #endif - if(m_BoostPriority) + if(m_BoostPriority) + { + if(m_HasVista) { - if(self.m_HasVista) - { - hTask = self.pAvSetMmThreadCharacteristics(TEXT("Pro Audio"), &task_idx); - } else - { - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); - } + hTask = pAvSetMmThreadCharacteristics(TEXT("Pro Audio"), &task_idx); + } else + { + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); } - } - CPriorityBooster::~CPriorityBooster() - //----------------------------------- +} + + +CPriorityBooster::~CPriorityBooster() +//----------------------------------- +{ + + if(m_BoostPriority) { - - if(m_BoostPriority) + if(m_HasVista) { - if(self.m_HasVista) - { - self.pAvRevertMmThreadCharacteristics(hTask); - hTask = NULL; - task_idx = 0; - } else - { - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); - } + pAvRevertMmThreadCharacteristics(hTask); + hTask = NULL; + task_idx = 0; + } else + { + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); } + } + pAvRevertMmThreadCharacteristics = nullptr; + pAvSetMmThreadCharacteristics = nullptr; + + if(m_hAvRtDLL) + { + FreeLibrary(m_hAvRtDLL); + m_hAvRtDLL = NULL; } -}; +} class CPeriodicWaker @@ -691,7 +681,7 @@ if(!terminate) { - CPriorityBooster priorityBooster(*this, m_SoundDevice.m_Settings.BoostThreadPriority); + CPriorityBooster priorityBooster(m_SoundDevice.m_Settings.BoostThreadPriority); CPeriodicWaker periodicWaker(*this, m_WakeupInterval); m_SoundDevice.StartFromSoundThread(); Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-12-31 16:46:21 UTC (rev 3534) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-12-31 17:36:35 UTC (rev 3535) @@ -16,27 +16,40 @@ class CSoundDeviceWithThread; + +class CPriorityBooster +{ +private: + typedef HANDLE (WINAPI *FAvSetMmThreadCharacteristics)(LPCTSTR, LPDWORD); + typedef BOOL (WINAPI *FAvRevertMmThreadCharacteristics)(HANDLE); +private: + bool m_HasVista; + HMODULE m_hAvRtDLL; + FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics; + FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics; + bool m_BoostPriority; + DWORD task_idx; + HANDLE hTask; +public: + CPriorityBooster(bool boostPriority); + ~CPriorityBooster(); +}; + + class CAudioThread { - friend class CPriorityBooster; friend class CPeriodicWaker; private: CSoundDeviceWithThread & m_SoundDevice; bool m_HasXP; - bool m_HasVista; HMODULE m_hKernel32DLL; - HMODULE m_hAvRtDLL; typedef HANDLE (WINAPI *FCreateWaitableTimer)(LPSECURITY_ATTRIBUTES, BOOL, LPCTSTR); typedef BOOL (WINAPI *FSetWaitableTimer)(HANDLE, const LARGE_INTEGER *, LONG, PTIMERAPCROUTINE, LPVOID, BOOL); typedef BOOL (WINAPI *FCancelWaitableTimer)(HANDLE); - typedef HANDLE (WINAPI *FAvSetMmThreadCharacteristics)(LPCTSTR, LPDWORD); - typedef BOOL (WINAPI *FAvRevertMmThreadCharacteristics)(HANDLE); FCreateWaitableTimer pCreateWaitableTimer; FSetWaitableTimer pSetWaitableTimer; FCancelWaitableTimer pCancelWaitableTimer; - FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics; - FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics; double m_WakeupInterval; HANDLE m_hAudioWakeUp; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |