Add video image settings per camera preset

This commit is contained in:
Gary Talent 2023-07-24 21:46:41 -05:00
parent bc342a290f
commit b119268396
8 changed files with 240 additions and 34 deletions

View File

@ -8,6 +8,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QSettings> #include <QSettings>
#include <string_view>
#include "settingsdata.hpp" #include "settingsdata.hpp"
#include "cameraclient.hpp" #include "cameraclient.hpp"
@ -20,16 +21,93 @@ CameraClient::CameraClient(QObject *parent): QObject(parent) {
} }
void CameraClient::setPreset(int preset) { void CameraClient::setPreset(int preset) {
if (preset > -1) { if (preset > 0 && preset < MaxCameraPresets) {
get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset)); get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset));
--preset;
auto const vc = getVideoConfig()[preset];
qDebug() << preset << vc.brightness;
setBrightness(vc.brightness);
setSaturation(vc.saturation);
setContrast(vc.contrast);
setSharpness(vc.sharpness);
setHue(vc.hue);
} }
} }
void CameraClient::setBrightness(int val) {
if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&bright&%1").arg(val));
}
}
void CameraClient::setSaturation(int val) {
if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&saturation&%1").arg(val));
}
}
void CameraClient::setContrast(int val) {
if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&contrast&%1").arg(val));
}
}
void CameraClient::setSharpness(int val) {
if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&sharpness&%1").arg(val));
}
}
void CameraClient::setHue(int val) {
if (val > -1) {
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&hue&%1").arg(val));
}
}
/*
void CameraClient::getVideoConfig() {
QUrl url(QString(m_baseUrl) + "/cgi-bin/param.cgi?get_image_conf");
QNetworkRequest rqst(url);
auto const reply = m_nam->get(rqst);
connect(reply, &QIODevice::readyRead, this, [this, reply] {processVideoConfig(reply);});
}
*/
void CameraClient::setBaseUrl() { void CameraClient::setBaseUrl() {
auto const [host, port] = getCameraConnectionData(); auto const [host, port] = getCameraConnectionData();
m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port)); m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port));
} }
/*
void CameraClient::processVideoConfig(QNetworkReply *reply) {
auto constexpr brightStart = std::string_view("bright = ");
auto constexpr saturationStart = std::string_view("saturation = ");
auto constexpr contrastStart = std::string_view("contrast = ");
auto constexpr sharpnessStart = std::string_view("sharpness = ");
auto constexpr hueStart = std::string_view("hue = ");
while (!reply->atEnd()) {
auto const line = reply->readLine();
if (line.startsWith(brightStart)) {
m_videoConfig.brightness = QString(line.mid(brightStart.size())).toInt();
} else if (line.startsWith(saturationStart)) {
m_videoConfig.saturation = QString(line.mid(saturationStart.size())).toInt();
} else if (line.startsWith(contrastStart)) {
m_videoConfig.contrast = QString(line.mid(contrastStart.size())).toInt();
} else if (line.startsWith(sharpnessStart)) {
m_videoConfig.sharpness = QString(line.mid(sharpnessStart.size())).toInt();
} else if (line.startsWith(hueStart)) {
m_videoConfig.hue = QString(line.mid(hueStart.size())).toInt();
}
}
qDebug() <<
"brightness:" << m_videoConfig.brightness <<
"saturation:" << m_videoConfig.brightness <<
"contrast:" << m_videoConfig.brightness <<
"sharpness:" << m_videoConfig.brightness <<
"hue:" << m_videoConfig.hue;
}
*/
void CameraClient::get(QString const&urlExt) { void CameraClient::get(QString const&urlExt) {
QUrl url(QString(m_baseUrl) + urlExt); QUrl url(QString(m_baseUrl) + urlExt);
QNetworkRequest rqst(url); QNetworkRequest rqst(url);

View File

@ -27,10 +27,22 @@ class CameraClient: public QObject {
void setPreset(int preset); void setPreset(int preset);
void setBrightness(int val);
void setSaturation(int val);
void setContrast(int val);
void setSharpness(int val);
void setHue(int val);
public slots: public slots:
void setBaseUrl(); void setBaseUrl();
private: private:
void processVideoConfig(QNetworkReply*);
void get(QString const&url); void get(QString const&url);
void poll(); void poll();

View File

@ -113,7 +113,7 @@ void MainWindow::setupMenu() {
// camera preset menu // camera preset menu
{ {
auto const menu = menuBar()->addMenu(tr("&Camera Preset")); auto const menu = menuBar()->addMenu(tr("&Camera Preset"));
for (auto i = 0; i < MaxCameraPresets; ++i) { for (auto i = 0; i < std::min(9, MaxCameraPresets); ++i) {
auto const cameraPresetAct = new QAction(tr("Camera Preset &%1").arg(i + 1), this); auto const cameraPresetAct = new QAction(tr("Camera Preset &%1").arg(i + 1), this);
cameraPresetAct->setShortcut(Qt::ALT | static_cast<Qt::Key>(Qt::Key_1 + i)); cameraPresetAct->setShortcut(Qt::ALT | static_cast<Qt::Key>(Qt::Key_1 + i));
connect(cameraPresetAct, &QAction::triggered, &m_cameraClient, [this, i] { connect(cameraPresetAct, &QAction::triggered, &m_cameraClient, [this, i] {
@ -141,27 +141,7 @@ Built on Qt library under LGPL 2.0)").arg(__DATE__));
} }
} }
void MainWindow::setupDefaultViewControls(QGridLayout *viewCtlLyt) { void MainWindow::setupViewControlButtons(QVector<View> const&views, QGridLayout *viewCtlLyt) {
auto const mainWidget = viewCtlLyt->parentWidget();
auto const btnHideSlides = new QPushButton(tr("1. Hide"), mainWidget);
auto const btnOpenLpShowSlides = new QPushButton(tr("2. Show in OpenLP Only"), mainWidget);
auto const btnShowSlides = new QPushButton(tr("3. Show"), mainWidget);
viewCtlLyt->addWidget(btnHideSlides, 0, 0);
viewCtlLyt->addWidget(btnOpenLpShowSlides, 0, 1);
viewCtlLyt->addWidget(btnShowSlides, 0, 2);
btnHideSlides->setShortcut(Qt::Key_1);
btnOpenLpShowSlides->setShortcut(Qt::Key_2);
btnHideSlides->setToolTip(tr("Also hides slides in OBS"));
btnShowSlides->setShortcut(Qt::Key_3);
connect(btnHideSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::blankScreen);
connect(btnHideSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides);
connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides);
connect(btnShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::showSlides);
connect(btnShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
}
void MainWindow::setupCustomViewControls(QVector<View> const&views, QGridLayout *viewCtlLyt) {
constexpr auto columns = 3; constexpr auto columns = 3;
auto const parent = viewCtlLyt->parentWidget(); auto const parent = viewCtlLyt->parentWidget();
for (auto i = 0; auto const&view : views) { for (auto i = 0; auto const&view : views) {
@ -203,8 +183,8 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) {
.obsSlides = false, .obsSlides = false,
}); });
views.emplace_back(View{ views.emplace_back(View{
.name = tr("Hide in OBS"), .name = tr("Show in OpenLP Only"),
.slides = false, .slides = true,
.obsSlides = false, .obsSlides = false,
}); });
views.emplace_back(View{ views.emplace_back(View{
@ -213,11 +193,7 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) {
.obsSlides = false, .obsSlides = false,
}); });
} }
if (views.empty()) { setupViewControlButtons(views, viewCtlLyt);
setupDefaultViewControls(viewCtlLyt);
} else {
setupCustomViewControls(views, viewCtlLyt);
}
} }
void MainWindow::openSettings() { void MainWindow::openSettings() {

View File

@ -40,9 +40,7 @@ class MainWindow: public QMainWindow {
private: private:
void setupMenu(); void setupMenu();
void setupDefaultViewControls(class QGridLayout *rootLyt); void setupViewControlButtons(QVector<View> const&views, class QGridLayout *rootLyt);
void setupCustomViewControls(QVector<View> const&views, class QGridLayout *rootLyt);
void setupViewControls(class QVBoxLayout *rootLyt); void setupViewControls(class QVBoxLayout *rootLyt);

View File

@ -8,8 +8,54 @@
#include <QSettings> #include <QSettings>
#include "consts.hpp"
#include "settingsdata.hpp" #include "settingsdata.hpp"
void setVideoConfig(QSettings &settings, QVector<VideoConfig> const&vcList) {
settings.beginGroup("Camera");
settings.beginWriteArray("VideoImageConfig");
for (auto i = 0; auto const&vc : vcList) {
settings.setArrayIndex(i);
settings.setValue("brightness", vc.brightness);
settings.setValue("saturation", vc.saturation);
settings.setValue("contrast", vc.contrast);
settings.setValue("sharpness", vc.sharpness);
settings.setValue("hue", vc.hue);
++i;
}
settings.endArray();
settings.endGroup();
}
void setVideoConfig(QVector<VideoConfig> const&vcList) {
QSettings s;
setVideoConfig(s, vcList);
}
QVector<VideoConfig> getVideoConfig(QSettings &settings) {
QVector<VideoConfig> vc(MaxCameraPresets);
settings.beginGroup("Camera");
auto const size = std::min(settings.beginReadArray("VideoImageConfig"), MaxCameraPresets);
for (auto i = 0; i < size; ++i) {
settings.setArrayIndex(i);
vc[i] = {
.brightness = settings.value("brightness").toInt(),
.saturation = settings.value("saturation").toInt(),
.contrast = settings.value("contrast").toInt(),
.sharpness = settings.value("sharpness").toInt(),
.hue = settings.value("hue").toInt(),
};
}
settings.endArray();
settings.endGroup();
return vc;
}
QVector<VideoConfig> getVideoConfig() {
QSettings s;
return getVideoConfig(s);
}
void setCameraConnectionData(QSettings &settings, ConnectionData const&cd) { void setCameraConnectionData(QSettings &settings, ConnectionData const&cd) {
settings.beginGroup("CameraClient"); settings.beginGroup("CameraClient");
settings.setValue("Host", cd.host); settings.setValue("Host", cd.host);

View File

@ -8,9 +8,26 @@
#pragma once #pragma once
#include <QHash>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
struct VideoConfig {
int brightness = 6;
int saturation = 4;
int contrast = 8;
int sharpness = 3;
int hue = 7;
};
void setVideoConfig(class QSettings &settings, QVector<VideoConfig> const&vc);
void setVideoConfig(QVector<VideoConfig> const&vc);
QVector<VideoConfig> getVideoConfig(QSettings &settings);
QVector<VideoConfig> getVideoConfig();
struct ConnectionData { struct ConnectionData {
QString host; QString host;
uint16_t port = 0; uint16_t port = 0;
@ -56,4 +73,4 @@ void setViews(QVector<View> const&views);
QVector<View> getViews(class QSettings &settings); QVector<View> getViews(class QSettings &settings);
[[nodiscard]] [[nodiscard]]
QVector<View> getViews(); QVector<View> getViews();

View File

@ -7,6 +7,7 @@
*/ */
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox>
#include <QFormLayout> #include <QFormLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QIntValidator> #include <QIntValidator>
@ -14,7 +15,9 @@
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
#include <QSettings> #include <QSettings>
#include <QSlider>
#include <QSpacerItem> #include <QSpacerItem>
#include <QSpinBox>
#include <QTabWidget> #include <QTabWidget>
#include <QTableWidget> #include <QTableWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -34,6 +37,7 @@ SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent) {
auto const lyt = new QVBoxLayout(this); auto const lyt = new QVBoxLayout(this);
auto const tabs = new QTabWidget(this); auto const tabs = new QTabWidget(this);
lyt->addWidget(tabs); lyt->addWidget(tabs);
tabs->addTab(setupImageConfig(tabs), tr("&Image"));
tabs->addTab(setupViewConfig(tabs), tr("&Views")); tabs->addTab(setupViewConfig(tabs), tr("&Views"));
tabs->addTab(setupNetworkInputs(tabs), tr("&Network")); tabs->addTab(setupNetworkInputs(tabs), tr("&Network"));
lyt->addWidget(setupButtons(this)); lyt->addWidget(setupButtons(this));
@ -81,6 +85,32 @@ QWidget *SettingsDialog::setupNetworkInputs(QWidget *parent) {
return root; return root;
} }
QWidget *SettingsDialog::setupImageConfig(QWidget *parent) {
auto const root = new QWidget(parent);
auto const lyt = new QFormLayout(root);
m_videoConfig = getVideoConfig();
auto const mkSb = [parent, lyt](QString lbl) {
auto const s = new QSpinBox(parent);
s->setAlignment(Qt::AlignRight);
s->setRange(0, 14);
lyt->addRow(lbl, s);
return s;
};
auto const presetNo = new QComboBox(parent);
connect(presetNo, &QComboBox::currentIndexChanged, this, &SettingsDialog::updateVidConfigPreset);
for (auto i = 0; i < MaxCameraPresets; ++i) {
presetNo->addItem(tr("Camera Preset %1").arg(i + 1));
}
lyt->addRow(presetNo);
m_vidBrightness = mkSb(tr("&Brightness:"));
m_vidSaturation = mkSb(tr("&Saturation:"));
m_vidContrast = mkSb(tr("C&ontrast:"));
m_vidSharpness = mkSb(tr("Sh&arpness:"));
m_vidHue = mkSb(tr("&Hue:"));
updateVidConfigPreset(0);
return root;
}
QWidget *SettingsDialog::setupViewConfig(QWidget *parent) { QWidget *SettingsDialog::setupViewConfig(QWidget *parent) {
auto const root = new QWidget(parent); auto const root = new QWidget(parent);
auto const lyt = new QVBoxLayout(root); auto const lyt = new QVBoxLayout(root);
@ -177,6 +207,8 @@ void SettingsDialog::handleOK() {
.host = m_obsHostLe->text(), .host = m_obsHostLe->text(),
.port = m_obsPortLe->text().toUShort(), .port = m_obsPortLe->text().toUShort(),
}); });
collectVideoConfig();
setVideoConfig(settings, m_videoConfig);
accept(); accept();
} }
@ -220,3 +252,38 @@ int SettingsDialog::collectViews(QVector<View> &views) const {
} }
return 0; return 0;
} }
void SettingsDialog::collectVideoConfig() {
auto &vc = m_videoConfig[m_vidCurrentPreset];
auto constexpr getVal = [](int &val, QSpinBox *src) {
if (src) {
val = src->value();
}
};
getVal(vc.brightness, m_vidBrightness);
getVal(vc.saturation, m_vidSaturation);
getVal(vc.contrast, m_vidContrast);
getVal(vc.sharpness, m_vidSharpness);
getVal(vc.hue, m_vidHue);
}
void SettingsDialog::updateVidConfigPreset(int preset) {
// update to new value
auto constexpr setVal = [](int val, QSpinBox *dst) {
if (dst) {
dst->setValue(val);
}
};
auto const&vc = m_videoConfig[preset];
setVal(vc.brightness, m_vidBrightness);
setVal(vc.saturation, m_vidSaturation);
setVal(vc.contrast, m_vidContrast);
setVal(vc.sharpness, m_vidSharpness);
setVal(vc.hue, m_vidHue);
m_vidCurrentPreset = preset;
}
void SettingsDialog::updateVidConfigPresetCollect(int preset) {
collectVideoConfig();
updateVidConfigPreset(preset);
}

View File

@ -10,11 +10,13 @@
#include <QDialog> #include <QDialog>
#include "consts.hpp"
#include "settingsdata.hpp" #include "settingsdata.hpp"
class SettingsDialog: public QDialog { class SettingsDialog: public QDialog {
Q_OBJECT Q_OBJECT
private: private:
QVector<VideoConfig> m_videoConfig = QVector<VideoConfig>(MaxCameraPresets);
class QLabel *m_errLbl = nullptr; class QLabel *m_errLbl = nullptr;
class QLineEdit *m_cameraHostLe = nullptr; class QLineEdit *m_cameraHostLe = nullptr;
class QLineEdit *m_cameraPortLe = nullptr; class QLineEdit *m_cameraPortLe = nullptr;
@ -22,12 +24,19 @@ class SettingsDialog: public QDialog {
class QLineEdit *m_openLpPortLe = nullptr; class QLineEdit *m_openLpPortLe = nullptr;
class QLineEdit *m_obsHostLe = nullptr; class QLineEdit *m_obsHostLe = nullptr;
class QLineEdit *m_obsPortLe = nullptr; class QLineEdit *m_obsPortLe = nullptr;
class QSpinBox *m_vidBrightness = nullptr;
class QSpinBox *m_vidSaturation = nullptr;
class QSpinBox *m_vidContrast = nullptr;
class QSpinBox *m_vidSharpness = nullptr;
class QSpinBox *m_vidHue = nullptr;
int m_vidCurrentPreset = 0;
class QTableWidget *m_viewTable = nullptr; class QTableWidget *m_viewTable = nullptr;
public: public:
explicit SettingsDialog(QWidget *parent); explicit SettingsDialog(QWidget *parent);
private: private:
QWidget *setupNetworkInputs(QWidget *parent); QWidget *setupNetworkInputs(QWidget *parent);
QWidget *setupViewConfig(QWidget *parent); QWidget *setupViewConfig(QWidget *parent);
QWidget *setupImageConfig(QWidget *parent);
QWidget *setupButtons(QWidget *parent); QWidget *setupButtons(QWidget *parent);
void handleOK(); void handleOK();
void setupViewRow(int row, View const&view = {}); void setupViewRow(int row, View const&view = {});
@ -37,4 +46,7 @@ class SettingsDialog: public QDialog {
*/ */
[[nodiscard("Must check error code")]] [[nodiscard("Must check error code")]]
int collectViews(QVector<View> &views) const; int collectViews(QVector<View> &views) const;
void collectVideoConfig();
void updateVidConfigPreset(int preset);
void updateVidConfigPresetCollect(int preset);
}; };