Merge two files with AudioEncoderOpus tests
Merge the contents of audio_encoder_mutable_opus_test.cc into audio_encoder_opus_unittest.cc, since they're now both testing AudioEncoderOpus. (While preparing this CL, I noted a bug in the PacketLossRateOptimized test. This CL leaves that test essentially unchanged; I've posted bug 4981 about the problem.) Review URL: https://codereview.webrtc.org/1319713004 Cr-Commit-Position: refs/heads/master@{#9906}
This commit is contained in:
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO(kwiberg): Merge these tests into audio_encoder_opus_unittest.cc
|
|
||||||
|
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
|
||||||
#include "webrtc/common_types.h"
|
|
||||||
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
|
||||||
namespace acm2 {
|
|
||||||
|
|
||||||
#ifdef WEBRTC_CODEC_OPUS
|
|
||||||
namespace {
|
|
||||||
const CodecInst kDefaultOpusCodecInst = {105, "opus", 48000, 960, 1, 32000};
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
class AudioEncoderMutableOpusTest : public ::testing::Test {
|
|
||||||
protected:
|
|
||||||
AudioEncoderMutableOpusTest() : codec_inst_(kDefaultOpusCodecInst) {}
|
|
||||||
|
|
||||||
void CreateCodec(int num_channels) {
|
|
||||||
codec_inst_.channels = num_channels;
|
|
||||||
encoder_.reset(new AudioEncoderOpus(codec_inst_));
|
|
||||||
auto expected_app =
|
|
||||||
num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio;
|
|
||||||
EXPECT_EQ(expected_app, encoder_->application());
|
|
||||||
}
|
|
||||||
|
|
||||||
CodecInst codec_inst_;
|
|
||||||
rtc::scoped_ptr<AudioEncoderOpus> encoder_;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeMono) {
|
|
||||||
CreateCodec(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeStereo) {
|
|
||||||
CreateCodec(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, ChangeApplicationMode) {
|
|
||||||
CreateCodec(2);
|
|
||||||
EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech));
|
|
||||||
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, ResetWontChangeApplicationMode) {
|
|
||||||
CreateCodec(2);
|
|
||||||
|
|
||||||
// Trigger a reset.
|
|
||||||
encoder_->Reset();
|
|
||||||
// Verify that the mode is still kAudio.
|
|
||||||
EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application());
|
|
||||||
|
|
||||||
// Now change to kVoip.
|
|
||||||
EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech));
|
|
||||||
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
|
||||||
|
|
||||||
// Trigger a reset again.
|
|
||||||
encoder_->Reset();
|
|
||||||
// Verify that the mode is still kVoip.
|
|
||||||
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, ToggleDtx) {
|
|
||||||
CreateCodec(2);
|
|
||||||
// Enable DTX
|
|
||||||
EXPECT_TRUE(encoder_->SetDtx(true));
|
|
||||||
// Verify that the mode is still kAudio.
|
|
||||||
EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application());
|
|
||||||
// Turn off DTX.
|
|
||||||
EXPECT_TRUE(encoder_->SetDtx(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AudioEncoderMutableOpusTest, SetBitrate) {
|
|
||||||
CreateCodec(1);
|
|
||||||
// Constants are replicated from audio_encoder_opus.cc.
|
|
||||||
const int kMinBitrateBps = 500;
|
|
||||||
const int kMaxBitrateBps = 512000;
|
|
||||||
// Set a too low bitrate.
|
|
||||||
encoder_->SetTargetBitrate(kMinBitrateBps - 1);
|
|
||||||
EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate());
|
|
||||||
// Set a too high bitrate.
|
|
||||||
encoder_->SetTargetBitrate(kMaxBitrateBps + 1);
|
|
||||||
EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate());
|
|
||||||
// Set the minimum rate.
|
|
||||||
encoder_->SetTargetBitrate(kMinBitrateBps);
|
|
||||||
EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate());
|
|
||||||
// Set the maximum rate.
|
|
||||||
encoder_->SetTargetBitrate(kMaxBitrateBps);
|
|
||||||
EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate());
|
|
||||||
// Set rates from 1000 up to 32000 bps.
|
|
||||||
for (int rate = 1000; rate <= 32000; rate += 1000) {
|
|
||||||
encoder_->SetTargetBitrate(rate);
|
|
||||||
EXPECT_EQ(rate, encoder_->GetTargetBitrate());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // WEBRTC_CODEC_OPUS
|
|
||||||
|
|
||||||
} // namespace acm2
|
|
||||||
} // namespace webrtc
|
|
@ -10,32 +10,97 @@
|
|||||||
|
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
#include "webrtc/base/scoped_ptr.h"
|
#include "webrtc/base/scoped_ptr.h"
|
||||||
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
|
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const CodecInst kOpusSettings = {105, "opus", 48000, 960, 1, 32000};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class AudioEncoderOpusTest : public ::testing::Test {
|
class AudioEncoderOpusTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
// The constructor simply creates an Opus encoder with default configuration.
|
void CreateCodec(int num_channels) {
|
||||||
AudioEncoderOpusTest()
|
codec_inst_.channels = num_channels;
|
||||||
: opus_(new AudioEncoderOpus(AudioEncoderOpus::Config())) {}
|
encoder_.reset(new AudioEncoderOpus(codec_inst_));
|
||||||
|
auto expected_app =
|
||||||
// Repeatedly sets packet loss rates in the range [from, to], increasing by
|
num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio;
|
||||||
// 0.01 in each step. The function verifies that the actual loss rate is
|
EXPECT_EQ(expected_app, encoder_->application());
|
||||||
// |expected_return|.
|
|
||||||
void TestSetPacketLossRate(double from, double to, double expected_return) {
|
|
||||||
ASSERT_TRUE(opus_);
|
|
||||||
for (double loss = from; loss <= to;
|
|
||||||
(to >= from) ? loss += 0.01 : loss -= 0.01) {
|
|
||||||
opus_->SetProjectedPacketLossRate(loss);
|
|
||||||
EXPECT_DOUBLE_EQ(expected_return, opus_->packet_loss_rate());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_ptr<AudioEncoderOpus> opus_;
|
CodecInst codec_inst_ = kOpusSettings;
|
||||||
|
rtc::scoped_ptr<AudioEncoderOpus> encoder_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, DefaultApplicationModeMono) {
|
||||||
|
CreateCodec(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, DefaultApplicationModeStereo) {
|
||||||
|
CreateCodec(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, ChangeApplicationMode) {
|
||||||
|
CreateCodec(2);
|
||||||
|
EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech));
|
||||||
|
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, ResetWontChangeApplicationMode) {
|
||||||
|
CreateCodec(2);
|
||||||
|
|
||||||
|
// Trigger a reset.
|
||||||
|
encoder_->Reset();
|
||||||
|
// Verify that the mode is still kAudio.
|
||||||
|
EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application());
|
||||||
|
|
||||||
|
// Now change to kVoip.
|
||||||
|
EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech));
|
||||||
|
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
||||||
|
|
||||||
|
// Trigger a reset again.
|
||||||
|
encoder_->Reset();
|
||||||
|
// Verify that the mode is still kVoip.
|
||||||
|
EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, ToggleDtx) {
|
||||||
|
CreateCodec(2);
|
||||||
|
// Enable DTX
|
||||||
|
EXPECT_TRUE(encoder_->SetDtx(true));
|
||||||
|
// Verify that the mode is still kAudio.
|
||||||
|
EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application());
|
||||||
|
// Turn off DTX.
|
||||||
|
EXPECT_TRUE(encoder_->SetDtx(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AudioEncoderOpusTest, SetBitrate) {
|
||||||
|
CreateCodec(1);
|
||||||
|
// Constants are replicated from audio_encoder_opus.cc.
|
||||||
|
const int kMinBitrateBps = 500;
|
||||||
|
const int kMaxBitrateBps = 512000;
|
||||||
|
// Set a too low bitrate.
|
||||||
|
encoder_->SetTargetBitrate(kMinBitrateBps - 1);
|
||||||
|
EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate());
|
||||||
|
// Set a too high bitrate.
|
||||||
|
encoder_->SetTargetBitrate(kMaxBitrateBps + 1);
|
||||||
|
EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate());
|
||||||
|
// Set the minimum rate.
|
||||||
|
encoder_->SetTargetBitrate(kMinBitrateBps);
|
||||||
|
EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate());
|
||||||
|
// Set the maximum rate.
|
||||||
|
encoder_->SetTargetBitrate(kMaxBitrateBps);
|
||||||
|
EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate());
|
||||||
|
// Set rates from 1000 up to 32000 bps.
|
||||||
|
for (int rate = 1000; rate <= 32000; rate += 1000) {
|
||||||
|
encoder_->SetTargetBitrate(rate);
|
||||||
|
EXPECT_EQ(rate, encoder_->GetTargetBitrate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// These constants correspond to those used in
|
// These constants correspond to those used in
|
||||||
// AudioEncoderOpus::SetProjectedPacketLossRate.
|
// AudioEncoderOpus::SetProjectedPacketLossRate.
|
||||||
const double kPacketLossRate20 = 0.20;
|
const double kPacketLossRate20 = 0.20;
|
||||||
@ -45,36 +110,52 @@ const double kPacketLossRate1 = 0.01;
|
|||||||
const double kLossRate20Margin = 0.02;
|
const double kLossRate20Margin = 0.02;
|
||||||
const double kLossRate10Margin = 0.01;
|
const double kLossRate10Margin = 0.01;
|
||||||
const double kLossRate5Margin = 0.01;
|
const double kLossRate5Margin = 0.01;
|
||||||
|
|
||||||
|
// Repeatedly sets packet loss rates in the range [from, to], increasing by
|
||||||
|
// 0.01 in each step. The function verifies that the actual loss rate is
|
||||||
|
// |expected_return|.
|
||||||
|
void TestSetPacketLossRate(AudioEncoderOpus* encoder,
|
||||||
|
double from,
|
||||||
|
double to,
|
||||||
|
double expected_return) {
|
||||||
|
for (double loss = from; loss <= to;
|
||||||
|
(to >= from) ? loss += 0.01 : loss -= 0.01) {
|
||||||
|
encoder->SetProjectedPacketLossRate(loss);
|
||||||
|
EXPECT_DOUBLE_EQ(expected_return, encoder->packet_loss_rate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) {
|
TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) {
|
||||||
|
CreateCodec(1);
|
||||||
|
|
||||||
// Note that the order of the following calls is critical.
|
// Note that the order of the following calls is critical.
|
||||||
TestSetPacketLossRate(0.0, 0.0, 0.0);
|
TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0);
|
||||||
TestSetPacketLossRate(kPacketLossRate1,
|
TestSetPacketLossRate(encoder_.get(), kPacketLossRate1,
|
||||||
kPacketLossRate5 + kLossRate5Margin - 0.01,
|
kPacketLossRate5 + kLossRate5Margin - 0.01,
|
||||||
kPacketLossRate1);
|
kPacketLossRate1);
|
||||||
TestSetPacketLossRate(kPacketLossRate5 + kLossRate5Margin,
|
TestSetPacketLossRate(encoder_.get(), kPacketLossRate5 + kLossRate5Margin,
|
||||||
kPacketLossRate10 + kLossRate10Margin - 0.01,
|
kPacketLossRate10 + kLossRate10Margin - 0.01,
|
||||||
kPacketLossRate5);
|
kPacketLossRate5);
|
||||||
TestSetPacketLossRate(kPacketLossRate10 + kLossRate10Margin,
|
TestSetPacketLossRate(encoder_.get(), kPacketLossRate10 + kLossRate10Margin,
|
||||||
kPacketLossRate20 + kLossRate20Margin - 0.01,
|
kPacketLossRate20 + kLossRate20Margin - 0.01,
|
||||||
kPacketLossRate10);
|
kPacketLossRate10);
|
||||||
TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
|
TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin,
|
||||||
1.0,
|
1.0, kPacketLossRate20);
|
||||||
kPacketLossRate20);
|
TestSetPacketLossRate(encoder_.get(), kPacketLossRate20 + kLossRate20Margin,
|
||||||
TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
|
|
||||||
kPacketLossRate20 - kLossRate20Margin,
|
kPacketLossRate20 - kLossRate20Margin,
|
||||||
kPacketLossRate20);
|
kPacketLossRate20);
|
||||||
TestSetPacketLossRate(kPacketLossRate20 - kLossRate20Margin - 0.01,
|
TestSetPacketLossRate(
|
||||||
kPacketLossRate10 - kLossRate10Margin,
|
encoder_.get(), kPacketLossRate20 - kLossRate20Margin - 0.01,
|
||||||
kPacketLossRate10);
|
kPacketLossRate10 - kLossRate10Margin, kPacketLossRate10);
|
||||||
TestSetPacketLossRate(kPacketLossRate10 - kLossRate10Margin - 0.01,
|
TestSetPacketLossRate(encoder_.get(),
|
||||||
kPacketLossRate5 - kLossRate5Margin,
|
kPacketLossRate10 - kLossRate10Margin - 0.01,
|
||||||
kPacketLossRate5);
|
kPacketLossRate5 - kLossRate5Margin, kPacketLossRate5);
|
||||||
TestSetPacketLossRate(kPacketLossRate5 - kLossRate5Margin - 0.01,
|
TestSetPacketLossRate(encoder_.get(),
|
||||||
kPacketLossRate1,
|
kPacketLossRate5 - kLossRate5Margin - 0.01,
|
||||||
kPacketLossRate1);
|
kPacketLossRate1, kPacketLossRate1);
|
||||||
TestSetPacketLossRate(0.0, 0.0, 0.0);
|
TestSetPacketLossRate(encoder_.get(), 0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -97,7 +97,6 @@
|
|||||||
],
|
],
|
||||||
'sources': [
|
'sources': [
|
||||||
'audio_coding/codecs/cng/audio_encoder_cng_unittest.cc',
|
'audio_coding/codecs/cng/audio_encoder_cng_unittest.cc',
|
||||||
'audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc',
|
|
||||||
'audio_coding/main/acm2/acm_receiver_unittest.cc',
|
'audio_coding/main/acm2/acm_receiver_unittest.cc',
|
||||||
'audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc',
|
'audio_coding/main/acm2/acm_receiver_unittest_oldapi.cc',
|
||||||
'audio_coding/main/acm2/audio_coding_module_unittest.cc',
|
'audio_coding/main/acm2/audio_coding_module_unittest.cc',
|
||||||
|
Reference in New Issue
Block a user