28 lines
697 B
C++
Raw Permalink Normal View History

2024-05-19 02:43:10 +08:00
2024-11-15 03:25:43 +08:00
#ifndef WINXP
2024-05-19 02:43:10 +08:00
#include "LoopbackCapture.h"
2024-11-15 03:25:43 +08:00
#endif
2024-11-10 19:19:58 +08:00
DECLARE_API HANDLE StartCaptureAsync(void (*datacb)(void *ptr, size_t size))
2024-05-19 02:43:10 +08:00
{
2024-11-15 03:21:30 +08:00
#ifndef WINXP
2024-08-11 22:45:33 +08:00
auto mutex = CreateSemaphoreW(NULL, 0, 1, NULL);
2024-11-10 19:19:58 +08:00
std::thread([=]()
{
CLoopbackCapture loopbackCapture;
2024-08-11 22:45:33 +08:00
loopbackCapture.StartCaptureAsync(GetCurrentProcessId(), false);
WaitForSingleObject(mutex, INFINITE);
CloseHandle(mutex);
2024-05-19 02:43:10 +08:00
loopbackCapture.StopCaptureAsync();
2024-11-10 19:19:58 +08:00
datacb(loopbackCapture.buffer.data(), loopbackCapture.buffer.size()); })
.detach();
return mutex;
2024-11-15 03:21:30 +08:00
#else
return NULL;
#endif
2024-08-11 22:45:33 +08:00
}
2024-11-04 23:10:41 +08:00
DECLARE_API void StopCaptureAsync(HANDLE m)
2024-08-11 22:45:33 +08:00
{
2024-11-15 03:21:30 +08:00
if (m)
ReleaseSemaphore(m, 1, NULL);
2024-05-19 02:43:10 +08:00
}