blob: acef75a9a821a50eb98fb950af39785980bd30a2 [file] [log] [blame]
turaj@webrtc.org42259e72012-12-11 02:15:12 +00001/*
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
kwibergb7f89d62016-02-17 10:04:18 -080011#include <memory>
12
turaj@webrtc.org42259e72012-12-11 02:15:12 +000013#include "webrtc/voice_engine/include/voe_codec.h"
14
kwiberg77eab702016-09-28 17:42:01 -070015#include "webrtc/test/gtest.h"
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000016#include "webrtc/modules/audio_device/include/fake_audio_device.h"
turaj@webrtc.org42259e72012-12-11 02:15:12 +000017#include "webrtc/voice_engine/include/voe_base.h"
18#include "webrtc/voice_engine/include/voe_hardware.h"
19#include "webrtc/voice_engine/voice_engine_defines.h"
20
21namespace webrtc {
22namespace voe {
23namespace {
24
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000025TEST(VoECodecInst, TestCompareCodecInstances) {
26 CodecInst codec1, codec2;
27 memset(&codec1, 0, sizeof(CodecInst));
28 memset(&codec2, 0, sizeof(CodecInst));
29
30 codec1.pltype = 101;
31 strncpy(codec1.plname, "isac", 4);
32 codec1.plfreq = 8000;
33 codec1.pacsize = 110;
34 codec1.channels = 1;
35 codec1.rate = 8000;
36 memcpy(&codec2, &codec1, sizeof(CodecInst));
37 // Compare two codecs now.
38 EXPECT_TRUE(codec1 == codec2);
39 EXPECT_FALSE(codec1 != codec2);
40
41 // Changing pltype.
42 codec2.pltype = 102;
43 EXPECT_FALSE(codec1 == codec2);
44 EXPECT_TRUE(codec1 != codec2);
45
46 // Reset to codec2 to codec1 state.
47 memcpy(&codec2, &codec1, sizeof(CodecInst));
48 // payload name should be case insensitive.
49 strncpy(codec2.plname, "ISAC", 4);
50 EXPECT_TRUE(codec1 == codec2);
51
52 // Test modifying the |plfreq|
53 codec2.plfreq = 16000;
54 EXPECT_FALSE(codec1 == codec2);
55
56 // Reset to codec2 to codec1 state.
57 memcpy(&codec2, &codec1, sizeof(CodecInst));
58 // Test modifying the |pacsize|.
59 codec2.pacsize = 440;
60 EXPECT_FALSE(codec1 == codec2);
61
62 // Reset to codec2 to codec1 state.
63 memcpy(&codec2, &codec1, sizeof(CodecInst));
64 // Test modifying the |channels|.
65 codec2.channels = 2;
66 EXPECT_FALSE(codec1 == codec2);
67
68 // Reset to codec2 to codec1 state.
69 memcpy(&codec2, &codec1, sizeof(CodecInst));
70 // Test modifying the |rate|.
71 codec2.rate = 0;
72 EXPECT_FALSE(codec1 == codec2);
73}
74
ivoc85228d62016-07-27 04:53:47 -070075// 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.
78TEST(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->GetOpusDtxStatus(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
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000105} // namespace
106} // namespace voe
107} // namespace webrtc