More accurate capture rate for NvFBC

This commit is contained in:
loki-47-6F-64 2021-09-25 17:46:26 +02:00
parent d7cb71f877
commit 50bd3094b4

View File

@ -393,6 +393,8 @@ public:
} }
} }
delay = std::chrono::nanoseconds { 1s } / framerate;
capture_params = NVFBC_CREATE_CAPTURE_SESSION_PARAMS { NVFBC_CREATE_CAPTURE_SESSION_PARAMS_VER }; capture_params = NVFBC_CREATE_CAPTURE_SESSION_PARAMS { NVFBC_CREATE_CAPTURE_SESSION_PARAMS_VER };
capture_params.eCaptureType = NVFBC_CAPTURE_SHARED_CUDA; capture_params.eCaptureType = NVFBC_CAPTURE_SHARED_CUDA;
@ -426,6 +428,8 @@ public:
} }
platf::capture_e capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr<platf::img_t> img, bool *cursor) override { platf::capture_e capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr<platf::img_t> img, bool *cursor) override {
auto next_frame = std::chrono::steady_clock::now();
// Force display_t::capture to initialize handle_t::capture // Force display_t::capture to initialize handle_t::capture
cursor_visible = !*cursor; cursor_visible = !*cursor;
@ -434,7 +438,17 @@ public:
}); });
while(img) { while(img) {
auto status = snapshot(img.get(), 500ms, *cursor); auto now = std::chrono::steady_clock::now();
if(next_frame > now) {
std::this_thread::sleep_for((next_frame - now) / 3 * 2);
}
while(next_frame > now) {
std::this_thread::sleep_for(1ns);
now = std::chrono::steady_clock::now();
}
next_frame = now + delay;
auto status = snapshot(img.get(), 150ms, *cursor);
switch(status) { switch(status) {
case platf::capture_e::reinit: case platf::capture_e::reinit:
case platf::capture_e::error: case platf::capture_e::error:
@ -552,10 +566,6 @@ public:
return platf::capture_e::error; return platf::capture_e::error;
} }
if(!info.bIsNewFrame) {
return platf::capture_e::timeout;
}
if(((img_t *)img)->tex.copy((std::uint8_t *)device_ptr, img->height, img->row_pitch)) { if(((img_t *)img)->tex.copy((std::uint8_t *)device_ptr, img->height, img->row_pitch)) {
return platf::capture_e::error; return platf::capture_e::error;
} }
@ -590,6 +600,8 @@ public:
return 0; return 0;
} }
std::chrono::nanoseconds delay;
bool cursor_visible; bool cursor_visible;
handle_t handle; handle_t handle;