niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tina.legrand@webrtc.org | ae1c454 | 2012-03-12 08:41:30 +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 | |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 11 | #include "webrtc/modules/audio_coding/test/EncodeDecodeTest.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 13 | #include <memory> |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 14 | #include <sstream> |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 15 | #include <stdio.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | #include <stdlib.h> |
tina.legrand@webrtc.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 17 | |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 18 | #include "webrtc/common_types.h" |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 19 | #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 20 | #include "webrtc/modules/audio_coding/codecs/audio_format_conversion.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 21 | #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
kjellander | 3e6db23 | 2015-11-26 04:44:54 -0800 | [diff] [blame] | 22 | #include "webrtc/modules/audio_coding/test/utility.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 23 | #include "webrtc/system_wrappers/include/trace.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 24 | #include "webrtc/test/gtest.h" |
tina.legrand@webrtc.org | 73222cf | 2013-03-15 13:29:17 +0000 | [diff] [blame] | 25 | #include "webrtc/test/testsupport/fileutils.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 27 | namespace webrtc { |
| 28 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 29 | TestPacketization::TestPacketization(RTPStream *rtpStream, uint16_t frequency) |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 30 | : _rtpStream(rtpStream), |
| 31 | _frequency(frequency), |
| 32 | _seqNo(0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | } |
| 34 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 35 | TestPacketization::~TestPacketization() { |
| 36 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 38 | int32_t TestPacketization::SendData( |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 39 | const FrameType /* frameType */, const uint8_t payloadType, |
| 40 | const uint32_t timeStamp, const uint8_t* payloadData, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 41 | const size_t payloadSize, |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 42 | const RTPFragmentationHeader* /* fragmentation */) { |
| 43 | _rtpStream->Write(payloadType, timeStamp, _seqNo++, payloadData, payloadSize, |
| 44 | _frequency); |
| 45 | return 1; |
| 46 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 48 | Sender::Sender() |
| 49 | : _acm(NULL), |
| 50 | _pcmFile(), |
| 51 | _audioFrame(), |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 52 | _packetization(NULL) { |
| 53 | } |
| 54 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 55 | void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 56 | std::string in_file_name, int sample_rate, size_t channels) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 57 | struct CodecInst sendCodec; |
| 58 | int noOfCodecs = acm->NumberOfCodecs(); |
| 59 | int codecNo; |
| 60 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 61 | // Open input file |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 62 | const std::string file_name = webrtc::test::ResourcePath(in_file_name, "pcm"); |
| 63 | _pcmFile.Open(file_name, sample_rate, "rb"); |
| 64 | if (channels == 2) { |
| 65 | _pcmFile.ReadStereo(true); |
| 66 | } |
Henrik Lundin | 4d68208 | 2015-12-10 16:24:39 +0100 | [diff] [blame] | 67 | // Set test length to 500 ms (50 blocks of 10 ms each). |
| 68 | _pcmFile.SetNum10MsBlocksToRead(50); |
| 69 | // Fast-forward 1 second (100 blocks) since the file starts with silence. |
| 70 | _pcmFile.FastForward(100); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 71 | |
| 72 | // Set the codec for the current test. |
| 73 | if ((testMode == 0) || (testMode == 1)) { |
| 74 | // Set the codec id. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 75 | codecNo = codeId; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 76 | } else { |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 77 | // Choose codec on command line. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 78 | printf("List of supported codec.\n"); |
| 79 | for (int n = 0; n < noOfCodecs; n++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 80 | EXPECT_EQ(0, acm->Codec(n, &sendCodec)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 81 | printf("%d %s\n", n, sendCodec.plname); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 83 | printf("Choose your codec:"); |
| 84 | ASSERT_GT(scanf("%d", &codecNo), 0); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 87 | EXPECT_EQ(0, acm->Codec(codecNo, &sendCodec)); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 88 | |
| 89 | sendCodec.channels = channels; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 90 | |
| 91 | EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 92 | _packetization = new TestPacketization(rtpStream, sendCodec.plfreq); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 93 | EXPECT_EQ(0, acm->RegisterTransportCallback(_packetization)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 94 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 95 | _acm = acm; |
| 96 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 97 | |
| 98 | void Sender::Teardown() { |
| 99 | _pcmFile.Close(); |
| 100 | delete _packetization; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | } |
| 102 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 103 | bool Sender::Add10MsData() { |
| 104 | if (!_pcmFile.EndOfFile()) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 105 | EXPECT_GT(_pcmFile.Read10MsData(_audioFrame), 0); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 106 | int32_t ok = _acm->Add10MsData(_audioFrame); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 107 | EXPECT_GE(ok, 0); |
| 108 | return ok >= 0 ? true : false; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 109 | } |
| 110 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | } |
| 112 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 113 | void Sender::Run() { |
| 114 | while (true) { |
| 115 | if (!Add10MsData()) { |
| 116 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | Receiver::Receiver() |
| 122 | : _playoutLengthSmpls(WEBRTC_10MS_PCM_AUDIO), |
| 123 | _payloadSizeBytes(MAX_INCOMING_PAYLOAD) { |
| 124 | } |
| 125 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 126 | void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 127 | std::string out_file_name, size_t channels) { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 128 | struct CodecInst recvCodec = CodecInst(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 129 | int noOfCodecs; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 130 | EXPECT_EQ(0, acm->InitializeReceiver()); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 131 | |
| 132 | noOfCodecs = acm->NumberOfCodecs(); |
| 133 | for (int i = 0; i < noOfCodecs; i++) { |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 134 | EXPECT_EQ(0, acm->Codec(i, &recvCodec)); |
| 135 | if (recvCodec.channels == channels) |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 136 | EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, |
| 137 | CodecInstToSdp(recvCodec))); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 138 | // Forces mono/stereo for Opus. |
| 139 | if (!strcmp(recvCodec.plname, "opus")) { |
| 140 | recvCodec.channels = channels; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 141 | EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, |
| 142 | CodecInstToSdp(recvCodec))); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 143 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 144 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 145 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 146 | int playSampFreq; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 147 | std::string file_name; |
| 148 | std::stringstream file_stream; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 149 | file_stream << webrtc::test::OutputPath() << out_file_name |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 150 | << static_cast<int>(codeId) << ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 151 | file_name = file_stream.str(); |
| 152 | _rtpStream = rtpStream; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 153 | |
| 154 | if (testMode == 1) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 155 | playSampFreq = recvCodec.plfreq; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 156 | _pcmFile.Open(file_name, recvCodec.plfreq, "wb+"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 157 | } else if (testMode == 0) { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 158 | playSampFreq = 32000; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 159 | _pcmFile.Open(file_name, 32000, "wb+"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 160 | } else { |
| 161 | printf("\nValid output frequencies:\n"); |
| 162 | printf("8000\n16000\n32000\n-1,"); |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 163 | printf("which means output frequency equal to received signal frequency"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 164 | printf("\n\nChoose output sampling frequency: "); |
| 165 | ASSERT_GT(scanf("%d", &playSampFreq), 0); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 166 | file_name = webrtc::test::OutputPath() + out_file_name + ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 167 | _pcmFile.Open(file_name, playSampFreq, "wb+"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 168 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 169 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 170 | _realPayloadSizeBytes = 0; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 171 | _playoutBuffer = new int16_t[WEBRTC_10MS_PCM_AUDIO]; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 172 | _frequency = playSampFreq; |
| 173 | _acm = acm; |
| 174 | _firstTime = true; |
| 175 | } |
| 176 | |
| 177 | void Receiver::Teardown() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 178 | delete[] _playoutBuffer; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 179 | _pcmFile.Close(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 180 | if (testMode > 1) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 181 | Trace::ReturnTrace(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 182 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | bool Receiver::IncomingPacket() { |
| 186 | if (!_rtpStream->EndOfFile()) { |
| 187 | if (_firstTime) { |
| 188 | _firstTime = false; |
| 189 | _realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload, |
| 190 | _payloadSizeBytes, &_nextTime); |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 191 | if (_realPayloadSizeBytes == 0) { |
| 192 | if (_rtpStream->EndOfFile()) { |
| 193 | _firstTime = true; |
| 194 | return true; |
| 195 | } else { |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 196 | return false; |
| 197 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 198 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 199 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 201 | EXPECT_EQ(0, _acm->IncomingPacket(_incomingPayload, _realPayloadSizeBytes, |
| 202 | _rtpInfo)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 203 | _realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload, |
| 204 | _payloadSizeBytes, &_nextTime); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 205 | if (_realPayloadSizeBytes == 0 && _rtpStream->EndOfFile()) { |
| 206 | _firstTime = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 208 | } |
| 209 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | } |
| 211 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 212 | bool Receiver::PlayoutData() { |
| 213 | AudioFrame audioFrame; |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 214 | bool muted; |
| 215 | int32_t ok = _acm->PlayoutData10Ms(_frequency, &audioFrame, &muted); |
| 216 | if (muted) { |
| 217 | ADD_FAILURE(); |
| 218 | return false; |
| 219 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 220 | EXPECT_EQ(0, ok); |
| 221 | if (ok < 0){ |
| 222 | return false; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 223 | } |
| 224 | if (_playoutLengthSmpls == 0) { |
| 225 | return false; |
| 226 | } |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 227 | _pcmFile.Write10MsData(audioFrame.data_, |
| 228 | audioFrame.samples_per_channel_ * audioFrame.num_channels_); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | |
| 232 | void Receiver::Run() { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 233 | uint8_t counter500Ms = 50; |
| 234 | uint32_t clock = 0; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 235 | |
| 236 | while (counter500Ms > 0) { |
| 237 | if (clock == 0 || clock >= _nextTime) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 238 | EXPECT_TRUE(IncomingPacket()); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 239 | if (clock == 0) { |
| 240 | clock = _nextTime; |
| 241 | } |
| 242 | } |
| 243 | if ((clock % 10) == 0) { |
| 244 | if (!PlayoutData()) { |
| 245 | clock++; |
| 246 | continue; |
| 247 | } |
| 248 | } |
| 249 | if (_rtpStream->EndOfFile()) { |
| 250 | counter500Ms--; |
| 251 | } |
| 252 | clock++; |
| 253 | } |
| 254 | } |
| 255 | |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 256 | EncodeDecodeTest::EncodeDecodeTest() { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 257 | _testMode = 2; |
| 258 | Trace::CreateTrace(); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 259 | Trace::SetTraceFile( |
| 260 | (webrtc::test::OutputPath() + "acm_encdec_trace.txt").c_str()); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 261 | } |
| 262 | |
henrik.lundin@webrtc.org | adaf809 | 2014-04-17 08:29:10 +0000 | [diff] [blame] | 263 | EncodeDecodeTest::EncodeDecodeTest(int testMode) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 264 | //testMode == 0 for autotest |
| 265 | //testMode == 1 for testing all codecs/parameters |
| 266 | //testMode > 1 for specific user-input test (as it was used before) |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 267 | _testMode = testMode; |
| 268 | if (_testMode != 0) { |
| 269 | Trace::CreateTrace(); |
| 270 | Trace::SetTraceFile( |
| 271 | (webrtc::test::OutputPath() + "acm_encdec_trace.txt").c_str()); |
| 272 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void EncodeDecodeTest::Perform() { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 276 | int numCodecs = 1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 277 | int codePars[3]; // Frequency, packet size, rate. |
| 278 | int numPars[52]; // Number of codec parameters sets (freq, pacsize, rate) |
| 279 | // to test, for a given codec. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 280 | |
| 281 | codePars[0] = 0; |
| 282 | codePars[1] = 0; |
| 283 | codePars[2] = 0; |
| 284 | |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 285 | std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(0)); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 286 | struct CodecInst sendCodecTmp; |
tina.legrand@webrtc.org | 5b4f36d | 2012-06-01 14:51:28 +0000 | [diff] [blame] | 287 | numCodecs = acm->NumberOfCodecs(); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 288 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 289 | if (_testMode != 2) { |
| 290 | for (int n = 0; n < numCodecs; n++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 291 | EXPECT_EQ(0, acm->Codec(n, &sendCodecTmp)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 292 | if (STR_CASE_CMP(sendCodecTmp.plname, "telephone-event") == 0) { |
| 293 | numPars[n] = 0; |
| 294 | } else if (STR_CASE_CMP(sendCodecTmp.plname, "cn") == 0) { |
| 295 | numPars[n] = 0; |
| 296 | } else if (STR_CASE_CMP(sendCodecTmp.plname, "red") == 0) { |
| 297 | numPars[n] = 0; |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 298 | } else if (sendCodecTmp.channels == 2) { |
| 299 | numPars[n] = 0; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 300 | } else { |
| 301 | numPars[n] = 1; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 304 | } else { |
| 305 | numCodecs = 1; |
| 306 | numPars[0] = 1; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | _receiver.testMode = _testMode; |
| 310 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 311 | // Loop over all mono codecs: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 312 | for (int codeId = 0; codeId < numCodecs; codeId++) { |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 313 | // Only encode using real mono encoders, not telephone-event and cng. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 314 | for (int loopPars = 1; loopPars <= numPars[codeId]; loopPars++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 315 | // Encode all data to file. |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 316 | std::string fileName = EncodeToFile(1, codeId, codePars, _testMode); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 317 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 318 | RTPFile rtpFile; |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 319 | rtpFile.Open(fileName.c_str(), "rb"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 320 | |
| 321 | _receiver.codeId = codeId; |
| 322 | |
| 323 | rtpFile.ReadHeader(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 324 | _receiver.Setup(acm.get(), &rtpFile, "encodeDecode_out", 1); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 325 | _receiver.Run(); |
| 326 | _receiver.Teardown(); |
| 327 | rtpFile.Close(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 330 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 331 | // End tracing. |
| 332 | if (_testMode == 1) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 333 | Trace::ReturnTrace(); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 334 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 335 | } |
| 336 | |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 337 | std::string EncodeDecodeTest::EncodeToFile(int fileType, |
| 338 | int codeId, |
| 339 | int* codePars, |
| 340 | int testMode) { |
kwiberg | 3747838 | 2016-02-14 20:40:57 -0800 | [diff] [blame] | 341 | std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(1)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 342 | RTPFile rtpFile; |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 343 | std::string fileName = webrtc::test::TempFilename(webrtc::test::OutputPath(), |
| 344 | "encode_decode_rtp"); |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 345 | rtpFile.Open(fileName.c_str(), "wb+"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 346 | rtpFile.WriteHeader(); |
| 347 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 348 | // Store for auto_test and logging. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 349 | _sender.testMode = testMode; |
| 350 | _sender.codeId = codeId; |
| 351 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 352 | _sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 353 | if (acm->SendCodec()) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 354 | _sender.Run(); |
| 355 | } |
| 356 | _sender.Teardown(); |
| 357 | rtpFile.Close(); |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 358 | |
| 359 | return fileName; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 360 | } |
| 361 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 362 | } // namespace webrtc |