1610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org/*
2610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *
4610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  Use of this source code is governed by a BSD-style license
5610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  that can be found in the LICENSE file in the root of the source
6610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  tree. An additional intellectual property rights grant can be found
7610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  in the file PATENTS.  All contributing project authors may
8610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
9610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org */
10610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
11956aa7e0874f2e08c335a82a2c32f400fac8b031pbos@webrtc.org#include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
12610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
13610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.orgclass CodecBeforeStreamingTest : public AfterInitializationFixture {
14610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org protected:
15610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  void SetUp() {
16610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    memset(&codec_instance_, 0, sizeof(codec_instance_));
17610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    codec_instance_.channels = 1;
18610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    codec_instance_.plfreq = 16000;
19610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    codec_instance_.pacsize = 480;
20610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
21610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    channel_ = voe_base_->CreateChannel();
22610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  }
23610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
24610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  void TearDown() {
25610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org    voe_base_->DeleteChannel(channel_);
26610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  }
27610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
28610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  webrtc::CodecInst codec_instance_;
29610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  int channel_;
30610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org};
31610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
32610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org// TODO(phoglund): add test which verifies default pltypes for various codecs.
33610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
34610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.orgTEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeFailsForInvalidCodecName) {
35610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  strcpy(codec_instance_.plname, "SomeInvalidCodecName");
36610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
37610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  // Should fail since the codec name is invalid.
38610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_NE(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
39610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org}
40610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
41610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.orgTEST_F(CodecBeforeStreamingTest, GetRecPayloadTypeRecognizesISAC) {
42610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  strcpy(codec_instance_.plname, "iSAC");
43610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
44610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  strcpy(codec_instance_.plname, "ISAC");
45610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
46610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org}
47610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
48610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.orgTEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeISACPayloadType) {
49610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  strcpy(codec_instance_.plname, "ISAC");
50a671f4b2cb7532fa2a09beb5eb91659958799ee8henrik.lundin@webrtc.org  codec_instance_.rate = 32000;
51610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
52610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.pltype = 123;
53610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
54610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
55610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(123, codec_instance_.pltype);
56610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
57610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.pltype = 104;
58610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
59610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
60610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
61610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(104, codec_instance_.pltype);
62610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org}
63610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
64610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.orgTEST_F(CodecBeforeStreamingTest, SetRecPayloadTypeCanChangeILBCPayloadType) {
65610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  strcpy(codec_instance_.plname, "iLBC");
66610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.plfreq = 8000;
67610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.pacsize = 240;
68610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.rate = 13300;
69610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
70610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
71610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  int original_pltype = codec_instance_.pltype;
72610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.pltype = 123;
73610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
74610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
75610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
76610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(123, codec_instance_.pltype);
77610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
78610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  codec_instance_.pltype = original_pltype;
79610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->SetRecPayloadType(channel_, codec_instance_));
80610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(0, voe_codec_->GetRecPayloadType(channel_, codec_instance_));
81610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org
82610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org  EXPECT_EQ(original_pltype, codec_instance_.pltype);
83610e90e9103731155fc1276ebd62ee9691933fa2phoglund@webrtc.org}
84