From 02328b82ffb90242f5afefac5a774e3a07b0943f Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 10 Mar 2017 14:28:04 +0100 Subject: [PATCH] ATV modulator: added camera devices scan and selector in the GUI --- plugins/channeltx/modatv/atvmod.cpp | 25 +++++++++++++++ plugins/channeltx/modatv/atvmod.h | 18 +++++++++++ plugins/channeltx/modatv/atvmodgui.cpp | 7 +++++ plugins/channeltx/modatv/atvmodgui.ui | 42 +++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/plugins/channeltx/modatv/atvmod.cpp b/plugins/channeltx/modatv/atvmod.cpp index 2c20413ee..b062ce50f 100644 --- a/plugins/channeltx/modatv/atvmod.cpp +++ b/plugins/channeltx/modatv/atvmod.cpp @@ -49,6 +49,7 @@ ATVMod::ATVMod() : m_videoOK(false) { setObjectName("ATVMod"); + scanCameras(); m_config.m_outputSampleRate = 1000000; m_config.m_inputFrequencyOffset = 0; @@ -69,6 +70,7 @@ ATVMod::ATVMod() : ATVMod::~ATVMod() { if (m_video.isOpened()) m_video.release(); + releaseCameras(); } void ATVMod::configure(MessageQueue* messageQueue, @@ -567,4 +569,27 @@ void ATVMod::seekVideoFileStream(int seekPercentage) } } +void ATVMod::scanCameras() +{ + for (int i = 0; i < 4; i++) + { + ATVCamera newCamera; + m_cameras.push_back(newCamera); + m_cameras.back().m_cameraNumber = i; + m_cameras.back().m_camera.open(i); + + if (!m_cameras.back().m_camera.isOpened()) + { + m_cameras.pop_back(); + } + } +} + +void ATVMod::releaseCameras() +{ + for (std::vector::iterator it = m_cameras.begin(); it != m_cameras.end(); ++it) + { + if (it->m_camera.isOpened()) it->m_camera.release(); + } +} diff --git a/plugins/channeltx/modatv/atvmod.h b/plugins/channeltx/modatv/atvmod.h index 733bc0c2f..0e98cb86e 100644 --- a/plugins/channeltx/modatv/atvmod.h +++ b/plugins/channeltx/modatv/atvmod.h @@ -20,6 +20,8 @@ #include #include +#include + #include #include @@ -59,6 +61,12 @@ public: ATVModulationFM } ATVModulation; + typedef struct + { + cv::VideoCapture m_camera; + int m_cameraNumber; + } ATVCamera; + class MsgConfigureImageFileName : public Message { MESSAGE_CLASS_DECLARATION @@ -206,6 +214,12 @@ public: Real getMagSq() const { return m_movingAverage.average(); } + void getCameraNumbers(std::vector& numbers) { + for (std::vector::iterator it = m_cameras.begin(); it != m_cameras.end(); ++it) { + numbers.push_back(it->m_cameraNumber); + } + } + static int getSampleRateUnits(ATVStd std); signals: @@ -361,6 +375,8 @@ private: bool m_videoEOF; //!< current video has reached end of file bool m_videoOK; + std::vector m_cameras; //!< vector of available cameras + static const float m_blackLevel; static const float m_spanLevel; static const int m_levelNbSamples; @@ -378,6 +394,8 @@ private: void calculateVideoSizes(); void resizeVideo(); void seekVideoFileStream(int seekPercentage); + void scanCameras(); + void releaseCameras(); inline void pullImageLine(Real& sample) { diff --git a/plugins/channeltx/modatv/atvmodgui.cpp b/plugins/channeltx/modatv/atvmodgui.cpp index b88601d88..a3cff2652 100644 --- a/plugins/channeltx/modatv/atvmodgui.cpp +++ b/plugins/channeltx/modatv/atvmodgui.cpp @@ -356,6 +356,13 @@ ATVModGUI::ATVModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa connect(m_atvMod->getOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); connect(m_atvMod, SIGNAL(levelChanged(qreal, qreal, int)), ui->volumeMeter, SLOT(levelChanged(qreal, qreal, int))); + + std::vector cameraNumbers; + m_atvMod->getCameraNumbers(cameraNumbers); + + for (std::vector::iterator it = cameraNumbers.begin(); it != cameraNumbers.end(); ++it) { + ui->camSelect->addItem(tr("%1").arg(*it)); + } } ATVModGUI::~ATVModGUI() diff --git a/plugins/channeltx/modatv/atvmodgui.ui b/plugins/channeltx/modatv/atvmodgui.ui index 5f9bd5979..335b8ce54 100644 --- a/plugins/channeltx/modatv/atvmodgui.ui +++ b/plugins/channeltx/modatv/atvmodgui.ui @@ -7,7 +7,7 @@ 0 0 342 - 366 + 364 @@ -284,6 +284,12 @@ 0 + + + 0 + 32 + + video signal level in % of 0:1 range @@ -639,6 +645,40 @@ + + + + Qt::Horizontal + + + + + + + + + Cam + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + +