Reland "Remove CodecInst pt.1"

This is a reland of 056f9738bf7a3d16da45398239656e165c4e0851

Original change's description:
> Remove CodecInst pt.1
> 
> Update audio_coding tests to not use CodecInst.
> 
> Bug: webrtc:7626
> Change-Id: I880fb8d72d7d0a915d274e67feb6106f023697c2
> Reviewed-on: https://webrtc-review.googlesource.com/c/112594
> Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#25879}

Bug: webrtc:7626
Change-Id: I5d6ca0baf6230bfe9bf95c2c25496d2a56812d90
Reviewed-on: https://webrtc-review.googlesource.com/c/112942
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25902}
This commit is contained in:
Fredrik Solenberg
2018-12-05 10:30:25 +01:00
committed by Commit Bot
parent 5b1477839d
commit 657b296ff5
24 changed files with 361 additions and 1215 deletions

View File

@ -1343,8 +1343,6 @@ if (rtc_include_tests) {
"test/opus_test.cc", "test/opus_test.cc",
"test/opus_test.h", "test/opus_test.h",
"test/target_delay_unittest.cc", "test/target_delay_unittest.cc",
"test/utility.cc",
"test/utility.h",
] ]
deps = [ deps = [
":audio_coding", ":audio_coding",

View File

@ -287,113 +287,6 @@ void Channel::ResetStats() {
_channelCritSect.Leave(); _channelCritSect.Leave();
} }
int16_t Channel::Stats(CodecInst& codecInst,
ACMTestPayloadStats& payloadStats) {
_channelCritSect.Enter();
int n;
payloadStats.payloadType = -1;
for (n = 0; n < MAX_NUM_PAYLOADS; n++) {
if (_payloadStats[n].payloadType == codecInst.pltype) {
memcpy(&payloadStats, &_payloadStats[n], sizeof(ACMTestPayloadStats));
break;
}
}
if (payloadStats.payloadType == -1) {
_channelCritSect.Leave();
return -1;
}
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (payloadStats.frameSizeStats[n].frameSizeSample == 0) {
_channelCritSect.Leave();
return 0;
}
payloadStats.frameSizeStats[n].usageLenSec =
(double)payloadStats.frameSizeStats[n].totalEncodedSamples /
(double)codecInst.plfreq;
payloadStats.frameSizeStats[n].rateBitPerSec =
payloadStats.frameSizeStats[n].totalPayloadLenByte * 8 /
payloadStats.frameSizeStats[n].usageLenSec;
}
_channelCritSect.Leave();
return 0;
}
void Channel::Stats(uint32_t* numPackets) {
_channelCritSect.Enter();
int k;
int n;
memset(numPackets, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for (k = 0; k < MAX_NUM_PAYLOADS; k++) {
if (_payloadStats[k].payloadType == -1) {
break;
}
numPackets[k] = 0;
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) {
break;
}
numPackets[k] += _payloadStats[k].frameSizeStats[n].numPackets;
}
}
_channelCritSect.Leave();
}
void Channel::Stats(uint8_t* payloadType, uint32_t* payloadLenByte) {
_channelCritSect.Enter();
int k;
int n;
memset(payloadLenByte, 0, MAX_NUM_PAYLOADS * sizeof(uint32_t));
for (k = 0; k < MAX_NUM_PAYLOADS; k++) {
if (_payloadStats[k].payloadType == -1) {
break;
}
payloadType[k] = (uint8_t)_payloadStats[k].payloadType;
payloadLenByte[k] = 0;
for (n = 0; n < MAX_NUM_FRAMESIZES; n++) {
if (_payloadStats[k].frameSizeStats[n].frameSizeSample == 0) {
break;
}
payloadLenByte[k] +=
(uint16_t)_payloadStats[k].frameSizeStats[n].totalPayloadLenByte;
}
}
_channelCritSect.Leave();
}
void Channel::PrintStats(CodecInst& codecInst) {
ACMTestPayloadStats payloadStats;
Stats(codecInst, payloadStats);
printf("%s %d kHz\n", codecInst.plname, codecInst.plfreq / 1000);
printf("=====================================================\n");
if (payloadStats.payloadType == -1) {
printf("No Packets are sent with payload-type %d (%s)\n\n",
codecInst.pltype, codecInst.plname);
return;
}
for (int k = 0; k < MAX_NUM_FRAMESIZES; k++) {
if (payloadStats.frameSizeStats[k].frameSizeSample == 0) {
break;
}
printf("Frame-size.................... %d samples\n",
payloadStats.frameSizeStats[k].frameSizeSample);
printf("Average Rate.................. %.0f bits/sec\n",
payloadStats.frameSizeStats[k].rateBitPerSec);
printf("Maximum Payload-Size.......... %" PRIuS " Bytes\n",
payloadStats.frameSizeStats[k].maxPayloadLen);
printf("Maximum Instantaneous Rate.... %.0f bits/sec\n",
((double)payloadStats.frameSizeStats[k].maxPayloadLen * 8.0 *
(double)codecInst.plfreq) /
(double)payloadStats.frameSizeStats[k].frameSizeSample);
printf("Number of Packets............. %u\n",
(unsigned int)payloadStats.frameSizeStats[k].numPackets);
printf("Duration...................... %0.3f sec\n\n",
payloadStats.frameSizeStats[k].usageLenSec);
}
}
uint32_t Channel::LastInTimestamp() { uint32_t Channel::LastInTimestamp() {
uint32_t timestamp; uint32_t timestamp;
_channelCritSect.Enter(); _channelCritSect.Enter();

View File

@ -58,14 +58,6 @@ class Channel : public AudioPacketizationCallback {
void ResetStats(); void ResetStats();
int16_t Stats(CodecInst& codecInst, ACMTestPayloadStats& payloadStats);
void Stats(uint32_t* numPackets);
void Stats(uint8_t* payloadType, uint32_t* payloadLenByte);
void PrintStats(CodecInst& codecInst);
void SetIsStereo(bool isStereo) { _isStereo = isStereo; } void SetIsStereo(bool isStereo) { _isStereo = isStereo; }
uint32_t LastInTimestamp(); uint32_t LastInTimestamp();

View File

@ -14,12 +14,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <memory> #include <memory>
#include "absl/strings/match.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/utility.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
@ -53,14 +50,12 @@ Sender::Sender()
} }
void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream, void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string in_file_name, int sample_rate, size_t channels) { std::string in_file_name, int in_sample_rate,
struct CodecInst sendCodec; int payload_type, SdpAudioFormat format) {
int codecNo;
// Open input file // Open input file
const std::string file_name = webrtc::test::ResourcePath(in_file_name, "pcm"); const std::string file_name = webrtc::test::ResourcePath(in_file_name, "pcm");
_pcmFile.Open(file_name, sample_rate, "rb"); _pcmFile.Open(file_name, in_sample_rate, "rb");
if (channels == 2) { if (format.num_channels == 2) {
_pcmFile.ReadStereo(true); _pcmFile.ReadStereo(true);
} }
// Set test length to 500 ms (50 blocks of 10 ms each). // Set test length to 500 ms (50 blocks of 10 ms each).
@ -68,16 +63,9 @@ void Sender::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
// Fast-forward 1 second (100 blocks) since the file starts with silence. // Fast-forward 1 second (100 blocks) since the file starts with silence.
_pcmFile.FastForward(100); _pcmFile.FastForward(100);
// Set the codec for the current test.
codecNo = codeId;
EXPECT_EQ(0, acm->Codec(codecNo, &sendCodec));
sendCodec.channels = channels;
acm->SetEncoder(CreateBuiltinAudioEncoderFactory()->MakeAudioEncoder( acm->SetEncoder(CreateBuiltinAudioEncoderFactory()->MakeAudioEncoder(
sendCodec.pltype, CodecInstToSdp(sendCodec), absl::nullopt)); payload_type, format, absl::nullopt));
_packetization = new TestPacketization(rtpStream, sendCodec.plfreq); _packetization = new TestPacketization(rtpStream, format.clockrate_hz);
EXPECT_EQ(0, acm->RegisterTransportCallback(_packetization)); EXPECT_EQ(0, acm->RegisterTransportCallback(_packetization));
_acm = acm; _acm = acm;
@ -112,30 +100,39 @@ Receiver::Receiver()
} }
void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream, void Receiver::Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string out_file_name, size_t channels) { std::string out_file_name, size_t channels, int file_num) {
struct CodecInst recvCodec = CodecInst();
int noOfCodecs;
EXPECT_EQ(0, acm->InitializeReceiver()); EXPECT_EQ(0, acm->InitializeReceiver());
noOfCodecs = acm->NumberOfCodecs(); if (channels == 1) {
for (int i = 0; i < noOfCodecs; i++) { acm->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
EXPECT_EQ(0, acm->Codec(i, &recvCodec)); {104, {"ISAC", 32000, 1}},
if (recvCodec.channels == channels) {107, {"L16", 8000, 1}},
EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, {108, {"L16", 16000, 1}},
CodecInstToSdp(recvCodec))); {109, {"L16", 32000, 1}},
// Forces mono/stereo for Opus. {0, {"PCMU", 8000, 1}},
if (!strcmp(recvCodec.plname, "opus")) { {8, {"PCMA", 8000, 1}},
recvCodec.channels = channels; {102, {"ILBC", 8000, 1}},
EXPECT_EQ(true, acm->RegisterReceiveCodec(recvCodec.pltype, {9, {"G722", 8000, 1}},
CodecInstToSdp(recvCodec))); {120, {"OPUS", 48000, 2}},
} {13, {"CN", 8000, 1}},
{98, {"CN", 16000, 1}},
{99, {"CN", 32000, 1}}});
} else {
ASSERT_EQ(channels, 2u);
acm->SetReceiveCodecs({{111, {"L16", 8000, 2}},
{112, {"L16", 16000, 2}},
{113, {"L16", 32000, 2}},
{110, {"PCMU", 8000, 2}},
{118, {"PCMA", 8000, 2}},
{119, {"G722", 8000, 2}},
{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
} }
int playSampFreq; int playSampFreq;
std::string file_name; std::string file_name;
rtc::StringBuilder file_stream; rtc::StringBuilder file_stream;
file_stream << webrtc::test::OutputPath() << out_file_name file_stream << webrtc::test::OutputPath() << out_file_name << file_num
<< static_cast<int>(codeId) << ".pcm"; << ".pcm";
file_name = file_stream.str(); file_name = file_stream.str();
_rtpStream = rtpStream; _rtpStream = rtpStream;
@ -225,85 +222,47 @@ void Receiver::Run() {
} }
} }
EncodeDecodeTest::EncodeDecodeTest(int test_mode) { EncodeDecodeTest::EncodeDecodeTest() = default;
// There used to be different test modes. The only one still supported is the
// "autotest" mode.
RTC_CHECK_EQ(0, test_mode);
}
void EncodeDecodeTest::Perform() { void EncodeDecodeTest::Perform() {
int numCodecs = 1; const std::map<int, SdpAudioFormat> send_codecs = {{103, {"ISAC", 16000, 1}},
int codePars[3]; // Frequency, packet size, rate. {104, {"ISAC", 32000, 1}},
int numPars[52]; // Number of codec parameters sets (freq, pacsize, rate) {107, {"L16", 8000, 1}},
// to test, for a given codec. {108, {"L16", 16000, 1}},
{109, {"L16", 32000, 1}},
{0, {"PCMU", 8000, 1}},
{8, {"PCMA", 8000, 1}},
#ifdef WEBRTC_CODEC_ILBC
{102, {"ILBC", 8000, 1}},
#endif
{9, {"G722", 8000, 1}}};
int file_num = 0;
for (const auto& send_codec : send_codecs) {
RTPFile rtpFile;
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory())));
codePars[0] = 0; std::string fileName = webrtc::test::TempFilename(
codePars[1] = 0; webrtc::test::OutputPath(), "encode_decode_rtp");
codePars[2] = 0; rtpFile.Open(fileName.c_str(), "wb+");
rtpFile.WriteHeader();
Sender sender;
sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000,
send_codec.first, send_codec.second);
sender.Run();
sender.Teardown();
rtpFile.Close();
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create( rtpFile.Open(fileName.c_str(), "rb");
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))); rtpFile.ReadHeader();
struct CodecInst sendCodecTmp; Receiver receiver;
numCodecs = acm->NumberOfCodecs(); receiver.Setup(acm.get(), &rtpFile, "encodeDecode_out", 1, file_num);
receiver.Run();
receiver.Teardown();
rtpFile.Close();
for (int n = 0; n < numCodecs; n++) { file_num++;
EXPECT_EQ(0, acm->Codec(n, &sendCodecTmp));
if (absl::EqualsIgnoreCase(sendCodecTmp.plname, "telephone-event")) {
numPars[n] = 0;
} else if (absl::EqualsIgnoreCase(sendCodecTmp.plname, "cn")) {
numPars[n] = 0;
} else if (absl::EqualsIgnoreCase(sendCodecTmp.plname, "red")) {
numPars[n] = 0;
} else if (sendCodecTmp.channels == 2) {
numPars[n] = 0;
} else {
numPars[n] = 1;
}
} }
// Loop over all mono codecs:
for (int codeId = 0; codeId < numCodecs; codeId++) {
// Only encode using real mono encoders, not telephone-event and cng.
for (int loopPars = 1; loopPars <= numPars[codeId]; loopPars++) {
// Encode all data to file.
std::string fileName = EncodeToFile(1, codeId, codePars);
RTPFile rtpFile;
rtpFile.Open(fileName.c_str(), "rb");
_receiver.codeId = codeId;
rtpFile.ReadHeader();
_receiver.Setup(acm.get(), &rtpFile, "encodeDecode_out", 1);
_receiver.Run();
_receiver.Teardown();
rtpFile.Close();
}
}
}
std::string EncodeDecodeTest::EncodeToFile(int fileType,
int codeId,
int* codePars) {
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory())));
RTPFile rtpFile;
std::string fileName = webrtc::test::TempFilename(webrtc::test::OutputPath(),
"encode_decode_rtp");
rtpFile.Open(fileName.c_str(), "wb+");
rtpFile.WriteHeader();
// Store for auto_test and logging.
_sender.codeId = codeId;
_sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1);
if (acm->SendCodec()) {
_sender.Run();
}
_sender.Teardown();
rtpFile.Close();
return fileName;
} }
} // namespace webrtc } // namespace webrtc

