Revert "Remove CodecInst pt.1"

This reverts commit 056f9738bf7a3d16da45398239656e165c4e0851.

Reason for revert: breaks downstream

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}

TBR=solenberg@webrtc.org,kwiberg@webrtc.org

Change-Id: I51d666969bcd63e2b7cb7d669ec2f59b5f8f9dde
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:7626
Reviewed-on: https://webrtc-review.googlesource.com/c/112906
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25881}
This commit is contained in:
Fredrik Solenberg
2018-12-03 15:50:44 +00:00
committed by Commit Bot
parent 9d54bd8898
commit ec0f45be11
24 changed files with 1215 additions and 359 deletions

View File

@ -14,9 +14,20 @@
#include <stdio.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 "api/audio_codecs/builtin_audio_decoder_factory.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/timeutils.h"
#include "system_wrappers/include/sleep.h"
@ -32,10 +43,15 @@ using ::testing::StrCaseEq;
namespace {
constexpr int kISAC16kPayloadType = 103;
constexpr int kISAC32kPayloadType = 104;
const SdpAudioFormat kISAC16kFormat = { "ISAC", 16000, 1 };
const SdpAudioFormat kISAC32kFormat = { "ISAC", 32000, 1 };
AudioEncoderIsacFloat::Config MakeConfig(const CodecInst& ci) {
EXPECT_THAT(ci.plname, StrCaseEq("ISAC"));
EXPECT_THAT(ci.plfreq, AnyOf(Eq(16000), Eq(32000)));
EXPECT_THAT(ci.channels, Eq(1u));
AudioEncoderIsacFloat::Config config;
config.sample_rate_hz = ci.plfreq;
EXPECT_THAT(config.IsOk(), Eq(true));
return config;
}
AudioEncoderIsacFloat::Config TweakConfig(
AudioEncoderIsacFloat::Config config,
@ -61,96 +77,43 @@ void SetISACConfigDefault(ACMTestISACConfig& isacConfig) {
} // namespace
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()
ISACTest::ISACTest(int testMode)
: _acmA(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
_acmB(AudioCodingModule::Create(
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))) {}
AudioCodingModule::Config(CreateBuiltinAudioDecoderFactory()))),
_testMode(testMode) {}
ISACTest::~ISACTest() {}
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.
std::map<int, SdpAudioFormat> receive_codecs =
{{kISAC16kPayloadType, kISAC16kFormat},
{kISAC32kPayloadType, kISAC32kFormat}};
_acmA->SetReceiveCodecs(receive_codecs);
_acmB->SetReceiveCodecs(receive_codecs);
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC16kHz.pltype,
CodecInstToSdp(_paramISAC16kHz)));
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(_paramISAC32kHz.pltype,
CodecInstToSdp(_paramISAC32kHz)));
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC16kHz.pltype,
CodecInstToSdp(_paramISAC16kHz)));
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(_paramISAC32kHz.pltype,
CodecInstToSdp(_paramISAC32kHz)));
//--- Set A-to-B channel
_channel_A2B.reset(new Channel);
@ -165,14 +128,10 @@ void ISACTest::Setup() {
file_name_swb_ =
webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype));
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype));
_inFileA.Open(file_name_swb_, 32000, "rb");
// Set test length to 500 ms (50 blocks of 10 ms each).
@ -187,9 +146,9 @@ void ISACTest::Setup() {
while (!_inFileA.EndOfFile()) {
Run10ms();
}
EXPECT_TRUE(_acmA->ReceiveFormat());
EXPECT_TRUE(_acmB->ReceiveFormat());
CodecInst receiveCodec;
EXPECT_EQ(0, _acmA->ReceiveCodec(&receiveCodec));
EXPECT_EQ(0, _acmB->ReceiveCodec(&receiveCodec));
_inFileA.Close();
_outFileA.Close();
@ -211,13 +170,45 @@ void ISACTest::Perform() {
testNr++;
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(swbISACConfig);
testNr++;
EncodeDecode(testNr, wbISACConfig, swbISACConfig);
testNr++;
SwitchingSamplingRate(testNr, 4);
if (_testMode == 0) {
SwitchingSamplingRate(testNr, 4);
} else {
SwitchingSamplingRate(testNr, 80);
}
}
void ISACTest::Run10ms() {
@ -254,16 +245,12 @@ void ISACTest::EncodeDecode(int testNr,
_outFileB.Open(file_name_out, 32000, "wb");
// Side A is sending super-wideband, and side B is sending wideband.
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
swbISACConfig),
kISAC32kPayloadType));
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
TweakConfig(*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
wbISACConfig),
kISAC16kPayloadType));
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
TweakConfig(MakeConfig(_paramISAC32kHz), swbISACConfig),
_paramISAC32kHz.pltype));
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
TweakConfig(MakeConfig(_paramISAC16kHz), wbISACConfig),
_paramISAC16kHz.pltype));
bool adaptiveMode = false;
if ((swbISACConfig.currentRateBitPerSec == -1) ||
@ -275,10 +262,30 @@ void ISACTest::EncodeDecode(int testNr,
_channel_B2A->ResetStats();
char currentTime[500];
int64_t time_ms = rtc::TimeMillis();
while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
Run10ms();
_myTimer.Tick10ms();
_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();
@ -309,14 +316,10 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
// Start with side A sending super-wideband and side B seding wideband.
// Toggle sending wideband/super-wideband in this test.
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype));
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype));
int numSendCodecChanged = 0;
_myTimer.Reset();
@ -325,23 +328,21 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
Run10ms();
_myTimer.Tick10ms();
_myTimer.CurrentTimeHMS(currentTime);
if (_testMode == 2)
printf("\r%s", currentTime);
if (_inFileA.EndOfFile()) {
if (_inFileA.SamplingFrequency() == 16000) {
// Switch side A to send super-wideband.
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype));
} else {
// Switch side A to send wideband.
_inFileA.Close();
_inFileA.Open(file_name_swb_, 32000, "rb");
_acmA->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
_acmA->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype));
}
numSendCodecChanged++;
}
@ -351,18 +352,14 @@ void ISACTest::SwitchingSamplingRate(int testNr, int maxSampRateChange) {
// Switch side B to send super-wideband.
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC32kFormat),
kISAC32kPayloadType));
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC32kHz), _paramISAC32kHz.pltype));
} else {
// Switch side B to send wideband.
_inFileB.Close();
_inFileB.Open(file_name_swb_, 32000, "rb");
_acmB->SetEncoder(
AudioEncoderIsacFloat::MakeAudioEncoder(
*AudioEncoderIsacFloat::SdpToConfig(kISAC16kFormat),
kISAC16kPayloadType));
_acmB->SetEncoder(AudioEncoderIsacFloat::MakeAudioEncoder(
MakeConfig(_paramISAC16kHz), _paramISAC16kHz.pltype));
}
numSendCodecChanged++;
}