author Randell Jesup <>
Thu, 04 Oct 2012 12:09:31 -0400
changeset 115578 174d772e83f42e84c3ba97b8fbb9c937cba027a9
parent 102049 media/webrtc/trunk/src/modules/rtp_rtcp/source/remote_rate_control.h@305edcfd646037062d1859565dd4bbda469f8282
permissions -rw-r--r--
Bug 797671: Import code from stable branch 3.12 (rev 2820) rs=jesup

 *  Copyright (c) 2012 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 "modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "typedefs.h"

#ifdef MATLAB
#include "../test/BWEStandAlone/MatlabPlot.h"

namespace webrtc {
class RemoteRateControl
    WebRtc_Word32 SetConfiguredBitRates(WebRtc_UWord32 minBitRate,
                                        WebRtc_UWord32 maxBitRate);
    WebRtc_UWord32 LatestEstimate() const;
    WebRtc_UWord32 UpdateBandwidthEstimate(WebRtc_Word64 nowMS);
    void SetRtt(unsigned int rtt);
    RateControlRegion Update(const RateControlInput* input,
                             WebRtc_Word64 nowMS);
    void Reset();

    // Returns true if there is a valid estimate of the incoming bitrate, false
    // otherwise.
    bool ValidEstimate() const;

    WebRtc_UWord32 ChangeBitRate(WebRtc_UWord32 currentBitRate,
                                 WebRtc_UWord32 incomingBitRate,
                                 double delayFactor,
                                 WebRtc_Word64 nowMS);
    double RateIncreaseFactor(WebRtc_Word64 nowMs,
                              WebRtc_Word64 lastMs,
                              WebRtc_UWord32 reactionTimeMs,
                              double noiseVar) const;
    void UpdateChangePeriod(WebRtc_Word64 nowMs);
    void UpdateMaxBitRateEstimate(float incomingBitRateKbps);
    void ChangeState(const RateControlInput& input, WebRtc_Word64 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;
    float               _avgMaxBitRate;
    float               _varMaxBitRate;
    RateControlState    _rcState;
    RateControlState    _cameFromState;
    RateControlRegion   _rcRegion;
    WebRtc_Word64         _lastBitRateChange;
    RateControlInput    _currentInput;
    bool                _updated;
    WebRtc_Word64         _timeFirstIncomingEstimate;
    bool                _initializedBitRate;

    float               _avgChangePeriod;
    WebRtc_Word64         _lastChangeMs;
    float               _beta;
    unsigned int _rtt;
#ifdef MATLAB
    MatlabPlot          *_plot1;
    MatlabPlot          *_plot2;
} // namespace webrtc