summaryrefslogtreecommitdiffhomepage
path: root/video-ps3eye
diff options
context:
space:
mode:
Diffstat (limited to 'video-ps3eye')
-rw-r--r--video-ps3eye/lang/nl_NL.ts15
-rw-r--r--video-ps3eye/lang/ru_RU.ts15
-rw-r--r--video-ps3eye/lang/stub.ts15
-rw-r--r--video-ps3eye/lang/zh_CN.ts15
-rw-r--r--video-ps3eye/module.cpp31
-rw-r--r--video-ps3eye/module.hpp7
m---------video-ps3eye/ps3eye-driver0
-rw-r--r--video-ps3eye/shm-layout.hpp6
-rw-r--r--video-ps3eye/wrapper.cxx10
9 files changed, 100 insertions, 14 deletions
diff --git a/video-ps3eye/lang/nl_NL.ts b/video-ps3eye/lang/nl_NL.ts
index c98370ec..81ffc826 100644
--- a/video-ps3eye/lang/nl_NL.ts
+++ b/video-ps3eye/lang/nl_NL.ts
@@ -20,4 +20,19 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>dialog</name>
+ <message>
+ <source>Can&apos;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..81ffc826 100644
--- a/video-ps3eye/lang/ru_RU.ts
+++ b/video-ps3eye/lang/ru_RU.ts
@@ -20,4 +20,19 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>dialog</name>
+ <message>
+ <source>Can&apos;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&apos;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..81ffc826 100644
--- a/video-ps3eye/lang/zh_CN.ts
+++ b/video-ps3eye/lang/zh_CN.ts
@@ -20,4 +20,19 @@
<translation type="unfinished"></translation>
</message>
</context>
+<context>
+ <name>dialog</name>
+ <message>
+ <source>Can&apos;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/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
diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp
index 56ffe5df..26cfad60 100644
--- a/video-ps3eye/module.hpp
+++ b/video-ps3eye/module.hpp
@@ -10,6 +10,7 @@
#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 67fa41fd0393076f4d0be3e17ae36a40f83bc0c
diff --git a/video-ps3eye/shm-layout.hpp b/video-ps3eye/shm-layout.hpp
index 577021b9..d7905109 100644
--- a/video-ps3eye/shm-layout.hpp
+++ b/video-ps3eye/shm-layout.hpp
@@ -3,6 +3,8 @@
namespace ps3eye {
+static constexpr unsigned num_channels = 1;
+
struct shm_in {
enum class mode : uint8_t { qvga, vga, };
@@ -23,8 +25,8 @@ 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];
};
};
diff --git a/video-ps3eye/wrapper.cxx b/video-ps3eye/wrapper.cxx
index eca8968d..0f9344eb 100644
--- a/video-ps3eye/wrapper.cxx
+++ b/video-ps3eye/wrapper.cxx
@@ -61,16 +61,20 @@ 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;
+ constexpr auto fmt = ps3eye::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 +98,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());