2015-05-11 15:40:07 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* Copyright (C) 2015
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* 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.
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* 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.
|
2012-02-19 03:32:47 -05:00
|
|
|
*
|
2015-05-11 15:40:07 -04:00
|
|
|
* 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.
|
|
|
|
****************************************************************/
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
#include "util/rsdir.h"
|
|
|
|
#include "retroshare/rsiface.h"
|
|
|
|
#include "pqi/pqibin.h"
|
|
|
|
#include "pqi/pqistore.h"
|
|
|
|
#include "pqi/p3linkmgr.h"
|
2012-02-19 10:07:47 -05:00
|
|
|
#include <serialiser/rsserial.h>
|
|
|
|
#include <serialiser/rsconfigitems.h>
|
|
|
|
|
2012-04-16 13:47:53 -04:00
|
|
|
#include <sstream> // for std::istringstream
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#include "services/p3VOIP.h"
|
|
|
|
#include "services/rsVOIPItems.h"
|
|
|
|
#include "gui/VOIPNotify.h"
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
/****
|
2015-05-11 15:40:07 -04:00
|
|
|
* #define DEBUG_VOIP 1
|
2012-02-19 03:32:47 -05:00
|
|
|
****/
|
|
|
|
|
|
|
|
/* DEFINE INTERFACE POINTER! */
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIP *rsVOIP = NULL;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
#define MAX_PONG_RESULTS 150
|
2015-05-11 15:40:07 -04:00
|
|
|
#define VOIP_PING_PERIOD 10
|
|
|
|
#define VOIP_BANDWIDTH_PERIOD 5
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/************ IMPLEMENTATION NOTES *********************************
|
|
|
|
*
|
|
|
|
* Voice over Retroshare ;)
|
|
|
|
*
|
|
|
|
* This will be a simple test VoIP system aimed at testing out the possibilities.
|
|
|
|
*
|
|
|
|
* Important things to test:
|
|
|
|
* 1) lag, and variability in data rate
|
|
|
|
* - To do this we time tag every packet..., the destination can use this info to calculate the results.
|
|
|
|
* - Like imixitup. Dt = clock_diff + lag.
|
|
|
|
* we expect clock_diff to be relatively constant, but lag to vary.
|
|
|
|
* lag cannot be negative, so minimal Dt is ~clock_diff, and delays on this are considered +lag.
|
|
|
|
*
|
|
|
|
* 2) we could directly measure lag. ping back and forth with Timestamps.
|
|
|
|
*
|
|
|
|
* 3) we also want to measure bandwidth...
|
|
|
|
* - not sure the best method?
|
|
|
|
* one way: send a ping, then a large amount of data (5 seconds worth), then another ping.
|
|
|
|
* the delta in timestamps should be a decent indication of bandwidth.
|
|
|
|
* say we have a 100kb/s connection... need 500kb.
|
|
|
|
* actually the amount of data should be based on a reasonable maximum that we require.
|
|
|
|
* what does decent video require?
|
|
|
|
* Audio we can test for 64kb/s - which seems like a decent rate: e.g. mono, 16bit 22k = 1 x 2 x 22k = 44 kilobytes/sec
|
|
|
|
* best to do this without a VoIP call going on ;)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/timeb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static double getCurrentTS()
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
struct timeval cts_tmp;
|
|
|
|
gettimeofday(&cts_tmp, NULL);
|
|
|
|
double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
|
|
|
|
#else
|
|
|
|
struct _timeb timebuf;
|
|
|
|
_ftime( &timebuf);
|
|
|
|
double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
|
|
|
|
#endif
|
|
|
|
return cts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t convertTsTo64bits(double ts)
|
|
|
|
{
|
|
|
|
uint32_t secs = (uint32_t) ts;
|
|
|
|
uint32_t usecs = (uint32_t) ((ts - (double) secs) * 1000000);
|
|
|
|
uint64_t bits = (((uint64_t) secs) << 32) + usecs;
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double convert64bitsToTs(uint64_t bits)
|
|
|
|
{
|
|
|
|
uint32_t usecs = (uint32_t) (bits & 0xffffffff);
|
|
|
|
uint32_t secs = (uint32_t) ((bits >> 32) & 0xffffffff);
|
|
|
|
double ts = (secs) + ((double) usecs) / 1000000.0;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
p3VOIP::p3VOIP(RsPluginHandler *handler,VOIPNotify *notifier)
|
|
|
|
: RsPQIService(RS_SERVICE_TYPE_VOIP_PLUGIN,0,handler), mVOIPMtx("p3VOIP"), mServiceControl(handler->getServiceControl()) , mNotify(notifier)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
addSerialType(new RsVOIPSerialiser());
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
mSentPingTime = 0;
|
2014-07-20 16:50:36 -04:00
|
|
|
mSentBandwidthInfoTime = 0;
|
2012-02-19 03:32:47 -05:00
|
|
|
mCounter = 0;
|
|
|
|
|
2012-02-26 15:54:34 -05:00
|
|
|
//plugin default configuration
|
|
|
|
_atransmit = 0;
|
|
|
|
_voice_hold = 75;
|
|
|
|
_vadmin = 16018;
|
|
|
|
_vadmax = 23661;
|
|
|
|
_min_loudness = 4702;
|
|
|
|
_noise_suppress = -45;
|
|
|
|
_echo_cancel = true;
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
RsServiceInfo p3VOIP::getServiceInfo()
|
2014-04-20 10:21:53 -04:00
|
|
|
{
|
|
|
|
const std::string TURTLE_APP_NAME = "VOIP";
|
|
|
|
const uint16_t TURTLE_APP_MAJOR_VERSION = 1;
|
|
|
|
const uint16_t TURTLE_APP_MINOR_VERSION = 0;
|
|
|
|
const uint16_t TURTLE_MIN_MAJOR_VERSION = 1;
|
|
|
|
const uint16_t TURTLE_MIN_MINOR_VERSION = 0;
|
|
|
|
|
|
|
|
return RsServiceInfo(RS_SERVICE_TYPE_VOIP_PLUGIN,
|
|
|
|
TURTLE_APP_NAME,
|
|
|
|
TURTLE_APP_MAJOR_VERSION,
|
|
|
|
TURTLE_APP_MINOR_VERSION,
|
|
|
|
TURTLE_MIN_MAJOR_VERSION,
|
|
|
|
TURTLE_MIN_MINOR_VERSION);
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-08-07 21:40:48 -04:00
|
|
|
void RsVOIPDataChunk::clear()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(data)
|
|
|
|
free(data) ;
|
|
|
|
data=NULL;
|
|
|
|
size=0 ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::tick()
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "ticking p3VOIP" << std::endl;
|
2012-08-30 12:14:55 -04:00
|
|
|
#endif
|
2012-02-21 16:53:25 -05:00
|
|
|
|
2013-10-03 09:15:10 -04:00
|
|
|
//processIncoming();
|
2012-02-19 03:32:47 -05:00
|
|
|
sendPackets();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::status()
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::sendPackets()
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
|
|
|
time_t pt;
|
2014-07-20 16:50:36 -04:00
|
|
|
time_t pt2;
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
pt = mSentPingTime;
|
2014-07-20 16:50:36 -04:00
|
|
|
pt2 = mSentBandwidthInfoTime;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
if (now > pt + VOIP_PING_PERIOD)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
sendPingMeasurements();
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
mSentPingTime = now;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
if (now > pt2 + VOIP_BANDWIDTH_PERIOD)
|
2014-07-20 16:50:36 -04:00
|
|
|
{
|
|
|
|
sendBandwidthInfo();
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2014-07-20 16:50:36 -04:00
|
|
|
mSentBandwidthInfoTime = now;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
return true ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::sendBandwidthInfo()
|
2014-07-20 16:50:36 -04:00
|
|
|
{
|
|
|
|
std::set<RsPeerId> onlineIds;
|
|
|
|
mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds);
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2014-07-20 16:50:36 -04:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
for(std::map<RsPeerId,VOIPPeerInfo>::iterator it(mPeerInfo.begin());it!=mPeerInfo.end();++it)
|
2014-07-20 16:50:36 -04:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
it->second.average_incoming_bandwidth = 0.75 * it->second.average_incoming_bandwidth + 0.25 * it->second.total_bytes_received / VOIP_BANDWIDTH_PERIOD ;
|
2014-07-20 16:50:36 -04:00
|
|
|
it->second.total_bytes_received = 0 ;
|
|
|
|
|
|
|
|
if(onlineIds.find(it->first) == onlineIds.end() || it->second.average_incoming_bandwidth == 0)
|
|
|
|
continue ;
|
|
|
|
|
|
|
|
std::cerr << "average bandwidth for peer " << it->first << ": " << it->second.average_incoming_bandwidth << " Bps" << std::endl;
|
|
|
|
sendVoipBandwidth(it->first,it->second.average_incoming_bandwidth) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 09:21:59 -04:00
|
|
|
int p3VOIP::sendVoipHangUpCall(const RsPeerId &peer_id, uint32_t flags)
|
2012-02-22 15:43:27 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
item->protocol = RsVOIPProtocolItem::VoipProtocol_Close;
|
2015-10-10 09:21:59 -04:00
|
|
|
item->flags = flags ;
|
2012-02-22 15:43:27 -05:00
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
|
|
|
|
sendItem(item) ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
2015-10-10 09:21:59 -04:00
|
|
|
int p3VOIP::sendVoipAcceptCall(const RsPeerId& peer_id, uint32_t flags)
|
2012-02-22 15:43:27 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
item->protocol = RsVOIPProtocolItem::VoipProtocol_Ackn ;
|
2015-10-10 09:21:59 -04:00
|
|
|
item->flags = flags ;
|
2012-02-22 15:43:27 -05:00
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
|
|
|
|
sendItem(item) ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-22 15:43:27 -05:00
|
|
|
return true ;
|
|
|
|
}
|
2015-10-10 09:21:59 -04:00
|
|
|
int p3VOIP::sendVoipRinging(const RsPeerId &peer_id, uint32_t flags)
|
2012-02-22 15:43:27 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
item->protocol = RsVOIPProtocolItem::VoipProtocol_Ring ;
|
2015-10-10 09:21:59 -04:00
|
|
|
item->flags = flags ;
|
2012-02-22 15:43:27 -05:00
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
|
|
|
|
sendItem(item) ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
|
2014-07-20 16:50:36 -04:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPProtocolItem *item = new RsVOIPProtocolItem ;
|
2014-07-20 16:50:36 -04:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
item->protocol = RsVOIPProtocolItem::VoipProtocol_Bandwidth ;
|
2014-07-20 16:50:36 -04:00
|
|
|
item->flags = bytes_per_sec ;
|
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
|
|
|
|
sendItem(item) ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
return true ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::sendVoipData(const RsPeerId& peer_id,const RsVOIPDataChunk& chunk)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
2012-02-25 07:18:40 -05:00
|
|
|
std::cerr << "Sending " << chunk.size << " bytes of voip data." << std::endl;
|
2012-08-30 12:14:55 -04:00
|
|
|
#endif
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPDataItem *item = new RsVOIPDataItem ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
if(!item)
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "Cannot allocate RsVOIPDataItem !" << std::endl;
|
2012-02-22 15:43:27 -05:00
|
|
|
return false ;
|
|
|
|
}
|
2016-01-12 21:43:04 -05:00
|
|
|
item->voip_data = rs_malloc(chunk.size) ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
if(item->voip_data == NULL)
|
|
|
|
{
|
2014-07-15 16:04:31 -04:00
|
|
|
delete item ;
|
2012-02-22 15:43:27 -05:00
|
|
|
return false ;
|
|
|
|
}
|
2012-02-25 07:18:40 -05:00
|
|
|
memcpy(item->voip_data,chunk.data,chunk.size) ;
|
2014-07-15 16:04:31 -04:00
|
|
|
item->PeerId(peer_id) ;
|
|
|
|
item->data_size = chunk.size;
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
if(chunk.type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
|
2014-07-15 16:04:31 -04:00
|
|
|
item->flags = RS_VOIP_FLAGS_AUDIO_DATA ;
|
2015-05-11 15:40:07 -04:00
|
|
|
else if(chunk.type == RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
|
2014-07-15 16:04:31 -04:00
|
|
|
item->flags = RS_VOIP_FLAGS_VIDEO_DATA ;
|
|
|
|
else
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "(EE) p3VOIP: cannot send chunk data. Unknown data type = " << chunk.type << std::endl;
|
2014-07-15 16:04:31 -04:00
|
|
|
delete item ;
|
|
|
|
return false ;
|
|
|
|
}
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
sendItem(item) ;
|
|
|
|
|
|
|
|
return true ;
|
2012-02-19 10:07:47 -05:00
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::sendPingMeasurements()
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
/* we ping our peers */
|
|
|
|
/* who is online? */
|
2014-04-20 10:21:53 -04:00
|
|
|
if(!mServiceControl)
|
|
|
|
return ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2014-04-20 10:21:53 -04:00
|
|
|
std::set<RsPeerId> onlineIds;
|
|
|
|
mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
double ts = getCurrentTS();
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::sendPingMeasurements() @ts: " << ts;
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* prepare packets */
|
2014-04-20 10:21:53 -04:00
|
|
|
std::set<RsPeerId>::iterator it;
|
|
|
|
for(it = onlineIds.begin(); it != onlineIds.end(); it++)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::sendPingMeasurements() Pinging: " << *it;
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* create the packet */
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPingItem *pingPkt = new RsVOIPPingItem();
|
2012-02-19 03:32:47 -05:00
|
|
|
pingPkt->PeerId(*it);
|
|
|
|
pingPkt->mSeqNo = mCounter;
|
|
|
|
pingPkt->mPingTS = convertTsTo64bits(ts);
|
|
|
|
|
|
|
|
storePingAttempt(*it, ts, mCounter);
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::sendPingMeasurements() With Packet:";
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
pingPkt->print(std::cerr, 10);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sendItem(pingPkt);
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
mCounter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::handleProtocol(RsVOIPProtocolItem *item)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
|
|
|
// should we keep a list of received requests?
|
|
|
|
|
2012-02-25 13:15:36 -05:00
|
|
|
switch(item->protocol)
|
|
|
|
{
|
2015-10-10 09:21:59 -04:00
|
|
|
case RsVOIPProtocolItem::VoipProtocol_Ring: mNotify->notifyReceivedVoipInvite(item->PeerId(), (uint32_t)item->flags);
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
2015-10-10 09:21:59 -04:00
|
|
|
std::cerr << "p3VOIP::handleProtocol(): Received protocol ring item." << std::endl;
|
2012-08-30 12:14:55 -04:00
|
|
|
#endif
|
2015-10-10 09:21:59 -04:00
|
|
|
break ;
|
2012-02-25 13:15:36 -05:00
|
|
|
|
2015-10-10 09:21:59 -04:00
|
|
|
case RsVOIPProtocolItem::VoipProtocol_Ackn: mNotify->notifyReceivedVoipAccept(item->PeerId(), (uint32_t)item->flags);
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
2015-10-10 09:21:59 -04:00
|
|
|
std::cerr << "p3VOIP::handleProtocol(): Received protocol accept call" << std::endl;
|
2012-08-30 12:14:55 -04:00
|
|
|
#endif
|
2015-10-10 09:21:59 -04:00
|
|
|
break ;
|
2012-02-26 10:49:07 -05:00
|
|
|
|
2015-10-10 09:21:59 -04:00
|
|
|
case RsVOIPProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId(), (uint32_t)item->flags);
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
2015-10-10 09:21:59 -04:00
|
|
|
std::cerr << "p3VOIP::handleProtocol(): Received protocol Close call." << std::endl;
|
2014-07-20 16:50:36 -04:00
|
|
|
#endif
|
2015-10-10 09:21:59 -04:00
|
|
|
break ;
|
2015-05-11 15:40:07 -04:00
|
|
|
case RsVOIPProtocolItem::VoipProtocol_Bandwidth: mNotify->notifyReceivedVoipBandwidth(item->PeerId(),(uint32_t)item->flags);
|
|
|
|
#ifdef DEBUG_VOIP
|
2015-10-10 09:21:59 -04:00
|
|
|
std::cerr << "p3VOIP::handleProtocol(): Received protocol bandwidth. Value=" << item->flags << std::endl;
|
2012-08-30 12:14:55 -04:00
|
|
|
#endif
|
2015-10-10 09:21:59 -04:00
|
|
|
break ;
|
2012-02-25 13:15:36 -05:00
|
|
|
default:
|
2015-10-10 09:21:59 -04:00
|
|
|
std::cerr << "p3VOIP::handleProtocol(): Received protocol item # " << item->protocol << ": not handled yet ! Sorry" << std::endl;
|
|
|
|
break ;
|
2012-02-25 13:15:36 -05:00
|
|
|
}
|
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::handleData(RsVOIPDataItem *item)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
// store the data in a queue.
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
std::map<RsPeerId,VOIPPeerInfo>::iterator it = mPeerInfo.find(item->PeerId()) ;
|
2014-07-15 16:04:31 -04:00
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
if(it == mPeerInfo.end())
|
|
|
|
{
|
|
|
|
std::cerr << "Peer unknown to VOIP process. Dropping data" << std::endl;
|
|
|
|
delete item ;
|
2014-07-20 16:50:36 -04:00
|
|
|
return ;
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
2014-07-20 16:50:36 -04:00
|
|
|
it->second.incoming_queue.push_back(item) ; // be careful with the delete action!
|
2012-02-25 07:18:40 -05:00
|
|
|
|
2014-07-20 16:50:36 -04:00
|
|
|
// For Video data, measure the bandwidth
|
|
|
|
|
|
|
|
if(item->flags & RS_VOIP_FLAGS_VIDEO_DATA)
|
|
|
|
it->second.total_bytes_received += item->data_size ;
|
|
|
|
|
|
|
|
mNotify->notifyReceivedVoipData(item->PeerId());
|
2012-02-25 07:18:40 -05:00
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
bool p3VOIP::getIncomingData(const RsPeerId& peer_id,std::vector<RsVOIPDataChunk>& incoming_data_chunks)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
incoming_data_chunks.clear() ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
std::map<RsPeerId,VOIPPeerInfo>::iterator it = mPeerInfo.find(peer_id) ;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
if(it == mPeerInfo.end())
|
|
|
|
{
|
|
|
|
std::cerr << "Peer unknown to VOIP process. No data returned. Probably a bug !" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
for(std::list<RsVOIPDataItem*>::const_iterator it2(it->second.incoming_queue.begin());it2!=it->second.incoming_queue.end();++it2)
|
2012-02-25 07:18:40 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPDataChunk chunk ;
|
2012-02-25 07:18:40 -05:00
|
|
|
chunk.size = (*it2)->data_size ;
|
2016-01-12 21:43:04 -05:00
|
|
|
chunk.data = rs_malloc((*it2)->data_size) ;
|
2016-01-11 23:49:00 -05:00
|
|
|
|
|
|
|
if(chunk.data == NULL)
|
|
|
|
{
|
|
|
|
delete *it2 ;
|
|
|
|
continue ;
|
|
|
|
}
|
2014-07-15 16:04:31 -04:00
|
|
|
|
|
|
|
uint32_t type_flags = (*it2)->flags & (RS_VOIP_FLAGS_AUDIO_DATA | RS_VOIP_FLAGS_VIDEO_DATA) ;
|
|
|
|
if(type_flags == RS_VOIP_FLAGS_AUDIO_DATA)
|
2015-05-11 15:40:07 -04:00
|
|
|
chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_AUDIO ;
|
2014-07-15 16:04:31 -04:00
|
|
|
else if(type_flags == RS_VOIP_FLAGS_VIDEO_DATA)
|
2015-05-11 15:40:07 -04:00
|
|
|
chunk.type = RsVOIPDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
|
2014-07-15 16:04:31 -04:00
|
|
|
else
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
std::cerr << "(EE) p3VOIP::getIncomingData(): error. Cannot handle item with unknown type " << type_flags << std::endl;
|
2014-07-15 16:04:31 -04:00
|
|
|
delete *it2 ;
|
|
|
|
free(chunk.data) ;
|
|
|
|
continue ;
|
|
|
|
}
|
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
memcpy(chunk.data,(*it2)->voip_data,(*it2)->data_size) ;
|
|
|
|
|
|
|
|
incoming_data_chunks.push_back(chunk) ;
|
|
|
|
|
|
|
|
delete *it2 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->second.incoming_queue.clear() ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
bool p3VOIP::recvItem(RsItem *item)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2013-10-03 09:15:10 -04:00
|
|
|
/* pass to specific handler */
|
|
|
|
bool keep = false ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2013-10-03 09:15:10 -04:00
|
|
|
switch(item->PacketSubType())
|
|
|
|
{
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_PING:
|
2015-05-11 15:40:07 -04:00
|
|
|
handlePing(dynamic_cast<RsVOIPPingItem*>(item));
|
2013-10-03 09:15:10 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_PONG:
|
2015-05-11 15:40:07 -04:00
|
|
|
handlePong(dynamic_cast<RsVOIPPongItem*>(item));
|
2013-10-03 09:15:10 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_PROTOCOL:
|
2015-05-11 15:40:07 -04:00
|
|
|
handleProtocol(dynamic_cast<RsVOIPProtocolItem*>(item)) ;
|
2013-10-03 09:15:10 -04:00
|
|
|
break ;
|
|
|
|
|
|
|
|
case RS_PKT_SUBTYPE_VOIP_DATA:
|
2015-05-11 15:40:07 -04:00
|
|
|
handleData(dynamic_cast<RsVOIPDataItem*>(item));
|
2013-10-03 09:15:10 -04:00
|
|
|
keep = true ;
|
|
|
|
break;
|
2012-02-19 03:32:47 -05:00
|
|
|
#if 0
|
2012-02-25 07:18:40 -05:00
|
|
|
/* THESE ARE ALL FUTURISTIC DATA TYPES */
|
2013-10-03 09:15:10 -04:00
|
|
|
case RS_BANDWIDTH_PING_ITEM:
|
|
|
|
handleBandwidthPing(item);
|
|
|
|
break;
|
2012-02-25 07:18:40 -05:00
|
|
|
|
2013-10-03 09:15:10 -04:00
|
|
|
case RS_BANDWIDTH_PONG_ITEM:
|
|
|
|
handleBandwidthPong(item);
|
|
|
|
break;
|
2012-02-19 03:32:47 -05:00
|
|
|
#endif
|
2013-10-03 09:15:10 -04:00
|
|
|
default:
|
|
|
|
break;
|
2012-02-19 03:32:47 -05:00
|
|
|
}
|
2013-10-03 09:15:10 -04:00
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
if(!keep)
|
|
|
|
delete item;
|
2012-02-19 03:32:47 -05:00
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::handlePing(RsVOIPPingItem *ping)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
/* cast to right type */
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::handlePing() Recvd Packet from: " << ping->PeerId();
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* with a ping, we just respond as quickly as possible - they do all the analysis */
|
2015-05-11 15:40:07 -04:00
|
|
|
RsVOIPPongItem *pong = new RsVOIPPongItem();
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
pong->PeerId(ping->PeerId());
|
|
|
|
pong->mPingTS = ping->mPingTS;
|
|
|
|
pong->mSeqNo = ping->mSeqNo;
|
|
|
|
|
|
|
|
// add our timestamp.
|
|
|
|
double ts = getCurrentTS();
|
|
|
|
pong->mPongTS = convertTsTo64bits(ts);
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::handlePing() With Packet:";
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
pong->print(std::cerr, 10);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sendItem(pong);
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::handlePong(RsVOIPPongItem *pong)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
/* cast to right type */
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::handlePong() Recvd Packet from: " << pong->PeerId();
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
pong->print(std::cerr, 10);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* with a pong, we do the maths! */
|
|
|
|
double recvTS = getCurrentTS();
|
|
|
|
double pingTS = convert64bitsToTs(pong->mPingTS);
|
|
|
|
double pongTS = convert64bitsToTs(pong->mPongTS);
|
|
|
|
|
|
|
|
double rtt = recvTS - pingTS;
|
|
|
|
double offset = pongTS - (recvTS - rtt / 2.0); // so to get to their time, we go ourTS + offset.
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::handlePong() Timing:";
|
2012-02-19 03:32:47 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\tpingTS: " << pingTS;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\tpongTS: " << pongTS;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\trecvTS: " << recvTS;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\t ==> rtt: " << rtt;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\t ==> offset: " << offset;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
storePongResult(pong->PeerId(), pong->mSeqNo, pingTS, rtt, offset);
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/* find corresponding local data */
|
2015-05-11 15:40:07 -04:00
|
|
|
VOIPPeerInfo *peerInfo = locked_GetPeerInfo(id);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
peerInfo->mCurrentPingTS = ts;
|
|
|
|
peerInfo->mCurrentPingCounter = seqno;
|
|
|
|
|
|
|
|
peerInfo->mSentPings++;
|
|
|
|
if (!peerInfo->mCurrentPongRecvd)
|
|
|
|
{
|
|
|
|
peerInfo->mLostPongs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
peerInfo->mCurrentPongRecvd = true;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::storePongResult(const RsPeerId &id, uint32_t counter, double ts, double rtt, double offset)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/* find corresponding local data */
|
2015-05-11 15:40:07 -04:00
|
|
|
VOIPPeerInfo *peerInfo = locked_GetPeerInfo(id);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
if (peerInfo->mCurrentPingCounter != counter)
|
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
#ifdef DEBUG_VOIP
|
|
|
|
std::cerr << "p3VOIP::storePongResult() ERROR Severly Delayed Measurements!" << std::endl;
|
2012-02-19 03:32:47 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
peerInfo->mCurrentPongRecvd = true;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
peerInfo->mPongResults.push_back(RsVOIPPongResult(ts, rtt, offset));
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
while(peerInfo->mPongResults.size() > MAX_PONG_RESULTS)
|
|
|
|
{
|
|
|
|
peerInfo->mPongResults.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* should do calculations */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
uint32_t p3VOIP::getPongResults(const RsPeerId& id, int n, std::list<RsVOIPPongResult> &results)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
RsStackMutex stack(mVOIPMtx); /****** LOCKED MUTEX *******/
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
VOIPPeerInfo *peer = locked_GetPeerInfo(id);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
std::list<RsVOIPPongResult>::reverse_iterator it;
|
2012-02-19 03:32:47 -05:00
|
|
|
int i = 0;
|
|
|
|
for(it = peer->mPongResults.rbegin(); (it != peer->mPongResults.rend()) && (i < n); it++, i++)
|
|
|
|
{
|
|
|
|
/* reversing order - so its easy to trim later */
|
|
|
|
results.push_back(*it);
|
|
|
|
}
|
|
|
|
return i ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
VOIPPeerInfo *p3VOIP::locked_GetPeerInfo(const RsPeerId &id)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
2015-05-11 15:40:07 -04:00
|
|
|
std::map<RsPeerId, VOIPPeerInfo>::iterator it;
|
2012-02-19 03:32:47 -05:00
|
|
|
it = mPeerInfo.find(id);
|
|
|
|
if (it == mPeerInfo.end())
|
|
|
|
{
|
|
|
|
/* add it in */
|
2015-05-11 15:40:07 -04:00
|
|
|
VOIPPeerInfo pinfo;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/* initialise entry */
|
|
|
|
pinfo.initialisePeerInfo(id);
|
|
|
|
|
|
|
|
mPeerInfo[id] = pinfo;
|
|
|
|
|
|
|
|
it = mPeerInfo.find(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(it->second);
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
bool VOIPPeerInfo::initialisePeerInfo(const RsPeerId& id)
|
2012-02-19 03:32:47 -05:00
|
|
|
{
|
|
|
|
mId = id;
|
|
|
|
|
|
|
|
/* reset variables */
|
|
|
|
mCurrentPingTS = 0;
|
|
|
|
mCurrentPingCounter = 0;
|
|
|
|
mCurrentPongRecvd = true;
|
|
|
|
|
|
|
|
mSentPings = 0;
|
|
|
|
mLostPongs = 0;
|
2014-07-20 16:50:36 -04:00
|
|
|
average_incoming_bandwidth = 0 ;
|
|
|
|
total_bytes_received = 0 ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
mPongResults.clear();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipATransmit(int t)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_atransmit = t ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipVoiceHold(int vh)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_voice_hold = vh ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipfVADmin(int vad)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_vadmin = vad ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipfVADmax(int vad)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_vadmax = vad ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipiNoiseSuppress(int n)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_noise_suppress = n ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipiMinLoudness(int ml)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_min_loudness = ml ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
void p3VOIP::setVoipEchoCancel(bool b)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
_echo_cancel = b ;
|
|
|
|
IndicateConfigChanged() ;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsTlvKeyValue p3VOIP::push_int_value(const std::string& key,int value)
|
2012-02-22 15:43:27 -05:00
|
|
|
{
|
|
|
|
RsTlvKeyValue kv ;
|
|
|
|
kv.key = key ;
|
2012-04-16 13:47:53 -04:00
|
|
|
rs_sprintf(kv.value, "%d", value);
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
return kv ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
int p3VOIP::pop_int_value(const std::string& s)
|
2012-02-22 15:43:27 -05:00
|
|
|
{
|
|
|
|
std::istringstream is(s) ;
|
|
|
|
|
|
|
|
int val ;
|
|
|
|
is >> val ;
|
|
|
|
|
|
|
|
return val ;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
bool p3VOIP::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
cleanup = true ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
|
|
|
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_ATRANSMIT",_atransmit)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_VOICEHOLD",_voice_hold)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_VADMIN" ,_vadmin)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_VADMAX" ,_vadmax)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_NOISE_SUP",_noise_suppress)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_MIN_LOUDN",_min_loudness)) ;
|
|
|
|
vitem->tlvkvs.pairs.push_back(push_int_value("P3VOIP_CONFIG_ECHO_CNCL",_echo_cancel)) ;
|
|
|
|
|
|
|
|
lst.push_back(vitem) ;
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
return true ;
|
|
|
|
}
|
2015-05-11 15:40:07 -04:00
|
|
|
bool p3VOIP::loadList(std::list<RsItem*>& load)
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
2012-02-22 15:43:27 -05:00
|
|
|
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
|
|
|
|
{
|
|
|
|
#ifdef P3TURTLE_DEBUG
|
|
|
|
assert(item!=NULL) ;
|
|
|
|
#endif
|
|
|
|
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet*>(*it) ;
|
|
|
|
|
|
|
|
if(vitem != NULL)
|
2016-10-22 17:48:19 -04:00
|
|
|
{
|
|
|
|
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
2012-02-22 15:43:27 -05:00
|
|
|
if(kit->key == "P3VOIP_CONFIG_ATRANSMIT")
|
|
|
|
_atransmit = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_VOICEHOLD")
|
|
|
|
_voice_hold = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_VADMIN")
|
|
|
|
_vadmin = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_VADMAX")
|
|
|
|
_vadmax = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_NOISE_SUP")
|
|
|
|
_noise_suppress = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_MIN_LOUDN")
|
|
|
|
_min_loudness = pop_int_value(kit->value) ;
|
|
|
|
else if(kit->key == "P3VOIP_CONFIG_ECHO_CNCL")
|
|
|
|
_echo_cancel = pop_int_value(kit->value) ;
|
2016-10-22 17:48:19 -04:00
|
|
|
}
|
2012-02-22 15:43:27 -05:00
|
|
|
delete vitem ;
|
|
|
|
}
|
2015-12-30 18:20:09 -05:00
|
|
|
|
|
|
|
load.clear() ;
|
2012-02-19 10:07:47 -05:00
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2015-05-11 15:40:07 -04:00
|
|
|
RsSerialiser *p3VOIP::setupSerialiser()
|
2012-02-19 10:07:47 -05:00
|
|
|
{
|
|
|
|
RsSerialiser *rsSerialiser = new RsSerialiser();
|
2015-05-11 15:40:07 -04:00
|
|
|
rsSerialiser->addSerialType(new RsVOIPSerialiser());
|
2012-02-19 10:07:47 -05:00
|
|
|
rsSerialiser->addSerialType(new RsGeneralConfigSerialiser());
|
|
|
|
|
|
|
|
return rsSerialiser ;
|
|
|
|
}
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|