View File

@ -47,13 +47,12 @@ class Sender {
public: public:
Sender(); Sender();
void Setup(AudioCodingModule *acm, RTPStream *rtpStream, void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string in_file_name, int sample_rate, size_t channels); std::string in_file_name, int in_sample_rate,
int payload_type, SdpAudioFormat format);
void Teardown(); void Teardown();
void Run(); void Run();
bool Add10MsData(); bool Add10MsData();
uint8_t codeId;
protected: protected:
AudioCodingModule* _acm; AudioCodingModule* _acm;
@ -68,15 +67,12 @@ class Receiver {
Receiver(); Receiver();
virtual ~Receiver() {}; virtual ~Receiver() {};
void Setup(AudioCodingModule *acm, RTPStream *rtpStream, void Setup(AudioCodingModule *acm, RTPStream *rtpStream,
std::string out_file_name, size_t channels); std::string out_file_name, size_t channels, int file_num);
void Teardown(); void Teardown();
void Run(); void Run();
virtual bool IncomingPacket(); virtual bool IncomingPacket();
bool PlayoutData(); bool PlayoutData();
//for auto_test and logging
uint8_t codeId;
private: private:
PCMFile _pcmFile; PCMFile _pcmFile;
int16_t* _playoutBuffer; int16_t* _playoutBuffer;
@ -96,17 +92,8 @@ class Receiver {
class EncodeDecodeTest { class EncodeDecodeTest {
public: public:
explicit EncodeDecodeTest(int test_mode); EncodeDecodeTest();
void Perform(); void Perform();
uint16_t _playoutFreq;
private:
std::string EncodeToFile(int fileType, int codeId, int* codePars);
protected:
Sender _sender;
Receiver _receiver;
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -30,6 +30,7 @@ void ReceiverWithPacketLoss::Setup(AudioCodingModule* acm,
RTPStream* rtpStream, RTPStream* rtpStream,
std::string out_file_name, std::string out_file_name,
int channels, int channels,
int file_num,
int loss_rate, int loss_rate,
int burst_length) { int burst_length) {
loss_rate_ = loss_rate; loss_rate_ = loss_rate;
@ -37,7 +38,7 @@ void ReceiverWithPacketLoss::Setup(AudioCodingModule* acm,
burst_lost_counter_ = burst_length_; // To prevent first packet gets lost. burst_lost_counter_ = burst_length_; // To prevent first packet gets lost.
rtc::StringBuilder ss; rtc::StringBuilder ss;
ss << out_file_name << "_" << loss_rate_ << "_" << burst_length_ << "_"; ss << out_file_name << "_" << loss_rate_ << "_" << burst_length_ << "_";
Receiver::Setup(acm, rtpStream, ss.str(), channels); Receiver::Setup(acm, rtpStream, ss.str(), channels, file_num);
} }
bool ReceiverWithPacketLoss::IncomingPacket() { bool ReceiverWithPacketLoss::IncomingPacket() {
@ -89,10 +90,11 @@ SenderWithFEC::SenderWithFEC() : expected_loss_rate_(0) {}
void SenderWithFEC::Setup(AudioCodingModule* acm, void SenderWithFEC::Setup(AudioCodingModule* acm,
RTPStream* rtpStream, RTPStream* rtpStream,
std::string in_file_name, std::string in_file_name,
int sample_rate, int payload_type,
int channels, SdpAudioFormat format,
int expected_loss_rate) { int expected_loss_rate) {
Sender::Setup(acm, rtpStream, in_file_name, sample_rate, channels); Sender::Setup(acm, rtpStream, in_file_name, format.clockrate_hz, payload_type,
format);
EXPECT_TRUE(SetFEC(true)); EXPECT_TRUE(SetFEC(true));
EXPECT_TRUE(SetPacketLossRate(expected_loss_rate)); EXPECT_TRUE(SetPacketLossRate(expected_loss_rate));
} }
@ -123,8 +125,6 @@ PacketLossTest::PacketLossTest(int channels,
in_file_name_(channels_ == 1 ? "audio_coding/testfile32kHz" in_file_name_(channels_ == 1 ? "audio_coding/testfile32kHz"
: "audio_coding/teststereo32kHz"), : "audio_coding/teststereo32kHz"),
sample_rate_hz_(32000), sample_rate_hz_(32000),
sender_(new SenderWithFEC),
receiver_(new ReceiverWithPacketLoss),
expected_loss_rate_(expected_loss_rate), expected_loss_rate_(expected_loss_rate),
actual_loss_rate_(actual_loss_rate), actual_loss_rate_(actual_loss_rate),
burst_length_(burst_length) {} burst_length_(burst_length) {}
@ -133,40 +133,32 @@ void PacketLossTest::Perform() {
#ifndef WEBRTC_CODEC_OPUS #ifndef WEBRTC_CODEC_OPUS
return; return;
#else #else
AudioCodingModule::Config config;
config.decoder_factory = CreateBuiltinAudioDecoderFactory();
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(config));
int codec_id = acm->Codec("opus", 48000, channels_);
RTPFile rtpFile; RTPFile rtpFile;
std::unique_ptr<AudioCodingModule> acm(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory())));
SdpAudioFormat send_format = SdpAudioFormat("opus", 48000, 2);
if (channels_ == 2) {
send_format.parameters = {{"stereo", "1"}};
}
std::string fileName = webrtc::test::TempFilename(webrtc::test::OutputPath(), std::string fileName = webrtc::test::TempFilename(webrtc::test::OutputPath(),
"packet_loss_test"); "packet_loss_test");
// Encode to file
rtpFile.Open(fileName.c_str(), "wb+"); rtpFile.Open(fileName.c_str(), "wb+");
rtpFile.WriteHeader(); rtpFile.WriteHeader();
SenderWithFEC sender;
sender_->codeId = codec_id; sender.Setup(acm.get(), &rtpFile, in_file_name_, 120, send_format,
sender_->Setup(acm.get(), &rtpFile, in_file_name_, sample_rate_hz_, channels_,
expected_loss_rate_); expected_loss_rate_);
if (acm->SendCodec()) { sender.Run();
sender_->Run(); sender.Teardown();
}
sender_->Teardown();
rtpFile.Close(); rtpFile.Close();
// Decode to file
rtpFile.Open(fileName.c_str(), "rb"); rtpFile.Open(fileName.c_str(), "rb");
rtpFile.ReadHeader(); rtpFile.ReadHeader();
ReceiverWithPacketLoss receiver;
receiver_->codeId = codec_id; receiver.Setup(acm.get(), &rtpFile, "packetLoss_out", channels_, 15,
receiver_->Setup(acm.get(), &rtpFile, "packetLoss_out", channels_,
actual_loss_rate_, burst_length_); actual_loss_rate_, burst_length_);
receiver_->Run(); receiver.Run();
receiver_->Teardown(); receiver.Teardown();
rtpFile.Close(); rtpFile.Close();
#endif #endif
} }

View File

@ -11,7 +11,6 @@
#ifndef MODULES_AUDIO_CODING_TEST_PACKETLOSSTEST_H_ #ifndef MODULES_AUDIO_CODING_TEST_PACKETLOSSTEST_H_
#define MODULES_AUDIO_CODING_TEST_PACKETLOSSTEST_H_ #define MODULES_AUDIO_CODING_TEST_PACKETLOSSTEST_H_
#include <memory>
#include <string> #include <string>
#include "modules/audio_coding/test/EncodeDecodeTest.h" #include "modules/audio_coding/test/EncodeDecodeTest.h"
@ -24,6 +23,7 @@ class ReceiverWithPacketLoss : public Receiver {
RTPStream* rtpStream, RTPStream* rtpStream,
std::string out_file_name, std::string out_file_name,
int channels, int channels,
int file_num,
int loss_rate, int loss_rate,
int burst_length); int burst_length);
bool IncomingPacket() override; bool IncomingPacket() override;
@ -43,8 +43,8 @@ class SenderWithFEC : public Sender {
void Setup(AudioCodingModule* acm, void Setup(AudioCodingModule* acm,
RTPStream* rtpStream, RTPStream* rtpStream,
std::string in_file_name, std::string in_file_name,
int sample_rate, int payload_type,
int channels, SdpAudioFormat format,
int expected_loss_rate); int expected_loss_rate);
bool SetPacketLossRate(int expected_loss_rate); bool SetPacketLossRate(int expected_loss_rate);
bool SetFEC(bool enable_fec); bool SetFEC(bool enable_fec);
@ -65,8 +65,6 @@ class PacketLossTest {
int channels_; int channels_;
std::string in_file_name_; std::string in_file_name_;
int sample_rate_hz_; int sample_rate_hz_;
std::unique_ptr<SenderWithFEC> sender_;
std::unique_ptr<ReceiverWithPacketLoss> receiver_;
int expected_loss_rate_; int expected_loss_rate_;
int actual_loss_rate_; int actual_loss_rate_;
int burst_length_; int burst_length_;

View File

@ -14,13 +14,11 @@
#include <limits> #include <limits>
#include <string> #include <string>
#include "absl/strings/match.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/test/utility.h" #include "modules/include/module_common_types.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/stringencode.h" #include "rtc_base/stringencode.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
@ -35,6 +33,11 @@
// The test loops through all available mono codecs, encode at "a" sends over // The test loops through all available mono codecs, encode at "a" sends over
// the channel, and decodes at "b". // the channel, and decodes at "b".
#define CHECK_ERROR(f) \
do { \
EXPECT_GE(f, 0) << "Error Calling API"; \
} while (0)
namespace { namespace {
const size_t kVariableSize = std::numeric_limits<size_t>::max(); const size_t kVariableSize = std::numeric_limits<size_t>::max();
} }
@ -101,7 +104,7 @@ void TestPack::reset_payload_size() {
payload_size_ = 0; payload_size_ = 0;
} }
TestAllCodecs::TestAllCodecs(int test_mode) TestAllCodecs::TestAllCodecs()
: acm_a_(AudioCodingModule::Create( : acm_a_(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
acm_b_(AudioCodingModule::Create( acm_b_(AudioCodingModule::Create(
@ -110,8 +113,6 @@ TestAllCodecs::TestAllCodecs(int test_mode)
test_count_(0), test_count_(0),
packet_size_samples_(0), packet_size_samples_(0),
packet_size_bytes_(0) { packet_size_bytes_(0) {
// test_mode = 0 for silent test (auto test)
test_mode_ = test_mode;
} }
TestAllCodecs::~TestAllCodecs() { TestAllCodecs::~TestAllCodecs() {
@ -126,23 +127,28 @@ void TestAllCodecs::Perform() {
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
infile_a_.Open(file_name, 32000, "rb"); infile_a_.Open(file_name, 32000, "rb");
if (test_mode_ == 0) {
RTC_LOG(LS_INFO) << "---------- TestAllCodecs ----------";
}
acm_a_->InitializeReceiver(); acm_a_->InitializeReceiver();
acm_b_->InitializeReceiver(); acm_b_->InitializeReceiver();
uint8_t num_encoders = acm_a_->NumberOfCodecs(); acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
CodecInst my_codec_param; {104, {"ISAC", 32000, 1}},
for (uint8_t n = 0; n < num_encoders; n++) { {107, {"L16", 8000, 1}},
acm_b_->Codec(n, &my_codec_param); {108, {"L16", 16000, 1}},
if (!strcmp(my_codec_param.plname, "opus")) { {109, {"L16", 32000, 1}},
my_codec_param.channels = 1; {111, {"L16", 8000, 2}},
} {112, {"L16", 16000, 2}},
acm_b_->RegisterReceiveCodec(my_codec_param.pltype, {113, {"L16", 32000, 2}},
CodecInstToSdp(my_codec_param)); {0, {"PCMU", 8000, 1}},
} {110, {"PCMU", 8000, 2}},
{8, {"PCMA", 8000, 1}},
{118, {"PCMA", 8000, 2}},
{102, {"ILBC", 8000, 1}},
{9, {"G722", 8000, 1}},
{119, {"G722", 8000, 2}},
{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
{13, {"CN", 8000, 1}},
{98, {"CN", 16000, 1}},
{99, {"CN", 32000, 1}}});
// Create and connect the channel // Create and connect the channel
channel_a_to_b_ = new TestPack; channel_a_to_b_ = new TestPack;
@ -151,9 +157,6 @@ void TestAllCodecs::Perform() {
// All codecs are tested for all allowed sampling frequencies, rates and // All codecs are tested for all allowed sampling frequencies, rates and
// packet sizes. // packet sizes.
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_g722[] = "G722"; char codec_g722[] = "G722";
@ -171,9 +174,6 @@ void TestAllCodecs::Perform() {
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
#ifdef WEBRTC_CODEC_ILBC #ifdef WEBRTC_CODEC_ILBC
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_ilbc[] = "ILBC"; char codec_ilbc[] = "ILBC";
@ -188,9 +188,6 @@ void TestAllCodecs::Perform() {
outfile_b_.Close(); outfile_b_.Close();
#endif #endif
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX))
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_isac[] = "ISAC"; char codec_isac[] = "ISAC";
@ -205,9 +202,6 @@ void TestAllCodecs::Perform() {
outfile_b_.Close(); outfile_b_.Close();
#endif #endif
#ifdef WEBRTC_CODEC_ISAC #ifdef WEBRTC_CODEC_ISAC
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
RegisterSendCodec('A', codec_isac, 32000, -1, 960, kVariableSize); RegisterSendCodec('A', codec_isac, 32000, -1, 960, kVariableSize);
@ -220,9 +214,6 @@ void TestAllCodecs::Perform() {
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
#endif #endif
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_l16[] = "L16"; char codec_l16[] = "L16";
@ -235,9 +226,7 @@ void TestAllCodecs::Perform() {
RegisterSendCodec('A', codec_l16, 8000, 128000, 320, 0); RegisterSendCodec('A', codec_l16, 8000, 128000, 320, 0);
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 0); RegisterSendCodec('A', codec_l16, 16000, 256000, 160, 0);
@ -249,9 +238,7 @@ void TestAllCodecs::Perform() {
RegisterSendCodec('A', codec_l16, 16000, 256000, 640, 0); RegisterSendCodec('A', codec_l16, 16000, 256000, 640, 0);
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 0); RegisterSendCodec('A', codec_l16, 32000, 512000, 320, 0);
@ -259,9 +246,7 @@ void TestAllCodecs::Perform() {
RegisterSendCodec('A', codec_l16, 32000, 512000, 640, 0); RegisterSendCodec('A', codec_l16, 32000, 512000, 640, 0);
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_pcma[] = "PCMA"; char codec_pcma[] = "PCMA";
@ -277,9 +262,7 @@ void TestAllCodecs::Perform() {
Run(channel_a_to_b_); Run(channel_a_to_b_);
RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, 0); RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, 0);
Run(channel_a_to_b_); Run(channel_a_to_b_);
if (test_mode_ != 0) {
printf("===============================================================\n");
}
char codec_pcmu[] = "PCMU"; char codec_pcmu[] = "PCMU";
RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 0); RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, 0);
Run(channel_a_to_b_); Run(channel_a_to_b_);
@ -295,9 +278,6 @@ void TestAllCodecs::Perform() {
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
#ifdef WEBRTC_CODEC_OPUS #ifdef WEBRTC_CODEC_OPUS
if (test_mode_ != 0) {
printf("===============================================================\n");
}
test_count_++; test_count_++;
OpenOutFile(test_count_); OpenOutFile(test_count_);
char codec_opus[] = "OPUS"; char codec_opus[] = "OPUS";
@ -317,24 +297,6 @@ void TestAllCodecs::Perform() {
Run(channel_a_to_b_); Run(channel_a_to_b_);
outfile_b_.Close(); outfile_b_.Close();
#endif #endif
if (test_mode_ != 0) {
printf("===============================================================\n");
/* Print out all codecs that were not tested in the run */
printf("The following codecs was not included in the test:\n");
#ifndef WEBRTC_CODEC_ILBC
printf(" iLBC\n");
#endif
#ifndef WEBRTC_CODEC_ISAC
printf(" ISAC float\n");
#endif
#ifndef WEBRTC_CODEC_ISACFX
printf(" ISAC fix\n");
#endif
printf("\nTo complete the test, listen to the %d number of output files.\n",
test_count_);
}
} }
// Register Codec to use in the test // Register Codec to use in the test
@ -354,21 +316,21 @@ void TestAllCodecs::RegisterSendCodec(char side,
int rate, int rate,
int packet_size, int packet_size,
size_t extra_byte) { size_t extra_byte) {
if (test_mode_ != 0) {
// Print out codec and settings.
printf("codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
sampling_freq_hz, rate, packet_size);
}
// Store packet-size in samples, used to validate the received packet. // Store packet-size in samples, used to validate the received packet.
// If G.722, store half the size to compensate for the timestamp bug in the // If G.722, store half the size to compensate for the timestamp bug in the
// RFC for G.722. // RFC for G.722.
// If iSAC runs in adaptive mode, packet size in samples can change on the // If iSAC runs in adaptive mode, packet size in samples can change on the
// fly, so we exclude this test by setting |packet_size_samples_| to -1. // fly, so we exclude this test by setting |packet_size_samples_| to -1.
if (!strcmp(codec_name, "G722")) { int clockrate_hz = sampling_freq_hz;
size_t num_channels = 1;
if (absl::EqualsIgnoreCase(codec_name, "G722")) {
packet_size_samples_ = packet_size / 2; packet_size_samples_ = packet_size / 2;
} else if (!strcmp(codec_name, "ISAC") && (rate == -1)) { clockrate_hz = sampling_freq_hz / 2;
} else if (absl::EqualsIgnoreCase(codec_name, "ISAC") && (rate == -1)) {
packet_size_samples_ = -1; packet_size_samples_ = -1;
} else if (absl::EqualsIgnoreCase(codec_name, "OPUS")) {
packet_size_samples_ = packet_size;
num_channels = 2;
} else { } else {
packet_size_samples_ = packet_size; packet_size_samples_ = packet_size;
} }
@ -402,16 +364,9 @@ void TestAllCodecs::RegisterSendCodec(char side,
} }
ASSERT_TRUE(my_acm != NULL); ASSERT_TRUE(my_acm != NULL);
// Get all codec parameters before registering
CodecInst my_codec_param;
CHECK_ERROR(AudioCodingModule::Codec(codec_name, &my_codec_param,
sampling_freq_hz, 1));
my_codec_param.rate = rate;
my_codec_param.pacsize = packet_size;
auto factory = CreateBuiltinAudioEncoderFactory(); auto factory = CreateBuiltinAudioEncoderFactory();
constexpr int payload_type = 17; constexpr int payload_type = 17;
SdpAudioFormat format = CodecInstToSdp(my_codec_param); SdpAudioFormat format = { codec_name, clockrate_hz, num_channels };
format.parameters["ptime"] = rtc::ToString(rtc::CheckedDivExact( format.parameters["ptime"] = rtc::ToString(rtc::CheckedDivExact(
packet_size, rtc::CheckedDivExact(sampling_freq_hz, 1000))); packet_size, rtc::CheckedDivExact(sampling_freq_hz, 1000)));
my_acm->SetEncoder( my_acm->SetEncoder(
@ -485,11 +440,4 @@ void TestAllCodecs::OpenOutFile(int test_number) {
outfile_b_.Open(filename, 32000, "wb"); outfile_b_.Open(filename, 32000, "wb");
} }
void TestAllCodecs::DisplaySendReceiveCodec() {
CodecInst my_codec_param;
printf("%s -> ", acm_a_->SendCodec()->plname);
acm_b_->ReceiveCodec(&my_codec_param);
printf("%s\n", my_codec_param.plname);
}
} // namespace webrtc } // namespace webrtc

View File

@ -13,7 +13,7 @@
#include <memory> #include <memory>
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
namespace webrtc { namespace webrtc {
@ -48,7 +48,7 @@ class TestPack : public AudioPacketizationCallback {
class TestAllCodecs { class TestAllCodecs {
public: public:
explicit TestAllCodecs(int test_mode); TestAllCodecs();
~TestAllCodecs(); ~TestAllCodecs();
void Perform(); void Perform();
@ -67,9 +67,7 @@ class TestAllCodecs {
void Run(TestPack* channel); void Run(TestPack* channel);
void OpenOutFile(int test_number); void OpenOutFile(int test_number);
void DisplaySendReceiveCodec();
int test_mode_;
std::unique_ptr<AudioCodingModule> acm_a_; std::unique_ptr<AudioCodingModule> acm_a_;
std::unique_ptr<AudioCodingModule> acm_b_; std::unique_ptr<AudioCodingModule> acm_b_;
TestPack* channel_a_to_b_; TestPack* channel_a_to_b_;

View File

@ -10,8 +10,9 @@
#include "modules/audio_coding/test/TestRedFec.h" #include "modules/audio_coding/test/TestRedFec.h"
#include <assert.h> #include <utility>
#include "absl/strings/match.h"
#include "api/audio_codecs/L16/audio_decoder_L16.h" #include "api/audio_codecs/L16/audio_decoder_L16.h"
#include "api/audio_codecs/L16/audio_encoder_L16.h" #include "api/audio_codecs/L16/audio_encoder_L16.h"
#include "api/audio_codecs/audio_decoder_factory_template.h" #include "api/audio_codecs/audio_decoder_factory_template.h"
@ -24,12 +25,11 @@
#include "api/audio_codecs/isac/audio_encoder_isac_float.h" #include "api/audio_codecs/isac/audio_encoder_isac_float.h"
#include "api/audio_codecs/opus/audio_decoder_opus.h" #include "api/audio_codecs/opus/audio_decoder_opus.h"
#include "api/audio_codecs/opus/audio_encoder_opus.h" #include "api/audio_codecs/opus/audio_encoder_opus.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h" #include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
#include "modules/audio_coding/codecs/red/audio_encoder_copy_red.h" #include "modules/audio_coding/codecs/red/audio_encoder_copy_red.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/test/utility.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
namespace webrtc { namespace webrtc {
@ -173,6 +173,7 @@ void TestRedFec::RegisterSendCodec(
auto encoder = encoder_factory_->MakeAudioEncoder(payload_type, codec_format, auto encoder = encoder_factory_->MakeAudioEncoder(payload_type, codec_format,
absl::nullopt); absl::nullopt);
EXPECT_NE(encoder, nullptr); EXPECT_NE(encoder, nullptr);
std::map<int, SdpAudioFormat> receive_codecs = {{payload_type, codec_format}};
if (!absl::EqualsIgnoreCase(codec_format.name, "opus")) { if (!absl::EqualsIgnoreCase(codec_format.name, "opus")) {
if (vad_mode.has_value()) { if (vad_mode.has_value()) {
AudioEncoderCngConfig config; AudioEncoderCngConfig config;
@ -181,22 +182,22 @@ void TestRedFec::RegisterSendCodec(
config.payload_type = cn_payload_type; config.payload_type = cn_payload_type;
config.vad_mode = vad_mode.value(); config.vad_mode = vad_mode.value();
encoder = CreateComfortNoiseEncoder(std::move(config)); encoder = CreateComfortNoiseEncoder(std::move(config));
EXPECT_EQ(true, receive_codecs.emplace(
other_acm->RegisterReceiveCodec( std::make_pair(cn_payload_type,
cn_payload_type, {"CN", codec_format.clockrate_hz, 1})); SdpAudioFormat("CN", codec_format.clockrate_hz, 1)));
} }
if (use_red) { if (use_red) {
AudioEncoderCopyRed::Config config; AudioEncoderCopyRed::Config config;
config.payload_type = red_payload_type; config.payload_type = red_payload_type;
config.speech_encoder = std::move(encoder); config.speech_encoder = std::move(encoder);
encoder = absl::make_unique<AudioEncoderCopyRed>(std::move(config)); encoder = absl::make_unique<AudioEncoderCopyRed>(std::move(config));
EXPECT_EQ(true, receive_codecs.emplace(
other_acm->RegisterReceiveCodec( std::make_pair(red_payload_type,
red_payload_type, {"red", codec_format.clockrate_hz, 1})); SdpAudioFormat("red", codec_format.clockrate_hz, 1)));
} }
} }
acm->SetEncoder(std::move(encoder)); acm->SetEncoder(std::move(encoder));
EXPECT_EQ(true, other_acm->RegisterReceiveCodec(payload_type, codec_format)); other_acm->SetReceiveCodecs(receive_codecs);
} }
void TestRedFec::Run() { void TestRedFec::Run() {

View File

@ -15,9 +15,8 @@
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/test/utility.h" #include "modules/include/module_common_types.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
@ -32,7 +31,6 @@ TestPackStereo::TestPackStereo()
last_in_timestamp_(0), last_in_timestamp_(0),
total_bytes_(0), total_bytes_(0),
payload_size_(0), payload_size_(0),
codec_mode_(kNotSet),
lost_packet_(false) {} lost_packet_(false) {}
TestPackStereo::~TestPackStereo() {} TestPackStereo::~TestPackStereo() {}
@ -98,7 +96,7 @@ void TestPackStereo::set_lost_packet(bool lost) {
lost_packet_ = lost; lost_packet_ = lost;
} }
TestStereo::TestStereo(int test_mode) TestStereo::TestStereo()
: acm_a_(AudioCodingModule::Create( : acm_a_(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
acm_b_(AudioCodingModule::Create( acm_b_(AudioCodingModule::Create(
@ -108,8 +106,6 @@ TestStereo::TestStereo(int test_mode)
pack_size_samp_(0), pack_size_samp_(0),
pack_size_bytes_(0), pack_size_bytes_(0),
counter_(0) { counter_(0) {
// test_mode = 0 for silent test (auto test)
test_mode_ = test_mode;
} }
TestStereo::~TestStereo() { TestStereo::~TestStereo() {
@ -142,27 +138,25 @@ void TestStereo::Perform() {
EXPECT_EQ(0, acm_a_->InitializeReceiver()); EXPECT_EQ(0, acm_a_->InitializeReceiver());
EXPECT_EQ(0, acm_b_->InitializeReceiver()); EXPECT_EQ(0, acm_b_->InitializeReceiver());
// Register all available codes as receiving codecs. acm_b_->SetReceiveCodecs({{103, {"ISAC", 16000, 1}},
uint8_t num_encoders = acm_a_->NumberOfCodecs(); {104, {"ISAC", 32000, 1}},
CodecInst my_codec_param; {107, {"L16", 8000, 1}},
for (uint8_t n = 0; n < num_encoders; n++) { {108, {"L16", 16000, 1}},
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); {109, {"L16", 32000, 1}},
EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( {111, {"L16", 8000, 2}},
my_codec_param.pltype, CodecInstToSdp(my_codec_param))); {112, {"L16", 16000, 2}},
} {113, {"L16", 32000, 2}},
{0, {"PCMU", 8000, 1}},
// Test that unregister all receive codecs works. {110, {"PCMU", 8000, 2}},
for (uint8_t n = 0; n < num_encoders; n++) { {8, {"PCMA", 8000, 1}},
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); {118, {"PCMA", 8000, 2}},
EXPECT_EQ(0, acm_b_->UnregisterReceiveCodec(my_codec_param.pltype)); {102, {"ILBC", 8000, 1}},
} {9, {"G722", 8000, 1}},
{119, {"G722", 8000, 2}},
// Register all available codes as receiving codecs once more. {120, {"OPUS", 48000, 2, {{"stereo", "1"}}}},
for (uint8_t n = 0; n < num_encoders; n++) { {13, {"CN", 8000, 1}},
EXPECT_EQ(0, acm_b_->Codec(n, &my_codec_param)); {98, {"CN", 16000, 1}},
EXPECT_EQ(true, acm_b_->RegisterReceiveCodec( {99, {"CN", 32000, 1}}});
my_codec_param.pltype, CodecInstToSdp(my_codec_param)));
}
// Create and connect the channel. // Create and connect the channel.
channel_a2b_ = new TestPackStereo; channel_a2b_ = new TestPackStereo;
@ -171,9 +165,6 @@ void TestStereo::Perform() {
char codec_pcma_temp[] = "PCMA"; char codec_pcma_temp[] = "PCMA";
RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2); RegisterSendCodec('A', codec_pcma_temp, 8000, 64000, 80, 2);
if (test_mode_ != 0) {
printf("\n");
}
// //
// Test Stereo-To-Stereo for all codecs. // Test Stereo-To-Stereo for all codecs.
@ -183,11 +174,6 @@ void TestStereo::Perform() {
// All codecs are tested for all allowed sampling frequencies, rates and // All codecs are tested for all allowed sampling frequencies, rates and
// packet sizes. // packet sizes.
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
@ -206,11 +192,6 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
@ -225,11 +206,6 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
@ -242,11 +218,6 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
@ -255,11 +226,6 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
#ifdef PCMA_AND_PCMU #ifdef PCMA_AND_PCMU
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
audio_channels = 2; audio_channels = 2;
codec_channels = 2; codec_channels = 2;
@ -278,13 +244,8 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels); RegisterSendCodec('A', codec_pcma, 8000, 64000, 480, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
char codec_pcmu[] = "PCMU"; char codec_pcmu[] = "PCMU";
@ -303,11 +264,6 @@ void TestStereo::Perform() {
out_file_.Close(); out_file_.Close();
#endif #endif
#ifdef WEBRTC_CODEC_OPUS #ifdef WEBRTC_CODEC_OPUS
if (test_mode_ != 0) {
printf("===========================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-stereo\n");
}
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
audio_channels = 2; audio_channels = 2;
codec_channels = 2; codec_channels = 2;
@ -340,11 +296,6 @@ void TestStereo::Perform() {
audio_channels = 1; audio_channels = 1;
codec_channels = 2; codec_channels = 2;
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
test_cntr_++; test_cntr_++;
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
@ -352,43 +303,25 @@ void TestStereo::Perform() {
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
test_cntr_++; test_cntr_++;
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels); RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
#ifdef PCMA_AND_PCMU #ifdef PCMA_AND_PCMU
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
test_cntr_++; test_cntr_++;
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
@ -399,12 +332,6 @@ void TestStereo::Perform() {
out_file_.Close(); out_file_.Close();
#endif #endif
#ifdef WEBRTC_CODEC_OPUS #ifdef WEBRTC_CODEC_OPUS
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Mono-to-stereo\n");
}
// Keep encode and decode in stereo. // Keep encode and decode in stereo.
test_cntr_++; test_cntr_++;
channel_a2b_->set_codec_mode(kStereo); channel_a2b_->set_codec_mode(kStereo);
@ -426,54 +353,30 @@ void TestStereo::Perform() {
channel_a2b_->set_codec_mode(kMono); channel_a2b_->set_codec_mode(kMono);
// Run stereo audio and mono codec. // Run stereo audio and mono codec.
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels); RegisterSendCodec('A', codec_g722, 16000, 64000, 160, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels); RegisterSendCodec('A', codec_l16, 8000, 128000, 80, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels); RegisterSendCodec('A', codec_l16, 16000, 256000, 160, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
if (test_mode_ != 0) {
printf("==============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels); RegisterSendCodec('A', codec_l16, 32000, 512000, 320, codec_channels);
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
#ifdef PCMA_AND_PCMU #ifdef PCMA_AND_PCMU
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels); RegisterSendCodec('A', codec_pcmu, 8000, 64000, 80, codec_channels);
@ -483,26 +386,11 @@ void TestStereo::Perform() {
out_file_.Close(); out_file_.Close();
#endif #endif
#ifdef WEBRTC_CODEC_OPUS #ifdef WEBRTC_CODEC_OPUS
if (test_mode_ != 0) {
printf("===============================================================\n");
printf("Test number: %d\n", test_cntr_ + 1);
printf("Test type: Stereo-to-mono\n");
}
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
// Encode and decode in mono. // Encode and decode in mono.
RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels); RegisterSendCodec('A', codec_opus, 48000, 32000, 960, codec_channels);
CodecInst opus_codec_param; acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
for (uint8_t n = 0; n < num_encoders; n++) {
EXPECT_EQ(0, acm_b_->Codec(n, &opus_codec_param));
if (!strcmp(opus_codec_param.plname, "opus")) {
opus_codec_param.channels = 1;
EXPECT_EQ(true,
acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
CodecInstToSdp(opus_codec_param)));
break;
}
}
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
// Encode in stereo, decode in mono. // Encode in stereo, decode in mono.
@ -516,65 +404,22 @@ void TestStereo::Perform() {
// Decode in mono. // Decode in mono.
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
if (test_mode_ != 0) {
// Print out codec and settings
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n",
test_cntr_);
}
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
// Decode in stereo. // Decode in stereo.
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
if (test_mode_ != 0) { acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2, {{"stereo", "1"}}}}});
// Print out codec and settings
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: stereo\n",
test_cntr_);
}
opus_codec_param.channels = 2;
EXPECT_EQ(true,
acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
CodecInstToSdp(opus_codec_param)));
Run(channel_a2b_, audio_channels, 2); Run(channel_a2b_, audio_channels, 2);
out_file_.Close(); out_file_.Close();
// Decode in mono. // Decode in mono.
test_cntr_++; test_cntr_++;
OpenOutFile(test_cntr_); OpenOutFile(test_cntr_);
if (test_mode_ != 0) { acm_b_->SetReceiveCodecs({{120, {"OPUS", 48000, 2}}});
// Print out codec and settings
printf(
"Test number: %d\nCodec: Opus Freq: 48000 Rate :32000 PackSize: 960"
" Decode: mono\n",
test_cntr_);
}
opus_codec_param.channels = 1;
EXPECT_EQ(true,
acm_b_->RegisterReceiveCodec(opus_codec_param.pltype,
CodecInstToSdp(opus_codec_param)));
Run(channel_a2b_, audio_channels, codec_channels); Run(channel_a2b_, audio_channels, codec_channels);
out_file_.Close(); out_file_.Close();
#endif #endif
// Print out which codecs were tested, and which were not, in the run.
if (test_mode_ != 0) {
printf("\nThe following codecs was INCLUDED in the test:\n");
printf(" G.722\n");
printf(" PCM16\n");
printf(" G.711\n");
#ifdef WEBRTC_CODEC_OPUS
printf(" Opus\n");
#endif
printf(
"\nTo complete the test, listen to the %d number of output "
"files.\n",
test_cntr_);
}
// Delete the file pointers. // Delete the file pointers.
delete in_file_stereo_; delete in_file_stereo_;
delete in_file_mono_; delete in_file_mono_;
@ -594,12 +439,6 @@ void TestStereo::RegisterSendCodec(char side,
int rate, int rate,
int pack_size, int pack_size,
int channels) { int channels) {
if (test_mode_ != 0) {
// Print out codec and settings
printf("Codec: %s Freq: %d Rate: %d PackSize: %d\n", codec_name,
sampling_freq_hz, rate, pack_size);
}
// Store packet size in samples, used to validate the received packet // Store packet size in samples, used to validate the received packet
pack_size_samp_ = pack_size; pack_size_samp_ = pack_size;
@ -719,7 +558,7 @@ void TestStereo::Run(TestPackStereo* channel,
} }
} }
// Run received side of ACM // Run receive side of ACM
bool muted; bool muted;
EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted)); EXPECT_EQ(0, acm_b_->PlayoutData10Ms(out_freq_hz_b, &audio_frame, &muted));
ASSERT_FALSE(muted); ASSERT_FALSE(muted);
@ -758,17 +597,4 @@ void TestStereo::OpenOutFile(int16_t test_number) {
out_file_.Open(file_name, 32000, "wb"); out_file_.Open(file_name, 32000, "wb");
} }
void TestStereo::DisplaySendReceiveCodec() {
auto send_codec = acm_a_->SendCodec();
if (test_mode_ != 0) {
ASSERT_TRUE(send_codec);
printf("%s -> ", send_codec->plname);
}
CodecInst receive_codec;
acm_b_->ReceiveCodec(&receive_codec);
if (test_mode_ != 0) {
printf("%s\n", receive_codec.plname);
}
}
} // namespace webrtc } // namespace webrtc

View File

@ -15,7 +15,7 @@
#include <memory> #include <memory>
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#define PCMA_AND_PCMU #define PCMA_AND_PCMU
@ -58,7 +58,7 @@ class TestPackStereo : public AudioPacketizationCallback {
class TestStereo { class TestStereo {
public: public:
explicit TestStereo(int test_mode); TestStereo();
~TestStereo(); ~TestStereo();
void Perform(); void Perform();
@ -79,9 +79,6 @@ class TestStereo {
int out_channels, int out_channels,
int percent_loss = 0); int percent_loss = 0);
void OpenOutFile(int16_t test_number); void OpenOutFile(int16_t test_number);
void DisplaySendReceiveCodec();
int test_mode_;
std::unique_ptr<AudioCodingModule> acm_a_; std::unique_ptr<AudioCodingModule> acm_a_;
std::unique_ptr<AudioCodingModule> acm_b_; std::unique_ptr<AudioCodingModule> acm_b_;

View File

@ -23,8 +23,8 @@
#include "api/audio_codecs/opus/audio_encoder_opus.h" #include "api/audio_codecs/opus/audio_encoder_opus.h"
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h" #include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/utility.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
namespace webrtc { namespace webrtc {
@ -94,8 +94,9 @@ bool TestVadDtx::RegisterCodec(const SdpAudioFormat& codec_format,
channel_->SetIsStereo(encoder->NumChannels() > 1); channel_->SetIsStereo(encoder->NumChannels() > 1);
acm_send_->SetEncoder(std::move(encoder)); acm_send_->SetEncoder(std::move(encoder));
EXPECT_EQ(true, std::map<int, SdpAudioFormat> receive_codecs = {{payload_type, codec_format}};
acm_receive_->RegisterReceiveCodec(payload_type, codec_format)); acm_receive_->SetReceiveCodecs(receive_codecs);
return added_comfort_noise; return added_comfort_noise;
} }

View File

@ -16,7 +16,6 @@
#include "api/audio_codecs/audio_decoder_factory.h" #include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_encoder_factory.h" #include "api/audio_codecs/audio_encoder_factory.h"
#include "common_audio/vad/include/vad.h" #include "common_audio/vad/include/vad.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/test/Channel.h"

View File

@ -25,12 +25,8 @@
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
// This parameter is used to describe how to run the tests. It is normally
// set to 0, and all tests are run in quite mode.
#define ACM_TEST_MODE 0
TEST(AudioCodingModuleTest, TestAllCodecs) { TEST(AudioCodingModuleTest, TestAllCodecs) {
webrtc::TestAllCodecs(ACM_TEST_MODE).Perform(); webrtc::TestAllCodecs().Perform();
} }
#if defined(WEBRTC_ANDROID) #if defined(WEBRTC_ANDROID)
@ -38,7 +34,7 @@ TEST(AudioCodingModuleTest, DISABLED_TestEncodeDecode) {
#else #else
TEST(AudioCodingModuleTest, TestEncodeDecode) { TEST(AudioCodingModuleTest, TestEncodeDecode) {
#endif #endif
webrtc::EncodeDecodeTest(ACM_TEST_MODE).Perform(); webrtc::EncodeDecodeTest().Perform();
} }
TEST(AudioCodingModuleTest, TestRedFec) { TEST(AudioCodingModuleTest, TestRedFec) {
@ -50,7 +46,7 @@ TEST(AudioCodingModuleTest, DISABLED_TestIsac) {
#else #else
TEST(AudioCodingModuleTest, TestIsac) { TEST(AudioCodingModuleTest, TestIsac) {
#endif #endif
webrtc::ISACTest(ACM_TEST_MODE).Perform(); webrtc::ISACTest().Perform();
} }
#if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \ #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) && \
@ -70,7 +66,7 @@ TEST(AudioCodingModuleTest, DISABLED_TestStereo) {
#else #else
TEST(AudioCodingModuleTest, TestStereo) { TEST(AudioCodingModuleTest, TestStereo) {
#endif #endif
webrtc::TestStereo(ACM_TEST_MODE).Perform(); webrtc::TestStereo().Perform();
} }
TEST(AudioCodingModuleTest, TestWebRtcVadDtx) { TEST(AudioCodingModuleTest, TestWebRtcVadDtx) {

View File

@ -16,15 +16,9 @@
#include <memory> #include <memory>
#ifdef WIN32
#include <Windows.h>
#endif
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/utility.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
@ -65,25 +59,26 @@ void TwoWayCommunication::SetUpAutotest(
const int payload_type1, const int payload_type1,
const SdpAudioFormat& format2, const SdpAudioFormat& format2,
const int payload_type2) { const int payload_type2) {
//--- Set A codecs //--- Set A codecs
_acmA->SetEncoder( _acmA->SetEncoder(
encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt)); encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt));
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(payload_type2, format2)); _acmA->SetReceiveCodecs({{payload_type2, format2}});
//--- Set ref-A codecs //--- Set ref-A codecs
_acmRefA->SetEncoder( _acmRefA->SetEncoder(
encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt)); encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt));
EXPECT_EQ(true, _acmRefA->RegisterReceiveCodec(payload_type2, format2)); _acmRefA->SetReceiveCodecs({{payload_type2, format2}});
//--- Set B codecs //--- Set B codecs
_acmB->SetEncoder( _acmB->SetEncoder(
encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt)); encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt));
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(payload_type1, format1)); _acmB->SetReceiveCodecs({{payload_type1, format1}});
//--- Set ref-B codecs //--- Set ref-B codecs
_acmRefB->SetEncoder( _acmRefB->SetEncoder(
encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt)); encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt));
EXPECT_EQ(true, _acmRefB->RegisterReceiveCodec(payload_type1, format1)); _acmRefB->SetReceiveCodecs({{payload_type1, format1}});
uint16_t frequencyHz; uint16_t frequencyHz;
@ -184,14 +179,13 @@ void TwoWayCommunication::Perform() {
if (((secPassed % 5) == 4) && (msecPassed >= 990)) { if (((secPassed % 5) == 4) && (msecPassed >= 990)) {
_acmB->SetEncoder(encoder_factory->MakeAudioEncoder( _acmB->SetEncoder(encoder_factory->MakeAudioEncoder(
payload_type2, format2, absl::nullopt)); payload_type2, format2, absl::nullopt));
EXPECT_TRUE(_acmB->SendCodec());
} }
// Initialize receiver on side A. // Initialize receiver on side A.
if (((secPassed % 7) == 6) && (msecPassed == 0)) if (((secPassed % 7) == 6) && (msecPassed == 0))
EXPECT_EQ(0, _acmA->InitializeReceiver()); EXPECT_EQ(0, _acmA->InitializeReceiver());
// Re-register codec on side A. // Re-register codec on side A.
if (((secPassed % 7) == 6) && (msecPassed >= 990)) { if (((secPassed % 7) == 6) && (msecPassed >= 990)) {
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(payload_type2, format2)); _acmA->SetReceiveCodecs({{payload_type2, format2}});
} }
} }
} }

View File

@ -18,7 +18,6 @@
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/test/Channel.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/utility.h"
namespace webrtc { namespace webrtc {

View File

@ -14,20 +14,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef _WIN32
#include <windows.h>
#elif defined(WEBRTC_LINUX)
#include <time.h>
#else
#include <sys/time.h>
#include <time.h>
#endif
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/isac/audio_encoder_isac_float.h" #include "api/audio_codecs/isac/audio_encoder_isac_float.h"
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/test/utility.h"
#include "rtc_base/strings/string_builder.h" #include "rtc_base/strings/string_builder.h"
#include "rtc_base/timeutils.h" #include "rtc_base/timeutils.h"
#include "system_wrappers/include/sleep.h" #include "system_wrappers/include/sleep.h"
@ -43,15 +32,10 @@ using ::testing::StrCaseEq;
namespace { namespace {
AudioEncoderIsacFloat::Config MakeConfig(const CodecInst& ci) { constexpr int kISAC16kPayloadType = 103;
EXPECT_THAT(ci.plname, StrCaseEq("ISAC")); constexpr int kISAC32kPayloadType = 104;
EXPECT_THAT(ci.plfreq, AnyOf(Eq(16000), Eq(32000))); const SdpAudioFormat kISAC16kFormat = { "ISAC", 16000, 1 };
EXPECT_THAT(ci.channels, Eq(1u)); const SdpAudioFormat kISAC32kFormat = { "ISAC", 32000, 1 };
AudioEncoderIsacFloat::Config config;
config.sample_rate_hz = ci.plfreq;
EXPECT_THAT(config.IsOk(), Eq(true));
return config;
}
AudioEncoderIsacFloat::Config TweakConfig( AudioEncoderIsacFloat::Config TweakConfig(
AudioEncoderIsacFloat::Config config, AudioEncoderIsacFloat::Config config,
@ -77,43 +61,96 @@ void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
} // namespace } // namespace
ISACTest::ISACTest(int testMode) ISACTest::ACMTestTimer::ACMTestTimer() : _msec(0), _sec(0), _min(0), _hour(0) {
return;
}
ISACTest::ACMTestTimer::~ACMTestTimer() {
return;
}
void ISACTest::ACMTestTimer::Reset() {
_msec = 0;
_sec = 0;
_min = 0;
_hour = 0;
return;
}
void ISACTest::ACMTestTimer::Tick10ms() {
_msec += 10;
Adjust();
return;
}
void ISACTest::ACMTestTimer::Tick1ms() {
_msec++;
Adjust();
return;
}
void ISACTest::ACMTestTimer::Tick100ms() {
_msec += 100;
Adjust();
return;
}
void ISACTest::ACMTestTimer::Tick1sec() {
_sec++;
Adjust();
return;
}
void ISACTest::ACMTestTimer::CurrentTimeHMS(char* currTime) {
sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min,
(double)_sec + (double)_msec / 1000.);
return;
}
void ISACTest::ACMTestTimer::CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms) {
h = _hour;
m = _min;
s = _sec;
ms = _msec;
return;
}
void ISACTest::ACMTestTimer::Adjust() {
unsigned int n;
if (_msec >= 1000) {
n = _msec / 1000;
_msec -= (1000 * n);
_sec += n;
}
if (_sec >= 60) {
n = _sec / 60;
_sec -= (n * 60);
_min += n;
}
if (_min >= 60) {
n = _min / 60;
_min -= (n * 60);
_hour += n;
}
}
ISACTest::ISACTest()
: _acmA(AudioCodingModule::Create( : _acmA(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
_acmB(AudioCodingModule::Create( _acmB(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))), AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))) {}
_testMode(testMode) {}
ISACTest::~ISACTest() {} ISACTest::~ISACTest() {}
void ISACTest::Setup() { void ISACTest::Setup() {
int codecCntr;
CodecInst codecParam;
for (codecCntr = 0; codecCntr < AudioCodingModule::NumberOfCodecs();
codecCntr++) {
EXPECT_EQ(0, AudioCodingModule::Codec(codecCntr, &codecParam));
if (absl::EqualsIgnoreCase(codecParam.plname, "ISAC") &&
codecParam.plfreq == 16000) {
memcpy(&_paramISAC16kHz, &codecParam, sizeof(CodecInst));
_idISAC16kHz = codecCntr;
}
if (absl::EqualsIgnoreCase(codecParam.plname, "ISAC") &&
codecParam.plfreq == 32000) {
memcpy(&_paramISAC32kHz, &codecParam, sizeof(CodecInst));
_idISAC32kHz = codecCntr;
}
}
// Register both iSAC-wb & iSAC-swb in both sides as receiver codecs. // Register both iSAC-wb & iSAC-swb in both sides as receiver codecs.
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype, std::map<int, SdpAudioFormat> receive_codecs =
CodecInstToSdp(_paramISAC16kHz))); {{kISAC16kPayloadType, kISAC16kFormat},
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype, {kISAC32kPayloadType, kISAC32kFormat}};
CodecInstToSdp(_paramISAC32kHz))); _acmA->SetReceiveCodecs(receive_codecs);
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC16kHz.pltype, _acmB->SetReceiveCodecs(receive_codecs);
CodecInstToSdp(_paramISAC16kHz)));
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC32kHz.pltype,
CodecInstToSdp(_paramISAC32kHz)));
//--- Set A-to-B channel //--- Set A-to-B channel
_channel_A2B.reset(new Channel); _channel_A2B.reset(new Channel);
@ -128,10 +165,14 @@ void ISACTest::Setup() {
file_name_swb_ = file_name_swb_ =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmB->SetEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( *AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); kISAC16kPayloadType));
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
_inFileA.Open(file_name_swb_, 32000, "rb"); _inFileA.Open(file_name_swb_, 32000, "rb");
// Set test length to 500 ms (50 blocks of 10 ms each). // Set test length to 500 ms (50 blocks of 10 ms each).
@ -146,9 +187,9 @@ void ISACTest::Setup() {
while (!_inFileA.EndOfFile()) { while (!_inFileA.EndOfFile()) {
Run10ms(); Run10ms();
} }
CodecInst receiveCodec;
EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec)); EXPECT_TRUE(_acmA->ReceiveFormat());
EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec)); EXPECT_TRUE(_acmB->ReceiveFormat());
_inFileA.Close(); _inFileA.Close();
_outFileA.Close(); _outFileA.Close();
@ -170,45 +211,13 @@ void ISACTest::Perform() {
testNr++; testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig); EncodeDecode(testNr, wbISACConfig, swbISACConfig);
if (_testMode != 0) {
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = -1;
swbISACConfig.currentRateBitPerSec = -1;
wbISACConfig.initRateBitPerSec = 13000;
wbISACConfig.initFrameSizeInMsec = 60;
swbISACConfig.initRateBitPerSec = 20000;
swbISACConfig.initFrameSizeInMsec = 30;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig);
wbISACConfig.currentRateBitPerSec = 20000;
swbISACConfig.currentRateBitPerSec = 48000;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
wbISACConfig.currentRateBitPerSec = 16000;
swbISACConfig.currentRateBitPerSec = 30000;
wbISACConfig.currentFrameSizeMsec = 60;
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
}
SetISACConfigDefault(wbISACConfig); SetISACConfigDefault(wbISACConfig);
SetISACConfigDefault(swbISACConfig); SetISACConfigDefault(swbISACConfig);
testNr++; testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig); EncodeDecode(testNr, wbISACConfig, swbISACConfig);
testNr++; testNr++;
if (_testMode == 0) { SwitchingSamplingRate(testNr, 4);
SwitchingSamplingRate(testNr, 4);
} else {
SwitchingSamplingRate(testNr, 80);
}
} }
void ISACTest::Run10ms() { void ISACTest::Run10ms() {
@ -245,12 +254,16 @@ void ISACTest::EncodeDecode(int testNr,
_outFileB.Open(file_name_out, 32000, "wb"); _outFileB.Open(file_name_out, 32000, "wb");
// Side A is sending super-wideband, and side B is sending wideband. // Side A is sending super-wideband, and side B is sending wideband.
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmA->SetEncoder(
TweakConfig(MakeConfig(_paramISAC32kHz), swbISACConfig), AudioEncoderIsacFloat::MakeAudioEncoder(
_paramISAC32kHz.pltype)); TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( swbISACConfig),
TweakConfig(MakeConfig(_paramISAC16kHz), wbISACConfig), kISAC32kPayloadType));
_paramISAC16kHz.pltype)); _acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
wbISACConfig),
kISAC16kPayloadType));
bool adaptiveMode = false; bool adaptiveMode = false;
if ((swbISACConfig.currentRateBitPerSec == -1) || if ((swbISACConfig.currentRateBitPerSec == -1) ||
@ -262,30 +275,10 @@ void ISACTest::EncodeDecode(int testNr,
_channel_B2A->ResetStats(); _channel_B2A->ResetStats();
char currentTime[500]; char currentTime[500];
int64_t time_ms = rtc::TimeMillis();
while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) { while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
Run10ms(); Run10ms();
_myTimer.Tick10ms(); _myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime); _myTimer.CurrentTimeHMS(currentTime);
if ((adaptiveMode) && (_testMode != 0)) {
time_ms += 10;
int64_t time_left_ms = time_ms - rtc::TimeMillis();
if (time_left_ms > 0) {
SleepMs(time_left_ms);
}
EXPECT_TRUE(_acmA->SendCodec());
EXPECT_TRUE(_acmB->SendCodec());
}
}
if (_testMode != 0) {
printf("\n\nSide A statistics\n\n");
_channel_A2B->PrintStats(_paramISAC32kHz);
printf("\n\nSide B statistics\n\n");
_channel_B2A->PrintStats(_paramISAC16kHz);
} }
_channel_A2B->ResetStats(); _channel_A2B->ResetStats();
@ -316,10 +309,14 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
// Start with side A sending super-wideband and side B seding wideband. // Start with side A sending super-wideband and side B seding wideband.
// Toggle sending wideband/super-wideband in this test. // Toggle sending wideband/super-wideband in this test.
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmA->SetEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( *AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); kISAC32kPayloadType));
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
int numSendCodecChanged = 0; int numSendCodecChanged = 0;
_myTimer.Reset(); _myTimer.Reset();
@ -328,21 +325,23 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
Run10ms(); Run10ms();
_myTimer.Tick10ms(); _myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime); _myTimer.CurrentTimeHMS(currentTime);
if (_testMode == 2)
printf("\r%s", currentTime);
if (_inFileA.EndOfFile()) { if (_inFileA.EndOfFile()) {
if (_inFileA.SamplingFrequency() == 16000) { if (_inFileA.SamplingFrequency() == 16000) {
// Switch side A to send super-wideband. // Switch side A to send super-wideband.
_inFileA.Close(); _inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb"); _inFileA.Open(file_name_swb_, 32000, "rb");
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmA->SetEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
} else { } else {
// Switch side A to send wideband. // Switch side A to send wideband.
_inFileA.Close(); _inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb"); _inFileA.Open(file_name_swb_, 32000, "rb");
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmA->SetEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
} }
numSendCodecChanged++; numSendCodecChanged++;
} }
@ -352,14 +351,18 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
// Switch side B to send super-wideband. // Switch side B to send super-wideband.
_inFileB.Close(); _inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb"); _inFileB.Open(file_name_swb_, 32000, "rb");
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmB->SetEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
} else { } else {
// Switch side B to send wideband. // Switch side B to send wideband.
_inFileB.Close(); _inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb"); _inFileB.Open(file_name_swb_, 32000, "rb");
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder( _acmB->SetEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype)); AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
} }
numSendCodecChanged++; numSendCodecChanged++;
} }

