diff --git a/api/test/videocodec_test_stats.cc b/api/test/videocodec_test_stats.cc index b973dc2d12..0cf00da85b 100644 --- a/api/test/videocodec_test_stats.cc +++ b/api/test/videocodec_test_stats.cc @@ -91,6 +91,9 @@ std::map VideoCodecTestStats::VideoStatistics::ToMap() map["max_delta_frame_delay_sec"] = std::to_string(max_delta_frame_delay_sec); map["time_to_reach_target_bitrate_sec"] = std::to_string(time_to_reach_target_bitrate_sec); + map["avg_bitrate_mismatch_pct"] = std::to_string(avg_bitrate_mismatch_pct); + map["avg_framerate_mismatch_pct"] = + std::to_string(avg_framerate_mismatch_pct); map["avg_key_frame_size_bytes"] = std::to_string(avg_key_frame_size_bytes); map["avg_delta_frame_size_bytes"] = std::to_string(avg_delta_frame_size_bytes); diff --git a/api/test/videocodec_test_stats.h b/api/test/videocodec_test_stats.h index 02a18a71d9..3f862338ee 100644 --- a/api/test/videocodec_test_stats.h +++ b/api/test/videocodec_test_stats.h @@ -105,6 +105,8 @@ class VideoCodecTestStats { float max_key_frame_delay_sec = 0.0f; float max_delta_frame_delay_sec = 0.0f; float time_to_reach_target_bitrate_sec = 0.0f; + float avg_bitrate_mismatch_pct = 0.0f; + float avg_framerate_mismatch_pct = 0.0f; float avg_key_frame_size_bytes = 0.0f; float avg_delta_frame_size_bytes = 0.0f; diff --git a/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc b/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc index 914f639b4f..07c330833f 100644 --- a/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc @@ -202,6 +202,7 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic( const size_t target_bitrate_kbps = CalcLayerTargetBitrateKbps(first_frame_num, last_frame_num, spatial_idx, temporal_idx, aggregate_independent_layers); + const size_t target_bitrate_bps = 1000 * target_bitrate_kbps; RTC_CHECK_GT(target_bitrate_kbps, 0); // We divide by `target_bitrate_kbps`. for (size_t frame_num = first_frame_num; frame_num <= last_frame_num; @@ -313,8 +314,8 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic( video_stat.temporal_idx = temporal_idx; RTC_CHECK_GT(duration_sec, 0); - video_stat.bitrate_kbps = - static_cast(8 * video_stat.length_bytes / 1000 / duration_sec); + const float bitrate_bps = 8 * video_stat.length_bytes / duration_sec; + video_stat.bitrate_kbps = static_cast((bitrate_bps + 500) / 1000); video_stat.framerate_fps = video_stat.num_encoded_frames / duration_sec; // http://bugs.webrtc.org/10400: On Windows, we only get millisecond @@ -340,6 +341,12 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic( video_stat.max_key_frame_delay_sec = MaxDelaySec(key_frame_size_bytes); video_stat.max_delta_frame_delay_sec = MaxDelaySec(key_frame_size_bytes); + video_stat.avg_bitrate_mismatch_pct = + 100 * (bitrate_bps - target_bitrate_bps) / target_bitrate_bps; + video_stat.avg_framerate_mismatch_pct = + 100 * (video_stat.framerate_fps - input_framerate_fps) / + input_framerate_fps; + video_stat.avg_key_frame_size_bytes = key_frame_size_bytes.GetMean().value_or(0); video_stat.avg_delta_frame_size_bytes =