Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor.cc

Issue 2709123004: Step #0: Minor cleanups in VideoProcessor. (Closed)
Patch Set: Rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/video_coding/codecs/test/videoprocessor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 #include "webrtc/modules/video_coding/include/video_codec_initializer.h" 24 #include "webrtc/modules/video_coding/include/video_codec_initializer.h"
25 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" 25 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
26 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" 26 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h"
27 #include "webrtc/system_wrappers/include/cpu_info.h" 27 #include "webrtc/system_wrappers/include/cpu_info.h"
28 28
29 namespace webrtc { 29 namespace webrtc {
30 namespace test { 30 namespace test {
31 31
32 namespace { 32 namespace {
33 const int k90khzTimestampFrameDiff = 3000; // Assuming 30 fps. 33 const int k90khzTimestampFrameDiff = 3000; // Assuming 30 fps.
34
35 std::unique_ptr<VideoBitrateAllocator> CreateBitrateAllocator(
36 const TestConfig& config) {
37 std::unique_ptr<TemporalLayersFactory> tl_factory;
38 if (config.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) {
39 tl_factory.reset(new TemporalLayersFactory());
40 config.codec_settings->VP8()->tl_factory = tl_factory.get();
41 }
42 return VideoCodecInitializer::CreateBitrateAllocator(*config.codec_settings,
åsapersson 2017/02/24 08:27:07 return std::unique_ptr<VideoBitrateAllocator>(Vide
brandtr 2017/02/28 13:59:54 Done.
43 std::move(tl_factory));
44 }
45
34 } // namespace 46 } // namespace
35 47
36 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) { 48 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e) {
37 switch (e) { 49 switch (e) {
38 case kExcludeOnlyFirstKeyFrame: 50 case kExcludeOnlyFirstKeyFrame:
39 return "ExcludeOnlyFirstKeyFrame"; 51 return "ExcludeOnlyFirstKeyFrame";
40 case kExcludeAllKeyFrames: 52 case kExcludeAllKeyFrames:
41 return "ExcludeAllKeyFrames"; 53 return "ExcludeAllKeyFrames";
42 default: 54 default:
43 RTC_NOTREACHED(); 55 RTC_NOTREACHED();
(...skipping 23 matching lines...) Expand all
67 FrameReader* analysis_frame_reader, 79 FrameReader* analysis_frame_reader,
68 FrameWriter* analysis_frame_writer, 80 FrameWriter* analysis_frame_writer,
69 PacketManipulator* packet_manipulator, 81 PacketManipulator* packet_manipulator,
70 const TestConfig& config, 82 const TestConfig& config,
71 Stats* stats, 83 Stats* stats,
72 FrameWriter* source_frame_writer, 84 FrameWriter* source_frame_writer,
73 IvfFileWriter* encoded_frame_writer, 85 IvfFileWriter* encoded_frame_writer,
74 FrameWriter* decoded_frame_writer) 86 FrameWriter* decoded_frame_writer)
75 : encoder_(encoder), 87 : encoder_(encoder),
76 decoder_(decoder), 88 decoder_(decoder),
89 bitrate_allocator_(CreateBitrateAllocator(config)),
90 encode_callback_(new VideoProcessorEncodeCompleteCallback(this)),
91 decode_callback_(new VideoProcessorDecodeCompleteCallback(this)),
92 packet_manipulator_(packet_manipulator),
93 config_(config),
77 analysis_frame_reader_(analysis_frame_reader), 94 analysis_frame_reader_(analysis_frame_reader),
78 analysis_frame_writer_(analysis_frame_writer), 95 analysis_frame_writer_(analysis_frame_writer),
79 packet_manipulator_(packet_manipulator),
80 config_(config),
81 stats_(stats),
82 source_frame_writer_(source_frame_writer), 96 source_frame_writer_(source_frame_writer),
83 encoded_frame_writer_(encoded_frame_writer), 97 encoded_frame_writer_(encoded_frame_writer),
84 decoded_frame_writer_(decoded_frame_writer), 98 decoded_frame_writer_(decoded_frame_writer),
85 first_key_frame_has_been_excluded_(false), 99 first_key_frame_has_been_excluded_(false),
86 last_frame_missing_(false), 100 last_frame_missing_(false),
87 initialized_(false), 101 initialized_(false),
88 encoded_frame_size_(0), 102 encoded_frame_size_(0),
89 encoded_frame_type_(kVideoFrameKey), 103 encoded_frame_type_(kVideoFrameKey),
90 prev_time_stamp_(0), 104 prev_time_stamp_(0),
105 last_encoder_frame_width_(0),
106 last_encoder_frame_height_(0),
107 stats_(stats),
91 num_dropped_frames_(0), 108 num_dropped_frames_(0),
92 num_spatial_resizes_(0), 109 num_spatial_resizes_(0),
93 last_encoder_frame_width_(0),
94 last_encoder_frame_height_(0),
95 bit_rate_factor_(0.0), 110 bit_rate_factor_(0.0),
96 encode_start_ns_(0), 111 encode_start_ns_(0),
97 decode_start_ns_(0) { 112 decode_start_ns_(0) {
98 std::unique_ptr<TemporalLayersFactory> tl_factory;
99 if (config_.codec_settings->codecType == VideoCodecType::kVideoCodecVP8) {
100 tl_factory.reset(new TemporalLayersFactory());
101 config.codec_settings->VP8()->tl_factory = tl_factory.get();
102 }
103 bitrate_allocator_ = VideoCodecInitializer::CreateBitrateAllocator(
104 *config.codec_settings, std::move(tl_factory));
105 RTC_DCHECK(encoder); 113 RTC_DCHECK(encoder);
106 RTC_DCHECK(decoder); 114 RTC_DCHECK(decoder);
115 RTC_DCHECK(packet_manipulator);
107 RTC_DCHECK(analysis_frame_reader); 116 RTC_DCHECK(analysis_frame_reader);
108 RTC_DCHECK(analysis_frame_writer); 117 RTC_DCHECK(analysis_frame_writer);
109 RTC_DCHECK(packet_manipulator);
110 RTC_DCHECK(stats); 118 RTC_DCHECK(stats);
111 } 119 }
112 120
113 bool VideoProcessorImpl::Init() { 121 bool VideoProcessorImpl::Init() {
114 // Calculate a factor used for bit rate calculations. 122 // Calculate a factor used for bit rate calculations.
115 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits 123 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits
116 124
117 // Initialize data structures used by the encoder/decoder APIs. 125 // Initialize data structures used by the encoder/decoder APIs.
118 size_t frame_length_in_bytes = analysis_frame_reader_->FrameLength(); 126 size_t frame_length_in_bytes = analysis_frame_reader_->FrameLength();
119 last_successful_frame_buffer_.reset(new uint8_t[frame_length_in_bytes]); 127 last_successful_frame_buffer_.reset(new uint8_t[frame_length_in_bytes]);
120 128
121 // Set fixed properties common for all frames. 129 // Set fixed properties common for all frames.
122 // To keep track of spatial resize actions by encoder. 130 // To keep track of spatial resize actions by encoder.
123 last_encoder_frame_width_ = config_.codec_settings->width; 131 last_encoder_frame_width_ = config_.codec_settings->width;
124 last_encoder_frame_height_ = config_.codec_settings->height; 132 last_encoder_frame_height_ = config_.codec_settings->height;
125 133
126 // Setup required callbacks for the encoder/decoder. 134 // Setup required callbacks for the encoder/decoder.
127 encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this));
128 decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this));
129 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), 135 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()),
130 WEBRTC_VIDEO_CODEC_OK) 136 WEBRTC_VIDEO_CODEC_OK)
131 << "Failed to register encode complete callback"; 137 << "Failed to register encode complete callback";
132 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), 138 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()),
133 WEBRTC_VIDEO_CODEC_OK) 139 WEBRTC_VIDEO_CODEC_OK)
134 << "Failed to register decode complete callback"; 140 << "Failed to register decode complete callback";
135 141
136 // Init the encoder and decoder. 142 // Initialize the encoder and decoder.
137 uint32_t num_cores = 143 uint32_t num_cores =
138 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); 144 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores();
139 RTC_CHECK_EQ( 145 RTC_CHECK_EQ(
140 encoder_->InitEncode(config_.codec_settings, num_cores, 146 encoder_->InitEncode(config_.codec_settings, num_cores,
141 config_.networking_config.max_payload_size_in_bytes), 147 config_.networking_config.max_payload_size_in_bytes),
142 WEBRTC_VIDEO_CODEC_OK) 148 WEBRTC_VIDEO_CODEC_OK)
143 << "Failed to initialize VideoEncoder"; 149 << "Failed to initialize VideoEncoder";
144 150
145 RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, num_cores), 151 RTC_CHECK_EQ(decoder_->InitDecode(config_.codec_settings, num_cores),
146 WEBRTC_VIDEO_CODEC_OK) 152 WEBRTC_VIDEO_CODEC_OK)
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 stat.frame_number = frame_number; 321 stat.frame_number = frame_number;
316 stat.frame_type = encoded_image._frameType; 322 stat.frame_type = encoded_image._frameType;
317 stat.qp = encoded_image.qp_; 323 stat.qp = encoded_image.qp_;
318 stat.bit_rate_in_kbps = encoded_image._length * bit_rate_factor_; 324 stat.bit_rate_in_kbps = encoded_image._length * bit_rate_factor_;
319 stat.total_packets = 325 stat.total_packets =
320 encoded_image._length / config_.networking_config.packet_size_in_bytes + 326 encoded_image._length / config_.networking_config.packet_size_in_bytes +
321 1; 327 1;
322 328
323 // Simulate packet loss. 329 // Simulate packet loss.
324 bool exclude_this_frame = false; 330 bool exclude_this_frame = false;
325 // Only keyframes can be excluded.
326 if (encoded_image._frameType == kVideoFrameKey) { 331 if (encoded_image._frameType == kVideoFrameKey) {
332 // Only keyframes can be excluded.
327 switch (config_.exclude_frame_types) { 333 switch (config_.exclude_frame_types) {
328 case kExcludeOnlyFirstKeyFrame: 334 case kExcludeOnlyFirstKeyFrame:
329 if (!first_key_frame_has_been_excluded_) { 335 if (!first_key_frame_has_been_excluded_) {
330 first_key_frame_has_been_excluded_ = true; 336 first_key_frame_has_been_excluded_ = true;
331 exclude_this_frame = true; 337 exclude_this_frame = true;
332 } 338 }
333 break; 339 break;
334 case kExcludeAllKeyFrames: 340 case kExcludeAllKeyFrames:
335 exclude_this_frame = true; 341 exclude_this_frame = true;
336 break; 342 break;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, 465 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start,
460 int64_t stop) { 466 int64_t stop) {
461 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; 467 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec;
462 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min()); 468 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min());
463 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max()); 469 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max());
464 return static_cast<int>(encode_time); 470 return static_cast<int>(encode_time);
465 } 471 }
466 472
467 } // namespace test 473 } // namespace test
468 } // namespace webrtc 474 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/test/videoprocessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698