Remove encoding code from RtcEventLogImpl and use RtcEventLogEncoder instead

RtcEventLogImpl no longer hard-codes the way encoding is done. It now relies on RtcEventEncoder for it. This gives two benefits:
1. We can decide between the current encoding and the new encoding (which is still WIP) without code duplication (no need for RtcEventLogImplNew).
2. Encoding is done only when the event needs to be written to a file. This both avoids unnecessary encoding of events which don't end up getting written to a file, as well as is useful for the new, delta-based encoding, which is stateful.

BUG=webrtc:8111

Change-Id: I9517132e5f96b8059002a66fde8d42d3a678c3bb
Reviewed-on: https://webrtc-review.googlesource.com/1365
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20118}
This commit is contained in:
Elad Alon
2017-10-03 16:11:34 +02:00
parent 45a0b36d3f
commit 4a87e1c211
27 changed files with 511 additions and 592 deletions

View File

@ -2178,6 +2178,7 @@ if (rtc_include_tests) {
"../../api/audio_codecs:builtin_audio_encoder_factory",
"../../common_audio",
"../../common_audio:mock_common_audio",
"../../logging:rtc_event_log_api",
"../../rtc_base:protobuf_utils",
"../../rtc_base:rtc_base",
"../../rtc_base:rtc_base_approved",

View File

@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include "logging/rtc_event_log/events/rtc_event.h"
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/audio_coding/audio_network_adaptor/audio_network_adaptor_impl.h"
#include "modules/audio_coding/audio_network_adaptor/mock/mock_controller.h"
@ -44,6 +46,14 @@ MATCHER_P(NetworkMetricsIs, metric, "") {
metric.uplink_recoverable_packet_loss_fraction;
}
MATCHER_P(IsRtcEventAnaConfigEqualTo, config, "") {
if (arg->GetType() != RtcEvent::Type::AudioNetworkAdaptation) {
return false;
}
auto ana_event = static_cast<RtcEventAudioNetworkAdaptation*>(arg);
return *ana_event->config_ == config;
}
MATCHER_P(EncoderRuntimeConfigIs, config, "") {
return arg.bitrate_bps == config.bitrate_bps &&
arg.frame_length_ms == config.frame_length_ms &&
@ -271,8 +281,7 @@ TEST(AudioNetworkAdaptorImplTest, LogRuntimeConfigOnGetEncoderRuntimeConfig) {
EXPECT_CALL(*states.mock_controllers[0], MakeDecision(_))
.WillOnce(SetArgPointee<0>(config));
EXPECT_CALL(*states.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(config)))
EXPECT_CALL(*states.event_log, LogProxy(IsRtcEventAnaConfigEqualTo(config)))
.Times(1);
states.audio_network_adaptor->GetEncoderRuntimeConfig();
}

View File

@ -9,10 +9,13 @@
*/
#include <math.h>
#include <algorithm>
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/audio_coding/audio_network_adaptor/event_log_writer.h"
#include "rtc_base/ptr_util.h"
namespace webrtc {
@ -60,7 +63,9 @@ void EventLogWriter::MaybeLogEncoderConfig(
}
void EventLogWriter::LogEncoderConfig(const AudioEncoderRuntimeConfig& config) {
event_log_->LogAudioNetworkAdaptation(config);
auto config_copy = rtc::MakeUnique<AudioEncoderRuntimeConfig>(config);
event_log_->Log(
rtc::MakeUnique<RtcEventAudioNetworkAdaptation>(std::move(config_copy)));
last_logged_config_ = config;
}

View File

@ -10,6 +10,7 @@
#include <memory>
#include "logging/rtc_event_log/events/rtc_event_audio_network_adaptation.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/audio_coding/audio_network_adaptor/event_log_writer.h"
#include "test/gtest.h"
@ -30,14 +31,12 @@ constexpr bool kEnableDtx = true;
constexpr float kPacketLossFraction = 0.05f;
constexpr size_t kNumChannels = 1;
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;
MATCHER_P(IsRtcEventAnaConfigEqualTo, config, "") {
if (arg->GetType() != RtcEvent::Type::AudioNetworkAdaptation) {
return false;
}
auto ana_event = static_cast<RtcEventAudioNetworkAdaptation*>(arg);
return *ana_event->config_ == config;
}
struct EventLogWriterStates {
@ -65,18 +64,16 @@ EventLogWriterStates CreateEventLogWriter() {
TEST(EventLogWriterTest, FirstConfigIsLogged) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, SameConfigIsNotLogged) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
@ -84,73 +81,64 @@ TEST(EventLogWriterTest, SameConfigIsNotLogged) {
TEST(EventLogWriterTest, LogFecStateChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.enable_fec = rtc::Optional<bool>(!kEnableFec);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, LogDtxStateChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.enable_dtx = rtc::Optional<bool>(!kEnableDtx);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, LogChannelChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.num_channels = rtc::Optional<size_t>(kNumChannels + 1);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, LogFrameLengthChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.frame_length_ms = rtc::Optional<int>(20);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, DoNotLogSmallBitrateChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.bitrate_bps =
@ -160,9 +148,8 @@ TEST(EventLogWriterTest, DoNotLogSmallBitrateChange) {
TEST(EventLogWriterTest, LogLargeBitrateChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
// At high bitrate, the min fraction rule requires a larger change than the
@ -171,9 +158,8 @@ TEST(EventLogWriterTest, LogLargeBitrateChange) {
kMinBitrateChangeBps);
state.runtime_config.bitrate_bps =
rtc::Optional<int>(kHighBitrateBps + kMinBitrateChangeBps);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
@ -181,27 +167,24 @@ TEST(EventLogWriterTest, LogLargeBitrateChange) {
TEST(EventLogWriterTest, LogMinBitrateChangeFractionOnLowBitrateChange) {
auto state = CreateEventLogWriter();
state.runtime_config.bitrate_bps = rtc::Optional<int>(kLowBitrateBps);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
// At high bitrate, the min change rule requires a larger change than the min
// fraction rule. We make sure that the min fraction rule applies.
state.runtime_config.bitrate_bps = rtc::Optional<int>(
kLowBitrateBps + kLowBitrateBps * kMinBitrateChangeFraction);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, DoNotLogSmallPacketLossFractionChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
@ -212,49 +195,43 @@ TEST(EventLogWriterTest, DoNotLogSmallPacketLossFractionChange) {
TEST(EventLogWriterTest, LogLargePacketLossFractionChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, LogJustOnceOnMultipleChanges) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.uplink_packet_loss_fraction = rtc::Optional<float>(
kPacketLossFraction + kMinPacketLossChangeFraction * kPacketLossFraction);
state.runtime_config.frame_length_ms = rtc::Optional<int>(20);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
}
TEST(EventLogWriterTest, LogAfterGradualChange) {
auto state = CreateEventLogWriter();
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
state.event_log_writer->MaybeLogEncoderConfig(state.runtime_config);
state.runtime_config.bitrate_bps =
rtc::Optional<int>(kHighBitrateBps + kMinBitrateChangeBps);
EXPECT_CALL(
*state.event_log,
LogAudioNetworkAdaptation(EncoderRuntimeConfigIs(state.runtime_config)))
EXPECT_CALL(*state.event_log,
LogProxy(IsRtcEventAnaConfigEqualTo(state.runtime_config)))
.Times(1);
for (int bitrate_bps = kHighBitrateBps;
bitrate_bps <= kHighBitrateBps + kMinBitrateChangeBps; bitrate_bps++) {

View File

@ -19,11 +19,8 @@ struct AudioEncoderRuntimeConfig {
AudioEncoderRuntimeConfig();
AudioEncoderRuntimeConfig(const AudioEncoderRuntimeConfig& other);
~AudioEncoderRuntimeConfig();
AudioEncoderRuntimeConfig& operator=(const AudioEncoderRuntimeConfig& other);
bool operator==(const AudioEncoderRuntimeConfig& other) const;
rtc::Optional<int> bitrate_bps;
rtc::Optional<int> frame_length_ms;
// Note: This is what we tell the encoder. It doesn't have to reflect