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:
pbos@webrtc.org 2013-04-08 10:04:37 +00:00
parent 37bf5847dc
commit ff7e1303e8
6 changed files with 50 additions and 50 deletions

View File

@ -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
// accumulate the history.
@ -47,7 +47,7 @@ void BitRateStats::Update(WebRtc_UWord32 packetSizeBytes, WebRtc_Word64 nowMs)
EraseOld(nowMs);
}
void BitRateStats::EraseOld(WebRtc_Word64 nowMs)
void BitRateStats::EraseOld(int64_t nowMs)
{
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.
// Removes any old samples from the list.
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);
}

View File

@ -24,8 +24,8 @@ public:
~BitRateStats();
void Init();
void Update(WebRtc_UWord32 packetSizeBytes, WebRtc_Word64 nowMs);
WebRtc_UWord32 BitRate(WebRtc_Word64 nowMs);
void Update(uint32_t packetSizeBytes, int64_t nowMs);
uint32_t BitRate(int64_t nowMs);
private:
struct DataTimeSizeTuple
@ -35,14 +35,14 @@ private:
_sizeBytes(sizeBytes),
_timeCompleteMs(timeCompleteMs) {}
WebRtc_UWord32 _sizeBytes;
WebRtc_Word64 _timeCompleteMs;
uint32_t _sizeBytes;
int64_t _timeCompleteMs;
};
void EraseOld(WebRtc_Word64 nowMs);
void EraseOld(int64_t nowMs);
std::list<DataTimeSizeTuple*> _dataSamples;
WebRtc_UWord32 _accumulatedBytes;
uint32_t _accumulatedBytes;
};
} // namespace webrtc

View File

@ -30,7 +30,7 @@ protected:
TEST_F(BitRateStatsTest, TestStrictMode)
{
WebRtc_Word64 nowMs = 0;
int64_t nowMs = 0;
// Should be initialized to 0.
EXPECT_EQ(0u, bitRate.BitRate(nowMs));
bitRate.Update(1500, nowMs);

View File

@ -42,14 +42,14 @@ class RateControlInput
{
public:
RateControlInput(BandwidthUsage bwState,
WebRtc_UWord32 incomingBitRate,
uint32_t incomingBitRate,
double noiseVar)
: _bwState(bwState),
_incomingBitRate(incomingBitRate),
_noiseVar(noiseVar) {}
BandwidthUsage _bwState;
WebRtc_UWord32 _incomingBitRate;
uint32_t _incomingBitRate;
double _noiseVar;
};
} //namespace webrtc

View File

