added load/save config values to VOIP plugin. Added methods for ringin/accepting calls

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4980 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-02-22 20:43:27 +00:00
parent 826e8f3728
commit e8f93f1569
4 changed files with 145 additions and 19 deletions

View File

@ -28,7 +28,10 @@ class RsVoipPongResult
class RsVoip
{
public:
virtual int sendVoipData(const void *data,uint32_t size) = 0;
virtual int sendVoipData(const std::string& peer_id,const void *data,uint32_t size) = 0;
virtual int sendVoipHangUpCall(const std::string& peer_id) = 0;
virtual int sendVoipRinging(const std::string& peer_id) = 0;
virtual int sendVoipAcceptCall(const std::string& peer_id) = 0;
typedef enum { AudioTransmitContinous = 0, AudioTransmitVAD = 1, AudioTransmitPushToTalk = 2 } enumAudioTransmit ;

View File

@ -185,12 +185,68 @@ int p3VoRS::sendPackets()
}
return true ;
}
int p3VoRS::sendVoipHangUpCall(const std::string& peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
int p3VoRS::sendVoipData(const void *data,uint32_t size)
item->protocol = RsVoipProtocolItem::VoipProtocol_Close;
item->flags = 0 ;
item->PeerId(peer_id) ;
sendItem(item) ;
return true ;
}
int p3VoRS::sendVoipAcceptCall(const std::string& peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Ackn ;
item->flags = 0 ;
item->PeerId(peer_id) ;
sendItem(item) ;
return true ;
}
int p3VoRS::sendVoipRinging(const std::string& peer_id)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Ring ;
item->flags = 0 ;
item->PeerId(peer_id) ;
sendItem(item) ;
return true ;
}
int p3VoRS::sendVoipData(const std::string& peer_id,const void *data,uint32_t size)
{
std::cerr << "Sending " << size << " bytes of voip data." << std::endl;
return size ;
RsVoipDataItem *item = new RsVoipDataItem ;
if(!item)
{
std::cerr << "Cannot allocate RsVoipDataItem !" << std::endl;
return false ;
}
item->voip_data = malloc(size) ;
if(item->voip_data == NULL)
{
std::cerr << "Cannot allocate RsVoipDataItem.voip_data of size " << size << " !" << std::endl;
return false ;
}
memcpy(item->voip_data,data,size) ;
item->flags = 0 ;
item->PeerId(peer_id) ;
sendItem(item) ;
return true ;
}
void p3VoRS::sendPingMeasurements()
@ -460,8 +516,6 @@ VorsPeerInfo *p3VoRS::locked_GetPeerInfo(std::string id)
return &(it->second);
}
bool VorsPeerInfo::initialisePeerInfo(std::string id)
{
mId = id;
@ -515,13 +569,73 @@ void p3VoRS::setVoipEchoCancel(bool b)
IndicateConfigChanged() ;
}
bool p3VoRS::saveList(bool& cleanup, std::list<RsItem*>&)
RsTlvKeyValue p3VoRS::push_int_value(const std::string& key,int value)
{
RsTlvKeyValue kv ;
kv.key = key ;
std::ostringstream s ;
s << value;
kv.value = s.str() ;
return kv ;
}
int p3VoRS::pop_int_value(const std::string& s)
{
std::istringstream is(s) ;
int val ;
is >> val ;
return val ;
}
bool p3VoRS::saveList(bool& cleanup, std::list<RsItem*>& lst)
{
cleanup = true ;
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) ;
return true ;
}
bool p3VoRS::loadList(std::list<RsItem*>& load)
{
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)
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
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) ;
delete vitem ;
}
return true ;
}

View File

@ -71,7 +71,13 @@ class p3VoRS: public RsPQIService, public RsVoip
/***** overloaded from rsVoip *****/
virtual uint32_t getPongResults(std::string id, int n, std::list<RsVoipPongResult> &results);
virtual int sendVoipData(const void *data,uint32_t size) ;
// Call stuff.
//
virtual int sendVoipData(const std::string& peer_id,const void *data,uint32_t size) ;
virtual int sendVoipHangUpCall(const std::string& peer_id) ;
virtual int sendVoipRinging(const std::string& peer_id) ;
virtual int sendVoipAcceptCall(const std::string& peer_id) ;
/***** overloaded from p3Service *****/
/*!
@ -84,16 +90,6 @@ class p3VoRS: public RsPQIService, public RsVoip
virtual int tick();
virtual int status();
int sendPackets();
void sendPingMeasurements();
int processIncoming();
int handlePing(RsItem *item);
int handlePong(RsItem *item);
int storePingAttempt(std::string id, double ts, uint32_t mCounter);
int storePongResult(std::string id, uint32_t counter, double ts, double rtt, double offset);
/*************** pqiMonitor callback ***********************/
//virtual void statusChange(const std::list<pqipeer> &plist);
@ -121,12 +117,25 @@ class p3VoRS: public RsPQIService, public RsVoip
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
virtual bool loadList(std::list<RsItem*>& load) ;
private:
int sendPackets();
void sendPingMeasurements();
int processIncoming();
int handlePing(RsItem *item);
int handlePong(RsItem *item);
int storePingAttempt(std::string id, double ts, uint32_t mCounter);
int storePongResult(std::string id, uint32_t counter, double ts, double rtt, double offset);
RsMutex mVorsMtx;
VorsPeerInfo *locked_GetPeerInfo(std::string id);
static RsTlvKeyValue push_int_value(const std::string& key,int value) ;
static int pop_int_value(const std::string& s) ;
std::map<std::string, VorsPeerInfo> mPeerInfo;
time_t mSentPingTime;
uint32_t mCounter;

View File

@ -78,7 +78,7 @@ class RsVoipDataItem: public RsVoipItem
{
public:
RsVoipDataItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_DATA) {}
RsVoipDataItem(void *data,uint32_t size) ;
RsVoipDataItem(void *data,uint32_t size) ; // de-serialization
virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ;