diff options
Diffstat (limited to 'video-ps3eye')
-rw-r--r-- | video-ps3eye/CMakeLists.txt | 4 | ||||
-rw-r--r-- | video-ps3eye/dialog.ui | 14 | ||||
-rw-r--r-- | video-ps3eye/lang/de_DE.ts | 38 | ||||
-rw-r--r-- | video-ps3eye/lang/nl_NL.ts | 17 | ||||
-rw-r--r-- | video-ps3eye/lang/ru_RU.ts | 17 | ||||
-rw-r--r-- | video-ps3eye/lang/stub.ts | 15 | ||||
-rw-r--r-- | video-ps3eye/lang/zh_CN.ts | 21 | ||||
-rw-r--r-- | video-ps3eye/module.cpp | 42 | ||||
-rw-r--r-- | video-ps3eye/module.hpp | 9 | ||||
m--------- | video-ps3eye/ps3eye-driver | 0 | ||||
-rw-r--r-- | video-ps3eye/shm-layout.hpp | 16 | ||||
-rw-r--r-- | video-ps3eye/wrapper.cxx | 9 |
12 files changed, 169 insertions, 33 deletions
diff --git a/video-ps3eye/CMakeLists.txt b/video-ps3eye/CMakeLists.txt index 2f0bf50b..1f1780f9 100644 --- a/video-ps3eye/CMakeLists.txt +++ b/video-ps3eye/CMakeLists.txt @@ -57,6 +57,10 @@ if(TARGET ps3eye-subprocess) if(EXISTS "${path}") otr_install_lib("${path}" "${opentrack-libexec}") endif() + set(vcrun "${SDK_LIBUSB}/vcruntime140.dll") + if(EXISTS "${vcrun}") + otr_install_lib("${vcrun}" "${opentrack-libexec}") + endif() endif() endif() diff --git a/video-ps3eye/dialog.ui b/video-ps3eye/dialog.ui index 1e94ce74..68060eb9 100644 --- a/video-ps3eye/dialog.ui +++ b/video-ps3eye/dialog.ui @@ -10,7 +10,7 @@ <x>0</x> <y>0</y> <width>439</width> - <height>211</height> + <height>124</height> </rect> </property> <property name="minimumSize"> @@ -31,6 +31,12 @@ <layout class="QGridLayout" name="gridLayout"> <item row="0" column="2"> <widget class="QSpinBox" name="exposure_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="readOnly"> <bool>true</bool> </property> @@ -64,8 +70,8 @@ <item row="0" column="1"> <widget class="QSlider" name="exposure_slider"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>1</horstretch> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> @@ -87,7 +93,7 @@ <item row="1" column="1"> <widget class="QSlider" name="gain_slider"> <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> diff --git a/video-ps3eye/lang/de_DE.ts b/video-ps3eye/lang/de_DE.ts new file mode 100644 index 00000000..f6281358 --- /dev/null +++ b/video-ps3eye/lang/de_DE.ts @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="de_DE"> +<context> + <name>Dialog</name> + <message> + <source>PS3 Eye</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Camera settings</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Exposure</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Gain</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>dialog</name> + <message> + <source>Unknown error</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Can't open camera</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>PS3 Eye driver error: %1</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/video-ps3eye/lang/nl_NL.ts b/video-ps3eye/lang/nl_NL.ts index c98370ec..f3a16fd4 100644 --- a/video-ps3eye/lang/nl_NL.ts +++ b/video-ps3eye/lang/nl_NL.ts @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> -<TS version="2.1"> +<TS version="2.1" language="nl_NL"> <context> <name>Dialog</name> <message> @@ -20,4 +20,19 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>dialog</name> + <message> + <source>Can't open camera</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>PS3 Eye driver error: %1</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Unknown error</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/ru_RU.ts b/video-ps3eye/lang/ru_RU.ts index c98370ec..1edcf50d 100644 --- a/video-ps3eye/lang/ru_RU.ts +++ b/video-ps3eye/lang/ru_RU.ts @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> -<TS version="2.1"> +<TS version="2.1" language="ru_RU"> <context> <name>Dialog</name> <message> @@ -20,4 +20,19 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>dialog</name> + <message> + <source>Can't open camera</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>PS3 Eye driver error: %1</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Unknown error</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/stub.ts b/video-ps3eye/lang/stub.ts index c98370ec..81ffc826 100644 --- a/video-ps3eye/lang/stub.ts +++ b/video-ps3eye/lang/stub.ts @@ -20,4 +20,19 @@ <translation type="unfinished"></translation> </message> </context> +<context> + <name>dialog</name> + <message> + <source>Can't open camera</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>PS3 Eye driver error: %1</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Unknown error</source> + <translation type="unfinished"></translation> + </message> +</context> </TS> diff --git a/video-ps3eye/lang/zh_CN.ts b/video-ps3eye/lang/zh_CN.ts index c98370ec..9650c966 100644 --- a/video-ps3eye/lang/zh_CN.ts +++ b/video-ps3eye/lang/zh_CN.ts @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> -<TS version="2.1"> +<TS version="2.1" language="zh_CN"> <context> <name>Dialog</name> <message> @@ -9,14 +9,29 @@ </message> <message> <source>Camera settings</source> - <translation type="unfinished"></translation> + <translation>相机设置</translation> </message> <message> <source>Exposure</source> - <translation type="unfinished"></translation> + <translation>曝光</translation> </message> <message> <source>Gain</source> + <translation>增益</translation> + </message> +</context> +<context> + <name>dialog</name> + <message> + <source>Can't open camera</source> + <translation>无法打开相机</translation> + </message> + <message> + <source>PS3 Eye driver error: %1</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Unknown error</source> <translation type="unfinished"></translation> </message> </context> diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index a7078180..02543082 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -92,7 +92,11 @@ std::unique_ptr<camera> ps3eye_camera_::make_camera(const QString& name) static bool show_dialog_() { - (new dialog)->show(); + auto& dlg = *new dialog; + dlg.setWindowFlag(Qt::MSWindowsFixedSizeDialogHint); + dlg.setAttribute(Qt::WA_DeleteOnClose); + dlg.adjustSize(); dlg.setFixedSize(dlg.size()); + dlg.show(); return true; } @@ -116,6 +120,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 +138,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(1000); + if (wrapper.state() != QProcess::NotRunning) wrapper.kill(); wrapper.waitForFinished(1000); @@ -143,6 +154,8 @@ bool ps3eye_camera::start(info& args) if (!shm.success()) return false; + stop(); + volatile auto& ptr = *(ps3eye::shm*)shm.ptr(); QString error; @@ -150,7 +163,7 @@ bool ps3eye_camera::start(info& args) open = false; fr = {}; - fr.channels = 3; + fr.channels = args.num_channels == 1 ? 1 : 3; fr.channel_size = 1; if (!args.width || args.width > 320) @@ -168,12 +181,13 @@ bool ps3eye_camera::start(info& args) ptr.in.framerate = (uint8_t)std::clamp(args.fps, 30, 187); ptr.in.gain = (uint8_t)s.gain; ptr.in.exposure = (uint8_t)s.exposure; + ptr.in.channels = args.num_channels == 1 ? 1 : 3; - 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(); - constexpr int sleep_ms = 10, max_sleeps = 5000/sleep_ms; + constexpr int sleep_ms = 10, max_sleeps = 2000/sleep_ms; for (int i = 0; i < max_sleeps; i++) { @@ -183,13 +197,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 +261,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 diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp index 56ffe5df..f6934d70 100644 --- a/video-ps3eye/module.hpp +++ b/video-ps3eye/module.hpp @@ -4,12 +4,13 @@ #include "shm-layout.hpp" #include "compat/shm.h" #include "options/options.hpp" -#include "compat/macros1.h" +#include "compat/macros.h" #include "compat/timer.hpp" #include "ui_dialog.h" #include <QDialog> #include <QProcess> +#include <QTimer> using namespace options; @@ -34,6 +35,7 @@ class dialog final : public QWidget Q_OBJECT Ui_Dialog ui; settings s; + QTimer t{this}; shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; @@ -41,10 +43,11 @@ class dialog final : public QWidget void do_cancel() { s.b->reload(); close(); deleteLater(); } protected: - void closeEvent(QCloseEvent*) override { do_cancel(); } + void closeEvent(QCloseEvent*) override { do_cancel(); if (t.isActive()) { s.set_exposure(); s.set_gain(); } } public: explicit dialog(QWidget* parent = nullptr); + static void show_open_failure_msgbox(const QString& error); }; struct ps3eye_camera final : video::impl::camera @@ -54,7 +57,7 @@ struct ps3eye_camera final : video::impl::camera settings s; frame fr; Timer t; - unsigned char data[640 * 480 * 3] = {}; + unsigned char data[640 * 480 * ps3eye::num_channels] = {}; int framerate = 30, sleep_ms = 1; bool open = false; unsigned timecode = 0; diff --git a/video-ps3eye/ps3eye-driver b/video-ps3eye/ps3eye-driver -Subproject ac056aa85dca83be3b1a14df7b20fd07104e052 +Subproject fe4eef71669bc6365a651b3c734ebd2bb5f57f8 diff --git a/video-ps3eye/shm-layout.hpp b/video-ps3eye/shm-layout.hpp index 577021b9..65b0a4f1 100644 --- a/video-ps3eye/shm-layout.hpp +++ b/video-ps3eye/shm-layout.hpp @@ -3,11 +3,13 @@ namespace ps3eye { +static constexpr unsigned num_channels = 3; + struct shm_in { enum class mode : uint8_t { qvga, vga, }; uint32_t settings_updated; - uint8_t framerate; + uint8_t framerate, channels; mode resolution; //uint8_t sharpness, contrast, brightness hue, saturation; uint8_t gain, exposure, auto_gain, test_pattern; @@ -23,18 +25,14 @@ struct shm_out status status_; char error_string[256]; union { - uint8_t data_320x240[320][240][3]; - uint8_t data_640x480[640][480][3]; + uint8_t data_320x240[320][240][num_channels]; + uint8_t data_640x480[640][480][num_channels]; }; }; -struct shm { - static constexpr unsigned _cacheline_len = 64; - static constexpr unsigned _padding_len = - (_cacheline_len - (sizeof(shm_in) & (_cacheline_len - 1))) & (_cacheline_len - 1); - +struct alignas(64) shm { shm_out out; - const char* _padding[_padding_len]; + [[maybe_unused]] const char _padding[128 - sizeof(shm_out) % 128]; // NOLINT shm_in in; }; diff --git a/video-ps3eye/wrapper.cxx b/video-ps3eye/wrapper.cxx index eca8968d..b7f58185 100644 --- a/video-ps3eye/wrapper.cxx +++ b/video-ps3eye/wrapper.cxx @@ -52,6 +52,7 @@ int main(int argc, char** argv) volatile auto& ptr_ = *(ps3eye::shm*)mem_.ptr(); volatile auto& in = ptr_.in; volatile auto& out = ptr_.out; + int num_channels = in.channels; auto cameras = ps3eye::list_devices(); @@ -61,16 +62,18 @@ int main(int argc, char** argv) error(out, "no camera found"); auto& camera = cameras[0]; - camera->set_debug(false); + camera->set_debug(true); auto* frame = (uint8_t*)out.data_640x480; decltype(out.timecode) timecode = 0; + auto fmt = num_channels == 1 ? ps3eye::format::Gray : ps3eye::format::BGR; + { int framerate = in.framerate; if (framerate <= 0) framerate = 60; - if (!camera->init(get_mode(in.resolution), framerate)) + if (!camera->init(get_mode(in.resolution), framerate, fmt)) error(out, "camera init failed: %s", camera->error_string()); update_settings(*camera, in); @@ -94,7 +97,7 @@ int main(int argc, char** argv) int framerate = in.framerate; if (framerate <= 0) framerate = 60; - if (!camera->init(get_mode(in.resolution), framerate)) + if (!camera->init(get_mode(in.resolution), framerate, fmt)) error(out, "camera init failed: %s", camera->error_string()); if (!camera->start()) error(out, "can't start camera: %s", camera->error_string()); |