From aebc61e3dcf9c21bc97c07e1abd03069dd462716 Mon Sep 17 00:00:00 2001 From: brandtr Date: Tue, 28 Feb 2017 07:13:47 -0800 Subject: [PATCH] Minor cleanups in VideoProcessor. This CL is broken out from a future "real" CL, that introduces support for pipelining HW codecs to VideoProcessor. I order to simplify the reviewing of that CL a bit, some of the cleanups are split out here. No functional changes are intended. BUG=webrtc::6634 Review-Url: https://codereview.webrtc.org/2709123004 Cr-Commit-Position: refs/heads/master@{#16909} --- .../codecs/test/videoprocessor.cc | 41 +++++++++++-------- .../video_coding/codecs/test/videoprocessor.h | 23 ++++++----- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc index d6d2c0ca63..9cda6922b4 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc @@ -31,6 +31,19 @@ namespace test { namespace { const int k90khzTimestampFrameDiff = 3000; // Assuming 30 fps. + +std::unique_ptr CreateBitrateAllocator( + const TestConfig& config) { + std::unique_ptr tl_factory; + if (config.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) { + tl_factory.reset(new TemporalLayersFactory()); + config.codec_settings->VP8()->tl_factory = tl_factory.get(); + } + return std::unique_ptr( + VideoCodecInitializer::CreateBitrateAllocator(*config.codec_settings, + std::move(tl_factory))); +} + } // namespace const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { @@ -74,11 +87,13 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder, FrameWriter* decoded_frame_writer) : encoder_(encoder), decoder_(decoder), - analysis_frame_reader_(analysis_frame_reader), - analysis_frame_writer_(analysis_frame_writer), + bitrate_allocator_(CreateBitrateAllocator(config)), + encode_callback_(new VideoProcessorEncodeCompleteCallback(this)), + decode_callback_(new VideoProcessorDecodeCompleteCallback(this)), packet_manipulator_(packet_manipulator), config_(config), - stats_(stats), + analysis_frame_reader_(analysis_frame_reader), + analysis_frame_writer_(analysis_frame_writer), source_frame_writer_(source_frame_writer), encoded_frame_writer_(encoded_frame_writer), decoded_frame_writer_(decoded_frame_writer), @@ -88,25 +103,19 @@ VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder, encoded_frame_size_(0), encoded_frame_type_(kVideoFrameKey), prev_time_stamp_(0), - num_dropped_frames_(0), - num_spatial_resizes_(0), last_encoder_frame_width_(0), last_encoder_frame_height_(0), + stats_(stats), + num_dropped_frames_(0), + num_spatial_resizes_(0), bit_rate_factor_(0.0), encode_start_ns_(0), decode_start_ns_(0) { - std::unique_ptr tl_factory; - if (config_.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) { - tl_factory.reset(new TemporalLayersFactory()); - config.codec_settings->VP8()->tl_factory = tl_factory.get(); - } - bitrate_allocator_ = VideoCodecInitializer::CreateBitrateAllocator( - *config.codec_settings, std::move(tl_factory)); RTC_DCHECK(encoder); RTC_DCHECK(decoder); + RTC_DCHECK(packet_manipulator); RTC_DCHECK(analysis_frame_reader); RTC_DCHECK(analysis_frame_writer); - RTC_DCHECK(packet_manipulator); RTC_DCHECK(stats); } @@ -124,8 +133,6 @@ bool VideoProcessorImpl::Init() { last_encoder_frame_height_ = config_.codec_settings->height; // Setup required callbacks for the encoder/decoder. - encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this)); - decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this)); RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), WEBRTC_VIDEO_CODEC_OK) << "Failed to register encode complete callback"; @@ -133,7 +140,7 @@ bool VideoProcessorImpl::Init() { WEBRTC_VIDEO_CODEC_OK) << "Failed to register decode complete callback"; - // Init the encoder and decoder. + // Initialize the encoder and decoder. uint32_t num_cores = config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); RTC_CHECK_EQ( @@ -322,8 +329,8 @@ void VideoProcessorImpl::FrameEncoded( // Simulate packet loss. bool exclude_this_frame = false; - // Only keyframes can be excluded. if (encoded_image._frameType == kVideoFrameKey) { + // Only keyframes can be excluded. switch (config_.exclude_frame_types) { case kExcludeOnlyFirstKeyFrame: if (!first_key_frame_has_been_excluded_) { diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.h b/webrtc/modules/video_coding/codecs/test/videoprocessor.h index c2e26b3f09..8623476de1 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.h @@ -251,14 +251,20 @@ class VideoProcessorImpl : public VideoProcessor { webrtc::VideoEncoder* const encoder_; webrtc::VideoDecoder* const decoder_; - std::unique_ptr bitrate_allocator_; + const std::unique_ptr bitrate_allocator_; + + // Adapters for the codec callbacks. + const std::unique_ptr encode_callback_; + const std::unique_ptr decode_callback_; + + PacketManipulator* const packet_manipulator_; + const TestConfig& config_; + // These (mandatory) file manipulators are used for, e.g., objective PSNR and // SSIM calculations at the end of a test run. FrameReader* const analysis_frame_reader_; FrameWriter* const analysis_frame_writer_; - PacketManipulator* const packet_manipulator_; - const TestConfig& config_; - Stats* stats_; + // These (optional) file writers are used for persistently storing the output // of the coding pipeline at different stages: pre encode (source), post // encode (encoded), and post decode (decoded). The purpose is to give the @@ -269,10 +275,6 @@ class VideoProcessorImpl : public VideoProcessor { IvfFileWriter* const encoded_frame_writer_; FrameWriter* const decoded_frame_writer_; - // Adapters for the codec callbacks. - std::unique_ptr encode_callback_; - std::unique_ptr decode_callback_; - // Keep track of the last successful frame, since we need to write that // when decoding fails. std::unique_ptr last_successful_frame_buffer_; @@ -285,12 +287,13 @@ class VideoProcessorImpl : public VideoProcessor { size_t encoded_frame_size_; FrameType encoded_frame_type_; int prev_time_stamp_; - int num_dropped_frames_; - int num_spatial_resizes_; int last_encoder_frame_width_; int last_encoder_frame_height_; // Statistics. + Stats* stats_; + int num_dropped_frames_; + int num_spatial_resizes_; double bit_rate_factor_; // Multiply frame length with this to get bit rate. int64_t encode_start_ns_; int64_t decode_start_ns_;