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 ab1223bc822a4bb677db759a30f0a548e5b6cd6d..4223805bfb4eb712b58b9918c5ded77b53f9678a 100644 |
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h |
@@ -17,6 +17,7 @@ |
#include <memory> |
#include <string> |
#include <utility> |
+#include <vector> |
#if defined(WEBRTC_ANDROID) |
#include "webrtc/modules/video_coding/codecs/test/android_test_initializer.h" |
@@ -37,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" |
@@ -65,7 +68,6 @@ const float kScaleKeyFrameSize = 0.5f; |
// Thresholds for the quality metrics. Defaults are maximally minimal. |
struct QualityThresholds { |
- QualityThresholds() {} |
QualityThresholds(double min_avg_psnr, |
double min_min_psnr, |
double min_avg_ssim, |
@@ -74,10 +76,10 @@ struct QualityThresholds { |
min_min_psnr(min_min_psnr), |
min_avg_ssim(min_avg_ssim), |
min_min_ssim(min_min_ssim) {} |
- double min_avg_psnr = std::numeric_limits<double>::min(); |
- double min_min_psnr = std::numeric_limits<double>::min(); |
- double min_avg_ssim = 0.0; |
- double min_min_ssim = 0.0; |
+ double min_avg_psnr; |
+ double min_min_psnr; |
+ double min_avg_ssim; |
+ double min_min_ssim; |
}; |
// The sequence of bit rate and frame rate changes for the encoder, the frame |
@@ -101,8 +103,8 @@ struct RateControlThresholds { |
int max_delta_frame_size_mismatch; |
int max_encoding_rate_mismatch; |
int max_time_hit_target; |
- int num_spatial_resizes; // Set to -1 to disable check. |
- int num_key_frames; // Set to -1 to disable check. |
+ int num_spatial_resizes; |
+ int num_key_frames; |
}; |
// Should video files be saved persistently to disk for post-run visualization? |
@@ -173,8 +175,8 @@ class VideoProcessorIntegrationTest : public testing::Test { |
break; |
} |
- RTC_CHECK(encoder_) << "Encoder not successfully created."; |
- RTC_CHECK(decoder_) << "Decoder not successfully created."; |
+ EXPECT_TRUE(encoder_) << "Encoder not successfully created."; |
+ EXPECT_TRUE(decoder_) << "Decoder not successfully created."; |
} |
void DestroyEncoderAndDecoder() { |
@@ -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. |
@@ -194,8 +197,8 @@ class VideoProcessorIntegrationTest : public testing::Test { |
analysis_frame_writer_.reset(new YuvFrameWriterImpl( |
config_.output_filename, config_.codec_settings.width, |
config_.codec_settings.height)); |
- RTC_CHECK(analysis_frame_reader_->Init()); |
- RTC_CHECK(analysis_frame_writer_->Init()); |
+ EXPECT_TRUE(analysis_frame_reader_->Init()); |
+ EXPECT_TRUE(analysis_frame_writer_->Init()); |
if (visualization_params) { |
const std::string codec_name = |
@@ -210,25 +213,57 @@ class VideoProcessorIntegrationTest : public testing::Test { |
// clang-format on |
if (visualization_params->save_encoded_ivf) { |
rtc::File post_encode_file = |
- rtc::File::Create(output_filename_base + "_encoded.ivf"); |
+ rtc::File::Create(output_filename_base + ".ivf"); |
encoded_frame_writer_ = |
IvfFileWriter::Wrap(std::move(post_encode_file), 0); |
} |
if (visualization_params->save_decoded_y4m) { |
decoded_frame_writer_.reset(new Y4mFrameWriterImpl( |
- output_filename_base + "_decoded.y4m", config_.codec_settings.width, |
+ output_filename_base + ".y4m", config_.codec_settings.width, |
config_.codec_settings.height, initial_framerate_fps)); |
- RTC_CHECK(decoded_frame_writer_->Init()); |
+ EXPECT_TRUE(decoded_frame_writer_->Init()); |
} |
} |
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.startBitrate = initial_bitrate_kbps; |
+ |
+ 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 |
@@ -242,11 +277,11 @@ class VideoProcessorIntegrationTest : public testing::Test { |
sum_encoded_frame_size_[i] = 0.0f; |
encoding_bitrate_[i] = 0.0f; |
// Update layer per-frame-bandwidth. |
- per_frame_bandwidth_[i] = static_cast<float>(bit_rate_layer_[i]) / |
- static_cast<float>(frame_rate_layer_[i]); |
+ per_frame_bandwidth_[i] = static_cast<float>(bitrate_layer_[i]) / |
+ static_cast<float>(framerate_layer_[i]); |
} |
// Set maximum size of key frames, following setting in the VP8 wrapper. |
- float max_key_size = kScaleKeyFrameSize * kOptimalBufferSize * frame_rate_; |
+ float max_key_size = kScaleKeyFrameSize * kOptimalBufferSize * framerate_; |
// We don't know exact target size of the key frames (except for first one), |
// but the minimum in libvpx is ~|3 * per_frame_bandwidth| and maximum is |
// set by |max_key_size_ * per_frame_bandwidth|. Take middle point/average |
@@ -267,9 +302,10 @@ class VideoProcessorIntegrationTest : public testing::Test { |
void UpdateRateControlMetrics(int frame_number) { |
RTC_CHECK_GE(frame_number, 0); |
int tl_idx = TemporalLayerIndexForFrame(frame_number); |
- FrameType frame_type = processor_->EncodedFrameType(frame_number); |
+ FrameType frame_type = stats_.stats_[frame_number].frame_type; |
float encoded_size_kbits = |
- processor_->EncodedFrameSize(frame_number) * 8.0f / 1000.0f; |
+ stats_.stats_[frame_number].encoded_frame_length_in_bytes * 8.0f / |
+ 1000.0f; |
// Update layer data. |
// Update rate mismatch relative to per-frame bandwidth for delta frames. |
@@ -289,14 +325,14 @@ class VideoProcessorIntegrationTest : public testing::Test { |
// Encoding bit rate per temporal layer: from the start of the update/run |
// to the current frame. |
encoding_bitrate_[tl_idx] = sum_encoded_frame_size_[tl_idx] * |
- frame_rate_layer_[tl_idx] / |
+ framerate_layer_[tl_idx] / |
num_frames_per_update_[tl_idx]; |
// Total encoding rate: from the start of the update/run to current frame. |
sum_encoded_frame_size_total_ += encoded_size_kbits; |
encoding_bitrate_total_ = |
- sum_encoded_frame_size_total_ * frame_rate_ / num_frames_total_; |
+ sum_encoded_frame_size_total_ * framerate_ / num_frames_total_; |
perc_encoding_rate_mismatch_ = |
- 100 * fabs(encoding_bitrate_total_ - bit_rate_) / bit_rate_; |
+ 100 * fabs(encoding_bitrate_total_ - bitrate_kbps_) / bitrate_kbps_; |
if (perc_encoding_rate_mismatch_ < kPercTargetvsActualMismatch && |
!encoding_rate_within_target_) { |
num_frames_to_hit_target_ = num_frames_total_; |
@@ -305,25 +341,34 @@ class VideoProcessorIntegrationTest : public testing::Test { |
} |
// Verify expected behavior of rate control and print out data. |
- void VerifyRateControlMetrics(int update_index, |
- const RateControlThresholds& rc_expected) { |
- int num_dropped_frames = processor_->NumberDroppedFrames(); |
- int num_resize_actions = processor_->NumberSpatialResizes(); |
+ void PrintAndMaybeVerifyRateControlMetrics( |
+ int rate_update_index, |
+ const std::vector<RateControlThresholds>* rc_thresholds, |
+ const std::vector<int>& num_dropped_frames, |
+ const std::vector<int>& num_resize_actions) { |
+ const RateControlThresholds* rc_threshold = nullptr; |
+ if (rc_thresholds) { |
+ rc_threshold = &(*rc_thresholds)[rate_update_index]; |
+ |
+ EXPECT_LE(perc_encoding_rate_mismatch_, |
+ rc_threshold->max_encoding_rate_mismatch); |
+ } |
+ |
printf( |
"Rate update #%d:\n" |
" Target bitrate : %d\n" |
" Encoded bitrate : %f\n" |
" Frame rate : %d\n", |
- update_index, bit_rate_, encoding_bitrate_total_, frame_rate_); |
+ rate_update_index, bitrate_kbps_, encoding_bitrate_total_, framerate_); |
printf( |
" # processed frames : %d\n" |
" # 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); |
- EXPECT_LE(perc_encoding_rate_mismatch_, |
- rc_expected.max_encoding_rate_mismatch); |
+ num_frames_total_, num_frames_to_hit_target_, |
+ num_dropped_frames[rate_update_index], |
+ num_resize_actions[rate_update_index]); |
+ |
if (num_key_frames_ > 0) { |
int perc_key_frame_size_mismatch = |
100 * sum_key_frame_size_mismatch_ / num_key_frames_; |
@@ -331,9 +376,12 @@ class VideoProcessorIntegrationTest : public testing::Test { |
" # key frames : %d\n" |
" Key frame rate mismatch: %d\n", |
num_key_frames_, perc_key_frame_size_mismatch); |
- EXPECT_LE(perc_key_frame_size_mismatch, |
- rc_expected.max_key_frame_size_mismatch); |
+ if (rc_threshold) { |
+ EXPECT_LE(perc_key_frame_size_mismatch, |
+ rc_threshold->max_key_frame_size_mismatch); |
+ } |
} |
+ |
const int num_temporal_layers = |
NumberOfTemporalLayers(config_.codec_settings); |
for (int i = 0; i < num_temporal_layers; i++) { |
@@ -341,8 +389,8 @@ class VideoProcessorIntegrationTest : public testing::Test { |
int perc_frame_size_mismatch = |
100 * sum_frame_size_mismatch_[i] / num_frames_per_update_[i]; |
int perc_encoding_rate_mismatch = |
- 100 * fabs(encoding_bitrate_[i] - bit_rate_layer_[i]) / |
- bit_rate_layer_[i]; |
+ 100 * fabs(encoding_bitrate_[i] - bitrate_layer_[i]) / |
+ bitrate_layer_[i]; |
printf( |
" Target layer bitrate : %f\n" |
" Layer frame rate : %f\n" |
@@ -350,45 +398,39 @@ class VideoProcessorIntegrationTest : public testing::Test { |
" Layer encoding bitrate : %f\n" |
" Layer percent frame size mismatch : %d\n" |
" Layer percent encoding rate mismatch: %d\n" |
- " # frame processed per layer : %d\n", |
- bit_rate_layer_[i], frame_rate_layer_[i], per_frame_bandwidth_[i], |
+ " # frames processed per layer : %d\n", |
+ bitrate_layer_[i], framerate_layer_[i], per_frame_bandwidth_[i], |
encoding_bitrate_[i], perc_frame_size_mismatch, |
perc_encoding_rate_mismatch, num_frames_per_update_[i]); |
- EXPECT_LE(perc_frame_size_mismatch, |
- rc_expected.max_delta_frame_size_mismatch); |
- EXPECT_LE(perc_encoding_rate_mismatch, |
- rc_expected.max_encoding_rate_mismatch); |
+ if (rc_threshold) { |
+ EXPECT_LE(perc_frame_size_mismatch, |
+ rc_threshold->max_delta_frame_size_mismatch); |
+ EXPECT_LE(perc_encoding_rate_mismatch, |
+ rc_threshold->max_encoding_rate_mismatch); |
+ } |
} |
printf("\n"); |
- EXPECT_LE(num_frames_to_hit_target_, rc_expected.max_time_hit_target); |
- EXPECT_LE(num_dropped_frames, rc_expected.max_num_dropped_frames); |
- if (rc_expected.num_spatial_resizes >= 0) { |
- EXPECT_EQ(rc_expected.num_spatial_resizes, num_resize_actions); |
- } |
- if (rc_expected.num_key_frames >= 0) { |
- EXPECT_EQ(rc_expected.num_key_frames, num_key_frames_); |
+ |
+ if (rc_threshold) { |
+ EXPECT_LE(num_frames_to_hit_target_, rc_threshold->max_time_hit_target); |
+ 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_); |
} |
} |
- void VerifyQuality(const QualityMetricsResult& psnr_result, |
- const QualityMetricsResult& ssim_result, |
- const QualityThresholds& quality_thresholds) { |
+ static void VerifyQuality(const QualityMetricsResult& psnr_result, |
+ const QualityMetricsResult& ssim_result, |
+ const QualityThresholds& quality_thresholds) { |
EXPECT_GT(psnr_result.average, quality_thresholds.min_avg_psnr); |
EXPECT_GT(psnr_result.min, quality_thresholds.min_min_psnr); |
EXPECT_GT(ssim_result.average, quality_thresholds.min_avg_ssim); |
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)); |
- } |
- } |
- |
- int NumberOfTemporalLayers(const VideoCodec& codec_settings) { |
+ static int NumberOfTemporalLayers(const VideoCodec& codec_settings) { |
if (codec_settings.codecType == kVideoCodecVP8) { |
return codec_settings.VP8().numberOfTemporalLayers; |
} else if (codec_settings.codecType == kVideoCodecVP9) { |
@@ -431,8 +473,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); |
@@ -442,125 +486,147 @@ class VideoProcessorIntegrationTest : public testing::Test { |
float bit_rate_delta_ratio = |
kVp8LayerRateAlloction[num_temporal_layers - 1][i] - |
kVp8LayerRateAlloction[num_temporal_layers - 1][i - 1]; |
- bit_rate_layer_[i] = bit_rate_ * bit_rate_delta_ratio; |
+ bitrate_layer_[i] = bitrate_kbps_ * bit_rate_delta_ratio; |
} else { |
- bit_rate_layer_[i] = bit_rate_ * bit_rate_ratio; |
+ bitrate_layer_[i] = bitrate_kbps_ * bit_rate_ratio; |
} |
- frame_rate_layer_[i] = |
- frame_rate_ / static_cast<float>(1 << (num_temporal_layers - 1)); |
+ framerate_layer_[i] = |
+ framerate_ / static_cast<float>(1 << (num_temporal_layers - 1)); |
} |
if (num_temporal_layers == 3) { |
- frame_rate_layer_[2] = frame_rate_ / 2.0f; |
+ framerate_layer_[2] = framerate_ / 2.0f; |
} |
} |
// Processes all frames in the clip and verifies the result. |
- // TODO(brandtr): Change the second last argument to be a |
- // const std::vector<RateControlThresholds>&, so we can ensure that the user |
- // does not expect us to do mid-clip rate updates when we are not able to, |
- // e.g., when we are operating in batch mode. |
- void ProcessFramesAndVerify(const QualityThresholds& quality_thresholds, |
- const RateProfile& rate_profile, |
- RateControlThresholds* rc_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]); |
+ void ProcessFramesAndMaybeVerify( |
+ const RateProfile& rate_profile, |
+ const std::vector<RateControlThresholds>* rc_thresholds, |
+ const QualityThresholds* quality_thresholds, |
+ const VisualizationParams* visualization_params) { |
+ // 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"); |
+ |
+ SetUpAndInitObjects(&task_queue, rate_profile.target_bit_rate[0], |
+ rate_profile.input_frame_rate[0], visualization_params); |
// Set initial rates. |
- bit_rate_ = rate_profile.target_bit_rate[0]; |
- frame_rate_ = rate_profile.input_frame_rate[0]; |
- SetTemporalLayerRates(); |
- // 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_); |
+ 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]); |
- |
- if (config_.batch_mode) { |
- // In batch mode, we calculate the metrics for all frames after all frames |
- // have been sent for encoding. |
- |
- // 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)); |
+ const int num_frames = rate_profile.num_frames; |
+ while (frame_number < num_frames) { |
+ // 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]); |
} |
- for (frame_number = 0; frame_number < num_frames; ++frame_number) { |
- const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
- ++num_frames_per_update_[tl_idx]; |
- ++num_frames_total_; |
- UpdateRateControlMetrics(frame_number); |
- } |
- } else { |
- // In online mode, we calculate the metrics for a given frame right after |
- // it has been sent for encoding. |
+ task_queue.PostTask( |
+ [this, frame_number] { processor_->ProcessFrame(frame_number); }); |
+ ++frame_number; |
- if (config_.hw_codec) { |
- LOG(LS_WARNING) << "HW codecs should mostly be run in batch mode, " |
- "since they may be pipelining."; |
- } |
+ if (frame_number == |
+ rate_profile.frame_index_rate_update[rate_update_index + 1]) { |
+ ++rate_update_index; |
- while (frame_number < num_frames) { |
- EXPECT_TRUE(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); |
- |
- ++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]) { |
- VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
- |
- // Update layer rates and the codec with new rates. |
- ++update_index; |
- bit_rate_ = rate_profile.target_bit_rate[update_index]; |
- frame_rate_ = rate_profile.input_frame_rate[update_index]; |
- SetTemporalLayerRates(); |
- ResetRateControlMetrics( |
- rate_profile.frame_index_rate_update[update_index + 1]); |
- processor_->SetRates(bit_rate_, frame_rate_); |
- } |
+ 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]); |
+ }); |
} |
- // TODO(brandtr): Refactor "frame number accounting" so we don't have to |
- // call ProcessFrame one extra time here. |
- EXPECT_TRUE(processor_->ProcessFrame(frame_number)); |
} |
- // Verify rate control metrics for all frames (if in batch mode), or for all |
- // frames since the last rate update (if not in batch mode). |
- VerifyRateControlMetrics(update_index, rc_thresholds[update_index]); |
- 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. |
- 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. |
+ rtc::Event sync_event(false, false); |
+ int num_frames_decoded = -1; |
+ int wait_count = 0; |
+ while (num_frames_decoded < num_frames && wait_count++ < 10) { |
+ sync_event.Reset(); |
+ task_queue.PostTask([this, &num_frames_decoded, &sync_event]() { |
+ num_frames_decoded = processor_->NumFramesDecoded(); |
+ 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. |
+ 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]; |
+ std::vector<int> num_dropped_frames; |
+ std::vector<int> num_resize_actions; |
+ rtc::Event sync_event(false, false); |
+ 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) { |
+ const int tl_idx = TemporalLayerIndexForFrame(frame_number); |
+ ++num_frames_per_update_[tl_idx]; |
+ ++num_frames_total_; |
+ 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]); |
+ } |
} |
+ 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(), |
@@ -568,8 +634,9 @@ class VideoProcessorIntegrationTest : public testing::Test { |
config_.codec_settings.width, |
config_.codec_settings.height, |
&psnr_result, &ssim_result)); |
- VerifyQuality(psnr_result, ssim_result, quality_thresholds); |
- stats_.PrintSummary(); |
+ if (quality_thresholds) { |
+ VerifyQuality(psnr_result, ssim_result, *quality_thresholds); |
+ } |
printf("PSNR avg: %f, min: %f\nSSIM avg: %f, min: %f\n", |
psnr_result.average, psnr_result.min, ssim_result.average, |
ssim_result.min); |
@@ -586,8 +653,7 @@ class VideoProcessorIntegrationTest : public testing::Test { |
bool use_single_core, |
float packet_loss_probability, |
std::string filename, |
- bool verbose_logging, |
- bool batch_mode) { |
+ bool verbose_logging) { |
config->filename = filename; |
config->input_filename = ResourcePath(filename, "yuv"); |
// Generate an output filename in a safe way. |
@@ -597,7 +663,6 @@ class VideoProcessorIntegrationTest : public testing::Test { |
config->use_single_core = use_single_core; |
config->verbose = verbose_logging; |
config->hw_codec = hw_codec; |
- config->batch_mode = batch_mode; |
} |
static void SetCodecSettings(TestConfig* config, |
@@ -648,35 +713,36 @@ class VideoProcessorIntegrationTest : public testing::Test { |
} |
static void SetRateProfile(RateProfile* rate_profile, |
- int update_index, |
- int bit_rate, |
- int frame_rate, |
+ int rate_update_index, |
+ int bit_rate_kbps, |
+ int frame_rate_fps, |
int frame_index_rate_update) { |
- rate_profile->target_bit_rate[update_index] = bit_rate; |
- rate_profile->input_frame_rate[update_index] = frame_rate; |
- rate_profile->frame_index_rate_update[update_index] = |
+ rate_profile->target_bit_rate[rate_update_index] = bit_rate_kbps; |
+ rate_profile->input_frame_rate[rate_update_index] = frame_rate_fps; |
+ rate_profile->frame_index_rate_update[rate_update_index] = |
frame_index_rate_update; |
} |
- static void SetRateControlThresholds(RateControlThresholds* rc_thresholds, |
- int update_index, |
- int max_num_dropped_frames, |
- int max_key_frame_size_mismatch, |
- int max_delta_frame_size_mismatch, |
- int max_encoding_rate_mismatch, |
- int max_time_hit_target, |
- int num_spatial_resizes, |
- int num_key_frames) { |
- rc_thresholds[update_index].max_num_dropped_frames = max_num_dropped_frames; |
- rc_thresholds[update_index].max_key_frame_size_mismatch = |
- max_key_frame_size_mismatch; |
- rc_thresholds[update_index].max_delta_frame_size_mismatch = |
- max_delta_frame_size_mismatch; |
- rc_thresholds[update_index].max_encoding_rate_mismatch = |
- max_encoding_rate_mismatch; |
- rc_thresholds[update_index].max_time_hit_target = max_time_hit_target; |
- rc_thresholds[update_index].num_spatial_resizes = num_spatial_resizes; |
- rc_thresholds[update_index].num_key_frames = num_key_frames; |
+ static void AddRateControlThresholds( |
+ int max_num_dropped_frames, |
+ int max_key_frame_size_mismatch, |
+ int max_delta_frame_size_mismatch, |
+ int max_encoding_rate_mismatch, |
+ int max_time_hit_target, |
+ int num_spatial_resizes, |
+ int num_key_frames, |
+ std::vector<RateControlThresholds>* rc_thresholds) { |
+ RTC_DCHECK(rc_thresholds); |
+ |
+ rc_thresholds->emplace_back(); |
+ RateControlThresholds* rc_threshold = &rc_thresholds->back(); |
+ rc_threshold->max_num_dropped_frames = max_num_dropped_frames; |
+ rc_threshold->max_key_frame_size_mismatch = max_key_frame_size_mismatch; |
+ rc_threshold->max_delta_frame_size_mismatch = max_delta_frame_size_mismatch; |
+ rc_threshold->max_encoding_rate_mismatch = max_encoding_rate_mismatch; |
+ rc_threshold->max_time_hit_target = max_time_hit_target; |
+ rc_threshold->num_spatial_resizes = num_spatial_resizes; |
+ rc_threshold->num_key_frames = num_key_frames; |
} |
// Config. |
@@ -704,16 +770,16 @@ class VideoProcessorIntegrationTest : public testing::Test { |
float sum_encoded_frame_size_[kMaxNumTemporalLayers]; |
float encoding_bitrate_[kMaxNumTemporalLayers]; |
float per_frame_bandwidth_[kMaxNumTemporalLayers]; |
- float bit_rate_layer_[kMaxNumTemporalLayers]; |
- float frame_rate_layer_[kMaxNumTemporalLayers]; |
+ float bitrate_layer_[kMaxNumTemporalLayers]; |
+ float framerate_layer_[kMaxNumTemporalLayers]; |
int num_frames_total_; |
float sum_encoded_frame_size_total_; |
float encoding_bitrate_total_; |
float perc_encoding_rate_mismatch_; |
int num_frames_to_hit_target_; |
bool encoding_rate_within_target_; |
- int bit_rate_; |
- int frame_rate_; |
+ int bitrate_kbps_; |
+ int framerate_; |
float target_size_key_frame_initial_; |
float target_size_key_frame_; |
float sum_key_frame_size_mismatch_; |