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