diff options
Diffstat (limited to 'webrtc/modules/rtp_rtcp/test')
16 files changed, 115 insertions, 2773 deletions
diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc deleted file mode 100644 index 711be4a623..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/BWEStandAlone.cc +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// BWEStandAlone.cpp : Defines the entry point for the console application. -// - -#include <stdio.h> -#include <string> - -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/trace.h" -#include "webrtc/test/channel_transport/udp_transport.h" - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h" -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h" - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h" - -//#include "vld.h" - -class myTransportCB: public UdpTransportData -{ -public: - myTransportCB (RtpRtcp *rtpMod) : _rtpMod(rtpMod) {}; -protected: - // Inherited from UdpTransportData - void IncomingRTPPacket(const int8_t* incomingRtpPacket, - const size_t rtpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) override; - - void IncomingRTCPPacket(const int8_t* incomingRtcpPacket, - const size_t rtcpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) override; - -private: - RtpRtcp *_rtpMod; -}; - -void myTransportCB::IncomingRTPPacket(const int8_t* incomingRtpPacket, - const size_t rtpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) -{ - printf("Receiving RTP from IP %s, port %u\n", fromIP, fromPort); - _rtpMod->IncomingPacket((uint8_t *) incomingRtpPacket, rtpPacketLength); -} - -void myTransportCB::IncomingRTCPPacket(const int8_t* incomingRtcpPacket, - const size_t rtcpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) -{ - printf("Receiving RTCP from IP %s, port %u\n", fromIP, fromPort); - _rtpMod->IncomingPacket((uint8_t *) incomingRtcpPacket, rtcpPacketLength); -} - - -int main(int argc, char* argv[]) -{ - bool isSender = false; - bool isReceiver = false; - uint16_t port; - std::string ip; - TestSenderReceiver *sendrec = new TestSenderReceiver(); - TestLoadGenerator *gen; - - if (argc == 2) - { - // receiver only - isReceiver = true; - - // read port - port = atoi(argv[1]); - } - else if (argc == 3) - { - // sender and receiver - isSender = true; - isReceiver = true; - - // read IP - ip = argv[1]; - - // read port - port = atoi(argv[2]); - } - - Trace::CreateTrace(); - Trace::SetTraceFile("BWEStandAloneTrace.txt"); - Trace::set_level_filter(webrtc::kTraceAll); - - sendrec->InitReceiver(port); - - sendrec->Start(); - - if (isSender) - { - const uint32_t startRateKbps = 1000; - //gen = new CBRGenerator(sendrec, 1000, 500); - gen = new CBRFixFRGenerator(sendrec, startRateKbps, 90000, 30, 0.2); - //gen = new PeriodicKeyFixFRGenerator(sendrec, startRateKbps, 90000, 30, 0.2, 7, 300); - //const uint16_t numFrameRates = 5; - //const uint8_t frameRates[numFrameRates] = {30, 15, 20, 23, 25}; - //gen = new CBRVarFRGenerator(sendrec, 1000, frameRates, numFrameRates, 90000, 4.0, 0.1, 0.2); - //gen = new CBRFrameDropGenerator(sendrec, startRateKbps, 90000, 0.2); - sendrec->SetLoadGenerator(gen); - sendrec->InitSender(startRateKbps, ip.c_str(), port); - gen->Start(); - } - - while (1) - { - } - - if (isSender) - { - gen->Stop(); - delete gen; - } - - delete sendrec; - - //uint8_t numberOfSocketThreads = 1; - //UdpTransport* transport = UdpTransport::Create(0, numberOfSocketThreads); - - //RtpRtcp* rtp = RtpRtcp::CreateRtpRtcp(1, false); - //if (rtp->InitSender() != 0) - //{ - // exit(1); - //} - //if (rtp->RegisterSendTransport(transport) != 0) - //{ - // exit(1); - //} - -// transport->InitializeSendSockets("192.168.200.39", 8000); - //transport->InitializeSendSockets("127.0.0.1", 10000); - //transport->InitializeSourcePorts(8000); - - - return(0); - // myTransportCB *tp = new myTransportCB(rtp); - // transport->InitializeReceiveSockets(tp, 10000, "0.0.0.0"); - // transport->StartReceiving(500); - - // int8_t data[100]; - // for (int i = 0; i < 100; data[i] = i++); - - // for (int i = 0; i < 100; i++) - // { - // transport->SendRaw(data, 100, false); - // } - - - - // int32_t totTime = 0; - // while (totTime < 10000) - // { - // transport->Process(); - // int32_t wTime = transport->TimeUntilNextProcess(); - // totTime += wTime; - // Sleep(wTime); - // } - - - //if (transport) - //{ - // // Destroy the Socket Transport module - // transport->StopReceiving(); - // transport->InitializeReceiveSockets(NULL,0);// deregister callback - // UdpTransport::Destroy(transport); - // transport = NULL; - // } - - // if (tp) - // { - // delete tp; - // tp = NULL; - // } - - // if (rtp) - // { - // RtpRtcp::DestroyRtpRtcp(rtp); - // rtp = NULL; - // } - - - //return 0; -} diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc deleted file mode 100644 index fe54d67ee7..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.cc +++ /dev/null @@ -1,1055 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h" - -#include <math.h> -#include <stdio.h> - -#include <algorithm> -#include <sstream> - -#ifdef MATLAB -#include "engine.h" -#endif - -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" - -using namespace webrtc; - -#ifdef MATLAB -MatlabEngine eng; - -MatlabLine::MatlabLine(int maxLen /*= -1*/, const char *plotAttrib /*= NULL*/, const char *name /*= NULL*/) -: -_xArray(NULL), -_yArray(NULL), -_maxLen(maxLen), -_plotAttribute(), -_name() -{ - if (_maxLen > 0) - { - _xArray = mxCreateDoubleMatrix(1, _maxLen, mxREAL); - _yArray = mxCreateDoubleMatrix(1, _maxLen, mxREAL); - } - - if (plotAttrib) - { - _plotAttribute = plotAttrib; - } - - if (name) - { - _name = name; - } -} - -MatlabLine::~MatlabLine() -{ - if (_xArray != NULL) - { - mxDestroyArray(_xArray); - } - if (_yArray != NULL) - { - mxDestroyArray(_yArray); - } -} - -void MatlabLine::Append(double x, double y) -{ - if (_maxLen > 0 && _xData.size() > static_cast<uint32_t>(_maxLen)) - { - _xData.resize(_maxLen); - _yData.resize(_maxLen); - } - - _xData.push_front(x); - _yData.push_front(y); -} - - -// append y-data with running integer index as x-data -void MatlabLine::Append(double y) -{ - if (_xData.empty()) - { - // first element is index 0 - Append(0, y); - } - else - { - // take last x-value and increment - double temp = _xData.back(); // last x-value - Append(temp + 1, y); - } -} - - -void MatlabLine::SetMaxLen(int maxLen) -{ - if (maxLen <= 0) - { - // means no maxLen - _maxLen = -1; - } - else - { - _maxLen = maxLen; - - if (_xArray != NULL) - { - mxDestroyArray(_xArray); - mxDestroyArray(_yArray); - } - _xArray = mxCreateDoubleMatrix(1, _maxLen, mxREAL); - _yArray = mxCreateDoubleMatrix(1, _maxLen, mxREAL); - - maxLen = ((unsigned int)maxLen <= _xData.size()) ? maxLen : (int)_xData.size(); - _xData.resize(maxLen); - _yData.resize(maxLen); - - //// reserve the right amount of memory - //_xData.reserve(_maxLen); - //_yData.reserve(_maxLen); - } -} - -void MatlabLine::SetAttribute(char *plotAttrib) -{ - _plotAttribute = plotAttrib; -} - -void MatlabLine::SetName(char *name) -{ - _name = name; -} - -void MatlabLine::GetPlotData(mxArray** xData, mxArray** yData) -{ - // Make sure we have enough Matlab allocated memory. - // Assuming both arrays (x and y) are of the same size. - if (_xData.empty()) - { - return; // No data - } - unsigned int size = 0; - if (_xArray != NULL) - { - size = (unsigned int)mxGetNumberOfElements(_xArray); - } - if (size < _xData.size()) - { - if (_xArray != NULL) - { - mxDestroyArray(_xArray); - mxDestroyArray(_yArray); - } - _xArray = mxCreateDoubleMatrix(1, _xData.size(), mxREAL); - _yArray = mxCreateDoubleMatrix(1, _yData.size(), mxREAL); - } - - if (!_xData.empty()) - { - double* x = mxGetPr(_xArray); - - std::list<double>::iterator it = _xData.begin(); - - for (int i = 0; it != _xData.end(); it++, i++) - { - x[i] = *it; - } - } - - if (!_yData.empty()) - { - double* y = mxGetPr(_yArray); - - std::list<double>::iterator it = _yData.begin(); - - for (int i = 0; it != _yData.end(); it++, i++) - { - y[i] = *it; - } - } - *xData = _xArray; - *yData = _yArray; -} - -std::string MatlabLine::GetXName() -{ - std::ostringstream xString; - xString << "x_" << _name; - return xString.str(); -} - -std::string MatlabLine::GetYName() -{ - std::ostringstream yString; - yString << "y_" << _name; - return yString.str(); -} - -std::string MatlabLine::GetPlotString() -{ - - std::ostringstream s; - - if (_xData.size() == 0) - { - s << "[0 1], [0 1]"; // To get an empty plot - } - else - { - s << GetXName() << "(1:" << _xData.size() << "),"; - s << GetYName() << "(1:" << _yData.size() << ")"; - } - - s << ", '"; - s << _plotAttribute; - s << "'"; - - return s.str(); -} - -std::string MatlabLine::GetRefreshString() -{ - std::ostringstream s; - - if (_xData.size() > 0) - { - s << "set(h,'xdata',"<< GetXName() <<"(1:" << _xData.size() << "),'ydata',"<< GetYName() << "(1:" << _yData.size() << "));"; - } - else - { - s << "set(h,'xdata',[NaN],'ydata',[NaN]);"; - } - return s.str(); -} - -std::string MatlabLine::GetLegendString() -{ - return ("'" + _name + "'"); -} - -bool MatlabLine::hasLegend() -{ - return (!_name.empty()); -} - - -// remove data points, but keep attributes -void MatlabLine::Reset() -{ - _xData.clear(); - _yData.clear(); -} - - -void MatlabLine::UpdateTrendLine(MatlabLine * sourceData, double slope, double offset) -{ - Reset(); // reset data, not attributes and name - - double thexMin = sourceData->xMin(); - double thexMax = sourceData->xMax(); - Append(thexMin, thexMin * slope + offset); - Append(thexMax, thexMax * slope + offset); -} - -double MatlabLine::xMin() -{ - if (!_xData.empty()) - { - std::list<double>::iterator theStart = _xData.begin(); - std::list<double>::iterator theEnd = _xData.end(); - return(*min_element(theStart, theEnd)); - } - return (0.0); -} - -double MatlabLine::xMax() -{ - if (!_xData.empty()) - { - std::list<double>::iterator theStart = _xData.begin(); - std::list<double>::iterator theEnd = _xData.end(); - return(*max_element(theStart, theEnd)); - } - return (0.0); -} - -double MatlabLine::yMin() -{ - if (!_yData.empty()) - { - std::list<double>::iterator theStart = _yData.begin(); - std::list<double>::iterator theEnd = _yData.end(); - return(*min_element(theStart, theEnd)); - } - return (0.0); -} - -double MatlabLine::yMax() -{ - if (!_yData.empty()) - { - std::list<double>::iterator theStart = _yData.begin(); - std::list<double>::iterator theEnd = _yData.end(); - return(*max_element(theStart, theEnd)); - } - return (0.0); -} - - - -MatlabTimeLine::MatlabTimeLine(int horizonSeconds /*= -1*/, const char *plotAttrib /*= NULL*/, - const char *name /*= NULL*/, - int64_t refTimeMs /* = -1*/) - : -_timeHorizon(horizonSeconds), -MatlabLine(-1, plotAttrib, name) // infinite number of elements -{ - if (refTimeMs < 0) - _refTimeMs = TickTime::MillisecondTimestamp(); - else - _refTimeMs = refTimeMs; -} - -void MatlabTimeLine::Append(double y) -{ - MatlabLine::Append(static_cast<double>(TickTime::MillisecondTimestamp() - _refTimeMs) / 1000.0, y); - - PurgeOldData(); -} - - -void MatlabTimeLine::PurgeOldData() -{ - if (_timeHorizon > 0) - { - // remove old data - double historyLimit = static_cast<double>(TickTime::MillisecondTimestamp() - _refTimeMs) / 1000.0 - - _timeHorizon; // remove data points older than this - - std::list<double>::reverse_iterator ritx = _xData.rbegin(); - uint32_t removeCount = 0; - while (ritx != _xData.rend()) - { - if (*ritx >= historyLimit) - { - break; - } - ritx++; - removeCount++; - } - if (removeCount == 0) - { - return; - } - - // remove the range [begin, it). - //if (removeCount > 10) - //{ - // printf("Removing %lu elements\n", removeCount); - //} - _xData.resize(_xData.size() - removeCount); - _yData.resize(_yData.size() - removeCount); - } -} - - -int64_t MatlabTimeLine::GetRefTime() -{ - return(_refTimeMs); -} - - - - -MatlabPlot::MatlabPlot() -: -_figHandle(-1), -_smartAxis(false), -_critSect(CriticalSectionWrapper::CreateCriticalSection()), -_timeToPlot(false), -_plotting(false), -_enabled(true), -_firstPlot(true), -_legendEnabled(true), -_donePlottingEvent(EventWrapper::Create()) -{ - CriticalSectionScoped cs(_critSect); - - _xlim[0] = 0; - _xlim[1] = 0; - _ylim[0] = 0; - _ylim[1] = 0; - -#ifdef PLOT_TESTING - _plotStartTime = -1; - _plotDelay = 0; -#endif - -} - - -MatlabPlot::~MatlabPlot() -{ - _critSect->Enter(); - - // delete all line objects - while (!_line.empty()) - { - delete *(_line.end() - 1); - _line.pop_back(); - } - - delete _critSect; - delete _donePlottingEvent; -} - - -int MatlabPlot::AddLine(int maxLen /*= -1*/, const char *plotAttrib /*= NULL*/, const char *name /*= NULL*/) -{ - CriticalSectionScoped cs(_critSect); - if (!_enabled) - { - return -1; - } - - MatlabLine *newLine = new MatlabLine(maxLen, plotAttrib, name); - _line.push_back(newLine); - - return (static_cast<int>(_line.size() - 1)); // index of newly inserted line -} - - -int MatlabPlot::AddTimeLine(int maxLen /*= -1*/, const char *plotAttrib /*= NULL*/, const char *name /*= NULL*/, - int64_t refTimeMs /*= -1*/) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return -1; - } - - MatlabTimeLine *newLine = new MatlabTimeLine(maxLen, plotAttrib, name, refTimeMs); - _line.push_back(newLine); - - return (static_cast<int>(_line.size() - 1)); // index of newly inserted line -} - - -int MatlabPlot::GetLineIx(const char *name) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return -1; - } - - // search the list for a matching line name - std::vector<MatlabLine*>::iterator it = _line.begin(); - bool matchFound = false; - int lineIx = 0; - - for (; it != _line.end(); it++, lineIx++) - { - if ((*it)->_name == name) - { - matchFound = true; - break; - } - } - - if (matchFound) - { - return (lineIx); - } - else - { - return (-1); - } -} - - -void MatlabPlot::Append(int lineIndex, double x, double y) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return; - } - - // sanity for index - if (lineIndex < 0 || lineIndex >= static_cast<int>(_line.size())) - { - throw "Line index out of range"; - exit(1); - } - - return (_line[lineIndex]->Append(x, y)); -} - - -void MatlabPlot::Append(int lineIndex, double y) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return; - } - - // sanity for index - if (lineIndex < 0 || lineIndex >= static_cast<int>(_line.size())) - { - throw "Line index out of range"; - exit(1); - } - - return (_line[lineIndex]->Append(y)); -} - - -int MatlabPlot::Append(const char *name, double x, double y) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return -1; - } - - // search the list for a matching line name - int lineIx = GetLineIx(name); - - if (lineIx < 0) //(!matchFound) - { - // no match; append new line - lineIx = AddLine(-1, NULL, name); - } - - // append data to line - Append(lineIx, x, y); - return (lineIx); -} - -int MatlabPlot::Append(const char *name, double y) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return -1; - } - - // search the list for a matching line name - int lineIx = GetLineIx(name); - - if (lineIx < 0) //(!matchFound) - { - // no match; append new line - lineIx = AddLine(-1, NULL, name); - } - - // append data to line - Append(lineIx, y); - return (lineIx); -} - -int MatlabPlot::Length(char *name) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return -1; - } - - int ix = GetLineIx(name); - if (ix >= 0) - { - return (static_cast<int>(_line[ix]->_xData.size())); - } - else - { - return (-1); - } -} - - -void MatlabPlot::SetPlotAttribute(char *name, char *plotAttrib) -{ - CriticalSectionScoped cs(_critSect); - - if (!_enabled) - { - return; - } - - int lineIx = GetLineIx(name); - - if (lineIx >= 0) - { - _line[lineIx]->SetAttribute(plotAttrib); - } -} - -// Must be called under critical section _critSect -void MatlabPlot::UpdateData(Engine* ep) -{ - if (!_enabled) - { - return; - } - - for (std::vector<MatlabLine*>::iterator it = _line.begin(); it != _line.end(); it++) - { - mxArray* xData = NULL; - mxArray* yData = NULL; - (*it)->GetPlotData(&xData, &yData); - if (xData != NULL) - { - std::string xName = (*it)->GetXName(); - std::string yName = (*it)->GetYName(); - _critSect->Leave(); -#ifdef MATLAB6 - mxSetName(xData, xName.c_str()); - mxSetName(yData, yName.c_str()); - engPutArray(ep, xData); - engPutArray(ep, yData); -#else - int ret = engPutVariable(ep, xName.c_str(), xData); - assert(ret == 0); - ret = engPutVariable(ep, yName.c_str(), yData); - assert(ret == 0); -#endif - _critSect->Enter(); - } - } -} - -bool MatlabPlot::GetPlotCmd(std::ostringstream & cmd, Engine* ep) -{ - _critSect->Enter(); - - if (!DataAvailable()) - { - return false; - } - - if (_firstPlot) - { - GetPlotCmd(cmd); - _firstPlot = false; - } - else - { - GetRefreshCmd(cmd); - } - - UpdateData(ep); - - _critSect->Leave(); - - return true; -} - -// Call inside critsect -void MatlabPlot::GetPlotCmd(std::ostringstream & cmd) -{ - // we have something to plot - // empty the stream - cmd.str(""); // (this seems to be the only way) - - cmd << "figure; h" << _figHandle << "= plot("; - - // first line - std::vector<MatlabLine*>::iterator it = _line.begin(); - cmd << (*it)->GetPlotString(); - - it++; - - // remaining lines - for (; it != _line.end(); it++) - { - cmd << ", "; - cmd << (*it)->GetPlotString(); - } - - cmd << "); "; - - if (_legendEnabled) - { - GetLegendCmd(cmd); - } - - if (_smartAxis) - { - double xMin = _xlim[0]; - double xMax = _xlim[1]; - double yMax = _ylim[1]; - for (std::vector<MatlabLine*>::iterator it = _line.begin(); it != _line.end(); it++) - { - xMax = std::max(xMax, (*it)->xMax()); - xMin = std::min(xMin, (*it)->xMin()); - - yMax = std::max(yMax, (*it)->yMax()); - yMax = std::max(yMax, fabs((*it)->yMin())); - } - _xlim[0] = xMin; - _xlim[1] = xMax; - _ylim[0] = -yMax; - _ylim[1] = yMax; - - cmd << "axis([" << _xlim[0] << ", " << _xlim[1] << ", " << _ylim[0] << ", " << _ylim[1] << "]);"; - } - - int i=1; - for (it = _line.begin(); it != _line.end(); i++, it++) - { - cmd << "set(h" << _figHandle << "(" << i << "), 'Tag', " << (*it)->GetLegendString() << ");"; - } -} - -// Call inside critsect -void MatlabPlot::GetRefreshCmd(std::ostringstream & cmd) -{ - cmd.str(""); // (this seems to be the only way) - std::vector<MatlabLine*>::iterator it = _line.begin(); - for (it = _line.begin(); it != _line.end(); it++) - { - cmd << "h = findobj(0, 'Tag', " << (*it)->GetLegendString() << ");"; - cmd << (*it)->GetRefreshString(); - } - //if (_legendEnabled) - //{ - // GetLegendCmd(cmd); - //} -} - -void MatlabPlot::GetLegendCmd(std::ostringstream & cmd) -{ - std::vector<MatlabLine*>::iterator it = _line.begin(); - bool anyLegend = false; - for (; it != _line.end(); it++) - { - anyLegend = anyLegend || (*it)->hasLegend(); - } - if (anyLegend) - { - // create the legend - - cmd << "legend(h" << _figHandle << ",{"; - - - // iterate lines - int i = 0; - for (std::vector<MatlabLine*>::iterator it = _line.begin(); it != _line.end(); it++) - { - if (i > 0) - { - cmd << ", "; - } - cmd << (*it)->GetLegendString(); - i++; - } - - cmd << "}, 2); "; // place legend in upper-left corner - } -} - -// Call inside critsect -bool MatlabPlot::DataAvailable() -{ - if (!_enabled) - { - return false; - } - - for (std::vector<MatlabLine*>::iterator it = _line.begin(); it != _line.end(); it++) - { - (*it)->PurgeOldData(); - } - - return true; -} - -void MatlabPlot::Plot() -{ - CriticalSectionScoped cs(_critSect); - - _timeToPlot = true; - -#ifdef PLOT_TESTING - _plotStartTime = TickTime::MillisecondTimestamp(); -#endif -} - - -void MatlabPlot::Reset() -{ - CriticalSectionScoped cs(_critSect); - - _enabled = true; - - for (std::vector<MatlabLine*>::iterator it = _line.begin(); it != _line.end(); it++) - { - (*it)->Reset(); - } - -} - -void MatlabPlot::SetFigHandle(int handle) -{ - CriticalSectionScoped cs(_critSect); - - if (handle > 0) - _figHandle = handle; -} - -bool -MatlabPlot::TimeToPlot() -{ - CriticalSectionScoped cs(_critSect); - return _enabled && _timeToPlot; -} - -void -MatlabPlot::Plotting() -{ - CriticalSectionScoped cs(_critSect); - _plotting = true; -} - -void -MatlabPlot::DonePlotting() -{ - CriticalSectionScoped cs(_critSect); - _timeToPlot = false; - _plotting = false; - _donePlottingEvent->Set(); -} - -void -MatlabPlot::DisablePlot() -{ - _critSect->Enter(); - while (_plotting) - { - _critSect->Leave(); - _donePlottingEvent->Wait(WEBRTC_EVENT_INFINITE); - _critSect->Enter(); - } - _enabled = false; -} - -int MatlabPlot::MakeTrend(const char *sourceName, const char *trendName, double slope, double offset, const char *plotAttrib) -{ - CriticalSectionScoped cs(_critSect); - - int sourceIx; - int trendIx; - - sourceIx = GetLineIx(sourceName); - if (sourceIx < 0) - { - // could not find source - return (-1); - } - - trendIx = GetLineIx(trendName); - if (trendIx < 0) - { - // no trend found; add new line - trendIx = AddLine(2 /*maxLen*/, plotAttrib, trendName); - } - - _line[trendIx]->UpdateTrendLine(_line[sourceIx], slope, offset); - - return (trendIx); - -} - - -MatlabEngine::MatlabEngine() -: -_critSect(CriticalSectionWrapper::CreateCriticalSection()), -_eventPtr(NULL), -_running(false), -_numPlots(0) -{ - _eventPtr = EventWrapper::Create(); - - _plotThread = ThreadWrapper::CreateThread(MatlabEngine::PlotThread, this, - kLowPriority, "MatlabPlot"); - _running = true; - _plotThread->Start(); -} - -MatlabEngine::~MatlabEngine() -{ - _critSect->Enter(); - - if (_plotThread) - { - _running = false; - _eventPtr->Set(); - - _plotThread->Stop(); - } - - _plots.clear(); - - delete _eventPtr; - _eventPtr = NULL; - - _critSect->Leave(); - delete _critSect; - -} - -MatlabPlot * MatlabEngine::NewPlot(MatlabPlot *newPlot) -{ - CriticalSectionScoped cs(_critSect); - - //MatlabPlot *newPlot = new MatlabPlot(); - - if (newPlot) - { - newPlot->SetFigHandle(++_numPlots); // first plot is number 1 - _plots.push_back(newPlot); - } - - return (newPlot); - -} - - -void MatlabEngine::DeletePlot(MatlabPlot *plot) -{ - CriticalSectionScoped cs(_critSect); - - if (plot == NULL) - { - return; - } - - std::vector<MatlabPlot *>::iterator it; - for (it = _plots.begin(); it < _plots.end(); it++) - { - if (plot == *it) - { - break; - } - } - - assert (plot == *it); - - (*it)->DisablePlot(); - - _plots.erase(it); - --_numPlots; - - delete plot; -} - - -bool MatlabEngine::PlotThread(void *obj) -{ - if (!obj) - { - return (false); - } - - MatlabEngine *eng = (MatlabEngine *) obj; - - Engine *ep = engOpen(NULL); - if (!ep) - { - throw "Cannot open Matlab engine"; - return (false); - } - - engSetVisible(ep, true); - engEvalString(ep, "close all;"); - - while (eng->_running) - { - eng->_critSect->Enter(); - - // iterate through all plots - for (unsigned int ix = 0; ix < eng->_plots.size(); ix++) - { - MatlabPlot *plot = eng->_plots[ix]; - if (plot->TimeToPlot()) - { - plot->Plotting(); - eng->_critSect->Leave(); - std::ostringstream cmd; - - if (engEvalString(ep, cmd.str().c_str())) - { - // engine dead - return (false); - } - - // empty the stream - cmd.str(""); // (this seems to be the only way) - if (plot->GetPlotCmd(cmd, ep)) - { - // things to plot, we have already accessed what we need in the plot - plot->DonePlotting(); - - int64_t start = TickTime::MillisecondTimestamp(); - // plot it - int ret = engEvalString(ep, cmd.str().c_str()); - printf("time=%I64i\n", TickTime::MillisecondTimestamp() - start); - if (ret) - { - // engine dead - return (false); - } - -#ifdef PLOT_TESTING - if(plot->_plotStartTime >= 0) - { - plot->_plotDelay = TickTime::MillisecondTimestamp() - plot->_plotStartTime; - plot->_plotStartTime = -1; - } -#endif - } - eng->_critSect->Enter(); - } - } - - eng->_critSect->Leave(); - // wait a while - eng->_eventPtr->Wait(66); // 33 ms - } - - if (ep) - { - engClose(ep); - ep = NULL; - } - - return (true); - -} - -#endif // MATLAB diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h deleted file mode 100644 index 3ed89f8f91..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/MatlabPlot.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_MATLABPLOT_H_ -#define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_MATLABPLOT_H_ - -#include <list> -#include <string> -#include <vector> - -#include "webrtc/typedefs.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" - -namespace webrtc { -class CriticalSectionWrapper; -class EventWrapper; -} - -//#define PLOT_TESTING - -#ifdef MATLAB - -typedef struct engine Engine; -typedef struct mxArray_tag mxArray; - -class MatlabLine -{ - friend class MatlabPlot; - -public: - MatlabLine(int maxLen = -1, const char *plotAttrib = NULL, const char *name = NULL); - ~MatlabLine(); - virtual void Append(double x, double y); - virtual void Append(double y); - void SetMaxLen(int maxLen); - void SetAttribute(char *plotAttrib); - void SetName(char *name); - void Reset(); - virtual void PurgeOldData() {}; - - void UpdateTrendLine(MatlabLine * sourceData, double slope, double offset); - - double xMin(); - double xMax(); - double yMin(); - double yMax(); - -protected: - void GetPlotData(mxArray** xData, mxArray** yData); - std::string GetXName(); - std::string GetYName(); - std::string GetPlotString(); - std::string GetRefreshString(); - std::string GetLegendString(); - bool hasLegend(); - std::list<double> _xData; - std::list<double> _yData; - mxArray* _xArray; - mxArray* _yArray; - int _maxLen; - std::string _plotAttribute; - std::string _name; -}; - - -class MatlabTimeLine : public MatlabLine -{ -public: - MatlabTimeLine(int horizonSeconds = -1, const char *plotAttrib = NULL, const char *name = NULL, - int64_t refTimeMs = -1); - ~MatlabTimeLine() {}; - void Append(double y); - void PurgeOldData(); - int64_t GetRefTime(); - -private: - int64_t _refTimeMs; - int _timeHorizon; -}; - - -class MatlabPlot -{ - friend class MatlabEngine; - -public: - MatlabPlot(); - ~MatlabPlot(); - - int AddLine(int maxLen = -1, const char *plotAttrib = NULL, const char *name = NULL); - int AddTimeLine(int maxLen = -1, const char *plotAttrib = NULL, const char *name = NULL, - int64_t refTimeMs = -1); - int GetLineIx(const char *name); - void Append(int lineIndex, double x, double y); - void Append(int lineIndex, double y); - int Append(const char *name, double x, double y); - int Append(const char *name, double y); - int Length(char *name); - void SetPlotAttribute(char *name, char *plotAttrib); - void Plot(); - void Reset(); - void SmartAxis(bool status = true) { _smartAxis = status; }; - void SetFigHandle(int handle); - void EnableLegend(bool enable) { _legendEnabled = enable; }; - - bool TimeToPlot(); - void Plotting(); - void DonePlotting(); - void DisablePlot(); - - int MakeTrend(const char *sourceName, const char *trendName, double slope, double offset, const char *plotAttrib = NULL); - -#ifdef PLOT_TESTING - int64_t _plotStartTime; - int64_t _plotDelay; -#endif - -private: - void UpdateData(Engine* ep); - bool GetPlotCmd(std::ostringstream & cmd, Engine* ep); - void GetPlotCmd(std::ostringstream & cmd); // call inside crit sect - void GetRefreshCmd(std::ostringstream & cmd); // call inside crit sect - void GetLegendCmd(std::ostringstream & cmd); - bool DataAvailable(); - - std::vector<MatlabLine *> _line; - int _figHandle; - bool _smartAxis; - double _xlim[2]; - double _ylim[2]; - webrtc::CriticalSectionWrapper *_critSect; - bool _timeToPlot; - bool _plotting; - bool _enabled; - bool _firstPlot; - bool _legendEnabled; - webrtc::EventWrapper* _donePlottingEvent; -}; - - -class MatlabEngine -{ -public: - MatlabEngine(); - ~MatlabEngine(); - - MatlabPlot * NewPlot(MatlabPlot *newPlot); - void DeletePlot(MatlabPlot *plot); - -private: - static bool PlotThread(void *obj); - - std::vector<MatlabPlot *> _plots; - webrtc::CriticalSectionWrapper *_critSect; - webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr<webrtc::ThreadWrapper> _plotThread; - bool _running; - int _numPlots; -}; - -#endif //MATLAB - -#endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_MATLABPLOT_H_ diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc deleted file mode 100644 index 0e3e87976c..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.cc +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h" - -#include <stdio.h> - -#include <algorithm> - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" - - -bool SenderThreadFunction(void *obj) -{ - if (obj == NULL) - { - return false; - } - TestLoadGenerator *_genObj = static_cast<TestLoadGenerator *>(obj); - - return _genObj->GeneratorLoop(); -} - - -TestLoadGenerator::TestLoadGenerator(TestSenderReceiver *sender, int32_t rtpSampleRate) -: -_critSect(CriticalSectionWrapper::CreateCriticalSection()), -_eventPtr(NULL), -_bitrateKbps(0), -_sender(sender), -_running(false), -_rtpSampleRate(rtpSampleRate) -{ -} - -TestLoadGenerator::~TestLoadGenerator () -{ - if (_running) - { - Stop(); - } - - delete _critSect; -} - -int32_t TestLoadGenerator::SetBitrate (int32_t newBitrateKbps) -{ - CriticalSectionScoped cs(_critSect); - - if (newBitrateKbps < 0) - { - return -1; - } - - _bitrateKbps = newBitrateKbps; - - printf("New bitrate = %i kbps\n", _bitrateKbps); - - return _bitrateKbps; -} - - -int32_t TestLoadGenerator::Start (const char *threadName) -{ - CriticalSectionScoped cs(_critSect); - - _eventPtr = EventWrapper::Create(); - - _genThread = ThreadWrapper::CreateThread(SenderThreadFunction, this, - threadName); - _running = true; - - _genThread->Start(); - _genThread->SetPriority(kRealtimePriority); - - return 0; -} - - -int32_t TestLoadGenerator::Stop () -{ - _critSect.Enter(); - - if (_genThread) - { - _running = false; - _eventPtr->Set(); - - _genThread->Stop(); - _genThread.reset(); - - delete _eventPtr; - _eventPtr = NULL; - } - - _critSect.Leave(); - return (0); -} - - -int TestLoadGenerator::generatePayload () -{ - return(generatePayload( static_cast<uint32_t>( TickTime::MillisecondTimestamp() * _rtpSampleRate / 1000 ))); -} - - -int TestLoadGenerator::sendPayload (const uint32_t timeStamp, - const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::FrameType frameType /*= webrtc::kVideoFrameDelta*/) -{ - - return (_sender->SendOutgoingData(timeStamp, payloadData, payloadSize, frameType)); -} - - -CBRGenerator::CBRGenerator (TestSenderReceiver *sender, - size_t payloadSizeBytes, - int32_t bitrateKbps, - int32_t rtpSampleRate) -: -//_eventPtr(NULL), -_payloadSizeBytes(payloadSizeBytes), -_payload(new uint8_t[payloadSizeBytes]), -TestLoadGenerator(sender, rtpSampleRate) -{ - SetBitrate (bitrateKbps); -} - -CBRGenerator::~CBRGenerator () -{ - if (_running) - { - Stop(); - } - - if (_payload) - { - delete [] _payload; - } - -} - -bool CBRGenerator::GeneratorLoop () -{ - double periodMs; - int64_t nextSendTime = TickTime::MillisecondTimestamp(); - - - // no critSect - while (_running) - { - // send data (critSect inside) - generatePayload( static_cast<uint32_t>(nextSendTime * _rtpSampleRate / 1000) ); - - // calculate wait time - periodMs = 8.0 * _payloadSizeBytes / ( _bitrateKbps ); - - nextSendTime = static_cast<int64_t>(nextSendTime + periodMs); - - int32_t waitTime = static_cast<int32_t>(nextSendTime - TickTime::MillisecondTimestamp()); - if (waitTime < 0) - { - waitTime = 0; - } - // wait - _eventPtr->Wait(static_cast<int32_t>(waitTime)); - } - - return true; -} - -int CBRGenerator::generatePayload ( uint32_t timestamp ) -{ - CriticalSectionScoped cs(_critSect); - - //uint8_t *payload = new uint8_t[_payloadSizeBytes]; - - int ret = sendPayload(timestamp, _payload, _payloadSizeBytes); - - //delete [] payload; - return ret; -} - - - - -///////////////////// - -CBRFixFRGenerator::CBRFixFRGenerator (TestSenderReceiver *sender, int32_t bitrateKbps, - int32_t rtpSampleRate, int32_t frameRateFps /*= 30*/, - double spread /*= 0.0*/) -: -//_eventPtr(NULL), -_payloadSizeBytes(0), -_payload(NULL), -_payloadAllocLen(0), -_frameRateFps(frameRateFps), -_spreadFactor(spread), -TestLoadGenerator(sender, rtpSampleRate) -{ - SetBitrate (bitrateKbps); -} - -CBRFixFRGenerator::~CBRFixFRGenerator () -{ - if (_running) - { - Stop(); - } - - if (_payload) - { - delete [] _payload; - _payloadAllocLen = 0; - } - -} - -bool CBRFixFRGenerator::GeneratorLoop () -{ - double periodMs; - int64_t nextSendTime = TickTime::MillisecondTimestamp(); - - _critSect.Enter(); - - if (_frameRateFps <= 0) - { - return false; - } - - _critSect.Leave(); - - // no critSect - while (_running) - { - _critSect.Enter(); - - // calculate payload size - _payloadSizeBytes = nextPayloadSize(); - - if (_payloadSizeBytes > 0) - { - - if (_payloadAllocLen < _payloadSizeBytes * (1 + _spreadFactor)) - { - // re-allocate _payload - if (_payload) - { - delete [] _payload; - _payload = NULL; - } - - _payloadAllocLen = static_cast<int32_t>((_payloadSizeBytes * (1 + _spreadFactor) * 3) / 2 + .5); // 50% extra to avoid frequent re-alloc - _payload = new uint8_t[_payloadAllocLen]; - } - - - // send data (critSect inside) - generatePayload( static_cast<uint32_t>(nextSendTime * _rtpSampleRate / 1000) ); - } - - _critSect.Leave(); - - // calculate wait time - periodMs = 1000.0 / _frameRateFps; - nextSendTime = static_cast<int64_t>(nextSendTime + periodMs + 0.5); - - int32_t waitTime = static_cast<int32_t>(nextSendTime - TickTime::MillisecondTimestamp()); - if (waitTime < 0) - { - waitTime = 0; - } - // wait - _eventPtr->Wait(waitTime); - } - - return true; -} - -size_t CBRFixFRGenerator::nextPayloadSize() -{ - const double periodMs = 1000.0 / _frameRateFps; - return static_cast<size_t>(_bitrateKbps * periodMs / 8 + 0.5); -} - -int CBRFixFRGenerator::generatePayload ( uint32_t timestamp ) -{ - CriticalSectionScoped cs(_critSect); - - double factor = ((double) rand() - RAND_MAX/2) / RAND_MAX; // [-0.5; 0.5] - factor = 1 + 2 * _spreadFactor * factor; // [1 - _spreadFactor ; 1 + _spreadFactor] - - size_t thisPayloadBytes = static_cast<size_t>(_payloadSizeBytes * factor); - // sanity - if (thisPayloadBytes > _payloadAllocLen) - { - thisPayloadBytes = _payloadAllocLen; - } - - int ret = sendPayload(timestamp, _payload, thisPayloadBytes); - return ret; -} - - -///////////////////// - -PeriodicKeyFixFRGenerator::PeriodicKeyFixFRGenerator (TestSenderReceiver *sender, int32_t bitrateKbps, - int32_t rtpSampleRate, int32_t frameRateFps /*= 30*/, - double spread /*= 0.0*/, double keyFactor /*= 4.0*/, uint32_t keyPeriod /*= 300*/) -: -_keyFactor(keyFactor), -_keyPeriod(keyPeriod), -_frameCount(0), -CBRFixFRGenerator(sender, bitrateKbps, rtpSampleRate, frameRateFps, spread) -{ -} - -size_t PeriodicKeyFixFRGenerator::nextPayloadSize() -{ - // calculate payload size for a delta frame - size_t payloadSizeBytes = static_cast<size_t>(1000 * _bitrateKbps / - (8.0 * _frameRateFps * (1.0 + (_keyFactor - 1.0) / _keyPeriod)) + 0.5); - - if (_frameCount % _keyPeriod == 0) - { - // this is a key frame, scale the payload size - payloadSizeBytes = - static_cast<size_t>(_keyFactor * _payloadSizeBytes + 0.5); - } - _frameCount++; - - return payloadSizeBytes; -} - -//////////////////// - -CBRVarFRGenerator::CBRVarFRGenerator(TestSenderReceiver *sender, int32_t bitrateKbps, const uint8_t* frameRates, - uint16_t numFrameRates, int32_t rtpSampleRate, double avgFrPeriodMs, - double frSpreadFactor, double spreadFactor) -: -_avgFrPeriodMs(avgFrPeriodMs), -_frSpreadFactor(frSpreadFactor), -_frameRates(NULL), -_numFrameRates(numFrameRates), -_frChangeTimeMs(TickTime::MillisecondTimestamp() + _avgFrPeriodMs), -CBRFixFRGenerator(sender, bitrateKbps, rtpSampleRate, frameRates[0], spreadFactor) -{ - _frameRates = new uint8_t[_numFrameRates]; - memcpy(_frameRates, frameRates, _numFrameRates); -} - -CBRVarFRGenerator::~CBRVarFRGenerator() -{ - delete [] _frameRates; -} - -void CBRVarFRGenerator::ChangeFrameRate() -{ - const int64_t nowMs = TickTime::MillisecondTimestamp(); - if (nowMs < _frChangeTimeMs) - { - return; - } - // Time to change frame rate - uint16_t frIndex = static_cast<uint16_t>(static_cast<double>(rand()) / RAND_MAX - * (_numFrameRates - 1) + 0.5) ; - assert(frIndex < _numFrameRates); - _frameRateFps = _frameRates[frIndex]; - // Update the next frame rate change time - double factor = ((double) rand() - RAND_MAX/2) / RAND_MAX; // [-0.5; 0.5] - factor = 1 + 2 * _frSpreadFactor * factor; // [1 - _frSpreadFactor ; 1 + _frSpreadFactor] - _frChangeTimeMs = nowMs + static_cast<int64_t>(1000.0 * factor * - _avgFrPeriodMs + 0.5); - - printf("New frame rate: %d\n", _frameRateFps); -} - -size_t CBRVarFRGenerator::nextPayloadSize() -{ - ChangeFrameRate(); - return CBRFixFRGenerator::nextPayloadSize(); -} - -//////////////////// - -CBRFrameDropGenerator::CBRFrameDropGenerator(TestSenderReceiver *sender, int32_t bitrateKbps, - int32_t rtpSampleRate, double spreadFactor) -: -_accBits(0), -CBRFixFRGenerator(sender, bitrateKbps, rtpSampleRate, 30, spreadFactor) -{ -} - -CBRFrameDropGenerator::~CBRFrameDropGenerator() -{ -} - -size_t CBRFrameDropGenerator::nextPayloadSize() -{ - _accBits -= 1000 * _bitrateKbps / _frameRateFps; - if (_accBits < 0) - { - _accBits = 0; - } - if (_accBits > 0.3 * _bitrateKbps * 1000) - { - //printf("drop\n"); - return 0; - } - else - { - //printf("keep\n"); - const double periodMs = 1000.0 / _frameRateFps; - size_t frameSize = - static_cast<size_t>(_bitrateKbps * periodMs / 8 + 0.5); - frameSize = - std::max(frameSize, static_cast<size_t>(300 * periodMs / 8 + 0.5)); - _accBits += frameSize * 8; - return frameSize; - } -} diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h deleted file mode 100644 index bd83962fa3..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTLOADGENERATOR_H_ -#define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTLOADGENERATOR_H_ - -#include <stdlib.h> - -#include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" -#include "webrtc/typedefs.h" - -class TestSenderReceiver; -namespace webrtc { -class CriticalSectionWrapper; -class EventWrapper; -} - -class TestLoadGenerator -{ -public: - TestLoadGenerator (TestSenderReceiver *sender, int32_t rtpSampleRate = 90000); - virtual ~TestLoadGenerator (); - - int32_t SetBitrate (int32_t newBitrateKbps); - virtual int32_t Start (const char *threadName = NULL); - virtual int32_t Stop (); - virtual bool GeneratorLoop () = 0; - -protected: - virtual int generatePayload ( uint32_t timestamp ) = 0; - int generatePayload (); - int sendPayload (const uint32_t timeStamp, - const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::FrameType frameType = webrtc::kVideoFrameDelta); - - webrtc::CriticalSectionWrapper* _critSect; - webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr<webrtc::ThreadWrapper> _genThread; - int32_t _bitrateKbps; - TestSenderReceiver *_sender; - bool _running; - int32_t _rtpSampleRate; -}; - - -class CBRGenerator : public TestLoadGenerator -{ -public: - CBRGenerator (TestSenderReceiver *sender, - size_t payloadSizeBytes, - int32_t bitrateKbps, - int32_t rtpSampleRate = 90000); - virtual ~CBRGenerator (); - - virtual int32_t Start () {return (TestLoadGenerator::Start("CBRGenerator"));}; - - virtual bool GeneratorLoop (); - -protected: - virtual int generatePayload ( uint32_t timestamp ); - - size_t _payloadSizeBytes; - uint8_t *_payload; -}; - - -class CBRFixFRGenerator : public TestLoadGenerator // constant bitrate and fixed frame rate -{ -public: - CBRFixFRGenerator (TestSenderReceiver *sender, int32_t bitrateKbps, int32_t rtpSampleRate = 90000, - int32_t frameRateFps = 30, double spread = 0.0); - virtual ~CBRFixFRGenerator (); - - virtual int32_t Start () {return (TestLoadGenerator::Start("CBRFixFRGenerator"));}; - - virtual bool GeneratorLoop (); - -protected: - virtual size_t nextPayloadSize (); - virtual int generatePayload ( uint32_t timestamp ); - - size_t _payloadSizeBytes; - uint8_t *_payload; - size_t _payloadAllocLen; - int32_t _frameRateFps; - double _spreadFactor; -}; - -class PeriodicKeyFixFRGenerator : public CBRFixFRGenerator // constant bitrate and fixed frame rate with periodically large frames -{ -public: - PeriodicKeyFixFRGenerator (TestSenderReceiver *sender, int32_t bitrateKbps, int32_t rtpSampleRate = 90000, - int32_t frameRateFps = 30, double spread = 0.0, double keyFactor = 4.0, uint32_t keyPeriod = 300); - virtual ~PeriodicKeyFixFRGenerator () {} - -protected: - virtual size_t nextPayloadSize (); - - double _keyFactor; - uint32_t _keyPeriod; - uint32_t _frameCount; -}; - -// Probably better to inherit CBRFixFRGenerator from CBRVarFRGenerator, but since -// the fix FR version already existed this was easier. -class CBRVarFRGenerator : public CBRFixFRGenerator // constant bitrate and variable frame rate -{ -public: - CBRVarFRGenerator(TestSenderReceiver *sender, int32_t bitrateKbps, const uint8_t* frameRates, - uint16_t numFrameRates, int32_t rtpSampleRate = 90000, double avgFrPeriodMs = 5.0, - double frSpreadFactor = 0.05, double spreadFactor = 0.0); - - ~CBRVarFRGenerator(); - -protected: - virtual void ChangeFrameRate(); - virtual size_t nextPayloadSize (); - - double _avgFrPeriodMs; - double _frSpreadFactor; - uint8_t* _frameRates; - uint16_t _numFrameRates; - int64_t _frChangeTimeMs; -}; - -class CBRFrameDropGenerator : public CBRFixFRGenerator // constant bitrate and variable frame rate -{ -public: - CBRFrameDropGenerator(TestSenderReceiver *sender, int32_t bitrateKbps, - int32_t rtpSampleRate = 90000, double spreadFactor = 0.0); - - ~CBRFrameDropGenerator(); - -protected: - virtual size_t nextPayloadSize(); - - double _accBits; -}; - -#endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTLOADGENERATOR_H_ diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc deleted file mode 100644 index 47f2880638..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.cc +++ /dev/null @@ -1,411 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h" - -#include <stdio.h> -#include <stdlib.h> - -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestLoadGenerator.h" -#include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/tick_util.h" -#include "webrtc/test/channel_transport/udp_transport.h" - -#define NR_OF_SOCKET_BUFFERS 500 - - -bool ProcThreadFunction(void *obj) -{ - if (obj == NULL) - { - return false; - } - TestSenderReceiver *theObj = static_cast<TestSenderReceiver *>(obj); - - return theObj->ProcLoop(); -} - - -TestSenderReceiver::TestSenderReceiver (void) -: -_critSect(CriticalSectionWrapper::CreateCriticalSection()), -_eventPtr(NULL), -_running(false), -_payloadType(0), -_loadGenerator(NULL), -_isSender(false), -_isReceiver(false), -_sendRecCB(NULL), -_lastBytesReceived(0), -_lastTime(-1) -{ - // RTP/RTCP module - _rtp = RtpRtcp::CreateRtpRtcp(0, false); - if (!_rtp) - { - throw "Could not create RTP/RTCP module"; - exit(1); - } - - if (_rtp->InitReceiver() != 0) - { - throw "_rtp->InitReceiver()"; - exit(1); - } - - if (_rtp->InitSender() != 0) - { - throw "_rtp->InitSender()"; - exit(1); - } - - // SocketTransport module - uint8_t numberOfThreads = 1; - _transport = UdpTransport::Create(0, numberOfThreads); - if (!_transport) - { - throw "Could not create transport module"; - exit(1); - } -} - -TestSenderReceiver::~TestSenderReceiver (void) -{ - - Stop(); // N.B. without critSect - - _critSect->Enter(); - - if (_rtp) - { - RtpRtcp::DestroyRtpRtcp(_rtp); - _rtp = NULL; - } - - if (_transport) - { - UdpTransport::Destroy(_transport); - _transport = NULL; - } - - delete _critSect; - -} - - -int32_t TestSenderReceiver::InitReceiver (const uint16_t rtpPort, - const uint16_t rtcpPort, - const int8_t payloadType /*= 127*/) -{ - CriticalSectionScoped cs(_critSect); - - // init transport - if (_transport->InitializeReceiveSockets(this, rtpPort/*, 0, NULL, 0, true*/) != 0) - { - throw "_transport->InitializeReceiveSockets"; - exit(1); - } - - if (_rtp->RegisterIncomingRTPCallback(this) != 0) - { - throw "_rtp->RegisterIncomingRTPCallback"; - exit(1); - } - - if (_rtp->RegisterIncomingDataCallback(this) != 0) - { - throw "_rtp->RegisterIncomingRTPCallback"; - exit(1); - } - - if (_rtp->SetRTCPStatus(RtcpMode::kReducedSize) != 0) { - throw "_rtp->SetRTCPStatus"; - exit(1); - } - - if (_rtp->SetTMMBRStatus(true) != 0) - { - throw "_rtp->SetTMMBRStatus"; - exit(1); - } - - if (_rtp->RegisterReceivePayload("I420", payloadType, 90000) != 0) - { - throw "_rtp->RegisterReceivePayload"; - exit(1); - } - - _isReceiver = true; - - return (0); -} - - -int32_t TestSenderReceiver::Start() -{ - CriticalSectionScoped cs(_critSect); - - _eventPtr = EventWrapper::Create(); - - if (_rtp->SetSendingStatus(true) != 0) - { - throw "_rtp->SetSendingStatus"; - exit(1); - } - - _procThread = ThreadWrapper::CreateThread(ProcThreadFunction, this, - "TestSenderReceiver"); - - _running = true; - - if (_isReceiver) - { - if (_transport->StartReceiving(NR_OF_SOCKET_BUFFERS) != 0) - { - throw "_transport->StartReceiving"; - exit(1); - } - } - - _procThread->Start(); - _procThread->SetPriority(kRealtimePriority); - - return 0; - -} - - -int32_t TestSenderReceiver::Stop () -{ - CriticalSectionScoped cs(_critSect); - - _transport->StopReceiving(); - - if (_procThread) - { - _running = false; - _eventPtr->Set(); - - _procThread->Stop(); - _procThread.reset(); - - delete _eventPtr; - } - - return (0); -} - - -bool TestSenderReceiver::ProcLoop(void) -{ - - // process RTP/RTCP module - _rtp->Process(); - - // process SocketTransport module - _transport->Process(); - - // no critSect - while (_running) - { - // ask RTP/RTCP module for wait time - int32_t rtpWait = _rtp->TimeUntilNextProcess(); - - // ask SocketTransport module for wait time - int32_t tpWait = _transport->TimeUntilNextProcess(); - - int32_t minWait = (rtpWait < tpWait) ? rtpWait: tpWait; - minWait = (minWait > 0) ? minWait : 0; - // wait - _eventPtr->Wait(minWait); - - // process RTP/RTCP module - _rtp->Process(); - - // process SocketTransport module - _transport->Process(); - - } - - return true; -} - - -int32_t TestSenderReceiver::ReceiveBitrateKbps () -{ - size_t bytesSent; - uint32_t packetsSent; - size_t bytesReceived; - uint32_t packetsReceived; - - if (_rtp->DataCountersRTP(&bytesSent, &packetsSent, &bytesReceived, &packetsReceived) == 0) - { - int64_t now = TickTime::MillisecondTimestamp(); - int32_t kbps = 0; - if (now > _lastTime) - { - if (_lastTime > 0) - { - // 8 * bytes / ms = kbps - kbps = static_cast<int32_t>( - (8 * (bytesReceived - _lastBytesReceived)) / (now - _lastTime)); - } - _lastTime = now; - _lastBytesReceived = bytesReceived; - } - return (kbps); - } - - return (-1); -} - - -int32_t TestSenderReceiver::SetPacketTimeout(const uint32_t timeoutMS) -{ - return (_rtp->SetPacketTimeout(timeoutMS, 0 /* RTCP timeout */)); -} - - -int32_t TestSenderReceiver::OnReceivedPayloadData(const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::WebRtcRTPHeader* rtpHeader) -{ - //printf("OnReceivedPayloadData\n"); - return (0); -} - - -void TestSenderReceiver::IncomingRTPPacket(const int8_t* incomingRtpPacket, - const size_t rtpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) -{ - _rtp->IncomingPacket((uint8_t *) incomingRtpPacket, rtpPacketLength); -} - - - -void TestSenderReceiver::IncomingRTCPPacket(const int8_t* incomingRtcpPacket, - const size_t rtcpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) -{ - _rtp->IncomingPacket((uint8_t *) incomingRtcpPacket, rtcpPacketLength); -} - - - - - -/////////////////// - - -int32_t TestSenderReceiver::InitSender (const uint32_t startBitrateKbps, - const int8_t* ipAddr, - const uint16_t rtpPort, - const uint16_t rtcpPort /*= 0*/, - const int8_t payloadType /*= 127*/) -{ - CriticalSectionScoped cs(_critSect); - - _payloadType = payloadType; - - // check load generator valid - if (_loadGenerator) - { - _loadGenerator->SetBitrate(startBitrateKbps); - } - - if (_rtp->RegisterSendTransport(_transport) != 0) - { - throw "_rtp->RegisterSendTransport"; - exit(1); - } - if (_rtp->RegisterSendPayload("I420", _payloadType, 90000) != 0) - { - throw "_rtp->RegisterSendPayload"; - exit(1); - } - - if (_rtp->RegisterIncomingVideoCallback(this) != 0) - { - throw "_rtp->RegisterIncomingVideoCallback"; - exit(1); - } - - if (_rtp->SetRTCPStatus(RtcpMode::kReducedSize) != 0) { - throw "_rtp->SetRTCPStatus"; - exit(1); - } - - if (_rtp->SetSendBitrate(startBitrateKbps*1000, 0, MAX_BITRATE_KBPS) != 0) - { - throw "_rtp->SetSendBitrate"; - exit(1); - } - - - // SocketTransport - if (_transport->InitializeSendSockets(ipAddr, rtpPort, rtcpPort)) - { - throw "_transport->InitializeSendSockets"; - exit(1); - } - - _isSender = true; - - return (0); -} - - - -int32_t -TestSenderReceiver::SendOutgoingData(const uint32_t timeStamp, - const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::FrameType frameType /*= webrtc::kVideoFrameDelta*/) -{ - return (_rtp->SendOutgoingData(frameType, _payloadType, timeStamp, payloadData, payloadSize)); -} - - -int32_t TestSenderReceiver::SetLoadGenerator(TestLoadGenerator *generator) -{ - CriticalSectionScoped cs(_critSect); - - _loadGenerator = generator; - return(0); - -} - -void TestSenderReceiver::OnNetworkChanged(const int32_t id, - const uint32_t minBitrateBps, - const uint32_t maxBitrateBps, - const uint8_t fractionLost, - const uint16_t roundTripTimeMs, - const uint16_t bwEstimateKbitMin, - const uint16_t bwEstimateKbitMax) -{ - if (_loadGenerator) - { - _loadGenerator->SetBitrate(maxBitrateBps/1000); - } - - if (_sendRecCB) - { - _sendRecCB->OnOnNetworkChanged(maxBitrateBps, - fractionLost, - roundTripTimeMs, - bwEstimateKbitMin, - bwEstimateKbitMax); - } -} diff --git a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h b/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h deleted file mode 100644 index f394412a73..0000000000 --- a/webrtc/modules/rtp_rtcp/test/BWEStandAlone/TestSenderReceiver.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_ -#define WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_ - -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" -#include "webrtc/test/channel_transport/udp_transport.h" -#include "webrtc/typedefs.h" - -class TestLoadGenerator; -namespace webrtc { -class CriticalSectionWrapper; -class EventWrapper; -} - -using namespace webrtc; - -#define MAX_BITRATE_KBPS 50000 - - -class SendRecCB -{ -public: - virtual void OnOnNetworkChanged(const uint32_t bitrateTarget, - const uint8_t fractionLost, - const uint16_t roundTripTimeMs, - const uint16_t bwEstimateKbitMin, - const uint16_t bwEstimateKbitMax) = 0; - - virtual ~SendRecCB() {}; -}; - - -class TestSenderReceiver : public RtpFeedback, public RtpData, public UdpTransportData, public RtpVideoFeedback -{ - -public: - TestSenderReceiver (void); - - ~TestSenderReceiver (void); - - void SetCallback (SendRecCB *cb) { _sendRecCB = cb; }; - - int32_t Start(); - - int32_t Stop(); - - bool ProcLoop(); - - ///////////////////////////////////////////// - // Receiver methods - - int32_t InitReceiver (const uint16_t rtpPort, - const uint16_t rtcpPort = 0, - const int8_t payloadType = 127); - - int32_t ReceiveBitrateKbps (); - - int32_t SetPacketTimeout(const uint32_t timeoutMS); - - // Inherited from RtpFeedback - int32_t OnInitializeDecoder(const int32_t id, - const int8_t payloadType, - const int8_t payloadName[RTP_PAYLOAD_NAME_SIZE], - const uint32_t frequency, - const uint8_t channels, - const uint32_t rate) override { - return 0; - } - - void OnIncomingSSRCChanged(const int32_t id, const uint32_t SSRC) override { - } - - void OnIncomingCSRCChanged(const int32_t id, - const uint32_t CSRC, - const bool added) override {} - - // Inherited from RtpData - int32_t OnReceivedPayloadData( - const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::WebRtcRTPHeader* rtpHeader) override; - - // Inherited from UdpTransportData - void IncomingRTPPacket(const int8_t* incomingRtpPacket, - const size_t rtpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) override; - - void IncomingRTCPPacket(const int8_t* incomingRtcpPacket, - const size_t rtcpPacketLength, - const int8_t* fromIP, - const uint16_t fromPort) override; - - ///////////////////////////////// - // Sender methods - - int32_t InitSender (const uint32_t startBitrateKbps, - const int8_t* ipAddr, - const uint16_t rtpPort, - const uint16_t rtcpPort = 0, - const int8_t payloadType = 127); - - int32_t SendOutgoingData(const uint32_t timeStamp, - const uint8_t* payloadData, - const size_t payloadSize, - const webrtc::FrameType frameType = webrtc::kVideoFrameDelta); - - int32_t SetLoadGenerator(TestLoadGenerator *generator); - - uint32_t BitrateSent() { return (_rtp->BitrateSent()); }; - - - // Inherited from RtpVideoFeedback - virtual void OnReceivedIntraFrameRequest(const int32_t id, - const uint8_t message = 0) {}; - - virtual void OnNetworkChanged(const int32_t id, - const uint32_t minBitrateBps, - const uint32_t maxBitrateBps, - const uint8_t fractionLost, - const uint16_t roundTripTimeMs, - const uint16_t bwEstimateKbitMin, - const uint16_t bwEstimateKbitMax); - -private: - RtpRtcp* _rtp; - UdpTransport* _transport; - webrtc::CriticalSectionWrapper* _critSect; - webrtc::EventWrapper *_eventPtr; - rtc::scoped_ptr<webrtc::ThreadWrapper> _procThread; - bool _running; - int8_t _payloadType; - TestLoadGenerator* _loadGenerator; - bool _isSender; - bool _isReceiver; - SendRecCB * _sendRecCB; - size_t _lastBytesReceived; - int64_t _lastTime; - -}; - -#endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_ diff --git a/webrtc/modules/rtp_rtcp/test/bwe_standalone.gypi b/webrtc/modules/rtp_rtcp/test/bwe_standalone.gypi deleted file mode 100644 index e45daec77d..0000000000 --- a/webrtc/modules/rtp_rtcp/test/bwe_standalone.gypi +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -{ - 'targets': [ - { - 'target_name': 'bwe_standalone', - 'type': 'executable', - 'dependencies': [ - 'matlab_plotting', - 'rtp_rtcp', - 'udp_transport', - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', - ], - 'sources': [ - 'BWEStandAlone/BWEStandAlone.cc', - 'BWEStandAlone/TestLoadGenerator.cc', - 'BWEStandAlone/TestLoadGenerator.h', - 'BWEStandAlone/TestSenderReceiver.cc', - 'BWEStandAlone/TestSenderReceiver.h', - ], # source - 'conditions': [ - ['OS=="linux"', { - 'cflags': [ - '-fexceptions', # enable exceptions - ], - }, - ], - ], - }, - - { - 'target_name': 'matlab_plotting', - 'type': 'static_library', - 'dependencies': [ - 'matlab_plotting_include', - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', - ], - 'include_dirs': [ - '/opt/matlab2010a/extern/include', - ], - 'export_dependent_settings': [ - 'matlab_plotting_include', - ], - 'sources': [ - 'BWEStandAlone/MatlabPlot.cc', - 'BWEStandAlone/MatlabPlot.h', - ], - 'link_settings': { - 'ldflags' : [ - '-L/opt/matlab2010a/bin/glnxa64', - '-leng', - '-lmx', - '-Wl,-rpath,/opt/matlab2010a/bin/glnxa64', - ], - }, - 'defines': [ - 'MATLAB', - ], - 'conditions': [ - ['OS=="linux"', { - 'cflags': [ - '-fexceptions', # enable exceptions - ], - }, - ], - ], - }, - - { - 'target_name': 'matlab_plotting_include', - 'type': 'none', - 'direct_dependent_settings': { - 'include_dirs': [ - 'BWEStandAlone', - ], - }, - }, - ], -} diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.cc index 0270e55802..1d4d6d04a5 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.cc +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.cc @@ -9,14 +9,14 @@ */ #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" -#include "webrtc/test/null_transport.h" #include <algorithm> #include <vector> -using namespace webrtc; +#include "webrtc/test/null_transport.h" namespace webrtc { + void LoopBackTransport::SetSendModule(RtpRtcp* rtp_rtcp_module, RTPPayloadRegistry* payload_registry, RtpReceiver* receiver, @@ -76,7 +76,6 @@ int32_t TestRtpReceiver::OnReceivedPayloadData( payload_size_ = payload_size; return 0; } -} // namespace webrtc class RtpRtcpAPITest : public ::testing::Test { protected: @@ -187,3 +186,5 @@ TEST_F(RtpRtcpAPITest, RtxReceiver) { rtx_header.payloadType = 0; EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header)); } + +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h index 73334a8b26..d8040f7902 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api.h @@ -7,16 +7,18 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#ifndef WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ +#define WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/transport.h" namespace webrtc { @@ -68,3 +70,4 @@ class TestRtpReceiver : public NullRtpData { }; } // namespace webrtc +#endif // WEBRTC_MODULES_RTP_RTCP_TEST_TESTAPI_TEST_API_H_ diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc index 745386d485..634969b311 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc @@ -15,12 +15,12 @@ #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" #include "webrtc/common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" -using namespace webrtc; - +namespace webrtc { +namespace { #define test_rate 64000u class VerifyingAudioReceiver : public NullRtpData { @@ -64,7 +64,7 @@ class RTPCallback : public NullRtpFeedback { int32_t OnInitializeDecoder(const int8_t payloadType, const char payloadName[RTP_PAYLOAD_NAME_SIZE], const int frequency, - const uint8_t channels, + const size_t channels, const uint32_t rate) override { if (payloadType == 96) { EXPECT_EQ(test_rate, rate) << @@ -165,7 +165,7 @@ TEST_F(RtpRtcpAudioTest, Basic) { module1->SetStartTimestamp(test_timestamp); // Test detection at the end of a DTMF tone. - //EXPECT_EQ(0, module2->SetTelephoneEventForwardToDecoder(true)); + // EXPECT_EQ(0, module2->SetTelephoneEventForwardToDecoder(true)); EXPECT_EQ(0, module1->SetSendingStatus(true)); @@ -241,7 +241,7 @@ TEST_F(RtpRtcpAudioTest, RED) { EXPECT_EQ(0, module1->SetSendREDPayloadType(voice_codec.pltype)); int8_t red = 0; - EXPECT_EQ(0, module1->SendREDPayloadType(red)); + EXPECT_EQ(0, module1->SendREDPayloadType(&red)); EXPECT_EQ(voice_codec.pltype, red); EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( voice_codec.plname, @@ -278,7 +278,7 @@ TEST_F(RtpRtcpAudioTest, RED) { &fragmentation)); EXPECT_EQ(0, module1->SetSendREDPayloadType(-1)); - EXPECT_EQ(-1, module1->SendREDPayloadType(red)); + EXPECT_EQ(-1, module1->SendREDPayloadType(&red)); } TEST_F(RtpRtcpAudioTest, DTMF) { @@ -334,7 +334,7 @@ TEST_F(RtpRtcpAudioTest, DTMF) { // Send RTP packets for 16 tones a 160 ms 100ms // pause between = 2560ms + 1600ms = 4160ms - for (;timeStamp <= 250 * 160; timeStamp += 160) { + for (; timeStamp <= 250 * 160; timeStamp += 160) { EXPECT_EQ(0, module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, timeStamp, -1, test, 4)); fake_clock.AdvanceTimeMilliseconds(20); @@ -342,10 +342,13 @@ TEST_F(RtpRtcpAudioTest, DTMF) { } EXPECT_EQ(0, module1->SendTelephoneEventOutband(32, 9000, 10)); - for (;timeStamp <= 740 * 160; timeStamp += 160) { + for (; timeStamp <= 740 * 160; timeStamp += 160) { EXPECT_EQ(0, module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, timeStamp, -1, test, 4)); fake_clock.AdvanceTimeMilliseconds(20); module1->Process(); } } + +} // namespace +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_rtcp.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_rtcp.cc index e9d81122b1..6c60bf1f6d 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_rtcp.cc +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_rtcp.cc @@ -14,13 +14,14 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" -using namespace webrtc; +namespace webrtc { +namespace { const uint64_t kTestPictureId = 12345678; const uint8_t kSliPictureId = 156; @@ -29,30 +30,29 @@ class RtcpCallback : public RtcpIntraFrameObserver { public: void SetModule(RtpRtcp* module) { _rtpRtcpModule = module; - }; + } virtual void OnRTCPPacketTimeout(const int32_t id) { } virtual void OnLipSyncUpdate(const int32_t id, - const int32_t audioVideoOffset) { - }; - virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) { - }; + const int32_t audioVideoOffset) {} + virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) {} virtual void OnReceivedSLI(uint32_t ssrc, uint8_t pictureId) { EXPECT_EQ(kSliPictureId & 0x3f, pictureId); - }; + } virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t pictureId) { EXPECT_EQ(kTestPictureId, pictureId); - }; - virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) {}; + } + virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) {} + private: RtpRtcp* _rtpRtcpModule; }; class TestRtpFeedback : public NullRtpFeedback { public: - TestRtpFeedback(RtpRtcp* rtp_rtcp) : rtp_rtcp_(rtp_rtcp) {} + explicit TestRtpFeedback(RtpRtcp* rtp_rtcp) : rtp_rtcp_(rtp_rtcp) {} virtual ~TestRtpFeedback() {} void OnIncomingSSRCChanged(const uint32_t ssrc) override { @@ -266,3 +266,6 @@ TEST_F(RtpRtcpRtcpTest, RemoteRTCPStatRemote) { EXPECT_EQ(test_sequence_number, report_blocks[0].extendedHighSeqNum); EXPECT_EQ(0u, report_blocks[0].fractionLost); } + +} // namespace +} // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc index 30a6a1c303..16ea540bd5 100644 --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_video.cc @@ -15,9 +15,9 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_video.h" #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" diff --git a/webrtc/modules/rtp_rtcp/test/testFec/average_residual_loss_xor_codes.h b/webrtc/modules/rtp_rtcp/test/testFec/average_residual_loss_xor_codes.h index 2e8d676e47..6c233bba17 100644 --- a/webrtc/modules/rtp_rtcp/test/testFec/average_residual_loss_xor_codes.h +++ b/webrtc/modules/rtp_rtcp/test/testFec/average_residual_loss_xor_codes.h @@ -7,8 +7,10 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#ifndef WEBRTC_MODULES_RTP_RTCP_TEST_TESTFEC_AVERAGE_RESIDUAL_LOSS_XOR_CODES_H_ +#define WEBRTC_MODULES_RTP_RTCP_TEST_TESTFEC_AVERAGE_RESIDUAL_LOSS_XOR_CODES_H_ -namespace { +namespace webrtc { // Maximum number of media packets allowed in this test. The burst mask types // are currently defined up to (kMaxMediaPacketsTest, kMaxMediaPacketsTest). @@ -185,4 +187,5 @@ const float kMaxResidualLossBurstyMask[kNumberCodes] = { 0.009657f }; -} // namespace +} // namespace webrtc +#endif // WEBRTC_MODULES_RTP_RTCP_TEST_TESTFEC_AVERAGE_RESIDUAL_LOSS_XOR_CODES_H_ diff --git a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc index a8eafdd27e..b164b7e04c 100644 --- a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc +++ b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc @@ -22,43 +22,49 @@ #include <list> #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/modules/rtp_rtcp/source/fec_private_tables_bursty.h" +#include "webrtc/base/random.h" +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" #include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h" - -#include "webrtc/modules/rtp_rtcp/source/byte_io.h" #include "webrtc/test/testsupport/fileutils.h" -//#define VERBOSE_OUTPUT +// #define VERBOSE_OUTPUT namespace webrtc { +namespace fec_private_tables { +extern const uint8_t** kPacketMaskBurstyTbl[12]; +} namespace test { +using fec_private_tables::kPacketMaskBurstyTbl; void ReceivePackets( ForwardErrorCorrection::ReceivedPacketList* toDecodeList, ForwardErrorCorrection::ReceivedPacketList* receivedPacketList, - uint32_t numPacketsToDecode, float reorderRate, float duplicateRate) { + size_t numPacketsToDecode, + float reorderRate, + float duplicateRate, + Random* random) { assert(toDecodeList->empty()); assert(numPacketsToDecode <= receivedPacketList->size()); ForwardErrorCorrection::ReceivedPacketList::iterator it; - for (uint32_t i = 0; i < numPacketsToDecode; i++) { + for (size_t i = 0; i < numPacketsToDecode; i++) { it = receivedPacketList->begin(); // Reorder packets. - float randomVariable = static_cast<float>(rand()) / RAND_MAX; + float randomVariable = random->Rand<float>(); while (randomVariable < reorderRate) { ++it; if (it == receivedPacketList->end()) { --it; break; } - randomVariable = static_cast<float>(rand()) / RAND_MAX; + randomVariable = random->Rand<float>(); } ForwardErrorCorrection::ReceivedPacket* receivedPacket = *it; toDecodeList->push_back(receivedPacket); // Duplicate packets. - randomVariable = static_cast<float>(rand()) / RAND_MAX; + randomVariable = random->Rand<float>(); while (randomVariable < duplicateRate) { ForwardErrorCorrection::ReceivedPacket* duplicatePacket = new ForwardErrorCorrection::ReceivedPacket; @@ -69,7 +75,7 @@ void ReceivePackets( duplicatePacket->pkt->length = receivedPacket->pkt->length; toDecodeList->push_back(duplicatePacket); - randomVariable = static_cast<float>(rand()) / RAND_MAX; + randomVariable = random->Rand<float>(); } receivedPacketList->erase(it); } @@ -77,12 +83,8 @@ void ReceivePackets( TEST(FecTest, FecTest) { // TODO(marpan): Split this function into subroutines/helper functions. - enum { - kMaxNumberMediaPackets = 48 - }; - enum { - kMaxNumberFecPackets = 48 - }; + enum { kMaxNumberMediaPackets = 48 }; + enum { kMaxNumberFecPackets = 48 }; const uint32_t kNumMaskBytesL0 = 2; const uint32_t kNumMaskBytesL1 = 6; @@ -91,15 +93,12 @@ TEST(FecTest, FecTest) { const bool kUseUnequalProtection = true; // FEC mask types. - const FecMaskType kMaskTypes[] = { kFecMaskRandom, kFecMaskBursty }; + const FecMaskType kMaskTypes[] = {kFecMaskRandom, kFecMaskBursty}; const int kNumFecMaskTypes = sizeof(kMaskTypes) / sizeof(*kMaskTypes); - // TODO(pbos): Fix this. Hack to prevent a warning - // ('-Wunneeded-internal-declaration') from clang. - (void) kPacketMaskBurstyTbl; - // Maximum number of media packets allowed for the mask type. - const uint16_t kMaxMediaPackets[] = {kMaxNumberMediaPackets, + const uint16_t kMaxMediaPackets[] = { + kMaxNumberMediaPackets, sizeof(kPacketMaskBurstyTbl) / sizeof(*kPacketMaskBurstyTbl)}; ASSERT_EQ(12, kMaxMediaPackets[1]) << "Max media packets for bursty mode not " @@ -115,7 +114,7 @@ TEST(FecTest, FecTest) { ForwardErrorCorrection::Packet* mediaPacket = NULL; // Running over only one loss rate to limit execution time. - const float lossRate[] = { 0.5f }; + const float lossRate[] = {0.5f}; const uint32_t lossRateSize = sizeof(lossRate) / sizeof(*lossRate); const float reorderRate = 0.1f; const float duplicateRate = 0.1f; @@ -127,7 +126,7 @@ TEST(FecTest, FecTest) { // Seed the random number generator, storing the seed to file in order to // reproduce past results. const unsigned int randomSeed = static_cast<unsigned int>(time(NULL)); - srand(randomSeed); + Random random(randomSeed); std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt"; FILE* randomSeedFile = fopen(filename.c_str(), "a"); fprintf(randomSeedFile, "%u\n", randomSeed); @@ -135,15 +134,13 @@ TEST(FecTest, FecTest) { randomSeedFile = NULL; uint16_t seqNum = 0; - uint32_t timeStamp = static_cast<uint32_t>(rand()); - const uint32_t ssrc = static_cast<uint32_t>(rand()); + uint32_t timeStamp = random.Rand<uint32_t>(); + const uint32_t ssrc = random.Rand(1u, 0xfffffffe); // Loop over the mask types: random and bursty. for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes; ++mask_type_idx) { - for (uint32_t lossRateIdx = 0; lossRateIdx < lossRateSize; ++lossRateIdx) { - printf("Loss rate: %.2f, Mask type %d \n", lossRate[lossRateIdx], mask_type_idx); @@ -159,14 +156,12 @@ TEST(FecTest, FecTest) { for (uint32_t numFecPackets = 1; numFecPackets <= numMediaPackets && numFecPackets <= packetMaskMax; numFecPackets++) { - // Loop over numImpPackets: usually <= (0.3*numMediaPackets). // For this test we check up to ~ (numMediaPackets / 4). uint32_t maxNumImpPackets = numMediaPackets / 4 + 1; for (uint32_t numImpPackets = 0; numImpPackets <= maxNumImpPackets && - numImpPackets <= packetMaskMax; + numImpPackets <= packetMaskMax; numImpPackets++) { - uint8_t protectionFactor = static_cast<uint8_t>(numFecPackets * 255 / numMediaPackets); @@ -181,10 +176,11 @@ TEST(FecTest, FecTest) { mask_table, packetMask); #ifdef VERBOSE_OUTPUT - printf("%u media packets, %u FEC packets, %u numImpPackets, " - "loss rate = %.2f \n", - numMediaPackets, numFecPackets, numImpPackets, - lossRate[lossRateIdx]); + printf( + "%u media packets, %u FEC packets, %u numImpPackets, " + "loss rate = %.2f \n", + numMediaPackets, numFecPackets, numImpPackets, + lossRate[lossRateIdx]); printf("Packet mask matrix \n"); #endif @@ -232,16 +228,15 @@ TEST(FecTest, FecTest) { for (uint32_t i = 0; i < numMediaPackets; ++i) { mediaPacket = new ForwardErrorCorrection::Packet; mediaPacketList.push_back(mediaPacket); - mediaPacket->length = static_cast<size_t>( - (static_cast<float>(rand()) / RAND_MAX) * - (IP_PACKET_SIZE - 12 - 28 - - ForwardErrorCorrection::PacketOverhead())); - if (mediaPacket->length < 12) { - mediaPacket->length = 12; - } + const uint32_t kMinPacketSize = 12; + const uint32_t kMaxPacketSize = static_cast<uint32_t>( + IP_PACKET_SIZE - 12 - 28 - + ForwardErrorCorrection::PacketOverhead()); + mediaPacket->length = random.Rand(kMinPacketSize, kMaxPacketSize); + // Generate random values for the first 2 bytes. - mediaPacket->data[0] = static_cast<uint8_t>(rand() % 256); - mediaPacket->data[1] = static_cast<uint8_t>(rand() % 256); + mediaPacket->data[0] = random.Rand<uint8_t>(); + mediaPacket->data[1] = random.Rand<uint8_t>(); // The first two bits are assumed to be 10 by the // FEC encoder. In fact the FEC decoder will set the @@ -266,7 +261,7 @@ TEST(FecTest, FecTest) { ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[8], ssrc); // Generate random values for payload for (size_t j = 12; j < mediaPacket->length; ++j) { - mediaPacket->data[j] = static_cast<uint8_t>(rand() % 256); + mediaPacket->data[j] = random.Rand<uint8_t>(); } seqNum++; } @@ -289,8 +284,7 @@ TEST(FecTest, FecTest) { while (mediaPacketListItem != mediaPacketList.end()) { mediaPacket = *mediaPacketListItem; // We want a value between 0 and 1. - const float lossRandomVariable = - (static_cast<float>(rand()) / (RAND_MAX)); + const float lossRandomVariable = random.Rand<float>(); if (lossRandomVariable >= lossRate[lossRateIdx]) { mediaLossMask[mediaPacketIdx] = 1; @@ -315,8 +309,7 @@ TEST(FecTest, FecTest) { uint32_t fecPacketIdx = 0; while (fecPacketListItem != fecPacketList.end()) { fecPacket = *fecPacketListItem; - const float lossRandomVariable = - (static_cast<float>(rand()) / (RAND_MAX)); + const float lossRandomVariable = random.Rand<float>(); if (lossRandomVariable >= lossRate[lossRateIdx]) { fecLossMask[fecPacketIdx] = 1; receivedPacket = new ForwardErrorCorrection::ReceivedPacket; @@ -387,18 +380,15 @@ TEST(FecTest, FecTest) { // For error-checking frame completion. bool fecPacketReceived = false; while (!receivedPacketList.empty()) { - uint32_t numPacketsToDecode = static_cast<uint32_t>( - (static_cast<float>(rand()) / RAND_MAX) * - receivedPacketList.size() + 0.5); - if (numPacketsToDecode < 1) { - numPacketsToDecode = 1; - } + size_t numPacketsToDecode = random.Rand( + 1u, static_cast<uint32_t>(receivedPacketList.size())); ReceivePackets(&toDecodeList, &receivedPacketList, - numPacketsToDecode, reorderRate, duplicateRate); + numPacketsToDecode, reorderRate, duplicateRate, + &random); if (fecPacketReceived == false) { ForwardErrorCorrection::ReceivedPacketList::iterator - toDecodeIt = toDecodeList.begin(); + toDecodeIt = toDecodeList.begin(); while (toDecodeIt != toDecodeList.end()) { receivedPacket = *toDecodeIt; if (receivedPacket->is_fec) { @@ -418,11 +408,11 @@ TEST(FecTest, FecTest) { if (mediaLossMask[mediaPacketIdx] == 1) { // Should have recovered this packet. ForwardErrorCorrection::RecoveredPacketList::iterator - recoveredPacketListItem = recoveredPacketList.begin(); + recoveredPacketListItem = recoveredPacketList.begin(); - ASSERT_FALSE( - recoveredPacketListItem == recoveredPacketList.end()) - << "Insufficient number of recovered packets."; + ASSERT_FALSE(recoveredPacketListItem == + recoveredPacketList.end()) + << "Insufficient number of recovered packets."; mediaPacket = *mediaPacketListItem; ForwardErrorCorrection::RecoveredPacket* recoveredPacket = *recoveredPacketListItem; @@ -462,7 +452,7 @@ TEST(FecTest, FecTest) { // Delete received packets we didn't pass to DecodeFEC(), due to // early frame completion. ForwardErrorCorrection::ReceivedPacketList::iterator - receivedPacketIt = receivedPacketList.begin(); + receivedPacketIt = receivedPacketList.begin(); while (receivedPacketIt != receivedPacketList.end()) { receivedPacket = *receivedPacketIt; delete receivedPacket; @@ -476,11 +466,11 @@ TEST(FecTest, FecTest) { } timeStamp += 90000 / 30; } // loop over numImpPackets - } // loop over FecPackets - } // loop over numMediaPackets + } // loop over FecPackets + } // loop over numMediaPackets delete[] packetMask; } // loop over loss rates - } // loop over mask types + } // loop over mask types // Have DecodeFEC free allocated memory. fec.ResetState(&recoveredPacketList); diff --git a/webrtc/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc b/webrtc/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc index 843a7f77f5..466214c740 100644 --- a/webrtc/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc +++ b/webrtc/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc @@ -59,13 +59,6 @@ enum { kMaxNumberMediaPackets = 48 }; // Maximum number of media packets allowed for each mask type. const uint16_t kMaxMediaPackets[] = {kMaxNumberMediaPackets, 12}; -// Maximum number of media packets allowed in this test. The burst mask types -// are currently defined up to (k=12,m=12). -const int kMaxMediaPacketsTest = 12; - -// Maximum number of FEC codes considered in this test. -const int kNumberCodes = kMaxMediaPacketsTest * (kMaxMediaPacketsTest + 1) / 2; - // Maximum gap size for characterizing the consecutiveness of the loss. const int kMaxGapSize = 2 * kMaxMediaPacketsTest; @@ -407,7 +400,7 @@ class FecPacketMaskMetricsTest : public ::testing::Test { // Loop over all loss configurations for the symbol sequence of length // |tot_num_packets|. In this version we process up to (k=12, m=12) codes, // and get exact expressions for the residual loss. - // TODO (marpan): For larger codes, loop over some random sample of loss + // TODO(marpan): For larger codes, loop over some random sample of loss // configurations, sampling driven by the underlying statistical loss model // (importance sampling). @@ -427,7 +420,7 @@ class FecPacketMaskMetricsTest : public ::testing::Test { // Map configuration number to a loss state. for (int j = 0; j < tot_num_packets; j++) { - state[j]=0; // Received state. + state[j] = 0; // Received state. int bit_value = i >> (tot_num_packets - j - 1) & 1; if (bit_value == 1) { state[j] = 1; // Lost state. @@ -860,9 +853,9 @@ TEST_F(FecPacketMaskMetricsTest, FecXorVsRS) { EXPECT_GE(kMetricsXorBursty[code_index].average_residual_loss[k], kMetricsReedSolomon[code_index].average_residual_loss[k]); } - // TODO (marpan): There are some cases (for high loss rates and/or - // burst loss models) where XOR is better than RS. Is there some pattern - // we can identify and enforce as a constraint? + // TODO(marpan): There are some cases (for high loss rates and/or + // burst loss models) where XOR is better than RS. Is there some pattern + // we can identify and enforce as a constraint? } } } @@ -874,7 +867,7 @@ TEST_F(FecPacketMaskMetricsTest, FecXorVsRS) { TEST_F(FecPacketMaskMetricsTest, FecTrendXorVsRsLossRate) { SetLossModels(); SetCodeParams(); - // TODO (marpan): Examine this further to see if the condition can be strictly + // TODO(marpan): Examine this further to see if the condition can be strictly // satisfied (i.e., scale = 1.0) for all codes with different/better masks. double scale = 0.90; int num_loss_rates = sizeof(kAverageLossRate) / @@ -898,7 +891,7 @@ TEST_F(FecPacketMaskMetricsTest, FecTrendXorVsRsLossRate) { kMetricsXorRandom[code_index].average_residual_loss[k+1]; EXPECT_GE(diff_rs_xor_random_loss1, scale * diff_rs_xor_random_loss2); } - // TODO (marpan): Investigate the cases for the bursty mask where + // TODO(marpan): Investigate the cases for the bursty mask where // this trend is not strictly satisfied. } } @@ -937,7 +930,7 @@ TEST_F(FecPacketMaskMetricsTest, FecBehaviorViaProtectionLevelAndLength) { EXPECT_LT( kMetricsReedSolomon[code_index2].average_residual_loss[k], kMetricsReedSolomon[code_index1].average_residual_loss[k]); - // TODO (marpan): There are some corner cases where this is not + // TODO(marpan): There are some corner cases where this is not // satisfied with the current packet masks. Look into updating // these cases to see if this behavior should/can be satisfied, // with overall lower residual loss for those XOR codes. @@ -963,7 +956,7 @@ TEST_F(FecPacketMaskMetricsTest, FecVarianceBehaviorXorVsRs) { SetCodeParams(); // The condition is not strictly satisfied with the current masks, // i.e., for some codes, the variance of XOR may be slightly higher than RS. - // TODO (marpan): Examine this further to see if the condition can be strictly + // TODO(marpan): Examine this further to see if the condition can be strictly // satisfied (i.e., scale = 1.0) for all codes with different/better masks. double scale = 0.95; for (int code_index = 0; code_index < max_num_codes_; code_index++) { @@ -998,7 +991,7 @@ TEST_F(FecPacketMaskMetricsTest, FecXorBurstyPerfectRecoveryConsecutiveLoss) { // bursty mask type, for random loss models at low loss rates. // The XOR codes with bursty mask types are generally better than the one with // random mask type, for bursty loss models and/or high loss rates. -// TODO (marpan): Enable this test when some of the packet masks are updated. +// TODO(marpan): Enable this test when some of the packet masks are updated. // Some isolated cases of the codes don't pass this currently. /* TEST_F(FecPacketMaskMetricsTest, FecXorRandomVsBursty) { |