From d03e959f54b7f9c5d3504abb1701df21f6c08e0b Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 24 Jul 2020 01:56:27 +0900 Subject: [PATCH] d3d11window: Remove timeout and wait a task if possible If the run_async() method is expected to be called from streaming thread and not from application thread, use INFINITE as timeout value so that d3d11window can wait UI dispatcher thread in any case. There is no way to get a robust timeout value from library side. So the fixed timeout value might not be optimal and therefore we should avoid it as much as possible. Rule whether a timeout value can be INFINITE or not is, * If the waiting can be cancelled by GstBaseSink:unlock(), use INFINITE. GstD3D11Window:on_resize() is one case for example. * Otherwise, use timeout value Some details are, GstBaseSink:start() and GstBaseSink:stop() will be called when NULL to READY or READY to NULL state change, so there will be no chance for GstBaseSink:unlock() and GstBaseSink:unlock_stop() to be called around them. So there is no other way then timeout way. GstD3D11Window:consturcted() and GstD3D11Window:unprepare() are the case. Part-of: --- sys/d3d11/gstd3d11window_corewindow.cpp | 4 ++-- sys/d3d11/gstd3d11window_swapchainpanel.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/d3d11/gstd3d11window_corewindow.cpp b/sys/d3d11/gstd3d11window_corewindow.cpp index af0104d358..1e2fab1167 100644 --- a/sys/d3d11/gstd3d11window_corewindow.cpp +++ b/sys/d3d11/gstd3d11window_corewindow.cpp @@ -223,7 +223,7 @@ get_window_size (const ComPtr &dispatcher, HANDLE cancellable, const ComPtr &window, Size *size) { - return run_async (dispatcher, cancellable, DEFAULT_ASYNC_TIMEOUT, + return run_async (dispatcher, cancellable, INFINITE, [window, size] { HRESULT hr; Rect bounds; @@ -481,7 +481,7 @@ gst_d3d11_window_core_window_on_resize (GstD3D11Window * window, GstD3D11WindowCoreWindow *self = GST_D3D11_WINDOW_CORE_WINDOW (window); CoreWindowWinRTStorage *storage = self->storage; - run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT, + run_async (storage->dispatcher, storage->cancellable, INFINITE, [window] { gst_d3d11_window_core_window_on_resize_sync (window); return S_OK; diff --git a/sys/d3d11/gstd3d11window_swapchainpanel.cpp b/sys/d3d11/gstd3d11window_swapchainpanel.cpp index f13d0d98c9..3aad0cf4c0 100644 --- a/sys/d3d11/gstd3d11window_swapchainpanel.cpp +++ b/sys/d3d11/gstd3d11window_swapchainpanel.cpp @@ -384,7 +384,7 @@ gst_d3d11_window_swap_chain_panel_create_swap_chain (GstD3D11Window * window, return FALSE; hr = run_async (storage->dispatcher, - storage->cancellable, DEFAULT_ASYNC_TIMEOUT, + storage->cancellable, INFINITE, [panel_native, new_swapchain] { return panel_native->SetSwapChain(new_swapchain.Get()); }); @@ -476,7 +476,7 @@ gst_d3d11_window_swap_chain_panel_on_resize (GstD3D11Window * window, GST_D3D11_WINDOW_SWAP_CHAIN_PANEL (window); SwapChainPanelWinRTStorage *storage = self->storage; - run_async (storage->dispatcher, storage->cancellable, DEFAULT_ASYNC_TIMEOUT, + run_async (storage->dispatcher, storage->cancellable, INFINITE, [window] { gst_d3d11_window_swap_chain_panel_on_resize_sync (window); return S_OK;