aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc
diff options
context:
space:
mode:
authorKarl Wiberg <kwiberg@webrtc.org>2015-05-07 12:35:12 +0200
committerKarl Wiberg <kwiberg@webrtc.org>2015-05-07 10:35:18 +0000
commitdcccab3ebb623df74fbb1425da2cb9d9a42439fa (patch)
treeb895b8c79cbd4186fc675e435848a1f7a8c1160d /webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc
parent81ea54eaac82b36b7208a02fd37a469d7d0bd9d0 (diff)
downloadwebrtc-dcccab3ebb623df74fbb1425da2cb9d9a42439fa.tar.gz
New interface: AudioEncoderMutable
With implementations for all codecs. It has no users yet. This new interface is the same as AudioEncoder (in fact it is a subclass) but it allows changing some parameters after construction. COAUTHOR=henrik.lundin@webrtc.org BUG=4228 R=jmarusic@webrtc.org, minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/51679004 Cr-Commit-Position: refs/heads/master@{#9149}
Diffstat (limited to 'webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc')
-rw-r--r--webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc
new file mode 100644
index 0000000000..ddb5f1ea80
--- /dev/null
+++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_mutable_opus_test.cc
@@ -0,0 +1,114 @@
+/*
+ * 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/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 AudioEncoderMutableOpus(codec_inst_));
+ auto expected_app =
+ num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio;
+ EXPECT_EQ(expected_app, encoder_->application());
+ }
+
+ CodecInst codec_inst_;
+ rtc::scoped_ptr<AudioEncoderMutableOpus> encoder_;
+};
+
+TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeMono) {
+ CreateCodec(1);
+}
+
+TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeStereo) {
+ CreateCodec(2);
+}
+
+TEST_F(AudioEncoderMutableOpusTest, ChangeApplicationMode) {
+ CreateCodec(2);
+ EXPECT_TRUE(
+ encoder_->SetApplication(AudioEncoderMutable::kApplicationSpeech, false));
+ 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(AudioEncoderMutable::kApplicationSpeech, false));
+ 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);
+
+ // DTX is not allowed in audio mode, if mode forcing flag is false.
+ EXPECT_FALSE(encoder_->SetDtx(true, false));
+ EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application());
+
+ // DTX will be on, if mode forcing flag is true. Then application mode is
+ // switched to kVoip.
+ EXPECT_TRUE(encoder_->SetDtx(true, true));
+ EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application());
+
+ // Audio mode is not allowed when DTX is on, and DTX forcing flag is false.
+ EXPECT_FALSE(
+ encoder_->SetApplication(AudioEncoderMutable::kApplicationAudio, false));
+ EXPECT_TRUE(encoder_->dtx_enabled());
+
+ // Audio mode will be set, if DTX forcing flag is true. Then DTX is switched
+ // off.
+ EXPECT_TRUE(
+ encoder_->SetApplication(AudioEncoderMutable::kApplicationAudio, true));
+ EXPECT_FALSE(encoder_->dtx_enabled());
+
+ // Now we set VOIP mode. The DTX forcing flag has no effect.
+ EXPECT_TRUE(
+ encoder_->SetApplication(AudioEncoderMutable::kApplicationSpeech, true));
+ EXPECT_FALSE(encoder_->dtx_enabled());
+
+ // In VOIP mode, we can enable DTX with mode forcing flag being false.
+ EXPECT_TRUE(encoder_->SetDtx(true, false));
+
+ // Turn off DTX.
+ EXPECT_TRUE(encoder_->SetDtx(false, false));
+
+ // When DTX is off, we can set Audio mode with DTX forcing flag being false.
+ EXPECT_TRUE(
+ encoder_->SetApplication(AudioEncoderMutable::kApplicationAudio, false));
+}
+#endif // WEBRTC_CODEC_OPUS
+
+} // namespace acm2
+} // namespace webrtc