added bandwidth measurement for video. Still needs codec to accound for it

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7463 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-07-20 20:50:36 +00:00
parent 9c3266fdd9
commit c6103b7535
15 changed files with 157 additions and 73 deletions

View File

@ -71,6 +71,7 @@ VOIPPlugin::VOIPPlugin()
QObject::connect(mPluginNotifier,SIGNAL(voipDataReceived(const QString&)),mPluginGUIHandler,SLOT(ReceivedVoipData(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(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(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) ;
} }
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces) void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)

View File

@ -24,8 +24,6 @@ void PluginGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/)
void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id) void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
{ {
std::cerr << "****** Plugin GUI handler: received VoipData!" << std::endl;
RsPeerId peer_id(qpeer_id.toStdString()) ; RsPeerId peer_id(qpeer_id.toStdString()) ;
std::vector<RsVoipDataChunk> chunks ; std::vector<RsVoipDataChunk> chunks ;
@ -54,10 +52,7 @@ void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO) if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO)
acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb); acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb);
else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO) else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO)
{
acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb); acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb);
std::cerr << "data triaged as video." << std::endl;
}
else else
std::cerr << "Unknown data type received. type=" << chunks[chunkIndex].type << std::endl; std::cerr << "Unknown data type received. type=" << chunks[chunkIndex].type << std::endl;
} }
@ -75,3 +70,32 @@ void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id)
} }
} }
void PluginGUIHandler::ReceivedVoipBandwidthInfo(const QString& qpeer_id,int bytes_per_sec)
{
RsPeerId peer_id(qpeer_id.toStdString()) ;
ChatDialog *di = ChatDialog::getExistingChat(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

@ -5,6 +5,7 @@
// in the main GUI thread. // in the main GUI thread.
// //
#include <stdint.h>
#include <QObject> #include <QObject>
class PluginGUIHandler: public QObject class PluginGUIHandler: public QObject
@ -16,4 +17,5 @@ class PluginGUIHandler: public QObject
void ReceivedVoipData(const QString& peer_id) ; void ReceivedVoipData(const QString& peer_id) ;
void ReceivedVoipHangUp(const QString& peer_id) ; void ReceivedVoipHangUp(const QString& peer_id) ;
void ReceivedVoipAccept(const QString& peer_id) ; void ReceivedVoipAccept(const QString& peer_id) ;
void ReceivedVoipBandwidthInfo(const QString& peer_id,int) ;
}; };

View File

@ -16,3 +16,7 @@ void PluginNotifier::notifyReceivedVoipHangUp(const RsPeerId &peer_id)
{ {
emit voipHangUpReceived(QString::fromStdString(peer_id.toStdString())) ; 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

@ -17,10 +17,13 @@ class PluginNotifier: public QObject
void notifyReceivedVoipInvite(const RsPeerId &peer_id) ; void notifyReceivedVoipInvite(const RsPeerId &peer_id) ;
void notifyReceivedVoipHangUp(const RsPeerId& peer_id) ; void notifyReceivedVoipHangUp(const RsPeerId& peer_id) ;
void notifyReceivedVoipAccept(const RsPeerId &peer_id) ; void notifyReceivedVoipAccept(const RsPeerId &peer_id) ;
void notifyReceivedVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ;
signals: signals:
void voipInvitationReceived(const QString&) ; // signal emitted when an invitation has been received void voipInvitationReceived(const QString&) ; // signal emitted when an invitation has been received
void voipDataReceived(const QString&) ; // signal emitted when some voip data has been received void voipDataReceived(const QString&) ; // signal emitted when some voip data has been received
void voipHangUpReceived(const QString& peer_id) ; // emitted when the peer closes the call (i.e. hangs up) void voipHangUpReceived(const QString& peer_id) ; // emitted when the peer closes the call (i.e. hangs up)
void voipAcceptReceived(const QString& peer_id) ; // emitted when the peer accepts the call void voipAcceptReceived(const QString& peer_id) ; // emitted when the peer accepts the call
void voipBandwidthInfoReceived(const QString& peer_id,int bytes_per_sec) ; // emitted when measured bandwidth info is received by the peer.
}; };

