diff --git a/plugins/VOIP/interface/rsvoip.h b/plugins/VOIP/interface/rsvoip.h index 74383b08b..92dc9f083 100644 --- a/plugins/VOIP/interface/rsvoip.h +++ b/plugins/VOIP/interface/rsvoip.h @@ -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 ; diff --git a/plugins/VOIP/services/p3vors.cc b/plugins/VOIP/services/p3vors.cc index c08b34d2a..976e9a0b4 100644 --- a/plugins/VOIP/services/p3vors.cc +++ b/plugins/VOIP/services/p3vors.cc @@ -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&) +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& 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& load) { + for(std::list::const_iterator it(load.begin());it!=load.end();++it) + { +#ifdef P3TURTLE_DEBUG + assert(item!=NULL) ; +#endif + RsConfigKeyValueSet *vitem = dynamic_cast(*it) ; + + if(vitem != NULL) + for(std::list::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 ; } diff --git a/plugins/VOIP/services/p3vors.h b/plugins/VOIP/services/p3vors.h index 46e717164..5d82df826 100644 --- a/plugins/VOIP/services/p3vors.h +++ b/plugins/VOIP/services/p3vors.h @@ -71,7 +71,13 @@ class p3VoRS: public RsPQIService, public RsVoip /***** overloaded from rsVoip *****/ virtual uint32_t getPongResults(std::string id, int n, std::list &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 &plist); @@ -121,12 +117,25 @@ class p3VoRS: public RsPQIService, public RsVoip virtual bool saveList(bool& cleanup, std::list&) ; virtual bool loadList(std::list& 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 mPeerInfo; time_t mSentPingTime; uint32_t mCounter; diff --git a/plugins/VOIP/services/rsvoipitems.h b/plugins/VOIP/services/rsvoipitems.h index 5a2373125..618bcd913 100644 --- a/plugins/VOIP/services/rsvoipitems.h +++ b/plugins/VOIP/services/rsvoipitems.h @@ -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 ;