diff --git a/webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h b/webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h index 6c3dc40042..59d1a2678a 100644 --- a/webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h +++ b/webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h @@ -13,9 +13,6 @@ #include "typedefs.h" -#define BWE_MAX(a,b) ((a)>(b)?(a):(b)) -#define BWE_MIN(a,b) ((a)<(b)?(a):(b)) - namespace webrtc { enum BandwidthUsage { diff --git a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc index 0fbf6f15fa..f9a98a375c 100644 --- a/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc +++ b/webrtc/modules/remote_bitrate_estimator/overuse_detector.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include #include #include // fabsf #if _WIN32 @@ -26,6 +27,10 @@ extern MatlabEngine eng; // global variable defined elsewhere enum { kOverUsingTimeThreshold = 100 }; enum { kMinFramePeriodHistoryLength = 60 }; +namespace { +const uint16_t kMaxDeltas = 60; +} + namespace webrtc { OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) : options_(options), @@ -249,7 +254,7 @@ void OveruseDetector::UpdateKalman(int64_t t_delta, const double residual = t_ts_delta - slope_*h[0] - offset_; const bool stable_state = - (BWE_MIN(num_of_deltas_, 60) * fabsf(offset_) < threshold_); + (std::min(num_of_deltas_, kMaxDeltas) * fabsf(offset_) < threshold_); // We try to filter out very late frames. For instance periodic key // frames doesn't fit the Gaussian model well. if (fabsf(residual) < 3 * sqrt(var_noise_)) { @@ -306,7 +311,8 @@ void OveruseDetector::UpdateKalman(int64_t t_delta, plots_.plot1_->Plot(); plots_.plot2_->Append("offset", offset_); - plots_.plot2_->Append("limitPos", threshold_/BWE_MIN(num_of_deltas_, 60)); + plots_.plot2_->Append("limitPos", threshold_ / + std::min(num_of_deltas_, kMaxDeltas)); plots_.plot2_->Plot(); plots_.plot3_->Append("noiseVar", var_noise_); @@ -322,7 +328,7 @@ double OveruseDetector::UpdateMinFramePeriod(double ts_delta) { } std::list::iterator it = ts_delta_hist_.begin(); for (; it != ts_delta_hist_.end(); it++) { - min_frame_period = BWE_MIN(*it, min_frame_period); + min_frame_period = std::min(*it, min_frame_period); } ts_delta_hist_.push_back(ts_delta); return min_frame_period; @@ -357,7 +363,7 @@ BandwidthUsage OveruseDetector::Detect(double ts_delta) { if (num_of_deltas_ < 2) { return kBwNormal; } - const double T = BWE_MIN(num_of_deltas_, 60) * offset_; + const double T = std::min(num_of_deltas_, kMaxDeltas) * offset_; if (fabsf(T) > threshold_) { if (offset_ > 0) { if (time_over_using_ == -1) { diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.h b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.h index 713b961b51..a5814892e6 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.h +++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_multi_stream.h @@ -35,13 +35,15 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator { RemoteBitrateObserver* observer, Clock* clock); - ~RemoteBitrateEstimatorMultiStream() {} + virtual ~RemoteBitrateEstimatorMultiStream() {} // 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 // two tuples the RemoteBitrateEstimator will switch to multi-stream mode. - void IncomingRtcp(unsigned int ssrc, uint32_t ntp_secs, uint32_t ntp_frac, - uint32_t rtp_timestamp); + virtual void IncomingRtcp(unsigned int ssrc, + uint32_t ntp_secs, + uint32_t ntp_frac, + uint32_t rtp_timestamp); // 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 @@ -49,10 +51,10 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator { // incoming payload bitrate 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 packet size excluding headers. - void IncomingPacket(unsigned int ssrc, - int payload_size, - int64_t arrival_time, - uint32_t rtp_timestamp); + virtual void IncomingPacket(unsigned int ssrc, + int payload_size, + int64_t arrival_time, + uint32_t rtp_timestamp); // Triggers a new estimate calculation. // Implements the Module interface. @@ -63,13 +65,13 @@ class RemoteBitrateEstimatorMultiStream : public RemoteBitrateEstimator { virtual void OnRttUpdate(uint32_t rtt); // Removes all data for |ssrc|. - void RemoveStream(unsigned int ssrc); + virtual void RemoveStream(unsigned int ssrc); // 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 // currently being received and of which the bitrate estimate is based upon. - bool LatestEstimate(std::vector* ssrcs, - unsigned int* bitrate_bps) const; + virtual bool LatestEstimate(std::vector* ssrcs, + unsigned int* bitrate_bps) const; private: typedef std::map StreamMap; diff --git a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h index 575ed09cd8..fd2c4e873a 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h +++ b/webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h @@ -35,18 +35,20 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { virtual ~RemoteBitrateEstimatorSingleStream() {} - void IncomingRtcp(unsigned int ssrc, uint32_t ntp_secs, uint32_t ntp_frac, - uint32_t rtp_timestamp) {} + virtual void IncomingRtcp(unsigned int ssrc, + uint32_t ntp_secs, + uint32_t ntp_frac, + uint32_t rtp_timestamp) {} // Called for each incoming packet. If this is a new SSRC, a new // BitrateControl will be created. Updates the incoming payload bitrate // 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 // packet size excluding headers. - void IncomingPacket(unsigned int ssrc, - int payload_size, - int64_t arrival_time, - uint32_t rtp_timestamp); + virtual void IncomingPacket(unsigned int ssrc, + int payload_size, + int64_t arrival_time, + uint32_t rtp_timestamp); // Triggers a new estimate calculation. // Implements the Module interface. @@ -57,13 +59,13 @@ class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { virtual void OnRttUpdate(uint32_t rtt); // Removes all data for |ssrc|. - void RemoveStream(unsigned int ssrc); + virtual void RemoveStream(unsigned int ssrc); // 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 // currently being received and of which the bitrate estimate is based upon. - bool LatestEstimate(std::vector* ssrcs, - unsigned int* bitrate_bps) const; + virtual bool LatestEstimate(std::vector* ssrcs, + unsigned int* bitrate_bps) const; private: typedef std::map SsrcOveruseDetectorMap; diff --git a/webrtc/modules/remote_bitrate_estimator/remote_rate_control.cc b/webrtc/modules/remote_bitrate_estimator/remote_rate_control.cc index fd54980d43..1cccea8d9b 100644 --- a/webrtc/modules/remote_bitrate_estimator/remote_rate_control.cc +++ b/webrtc/modules/remote_bitrate_estimator/remote_rate_control.cc @@ -10,6 +10,7 @@ #include "modules/remote_bitrate_estimator/remote_rate_control.h" +#include #include #include #include @@ -91,7 +92,7 @@ bool RemoteRateControl::ValidEstimate() const { bool RemoteRateControl::TimeToReduceFurther( int64_t time_now, unsigned int incoming_bitrate) const { - const int bitrate_reduction_interval = BWE_MAX(BWE_MIN(_rtt, 200), 10); + const int bitrate_reduction_interval = std::max(std::min(_rtt, 200u), 10u); if (time_now - _lastBitRateChange >= bitrate_reduction_interval) { return true; } @@ -112,7 +113,7 @@ int32_t RemoteRateControl::SetConfiguredBitRates( } _minConfiguredBitRate = minBitRateBps; _maxConfiguredBitRate = maxBitRateBps; - _currentBitRate = BWE_MIN(BWE_MAX(minBitRateBps, _currentBitRate), + _currentBitRate = std::min(std::max(minBitRateBps, _currentBitRate), maxBitRateBps); return 0; } @@ -214,7 +215,7 @@ uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate, { case kRcHold: { - _maxHoldRate = BWE_MAX(_maxHoldRate, incomingBitRate); + _maxHoldRate = std::max(_maxHoldRate, incomingBitRate); break; } case kRcIncrease: @@ -276,7 +277,7 @@ uint32_t RemoteRateControl::ChangeBitRate(uint32_t currentBitRate, { currentBitRate = static_cast(_beta * _avgMaxBitRate * 1000 + 0.5f); } - currentBitRate = BWE_MIN(currentBitRate, _currentBitRate); + currentBitRate = std::min(currentBitRate, _currentBitRate); } ChangeRegion(kRcNearMax); @@ -393,7 +394,7 @@ void RemoteRateControl::UpdateMaxBitRateEstimate(float incomingBitRateKbps) } // Estimate the max bit rate variance and normalize the variance // with the average max bit rate. - const float norm = BWE_MAX(_avgMaxBitRate, 1.0f); + const float norm = std::max(_avgMaxBitRate, 1.0f); _varMaxBitRate = (1 - alpha) * _varMaxBitRate + alpha * (_avgMaxBitRate - incomingBitRateKbps) * (_avgMaxBitRate - incomingBitRateKbps) /