-
Notifications
You must be signed in to change notification settings - Fork 193
Open
Description
I am using Windows.Graphics.Capture to capture window, but sometimes I encounter the issue of GraphicsCapture Session::Close not responding. I always start window capture, stop, and call back data in the same thread.
Can anyone give me some suggestions to resolve this issue?
Here is my sample code:
winrt::Windows::Graphics::Capture::GraphicsCaptureItem m_captureItem = {nullptr};
winrt::Windows::Graphics::SizeInt32 m_contentSize;
winrt::Windows::Graphics::Capture::GraphicsCaptureSession m_session = {nullptr};
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool m_framepool = {nullptr};
winrt::Windows::Graphics::Capture::GraphicsCaptureItem::Closed_revoker m_closedtoken;
winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::FrameArrived_revoker m_frametoken;
BOOL CaptureRT::StartWindowCapture(HWND hWND)
{
try
{
LOG(INFO) << StringPrintf("[CaptureRT] Start Window Capture (0x%08X)", hWND);
HRESULT hRes = S_OK;
if (m_captureApp.m_deviceRT != nullptr && hWND != nullptr)
{
auto interop = winrt::get_activation_factory<winrt::Windows::Graphics::Capture::GraphicsCaptureItem,
IGraphicsCaptureItemInterop>();
hRes = interop->CreateForWindow(hWND, winrt::guid_of<ABI::Windows::Graphics::Capture::IGraphicsCaptureItem>(),
reinterpret_cast<void**>(winrt::put_abi(m_captureItem)));
m_closedtoken = m_captureItem.Closed(winrt::auto_revoke, {this, &CaptureRT::OnClosed});
m_contentSize = m_captureItem.Size();
m_framepool = winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::Create(
m_captureApp.m_deviceRT, winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized, 2,
m_contentSize);
m_session = m_framepool.CreateCaptureSession(m_captureItem);
m_frametoken = m_framepool.FrameArrived(winrt::auto_revoke, {this, &CaptureRT::OnFrameArrived});
m_session.StartCapture();
LOG(INFO) << StringPrintf("[CaptureRT] StartCapture success");
return TRUE;
}
return FALSE;
}
catch (...)
{
LOG(ERROR) << StringPrintf("Failed to Create(Unknown exception)");
}
return FALSE;
}
void CaptureRT::Stop()
{
try
{
m_closedtoken.revoke();
m_frametoken.revoke();
if (m_framepool != nullptr)
m_framepool.Close();
m_framepool = nullptr;
if (m_session != nullptr)
m_session.Close();
m_session = nullptr;
m_contentSize.Width = m_contentSize.Height = 0;
}
catch (...)
{
LOG(ERROR) << "Failed to Destroy(Unknown exception)";
}
}The following is the dump and related call stack on anr thread
issue.dmp
Metadata
Metadata
Assignees
Labels
No labels
