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