Avoid using global task queue factory in fake encoder

by not using convenient rtc::TaskQueue constructor

Bug: webrtc:10284
Change-Id: I3c6703fd8c86b2a230f62cac734eb616039e4abe
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128603
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27207}
This commit is contained in:
Danil Chapovalov
2019-03-19 19:39:49 +01:00
committed by Commit Bot
parent cde8ab265e
commit 22ed366fec
4 changed files with 28 additions and 13 deletions

View File

@ -363,8 +363,11 @@ int32_t DelayedEncoder::Encode(const VideoFrame& input_image,
return FakeEncoder::Encode(input_image, frame_types);
}
MultithreadedFakeH264Encoder::MultithreadedFakeH264Encoder(Clock* clock)
MultithreadedFakeH264Encoder::MultithreadedFakeH264Encoder(
Clock* clock,
TaskQueueFactory* task_queue_factory)
: test::FakeH264Encoder(clock),
task_queue_factory_(task_queue_factory),
current_queue_(0),
queue1_(nullptr),
queue2_(nullptr) {
@ -378,8 +381,10 @@ int32_t MultithreadedFakeH264Encoder::InitEncode(const VideoCodec* config,
size_t max_payload_size) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
queue1_.reset(new rtc::TaskQueue("Queue 1"));
queue2_.reset(new rtc::TaskQueue("Queue 2"));
queue1_ = task_queue_factory_->CreateTaskQueue(
"Queue 1", TaskQueueFactory::Priority::NORMAL);
queue2_ = task_queue_factory_->CreateTaskQueue(
"Queue 2", TaskQueueFactory::Priority::NORMAL);
return FakeH264Encoder::InitEncode(config, number_of_cores, max_payload_size);
}
@ -409,8 +414,8 @@ int32_t MultithreadedFakeH264Encoder::Encode(
const std::vector<VideoFrameType>* frame_types) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequence_checker_);
std::unique_ptr<rtc::TaskQueue>& queue =
(current_queue_++ % 2 == 0) ? queue1_ : queue2_;
TaskQueueBase* queue =
(current_queue_++ % 2 == 0) ? queue1_.get() : queue2_.get();
if (!queue) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;

View File

@ -16,6 +16,7 @@
#include <memory>
#include <vector>
#include "api/task_queue/task_queue_factory.h"
#include "api/video/encoded_image.h"
#include "api/video/video_bitrate_allocation.h"
#include "api/video/video_frame.h"
@ -26,7 +27,6 @@
#include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/sequenced_task_checker.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
@ -137,7 +137,8 @@ class DelayedEncoder : public test::FakeEncoder {
// as it is called from the task queue in VideoStreamEncoder.
class MultithreadedFakeH264Encoder : public test::FakeH264Encoder {
public:
explicit MultithreadedFakeH264Encoder(Clock* clock);
MultithreadedFakeH264Encoder(Clock* clock,
TaskQueueFactory* task_queue_factory);
virtual ~MultithreadedFakeH264Encoder() = default;
int32_t InitEncode(const VideoCodec* config,
@ -155,9 +156,12 @@ class MultithreadedFakeH264Encoder : public test::FakeH264Encoder {
protected:
class EncodeTask;
TaskQueueFactory* const task_queue_factory_;
int current_queue_ RTC_GUARDED_BY(sequence_checker_);
std::unique_ptr<rtc::TaskQueue> queue1_ RTC_GUARDED_BY(sequence_checker_);
std::unique_ptr<rtc::TaskQueue> queue2_ RTC_GUARDED_BY(sequence_checker_);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> queue1_
RTC_GUARDED_BY(sequence_checker_);
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> queue2_
RTC_GUARDED_BY(sequence_checker_);
rtc::SequencedTaskChecker sequence_checker_;
};

View File

@ -510,6 +510,7 @@ if (rtc_include_tests) {
"../api:mock_frame_decryptor",
"../api:scoped_refptr",
"../api:simulated_network_api",
"../api/task_queue:default_task_queue_factory",
"../api/task_queue:global_task_queue_factory",
"../api/test/video:function_video_factory",
"../api/units:data_rate",

View File

@ -12,6 +12,7 @@
#include <vector>
#include "absl/memory/memory.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/simulated_network.h"
#include "api/video/encoded_image.h"
#include "api/video/video_bitrate_allocation.h"
@ -681,9 +682,11 @@ TEST_F(VideoSendStreamTest, DISABLED_DoesUtilizeUlpfecForVp9WithNackEnabled) {
#endif // defined(RTC_ENABLE_VP9)
TEST_F(VideoSendStreamTest, SupportsUlpfecWithMultithreadedH264) {
test::FunctionVideoEncoderFactory encoder_factory([]() {
std::unique_ptr<TaskQueueFactory> task_queue_factory =
CreateDefaultTaskQueueFactory();
test::FunctionVideoEncoderFactory encoder_factory([&]() {
return absl::make_unique<test::MultithreadedFakeH264Encoder>(
Clock::GetRealTimeClock());
Clock::GetRealTimeClock(), task_queue_factory.get());
});
UlpfecObserver test(false, false, true, true, "H264", &encoder_factory);
RunBaseTest(&test);
@ -861,9 +864,11 @@ TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackH264) {
}
TEST_F(VideoSendStreamTest, SupportsFlexfecWithMultithreadedH264) {
test::FunctionVideoEncoderFactory encoder_factory([]() {
std::unique_ptr<TaskQueueFactory> task_queue_factory =
CreateDefaultTaskQueueFactory();
test::FunctionVideoEncoderFactory encoder_factory([&]() {
return absl::make_unique<test::MultithreadedFakeH264Encoder>(
Clock::GetRealTimeClock());
Clock::GetRealTimeClock(), task_queue_factory.get());
});
FlexfecObserver test(false, false, "H264", &encoder_factory, 1);