mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-08-08 19:56:14 +00:00
only use platf timer
This commit is contained in:
parent
623c6b7a77
commit
91f8dd54bf
11
src/main.cpp
11
src/main.cpp
@ -219,6 +219,7 @@ main(int argc, char *argv[]) {
|
||||
auto mail = std::make_shared<safe::mail_raw_t>();
|
||||
|
||||
auto pull = [process_shutdown_event,queue,mail](){
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
auto local_shutdown= mail->event<bool>(mail::shutdown);
|
||||
auto bitrate = mail->event<int>(mail::bitrate);
|
||||
auto framerate = mail->event<int>(mail::framerate);
|
||||
@ -229,7 +230,7 @@ main(int argc, char *argv[]) {
|
||||
char buffer[512] = {0};
|
||||
while (!process_shutdown_event->peek() && !local_shutdown->peek()) {
|
||||
while (expected_index == queue->outindex)
|
||||
std::this_thread::sleep_for(1ms);
|
||||
timer->sleep_for(1ms);
|
||||
|
||||
memcpy(buffer,
|
||||
queue->outcoming[expected_index].data,
|
||||
@ -341,12 +342,13 @@ main(int argc, char *argv[]) {
|
||||
};
|
||||
|
||||
auto touch_fun = [mail,process_shutdown_event](Queue* queue){
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
auto local_shutdown= mail->event<bool>(mail::shutdown);
|
||||
auto touch_port = mail->event<input::touch_port_t>(mail::touch_port);
|
||||
|
||||
while (!process_shutdown_event->peek() && !local_shutdown->peek()) {
|
||||
if(!touch_port->peek()) {
|
||||
std::this_thread::sleep_for(100ms);
|
||||
timer->sleep_for(100ms);
|
||||
} else {
|
||||
auto touch = touch_port->pop();
|
||||
if (touch.has_value()) {
|
||||
@ -386,13 +388,14 @@ main(int argc, char *argv[]) {
|
||||
forward.detach();
|
||||
}
|
||||
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
auto local_shutdown= mail->event<bool>(mail::shutdown);
|
||||
while (!process_shutdown_event->peek() && !local_shutdown->peek())
|
||||
std::this_thread::sleep_for(100ms);
|
||||
timer->sleep_for(100ms);
|
||||
|
||||
BOOST_LOG(info) << "Closed";
|
||||
// let other threads to close
|
||||
std::this_thread::sleep_for(1s);
|
||||
timer->sleep_for(1s);
|
||||
task_pool.stop();
|
||||
task_pool.join();
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ namespace platf::dxgi {
|
||||
int
|
||||
duplication_t::init(display_base_t *display, const ::video::config_t &config) {
|
||||
HRESULT status;
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
|
||||
// Capture format will be determined from the first call to AcquireNextFrame()
|
||||
display->capture_format = DXGI_FORMAT_UNKNOWN;
|
||||
@ -56,7 +57,7 @@ namespace platf::dxgi {
|
||||
if (SUCCEEDED(status)) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(200ms);
|
||||
timer->sleep_for(200ms);
|
||||
}
|
||||
|
||||
// We don't retry with DuplicateOutput() because we can hit this codepath when we're racing
|
||||
@ -85,7 +86,7 @@ namespace platf::dxgi {
|
||||
if (SUCCEEDED(status)) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(200ms);
|
||||
timer->sleep_for(200ms);
|
||||
}
|
||||
|
||||
if (FAILED(status)) {
|
||||
@ -224,7 +225,7 @@ namespace platf::dxgi {
|
||||
// To avoid starving the encoding thread, sleep without the lock held for a little
|
||||
// while each time we reach our max frame timeout. This will only happen when nothing
|
||||
// is updating the display, so no visible stutter should be introduced by the sleep.
|
||||
std::this_thread::sleep_for(10ms);
|
||||
timer->sleep_for(10ms);
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,6 +326,8 @@ namespace platf::dxgi {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
|
||||
// Check if we can use the Desktop Duplication API on this output
|
||||
for (int x = 0; x < 2; ++x) {
|
||||
dup_t dup;
|
||||
@ -347,7 +350,7 @@ namespace platf::dxgi {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
std::this_thread::sleep_for(200ms);
|
||||
timer->sleep_for(200ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -896,6 +896,7 @@ namespace video {
|
||||
void
|
||||
reset_display(std::shared_ptr<platf::display_t> &disp, const platf::mem_type_e &type, const std::string &display_name, config_t *config) {
|
||||
// We try this twice, in case we still get an error on reinitialization
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
for (int x = 0; x < 2; ++x) {
|
||||
disp.reset();
|
||||
disp = platf::display(type, display_name, *config);
|
||||
@ -906,7 +907,7 @@ namespace video {
|
||||
}
|
||||
|
||||
// The capture code depends on us to sleep between failures
|
||||
std::this_thread::sleep_for(200ms);
|
||||
timer->sleep_for(200ms);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1057,6 +1058,7 @@ namespace video {
|
||||
}
|
||||
};
|
||||
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
auto pull_free_image_callback = [&](std::shared_ptr<platf::img_t> &img_out) -> bool {
|
||||
img_out.reset();
|
||||
while (capture_ctx_queue->running()) {
|
||||
@ -1096,7 +1098,7 @@ namespace video {
|
||||
}
|
||||
else {
|
||||
// sleep and retry if image pool is full
|
||||
std::this_thread::sleep_for(1ms);
|
||||
timer->sleep_for(1ms);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -1179,7 +1181,7 @@ namespace video {
|
||||
++capture_ctx;
|
||||
});
|
||||
|
||||
std::this_thread::sleep_for(20ms);
|
||||
timer->sleep_for(20ms);
|
||||
}
|
||||
|
||||
while (capture_ctx_queue->running()) {
|
||||
@ -1845,7 +1847,7 @@ namespace video {
|
||||
SetWaitableTimer(timer, &due_time, 0, nullptr, nullptr, false);
|
||||
WaitForSingleObject(timer, INFINITE);
|
||||
#else
|
||||
std::this_thread::sleep_for(sleep_period * 1ns);
|
||||
timer->sleep_for(sleep_period * 1ns);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -2172,11 +2174,12 @@ namespace video {
|
||||
|
||||
// Encoding takes place on this thread
|
||||
platf::adjust_thread_priority(platf::thread_priority_e::high);
|
||||
auto timer = platf::create_high_precision_timer();
|
||||
|
||||
while (!shutdown_event->peek() && images->running()) {
|
||||
// Wait for the main capture event when the display is being reinitialized
|
||||
if (ref->reinit_event.peek()) {
|
||||
std::this_thread::sleep_for(20ms);
|
||||
timer->sleep_for(20ms);
|
||||
continue;
|
||||
}
|
||||
// Wait for the display to be ready
|
||||
|
||||
Loading…
Reference in New Issue
Block a user