rtp_rtcp/test/BWEStandAlone deleted as obsolete
BUG=webrtc:5277 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/1525573002 Cr-Commit-Position: refs/heads/master@{#11008}
This commit is contained in:
parent
a78c0211fd
commit
b2f80e3a28
@ -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/include/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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -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/base/platform_thread.h"
|
||||
#include "webrtc/typedefs.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<rtc::PlatformThread> _plotThread;
|
||||
bool _running;
|
||||
int _numPlots;
|
||||
};
|
||||
|
||||
#endif //MATLAB
|
||||
|
||||
#endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_MATLABPLOT_H_
|
||||
@ -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.reset(
|
||||
new rtc::PlatformThread(SenderThreadFunction, this, threadName));
|
||||
_running = true;
|
||||
|
||||
_genThread->Start();
|
||||
_genThread->SetPriority(rtc::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;
|
||||
}
|
||||
}
|
||||
@ -1,150 +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/base/platform_thread.h"
|
||||
#include "webrtc/modules/include/module_common_types.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;
|
||||
// TODO(pbos): Replace without pointer usage.
|
||||
rtc::scoped_ptr<rtc::PlatformThread> _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_
|
||||
@ -1,408 +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/include/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),
|
||||
_procThread(ProcThreadFunction, this, "TestSenderReceiver"),
|
||||
_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);
|
||||
}
|
||||
|
||||
_running = true;
|
||||
|
||||
if (_isReceiver)
|
||||
{
|
||||
if (_transport->StartReceiving(NR_OF_SOCKET_BUFFERS) != 0)
|
||||
{
|
||||
throw "_transport->StartReceiving";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
_procThread.Start();
|
||||
_procThread.SetPriority(rtc::kRealtimePriority);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t TestSenderReceiver::Stop ()
|
||||
{
|
||||
CriticalSectionScoped cs(_critSect);
|
||||
|
||||
_transport->StopReceiving();
|
||||
|
||||
if (_running)
|
||||
{
|
||||
_running = false;
|
||||
_eventPtr->Set();
|
||||
|
||||
_procThread.Stop();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -1,150 +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/base/platform_thread.h"
|
||||
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
|
||||
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "webrtc/test/channel_transport/udp_transport.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
class TestLoadGenerator;
|
||||
namespace webrtc {
|
||||
class CriticalSectionWrapper;
|
||||
class EventWrapper;
|
||||
|
||||
#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::PlatformThread _procThread;
|
||||
bool _running;
|
||||
int8_t _payloadType;
|
||||
TestLoadGenerator* _loadGenerator;
|
||||
bool _isSender;
|
||||
bool _isReceiver;
|
||||
SendRecCB * _sendRecCB;
|
||||
size_t _lastBytesReceived;
|
||||
int64_t _lastTime;
|
||||
|
||||
};
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_RTP_RTCP_TEST_BWESTANDALONE_TESTSENDERRECEIVER_H_
|
||||
@ -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',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user