Renaming all to VOIP in VOIP plugin (patch from Phenom)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8231 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
electron128 2015-05-11 19:40:07 +00:00
parent a3b32b92d5
commit b5bf3ce130
29 changed files with 860 additions and 686 deletions

View File

@ -33,38 +33,38 @@ win32 {
QMAKE_CXXFLAGS *= -Wall
SOURCES = services/p3vors.cc \
services/rsvoipitems.cc \
gui/AudioInputConfig.cpp \
gui/AudioStats.cpp \
gui/AudioWizard.cpp \
gui/SpeexProcessor.cpp \
gui/audiodevicehelper.cpp \
SOURCES = VOIPPlugin.cpp \
services/p3VOIP.cc \
services/rsVOIPItems.cc \
gui/AudioInputConfig.cpp \
gui/AudioStats.cpp \
gui/AudioWizard.cpp \
gui/SpeexProcessor.cpp \
gui/audiodevicehelper.cpp \
gui/VideoProcessor.cpp \
gui/QVideoDevice.cpp \
gui/VOIPChatWidgetHolder.cpp \
gui/PluginGUIHandler.cpp \
gui/PluginNotifier.cpp \
gui/VideoProcessor.cpp \
gui/QVideoDevice.cpp \
VOIPPlugin.cpp
gui/VOIPGUIHandler.cpp \
gui/VOIPNotify.cpp
HEADERS = services/p3vors.h \
services/rsvoipitems.h \
gui/AudioInputConfig.h \
gui/AudioStats.h \
gui/AudioWizard.h \
gui/SpeexProcessor.h \
gui/audiodevicehelper.h \
gui/VOIPChatWidgetHolder.h \
gui/PluginGUIHandler.h \
gui/PluginNotifier.h \
gui/VideoProcessor.h \
gui/QVideoDevice.h \
interface/rsvoip.h \
VOIPPlugin.h
HEADERS = VOIPPlugin.h \
services/p3VOIP.h \
services/rsVOIPItems.h \
gui/AudioInputConfig.h \
gui/AudioStats.h \
gui/AudioWizard.h \
gui/SpeexProcessor.h \
gui/audiodevicehelper.h \
gui/VideoProcessor.h \
gui/QVideoDevice.h \
gui/VOIPChatWidgetHolder.h \
gui/VOIPGUIHandler.h \
gui/VOIPNotify.h \
interface/rsVOIP.h
FORMS = gui/AudioInputConfig.ui \
gui/AudioStats.ui \
gui/AudioWizard.ui
FORMS = gui/AudioInputConfig.ui \
gui/AudioStats.ui \
gui/AudioWizard.ui
TARGET = VOIP

View File

@ -1,3 +1,23 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <retroshare/rsplugin.h>
#include <retroshare/rsversion.h>
#include <retroshare-gui/RsAutoUpdatePage.h>
@ -8,12 +28,12 @@
#include <QMessageBox>
#include "VOIPPlugin.h"
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
#include "gui/AudioInputConfig.h"
#include "gui/VOIPChatWidgetHolder.h"
#include "gui/PluginGUIHandler.h"
#include "gui/PluginNotifier.h"
#include "gui/VOIPGUIHandler.h"
#include "gui/VOIPNotify.h"
#include "gui/SoundManager.h"
#include "gui/chat/ChatWidget.h"
@ -58,20 +78,20 @@ void VOIPPlugin::getPluginVersion(int& major, int& minor, int& build, int& svn_r
VOIPPlugin::VOIPPlugin()
{
mVoip = NULL ;
mVOIP = NULL ;
mPlugInHandler = NULL;
mPeers = NULL;
config_page = NULL ;
mIcon = NULL ;
mPluginGUIHandler = new PluginGUIHandler ;
mPluginNotifier = new PluginNotifier ;
mVOIPGUIHandler = new VOIPGUIHandler ;
mVOIPNotify = new VOIPNotify ;
QObject::connect(mPluginNotifier,SIGNAL(voipInvitationReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedInvitation(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mPluginNotifier,SIGNAL(voipDataReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedVoipData(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mPluginNotifier,SIGNAL(voipAcceptReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedVoipAccept(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mPluginNotifier,SIGNAL(voipHangUpReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedVoipHangUp(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mPluginNotifier,SIGNAL(voipBandwidthInfoReceived(const QString&,int)),mPluginGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const QString&,int)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipInvitationReceived(const QString&)),mVOIPGUIHandler,SLOT(ReceivedInvitation(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipDataReceived(const QString&)),mVOIPGUIHandler,SLOT(ReceivedVoipData(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipAcceptReceived(const QString&)),mVOIPGUIHandler,SLOT(ReceivedVoipAccept(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipHangUpReceived(const QString&)),mVOIPGUIHandler,SLOT(ReceivedVoipHangUp(const QString&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipBandwidthInfoReceived(const QString&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const QString&,int)),Qt::QueuedConnection) ;
}
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
@ -127,10 +147,10 @@ ChatWidgetHolder *VOIPPlugin::qt_get_chat_widget_holder(ChatWidget *chatWidget)
p3Service *VOIPPlugin::p3_service() const
{
if(mVoip == NULL)
rsVoip = mVoip = new p3VoRS(mPlugInHandler,mPluginNotifier) ; // , 3600 * 24 * 30 * 6); // 6 Months
if(mVOIP == NULL)
rsVOIP = mVOIP = new p3VOIP(mPlugInHandler,mVOIPNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months
return mVoip ;
return mVOIP ;
}
void VOIPPlugin::setPlugInHandler(RsPluginHandler *pgHandler)

View File

@ -1,10 +1,30 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#pragma once
#include <retroshare/rsplugin.h>
#include "services/p3vors.h"
#include "services/p3VOIP.h"
class PluginGUIHandler ;
class PluginNotifier ;
class VOIPGUIHandler ;
class VOIPNotify ;
class VOIPPlugin: public RsPlugin
{
@ -32,13 +52,13 @@ class VOIPPlugin: public RsPlugin
virtual void setInterfaces(RsPlugInInterfaces& interfaces);
private:
mutable p3VoRS *mVoip ;
mutable p3VOIP *mVOIP ;
mutable RsPluginHandler *mPlugInHandler;
mutable RsPeers* mPeers;
mutable ConfigPage *config_page ;
mutable QIcon *mIcon;
PluginNotifier *mPluginNotifier ;
PluginGUIHandler *mPluginGUIHandler ;
VOIPNotify *mVOIPNotify ;
VOIPGUIHandler *mVOIPGUIHandler ;
};

View File

@ -39,7 +39,7 @@
//#include "NetworkConfig.h"
#include "audiodevicehelper.h"
#include "AudioWizard.h"
#include <interface/rsvoip.h>
#include <interface/rsVOIP.h>
#define iroundf(x) ( static_cast<int>(x) )
@ -112,9 +112,9 @@ void AudioInputConfig::load()
}
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);
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;
@ -151,26 +151,26 @@ void AudioInputConfig::loadSettings() {
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());
on_qsTransmitHold_valueChanged(rsVoip->getVoipVoiceHold());
ui.qsTransmitMin->setValue(rsVoip->getVoipfVADmin());
ui.qsTransmitMax->setValue(rsVoip->getVoipfVADmax());
ui.qcbEchoCancel->setChecked(rsVoip->getVoipEchoCancel());
ui.qcbTransmit->setCurrentIndex(rsVOIP->getVoipATransmit());
on_qcbTransmit_currentIndexChanged(rsVOIP->getVoipATransmit());
ui.qsTransmitHold->setValue(rsVOIP->getVoipVoiceHold());
on_qsTransmitHold_valueChanged(rsVOIP->getVoipVoiceHold());
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());
if (rsVOIP->getVoipiNoiseSuppress() != 0)
ui.qsNoise->setValue(-rsVOIP->getVoipiNoiseSuppress());
else
ui.qsNoise->setValue(14);
on_qsNoise_valueChanged(-rsVoip->getVoipiNoiseSuppress());
on_qsNoise_valueChanged(-rsVOIP->getVoipiNoiseSuppress());
ui.qsAmp->setValue(20000 - rsVoip->getVoipiMinLoudness());
on_qsAmp_valueChanged(20000 - rsVoip->getVoipiMinLoudness());
ui.qsAmp->setValue(20000 - rsVOIP->getVoipiMinLoudness());
on_qsAmp_valueChanged(20000 - rsVOIP->getVoipiMinLoudness());
//loadSlider(qsIdle, r.iIdleTime);
/*int echo = 0;
@ -190,14 +190,14 @@ void AudioInputConfig::loadSettings() {
bool AudioInputConfig::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());
rsVoip->setVoipVoiceHold(ui.qsTransmitHold->value());
rsVoip->setVoipfVADmin(ui.qsTransmitMin->value());
rsVoip->setVoipfVADmax(ui.qsTransmitMax->value());
rsVOIP->setVoipiNoiseSuppress((ui.qsNoise->value() == 14) ? 0 : - ui.qsNoise->value());
rsVOIP->setVoipiMinLoudness(20000 - ui.qsAmp->value());
rsVOIP->setVoipVoiceHold(ui.qsTransmitHold->value());
rsVOIP->setVoipfVADmin(ui.qsTransmitMin->value());
rsVOIP->setVoipfVADmax(ui.qsTransmitMax->value());
/*s.uiDoublePush = qsDoublePush->value() * 1000;*/
rsVoip->setVoipATransmit(static_cast<RsVoip::enumAudioTransmit>(ui.qcbTransmit->currentIndex() ));
rsVoip->setVoipEchoCancel(ui.qcbEchoCancel->isChecked());
rsVOIP->setVoipATransmit(static_cast<RsVOIP::enumAudioTransmit>(ui.qcbTransmit->currentIndex() ));
rsVOIP->setVoipEchoCancel(ui.qcbEchoCancel->isChecked());
return true;
}
@ -220,7 +220,7 @@ void AudioInputConfig::on_qsTransmitHold_valueChanged(int v) {
float val = static_cast<float>(v * FRAME_SIZE);
val = val / SAMPLING_RATE;
ui.qlTransmitHold->setText(tr("%1 s").arg(val, 0, 'f', 2));
rsVoip->setVoipVoiceHold(v);
rsVOIP->setVoipVoiceHold(v);
}
void AudioInputConfig::on_qsNoise_valueChanged(int v) {
@ -233,18 +233,18 @@ void AudioInputConfig::on_qsNoise_valueChanged(int v) {
ui.qlNoise->setText(tr("-%1 dB").arg(v));
}
ui.qlNoise->setPalette(pal);
rsVoip->setVoipiNoiseSuppress(- ui.qsNoise->value());
rsVOIP->setVoipiNoiseSuppress(- ui.qsNoise->value());
}
void AudioInputConfig::on_qsAmp_valueChanged(int v) {
v = 20000 - v;
float d = 20000.0f/static_cast<float>(v);
ui.qlAmp->setText(QString::fromLatin1("%1").arg(d, 0, 'f', 2));
rsVoip->setVoipiMinLoudness(20000 - ui.qsAmp->value());
rsVOIP->setVoipiMinLoudness(20000 - ui.qsAmp->value());
}
void AudioInputConfig::on_qcbEchoCancel_clicked() {
rsVoip->setVoipEchoCancel(ui.qcbEchoCancel->isChecked());
rsVOIP->setVoipEchoCancel(ui.qcbEchoCancel->isChecked());
}
@ -261,7 +261,7 @@ void AudioInputConfig::on_qcbTransmit_currentIndexChanged(int v) {
break;
}
if (loaded)
rsVoip->setVoipATransmit(static_cast<RsVoip::enumAudioTransmit>(ui.qcbTransmit->currentIndex() ));
rsVOIP->setVoipATransmit(static_cast<RsVOIP::enumAudioTransmit>(ui.qcbTransmit->currentIndex() ));
}
@ -280,8 +280,8 @@ void AudioInputConfig::on_Tick_timeout() {
abSpeech->iBelow = ui.qsTransmitMin->value();
abSpeech->iAbove = ui.qsTransmitMax->value();
if (loaded) {
rsVoip->setVoipfVADmin(ui.qsTransmitMin->value());
rsVoip->setVoipfVADmax(ui.qsTransmitMax->value());
rsVOIP->setVoipfVADmin(ui.qsTransmitMin->value());
rsVOIP->setVoipfVADmax(ui.qsTransmitMax->value());
}
abSpeech->iValue = iroundf(inputAudioProcessor->dVoiceAcivityLevel * 32767.0f + 0.5f);

View File

@ -28,8 +28,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _AUDIOINPUTCONFIG_H
#define _AUDIOINPUTCONFIG_H
#pragma once
#include <QAudioInput>
#include <QWidget>
@ -88,5 +87,3 @@ class AudioInputConfig : public ConfigPage
void on_qpbAudioWizard_clicked();
void on_qcbEchoCancel_clicked();
};
#endif

View File

@ -28,8 +28,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _AUDIOSTATS_H
#define _AUDIOSTATS_H
#pragma once
#include <QWidget>
@ -89,7 +88,3 @@ class AudioStats : public QDialog, public Ui::AudioStats {
void on_Tick_timeout();
};
*/
#else
class AudioStats;
#endif

View File

@ -37,7 +37,7 @@
//#include "Log.h"
//#include "MainWindow.h"
#include "audiodevicehelper.h"
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
#define iroundf(x) ( static_cast<int>(x) )
@ -89,9 +89,9 @@ AudioWizard::AudioWizard(QWidget *p) : QWizard(p) {
verticalLayout_3->addWidget(abAmplify);
if (rsVoip->getVoipATransmit() == RsVoip::AudioTransmitPushToTalk)
if (rsVOIP->getVoipATransmit() == RsVOIP::AudioTransmitPushToTalk)
qrPTT->setChecked(true);
else if (rsVoip->getVoipATransmit() == RsVoip::AudioTransmitVAD)
else if (rsVOIP->getVoipATransmit() == RsVOIP::AudioTransmitVAD)
qrVAD->setChecked(true);
else
qrContinuous->setChecked(true);
@ -101,13 +101,13 @@ AudioWizard::AudioWizard(QWidget *p) : QWizard(p) {
abVAD->qcInside = Qt::yellow;
abVAD->qcAbove = Qt::green;
qsTransmitMin->setValue(rsVoip->getVoipfVADmin());
qsTransmitMax->setValue(rsVoip->getVoipfVADmax());
qsTransmitMin->setValue(rsVOIP->getVoipfVADmin());
qsTransmitMax->setValue(rsVOIP->getVoipfVADmax());
verticalLayout_6->addWidget(abVAD);
// Volume
qsMaxAmp->setValue(rsVoip->getVoipiMinLoudness());
qsMaxAmp->setValue(rsVOIP->getVoipiMinLoudness());
setOption(QWizard::NoCancelButton, false);
resize(700, 500);
@ -149,7 +149,7 @@ AudioWizard::AudioWizard(QWidget *p) : QWizard(p) {
void AudioWizard::on_qsMaxAmp_valueChanged(int v) {
rsVoip->setVoipiMinLoudness(qMin(v, 30000));
rsVOIP->setVoipiMinLoudness(qMin(v, 30000));
}
void AudioWizard::on_Ticker_timeout() {
@ -177,8 +177,8 @@ void AudioWizard::on_Ticker_timeout() {
abVAD->iBelow = qsTransmitMin->value();
abVAD->iAbove = qsTransmitMax->value();
rsVoip->setVoipfVADmin(qsTransmitMin->value());
rsVoip->setVoipfVADmax(qsTransmitMax->value());
rsVOIP->setVoipfVADmin(qsTransmitMin->value());
rsVOIP->setVoipfVADmax(qsTransmitMax->value());
abVAD->iValue = iroundf(inputProcessor->dVoiceAcivityLevel * 32767.0f + 0.5f);
@ -233,19 +233,19 @@ void AudioWizard::on_playEcho_timeout() {
void AudioWizard::on_qsTransmitMax_valueChanged(int v) {
if (! bInit) {
rsVoip->setVoipfVADmax(v);
rsVOIP->setVoipfVADmax(v);
}
}
void AudioWizard::on_qsTransmitMin_valueChanged(int v) {
if (! bInit) {
rsVoip->setVoipfVADmin(v);
rsVOIP->setVoipfVADmin(v);
}
}
void AudioWizard::on_qrVAD_clicked(bool on) {
if (on) {
rsVoip->setVoipATransmit(RsVoip::AudioTransmitVAD);
rsVOIP->setVoipATransmit(RsVOIP::AudioTransmitVAD);
updateTriggerWidgets(true);
bTransmitChanged = true;
}
@ -253,7 +253,7 @@ void AudioWizard::on_qrVAD_clicked(bool on) {
void AudioWizard::on_qrPTT_clicked(bool on) {
if (on) {
rsVoip->setVoipATransmit(RsVoip::AudioTransmitPushToTalk);
rsVOIP->setVoipATransmit(RsVOIP::AudioTransmitPushToTalk);
updateTriggerWidgets(false);
bTransmitChanged = true;
}
@ -261,7 +261,7 @@ void AudioWizard::on_qrPTT_clicked(bool on) {
void AudioWizard::on_qrContinuous_clicked(bool on) {
if (on) {
rsVoip->setVoipATransmit(RsVoip::AudioTransmitContinous);
rsVOIP->setVoipATransmit(RsVOIP::AudioTransmitContinous);
updateTriggerWidgets(false);
bTransmitChanged = true;
}

View File

@ -28,8 +28,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _AUDIOWIZARD_H
#define _AUDIOWIZARD_H
#pragma once
#include <QAudioInput>
#include <QAudioOutput>
@ -95,5 +94,3 @@ class AudioWizard: public QWizard, public Ui::AudioWizard {
void loopAudio();
};
#endif

View File

@ -1,102 +0,0 @@
#include <iostream>
#include <vector>
#include <list>
#include <interface/rsvoip.h>
#include "PluginGUIHandler.h"
#include <gui/chat/ChatDialog.h>
#include <gui/VOIPChatWidgetHolder.h>
#include "gui/chat/ChatWidget.h"
#include "gui/settings/rsharesettings.h"
void PluginGUIHandler::ReceivedInvitation(const QString& /*peer_id*/)
{
std::cerr << "****** Plugin GUI handler: received Invitation!" << std::endl;
}
void PluginGUIHandler::ReceivedVoipHangUp(const QString& /*peer_id*/)
{
std::cerr << "****** Plugin GUI handler: received HangUp!" << std::endl;
}
void PluginGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/)
{
std::cerr << "****** Plugin GUI handler: received VoipAccept!" << std::endl;
}
void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
{
RsPeerId peer_id(qpeer_id.toStdString()) ;
std::vector<RsVoipDataChunk> chunks ;
if(!rsVoip->getIncomingData(peer_id,chunks))
{
std::cerr << "PluginGUIHandler::ReceivedVoipData(): No data chunks to get. Weird!" << std::endl;
return ;
}
ChatDialog *di = ChatDialog::getChat(ChatId(peer_id), Settings->getChatFlags());
if (di) {
ChatWidget *cw = di->getChatWidget();
if (cw) {
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
{
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
if (acwh) {
for (unsigned int i = 0; i < chunks.size(); ++i) {
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++)
{
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb);
else
std::cerr << "Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
}
}
break;
}
}
}
} else {
std::cerr << "Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl;
}
for(unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
free(chunks[chunkIndex].data);
}
}
void PluginGUIHandler::ReceivedVoipBandwidthInfo(const QString& qpeer_id,int bytes_per_sec)
{
RsPeerId peer_id(qpeer_id.toStdString()) ;
ChatDialog *di = ChatDialog::getExistingChat(ChatId(peer_id)) ;
std::cerr << "PluginGUIHandler::received bw info for peer " << qpeer_id.toStdString() << ": " << bytes_per_sec << " Bps" << std::endl;
if(!di)
{
std::cerr << "Error: received bandwidth info for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl;
return ;
}
ChatWidget *cw = di->getChatWidget();
if(!cw)
{
return ;
}
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
{
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
if (acwh)
acwh->setAcceptedBandwidth(QString::fromStdString(peer_id.toStdString()),bytes_per_sec);
}
}

View File

@ -1,21 +0,0 @@
// This class receives async-ed signals from the plugin notifier,
// and executes GUI requests.
//
// It is never called directly: it is called by Qt signal-received callback,
// in the main GUI thread.
//
#include <stdint.h>
#include <QObject>
class PluginGUIHandler: public QObject
{
Q_OBJECT
public slots:
void ReceivedInvitation(const QString& peer_id) ;
void ReceivedVoipData(const QString& peer_id) ;
void ReceivedVoipHangUp(const QString& peer_id) ;
void ReceivedVoipAccept(const QString& peer_id) ;
void ReceivedVoipBandwidthInfo(const QString& peer_id,int) ;
};

View File

@ -1,22 +0,0 @@
#include "PluginNotifier.h"
void PluginNotifier::notifyReceivedVoipInvite(const RsPeerId& peer_id)
{
emit voipInvitationReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void PluginNotifier::notifyReceivedVoipData(const RsPeerId &peer_id)
{
emit voipDataReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void PluginNotifier::notifyReceivedVoipAccept(const RsPeerId& peer_id)
{
emit voipAcceptReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void PluginNotifier::notifyReceivedVoipHangUp(const RsPeerId &peer_id)
{
emit voipHangUpReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void PluginNotifier::notifyReceivedVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
{
emit voipBandwidthInfoReceived(QString::fromStdString(peer_id.toStdString()),bytes_per_sec) ;
}

View File

@ -7,6 +7,7 @@
#include "VideoProcessor.h"
QVideoInputDevice::QVideoInputDevice(QWidget *parent)
:QObject(parent)
{
_timer = NULL ;
_capture_device = NULL ;
@ -85,7 +86,7 @@ void QVideoInputDevice::grabFrame()
if(_echo_output_device != NULL) _echo_output_device->showFrame(image) ;
}
bool QVideoInputDevice::getNextEncodedPacket(RsVoipDataChunk& chunk)
bool QVideoInputDevice::getNextEncodedPacket(RsVOIPDataChunk& chunk)
{
return _video_encoder->nextPacket(chunk) ;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <QLabel>
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
class VideoEncoder ;
class CvCapture ;
@ -12,7 +12,7 @@ class CvCapture ;
class QVideoOutputDevice: public QLabel
{
public:
QVideoOutputDevice(QWidget *parent) ;
QVideoOutputDevice(QWidget *parent = 0) ;
void showFrame(const QImage&) ;
void showFrameOff() ;
@ -26,7 +26,7 @@ class QVideoInputDevice: public QObject
Q_OBJECT
public:
QVideoInputDevice(QWidget *parent) ;
QVideoInputDevice(QWidget *parent = 0) ;
~QVideoInputDevice() ;
// Captured images are sent to this encoder. Can be NULL.
@ -40,7 +40,7 @@ class QVideoInputDevice: public QObject
// get the next encoded video data chunk.
//
bool getNextEncodedPacket(RsVoipDataChunk&) ;
bool getNextEncodedPacket(RsVOIPDataChunk&) ;
void start() ;
void stop() ;
@ -58,6 +58,6 @@ class QVideoInputDevice: public QObject
QVideoOutputDevice *_echo_output_device ;
std::list<RsVoipDataChunk> _out_queue ;
std::list<RsVOIPDataChunk> _out_queue ;
};

View File

@ -12,7 +12,7 @@
#include <QDateTime>
#include <limits.h>
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
//#include "gui/settings/rsharesettings.h"
@ -165,7 +165,7 @@ qint64 SpeexInputProcessor::writeData(const char *data, qint64 maxSize) {
iArg = -60;
speex_preprocess_ctl(preprocessor, SPEEX_PREPROCESS_SET_AGC_DECREMENT, &iArg);
iArg = rsVoip->getVoipiNoiseSuppress();
iArg = rsVOIP->getVoipiNoiseSuppress();
speex_preprocess_ctl(preprocessor, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &iArg);
if (echo_state) {
@ -177,18 +177,18 @@ qint64 SpeexInputProcessor::writeData(const char *data, qint64 maxSize) {
bResetProcessor = false;
}
float v = 30000.0f / static_cast<float>(rsVoip->getVoipiMinLoudness());
float v = 30000.0f / static_cast<float>(rsVOIP->getVoipiMinLoudness());
iArg = iroundf(floorf(20.0f * log10f(v)));
speex_preprocess_ctl(preprocessor, SPEEX_PREPROCESS_SET_AGC_MAX_GAIN, &iArg);
speex_preprocess_ctl(preprocessor, SPEEX_PREPROCESS_GET_AGC_GAIN, &iArg);
float gainValue = static_cast<float>(iArg);
iArg = rsVoip->getVoipiNoiseSuppress() - iArg;
iArg = rsVOIP->getVoipiNoiseSuppress() - iArg;
speex_preprocess_ctl(preprocessor, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &iArg);
short * psSource = psMic;
if (echo_state && rsVoip->getVoipEchoCancel()) {
if (echo_state && rsVOIP->getVoipEchoCancel()) {
speex_echo_playback(echo_state, (short*)lastEchoFrame->data());
speex_echo_capture(echo_state,psMic,psClean);
psSource = psClean;
@ -212,29 +212,29 @@ qint64 SpeexInputProcessor::writeData(const char *data, qint64 maxSize) {
bool bIsSpeech = false;
if (dVoiceAcivityLevel > (static_cast<float>(rsVoip->getVoipfVADmax()) / 32767))
if (dVoiceAcivityLevel > (static_cast<float>(rsVOIP->getVoipfVADmax()) / 32767))
bIsSpeech = true;
else if (dVoiceAcivityLevel > (static_cast<float>(rsVoip->getVoipfVADmin()) / 32767) && bPreviousVoice)
else if (dVoiceAcivityLevel > (static_cast<float>(rsVOIP->getVoipfVADmin()) / 32767) && bPreviousVoice)
bIsSpeech = true;
if (! bIsSpeech) {
iHoldFrames++;
if (iHoldFrames < rsVoip->getVoipVoiceHold())
if (iHoldFrames < rsVOIP->getVoipVoiceHold())
bIsSpeech = true;
} else {
iHoldFrames = 0;
}
if (rsVoip->getVoipATransmit() == RsVoip::AudioTransmitContinous) {
if (rsVOIP->getVoipATransmit() == RsVOIP::AudioTransmitContinous) {
bIsSpeech = true;
}
else if (rsVoip->getVoipATransmit() == RsVoip::AudioTransmitPushToTalk)
else if (rsVOIP->getVoipATransmit() == RsVOIP::AudioTransmitPushToTalk)
bIsSpeech = false;//g.s.uiDoublePush && ((g.uiDoublePush < g.s.uiDoublePush) || (g.tDoublePush.elapsed() < g.s.uiDoublePush));
//bIsSpeech = bIsSpeech || (g.iPushToTalk > 0);
/*if (g.s.bMute || ((g.s.lmLoopMode != RsVoip::Local) && p && (p->bMute || p->bSuppress)) || g.bPushToMute || (g.iTarget < 0)) {
/*if (g.s.bMute || ((g.s.lmLoopMode != RsVOIP::Local) && p && (p->bMute || p->bSuppress)) || g.bPushToMute || (g.iTarget < 0)) {
bIsSpeech = false;
}*/
@ -246,11 +246,11 @@ qint64 SpeexInputProcessor::writeData(const char *data, qint64 maxSize) {
/*if (p) {
if (! bIsSpeech)
p->setTalking(RsVoip::Passive);
p->setTalking(RsVOIP::Passive);
else if (g.iTarget == 0)
p->setTalking(RsVoip::Talking);
p->setTalking(RsVOIP::Talking);
else
p->setTalking(RsVoip::Shouting);
p->setTalking(RsVOIP::Shouting);
}*/
@ -271,7 +271,7 @@ qint64 SpeexInputProcessor::writeData(const char *data, qint64 maxSize) {
int vbr_on=0;
//just use fixed bitrate for now
//encryption of VBR-encoded speech may not ensure complete privacy, as phrases can still be identified, at least in a controlled setting with a small dictionary of phrases, by analysing the pattern of variation of the bit rate.
if (rsVoip->getVoipATransmit() == RsVoip::AudioTransmitVAD) {//maybe we can do fixer bitrate when voice detection is active
if (rsVOIP->getVoipATransmit() == RsVOIP::AudioTransmitVAD) {//maybe we can do fixer bitrate when voice detection is active
vbr_on = 1;//test it on for all modes
} else {//maybe we can do vbr for ppt and continuous
vbr_on = 1;
@ -370,7 +370,7 @@ bool SpeexInputProcessor::isSequential() const {
}
void SpeexInputProcessor::addEchoFrame(QByteArray* echo_frame) {
if (rsVoip->getVoipEchoCancel() && echo_frame) {
if (rsVOIP->getVoipEchoCancel() && echo_frame) {
QMutexLocker l(&qmSpeex);
lastEchoFrame = echo_frame;
if (!echo_state) {//init echo_state

View File

@ -3,8 +3,7 @@
* Copyright (C) 2010 Peter Zotov
*/
#ifndef SPEEXPROCESSOR_H
#define SPEEXPROCESSOR_H
#pragma once
#include <iostream>
@ -117,5 +116,3 @@ namespace QtSpeex {
int speex_jitter_get_pointer_timestamp(SpeexJitter jitter);
};
}
#endif // SPEEXPROCESSOR_H

View File

@ -1,10 +1,30 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QToolButton>
#include <QPropertyAnimation>
#include <QIcon>
#include <QLayout>
#include <gui/audiodevicehelper.h>
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
#include "gui/SoundManager.h"
#include "util/HandleRichText.h"
#include "gui/common/StatusDefs.h"
@ -377,21 +397,21 @@ void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
void VOIPChatWidgetHolder::sendVideoData()
{
RsVoipDataChunk chunk ;
RsVOIPDataChunk chunk ;
while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk))
rsVoip->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk) ;
rsVOIP->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk) ;
}
void VOIPChatWidgetHolder::sendAudioData()
{
while(inputAudioProcessor && inputAudioProcessor->hasPendingPackets()) {
QByteArray qbarray = inputAudioProcessor->getNetworkPacket();
RsVoipDataChunk chunk;
RsVOIPDataChunk chunk;
chunk.size = qbarray.size();
chunk.data = (void*)qbarray.constData();
chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
rsVoip->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk);
chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
rsVOIP->sendVoipData(mChatWidget->getChatId().toPeerId(),chunk);
}
}

View File

@ -1,3 +1,26 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#pragma once
#include <QObject>
#include <QGraphicsEffect>
#include <gui/SpeexProcessor.h>

View File

@ -0,0 +1,122 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <iostream>
#include <vector>
#include <list>
#include <interface/rsVOIP.h>
#include "VOIPGUIHandler.h"
#include <gui/chat/ChatDialog.h>
#include <gui/VOIPChatWidgetHolder.h>
#include "gui/chat/ChatWidget.h"
#include "gui/settings/rsharesettings.h"
void VOIPGUIHandler::ReceivedInvitation(const QString& /*peer_id*/)
{
std::cerr << "****** VOIPGUIHandler: received Invitation!" << std::endl;
}
void VOIPGUIHandler::ReceivedVoipHangUp(const QString& /*peer_id*/)
{
std::cerr << "****** VOIPGUIHandler: received HangUp!" << std::endl;
}
void VOIPGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/)
{
std::cerr << "****** VOIPGUIHandler: received VoipAccept!" << std::endl;
}
void VOIPGUIHandler::ReceivedVoipData(const QString& qpeer_id)
{
RsPeerId peer_id(qpeer_id.toStdString()) ;
std::vector<RsVOIPDataChunk> chunks ;
if(!rsVOIP->getIncomingData(peer_id,chunks))
{
std::cerr << "VOIPGUIHandler::ReceivedVoipData(): No data chunks to get. Weird!" << std::endl;
return ;
}
ChatDialog *di = ChatDialog::getChat(ChatId(peer_id), Settings->getChatFlags());
if (di) {
ChatWidget *cw = di->getChatWidget();
if (cw) {
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
{
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
if (acwh) {
for (unsigned int i = 0; i < chunks.size(); ++i) {
for (unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++)
{
QByteArray qb(reinterpret_cast<const char *>(chunks[chunkIndex].data),chunks[chunkIndex].size);
if(chunks[chunkIndex].type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
else if(chunks[chunkIndex].type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb);
else
std::cerr << "VOIPGUIHandler: Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
}
}
break;
}
}
}
} else {
std::cerr << "VOIPGUIHandler Error: received audio data for a chat dialog that does not stand Audio (Peer id = " << peer_id.toStdString() << "!" << std::endl;
}
for(unsigned int chunkIndex=0; chunkIndex<chunks.size(); chunkIndex++){
free(chunks[chunkIndex].data);
}
}
void VOIPGUIHandler::ReceivedVoipBandwidthInfo(const QString& qpeer_id,int bytes_per_sec)
{
RsPeerId peer_id(qpeer_id.toStdString()) ;
ChatDialog *di = ChatDialog::getExistingChat(ChatId(peer_id)) ;
std::cerr << "VOIPGUIHandler::received bw info for peer " << qpeer_id.toStdString() << ": " << bytes_per_sec << " Bps" << std::endl;
if(!di)
{
std::cerr << "VOIPGUIHandler Error: received bandwidth info for a chat dialog that does not stand VOIP (Peer id = " << peer_id.toStdString() << "!" << std::endl;
return ;
}
ChatWidget *cw = di->getChatWidget();
if(!cw)
{
return ;
}
const QList<ChatWidgetHolder*> &chatWidgetHolderList = cw->chatWidgetHolderList();
foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList)
{
VOIPChatWidgetHolder *acwh = dynamic_cast<VOIPChatWidgetHolder*>(chatWidgetHolder) ;
if (acwh)
acwh->setAcceptedBandwidth(QString::fromStdString(peer_id.toStdString()),bytes_per_sec);
}
}

View File

@ -0,0 +1,44 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
// This class receives async-ed signals from the plugin notifier,
// and executes GUI requests.
//
// It is never called directly: it is called by Qt signal-received callback,
// in the main GUI thread.
//
#pragma once
#include <stdint.h>
#include <QObject>
class VOIPGUIHandler: public QObject
{
Q_OBJECT
public slots:
void ReceivedInvitation(const QString& peer_id) ;
void ReceivedVoipData(const QString& peer_id) ;
void ReceivedVoipHangUp(const QString& peer_id) ;
void ReceivedVoipAccept(const QString& peer_id) ;
void ReceivedVoipBandwidthInfo(const QString& peer_id,int) ;
};

View File

@ -0,0 +1,43 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "VOIPNotify.h"
void VOIPNotify::notifyReceivedVoipInvite(const RsPeerId& peer_id)
{
emit voipInvitationReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void VOIPNotify::notifyReceivedVoipData(const RsPeerId &peer_id)
{
emit voipDataReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void VOIPNotify::notifyReceivedVoipAccept(const RsPeerId& peer_id)
{
emit voipAcceptReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void VOIPNotify::notifyReceivedVoipHangUp(const RsPeerId &peer_id)
{
emit voipHangUpReceived(QString::fromStdString(peer_id.toStdString())) ;
}
void VOIPNotify::notifyReceivedVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
{
emit voipBandwidthInfoReceived(QString::fromStdString(peer_id.toStdString()),bytes_per_sec) ;
}

View File

@ -1,3 +1,24 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
// This class is a Qt object to get notification from the plugin's service threads,
// and responsible to pass the info the the GUI part.
//
@ -5,10 +26,12 @@
// QObject connect system to communicate between the p3Service and the gui part (handled by Qt)
//
#pragma once
#include <QObject>
#include <retroshare/rstypes.h>
class PluginNotifier: public QObject
class VOIPNotify: public QObject
{
Q_OBJECT

View File

@ -19,7 +19,7 @@ bool VideoEncoder::addImage(const QImage& img)
return true ;
}
bool VideoEncoder::nextPacket(RsVoipDataChunk& chunk)
bool VideoEncoder::nextPacket(RsVOIPDataChunk& chunk)
{
if(_out_queue.empty())
return false ;
@ -62,11 +62,11 @@ void JPEGVideoEncoder::encodeData(const QImage& image)
buffer.open(QIODevice::WriteOnly) ;
image.save(&buffer,"JPEG") ;
RsVoipDataChunk voip_chunk ;
RsVOIPDataChunk voip_chunk ;
voip_chunk.data = malloc(qb.size());
memcpy(voip_chunk.data,qb.data(),qb.size()) ;
voip_chunk.size = qb.size() ;
voip_chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
voip_chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
_out_queue.push_back(voip_chunk) ;
}

View File

@ -2,7 +2,7 @@
#include <stdint.h>
#include <QImage>
#include "interface/rsvoip.h"
#include "interface/rsVOIP.h"
class QVideoOutputDevice ;
@ -43,7 +43,7 @@ class VideoDecoder
};
// This class encodes video using a video codec (possibly homemade, or based on existing codecs)
// and produces a data stream that is sent to the network transfer service (e.g. p3VoRs).
// and produces a data stream that is sent to the network transfer service (e.g. p3VOIP).
//
class VideoEncoder
{
@ -55,7 +55,7 @@ class VideoEncoder
bool addImage(const QImage& Image) ;
bool packetReady() const { return !_out_queue.empty() ; }
bool nextPacket(RsVoipDataChunk& ) ;
bool nextPacket(RsVOIPDataChunk& ) ;
// Used to tweak the compression ratio so that the video can stream ok.
//
@ -65,7 +65,7 @@ class VideoEncoder
//virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ;
virtual void encodeData(const QImage& image) = 0 ;
std::list<RsVoipDataChunk> _out_queue ;
std::list<RsVOIPDataChunk> _out_queue ;
};
// Now derive various image encoding/decoding algorithms.

View File

@ -1,5 +1,5 @@
#ifndef AUDIODEVICEHELPER_H
#define AUDIODEVICEHELPER_H
#pragma once
#include <QAudioInput>
#include <QAudioOutput>
@ -15,5 +15,3 @@ public:
static QAudioOutput* getPreferedOutputDevice();
//static list getOutputDeviceList();
};
#endif // AUDIODEVICEHELPER_H

View File

@ -1,4 +1,25 @@
// interface class for p3Voip service
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
// interface class for p3VOIP service
//
#pragma once
@ -9,18 +30,18 @@
#include <vector>
#include <retroshare/rstypes.h>
class RsVoip ;
extern RsVoip *rsVoip;
class RsVOIP ;
extern RsVOIP *rsVOIP;
static const uint32_t CONFIG_TYPE_VOIP_PLUGIN = 0xe001 ;
class RsVoipPongResult
class RsVOIPPongResult
{
public:
RsVoipPongResult()
RsVOIPPongResult()
:mTS(0), mRTT(0), mOffset(0) { return; }
RsVoipPongResult(double ts, double rtt, double offset)
RsVOIPPongResult(double ts, double rtt, double offset)
:mTS(ts), mRTT(rtt), mOffset(offset) { return; }
double mTS;
@ -28,16 +49,16 @@ class RsVoipPongResult
double mOffset;
};
struct RsVoipDataChunk
struct RsVOIPDataChunk
{
typedef enum { RS_VOIP_DATA_TYPE_AUDIO, RS_VOIP_DATA_TYPE_VIDEO } RsVoipDataType ;
typedef enum { RS_VOIP_DATA_TYPE_AUDIO, RS_VOIP_DATA_TYPE_VIDEO } RsVOIPDataType ;
void *data ; // create/delete using malloc/free.
uint32_t size ;
RsVoipDataType type ; // video or audio
RsVOIPDataType type ; // video or audio
};
class RsVoip
class RsVOIP
{
public:
virtual int sendVoipHangUpCall(const RsPeerId& peer_id) = 0;
@ -45,12 +66,12 @@ class RsVoip
virtual int sendVoipAcceptCall(const RsPeerId& peer_id) = 0;
// Sending data. The client keeps the memory ownership and must delete it after calling this.
virtual int sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk) = 0;
virtual int sendVoipData(const RsPeerId& peer_id,const RsVOIPDataChunk& chunk) = 0;
// The server fill in the data and gives up memory ownership. The client must delete the memory
// in each chunk once it has been used.
//
virtual bool getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk>& chunks) = 0;
virtual bool getIncomingData(const RsPeerId& peer_id,std::vector<RsVOIPDataChunk>& chunks) = 0;
typedef enum { AudioTransmitContinous = 0, AudioTransmitVAD = 1, AudioTransmitPushToTalk = 2 } enumAudioTransmit ;
@ -71,7 +92,7 @@ class RsVoip
virtual bool getVoipEchoCancel() const = 0 ;
virtual void setVoipEchoCancel(bool) = 0 ;
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsVoipPongResult> &results) = 0;
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsVOIPPongResult> &results) = 0;
};

View File

@ -1,27 +1,23 @@
/*
* libretroshare/src/services p3vors.cc
/****************************************************************
* RetroShare is distributed under the following license:
*
* Voice Over Retroshare Service for RetroShare.
* Copyright (C) 2015
*
* Copyright 2011-2011 by Robert Fernie.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "util/rsdir.h"
#include "retroshare/rsiface.h"
@ -33,23 +29,23 @@
#include <sstream> // for std::istringstream
#include "services/p3vors.h"
#include "services/rsvoipitems.h"
#include "gui/PluginNotifier.h"
#include "services/p3VOIP.h"
#include "services/rsVOIPItems.h"
#include "gui/VOIPNotify.h"
#include <sys/time.h>
/****
* #define DEBUG_VORS 1
* #define DEBUG_VOIP 1
****/
/* DEFINE INTERFACE POINTER! */
RsVoip *rsVoip = NULL;
RsVOIP *rsVOIP = NULL;
#define MAX_PONG_RESULTS 150
#define VORS_PING_PERIOD 10
#define VORS_BANDWIDTH_PERIOD 5
#define VOIP_PING_PERIOD 10
#define VOIP_BANDWIDTH_PERIOD 5
/************ IMPLEMENTATION NOTES *********************************
*
@ -116,10 +112,10 @@ static double convert64bitsToTs(uint64_t bits)
return ts;
}
p3VoRS::p3VoRS(RsPluginHandler *handler,PluginNotifier *notifier)
: RsPQIService(RS_SERVICE_TYPE_VOIP_PLUGIN,0,handler), mVorsMtx("p3VoRS"), mServiceControl(handler->getServiceControl()) , mNotify(notifier)
p3VOIP::p3VOIP(RsPluginHandler *handler,VOIPNotify *notifier)
: RsPQIService(RS_SERVICE_TYPE_VOIP_PLUGIN,0,handler), mVOIPMtx("p3VOIP"), mServiceControl(handler->getServiceControl()) , mNotify(notifier)
{
addSerialType(new RsVoipSerialiser());
addSerialType(new RsVOIPSerialiser());
mSentPingTime = 0;
mSentBandwidthInfoTime = 0;
@ -135,7 +131,7 @@ p3VoRS::p3VoRS(RsPluginHandler *handler,PluginNotifier *notifier)
_echo_cancel = true;
}
RsServiceInfo p3VoRS::getServiceInfo()
RsServiceInfo p3VOIP::getServiceInfo()
{
const std::string TURTLE_APP_NAME = "VOIP";
const uint16_t TURTLE_APP_MAJOR_VERSION = 1;
@ -151,10 +147,10 @@ RsServiceInfo p3VoRS::getServiceInfo()
TURTLE_MIN_MINOR_VERSION);
}
int p3VoRS::tick()
int p3VOIP::tick()
{
#ifdef DEBUG_VORS
std::cerr << "ticking p3VoRS" << std::endl;
#ifdef DEBUG_VOIP
std::cerr << "ticking p3VOIP" << std::endl;
#endif
//processIncoming();
@ -163,48 +159,48 @@ int p3VoRS::tick()
return 0;
}
int p3VoRS::status()
int p3VOIP::status()
{
return 1;
}
int p3VoRS::sendPackets()
int p3VOIP::sendPackets()
{
time_t now = time(NULL);
time_t pt;
time_t pt2;
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
pt = mSentPingTime;
pt2 = mSentBandwidthInfoTime;
}
if (now > pt + VORS_PING_PERIOD)
if (now > pt + VOIP_PING_PERIOD)
{
sendPingMeasurements();
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
mSentPingTime = now;
}
if (now > pt2 + VORS_BANDWIDTH_PERIOD)
if (now > pt2 + VOIP_BANDWIDTH_PERIOD)
{
sendBandwidthInfo();
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
mSentBandwidthInfoTime = now;
}
return true ;
}
void p3VoRS::sendBandwidthInfo()
void p3VOIP::sendBandwidthInfo()
{
std::set<RsPeerId> onlineIds;
mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds);
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
for(std::map<RsPeerId,VorsPeerInfo>::iterator it(mPeerInfo.begin());it!=mPeerInfo.end();++it)
for(std::map<RsPeerId,VOIPPeerInfo>::iterator it(mPeerInfo.begin());it!=mPeerInfo.end();++it)
{
it->second.average_incoming_bandwidth = 0.75 * it->second.average_incoming_bandwidth + 0.25 * it->second.total_bytes_received / VORS_BANDWIDTH_PERIOD ;
it->second.average_incoming_bandwidth = 0.75 * it->second.average_incoming_bandwidth + 0.25 * it->second.total_bytes_received / VOIP_BANDWIDTH_PERIOD ;
it->second.total_bytes_received = 0 ;
if(onlineIds.find(it->first) == onlineIds.end() || it->second.average_incoming_bandwidth == 0)
@ -215,11 +211,11 @@ void p3VoRS::sendBandwidthInfo()
}
}
int p3VoRS::sendVoipHangUpCall(const RsPeerId &peer_id)
int p3VOIP::sendVoipHangUpCall(const RsPeerId &peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Close;
item->protocol = RsVOIPProtocolItem::VoipProtocol_Close;
item->flags = 0 ;
item->PeerId(peer_id) ;
@ -227,11 +223,11 @@ int p3VoRS::sendVoipHangUpCall(const RsPeerId &peer_id)
return true ;
}
int p3VoRS::sendVoipAcceptCall(const RsPeerId& peer_id)
int p3VOIP::sendVoipAcceptCall(const RsPeerId& peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Ackn ;
item->protocol = RsVOIPProtocolItem::VoipProtocol_Ackn ;
item->flags = 0 ;
item->PeerId(peer_id) ;
@ -239,11 +235,11 @@ int p3VoRS::sendVoipAcceptCall(const RsPeerId& peer_id)
return true ;
}
int p3VoRS::sendVoipRinging(const RsPeerId &peer_id)
int p3VOIP::sendVoipRinging(const RsPeerId &peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Ring ;
item->protocol = RsVOIPProtocolItem::VoipProtocol_Ring ;
item->flags = 0 ;
item->PeerId(peer_id) ;
@ -251,11 +247,11 @@ int p3VoRS::sendVoipRinging(const RsPeerId &peer_id)
return true ;
}
int p3VoRS::sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
int p3VOIP::sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Bandwidth ;
item->protocol = RsVOIPProtocolItem::VoipProtocol_Bandwidth ;
item->flags = bytes_per_sec ;
item->PeerId(peer_id) ;
@ -263,24 +259,24 @@ int p3VoRS::sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
return true ;
}
int p3VoRS::sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk)
int p3VOIP::sendVoipData(const RsPeerId& peer_id,const RsVOIPDataChunk& chunk)
{
#ifdef DEBUG_VORS
#ifdef DEBUG_VOIP
std::cerr << "Sending " << chunk.size << " bytes of voip data." << std::endl;
#endif
RsVoipDataItem *item = new RsVoipDataItem ;
RsVOIPDataItem *item = new RsVOIPDataItem ;
if(!item)
{
std::cerr << "Cannot allocate RsVoipDataItem !" << std::endl;
std::cerr << "Cannot allocate RsVOIPDataItem !" << std::endl;
return false ;
}
item->voip_data = malloc(chunk.size) ;
if(item->voip_data == NULL)
{
std::cerr << "Cannot allocate RsVoipDataItem.voip_data of size " << chunk.size << " !" << std::endl;
std::cerr << "Cannot allocate RsVOIPDataItem.voip_data of size " << chunk.size << " !" << std::endl;
delete item ;
return false ;
}
@ -288,13 +284,13 @@ int p3VoRS::sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk)
item->PeerId(peer_id) ;
item->data_size = chunk.size;
if(chunk.type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
if(chunk.type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
item->flags = RS_VOIP_FLAGS_AUDIO_DATA ;
else if(chunk.type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
else if(chunk.type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
item->flags = RS_VOIP_FLAGS_VIDEO_DATA ;
else
{
std::cerr << "(EE) p3VoRs: cannot send chunk data. Unknown data type = " << chunk.type << std::endl;
std::cerr << "(EE) p3VOIP: cannot send chunk data. Unknown data type = " << chunk.type << std::endl;
delete item ;
return false ;
}
@ -304,7 +300,7 @@ int p3VoRS::sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk)
return true ;
}
void p3VoRS::sendPingMeasurements()
void p3VOIP::sendPingMeasurements()
{
/* we ping our peers */
/* who is online? */
@ -316,8 +312,8 @@ void p3VoRS::sendPingMeasurements()
double ts = getCurrentTS();
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::sendPingMeasurements() @ts: " << ts;
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::sendPingMeasurements() @ts: " << ts;
std::cerr << std::endl;
#endif
@ -325,21 +321,21 @@ void p3VoRS::sendPingMeasurements()
std::set<RsPeerId>::iterator it;
for(it = onlineIds.begin(); it != onlineIds.end(); it++)
{
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::sendPingMeasurements() Pinging: " << *it;
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::sendPingMeasurements() Pinging: " << *it;
std::cerr << std::endl;
#endif
/* create the packet */
RsVoipPingItem *pingPkt = new RsVoipPingItem();
RsVOIPPingItem *pingPkt = new RsVOIPPingItem();
pingPkt->PeerId(*it);
pingPkt->mSeqNo = mCounter;
pingPkt->mPingTS = convertTsTo64bits(ts);
storePingAttempt(*it, ts, mCounter);
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::sendPingMeasurements() With Packet:";
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::sendPingMeasurements() With Packet:";
std::cerr << std::endl;
pingPkt->print(std::cerr, 10);
#endif
@ -347,55 +343,55 @@ void p3VoRS::sendPingMeasurements()
sendItem(pingPkt);
}
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
mCounter++;
}
void p3VoRS::handleProtocol(RsVoipProtocolItem *item)
void p3VOIP::handleProtocol(RsVOIPProtocolItem *item)
{
// should we keep a list of received requests?
switch(item->protocol)
{
case RsVoipProtocolItem::VoipProtocol_Ring: mNotify->notifyReceivedVoipInvite(item->PeerId());
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol ring item." << std::endl;
case RsVOIPProtocolItem::VoipProtocol_Ring: mNotify->notifyReceivedVoipInvite(item->PeerId());
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handleProtocol(): Received protocol ring item." << std::endl;
#endif
break ;
case RsVoipProtocolItem::VoipProtocol_Ackn: mNotify->notifyReceivedVoipAccept(item->PeerId());
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol accept call" << std::endl;
case RsVOIPProtocolItem::VoipProtocol_Ackn: mNotify->notifyReceivedVoipAccept(item->PeerId());
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handleProtocol(): Received protocol accept call" << std::endl;
#endif
break ;
case RsVoipProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId());
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol Close call." << std::endl;
case RsVOIPProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId());
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handleProtocol(): Received protocol Close call." << std::endl;
#endif
break ;
case RsVoipProtocolItem::VoipProtocol_Bandwidth: mNotify->notifyReceivedVoipBandwidth(item->PeerId(),(uint32_t)item->flags);
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl;
case RsVOIPProtocolItem::VoipProtocol_Bandwidth: mNotify->notifyReceivedVoipBandwidth(item->PeerId(),(uint32_t)item->flags);
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl;
#endif
break ;
default:
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl;
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl;
#endif
break ;
}
}
void p3VoRS::handleData(RsVoipDataItem *item)
void p3VOIP::handleData(RsVOIPDataItem *item)
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
// store the data in a queue.
std::map<RsPeerId,VorsPeerInfo>::iterator it = mPeerInfo.find(item->PeerId()) ;
std::map<RsPeerId,VOIPPeerInfo>::iterator it = mPeerInfo.find(item->PeerId()) ;
if(it == mPeerInfo.end())
{
@ -413,33 +409,33 @@ void p3VoRS::handleData(RsVoipDataItem *item)
mNotify->notifyReceivedVoipData(item->PeerId());
}
bool p3VoRS::getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk>& incoming_data_chunks)
bool p3VOIP::getIncomingData(const RsPeerId& peer_id,std::vector<RsVOIPDataChunk>& incoming_data_chunks)
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
incoming_data_chunks.clear() ;
std::map<RsPeerId,VorsPeerInfo>::iterator it = mPeerInfo.find(peer_id) ;
std::map<RsPeerId,VOIPPeerInfo>::iterator it = mPeerInfo.find(peer_id) ;
if(it == mPeerInfo.end())
{
std::cerr << "Peer unknown to VOIP process. No data returned. Probably a bug !" << std::endl;
return false ;
}
for(std::list<RsVoipDataItem*>::const_iterator it2(it->second.incoming_queue.begin());it2!=it->second.incoming_queue.end();++it2)
for(std::list<RsVOIPDataItem*>::const_iterator it2(it->second.incoming_queue.begin());it2!=it->second.incoming_queue.end();++it2)
{
RsVoipDataChunk chunk ;
RsVOIPDataChunk chunk ;
chunk.size = (*it2)->data_size ;
chunk.data = malloc((*it2)->data_size) ;
uint32_t type_flags = (*it2)->flags & (RS_VOIP_FLAGS_AUDIO_DATA | RS_VOIP_FLAGS_VIDEO_DATA) ;
if(type_flags == RS_VOIP_FLAGS_AUDIO_DATA)
chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
else if(type_flags == RS_VOIP_FLAGS_VIDEO_DATA)
chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
else
{
std::cerr << "(EE) p3VoRS::getIncomingData(): error. Cannot handle item with unknown type " << type_flags << std::endl;
std::cerr << "(EE) p3VOIP::getIncomingData(): error. Cannot handle item with unknown type " << type_flags << std::endl;
delete *it2 ;
free(chunk.data) ;
continue ;
@ -457,7 +453,7 @@ bool p3VoRS::getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk
return true ;
}
bool p3VoRS::recvItem(RsItem *item)
bool p3VOIP::recvItem(RsItem *item)
{
/* pass to specific handler */
bool keep = false ;
@ -465,19 +461,19 @@ bool p3VoRS::recvItem(RsItem *item)
switch(item->PacketSubType())
{
case RS_PKT_SUBTYPE_VOIP_PING:
handlePing(dynamic_cast<RsVoipPingItem*>(item));
handlePing(dynamic_cast<RsVOIPPingItem*>(item));
break;
case RS_PKT_SUBTYPE_VOIP_PONG:
handlePong(dynamic_cast<RsVoipPongItem*>(item));
handlePong(dynamic_cast<RsVOIPPongItem*>(item));
break;
case RS_PKT_SUBTYPE_VOIP_PROTOCOL:
handleProtocol(dynamic_cast<RsVoipProtocolItem*>(item)) ;
handleProtocol(dynamic_cast<RsVOIPProtocolItem*>(item)) ;
break ;
case RS_PKT_SUBTYPE_VOIP_DATA:
handleData(dynamic_cast<RsVoipDataItem*>(item));
handleData(dynamic_cast<RsVOIPDataItem*>(item));
keep = true ;
break;
#if 0
@ -500,17 +496,17 @@ bool p3VoRS::recvItem(RsItem *item)
return true ;
}
int p3VoRS::handlePing(RsVoipPingItem *ping)
int p3VOIP::handlePing(RsVOIPPingItem *ping)
{
/* cast to right type */
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handlePing() Recvd Packet from: " << ping->PeerId();
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handlePing() Recvd Packet from: " << ping->PeerId();
std::cerr << std::endl;
#endif
/* with a ping, we just respond as quickly as possible - they do all the analysis */
RsVoipPongItem *pong = new RsVoipPongItem();
RsVOIPPongItem *pong = new RsVOIPPongItem();
pong->PeerId(ping->PeerId());
@ -522,8 +518,8 @@ int p3VoRS::handlePing(RsVoipPingItem *ping)
pong->mPongTS = convertTsTo64bits(ts);
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handlePing() With Packet:";
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handlePing() With Packet:";
std::cerr << std::endl;
pong->print(std::cerr, 10);
#endif
@ -533,12 +529,12 @@ int p3VoRS::handlePing(RsVoipPingItem *ping)
}
int p3VoRS::handlePong(RsVoipPongItem *pong)
int p3VOIP::handlePong(RsVOIPPongItem *pong)
{
/* cast to right type */
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handlePong() Recvd Packet from: " << pong->PeerId();
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handlePong() Recvd Packet from: " << pong->PeerId();
std::cerr << std::endl;
pong->print(std::cerr, 10);
#endif
@ -551,8 +547,8 @@ int p3VoRS::handlePong(RsVoipPongItem *pong)
double rtt = recvTS - pingTS;
double offset = pongTS - (recvTS - rtt / 2.0); // so to get to their time, we go ourTS + offset.
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::handlePong() Timing:";
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::handlePong() Timing:";
std::cerr << std::endl;
std::cerr << "\tpingTS: " << pingTS;
std::cerr << std::endl;
@ -570,12 +566,12 @@ int p3VoRS::handlePong(RsVoipPongItem *pong)
return true ;
}
int p3VoRS::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno)
int p3VOIP::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno)
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
/* find corresponding local data */
VorsPeerInfo *peerInfo = locked_GetPeerInfo(id);
VOIPPeerInfo *peerInfo = locked_GetPeerInfo(id);
peerInfo->mCurrentPingTS = ts;
peerInfo->mCurrentPingCounter = seqno;
@ -593,17 +589,17 @@ int p3VoRS::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno)
int p3VoRS::storePongResult(const RsPeerId &id, uint32_t counter, double ts, double rtt, double offset)
int p3VOIP::storePongResult(const RsPeerId &id, uint32_t counter, double ts, double rtt, double offset)
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
/* find corresponding local data */
VorsPeerInfo *peerInfo = locked_GetPeerInfo(id);
VOIPPeerInfo *peerInfo = locked_GetPeerInfo(id);
if (peerInfo->mCurrentPingCounter != counter)
{
#ifdef DEBUG_VORS
std::cerr << "p3VoRS::storePongResult() ERROR Severly Delayed Measurements!" << std::endl;
#ifdef DEBUG_VOIP
std::cerr << "p3VOIP::storePongResult() ERROR Severly Delayed Measurements!" << std::endl;
#endif
}
else
@ -611,7 +607,7 @@ int p3VoRS::storePongResult(const RsPeerId &id, uint32_t counter, double ts, dou
peerInfo->mCurrentPongRecvd = true;
}
peerInfo->mPongResults.push_back(RsVoipPongResult(ts, rtt, offset));
peerInfo->mPongResults.push_back(RsVOIPPongResult(ts, rtt, offset));
while(peerInfo->mPongResults.size() > MAX_PONG_RESULTS)
@ -624,13 +620,13 @@ int p3VoRS::storePongResult(const RsPeerId &id, uint32_t counter, double ts, dou
}
uint32_t p3VoRS::getPongResults(const RsPeerId& id, int n, std::list<RsVoipPongResult> &results)
uint32_t p3VOIP::getPongResults(const RsPeerId& id, int n, std::list<RsVOIPPongResult> &results)
{
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
VorsPeerInfo *peer = locked_GetPeerInfo(id);
VOIPPeerInfo *peer = locked_GetPeerInfo(id);
std::list<RsVoipPongResult>::reverse_iterator it;
std::list<RsVOIPPongResult>::reverse_iterator it;
int i = 0;
for(it = peer->mPongResults.rbegin(); (it != peer->mPongResults.rend()) && (i < n); it++, i++)
{
@ -642,14 +638,14 @@ uint32_t p3VoRS::getPongResults(const RsPeerId& id, int n, std::list<RsVoipPongR
VorsPeerInfo *p3VoRS::locked_GetPeerInfo(const RsPeerId &id)
VOIPPeerInfo *p3VOIP::locked_GetPeerInfo(const RsPeerId &id)
{
std::map<RsPeerId, VorsPeerInfo>::iterator it;
std::map<RsPeerId, VOIPPeerInfo>::iterator it;
it = mPeerInfo.find(id);
if (it == mPeerInfo.end())
{
/* add it in */
VorsPeerInfo pinfo;
VOIPPeerInfo pinfo;
/* initialise entry */
pinfo.initialisePeerInfo(id);
@ -662,7 +658,7 @@ VorsPeerInfo *p3VoRS::locked_GetPeerInfo(const RsPeerId &id)
return &(it->second);
}
bool VorsPeerInfo::initialisePeerInfo(const RsPeerId& id)
bool VOIPPeerInfo::initialisePeerInfo(const RsPeerId& id)
{
mId = id;
@ -681,43 +677,43 @@ bool VorsPeerInfo::initialisePeerInfo(const RsPeerId& id)
return true;
}
void p3VoRS::setVoipATransmit(int t)
void p3VOIP::setVoipATransmit(int t)
{
_atransmit = t ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipVoiceHold(int vh)
void p3VOIP::setVoipVoiceHold(int vh)
{
_voice_hold = vh ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipfVADmin(int vad)
void p3VOIP::setVoipfVADmin(int vad)
{
_vadmin = vad ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipfVADmax(int vad)
void p3VOIP::setVoipfVADmax(int vad)
{
_vadmax = vad ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipiNoiseSuppress(int n)
void p3VOIP::setVoipiNoiseSuppress(int n)
{
_noise_suppress = n ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipiMinLoudness(int ml)
void p3VOIP::setVoipiMinLoudness(int ml)
{
_min_loudness = ml ;
IndicateConfigChanged() ;
}
void p3VoRS::setVoipEchoCancel(bool b)
void p3VOIP::setVoipEchoCancel(bool b)
{
_echo_cancel = b ;
IndicateConfigChanged() ;
}
RsTlvKeyValue p3VoRS::push_int_value(const std::string& key,int value)
RsTlvKeyValue p3VOIP::push_int_value(const std::string& key,int value)
{
RsTlvKeyValue kv ;
kv.key = key ;
@ -725,7 +721,7 @@ RsTlvKeyValue p3VoRS::push_int_value(const std::string& key,int value)
return kv ;
}
int p3VoRS::pop_int_value(const std::string& s)
int p3VOIP::pop_int_value(const std::string& s)
{
std::istringstream is(s) ;
@ -735,7 +731,7 @@ int p3VoRS::pop_int_value(const std::string& s)
return val ;
}
bool p3VoRS::saveList(bool& cleanup, std::list<RsItem*>& lst)
bool p3VOIP::saveList(bool& cleanup, std::list<RsItem*>& lst)
{
cleanup = true ;
@ -753,7 +749,7 @@ bool p3VoRS::saveList(bool& cleanup, std::list<RsItem*>& lst)
return true ;
}
bool p3VoRS::loadList(std::list<RsItem*>& load)
bool p3VOIP::loadList(std::list<RsItem*>& load)
{
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
{
@ -785,10 +781,10 @@ bool p3VoRS::loadList(std::list<RsItem*>& load)
return true ;
}
RsSerialiser *p3VoRS::setupSerialiser()
RsSerialiser *p3VOIP::setupSerialiser()
{
RsSerialiser *rsSerialiser = new RsSerialiser();
rsSerialiser->addSerialType(new RsVoipSerialiser());
rsSerialiser->addSerialType(new RsVOIPSerialiser());
rsSerialiser->addSerialType(new RsGeneralConfigSerialiser());
return rsSerialiser ;

View File

@ -1,46 +1,40 @@
/*
* libretroshare/src/services/p3vors.h
/****************************************************************
* RetroShare is distributed under the following license:
*
* Tests for VoIP for RetroShare.
* Copyright (C) 2015
*
* Copyright 2011 by Robert Fernie.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef SERVICE_RSVOIP_HEADER
#define SERVICE_RSVOIP_HEADER
#pragma once
#include <list>
#include <string>
#include "services/rsvoipitems.h"
#include "services/rsVOIPItems.h"
#include "services/p3service.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rsconfigitems.h"
#include "plugins/rspqiservice.h"
#include <interface/rsvoip.h>
#include <interface/rsVOIP.h>
class p3LinkMgr;
class PluginNotifier ;
class VOIPNotify ;
class VorsPeerInfo
class VOIPPeerInfo
{
public:
@ -56,8 +50,8 @@ class VorsPeerInfo
uint32_t total_bytes_received ;
uint32_t average_incoming_bandwidth ;
std::list<RsVoipPongResult> mPongResults;
std::list<RsVoipDataItem*> incoming_queue ;
std::list<RsVOIPPongResult> mPongResults;
std::list<RsVOIPDataItem*> incoming_queue ;
};
@ -67,27 +61,27 @@ class VorsPeerInfo
* This is only used to test Latency for the moment.
*/
class p3VoRS: public RsPQIService, public RsVoip
class p3VOIP: public RsPQIService, public RsVOIP
// Maybe we inherit from these later - but not needed for now.
//, public p3Config, public pqiMonitor
{
public:
p3VoRS(RsPluginHandler *cm,PluginNotifier *);
p3VOIP(RsPluginHandler *cm,VOIPNotify *);
/***** overloaded from rsVoip *****/
/***** overloaded from rsVOIP *****/
virtual uint32_t getPongResults(const RsPeerId &id, int n, std::list<RsVoipPongResult> &results);
virtual uint32_t getPongResults(const RsPeerId &id, int n, std::list<RsVOIPPongResult> &results);
// Call stuff.
//
// Sending data. The client keeps the memory ownership and must delete it after calling this.
virtual int sendVoipData(const RsPeerId &peer_id,const RsVoipDataChunk& chunk) ;
virtual int sendVoipData(const RsPeerId &peer_id,const RsVOIPDataChunk& chunk) ;
// The server fill in the data and gives up memory ownership. The client must delete the memory
// in each chunk once it has been used.
//
virtual bool getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk>& chunks) ;
virtual bool getIncomingData(const RsPeerId& peer_id,std::vector<RsVOIPDataChunk>& chunks) ;
virtual int sendVoipHangUpCall(const RsPeerId& peer_id) ;
virtual int sendVoipRinging(const RsPeerId& peer_id) ;
@ -142,29 +136,29 @@ class p3VoRS: public RsPQIService, public RsVoip
int sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ;
int handlePing(RsVoipPingItem *item);
int handlePong(RsVoipPongItem *item);
int handlePing(RsVOIPPingItem *item);
int handlePong(RsVOIPPongItem *item);
int storePingAttempt(const RsPeerId &id, double ts, uint32_t mCounter);
int storePongResult(const RsPeerId& id, uint32_t counter, double ts, double rtt, double offset);
void handleProtocol(RsVoipProtocolItem*) ;
void handleData(RsVoipDataItem*) ;
void handleProtocol(RsVOIPProtocolItem*) ;
void handleData(RsVOIPDataItem*) ;
RsMutex mVorsMtx;
RsMutex mVOIPMtx;
VorsPeerInfo *locked_GetPeerInfo(const RsPeerId& id);
VOIPPeerInfo *locked_GetPeerInfo(const RsPeerId& id);
static RsTlvKeyValue push_int_value(const std::string& key,int value) ;
static int pop_int_value(const std::string& s) ;
std::map<RsPeerId, VorsPeerInfo> mPeerInfo;
std::map<RsPeerId, VOIPPeerInfo> mPeerInfo;
time_t mSentPingTime;
time_t mSentBandwidthInfoTime;
uint32_t mCounter;
RsServiceControl *mServiceControl;
PluginNotifier *mNotify ;
VOIPNotify *mNotify ;
int _atransmit ;
int _voice_hold ;
@ -174,6 +168,3 @@ class p3VoRS: public RsPQIService, public RsVoip
int _noise_suppress ;
bool _echo_cancel ;
};
#endif // SERVICE_RSVOIP_HEADER

View File

@ -1,34 +1,29 @@
/*
* libretroshare/src/serialiser: rsvoipitems.cc
/****************************************************************
* RetroShare is distributed under the following license:
*
* RetroShare Serialiser.
* Copyright (C) 2015
*
* Copyright 2011 by Robert Fernie.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <stdexcept>
#include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h"
#include "services/rsvoipitems.h"
#include "services/rsVOIPItems.h"
/***
#define RSSERIAL_DEBUG 1
@ -38,9 +33,9 @@
/*************************************************************************/
std::ostream& RsVoipPingItem::print(std::ostream &out, uint16_t indent)
std::ostream& RsVOIPPingItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsVoipPingItem", indent);
printRsItemBase(out, "RsVOIPPingItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
@ -48,13 +43,13 @@ std::ostream& RsVoipPingItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent);
out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl;
printRsItemEnd(out, "RsVoipPingItem", indent);
printRsItemEnd(out, "RsVOIPPingItem", indent);
return out;
}
std::ostream& RsVoipPongItem::print(std::ostream &out, uint16_t indent)
std::ostream& RsVOIPPongItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsVoipPongItem", indent);
printRsItemBase(out, "RsVOIPPongItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "SeqNo: " << mSeqNo << std::endl;
@ -65,12 +60,12 @@ std::ostream& RsVoipPongItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent);
out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl;
printRsItemEnd(out, "RsVoipPongItem", indent);
printRsItemEnd(out, "RsVOIPPongItem", indent);
return out;
}
std::ostream& RsVoipProtocolItem::print(std::ostream &out, uint16_t indent)
std::ostream& RsVOIPProtocolItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsVoipProtocolItem", indent);
printRsItemBase(out, "RsVOIPProtocolItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "flags: " << flags << std::endl;
@ -78,12 +73,12 @@ std::ostream& RsVoipProtocolItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent);
out << "protocol: " << std::hex << protocol << std::dec << std::endl;
printRsItemEnd(out, "RsVoipProtocolItem", indent);
printRsItemEnd(out, "RsVOIPProtocolItem", indent);
return out;
}
std::ostream& RsVoipDataItem::print(std::ostream &out, uint16_t indent)
std::ostream& RsVOIPDataItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsVoipDataItem", indent);
printRsItemBase(out, "RsVOIPDataItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "flags: " << flags << std::endl;
@ -91,12 +86,12 @@ std::ostream& RsVoipDataItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent);
out << "data size: " << std::hex << data_size << std::dec << std::endl;
printRsItemEnd(out, "RsVoipDataItem", indent);
printRsItemEnd(out, "RsVOIPDataItem", indent);
return out;
}
/*************************************************************************/
uint32_t RsVoipDataItem::serial_size() const
uint32_t RsVOIPDataItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4; /* flags */
@ -105,7 +100,7 @@ uint32_t RsVoipDataItem::serial_size() const
return s;
}
uint32_t RsVoipProtocolItem::serial_size() const
uint32_t RsVOIPProtocolItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4; /* flags */
@ -113,7 +108,7 @@ uint32_t RsVoipProtocolItem::serial_size() const
return s;
}
uint32_t RsVoipPingItem::serial_size() const
uint32_t RsVOIPPingItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
@ -121,7 +116,7 @@ uint32_t RsVoipPingItem::serial_size() const
return s;
}
bool RsVoipProtocolItem::serialise(void *data, uint32_t& pktsize)
bool RsVOIPProtocolItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
@ -136,8 +131,8 @@ bool RsVoipProtocolItem::serialise(void *data, uint32_t& pktsize)
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Header: " << ok << std::endl;
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Size: " << tlvsize << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
@ -150,13 +145,13 @@ bool RsVoipProtocolItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
}
return ok;
}
/* serialise the data to the buffer */
bool RsVoipDataItem::serialise(void *data, uint32_t& pktsize)
bool RsVOIPDataItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
@ -171,8 +166,8 @@ bool RsVoipDataItem::serialise(void *data, uint32_t& pktsize)
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Header: " << ok << std::endl;
std::cerr << "RsVoipSerialiser::serialiseVoipDataItem() Size: " << tlvsize << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Header: " << ok << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPDataItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
@ -188,13 +183,13 @@ bool RsVoipDataItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
}
return ok;
}
/* serialise the data to the buffer */
bool RsVoipPingItem::serialise(void *data, uint32_t& pktsize)
bool RsVOIPPingItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
@ -209,8 +204,8 @@ bool RsVoipPingItem::serialise(void *data, uint32_t& pktsize)
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Header: " << ok << std::endl;
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size: " << tlvsize << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Header: " << ok << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
@ -223,14 +218,14 @@ bool RsVoipPingItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsVoipSerialiser::serialiseVoipPingItem() Size Error! " << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPingItem() Size Error! " << std::endl;
}
return ok;
}
RsVoipProtocolItem::RsVoipProtocolItem(void *data, uint32_t pktsize)
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL)
RsVOIPProtocolItem::RsVOIPProtocolItem(void *data, uint32_t pktsize)
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -259,8 +254,8 @@ RsVoipProtocolItem::RsVoipProtocolItem(void *data, uint32_t pktsize)
if (!ok)
throw std::runtime_error("Deserialisation error!") ;
}
RsVoipPingItem::RsVoipPingItem(void *data, uint32_t pktsize)
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_PING)
RsVOIPPingItem::RsVOIPPingItem(void *data, uint32_t pktsize)
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -295,7 +290,7 @@ RsVoipPingItem::RsVoipPingItem(void *data, uint32_t pktsize)
/*************************************************************************/
uint32_t RsVoipPongItem::serial_size() const
uint32_t RsVOIPPongItem::serial_size() const
{
uint32_t s = 8; /* header */
s += 4; /* seqno */
@ -306,7 +301,7 @@ uint32_t RsVoipPongItem::serial_size() const
}
/* serialise the data to the buffer */
bool RsVoipPongItem::serialise(void *data, uint32_t& pktsize)
bool RsVOIPPongItem::serialise(void *data, uint32_t& pktsize)
{
uint32_t tlvsize = serial_size() ;
uint32_t offset = 0;
@ -321,8 +316,8 @@ bool RsVoipPongItem::serialise(void *data, uint32_t& pktsize)
ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Header: " << ok << std::endl;
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Size: " << tlvsize << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Header: " << ok << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
@ -336,13 +331,13 @@ bool RsVoipPongItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsVoipSerialiser::serialiseVoipPongItem() Size Error! " << std::endl;
std::cerr << "RsVOIPSerialiser::serialiseVOIPPongItem() Size Error! " << std::endl;
}
return ok;
}
RsVoipDataItem::RsVoipDataItem(void *data, uint32_t pktsize)
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_DATA)
RsVOIPDataItem::RsVOIPDataItem(void *data, uint32_t pktsize)
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -375,8 +370,8 @@ RsVoipDataItem::RsVoipDataItem(void *data, uint32_t pktsize)
if (!ok)
throw std::runtime_error("Serialization error.") ;
}
RsVoipPongItem::RsVoipPongItem(void *data, uint32_t pktsize)
: RsVoipItem(RS_PKT_SUBTYPE_VOIP_PONG)
RsVOIPPongItem::RsVOIPPongItem(void *data, uint32_t pktsize)
: RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
@ -409,10 +404,10 @@ RsVoipPongItem::RsVoipPongItem(void *data, uint32_t pktsize)
/*************************************************************************/
RsItem* RsVoipSerialiser::deserialise(void *data, uint32_t *pktsize)
RsItem* RsVOIPSerialiser::deserialise(void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsVoipSerialiser::deserialise()" << std::endl;
std::cerr << "RsVOIPSerialiser::deserialise()" << std::endl;
#endif
/* get the type and size */
@ -425,10 +420,10 @@ RsItem* RsVoipSerialiser::deserialise(void *data, uint32_t *pktsize)
{
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_VOIP_PING: return new RsVoipPingItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_PONG: return new RsVoipPongItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_PROTOCOL: return new RsVoipProtocolItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_DATA: return new RsVoipDataItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_PING: return new RsVOIPPingItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_PONG: return new RsVOIPPongItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_PROTOCOL: return new RsVOIPProtocolItem(data, *pktsize);
case RS_PKT_SUBTYPE_VOIP_DATA: return new RsVOIPDataItem(data, *pktsize);
default:
return NULL;
@ -436,7 +431,7 @@ RsItem* RsVoipSerialiser::deserialise(void *data, uint32_t *pktsize)
}
catch(std::exception& e)
{
std::cerr << "RsVoipSerialiser: deserialization error: " << e.what() << std::endl;
std::cerr << "RsVOIPSerialiser: deserialization error: " << e.what() << std::endl;
return NULL;
}
}

View File

@ -1,8 +1,28 @@
#ifndef RS_VOIP_ITEMS_H
#define RS_VOIP_ITEMS_H
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2015
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#pragma once
/*
* libretroshare/src/serialiser: rsvoipitems.h
* libretroshare/src/serialiser: rsVOIPItems.h
*
* RetroShare Serialiser.
*
@ -46,16 +66,16 @@ const uint8_t QOS_PRIORITY_RS_VOIP = 9 ;
const uint32_t RS_VOIP_FLAGS_VIDEO_DATA = 0x0001 ;
const uint32_t RS_VOIP_FLAGS_AUDIO_DATA = 0x0002 ;
class RsVoipItem: public RsItem
class RsVOIPItem: public RsItem
{
public:
RsVoipItem(uint8_t voip_subtype)
RsVOIPItem(uint8_t voip_subtype)
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_VOIP_PLUGIN,voip_subtype)
{
setPriorityLevel(QOS_PRIORITY_RS_VOIP) ;
}
virtual ~RsVoipItem() {};
virtual ~RsVOIPItem() {};
virtual void clear() {};
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
@ -63,32 +83,32 @@ class RsVoipItem: public RsItem
virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor
};
class RsVoipPingItem: public RsVoipItem
class RsVOIPPingItem: public RsVOIPItem
{
public:
RsVoipPingItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PING) {}
RsVoipPingItem(void *data,uint32_t size) ;
RsVOIPPingItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PING) {}
RsVOIPPingItem(void *data,uint32_t size) ;
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ;
virtual ~RsVoipPingItem() {}
virtual ~RsVOIPPingItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
uint32_t mSeqNo;
uint64_t mPingTS;
};
class RsVoipDataItem: public RsVoipItem
class RsVOIPDataItem: public RsVOIPItem
{
public:
RsVoipDataItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_DATA) {}
RsVoipDataItem(void *data,uint32_t size) ; // de-serialization
RsVOIPDataItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_DATA) {}
RsVOIPDataItem(void *data,uint32_t size) ; // de-serialization
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ;
virtual ~RsVoipDataItem()
virtual ~RsVOIPDataItem()
{
free(voip_data) ;
voip_data = NULL ;
@ -100,34 +120,34 @@ class RsVoipDataItem: public RsVoipItem
void *voip_data ;
};
class RsVoipProtocolItem: public RsVoipItem
class RsVOIPProtocolItem: public RsVOIPItem
{
public:
RsVoipProtocolItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {}
RsVoipProtocolItem(void *data,uint32_t size) ;
RsVOIPProtocolItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {}
RsVOIPProtocolItem(void *data,uint32_t size) ;
enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } ;
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ;
virtual ~RsVoipProtocolItem() {}
virtual ~RsVOIPProtocolItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
uint32_t protocol ;
uint32_t flags ;
};
class RsVoipPongItem: public RsVoipItem
class RsVOIPPongItem: public RsVOIPItem
{
public:
RsVoipPongItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PONG) {}
RsVoipPongItem(void *data,uint32_t size) ;
RsVOIPPongItem() :RsVOIPItem(RS_PKT_SUBTYPE_VOIP_PONG) {}
RsVOIPPongItem(void *data,uint32_t size) ;
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ;
virtual ~RsVoipPongItem() {}
virtual ~RsVOIPPongItem() {}
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
uint32_t mSeqNo;
@ -135,29 +155,25 @@ class RsVoipPongItem: public RsVoipItem
uint64_t mPongTS;
};
class RsVoipSerialiser: public RsSerialType
class RsVOIPSerialiser: public RsSerialType
{
public:
RsVoipSerialiser()
RsVOIPSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_VOIP_PLUGIN)
{
}
virtual ~RsVoipSerialiser() {}
virtual ~RsVOIPSerialiser() {}
virtual uint32_t size (RsItem *item)
{
return dynamic_cast<RsVoipItem *>(item)->serial_size() ;
return dynamic_cast<RsVOIPItem *>(item)->serial_size() ;
}
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
{
return dynamic_cast<RsVoipItem *>(item)->serialise(data,*size) ;
return dynamic_cast<RsVOIPItem *>(item)->serialise(data,*size) ;
}
virtual RsItem *deserialise(void *data, uint32_t *size);
};
/**************************************************************************/
#endif /* RS_VOIP_ITEMS_H */