niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
andrew@webrtc.org | 9dc45da | 2012-05-23 15:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/main/test/iSACTest.h" |
| 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <ctype.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | |
| 17 | #if _WIN32 |
| 18 | #include <windows.h> |
| 19 | #elif WEBRTC_LINUX |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 20 | #include <time.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #else |
| 22 | #include <sys/time.h> |
| 23 | #include <time.h> |
| 24 | #endif |
| 25 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 26 | #include "webrtc/modules/audio_coding/main/source/acm_common_defs.h" |
| 27 | #include "webrtc/modules/audio_coding/main/test/utility.h" |
| 28 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 29 | #include "webrtc/system_wrappers/interface/tick_util.h" |
| 30 | #include "webrtc/system_wrappers/interface/trace.h" |
| 31 | #include "webrtc/test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 33 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 35 | void SetISACConfigDefault(ACMTestISACConfig& isacConfig) { |
| 36 | isacConfig.currentRateBitPerSec = 0; |
| 37 | isacConfig.currentFrameSizeMsec = 0; |
| 38 | isacConfig.maxRateBitPerSec = 0; |
| 39 | isacConfig.maxPayloadSizeByte = 0; |
| 40 | isacConfig.encodingMode = -1; |
| 41 | isacConfig.initRateBitPerSec = 0; |
| 42 | isacConfig.initFrameSizeInMsec = 0; |
| 43 | isacConfig.enforceFrameSize = false; |
| 44 | return; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | } |
| 46 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 47 | int16_t SetISAConfig(ACMTestISACConfig& isacConfig, AudioCodingModule* acm, |
| 48 | int testMode) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 50 | if ((isacConfig.currentRateBitPerSec != 0) |
| 51 | || (isacConfig.currentFrameSizeMsec != 0)) { |
| 52 | CodecInst sendCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 53 | EXPECT_EQ(0, acm->SendCodec(&sendCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 54 | if (isacConfig.currentRateBitPerSec < 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 55 | // Register iSAC in adaptive (channel-dependent) mode. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 56 | sendCodec.rate = -1; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 57 | EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 58 | } else { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 59 | if (isacConfig.currentRateBitPerSec != 0) { |
| 60 | sendCodec.rate = isacConfig.currentRateBitPerSec; |
| 61 | } |
| 62 | if (isacConfig.currentFrameSizeMsec != 0) { |
| 63 | sendCodec.pacsize = isacConfig.currentFrameSizeMsec |
| 64 | * (sendCodec.plfreq / 1000); |
| 65 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 66 | EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 68 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 70 | if (isacConfig.maxRateBitPerSec > 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 71 | // Set max rate. |
| 72 | EXPECT_EQ(0, acm->SetISACMaxRate(isacConfig.maxRateBitPerSec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 73 | } |
| 74 | if (isacConfig.maxPayloadSizeByte > 0) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 75 | // Set max payload size. |
| 76 | EXPECT_EQ(0, acm->SetISACMaxPayloadSize(isacConfig.maxPayloadSizeByte)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 77 | } |
| 78 | if ((isacConfig.initFrameSizeInMsec != 0) |
| 79 | || (isacConfig.initRateBitPerSec != 0)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 80 | EXPECT_EQ(0, acm->ConfigISACBandwidthEstimator( |
| 81 | static_cast<uint8_t>(isacConfig.initFrameSizeInMsec), |
| 82 | static_cast<uint16_t>(isacConfig.initRateBitPerSec), |
| 83 | isacConfig.enforceFrameSize)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 84 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 86 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | } |
| 88 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 89 | ISACTest::ISACTest(int testMode) { |
| 90 | _testMode = testMode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 93 | ISACTest::~ISACTest() { |
| 94 | AudioCodingModule::Destroy(_acmA); |
| 95 | AudioCodingModule::Destroy(_acmB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 97 | delete _channel_A2B; |
| 98 | delete _channel_B2A; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 101 | void ISACTest::Setup() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 102 | int codecCntr; |
| 103 | CodecInst codecParam; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 105 | _acmA = AudioCodingModule::Create(1); |
| 106 | _acmB = AudioCodingModule::Create(2); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 108 | for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs(); |
| 109 | codecCntr++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 110 | EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 111 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 112 | && codecParam.plfreq == 16000) { |
| 113 | memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst)); |
| 114 | _idISAC16kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 116 | if (!STR_CASE_CMP(codecParam.plname, "ISAC") |
| 117 | && codecParam.plfreq == 32000) { |
| 118 | memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst)); |
| 119 | _idISAC32kHz = codecCntr; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 121 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 123 | // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. |
| 124 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC16kHz)); |
| 125 | EXPECT_EQ(0, _acmA->RegisterReceiveCodec(_paramISAC32kHz)); |
| 126 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC16kHz)); |
| 127 | EXPECT_EQ(0, _acmB->RegisterReceiveCodec(_paramISAC32kHz)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 129 | //--- Set A-to-B channel |
| 130 | _channel_A2B = new Channel; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 131 | EXPECT_EQ(0, _acmA->RegisterTransportCallback(_channel_A2B)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 132 | _channel_A2B->RegisterReceiverACM(_acmB); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 134 | //--- Set B-to-A channel |
| 135 | _channel_B2A = new Channel; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 136 | EXPECT_EQ(0, _acmB->RegisterTransportCallback(_channel_B2A)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 137 | _channel_B2A->RegisterReceiverACM(_acmA); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 139 | file_name_swb_ = webrtc::test::ResourcePath("audio_coding/testfile32kHz", |
| 140 | "pcm"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 142 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
| 143 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 144 | |
| 145 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 146 | std::string fileNameA = webrtc::test::OutputPath() + "testisac_a.pcm"; |
| 147 | std::string fileNameB = webrtc::test::OutputPath() + "testisac_b.pcm"; |
| 148 | _outFileA.Open(fileNameA, 32000, "wb"); |
| 149 | _outFileB.Open(fileNameB, 32000, "wb"); |
| 150 | |
| 151 | while (!_inFileA.EndOfFile()) { |
| 152 | Run10ms(); |
| 153 | } |
| 154 | CodecInst receiveCodec; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 155 | EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); |
| 156 | EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 157 | |
| 158 | _inFileA.Close(); |
| 159 | _outFileA.Close(); |
| 160 | _outFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | } |
| 162 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 163 | void ISACTest::Perform() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 164 | Setup(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 166 | int16_t testNr = 0; |
| 167 | ACMTestISACConfig wbISACConfig; |
| 168 | ACMTestISACConfig swbISACConfig; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 170 | SetISACConfigDefault(wbISACConfig); |
| 171 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 173 | wbISACConfig.currentRateBitPerSec = -1; |
| 174 | swbISACConfig.currentRateBitPerSec = -1; |
| 175 | testNr++; |
| 176 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 177 | |
| 178 | if (_testMode != 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | SetISACConfigDefault(wbISACConfig); |
| 180 | SetISACConfigDefault(swbISACConfig); |
| 181 | |
| 182 | wbISACConfig.currentRateBitPerSec = -1; |
| 183 | swbISACConfig.currentRateBitPerSec = -1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 184 | wbISACConfig.initRateBitPerSec = 13000; |
| 185 | wbISACConfig.initFrameSizeInMsec = 60; |
| 186 | swbISACConfig.initRateBitPerSec = 20000; |
| 187 | swbISACConfig.initFrameSizeInMsec = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | testNr++; |
| 189 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 190 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | SetISACConfigDefault(wbISACConfig); |
| 192 | SetISACConfigDefault(swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 193 | |
| 194 | wbISACConfig.currentRateBitPerSec = 20000; |
| 195 | swbISACConfig.currentRateBitPerSec = 48000; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 196 | testNr++; |
| 197 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 198 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 199 | wbISACConfig.currentRateBitPerSec = 16000; |
| 200 | swbISACConfig.currentRateBitPerSec = 30000; |
| 201 | wbISACConfig.currentFrameSizeMsec = 60; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 202 | testNr++; |
| 203 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 204 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 205 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 206 | SetISACConfigDefault(wbISACConfig); |
| 207 | SetISACConfigDefault(swbISACConfig); |
| 208 | testNr++; |
| 209 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 211 | int user_input; |
| 212 | if ((_testMode == 0) || (_testMode == 1)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 213 | swbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200); |
| 214 | wbISACConfig.maxPayloadSizeByte = static_cast<uint16_t>(200); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 215 | } else { |
| 216 | printf("Enter the max payload-size for side A: "); |
| 217 | CHECK_ERROR(scanf("%d", &user_input)); |
| 218 | swbISACConfig.maxPayloadSizeByte = (uint16_t) user_input; |
| 219 | printf("Enter the max payload-size for side B: "); |
| 220 | CHECK_ERROR(scanf("%d", &user_input)); |
| 221 | wbISACConfig.maxPayloadSizeByte = (uint16_t) user_input; |
| 222 | } |
| 223 | testNr++; |
| 224 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 225 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 226 | _acmA->ResetEncoder(); |
| 227 | _acmB->ResetEncoder(); |
| 228 | SetISACConfigDefault(wbISACConfig); |
| 229 | SetISACConfigDefault(swbISACConfig); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 231 | if ((_testMode == 0) || (_testMode == 1)) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 232 | swbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000); |
| 233 | wbISACConfig.maxRateBitPerSec = static_cast<uint32_t>(48000); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 234 | } else { |
| 235 | printf("Enter the max rate for side A: "); |
| 236 | CHECK_ERROR(scanf("%d", &user_input)); |
| 237 | swbISACConfig.maxRateBitPerSec = (uint32_t) user_input; |
| 238 | printf("Enter the max rate for side B: "); |
| 239 | CHECK_ERROR(scanf("%d", &user_input)); |
| 240 | wbISACConfig.maxRateBitPerSec = (uint32_t) user_input; |
| 241 | } |
| 242 | |
| 243 | testNr++; |
| 244 | EncodeDecode(testNr, wbISACConfig, swbISACConfig); |
| 245 | |
| 246 | testNr++; |
| 247 | if (_testMode == 0) { |
| 248 | SwitchingSamplingRate(testNr, 4); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 249 | } else { |
| 250 | SwitchingSamplingRate(testNr, 80); |
| 251 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | } |
| 253 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 254 | void ISACTest::Run10ms() { |
| 255 | AudioFrame audioFrame; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 256 | EXPECT_GT(_inFileA.Read10MsData(audioFrame), 0); |
| 257 | EXPECT_EQ(0, _acmA->Add10MsData(audioFrame)); |
| 258 | EXPECT_EQ(0, _acmB->Add10MsData(audioFrame)); |
| 259 | EXPECT_GT(_acmA->Process(), -1); |
| 260 | EXPECT_GT(_acmB->Process(), -1); |
| 261 | EXPECT_EQ(0, _acmA->PlayoutData10Ms(32000, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 262 | _outFileA.Write10MsData(audioFrame); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 263 | EXPECT_EQ(0, _acmB->PlayoutData10Ms(32000, &audioFrame)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 264 | _outFileB.Write10MsData(audioFrame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 267 | void ISACTest::EncodeDecode(int testNr, ACMTestISACConfig& wbISACConfig, |
| 268 | ACMTestISACConfig& swbISACConfig) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 269 | // Files in Side A and B |
| 270 | _inFileA.Open(file_name_swb_, 32000, "rb", true); |
| 271 | _inFileB.Open(file_name_swb_, 32000, "rb", true); |
| 272 | |
| 273 | std::string file_name_out; |
| 274 | std::stringstream file_stream_a; |
| 275 | std::stringstream file_stream_b; |
| 276 | file_stream_a << webrtc::test::OutputPath(); |
| 277 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 278 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 279 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 280 | file_name_out = file_stream_a.str(); |
| 281 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 282 | file_name_out = file_stream_b.str(); |
| 283 | _outFileB.Open(file_name_out, 32000, "wb"); |
| 284 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 285 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
| 286 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 287 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
| 288 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 289 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 290 | // Side A is sending super-wideband, and side B is sending wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 291 | SetISAConfig(swbISACConfig, _acmA, _testMode); |
| 292 | SetISAConfig(wbISACConfig, _acmB, _testMode); |
| 293 | |
| 294 | bool adaptiveMode = false; |
| 295 | if ((swbISACConfig.currentRateBitPerSec == -1) |
| 296 | || (wbISACConfig.currentRateBitPerSec == -1)) { |
| 297 | adaptiveMode = true; |
| 298 | } |
| 299 | _myTimer.Reset(); |
| 300 | _channel_A2B->ResetStats(); |
| 301 | _channel_B2A->ResetStats(); |
| 302 | |
| 303 | char currentTime[500]; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 304 | CodecInst sendCodec; |
| 305 | EventWrapper* myEvent = EventWrapper::Create(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 306 | EXPECT_TRUE(myEvent->StartTimer(true, 10)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 307 | while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { |
| 308 | Run10ms(); |
| 309 | _myTimer.Tick10ms(); |
| 310 | _myTimer.CurrentTimeHMS(currentTime); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 311 | |
| 312 | if ((adaptiveMode) && (_testMode != 0)) { |
| 313 | myEvent->Wait(5000); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 314 | EXPECT_EQ(0, _acmA->SendCodec(&sendCodec)); |
| 315 | EXPECT_EQ(0, _acmB->SendCodec(&sendCodec)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 316 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 317 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 318 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 319 | if (_testMode != 0) { |
| 320 | printf("\n\nSide A statistics\n\n"); |
| 321 | _channel_A2B->PrintStats(_paramISAC32kHz); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 322 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 323 | printf("\n\nSide B statistics\n\n"); |
| 324 | _channel_B2A->PrintStats(_paramISAC16kHz); |
| 325 | } |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 326 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 327 | _channel_A2B->ResetStats(); |
| 328 | _channel_B2A->ResetStats(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 329 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 330 | _outFileA.Close(); |
| 331 | _outFileB.Close(); |
| 332 | _inFileA.Close(); |
| 333 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 334 | } |
| 335 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 336 | void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) { |
| 337 | // Files in Side A |
| 338 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
| 339 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 340 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 341 | std::string file_name_out; |
| 342 | std::stringstream file_stream_a; |
| 343 | std::stringstream file_stream_b; |
| 344 | file_stream_a << webrtc::test::OutputPath(); |
| 345 | file_stream_b << webrtc::test::OutputPath(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 346 | file_stream_a << "out_iSACTest_A_" << testNr << ".pcm"; |
| 347 | file_stream_b << "out_iSACTest_B_" << testNr << ".pcm"; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 348 | file_name_out = file_stream_a.str(); |
| 349 | _outFileA.Open(file_name_out, 32000, "wb"); |
| 350 | file_name_out = file_stream_b.str(); |
| 351 | _outFileB.Open(file_name_out, 32000, "wb"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 352 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 353 | // Start with side A sending super-wideband and side B seding wideband. |
| 354 | // Toggle sending wideband/super-wideband in this test. |
| 355 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
| 356 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 357 | |
| 358 | int numSendCodecChanged = 0; |
| 359 | _myTimer.Reset(); |
| 360 | char currentTime[50]; |
| 361 | while (numSendCodecChanged < (maxSampRateChange << 1)) { |
| 362 | Run10ms(); |
| 363 | _myTimer.Tick10ms(); |
| 364 | _myTimer.CurrentTimeHMS(currentTime); |
| 365 | if (_testMode == 2) |
| 366 | printf("\r%s", currentTime); |
| 367 | if (_inFileA.EndOfFile()) { |
| 368 | if (_inFileA.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 369 | // Switch side A to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 370 | _inFileA.Close(); |
| 371 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 372 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 373 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 374 | // Switch side A to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 375 | _inFileA.Close(); |
| 376 | _inFileA.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 377 | EXPECT_EQ(0, _acmA->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 378 | } |
| 379 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 380 | } |
| 381 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 382 | if (_inFileB.EndOfFile()) { |
| 383 | if (_inFileB.SamplingFrequency() == 16000) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 384 | // Switch side B to send super-wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 385 | _inFileB.Close(); |
| 386 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 387 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC32kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 388 | } else { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 389 | // Switch side B to send wideband. |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 390 | _inFileB.Close(); |
| 391 | _inFileB.Open(file_name_swb_, 32000, "rb"); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 392 | EXPECT_EQ(0, _acmB->RegisterSendCodec(_paramISAC16kHz)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 393 | } |
| 394 | numSendCodecChanged++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 395 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 396 | } |
| 397 | _outFileA.Close(); |
| 398 | _outFileB.Close(); |
| 399 | _inFileA.Close(); |
| 400 | _inFileB.Close(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 401 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 402 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 403 | } // namespace webrtc |