microsoft / Windows.UI.Composition-Win32-Samples

Windows.UI.Composition Win32 Samples
MIT License
469 stars 186 forks source link

Can I do successive captures on two different windows #116

Closed rjx-ray closed 10 months ago

rjx-ray commented 1 year ago

I can successfully capture a window without problems. However I now need to capture 2 or more windows. I am trying to do this by stopping the current capture with this code if (m_capture) { m_capture->Close(); m_capture = nullptr; m_itemClosedRevoker.revoke(); } And then restarting with the new HWND However on restart I get a winrt:hresult_error exception in interop_factory->CreateForWindow

Can this be made to work?

robmikh commented 1 year ago

Yea it should work. Can you share which build of Windows you're trying this on as well as the error code inside the hresult_error object?

rjx-ray commented 1 year ago

I'm running on Windows 11 Pro 22H2 SDK 10.0.19041.685

I'm having trouble getting the error code- this isn't working

image

CreateForWindow doesn't return, I just see

image

Its complicated by the fact that I'm running the capture in a DLL as the main project can't use WinRT. The call stack is

image
robmikh commented 1 year ago

Usually this happens because the window you're trying to capture is deemed non-capturable by the shell. Is it always the same window? Does it work if you attempt to capture that window first?

Does this sample work for you for successive window captures?

rjx-ray commented 1 year ago

So if I try and capture the second window first I get the exception straight away. I'll investigate the differences between the windows tomorrow.

What could make a window non-capturable?

robmikh commented 1 year ago

The general rule of thumb is anything that shows up in the Alt+Tab view is considered capturable.

rjx-ray commented 1 year ago

Thanks for your help. I can now do the successive captures. But its pretty slow, averaging ~10fps and I'm having to wait up to 100ms for the new frame. I guess that's to be expected. Is it possible to run multiple simultaneous capture instances?

robmikh commented 1 year ago

I'm a little surprised you're seeing that kind of performance. What hardware are you running on?

Yes, you should be able to run more than one capture at once. There is a bug in Windows 10 when running multiple captures from the same GraphicsCaptureItem object though.

rjx-ray commented 10 months ago

Just to say that our main app can now use WinRT and I don't need to run the capture in a DLL any more. All these issues have now gone away and I can do multiple simultaneous captures at full speed