View File

@ -95,17 +95,17 @@ QVideoInputDevice::~QVideoInputDevice()
QVideoOutputDevice::QVideoOutputDevice(QWidget *parent) QVideoOutputDevice::QVideoOutputDevice(QWidget *parent)
: QLabel(parent) : QLabel(parent)
{
showFrameOff() ;
}
void QVideoOutputDevice::showFrameOff()
{ {
setPixmap(QPixmap(":/images/video-icon-big.png").scaled(170,128,Qt::KeepAspectRatio,Qt::SmoothTransformation)) ; setPixmap(QPixmap(":/images/video-icon-big.png").scaled(170,128,Qt::KeepAspectRatio,Qt::SmoothTransformation)) ;
} }
void QVideoOutputDevice::showFrame(const QImage& img) void QVideoOutputDevice::showFrame(const QImage& img)
{ {
//std::cerr << "Displaying frame!!" << std::endl;
//QPainter painter(this) ;
//painter.drawImage(QPointF(0,0),img) ;
setPixmap(QPixmap::fromImage(img).scaled(minimumSize(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)) ; setPixmap(QPixmap::fromImage(img).scaled(minimumSize(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)) ;
} }

View File

@ -15,6 +15,7 @@ class QVideoOutputDevice: public QLabel
QVideoOutputDevice(QWidget *parent) ; QVideoOutputDevice(QWidget *parent) ;
void showFrame(const QImage&) ; void showFrame(const QImage&) ;
void showFrameOff() ;
}; };
// Responsible for grabbing the video from the webcam and sending it to the // Responsible for grabbing the video from the webcam and sending it to the

View File

@ -24,8 +24,6 @@
VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget) VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget)
: QObject(), ChatWidgetHolder(chatWidget) : QObject(), ChatWidgetHolder(chatWidget)
{ {
std::cerr << "****** VOIPLugin: Creating new VOIPChatWidgetHolder !!" << std::endl;
QIcon icon ; QIcon icon ;
icon.addPixmap(QPixmap(":/images/audio-volume-muted-22.png")) ; icon.addPixmap(QPixmap(":/images/audio-volume-muted-22.png")) ;
icon.addPixmap(QPixmap(":/images/audio-volume-medium-22.png"),QIcon::Normal,QIcon::On) ; icon.addPixmap(QPixmap(":/images/audio-volume-medium-22.png"),QIcon::Normal,QIcon::On) ;
@ -136,7 +134,6 @@ VOIPChatWidgetHolder::~VOIPChatWidgetHolder()
void VOIPChatWidgetHolder::toggleAudioListen() void VOIPChatWidgetHolder::toggleAudioListen()
{ {
std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl;
if (audioListenToggleButton->isChecked()) { if (audioListenToggleButton->isChecked()) {
audioListenToggleButton->setToolTip(tr("Mute yourself")); audioListenToggleButton->setToolTip(tr("Mute yourself"));
} else { } else {
@ -150,22 +147,19 @@ void VOIPChatWidgetHolder::toggleAudioListen()
void VOIPChatWidgetHolder::hangupCall() void VOIPChatWidgetHolder::hangupCall()
{ {
std::cerr << "******** VOIPLugin: Hangup call!" << std::endl; disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData()));
if (inputAudioDevice) {
disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); inputAudioDevice->stop();
if (inputAudioDevice) { }
inputAudioDevice->stop(); if (outputAudioDevice) {
} outputAudioDevice->stop();
if (outputAudioDevice) { }
outputAudioDevice->stop(); audioListenToggleButton->setChecked(false);
} audioCaptureToggleButton->setChecked(false);
audioListenToggleButton->setChecked(false);
audioCaptureToggleButton->setChecked(false);
} }
void VOIPChatWidgetHolder::toggleAudioCapture() void VOIPChatWidgetHolder::toggleAudioCapture()
{ {
std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl;
if (audioCaptureToggleButton->isChecked()) { if (audioCaptureToggleButton->isChecked()) {
//activate audio output //activate audio output
audioListenToggleButton->setChecked(true); audioListenToggleButton->setChecked(true);
@ -199,8 +193,6 @@ void VOIPChatWidgetHolder::toggleAudioCapture()
} }
void VOIPChatWidgetHolder::toggleVideoCapture() void VOIPChatWidgetHolder::toggleVideoCapture()
{ {
std::cerr << "******** VOIPLugin: Toggling video capture!" << std::endl;
if (videoCaptureToggleButton->isChecked()) if (videoCaptureToggleButton->isChecked())
{ {
//activate video input //activate video input
@ -216,6 +208,7 @@ void VOIPChatWidgetHolder::toggleVideoCapture()
{ {
inputVideoDevice->stop() ; inputVideoDevice->stop() ;
videoCaptureToggleButton->setToolTip(tr("Activate camera")); videoCaptureToggleButton->setToolTip(tr("Activate camera"));
outputVideoDevice->showFrameOff();
} }
} }
@ -224,6 +217,11 @@ void VOIPChatWidgetHolder::addVideoData(const QString name, QByteArray* array)
outputVideoProcessor->receiveEncodedData((unsigned char *)array->data(),array->size()) ; outputVideoProcessor->receiveEncodedData((unsigned char *)array->data(),array->size()) ;
} }
void VOIPChatWidgetHolder::setAcceptedBandwidth(const QString name, uint32_t bytes_per_sec)
{
inputVideoProcessor->setMaximumFrameRate(bytes_per_sec) ;
}
void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array) void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
{ {
if (!audioCaptureToggleButton->isChecked()) { if (!audioCaptureToggleButton->isChecked()) {
@ -288,10 +286,7 @@ void VOIPChatWidgetHolder::sendVideoData()
RsVoipDataChunk chunk ; RsVoipDataChunk chunk ;
while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk)) while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk))
{
std::cerr << "Video data ready: sending it" << std::endl;
rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk) ; rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk) ;
}
} }
void VOIPChatWidgetHolder::sendAudioData() void VOIPChatWidgetHolder::sendAudioData()

