turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 13 | #include "webrtc/voice_engine/include/voe_codec.h" |
| 14 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/audio_device/include/fake_audio_device.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 16 | #include "webrtc/test/gtest.h" |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 17 | #include "webrtc/voice_engine/include/voe_base.h" |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 18 | #include "webrtc/voice_engine/voice_engine_defines.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | namespace voe { |
| 22 | namespace { |
| 23 | |
mallinath@webrtc.org | 0209e56 | 2014-03-21 00:41:28 +0000 | [diff] [blame] | 24 | TEST(VoECodecInst, TestCompareCodecInstances) { |
| 25 | CodecInst codec1, codec2; |
| 26 | memset(&codec1, 0, sizeof(CodecInst)); |
| 27 | memset(&codec2, 0, sizeof(CodecInst)); |
| 28 | |
| 29 | codec1.pltype = 101; |
| 30 | strncpy(codec1.plname, "isac", 4); |
| 31 | codec1.plfreq = 8000; |
| 32 | codec1.pacsize = 110; |
| 33 | codec1.channels = 1; |
| 34 | codec1.rate = 8000; |
| 35 | memcpy(&codec2, &codec1, sizeof(CodecInst)); |
| 36 | // Compare two codecs now. |
| 37 | EXPECT_TRUE(codec1 == codec2); |
| 38 | EXPECT_FALSE(codec1 != codec2); |
| 39 | |
| 40 | // Changing pltype. |
| 41 | codec2.pltype = 102; |
| 42 | EXPECT_FALSE(codec1 == codec2); |
| 43 | EXPECT_TRUE(codec1 != codec2); |
| 44 | |
| 45 | // Reset to codec2 to codec1 state. |
| 46 | memcpy(&codec2, &codec1, sizeof(CodecInst)); |
| 47 | // payload name should be case insensitive. |
| 48 | strncpy(codec2.plname, "ISAC", 4); |
| 49 | EXPECT_TRUE(codec1 == codec2); |
| 50 | |
| 51 | // Test modifying the |plfreq| |
| 52 | codec2.plfreq = 16000; |
| 53 | EXPECT_FALSE(codec1 == codec2); |
| 54 | |
| 55 | // Reset to codec2 to codec1 state. |
| 56 | memcpy(&codec2, &codec1, sizeof(CodecInst)); |
| 57 | // Test modifying the |pacsize|. |
| 58 | codec2.pacsize = 440; |
| 59 | EXPECT_FALSE(codec1 == codec2); |
| 60 | |
| 61 | // Reset to codec2 to codec1 state. |
| 62 | memcpy(&codec2, &codec1, sizeof(CodecInst)); |
| 63 | // Test modifying the |channels|. |
| 64 | codec2.channels = 2; |
| 65 | EXPECT_FALSE(codec1 == codec2); |
| 66 | |
| 67 | // Reset to codec2 to codec1 state. |
| 68 | memcpy(&codec2, &codec1, sizeof(CodecInst)); |
| 69 | // Test modifying the |rate|. |
| 70 | codec2.rate = 0; |
| 71 | EXPECT_FALSE(codec1 == codec2); |
| 72 | } |
| 73 | |
ivoc | 85228d6 | 2016-07-27 04:53:47 -0700 | [diff] [blame] | 74 | // This is a regression test for |
| 75 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6020 |
| 76 | // The Opus DTX setting was being forgotten after unrelated VoE calls. |
| 77 | TEST(VoECodecInst, RememberOpusDtxAfterSettingChange) { |
| 78 | VoiceEngine* voe(VoiceEngine::Create()); |
| 79 | VoEBase* base(VoEBase::GetInterface(voe)); |
| 80 | VoECodec* voe_codec(VoECodec::GetInterface(voe)); |
| 81 | std::unique_ptr<FakeAudioDeviceModule> adm(new FakeAudioDeviceModule); |
| 82 | |
| 83 | base->Init(adm.get()); |
| 84 | |
| 85 | CodecInst codec = {111, "opus", 48000, 960, 1, 32000}; |
| 86 | |
| 87 | int channel = base->CreateChannel(); |
| 88 | |
| 89 | bool DTX = false; |
| 90 | |
| 91 | EXPECT_EQ(0, voe_codec->SetSendCodec(channel, codec)); |
| 92 | EXPECT_EQ(0, voe_codec->SetOpusDtx(channel, true)); |
| 93 | EXPECT_EQ(0, voe_codec->SetFECStatus(channel, true)); |
| 94 | EXPECT_EQ(0, voe_codec->GetOpusDtxStatus(channel, &DTX)); |
| 95 | EXPECT_TRUE(DTX); |
| 96 | |
| 97 | base->DeleteChannel(channel); |
| 98 | base->Terminate(); |
| 99 | base->Release(); |
| 100 | voe_codec->Release(); |
| 101 | VoiceEngine::Delete(voe); |
| 102 | } |
| 103 | |
turaj@webrtc.org | 42259e7 | 2012-12-11 02:15:12 +0000 | [diff] [blame] | 104 | } // namespace |
| 105 | } // namespace voe |
| 106 | } // namespace webrtc |