libobs-winrt: win-capture: Clean up error handling
Use proper check to fix false positive on 1809, and rework error spew to remove output parameters from winrt_capture_init.master
parent
327a6f599e
commit
e4e96c5cef
|
@ -14,10 +14,10 @@ struct __declspec(uuid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1"))
|
|||
|
||||
extern "C" EXPORT BOOL winrt_capture_supported()
|
||||
{
|
||||
return winrt::Windows::Foundation::Metadata::ApiInformation::IsTypePresent(
|
||||
L"Windows.Graphics.Capture.GraphicsCaptureSession") &&
|
||||
winrt::Windows::Graphics::Capture::GraphicsCaptureSession::
|
||||
IsSupported();
|
||||
/* no contract for IGraphicsCaptureItemInterop, verify 10.0.18362.0 */
|
||||
return winrt::Windows::Foundation::Metadata::ApiInformation::
|
||||
IsApiContractPresent(L"Windows.Foundation.UniversalApiContract",
|
||||
8);
|
||||
}
|
||||
|
||||
extern "C" EXPORT BOOL winrt_capture_cursor_toggle_supported()
|
||||
|
@ -311,18 +311,14 @@ static void winrt_capture_device_loss_rebuild(void *device_void, void *data)
|
|||
thread_local bool initialized_tls;
|
||||
|
||||
extern "C" EXPORT struct winrt_capture *
|
||||
winrt_capture_init(BOOL cursor, HWND window, BOOL client_area, char **error,
|
||||
HRESULT *hr_out)
|
||||
winrt_capture_init(BOOL cursor, HWND window, BOOL client_area)
|
||||
try {
|
||||
ID3D11Device *const d3d_device = (ID3D11Device *)gs_get_device_obj();
|
||||
ComPtr<IDXGIDevice> dxgi_device;
|
||||
|
||||
*error = nullptr;
|
||||
|
||||
HRESULT hr = d3d_device->QueryInterface(&dxgi_device);
|
||||
if (FAILED(hr)) {
|
||||
*error = bstrdup("Failed to get DXGI device");
|
||||
*hr_out = hr;
|
||||
blog(LOG_ERROR, "Failed to get DXGI device");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -330,8 +326,7 @@ try {
|
|||
hr = CreateDirect3D11DeviceFromDXGIDevice(dxgi_device.Get(),
|
||||
inspectable.put());
|
||||
if (FAILED(hr)) {
|
||||
*error = bstrdup("Failed to get WinRT device");
|
||||
*hr_out = hr;
|
||||
blog(LOG_ERROR, "Failed to get WinRT device");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -347,8 +342,8 @@ try {
|
|||
IGraphicsCaptureItem>(),
|
||||
reinterpret_cast<void **>(winrt::put_abi(item)));
|
||||
} catch (winrt::hresult_error &err) {
|
||||
*error = bstrdup("CreateForWindow failed");
|
||||
*hr_out = err.code();
|
||||
blog(LOG_ERROR, "CreateForWindow (0x%08X): %ls", err.to_abi(),
|
||||
err.message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -404,8 +399,8 @@ try {
|
|||
return capture;
|
||||
|
||||
} catch (winrt::hresult_error &err) {
|
||||
*error = bstrdup("oh wow something else in winrt_capture_init failed");
|
||||
*hr_out = err.code();
|
||||
blog(LOG_ERROR, "winrt_capture_init (0x%08X): %ls", err.to_abi(),
|
||||
err.message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ extern "C" {
|
|||
EXPORT BOOL winrt_capture_supported();
|
||||
EXPORT BOOL winrt_capture_cursor_toggle_supported();
|
||||
EXPORT struct winrt_capture *winrt_capture_init(BOOL cursor, HWND window,
|
||||
BOOL client_area, char **error,
|
||||
HRESULT *hr);
|
||||
BOOL client_area);
|
||||
EXPORT void winrt_capture_free(struct winrt_capture *capture);
|
||||
|
||||
EXPORT void winrt_capture_show_cursor(struct winrt_capture *capture,
|
||||
|
|
|
@ -29,8 +29,7 @@ struct winrt_exports {
|
|||
BOOL *(*winrt_capture_supported)();
|
||||
BOOL *(*winrt_capture_cursor_toggle_supported)();
|
||||
struct winrt_capture *(*winrt_capture_init)(BOOL cursor, HWND window,
|
||||
BOOL client_area,
|
||||
char **error, HRESULT *hr);
|
||||
BOOL client_area);
|
||||
void (*winrt_capture_free)(struct winrt_capture *capture);
|
||||
void (*winrt_capture_show_cursor)(struct winrt_capture *capture,
|
||||
BOOL visible);
|
||||
|
@ -247,6 +246,8 @@ static void wc_update(void *data, obs_data_t *settings)
|
|||
/* forces a reset */
|
||||
wc->window = NULL;
|
||||
wc->check_window_timer = WC_CHECK_TIMER;
|
||||
|
||||
wc->previously_failed = false;
|
||||
}
|
||||
|
||||
static uint32_t wc_width(void *data)
|
||||
|
@ -480,24 +481,16 @@ static void wc_tick(void *data, float seconds)
|
|||
dc_capture_capture(&wc->capture, wc->window);
|
||||
} else if (wc->method == METHOD_WGC) {
|
||||
if (wc->window && (wc->capture_winrt == NULL)) {
|
||||
char *error = NULL;
|
||||
HRESULT hr;
|
||||
if (!wc->previously_failed) {
|
||||
wc->capture_winrt =
|
||||
wc->exports.winrt_capture_init(
|
||||
wc->cursor, wc->window,
|
||||
wc->client_area);
|
||||
|
||||
wc->capture_winrt = wc->exports.winrt_capture_init(
|
||||
wc->cursor, wc->window, wc->client_area, &error,
|
||||
&hr);
|
||||
|
||||
if (!wc->capture_winrt && !wc->previously_failed) {
|
||||
blog(LOG_WARNING,
|
||||
"%s: winrt_capture_init failed: %s: %lX",
|
||||
obs_source_get_name(wc->source), error,
|
||||
hr);
|
||||
wc->previously_failed = true;
|
||||
} else if (wc->capture_winrt) {
|
||||
wc->previously_failed = false;
|
||||
if (!wc->capture_winrt) {
|
||||
wc->previously_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
bfree(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue