blob: 7d277852a0a853aae0abaf6dd0e49080fe8ff86d [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"
peaha9cc40b2017-06-29 08:32:09 -070016#include "webrtc/modules/audio_processing/include/audio_processing.h"
kwibergac9f8762016-09-30 22:29:43 -070017#include "webrtc/test/gtest.h"
turaj@webrtc.org42259e72012-12-11 02:15:12 +000018#include "webrtc/voice_engine/include/voe_base.h"
turaj@webrtc.org42259e72012-12-11 02:15:12 +000019#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);
peaha9cc40b2017-06-29 08:32:09 -070083 std::unique_ptr<AudioProcessing> apm(AudioProcessing::Create());
ivoc85228d62016-07-27 04:53:47 -070084
peaha9cc40b2017-06-29 08:32:09 -070085 base->Init(adm.get(), apm.get());
ivoc85228d62016-07-27 04:53:47 -070086
87 CodecInst codec = {111, "opus", 48000, 960, 1, 32000};
88
89 int channel = base->CreateChannel();
90
91 bool DTX = false;
92
93 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, codec));
94 EXPECT_EQ(0, voe_codec->SetOpusDtx(channel, true));
95 EXPECT_EQ(0, voe_codec->SetFECStatus(channel, true));
96 EXPECT_EQ(0, voe_codec->GetOpusDtxStatus(channel, &DTX));
97 EXPECT_TRUE(DTX);
98
99 base->DeleteChannel(channel);
100 base->Terminate();
101 base->Release();
102 voe_codec->Release();
103 VoiceEngine::Delete(voe);
104}
105
turaj@webrtc.org42259e72012-12-11 02:15:12 +0000106} // namespace
107} // namespace voe
108} // namespace webrtc