xref: /aosp_15_r20/external/webrtc/api/test/videocodec_test_stats.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "api/test/videocodec_test_stats.h"
12 
13 #include "rtc_base/strings/string_builder.h"
14 
15 namespace webrtc {
16 namespace test {
17 
FrameStatistics(size_t frame_number,size_t rtp_timestamp,size_t spatial_idx)18 VideoCodecTestStats::FrameStatistics::FrameStatistics(size_t frame_number,
19                                                       size_t rtp_timestamp,
20                                                       size_t spatial_idx)
21     : frame_number(frame_number),
22       rtp_timestamp(rtp_timestamp),
23       spatial_idx(spatial_idx) {}
24 
ToString() const25 std::string VideoCodecTestStats::FrameStatistics::ToString() const {
26   rtc::StringBuilder ss;
27   for (const auto& entry : ToMap()) {
28     if (ss.size() > 0) {
29       ss << " ";
30     }
31     ss << entry.first << " " << entry.second;
32   }
33   return ss.Release();
34 }
35 
ToMap() const36 std::map<std::string, std::string> VideoCodecTestStats::FrameStatistics::ToMap()
37     const {
38   std::map<std::string, std::string> map;
39   map["frame_number"] = std::to_string(frame_number);
40   map["decoded_width"] = std::to_string(decoded_width);
41   map["decoded_height"] = std::to_string(decoded_height);
42   map["spatial_idx"] = std::to_string(spatial_idx);
43   map["temporal_idx"] = std::to_string(temporal_idx);
44   map["inter_layer_predicted"] = std::to_string(inter_layer_predicted);
45   map["non_ref_for_inter_layer_pred"] =
46       std::to_string(non_ref_for_inter_layer_pred);
47   map["frame_type"] = std::to_string(static_cast<int>(frame_type));
48   map["length_bytes"] = std::to_string(length_bytes);
49   map["qp"] = std::to_string(qp);
50   map["psnr"] = std::to_string(psnr);
51   map["psnr_y"] = std::to_string(psnr_y);
52   map["psnr_u"] = std::to_string(psnr_u);
53   map["psnr_v"] = std::to_string(psnr_v);
54   map["ssim"] = std::to_string(ssim);
55   map["encode_time_us"] = std::to_string(encode_time_us);
56   map["decode_time_us"] = std::to_string(decode_time_us);
57   map["rtp_timestamp"] = std::to_string(rtp_timestamp);
58   map["target_bitrate_kbps"] = std::to_string(target_bitrate_kbps);
59   map["target_framerate_fps"] = std::to_string(target_framerate_fps);
60   return map;
61 }
62 
ToString(std::string prefix) const63 std::string VideoCodecTestStats::VideoStatistics::ToString(
64     std::string prefix) const {
65   rtc::StringBuilder ss;
66   for (const auto& entry : ToMap()) {
67     if (ss.size() > 0) {
68       ss << "\n";
69     }
70     ss << prefix << entry.first << ": " << entry.second;
71   }
72   return ss.Release();
73 }
74 
ToMap() const75 std::map<std::string, std::string> VideoCodecTestStats::VideoStatistics::ToMap()
76     const {
77   std::map<std::string, std::string> map;
78   map["target_bitrate_kbps"] = std::to_string(target_bitrate_kbps);
79   map["input_framerate_fps"] = std::to_string(input_framerate_fps);
80   map["spatial_idx"] = std::to_string(spatial_idx);
81   map["temporal_idx"] = std::to_string(temporal_idx);
82   map["width"] = std::to_string(width);
83   map["height"] = std::to_string(height);
84   map["length_bytes"] = std::to_string(length_bytes);
85   map["bitrate_kbps"] = std::to_string(bitrate_kbps);
86   map["framerate_fps"] = std::to_string(framerate_fps);
87   map["enc_speed_fps"] = std::to_string(enc_speed_fps);
88   map["dec_speed_fps"] = std::to_string(dec_speed_fps);
89   map["avg_encode_latency_sec"] = std::to_string(avg_encode_latency_sec);
90   map["max_encode_latency_sec"] = std::to_string(max_encode_latency_sec);
91   map["avg_decode_latency_sec"] = std::to_string(avg_decode_latency_sec);
92   map["max_decode_latency_sec"] = std::to_string(max_decode_latency_sec);
93   map["avg_delay_sec"] = std::to_string(avg_delay_sec);
94   map["max_key_frame_delay_sec"] = std::to_string(max_key_frame_delay_sec);
95   map["max_delta_frame_delay_sec"] = std::to_string(max_delta_frame_delay_sec);
96   map["time_to_reach_target_bitrate_sec"] =
97       std::to_string(time_to_reach_target_bitrate_sec);
98   map["avg_bitrate_mismatch_pct"] = std::to_string(avg_bitrate_mismatch_pct);
99   map["avg_framerate_mismatch_pct"] =
100       std::to_string(avg_framerate_mismatch_pct);
101   map["avg_key_frame_size_bytes"] = std::to_string(avg_key_frame_size_bytes);
102   map["avg_delta_frame_size_bytes"] =
103       std::to_string(avg_delta_frame_size_bytes);
104   map["avg_qp"] = std::to_string(avg_qp);
105   map["avg_psnr"] = std::to_string(avg_psnr);
106   map["min_psnr"] = std::to_string(min_psnr);
107   map["avg_ssim"] = std::to_string(avg_ssim);
108   map["min_ssim"] = std::to_string(min_ssim);
109   map["num_input_frames"] = std::to_string(num_input_frames);
110   map["num_encoded_frames"] = std::to_string(num_encoded_frames);
111   map["num_decoded_frames"] = std::to_string(num_decoded_frames);
112   map["num_dropped_frames"] =
113       std::to_string(num_input_frames - num_encoded_frames);
114   map["num_key_frames"] = std::to_string(num_key_frames);
115   map["num_spatial_resizes"] = std::to_string(num_spatial_resizes);
116   map["max_nalu_size_bytes"] = std::to_string(max_nalu_size_bytes);
117   return map;
118 }
119 
120 }  // namespace test
121 }  // namespace webrtc
122