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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h

Issue 2741953002: Step #4: Run VideoProcessor integration test batch mode on task queue. (Closed)
Patch Set: Rebase. 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 10 matching lines...) Expand all
21 #if defined(WEBRTC_ANDROID) 21 #if defined(WEBRTC_ANDROID)
22 #include "webrtc/modules/video_coding/codecs/test/android_test_initializer.h" 22 #include "webrtc/modules/video_coding/codecs/test/android_test_initializer.h"
23 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h" 23 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h"
24 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h" 24 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h"
25 #elif defined(WEBRTC_IOS) 25 #elif defined(WEBRTC_IOS)
26 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h" 26 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h"
27 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h" 27 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h"
28 #endif 28 #endif
29 29
30 #include "webrtc/base/checks.h" 30 #include "webrtc/base/checks.h"
31 #include "webrtc/base/event.h"
31 #include "webrtc/base/file.h" 32 #include "webrtc/base/file.h"
32 #include "webrtc/base/logging.h" 33 #include "webrtc/base/logging.h"
34 #include "webrtc/base/task_queue.h"
33 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" 35 #include "webrtc/media/engine/webrtcvideodecoderfactory.h"
34 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 36 #include "webrtc/media/engine/webrtcvideoencoderfactory.h"
35 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 37 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
36 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" 38 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h"
37 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" 39 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h"
38 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 40 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
39 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" 41 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
40 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 42 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
41 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 43 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
42 #include "webrtc/modules/video_coding/include/video_coding.h" 44 #include "webrtc/modules/video_coding/include/video_coding.h"
43 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" 45 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h"
46 #include "webrtc/system_wrappers/include/sleep.h"
44 #include "webrtc/test/gtest.h" 47 #include "webrtc/test/gtest.h"
45 #include "webrtc/test/testsupport/fileutils.h" 48 #include "webrtc/test/testsupport/fileutils.h"
46 #include "webrtc/test/testsupport/frame_reader.h" 49 #include "webrtc/test/testsupport/frame_reader.h"
47 #include "webrtc/test/testsupport/frame_writer.h" 50 #include "webrtc/test/testsupport/frame_writer.h"
48 #include "webrtc/test/testsupport/metrics/video_metrics.h" 51 #include "webrtc/test/testsupport/metrics/video_metrics.h"
49 #include "webrtc/test/testsupport/packet_reader.h" 52 #include "webrtc/test/testsupport/packet_reader.h"
50 #include "webrtc/typedefs.h" 53 #include "webrtc/typedefs.h"
51 54
52 namespace webrtc { 55 namespace webrtc {
53 namespace test { 56 namespace test {
54 // Maximum number of rate updates (i.e., calls to encoder to change bitrate 57 // Maximum number of rate updates (i.e., calls to encoder to change bitrate
55 // and/or frame rate) for the current tests. 58 // and/or frame rate) for the current tests.
56 const int kMaxNumRateUpdates = 3; 59 const int kMaxNumRateUpdates = 3;
57 60
58 // Maximum number of temporal layers to use in tests. 61 // Maximum number of temporal layers to use in tests.
59 const int kMaxNumTemporalLayers = 3; 62 const int kMaxNumTemporalLayers = 3;
60 63
61 const int kPercTargetvsActualMismatch = 20; 64 const int kPercTargetvsActualMismatch = 20;
62 const int kBaseKeyFrameInterval = 3000; 65 const int kBaseKeyFrameInterval = 3000;
63 66
64 // Default sequence is foreman (CIF): may be better to use VGA for resize test. 67 // Default sequence is foreman (CIF): may be better to use VGA for resize test.
65 const int kCifWidth = 352; 68 const int kCifWidth = 352;
66 const int kCifHeight = 288; 69 const int kCifHeight = 288;
67 const char kFilenameForemanCif[] = "foreman_cif"; 70 const char kFilenameForemanCif[] = "foreman_cif";
68 71
72 const int kNumMillisecondsPerSecond = 1000;
73
69 // Codec and network settings. 74 // Codec and network settings.
70 struct CodecParams { 75 struct CodecParams {
71 VideoCodecType codec_type; 76 VideoCodecType codec_type;
72 bool hw_codec; 77 bool hw_codec;
73 bool use_single_core; 78 bool use_single_core;
74 79
75 int width; 80 int width;
76 int height; 81 int height;
77 82
78 int num_temporal_layers; 83 int num_temporal_layers;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 encoder_.reset(VP9Encoder::Create()); 234 encoder_.reset(VP9Encoder::Create());
230 decoder_.reset(VP9Decoder::Create()); 235 decoder_.reset(VP9Decoder::Create());
231 break; 236 break;
232 default: 237 default:
233 RTC_NOTREACHED(); 238 RTC_NOTREACHED();
234 break; 239 break;
235 } 240 }
236 } 241 }
237 242
238 void SetUpCodecConfig(const CodecParams& process, 243 void SetUpCodecConfig(const CodecParams& process,
244 const RateProfile& rate_profile,
239 const VisualizationParams* visualization_params) { 245 const VisualizationParams* visualization_params) {
240 CreateEncoderAndDecoder(process.hw_codec, process.codec_type); 246 CreateEncoderAndDecoder(process.hw_codec, process.codec_type);
241 247
242 // Configure input filename. 248 // Configure input filename.
243 config_.input_filename = test::ResourcePath(process.filename, "yuv"); 249 config_.input_filename = test::ResourcePath(process.filename, "yuv");
244 if (process.verbose_logging) 250 if (process.verbose_logging)
245 printf("Filename: %s\n", process.filename.c_str()); 251 printf("Filename: %s\n", process.filename.c_str());
246 // Generate an output filename in a safe way. 252 // Generate an output filename in a safe way.
247 config_.output_filename = test::TempFilename( 253 config_.output_filename = test::TempFilename(
248 test::OutputPath(), "videoprocessor_integrationtest"); 254 test::OutputPath(), "videoprocessor_integrationtest");
249 255
250 config_.frame_length_in_bytes = 256 config_.frame_length_in_bytes =
251 CalcBufferSize(kI420, process.width, process.height); 257 CalcBufferSize(kI420, process.width, process.height);
252 config_.verbose = process.verbose_logging; 258 config_.verbose = process.verbose_logging;
253 config_.use_single_core = process.use_single_core; 259 config_.use_single_core = process.use_single_core;
254 // Key frame interval and packet loss are set for each test. 260 // Key frame interval and packet loss are set for each test.
255 config_.keyframe_interval = process.key_frame_interval; 261 config_.keyframe_interval = process.key_frame_interval;
256 config_.networking_config.packet_loss_probability = 262 config_.networking_config.packet_loss_probability =
257 packet_loss_probability_; 263 process.packet_loss_probability;
258 264
259 // Configure codec settings. 265 // Configure codec settings.
260 VideoCodingModule::Codec(process.codec_type, &codec_settings_); 266 VideoCodingModule::Codec(process.codec_type, &codec_settings_);
261 config_.codec_settings = &codec_settings_; 267 config_.codec_settings = &codec_settings_;
262 config_.codec_settings->startBitrate = start_bitrate_; 268 float start_bitrate = rate_profile.target_bit_rate[0];
269 config_.codec_settings->startBitrate = start_bitrate;
263 config_.codec_settings->width = process.width; 270 config_.codec_settings->width = process.width;
264 config_.codec_settings->height = process.height; 271 config_.codec_settings->height = process.height;
265 272
266 // These features may be set depending on the test. 273 // These features may be set depending on the test.
267 switch (config_.codec_settings->codecType) { 274 switch (config_.codec_settings->codecType) {
268 case kVideoCodecH264: 275 case kVideoCodecH264:
269 config_.codec_settings->H264()->frameDroppingOn = 276 config_.codec_settings->H264()->frameDroppingOn =
270 process.frame_dropper_on; 277 process.frame_dropper_on;
271 config_.codec_settings->H264()->keyFrameInterval = 278 config_.codec_settings->H264()->keyFrameInterval =
272 kBaseKeyFrameInterval; 279 kBaseKeyFrameInterval;
(...skipping 29 matching lines...) Expand all
302 analysis_frame_reader_.reset(new test::YuvFrameReaderImpl( 309 analysis_frame_reader_.reset(new test::YuvFrameReaderImpl(
303 config_.input_filename, config_.codec_settings->width, 310 config_.input_filename, config_.codec_settings->width,
304 config_.codec_settings->height)); 311 config_.codec_settings->height));
305 analysis_frame_writer_.reset(new test::YuvFrameWriterImpl( 312 analysis_frame_writer_.reset(new test::YuvFrameWriterImpl(
306 config_.output_filename, config_.codec_settings->width, 313 config_.output_filename, config_.codec_settings->width,
307 config_.codec_settings->height)); 314 config_.codec_settings->height));
308 RTC_CHECK(analysis_frame_reader_->Init()); 315 RTC_CHECK(analysis_frame_reader_->Init());
309 RTC_CHECK(analysis_frame_writer_->Init()); 316 RTC_CHECK(analysis_frame_writer_->Init());
310 317
311 if (visualization_params) { 318 if (visualization_params) {
319 int start_frame_rate = rate_profile.input_frame_rate[0];
312 // clang-format off 320 // clang-format off
313 const std::string output_filename_base = 321 const std::string output_filename_base =
314 test::OutputPath() + process.filename + 322 test::OutputPath() + process.filename +
315 "_cd-" + CodecTypeToPayloadName(process.codec_type).value_or("") + 323 "_cd-" + CodecTypeToPayloadName(process.codec_type).value_or("") +
316 "_hw-" + std::to_string(process.hw_codec) + 324 "_hw-" + std::to_string(process.hw_codec) +
317 "_fr-" + std::to_string(start_frame_rate_) + 325 "_fr-" + std::to_string(start_frame_rate) +
318 "_br-" + std::to_string(static_cast<int>(start_bitrate_)); 326 "_br-" + std::to_string(static_cast<int>(start_bitrate));
319 // clang-format on 327 // clang-format on
320 if (visualization_params->save_source_y4m) { 328 if (visualization_params->save_source_y4m) {
321 source_frame_writer_.reset(new test::Y4mFrameWriterImpl( 329 source_frame_writer_.reset(new test::Y4mFrameWriterImpl(
322 output_filename_base + "_source.y4m", config_.codec_settings->width, 330 output_filename_base + "_source.y4m", config_.codec_settings->width,
323 config_.codec_settings->height, start_frame_rate_)); 331 config_.codec_settings->height, start_frame_rate));
324 RTC_CHECK(source_frame_writer_->Init()); 332 RTC_CHECK(source_frame_writer_->Init());
325 } 333 }
326 if (visualization_params->save_encoded_ivf) { 334 if (visualization_params->save_encoded_ivf) {
327 rtc::File post_encode_file = 335 rtc::File post_encode_file =
328 rtc::File::Create(output_filename_base + "_encoded.ivf"); 336 rtc::File::Create(output_filename_base + "_encoded.ivf");
329 encoded_frame_writer_ = 337 encoded_frame_writer_ =
330 IvfFileWriter::Wrap(std::move(post_encode_file), 0); 338 IvfFileWriter::Wrap(std::move(post_encode_file), 0);
331 } 339 }
332 if (visualization_params->save_decoded_y4m) { 340 if (visualization_params->save_decoded_y4m) {
333 decoded_frame_writer_.reset(new test::Y4mFrameWriterImpl( 341 decoded_frame_writer_.reset(new test::Y4mFrameWriterImpl(
334 output_filename_base + "_decoded.y4m", 342 output_filename_base + "_decoded.y4m",
335 config_.codec_settings->width, config_.codec_settings->height, 343 config_.codec_settings->width, config_.codec_settings->height,
336 start_frame_rate_)); 344 start_frame_rate));
337 RTC_CHECK(decoded_frame_writer_->Init()); 345 RTC_CHECK(decoded_frame_writer_->Init());
338 } 346 }
339 } 347 }
348 }
340 349
350 void SetUpHelperObjects() {
341 packet_manipulator_.reset(new test::PacketManipulatorImpl( 351 packet_manipulator_.reset(new test::PacketManipulatorImpl(
342 &packet_reader_, config_.networking_config, config_.verbose)); 352 &packet_reader_, config_.networking_config, config_.verbose));
343 processor_.reset(new test::VideoProcessorImpl( 353 processor_.reset(new test::VideoProcessorImpl(
344 encoder_.get(), decoder_.get(), analysis_frame_reader_.get(), 354 encoder_.get(), decoder_.get(), analysis_frame_reader_.get(),
345 analysis_frame_writer_.get(), packet_manipulator_.get(), config_, 355 analysis_frame_writer_.get(), packet_manipulator_.get(), config_,
346 &stats_, source_frame_writer_.get(), encoded_frame_writer_.get(), 356 &stats_, source_frame_writer_.get(), encoded_frame_writer_.get(),
347 decoded_frame_writer_.get())); 357 decoded_frame_writer_.get()));
348 RTC_CHECK(processor_->Init()); 358 RTC_CHECK(processor_->Init());
brandtr 2017/03/10 09:50:55 Must be called on the task queue.
349 } 359 }
350 360
351 // Reset quantities after each encoder update, update the target 361 // Reset quantities after each encoder update, update the target
352 // per-frame bandwidth. 362 // per-frame bandwidth.
353 void ResetRateControlMetrics(int num_frames_to_hit_target) { 363 void ResetRateControlMetrics(int num_frames_to_hit_target) {
354 for (int i = 0; i < num_temporal_layers_; i++) { 364 for (int i = 0; i < num_temporal_layers_; i++) {
355 num_frames_per_update_[i] = 0; 365 num_frames_per_update_[i] = 0;
356 sum_frame_size_mismatch_[i] = 0.0f; 366 sum_frame_size_mismatch_[i] = 0.0f;
357 sum_encoded_frame_size_[i] = 0.0f; 367 sum_encoded_frame_size_[i] = 0.0f;
358 encoding_bitrate_[i] = 0.0f; 368 encoding_bitrate_[i] = 0.0f;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 if (num_temporal_layers_ == 3) { 553 if (num_temporal_layers_ == 3) {
544 frame_rate_layer_[2] = frame_rate_ / 2.0f; 554 frame_rate_layer_[2] = frame_rate_ / 2.0f;
545 } 555 }
546 } 556 }
547 557
548 // Processes all frames in the clip and verifies the result. 558 // Processes all frames in the clip and verifies the result.
549 // TODO(brandtr): Change the second last argument to be a 559 // TODO(brandtr): Change the second last argument to be a
550 // const std::vector<RateControlThresholds>&, so we can ensure that the user 560 // const std::vector<RateControlThresholds>&, so we can ensure that the user
551 // does not expect us to do mid-clip rate updates when we are not able to, 561 // does not expect us to do mid-clip rate updates when we are not able to,
552 // e.g., when we are operating in batch mode. 562 // e.g., when we are operating in batch mode.
553 void ProcessFramesAndVerify(QualityThresholds quality_thresholds, 563 void ProcessFramesAndVerify(QualityThresholds quality_thresholds,
brandtr 2017/03/10 09:50:55 This function is called on the main thread, from t
554 RateProfile rate_profile, 564 RateProfile rate_profile,
555 CodecParams process, 565 CodecParams process,
556 RateControlThresholds* rc_thresholds, 566 RateControlThresholds* rc_thresholds,
557 const VisualizationParams* visualization_params) { 567 const VisualizationParams* visualization_params) {
558 // Codec/config settings. 568 // Codec/config settings.
559 start_bitrate_ = rate_profile.target_bit_rate[0];
560 start_frame_rate_ = rate_profile.input_frame_rate[0];
561 packet_loss_probability_ = process.packet_loss_probability;
562 num_temporal_layers_ = process.num_temporal_layers; 569 num_temporal_layers_ = process.num_temporal_layers;
563 SetUpCodecConfig(process, visualization_params); 570 SetUpCodecConfig(process, rate_profile, visualization_params);
571
564 // Update the temporal layers and the codec with the initial rates. 572 // Update the temporal layers and the codec with the initial rates.
565 bit_rate_ = rate_profile.target_bit_rate[0]; 573 bit_rate_ = rate_profile.target_bit_rate[0];
566 frame_rate_ = rate_profile.input_frame_rate[0]; 574 frame_rate_ = rate_profile.input_frame_rate[0];
567 SetTemporalLayerRates(); 575 SetTemporalLayerRates();
568 // Set the initial target size for key frame. 576 // Set the initial target size for key frame.
569 target_size_key_frame_initial_ = 577 target_size_key_frame_initial_ =
570 0.5 * kInitialBufferSize * bit_rate_layer_[0]; 578 0.5 * kInitialBufferSize * bit_rate_layer_[0];
571 processor_->SetRates(bit_rate_, frame_rate_);
572 579
573 // Process each frame, up to |num_frames|. 580 // Process each frame, up to |num_frames|.
574 int frame_number = 0; 581 int frame_number = 0;
575 int update_index = 0; 582 int update_index = 0;
576 int num_frames = rate_profile.num_frames; 583 int num_frames = rate_profile.num_frames;
577 ResetRateControlMetrics( 584 ResetRateControlMetrics(
578 rate_profile.frame_index_rate_update[update_index + 1]); 585 rate_profile.frame_index_rate_update[update_index + 1]);
579 586
580 if (process.batch_mode) { 587 if (process.batch_mode) {
581 // In batch mode, we calculate the metrics for all frames after all frames 588 // In batch mode, we calculate the metrics for all frames after all frames
582 // have been sent for encoding. 589 // have been sent for encoding.
583 590
591 // AndroidMediaEncoder must be called on a task queue, so during the batch
592 // run we will call |processor_| on a task queue.
593 std::unique_ptr<rtc::TaskQueue> task_queue(
594 new rtc::TaskQueue("Integration test task queue."));
595 rtc::Event sync_event(false, false);
596
597 // Set up |processor_|, thus initiating the encoder and decoder.
598 task_queue->PostTask([this, &sync_event]() {
599 SetUpHelperObjects();
600 processor_->SetRates(bit_rate_, frame_rate_);
601 sync_event.Set();
602 });
603 sync_event.Wait(rtc::Event::kForever);
brandtr 2017/03/10 09:50:55 VideoProcessor is not thread safe, so we need to s
604
605 // Post all frames (in order) to encoder.
606 int start_frame_rate = rate_profile.input_frame_rate[0];
584 // TODO(brandtr): Refactor "frame number accounting" so we don't have to 607 // TODO(brandtr): Refactor "frame number accounting" so we don't have to
585 // call ProcessFrame num_frames+1 times here. 608 // call ProcessFrame num_frames+1 times here.
586 for (frame_number = 0; frame_number <= num_frames; ++frame_number) { 609 for (frame_number = 0; frame_number <= num_frames; ++frame_number) {
587 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); 610 task_queue->PostTask([this, frame_number]() {
611 EXPECT_TRUE(processor_->ProcessFrame(frame_number));
612 });
613
614 // HW codecs can get stressed out if frames are arriving to quickly,
615 // so we do some rough pacing here.
616 if (process.hw_codec) {
617 SleepMs(kNumMillisecondsPerSecond / start_frame_rate);
618 }
588 } 619 }
589 620
621 // Give the task queue some time to finish processing the posted frames,
622 // then shut down processing and synchronize with main thread.
623 SleepMs(1 * kNumMillisecondsPerSecond);
624 sync_event.Reset();
625 task_queue->PostTask([this, &sync_event]() {
626 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
627 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
628 processor_->DeregisterCallbacks();
629 sync_event.Set();
630 });
631 sync_event.Wait(rtc::Event::kForever);
632
633 // Tear down the task queue, to make sure it is safe to call |processor_|
634 // from the main thread now.
635 task_queue.reset();
636
590 for (frame_number = 0; frame_number < num_frames; ++frame_number) { 637 for (frame_number = 0; frame_number < num_frames; ++frame_number) {
591 ++num_frames_per_update_[TemporalLayerIndexForFrame(frame_number)]; 638 ++num_frames_per_update_[TemporalLayerIndexForFrame(frame_number)];
592 ++num_frames_total_; 639 ++num_frames_total_;
593 UpdateRateControlMetrics(frame_number); 640 UpdateRateControlMetrics(frame_number);
594 } 641 }
595 } else { 642 } else {
596 // In online mode, we calculate the metrics for a given frame right after 643 // In online mode, we calculate the metrics for a given frame right after
597 // it has been sent for encoding. 644 // it has been sent for encoding.
598 645
599 if (process.hw_codec) { 646 if (process.hw_codec) {
600 LOG(LS_WARNING) << "HW codecs should mostly be run in batch mode, " 647 LOG(LS_WARNING) << "HW codecs should mostly be run in batch mode, "
601 "since they may be pipelining."; 648 "since they may be pipelining.";
602 } 649 }
603 650
651 SetUpHelperObjects();
652 processor_->SetRates(bit_rate_, frame_rate_);
653
604 while (frame_number < num_frames) { 654 while (frame_number < num_frames) {
605 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); 655 EXPECT_TRUE(processor_->ProcessFrame(frame_number));
606 656
607 ++num_frames_per_update_[TemporalLayerIndexForFrame(frame_number)]; 657 ++num_frames_per_update_[TemporalLayerIndexForFrame(frame_number)];
608 ++num_frames_total_; 658 ++num_frames_total_;
609 UpdateRateControlMetrics(frame_number); 659 UpdateRateControlMetrics(frame_number);
610 660
611 ++frame_number; 661 ++frame_number;
612 662
613 // If we hit another/next update, verify stats for current state and 663 // If we hit another/next update, verify stats for current state and
614 // update layers and codec with new rates. 664 // update layers and codec with new rates.
615 if (frame_number == 665 if (frame_number ==
616 rate_profile.frame_index_rate_update[update_index + 1]) { 666 rate_profile.frame_index_rate_update[update_index + 1]) {
617 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); 667 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]);
618 668
619 // Update layer rates and the codec with new rates. 669 // Update layer rates and the codec with new rates.
620 ++update_index; 670 ++update_index;
621 bit_rate_ = rate_profile.target_bit_rate[update_index]; 671 bit_rate_ = rate_profile.target_bit_rate[update_index];
622 frame_rate_ = rate_profile.input_frame_rate[update_index]; 672 frame_rate_ = rate_profile.input_frame_rate[update_index];
623 SetTemporalLayerRates(); 673 SetTemporalLayerRates();
624 ResetRateControlMetrics( 674 ResetRateControlMetrics(
625 rate_profile.frame_index_rate_update[update_index + 1]); 675 rate_profile.frame_index_rate_update[update_index + 1]);
626 processor_->SetRates(bit_rate_, frame_rate_); 676 processor_->SetRates(bit_rate_, frame_rate_);
627 } 677 }
628 } 678 }
629 // TODO(brandtr): Refactor "frame number accounting" so we don't have to 679 // TODO(brandtr): Refactor "frame number accounting" so we don't have to
630 // call ProcessFrame one extra time here. 680 // call ProcessFrame one extra time here.
631 EXPECT_TRUE(processor_->ProcessFrame(frame_number)); 681 EXPECT_TRUE(processor_->ProcessFrame(frame_number));
682
683 // Release encoder and decoder to make sure they have finished processing.
684 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
685 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
686 processor_->DeregisterCallbacks();
632 } 687 }
633 688
634 // Verify rate control metrics for all frames (if in batch mode), or for all 689 // Verify rate control metrics for all frames (if in batch mode), or for all
635 // frames since the last rate update (if not in batch mode). 690 // frames since the last rate update (if not in batch mode).
636 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); 691 VerifyRateControlMetrics(update_index, rc_thresholds[update_index]);
637 EXPECT_EQ(num_frames, frame_number); 692 EXPECT_EQ(num_frames, frame_number);
638 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); 693 EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size()));
639 694
640 // Release encoder and decoder to make sure they have finished processing.
641 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
642 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
643
644 // Close the analysis files before we use them for SSIM/PSNR calculations. 695 // Close the analysis files before we use them for SSIM/PSNR calculations.
645 analysis_frame_reader_->Close(); 696 analysis_frame_reader_->Close();
646 analysis_frame_writer_->Close(); 697 analysis_frame_writer_->Close();
647 698
648 // Close visualization files. 699 // Close visualization files.
649 if (source_frame_writer_) { 700 if (source_frame_writer_) {
650 source_frame_writer_->Close(); 701 source_frame_writer_->Close();
651 } 702 }
652 if (encoded_frame_writer_) { 703 if (encoded_frame_writer_) {
653 EXPECT_TRUE(encoded_frame_writer_->Close()); 704 EXPECT_TRUE(encoded_frame_writer_->Close());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 float sum_encoded_frame_size_total_; 855 float sum_encoded_frame_size_total_;
805 float encoding_bitrate_total_; 856 float encoding_bitrate_total_;
806 float perc_encoding_rate_mismatch_; 857 float perc_encoding_rate_mismatch_;
807 int num_frames_to_hit_target_; 858 int num_frames_to_hit_target_;
808 bool encoding_rate_within_target_; 859 bool encoding_rate_within_target_;
809 int bit_rate_; 860 int bit_rate_;
810 int frame_rate_; 861 int frame_rate_;
811 float target_size_key_frame_initial_; 862 float target_size_key_frame_initial_;
812 float target_size_key_frame_; 863 float target_size_key_frame_;
813 float sum_key_frame_size_mismatch_; 864 float sum_key_frame_size_mismatch_;
814 int num_key_frames_; 865 int num_key_frames_;
brandtr 2017/03/10 09:50:55 Trying to reduce the number of members, to make it
815 float start_bitrate_;
816 int start_frame_rate_;
817 866
818 // Codec and network settings. 867 // Codec and network settings.
819 float packet_loss_probability_;
820 int num_temporal_layers_; 868 int num_temporal_layers_;
821 }; 869 };
822 870
823 } // namespace test 871 } // namespace test
824 } // namespace webrtc 872 } // namespace webrtc
825 873
826 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_ 874 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTES T_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698