View File

@ -25,6 +25,7 @@ public:
void addAudioData(const QString name, QByteArray* array) ; void addAudioData(const QString name, QByteArray* array) ;
void addVideoData(const QString name, QByteArray* array) ; void addVideoData(const QString name, QByteArray* array) ;
void setAcceptedBandwidth(const QString name, uint32_t bytes_per_sec) ;
private slots: private slots:
void toggleAudioListen(); void toggleAudioListen();

View File

@ -7,21 +7,13 @@
#include "VideoProcessor.h" #include "VideoProcessor.h"
#include "QVideoDevice.h" #include "QVideoDevice.h"
//bool VideoDecoder::getNextImage(QImage& image) VideoDecoder::VideoDecoder()
//{ {
// if(_image_queue.empty()) _output_device = NULL ;
// return false ; }
//
// image = _image_queue.front() ;
// _image_queue.pop_front() ;
//
// return true ;
//}
bool VideoEncoder::addImage(const QImage& img) bool VideoEncoder::addImage(const QImage& img)
{ {
std::cerr << "VideoEncoder: adding image." << std::endl;
encodeData(img) ; encodeData(img) ;
return true ; return true ;
@ -48,10 +40,7 @@ QImage JPEGVideoDecoder::decodeData(const unsigned char *encoded_image_data,uint
QByteArray qb((char*)encoded_image_data,size) ; QByteArray qb((char*)encoded_image_data,size) ;
QImage image ; QImage image ;
if(image.loadFromData(qb,"JPEG")) if(image.loadFromData(qb,"JPEG"))
{
std::cerr << "image decoded successfully" << std::endl;
return image ; return image ;
}
else else
{ {
std::cerr << "image.loadFromData(): returned an error.: " << std::endl; std::cerr << "image.loadFromData(): returned an error.: " << std::endl;
@ -59,6 +48,12 @@ QImage JPEGVideoDecoder::decodeData(const unsigned char *encoded_image_data,uint
} }
} }
void VideoEncoder::setMaximumFrameRate(uint32_t bytes_per_sec)
{
std::cerr << "Video Encoder: maximum frame rate is set to " << bytes_per_sec << " Bps" << std::endl;
}
void JPEGVideoEncoder::encodeData(const QImage& image) void JPEGVideoEncoder::encodeData(const QImage& image)
{ {
QByteArray qb ; QByteArray qb ;
@ -67,8 +62,6 @@ void JPEGVideoEncoder::encodeData(const QImage& image)
buffer.open(QIODevice::WriteOnly) ; buffer.open(QIODevice::WriteOnly) ;
image.save(&buffer,"JPEG") ; image.save(&buffer,"JPEG") ;
//destination_decoder->receiveEncodedData((unsigned char *)qb.data(),qb.size()) ;
RsVoipDataChunk voip_chunk ; RsVoipDataChunk voip_chunk ;
voip_chunk.data = malloc(qb.size()); voip_chunk.data = malloc(qb.size());
memcpy(voip_chunk.data,qb.data(),qb.size()) ; memcpy(voip_chunk.data,qb.data(),qb.size()) ;
@ -76,7 +69,5 @@ void JPEGVideoEncoder::encodeData(const QImage& image)
voip_chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO ; voip_chunk.type = RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO ;
_out_queue.push_back(voip_chunk) ; _out_queue.push_back(voip_chunk) ;
std::cerr << "sending encoded data. size = " << std::dec << qb.size() << std::endl;
} }

View File

@ -12,7 +12,7 @@ class QVideoOutputDevice ;
class VideoDecoder class VideoDecoder
{ {
public: public:
VideoDecoder() { _output_device = NULL ;} VideoDecoder() ;
// Gets the next image to be displayed. Once returned, the image should // Gets the next image to be displayed. Once returned, the image should
// be cleared from the incoming queue. // be cleared from the incoming queue.
@ -21,6 +21,10 @@ class VideoDecoder
virtual void receiveEncodedData(const unsigned char *data,uint32_t size) ; virtual void receiveEncodedData(const unsigned char *data,uint32_t size) ;
// returns the current (measured) frame rate in bytes per second.
//
uint32_t currentFrameRate() const;
private: private:
QVideoOutputDevice *_output_device ; QVideoOutputDevice *_output_device ;
@ -30,12 +34,12 @@ class VideoDecoder
// //
virtual QImage decodeData(const unsigned char *encoded_image,uint32_t encoded_image_size) = 0 ; virtual QImage decodeData(const unsigned char *encoded_image,uint32_t encoded_image_size) = 0 ;
// This buffer accumulated incoming encoded data, until a full packet is obtained, // // This buffer accumulated incoming encoded data, until a full packet is obtained,
// since the stream might not send images at once. When incoming images are decoded, the // // since the stream might not send images at once. When incoming images are decoded, the
// data is removed from the buffer. // // data is removed from the buffer.
// // //
unsigned char *buffer ; // unsigned char *buffer ;
uint32_t buffer_size ; // uint32_t buffer_size ;
}; };
// This class encodes video using a video codec (possibly homemade, or based on existing codecs) // This class encodes video using a video codec (possibly homemade, or based on existing codecs)
@ -52,6 +56,11 @@ class VideoEncoder
bool packetReady() const { return !_out_queue.empty() ; } 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.
//
void setMaximumFrameRate(uint32_t bytes_per_second) ;
protected: protected:
//virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ; //virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ;
virtual void encodeData(const QImage& image) = 0 ; virtual void encodeData(const QImage& image) = 0 ;

View File

@ -47,8 +47,9 @@
RsVoip *rsVoip = NULL; RsVoip *rsVoip = NULL;
#define MAX_PONG_RESULTS 150 #define MAX_PONG_RESULTS 150
#define VORS_PING_PERIOD 10 #define VORS_PING_PERIOD 10
#define VORS_BANDWIDTH_PERIOD 5
/************ IMPLEMENTATION NOTES ********************************* /************ IMPLEMENTATION NOTES *********************************
* *
@ -121,6 +122,7 @@ p3VoRS::p3VoRS(RsPluginHandler *handler,PluginNotifier *notifier)
addSerialType(new RsVoipSerialiser()); addSerialType(new RsVoipSerialiser());
mSentPingTime = 0; mSentPingTime = 0;
mSentBandwidthInfoTime = 0;
mCounter = 0; mCounter = 0;
//plugin default configuration //plugin default configuration
@ -170,20 +172,49 @@ int p3VoRS::sendPackets()
{ {
time_t now = time(NULL); time_t now = time(NULL);
time_t pt; time_t pt;
time_t pt2;
{ {
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
pt = mSentPingTime; pt = mSentPingTime;
pt2 = mSentBandwidthInfoTime;
} }
if (now - pt > VORS_PING_PERIOD) if (now > pt + VORS_PING_PERIOD)
{ {
sendPingMeasurements(); sendPingMeasurements();
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
mSentPingTime = now; mSentPingTime = now;
} }
if (now > pt2 + VORS_BANDWIDTH_PERIOD)
{
sendBandwidthInfo();
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
mSentBandwidthInfoTime = now;
}
return true ; return true ;
} }
void p3VoRS::sendBandwidthInfo()
{
std::set<RsPeerId> onlineIds;
mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds);
RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/
for(std::map<RsPeerId,VorsPeerInfo>::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.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) ;
}
}
int p3VoRS::sendVoipHangUpCall(const RsPeerId &peer_id) int p3VoRS::sendVoipHangUpCall(const RsPeerId &peer_id)
{ {
RsVoipProtocolItem *item = new RsVoipProtocolItem ; RsVoipProtocolItem *item = new RsVoipProtocolItem ;
@ -220,7 +251,18 @@ int p3VoRS::sendVoipRinging(const RsPeerId &peer_id)
return true ; return true ;
} }
int p3VoRS::sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec)
{
RsVoipProtocolItem *item = new RsVoipProtocolItem ;
item->protocol = RsVoipProtocolItem::VoipProtocol_Bandwidth ;
item->flags = bytes_per_sec ;
item->PeerId(peer_id) ;
sendItem(item) ;
return true ;
}
int p3VoRS::sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk) int p3VoRS::sendVoipData(const RsPeerId& peer_id,const RsVoipDataChunk& chunk)
{ {
#ifdef DEBUG_VORS #ifdef DEBUG_VORS
@ -331,6 +373,11 @@ void p3VoRS::handleProtocol(RsVoipProtocolItem *item)
case RsVoipProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId()); case RsVoipProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId());
#ifdef DEBUG_VORS #ifdef DEBUG_VORS
std::cerr << "p3VoRS::handleProtocol(): Received protocol Close call." << std::endl; std::cerr << "p3VoRS::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;
#endif #endif
break ; break ;
default: default:
@ -350,19 +397,20 @@ void p3VoRS::handleData(RsVoipDataItem *item)
std::map<RsPeerId,VorsPeerInfo>::iterator it = mPeerInfo.find(item->PeerId()) ; std::map<RsPeerId,VorsPeerInfo>::iterator it = mPeerInfo.find(item->PeerId()) ;
std::cerr << "Received VOIP data item. size = " << item->data_size << ", flags=" << item->flags <<std::endl;
if(it == mPeerInfo.end()) if(it == mPeerInfo.end())
{ {
std::cerr << "Peer unknown to VOIP process. Dropping data" << std::endl; std::cerr << "Peer unknown to VOIP process. Dropping data" << std::endl;
delete item ; delete item ;
return ;
} }
else it->second.incoming_queue.push_back(item) ; // be careful with the delete action!
{
it->second.incoming_queue.push_back(item) ; // be careful with the delete action!
mNotify->notifyReceivedVoipData(item->PeerId()); // 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());
} }
bool p3VoRS::getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk>& incoming_data_chunks) bool p3VoRS::getIncomingData(const RsPeerId& peer_id,std::vector<RsVoipDataChunk>& incoming_data_chunks)
@ -609,7 +657,6 @@ VorsPeerInfo *p3VoRS::locked_GetPeerInfo(const RsPeerId &id)
mPeerInfo[id] = pinfo; mPeerInfo[id] = pinfo;
it = mPeerInfo.find(id); it = mPeerInfo.find(id);
} }
return &(it->second); return &(it->second);
@ -626,6 +673,8 @@ bool VorsPeerInfo::initialisePeerInfo(const RsPeerId& id)
mSentPings = 0; mSentPings = 0;
mLostPongs = 0; mLostPongs = 0;
average_incoming_bandwidth = 0 ;
total_bytes_received = 0 ;
mPongResults.clear(); mPongResults.clear();

View File

@ -53,6 +53,8 @@ class VorsPeerInfo
uint32_t mLostPongs; uint32_t mLostPongs;
uint32_t mSentPings; uint32_t mSentPings;
uint32_t total_bytes_received ;
uint32_t average_incoming_bandwidth ;
std::list<RsVoipPongResult> mPongResults; std::list<RsVoipPongResult> mPongResults;
std::list<RsVoipDataItem*> incoming_queue ; std::list<RsVoipDataItem*> incoming_queue ;
@ -136,7 +138,9 @@ class p3VoRS: public RsPQIService, public RsVoip
private: private:
int sendPackets(); int sendPackets();
void sendPingMeasurements(); void sendPingMeasurements();
//int processIncoming(); void sendBandwidthInfo();
int sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ;
int handlePing(RsVoipPingItem *item); int handlePing(RsVoipPingItem *item);
int handlePong(RsVoipPongItem *item); int handlePong(RsVoipPongItem *item);
@ -156,6 +160,7 @@ class p3VoRS: public RsPQIService, public RsVoip
std::map<RsPeerId, VorsPeerInfo> mPeerInfo; std::map<RsPeerId, VorsPeerInfo> mPeerInfo;
time_t mSentPingTime; time_t mSentPingTime;
time_t mSentBandwidthInfoTime;
uint32_t mCounter; uint32_t mCounter;
RsServiceControl *mServiceControl; RsServiceControl *mServiceControl;

View File

@ -181,9 +181,8 @@ bool RsVoipDataItem::serialise(void *data, uint32_t& pktsize)
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, flags); ok &= setRawUInt32(data, tlvsize, &offset, flags);
ok &= setRawUInt32(data, tlvsize, &offset, data_size); ok &= setRawUInt32(data, tlvsize, &offset, data_size);
std::cerr << "data_size : " << data_size << std::endl;
//memcpy(data+offset,voip_data,data_size) ; memcpy( &((uint8_t*)data)[offset],voip_data,data_size) ;
memcpy( &((uint8_t*)data)[offset],voip_data,data_size) ;
offset += data_size ; offset += data_size ;
if (offset != tlvsize) if (offset != tlvsize)
@ -239,7 +238,7 @@ RsVoipProtocolItem::RsVoipProtocolItem(void *data, uint32_t pktsize)
uint32_t offset = 0; uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PING != getRsItemSubType(rstype))) if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_VOIP_PLUGIN != getRsItemService(rstype)) || (RS_PKT_SUBTYPE_VOIP_PROTOCOL != getRsItemSubType(rstype)))
throw std::runtime_error("Wrong packet type!") ; throw std::runtime_error("Wrong packet type!") ;
if (pktsize < rssize) /* check size */ if (pktsize < rssize) /* check size */

View File

@ -106,7 +106,7 @@ class RsVoipProtocolItem: public RsVoipItem
RsVoipProtocolItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {} RsVoipProtocolItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {}
RsVoipProtocolItem(void *data,uint32_t size) ; RsVoipProtocolItem(void *data,uint32_t size) ;
enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3 } ; enum { VoipProtocol_Ring = 1, VoipProtocol_Ackn = 2, VoipProtocol_Close = 3, VoipProtocol_Bandwidth = 4 } ;
virtual bool serialise(void *data,uint32_t& size) ; virtual bool serialise(void *data,uint32_t& size) ;
virtual uint32_t serial_size() const ; virtual uint32_t serial_size() const ;