From c6103b7535b60b553b689bf81bd5689af19774d5 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 20 Jul 2014 20:50:36 +0000 Subject: [PATCH] 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 --- plugins/VOIP/VOIPPlugin.cpp | 1 + plugins/VOIP/gui/PluginGUIHandler.cpp | 34 +++++++++-- plugins/VOIP/gui/PluginGUIHandler.h | 2 + plugins/VOIP/gui/PluginNotifier.cpp | 4 ++ plugins/VOIP/gui/PluginNotifier.h | 3 + plugins/VOIP/gui/QVideoDevice.cpp | 10 ++-- plugins/VOIP/gui/QVideoDevice.h | 1 + plugins/VOIP/gui/VOIPChatWidgetHolder.cpp | 35 +++++------ plugins/VOIP/gui/VOIPChatWidgetHolder.h | 1 + plugins/VOIP/gui/VideoProcessor.cpp | 29 ++++----- plugins/VOIP/gui/VideoProcessor.h | 23 +++++--- plugins/VOIP/services/p3vors.cc | 71 +++++++++++++++++++---- plugins/VOIP/services/p3vors.h | 7 ++- plugins/VOIP/services/rsvoipitems.cc | 7 +-- plugins/VOIP/services/rsvoipitems.h | 2 +- 15 files changed, 157 insertions(+), 73 deletions(-) diff --git a/plugins/VOIP/VOIPPlugin.cpp b/plugins/VOIP/VOIPPlugin.cpp index e3843a53b..535ac828c 100644 --- a/plugins/VOIP/VOIPPlugin.cpp +++ b/plugins/VOIP/VOIPPlugin.cpp @@ -71,6 +71,7 @@ VOIPPlugin::VOIPPlugin() 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(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) diff --git a/plugins/VOIP/gui/PluginGUIHandler.cpp b/plugins/VOIP/gui/PluginGUIHandler.cpp index a2209b635..ce2f8a066 100644 --- a/plugins/VOIP/gui/PluginGUIHandler.cpp +++ b/plugins/VOIP/gui/PluginGUIHandler.cpp @@ -24,8 +24,6 @@ void PluginGUIHandler::ReceivedVoipAccept(const QString& /*peer_id*/) void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id) { - std::cerr << "****** Plugin GUI handler: received VoipData!" << std::endl; - RsPeerId peer_id(qpeer_id.toStdString()) ; std::vector chunks ; @@ -54,10 +52,7 @@ void PluginGUIHandler::ReceivedVoipData(const QString& qpeer_id) if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_AUDIO) acwh->addAudioData(QString::fromStdString(peer_id.toStdString()),&qb); else if(chunks[chunkIndex].type == RsVoipDataChunk::RS_VOIP_DATA_TYPE_VIDEO) - { acwh->addVideoData(QString::fromStdString(peer_id.toStdString()),&qb); - std::cerr << "data triaged as video." << std::endl; - } else 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 &chatWidgetHolderList = cw->chatWidgetHolderList(); + + foreach (ChatWidgetHolder *chatWidgetHolder, chatWidgetHolderList) + { + VOIPChatWidgetHolder *acwh = dynamic_cast(chatWidgetHolder) ; + + if (acwh) + acwh->setAcceptedBandwidth(QString::fromStdString(peer_id.toStdString()),bytes_per_sec); + } +} diff --git a/plugins/VOIP/gui/PluginGUIHandler.h b/plugins/VOIP/gui/PluginGUIHandler.h index cf7a1022d..05c34dca2 100644 --- a/plugins/VOIP/gui/PluginGUIHandler.h +++ b/plugins/VOIP/gui/PluginGUIHandler.h @@ -5,6 +5,7 @@ // in the main GUI thread. // +#include #include class PluginGUIHandler: public QObject @@ -16,4 +17,5 @@ class PluginGUIHandler: public QObject void ReceivedVoipData(const QString& peer_id) ; void ReceivedVoipHangUp(const QString& peer_id) ; void ReceivedVoipAccept(const QString& peer_id) ; + void ReceivedVoipBandwidthInfo(const QString& peer_id,int) ; }; diff --git a/plugins/VOIP/gui/PluginNotifier.cpp b/plugins/VOIP/gui/PluginNotifier.cpp index 2b5755f46..c9b09c078 100644 --- a/plugins/VOIP/gui/PluginNotifier.cpp +++ b/plugins/VOIP/gui/PluginNotifier.cpp @@ -16,3 +16,7 @@ void PluginNotifier::notifyReceivedVoipHangUp(const RsPeerId &peer_id) { 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) ; +} diff --git a/plugins/VOIP/gui/PluginNotifier.h b/plugins/VOIP/gui/PluginNotifier.h index 7a8339adf..85dfbdd50 100644 --- a/plugins/VOIP/gui/PluginNotifier.h +++ b/plugins/VOIP/gui/PluginNotifier.h @@ -17,10 +17,13 @@ class PluginNotifier: public QObject void notifyReceivedVoipInvite(const RsPeerId &peer_id) ; void notifyReceivedVoipHangUp(const RsPeerId& peer_id) ; void notifyReceivedVoipAccept(const RsPeerId &peer_id) ; + void notifyReceivedVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ; signals: 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 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 voipBandwidthInfoReceived(const QString& peer_id,int bytes_per_sec) ; // emitted when measured bandwidth info is received by the peer. }; + diff --git a/plugins/VOIP/gui/QVideoDevice.cpp b/plugins/VOIP/gui/QVideoDevice.cpp index 7b2b14c8f..d6551ea38 100644 --- a/plugins/VOIP/gui/QVideoDevice.cpp +++ b/plugins/VOIP/gui/QVideoDevice.cpp @@ -95,17 +95,17 @@ QVideoInputDevice::~QVideoInputDevice() QVideoOutputDevice::QVideoOutputDevice(QWidget *parent) : QLabel(parent) +{ + showFrameOff() ; +} + +void QVideoOutputDevice::showFrameOff() { setPixmap(QPixmap(":/images/video-icon-big.png").scaled(170,128,Qt::KeepAspectRatio,Qt::SmoothTransformation)) ; } 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)) ; } diff --git a/plugins/VOIP/gui/QVideoDevice.h b/plugins/VOIP/gui/QVideoDevice.h index d2e77b938..f20d0d7c0 100644 --- a/plugins/VOIP/gui/QVideoDevice.h +++ b/plugins/VOIP/gui/QVideoDevice.h @@ -15,6 +15,7 @@ class QVideoOutputDevice: public QLabel QVideoOutputDevice(QWidget *parent) ; void showFrame(const QImage&) ; + void showFrameOff() ; }; // Responsible for grabbing the video from the webcam and sending it to the diff --git a/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp b/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp index 5b5355f63..889fc13f8 100644 --- a/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp +++ b/plugins/VOIP/gui/VOIPChatWidgetHolder.cpp @@ -24,8 +24,6 @@ VOIPChatWidgetHolder::VOIPChatWidgetHolder(ChatWidget *chatWidget) : QObject(), ChatWidgetHolder(chatWidget) { - std::cerr << "****** VOIPLugin: Creating new VOIPChatWidgetHolder !!" << std::endl; - QIcon icon ; icon.addPixmap(QPixmap(":/images/audio-volume-muted-22.png")) ; icon.addPixmap(QPixmap(":/images/audio-volume-medium-22.png"),QIcon::Normal,QIcon::On) ; @@ -136,7 +134,6 @@ VOIPChatWidgetHolder::~VOIPChatWidgetHolder() void VOIPChatWidgetHolder::toggleAudioListen() { - std::cerr << "******** VOIPLugin: Toggling audio listen!" << std::endl; if (audioListenToggleButton->isChecked()) { audioListenToggleButton->setToolTip(tr("Mute yourself")); } else { @@ -150,22 +147,19 @@ void VOIPChatWidgetHolder::toggleAudioListen() void VOIPChatWidgetHolder::hangupCall() { - std::cerr << "******** VOIPLugin: Hangup call!" << std::endl; - - disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); - if (inputAudioDevice) { - inputAudioDevice->stop(); - } - if (outputAudioDevice) { - outputAudioDevice->stop(); - } - audioListenToggleButton->setChecked(false); - audioCaptureToggleButton->setChecked(false); + disconnect(inputAudioProcessor, SIGNAL(networkPacketReady()), this, SLOT(sendAudioData())); + if (inputAudioDevice) { + inputAudioDevice->stop(); + } + if (outputAudioDevice) { + outputAudioDevice->stop(); + } + audioListenToggleButton->setChecked(false); + audioCaptureToggleButton->setChecked(false); } void VOIPChatWidgetHolder::toggleAudioCapture() { - std::cerr << "******** VOIPLugin: Toggling audio mute capture!" << std::endl; if (audioCaptureToggleButton->isChecked()) { //activate audio output audioListenToggleButton->setChecked(true); @@ -199,8 +193,6 @@ void VOIPChatWidgetHolder::toggleAudioCapture() } void VOIPChatWidgetHolder::toggleVideoCapture() { - std::cerr << "******** VOIPLugin: Toggling video capture!" << std::endl; - if (videoCaptureToggleButton->isChecked()) { //activate video input @@ -216,6 +208,7 @@ void VOIPChatWidgetHolder::toggleVideoCapture() { inputVideoDevice->stop() ; 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()) ; } +void VOIPChatWidgetHolder::setAcceptedBandwidth(const QString name, uint32_t bytes_per_sec) +{ + inputVideoProcessor->setMaximumFrameRate(bytes_per_sec) ; +} + void VOIPChatWidgetHolder::addAudioData(const QString name, QByteArray* array) { if (!audioCaptureToggleButton->isChecked()) { @@ -288,10 +286,7 @@ void VOIPChatWidgetHolder::sendVideoData() RsVoipDataChunk chunk ; while(inputVideoDevice && inputVideoDevice->getNextEncodedPacket(chunk)) - { - std::cerr << "Video data ready: sending it" << std::endl; rsVoip->sendVoipData(mChatWidget->getPeerId(),chunk) ; - } } void VOIPChatWidgetHolder::sendAudioData() diff --git a/plugins/VOIP/gui/VOIPChatWidgetHolder.h b/plugins/VOIP/gui/VOIPChatWidgetHolder.h index 8a528541e..633f1395b 100644 --- a/plugins/VOIP/gui/VOIPChatWidgetHolder.h +++ b/plugins/VOIP/gui/VOIPChatWidgetHolder.h @@ -25,6 +25,7 @@ public: void addAudioData(const QString name, QByteArray* array) ; void addVideoData(const QString name, QByteArray* array) ; + void setAcceptedBandwidth(const QString name, uint32_t bytes_per_sec) ; private slots: void toggleAudioListen(); diff --git a/plugins/VOIP/gui/VideoProcessor.cpp b/plugins/VOIP/gui/VideoProcessor.cpp index 02c868849..f1167ddad 100644 --- a/plugins/VOIP/gui/VideoProcessor.cpp +++ b/plugins/VOIP/gui/VideoProcessor.cpp @@ -7,21 +7,13 @@ #include "VideoProcessor.h" #include "QVideoDevice.h" -//bool VideoDecoder::getNextImage(QImage& image) -//{ -// if(_image_queue.empty()) -// return false ; -// -// image = _image_queue.front() ; -// _image_queue.pop_front() ; -// -// return true ; -//} +VideoDecoder::VideoDecoder() +{ + _output_device = NULL ; +} bool VideoEncoder::addImage(const QImage& img) { - std::cerr << "VideoEncoder: adding image." << std::endl; - encodeData(img) ; return true ; @@ -48,10 +40,7 @@ QImage JPEGVideoDecoder::decodeData(const unsigned char *encoded_image_data,uint QByteArray qb((char*)encoded_image_data,size) ; QImage image ; if(image.loadFromData(qb,"JPEG")) - { - std::cerr << "image decoded successfully" << std::endl; return image ; - } else { 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) { QByteArray qb ; @@ -67,8 +62,6 @@ void JPEGVideoEncoder::encodeData(const QImage& image) buffer.open(QIODevice::WriteOnly) ; image.save(&buffer,"JPEG") ; - //destination_decoder->receiveEncodedData((unsigned char *)qb.data(),qb.size()) ; - RsVoipDataChunk voip_chunk ; voip_chunk.data = malloc(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 ; _out_queue.push_back(voip_chunk) ; - - std::cerr << "sending encoded data. size = " << std::dec << qb.size() << std::endl; } diff --git a/plugins/VOIP/gui/VideoProcessor.h b/plugins/VOIP/gui/VideoProcessor.h index e0bea8e83..2771bd6e9 100644 --- a/plugins/VOIP/gui/VideoProcessor.h +++ b/plugins/VOIP/gui/VideoProcessor.h @@ -12,7 +12,7 @@ class QVideoOutputDevice ; class VideoDecoder { public: - VideoDecoder() { _output_device = NULL ;} + VideoDecoder() ; // Gets the next image to be displayed. Once returned, the image should // be cleared from the incoming queue. @@ -21,6 +21,10 @@ class VideoDecoder 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: QVideoOutputDevice *_output_device ; @@ -30,12 +34,12 @@ class VideoDecoder // 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, - // since the stream might not send images at once. When incoming images are decoded, the - // data is removed from the buffer. - // - unsigned char *buffer ; - uint32_t buffer_size ; +// // 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 +// // data is removed from the buffer. +// // +// unsigned char *buffer ; +// uint32_t buffer_size ; }; // 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 nextPacket(RsVoipDataChunk& ) ; + + // Used to tweak the compression ratio so that the video can stream ok. + // + void setMaximumFrameRate(uint32_t bytes_per_second) ; + protected: //virtual bool sendEncodedData(unsigned char *mem,uint32_t size) = 0 ; virtual void encodeData(const QImage& image) = 0 ; diff --git a/plugins/VOIP/services/p3vors.cc b/plugins/VOIP/services/p3vors.cc index 7652c926b..c627b7de7 100644 --- a/plugins/VOIP/services/p3vors.cc +++ b/plugins/VOIP/services/p3vors.cc @@ -47,8 +47,9 @@ RsVoip *rsVoip = NULL; -#define MAX_PONG_RESULTS 150 -#define VORS_PING_PERIOD 10 +#define MAX_PONG_RESULTS 150 +#define VORS_PING_PERIOD 10 +#define VORS_BANDWIDTH_PERIOD 5 /************ IMPLEMENTATION NOTES ********************************* * @@ -121,6 +122,7 @@ p3VoRS::p3VoRS(RsPluginHandler *handler,PluginNotifier *notifier) addSerialType(new RsVoipSerialiser()); mSentPingTime = 0; + mSentBandwidthInfoTime = 0; mCounter = 0; //plugin default configuration @@ -170,20 +172,49 @@ int p3VoRS::sendPackets() { time_t now = time(NULL); time_t pt; + time_t pt2; { RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ pt = mSentPingTime; + pt2 = mSentBandwidthInfoTime; } - if (now - pt > VORS_PING_PERIOD) + if (now > pt + VORS_PING_PERIOD) { sendPingMeasurements(); RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ mSentPingTime = now; } + if (now > pt2 + VORS_BANDWIDTH_PERIOD) + { + sendBandwidthInfo(); + + RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ + mSentBandwidthInfoTime = now; + } return true ; } +void p3VoRS::sendBandwidthInfo() +{ + std::set onlineIds; + mServiceControl->getPeersConnected(getServiceInfo().mServiceType, onlineIds); + + RsStackMutex stack(mVorsMtx); /****** LOCKED MUTEX *******/ + + for(std::map::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) { RsVoipProtocolItem *item = new RsVoipProtocolItem ; @@ -220,7 +251,18 @@ int p3VoRS::sendVoipRinging(const RsPeerId &peer_id) 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) { #ifdef DEBUG_VORS @@ -331,6 +373,11 @@ void p3VoRS::handleProtocol(RsVoipProtocolItem *item) case RsVoipProtocolItem::VoipProtocol_Close: mNotify->notifyReceivedVoipHangUp(item->PeerId()); #ifdef DEBUG_VORS 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 break ; default: @@ -350,19 +397,20 @@ void p3VoRS::handleData(RsVoipDataItem *item) std::map::iterator it = mPeerInfo.find(item->PeerId()) ; - std::cerr << "Received VOIP data item. size = " << item->data_size << ", flags=" << item->flags <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& incoming_data_chunks) @@ -609,7 +657,6 @@ VorsPeerInfo *p3VoRS::locked_GetPeerInfo(const RsPeerId &id) mPeerInfo[id] = pinfo; it = mPeerInfo.find(id); - } return &(it->second); @@ -626,6 +673,8 @@ bool VorsPeerInfo::initialisePeerInfo(const RsPeerId& id) mSentPings = 0; mLostPongs = 0; + average_incoming_bandwidth = 0 ; + total_bytes_received = 0 ; mPongResults.clear(); diff --git a/plugins/VOIP/services/p3vors.h b/plugins/VOIP/services/p3vors.h index 757daf4e2..78d9cc334 100644 --- a/plugins/VOIP/services/p3vors.h +++ b/plugins/VOIP/services/p3vors.h @@ -53,6 +53,8 @@ class VorsPeerInfo uint32_t mLostPongs; uint32_t mSentPings; + uint32_t total_bytes_received ; + uint32_t average_incoming_bandwidth ; std::list mPongResults; std::list incoming_queue ; @@ -136,7 +138,9 @@ class p3VoRS: public RsPQIService, public RsVoip private: int sendPackets(); void sendPingMeasurements(); - //int processIncoming(); + void sendBandwidthInfo(); + + int sendVoipBandwidth(const RsPeerId &peer_id,uint32_t bytes_per_sec) ; int handlePing(RsVoipPingItem *item); int handlePong(RsVoipPongItem *item); @@ -156,6 +160,7 @@ class p3VoRS: public RsPQIService, public RsVoip std::map mPeerInfo; time_t mSentPingTime; + time_t mSentBandwidthInfoTime; uint32_t mCounter; RsServiceControl *mServiceControl; diff --git a/plugins/VOIP/services/rsvoipitems.cc b/plugins/VOIP/services/rsvoipitems.cc index a68634ea3..1f74a3f5a 100644 --- a/plugins/VOIP/services/rsvoipitems.cc +++ b/plugins/VOIP/services/rsvoipitems.cc @@ -181,9 +181,8 @@ bool RsVoipDataItem::serialise(void *data, uint32_t& pktsize) /* add mandatory parts first */ ok &= setRawUInt32(data, tlvsize, &offset, flags); 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 ; if (offset != tlvsize) @@ -239,7 +238,7 @@ RsVoipProtocolItem::RsVoipProtocolItem(void *data, uint32_t pktsize) 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!") ; if (pktsize < rssize) /* check size */ diff --git a/plugins/VOIP/services/rsvoipitems.h b/plugins/VOIP/services/rsvoipitems.h index 452ffb635..26bb2d0a0 100644 --- a/plugins/VOIP/services/rsvoipitems.h +++ b/plugins/VOIP/services/rsvoipitems.h @@ -106,7 +106,7 @@ class RsVoipProtocolItem: public RsVoipItem RsVoipProtocolItem() :RsVoipItem(RS_PKT_SUBTYPE_VOIP_PROTOCOL) {} 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 uint32_t serial_size() const ;