| Index: webrtc/modules/audio_coding/audio_network_adaptor/event_log_writer_unittest.cc
|
| diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/event_log_writer_unittest.cc b/webrtc/modules/audio_coding/audio_network_adaptor/event_log_writer_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a87ba54db7d118b730f1836630704e8a2efcfb9d
|
| --- /dev/null
|
| +++ b/webrtc/modules/audio_coding/audio_network_adaptor/event_log_writer_unittest.cc
|
| @@ -0,0 +1,157 @@
|
| +/*
|
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include <memory>
|
| +
|
| +#include "webrtc/logging/rtc_event_log/mock/mock_rtc_event_log.h"
|
| +#include "webrtc/modules/audio_coding/audio_network_adaptor/event_log_writer.h"
|
| +#include "webrtc/test/gtest.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +namespace {
|
| +constexpr int kMinBitreateChangeBps = 5000;
|
| +constexpr float kMinPacketLossChangeFraction = 0.5;
|
| +
|
| +constexpr int kBitrateBps = 50000;
|
| +constexpr int kFrameLengthMs = 60;
|
| +constexpr bool kEnableFec = true;
|
| +constexpr bool kEnableDtx = true;
|
| +constexpr float kPacketLossFraction = 0.05;
|
| +constexpr size_t kNumChannels = 1;
|
| +
|
| +struct EventLogWriterStates {
|
| + std::unique_ptr<EventLogWriter> event_log_writer;
|
| + std::unique_ptr<MockRtcEventLog> event_log;
|
| + AudioNetworkAdaptor::EncoderRuntimeConfig runtime_config;
|
| +};
|
| +
|
| +EventLogWriterStates CreateEventLogWriter() {
|
| + EventLogWriterStates state;
|
| + state.event_log.reset(new MockRtcEventLog());
|
| + state.event_log_writer.reset(
|
| + new EventLogWriter(state.event_log.get(), kMinBitreateChangeBps,
|
| + kMinPacketLossChangeFraction));
|
| + state.runtime_config.bitrate_bps = rtc::Optional<int>(kBitrateBps);
|
| + state.runtime_config.frame_length_ms = rtc::Optional<int>(kFrameLengthMs);
|
| + state.runtime_config.uplink_packet_loss_fraction =
|
| + rtc::Optional<float>(kPacketLossFraction);
|
| + state.runtime_config.enable_fec = rtc::Optional<bool>(kEnableFec);
|
| + state.runtime_config.enable_dtx = rtc::Optional<bool>(kEnableDtx);
|
| + state.runtime_config.num_channels = rtc::Optional<size_t>(kNumChannels);
|
| + return state;
|
| +}
|
| +
|
| +void ExpectLogEncoderRuntimeConfig(
|
| + const std::unique_ptr<MockRtcEventLog>& event_log,
|
| + const AudioNetworkAdaptor::EncoderRuntimeConfig& runtime_config) {
|
| + EXPECT_CALL(
|
| + *event_log,
|
| + LogAnaDecisionEvent(
|
| + runtime_config.bitrate_bps, runtime_config.frame_length_ms,
|
| + runtime_config.uplink_packet_loss_fraction, runtime_config.enable_fec,
|
| + runtime_config.enable_dtx, runtime_config.num_channels))
|
| + .Times(1);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST(EventLogWriterTest, FirstConfigIsLogged) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, SameConfigIsNotLogged) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogOnFecStateChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +
|
| + state.runtime_config.enable_fec = rtc::Optional<bool>(!kEnableFec);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogOnDtxStateChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +
|
| + state.runtime_config.enable_dtx = rtc::Optional<bool>(!kEnableDtx);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogOnChannelChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +
|
| + state.runtime_config.num_channels = rtc::Optional<size_t>(kNumChannels + 1);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogOnFrameLengthChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +
|
| + state.runtime_config.frame_length_ms = rtc::Optional<int>(20);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, DoNotLogSmallBitrateChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| + state.runtime_config.bitrate_bps =
|
| + rtc::Optional<int>(kBitrateBps + kMinBitreateChangeBps - 1);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogBigBitrateChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| + state.runtime_config.bitrate_bps =
|
| + rtc::Optional<int>(kBitrateBps + kMinBitreateChangeBps);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, DoNotLogSmallPacketLossFractionChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| + state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
|
| + kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction -
|
| + 0.001);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +
|
| +TEST(EventLogWriterTest, LogBigPacketLossFractionChange) {
|
| + auto state = CreateEventLogWriter();
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| + state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
|
| + kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction);
|
| + ExpectLogEncoderRuntimeConfig(state.event_log, state.runtime_config);
|
| + state.event_log_writer->MayLogEncoderRuntimeConfig(state.runtime_config);
|
| +}
|
| +} // namespace webrtc
|
|
|