AudioCodingModuleTest.TwoWayCommunication: Don't let the ACM create encoders

It will soon lose the ability to do so.

Bug: webrtc:8396
Change-Id: I7d8e1549c44628fc9bdf2480468a0f1d3ae812f2
Reviewed-on: https://webrtc-review.googlesource.com/102062
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24853}
This commit is contained in:
Karl Wiberg
2018-09-26 11:22:50 +02:00
committed by Commit Bot
parent 3a6b6bda17
commit 91957c1540
3 changed files with 39 additions and 30 deletions

View File

@ -1330,6 +1330,7 @@ if (rtc_include_tests) {
"..:module_api", "..:module_api",
"../..:webrtc_common", "../..:webrtc_common",
"../../api/audio:audio_frame_api", "../../api/audio:audio_frame_api",
"../../api/audio_codecs:audio_codecs_api",
"../../api/audio_codecs:builtin_audio_decoder_factory", "../../api/audio_codecs:builtin_audio_decoder_factory",
"../../api/audio_codecs:builtin_audio_encoder_factory", "../../api/audio_codecs:builtin_audio_encoder_factory",
"../../api/audio_codecs/isac:audio_encoder_isac_float", "../../api/audio_codecs/isac:audio_encoder_isac_float",

View File

@ -21,8 +21,8 @@
#endif #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 "common_types.h" // NOLINT(build/include) #include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/codecs/audio_format_conversion.h"
#include "modules/audio_coding/test/PCMFile.h" #include "modules/audio_coding/test/PCMFile.h"
#include "modules/audio_coding/test/utility.h" #include "modules/audio_coding/test/utility.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -59,34 +59,31 @@ TwoWayCommunication::~TwoWayCommunication() {
_outFileRefB.Close(); _outFileRefB.Close();
} }
void TwoWayCommunication::SetUpAutotest() { void TwoWayCommunication::SetUpAutotest(
CodecInst codecInst_A; AudioEncoderFactory* const encoder_factory,
CodecInst codecInst_B; const SdpAudioFormat& format1,
CodecInst dummyCodec; const int payload_type1,
const SdpAudioFormat& format2,
EXPECT_EQ(0, _acmA->Codec("ISAC", &codecInst_A, 16000, 1)); const int payload_type2) {
EXPECT_EQ(0, _acmB->Codec("L16", &codecInst_B, 8000, 1));
EXPECT_EQ(0, _acmA->Codec(6, &dummyCodec));
//--- Set A codecs //--- Set A codecs
EXPECT_EQ(0, _acmA->RegisterSendCodec(codecInst_A)); _acmA->SetEncoder(
EXPECT_EQ(true, _acmA->RegisterReceiveCodec(codecInst_B.pltype, encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt));
CodecInstToSdp(codecInst_B))); EXPECT_EQ(true, _acmA->RegisterReceiveCodec(payload_type2, format2));
//--- Set ref-A codecs //--- Set ref-A codecs
EXPECT_GT(_acmRefA->RegisterSendCodec(codecInst_A), -1); _acmRefA->SetEncoder(
EXPECT_EQ(true, _acmRefA->RegisterReceiveCodec(codecInst_B.pltype, encoder_factory->MakeAudioEncoder(payload_type1, format1, absl::nullopt));
CodecInstToSdp(codecInst_B))); EXPECT_EQ(true, _acmRefA->RegisterReceiveCodec(payload_type2, format2));
//--- Set B codecs //--- Set B codecs
EXPECT_GT(_acmB->RegisterSendCodec(codecInst_B), -1); _acmB->SetEncoder(
EXPECT_EQ(true, _acmB->RegisterReceiveCodec(codecInst_A.pltype, encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt));
CodecInstToSdp(codecInst_A))); EXPECT_EQ(true, _acmB->RegisterReceiveCodec(payload_type1, format1));
//--- Set ref-B codecs //--- Set ref-B codecs
EXPECT_EQ(0, _acmRefB->RegisterSendCodec(codecInst_B)); _acmRefB->SetEncoder(
EXPECT_EQ(true, _acmRefB->RegisterReceiveCodec(codecInst_A.pltype, encoder_factory->MakeAudioEncoder(payload_type2, format2, absl::nullopt));
CodecInstToSdp(codecInst_A))); EXPECT_EQ(true, _acmRefB->RegisterReceiveCodec(payload_type1, format1));
uint16_t frequencyHz; uint16_t frequencyHz;
@ -133,7 +130,15 @@ void TwoWayCommunication::SetUpAutotest() {
} }
void TwoWayCommunication::Perform() { void TwoWayCommunication::Perform() {
SetUpAutotest(); const SdpAudioFormat format1("ISAC", 16000, 1);
const SdpAudioFormat format2("L16", 8000, 1);
constexpr int payload_type1 = 17, payload_type2 = 18;
auto encoder_factory = CreateBuiltinAudioEncoderFactory();
SetUpAutotest(encoder_factory.get(), format1, payload_type1, format2,
payload_type2);
unsigned int msecPassed = 0; unsigned int msecPassed = 0;
unsigned int secPassed = 0; unsigned int secPassed = 0;
@ -142,9 +147,6 @@ void TwoWayCommunication::Perform() {
AudioFrame audioFrame; AudioFrame audioFrame;
auto codecInst_B = _acmB->SendCodec();
ASSERT_TRUE(codecInst_B);
// In the following loop we tests that the code can handle misuse of the APIs. // In the following loop we tests that the code can handle misuse of the APIs.
// In the middle of a session with data flowing between two sides, called A // In the middle of a session with data flowing between two sides, called A
// and B, APIs will be called, and the code should continue to run, and be // and B, APIs will be called, and the code should continue to run, and be
@ -180,7 +182,8 @@ void TwoWayCommunication::Perform() {
} }
// Re-register send codec on side B. // Re-register send codec on side B.
if (((secPassed % 5) == 4) && (msecPassed >= 990)) { if (((secPassed % 5) == 4) && (msecPassed >= 990)) {
EXPECT_EQ(0, _acmB->RegisterSendCodec(*codecInst_B)); _acmB->SetEncoder(encoder_factory->MakeAudioEncoder(
payload_type2, format2, absl::nullopt));
EXPECT_TRUE(_acmB->SendCodec()); EXPECT_TRUE(_acmB->SendCodec());
} }
// Initialize receiver on side A. // Initialize receiver on side A.
@ -188,8 +191,7 @@ void TwoWayCommunication::Perform() {
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( EXPECT_EQ(true, _acmA->RegisterReceiveCodec(payload_type2, format2));
codecInst_B->pltype, CodecInstToSdp(*codecInst_B)));
} }
} }
} }

View File

@ -13,6 +13,8 @@
#include <memory> #include <memory>
#include "api/audio_codecs/audio_encoder_factory.h"
#include "api/audio_codecs/audio_format.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_coding/test/ACMTest.h" #include "modules/audio_coding/test/ACMTest.h"
#include "modules/audio_coding/test/Channel.h" #include "modules/audio_coding/test/Channel.h"
@ -29,7 +31,11 @@ class TwoWayCommunication : public ACMTest {
void Perform(); void Perform();
private: private:
void SetUpAutotest(); void SetUpAutotest(AudioEncoderFactory* const encoder_factory,
const SdpAudioFormat& format1,
const int payload_type1,
const SdpAudioFormat& format2,
const int payload_type2);
std::unique_ptr<AudioCodingModule> _acmA; std::unique_ptr<AudioCodingModule> _acmA;
std::unique_ptr<AudioCodingModule> _acmB; std::unique_ptr<AudioCodingModule> _acmB;