Create/destroying codecs on task queue + switch to TaskQueueForTest.
After https://webrtc-review.googlesource.com/c/src/+/70740, we are creating/destroying the codecs on a task queue in the VideoStreamEncoder. This CL updates the VideoCodecTest to do the same. Also, this CL switches from manually Wait()'ing on the task queue to using TaskQueueForTest::SendTask. Bug: None Change-Id: Ia0398b24e32e9cc5361ba5ee4c08441116def18e Reviewed-on: https://webrtc-review.googlesource.com/76800 Commit-Queue: Rasmus Brandt <brandtr@webrtc.org> Reviewed-by: Åsa Persson <asapersson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23257}
This commit is contained in:
committed by
Commit Bot
parent
59130a11b8
commit
8dd4db49e2
@ -18,7 +18,7 @@
|
||||
#include "modules/video_coding/include/video_coding.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
#include "test/testsupport/mock/mock_frame_reader.h"
|
||||
@ -39,16 +39,6 @@ const int kFrameSize = kWidth * kHeight * 3 / 2; // I420.
|
||||
|
||||
} // namespace
|
||||
|
||||
#define DO_SYNC(q, block) \
|
||||
{ \
|
||||
rtc::Event event(false, false); \
|
||||
q.PostTask([&, this] { \
|
||||
block; \
|
||||
event.Set(); \
|
||||
}); \
|
||||
RTC_CHECK(event.Wait(rtc::Event::kForever)); \
|
||||
}
|
||||
|
||||
class VideoProcessorTest : public testing::Test {
|
||||
protected:
|
||||
VideoProcessorTest() : q_("VP queue") {
|
||||
@ -61,7 +51,7 @@ class VideoProcessorTest : public testing::Test {
|
||||
ExpectInit();
|
||||
EXPECT_CALL(frame_reader_mock_, FrameLength())
|
||||
.WillRepeatedly(Return(kFrameSize));
|
||||
DO_SYNC(q_, {
|
||||
q_.SendTask([this] {
|
||||
video_processor_ = rtc::MakeUnique<VideoProcessor>(
|
||||
&encoder_mock_, &decoders_, &frame_reader_mock_, config_, &stats_,
|
||||
nullptr /* encoded_frame_writer */,
|
||||
@ -70,7 +60,7 @@ class VideoProcessorTest : public testing::Test {
|
||||
}
|
||||
|
||||
~VideoProcessorTest() {
|
||||
DO_SYNC(q_, { video_processor_.reset(); });
|
||||
q_.SendTask([this] { video_processor_.reset(); });
|
||||
}
|
||||
|
||||
void ExpectInit() {
|
||||
@ -87,7 +77,7 @@ class VideoProcessorTest : public testing::Test {
|
||||
EXPECT_CALL(*decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
|
||||
}
|
||||
|
||||
rtc::TaskQueue q_;
|
||||
rtc::test::TaskQueueForTest q_;
|
||||
|
||||
TestConfig config_;
|
||||
|
||||
@ -109,7 +99,7 @@ TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
|
||||
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kFramerateFps))
|
||||
.Times(1)
|
||||
.WillOnce(Return(0));
|
||||
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
||||
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
||||
|
||||
EXPECT_CALL(frame_reader_mock_, ReadFrame())
|
||||
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
|
||||
@ -117,13 +107,13 @@ TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
|
||||
encoder_mock_,
|
||||
Encode(Property(&VideoFrame::timestamp, 1 * 90000 / kFramerateFps), _, _))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
||||
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
||||
|
||||
EXPECT_CALL(
|
||||
encoder_mock_,
|
||||
Encode(Property(&VideoFrame::timestamp, 2 * 90000 / kFramerateFps), _, _))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
||||
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
||||
|
||||
ExpectRelease();
|
||||
}
|
||||
@ -135,28 +125,29 @@ TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
|
||||
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kStartFramerateFps))
|
||||
.Times(1)
|
||||
.WillOnce(Return(0));
|
||||
DO_SYNC(q_,
|
||||
{ video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
|
||||
q_.SendTask(
|
||||
[=] { video_processor_->SetRates(kBitrateKbps, kStartFramerateFps); });
|
||||
|
||||
EXPECT_CALL(frame_reader_mock_, ReadFrame())
|
||||
.WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
|
||||
EXPECT_CALL(encoder_mock_,
|
||||
Encode(Property(&VideoFrame::timestamp, kStartTimestamp), _, _))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
||||
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
||||
|
||||
const int kNewFramerateFps = 13;
|
||||
EXPECT_CALL(encoder_mock_, SetRateAllocation(_, kNewFramerateFps))
|
||||
.Times(1)
|
||||
.WillOnce(Return(0));
|
||||
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); });
|
||||
q_.SendTask(
|
||||
[=] { video_processor_->SetRates(kBitrateKbps, kNewFramerateFps); });
|
||||
|
||||
EXPECT_CALL(encoder_mock_,
|
||||
Encode(Property(&VideoFrame::timestamp,
|
||||
kStartTimestamp + 90000 / kNewFramerateFps),
|
||||
_, _))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->ProcessFrame(); });
|
||||
q_.SendTask([this] { video_processor_->ProcessFrame(); });
|
||||
|
||||
ExpectRelease();
|
||||
}
|
||||
@ -169,7 +160,7 @@ TEST_F(VideoProcessorTest, SetRates) {
|
||||
Property(&VideoBitrateAllocation::get_sum_kbps, kBitrateKbps),
|
||||
kFramerateFps))
|
||||
.Times(1);
|
||||
DO_SYNC(q_, { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
||||
q_.SendTask([=] { video_processor_->SetRates(kBitrateKbps, kFramerateFps); });
|
||||
|
||||
const int kNewBitrateKbps = 456;
|
||||
const int kNewFramerateFps = 34;
|
||||
@ -178,8 +169,8 @@ TEST_F(VideoProcessorTest, SetRates) {
|
||||
kNewBitrateKbps),
|
||||
kNewFramerateFps))
|
||||
.Times(1);
|
||||
DO_SYNC(q_,
|
||||
{ video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });
|
||||
q_.SendTask(
|
||||
[=] { video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps); });
|
||||
|
||||
ExpectRelease();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user