1 /*
2 * Copyright (c) 2011 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
11 #include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
12
13 class CodecBeforeStreamingTest : public AfterInitializationFixture {
14 protected:
SetUp()15 void SetUp() {
16 memset(&codec_instance_, 0, sizeof(codec_instance_));
17 codec_instance_.channels = 1;
18 codec_instance_.plfreq = 16000;
19 codec_instance_.pacsize = 480;
20
21 channel_ = voe_base_->CreateChannel();
22 }
23
TearDown()24 void TearDown() {
25 voe_base_->DeleteChannel(channel_);
26 }
27
28 webrtc::CodecInst codec_instance_;
29 int channel_;
30 };
31
32 // TODO(phoglund): add test which verifies default pltypes for various codecs.
33
TEST_F(CodecBeforeStreamingTest,GetRecPayloadTypeFailsForInvalidCodecName)34 TEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeFailsForInvalidCodecName) {
35 strcpy(codec_instance_.plname, "SomeInvalidCodecName");
36
37 // Should fail since the codec name is invalid.
38 EXPECT_NE(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
39 }
40
TEST_F(CodecBeforeStreamingTest,GetRecPayloadTypeRecognizesISAC)41 TEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeRecognizesISAC) {
42 strcpy(codec_instance_.plname, "iSAC");
43 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
44 strcpy(codec_instance_.plname, "ISAC");
45 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
46 }
47
TEST_F(CodecBeforeStreamingTest,SetRecPayloadTypeCanChangeISACPayloadType)48 TEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeISACPayloadType) {
49 strcpy(codec_instance_.plname, "ISAC");
50 codec_instance_.rate = 32000;
51
52 codec_instance_.pltype = 123;
53 EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
54 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
55 EXPECT_EQ(123, codec_instance_.pltype);
56
57 codec_instance_.pltype = 104;
58 EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
59 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
60
61 EXPECT_EQ(104, codec_instance_.pltype);
62 }
63
TEST_F(CodecBeforeStreamingTest,SetRecPayloadTypeCanChangeILBCPayloadType)64 TEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeILBCPayloadType) {
65 strcpy(codec_instance_.plname, "iLBC");
66 codec_instance_.plfreq = 8000;
67 codec_instance_.pacsize = 240;
68 codec_instance_.rate = 13300;
69
70 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
71 int original_pltype = codec_instance_.pltype;
72 codec_instance_.pltype = 123;
73 EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
74 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
75
76 EXPECT_EQ(123, codec_instance_.pltype);
77
78 codec_instance_.pltype = original_pltype;
79 EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
80 EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
81
82 EXPECT_EQ(original_pltype, codec_instance_.pltype);
83 }
84