Move client frame interval to local variable
This commit is contained in:
@@ -132,14 +132,16 @@ namespace platf::dxgi {
|
|||||||
capture_e
|
capture_e
|
||||||
capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override;
|
capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override;
|
||||||
|
|
||||||
std::chrono::nanoseconds delay;
|
|
||||||
|
|
||||||
factory1_t factory;
|
factory1_t factory;
|
||||||
adapter_t adapter;
|
adapter_t adapter;
|
||||||
output_t output;
|
output_t output;
|
||||||
device_t device;
|
device_t device;
|
||||||
device_ctx_t device_ctx;
|
device_ctx_t device_ctx;
|
||||||
duplication_t dup;
|
duplication_t dup;
|
||||||
|
DXGI_RATIONAL display_refresh_rate;
|
||||||
|
int display_refresh_rate_rounded;
|
||||||
|
|
||||||
|
int client_frame_rate;
|
||||||
|
|
||||||
DXGI_FORMAT capture_format;
|
DXGI_FORMAT capture_format;
|
||||||
D3D_FEATURE_LEVEL feature_level;
|
D3D_FEATURE_LEVEL feature_level;
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ namespace platf::dxgi {
|
|||||||
capture_e
|
capture_e
|
||||||
display_base_t::capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) {
|
display_base_t::capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) {
|
||||||
auto next_frame = std::chrono::steady_clock::now();
|
auto next_frame = std::chrono::steady_clock::now();
|
||||||
|
const auto client_frame_interval = std::chrono::nanoseconds { 1s } / client_frame_rate;
|
||||||
|
|
||||||
// Keep the display awake during capture. If the display goes to sleep during
|
// Keep the display awake during capture. If the display goes to sleep during
|
||||||
// capture, best case is that capture stops until it powers back on. However,
|
// capture, best case is that capture stops until it powers back on. However,
|
||||||
@@ -142,14 +143,14 @@ namespace platf::dxgi {
|
|||||||
auto wait_time = next_frame - std::chrono::steady_clock::now();
|
auto wait_time = next_frame - std::chrono::steady_clock::now();
|
||||||
if (wait_time > 0s && wait_time < 1s) {
|
if (wait_time > 0s && wait_time < 1s) {
|
||||||
high_precision_sleep(wait_time);
|
high_precision_sleep(wait_time);
|
||||||
next_frame += delay;
|
next_frame += client_frame_interval;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If the wait time is negative (meaning the frame is past due) or the
|
// If the wait time is negative (meaning the frame is past due) or the
|
||||||
// computed wait time is beyond a second (meaning possible clock issues),
|
// computed wait time is beyond a second (meaning possible clock issues),
|
||||||
// just capture the frame now and resynchronize the frame interval with
|
// just capture the frame now and resynchronize the frame interval with
|
||||||
// the current time.
|
// the current time.
|
||||||
next_frame = std::chrono::steady_clock::now() + delay;
|
next_frame = std::chrono::steady_clock::now() + client_frame_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<img_t> img_out;
|
std::shared_ptr<img_t> img_out;
|
||||||
@@ -334,8 +335,6 @@ namespace platf::dxgi {
|
|||||||
// Ensure we can duplicate the current display
|
// Ensure we can duplicate the current display
|
||||||
syncThreadDesktop();
|
syncThreadDesktop();
|
||||||
|
|
||||||
delay = std::chrono::nanoseconds { 1s } / config.framerate;
|
|
||||||
|
|
||||||
// Get rectangle of full desktop for absolute mouse coordinates
|
// Get rectangle of full desktop for absolute mouse coordinates
|
||||||
env_width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
env_width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||||
env_height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
env_height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||||
@@ -595,6 +594,13 @@ namespace platf::dxgi {
|
|||||||
BOOST_LOG(info) << "Desktop resolution ["sv << dup_desc.ModeDesc.Width << 'x' << dup_desc.ModeDesc.Height << ']';
|
BOOST_LOG(info) << "Desktop resolution ["sv << dup_desc.ModeDesc.Width << 'x' << dup_desc.ModeDesc.Height << ']';
|
||||||
BOOST_LOG(info) << "Desktop format ["sv << dxgi_format_to_string(dup_desc.ModeDesc.Format) << ']';
|
BOOST_LOG(info) << "Desktop format ["sv << dxgi_format_to_string(dup_desc.ModeDesc.Format) << ']';
|
||||||
|
|
||||||
|
display_refresh_rate = dup_desc.ModeDesc.RefreshRate;
|
||||||
|
display_refresh_rate_rounded = lround((double) display_refresh_rate.Numerator / display_refresh_rate.Denominator);
|
||||||
|
BOOST_LOG(info) << "Display refresh rate [" << display_refresh_rate_rounded << "Hz]";
|
||||||
|
|
||||||
|
client_frame_rate = config.framerate;
|
||||||
|
BOOST_LOG(info) << "Requested frame rate [" << client_frame_rate << "fps]";
|
||||||
|
|
||||||
dxgi::output6_t output6 {};
|
dxgi::output6_t output6 {};
|
||||||
status = output->QueryInterface(IID_IDXGIOutput6, (void **) &output6);
|
status = output->QueryInterface(IID_IDXGIOutput6, (void **) &output6);
|
||||||
if (SUCCEEDED(status)) {
|
if (SUCCEEDED(status)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user