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