Add base class NetworkPredictor and NetworkPredictorFactory and wire up.

Add base class NetworkPredictor and NetworkPredictorFactory in /api, make it possible to inject customized NetworkPredictor in PeerConnectionFactory level. The NetworkPredictor object will be pass down to GoogCCNetworkControl and DelayBasedBwe.

Bug: webrtc:10492
Change-Id: Iceeadbe1c9388b11ce4ac01ee56554cb0bf64d04
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130201
Commit-Queue: Ying Wang <yinwa@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27543}
This commit is contained in:
Ying Wang 2019-04-10 13:48:24 +02:00 committed by Commit Bot
parent c21cf04618
commit 0810a7c25a
37 changed files with 294 additions and 96 deletions

View file

@ -45,6 +45,7 @@ rtc_static_library("create_peerconnection_factory") {
":callfactory_api", ":callfactory_api",
":fec_controller_api", ":fec_controller_api",
":libjingle_peerconnection_api", ":libjingle_peerconnection_api",
":network_state_predictor_api",
":scoped_refptr", ":scoped_refptr",
"../logging:rtc_event_log_api", "../logging:rtc_event_log_api",
"../logging:rtc_event_log_impl_base", "../logging:rtc_event_log_impl_base",
@ -140,6 +141,7 @@ rtc_static_library("libjingle_peerconnection_api") {
":callfactory_api", ":callfactory_api",
":fec_controller_api", ":fec_controller_api",
":libjingle_logging_api", ":libjingle_logging_api",
":network_state_predictor_api",
":rtc_stats_api", ":rtc_stats_api",
":scoped_refptr", ":scoped_refptr",
"audio:audio_mixer_api", "audio:audio_mixer_api",
@ -187,6 +189,7 @@ rtc_source_set("video_quality_test_fixture_api") {
deps = [ deps = [
":fec_controller_api", ":fec_controller_api",
":libjingle_peerconnection_api", ":libjingle_peerconnection_api",
":network_state_predictor_api",
":simulated_network_api", ":simulated_network_api",
"../call:fake_network", "../call:fake_network",
"../call:rtp_interfaces", "../call:rtp_interfaces",
@ -259,6 +262,7 @@ rtc_source_set("peer_connection_quality_test_fixture_api") {
":fec_controller_api", ":fec_controller_api",
":function_view", ":function_view",
":libjingle_peerconnection_api", ":libjingle_peerconnection_api",
":network_state_predictor_api",
":simulated_network_api", ":simulated_network_api",
":video_quality_analyzer_api", ":video_quality_analyzer_api",
"../logging:rtc_event_log_api", "../logging:rtc_event_log_api",
@ -296,6 +300,7 @@ if (rtc_include_tests) {
] ]
deps = [ deps = [
":fec_controller_api", ":fec_controller_api",
":network_state_predictor_api",
":scoped_refptr", ":scoped_refptr",
":video_quality_test_fixture_api", ":video_quality_test_fixture_api",
"../video:video_quality_test", "../video:video_quality_test",
@ -443,6 +448,13 @@ rtc_source_set("fec_controller_api") {
] ]
} }
rtc_source_set("network_state_predictor_api") {
visibility = [ "*" ]
sources = [
"network_state_predictor.h",
]
}
rtc_source_set("array_view") { rtc_source_set("array_view") {
visibility = [ "*" ] visibility = [ "*" ]
sources = [ sources = [

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 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.
*/
#ifndef API_NETWORK_STATE_PREDICTOR_H_
#define API_NETWORK_STATE_PREDICTOR_H_
#include <memory>
#include <vector>
namespace webrtc {
enum class BandwidthUsage {
kBwNormal = 0,
kBwUnderusing = 1,
kBwOverusing = 2,
kLast
};
// TODO(yinwa): work in progress. API in class NetworkStatePredictor should not
// be used by other users until this comment is removed.
// NetworkStatePredictor predict network state based on current network metrics.
// Usage:
// Setup by calling Initialize.
// For each update, call Update. Update returns network state
// prediction.
class NetworkStatePredictor {
public:
virtual ~NetworkStatePredictor() {}
// Returns current network state prediction.
// Inputs: send_time_ms - packet send time.
// arrival_time_ms - packet arrival time.
// network_state - computed network state.
virtual BandwidthUsage Update(int64_t send_time_ms,
int64_t arrival_time_ms,
BandwidthUsage network_state) = 0;
};
class NetworkStatePredictorFactoryInterface {
public:
virtual std::unique_ptr<NetworkStatePredictor>
CreateNetworkStatePredictor() = 0;
virtual ~NetworkStatePredictorFactoryInterface() = default;
};
} // namespace webrtc
#endif // API_NETWORK_STATE_PREDICTOR_H_

View file

@ -83,6 +83,7 @@
#include "api/jsep.h" #include "api/jsep.h"
#include "api/media_stream_interface.h" #include "api/media_stream_interface.h"
#include "api/media_transport_interface.h" #include "api/media_transport_interface.h"
#include "api/network_state_predictor.h"
#include "api/rtc_error.h" #include "api/rtc_error.h"
#include "api/rtc_event_log_output.h" #include "api/rtc_event_log_output.h"
#include "api/rtp_receiver_interface.h" #include "api/rtp_receiver_interface.h"
@ -1248,6 +1249,8 @@ struct PeerConnectionFactoryDependencies final {
std::unique_ptr<CallFactoryInterface> call_factory; std::unique_ptr<CallFactoryInterface> call_factory;
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory; std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory; std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
std::unique_ptr<NetworkStatePredictorFactoryInterface>
network_state_predictor_factory;
std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory; std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
std::unique_ptr<MediaTransportFactory> media_transport_factory; std::unique_ptr<MediaTransportFactory> media_transport_factory;
}; };
@ -1427,6 +1430,8 @@ CreateModularPeerConnectionFactory(
std::unique_ptr<CallFactoryInterface> call_factory, std::unique_ptr<CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory, std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
std::unique_ptr<NetworkStatePredictorFactoryInterface>
network_state_predictor_factory,
std::unique_ptr<NetworkControllerFactoryInterface> std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory = nullptr); network_controller_factory = nullptr);

View file

@ -78,6 +78,7 @@ rtc_static_library("goog_cc") {
deps = [ deps = [
":network_control", ":network_control",
":webrtc_key_value_config", ":webrtc_key_value_config",
"..:network_state_predictor_api",
"../../modules/congestion_controller/goog_cc", "../../modules/congestion_controller/goog_cc",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
] ]

View file

@ -18,11 +18,21 @@
namespace webrtc { namespace webrtc {
GoogCcNetworkControllerFactory::GoogCcNetworkControllerFactory( GoogCcNetworkControllerFactory::GoogCcNetworkControllerFactory(
RtcEventLog* event_log) RtcEventLog* event_log)
: event_log_(event_log) {} : event_log_(event_log), network_state_predictor_factory_(nullptr) {}
GoogCcNetworkControllerFactory::GoogCcNetworkControllerFactory(
RtcEventLog* event_log,
NetworkStatePredictorFactoryInterface* network_state_predictor_factory)
: event_log_(event_log),
network_state_predictor_factory_(network_state_predictor_factory) {}
std::unique_ptr<NetworkControllerInterface> std::unique_ptr<NetworkControllerInterface>
GoogCcNetworkControllerFactory::Create(NetworkControllerConfig config) { GoogCcNetworkControllerFactory::Create(NetworkControllerConfig config) {
return absl::make_unique<GoogCcNetworkController>(event_log_, config, false); return absl::make_unique<GoogCcNetworkController>(
event_log_, config, false,
network_state_predictor_factory_
? network_state_predictor_factory_->CreateNetworkStatePredictor()
: nullptr);
} }
TimeDelta GoogCcNetworkControllerFactory::GetProcessInterval() const { TimeDelta GoogCcNetworkControllerFactory::GetProcessInterval() const {
@ -36,7 +46,8 @@ GoogCcFeedbackNetworkControllerFactory::GoogCcFeedbackNetworkControllerFactory(
std::unique_ptr<NetworkControllerInterface> std::unique_ptr<NetworkControllerInterface>
GoogCcFeedbackNetworkControllerFactory::Create(NetworkControllerConfig config) { GoogCcFeedbackNetworkControllerFactory::Create(NetworkControllerConfig config) {
return absl::make_unique<GoogCcNetworkController>(event_log_, config, true); return absl::make_unique<GoogCcNetworkController>(event_log_, config, true,
nullptr);
} }
TimeDelta GoogCcFeedbackNetworkControllerFactory::GetProcessInterval() const { TimeDelta GoogCcFeedbackNetworkControllerFactory::GetProcessInterval() const {

View file

@ -12,6 +12,7 @@
#define API_TRANSPORT_GOOG_CC_FACTORY_H_ #define API_TRANSPORT_GOOG_CC_FACTORY_H_
#include <memory> #include <memory>
#include "api/network_state_predictor.h"
#include "api/transport/network_control.h" #include "api/transport/network_control.h"
namespace webrtc { namespace webrtc {
@ -20,13 +21,17 @@ class RtcEventLog;
class GoogCcNetworkControllerFactory class GoogCcNetworkControllerFactory
: public NetworkControllerFactoryInterface { : public NetworkControllerFactoryInterface {
public: public:
explicit GoogCcNetworkControllerFactory(RtcEventLog*); explicit GoogCcNetworkControllerFactory(RtcEventLog* event_log);
explicit GoogCcNetworkControllerFactory(
RtcEventLog* event_log,
NetworkStatePredictorFactoryInterface* network_state_predictor_factory);
std::unique_ptr<NetworkControllerInterface> Create( std::unique_ptr<NetworkControllerInterface> Create(
NetworkControllerConfig config) override; NetworkControllerConfig config) override;
TimeDelta GetProcessInterval() const override; TimeDelta GetProcessInterval() const override;
private: private:
RtcEventLog* const event_log_; RtcEventLog* const event_log_;
NetworkStatePredictorFactoryInterface* const network_state_predictor_factory_;
}; };
// Factory to create packet feedback only GoogCC, this can be used for // Factory to create packet feedback only GoogCC, this can be used for
@ -34,7 +39,7 @@ class GoogCcNetworkControllerFactory
class GoogCcFeedbackNetworkControllerFactory class GoogCcFeedbackNetworkControllerFactory
: public NetworkControllerFactoryInterface { : public NetworkControllerFactoryInterface {
public: public:
explicit GoogCcFeedbackNetworkControllerFactory(RtcEventLog*); explicit GoogCcFeedbackNetworkControllerFactory(RtcEventLog* event_log);
std::unique_ptr<NetworkControllerInterface> Create( std::unique_ptr<NetworkControllerInterface> Create(
NetworkControllerConfig config) override; NetworkControllerConfig config) override;
TimeDelta GetProcessInterval() const override; TimeDelta GetProcessInterval() const override;

View file

@ -125,7 +125,7 @@ TEST(AudioWithMediaTransport, DeliversAudio) {
std::unique_ptr<TaskQueueFactory> task_queue_factory = std::unique_ptr<TaskQueueFactory> task_queue_factory =
CreateDefaultTaskQueueFactory(); CreateDefaultTaskQueueFactory();
RtpTransportControllerSend rtp_transport( RtpTransportControllerSend rtp_transport(
Clock::GetRealTimeClock(), null_event_log.get(), nullptr, Clock::GetRealTimeClock(), null_event_log.get(), nullptr, nullptr,
BitrateConstraints(), ProcessThread::Create("Pacer"), BitrateConstraints(), ProcessThread::Create("Pacer"),
task_queue_factory.get()); task_queue_factory.get());
webrtc::internal::AudioSendStream send_stream( webrtc::internal::AudioSendStream send_stream(

View file

@ -32,6 +32,7 @@ rtc_source_set("call_interfaces") {
":video_stream_api", ":video_stream_api",
"../api:fec_controller_api", "../api:fec_controller_api",
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:network_state_predictor_api",
"../api:rtp_headers", "../api:rtp_headers",
"../api:scoped_refptr", "../api:scoped_refptr",
"../api:transport_api", "../api:transport_api",
@ -124,6 +125,7 @@ rtc_source_set("rtp_sender") {
":bitrate_configurator", ":bitrate_configurator",
":rtp_interfaces", ":rtp_interfaces",
"../api:fec_controller_api", "../api:fec_controller_api",
"../api:network_state_predictor_api",
"../api:transport_api", "../api:transport_api",
"../api/transport:field_trial_based_config", "../api/transport:field_trial_based_config",
"../api/transport:goog_cc", "../api/transport:goog_cc",

View file

@ -439,8 +439,9 @@ Call* Call::Create(const Call::Config& config,
return new internal::Call( return new internal::Call(
clock, config, clock, config,
absl::make_unique<RtpTransportControllerSend>( absl::make_unique<RtpTransportControllerSend>(
clock, config.event_log, config.network_controller_factory, clock, config.event_log, config.network_state_predictor_factory,
config.bitrate_config, std::move(pacer_thread), task_queue_factory), config.network_controller_factory, config.bitrate_config,
std::move(pacer_thread), task_queue_factory),
std::move(call_thread), task_queue_factory); std::move(call_thread), task_queue_factory);
} }

View file

@ -12,6 +12,7 @@
#include "api/bitrate_constraints.h" #include "api/bitrate_constraints.h"
#include "api/fec_controller.h" #include "api/fec_controller.h"
#include "api/network_state_predictor.h"
#include "api/rtc_error.h" #include "api/rtc_error.h"
#include "api/task_queue/task_queue_factory.h" #include "api/task_queue/task_queue_factory.h"
#include "api/transport/network_control.h" #include "api/transport/network_control.h"
@ -49,6 +50,10 @@ struct CallConfig {
// Task Queue Factory to be used in this call. // Task Queue Factory to be used in this call.
TaskQueueFactory* task_queue_factory = nullptr; TaskQueueFactory* task_queue_factory = nullptr;
// NetworkStatePredictor to use for this call.
NetworkStatePredictorFactoryInterface* network_state_predictor_factory =
nullptr;
// Network controller factory to use for this call. // Network controller factory to use for this call.
NetworkControllerFactoryInterface* network_controller_factory = nullptr; NetworkControllerFactoryInterface* network_controller_factory = nullptr;
}; };

View file

@ -58,6 +58,7 @@ TargetRateConstraints ConvertConstraints(const BitrateConstraints& contraints,
RtpTransportControllerSend::RtpTransportControllerSend( RtpTransportControllerSend::RtpTransportControllerSend(
Clock* clock, Clock* clock,
webrtc::RtcEventLog* event_log, webrtc::RtcEventLog* event_log,
NetworkStatePredictorFactoryInterface* predictor_factory,
NetworkControllerFactoryInterface* controller_factory, NetworkControllerFactoryInterface* controller_factory,
const BitrateConstraints& bitrate_config, const BitrateConstraints& bitrate_config,
std::unique_ptr<ProcessThread> process_thread, std::unique_ptr<ProcessThread> process_thread,
@ -69,7 +70,8 @@ RtpTransportControllerSend::RtpTransportControllerSend(
observer_(nullptr), observer_(nullptr),
controller_factory_override_(controller_factory), controller_factory_override_(controller_factory),
controller_factory_fallback_( controller_factory_fallback_(
absl::make_unique<GoogCcNetworkControllerFactory>(event_log)), absl::make_unique<GoogCcNetworkControllerFactory>(event_log,
predictor_factory)),
process_interval_(controller_factory_fallback_->GetProcessInterval()), process_interval_(controller_factory_fallback_->GetProcessInterval()),
last_report_block_time_(Timestamp::ms(clock_->TimeInMilliseconds())), last_report_block_time_(Timestamp::ms(clock_->TimeInMilliseconds())),
reset_feedback_on_route_change_( reset_feedback_on_route_change_(

View file

@ -17,6 +17,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/network_state_predictor.h"
#include "api/transport/network_control.h" #include "api/transport/network_control.h"
#include "call/rtp_bitrate_configurator.h" #include "call/rtp_bitrate_configurator.h"
#include "call/rtp_transport_controller_send_interface.h" #include "call/rtp_transport_controller_send_interface.h"
@ -47,6 +48,7 @@ class RtpTransportControllerSend final
RtpTransportControllerSend( RtpTransportControllerSend(
Clock* clock, Clock* clock,
RtcEventLog* event_log, RtcEventLog* event_log,
NetworkStatePredictorFactoryInterface* predictor_factory,
NetworkControllerFactoryInterface* controller_factory, NetworkControllerFactoryInterface* controller_factory,
const BitrateConstraints& bitrate_config, const BitrateConstraints& bitrate_config,
std::unique_ptr<ProcessThread> process_thread, std::unique_ptr<ProcessThread> process_thread,

View file

@ -83,6 +83,7 @@ class RtpVideoSenderTestFixture {
transport_controller_(&clock_, transport_controller_(&clock_,
&event_log_, &event_log_,
nullptr, nullptr,
nullptr,
bitrate_config_, bitrate_config_,
ProcessThread::Create("PacerThread"), ProcessThread::Create("PacerThread"),
&GlobalTaskQueueFactory()), &GlobalTaskQueueFactory()),

View file

@ -3,6 +3,7 @@ stefan@webrtc.org
terelius@webrtc.org terelius@webrtc.org
philipel@webrtc.org philipel@webrtc.org
mflodman@webrtc.org mflodman@webrtc.org
yinwa@webrtc.org
# These are for the common case of adding or renaming files. If you're doing # These are for the common case of adding or renaming files. If you're doing
# structural changes, please get a review from a reviewer in this file. # structural changes, please get a review from a reviewer in this file.

View file

@ -30,6 +30,8 @@ rtc_static_library("goog_cc") {
":probe_controller", ":probe_controller",
":pushback_controller", ":pushback_controller",
"../..:module_api", "../..:module_api",
"../../..:webrtc_common",
"../../../api:network_state_predictor_api",
"../../../api/transport:field_trial_based_config", "../../../api/transport:field_trial_based_config",
"../../../api/transport:network_control", "../../../api/transport:network_control",
"../../../api/transport:webrtc_key_value_config", "../../../api/transport:webrtc_key_value_config",
@ -116,6 +118,7 @@ rtc_source_set("estimators") {
] ]
deps = [ deps = [
"../../../api:network_state_predictor_api",
"../../../api/transport:webrtc_key_value_config", "../../../api/transport:webrtc_key_value_config",
"../../../api/units:data_rate", "../../../api/units:data_rate",
"../../../logging:rtc_event_bwe", "../../../logging:rtc_event_bwe",
@ -143,6 +146,7 @@ rtc_source_set("delay_based_bwe") {
deps = [ deps = [
":estimators", ":estimators",
"../../../api:network_state_predictor_api",
"../../../api/transport:network_control", "../../../api/transport:network_control",
"../../../api/transport:webrtc_key_value_config", "../../../api/transport:webrtc_key_value_config",
"../../../logging:rtc_event_bwe", "../../../logging:rtc_event_bwe",

View file

@ -83,7 +83,8 @@ DelayBasedBwe::Result::Result(bool probe, DataRate target_bitrate)
DelayBasedBwe::Result::~Result() {} DelayBasedBwe::Result::~Result() {}
DelayBasedBwe::DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config, DelayBasedBwe::DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config,
RtcEventLog* event_log) RtcEventLog* event_log,
NetworkStatePredictor* network_state_predictor)
: event_log_(event_log), : event_log_(event_log),
inter_arrival_(), inter_arrival_(),
delay_detector_(), delay_detector_(),
@ -100,13 +101,14 @@ DelayBasedBwe::DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config,
prev_state_(BandwidthUsage::kBwNormal), prev_state_(BandwidthUsage::kBwNormal),
alr_limited_backoff_enabled_( alr_limited_backoff_enabled_(
key_value_config->Lookup("WebRTC-Bwe-AlrLimitedBackoff") key_value_config->Lookup("WebRTC-Bwe-AlrLimitedBackoff")
.find("Enabled") == 0) { .find("Enabled") == 0),
network_state_predictor_(network_state_predictor) {
RTC_LOG(LS_INFO) RTC_LOG(LS_INFO)
<< "Using Trendline filter for delay change estimation with window size " << "Using Trendline filter for delay change estimation with window size "
<< trendline_window_size_; << trendline_window_size_;
delay_detector_.reset(new TrendlineEstimator(trendline_window_size_, delay_detector_.reset(new TrendlineEstimator(
trendline_smoothing_coeff_, trendline_window_size_, trendline_smoothing_coeff_,
trendline_threshold_gain_)); trendline_threshold_gain_, network_state_predictor_));
} }
DelayBasedBwe::~DelayBasedBwe() {} DelayBasedBwe::~DelayBasedBwe() {}
@ -169,9 +171,9 @@ void DelayBasedBwe::IncomingPacketFeedback(
inter_arrival_.reset( inter_arrival_.reset(
new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000,
kTimestampToMs, true)); kTimestampToMs, true));
delay_detector_.reset(new TrendlineEstimator(trendline_window_size_, delay_detector_.reset(new TrendlineEstimator(
trendline_smoothing_coeff_, trendline_window_size_, trendline_smoothing_coeff_,
trendline_threshold_gain_)); trendline_threshold_gain_, network_state_predictor_));
} }
last_seen_packet_ = at_time; last_seen_packet_ = at_time;
@ -189,13 +191,12 @@ void DelayBasedBwe::IncomingPacketFeedback(
uint32_t ts_delta = 0; uint32_t ts_delta = 0;
int64_t t_delta = 0; int64_t t_delta = 0;
int size_delta = 0; int size_delta = 0;
if (inter_arrival_->ComputeDeltas(timestamp, packet_feedback.arrival_time_ms, bool calculated_deltas = inter_arrival_->ComputeDeltas(
at_time.ms(), packet_feedback.payload_size, timestamp, packet_feedback.arrival_time_ms, at_time.ms(),
&ts_delta, &t_delta, &size_delta)) { packet_feedback.payload_size, &ts_delta, &t_delta, &size_delta);
double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift);
delay_detector_->Update(t_delta, ts_delta_ms, delay_detector_->Update(t_delta, ts_delta_ms, packet_feedback.send_time_ms,
packet_feedback.arrival_time_ms); packet_feedback.arrival_time_ms, calculated_deltas);
}
} }
DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate( DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(

View file

@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/network_state_predictor.h"
#include "api/transport/webrtc_key_value_config.h" #include "api/transport/webrtc_key_value_config.h"
#include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h" #include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h"
#include "modules/congestion_controller/goog_cc/probe_bitrate_estimator.h" #include "modules/congestion_controller/goog_cc/probe_bitrate_estimator.h"
@ -44,7 +45,8 @@ class DelayBasedBwe {
}; };
explicit DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config, explicit DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config,
RtcEventLog* event_log); RtcEventLog* event_log,
NetworkStatePredictor* network_state_predictor);
virtual ~DelayBasedBwe(); virtual ~DelayBasedBwe();
Result IncomingPacketFeedbackVector( Result IncomingPacketFeedbackVector(
@ -88,6 +90,7 @@ class DelayBasedBwe {
DataRate prev_bitrate_; DataRate prev_bitrate_;
BandwidthUsage prev_state_; BandwidthUsage prev_state_;
bool alr_limited_backoff_enabled_; bool alr_limited_backoff_enabled_;
NetworkStatePredictor* network_state_predictor_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
}; };

View file

@ -155,7 +155,8 @@ DelayBasedBweTest::DelayBasedBweTest()
absl::make_unique<AcknowledgedBitrateEstimator>( absl::make_unique<AcknowledgedBitrateEstimator>(
&field_trial_config_)), &field_trial_config_)),
probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)), probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)),
bitrate_estimator_(new DelayBasedBwe(&field_trial_config_, nullptr)), bitrate_estimator_(
new DelayBasedBwe(&field_trial_config_, nullptr, nullptr)),
stream_generator_(new test::StreamGenerator(1e6, // Capacity. stream_generator_(new test::StreamGenerator(1e6, // Capacity.
clock_.TimeInMicroseconds())), clock_.TimeInMicroseconds())),
arrival_time_offset_ms_(0), arrival_time_offset_ms_(0),
@ -169,7 +170,8 @@ DelayBasedBweTest::DelayBasedBweTest(const std::string& field_trial_string)
absl::make_unique<AcknowledgedBitrateEstimator>( absl::make_unique<AcknowledgedBitrateEstimator>(
&field_trial_config_)), &field_trial_config_)),
probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)), probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)),
bitrate_estimator_(new DelayBasedBwe(&field_trial_config_, nullptr)), bitrate_estimator_(
new DelayBasedBwe(&field_trial_config_, nullptr, nullptr)),
stream_generator_(new test::StreamGenerator(1e6, // Capacity. stream_generator_(new test::StreamGenerator(1e6, // Capacity.
clock_.TimeInMicroseconds())), clock_.TimeInMicroseconds())),
arrival_time_offset_ms_(0), arrival_time_offset_ms_(0),

View file

@ -26,7 +26,9 @@ class DelayIncreaseDetectorInterface {
// between timestamp groups as defined by the InterArrival class. // between timestamp groups as defined by the InterArrival class.
virtual void Update(double recv_delta_ms, virtual void Update(double recv_delta_ms,
double send_delta_ms, double send_delta_ms,
int64_t arrival_time_ms) = 0; int64_t send_time_ms,
int64_t arrival_time_ms,
bool calculated_deltas) = 0;
virtual BandwidthUsage State() const = 0; virtual BandwidthUsage State() const = 0;

View file

@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include <numeric> #include <numeric>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
@ -77,9 +78,11 @@ bool IsNotDisabled(const WebRtcKeyValueConfig* config, absl::string_view key) {
} }
} // namespace } // namespace
GoogCcNetworkController::GoogCcNetworkController(RtcEventLog* event_log, GoogCcNetworkController::GoogCcNetworkController(
NetworkControllerConfig config, RtcEventLog* event_log,
bool feedback_only) NetworkControllerConfig config,
bool feedback_only,
std::unique_ptr<NetworkStatePredictor> network_state_predictor)
: key_value_config_(config.key_value_config ? config.key_value_config : key_value_config_(config.key_value_config ? config.key_value_config
: &trial_based_config_), : &trial_based_config_),
event_log_(event_log), event_log_(event_log),
@ -104,7 +107,9 @@ GoogCcNetworkController::GoogCcNetworkController(RtcEventLog* event_log,
absl::make_unique<SendSideBandwidthEstimation>(event_log_)), absl::make_unique<SendSideBandwidthEstimation>(event_log_)),
alr_detector_(absl::make_unique<AlrDetector>()), alr_detector_(absl::make_unique<AlrDetector>()),
probe_bitrate_estimator_(new ProbeBitrateEstimator(event_log)), probe_bitrate_estimator_(new ProbeBitrateEstimator(event_log)),
delay_based_bwe_(new DelayBasedBwe(key_value_config_, event_log_)), delay_based_bwe_(new DelayBasedBwe(key_value_config_,
event_log_,
network_state_predictor.get())),
acknowledged_bitrate_estimator_( acknowledged_bitrate_estimator_(
absl::make_unique<AcknowledgedBitrateEstimator>(key_value_config_)), absl::make_unique<AcknowledgedBitrateEstimator>(key_value_config_)),
initial_config_(config), initial_config_(config),
@ -117,7 +122,8 @@ GoogCcNetworkController::GoogCcNetworkController(RtcEventLog* event_log,
DataRate::Zero())), DataRate::Zero())),
max_padding_rate_(config.stream_based_config.max_padding_rate.value_or( max_padding_rate_(config.stream_based_config.max_padding_rate.value_or(
DataRate::Zero())), DataRate::Zero())),
max_total_allocated_bitrate_(DataRate::Zero()) { max_total_allocated_bitrate_(DataRate::Zero()),
network_state_predictor_(std::move(network_state_predictor)) {
RTC_DCHECK(config.constraints.at_time.IsFinite()); RTC_DCHECK(config.constraints.at_time.IsFinite());
ParseFieldTrial( ParseFieldTrial(
{&safe_reset_on_route_change_, &safe_reset_acknowledged_rate_}, {&safe_reset_on_route_change_, &safe_reset_acknowledged_rate_},
@ -164,7 +170,8 @@ NetworkControlUpdate GoogCcNetworkController::OnNetworkRouteChange(
acknowledged_bitrate_estimator_.reset( acknowledged_bitrate_estimator_.reset(
new AcknowledgedBitrateEstimator(key_value_config_)); new AcknowledgedBitrateEstimator(key_value_config_));
probe_bitrate_estimator_.reset(new ProbeBitrateEstimator(event_log_)); probe_bitrate_estimator_.reset(new ProbeBitrateEstimator(event_log_));
delay_based_bwe_.reset(new DelayBasedBwe(key_value_config_, event_log_)); delay_based_bwe_.reset(new DelayBasedBwe(key_value_config_, event_log_,
network_state_predictor_.get()));
bandwidth_estimation_->OnRouteChange(); bandwidth_estimation_->OnRouteChange();
probe_controller_->Reset(msg.at_time.ms()); probe_controller_->Reset(msg.at_time.ms());
NetworkControlUpdate update; NetworkControlUpdate update;

View file

@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/network_state_predictor.h"
#include "api/transport/field_trial_based_config.h" #include "api/transport/field_trial_based_config.h"
#include "api/transport/network_control.h" #include "api/transport/network_control.h"
#include "api/transport/network_types.h" #include "api/transport/network_types.h"
@ -40,9 +41,11 @@ namespace webrtc {
class GoogCcNetworkController : public NetworkControllerInterface { class GoogCcNetworkController : public NetworkControllerInterface {
public: public:
GoogCcNetworkController(RtcEventLog* event_log, GoogCcNetworkController(
NetworkControllerConfig config, RtcEventLog* event_log,
bool feedback_only); NetworkControllerConfig config,
bool feedback_only,
std::unique_ptr<NetworkStatePredictor> network_state_predictor);
~GoogCcNetworkController() override; ~GoogCcNetworkController() override;
// NetworkControllerInterface // NetworkControllerInterface
@ -121,6 +124,8 @@ class GoogCcNetworkController : public NetworkControllerInterface {
absl::optional<DataSize> current_data_window_; absl::optional<DataSize> current_data_window_;
std::unique_ptr<NetworkStatePredictor> network_state_predictor_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GoogCcNetworkController); RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GoogCcNetworkController);
}; };

View file

@ -110,7 +110,7 @@ void UpdatesTargetRateBasedOnLinkCapacity(std::string test_name = "") {
class GoogCcNetworkControllerTest : public ::testing::Test { class GoogCcNetworkControllerTest : public ::testing::Test {
protected: protected:
GoogCcNetworkControllerTest() GoogCcNetworkControllerTest()
: current_time_(Timestamp::ms(123456)), factory_(&event_log_) {} : current_time_(Timestamp::ms(123456)), factory_(&event_log_, nullptr) {}
~GoogCcNetworkControllerTest() override {} ~GoogCcNetworkControllerTest() override {}
void SetUp() override { void SetUp() override {

View file

@ -60,7 +60,7 @@ NetworkControlUpdate GoogCcStatePrinter::GetState(Timestamp at_time) const {
GoogCcDebugFactory::GoogCcDebugFactory(RtcEventLog* event_log, GoogCcDebugFactory::GoogCcDebugFactory(RtcEventLog* event_log,
GoogCcStatePrinter* printer) GoogCcStatePrinter* printer)
: GoogCcNetworkControllerFactory(event_log), printer_(printer) {} : GoogCcNetworkControllerFactory(event_log, nullptr), printer_(printer) {}
std::unique_ptr<NetworkControllerInterface> GoogCcDebugFactory::Create( std::unique_ptr<NetworkControllerInterface> GoogCcDebugFactory::Create(
NetworkControllerConfig config) { NetworkControllerConfig config) {

View file

@ -15,6 +15,7 @@
#include <algorithm> #include <algorithm>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" #include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/numerics/safe_minmax.h" #include "rtc_base/numerics/safe_minmax.h"
@ -53,9 +54,11 @@ constexpr int kDeltaCounterMax = 1000;
} // namespace } // namespace
TrendlineEstimator::TrendlineEstimator(size_t window_size, TrendlineEstimator::TrendlineEstimator(
double smoothing_coef, size_t window_size,
double threshold_gain) double smoothing_coef,
double threshold_gain,
NetworkStatePredictor* network_state_predictor)
: window_size_(window_size), : window_size_(window_size),
smoothing_coef_(smoothing_coef), smoothing_coef_(smoothing_coef),
threshold_gain_(threshold_gain), threshold_gain_(threshold_gain),
@ -73,51 +76,61 @@ TrendlineEstimator::TrendlineEstimator(size_t window_size,
prev_trend_(0.0), prev_trend_(0.0),
time_over_using_(-1), time_over_using_(-1),
overuse_counter_(0), overuse_counter_(0),
hypothesis_(BandwidthUsage::kBwNormal) {} hypothesis_(BandwidthUsage::kBwNormal),
hypothesis_predicted_(BandwidthUsage::kBwNormal),
network_state_predictor_(network_state_predictor) {}
TrendlineEstimator::~TrendlineEstimator() {} TrendlineEstimator::~TrendlineEstimator() {}
void TrendlineEstimator::Update(double recv_delta_ms, void TrendlineEstimator::Update(double recv_delta_ms,
double send_delta_ms, double send_delta_ms,
int64_t arrival_time_ms) { int64_t send_time_ms,
const double delta_ms = recv_delta_ms - send_delta_ms; int64_t arrival_time_ms,
++num_of_deltas_; bool calculated_deltas) {
num_of_deltas_ = std::min(num_of_deltas_, kDeltaCounterMax); if (calculated_deltas) {
if (first_arrival_time_ms_ == -1) const double delta_ms = recv_delta_ms - send_delta_ms;
first_arrival_time_ms_ = arrival_time_ms; ++num_of_deltas_;
num_of_deltas_ = std::min(num_of_deltas_, kDeltaCounterMax);
if (first_arrival_time_ms_ == -1)
first_arrival_time_ms_ = arrival_time_ms;
// Exponential backoff filter. // Exponential backoff filter.
accumulated_delay_ += delta_ms; accumulated_delay_ += delta_ms;
BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", arrival_time_ms, BWE_TEST_LOGGING_PLOT(1, "accumulated_delay_ms", arrival_time_ms,
accumulated_delay_); accumulated_delay_);
smoothed_delay_ = smoothing_coef_ * smoothed_delay_ + smoothed_delay_ = smoothing_coef_ * smoothed_delay_ +
(1 - smoothing_coef_) * accumulated_delay_; (1 - smoothing_coef_) * accumulated_delay_;
BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", arrival_time_ms, BWE_TEST_LOGGING_PLOT(1, "smoothed_delay_ms", arrival_time_ms,
smoothed_delay_); smoothed_delay_);
// Simple linear regression. // Simple linear regression.
delay_hist_.push_back(std::make_pair( delay_hist_.push_back(std::make_pair(
static_cast<double>(arrival_time_ms - first_arrival_time_ms_), static_cast<double>(arrival_time_ms - first_arrival_time_ms_),
smoothed_delay_)); smoothed_delay_));
if (delay_hist_.size() > window_size_) if (delay_hist_.size() > window_size_)
delay_hist_.pop_front(); delay_hist_.pop_front();
double trend = prev_trend_; double trend = prev_trend_;
if (delay_hist_.size() == window_size_) { if (delay_hist_.size() == window_size_) {
// Update trend_ if it is possible to fit a line to the data. The delay // Update trend_ if it is possible to fit a line to the data. The delay
// trend can be seen as an estimate of (send_rate - capacity)/capacity. // trend can be seen as an estimate of (send_rate - capacity)/capacity.
// 0 < trend < 1 -> the delay increases, queues are filling up // 0 < trend < 1 -> the delay increases, queues are filling up
// trend == 0 -> the delay does not change // trend == 0 -> the delay does not change
// trend < 0 -> the delay decreases, queues are being emptied // trend < 0 -> the delay decreases, queues are being emptied
trend = LinearFitSlope(delay_hist_).value_or(trend); trend = LinearFitSlope(delay_hist_).value_or(trend);
}
BWE_TEST_LOGGING_PLOT(1, "trendline_slope", arrival_time_ms, trend);
Detect(trend, send_delta_ms, arrival_time_ms);
}
if (network_state_predictor_) {
hypothesis_predicted_ = network_state_predictor_->Update(
send_time_ms, arrival_time_ms, hypothesis_);
} }
BWE_TEST_LOGGING_PLOT(1, "trendline_slope", arrival_time_ms, trend);
Detect(trend, send_delta_ms, arrival_time_ms);
} }
BandwidthUsage TrendlineEstimator::State() const { BandwidthUsage TrendlineEstimator::State() const {
return hypothesis_; return network_state_predictor_ ? hypothesis_predicted_ : hypothesis_;
} }
void TrendlineEstimator::Detect(double trend, double ts_delta, int64_t now_ms) { void TrendlineEstimator::Detect(double trend, double ts_delta, int64_t now_ms) {

View file

@ -15,6 +15,7 @@
#include <deque> #include <deque>
#include <utility> #include <utility>
#include "api/network_state_predictor.h"
#include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h" #include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h"
#include "modules/remote_bitrate_estimator/include/bwe_defines.h" #include "modules/remote_bitrate_estimator/include/bwe_defines.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
@ -28,10 +29,12 @@ class TrendlineEstimator : public DelayIncreaseDetectorInterface {
// the trend line. |threshold_gain| is used to scale the trendline slope for // the trend line. |threshold_gain| is used to scale the trendline slope for
// comparison to the old threshold. Once the old estimator has been removed // comparison to the old threshold. Once the old estimator has been removed
// (or the thresholds been merged into the estimators), we can just set the // (or the thresholds been merged into the estimators), we can just set the
// threshold instead of setting a gain. // threshold instead of setting a gain.|network_state_predictor| is used to
// bettter predict network state.
TrendlineEstimator(size_t window_size, TrendlineEstimator(size_t window_size,
double smoothing_coef, double smoothing_coef,
double threshold_gain); double threshold_gain,
NetworkStatePredictor* network_state_predictor);
~TrendlineEstimator() override; ~TrendlineEstimator() override;
@ -39,7 +42,9 @@ class TrendlineEstimator : public DelayIncreaseDetectorInterface {
// between timestamp groups as defined by the InterArrival class. // between timestamp groups as defined by the InterArrival class.
void Update(double recv_delta_ms, void Update(double recv_delta_ms,
double send_delta_ms, double send_delta_ms,
int64_t arrival_time_ms) override; int64_t send_time_ms,
int64_t arrival_time_ms,
bool calculated_deltas) override;
BandwidthUsage State() const override; BandwidthUsage State() const override;
@ -78,6 +83,8 @@ class TrendlineEstimator : public DelayIncreaseDetectorInterface {
double time_over_using_; double time_over_using_;
int overuse_counter_; int overuse_counter_;
BandwidthUsage hypothesis_; BandwidthUsage hypothesis_;
BandwidthUsage hypothesis_predicted_;
NetworkStatePredictor* network_state_predictor_;
RTC_DISALLOW_COPY_AND_ASSIGN(TrendlineEstimator); RTC_DISALLOW_COPY_AND_ASSIGN(TrendlineEstimator);
}; };

View file

@ -26,7 +26,7 @@ class TrendlineEstimatorForTest : public TrendlineEstimator {
using TrendlineEstimator::modified_trend; using TrendlineEstimator::modified_trend;
}; };
void TestEstimator(double slope, double jitter_stddev, double tolerance) { void TestEstimator(double slope, double jitter_stddev, double tolerance) {
TrendlineEstimatorForTest estimator(kWindowSize, kSmoothing, kGain); TrendlineEstimatorForTest estimator(kWindowSize, kSmoothing, kGain, nullptr);
Random random(0x1234567); Random random(0x1234567);
int64_t send_times[kPacketCount]; int64_t send_times[kPacketCount];
int64_t recv_times[kPacketCount]; int64_t recv_times[kPacketCount];
@ -41,7 +41,7 @@ void TestEstimator(double slope, double jitter_stddev, double tolerance) {
for (size_t i = 1; i < kPacketCount; ++i) { for (size_t i = 1; i < kPacketCount; ++i) {
double recv_delta = recv_times[i] - recv_times[i - 1]; double recv_delta = recv_times[i] - recv_times[i - 1];
double send_delta = send_times[i] - send_times[i - 1]; double send_delta = send_times[i] - send_times[i - 1];
estimator.Update(recv_delta, send_delta, recv_times[i]); estimator.Update(recv_delta, send_delta, 0, recv_times[i], true);
if (i < kWindowSize) if (i < kWindowSize)
EXPECT_NEAR(estimator.modified_trend(), 0, 0.001); EXPECT_NEAR(estimator.modified_trend(), 0, 0.001);
else else

View file

@ -104,7 +104,8 @@ DEPRECATED_SendSideCongestionController::
pacer_paused_(false), pacer_paused_(false),
min_bitrate_bps_(congestion_controller::GetMinBitrateBps()), min_bitrate_bps_(congestion_controller::GetMinBitrateBps()),
probe_bitrate_estimator_(new ProbeBitrateEstimator(event_log_)), probe_bitrate_estimator_(new ProbeBitrateEstimator(event_log_)),
delay_based_bwe_(new DelayBasedBwe(key_value_config_, event_log_)), delay_based_bwe_(
new DelayBasedBwe(key_value_config_, event_log_, nullptr)),
was_in_alr_(false), was_in_alr_(false),
send_side_bwe_with_overhead_( send_side_bwe_with_overhead_(
key_value_config_->Lookup("WebRTC-SendSideBwe-WithOverhead") key_value_config_->Lookup("WebRTC-SendSideBwe-WithOverhead")
@ -235,7 +236,8 @@ void DEPRECATED_SendSideCongestionController::OnNetworkRouteChanged(
transport_overhead_bytes_per_packet_ = network_route.packet_overhead; transport_overhead_bytes_per_packet_ = network_route.packet_overhead;
min_bitrate_bps_ = min_bitrate_bps; min_bitrate_bps_ = min_bitrate_bps;
probe_bitrate_estimator_.reset(new ProbeBitrateEstimator(event_log_)); probe_bitrate_estimator_.reset(new ProbeBitrateEstimator(event_log_));
delay_based_bwe_.reset(new DelayBasedBwe(key_value_config_, event_log_)); delay_based_bwe_.reset(
new DelayBasedBwe(key_value_config_, event_log_, nullptr));
acknowledged_bitrate_estimator_.reset( acknowledged_bitrate_estimator_.reset(
new AcknowledgedBitrateEstimator(key_value_config_)); new AcknowledgedBitrateEstimator(key_value_config_));
if (bitrate_bps > 0) { if (bitrate_bps > 0) {

View file

@ -41,6 +41,7 @@ rtc_static_library("remote_bitrate_estimator") {
deps = [ deps = [
"../..:webrtc_common", "../..:webrtc_common",
"../../api:network_state_predictor_api",
"../../api:rtp_headers", "../../api:rtp_headers",
"../../api/units:data_rate", "../../api/units:data_rate",
"../../api/units:timestamp", "../../api/units:timestamp",

View file

@ -14,6 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/network_state_predictor.h"
#include "api/units/data_rate.h" #include "api/units/data_rate.h"
#define BWE_MAX(a, b) ((a) > (b) ? (a) : (b)) #define BWE_MAX(a, b) ((a) > (b) ? (a) : (b))
@ -38,13 +39,6 @@ enum BweNames {
kBweNamesMax = 4 kBweNamesMax = 4
}; };
enum class BandwidthUsage {
kBwNormal = 0,
kBwUnderusing = 1,
kBwOverusing = 2,
kLast
};
enum RateControlState { kRcHold, kRcIncrease, kRcDecrease }; enum RateControlState { kRcHold, kRcIncrease, kRcDecrease };
struct RateControlInput { struct RateControlInput {

View file

@ -38,7 +38,7 @@ SendSideBweSender::SendSideBweSender(int kbps,
absl::make_unique<AcknowledgedBitrateEstimator>( absl::make_unique<AcknowledgedBitrateEstimator>(
&field_trial_config_)), &field_trial_config_)),
probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)), probe_bitrate_estimator_(new ProbeBitrateEstimator(nullptr)),
bwe_(new DelayBasedBwe(&field_trial_config_, nullptr)), bwe_(new DelayBasedBwe(&field_trial_config_, nullptr, nullptr)),
feedback_observer_(bitrate_controller_.get()), feedback_observer_(bitrate_controller_.get()),
clock_(clock), clock_(clock),
send_time_history_(10000), send_time_history_(10000),

View file

@ -196,6 +196,7 @@ rtc_static_library("peerconnection") {
"../api:call_api", "../api:call_api",
"../api:fec_controller_api", "../api:fec_controller_api",
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:network_state_predictor_api",
"../api:rtc_stats_api", "../api:rtc_stats_api",
"../api:scoped_refptr", "../api:scoped_refptr",
"../api/task_queue", "../api/task_queue",

View file

@ -10,6 +10,7 @@
#include "pc/peer_connection_factory.h" #include "pc/peer_connection_factory.h"
#include <memory>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -18,6 +19,7 @@
#include "api/media_stream_proxy.h" #include "api/media_stream_proxy.h"
#include "api/media_stream_track_proxy.h" #include "api/media_stream_track_proxy.h"
#include "api/media_transport_interface.h" #include "api/media_transport_interface.h"
#include "api/network_state_predictor.h"
#include "api/peer_connection_factory_proxy.h" #include "api/peer_connection_factory_proxy.h"
#include "api/peer_connection_proxy.h" #include "api/peer_connection_proxy.h"
#include "api/turn_customizer.h" #include "api/turn_customizer.h"
@ -25,16 +27,16 @@
#include "logging/rtc_event_log/rtc_event_log.h" #include "logging/rtc_event_log/rtc_event_log.h"
#include "media/base/rtp_data_engine.h" #include "media/base/rtp_data_engine.h"
#include "media/sctp/sctp_transport.h" #include "media/sctp/sctp_transport.h"
#include "pc/rtp_parameters_conversion.h"
#include "rtc_base/bind.h"
#include "rtc_base/checks.h"
#include "p2p/base/basic_packet_socket_factory.h" #include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/client/basic_port_allocator.h" #include "p2p/client/basic_port_allocator.h"
#include "pc/audio_track.h" #include "pc/audio_track.h"
#include "pc/local_audio_source.h" #include "pc/local_audio_source.h"
#include "pc/media_stream.h" #include "pc/media_stream.h"
#include "pc/peer_connection.h" #include "pc/peer_connection.h"
#include "pc/rtp_parameters_conversion.h"
#include "pc/video_track.h" #include "pc/video_track.h"
#include "rtc_base/bind.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
namespace webrtc { namespace webrtc {
@ -66,6 +68,8 @@ CreateModularPeerConnectionFactory(
std::unique_ptr<CallFactoryInterface> call_factory, std::unique_ptr<CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory, std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
std::unique_ptr<NetworkStatePredictorFactoryInterface>
network_state_predictor_factory,
std::unique_ptr<NetworkControllerFactoryInterface> std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory) { network_controller_factory) {
PeerConnectionFactoryDependencies dependencies; PeerConnectionFactoryDependencies dependencies;
@ -76,6 +80,8 @@ CreateModularPeerConnectionFactory(
dependencies.call_factory = std::move(call_factory); dependencies.call_factory = std::move(call_factory);
dependencies.event_log_factory = std::move(event_log_factory); dependencies.event_log_factory = std::move(event_log_factory);
dependencies.fec_controller_factory = std::move(fec_controller_factory); dependencies.fec_controller_factory = std::move(fec_controller_factory);
dependencies.network_state_predictor_factory =
std::move(network_state_predictor_factory);
dependencies.network_controller_factory = dependencies.network_controller_factory =
std::move(network_controller_factory); std::move(network_controller_factory);
return CreateModularPeerConnectionFactory(std::move(dependencies)); return CreateModularPeerConnectionFactory(std::move(dependencies));
@ -111,6 +117,8 @@ PeerConnectionFactory::PeerConnectionFactory(
call_factory_(std::move(dependencies.call_factory)), call_factory_(std::move(dependencies.call_factory)),
event_log_factory_(std::move(dependencies.event_log_factory)), event_log_factory_(std::move(dependencies.event_log_factory)),
fec_controller_factory_(std::move(dependencies.fec_controller_factory)), fec_controller_factory_(std::move(dependencies.fec_controller_factory)),
network_state_predictor_factory_(
std::move(dependencies.network_state_predictor_factory)),
injected_network_controller_factory_( injected_network_controller_factory_(
std::move(dependencies.network_controller_factory)), std::move(dependencies.network_controller_factory)),
media_transport_factory_( media_transport_factory_(
@ -388,6 +396,8 @@ std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
call_config.fec_controller_factory = fec_controller_factory_.get(); call_config.fec_controller_factory = fec_controller_factory_.get();
call_config.task_queue_factory = task_queue_factory_.get(); call_config.task_queue_factory = task_queue_factory_.get();
call_config.network_state_predictor_factory =
network_state_predictor_factory_.get();
if (field_trial::IsEnabled("WebRTC-Bwe-InjectedCongestionController")) { if (field_trial::IsEnabled("WebRTC-Bwe-InjectedCongestionController")) {
RTC_LOG(LS_INFO) << "Using injected network controller factory"; RTC_LOG(LS_INFO) << "Using injected network controller factory";

View file

@ -122,6 +122,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
std::unique_ptr<webrtc::CallFactoryInterface> call_factory_; std::unique_ptr<webrtc::CallFactoryInterface> call_factory_;
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_; std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_;
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_; std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
std::unique_ptr<NetworkStatePredictorFactoryInterface>
network_state_predictor_factory_;
std::unique_ptr<NetworkControllerFactoryInterface> std::unique_ptr<NetworkControllerFactoryInterface>
injected_network_controller_factory_; injected_network_controller_factory_;
std::unique_ptr<MediaTransportFactory> media_transport_factory_; std::unique_ptr<MediaTransportFactory> media_transport_factory_;

View file

@ -295,6 +295,7 @@ if (is_android) {
"api/org/webrtc/DataChannel.java", "api/org/webrtc/DataChannel.java",
"api/org/webrtc/DtmfSender.java", "api/org/webrtc/DtmfSender.java",
"api/org/webrtc/FecControllerFactoryFactoryInterface.java", "api/org/webrtc/FecControllerFactoryFactoryInterface.java",
"api/org/webrtc/NetworkStatePredictorFactoryFactory.java",
"api/org/webrtc/MediaTransportFactoryFactory.java", "api/org/webrtc/MediaTransportFactoryFactory.java",
"api/org/webrtc/FrameDecryptor.java", "api/org/webrtc/FrameDecryptor.java",
"api/org/webrtc/FrameEncryptor.java", "api/org/webrtc/FrameEncryptor.java",

View file

@ -0,0 +1,20 @@
/*
* Copyright 2019 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.
*/
package org.webrtc;
/** Factory for creating webrtc::NetworkStatePredictorFactory instances. */
public interface NetworkStatePredictorFactoryFactory {
/**
* Dynamically allocates a webrtc::NetworkStatePredictorFactory instance and returns a pointer to
* it. The caller takes ownership of the object.
*/
public long createNativeNetworkStatePredictorFactory();
}

View file

@ -173,6 +173,7 @@ public class PeerConnectionFactory {
@Nullable private VideoDecoderFactory videoDecoderFactory; @Nullable private VideoDecoderFactory videoDecoderFactory;
@Nullable private AudioProcessingFactory audioProcessingFactory; @Nullable private AudioProcessingFactory audioProcessingFactory;
@Nullable private FecControllerFactoryFactoryInterface fecControllerFactoryFactory; @Nullable private FecControllerFactoryFactoryInterface fecControllerFactoryFactory;
@Nullable private NetworkStatePredictorFactoryFactory networkStatePredictorFactoryFactory;
@Nullable private MediaTransportFactoryFactory mediaTransportFactoryFactory; @Nullable private MediaTransportFactoryFactory mediaTransportFactoryFactory;
private Builder() {} private Builder() {}
@ -232,6 +233,12 @@ public class PeerConnectionFactory {
return this; return this;
} }
public Builder NetworkStatePredictorFactoryFactory(
NetworkStatePredictorFactoryFactory networkStatePredictorFactoryFactory) {
this.networkStatePredictorFactoryFactory = networkStatePredictorFactoryFactory;
return this;
}
/** Sets a MediaTransportFactoryFactory for a PeerConnectionFactory. */ /** Sets a MediaTransportFactoryFactory for a PeerConnectionFactory. */
public Builder setMediaTransportFactoryFactory( public Builder setMediaTransportFactoryFactory(
MediaTransportFactoryFactory mediaTransportFactoryFactory) { MediaTransportFactoryFactory mediaTransportFactoryFactory) {
@ -252,6 +259,9 @@ public class PeerConnectionFactory {
videoDecoderFactory, videoDecoderFactory,
audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(), audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(),
fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative(), fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative(),
networkStatePredictorFactoryFactory == null
? 0
: networkStatePredictorFactoryFactory.createNativeNetworkStatePredictorFactory(),
mediaTransportFactoryFactory == null mediaTransportFactoryFactory == null
? 0 ? 0
: mediaTransportFactoryFactory.createNativeMediaTransportFactory()); : mediaTransportFactoryFactory.createNativeMediaTransportFactory());
@ -575,7 +585,8 @@ public class PeerConnectionFactory {
Options options, long nativeAudioDeviceModule, long audioEncoderFactory, Options options, long nativeAudioDeviceModule, long audioEncoderFactory,
long audioDecoderFactory, VideoEncoderFactory encoderFactory, long audioDecoderFactory, VideoEncoderFactory encoderFactory,
VideoDecoderFactory decoderFactory, long nativeAudioProcessor, VideoDecoderFactory decoderFactory, long nativeAudioProcessor,
long nativeFecControllerFactory, long mediaTransportFactory); long nativeFecControllerFactory, long nativeNetworkStatePredictorFactory,
long mediaTransportFactory);
private static native long nativeCreatePeerConnection(long factory, private static native long nativeCreatePeerConnection(long factory,
PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, long nativeObserver, PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, long nativeObserver,

View file

@ -240,7 +240,8 @@ static void JNI_PeerConnectionFactory_ShutdownInternalTracer(JNIEnv* jni) {
// Following parameters are optional: // Following parameters are optional:
// |audio_device_module|, |jencoder_factory|, |jdecoder_factory|, // |audio_device_module|, |jencoder_factory|, |jdecoder_factory|,
// |audio_processor|, |media_transport_factory|, |fec_controller_factory|. // |audio_processor|, |media_transport_factory|, |fec_controller_factory|,
// |network_state_predictor_factory|.
ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava( ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
JNIEnv* jni, JNIEnv* jni,
const JavaParamRef<jobject>& jcontext, const JavaParamRef<jobject>& jcontext,
@ -252,6 +253,8 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
const JavaParamRef<jobject>& jdecoder_factory, const JavaParamRef<jobject>& jdecoder_factory,
rtc::scoped_refptr<AudioProcessing> audio_processor, rtc::scoped_refptr<AudioProcessing> audio_processor,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
std::unique_ptr<NetworkStatePredictorFactoryInterface>
network_state_predictor_factory,
std::unique_ptr<MediaTransportFactory> media_transport_factory) { std::unique_ptr<MediaTransportFactory> media_transport_factory) {
// talk/ assumes pretty widely that the current Thread is ThreadManager'd, but // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
// ThreadManager only WrapCurrentThread()s the thread where it is first // ThreadManager only WrapCurrentThread()s the thread where it is first
@ -305,6 +308,8 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
dependencies.call_factory = std::move(call_factory); dependencies.call_factory = std::move(call_factory);
dependencies.event_log_factory = std::move(rtc_event_log_factory); dependencies.event_log_factory = std::move(rtc_event_log_factory);
dependencies.fec_controller_factory = std::move(fec_controller_factory); dependencies.fec_controller_factory = std::move(fec_controller_factory);
dependencies.network_state_predictor_factory =
std::move(network_state_predictor_factory);
dependencies.media_transport_factory = std::move(media_transport_factory); dependencies.media_transport_factory = std::move(media_transport_factory);
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
@ -334,6 +339,7 @@ JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
const JavaParamRef<jobject>& jdecoder_factory, const JavaParamRef<jobject>& jdecoder_factory,
jlong native_audio_processor, jlong native_audio_processor,
jlong native_fec_controller_factory, jlong native_fec_controller_factory,
jlong native_network_state_predictor_factory,
jlong native_media_transport_factory) { jlong native_media_transport_factory) {
rtc::scoped_refptr<AudioProcessing> audio_processor = rtc::scoped_refptr<AudioProcessing> audio_processor =
reinterpret_cast<AudioProcessing*>(native_audio_processor); reinterpret_cast<AudioProcessing*>(native_audio_processor);
@ -346,6 +352,8 @@ JNI_PeerConnectionFactory_CreatePeerConnectionFactory(
audio_processor ? audio_processor : CreateAudioProcessing(), audio_processor ? audio_processor : CreateAudioProcessing(),
TakeOwnershipOfUniquePtr<FecControllerFactoryInterface>( TakeOwnershipOfUniquePtr<FecControllerFactoryInterface>(
native_fec_controller_factory), native_fec_controller_factory),
TakeOwnershipOfUniquePtr<NetworkStatePredictorFactoryInterface>(
native_network_state_predictor_factory),
TakeOwnershipOfUniquePtr<MediaTransportFactory>( TakeOwnershipOfUniquePtr<MediaTransportFactory>(
native_media_transport_factory)); native_media_transport_factory));
} }