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

Unified Diff: webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h

Issue 2997283002: VideoProcessorIntegrationTest: make it runnable on a task queue. (Closed)
Patch Set: Rebase. Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
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 d84145fa4606523246a1b2f93b28830bc029c7e8..0900955c13afb6578578584c7862b4ee54102cc0 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h
@@ -38,9 +38,11 @@
#include "webrtc/modules/video_coding/include/video_coding.h"
#include "webrtc/modules/video_coding/utility/ivf_file_writer.h"
#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/event.h"
#include "webrtc/rtc_base/file.h"
#include "webrtc/rtc_base/logging.h"
#include "webrtc/rtc_base/ptr_util.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"
@@ -182,9 +184,10 @@ class VideoProcessorIntegrationTest : public testing::Test {
decoder_factory_->DestroyVideoDecoder(decoder_);
}
- void SetUpObjects(const VisualizationParams* visualization_params,
- const int initial_bitrate_kbps,
- const int initial_framerate_fps) {
+ void SetUpAndInitObjects(rtc::TaskQueue* task_queue,
+ const int initial_bitrate_kbps,
+ const int initial_framerate_fps,
+ const VisualizationParams* visualization_params) {
CreateEncoderAndDecoder();
// Create file objects for quality analysis.
@@ -223,11 +226,45 @@ class VideoProcessorIntegrationTest : public testing::Test {
packet_manipulator_.reset(new PacketManipulatorImpl(
&packet_reader_, config_.networking_config, config_.verbose));
- processor_ = rtc::MakeUnique<VideoProcessor>(
- encoder_, decoder_, analysis_frame_reader_.get(),
- analysis_frame_writer_.get(), packet_manipulator_.get(), config_,
- &stats_, encoded_frame_writer_.get(), decoded_frame_writer_.get());
- processor_->Init();
+
+ config_.codec_settings.minBitrate = 0;
+ config_.codec_settings.startBitrate = initial_bitrate_kbps;
+ config_.codec_settings.maxFramerate = initial_framerate_fps;
+
+ rtc::Event sync_event(false, false);
+ task_queue->PostTask([this, &sync_event]() {
+ processor_ = rtc::MakeUnique<VideoProcessor>(
+ encoder_, decoder_, analysis_frame_reader_.get(),
+ analysis_frame_writer_.get(), packet_manipulator_.get(), config_,
+ &stats_, encoded_frame_writer_.get(), decoded_frame_writer_.get());
+ processor_->Init();
+ sync_event.Set();
+ });
+ sync_event.Wait(rtc::Event::kForever);
+ }
+
+ void ReleaseAndCloseObjects(rtc::TaskQueue* task_queue) {
+ rtc::Event sync_event(false, false);
+ task_queue->PostTask([this, &sync_event]() {
+ processor_->Release();
+ sync_event.Set();
+ });
+ sync_event.Wait(rtc::Event::kForever);
+
+ // The VideoProcessor must be ::Release()'d before we destroy the codecs.
+ DestroyEncoderAndDecoder();
+
+ // Close the analysis files before we use them for SSIM/PSNR calculations.
+ analysis_frame_reader_->Close();
+ analysis_frame_writer_->Close();
+
+ // Close visualization files.
+ if (encoded_frame_writer_) {
+ EXPECT_TRUE(encoded_frame_writer_->Close());
+ }
+ if (decoded_frame_writer_) {
+ decoded_frame_writer_->Close();
+ }
}
// Reset quantities after each encoder update, update the target per-frame
@@ -266,11 +303,14 @@ class VideoProcessorIntegrationTest : public testing::Test {
void UpdateRateControlMetrics(int frame_number) {
RTC_CHECK_GE(frame_number, 0);
+ const int tl_idx = TemporalLayerIndexForFrame(frame_number);
+ ++num_frames_per_update_[tl_idx];
+ ++num_frames_total_;
+
FrameType frame_type = stats_.stats_[frame_number].frame_type;
float encoded_size_kbits =
stats_.stats_[frame_number].encoded_frame_length_in_bytes * 8.0f /
1000.0f;
- const int tl_idx = TemporalLayerIndexForFrame(frame_number);
// Update layer data.
// Update rate mismatch relative to per-frame bandwidth for delta frames.
@@ -308,9 +348,9 @@ class VideoProcessorIntegrationTest : public testing::Test {
// Verify expected behavior of rate control and print out data.
void PrintAndMaybeVerifyRateControlMetrics(
int rate_update_index,
- const std::vector<RateControlThresholds>* rc_thresholds) {
- int num_dropped_frames = processor_->NumberDroppedFrames();
- int num_resize_actions = processor_->NumberSpatialResizes();
+ const std::vector<RateControlThresholds>* rc_thresholds,
+ const std::vector<int>& num_dropped_frames,
+ const std::vector<int>& num_resize_actions) {
printf(
"Rate update #%d:\n"
" Target bitrate : %d\n"
@@ -322,8 +362,9 @@ class VideoProcessorIntegrationTest : public testing::Test {
" # frames to convergence: %d\n"
" # dropped frames : %d\n"
" # spatial resizes : %d\n",
- num_frames_total_, num_frames_to_hit_target_, num_dropped_frames,
- num_resize_actions);
+ num_frames_total_, num_frames_to_hit_target_,
+ num_dropped_frames[rate_update_index],
+ num_resize_actions[rate_update_index]);
const RateControlThresholds* rc_threshold = nullptr;
if (rc_thresholds) {
@@ -376,8 +417,10 @@ class VideoProcessorIntegrationTest : public testing::Test {
if (rc_threshold) {
EXPECT_LE(num_frames_to_hit_target_, rc_threshold->max_time_hit_target);
- EXPECT_LE(num_dropped_frames, rc_threshold->max_num_dropped_frames);
- EXPECT_EQ(rc_threshold->num_spatial_resizes, num_resize_actions);
+ EXPECT_LE(num_dropped_frames[rate_update_index],
+ rc_threshold->max_num_dropped_frames);
+ EXPECT_EQ(rc_threshold->num_spatial_resizes,
+ num_resize_actions[rate_update_index]);
EXPECT_EQ(rc_threshold->num_key_frames, num_key_frames_);
}
}
@@ -391,15 +434,6 @@ class VideoProcessorIntegrationTest : public testing::Test {
EXPECT_GT(ssim_result.min, quality_thresholds.min_min_ssim);
}
- void VerifyQpParser(int frame_number) {
- if (!config_.hw_codec &&
- (config_.codec_settings.codecType == kVideoCodecVP8 ||
- config_.codec_settings.codecType == kVideoCodecVP9)) {
- EXPECT_EQ(processor_->GetQpFromEncoder(frame_number),
- processor_->GetQpFromBitstream(frame_number));
- }
- }
-
static int NumberOfTemporalLayers(const VideoCodec& codec_settings) {
if (codec_settings.codecType == kVideoCodecVP8) {
return codec_settings.VP8().numberOfTemporalLayers;
@@ -443,8 +477,10 @@ class VideoProcessorIntegrationTest : public testing::Test {
return tl_idx;
}
- // Set the bit rate and frame rate per temporal layer, for up to 3 layers.
- void SetTemporalLayerRates() {
+ void UpdateRates(int rate_update_index, const RateProfile& rate_profile) {
+ bitrate_kbps_ = rate_profile.target_bit_rate[rate_update_index];
+ framerate_ = rate_profile.input_frame_rate[rate_update_index];
+
const int num_temporal_layers =
NumberOfTemporalLayers(config_.codec_settings);
RTC_DCHECK_LE(num_temporal_layers, kMaxNumTemporalLayers);
@@ -472,74 +508,132 @@ class VideoProcessorIntegrationTest : public testing::Test {
const std::vector<RateControlThresholds>* rc_thresholds,
const QualityThresholds* quality_thresholds,
const VisualizationParams* visualization_params) {
- config_.codec_settings.startBitrate = rate_profile.target_bit_rate[0];
- SetUpObjects(visualization_params, rate_profile.target_bit_rate[0],
- rate_profile.input_frame_rate[0]);
+ // The Android HW codec needs to be run on a task queue, so we simply always
+ // run the test on a task queue.
+ rtc::TaskQueue task_queue("VidProc TQ");
+ rtc::Event sync_event(false, false);
+
+ SetUpAndInitObjects(&task_queue, rate_profile.target_bit_rate[0],
+ rate_profile.input_frame_rate[0], visualization_params);
// Set initial rates.
- bitrate_kbps_ = rate_profile.target_bit_rate[0];
- framerate_ = rate_profile.input_frame_rate[0];
- SetTemporalLayerRates();
- // Set the initial target size for key frame.
- target_size_key_frame_initial_ =
- 0.5 * kInitialBufferSize * bitrate_layer_[0];
- processor_->SetRates(bitrate_kbps_, framerate_);
+ int rate_update_index = 0;
+ task_queue.PostTask([this, &rate_profile, rate_update_index] {
+ processor_->SetRates(rate_profile.target_bit_rate[rate_update_index],
+ rate_profile.input_frame_rate[rate_update_index]);
+ });
- // Process each frame, up to |num_frames|.
+ // Process all frames.
int frame_number = 0;
- int update_index = 0;
- int num_frames = rate_profile.num_frames;
- ResetRateControlMetrics(
- rate_profile.frame_index_rate_update[update_index + 1]);
-
+ const int num_frames = rate_profile.num_frames;
+ RTC_DCHECK_GE(num_frames, 1);
while (frame_number < num_frames) {
- processor_->ProcessFrame(frame_number);
- VerifyQpParser(frame_number);
- const int tl_idx = TemporalLayerIndexForFrame(frame_number);
- ++num_frames_per_update_[tl_idx];
- ++num_frames_total_;
- UpdateRateControlMetrics(frame_number);
+ // In order to not overwhelm the OpenMAX buffers in the Android
+ // MediaCodec API, we roughly pace the frames here. The downside
+ // of this is that the encode run will be done in real-time.
+ // TODO(brandtr): Investigate if this is needed on iOS.
+ if (config_.hw_codec) {
+ SleepMs(rtc::kNumMillisecsPerSec /
+ rate_profile.input_frame_rate[rate_update_index]);
+ }
+ task_queue.PostTask(
+ [this, frame_number] { processor_->ProcessFrame(frame_number); });
++frame_number;
- // If we hit another/next update, verify stats for current state and
- // update layers and codec with new rates.
if (frame_number ==
- rate_profile.frame_index_rate_update[update_index + 1]) {
- PrintAndMaybeVerifyRateControlMetrics(update_index, rc_thresholds);
-
- // Update layer rates and the codec with new rates.
- ++update_index;
- bitrate_kbps_ = rate_profile.target_bit_rate[update_index];
- framerate_ = rate_profile.input_frame_rate[update_index];
- SetTemporalLayerRates();
- ResetRateControlMetrics(
- rate_profile.frame_index_rate_update[update_index + 1]);
- processor_->SetRates(bitrate_kbps_, framerate_);
+ rate_profile.frame_index_rate_update[rate_update_index + 1]) {
+ ++rate_update_index;
+
+ task_queue.PostTask([this, &rate_profile, rate_update_index] {
+ processor_->SetRates(
+ rate_profile.target_bit_rate[rate_update_index],
+ rate_profile.input_frame_rate[rate_update_index]);
+ });
}
}
- // Verify rate control metrics for all frames since the last rate update.
- PrintAndMaybeVerifyRateControlMetrics(update_index, rc_thresholds);
- EXPECT_EQ(num_frames, frame_number);
- EXPECT_EQ(num_frames, static_cast<int>(stats_.stats_.size()));
-
- // Release encoder and decoder to make sure they have finished processing.
- processor_->Release();
- DestroyEncoderAndDecoder();
+ // TODO(brandtr): Verify the assumption that HW codecs never
+ // drop frames internally.
+ if (config_.hw_codec) {
+ // Ensure that all the frames have been encoded and decoded.
+ int last_decoded_frame_num = -1;
+ int wait_count = 0;
+ while (last_decoded_frame_num != (num_frames - 1) && wait_count++ < 10) {
+ sync_event.Reset();
+ task_queue.PostTask([this, &last_decoded_frame_num, &sync_event]() {
+ last_decoded_frame_num = processor_->LastDecodedFrameNumber();
+ sync_event.Set();
+ });
+ sync_event.Wait(rtc::Event::kForever);
+
+ SleepMs(1000);
+ }
+ EXPECT_LT(wait_count, 10) << "Lost frames in the VideoProcessor.";
+ }
- // Close the analysis files before we use them for SSIM/PSNR calculations.
- analysis_frame_reader_->Close();
- analysis_frame_writer_->Close();
+ ReleaseAndCloseObjects(&task_queue);
- // Close visualization files.
- if (encoded_frame_writer_) {
- EXPECT_TRUE(encoded_frame_writer_->Close());
+ // Verify QP parsing.
+ // TODO(brandtr): This verification is somewhat orthogonal to the rest of
+ // this test, which is focused on measuring image quality and rate control
+ // quality. We should create a whole separate test that verifies the QP
+ // parsing. This could be done by instantiating a VideoProcessor, encoding
+ // a number of frames, and then verifying the parsing.
+ if (!config_.hw_codec &&
+ (config_.codec_settings.codecType == kVideoCodecVP8 ||
+ config_.codec_settings.codecType == kVideoCodecVP9)) {
+ for (int frame_number = 0; frame_number < num_frames; ++frame_number) {
+ task_queue.PostTask([this, frame_number] {
+ EXPECT_EQ(processor_->GetQpFromEncoder(frame_number),
+ processor_->GetQpFromBitstream(frame_number));
+ });
+ }
}
- if (decoded_frame_writer_) {
- decoded_frame_writer_->Close();
+
+ // Calculate and print rate control statistics.
+ rate_update_index = 0;
+ frame_number = 0;
+ UpdateRates(rate_update_index, rate_profile);
+ ResetRateControlMetrics(
+ rate_profile.frame_index_rate_update[rate_update_index + 1]);
+ target_size_key_frame_initial_ =
+ 0.5 * kInitialBufferSize * bitrate_layer_[0];
åsapersson 2017/08/29 13:42:33 maybe move to ResetRateControlMetrics?
brandtr 2017/08/30 11:44:26 Done.
+ std::vector<int> num_dropped_frames;
+ std::vector<int> num_resize_actions;
+ sync_event.Reset();
+ task_queue.PostTask(
+ [this, &num_dropped_frames, &num_resize_actions, &sync_event]() {
+ num_dropped_frames = processor_->NumberDroppedFramesPerRateUpdate();
+ num_resize_actions = processor_->NumberSpatialResizesPerRateUpdate();
+ sync_event.Set();
+ });
+ sync_event.Wait(rtc::Event::kForever);
+ while (frame_number < num_frames) {
+ UpdateRateControlMetrics(frame_number);
+
+ ++frame_number;
+
+ if (frame_number ==
+ rate_profile.frame_index_rate_update[rate_update_index + 1]) {
+ PrintAndMaybeVerifyRateControlMetrics(rate_update_index, rc_thresholds,
+ num_dropped_frames,
+ num_resize_actions);
+ ++rate_update_index;
+ UpdateRates(rate_update_index, rate_profile);
+ ResetRateControlMetrics(
+ rate_profile.frame_index_rate_update[rate_update_index + 1]);
åsapersson 2017/08/29 13:42:33 call ResetRateControlMetrics from UpdateRates?
brandtr 2017/08/30 11:44:26 Done: merged the two functions into one.
+ }
}
+ PrintAndMaybeVerifyRateControlMetrics(rate_update_index, rc_thresholds,
+ num_dropped_frames,
+ num_resize_actions);
+ // Calculate and print other statistics.
+ EXPECT_EQ(num_frames, static_cast<int>(stats_.stats_.size()));
+ stats_.PrintSummary();
+
+ // Calculate and print image quality statistics.
// TODO(marpan): Should compute these quality metrics per SetRates update.
QualityMetricsResult psnr_result, ssim_result;
EXPECT_EQ(0, I420MetricsFromFiles(config_.input_filename.c_str(),
@@ -550,7 +644,6 @@ class VideoProcessorIntegrationTest : public testing::Test {
if (quality_thresholds) {
VerifyQuality(psnr_result, ssim_result, *quality_thresholds);
}
- stats_.PrintSummary();
printf("PSNR avg: %f, min: %f\nSSIM avg: %f, min: %f\n",
psnr_result.average, psnr_result.min, ssim_result.average,
ssim_result.min);

Powered by Google App Engine
This is Rietveld 408576698