Create name->value text map for frame and video statistics
This is needed to facilitate dumping of stats to CSV in tests.
Bug: none
Change-Id: Ic78a4630f70a9238d26161ac89c205903dfc852f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/225300
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34435}
diff --git a/api/test/videocodec_test_stats.cc b/api/test/videocodec_test_stats.cc
index b2f88a4..b973dc2 100644
--- a/api/test/videocodec_test_stats.cc
+++ b/api/test/videocodec_test_stats.cc
@@ -24,71 +24,91 @@
std::string VideoCodecTestStats::FrameStatistics::ToString() const {
rtc::StringBuilder ss;
- ss << "frame_number " << frame_number;
- ss << " decoded_width " << decoded_width;
- ss << " decoded_height " << decoded_height;
- ss << " spatial_idx " << spatial_idx;
- ss << " temporal_idx " << temporal_idx;
- ss << " inter_layer_predicted " << inter_layer_predicted;
- ss << " non_ref_for_inter_layer_pred " << non_ref_for_inter_layer_pred;
- ss << " frame_type " << static_cast<int>(frame_type);
- ss << " length_bytes " << length_bytes;
- ss << " qp " << qp;
- ss << " psnr " << psnr;
- ss << " psnr_y " << psnr_y;
- ss << " psnr_u " << psnr_u;
- ss << " psnr_v " << psnr_v;
- ss << " ssim " << ssim;
- ss << " encode_time_us " << encode_time_us;
- ss << " decode_time_us " << decode_time_us;
- ss << " rtp_timestamp " << rtp_timestamp;
- ss << " target_bitrate_kbps " << target_bitrate_kbps;
- ss << " target_framerate_fps " << target_framerate_fps;
+ for (const auto& entry : ToMap()) {
+ if (ss.size() > 0) {
+ ss << " ";
+ }
+ ss << entry.first << " " << entry.second;
+ }
return ss.Release();
}
+std::map<std::string, std::string> VideoCodecTestStats::FrameStatistics::ToMap()
+ const {
+ std::map<std::string, std::string> map;
+ map["frame_number"] = std::to_string(frame_number);
+ map["decoded_width"] = std::to_string(decoded_width);
+ map["decoded_height"] = std::to_string(decoded_height);
+ map["spatial_idx"] = std::to_string(spatial_idx);
+ map["temporal_idx"] = std::to_string(temporal_idx);
+ map["inter_layer_predicted"] = std::to_string(inter_layer_predicted);
+ map["non_ref_for_inter_layer_pred"] =
+ std::to_string(non_ref_for_inter_layer_pred);
+ map["frame_type"] = std::to_string(static_cast<int>(frame_type));
+ map["length_bytes"] = std::to_string(length_bytes);
+ map["qp"] = std::to_string(qp);
+ map["psnr"] = std::to_string(psnr);
+ map["psnr_y"] = std::to_string(psnr_y);
+ map["psnr_u"] = std::to_string(psnr_u);
+ map["psnr_v"] = std::to_string(psnr_v);
+ map["ssim"] = std::to_string(ssim);
+ map["encode_time_us"] = std::to_string(encode_time_us);
+ map["decode_time_us"] = std::to_string(decode_time_us);
+ map["rtp_timestamp"] = std::to_string(rtp_timestamp);
+ map["target_bitrate_kbps"] = std::to_string(target_bitrate_kbps);
+ map["target_framerate_fps"] = std::to_string(target_framerate_fps);
+ return map;
+}
+
std::string VideoCodecTestStats::VideoStatistics::ToString(
std::string prefix) const {
rtc::StringBuilder ss;
- ss << prefix << "target_bitrate_kbps: " << target_bitrate_kbps;
- ss << "\n" << prefix << "input_framerate_fps: " << input_framerate_fps;
- ss << "\n" << prefix << "spatial_idx: " << spatial_idx;
- ss << "\n" << prefix << "temporal_idx: " << temporal_idx;
- ss << "\n" << prefix << "width: " << width;
- ss << "\n" << prefix << "height: " << height;
- ss << "\n" << prefix << "length_bytes: " << length_bytes;
- ss << "\n" << prefix << "bitrate_kbps: " << bitrate_kbps;
- ss << "\n" << prefix << "framerate_fps: " << framerate_fps;
- ss << "\n" << prefix << "enc_speed_fps: " << enc_speed_fps;
- ss << "\n" << prefix << "dec_speed_fps: " << dec_speed_fps;
- ss << "\n" << prefix << "avg_delay_sec: " << avg_delay_sec;
- ss << "\n"
- << prefix << "max_key_frame_delay_sec: " << max_key_frame_delay_sec;
- ss << "\n"
- << prefix << "max_delta_frame_delay_sec: " << max_delta_frame_delay_sec;
- ss << "\n"
- << prefix << "time_to_reach_target_bitrate_sec: "
- << time_to_reach_target_bitrate_sec;
- ss << "\n"
- << prefix << "avg_key_frame_size_bytes: " << avg_key_frame_size_bytes;
- ss << "\n"
- << prefix << "avg_delta_frame_size_bytes: " << avg_delta_frame_size_bytes;
- ss << "\n" << prefix << "avg_qp: " << avg_qp;
- ss << "\n" << prefix << "avg_psnr: " << avg_psnr;
- ss << "\n" << prefix << "min_psnr: " << min_psnr;
- ss << "\n" << prefix << "avg_ssim: " << avg_ssim;
- ss << "\n" << prefix << "min_ssim: " << min_ssim;
- ss << "\n" << prefix << "num_input_frames: " << num_input_frames;
- ss << "\n" << prefix << "num_encoded_frames: " << num_encoded_frames;
- ss << "\n" << prefix << "num_decoded_frames: " << num_decoded_frames;
- ss << "\n"
- << prefix
- << "num_dropped_frames: " << num_input_frames - num_encoded_frames;
- ss << "\n" << prefix << "num_key_frames: " << num_key_frames;
- ss << "\n" << prefix << "num_spatial_resizes: " << num_spatial_resizes;
- ss << "\n" << prefix << "max_nalu_size_bytes: " << max_nalu_size_bytes;
+ for (const auto& entry : ToMap()) {
+ if (ss.size() > 0) {
+ ss << "\n";
+ }
+ ss << prefix << entry.first << ": " << entry.second;
+ }
return ss.Release();
}
+std::map<std::string, std::string> VideoCodecTestStats::VideoStatistics::ToMap()
+ const {
+ std::map<std::string, std::string> map;
+ map["target_bitrate_kbps"] = std::to_string(target_bitrate_kbps);
+ map["input_framerate_fps"] = std::to_string(input_framerate_fps);
+ map["spatial_idx"] = std::to_string(spatial_idx);
+ map["temporal_idx"] = std::to_string(temporal_idx);
+ map["width"] = std::to_string(width);
+ map["height"] = std::to_string(height);
+ map["length_bytes"] = std::to_string(length_bytes);
+ map["bitrate_kbps"] = std::to_string(bitrate_kbps);
+ map["framerate_fps"] = std::to_string(framerate_fps);
+ map["enc_speed_fps"] = std::to_string(enc_speed_fps);
+ map["dec_speed_fps"] = std::to_string(dec_speed_fps);
+ map["avg_delay_sec"] = std::to_string(avg_delay_sec);
+ map["max_key_frame_delay_sec"] = std::to_string(max_key_frame_delay_sec);
+ 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_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);
+ map["avg_qp"] = std::to_string(avg_qp);
+ map["avg_psnr"] = std::to_string(avg_psnr);
+ map["min_psnr"] = std::to_string(min_psnr);
+ map["avg_ssim"] = std::to_string(avg_ssim);
+ map["min_ssim"] = std::to_string(min_ssim);
+ map["num_input_frames"] = std::to_string(num_input_frames);
+ map["num_encoded_frames"] = std::to_string(num_encoded_frames);
+ map["num_decoded_frames"] = std::to_string(num_decoded_frames);
+ map["num_dropped_frames"] =
+ std::to_string(num_input_frames - num_encoded_frames);
+ map["num_key_frames"] = std::to_string(num_key_frames);
+ map["num_spatial_resizes"] = std::to_string(num_spatial_resizes);
+ map["max_nalu_size_bytes"] = std::to_string(max_nalu_size_bytes);
+ return map;
+}
+
} // namespace test
} // namespace webrtc
diff --git a/api/test/videocodec_test_stats.h b/api/test/videocodec_test_stats.h
index df1aed7..02a18a7 100644
--- a/api/test/videocodec_test_stats.h
+++ b/api/test/videocodec_test_stats.h
@@ -14,6 +14,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <map>
#include <string>
#include <vector>
@@ -33,6 +34,9 @@
std::string ToString() const;
+ // Returns name -> value text map of frame statistics.
+ std::map<std::string, std::string> ToMap() const;
+
size_t frame_number = 0;
size_t rtp_timestamp = 0;
@@ -78,6 +82,9 @@
struct VideoStatistics {
std::string ToString(std::string prefix) const;
+ // Returns name -> value text map of video statistics.
+ std::map<std::string, std::string> ToMap() const;
+
size_t target_bitrate_kbps = 0;
float input_framerate_fps = 0.0f;