From 3dc0125cf7e8df6e60222fc5b69f08c52486a959 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Mon, 19 Mar 2018 19:27:44 +0100 Subject: [PATCH] Moving ConfigureEncoderTask to the calling scope. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL replaces ConfigureEncoderTask with a slightly simpler struct that is defined within the scope of the function using it. This makes it more clear that it is only used once and slightly reduces the amount of code. Bug: None Change-Id: I181a3da90540aa514048ff77fc9a9e9cf19d8f34 Reviewed-on: https://webrtc-review.googlesource.com/63026 Reviewed-by: Erik Språng Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#22514} --- video/video_stream_encoder.cc | 41 ++++++++++++----------------------- video/video_stream_encoder.h | 1 - 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 8095222088..f5f0ca5cf3 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -96,30 +96,6 @@ bool IsFramerateScalingEnabled( } // namespace -class VideoStreamEncoder::ConfigureEncoderTask : public rtc::QueuedTask { - public: - ConfigureEncoderTask(VideoStreamEncoder* video_stream_encoder, - VideoEncoderConfig config, - size_t max_data_payload_length, - bool nack_enabled) - : video_stream_encoder_(video_stream_encoder), - config_(std::move(config)), - max_data_payload_length_(max_data_payload_length), - nack_enabled_(nack_enabled) {} - - private: - bool Run() override { - video_stream_encoder_->ConfigureEncoderOnTaskQueue( - std::move(config_), max_data_payload_length_, nack_enabled_); - return true; - } - - VideoStreamEncoder* const video_stream_encoder_; - VideoEncoderConfig config_; - size_t max_data_payload_length_; - bool nack_enabled_; -}; - class VideoStreamEncoder::EncodeTask : public rtc::QueuedTask { public: EncodeTask(const VideoFrame& frame, @@ -510,9 +486,20 @@ void VideoStreamEncoder::SetStartBitrate(int start_bitrate_bps) { void VideoStreamEncoder::ConfigureEncoder(VideoEncoderConfig config, size_t max_data_payload_length, bool nack_enabled) { - encoder_queue_.PostTask( - std::unique_ptr(new ConfigureEncoderTask( - this, std::move(config), max_data_payload_length, nack_enabled))); + // TODO(srte): This struct should be replaced by a lambda with move capture + // when C++14 lambda is allowed. + struct ConfigureEncoderTask { + void operator()() { + encoder->ConfigureEncoderOnTaskQueue( + std::move(config), max_data_payload_length, nack_enabled); + } + VideoStreamEncoder* encoder; + VideoEncoderConfig config; + size_t max_data_payload_length; + bool nack_enabled; + }; + encoder_queue_.PostTask(ConfigureEncoderTask{ + this, std::move(config), max_data_payload_length, nack_enabled}); } void VideoStreamEncoder::ConfigureEncoderOnTaskQueue( diff --git a/video/video_stream_encoder.h b/video/video_stream_encoder.h index 37223e8ccc..3d707b47e6 100644 --- a/video/video_stream_encoder.h +++ b/video/video_stream_encoder.h @@ -117,7 +117,6 @@ class VideoStreamEncoder : public rtc::VideoSinkInterface, void AdaptDown(AdaptReason reason) override; private: - class ConfigureEncoderTask; class EncodeTask; class VideoSourceProxy;