Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphicsCapture.dll marshall error #90

Open
Wmeeww opened this issue Jan 19, 2025 · 1 comment
Open

GraphicsCapture.dll marshall error #90

Wmeeww opened this issue Jan 19, 2025 · 1 comment

Comments

@Wmeeww
Copy link

Wmeeww commented Jan 19, 2025

Hi rob, thank you for sharing with us this sample, very helpful I'm studying it to learn more about screen capturing using DirectX.

I have compiled the project source on Windows 10 19045.5073, using VS22 17.12.4, Radeon RX 7600 XT (drivers updated) but I'm getting these errors whenever I try to capture any window:

GraphicsCapture.dll!00007FFA693E7FFB: ReturnHr(1) tid(8a94) 8001010E The application called an interface that was marshalled for a different thread.
    Msg:[winrt::hresult_error: The application called an interface that was marshalled for a different thread.] 
C:\Users\RUAN\Desktop\Win32CaptureSample-main\Win32CaptureSample\x64\Debug\Generated Files\winrt\Windows.Graphics.Capture.h(54)\Win32CaptureSample.exe!00007FF678AFBA5B: LogHr(1) tid(8a94) 8001010E The application called an interface that was marshalled for a different thread.
    [auto __cdecl winrt::impl::consume_Windows_Graphics_Capture_IDirect3D11CaptureFramePool<struct winrt::Windows::Graphics::Capture::IDirect3D11CaptureFramePool>::Recreate(const struct winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice &,const enum winrt::Windows::Graphics::DirectX::DirectXPixelFormat &,int,const struct winrt::Windows::Graphics::SizeInt32 &) const]
Win32CaptureSample.exe!00007FF678C55040: ReturnHr(1) tid(8a94) 8001010E The application called an interface that was marshalled for a different thread.
    Msg:[winrt::hresult_error: The application called an interface that was marshalled for a different thread.] 
GraphicsCapture.dll!00007FFA693E7B24: ReturnHr(2) tid(8a94) 8001010E The application called an interface that was marshalled for a different thread.
    Msg:[winrt::hresult_error: The application called an interface that was marshalled for a different thread.] 

At the moment I'm using BitBlt to capture a specific window (960x540) compress the image and send it through a websocket server, I'm taking one frame/image every 100ms which result in something like 10fps, i'm doing it like this:

// ...

BITMAPINFO bi;
data->bi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
data->bi.bmiHeader.biWidth       = data->width;
data->bi.bmiHeader.biHeight      = -data->height;
data->bi.bmiHeader.biPlanes      = 1;
data->bi.bmiHeader.biBitCount    = 24;
data->bi.bmiHeader.biCompression = BI_RGB;

data->hdcWindow = GetDCEx(hwnd, 0, DCX_WINDOW | DCX_CACHE);
data->hdcMemDC = CreateCompatibleDC(data->hdcWindow);
data->hbm = CreateDIBSection(data->hdcMemDC, &data->bi, DIB_RGB_COLORS, (void**)&data->Scan0, 0, 0);
SelectObject(data->hdcMemDC, data->hbm);

// ...

void capture() {
    BitBlt(data->hdcMemDC, 0, 0, data->width, data->height, data->hdcWindow, 0, 0, SRCCOPY);
}

I'm capturing 200~ windows, BitBlt is using so much GPU;
I'm reading that using DirectX is more efficient.

Using the Windows.Graphics.Capture API is it possible to take one capture every 100ms instead of a live stream?
Would it use less GPU than BitBlt in this specific use case?

@robmikh
Copy link
Owner

robmikh commented Jan 20, 2025

Do you see the same issue with this commit?
0c07c6a

Windows.Graphics.Capture will be a bit more efficient, but at the end of the day you're capturing a fairly large number of windows and pulling the pixels back into system memory. I would advise doing as much as you can on the GPU (e.g. changing color depth, resizing, hardware accelerated encoding) and only copy to system memory at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants