Index: webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl_unittest.cc |
diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl_unittest.cc b/webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl_unittest.cc |
index 65626743adb3a59149b9e856766f7941d0bd9bcc..aee41da1b0b5c0523bf853ba483964a5ae488281 100644 |
--- a/webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl_unittest.cc |
+++ b/webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl_unittest.cc |
@@ -15,20 +15,25 @@ |
#include "webrtc/modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl.h" |
#include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller.h" |
#include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_controller_manager.h" |
+#include "webrtc/modules/audio_coding/audio_network_adaptor/mock/mock_debug_dump_writer.h" |
namespace webrtc { |
using ::testing::_; |
using ::testing::NiceMock; |
using ::testing::Return; |
+using ::testing::SetArgPointee; |
namespace { |
constexpr size_t kNumControllers = 2; |
+constexpr int64_t kClockInitialTimeMs = 12345678; |
+ |
MATCHER_P(NetworkMetricsIs, metric, "") { |
return arg.uplink_bandwidth_bps == metric.uplink_bandwidth_bps && |
arg.target_audio_bitrate_bps == metric.target_audio_bitrate_bps && |
+ arg.rtt_ms == metric.rtt_ms && |
arg.uplink_packet_loss_fraction == metric.uplink_packet_loss_fraction; |
} |
@@ -39,9 +44,21 @@ MATCHER_P(ConstraintsReceiverFrameLengthRangeIs, frame_length_range, "") { |
frame_length_range.max_frame_length_ms; |
} |
+MATCHER_P(EncoderRuntimeConfigIs, config, "") { |
+ return arg.bitrate_bps == config.bitrate_bps && |
+ arg.frame_length_ms == config.frame_length_ms && |
+ arg.uplink_packet_loss_fraction == |
+ config.uplink_packet_loss_fraction && |
+ arg.enable_fec == config.enable_fec && |
+ arg.enable_dtx == config.enable_dtx && |
+ arg.num_channels == config.num_channels; |
+} |
+ |
struct AudioNetworkAdaptorStates { |
std::unique_ptr<AudioNetworkAdaptorImpl> audio_network_adaptor; |
std::vector<std::unique_ptr<MockController>> mock_controllers; |
+ std::unique_ptr<SimulatedClock> simulated_clock; |
+ MockDebugDumpWriter* mock_debug_dump_writer; |
}; |
AudioNetworkAdaptorStates CreateAudioNetworkAdaptor() { |
@@ -64,9 +81,19 @@ AudioNetworkAdaptorStates CreateAudioNetworkAdaptor() { |
EXPECT_CALL(*controller_manager, GetSortedControllers(_)) |
.WillRepeatedly(Return(controllers)); |
+ states.simulated_clock.reset(new SimulatedClock(kClockInitialTimeMs * 1000)); |
+ |
+ auto debug_dump_writer = |
+ std::unique_ptr<MockDebugDumpWriter>(new NiceMock<MockDebugDumpWriter>()); |
+ EXPECT_CALL(*debug_dump_writer, Die()); |
+ states.mock_debug_dump_writer = debug_dump_writer.get(); |
+ |
+ AudioNetworkAdaptorImpl::Config config; |
+ config.clock = states.simulated_clock.get(); |
// AudioNetworkAdaptorImpl governs the lifetime of controller manager. |
states.audio_network_adaptor.reset(new AudioNetworkAdaptorImpl( |
- AudioNetworkAdaptorImpl::Config(), std::move(controller_manager))); |
+ config, |
+ std::move(controller_manager), std::move(debug_dump_writer))); |
return states; |
} |
@@ -108,4 +135,52 @@ TEST(AudioNetworkAdaptorImplTest, SetConstraintsIsCalledOnSetFrameLengthRange) { |
states.audio_network_adaptor->SetReceiverFrameLengthRange(20, 120); |
} |
+TEST(AudioNetworkAdaptorImplTest, |
+ DumpEncoderRuntimeConfigIsCalledOnGetEncoderRuntimeConfig) { |
+ auto states = CreateAudioNetworkAdaptor(); |
+ |
+ AudioNetworkAdaptor::EncoderRuntimeConfig config; |
+ config.bitrate_bps = rtc::Optional<int>(32000); |
+ config.enable_fec = rtc::Optional<bool>(true); |
+ |
+ EXPECT_CALL(*states.mock_controllers[0], MakeDecision(_, _)) |
+ .WillOnce(SetArgPointee<1>(config)); |
+ |
+ EXPECT_CALL(*states.mock_debug_dump_writer, |
+ DumpEncoderRuntimeConfig(EncoderRuntimeConfigIs(config), |
+ kClockInitialTimeMs)); |
+ states.audio_network_adaptor->GetEncoderRuntimeConfig(); |
+} |
+ |
+TEST(AudioNetworkAdaptorImplTest, |
+ DumpNetworkMetricsIsCalledOnSetNetworkMetrics) { |
+ auto states = CreateAudioNetworkAdaptor(); |
+ |
+ constexpr int kBandwidth = 16000; |
+ constexpr float kPacketLoss = 0.7f; |
+ constexpr int kRtt = 100; |
+ |
+ Controller::NetworkMetrics check; |
+ check.uplink_bandwidth_bps = rtc::Optional<int>(kBandwidth); |
+ int64_t timestamp_check = kClockInitialTimeMs; |
+ |
+ EXPECT_CALL(*states.mock_debug_dump_writer, |
+ DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check)); |
+ states.audio_network_adaptor->SetUplinkBandwidth(kBandwidth); |
+ |
+ states.simulated_clock->AdvanceTimeMilliseconds(100); |
+ timestamp_check += 100; |
+ check.uplink_packet_loss_fraction = rtc::Optional<float>(kPacketLoss); |
+ EXPECT_CALL(*states.mock_debug_dump_writer, |
+ DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check)); |
+ states.audio_network_adaptor->SetUplinkPacketLossFraction(kPacketLoss); |
+ |
+ states.simulated_clock->AdvanceTimeMilliseconds(200); |
+ timestamp_check += 200; |
+ check.rtt_ms = rtc::Optional<int>(kRtt); |
+ EXPECT_CALL(*states.mock_debug_dump_writer, |
+ DumpNetworkMetrics(NetworkMetricsIs(check), timestamp_check)); |
+ states.audio_network_adaptor->SetRtt(kRtt); |
+} |
+ |
} // namespace webrtc |