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