increase buffer size, remove capture sleep

This commit is contained in:
pigeatgarlic 2024-04-21 09:21:32 +07:00
parent a4e41cd230
commit acbf446337
4 changed files with 7 additions and 34 deletions

View File

@ -1,4 +1,4 @@
#define QUEUE_SIZE 32
#define QUEUE_SIZE 128
#ifdef _WIN32
#define PACKET_SIZE 512 * 1024
#else

View File

@ -81,7 +81,7 @@ main(int argc, char *argv[]) {
BOOST_LOG(info) << PROJECT_NAME << " version: " << PROJECT_VER;
#ifdef WIN32
#ifdef _WIN32
// Modify relevant NVIDIA control panel settings if the system has corresponding gpu
if (nvprefs_instance.load()) {
// Restore global settings to the undo file left by improper termination of sunshine.exe
@ -269,7 +269,7 @@ main(int argc, char *argv[]) {
task_pool.stop();
task_pool.join();
#ifdef WIN32
#ifdef _WIN32
// Restore global NVIDIA control panel settings
if (nvprefs_instance.owning_undo_file() && nvprefs_instance.load()) {
nvprefs_instance.restore_global_profile();

View File

@ -99,31 +99,6 @@ namespace platf::dxgi {
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) {
auto adjust_client_frame_rate = [&]() -> DXGI_RATIONAL {
// Adjust capture frame interval when display refresh rate is not integral but very close to requested fps.
if (display_refresh_rate.Denominator > 1) {
DXGI_RATIONAL candidate = display_refresh_rate;
if (client_frame_rate % display_refresh_rate_rounded == 0) {
candidate.Numerator *= client_frame_rate / display_refresh_rate_rounded;
}
else if (display_refresh_rate_rounded % client_frame_rate == 0) {
candidate.Denominator *= display_refresh_rate_rounded / client_frame_rate;
}
double candidate_rate = (double) candidate.Numerator / candidate.Denominator;
// Can only decrease requested fps, otherwise client may start accumulating frames and suffer increased latency.
if (client_frame_rate > candidate_rate && candidate_rate / client_frame_rate > 0.99) {
BOOST_LOG(info) << "Adjusted capture rate to " << candidate_rate << "fps to better match display";
return candidate;
}
}
return { (uint32_t) client_frame_rate, 1 };
};
DXGI_RATIONAL client_frame_rate_adjusted = adjust_client_frame_rate();
std::optional<std::chrono::steady_clock::time_point> frame_pacing_group_start;
uint32_t frame_pacing_group_frames = 0;
// 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,
// worst case it will trigger us to reinit DD, waking the display back up in
@ -133,8 +108,6 @@ namespace platf::dxgi {
SetThreadExecutionState(ES_CONTINUOUS);
});
stat_trackers::min_max_avg_tracker<double> sleep_overshoot_tracker;
while (true) {
// This will return false if the HDR state changes or for any number of other
// display or GPU changes. We should reinit to examine the updated state of
@ -147,8 +120,8 @@ namespace platf::dxgi {
std::shared_ptr<img_t> img_out;
// Start new frame pacing group if necessary, snapshot() is called with non-zero timeout
if (status == capture_e::timeout || (status == capture_e::ok && !frame_pacing_group_start)) {
status = snapshot(pull_free_image_cb, img_out, 200ms, *cursor);
if (status == capture_e::timeout || status == capture_e::ok) {
status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor);
if (status == platf::capture_e::timeout) {
// The D3D11 device is protected by an unfair lock that is held the entire time that

View File

@ -1801,7 +1801,7 @@ namespace video {
}
}
#ifdef WIN32
#ifdef _WIN32
auto timer = CreateWaitableTimerEx(nullptr, nullptr, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
if (!timer)
timer = CreateWaitableTimerEx(nullptr, nullptr, 0, TIMER_ALL_ACCESS);
@ -1860,7 +1860,7 @@ namespace video {
auto sleep_period = std::chrono::nanoseconds(1s).count() / config->framerate - cycle.count();
#ifdef WIN32
#ifdef _WIN32
if(sleep_period > 0) {
LARGE_INTEGER due_time;
due_time.QuadPart = sleep_period / -100;