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 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 13 | #include <stdio.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 15 | #include <memory> |
| 16 | #include <sstream> // no-presubmit-check TODO(webrtc:8982) |
tina.legrand@webrtc.org | 5e7ca60 | 2012-06-12 07:16:24 +0000 | [diff] [blame] | 17 | |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 18 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Karl Wiberg | 658a552 | 2018-08-15 15:20:49 +0200 | [diff] [blame] | 19 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 20 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_coding/codecs/audio_format_conversion.h" |
| 22 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 23 | #include "modules/audio_coding/test/utility.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "test/gtest.h" |
| 25 | #include "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; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 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. |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 72 | codecNo = codeId; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 73 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 74 | EXPECT_EQ(0, acm->Codec(codecNo, &sendCodec)); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 75 | |
| 76 | sendCodec.channels = channels; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 77 | |
Karl Wiberg | 658a552 | 2018-08-15 15:20:49 +0200 | [diff] [blame] | 78 | acm->SetEncoder(CreateBuiltinAudioEncoderFactory()->MakeAudioEncoder( |
| 79 | sendCodec.pltype, CodecInstToSdp(sendCodec), absl::nullopt)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 80 | _packetization = new TestPacketization(rtpStream, sendCodec.plfreq); |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 81 | EXPECT_EQ(0, acm->RegisterTransportCallback(_packetization)); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 82 | |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 83 | _acm = acm; |
| 84 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 85 | |
| 86 | void Sender::Teardown() { |
| 87 | _pcmFile.Close(); |
| 88 | delete _packetization; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | } |
| 90 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 91 | bool Sender::Add10MsData() { |
| 92 | if (!_pcmFile.EndOfFile()) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 93 | EXPECT_GT(_pcmFile.Read10MsData(_audioFrame), 0); |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 94 | int32_t ok = _acm->Add10MsData(_audioFrame); |
henrik.lundin@webrtc.org | f56c162 | 2015-03-02 12:29:30 +0000 | [diff] [blame] | 95 | EXPECT_GE(ok, 0); |
| 96 | return ok >= 0 ? true : false; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 97 | } |
| 98 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 101 | void Sender::Run() { |
| 102 | while (true) { |
| 103 | if (!Add10MsData()) { |
| 104 | break; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | Receiver::Receiver() |
| 110 | : _playoutLengthSmpls(WEBRTC_10MS_PCM_AUDIO), |
| 111 | _payloadSizeBytes(MAX_INCOMING_PAYLOAD) { |
| 112 | } |
| 113 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 114 | void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 115 | std::string out_file_name, size_t channels) { |
henrike@webrtc.org | 6ac22e6 | 2014-08-11 21:06:30 +0000 | [diff] [blame] | 116 | struct CodecInst recvCodec = CodecInst(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 117 | int noOfCodecs; |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 118 | EXPECT_EQ(0, acm->InitializeReceiver()); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 119 | |
| 120 | noOfCodecs = acm->NumberOfCodecs(); |
| 121 | for (int i = 0; i < noOfCodecs; i++) { |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 122 | EXPECT_EQ(0, acm->Codec(i, &recvCodec)); |
| 123 | if (recvCodec.channels == channels) |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 124 | EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, |
| 125 | CodecInstToSdp(recvCodec))); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 126 | // Forces mono/stereo for Opus. |
| 127 | if (!strcmp(recvCodec.plname, "opus")) { |
| 128 | recvCodec.channels = channels; |
kwiberg | da2bf4e | 2016-10-24 13:47:09 -0700 | [diff] [blame] | 129 | EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, |
| 130 | CodecInstToSdp(recvCodec))); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 131 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 132 | } |
phoglund@webrtc.org | d1a860b | 2012-01-26 14:49:28 +0000 | [diff] [blame] | 133 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 134 | int playSampFreq; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 135 | std::string file_name; |
| 136 | std::stringstream file_stream; |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 137 | file_stream << webrtc::test::OutputPath() << out_file_name |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 138 | << static_cast<int>(codeId) << ".pcm"; |
tina.legrand@webrtc.org | ba46804 | 2012-08-17 10:38:28 +0000 | [diff] [blame] | 139 | file_name = file_stream.str(); |
| 140 | _rtpStream = rtpStream; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 141 | |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 142 | playSampFreq = 32000; |
| 143 | _pcmFile.Open(file_name, 32000, "wb+"); |
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 | _realPayloadSizeBytes = 0; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 146 | _playoutBuffer = new int16_t[WEBRTC_10MS_PCM_AUDIO]; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 147 | _frequency = playSampFreq; |
| 148 | _acm = acm; |
| 149 | _firstTime = true; |
| 150 | } |
| 151 | |
| 152 | void Receiver::Teardown() { |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 153 | delete[] _playoutBuffer; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 154 | _pcmFile.Close(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | bool Receiver::IncomingPacket() { |
| 158 | if (!_rtpStream->EndOfFile()) { |
| 159 | if (_firstTime) { |
| 160 | _firstTime = false; |
| 161 | _realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload, |
| 162 | _payloadSizeBytes, &_nextTime); |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 163 | if (_realPayloadSizeBytes == 0) { |
| 164 | if (_rtpStream->EndOfFile()) { |
| 165 | _firstTime = true; |
| 166 | return true; |
| 167 | } else { |
andrew@webrtc.org | 975e4a3 | 2012-01-17 19:27:33 +0000 | [diff] [blame] | 168 | return false; |
| 169 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 170 | } |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 171 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 173 | EXPECT_EQ(0, _acm->IncomingPacket(_incomingPayload, _realPayloadSizeBytes, |
| 174 | _rtpInfo)); |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 175 | _realPayloadSizeBytes = _rtpStream->Read(&_rtpInfo, _incomingPayload, |
| 176 | _payloadSizeBytes, &_nextTime); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 177 | if (_realPayloadSizeBytes == 0 && _rtpStream->EndOfFile()) { |
| 178 | _firstTime = true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 179 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 180 | } |
| 181 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | } |
| 183 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 184 | bool Receiver::PlayoutData() { |
| 185 | AudioFrame audioFrame; |
henrik.lundin | d4ccb00 | 2016-05-17 12:21:55 -0700 | [diff] [blame] | 186 | bool muted; |
| 187 | int32_t ok = _acm->PlayoutData10Ms(_frequency, &audioFrame, &muted); |
| 188 | if (muted) { |
| 189 | ADD_FAILURE(); |
| 190 | return false; |
| 191 | } |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 192 | EXPECT_EQ(0, ok); |
| 193 | if (ok < 0){ |
| 194 | return false; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 195 | } |
| 196 | if (_playoutLengthSmpls == 0) { |
| 197 | return false; |
| 198 | } |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 199 | _pcmFile.Write10MsData(audioFrame.data(), |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 200 | audioFrame.samples_per_channel_ * audioFrame.num_channels_); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 201 | return true; |
| 202 | } |
| 203 | |
| 204 | void Receiver::Run() { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 205 | uint8_t counter500Ms = 50; |
| 206 | uint32_t clock = 0; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 207 | |
| 208 | while (counter500Ms > 0) { |
| 209 | if (clock == 0 || clock >= _nextTime) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 210 | EXPECT_TRUE(IncomingPacket()); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 211 | if (clock == 0) { |
| 212 | clock = _nextTime; |
| 213 | } |
| 214 | } |
| 215 | if ((clock % 10) == 0) { |
| 216 | if (!PlayoutData()) { |
| 217 | clock++; |
| 218 | continue; |
| 219 | } |
| 220 | } |
| 221 | if (_rtpStream->EndOfFile()) { |
| 222 | counter500Ms--; |
| 223 | } |
| 224 | clock++; |
| 225 | } |
| 226 | } |
| 227 | |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 228 | EncodeDecodeTest::EncodeDecodeTest(int test_mode) { |
| 229 | // There used to be different test modes. The only one still supported is the |
| 230 | // "autotest" mode. |
| 231 | RTC_CHECK_EQ(0, test_mode); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void EncodeDecodeTest::Perform() { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 235 | int numCodecs = 1; |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 236 | int codePars[3]; // Frequency, packet size, rate. |
| 237 | int numPars[52]; // Number of codec parameters sets (freq, pacsize, rate) |
| 238 | // to test, for a given codec. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 239 | |
| 240 | codePars[0] = 0; |
| 241 | codePars[1] = 0; |
| 242 | codePars[2] = 0; |
| 243 | |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 244 | std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create( |
| 245 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 246 | struct CodecInst sendCodecTmp; |
tina.legrand@webrtc.org | 5b4f36d | 2012-06-01 14:51:28 +0000 | [diff] [blame] | 247 | numCodecs = acm->NumberOfCodecs(); |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 248 | |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 249 | for (int n = 0; n < numCodecs; n++) { |
| 250 | EXPECT_EQ(0, acm->Codec(n, &sendCodecTmp)); |
| 251 | if (STR_CASE_CMP(sendCodecTmp.plname, "telephone-event") == 0) { |
| 252 | numPars[n] = 0; |
| 253 | } else if (STR_CASE_CMP(sendCodecTmp.plname, "cn") == 0) { |
| 254 | numPars[n] = 0; |
| 255 | } else if (STR_CASE_CMP(sendCodecTmp.plname, "red") == 0) { |
| 256 | numPars[n] = 0; |
| 257 | } else if (sendCodecTmp.channels == 2) { |
| 258 | numPars[n] = 0; |
| 259 | } else { |
| 260 | numPars[n] = 1; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 261 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 262 | } |
| 263 | |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 264 | // Loop over all mono codecs: |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 265 | for (int codeId = 0; codeId < numCodecs; codeId++) { |
tina.legrand@webrtc.org | 4517585 | 2012-06-01 09:27:35 +0000 | [diff] [blame] | 266 | // 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] | 267 | for (int loopPars = 1; loopPars <= numPars[codeId]; loopPars++) { |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 268 | // Encode all data to file. |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 269 | std::string fileName = EncodeToFile(1, codeId, codePars); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 270 | |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 271 | RTPFile rtpFile; |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 272 | rtpFile.Open(fileName.c_str(), "rb"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 273 | |
| 274 | _receiver.codeId = codeId; |
| 275 | |
| 276 | rtpFile.ReadHeader(); |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 277 | _receiver.Setup(acm.get(), &rtpFile, "encodeDecode_out", 1); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 278 | _receiver.Run(); |
| 279 | _receiver.Teardown(); |
| 280 | rtpFile.Close(); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 283 | } |
| 284 | |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 285 | std::string EncodeDecodeTest::EncodeToFile(int fileType, |
| 286 | int codeId, |
Karl Wiberg | 88aee28 | 2018-06-14 13:12:05 +0200 | [diff] [blame] | 287 | int* codePars) { |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 288 | std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create( |
| 289 | AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 290 | RTPFile rtpFile; |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 291 | std::string fileName = webrtc::test::TempFilename(webrtc::test::OutputPath(), |
| 292 | "encode_decode_rtp"); |
kjellander@webrtc.org | 5490c71 | 2011-12-21 13:34:18 +0000 | [diff] [blame] | 293 | rtpFile.Open(fileName.c_str(), "wb+"); |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 294 | rtpFile.WriteHeader(); |
| 295 | |
tina.legrand@webrtc.org | ee92b66 | 2013-08-27 07:33:51 +0000 | [diff] [blame] | 296 | // Store for auto_test and logging. |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 297 | _sender.codeId = codeId; |
| 298 | |
minyue@webrtc.org | aa5ea1c | 2014-05-23 15:16:51 +0000 | [diff] [blame] | 299 | _sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1); |
kwiberg | 1fd4a4a | 2015-11-03 11:20:50 -0800 | [diff] [blame] | 300 | if (acm->SendCodec()) { |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 301 | _sender.Run(); |
| 302 | } |
| 303 | _sender.Teardown(); |
| 304 | rtpFile.Close(); |
pbos@webrtc.org | c86e45d | 2014-10-01 10:05:40 +0000 | [diff] [blame] | 305 | |
| 306 | return fileName; |
tina.legrand@webrtc.org | 554ae1a | 2011-12-16 10:09:04 +0000 | [diff] [blame] | 307 | } |
| 308 | |
tina.legrand@webrtc.org | d5726a1 | 2013-05-03 07:34:12 +0000 | [diff] [blame] | 309 | } // namespace webrtc |