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

Stutterless capture? #38

Open
3DI70R opened this issue Apr 8, 2020 · 2 comments
Open

Stutterless capture? #38

3DI70R opened this issue Apr 8, 2020 · 2 comments
Assignees

Comments

@3DI70R
Copy link

3DI70R commented Apr 8, 2020

Hello

I'm using your library in personal OBS-like project and while overall its working great, i noticed that captured desktop texture stutters and never achieve desktop framerate. Fps are pretty close, but sometimes frame drops occur. If i understand correctly, that because frame grab occur on background thread and copied to unity on demand without any sync.

While experimenting i moved duplication from Duplicator::Start() to Monitor::Render(), and now stuters are gone, since AcquireNextFrame locks thread untill new image is captured
image

I'm not very familiar with native-side things and i don't understand how this dirty hack didn't slowed all things down to a crawl, but it works for me.

I understand that your library prioritizes unity performance over capture performance, but "official" setting for stutterless capture would be nice.

Also, is there any unforeseen consequences in my hack, except frame skips synced to desktop skips?

@3DI70R 3DI70R changed the title 60fps capture? Stutterless capture? Apr 8, 2020
@hecomi hecomi self-assigned this Apr 14, 2020
@hecomi
Copy link
Owner

hecomi commented Apr 14, 2020

Thank you for using uDD! And thank you for providing a good solution to enhance a frame rate. I'll check your code also in my environment and if it doesn't have big problem, I'll add a parameter to executing Duplicate() in the render thread.

@3DI70R
Copy link
Author

3DI70R commented Oct 6, 2020

I'd want to notice you about my new findings.

Well, i've tried to use my "hack" with dual monitor setup, and its problem became very apparent. It worked fine with one monitor just because my unity app is fullscreen transparent window, and it forced desktop to update on every frame. When nothing happens on second monitor, app freezes, just because it waits for new frame from second monitor.

So, i probably found different, and more correct solution.
I always used OBS as reference during stutter detection, and here is OBS implementation of desktop duplicator:
https://github.com/obsproject/obs-studio/blob/master/libobs-d3d11/d3d11-duplicator.cpp (gs_duplicator_update_frame)
It uses no timeouts and releases frame right after its copied to output texture.

I've removed timeout in Duplicate, and called release after Monitor::Render(), and to my surprise, now capture is very smooth, even with multiple monitors. I didn't tested it very much, but no side effects found yet.

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

No branches or pull requests

2 participants