WebRtc_Word32 => int32_t remote_bitrate_estimator/
BUG=314 Review URL: https://webrtc-codereview.appspot.com/1275009 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3775 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
37bf5847dc
commit
ff7e1303e8
@ -38,7 +38,7 @@ void BitRateStats::Init()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitRateStats::Update(WebRtc_UWord32 packetSizeBytes, WebRtc_Word64 nowMs)
|
void BitRateStats::Update(uint32_t packetSizeBytes, int64_t nowMs)
|
||||||
{
|
{
|
||||||
// Find an empty slot for storing the new sample and at the same time
|
// Find an empty slot for storing the new sample and at the same time
|
||||||
// accumulate the history.
|
// accumulate the history.
|
||||||
@ -47,7 +47,7 @@ void BitRateStats::Update(WebRtc_UWord32 packetSizeBytes, WebRtc_Word64 nowMs)
|
|||||||
EraseOld(nowMs);
|
EraseOld(nowMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitRateStats::EraseOld(WebRtc_Word64 nowMs)
|
void BitRateStats::EraseOld(int64_t nowMs)
|
||||||
{
|
{
|
||||||
while (_dataSamples.size() > 0)
|
while (_dataSamples.size() > 0)
|
||||||
{
|
{
|
||||||
@ -66,12 +66,12 @@ void BitRateStats::EraseOld(WebRtc_Word64 nowMs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_UWord32 BitRateStats::BitRate(WebRtc_Word64 nowMs)
|
uint32_t BitRateStats::BitRate(int64_t nowMs)
|
||||||
{
|
{
|
||||||
// Calculate the average bit rate the past BITRATE_AVERAGE_WINDOW ms.
|
// Calculate the average bit rate the past BITRATE_AVERAGE_WINDOW ms.
|
||||||
// Removes any old samples from the list.
|
// Removes any old samples from the list.
|
||||||
EraseOld(nowMs);
|
EraseOld(nowMs);
|
||||||
return static_cast<WebRtc_UWord32>(_accumulatedBytes * 8.0f * 1000.0f /
|
return static_cast<uint32_t>(_accumulatedBytes * 8.0f * 1000.0f /
|
||||||
kBitrateAverageWindow + 0.5f);
|
kBitrateAverageWindow + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ public:
|
|||||||
~BitRateStats();
|
~BitRateStats();
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Update(WebRtc_UWord32 packetSizeBytes, WebRtc_Word64 nowMs);
|
void Update(uint32_t packetSizeBytes, int64_t nowMs);
|
||||||
WebRtc_UWord32 BitRate(WebRtc_Word64 nowMs);
|
uint32_t BitRate(int64_t nowMs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DataTimeSizeTuple
|
struct DataTimeSizeTuple
|
||||||
@ -35,14 +35,14 @@ private:
|
|||||||
_sizeBytes(sizeBytes),
|
_sizeBytes(sizeBytes),
|
||||||
_timeCompleteMs(timeCompleteMs) {}
|
_timeCompleteMs(timeCompleteMs) {}
|
||||||
|
|
||||||
WebRtc_UWord32 _sizeBytes;
|
uint32_t _sizeBytes;
|
||||||
WebRtc_Word64 _timeCompleteMs;
|
int64_t _timeCompleteMs;
|
||||||
};
|
};
|
||||||
|
|
||||||
void EraseOld(WebRtc_Word64 nowMs);
|
void EraseOld(int64_t nowMs);
|
||||||
|
|
||||||
std::list<DataTimeSizeTuple*> _dataSamples;
|
std::list<DataTimeSizeTuple*> _dataSamples;
|
||||||
WebRtc_UWord32 _accumulatedBytes;
|
uint32_t _accumulatedBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -30,7 +30,7 @@ protected:
|
|||||||
|
|
||||||
TEST_F(BitRateStatsTest, TestStrictMode)
|
TEST_F(BitRateStatsTest, TestStrictMode)
|
||||||
{
|
{
|
||||||
WebRtc_Word64 nowMs = 0;
|
int64_t nowMs = 0;
|
||||||
// Should be initialized to 0.
|
// Should be initialized to 0.
|
||||||
EXPECT_EQ(0u, bitRate.BitRate(nowMs));
|
EXPECT_EQ(0u, bitRate.BitRate(nowMs));
|
||||||
bitRate.Update(1500, nowMs);
|
bitRate.Update(1500, nowMs);
|
||||||
|
@ -42,14 +42,14 @@ class RateControlInput
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RateControlInput(BandwidthUsage bwState,
|
RateControlInput(BandwidthUsage bwState,
|
||||||
WebRtc_UWord32 incomingBitRate,
|
uint32_t incomingBitRate,
|
||||||
double noiseVar)
|
double noiseVar)
|
||||||
: _bwState(bwState),
|
: _bwState(bwState),
|
||||||
_incomingBitRate(incomingBitRate),
|
_incomingBitRate(incomingBitRate),
|
||||||
_noiseVar(noiseVar) {}
|
_noiseVar(noiseVar) {}
|
||||||
|
|
||||||
BandwidthUsage _bwState;
|
BandwidthUsage _bwState;
|
||||||
WebRtc_UWord32 _incomingBitRate;
|
uint32_t _incomingBitRate;
|
||||||
double _noiseVar;
|
double _noiseVar;
|
||||||
};
|
};
|
||||||
} //namespace webrtc
|
} //namespace webrtc
|
||||||
|
@ -103,8 +103,8 @@ bool RemoteRateControl::TimeToReduceFurther(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word32 RemoteRateControl::SetConfiguredBitRates(
|
int32_t RemoteRateControl::SetConfiguredBitRates(
|
||||||
WebRtc_UWord32 minBitRateBps, WebRtc_UWord32 maxBitRateBps)
|
uint32_t minBitRateBps, uint32_t maxBitRateBps)
|
||||||
{
|
{
|
||||||
if (minBitRateBps > maxBitRateBps)
|
if (minBitRateBps > maxBitRateBps)
|
||||||
{
|
{
|
||||||
@ -117,11 +117,11 @@ WebRtc_Word32 RemoteRateControl::SetConfiguredBitRates(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_UWord32 RemoteRateControl::LatestEstimate() const {
|
uint32_t RemoteRateControl::LatestEstimate() const {
|
||||||
return _currentBitRate;
|
return _currentBitRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_UWord32 RemoteRateControl::UpdateBandwidthEstimate(WebRtc_Word64 nowMS)
|
uint32_t RemoteRateControl::UpdateBandwidthEstimate(int64_t nowMS)
|
||||||
{
|
{
|
||||||
_currentBitRate = ChangeBitRate(_currentBitRate,
|
_currentBitRate = ChangeBitRate(_currentBitRate,
|
||||||
_currentInput._incomingBitRate,
|
_currentInput._incomingBitRate,
|
||||||
@ -135,7 +135,7 @@ void RemoteRateControl::SetRtt(unsigned int rtt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RateControlRegion RemoteRateControl::Update(const RateControlInput* input,
|
RateControlRegion RemoteRateControl::Update(const RateControlInput* input,
|
||||||
WebRtc_Word64 nowMS)
|
int64_t nowMS)
|
||||||
{
|
{
|
||||||
assert(input);
|
assert(input);
|
||||||
#ifdef MATLAB
|
#ifdef MATLAB
|
||||||
@ -192,10 +192,10 @@ RateControlRegion RemoteRateControl::Update(const RateControlInput* input,
|
|||||||
return _rcRegion;
|
return _rcRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
|
uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate,
|
||||||
WebRtc_UWord32 incomingBitRate,
|
uint32_t incomingBitRate,
|
||||||
double noiseVar,
|
double noiseVar,
|
||||||
WebRtc_Word64 nowMS)
|
int64_t nowMS)
|
||||||
{
|
{
|
||||||
if (!_updated)
|
if (!_updated)
|
||||||
{
|
{
|
||||||
@ -234,17 +234,17 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
|
|||||||
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
|
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
|
||||||
"BWE: Response time: %f + %i + 10*33\n",
|
"BWE: Response time: %f + %i + 10*33\n",
|
||||||
_avgChangePeriod, _rtt);
|
_avgChangePeriod, _rtt);
|
||||||
const WebRtc_UWord32 responseTime = static_cast<WebRtc_UWord32>(_avgChangePeriod + 0.5f) + _rtt + 300;
|
const uint32_t responseTime = static_cast<uint32_t>(_avgChangePeriod + 0.5f) + _rtt + 300;
|
||||||
double alpha = RateIncreaseFactor(nowMS, _lastBitRateChange,
|
double alpha = RateIncreaseFactor(nowMS, _lastBitRateChange,
|
||||||
responseTime, noiseVar);
|
responseTime, noiseVar);
|
||||||
|
|
||||||
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
|
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
|
||||||
"BWE: _avgChangePeriod = %f ms; RTT = %u ms", _avgChangePeriod, _rtt);
|
"BWE: _avgChangePeriod = %f ms; RTT = %u ms", _avgChangePeriod, _rtt);
|
||||||
|
|
||||||
currentBitRate = static_cast<WebRtc_UWord32>(currentBitRate * alpha) + 1000;
|
currentBitRate = static_cast<uint32_t>(currentBitRate * alpha) + 1000;
|
||||||
if (_maxHoldRate > 0 && _beta * _maxHoldRate > currentBitRate)
|
if (_maxHoldRate > 0 && _beta * _maxHoldRate > currentBitRate)
|
||||||
{
|
{
|
||||||
currentBitRate = static_cast<WebRtc_UWord32>(_beta * _maxHoldRate);
|
currentBitRate = static_cast<uint32_t>(_beta * _maxHoldRate);
|
||||||
_avgMaxBitRate = _beta * _maxHoldRate / 1000.0f;
|
_avgMaxBitRate = _beta * _maxHoldRate / 1000.0f;
|
||||||
ChangeRegion(kRcNearMax);
|
ChangeRegion(kRcNearMax);
|
||||||
recovery = true;
|
recovery = true;
|
||||||
@ -268,13 +268,13 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
|
|||||||
{
|
{
|
||||||
// Set bit rate to something slightly lower than max
|
// Set bit rate to something slightly lower than max
|
||||||
// to get rid of any self-induced delay.
|
// to get rid of any self-induced delay.
|
||||||
currentBitRate = static_cast<WebRtc_UWord32>(_beta * incomingBitRate + 0.5);
|
currentBitRate = static_cast<uint32_t>(_beta * incomingBitRate + 0.5);
|
||||||
if (currentBitRate > _currentBitRate)
|
if (currentBitRate > _currentBitRate)
|
||||||
{
|
{
|
||||||
// Avoid increasing the rate when over-using.
|
// Avoid increasing the rate when over-using.
|
||||||
if (_rcRegion != kRcMaxUnknown)
|
if (_rcRegion != kRcMaxUnknown)
|
||||||
{
|
{
|
||||||
currentBitRate = static_cast<WebRtc_UWord32>(_beta * _avgMaxBitRate * 1000 + 0.5f);
|
currentBitRate = static_cast<uint32_t>(_beta * _avgMaxBitRate * 1000 + 0.5f);
|
||||||
}
|
}
|
||||||
currentBitRate = BWE_MIN(currentBitRate, _currentBitRate);
|
currentBitRate = BWE_MIN(currentBitRate, _currentBitRate);
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
|
|||||||
return currentBitRate;
|
return currentBitRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
double RemoteRateControl::RateIncreaseFactor(WebRtc_Word64 nowMs, WebRtc_Word64 lastMs, WebRtc_UWord32 reactionTimeMs, double noiseVar) const
|
double RemoteRateControl::RateIncreaseFactor(int64_t nowMs, int64_t lastMs, uint32_t reactionTimeMs, double noiseVar) const
|
||||||
{
|
{
|
||||||
// alpha = 1.02 + B ./ (1 + exp(b*(tr - (c1*s2 + c2))))
|
// alpha = 1.02 + B ./ (1 + exp(b*(tr - (c1*s2 + c2))))
|
||||||
// Parameters
|
// Parameters
|
||||||
@ -368,9 +368,9 @@ double RemoteRateControl::RateIncreaseFactor(WebRtc_Word64 nowMs, WebRtc_Word64
|
|||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteRateControl::UpdateChangePeriod(WebRtc_Word64 nowMs)
|
void RemoteRateControl::UpdateChangePeriod(int64_t nowMs)
|
||||||
{
|
{
|
||||||
WebRtc_Word64 changePeriod = 0;
|
int64_t changePeriod = 0;
|
||||||
if (_lastChangeMs > -1)
|
if (_lastChangeMs > -1)
|
||||||
{
|
{
|
||||||
changePeriod = nowMs - _lastChangeMs;
|
changePeriod = nowMs - _lastChangeMs;
|
||||||
@ -410,7 +410,7 @@ void RemoteRateControl::UpdateMaxBitRateEstimate(float incomingBitRateKbps)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteRateControl::ChangeState(const RateControlInput& input, WebRtc_Word64 nowMs)
|
void RemoteRateControl::ChangeState(const RateControlInput& input, int64_t nowMs)
|
||||||
{
|
{
|
||||||
switch (_currentInput._bwState)
|
switch (_currentInput._bwState)
|
||||||
{
|
{
|
||||||
|
@ -24,13 +24,13 @@ class RemoteRateControl
|
|||||||
public:
|
public:
|
||||||
RemoteRateControl();
|
RemoteRateControl();
|
||||||
~RemoteRateControl();
|
~RemoteRateControl();
|
||||||
WebRtc_Word32 SetConfiguredBitRates(WebRtc_UWord32 minBitRate,
|
int32_t SetConfiguredBitRates(uint32_t minBitRate,
|
||||||
WebRtc_UWord32 maxBitRate);
|
uint32_t maxBitRate);
|
||||||
WebRtc_UWord32 LatestEstimate() const;
|
uint32_t LatestEstimate() const;
|
||||||
WebRtc_UWord32 UpdateBandwidthEstimate(WebRtc_Word64 nowMS);
|
uint32_t UpdateBandwidthEstimate(int64_t nowMS);
|
||||||
void SetRtt(unsigned int rtt);
|
void SetRtt(unsigned int rtt);
|
||||||
RateControlRegion Update(const RateControlInput* input,
|
RateControlRegion Update(const RateControlInput* input,
|
||||||
WebRtc_Word64 nowMS);
|
int64_t nowMS);
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
// Returns true if there is a valid estimate of the incoming bitrate, false
|
// Returns true if there is a valid estimate of the incoming bitrate, false
|
||||||
@ -44,39 +44,39 @@ public:
|
|||||||
unsigned int incoming_bitrate) const;
|
unsigned int incoming_bitrate) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebRtc_UWord32 ChangeBitRate(WebRtc_UWord32 currentBitRate,
|
uint32_t ChangeBitRate(uint32_t currentBitRate,
|
||||||
WebRtc_UWord32 incomingBitRate,
|
uint32_t incomingBitRate,
|
||||||
double delayFactor,
|
double delayFactor,
|
||||||
WebRtc_Word64 nowMS);
|
int64_t nowMS);
|
||||||
double RateIncreaseFactor(WebRtc_Word64 nowMs,
|
double RateIncreaseFactor(int64_t nowMs,
|
||||||
WebRtc_Word64 lastMs,
|
int64_t lastMs,
|
||||||
WebRtc_UWord32 reactionTimeMs,
|
uint32_t reactionTimeMs,
|
||||||
double noiseVar) const;
|
double noiseVar) const;
|
||||||
void UpdateChangePeriod(WebRtc_Word64 nowMs);
|
void UpdateChangePeriod(int64_t nowMs);
|
||||||
void UpdateMaxBitRateEstimate(float incomingBitRateKbps);
|
void UpdateMaxBitRateEstimate(float incomingBitRateKbps);
|
||||||
void ChangeState(const RateControlInput& input, WebRtc_Word64 nowMs);
|
void ChangeState(const RateControlInput& input, int64_t nowMs);
|
||||||
void ChangeState(RateControlState newState);
|
void ChangeState(RateControlState newState);
|
||||||
void ChangeRegion(RateControlRegion region);
|
void ChangeRegion(RateControlRegion region);
|
||||||
static void StateStr(RateControlState state, char* str);
|
static void StateStr(RateControlState state, char* str);
|
||||||
static void StateStr(BandwidthUsage state, char* str);
|
static void StateStr(BandwidthUsage state, char* str);
|
||||||
|
|
||||||
WebRtc_UWord32 _minConfiguredBitRate;
|
uint32_t _minConfiguredBitRate;
|
||||||
WebRtc_UWord32 _maxConfiguredBitRate;
|
uint32_t _maxConfiguredBitRate;
|
||||||
WebRtc_UWord32 _currentBitRate;
|
uint32_t _currentBitRate;
|
||||||
WebRtc_UWord32 _maxHoldRate;
|
uint32_t _maxHoldRate;
|
||||||
float _avgMaxBitRate;
|
float _avgMaxBitRate;
|
||||||
float _varMaxBitRate;
|
float _varMaxBitRate;
|
||||||
RateControlState _rcState;
|
RateControlState _rcState;
|
||||||
RateControlState _cameFromState;
|
RateControlState _cameFromState;
|
||||||
RateControlRegion _rcRegion;
|
RateControlRegion _rcRegion;
|
||||||
WebRtc_Word64 _lastBitRateChange;
|
int64_t _lastBitRateChange;
|
||||||
RateControlInput _currentInput;
|
RateControlInput _currentInput;
|
||||||
bool _updated;
|
bool _updated;
|
||||||
WebRtc_Word64 _timeFirstIncomingEstimate;
|
int64_t _timeFirstIncomingEstimate;
|
||||||
bool _initializedBitRate;
|
bool _initializedBitRate;
|
||||||
|
|
||||||
float _avgChangePeriod;
|
float _avgChangePeriod;
|
||||||
WebRtc_Word64 _lastChangeMs;
|
int64_t _lastChangeMs;
|
||||||
float _beta;
|
float _beta;
|
||||||
unsigned int _rtt;
|
unsigned int _rtt;
|
||||||
#ifdef MATLAB
|
#ifdef MATLAB
|
||||||
|
Loading…
x
Reference in New Issue
Block a user