OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 // TODO(kwiberg): Merge these tests into audio_encoder_opus_unittest.cc | |
12 | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include "webrtc/common_types.h" | |
15 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h
" | |
16 | |
17 namespace webrtc { | |
18 namespace acm2 { | |
19 | |
20 #ifdef WEBRTC_CODEC_OPUS | |
21 namespace { | |
22 const CodecInst kDefaultOpusCodecInst = {105, "opus", 48000, 960, 1, 32000}; | |
23 } // namespace | |
24 | |
25 class AudioEncoderMutableOpusTest : public ::testing::Test { | |
26 protected: | |
27 AudioEncoderMutableOpusTest() : codec_inst_(kDefaultOpusCodecInst) {} | |
28 | |
29 void CreateCodec(int num_channels) { | |
30 codec_inst_.channels = num_channels; | |
31 encoder_.reset(new AudioEncoderOpus(codec_inst_)); | |
32 auto expected_app = | |
33 num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio; | |
34 EXPECT_EQ(expected_app, encoder_->application()); | |
35 } | |
36 | |
37 CodecInst codec_inst_; | |
38 rtc::scoped_ptr<AudioEncoderOpus> encoder_; | |
39 }; | |
40 | |
41 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeMono) { | |
42 CreateCodec(1); | |
43 } | |
44 | |
45 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeStereo) { | |
46 CreateCodec(2); | |
47 } | |
48 | |
49 TEST_F(AudioEncoderMutableOpusTest, ChangeApplicationMode) { | |
50 CreateCodec(2); | |
51 EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech)); | |
52 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | |
53 } | |
54 | |
55 TEST_F(AudioEncoderMutableOpusTest, ResetWontChangeApplicationMode) { | |
56 CreateCodec(2); | |
57 | |
58 // Trigger a reset. | |
59 encoder_->Reset(); | |
60 // Verify that the mode is still kAudio. | |
61 EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application()); | |
62 | |
63 // Now change to kVoip. | |
64 EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech)); | |
65 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | |
66 | |
67 // Trigger a reset again. | |
68 encoder_->Reset(); | |
69 // Verify that the mode is still kVoip. | |
70 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | |
71 } | |
72 | |
73 TEST_F(AudioEncoderMutableOpusTest, ToggleDtx) { | |
74 CreateCodec(2); | |
75 // Enable DTX | |
76 EXPECT_TRUE(encoder_->SetDtx(true)); | |
77 // Verify that the mode is still kAudio. | |
78 EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application()); | |
79 // Turn off DTX. | |
80 EXPECT_TRUE(encoder_->SetDtx(false)); | |
81 } | |
82 | |
83 TEST_F(AudioEncoderMutableOpusTest, SetBitrate) { | |
84 CreateCodec(1); | |
85 // Constants are replicated from audio_encoder_opus.cc. | |
86 const int kMinBitrateBps = 500; | |
87 const int kMaxBitrateBps = 512000; | |
88 // Set a too low bitrate. | |
89 encoder_->SetTargetBitrate(kMinBitrateBps - 1); | |
90 EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate()); | |
91 // Set a too high bitrate. | |
92 encoder_->SetTargetBitrate(kMaxBitrateBps + 1); | |
93 EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate()); | |
94 // Set the minimum rate. | |
95 encoder_->SetTargetBitrate(kMinBitrateBps); | |
96 EXPECT_EQ(kMinBitrateBps, encoder_->GetTargetBitrate()); | |
97 // Set the maximum rate. | |
98 encoder_->SetTargetBitrate(kMaxBitrateBps); | |
99 EXPECT_EQ(kMaxBitrateBps, encoder_->GetTargetBitrate()); | |
100 // Set rates from 1000 up to 32000 bps. | |
101 for (int rate = 1000; rate <= 32000; rate += 1000) { | |
102 encoder_->SetTargetBitrate(rate); | |
103 EXPECT_EQ(rate, encoder_->GetTargetBitrate()); | |
104 } | |
105 } | |
106 #endif // WEBRTC_CODEC_OPUS | |
107 | |
108 } // namespace acm2 | |
109 } // namespace webrtc | |
OLD | NEW |