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

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

Issue 2741953002: Step #4: Run VideoProcessor integration test batch mode on task queue. (Closed)
Patch Set: Fix gn. Created 3 years, 9 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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 output_filename(""), 107 output_filename(""),
108 output_dir("out"), 108 output_dir("out"),
109 networking_config(), 109 networking_config(),
110 exclude_frame_types(kExcludeOnlyFirstKeyFrame), 110 exclude_frame_types(kExcludeOnlyFirstKeyFrame),
111 frame_length_in_bytes(0), 111 frame_length_in_bytes(0),
112 use_single_core(false), 112 use_single_core(false),
113 keyframe_interval(0), 113 keyframe_interval(0),
114 codec_settings(nullptr), 114 codec_settings(nullptr),
115 verbose(true) {} 115 verbose(true) {}
116 116
117 TestConfig::~TestConfig() {} 117 TestConfig::~TestConfig() = default;
118
119 VideoProcessor::~VideoProcessor() = default;
118 120
119 VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder, 121 VideoProcessorImpl::VideoProcessorImpl(webrtc::VideoEncoder* encoder,
120 webrtc::VideoDecoder* decoder, 122 webrtc::VideoDecoder* decoder,
121 FrameReader* analysis_frame_reader, 123 FrameReader* analysis_frame_reader,
122 FrameWriter* analysis_frame_writer, 124 FrameWriter* analysis_frame_writer,
123 PacketManipulator* packet_manipulator, 125 PacketManipulator* packet_manipulator,
124 const TestConfig& config, 126 const TestConfig& config,
125 Stats* stats, 127 Stats* stats,
126 FrameWriter* source_frame_writer, 128 FrameWriter* source_frame_writer,
127 IvfFileWriter* encoded_frame_writer, 129 IvfFileWriter* encoded_frame_writer,
128 FrameWriter* decoded_frame_writer) 130 FrameWriter* decoded_frame_writer)
129 : encoder_(encoder), 131 : encoder_(encoder),
130 decoder_(decoder), 132 decoder_(decoder),
131 bitrate_allocator_(CreateBitrateAllocator(config)), 133 bitrate_allocator_(CreateBitrateAllocator(config)),
132 encode_callback_(new VideoProcessorEncodeCompleteCallback(this)),
133 decode_callback_(new VideoProcessorDecodeCompleteCallback(this)),
134 packet_manipulator_(packet_manipulator), 134 packet_manipulator_(packet_manipulator),
135 config_(config), 135 config_(config),
136 analysis_frame_reader_(analysis_frame_reader), 136 analysis_frame_reader_(analysis_frame_reader),
137 analysis_frame_writer_(analysis_frame_writer), 137 analysis_frame_writer_(analysis_frame_writer),
138 num_frames_(analysis_frame_reader->NumberOfFrames()), 138 num_frames_(analysis_frame_reader->NumberOfFrames()),
139 source_frame_writer_(source_frame_writer), 139 source_frame_writer_(source_frame_writer),
140 encoded_frame_writer_(encoded_frame_writer), 140 encoded_frame_writer_(encoded_frame_writer),
141 decoded_frame_writer_(decoded_frame_writer), 141 decoded_frame_writer_(decoded_frame_writer),
142 initialized_(false), 142 initialized_(false),
143 last_encoded_frame_num_(-1), 143 last_encoded_frame_num_(-1),
144 last_decoded_frame_num_(-1), 144 last_decoded_frame_num_(-1),
145 first_key_frame_has_been_excluded_(false), 145 first_key_frame_has_been_excluded_(false),
146 last_decoded_frame_buffer_(0, analysis_frame_reader->FrameLength()), 146 last_decoded_frame_buffer_(0, analysis_frame_reader->FrameLength()),
147 stats_(stats), 147 stats_(stats),
148 num_dropped_frames_(0), 148 num_dropped_frames_(0),
149 num_spatial_resizes_(0), 149 num_spatial_resizes_(0),
150 bit_rate_factor_(0.0) { 150 bit_rate_factor_(0.0) {
151 RTC_DCHECK(encoder); 151 RTC_DCHECK(encoder);
152 RTC_DCHECK(decoder); 152 RTC_DCHECK(decoder);
153 RTC_DCHECK(packet_manipulator); 153 RTC_DCHECK(packet_manipulator);
154 RTC_DCHECK(analysis_frame_reader); 154 RTC_DCHECK(analysis_frame_reader);
155 RTC_DCHECK(analysis_frame_writer); 155 RTC_DCHECK(analysis_frame_writer);
156 RTC_DCHECK(stats); 156 RTC_DCHECK(stats);
157 157
158 frame_infos_.reserve(num_frames_); 158 frame_infos_.reserve(num_frames_);
159
160 task_checker_.Detach();
159 } 161 }
160 162
163 VideoProcessorImpl::~VideoProcessorImpl() = default;
164
161 bool VideoProcessorImpl::Init() { 165 bool VideoProcessorImpl::Init() {
166 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
162 RTC_DCHECK(!initialized_) 167 RTC_DCHECK(!initialized_)
163 << "This VideoProcessor has already been initialized."; 168 << "This VideoProcessor has already been initialized.";
164 169
165 // Calculate a factor used for bit rate calculations. 170 // Calculate a factor used for bit rate calculations.
166 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits 171 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits
167 172
168 // Setup required callbacks for the encoder/decoder. 173 // Setup required callbacks for the encoder/decoder.
174 encode_callback_.reset(new VideoProcessorEncodeCompleteCallback(this));
169 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()), 175 RTC_CHECK_EQ(encoder_->RegisterEncodeCompleteCallback(encode_callback_.get()),
170 WEBRTC_VIDEO_CODEC_OK) 176 WEBRTC_VIDEO_CODEC_OK)
171 << "Failed to register encode complete callback"; 177 << "Failed to register encode complete callback";
178 decode_callback_.reset(new VideoProcessorDecodeCompleteCallback(this));
172 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()), 179 RTC_CHECK_EQ(decoder_->RegisterDecodeCompleteCallback(decode_callback_.get()),
173 WEBRTC_VIDEO_CODEC_OK) 180 WEBRTC_VIDEO_CODEC_OK)
174 << "Failed to register decode complete callback"; 181 << "Failed to register decode complete callback";
175 182
176 // Initialize the encoder and decoder. 183 // Initialize the encoder and decoder.
177 uint32_t num_cores = 184 uint32_t num_cores =
178 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores(); 185 config_.use_single_core ? 1 : CpuInfo::DetectNumberOfCores();
179 RTC_CHECK_EQ( 186 RTC_CHECK_EQ(
180 encoder_->InitEncode(config_.codec_settings, num_cores, 187 encoder_->InitEncode(config_.codec_settings, num_cores,
181 config_.networking_config.max_payload_size_in_bytes), 188 config_.networking_config.max_payload_size_in_bytes),
(...skipping 14 matching lines...) Expand all
196 printf(" Decoder implementation name: %s\n", 203 printf(" Decoder implementation name: %s\n",
197 decoder_->ImplementationName()); 204 decoder_->ImplementationName());
198 PrintCodecSettings(config_.codec_settings); 205 PrintCodecSettings(config_.codec_settings);
199 } 206 }
200 207
201 initialized_ = true; 208 initialized_ = true;
202 209
203 return true; 210 return true;
204 } 211 }
205 212
206 VideoProcessorImpl::~VideoProcessorImpl() { 213 void VideoProcessorImpl::DeregisterCallbacks() {
214 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
tommi 2017/03/21 10:03:27 if DeregisterCallbacks() is always followed by del
brandtr 2017/06/28 09:40:24 The calling of Deinit() is not directly followed b
207 encoder_->RegisterEncodeCompleteCallback(nullptr); 215 encoder_->RegisterEncodeCompleteCallback(nullptr);
208 decoder_->RegisterDecodeCompleteCallback(nullptr); 216 decoder_->RegisterDecodeCompleteCallback(nullptr);
209 } 217 }
210 218
211 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) { 219 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
220 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
212 int set_rates_result = encoder_->SetRateAllocation( 221 int set_rates_result = encoder_->SetRateAllocation(
213 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate), 222 bitrate_allocator_->GetAllocation(bit_rate * 1000, frame_rate),
214 frame_rate); 223 frame_rate);
215 RTC_DCHECK_GE(set_rates_result, 0) 224 RTC_DCHECK_GE(set_rates_result, 0)
216 << "Failed to update encoder with new rate " << bit_rate; 225 << "Failed to update encoder with new rate " << bit_rate;
217 num_dropped_frames_ = 0; 226 num_dropped_frames_ = 0;
218 num_spatial_resizes_ = 0; 227 num_spatial_resizes_ = 0;
219 } 228 }
220 229
221 size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) { 230 size_t VideoProcessorImpl::EncodedFrameSize(int frame_number) {
231 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
222 RTC_DCHECK_LT(frame_number, frame_infos_.size()); 232 RTC_DCHECK_LT(frame_number, frame_infos_.size());
223 return frame_infos_[frame_number].encoded_frame_size; 233 return frame_infos_[frame_number].encoded_frame_size;
224 } 234 }
225 235
226 FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) { 236 FrameType VideoProcessorImpl::EncodedFrameType(int frame_number) {
237 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
227 RTC_DCHECK_LT(frame_number, frame_infos_.size()); 238 RTC_DCHECK_LT(frame_number, frame_infos_.size());
228 return frame_infos_[frame_number].encoded_frame_type; 239 return frame_infos_[frame_number].encoded_frame_type;
229 } 240 }
230 241
231 int VideoProcessorImpl::NumberDroppedFrames() { 242 int VideoProcessorImpl::NumberDroppedFrames() {
243 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
232 return num_dropped_frames_; 244 return num_dropped_frames_;
233 } 245 }
234 246
235 int VideoProcessorImpl::NumberSpatialResizes() { 247 int VideoProcessorImpl::NumberSpatialResizes() {
248 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
236 return num_spatial_resizes_; 249 return num_spatial_resizes_;
237 } 250 }
238 251
239 bool VideoProcessorImpl::ProcessFrame(int frame_number) { 252 bool VideoProcessorImpl::ProcessFrame(int frame_number) {
253 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
240 RTC_DCHECK_GE(frame_number, 0); 254 RTC_DCHECK_GE(frame_number, 0);
241 RTC_DCHECK_LE(frame_number, frame_infos_.size()) 255 RTC_DCHECK_LE(frame_number, frame_infos_.size())
242 << "Must process frames without gaps."; 256 << "Must process frames without gaps.";
243 RTC_DCHECK(initialized_) << "Attempting to use uninitialized VideoProcessor"; 257 RTC_DCHECK(initialized_) << "Attempting to use uninitialized VideoProcessor";
244 258
245 rtc::scoped_refptr<VideoFrameBuffer> buffer( 259 rtc::scoped_refptr<VideoFrameBuffer> buffer(
246 analysis_frame_reader_->ReadFrame()); 260 analysis_frame_reader_->ReadFrame());
247 261
248 if (!buffer) { 262 if (!buffer) {
249 // Last frame has been reached. 263 // Last frame has been reached.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 304
291 return true; 305 return true;
292 } 306 }
293 307
294 void VideoProcessorImpl::FrameEncoded( 308 void VideoProcessorImpl::FrameEncoded(
295 webrtc::VideoCodecType codec, 309 webrtc::VideoCodecType codec,
296 const EncodedImage& encoded_image, 310 const EncodedImage& encoded_image,
297 const webrtc::RTPFragmentationHeader* fragmentation) { 311 const webrtc::RTPFragmentationHeader* fragmentation) {
298 // For the highest measurement accuracy of the encode time, the start/stop 312 // For the highest measurement accuracy of the encode time, the start/stop
299 // time recordings should wrap the Encode call as tightly as possible. 313 // time recordings should wrap the Encode call as tightly as possible.
314 // TODO(brandtr): Consider moving this measurement into the callback wrapper
315 // class.
300 int64_t encode_stop_ns = rtc::TimeNanos(); 316 int64_t encode_stop_ns = rtc::TimeNanos();
301 317
318 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
tommi 2017/03/21 10:03:27 nit: keep these checks at the top of each function
brandtr 2017/06/28 09:40:24 Done.
319
302 if (encoded_frame_writer_) { 320 if (encoded_frame_writer_) {
303 RTC_CHECK(encoded_frame_writer_->WriteFrame(encoded_image, codec)); 321 RTC_CHECK(encoded_frame_writer_->WriteFrame(encoded_image, codec));
304 } 322 }
305 323
306 // Timestamp is proportional to frame number, so this gives us number of 324 // Timestamp is proportional to frame number, so this gives us number of
307 // dropped frames. 325 // dropped frames.
308 int frame_number = TimestampToFrameNumber(encoded_image._timeStamp); 326 int frame_number = TimestampToFrameNumber(encoded_image._timeStamp);
309 bool last_frame_missing = false; 327 bool last_frame_missing = false;
310 if (frame_number > 0) { 328 if (frame_number > 0) {
311 RTC_DCHECK_GE(last_encoded_frame_num_, 0); 329 RTC_DCHECK_GE(last_encoded_frame_num_, 0);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 decoded_frame_writer_->FrameLength()); 432 decoded_frame_writer_->FrameLength());
415 RTC_CHECK( 433 RTC_CHECK(
416 decoded_frame_writer_->WriteFrame(last_decoded_frame_buffer_.data())); 434 decoded_frame_writer_->WriteFrame(last_decoded_frame_buffer_.data()));
417 } 435 }
418 } 436 }
419 } 437 }
420 438
421 void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) { 439 void VideoProcessorImpl::FrameDecoded(const VideoFrame& image) {
422 // For the highest measurement accuracy of the decode time, the start/stop 440 // For the highest measurement accuracy of the decode time, the start/stop
423 // time recordings should wrap the Decode call as tightly as possible. 441 // time recordings should wrap the Decode call as tightly as possible.
442 // TODO(brandtr): Consider moving this measurement into the callback wrapper
443 // class.
424 int64_t decode_stop_ns = rtc::TimeNanos(); 444 int64_t decode_stop_ns = rtc::TimeNanos();
425 445
446 RTC_DCHECK_CALLED_SEQUENTIALLY(&task_checker_);
447
426 // Update frame information and statistics. 448 // Update frame information and statistics.
427 int frame_number = TimestampToFrameNumber(image.timestamp()); 449 int frame_number = TimestampToFrameNumber(image.timestamp());
428 RTC_DCHECK_LT(frame_number, frame_infos_.size()); 450 RTC_DCHECK_LT(frame_number, frame_infos_.size());
429 FrameInfo* frame_info = &frame_infos_[frame_number]; 451 FrameInfo* frame_info = &frame_infos_[frame_number];
430 frame_info->decoded_width = image.width(); 452 frame_info->decoded_width = image.width();
431 frame_info->decoded_height = image.height(); 453 frame_info->decoded_height = image.height();
432 FrameStatistic* frame_stat = &stats_->stats_[frame_number]; 454 FrameStatistic* frame_stat = &stats_->stats_[frame_number];
433 frame_stat->decode_time_in_us = 455 frame_stat->decode_time_in_us =
434 GetElapsedTimeMicroseconds(frame_info->decode_start_ns, decode_stop_ns); 456 GetElapsedTimeMicroseconds(frame_info->decode_start_ns, decode_stop_ns);
435 frame_stat->decoding_successful = true; 457 frame_stat->decoding_successful = true;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 if (decoded_frame_writer_) { 513 if (decoded_frame_writer_) {
492 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength()); 514 RTC_DCHECK_EQ(extracted_length, decoded_frame_writer_->FrameLength());
493 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data())); 515 RTC_CHECK(decoded_frame_writer_->WriteFrame(extracted_buffer.data()));
494 } 516 }
495 517
496 last_decoded_frame_buffer_ = std::move(extracted_buffer); 518 last_decoded_frame_buffer_ = std::move(extracted_buffer);
497 } 519 }
498 520
499 } // namespace test 521 } // namespace test
500 } // namespace webrtc 522 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698