This will allow me to test that Call invokes SendSideCongestionController::SetBweBitrates as expected (for https://codereview.chromium.org/2793913008).
FakeRtpTransportController moves to a common header and its constructor is changed to take a SendSideCongestionController to enable injecting the mock.
BUG=webrtc:7395
Review-Url: https://codereview.webrtc.org/2834663003
Cr-Commit-Position: refs/heads/master@{#18055}
diff --git a/webrtc/call/BUILD.gn b/webrtc/call/BUILD.gn
index 826ef65..da94de5 100644
--- a/webrtc/call/BUILD.gn
+++ b/webrtc/call/BUILD.gn
@@ -93,6 +93,7 @@
"../modules/audio_device:mock_audio_device",
"../modules/audio_mixer",
"../modules/bitrate_controller",
+ "../modules/congestion_controller:mock_congestion_controller",
"../modules/pacing",
"../modules/rtp_rtcp",
"../system_wrappers",
diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc
index 0e64269..e594dcc 100644
--- a/webrtc/call/call.cc
+++ b/webrtc/call/call.cc
@@ -26,6 +26,7 @@
#include "webrtc/base/location.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/optional.h"
+#include "webrtc/base/ptr_util.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/base/thread_checker.h"
@@ -97,7 +98,7 @@
public BitrateAllocator::LimitObserver {
public:
Call(const Call::Config& config,
- std::unique_ptr<RtpTransportControllerSend> transport_send);
+ std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
virtual ~Call();
// Implements webrtc::Call.
@@ -298,16 +299,21 @@
}
Call* Call::Create(const Call::Config& config) {
- return new internal::Call(
- config, std::unique_ptr<RtpTransportControllerSend>(
- new RtpTransportControllerSend(Clock::GetRealTimeClock(),
- config.event_log)));
+ return new internal::Call(config,
+ rtc::MakeUnique<RtpTransportControllerSend>(
+ Clock::GetRealTimeClock(), config.event_log));
+}
+
+Call* Call::Create(
+ const Call::Config& config,
+ std::unique_ptr<RtpTransportControllerSendInterface> transport_send) {
+ return new internal::Call(config, std::move(transport_send));
}
namespace internal {
Call::Call(const Call::Config& config,
- std::unique_ptr<RtpTransportControllerSend> transport_send)
+ std::unique_ptr<RtpTransportControllerSendInterface> transport_send)
: clock_(Clock::GetRealTimeClock()),
num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
@@ -342,7 +348,7 @@
config.bitrate_config.start_bitrate_bps);
}
Trace::CreateTrace();
- transport_send->RegisterNetworkObserver(this);
+ transport_send->send_side_cc()->RegisterNetworkObserver(this);
transport_send_ = std::move(transport_send);
transport_send_->send_side_cc()->SignalNetworkState(kNetworkDown);
transport_send_->send_side_cc()->SetBweBitrates(
diff --git a/webrtc/call/call.h b/webrtc/call/call.h
index caf0ee2..f67b690 100644
--- a/webrtc/call/call.h
+++ b/webrtc/call/call.h
@@ -10,6 +10,7 @@
#ifndef WEBRTC_CALL_CALL_H_
#define WEBRTC_CALL_CALL_H_
+#include <memory>
#include <string>
#include <vector>
@@ -20,6 +21,7 @@
#include "webrtc/call/audio_send_stream.h"
#include "webrtc/call/audio_state.h"
#include "webrtc/call/flexfec_receive_stream.h"
+#include "webrtc/call/rtp_transport_controller_send_interface.h"
#include "webrtc/common_types.h"
#include "webrtc/video_receive_stream.h"
#include "webrtc/video_send_stream.h"
@@ -98,6 +100,11 @@
static Call* Create(const Call::Config& config);
+ // Allows mocking |transport_send| for testing.
+ static Call* Create(
+ const Call::Config& config,
+ std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
+
virtual AudioSendStream* CreateAudioSendStream(
const AudioSendStream::Config& config) = 0;
virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
diff --git a/webrtc/call/call_unittest.cc b/webrtc/call/call_unittest.cc
index 27d2329..564f6bd 100644
--- a/webrtc/call/call_unittest.cc
+++ b/webrtc/call/call_unittest.cc
@@ -11,11 +11,15 @@
#include <list>
#include <map>
#include <memory>
+#include <utility>
+#include "webrtc/base/ptr_util.h"
#include "webrtc/call/audio_state.h"
#include "webrtc/call/call.h"
+#include "webrtc/call/fake_rtp_transport_controller_send.h"
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
+#include "webrtc/modules/congestion_controller/include/mock/mock_send_side_congestion_controller.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/mock_audio_decoder_factory.h"
#include "webrtc/test/mock_transport.h"
@@ -305,4 +309,28 @@
}
}
+// TODO(zstein): This is just a motivating example for
+// MockSendSideCongestionController. It should be deleted once we have more
+// meaningful tests.
+TEST(CallTest, MockSendSideCongestionControllerExample) {
+ RtcEventLogNullImpl event_log;
+ Call::Config config(&event_log);
+
+ SimulatedClock clock(123456);
+ PacketRouter packet_router;
+ testing::NiceMock<test::MockSendSideCongestionController> mock_cc(
+ &clock, &event_log, &packet_router);
+ auto transport_send =
+ rtc::MakeUnique<FakeRtpTransportControllerSend>(&mock_cc);
+ std::unique_ptr<Call> call(Call::Create(config, std::move(transport_send)));
+
+ Call::Config::BitrateConfig bitrate_config;
+ bitrate_config.min_bitrate_bps = 1;
+ bitrate_config.start_bitrate_bps = 2;
+ bitrate_config.max_bitrate_bps = 3;
+
+ EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3));
+ call->SetBitrateConfig(bitrate_config);
+}
+
} // namespace webrtc
diff --git a/webrtc/call/fake_rtp_transport_controller_send.h b/webrtc/call/fake_rtp_transport_controller_send.h
new file mode 100644
index 0000000..42462d9
--- /dev/null
+++ b/webrtc/call/fake_rtp_transport_controller_send.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 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 WEBRTC_CALL_FAKE_RTP_TRANSPORT_CONTROLLER_SEND_H_
+#define WEBRTC_CALL_FAKE_RTP_TRANSPORT_CONTROLLER_SEND_H_
+
+#include "webrtc/call/rtp_transport_controller_send_interface.h"
+#include "webrtc/modules/congestion_controller/include/send_side_congestion_controller.h"
+#include "webrtc/modules/pacing/packet_router.h"
+
+namespace webrtc {
+
+class FakeRtpTransportControllerSend
+ : public RtpTransportControllerSendInterface {
+ public:
+ explicit FakeRtpTransportControllerSend(
+ SendSideCongestionController* send_side_cc)
+ : send_side_cc_(send_side_cc) {
+ RTC_DCHECK(send_side_cc);
+ }
+
+ PacketRouter* packet_router() override { return &packet_router_; }
+
+ SendSideCongestionController* send_side_cc() override {
+ return send_side_cc_;
+ }
+
+ TransportFeedbackObserver* transport_feedback_observer() override {
+ return send_side_cc_;
+ }
+
+ RtpPacketSender* packet_sender() override { return send_side_cc_->pacer(); }
+
+ private:
+ PacketRouter packet_router_;
+ SendSideCongestionController* send_side_cc_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_CALL_FAKE_RTP_TRANSPORT_CONTROLLER_SEND_H_
diff --git a/webrtc/call/rtp_transport_controller_send.cc b/webrtc/call/rtp_transport_controller_send.cc
index a006f28..1040218 100644
--- a/webrtc/call/rtp_transport_controller_send.cc
+++ b/webrtc/call/rtp_transport_controller_send.cc
@@ -18,10 +18,4 @@
: send_side_cc_(clock, nullptr /* observer */, event_log, &packet_router_) {
}
-void RtpTransportControllerSend::RegisterNetworkObserver(
- SendSideCongestionController::Observer* observer) {
- // Must be called only once.
- send_side_cc_.RegisterNetworkObserver(observer);
-}
-
} // namespace webrtc
diff --git a/webrtc/call/rtp_transport_controller_send.h b/webrtc/call/rtp_transport_controller_send.h
index 2bbb547..b626fa8 100644
--- a/webrtc/call/rtp_transport_controller_send.h
+++ b/webrtc/call/rtp_transport_controller_send.h
@@ -26,9 +26,6 @@
public:
RtpTransportControllerSend(Clock* clock, webrtc::RtcEventLog* event_log);
- void RegisterNetworkObserver(
- SendSideCongestionController::Observer* observer);
-
// Implements RtpTransportControllerSendInterface
PacketRouter* packet_router() override { return &packet_router_; }
SendSideCongestionController* send_side_cc() override {