made camera/audio only active when config panel is shown

This commit is contained in:
csoler 2021-05-12 23:05:15 +02:00
parent c4fbd3a4f5
commit d7ecd775eb
3 changed files with 132 additions and 133 deletions

View File

@ -22,7 +22,7 @@
#pragma once
#include "AudioStats.h"
#include "AudioInputConfig.h"
#include "VOIPConfigPanel.h"
#include "audiodevicehelper.h"
#include "AudioWizard.h"
#include "gui/VideoProcessor.h"
@ -95,10 +95,41 @@ VOIPConfigPanel::VOIPConfigPanel(QWidget * parent, Qt::WindowFlags flags)
abSpeech = NULL;
qtTick = NULL;
ui.qcbTransmit->addItem(tr("Continuous"), RsVOIP::AudioTransmitContinous);
ui.qcbTransmit->addItem(tr("Voice Activity"), RsVOIP::AudioTransmitVAD);
ui.qcbTransmit->addItem(tr("Push To Talk"), RsVOIP::AudioTransmitPushToTalk);
abSpeech = new AudioBar();
abSpeech->qcBelow = Qt::red;
abSpeech->qcInside = Qt::yellow;
abSpeech->qcAbove = Qt::green;
//abSpeech->setGeometry(9,20,50,10);
ui.qwVadLayout_2->addWidget(abSpeech,0,0,1,0);
connect( ui.qsTransmitHold, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsTransmitHold_valueChanged(int) ) );
connect( ui.qsNoise, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsNoise_valueChanged(int) ) );
connect( ui.qsAmp, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsAmp_valueChanged(int) ) );
connect( ui.qcbTransmit, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( on_qcbTransmit_currentIndexChanged(int) ) );
}
void VOIPConfigPanel::showEvent(QShowEvent *)
{
std::cerr << "Creating the audio pipeline" << std::endl;
inputAudioProcessor = new QtSpeex::SpeexInputProcessor();
inputAudioProcessor->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
inputAudioDevice = AudioDeviceHelper::getPreferedInputDevice();
inputAudioDevice->start(inputAudioProcessor);
connect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(emptyBuffer()));
std::cerr << "Creating the video pipeline" << std::endl;
// Create the video pipeline.
//
videoInput = new QVideoInputDevice(this) ;
videoInput->setEchoVideoTarget(ui.videoDisplay) ;
videoProcessor = new VideoProcessor() ;
videoProcessor->setDisplayTarget(NULL) ;
@ -114,8 +145,34 @@ VOIPConfigPanel::VOIPConfigPanel(QWidget * parent, Qt::WindowFlags flags)
graph_source->setCollectionTimeLimit(1000*300) ;
graph_source->start() ;
if(ui.showEncoded_CB->isChecked())
{
videoInput->setEchoVideoTarget(nullptr) ;
videoProcessor->setDisplayTarget(ui.videoDisplay) ;
}
else
{
videoInput->setEchoVideoTarget(ui.videoDisplay) ;
videoProcessor->setDisplayTarget(nullptr);
}
QObject::connect(ui.showEncoded_CB,SIGNAL(toggled(bool)),this,SLOT(togglePreview(bool))) ;
QObject::connect(ui.availableBW_SB,SIGNAL(valueChanged(double)),this,SLOT(updateAvailableBW(double))) ;
loadSettings();
qtTick = new RsProtectedTimer(this);
connect( qtTick, SIGNAL( timeout ( ) ), this, SLOT( on_Tick_timeout() ) );
qtTick->start(20);
videoInput->start();
}
void VOIPConfigPanel::hideEvent(QHideEvent *)
{
std::cerr << "Deleting the video pipeline" << std::endl;
clearPipeline();
}
void VOIPConfigPanel::updateAvailableBW(double r)
@ -140,87 +197,51 @@ void VOIPConfigPanel::togglePreview(bool b)
VOIPConfigPanel::~VOIPConfigPanel()
{
disconnect( qtTick, SIGNAL( timeout ( ) ), this, SLOT( on_Tick_timeout() ) );
clearPipeline();
}
void VOIPConfigPanel::clearPipeline()
{
delete qtTick;
graph_source->stop() ;
graph_source->setVideoInput(NULL) ;
graph_source=nullptr; // is deleted by setSource below. This is a bad design.
ui.voipBwGraph->setSource(nullptr);
std::cerr << "Deleting audioInputConfig object" << std::endl;
if(videoInput != NULL)
{
videoInput->stop() ;
delete videoInput ;
videoInput = nullptr;
}
delete videoProcessor;
videoProcessor = nullptr;
if (inputAudioDevice) {
inputAudioDevice->stop();
delete inputAudioDevice ;
inputAudioDevice = NULL ;
inputAudioDevice = nullptr ;
}
if(inputAudioProcessor)
{
delete inputAudioProcessor ;
inputAudioProcessor = NULL ;
inputAudioProcessor = nullptr ;
}
}
void VOIPConfigPanel::load()
{
}
/** Loads the settings for this page */
void VOIPConfigPanel::load()
void VOIPConfigPanel::loadSettings()
{
//connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) );
//connect( ui.allowTunnelConnectionCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) );
qtTick = new RsProtectedTimer(this);
connect( qtTick, SIGNAL( timeout ( ) ), this, SLOT( on_Tick_timeout() ) );
qtTick->start(20);
/*if (AudioInputRegistrar::qmNew) {
QList<QString> keys = AudioInputRegistrar::qmNew->keys();
foreach(QString key, keys) {
qcbSystem->addItem(key);
}
}
qcbSystem->setEnabled(qcbSystem->count() > 1);*/
ui.qcbTransmit->addItem(tr("Continuous"), RsVOIP::AudioTransmitContinous);
ui.qcbTransmit->addItem(tr("Voice Activity"), RsVOIP::AudioTransmitVAD);
ui.qcbTransmit->addItem(tr("Push To Talk"), RsVOIP::AudioTransmitPushToTalk);
abSpeech = new AudioBar();
abSpeech->qcBelow = Qt::red;
abSpeech->qcInside = Qt::yellow;
abSpeech->qcAbove = Qt::green;
//abSpeech->setGeometry(9,20,50,10);
ui.qwVadLayout_2->addWidget(abSpeech,0,0,1,0);
//on_qcbPushClick_clicked(g.s.bPushClick);
//ui.on_Tick_timeout();
loadSettings();
}
void VOIPConfigPanel::loadSettings() {
/*QList<QString> keys;
if (AudioInputRegistrar::qmNew)
keys=AudioInputRegistrar::qmNew->keys();
else
keys.clear();
i=keys.indexOf(AudioInputRegistrar::current);
if (i >= 0)
loadComboBox(qcbSystem, i);
loadCheckBox(qcbExclusive, r.bExclusiveInput);*/
//qlePushClickPathOn->setText(r.qsPushClickOn);
//qlePushClickPathOff->setText(r.qsPushClickOff);
/*loadComboBox(qcbTransmit, r.atTransmit);
loadSlider(qsTransmitHold, r.iVoiceHold);
loadSlider(qsTransmitMin, iroundf(r.fVADmin * 32767.0f + 0.5f));
loadSlider(qsTransmitMax, iroundf(r.fVADmax * 32767.0f + 0.5f));
loadSlider(qsFrames, (r.iFramesPerPacket == 1) ? 1 : (r.iFramesPerPacket/2 + 1));
loadSlider(qsDoublePush, iroundf(static_cast<float>(r.uiDoublePush) / 1000.f + 0.5f));*/
ui.qcbTransmit->setCurrentIndex(rsVOIP->getVoipATransmit());
on_qcbTransmit_currentIndexChanged(rsVOIP->getVoipATransmit());
ui.qsTransmitHold->setValue(rsVOIP->getVoipVoiceHold());
@ -228,10 +249,7 @@ void VOIPConfigPanel::loadSettings() {
ui.qsTransmitMin->setValue(rsVOIP->getVoipfVADmin());
ui.qsTransmitMax->setValue(rsVOIP->getVoipfVADmax());
ui.qcbEchoCancel->setChecked(rsVOIP->getVoipEchoCancel());
//ui.qsDoublePush->setValue(iroundf(static_cast<float>(r.uiDoublePush) / 1000.f + 0.5f));
//loadCheckBox(qcbPushClick, r.bPushClick);
//loadSlider(qsQuality, r.iQuality);
if (rsVOIP->getVoipiNoiseSuppress() != 0)
ui.qsNoise->setValue(-rsVOIP->getVoipiNoiseSuppress());
else
@ -241,24 +259,13 @@ void VOIPConfigPanel::loadSettings() {
ui.qsAmp->setValue(20000 - rsVOIP->getVoipiMinLoudness());
on_qsAmp_valueChanged(20000 - rsVOIP->getVoipiMinLoudness());
//loadSlider(qsIdle, r.iIdleTime);
/*int echo = 0;
if (r.bEcho)
echo = r.bEchoMulti ? 2 : 1;
loadComboBox(qcbEcho, echo);*/
connect( ui.qsTransmitHold, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsTransmitHold_valueChanged(int) ) );
connect( ui.qsNoise, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsNoise_valueChanged(int) ) );
connect( ui.qsAmp, SIGNAL( valueChanged ( int ) ), this, SLOT( on_qsAmp_valueChanged(int) ) );
connect( ui.qcbTransmit, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( on_qcbTransmit_currentIndexChanged(int) ) );
loaded = true;
std::cerr << "AudioInputConfig:: starting video." << std::endl;
videoInput->start() ;
}
bool VOIPConfigPanel::save(QString &/*errmsg*/) {//mainly useless beacause saving occurs in realtime
bool VOIPConfigPanel::save(QString &/*errmsg*/)
{
//mainly useless beacause saving occurs in realtime
//s.iQuality = qsQuality->value();
rsVOIP->setVoipiNoiseSuppress((ui.qsNoise->value() == 14) ? 0 : - ui.qsNoise->value());
rsVOIP->setVoipiMinLoudness(20000 - ui.qsAmp->value());
@ -323,30 +330,21 @@ void VOIPConfigPanel::on_qcbTransmit_currentIndexChanged(int v) {
void VOIPConfigPanel::on_Tick_timeout()
{
if (!inputAudioProcessor)
{
inputAudioProcessor = new QtSpeex::SpeexInputProcessor();
inputAudioProcessor->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
if (!inputAudioDevice) {
inputAudioDevice = AudioDeviceHelper::getPreferedInputDevice();
}
inputAudioDevice->start(inputAudioProcessor);
connect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(emptyBuffer()));
}
// update the sound capture bar
abSpeech->iBelow = ui.qsTransmitMin->value();
abSpeech->iAbove = ui.qsTransmitMax->value();
if (loaded) {
rsVOIP->setVoipfVADmin(ui.qsTransmitMin->value());
rsVOIP->setVoipfVADmax(ui.qsTransmitMax->value());
}
abSpeech->iValue = iroundf(inputAudioProcessor->dVoiceAcivityLevel * 32767.0f + 0.5f);
abSpeech->update();
// also transmit encoded video
RsVOIPDataChunk chunk ;
while((!videoInput->stopped()) && videoInput->getNextEncodedPacket(chunk))

View File

@ -67,9 +67,8 @@ class VOIPConfigPanel : public ConfigPage
protected:
QTimer *qtTick;
/*void hideEvent(QHideEvent *event);
void showEvent(QShowEvent *event);*/
void clearPipeline();
public:
/** Default Constructor */
VOIPConfigPanel(QWidget * parent = 0, Qt::WindowFlags flags = 0);
@ -77,14 +76,16 @@ class VOIPConfigPanel : public ConfigPage
~VOIPConfigPanel();
/** Saves the changes on this page */
virtual bool save(QString &errmsg);
virtual bool save(QString &errmsg)override ;
/** Loads the settings for this page */
virtual void load();
virtual void load()override ;
virtual QPixmap iconPixmap() const { return QPixmap(":/images/talking_on.svg") ; }
virtual QString pageName() const { return tr("VOIP") ; }
virtual QString helpText() const { return ""; }
virtual QPixmap iconPixmap() const override { return QPixmap(":/images/talking_on.svg") ; }
virtual QString pageName() const override { return tr("VOIP") ; }
virtual QString helpText() const override { return ""; }
virtual void showEvent(QShowEvent *) override;
virtual void hideEvent(QHideEvent *event) override;
private slots:
void updateAvailableBW(double r);
void loadSettings();

View File

@ -239,7 +239,7 @@
<item>
<widget class="QGroupBox" name="qgbAudio">
<property name="title">
<string>Audio Processing</string>
<string>Audio</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
@ -353,7 +353,7 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Video Processing</string>
<string>Video</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>