View File

@ -15,14 +15,9 @@
#include <memory> #include <memory>
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/test/Channel.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/utility.h"
#define MAX_FILE_NAME_LENGTH_BYTE 500
#define NO_OF_CLIENTS 15
namespace webrtc { namespace webrtc {
@ -37,12 +32,37 @@ struct ACMTestISACConfig {
class ISACTest { class ISACTest {
public: public:
explicit ISACTest(int testMode); ISACTest();
~ISACTest(); ~ISACTest();
void Perform(); void Perform();
private: private:
class ACMTestTimer {
public:
ACMTestTimer();
~ACMTestTimer();
void Reset();
void Tick10ms();
void Tick1ms();
void Tick100ms();
void Tick1sec();
void CurrentTimeHMS(char* currTime);
void CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms);
private:
void Adjust();
unsigned short _msec;
unsigned char _sec;
unsigned char _min;
unsigned long _hour;
};
void Setup(); void Setup();
void Run10ms(); void Run10ms();
@ -65,15 +85,9 @@ class ISACTest {
PCMFile _outFileA; PCMFile _outFileA;
PCMFile _outFileB; PCMFile _outFileB;
uint8_t _idISAC16kHz;
uint8_t _idISAC32kHz;
CodecInst _paramISAC16kHz;
CodecInst _paramISAC32kHz;
std::string file_name_swb_; std::string file_name_swb_;
ACMTestTimer _myTimer; ACMTestTimer _myTimer;
int _testMode;
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -13,12 +13,9 @@
#include <string> #include <string>
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/codecs/opus/opus_interface.h" #include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "modules/audio_coding/test/TestStereo.h" #include "modules/audio_coding/test/TestStereo.h"
#include "modules/audio_coding/test/utility.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
@ -89,13 +86,10 @@ void OpusTest::Perform() {
EXPECT_EQ(0, acm_receiver_->InitializeReceiver()); EXPECT_EQ(0, acm_receiver_->InitializeReceiver());
// Register Opus stereo as receiving codec. // Register Opus stereo as receiving codec.
CodecInst opus_codec_param; constexpr int kOpusPayloadType = 120;
int codec_id = acm_receiver_->Codec("opus", 48000, 2); const SdpAudioFormat kOpusFormatStereo("opus", 48000, 2, {{"stereo", "1"}});
EXPECT_EQ(0, acm_receiver_->Codec(codec_id, &opus_codec_param)); payload_type_ = kOpusPayloadType;
payload_type_ = opus_codec_param.pltype; acm_receiver_->SetReceiveCodecs({{kOpusPayloadType, kOpusFormatStereo}});
EXPECT_EQ(true,
acm_receiver_->RegisterReceiveCodec(
opus_codec_param.pltype, CodecInstToSdp(opus_codec_param)));
// Create and connect the channel. // Create and connect the channel.
channel_a2b_ = new TestPackStereo; channel_a2b_ = new TestPackStereo;
@ -159,10 +153,8 @@ void OpusTest::Perform() {
OpenOutFile(test_cntr); OpenOutFile(test_cntr);
// Register Opus mono as receiving codec. // Register Opus mono as receiving codec.
opus_codec_param.channels = 1; const SdpAudioFormat kOpusFormatMono("opus", 48000, 2);
EXPECT_EQ(true, acm_receiver_->SetReceiveCodecs({{kOpusPayloadType, kOpusFormatMono}});
acm_receiver_->RegisterReceiveCodec(
opus_codec_param.pltype, CodecInstToSdp(opus_codec_param)));
// Run Opus with 2.5 ms frame size. // Run Opus with 2.5 ms frame size.
Run(channel_a2b_, audio_channels, 32000, 120); Run(channel_a2b_, audio_channels, 32000, 120);

View File

@ -17,7 +17,6 @@
#include "modules/audio_coding/acm2/acm_resampler.h" #include "modules/audio_coding/acm2/acm_resampler.h"
#include "modules/audio_coding/codecs/opus/opus_interface.h" #include "modules/audio_coding/codecs/opus/opus_interface.h"
#include "modules/audio_coding/test/Channel.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/TestStereo.h" #include "modules/audio_coding/test/TestStereo.h"

View File

@ -12,10 +12,8 @@
#include "api/audio/audio_frame.h" #include "api/audio/audio_frame.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/pcm16b/pcm16b.h" #include "modules/audio_coding/codecs/pcm16b/pcm16b.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/utility.h"
#include "modules/include/module_common_types.h" #include "modules/include/module_common_types.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/testsupport/fileutils.h" #include "test/testsupport/fileutils.h"
@ -35,8 +33,9 @@ class TargetDelayTest : public ::testing::Test {
ASSERT_EQ(0, acm_->InitializeReceiver()); ASSERT_EQ(0, acm_->InitializeReceiver());
constexpr int pltype = 108; constexpr int pltype = 108;
ASSERT_EQ(true, std::map<int, SdpAudioFormat> receive_codecs =
acm_->RegisterReceiveCodec(pltype, {"L16", kSampleRateHz, 1})); {{pltype, {"L16", kSampleRateHz, 1}}};
acm_->SetReceiveCodecs(receive_codecs);
rtp_info_.header.payloadType = pltype; rtp_info_.header.payloadType = pltype;
rtp_info_.header.timestamp = 0; rtp_info_.header.timestamp = 0;

View File

@ -1,299 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "utility.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "absl/strings/match.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "test/gtest.h"
#define NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE 13
namespace webrtc {
ACMTestTimer::ACMTestTimer() : _msec(0), _sec(0), _min(0), _hour(0) {
return;
}
ACMTestTimer::~ACMTestTimer() {
return;
}
void ACMTestTimer::Reset() {
_msec = 0;
_sec = 0;
_min = 0;
_hour = 0;
return;
}
void ACMTestTimer::Tick10ms() {
_msec += 10;
Adjust();
return;
}
void ACMTestTimer::Tick1ms() {
_msec++;
Adjust();
return;
}
void ACMTestTimer::Tick100ms() {
_msec += 100;
Adjust();
return;
}
void ACMTestTimer::Tick1sec() {
_sec++;
Adjust();
return;
}
void ACMTestTimer::CurrentTimeHMS(char* currTime) {
sprintf(currTime, "%4lu:%02u:%06.3f", _hour, _min,
(double)_sec + (double)_msec / 1000.);
return;
}
void ACMTestTimer::CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms) {
h = _hour;
m = _min;
s = _sec;
ms = _msec;
return;
}
void ACMTestTimer::Adjust() {
unsigned int n;
if (_msec >= 1000) {
n = _msec / 1000;
_msec -= (1000 * n);
_sec += n;
}
if (_sec >= 60) {
n = _sec / 60;
_sec -= (n * 60);
_min += n;
}
if (_min >= 60) {
n = _min / 60;
_min -= (n * 60);
_hour += n;
}
}
int16_t ChooseCodec(CodecInst& codecInst) {
PrintCodecs();
// AudioCodingModule* tmpACM = AudioCodingModule::Create(0);
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
int8_t codecID;
bool outOfRange = false;
char myStr[15] = "";
do {
printf("\nChoose a codec [0]: ");
EXPECT_TRUE(fgets(myStr, 10, stdin) != NULL);
codecID = atoi(myStr);
if ((codecID < 0) || (codecID >= noCodec)) {
printf("\nOut of range.\n");
outOfRange = true;
}
} while (outOfRange);
CHECK_ERROR(AudioCodingModule::Codec((uint8_t)codecID, &codecInst));
return 0;
}
void PrintCodecs() {
uint8_t noCodec = AudioCodingModule::NumberOfCodecs();
CodecInst codecInst;
printf("No Name [Hz] [bps]\n");
for (uint8_t codecCntr = 0; codecCntr < noCodec; codecCntr++) {
AudioCodingModule::Codec(codecCntr, &codecInst);
printf("%2d- %-18s %5d %6d\n", codecCntr, codecInst.plname,
codecInst.plfreq, codecInst.rate);
}
}
namespace test {
CircularBuffer::CircularBuffer(uint32_t len)
: _buff(NULL),
_idx(0),
_buffIsFull(false),
_calcAvg(false),
_calcVar(false),
_sum(0),
_sumSqr(0) {
_buff = new double[len];
if (_buff == NULL) {
_buffLen = 0;
} else {
for (uint32_t n = 0; n < len; n++) {
_buff[n] = 0;
}
_buffLen = len;
}
}
CircularBuffer::~CircularBuffer() {
if (_buff != NULL) {
delete[] _buff;
_buff = NULL;
}
}
void CircularBuffer::Update(const double newVal) {
assert(_buffLen > 0);
// store the value that is going to be overwritten
double oldVal = _buff[_idx];
// record the new value
_buff[_idx] = newVal;
// increment the index, to point to where we would
// write next
_idx++;
// it is a circular buffer, if we are at the end
// we have to cycle to the beginning
if (_idx >= _buffLen) {
// flag that the buffer is filled up.
_buffIsFull = true;
_idx = 0;
}
// Update
if (_calcAvg) {
// for the average we have to update
// the sum
_sum += (newVal - oldVal);
}
if (_calcVar) {
// to calculate variance we have to update
// the sum of squares
_sumSqr += (double)(newVal - oldVal) * (double)(newVal + oldVal);
}
}
void CircularBuffer::SetArithMean(bool enable) {
assert(_buffLen > 0);
if (enable && !_calcAvg) {
uint32_t lim;
if (_buffIsFull) {
lim = _buffLen;
} else {
lim = _idx;
}
_sum = 0;
for (uint32_t n = 0; n < lim; n++) {
_sum += _buff[n];
}
}
_calcAvg = enable;
}
void CircularBuffer::SetVariance(bool enable) {
assert(_buffLen > 0);
if (enable && !_calcVar) {
uint32_t lim;
if (_buffIsFull) {
lim = _buffLen;
} else {
lim = _idx;
}
_sumSqr = 0;
for (uint32_t n = 0; n < lim; n++) {
_sumSqr += _buff[n] * _buff[n];
}
}
_calcAvg = enable;
}
int16_t CircularBuffer::ArithMean(double& mean) {
assert(_buffLen > 0);
if (_buffIsFull) {
mean = _sum / (double)_buffLen;
return 0;
} else {
if (_idx > 0) {
mean = _sum / (double)_idx;
return 0;
} else {
return -1;
}
}
}
int16_t CircularBuffer::Variance(double& var) {
assert(_buffLen > 0);
if (_buffIsFull) {
var = _sumSqr / (double)_buffLen;
return 0;
} else {
if (_idx > 0) {
var = _sumSqr / (double)_idx;
return 0;
} else {
return -1;
}
}
}
} // namespace test
bool FixedPayloadTypeCodec(const char* payloadName) {
char fixPayloadTypeCodecs[NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE][32] = {
"PCMU", "PCMA", "GSM", "G723", "DVI4", "LPC", "PCMA",
"G722", "QCELP", "CN", "MPA", "G728", "G729"};
for (int n = 0; n < NUM_CODECS_WITH_FIXED_PAYLOAD_TYPE; n++) {
if (absl::EqualsIgnoreCase(payloadName, fixPayloadTypeCodecs[n])) {
return true;
}
}
return false;
}
void VADCallback::Reset() {
memset(_numFrameTypes, 0, sizeof(_numFrameTypes));
}
VADCallback::VADCallback() {
memset(_numFrameTypes, 0, sizeof(_numFrameTypes));
}
void VADCallback::PrintFrameTypes() {
printf("kEmptyFrame......... %d\n", _numFrameTypes[kEmptyFrame]);
printf("kAudioFrameSpeech... %d\n", _numFrameTypes[kAudioFrameSpeech]);
printf("kAudioFrameCN....... %d\n", _numFrameTypes[kAudioFrameCN]);
printf("kVideoFrameKey...... %d\n", _numFrameTypes[kVideoFrameKey]);
printf("kVideoFrameDelta.... %d\n", _numFrameTypes[kVideoFrameDelta]);
}
int32_t VADCallback::InFrameType(FrameType frame_type) {
_numFrameTypes[frame_type]++;
return 0;
}
} // namespace webrtc

View File

@ -1,140 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_AUDIO_CODING_TEST_UTILITY_H_
#define MODULES_AUDIO_CODING_TEST_UTILITY_H_
#include "modules/audio_coding/include/audio_coding_module.h"
#include "test/gtest.h"
namespace webrtc {
//-----------------------------
#define CHECK_ERROR(f) \
do { \
EXPECT_GE(f, 0) << "Error Calling API"; \
} while (0)
//-----------------------------
#define CHECK_PROTECTED(f) \
do { \
if (f >= 0) { \
ADD_FAILURE() << "Error Calling API"; \
} else { \
printf("An expected error is caught.\n"); \
} \
} while (0)
//----------------------------
#define CHECK_ERROR_MT(f) \
do { \
if (f < 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
__LINE__); \
} \
} while (0)
//----------------------------
#define CHECK_PROTECTED_MT(f) \
do { \
if (f >= 0) { \
fprintf(stderr, "Error Calling API in file %s at line %d \n", __FILE__, \
__LINE__); \
} else { \
printf("An expected error is caught.\n"); \
} \
} while (0)
#define DELETE_POINTER(p) \
do { \
if (p != NULL) { \
delete p; \
p = NULL; \
} \
} while (0)
class ACMTestTimer {
public:
ACMTestTimer();
~ACMTestTimer();
void Reset();
void Tick10ms();
void Tick1ms();
void Tick100ms();
void Tick1sec();
void CurrentTimeHMS(char* currTime);
void CurrentTime(unsigned long& h,
unsigned char& m,
unsigned char& s,
unsigned short& ms);
private:
void Adjust();
unsigned short _msec;
unsigned char _sec;
unsigned char _min;
unsigned long _hour;
};
// To avoid clashes with CircularBuffer in APM.
namespace test {
class CircularBuffer {
public:
CircularBuffer(uint32_t len);
~CircularBuffer();
void SetArithMean(bool enable);
void SetVariance(bool enable);
void Update(const double newVal);
void IsBufferFull();
int16_t Variance(double& var);
int16_t ArithMean(double& mean);
protected:
double* _buff;
uint32_t _idx;
uint32_t _buffLen;
bool _buffIsFull;
bool _calcAvg;
bool _calcVar;
double _sum;
double _sumSqr;
};
} // namespace test
int16_t ChooseCodec(CodecInst& codecInst);
void PrintCodecs();
bool FixedPayloadTypeCodec(const char* payloadName);
class VADCallback : public ACMVADCallback {
public:
VADCallback();
int32_t InFrameType(FrameType frame_type) override;
void PrintFrameTypes();
void Reset();
private:
uint32_t _numFrameTypes[5];
};
} // namespace webrtc
#endif // MODULES_AUDIO_CODING_TEST_UTILITY_H_