Add new AudioEncoderOpusTest

This test will replace AcmOpusTest when ACMOpus is removed. The old
AcmOpusTest also contains tests for setting and updating the
"application" setting in Opus. However, in the new AudioEncoderOpus
class, the application is trivially set in the Config struct at
construction, wherefore a test is no longer needed.

BUG=3926
R=minyue@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/37929004

Cr-Commit-Position: refs/heads/master@{#8244}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8244 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2015-02-04 15:34:05 +00:00
parent 520a69e8ea
commit cf7efeba37
3 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,80 @@
/*
* 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.
*/
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
namespace webrtc {
class AudioEncoderOpusTest : public ::testing::Test {
protected:
// The constructor simply creates an Opus encoder with default configuration.
AudioEncoderOpusTest()
: opus_(new AudioEncoderOpus(AudioEncoderOpus::Config())) {}
// 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(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());
}
}
scoped_ptr<AudioEncoderOpus> opus_;
};
namespace {
// These constants correspond to those used in
// AudioEncoderOpus::SetProjectedPacketLossRate.
const double kPacketLossRate20 = 0.20;
const double kPacketLossRate10 = 0.10;
const double kPacketLossRate5 = 0.05;
const double kPacketLossRate1 = 0.01;
const double kLossRate20Margin = 0.02;
const double kLossRate10Margin = 0.01;
const double kLossRate5Margin = 0.01;
} // namespace
TEST_F(AudioEncoderOpusTest, PacketLossRateOptimized) {
// Note that the order of the following calls is critical.
TestSetPacketLossRate(0.0, 0.0, 0.0);
TestSetPacketLossRate(kPacketLossRate1,
kPacketLossRate5 + kLossRate5Margin - 0.01,
kPacketLossRate1);
TestSetPacketLossRate(kPacketLossRate5 + kLossRate5Margin,
kPacketLossRate10 + kLossRate10Margin - 0.01,
kPacketLossRate5);
TestSetPacketLossRate(kPacketLossRate10 + kLossRate10Margin,
kPacketLossRate20 + kLossRate20Margin - 0.01,
kPacketLossRate10);
TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
1.0,
kPacketLossRate20);
TestSetPacketLossRate(kPacketLossRate20 + kLossRate20Margin,
kPacketLossRate20 - kLossRate20Margin,
kPacketLossRate20);
TestSetPacketLossRate(kPacketLossRate20 - kLossRate20Margin - 0.01,
kPacketLossRate10 - kLossRate10Margin,
kPacketLossRate10);
TestSetPacketLossRate(kPacketLossRate10 - kLossRate10Margin - 0.01,
kPacketLossRate5 - kLossRate5Margin,
kPacketLossRate5);
TestSetPacketLossRate(kPacketLossRate5 - kLossRate5Margin - 0.01,
kPacketLossRate1,
kPacketLossRate1);
TestSetPacketLossRate(0.0, 0.0, 0.0);
}
} // namespace webrtc

View File

@ -49,6 +49,7 @@ class AudioEncoderOpus final : public AudioEncoder {
virtual int Max10MsFramesInAPacket() const OVERRIDE;
void SetTargetBitrate(int bits_per_second) override;
void SetProjectedPacketLossRate(double fraction) override;
double packet_loss_rate() const { return packet_loss_rate_; }
protected:
virtual bool EncodeInternal(uint32_t rtp_timestamp,

View File

@ -105,6 +105,7 @@
'audio_coding/codecs/isac/fix/source/transform_unittest.cc',
'audio_coding/codecs/isac/main/source/isac_unittest.cc',
'audio_coding/codecs/isac/main/source/audio_encoder_isac_red_unittest.cc',
'audio_coding/codecs/opus/audio_encoder_opus_unittest.cc',
'audio_coding/codecs/opus/opus_unittest.cc',
'audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc',
'audio_coding/neteq/audio_classifier_unittest.cc',