blob: af04a613081e8690ff7c4050deddc08ae576ac38 [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
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000015#include "webrtc/modules/audio_device/include/fake_audio_device.h"
kwibergac9f8762016-09-30 22:29:43 -070016#include "webrtc/test/gtest.h"
turaj@webrtc.org42259e72012-12-11 02:15:12 +000017#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org42259e72012-12-11 02:15:12 +000018#include "webrtc/voice_engine/voice_engine_defines.h"
19
20namespace webrtc {
21namespace voe {
22namespace {
23
mallinath@webrtc.org0209e562014-03-21 00:41:28 +000024TEST(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
ivoc85228d62016-07-27 04:53:47 -070074// 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.
77TEST(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.org42259e72012-12-11 02:15:12 +0000104} // namespace
105} // namespace voe
106} // namespace webrtc