forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request obsproject#2964 from jpark37/winrt-dispatcher
Set up dispatcher queue for WGC stability
- Loading branch information
Showing
6 changed files
with
231 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
extern "C" EXPORT void winrt_initialize() | ||
{ | ||
winrt::init_apartment(winrt::apartment_type::single_threaded); | ||
} | ||
|
||
extern "C" EXPORT void winrt_uninitialize() | ||
{ | ||
winrt::uninit_apartment(); | ||
} | ||
|
||
static winrt::Windows::System::DispatcherQueueController | ||
CreateDispatcherQueueController() | ||
{ | ||
DispatcherQueueOptions options{sizeof(DispatcherQueueOptions), | ||
DQTYPE_THREAD_CURRENT, DQTAT_COM_STA}; | ||
|
||
winrt::Windows::System::DispatcherQueueController controller{nullptr}; | ||
winrt::check_hresult(CreateDispatcherQueueController( | ||
options, | ||
reinterpret_cast< | ||
ABI::Windows::System::IDispatcherQueueController **>( | ||
winrt::put_abi(controller)))); | ||
return controller; | ||
} | ||
|
||
struct winrt_disaptcher { | ||
winrt::Windows::System::DispatcherQueueController controller{nullptr}; | ||
}; | ||
|
||
extern "C" EXPORT struct winrt_disaptcher *winrt_dispatcher_init() | ||
{ | ||
struct winrt_disaptcher *dispatcher = NULL; | ||
try { | ||
if (winrt::Windows::Foundation::Metadata::ApiInformation:: | ||
IsApiContractPresent( | ||
L"Windows.Foundation.UniversalApiContract", | ||
5)) { | ||
winrt::Windows::System::DispatcherQueueController | ||
controller = CreateDispatcherQueueController(); | ||
|
||
dispatcher = new struct winrt_disaptcher; | ||
dispatcher->controller = std::move(controller); | ||
} | ||
} catch (const winrt::hresult_error &err) { | ||
blog(LOG_ERROR, "winrt_dispatcher_init (0x%08X): %ls", | ||
err.to_abi(), err.message().c_str()); | ||
} catch (...) { | ||
blog(LOG_ERROR, "winrt_dispatcher_init (0x%08X)", | ||
winrt::to_hresult()); | ||
} | ||
|
||
return dispatcher; | ||
} | ||
|
||
extern "C" EXPORT void | ||
winrt_dispatcher_free(struct winrt_disaptcher *dispatcher) | ||
try { | ||
delete dispatcher; | ||
} catch (const winrt::hresult_error &err) { | ||
blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X): %ls", err.to_abi(), | ||
err.message().c_str()); | ||
} catch (...) { | ||
blog(LOG_ERROR, "winrt_dispatcher_free (0x%08X)", winrt::to_hresult()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
|
||
#include <obs-module.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
EXPORT void winrt_initialize(); | ||
EXPORT void winrt_uninitialize(); | ||
EXPORT struct winrt_disaptcher *winrt_dispatcher_init(); | ||
EXPORT void winrt_dispatcher_free(struct winrt_disaptcher *dispatcher); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters