Refactor rate profile update.

RateProfile::frame_num specifies frame at which this rate profile
should be applied.

Bug: none
Change-Id: I003ee43f44299a49d83f547558284817bfaeacc0
Reviewed-on: https://webrtc-review.googlesource.com/c/115242
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26080}
This commit is contained in:
Sergey Silkin
2018-12-20 14:41:23 +01:00
committed by Commit Bot
parent 05cb485999
commit b6cdfdc165
6 changed files with 53 additions and 66 deletions

View File

@ -22,11 +22,11 @@
namespace webrtc { namespace webrtc {
namespace test { namespace test {
// Rates for the encoder and the frame number when to change profile. // Rates for the encoder and the frame number when to apply profile.
struct RateProfile { struct RateProfile {
size_t target_kbps; size_t target_kbps;
size_t input_fps; size_t input_fps;
size_t frame_index_rate_update; size_t frame_num;
}; };
struct RateControlThresholds { struct RateControlThresholds {

View File

@ -422,27 +422,22 @@ void VideoCodecTestFixtureImpl::RunTest(
void VideoCodecTestFixtureImpl::ProcessAllFrames( void VideoCodecTestFixtureImpl::ProcessAllFrames(
rtc::TaskQueue* task_queue, rtc::TaskQueue* task_queue,
const std::vector<RateProfile>& rate_profiles) { const std::vector<RateProfile>& rate_profiles) {
// Process all frames.
size_t rate_update_index = 0;
// Set initial rates. // Set initial rates.
task_queue->PostTask([this, &rate_profiles, rate_update_index] { auto rate_profile = rate_profiles.begin();
processor_->SetRates(rate_profiles[rate_update_index].target_kbps, task_queue->PostTask([this, rate_profile] {
rate_profiles[rate_update_index].input_fps); processor_->SetRates(rate_profile->target_kbps, rate_profile->input_fps);
}); });
cpu_process_time_->Start(); cpu_process_time_->Start();
for (size_t frame_number = 0; frame_number < config_.num_frames; for (size_t frame_num = 0; frame_num < config_.num_frames; ++frame_num) {
++frame_number) { auto next_rate_profile = std::next(rate_profile);
if (frame_number == if (next_rate_profile != rate_profiles.end() &&
rate_profiles[rate_update_index].frame_index_rate_update) { frame_num == next_rate_profile->frame_num) {
++rate_update_index; rate_profile = next_rate_profile;
RTC_DCHECK_GT(rate_profiles.size(), rate_update_index); task_queue->PostTask([this, rate_profile] {
processor_->SetRates(rate_profile->target_kbps,
task_queue->PostTask([this, &rate_profiles, rate_update_index] { rate_profile->input_fps);
processor_->SetRates(rate_profiles[rate_update_index].target_kbps,
rate_profiles[rate_update_index].input_fps);
}); });
} }
@ -451,7 +446,7 @@ void VideoCodecTestFixtureImpl::ProcessAllFrames(
if (RunEncodeInRealTime(config_)) { if (RunEncodeInRealTime(config_)) {
// Roughly pace the frames. // Roughly pace the frames.
const size_t frame_duration_ms = const size_t frame_duration_ms =
rtc::kNumMillisecsPerSec / rate_profiles[rate_update_index].input_fps; rtc::kNumMillisecsPerSec / rate_profile->input_fps;
SleepMs(static_cast<int>(frame_duration_ms)); SleepMs(static_cast<int>(frame_duration_ms));
} }
} }
@ -472,14 +467,13 @@ void VideoCodecTestFixtureImpl::AnalyzeAllFrames(
const std::vector<RateControlThresholds>* rc_thresholds, const std::vector<RateControlThresholds>* rc_thresholds,
const std::vector<QualityThresholds>* quality_thresholds, const std::vector<QualityThresholds>* quality_thresholds,
const BitstreamThresholds* bs_thresholds) { const BitstreamThresholds* bs_thresholds) {
for (size_t rate_update_idx = 0; rate_update_idx < rate_profiles.size(); for (size_t rate_profile_idx = 0; rate_profile_idx < rate_profiles.size();
++rate_update_idx) { ++rate_profile_idx) {
const size_t first_frame_num = const size_t first_frame_num = rate_profiles[rate_profile_idx].frame_num;
(rate_update_idx == 0)
? 0
: rate_profiles[rate_update_idx - 1].frame_index_rate_update;
const size_t last_frame_num = const size_t last_frame_num =
rate_profiles[rate_update_idx].frame_index_rate_update - 1; rate_profile_idx + 1 < rate_profiles.size()
? rate_profiles[rate_profile_idx + 1].frame_num - 1
: config_.num_frames - 1;
RTC_CHECK(last_frame_num >= first_frame_num); RTC_CHECK(last_frame_num >= first_frame_num);
std::vector<VideoStatistics> layer_stats = std::vector<VideoStatistics> layer_stats =
@ -495,14 +489,14 @@ void VideoCodecTestFixtureImpl::AnalyzeAllFrames(
printf("%s\n", send_stat.ToString("send_").c_str()); printf("%s\n", send_stat.ToString("send_").c_str());
const RateControlThresholds* rc_threshold = const RateControlThresholds* rc_threshold =
rc_thresholds ? &(*rc_thresholds)[rate_update_idx] : nullptr; rc_thresholds ? &(*rc_thresholds)[rate_profile_idx] : nullptr;
const QualityThresholds* quality_threshold = const QualityThresholds* quality_threshold =
quality_thresholds ? &(*quality_thresholds)[rate_update_idx] : nullptr; quality_thresholds ? &(*quality_thresholds)[rate_profile_idx] : nullptr;
VerifyVideoStatistic(send_stat, rc_threshold, quality_threshold, VerifyVideoStatistic(send_stat, rc_threshold, quality_threshold,
bs_thresholds, bs_thresholds,
rate_profiles[rate_update_idx].target_kbps, rate_profiles[rate_profile_idx].target_kbps,
rate_profiles[rate_update_idx].input_fps); rate_profiles[rate_profile_idx].input_fps);
} }
if (config_.print_frame_level_stats) { if (config_.print_frame_level_stats) {

View File

@ -100,7 +100,7 @@ TEST(VideoCodecTestLibvpx, HighBitrateVP9) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{500, 30, kNumFramesShort}}; std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 1, 0.3, 0.1, 0, 1}}; {5, 1, 0, 1, 0.3, 0.1, 0, 1}};
@ -119,9 +119,9 @@ TEST(VideoCodecTestLibvpx, ChangeBitrateVP9) {
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {
{200, 30, 100}, // target_kbps, input_fps, frame_index_rate_update {200, 30, 0}, // target_kbps, input_fps, frame_num
{700, 30, 200}, {700, 30, 100},
{500, 30, kNumFramesLong}}; {500, 30, 200}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 2, 0, 1, 0.5, 0.1, 0, 1}, {5, 2, 0, 1, 0.5, 0.1, 0, 1},
@ -143,9 +143,9 @@ TEST(VideoCodecTestLibvpx, ChangeFramerateVP9) {
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {
{100, 24, 100}, // target_kbps, input_fps, frame_index_rate_update {100, 24, 0}, // target_kbps, input_fps, frame_num
{100, 15, 200}, {100, 15, 100},
{100, 10, kNumFramesLong}}; {100, 10, 200}};
// Framerate mismatch should be lower for lower framerate. // Framerate mismatch should be lower for lower framerate.
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
@ -169,7 +169,7 @@ TEST(VideoCodecTestLibvpx, DenoiserOnVP9) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{500, 30, kNumFramesShort}}; std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 1, 0.3, 0.1, 0, 1}}; {5, 1, 0, 1, 0.3, 0.1, 0, 1}};
@ -187,7 +187,7 @@ TEST(VideoCodecTestLibvpx, VeryLowBitrateVP9) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{50, 30, kNumFramesLong}}; std::vector<RateProfile> rate_profiles = {{50, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{15, 3, 75, 1, 0.5, 0.4, 1, 1}}; {15, 3, 75, 1, 0.5, 0.4, 1, 1}};
@ -211,7 +211,7 @@ TEST(VideoCodecTestLibvpx, HighBitrateVP8) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{500, 30, kNumFramesShort}}; std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 1, 0.2, 0.1, 0, 1}}; {5, 1, 0, 1, 0.2, 0.1, 0, 1}};
@ -248,9 +248,9 @@ TEST(VideoCodecTestLibvpx, MAYBE_ChangeBitrateVP8) {
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {
{200, 30, 100}, // target_kbps, input_fps, frame_index_rate_update {200, 30, 0}, // target_kbps, input_fps, frame_num
{800, 30, 200}, {800, 30, 100},
{500, 30, kNumFramesLong}}; {500, 30, 200}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 1, 0.2, 0.1, 0, 1}, {5, 1, 0, 1, 0.2, 0.1, 0, 1},
@ -282,9 +282,9 @@ TEST(VideoCodecTestLibvpx, MAYBE_ChangeFramerateVP8) {
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {
{80, 24, 100}, // target_kbps, input_fps, frame_index_rate_update {80, 24, 0}, // target_kbps, input_fps, frame_index_rate_update
{80, 15, 200}, {80, 15, 100},
{80, 10, kNumFramesLong}}; {80, 10, 200}};
#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64)
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
@ -321,8 +321,7 @@ TEST(VideoCodecTestLibvpx, MAYBE_TemporalLayersVP8) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{200, 30, 150}, std::vector<RateProfile> rate_profiles = {{200, 30, 0}, {400, 30, 150}};
{400, 30, kNumFramesLong}};
#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64)
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
@ -358,7 +357,7 @@ TEST(VideoCodecTestLibvpx, MAYBE_MultiresVP8) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{1500, 30, config.num_frames}}; std::vector<RateProfile> rate_profiles = {{1500, 30, 0}};
#if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64)
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{3.5, 1.04, 6, 0.18, 0.14, 0.07, 0, 1}}; {3.5, 1.04, 6, 0.18, 0.14, 0.07, 0, 1}};
@ -399,7 +398,7 @@ TEST(VideoCodecTestLibvpx, MAYBE_SimulcastVP8) {
CreateVideoCodecTestFixture(config, std::move(internal_decoder_factory), CreateVideoCodecTestFixture(config, std::move(internal_decoder_factory),
std::move(adapted_encoder_factory)); std::move(adapted_encoder_factory));
std::vector<RateProfile> rate_profiles = {{1500, 30, config.num_frames}}; std::vector<RateProfile> rate_profiles = {{1500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{20, 5, 90, 1, 0.5, 0.3, 0, 1}}; {20, 5, 90, 1, 0.5, 0.3, 0, 1}};
@ -424,7 +423,7 @@ TEST(VideoCodecTestLibvpx, MAYBE_SvcVP9) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{1500, 30, config.num_frames}}; std::vector<RateProfile> rate_profiles = {{1500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 5, 1, 0.3, 0.1, 0, 1}}; {5, 1, 5, 1, 0.3, 0.1, 0, 1}};
@ -447,8 +446,7 @@ TEST(VideoCodecTestLibvpx, DISABLED_MultiresVP8RdPerf) {
std::map<size_t, std::vector<VideoStatistics>> rd_stats; std::map<size_t, std::vector<VideoStatistics>> rd_stats;
for (size_t bitrate_kbps : kBitrateRdPerfKbps) { for (size_t bitrate_kbps : kBitrateRdPerfKbps) {
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{bitrate_kbps, 30, 0}};
{bitrate_kbps, 30, config.num_frames}};
fixture->RunTest(rate_profiles, nullptr, nullptr, nullptr); fixture->RunTest(rate_profiles, nullptr, nullptr, nullptr);
@ -474,8 +472,7 @@ TEST(VideoCodecTestLibvpx, DISABLED_SvcVP9RdPerf) {
std::map<size_t, std::vector<VideoStatistics>> rd_stats; std::map<size_t, std::vector<VideoStatistics>> rd_stats;
for (size_t bitrate_kbps : kBitrateRdPerfKbps) { for (size_t bitrate_kbps : kBitrateRdPerfKbps) {
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{bitrate_kbps, 30, 0}};
{bitrate_kbps, 30, config.num_frames}};
fixture->RunTest(rate_profiles, nullptr, nullptr, nullptr); fixture->RunTest(rate_profiles, nullptr, nullptr, nullptr);

View File

@ -54,8 +54,7 @@ TEST(VideoCodecTestMediaCodec, ForemanCif500kbpsVp8) {
352, 288); 352, 288);
auto fixture = CreateTestFixtureWithConfig(config); auto fixture = CreateTestFixtureWithConfig(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
{500, kForemanFramerateFps, kForemanNumFrames}};
// The thresholds below may have to be tweaked to let even poor MediaCodec // The thresholds below may have to be tweaked to let even poor MediaCodec
// implementations pass. If this test fails on the bots, disable it and // implementations pass. If this test fails on the bots, disable it and
@ -77,8 +76,7 @@ TEST(VideoCodecTestMediaCodec, ForemanCif500kbpsH264CBP) {
352, 288); 352, 288);
auto fixture = CreateTestFixtureWithConfig(config); auto fixture = CreateTestFixtureWithConfig(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
{500, kForemanFramerateFps, kForemanNumFrames}};
// The thresholds below may have to be tweaked to let even poor MediaCodec // The thresholds below may have to be tweaked to let even poor MediaCodec
// implementations pass. If this test fails on the bots, disable it and // implementations pass. If this test fails on the bots, disable it and
@ -104,8 +102,7 @@ TEST(VideoCodecTestMediaCodec, DISABLED_ForemanCif500kbpsH264CHP) {
352, 288); 352, 288);
auto fixture = CreateTestFixtureWithConfig(config); auto fixture = CreateTestFixtureWithConfig(config);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
{500, kForemanFramerateFps, kForemanNumFrames}};
// The thresholds below may have to be tweaked to let even poor MediaCodec // The thresholds below may have to be tweaked to let even poor MediaCodec
// implementations pass. If this test fails on the bots, disable it and // implementations pass. If this test fails on the bots, disable it and
@ -126,7 +123,7 @@ TEST(VideoCodecTestMediaCodec, ForemanMixedRes100kbpsVp8H264) {
const std::vector<std::tuple<int, int>> resolutions = { const std::vector<std::tuple<int, int>> resolutions = {
{128, 96}, {160, 120}, {176, 144}, {240, 136}, {320, 240}, {480, 272}}; {128, 96}, {160, 120}, {176, 144}, {240, 136}, {320, 240}, {480, 272}};
const std::vector<RateProfile> rate_profiles = { const std::vector<RateProfile> rate_profiles = {
{100, kForemanFramerateFps, kNumFrames}}; {100, kForemanFramerateFps, 0}};
const std::vector<QualityThresholds> quality_thresholds = { const std::vector<QualityThresholds> quality_thresholds = {
{29, 26, 0.8, 0.75}}; {29, 26, 0.8, 0.75}};

View File

@ -45,7 +45,7 @@ TEST(VideoCodecTestOpenH264, ConstantHighBitrate) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{500, 30, kNumFrames}}; std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 0.1, 0.2, 0.1, 0, 1}}; {5, 1, 0, 0.1, 0.2, 0.1, 0, 1}};
@ -69,7 +69,7 @@ TEST(VideoCodecTestOpenH264, SingleNalUnit) {
config.encoded_frame_checker = frame_checker.get(); config.encoded_frame_checker = frame_checker.get();
auto fixture = CreateVideoCodecTestFixture(config); auto fixture = CreateVideoCodecTestFixture(config);
std::vector<RateProfile> rate_profiles = {{500, 30, kNumFrames}}; std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
std::vector<RateControlThresholds> rc_thresholds = { std::vector<RateControlThresholds> rc_thresholds = {
{5, 1, 0, 0.1, 0.2, 0.1, 0, 1}}; {5, 1, 0, 0.1, 0.2, 0.1, 0, 1}};

View File

@ -67,8 +67,7 @@ class VideoCodecTestParameterized
kDenoisingOn, kFrameDropperOn, kSpatialResizeOn, kDenoisingOn, kFrameDropperOn, kSpatialResizeOn,
width, height); width, height);
std::vector<RateProfile> rate_profiles = { std::vector<RateProfile> rate_profiles = {{bitrate_, framerate, 0}};
{bitrate_, framerate, kNumFrames}};
fixture_ = CreateVideoCodecTestFixture(config); fixture_ = CreateVideoCodecTestFixture(config);
fixture_->RunTest(rate_profiles, nullptr, nullptr, nullptr); fixture_->RunTest(rate_profiles, nullptr, nullptr, nullptr);