diff options
Diffstat (limited to 'video-ps3eye/module.cpp')
-rw-r--r-- | video-ps3eye/module.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index a7078180..25d82170 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -116,6 +116,8 @@ ps3eye_camera::ps3eye_camera() wrapper.setWorkingDirectory(library_path); #ifdef _WIN32 wrapper.setProgram("\"ps3eye-subprocess.exe\""); + // workaround apparent Qt 5.15.2 bug -sh 20210817 + wrapper.setProcessChannelMode(QProcess::ForwardedChannels); #else wrapper.setProgram("ps3eye-subprocess"); #endif @@ -132,6 +134,11 @@ void ps3eye_camera::stop() if (wrapper.state() != QProcess::NotRunning) { + volatile auto& ptr = *(ps3eye::shm*)shm.ptr(); + ptr.in.do_exit = 1; + std::atomic_thread_fence(std::memory_order_seq_cst); + wrapper.waitForFinished(5000); + if (wrapper.state() != QProcess::NotRunning) wrapper.kill(); wrapper.waitForFinished(1000); @@ -150,7 +157,7 @@ bool ps3eye_camera::start(info& args) open = false; fr = {}; - fr.channels = 3; + fr.channels = 1; fr.channel_size = 1; if (!args.width || args.width > 320) @@ -169,7 +176,7 @@ bool ps3eye_camera::start(info& args) ptr.in.gain = (uint8_t)s.gain; ptr.in.exposure = (uint8_t)s.exposure; - sleep_ms = std::clamp(int(std::floor(1000./ptr.in.framerate*2)), 1, 10); + sleep_ms = std::clamp(int(std::floor(450./ptr.in.framerate)), 1, 10); wrapper.start(); @@ -183,13 +190,13 @@ bool ps3eye_camera::start(info& args) } if (ptr.out.error_string[0] == '\0') - error = "Unknown error"; + error = QString{}; else error = QString::fromLatin1((const char*)ptr.out.error_string, strnlen((const char*)ptr.out.error_string, sizeof(ptr.out.error_string))); - run_in_thread_async(qApp, [=]() { - QMessageBox::critical(nullptr, "Can't open camera", "PS3 Eye driver error: " + error, QMessageBox::Close); + run_in_thread_async(qApp, [error = std::move(error)] { + dialog::show_open_failure_msgbox(error); }); return false; @@ -247,16 +254,26 @@ OTR_REGISTER_CAMERA(ps3eye_camera_) dialog::dialog(QWidget* parent) : QWidget(parent) { ui.setupUi(this); + t.setInterval(500); t.setSingleShot(true); tie_setting(s.exposure, ui.exposure_slider); tie_setting(s.gain, ui.gain_slider); ui.exposure_label->setValue((int)*s.exposure); ui.gain_label->setValue((int)*s.gain); - connect(&s.exposure, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_exposure(); }); - connect(&s.gain, value_::value_changed<slider_value>(), this, [this](const slider_value&) { s.set_gain(); }); + connect(&s.exposure, value_::value_changed<slider_value>(), this, [this](const slider_value&) { t.stop(); t.start(); }); + connect(&s.gain, value_::value_changed<slider_value>(), this, [this](const slider_value&) { t.stop(); t.start(); }); connect(ui.exposure_slider, &QSlider::valueChanged, ui.exposure_label, &QSpinBox::setValue); connect(ui.gain_slider, &QSlider::valueChanged, ui.gain_label, &QSpinBox::setValue); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &dialog::do_ok); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &dialog::do_cancel); + connect(&t, &QTimer::timeout, this, [this] { s.set_exposure(); s.set_gain(); }); +} +void dialog::show_open_failure_msgbox(const QString& error) +{ + const QString& error_ = error.isNull() ? tr("Unknown error") : error; + QMessageBox::critical(nullptr, + tr("Can't open camera"), + tr("PS3 Eye driver error: %1").arg(error_), + QMessageBox::Close); } // XXX copypasta -sh 20200329 |