Test for audio codec pair ID assignment

We want to ensure that encoders and decoders actually get IDs with the
desired properties.

Bug: webrtc:8941
Change-Id: Ie64b67c2e9cb67171725d27f92e954afd1b77834
Reviewed-on: https://webrtc-review.googlesource.com/63300
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22547}
This commit is contained in:
Karl Wiberg 2018-03-22 00:07:39 +01:00 committed by Commit Bot
parent 77490b95c0
commit 5bdc82a60f

View File

@ -76,15 +76,18 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
#endif
}
void CreatePcs(const MediaConstraintsInterface* pc_constraints,
const rtc::scoped_refptr<webrtc::AudioEncoderFactory>&
audio_encoder_factory,
const rtc::scoped_refptr<webrtc::AudioDecoderFactory>&
audio_decoder_factory) {
EXPECT_TRUE(caller_->CreatePc(
pc_constraints, config_, audio_encoder_factory, audio_decoder_factory));
EXPECT_TRUE(callee_->CreatePc(
pc_constraints, config_, audio_encoder_factory, audio_decoder_factory));
void CreatePcs(
const MediaConstraintsInterface* pc_constraints,
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory1,
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory1,
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory2,
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory2) {
EXPECT_TRUE(caller_->CreatePc(pc_constraints, config_,
audio_encoder_factory1,
audio_decoder_factory1));
EXPECT_TRUE(callee_->CreatePc(pc_constraints, config_,
audio_encoder_factory2,
audio_decoder_factory2));
PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get());
caller_->SignalOnDataChannel.connect(
@ -93,6 +96,14 @@ class PeerConnectionEndToEndBaseTest : public sigslot::has_slots<>,
this, &PeerConnectionEndToEndBaseTest::OnCalleeAddedDataChannel);
}
void CreatePcs(
const MediaConstraintsInterface* pc_constraints,
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) {
CreatePcs(pc_constraints, audio_encoder_factory, audio_decoder_factory,
audio_encoder_factory, audio_decoder_factory);
}
void GetAndAddUserMedia() {
FakeConstraints audio_constraints;
FakeConstraints video_constraints;
@ -381,13 +392,94 @@ TEST_P(PeerConnectionEndToEndTest, CallWithLegacySdp) {
#endif // !defined(ADDRESS_SANITIZER)
TEST_P(PeerConnectionEndToEndTest, CallWithCustomCodec) {
CreatePcs(
nullptr,
webrtc::CreateAudioEncoderFactory<AudioEncoderUnicornSparklesRainbow>(),
webrtc::CreateAudioDecoderFactory<AudioDecoderUnicornSparklesRainbow>());
class IdLoggingAudioEncoderFactory : public webrtc::AudioEncoderFactory {
public:
IdLoggingAudioEncoderFactory(
rtc::scoped_refptr<AudioEncoderFactory> real_factory,
std::vector<webrtc::AudioCodecPairId>* const codec_ids)
: fact_(real_factory), codec_ids_(codec_ids) {}
std::vector<webrtc::AudioCodecSpec> GetSupportedEncoders() override {
return fact_->GetSupportedEncoders();
}
rtc::Optional<webrtc::AudioCodecInfo> QueryAudioEncoder(
const webrtc::SdpAudioFormat& format) override {
return fact_->QueryAudioEncoder(format);
}
std::unique_ptr<webrtc::AudioEncoder> MakeAudioEncoder(
int payload_type,
const webrtc::SdpAudioFormat& format,
rtc::Optional<webrtc::AudioCodecPairId> codec_pair_id) override {
EXPECT_TRUE(codec_pair_id.has_value());
codec_ids_->push_back(*codec_pair_id);
return fact_->MakeAudioEncoder(payload_type, format, codec_pair_id);
}
private:
const rtc::scoped_refptr<webrtc::AudioEncoderFactory> fact_;
std::vector<webrtc::AudioCodecPairId>* const codec_ids_;
};
class IdLoggingAudioDecoderFactory : public webrtc::AudioDecoderFactory {
public:
IdLoggingAudioDecoderFactory(
rtc::scoped_refptr<AudioDecoderFactory> real_factory,
std::vector<webrtc::AudioCodecPairId>* const codec_ids)
: fact_(real_factory), codec_ids_(codec_ids) {}
std::vector<webrtc::AudioCodecSpec> GetSupportedDecoders() override {
return fact_->GetSupportedDecoders();
}
bool IsSupportedDecoder(const webrtc::SdpAudioFormat& format) override {
return fact_->IsSupportedDecoder(format);
}
std::unique_ptr<webrtc::AudioDecoder> MakeAudioDecoder(
const webrtc::SdpAudioFormat& format,
rtc::Optional<webrtc::AudioCodecPairId> codec_pair_id) override {
EXPECT_TRUE(codec_pair_id.has_value());
codec_ids_->push_back(*codec_pair_id);
return fact_->MakeAudioDecoder(format, codec_pair_id);
}
private:
const rtc::scoped_refptr<webrtc::AudioDecoderFactory> fact_;
std::vector<webrtc::AudioCodecPairId>* const codec_ids_;
};
std::vector<webrtc::AudioCodecPairId> encoder_id1, encoder_id2, decoder_id1,
decoder_id2;
CreatePcs(nullptr,
rtc::scoped_refptr<webrtc::AudioEncoderFactory>(
new rtc::RefCountedObject<IdLoggingAudioEncoderFactory>(
webrtc::CreateAudioEncoderFactory<
AudioEncoderUnicornSparklesRainbow>(),
&encoder_id1)),
rtc::scoped_refptr<webrtc::AudioDecoderFactory>(
new rtc::RefCountedObject<IdLoggingAudioDecoderFactory>(
webrtc::CreateAudioDecoderFactory<
AudioDecoderUnicornSparklesRainbow>(),
&decoder_id1)),
rtc::scoped_refptr<webrtc::AudioEncoderFactory>(
new rtc::RefCountedObject<IdLoggingAudioEncoderFactory>(
webrtc::CreateAudioEncoderFactory<
AudioEncoderUnicornSparklesRainbow>(),
&encoder_id2)),
rtc::scoped_refptr<webrtc::AudioDecoderFactory>(
new rtc::RefCountedObject<IdLoggingAudioDecoderFactory>(
webrtc::CreateAudioDecoderFactory<
AudioDecoderUnicornSparklesRainbow>(),
&decoder_id2)));
GetAndAddUserMedia();
Negotiate();
WaitForCallEstablished();
// Each codec factory has been used to create one codec. The first pair got
// the same ID because they were passed to the same PeerConnectionFactory,
// and the second pair got the same ID---but these two IDs are not equal,
// because each PeerConnectionFactory has its own ID.
EXPECT_EQ(1, encoder_id1.size());
EXPECT_EQ(1, encoder_id2.size());
EXPECT_EQ(encoder_id1, decoder_id1);
EXPECT_EQ(encoder_id2, decoder_id2);
EXPECT_NE(encoder_id1, encoder_id2);
}
#ifdef HAVE_SCTP