| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // TODO(kwiberg): Merge these tests into audio_encoder_opus_unittest.cc |
| 12 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/common_types.h" | 14 #include "webrtc/common_types.h" |
| 13 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h
" | 15 #include "webrtc/modules/audio_coding/codecs/opus/interface/audio_encoder_opus.h
" |
| 14 | 16 |
| 15 namespace webrtc { | 17 namespace webrtc { |
| 16 namespace acm2 { | 18 namespace acm2 { |
| 17 | 19 |
| 18 #ifdef WEBRTC_CODEC_OPUS | 20 #ifdef WEBRTC_CODEC_OPUS |
| 19 namespace { | 21 namespace { |
| 20 const CodecInst kDefaultOpusCodecInst = {105, "opus", 48000, 960, 1, 32000}; | 22 const CodecInst kDefaultOpusCodecInst = {105, "opus", 48000, 960, 1, 32000}; |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 class AudioEncoderMutableOpusTest : public ::testing::Test { | 25 class AudioEncoderMutableOpusTest : public ::testing::Test { |
| 24 protected: | 26 protected: |
| 25 AudioEncoderMutableOpusTest() : codec_inst_(kDefaultOpusCodecInst) {} | 27 AudioEncoderMutableOpusTest() : codec_inst_(kDefaultOpusCodecInst) {} |
| 26 | 28 |
| 27 void CreateCodec(int num_channels) { | 29 void CreateCodec(int num_channels) { |
| 28 codec_inst_.channels = num_channels; | 30 codec_inst_.channels = num_channels; |
| 29 encoder_.reset(new AudioEncoderMutableOpus(codec_inst_)); | 31 encoder_.reset(new AudioEncoderOpus(codec_inst_)); |
| 30 auto expected_app = | 32 auto expected_app = |
| 31 num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio; | 33 num_channels == 1 ? AudioEncoderOpus::kVoip : AudioEncoderOpus::kAudio; |
| 32 EXPECT_EQ(expected_app, encoder_->application()); | 34 EXPECT_EQ(expected_app, encoder_->application()); |
| 33 } | 35 } |
| 34 | 36 |
| 35 CodecInst codec_inst_; | 37 CodecInst codec_inst_; |
| 36 rtc::scoped_ptr<AudioEncoderMutableOpus> encoder_; | 38 rtc::scoped_ptr<AudioEncoderOpus> encoder_; |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeMono) { | 41 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeMono) { |
| 40 CreateCodec(1); | 42 CreateCodec(1); |
| 41 } | 43 } |
| 42 | 44 |
| 43 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeStereo) { | 45 TEST_F(AudioEncoderMutableOpusTest, DefaultApplicationModeStereo) { |
| 44 CreateCodec(2); | 46 CreateCodec(2); |
| 45 } | 47 } |
| 46 | 48 |
| 47 TEST_F(AudioEncoderMutableOpusTest, ChangeApplicationMode) { | 49 TEST_F(AudioEncoderMutableOpusTest, ChangeApplicationMode) { |
| 48 CreateCodec(2); | 50 CreateCodec(2); |
| 49 EXPECT_TRUE( | 51 EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech)); |
| 50 encoder_->SetApplication(AudioEncoderMutable::kApplicationSpeech)); | |
| 51 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | 52 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); |
| 52 } | 53 } |
| 53 | 54 |
| 54 TEST_F(AudioEncoderMutableOpusTest, ResetWontChangeApplicationMode) { | 55 TEST_F(AudioEncoderMutableOpusTest, ResetWontChangeApplicationMode) { |
| 55 CreateCodec(2); | 56 CreateCodec(2); |
| 56 | 57 |
| 57 // Trigger a reset. | 58 // Trigger a reset. |
| 58 encoder_->Reset(); | 59 encoder_->Reset(); |
| 59 // Verify that the mode is still kAudio. | 60 // Verify that the mode is still kAudio. |
| 60 EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application()); | 61 EXPECT_EQ(AudioEncoderOpus::kAudio, encoder_->application()); |
| 61 | 62 |
| 62 // Now change to kVoip. | 63 // Now change to kVoip. |
| 63 EXPECT_TRUE( | 64 EXPECT_TRUE(encoder_->SetApplication(AudioEncoder::Application::kSpeech)); |
| 64 encoder_->SetApplication(AudioEncoderMutable::kApplicationSpeech)); | |
| 65 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | 65 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); |
| 66 | 66 |
| 67 // Trigger a reset again. | 67 // Trigger a reset again. |
| 68 encoder_->Reset(); | 68 encoder_->Reset(); |
| 69 // Verify that the mode is still kVoip. | 69 // Verify that the mode is still kVoip. |
| 70 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); | 70 EXPECT_EQ(AudioEncoderOpus::kVoip, encoder_->application()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST_F(AudioEncoderMutableOpusTest, ToggleDtx) { | 73 TEST_F(AudioEncoderMutableOpusTest, ToggleDtx) { |
| 74 CreateCodec(2); | 74 CreateCodec(2); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 100 // Set rates from 1000 up to 32000 bps. | 100 // Set rates from 1000 up to 32000 bps. |
| 101 for (int rate = 1000; rate <= 32000; rate += 1000) { | 101 for (int rate = 1000; rate <= 32000; rate += 1000) { |
| 102 encoder_->SetTargetBitrate(rate); | 102 encoder_->SetTargetBitrate(rate); |
| 103 EXPECT_EQ(rate, encoder_->GetTargetBitrate()); | 103 EXPECT_EQ(rate, encoder_->GetTargetBitrate()); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 #endif // WEBRTC_CODEC_OPUS | 106 #endif // WEBRTC_CODEC_OPUS |
| 107 | 107 |
| 108 } // namespace acm2 | 108 } // namespace acm2 |
| 109 } // namespace webrtc | 109 } // namespace webrtc |
| OLD | NEW |