Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/sanear.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Marsev <alex.marsev@gmail.com>2016-01-26 15:22:30 +0300
committerAlex Marsev <alex.marsev@gmail.com>2016-01-27 09:23:14 +0300
commit85e9c5b1d4232994f64a0a42e543680e596736c1 (patch)
tree2a519c7c61d3cf4040e99cdcef584f9bcb69a8ce
parente574fd060be9858dff383da1ad539d7ee9c6b5d8 (diff)
Use MMCSS for event mode audio device
-rw-r--r--src/AudioDeviceEvent.cpp23
-rw-r--r--src/Utils.h18
-rw-r--r--src/pch.h1
3 files changed, 41 insertions, 1 deletions
diff --git a/src/AudioDeviceEvent.cpp b/src/AudioDeviceEvent.cpp
index b4fd323..774b74b 100644
--- a/src/AudioDeviceEvent.cpp
+++ b/src/AudioDeviceEvent.cpp
@@ -3,6 +3,15 @@
namespace SaneAudioRenderer
{
+ namespace
+ {
+ WinapiFunc<decltype(AvSetMmThreadCharacteristicsW)>
+ AvSetMmThreadCharacteristicsFunction(L"avrt.dll", "AvSetMmThreadCharacteristicsW");
+
+ WinapiFunc<decltype(AvRevertMmThreadCharacteristics)>
+ AvRevertMmThreadCharacteristicsFunction(L"avrt.dll", "AvRevertMmThreadCharacteristics");
+ }
+
AudioDeviceEvent::AudioDeviceEvent(std::shared_ptr<AudioDeviceBackend> backend)
{
assert(backend);
@@ -143,7 +152,16 @@ namespace SaneAudioRenderer
void AudioDeviceEvent::EventFeed()
{
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
+ HANDLE taskHandle = NULL;
+ if (AvSetMmThreadCharacteristicsFunction && AvRevertMmThreadCharacteristicsFunction)
+ {
+ DWORD taskIndex = 0;
+ taskHandle = AvSetMmThreadCharacteristicsFunction(L"Pro Audio", &taskIndex);
+ assert(taskHandle != NULL);
+ }
+
+ if (taskHandle == NULL)
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
while (!m_exit)
{
@@ -172,6 +190,9 @@ namespace SaneAudioRenderer
m_wake.Wait();
}
+
+ if (taskHandle != NULL)
+ AvRevertMmThreadCharacteristicsFunction(taskHandle);
}
void AudioDeviceEvent::PushBufferToDevice()
diff --git a/src/Utils.h b/src/Utils.h
index 1a8d9a9..8b996aa 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -118,4 +118,22 @@ namespace SaneAudioRenderer
}
#endif
}
+
+ template <typename>
+ class WinapiFunc;
+ template <typename ReturnType, typename...Args>
+ class WinapiFunc<ReturnType WINAPI(Args...)> final
+ {
+ public:
+ typedef ReturnType(WINAPI* Func)(Args...);
+ WinapiFunc(LPCWSTR dll, LPCSTR func) { m_lib = LoadLibrary(dll); m_func = (Func)GetProcAddress(m_lib, func); }
+ WinapiFunc(const WinapiFunc&) = delete;
+ WinapiFunc& operator=(const WinapiFunc&) = delete;
+ ~WinapiFunc() { FreeLibrary(m_lib); }
+ explicit operator bool() const { return !!m_func; }
+ ReturnType operator()(Args...args) const { return m_func(args...); }
+ private:
+ HMODULE m_lib = NULL;
+ Func m_func = nullptr;
+ };
}
diff --git a/src/pch.h b/src/pch.h
index 530d9ac..7490c9a 100644
--- a/src/pch.h
+++ b/src/pch.h
@@ -8,6 +8,7 @@
#include <streams.h>
+#include <avrt.h>
#include <audioclient.h>
#include <comdef.h>
#include <malloc.h>