2013-10-04 08:13:09 -04:00
|
|
|
#include <QToolButton>
|
2012-02-25 07:18:40 -05:00
|
|
|
#include <QPropertyAnimation>
|
|
|
|
#include <QIcon>
|
|
|
|
#include "AudioPopupChatDialog.h"
|
2012-02-26 11:10:27 -05:00
|
|
|
#include "interface/rsvoip.h"
|
2012-10-21 17:38:55 -04:00
|
|
|
#include "gui/SoundManager.h"
|
2012-02-25 07:18:40 -05:00
|
|
|
|
2013-10-03 18:00:16 -04:00
|
|
|
#define CALL_START ":/images/call-start-22.png"
|
|
|
|
#define CALL_STOP ":/images/call-stop-22.png"
|
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent)
|
2012-09-30 05:38:13 -04:00
|
|
|
: PopupChatDialog(parent)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
2013-10-04 08:13:09 -04:00
|
|
|
audioListenToggleButton = new QToolButton ;
|
2012-02-25 07:18:40 -05:00
|
|
|
audioListenToggleButton->setMinimumSize(QSize(28,28)) ;
|
|
|
|
audioListenToggleButton->setMaximumSize(QSize(28,28)) ;
|
2012-10-21 17:38:55 -04:00
|
|
|
audioListenToggleButton->setText(QString()) ;
|
2012-10-17 08:08:30 -04:00
|
|
|
audioListenToggleButton->setToolTip(tr("Mute yourself"));
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
std::cerr << "****** VOIPLugin: Creating new AudioPopupChatDialog !!" << std::endl;
|
|
|
|
|
|
|
|
QIcon icon ;
|
2013-10-04 08:13:09 -04:00
|
|
|
icon.addPixmap(QPixmap(":/images/deafened_self.svg")) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
icon.addPixmap(QPixmap(":/images/self_undeafened.svg"),QIcon::Normal,QIcon::On) ;
|
|
|
|
icon.addPixmap(QPixmap(":/images/self_undeafened.svg"),QIcon::Disabled,QIcon::On) ;
|
|
|
|
icon.addPixmap(QPixmap(":/images/self_undeafened.svg"),QIcon::Active,QIcon::On) ;
|
2013-10-04 08:13:09 -04:00
|
|
|
icon.addPixmap(QPixmap(":/images/self_undeafened.svg"),QIcon::Selected,QIcon::On) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
audioListenToggleButton->setIcon(icon) ;
|
|
|
|
audioListenToggleButton->setIconSize(QSize(22,22)) ;
|
2013-10-04 08:13:09 -04:00
|
|
|
audioListenToggleButton->setAutoRaise(true) ;
|
|
|
|
audioListenToggleButton->setCheckable(true);
|
2012-02-25 07:18:40 -05:00
|
|
|
|
2013-10-04 08:13:09 -04:00
|
|
|
audioMuteCaptureToggleButton = new QToolButton ;
|
2012-02-25 07:18:40 -05:00
|
|
|
audioMuteCaptureToggleButton->setMinimumSize(QSize(28,28)) ;
|
|
|
|
audioMuteCaptureToggleButton->setMaximumSize(QSize(28,28)) ;
|
2012-10-21 17:38:55 -04:00
|
|
|
audioMuteCaptureToggleButton->setText(QString()) ;
|
2013-10-03 18:00:16 -04:00
|
|
|
audioMuteCaptureToggleButton->setToolTip(tr("Start Call"));
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
QIcon icon2 ;
|
2013-10-04 08:13:09 -04:00
|
|
|
icon2.addPixmap(QPixmap(":/images/call-start-22.png")) ;
|
2013-10-03 18:00:16 -04:00
|
|
|
icon2.addPixmap(QPixmap(":/images/call-stop-22.png"),QIcon::Normal,QIcon::On) ;
|
|
|
|
icon2.addPixmap(QPixmap(":/images/call-stop-22.png"),QIcon::Disabled,QIcon::On) ;
|
|
|
|
icon2.addPixmap(QPixmap(":/images/call-stop-22.png"),QIcon::Active,QIcon::On) ;
|
2013-10-04 08:13:09 -04:00
|
|
|
icon2.addPixmap(QPixmap(":/images/call-stop-22.png"),QIcon::Selected,QIcon::On) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
audioMuteCaptureToggleButton->setIcon(icon2) ;
|
|
|
|
audioMuteCaptureToggleButton->setIconSize(QSize(22,22)) ;
|
2013-10-04 08:13:09 -04:00
|
|
|
audioMuteCaptureToggleButton->setAutoRaise(true) ;
|
|
|
|
audioMuteCaptureToggleButton->setCheckable(true) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
connect(audioListenToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioListen()));
|
|
|
|
connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture()));
|
|
|
|
|
2013-04-23 18:43:19 -04:00
|
|
|
addChatBarWidget(audioListenToggleButton) ;
|
|
|
|
addChatBarWidget(audioMuteCaptureToggleButton) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
//ui.chatWidget->resetStatusBar();
|
|
|
|
|
|
|
|
outputProcessor = NULL ;
|
|
|
|
outputDevice = NULL ;
|
|
|
|
inputProcessor = NULL ;
|
|
|
|
inputDevice = NULL ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPopupChatDialog::toggleAudioListen()
|
|
|
|
{
|
|
|
|
std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl;
|
2012-10-21 17:38:55 -04:00
|
|
|
if (audioListenToggleButton->isChecked()) {
|
2012-02-25 07:18:40 -05:00
|
|
|
} else {
|
2012-02-26 11:10:27 -05:00
|
|
|
//audioListenToggleButton->setChecked(false);
|
2012-02-25 07:18:40 -05:00
|
|
|
/*if (outputDevice) {
|
|
|
|
outputDevice->stop();
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPopupChatDialog::toggleAudioMuteCapture()
|
|
|
|
{
|
|
|
|
std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl;
|
|
|
|
if (audioMuteCaptureToggleButton->isChecked()) {
|
|
|
|
//activate audio output
|
|
|
|
audioListenToggleButton->setChecked(true);
|
2013-10-03 18:00:16 -04:00
|
|
|
audioMuteCaptureToggleButton->setToolTip(tr("Stop Call"));
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
//activate audio input
|
|
|
|
if (!inputProcessor) {
|
|
|
|
inputProcessor = new QtSpeex::SpeexInputProcessor();
|
|
|
|
if (outputProcessor) {
|
|
|
|
connect(outputProcessor, SIGNAL(playingFrame(QByteArray*)), inputProcessor, SLOT(addEchoFrame(QByteArray*)));
|
|
|
|
}
|
|
|
|
inputProcessor->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
|
|
|
|
}
|
|
|
|
if (!inputDevice) {
|
|
|
|
inputDevice = AudioDeviceHelper::getPreferedInputDevice();
|
|
|
|
}
|
|
|
|
connect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
|
|
|
|
inputDevice->start(inputProcessor);
|
|
|
|
} else {
|
|
|
|
disconnect(inputProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
|
|
|
|
if (inputDevice) {
|
|
|
|
inputDevice->stop();
|
|
|
|
}
|
2013-10-03 18:00:16 -04:00
|
|
|
audioMuteCaptureToggleButton->setToolTip(tr("Start Call"));
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPopupChatDialog::addAudioData(const QString name, QByteArray* array)
|
|
|
|
{
|
2013-10-03 18:00:16 -04:00
|
|
|
if (!audioMuteCaptureToggleButton->isChecked()) {
|
2012-02-25 07:18:40 -05:00
|
|
|
//launch an animation. Don't launch it if already animating
|
2013-10-03 18:00:16 -04:00
|
|
|
if (!audioMuteCaptureToggleButton->graphicsEffect() ||
|
|
|
|
(audioMuteCaptureToggleButton->graphicsEffect()->inherits("QGraphicsOpacityEffect") &&
|
|
|
|
((QGraphicsOpacityEffect*)audioMuteCaptureToggleButton->graphicsEffect())->opacity() == 1)
|
2012-02-25 07:18:40 -05:00
|
|
|
) {
|
|
|
|
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(audioListenToggleButton);
|
2013-10-03 18:00:16 -04:00
|
|
|
audioMuteCaptureToggleButton->setGraphicsEffect(effect);
|
2012-02-25 07:18:40 -05:00
|
|
|
QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity");
|
|
|
|
anim->setStartValue(1);
|
|
|
|
anim->setKeyValueAt(0.5,0);
|
|
|
|
anim->setEndValue(1);
|
|
|
|
anim->setDuration(400);
|
|
|
|
anim->start();
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
// soundManager->play(VOIP_SOUND_INCOMING_CALL);
|
|
|
|
|
2013-10-03 18:00:16 -04:00
|
|
|
audioMuteCaptureToggleButton->setToolTip(tr("Answer"));
|
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
//TODO make a toaster and a sound for the incoming call
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outputDevice) {
|
|
|
|
outputDevice = AudioDeviceHelper::getDefaultOutputDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outputProcessor) {
|
|
|
|
//start output audio device
|
|
|
|
outputProcessor = new QtSpeex::SpeexOutputProcessor();
|
|
|
|
if (inputProcessor) {
|
|
|
|
connect(outputProcessor, SIGNAL(playingFrame(QByteArray*)), inputProcessor, SLOT(addEchoFrame(QByteArray*)));
|
|
|
|
}
|
|
|
|
outputProcessor->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
|
|
|
|
outputDevice->start(outputProcessor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputDevice && outputDevice->error() != QAudio::NoError) {
|
|
|
|
std::cerr << "Restarting output device. Error before reset " << outputDevice->error() << " buffer size : " << outputDevice->bufferSize() << std::endl;
|
|
|
|
outputDevice->stop();
|
|
|
|
outputDevice->reset();
|
|
|
|
if (outputDevice->error() == QAudio::UnderrunError)
|
|
|
|
outputDevice->setBufferSize(20);
|
|
|
|
outputDevice->start(outputProcessor);
|
|
|
|
}
|
|
|
|
outputProcessor->putNetworkPacket(name, *array);
|
|
|
|
|
|
|
|
//check the input device for errors
|
|
|
|
if (inputDevice && inputDevice->error() != QAudio::NoError) {
|
|
|
|
std::cerr << "Restarting input device. Error before reset " << inputDevice->error() << std::endl;
|
|
|
|
inputDevice->stop();
|
|
|
|
inputDevice->reset();
|
|
|
|
inputDevice->start(inputProcessor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPopupChatDialog::sendAudioData() {
|
|
|
|
while(inputProcessor && inputProcessor->hasPendingPackets()) {
|
|
|
|
QByteArray qbarray = inputProcessor->getNetworkPacket();
|
2012-02-26 11:10:27 -05:00
|
|
|
RsVoipDataChunk chunk;
|
|
|
|
chunk.size = qbarray.size();
|
2012-02-26 15:31:16 -05:00
|
|
|
chunk.data = (void*)qbarray.constData();
|
2012-02-26 11:10:27 -05:00
|
|
|
rsVoip->sendVoipData(peerId,chunk);
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 19:22:25 -05:00
|
|
|
void AudioPopupChatDialog::updateStatus(int status)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
|
|
|
audioListenToggleButton->setEnabled(true);
|
|
|
|
audioMuteCaptureToggleButton->setEnabled(true);
|
|
|
|
|
2012-03-10 19:22:25 -05:00
|
|
|
PopupChatDialog::updateStatus(status) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
|