@ -103,8 +103,8 @@ bool RemoteRateControl::TimeToReduceFurther(
return false;
}
WebRtc_Word32 RemoteRateControl::SetConfiguredBitRates(
WebRtc_UWord32 minBitRateBps, WebRtc_UWord32 maxBitRateBps)
int32_t RemoteRateControl::SetConfiguredBitRates(
uint32_t minBitRateBps, uint32_t maxBitRateBps)
{
if (minBitRateBps > maxBitRateBps)
{
@ -117,11 +117,11 @@ WebRtc_Word32 RemoteRateControl::SetConfiguredBitRates(
return 0;
}
WebRtc_UWord32 RemoteRateControl::LatestEstimate() const {
uint32_t RemoteRateControl::LatestEstimate() const {
return _currentBitRate;
}
WebRtc_UWord32 RemoteRateControl::UpdateBandwidthEstimate(WebRtc_Word64 nowMS)
uint32_t RemoteRateControl::UpdateBandwidthEstimate(int64_t nowMS)
{
_currentBitRate = ChangeBitRate(_currentBitRate,
_currentInput._incomingBitRate,
@ -135,7 +135,7 @@ void RemoteRateControl::SetRtt(unsigned int rtt) {
}
RateControlRegion RemoteRateControl::Update(const RateControlInput* input,
WebRtc_Word64 nowMS)
int64_t nowMS)
{
assert(input);
#ifdef MATLAB
@ -192,10 +192,10 @@ RateControlRegion RemoteRateControl::Update(const RateControlInput* input,
return _rcRegion;
}
WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
WebRtc_UWord32 incomingBitRate,
uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate,
uint32_t incomingBitRate,
double noiseVar,
WebRtc_Word64 nowMS)
int64_t nowMS)
{
if (!_updated)
{
@ -234,17 +234,17 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
"BWE: Response time: %f + %i + 10*33\n",
_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,
responseTime, noiseVar);
WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
"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)
{
currentBitRate = static_cast<WebRtc_UWord32>(_beta * _maxHoldRate);
currentBitRate = static_cast<uint32_t>(_beta * _maxHoldRate);
_avgMaxBitRate = _beta * _maxHoldRate / 1000.0f;
ChangeRegion(kRcNearMax);
recovery = true;
@ -268,13 +268,13 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 currentBitRate,
{
// Set bit rate to something slightly lower than max
// 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)
{
// Avoid increasing the rate when over-using.
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);
}
@ -321,7 +321,7 @@ WebRtc_UWord32 RemoteRateControl::ChangeBitRate(WebRtc_UWord32 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))))
// Parameters
@ -368,9 +368,9 @@ double RemoteRateControl::RateIncreaseFactor(WebRtc_Word64 nowMs, WebRtc_Word64
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)
{
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)
{

View File

@ -24,13 +24,13 @@ class RemoteRateControl
public:
RemoteRateControl();
~RemoteRateControl();
WebRtc_Word32 SetConfiguredBitRates(WebRtc_UWord32 minBitRate,
WebRtc_UWord32 maxBitRate);
WebRtc_UWord32 LatestEstimate() const;
WebRtc_UWord32 UpdateBandwidthEstimate(WebRtc_Word64 nowMS);
int32_t SetConfiguredBitRates(uint32_t minBitRate,
uint32_t maxBitRate);
uint32_t LatestEstimate() const;
uint32_t UpdateBandwidthEstimate(int64_t nowMS);
void SetRtt(unsigned int rtt);
RateControlRegion Update(const RateControlInput* input,
WebRtc_Word64 nowMS);
int64_t nowMS);
void Reset();
// Returns true if there is a valid estimate of the incoming bitrate, false
@ -44,39 +44,39 @@ public:
unsigned int incoming_bitrate) const;
private:
WebRtc_UWord32 ChangeBitRate(WebRtc_UWord32 currentBitRate,
WebRtc_UWord32 incomingBitRate,
uint32_t ChangeBitRate(uint32_t currentBitRate,
uint32_t incomingBitRate,
double delayFactor,
WebRtc_Word64 nowMS);
double RateIncreaseFactor(WebRtc_Word64 nowMs,
WebRtc_Word64 lastMs,
WebRtc_UWord32 reactionTimeMs,
int64_t nowMS);
double RateIncreaseFactor(int64_t nowMs,
int64_t lastMs,
uint32_t reactionTimeMs,
double noiseVar) const;
void UpdateChangePeriod(WebRtc_Word64 nowMs);
void UpdateChangePeriod(int64_t nowMs);
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 ChangeRegion(RateControlRegion region);
static void StateStr(RateControlState state, char* str);
static void StateStr(BandwidthUsage state, char* str);
WebRtc_UWord32 _minConfiguredBitRate;
WebRtc_UWord32 _maxConfiguredBitRate;
WebRtc_UWord32 _currentBitRate;
WebRtc_UWord32 _maxHoldRate;
uint32_t _minConfiguredBitRate;
uint32_t _maxConfiguredBitRate;
uint32_t _currentBitRate;
uint32_t _maxHoldRate;
float _avgMaxBitRate;
float _varMaxBitRate;
RateControlState _rcState;
RateControlState _cameFromState;
RateControlRegion _rcRegion;
WebRtc_Word64 _lastBitRateChange;
int64_t _lastBitRateChange;
RateControlInput _currentInput;
bool _updated;
WebRtc_Word64 _timeFirstIncomingEstimate;
int64_t _timeFirstIncomingEstimate;
bool _initializedBitRate;
float _avgChangePeriod;
WebRtc_Word64 _lastChangeMs;
int64_t _lastChangeMs;
float _beta;
unsigned int _rtt;
#ifdef MATLAB