Merge SendTask implementation for SingleThreadedTaskQueueForTesting and TaskQueueForTest

That allows to use SingleThreadedTaskQueueForTesting via TaskQueueBase interface
but still have access to test-only SendTask function.

Bug: webrtc:10933
Change-Id: I3cc397e55ea2f1ed9e5d885d6a2ccda412beb826
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156002
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29480}
This commit is contained in:
Danil Chapovalov
2019-10-15 10:04:57 +02:00
committed by Commit Bot
parent 35214fcfe2
commit eb90e6ffe3
18 changed files with 773 additions and 668 deletions

View File

@ -447,7 +447,7 @@ void VideoCodecTestFixtureImpl::ProcessAllFrames(
}
// Wait until we know that the last frame has been sent for encode.
task_queue->SendTask([] {});
task_queue->SendTask([] {}, RTC_FROM_HERE);
// Give the VideoProcessor pipeline some time to process the last frame,
// and then release the codecs.
@ -686,22 +686,26 @@ void VideoCodecTestFixtureImpl::SetUpAndInitObjects(
cpu_process_time_.reset(new CpuProcessTime(config_));
task_queue->SendTask([this]() {
CreateEncoderAndDecoder();
processor_ = std::make_unique<VideoProcessor>(
encoder_.get(), &decoders_, source_frame_reader_.get(), config_,
&stats_, &encoded_frame_writers_,
decoded_frame_writers_.empty() ? nullptr : &decoded_frame_writers_);
});
task_queue->SendTask(
[this]() {
CreateEncoderAndDecoder();
processor_ = std::make_unique<VideoProcessor>(
encoder_.get(), &decoders_, source_frame_reader_.get(), config_,
&stats_, &encoded_frame_writers_,
decoded_frame_writers_.empty() ? nullptr : &decoded_frame_writers_);
},
RTC_FROM_HERE);
}
void VideoCodecTestFixtureImpl::ReleaseAndCloseObjects(
TaskQueueForTest* task_queue) {
task_queue->SendTask([this]() {
processor_.reset();
// The VideoProcessor must be destroyed before the codecs.
DestroyEncoderAndDecoder();
});
task_queue->SendTask(
[this]() {
processor_.reset();
// The VideoProcessor must be destroyed before the codecs.
DestroyEncoderAndDecoder();
},
RTC_FROM_HERE);
source_frame_reader_->Close();
@ -724,10 +728,12 @@ void VideoCodecTestFixtureImpl::PrintSettings(
RTC_LOG(LS_INFO) << "==> Codec names";
std::string encoder_name;
std::string decoder_name;
task_queue->SendTask([this, &encoder_name, &decoder_name] {
encoder_name = encoder_->GetEncoderInfo().implementation_name;
decoder_name = decoders_.at(0)->ImplementationName();
});
task_queue->SendTask(
[this, &encoder_name, &decoder_name] {
encoder_name = encoder_->GetEncoderInfo().implementation_name;
decoder_name = decoders_.at(0)->ImplementationName();
},
RTC_FROM_HERE);
RTC_LOG(LS_INFO) << "enc_impl_name: " << encoder_name;
RTC_LOG(LS_INFO) << "dec_impl_name: " << decoder_name;
}

View File

@ -54,15 +54,17 @@ class VideoProcessorTest : public ::testing::Test {
ExpectInit();
EXPECT_CALL(frame_reader_mock_, FrameLength())
.WillRepeatedly(Return(kFrameSize));
q_.SendTask([this] {
video_processor_ = std::make_unique<VideoProcessor>(
&encoder_mock_, &decoders_, &frame_reader_mock_, config_, &stats_,
&encoded_frame_writers_, /*decoded_frame_writers=*/nullptr);
});
q_.SendTask(
[this] {
video_processor_ = std::make_unique<VideoProcessor>(
&encoder_mock_, &decoders_, &frame_reader_mock_, config_, &stats_,
&encoded_frame_writers_, /*decoded_frame_writers=*/nullptr);
},
RTC_FROM_HERE);
}
~VideoProcessorTest() {
q_.SendTask([this] { video_processor_.reset(); });
q_.SendTask([this] { video_processor_.reset(); }, RTC_FROM_HERE);
}
void ExpectInit() {
@ -104,7 +106,8 @@ TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
SetRates(Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kFramerateFps))))
.Times(1);
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); },
RTC_FROM_HERE);
EXPECT_CALL(frame_reader_mock_, ReadFrame())
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
@ -112,13 +115,13 @@ TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
encoder_mock_,
Encode(Property(&VideoFrame::timestamp, 1 * 90000 / kFramerateFps), _))
.Times(1);
q_.SendTask([this] { video_processor_->ProcessFrame(); });
q_.SendTask([this] { video_processor_->ProcessFrame(); }, RTC_FROM_HERE);
EXPECT_CALL(
encoder_mock_,
Encode(Property(&VideoFrame::timestamp, 2 * 90000 / kFramerateFps), _))
.Times(1);
q_.SendTask([this] { video_processor_->ProcessFrame(); });
q_.SendTask([this] { video_processor_->ProcessFrame(); }, RTC_FROM_HERE);
ExpectRelease();
}
@ -133,14 +136,15 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
static_cast<double>(kStartFramerateFps))))
.Times(1);
q_.SendTask(
[=] { video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
[=] { video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); },
RTC_FROM_HERE);
EXPECT_CALL(frame_reader_mock_, ReadFrame())
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
EXPECT_CALL(encoder_mock_,
Encode(Property(&VideoFrame::timestamp, kStartTimestamp), _))
.Times(1);
q_.SendTask([this] { video_processor_->ProcessFrame(); });
q_.SendTask([this] { video_processor_->ProcessFrame(); }, RTC_FROM_HERE);
const int kNewFramerateFps = 13;
EXPECT_CALL(
@ -149,14 +153,15 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
static_cast<double>(kNewFramerateFps))))
.Times(1);
q_.SendTask(
[=] { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); });
[=] { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); },
RTC_FROM_HERE);
EXPECT_CALL(encoder_mock_,
Encode(Property(&VideoFrame::timestamp,
kStartTimestamp + 90000 / kNewFramerateFps),
_))
.Times(1);
q_.SendTask([this] { video_processor_->ProcessFrame(); });
q_.SendTask([this] { video_processor_->ProcessFrame(); }, RTC_FROM_HERE);
ExpectRelease();
}
@ -175,7 +180,8 @@ TEST_F(VideoProcessorTest, SetRates) {
Field(&VideoEncoder::RateControlParameters::framerate_fps,
static_cast<double>(kFramerateFps)))))
.Times(1);
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); },
RTC_FROM_HERE);
const uint32_t kNewBitrateKbps = 456;
const int kNewFramerateFps = 34;
@ -190,7 +196,8 @@ TEST_F(VideoProcessorTest, SetRates) {
static_cast<double>(kNewFramerateFps)))))
.Times(1);
q_.SendTask(
[=] { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });
[=] { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); },
RTC_FROM_HERE);
ExpectRelease();
}