revert r3871

TBR= solenberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1331004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3872 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mikhal@webrtc.org 2013-04-18 20:26:28 +00:00
parent 9756017717
commit a73d52ca52
5 changed files with 31 additions and 39 deletions

View File

@ -13,6 +13,9 @@
#include "typedefs.h" #include "typedefs.h"
#define BWE_MAX(a,b) ((a)>(b)?(a):(b))
#define BWE_MIN(a,b) ((a)<(b)?(a):(b))
namespace webrtc { namespace webrtc {
enum BandwidthUsage enum BandwidthUsage
{ {

View File

@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <algorithm>
#include <math.h> #include <math.h>
#include <stdlib.h> // fabsf #include <stdlib.h> // fabsf
#if _WIN32 #if _WIN32
@ -27,10 +26,6 @@ extern MatlabEngine eng; // global variable defined elsewhere
enum { kOverUsingTimeThreshold = 100 }; enum { kOverUsingTimeThreshold = 100 };
enum { kMinFramePeriodHistoryLength = 60 }; enum { kMinFramePeriodHistoryLength = 60 };
namespace {
const uint16_t kMaxDeltas = 60;
}
namespace webrtc { namespace webrtc {
OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options)
: options_(options), : options_(options),
@ -254,7 +249,7 @@ void OveruseDetector::UpdateKalman(int64_t t_delta,
const double residual = t_ts_delta - slope_*h[0] - offset_; const double residual = t_ts_delta - slope_*h[0] - offset_;
const bool stable_state = const bool stable_state =
(std::min(num_of_deltas_, kMaxDeltas) * fabsf(offset_) < threshold_); (BWE_MIN(num_of_deltas_, 60) * fabsf(offset_) < threshold_);
// We try to filter out very late frames. For instance periodic key // We try to filter out very late frames. For instance periodic key
// frames doesn't fit the Gaussian model well. // frames doesn't fit the Gaussian model well.
if (fabsf(residual) < 3 * sqrt(var_noise_)) { if (fabsf(residual) < 3 * sqrt(var_noise_)) {
@ -311,8 +306,7 @@ void OveruseDetector::UpdateKalman(int64_t t_delta,
plots_.plot1_->Plot(); plots_.plot1_->Plot();
plots_.plot2_->Append("offset", offset_); plots_.plot2_->Append("offset", offset_);
plots_.plot2_->Append("limitPos", threshold_ / plots_.plot2_->Append("limitPos", threshold_/BWE_MIN(num_of_deltas_, 60));
std::min(num_of_deltas_, kMaxDeltas));
plots_.plot2_->Plot(); plots_.plot2_->Plot();
plots_.plot3_->Append("noiseVar", var_noise_); plots_.plot3_->Append("noiseVar", var_noise_);
@ -328,7 +322,7 @@ double OveruseDetector::UpdateMinFramePeriod(double ts_delta) {
} }
std::list<double>::iterator it = ts_delta_hist_.begin(); std::list<double>::iterator it = ts_delta_hist_.begin();
for (; it != ts_delta_hist_.end(); it++) { for (; it != ts_delta_hist_.end(); it++) {
min_frame_period = std::min(*it, min_frame_period); min_frame_period = BWE_MIN(*it, min_frame_period);
} }
ts_delta_hist_.push_back(ts_delta); ts_delta_hist_.push_back(ts_delta);
return min_frame_period; return min_frame_period;
@ -363,7 +357,7 @@ BandwidthUsage OveruseDetector::Detect(double ts_delta) {
if (num_of_deltas_ < 2) { if (num_of_deltas_ < 2) {
return kBwNormal; return kBwNormal;
} }
const double T = std::min(num_of_deltas_, kMaxDeltas) * offset_; const double T = BWE_MIN(num_of_deltas_, 60) * offset_;
if (fabsf(T) > threshold_) { if (fabsf(T) > threshold_) {
if (offset_ > 0) { if (offset_ > 0) {
if (time_over_using_ == -1) { if (time_over_using_ == -1) {

View File

@ -35,15 +35,13 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator {
RemoteBitrateObserver* observer, RemoteBitrateObserver* observer,
Clock* clock); Clock* clock);
virtual ~RemoteBitrateEstimatorMultiStream() {} ~RemoteBitrateEstimatorMultiStream() {}
// Stores an RTCP SR (NTP, RTP timestamp) tuple for a specific SSRC to be used // Stores an RTCP SR (NTP, RTP timestamp) tuple for a specific SSRC to be used
// in future RTP timestamp to NTP time conversions. As soon as any SSRC has // in future RTP timestamp to NTP time conversions. As soon as any SSRC has
// two tuples the RemoteBitrateEstimator will switch to multi-stream mode. // two tuples the RemoteBitrateEstimator will switch to multi-stream mode.
virtual void IncomingRtcp(unsigned int ssrc, void IncomingRtcp(unsigned int ssrc, uint32_t ntp_secs, uint32_t ntp_frac,
uint32_t ntp_secs, uint32_t rtp_timestamp);
uint32_t ntp_frac,
uint32_t rtp_timestamp);
// Called for each incoming packet. The first SSRC will immediately be used // Called for each incoming packet. The first SSRC will immediately be used
// for over-use detection. Subsequent SSRCs will only be used when at least // for over-use detection. Subsequent SSRCs will only be used when at least
@ -51,10 +49,10 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator {
// incoming payload bitrate estimate and the over-use detector. // incoming payload bitrate estimate and the over-use detector.
// If an over-use is detected the remote bitrate estimate will be updated. // If an over-use is detected the remote bitrate estimate will be updated.
// Note that |payload_size| is the packet size excluding headers. // Note that |payload_size| is the packet size excluding headers.
virtual void IncomingPacket(unsigned int ssrc, void IncomingPacket(unsigned int ssrc,
int payload_size, int payload_size,
int64_t arrival_time, int64_t arrival_time,
uint32_t rtp_timestamp); uint32_t rtp_timestamp);
// Triggers a new estimate calculation. // Triggers a new estimate calculation.
// Implements the Module interface. // Implements the Module interface.
@ -65,13 +63,13 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator {
virtual void OnRttUpdate(uint32_t rtt); virtual void OnRttUpdate(uint32_t rtt);
// Removes all data for |ssrc|. // Removes all data for |ssrc|.
virtual void RemoveStream(unsigned int ssrc); void RemoveStream(unsigned int ssrc);
// Returns true if a valid estimate exists and sets |bitrate_bps| to the // Returns true if a valid estimate exists and sets |bitrate_bps| to the
// estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
// currently being received and of which the bitrate estimate is based upon. // currently being received and of which the bitrate estimate is based upon.
virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs, bool LatestEstimate(std::vector<unsigned int>* ssrcs,
unsigned int* bitrate_bps) const; unsigned int* bitrate_bps) const;
private: private:
typedef std::map<unsigned int, synchronization::RtcpList> StreamMap; typedef std::map<unsigned int, synchronization::RtcpList> StreamMap;

View File

@ -35,20 +35,18 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator {
virtual ~RemoteBitrateEstimatorSingleStream() {} virtual ~RemoteBitrateEstimatorSingleStream() {}
virtual void IncomingRtcp(unsigned int ssrc, void IncomingRtcp(unsigned int ssrc, uint32_t ntp_secs, uint32_t ntp_frac,
uint32_t ntp_secs, uint32_t rtp_timestamp) {}
uint32_t ntp_frac,
uint32_t rtp_timestamp) {}
// Called for each incoming packet. If this is a new SSRC, a new // Called for each incoming packet. If this is a new SSRC, a new
// BitrateControl will be created. Updates the incoming payload bitrate // BitrateControl will be created. Updates the incoming payload bitrate
// estimate and the over-use detector. If an over-use is detected the // estimate and the over-use detector. If an over-use is detected the
// remote bitrate estimate will be updated. Note that |payload_size| is the // remote bitrate estimate will be updated. Note that |payload_size| is the
// packet size excluding headers. // packet size excluding headers.
virtual void IncomingPacket(unsigned int ssrc, void IncomingPacket(unsigned int ssrc,
int payload_size, int payload_size,
int64_t arrival_time, int64_t arrival_time,
uint32_t rtp_timestamp); uint32_t rtp_timestamp);
// Triggers a new estimate calculation. // Triggers a new estimate calculation.
// Implements the Module interface. // Implements the Module interface.
@ -59,13 +57,13 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator {
virtual void OnRttUpdate(uint32_t rtt); virtual void OnRttUpdate(uint32_t rtt);
// Removes all data for |ssrc|. // Removes all data for |ssrc|.
virtual void RemoveStream(unsigned int ssrc); void RemoveStream(unsigned int ssrc);
// Returns true if a valid estimate exists and sets |bitrate_bps| to the // Returns true if a valid estimate exists and sets |bitrate_bps| to the
// estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
// currently being received and of which the bitrate estimate is based upon. // currently being received and of which the bitrate estimate is based upon.
virtual bool LatestEstimate(std::vector<unsigned int>* ssrcs, bool LatestEstimate(std::vector<unsigned int>* ssrcs,
unsigned int* bitrate_bps) const; unsigned int* bitrate_bps) const;
private: private:
typedef std::map<unsigned int, OveruseDetector> SsrcOveruseDetectorMap; typedef std::map<unsigned int, OveruseDetector> SsrcOveruseDetectorMap;

View File

@ -10,7 +10,6 @@
#include "modules/remote_bitrate_estimator/remote_rate_control.h" #include "modules/remote_bitrate_estimator/remote_rate_control.h"
#include <algorithm>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
@ -92,7 +91,7 @@ bool RemoteRateControl::ValidEstimate() const {
bool RemoteRateControl::TimeToReduceFurther( bool RemoteRateControl::TimeToReduceFurther(
int64_t time_now, unsigned int incoming_bitrate) const { int64_t time_now, unsigned int incoming_bitrate) const {
const int bitrate_reduction_interval = std::max(std::min(_rtt, 200u), 10u); const int bitrate_reduction_interval = BWE_MAX(BWE_MIN(_rtt, 200), 10);
if (time_now - _lastBitRateChange >= bitrate_reduction_interval) { if (time_now - _lastBitRateChange >= bitrate_reduction_interval) {
return true; return true;
} }
@ -113,7 +112,7 @@ int32_t RemoteRateControl::SetConfiguredBitRates(
} }
_minConfiguredBitRate = minBitRateBps; _minConfiguredBitRate = minBitRateBps;
_maxConfiguredBitRate = maxBitRateBps; _maxConfiguredBitRate = maxBitRateBps;
_currentBitRate = std::min(std::max(minBitRateBps, _currentBitRate), _currentBitRate = BWE_MIN(BWE_MAX(minBitRateBps, _currentBitRate),
maxBitRateBps); maxBitRateBps);
return 0; return 0;
} }
@ -215,7 +214,7 @@ uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate,
{ {
case kRcHold: case kRcHold:
{ {
_maxHoldRate = std::max(_maxHoldRate, incomingBitRate); _maxHoldRate = BWE_MAX(_maxHoldRate, incomingBitRate);
break; break;
} }
case kRcIncrease: case kRcIncrease:
@ -277,7 +276,7 @@ uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate,
{ {
currentBitRate = static_cast<uint32_t>(_beta * _avgMaxBitRate * 1000 + 0.5f); currentBitRate = static_cast<uint32_t>(_beta * _avgMaxBitRate * 1000 + 0.5f);
} }
currentBitRate = std::min(currentBitRate, _currentBitRate); currentBitRate = BWE_MIN(currentBitRate, _currentBitRate);
} }
ChangeRegion(kRcNearMax); ChangeRegion(kRcNearMax);
@ -394,7 +393,7 @@ void RemoteRateControl::UpdateMaxBitRateEstimate(float incomingBitRateKbps)
} }
// Estimate the max bit rate variance and normalize the variance // Estimate the max bit rate variance and normalize the variance
// with the average max bit rate. // with the average max bit rate.
const float norm = std::max(_avgMaxBitRate, 1.0f); const float norm = BWE_MAX(_avgMaxBitRate, 1.0f);
_varMaxBitRate = (1 - alpha) * _varMaxBitRate + _varMaxBitRate = (1 - alpha) * _varMaxBitRate +
alpha * (_avgMaxBitRate - incomingBitRateKbps) * alpha * (_avgMaxBitRate - incomingBitRateKbps) *
(_avgMaxBitRate - incomingBitRateKbps) / (_avgMaxBitRate - incomingBitRateKbps) /