2012-03-05 17:12:41 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-23 13:30:42 +01:00
|
|
|
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
|
2012-03-05 17:12:41 +00:00
|
|
|
|
2016-02-16 17:07:21 +01:00
|
|
|
#include <algorithm>
|
2016-03-17 09:17:43 -07:00
|
|
|
#include <memory>
|
2016-02-08 14:31:30 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
2015-03-09 10:06:40 +00:00
|
|
|
#include "webrtc/base/checks.h"
|
2016-04-26 08:14:39 -07:00
|
|
|
#include "webrtc/base/constructormagic.h"
|
2015-12-04 16:13:05 +01:00
|
|
|
#include "webrtc/base/logging.h"
|
2016-02-08 14:31:30 +01:00
|
|
|
#include "webrtc/base/socket.h"
|
2014-09-24 06:05:00 +00:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2015-11-12 21:02:42 -08:00
|
|
|
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
|
2016-06-17 09:21:34 -07:00
|
|
|
#include "webrtc/modules/congestion_controller/delay_based_bwe.h"
|
2015-08-03 04:38:41 -07:00
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
|
2015-07-06 10:50:47 +02:00
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
|
|
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/utility/include/process_thread.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
2015-12-09 12:13:30 +01:00
|
|
|
#include "webrtc/video/payload_router.h"
|
2012-03-05 17:12:41 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2013-05-27 16:02:56 +00:00
|
|
|
namespace {
|
|
|
|
|
|
2013-12-16 12:24:44 +00:00
|
|
|
static const uint32_t kTimeOffsetSwitchThreshold = 30;
|
|
|
|
|
|
2016-06-24 11:03:55 -07:00
|
|
|
// Makes sure that the bitrate and the min, max values are in valid range.
|
|
|
|
|
static void ClampBitrates(int* bitrate_bps,
|
|
|
|
|
int* min_bitrate_bps,
|
|
|
|
|
int* max_bitrate_bps) {
|
|
|
|
|
// TODO(holmer): We should make sure the default bitrates are set to 10 kbps,
|
|
|
|
|
// and that we don't try to set the min bitrate to 0 from any applications.
|
|
|
|
|
// The congestion controller should allow a min bitrate of 0.
|
|
|
|
|
const int kMinBitrateBps = 10000;
|
|
|
|
|
if (*min_bitrate_bps < kMinBitrateBps)
|
|
|
|
|
*min_bitrate_bps = kMinBitrateBps;
|
|
|
|
|
if (*max_bitrate_bps > 0)
|
|
|
|
|
*max_bitrate_bps = std::max(*min_bitrate_bps, *max_bitrate_bps);
|
|
|
|
|
if (*bitrate_bps > 0)
|
|
|
|
|
*bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 16:02:56 +00:00
|
|
|
class WrappingBitrateEstimator : public RemoteBitrateEstimator {
|
|
|
|
|
public:
|
2015-07-27 08:37:06 -07:00
|
|
|
WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock)
|
2013-05-27 16:02:56 +00:00
|
|
|
: observer_(observer),
|
|
|
|
|
clock_(clock),
|
|
|
|
|
crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
|
2015-09-28 03:57:14 -07:00
|
|
|
rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)),
|
2013-12-16 12:24:44 +00:00
|
|
|
using_absolute_send_time_(false),
|
2015-09-28 03:57:14 -07:00
|
|
|
packets_since_absolute_send_time_(0),
|
|
|
|
|
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {}
|
2013-05-27 16:02:56 +00:00
|
|
|
|
2014-07-02 13:23:19 +00:00
|
|
|
virtual ~WrappingBitrateEstimator() {}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void IncomingPacket(int64_t arrival_time_ms,
|
|
|
|
|
size_t payload_size,
|
2016-06-20 11:53:02 -07:00
|
|
|
const RTPHeader& header) override {
|
2013-05-27 16:02:56 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
2014-03-25 10:37:31 +00:00
|
|
|
PickEstimatorFromHeader(header);
|
2016-06-20 11:53:02 -07:00
|
|
|
rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
|
2013-05-27 16:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 04:50:01 -08:00
|
|
|
void Process() override {
|
2014-07-02 13:23:19 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
2016-02-25 04:50:01 -08:00
|
|
|
rbe_->Process();
|
2013-05-27 16:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int64_t TimeUntilNextProcess() override {
|
2014-07-02 13:23:19 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
|
|
|
|
return rbe_->TimeUntilNextProcess();
|
2013-05-27 16:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-07 04:27:51 -07:00
|
|
|
void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override {
|
2013-05-27 16:02:56 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
2015-08-07 04:27:51 -07:00
|
|
|
rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
2013-05-27 16:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void RemoveStream(unsigned int ssrc) override {
|
2013-05-27 16:02:56 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
|
|
|
|
rbe_->RemoveStream(ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
bool LatestEstimate(std::vector<unsigned int>* ssrcs,
|
|
|
|
|
unsigned int* bitrate_bps) const override {
|
2013-05-27 16:02:56 +00:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
|
|
|
|
return rbe_->LatestEstimate(ssrcs, bitrate_bps);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 06:09:15 -07:00
|
|
|
void SetMinBitrate(int min_bitrate_bps) override {
|
2015-09-28 03:57:14 -07:00
|
|
|
CriticalSectionScoped cs(crit_sect_.get());
|
|
|
|
|
rbe_->SetMinBitrate(min_bitrate_bps);
|
|
|
|
|
min_bitrate_bps_ = min_bitrate_bps;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 16:02:56 +00:00
|
|
|
private:
|
2014-03-25 10:37:31 +00:00
|
|
|
void PickEstimatorFromHeader(const RTPHeader& header)
|
|
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
|
2013-12-16 12:24:44 +00:00
|
|
|
if (header.extension.hasAbsoluteSendTime) {
|
|
|
|
|
// If we see AST in header, switch RBE strategy immediately.
|
|
|
|
|
if (!using_absolute_send_time_) {
|
2014-04-07 10:56:31 +00:00
|
|
|
LOG(LS_INFO) <<
|
|
|
|
|
"WrappingBitrateEstimator: Switching to absolute send time RBE.";
|
2013-12-16 12:24:44 +00:00
|
|
|
using_absolute_send_time_ = true;
|
2014-03-25 10:37:31 +00:00
|
|
|
PickEstimator();
|
2013-12-16 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
packets_since_absolute_send_time_ = 0;
|
|
|
|
|
} else {
|
|
|
|
|
// When we don't see AST, wait for a few packets before going back to TOF.
|
|
|
|
|
if (using_absolute_send_time_) {
|
|
|
|
|
++packets_since_absolute_send_time_;
|
|
|
|
|
if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) {
|
2014-04-07 10:56:31 +00:00
|
|
|
LOG(LS_INFO) << "WrappingBitrateEstimator: Switching to transmission "
|
|
|
|
|
<< "time offset RBE.";
|
2013-12-16 12:24:44 +00:00
|
|
|
using_absolute_send_time_ = false;
|
2014-03-25 10:37:31 +00:00
|
|
|
PickEstimator();
|
2013-12-16 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 10:37:31 +00:00
|
|
|
// Instantiate RBE for Time Offset or Absolute Send Time extensions.
|
|
|
|
|
void PickEstimator() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
|
|
|
|
|
if (using_absolute_send_time_) {
|
2016-04-14 08:08:15 -07:00
|
|
|
rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_));
|
2014-03-25 10:37:31 +00:00
|
|
|
} else {
|
2015-09-28 03:57:14 -07:00
|
|
|
rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_));
|
2014-03-25 10:37:31 +00:00
|
|
|
}
|
2015-09-28 03:57:14 -07:00
|
|
|
rbe_->SetMinBitrate(min_bitrate_bps_);
|
2014-03-25 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-27 16:02:56 +00:00
|
|
|
RemoteBitrateObserver* observer_;
|
2016-02-08 14:31:30 +01:00
|
|
|
Clock* const clock_;
|
2016-03-17 09:17:43 -07:00
|
|
|
std::unique_ptr<CriticalSectionWrapper> crit_sect_;
|
|
|
|
|
std::unique_ptr<RemoteBitrateEstimator> rbe_;
|
2013-12-16 12:24:44 +00:00
|
|
|
bool using_absolute_send_time_;
|
|
|
|
|
uint32_t packets_since_absolute_send_time_;
|
2015-09-28 03:57:14 -07:00
|
|
|
int min_bitrate_bps_;
|
2013-05-27 16:02:56 +00:00
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
|
2013-05-27 16:02:56 +00:00
|
|
|
};
|
2015-08-03 04:38:41 -07:00
|
|
|
|
2013-05-27 16:02:56 +00:00
|
|
|
} // namespace
|
2012-03-05 17:12:41 +00:00
|
|
|
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
CongestionController::CongestionController(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
BitrateObserver* bitrate_observer,
|
|
|
|
|
RemoteBitrateObserver* remote_bitrate_observer)
|
|
|
|
|
: clock_(clock),
|
|
|
|
|
observer_(nullptr),
|
|
|
|
|
packet_router_(new PacketRouter()),
|
|
|
|
|
pacer_(new PacedSender(clock_, packet_router_.get())),
|
|
|
|
|
remote_bitrate_estimator_(
|
|
|
|
|
new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
|
|
|
|
|
bitrate_controller_(
|
|
|
|
|
BitrateController::CreateBitrateController(clock_, bitrate_observer)),
|
|
|
|
|
remote_estimator_proxy_(clock_, packet_router_.get()),
|
|
|
|
|
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
|
|
|
|
|
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
|
|
|
|
|
last_reported_bitrate_bps_(0),
|
|
|
|
|
last_reported_fraction_loss_(0),
|
|
|
|
|
last_reported_rtt_(0),
|
|
|
|
|
network_state_(kNetworkUp) {
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 06:01:13 -07:00
|
|
|
CongestionController::CongestionController(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
Observer* observer,
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
RemoteBitrateObserver* remote_bitrate_observer)
|
2016-05-11 06:01:13 -07:00
|
|
|
: clock_(clock),
|
|
|
|
|
observer_(observer),
|
|
|
|
|
packet_router_(new PacketRouter()),
|
2016-05-14 00:58:48 -07:00
|
|
|
pacer_(new PacedSender(clock_, packet_router_.get())),
|
2016-05-11 06:01:13 -07:00
|
|
|
remote_bitrate_estimator_(
|
|
|
|
|
new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
|
2016-05-11 06:01:13 -07:00
|
|
|
remote_estimator_proxy_(clock_, packet_router_.get()),
|
|
|
|
|
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
|
|
|
|
|
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
|
2016-05-14 00:58:48 -07:00
|
|
|
last_reported_bitrate_bps_(0),
|
|
|
|
|
last_reported_fraction_loss_(0),
|
|
|
|
|
last_reported_rtt_(0),
|
|
|
|
|
network_state_(kNetworkUp) {
|
2016-05-11 06:01:13 -07:00
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CongestionController::CongestionController(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
Observer* observer,
|
|
|
|
|
RemoteBitrateObserver* remote_bitrate_observer,
|
|
|
|
|
std::unique_ptr<PacketRouter> packet_router,
|
|
|
|
|
std::unique_ptr<PacedSender> pacer)
|
|
|
|
|
: clock_(clock),
|
|
|
|
|
observer_(observer),
|
|
|
|
|
packet_router_(std::move(packet_router)),
|
|
|
|
|
pacer_(std::move(pacer)),
|
|
|
|
|
remote_bitrate_estimator_(
|
|
|
|
|
new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
|
|
|
|
|
// Constructed last as this object calls the provided callback on
|
|
|
|
|
// construction.
|
Revert of Move RtcEventLog object from inside VoiceEngine to Call. (patchset #16 id:420001 of https://codereview.webrtc.org/1748403002/ )
Reason for revert:
Reverting all CLs related to moving the eventlog, as they break Chromium tests.
Original issue's description:
> Move RtcEventLog object from inside VoiceEngine to Call.
>
> In addition to moving the logging object itself, this also moves the interface from PeerConnectionFactory to PeerConnection, which makes more sense for this functionality. An API parameter to set an upper limit to the size of the logfile is introduced.
> The old interface on PeerConnectionFactory is not removed in this CL, because it is called from Chrome, it will be removed after Chrome is updated to use the PeerConnection interface.
>
> BUG=webrtc:4741,webrtc:5603,chromium:609749
> R=solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org, tommi@webrtc.org
>
> Committed: https://crrev.com/1895526c6130e3d0e9b154f95079b8eda7567016
> Cr-Commit-Position: refs/heads/master@{#13321}
TBR=solenberg@webrtc.org,tommi@webrtc.org,stefan@webrtc.org,terelius@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:4741,webrtc:5603,chromium:609749
Review-Url: https://codereview.webrtc.org/2111813002
Cr-Commit-Position: refs/heads/master@{#13340}
2016-06-30 00:59:43 -07:00
|
|
|
bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
|
2016-05-11 06:01:13 -07:00
|
|
|
remote_estimator_proxy_(clock_, packet_router_.get()),
|
2016-02-17 15:52:17 +01:00
|
|
|
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
|
2016-05-11 06:01:13 -07:00
|
|
|
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
|
2016-05-14 00:58:48 -07:00
|
|
|
last_reported_bitrate_bps_(0),
|
|
|
|
|
last_reported_fraction_loss_(0),
|
|
|
|
|
last_reported_rtt_(0),
|
|
|
|
|
network_state_(kNetworkUp) {
|
2016-05-11 06:01:13 -07:00
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CongestionController::~CongestionController() {}
|
|
|
|
|
|
|
|
|
|
void CongestionController::Init() {
|
2016-02-17 15:52:17 +01:00
|
|
|
transport_feedback_adapter_.SetBitrateEstimator(
|
2016-06-17 09:21:34 -07:00
|
|
|
new DelayBasedBwe(&transport_feedback_adapter_));
|
2016-02-17 15:52:17 +01:00
|
|
|
transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
|
|
|
|
|
min_bitrate_bps_);
|
2016-05-09 04:57:11 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
void CongestionController::SetBweBitrates(int min_bitrate_bps,
|
|
|
|
|
int start_bitrate_bps,
|
|
|
|
|
int max_bitrate_bps) {
|
2016-06-24 11:03:55 -07:00
|
|
|
ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
|
2016-04-28 15:52:49 +02:00
|
|
|
bitrate_controller_->SetBitrates(start_bitrate_bps,
|
|
|
|
|
min_bitrate_bps,
|
|
|
|
|
max_bitrate_bps);
|
|
|
|
|
|
2016-02-17 15:52:17 +01:00
|
|
|
if (remote_bitrate_estimator_)
|
2015-09-28 03:57:14 -07:00
|
|
|
remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
|
|
|
|
|
min_bitrate_bps_ = min_bitrate_bps;
|
2016-02-17 15:52:17 +01:00
|
|
|
transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
|
|
|
|
|
min_bitrate_bps_);
|
2016-05-11 06:01:13 -07:00
|
|
|
MaybeTriggerOnNetworkChanged();
|
2015-09-28 03:57:14 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 11:03:55 -07:00
|
|
|
void CongestionController::ResetBweAndBitrates(int bitrate_bps,
|
|
|
|
|
int min_bitrate_bps,
|
|
|
|
|
int max_bitrate_bps) {
|
|
|
|
|
ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
|
|
|
|
|
// TODO(honghaiz): Recreate this object once the bitrate controller is
|
|
|
|
|
// no longer exposed outside CongestionController.
|
|
|
|
|
bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
|
|
|
|
|
max_bitrate_bps);
|
|
|
|
|
min_bitrate_bps_ = min_bitrate_bps;
|
|
|
|
|
// TODO(honghaiz): Recreate this object once the remote bitrate estimator is
|
|
|
|
|
// no longer exposed outside CongestionController.
|
|
|
|
|
if (remote_bitrate_estimator_)
|
|
|
|
|
remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
|
|
|
|
|
|
|
|
|
|
RemoteBitrateEstimator* rbe =
|
|
|
|
|
new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_);
|
|
|
|
|
transport_feedback_adapter_.SetBitrateEstimator(rbe);
|
|
|
|
|
rbe->SetMinBitrate(min_bitrate_bps);
|
|
|
|
|
// TODO(holmer): Trigger a new probe once mid-call probing is implemented.
|
|
|
|
|
MaybeTriggerOnNetworkChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
BitrateController* CongestionController::GetBitrateController() const {
|
2012-06-05 12:25:35 +00:00
|
|
|
return bitrate_controller_.get();
|
2012-06-05 10:44:00 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
|
2016-02-17 15:52:17 +01:00
|
|
|
bool send_side_bwe) {
|
|
|
|
|
if (send_side_bwe) {
|
|
|
|
|
return &remote_estimator_proxy_;
|
|
|
|
|
} else {
|
2015-10-18 22:08:19 -07:00
|
|
|
return remote_bitrate_estimator_.get();
|
2016-02-17 15:52:17 +01:00
|
|
|
}
|
2012-06-07 08:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
TransportFeedbackObserver*
|
|
|
|
|
CongestionController::GetTransportFeedbackObserver() {
|
2016-02-17 15:52:17 +01:00
|
|
|
return &transport_feedback_adapter_;
|
2015-10-16 02:31:11 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-15 00:47:53 -07:00
|
|
|
void CongestionController::SetAllocatedSendBitrateLimits(
|
|
|
|
|
int min_send_bitrate_bps,
|
|
|
|
|
int max_padding_bitrate_bps) {
|
|
|
|
|
pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps);
|
2015-11-12 21:02:42 -08:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
int64_t CongestionController::GetPacerQueuingDelayMs() const {
|
2015-03-26 11:11:06 +01:00
|
|
|
return pacer_->QueueInMs();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
void CongestionController::SignalNetworkState(NetworkState state) {
|
2015-10-14 03:12:59 -07:00
|
|
|
if (state == kNetworkUp) {
|
|
|
|
|
pacer_->Resume();
|
|
|
|
|
} else {
|
|
|
|
|
pacer_->Pause();
|
|
|
|
|
}
|
2016-05-14 00:58:48 -07:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
network_state_ = state;
|
|
|
|
|
}
|
|
|
|
|
MaybeTriggerOnNetworkChanged();
|
2015-10-14 03:12:59 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 15:52:16 +02:00
|
|
|
void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
|
2016-02-17 15:52:17 +01:00
|
|
|
transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
|
|
|
|
|
sent_packet.send_time_ms);
|
2015-10-15 07:26:07 -07:00
|
|
|
}
|
2016-02-17 15:52:17 +01:00
|
|
|
|
|
|
|
|
void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
|
|
|
|
|
remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
|
|
|
|
transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t CongestionController::TimeUntilNextProcess() {
|
|
|
|
|
return std::min(bitrate_controller_->TimeUntilNextProcess(),
|
|
|
|
|
remote_bitrate_estimator_->TimeUntilNextProcess());
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 04:50:01 -08:00
|
|
|
void CongestionController::Process() {
|
2016-02-17 15:52:17 +01:00
|
|
|
bitrate_controller_->Process();
|
|
|
|
|
remote_bitrate_estimator_->Process();
|
2016-05-11 06:01:13 -07:00
|
|
|
MaybeTriggerOnNetworkChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CongestionController::MaybeTriggerOnNetworkChanged() {
|
|
|
|
|
// TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
|
|
|
|
|
// BitrateObserver is used. Remove this check once the ctor is removed.
|
|
|
|
|
if (!observer_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint32_t bitrate_bps;
|
|
|
|
|
uint8_t fraction_loss;
|
|
|
|
|
int64_t rtt;
|
2016-05-14 00:58:48 -07:00
|
|
|
bool estimate_changed = bitrate_controller_->GetNetworkParameters(
|
2016-05-11 06:01:13 -07:00
|
|
|
&bitrate_bps, &fraction_loss, &rtt);
|
2016-05-14 00:58:48 -07:00
|
|
|
if (estimate_changed)
|
2016-05-11 06:01:13 -07:00
|
|
|
pacer_->SetEstimatedBitrate(bitrate_bps);
|
2016-05-14 00:58:48 -07:00
|
|
|
|
|
|
|
|
bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
|
|
|
|
|
|
|
|
|
|
if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
|
2016-05-11 06:01:13 -07:00
|
|
|
observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-14 00:58:48 -07:00
|
|
|
bool CongestionController::HasNetworkParametersToReportChanged(
|
|
|
|
|
uint32_t bitrate_bps,
|
|
|
|
|
uint8_t fraction_loss,
|
|
|
|
|
int64_t rtt) {
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
bool changed =
|
|
|
|
|
last_reported_bitrate_bps_ != bitrate_bps ||
|
|
|
|
|
(bitrate_bps > 0 && (last_reported_fraction_loss_ != fraction_loss ||
|
|
|
|
|
last_reported_rtt_ != rtt));
|
|
|
|
|
last_reported_bitrate_bps_ = bitrate_bps;
|
|
|
|
|
last_reported_fraction_loss_ = fraction_loss;
|
|
|
|
|
last_reported_rtt_ = rtt;
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CongestionController::IsSendQueueFull() const {
|
|
|
|
|
return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CongestionController::IsNetworkDown() const {
|
2016-05-11 06:01:13 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2016-05-14 00:58:48 -07:00
|
|
|
return network_state_ == kNetworkDown;
|
2016-02-17 15:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-05 17:12:41 +00:00
|
|
|
} // namespace webrtc
|