2012-02-19 03:32:47 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services/p3vors.h
|
|
|
|
*
|
|
|
|
* Tests for VoIP for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2011 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* 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 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVICE_RSVOIP_HEADER
|
|
|
|
#define SERVICE_RSVOIP_HEADER
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
#include "services/rsvoipitems.h"
|
2012-02-19 03:32:47 -05:00
|
|
|
#include "services/p3service.h"
|
2012-02-19 10:07:47 -05:00
|
|
|
#include "plugins/rspqiservice.h"
|
|
|
|
#include <interface/rsvoip.h>
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
class p3LinkMgr;
|
2012-02-25 13:15:36 -05:00
|
|
|
class PluginNotifier ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
class VorsPeerInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool initialisePeerInfo(std::string id);
|
|
|
|
|
|
|
|
std::string mId;
|
|
|
|
double mCurrentPingTS;
|
|
|
|
double mCurrentPingCounter;
|
|
|
|
bool mCurrentPongRecvd;
|
|
|
|
|
|
|
|
uint32_t mLostPongs;
|
|
|
|
uint32_t mSentPings;
|
|
|
|
|
|
|
|
std::list<RsVoipPongResult> mPongResults;
|
2012-02-25 07:18:40 -05:00
|
|
|
std::list<RsVoipDataItem*> incoming_queue ;
|
2012-02-19 03:32:47 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//!The RS VoIP Test service.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* This is only used to test Latency for the moment.
|
|
|
|
*/
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
class p3VoRS: public RsPQIService, public RsVoip
|
2012-02-19 03:32:47 -05:00
|
|
|
// Maybe we inherit from these later - but not needed for now.
|
|
|
|
//, public p3Config, public pqiMonitor
|
|
|
|
{
|
|
|
|
public:
|
2012-02-25 13:15:36 -05:00
|
|
|
p3VoRS(RsPluginHandler *cm,PluginNotifier *);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/***** overloaded from rsVoip *****/
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
virtual uint32_t getPongResults(std::string id, int n, std::list<RsVoipPongResult> &results);
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
// Call stuff.
|
|
|
|
//
|
2012-02-25 07:18:40 -05:00
|
|
|
|
|
|
|
// Sending data. The client keeps the memory ownership and must delete it after calling this.
|
|
|
|
virtual int sendVoipData(const std::string& 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 std::string& peer_id,std::vector<RsVoipDataChunk>& chunks) ;
|
|
|
|
|
2012-02-22 15:43:27 -05:00
|
|
|
virtual int sendVoipHangUpCall(const std::string& peer_id) ;
|
|
|
|
virtual int sendVoipRinging(const std::string& peer_id) ;
|
|
|
|
virtual int sendVoipAcceptCall(const std::string& peer_id) ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/***** overloaded from p3Service *****/
|
|
|
|
/*!
|
|
|
|
* This retrieves all chat msg items and also (important!)
|
|
|
|
* processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned
|
|
|
|
* (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status
|
|
|
|
* : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar
|
|
|
|
* @see NotifyBase
|
|
|
|
*/
|
|
|
|
virtual int tick();
|
|
|
|
virtual int status();
|
2013-10-03 09:15:10 -04:00
|
|
|
virtual bool recvItem(RsItem *item);
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/*************** pqiMonitor callback ***********************/
|
|
|
|
//virtual void statusChange(const std::list<pqipeer> &plist);
|
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
virtual int getVoipATransmit() const { return _atransmit ; }
|
|
|
|
virtual void setVoipATransmit(int) ;
|
|
|
|
virtual int getVoipVoiceHold() const { return _voice_hold ; }
|
|
|
|
virtual void setVoipVoiceHold(int) ;
|
|
|
|
virtual int getVoipfVADmin() const { return _vadmin ; }
|
|
|
|
virtual void setVoipfVADmin(int) ;
|
|
|
|
virtual int getVoipfVADmax() const { return _vadmax ; }
|
|
|
|
virtual void setVoipfVADmax(int) ;
|
|
|
|
virtual int getVoipiNoiseSuppress() const { return _noise_suppress ; }
|
|
|
|
virtual void setVoipiNoiseSuppress(int) ;
|
|
|
|
virtual int getVoipiMinLoudness() const { return _min_loudness ; }
|
|
|
|
virtual void setVoipiMinLoudness(int) ;
|
|
|
|
virtual bool getVoipEchoCancel() const { return _echo_cancel ; }
|
|
|
|
virtual void setVoipEchoCancel(bool) ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
|
|
|
/************* from p3Config *******************/
|
2012-02-19 10:07:47 -05:00
|
|
|
virtual RsSerialiser *setupSerialiser() ;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* chat msg items and custom status are saved
|
|
|
|
*/
|
|
|
|
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
|
|
|
virtual bool loadList(std::list<RsItem*>& load) ;
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
private:
|
2012-02-25 13:15:36 -05:00
|
|
|
int sendPackets();
|
2012-02-22 15:43:27 -05:00
|
|
|
void sendPingMeasurements();
|
2013-10-03 09:15:10 -04:00
|
|
|
//int processIncoming();
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
int handlePing(RsVoipPingItem *item);
|
|
|
|
int handlePong(RsVoipPongItem *item);
|
2012-02-22 15:43:27 -05:00
|
|
|
|
|
|
|
int storePingAttempt(std::string id, double ts, uint32_t mCounter);
|
|
|
|
int storePongResult(std::string id, uint32_t counter, double ts, double rtt, double offset);
|
|
|
|
|
2012-02-25 07:18:40 -05:00
|
|
|
void handleProtocol(RsVoipProtocolItem*) ;
|
|
|
|
void handleData(RsVoipDataItem*) ;
|
2012-02-22 15:43:27 -05:00
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
RsMutex mVorsMtx;
|
|
|
|
|
|
|
|
VorsPeerInfo *locked_GetPeerInfo(std::string id);
|
|
|
|
|
2012-02-22 15:43:27 -05:00
|
|
|
static RsTlvKeyValue push_int_value(const std::string& key,int value) ;
|
|
|
|
static int pop_int_value(const std::string& s) ;
|
|
|
|
|
2012-02-19 03:32:47 -05:00
|
|
|
std::map<std::string, VorsPeerInfo> mPeerInfo;
|
|
|
|
time_t mSentPingTime;
|
|
|
|
uint32_t mCounter;
|
|
|
|
|
|
|
|
p3LinkMgr *mLinkMgr;
|
2012-02-25 13:15:36 -05:00
|
|
|
PluginNotifier *mNotify ;
|
2012-02-19 03:32:47 -05:00
|
|
|
|
2012-02-19 10:07:47 -05:00
|
|
|
int _atransmit ;
|
|
|
|
int _voice_hold ;
|
|
|
|
int _vadmin ;
|
|
|
|
int _vadmax ;
|
|
|
|
int _min_loudness ;
|
|
|
|
int _noise_suppress ;
|
|
|
|
bool _echo_cancel ;
|
2012-02-19 03:32:47 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SERVICE_RSVOIP_HEADER
|
|
|
|
|