Create pre-allocated decoders on the decoder thread.

This way we're sure instantiation, configuration and decode calls all
happen on the decoder queue - making thread checking easier in the
actual decoder classes.

Bug: None
Change-Id: Ia98f47009f26b34eb8dad2ee0b4ddcde082d1994
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272022
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Auto-Submit: Erik Språng <sprang@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37825}
This commit is contained in:
Erik Språng 2022-08-18 13:18:27 +02:00 committed by WebRTC LUCI CQ
parent e7280c314d
commit 7aaeb5a270
3 changed files with 29 additions and 26 deletions

View File

@ -1076,6 +1076,8 @@ TEST_F(WebRtcVideoEngineTest, RegisterDecodersIfSupported) {
EXPECT_TRUE(
channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc)));
// Decoder creation happens on the decoder thread, make sure it runs.
time_controller_.AdvanceTime(webrtc::TimeDelta::Zero());
ASSERT_EQ(1u, decoder_factory_->decoders().size());
// Setting codecs of the same type should not reallocate the decoder.
@ -1102,6 +1104,8 @@ TEST_F(WebRtcVideoEngineTest, RegisterH264DecoderIfSupported) {
EXPECT_TRUE(
channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc)));
// Decoder creation happens on the decoder thread, make sure it runs.
time_controller_.AdvanceTime(webrtc::TimeDelta::Zero());
ASSERT_EQ(1u, decoder_factory_->decoders().size());
}

View File

@ -357,16 +357,7 @@ void VideoReceiveStream2::Start() {
renderer = this;
}
int decoders_count = 0;
for (const Decoder& decoder : config_.decoders) {
// Create up to maximum_pre_stream_decoders_ up front, wait the the other
// decoders until they are requested (i.e., we receive the corresponding
// payload).
if (decoders_count < maximum_pre_stream_decoders_) {
CreateAndRegisterExternalDecoder(decoder);
++decoders_count;
}
VideoDecoder::Settings settings;
settings.set_codec_type(
PayloadStringToCodecType(decoder.video_format.name));
@ -399,6 +390,18 @@ void VideoReceiveStream2::Start() {
stats_proxy_.DecoderThreadStarting();
decode_queue_.PostTask([this] {
RTC_DCHECK_RUN_ON(&decode_queue_);
// Create up to maximum_pre_stream_decoders_ up front, wait the the other
// decoders until they are requested (i.e., we receive the corresponding
// payload).
int decoders_count = 0;
for (const Decoder& decoder : config_.decoders) {
if (decoders_count >= maximum_pre_stream_decoders_) {
break;
}
CreateAndRegisterExternalDecoder(decoder);
++decoders_count;
}
decoder_stopped_ = false;
});
buffer_->StartNextDecode(true);

View File

@ -494,33 +494,29 @@ TEST_P(VideoReceiveStream2Test, LazyDecoderCreation) {
// Only 1 decoder is created by default. It will be H265 since that was the
// first in the decoder list.
EXPECT_CALL(mock_h264_decoder_factory_, CreateVideoDecoder(_)).Times(0);
EXPECT_CALL(mock_h264_decoder_factory_,
CreateVideoDecoder(
testing::Field(&SdpVideoFormat::name, testing::Eq("H265"))))
.Times(1);
EXPECT_CALL(
mock_h264_decoder_factory_,
CreateVideoDecoder(Field(&SdpVideoFormat::name, testing::Eq("H265"))));
video_receive_stream_->Start();
// Decoder creation happens on the decoder thread, make sure it runs.
time_controller_.AdvanceTime(TimeDelta::Zero());
EXPECT_TRUE(
testing::Mock::VerifyAndClearExpectations(&mock_h264_decoder_factory_));
EXPECT_CALL(mock_h264_decoder_factory_,
CreateVideoDecoder(
testing::Field(&SdpVideoFormat::name, testing::Eq("H264"))))
.Times(1);
rtc::Event init_decode_event;
EXPECT_CALL(mock_decoder_, Configure).WillOnce(WithoutArgs([&] {
init_decode_event.Set();
return true;
}));
EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback(_));
EXPECT_CALL(mock_decoder_, Decode(_, false, _));
EXPECT_CALL(
mock_h264_decoder_factory_,
CreateVideoDecoder(Field(&SdpVideoFormat::name, testing::Eq("H264"))));
EXPECT_CALL(mock_decoder_, Configure);
EXPECT_CALL(mock_decoder_, RegisterDecodeCompleteCallback);
EXPECT_CALL(mock_decoder_, Decode);
RtpPacketReceived parsed_packet;
ASSERT_TRUE(parsed_packet.Parse(rtppacket.data(), rtppacket.size()));
rtp_stream_receiver_controller_.OnRtpPacket(parsed_packet);
EXPECT_CALL(mock_decoder_, Release());
EXPECT_CALL(mock_decoder_, Release);
// Make sure the decoder thread had a chance to run.
init_decode_event.Wait(kDefaultTimeOut.ms());
time_controller_.AdvanceTime(TimeDelta::Zero());
}
TEST_P(VideoReceiveStream2Test, PassesNtpTime) {