Chromium Code Reviews| Index: webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
| diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
| index 20d71d192b865d2f4a95c679885c801a83c57b15..5b179e208447677fdcbba2bdd54dac0c480ce6cf 100644 |
| --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
| +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
| @@ -28,8 +28,10 @@ |
| #endif |
| #include "webrtc/base/checks.h" |
| +#include "webrtc/base/event.h" |
| #include "webrtc/base/file.h" |
| #include "webrtc/base/logging.h" |
| +#include "webrtc/base/task_queue.h" |
| #include "webrtc/media/engine/webrtcvideodecoderfactory.h" |
| #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
| #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| @@ -41,6 +43,7 @@ |
| #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| #include "webrtc/modules/video_coding/include/video_coding.h" |
| #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| +#include "webrtc/system_wrappers/include/sleep.h" |
| #include "webrtc/test/gtest.h" |
| #include "webrtc/test/testsupport/fileutils.h" |
| #include "webrtc/test/testsupport/frame_reader.h" |
| @@ -66,6 +69,8 @@ const int kCifWidth = 352; |
| const int kCifHeight = 288; |
| const char kFilenameForemanCif[] = "foreman_cif"; |
| +const int kNumMillisecondsPerSecond = 1000; |
| + |
| // Codec and network settings. |
| struct CodecParams { |
| VideoCodecType codec_type; |
| @@ -236,6 +241,7 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| } |
| void SetUpCodecConfig(const CodecParams& process, |
| + const RateProfile& rate_profile, |
| const VisualizationParams* visualization_params) { |
| CreateEncoderAndDecoder(process.hw_codec, process.codec_type); |
| @@ -254,12 +260,13 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| // Key frame interval and packet loss are set for each test. |
| config_.keyframe_interval = process.key_frame_interval; |
| config_.networking_config.packet_loss_probability = |
| - packet_loss_probability_; |
| + process.packet_loss_probability; |
| // Configure codec settings. |
| VideoCodingModule::Codec(process.codec_type, &codec_settings_); |
| config_.codec_settings = &codec_settings_; |
| - config_.codec_settings->startBitrate = start_bitrate_; |
| + float start_bitrate = rate_profile.target_bit_rate[0]; |
| + config_.codec_settings->startBitrate = start_bitrate; |
| config_.codec_settings->width = process.width; |
| config_.codec_settings->height = process.height; |
| @@ -309,18 +316,19 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| RTC_CHECK(analysis_frame_writer_->Init()); |
| if (visualization_params) { |
| + int start_frame_rate = rate_profile.input_frame_rate[0]; |
| // clang-format off |
| const std::string output_filename_base = |
| test::OutputPath() + process.filename + |
| "_cd-" + CodecTypeToPayloadName(process.codec_type).value_or("") + |
| "_hw-" + std::to_string(process.hw_codec) + |
| - "_fr-" + std::to_string(start_frame_rate_) + |
| - "_br-" + std::to_string(static_cast<int>(start_bitrate_)); |
| + "_fr-" + std::to_string(start_frame_rate) + |
| + "_br-" + std::to_string(static_cast<int>(start_bitrate)); |
| // clang-format on |
| if (visualization_params->save_source_y4m) { |
| source_frame_writer_.reset(new test::Y4mFrameWriterImpl( |
| output_filename_base + "_source.y4m", config_.codec_settings->width, |
| - config_.codec_settings->height, start_frame_rate_)); |
| + config_.codec_settings->height, start_frame_rate)); |
| RTC_CHECK(source_frame_writer_->Init()); |
| } |
| if (visualization_params->save_encoded_ivf) { |
| @@ -333,11 +341,13 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| decoded_frame_writer_.reset(new test::Y4mFrameWriterImpl( |
| output_filename_base + "_decoded.y4m", |
| config_.codec_settings->width, config_.codec_settings->height, |
| - start_frame_rate_)); |
| + start_frame_rate)); |
| RTC_CHECK(decoded_frame_writer_->Init()); |
| } |
| } |
| + } |
| + void SetUpHelperObjects() { |
| packet_manipulator_.reset(new test::PacketManipulatorImpl( |
| &packet_reader_, config_.networking_config, config_.verbose)); |
| processor_.reset(new test::VideoProcessorImpl( |
| @@ -556,11 +566,9 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| RateControlThresholds* rc_thresholds, |
| const VisualizationParams* visualization_params) { |
| // Codec/config settings. |
| - start_bitrate_ = rate_profile.target_bit_rate[0]; |
| - start_frame_rate_ = rate_profile.input_frame_rate[0]; |
| - packet_loss_probability_ = process.packet_loss_probability; |
| num_temporal_layers_ = process.num_temporal_layers; |
| - SetUpCodecConfig(process, visualization_params); |
| + SetUpCodecConfig(process, rate_profile, visualization_params); |
| + |
| // Update the temporal layers and the codec with the initial rates. |
| bit_rate_ = rate_profile.target_bit_rate[0]; |
| frame_rate_ = rate_profile.input_frame_rate[0]; |
| @@ -568,7 +576,6 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| // Set the initial target size for key frame. |
| target_size_key_frame_initial_ = |
| 0.5 * kInitialBufferSize * bit_rate_layer_[0]; |
| - processor_->SetRates(bit_rate_, frame_rate_); |
| // Process each frame, up to |num_frames|. |
| int frame_number = 0; |
| @@ -581,12 +588,52 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| // In batch mode, we calculate the metrics for all frames after all frames |
| // have been sent for encoding. |
| + // AndroidMediaEncoder must be called on a task queue, so during the batch |
| + // run we will call |processor_| on a task queue. |
| + std::unique_ptr<rtc::TaskQueue> task_queue( |
| + new rtc::TaskQueue("Integration test task queue.")); |
| + rtc::Event sync_event(false, false); |
| + |
| + // Set up |processor_|, thus initiating the encoder and decoder. |
| + task_queue->PostTask([this, &sync_event]() { |
| + SetUpHelperObjects(); |
| + processor_->SetRates(bit_rate_, frame_rate_); |
| + sync_event.Set(); |
| + }); |
| + sync_event.Wait(rtc::Event::kForever); |
|
brandtr
2017/03/10 09:50:55
VideoProcessor is not thread safe, so we need to s
|
| + |
| + // Post all frames (in order) to encoder. |
| + int start_frame_rate = rate_profile.input_frame_rate[0]; |
| // TODO(brandtr): Refactor "frame number accounting" so we don't have to |
| // call ProcessFrame num_frames+1 times here. |
| for (frame_number = 0; frame_number <= num_frames; ++frame_number) { |
| - EXPECT_TRUE(processor_->ProcessFrame(frame_number)); |
| + task_queue->PostTask([this, frame_number]() { |
| + EXPECT_TRUE(processor_->ProcessFrame(frame_number)); |
| + }); |
| + |
| + // HW codecs can get stressed out if frames are arriving to quickly, |
| + // so we do some rough pacing here. |
| + if (process.hw_codec) { |
| + SleepMs(kNumMillisecondsPerSecond / start_frame_rate); |
| + } |
| } |
| + // Give the task queue some time to finish processing the posted frames, |
| + // then shut down processing and synchronize with main thread. |
| + SleepMs(1 * kNumMillisecondsPerSecond); |
| + sync_event.Reset(); |
| + task_queue->PostTask([this, &sync_event]() { |
| + EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
| + EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
| + processor_->DeregisterCallbacks(); |
| + sync_event.Set(); |
| + }); |
| + sync_event.Wait(rtc::Event::kForever); |
| + |
| + // Tear down the task queue, to make sure it is safe to call |processor_| |
| + // from the main thread now. |
| + task_queue.reset(); |
| + |
| for (frame_number = 0; frame_number < num_frames; ++frame_number) { |
| ++num_frames_per_update_[TemporalLayerIndexForFrame(frame_number)]; |
| ++num_frames_total_; |
| @@ -601,6 +648,9 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| "since they may be pipelining."; |
| } |
| + SetUpHelperObjects(); |
| + processor_->SetRates(bit_rate_, frame_rate_); |
| + |
| while (frame_number < num_frames) { |
| EXPECT_TRUE(processor_->ProcessFrame(frame_number)); |
| @@ -629,6 +679,11 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| // TODO(brandtr): Refactor "frame number accounting" so we don't have to |
| // call ProcessFrame one extra time here. |
| EXPECT_TRUE(processor_->ProcessFrame(frame_number)); |
| + |
| + // Release encoder and decoder to make sure they have finished processing. |
| + EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
| + EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
| + processor_->DeregisterCallbacks(); |
| } |
| // Verify rate control metrics for all frames (if in batch mode), or for all |
| @@ -637,10 +692,6 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| EXPECT_EQ(num_frames, frame_number); |
| EXPECT_EQ(num_frames + 1, static_cast<int>(stats_.stats_.size())); |
| - // Release encoder and decoder to make sure they have finished processing. |
| - EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
| - EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
| - |
| // Close the analysis files before we use them for SSIM/PSNR calculations. |
| analysis_frame_reader_->Close(); |
| analysis_frame_writer_->Close(); |
| @@ -812,11 +863,8 @@ class VideoProcessorIntegrationTest : public testing::Test { |
| float target_size_key_frame_; |
| float sum_key_frame_size_mismatch_; |
| int num_key_frames_; |
|
brandtr
2017/03/10 09:50:55
Trying to reduce the number of members, to make it
|
| - float start_bitrate_; |
| - int start_frame_rate_; |
| // Codec and network settings. |
| - float packet_loss_probability_; |
| int num_temporal_layers_; |
| }; |