OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/voice_engine/include/voe_codec.h" | 13 #include "webrtc/voice_engine/include/voe_codec.h" |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/modules/audio_device/include/fake_audio_device.h" | 16 #include "webrtc/modules/audio_device/include/fake_audio_device.h" |
17 #include "webrtc/voice_engine/include/voe_base.h" | 17 #include "webrtc/voice_engine/include/voe_base.h" |
18 #include "webrtc/voice_engine/include/voe_hardware.h" | 18 #include "webrtc/voice_engine/include/voe_hardware.h" |
19 #include "webrtc/voice_engine/voice_engine_defines.h" | 19 #include "webrtc/voice_engine/voice_engine_defines.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 namespace voe { | 22 namespace voe { |
23 namespace { | 23 namespace { |
24 | 24 |
25 class VoECodecTest : public ::testing::Test { | |
26 protected: | |
27 VoECodecTest() | |
28 : voe_(VoiceEngine::Create()), | |
29 base_(VoEBase::GetInterface(voe_)), | |
30 voe_codec_(VoECodec::GetInterface(voe_)), | |
31 channel_(-1), | |
32 adm_(new FakeAudioDeviceModule), | |
33 red_payload_type_(-1) {} | |
34 | |
35 ~VoECodecTest() {} | |
36 | |
37 void TearDown() { | |
38 base_->DeleteChannel(channel_); | |
39 base_->Terminate(); | |
40 base_->Release(); | |
41 voe_codec_->Release(); | |
42 VoiceEngine::Delete(voe_); | |
43 } | |
44 | |
45 void SetUp() { | |
46 // Check if all components are valid. | |
47 ASSERT_TRUE(voe_ != NULL); | |
48 ASSERT_TRUE(base_ != NULL); | |
49 ASSERT_TRUE(voe_codec_ != NULL); | |
50 ASSERT_TRUE(adm_.get() != NULL); | |
51 ASSERT_EQ(0, base_->Init(adm_.get())); | |
52 channel_ = base_->CreateChannel(); | |
53 ASSERT_NE(-1, channel_); | |
54 | |
55 CodecInst my_codec; | |
56 | |
57 bool primary_found = false; | |
58 bool valid_secondary_found = false; | |
59 bool invalid_secondary_found = false; | |
60 | |
61 // Find primary and secondary codecs. | |
62 int num_codecs = voe_codec_->NumOfCodecs(); | |
63 int n = 0; | |
64 while (n < num_codecs && | |
65 (!primary_found || !valid_secondary_found || | |
66 !invalid_secondary_found || red_payload_type_ < 0)) { | |
67 EXPECT_EQ(0, voe_codec_->GetCodec(n, my_codec)); | |
68 if (!STR_CASE_CMP(my_codec.plname, "isac") && my_codec.plfreq == 16000) { | |
69 memcpy(&valid_secondary_, &my_codec, sizeof(my_codec)); | |
70 valid_secondary_found = true; | |
71 } else if (!STR_CASE_CMP(my_codec.plname, "isac") && | |
72 my_codec.plfreq == 32000) { | |
73 memcpy(&invalid_secondary_, &my_codec, sizeof(my_codec)); | |
74 invalid_secondary_found = true; | |
75 } else if (!STR_CASE_CMP(my_codec.plname, "L16") && | |
76 my_codec.plfreq == 16000) { | |
77 memcpy(&primary_, &my_codec, sizeof(my_codec)); | |
78 primary_found = true; | |
79 } else if (!STR_CASE_CMP(my_codec.plname, "RED")) { | |
80 red_payload_type_ = my_codec.pltype; | |
81 } | |
82 n++; | |
83 } | |
84 | |
85 EXPECT_TRUE(primary_found); | |
86 EXPECT_TRUE(valid_secondary_found); | |
87 EXPECT_TRUE(invalid_secondary_found); | |
88 EXPECT_NE(-1, red_payload_type_); | |
89 } | |
90 | |
91 VoiceEngine* voe_; | |
92 VoEBase* base_; | |
93 VoECodec* voe_codec_; | |
94 int channel_; | |
95 CodecInst primary_; | |
96 CodecInst valid_secondary_; | |
97 std::unique_ptr<FakeAudioDeviceModule> adm_; | |
98 | |
99 // A codec which is not valid to be registered as secondary codec. | |
100 CodecInst invalid_secondary_; | |
101 int red_payload_type_; | |
102 }; | |
103 | |
104 TEST(VoECodecInst, TestCompareCodecInstances) { | 25 TEST(VoECodecInst, TestCompareCodecInstances) { |
105 CodecInst codec1, codec2; | 26 CodecInst codec1, codec2; |
106 memset(&codec1, 0, sizeof(CodecInst)); | 27 memset(&codec1, 0, sizeof(CodecInst)); |
107 memset(&codec2, 0, sizeof(CodecInst)); | 28 memset(&codec2, 0, sizeof(CodecInst)); |
108 | 29 |
109 codec1.pltype = 101; | 30 codec1.pltype = 101; |
110 strncpy(codec1.plname, "isac", 4); | 31 strncpy(codec1.plname, "isac", 4); |
111 codec1.plfreq = 8000; | 32 codec1.plfreq = 8000; |
112 codec1.pacsize = 110; | 33 codec1.pacsize = 110; |
113 codec1.channels = 1; | 34 codec1.channels = 1; |
(...skipping 30 matching lines...) Expand all Loading... |
144 codec2.channels = 2; | 65 codec2.channels = 2; |
145 EXPECT_FALSE(codec1 == codec2); | 66 EXPECT_FALSE(codec1 == codec2); |
146 | 67 |
147 // Reset to codec2 to codec1 state. | 68 // Reset to codec2 to codec1 state. |
148 memcpy(&codec2, &codec1, sizeof(CodecInst)); | 69 memcpy(&codec2, &codec1, sizeof(CodecInst)); |
149 // Test modifying the |rate|. | 70 // Test modifying the |rate|. |
150 codec2.rate = 0; | 71 codec2.rate = 0; |
151 EXPECT_FALSE(codec1 == codec2); | 72 EXPECT_FALSE(codec1 == codec2); |
152 } | 73 } |
153 | 74 |
| 75 // This is a regression test for |
| 76 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6020 |
| 77 // The Opus DTX setting was being forgotten after unrelated VoE calls. |
| 78 TEST(VoECodecInst, RememberOpusDtxAfterSettingChange) { |
| 79 VoiceEngine* voe(VoiceEngine::Create()); |
| 80 VoEBase* base(VoEBase::GetInterface(voe)); |
| 81 VoECodec* voe_codec(VoECodec::GetInterface(voe)); |
| 82 std::unique_ptr<FakeAudioDeviceModule> adm(new FakeAudioDeviceModule); |
| 83 |
| 84 base->Init(adm.get()); |
| 85 |
| 86 CodecInst codec = {111, "opus", 48000, 960, 1, 32000}; |
| 87 |
| 88 int channel = base->CreateChannel(); |
| 89 |
| 90 bool DTX = false; |
| 91 |
| 92 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, codec)); |
| 93 EXPECT_EQ(0, voe_codec->SetOpusDtx(channel, true)); |
| 94 EXPECT_EQ(0, voe_codec->SetFECStatus(channel, true)); |
| 95 EXPECT_EQ(0, voe_codec->GetOpusDtx(channel, &DTX)); |
| 96 EXPECT_TRUE(DTX); |
| 97 |
| 98 base->DeleteChannel(channel); |
| 99 base->Terminate(); |
| 100 base->Release(); |
| 101 voe_codec->Release(); |
| 102 VoiceEngine::Delete(voe); |
| 103 } |
| 104 |
154 } // namespace | 105 } // namespace |
155 } // namespace voe | 106 } // namespace voe |
156 } // namespace webrtc | 107 } // namespace webrtc |
OLD | NEW |