• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef API_TEST_VIDEOCODEC_TEST_STATS_H_
12 #define API_TEST_VIDEOCODEC_TEST_STATS_H_
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 #include "api/video/video_frame_type.h"
22 
23 namespace webrtc {
24 namespace test {
25 
26 // Statistics for a sequence of processed frames. This class is not thread safe.
27 class VideoCodecTestStats {
28  public:
29   // Statistics for one processed frame.
30   struct FrameStatistics {
31     FrameStatistics(size_t frame_number,
32                     size_t rtp_timestamp,
33                     size_t spatial_idx);
34 
35     std::string ToString() const;
36 
37     // Returns name -> value text map of frame statistics.
38     std::map<std::string, std::string> ToMap() const;
39 
40     size_t frame_number = 0;
41     size_t rtp_timestamp = 0;
42 
43     // Encoding.
44     int64_t encode_start_ns = 0;
45     int encode_return_code = 0;
46     bool encoding_successful = false;
47     size_t encode_time_us = 0;
48     size_t target_bitrate_kbps = 0;
49     double target_framerate_fps = 0.0;
50     size_t length_bytes = 0;
51     VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta;
52 
53     // Layering.
54     size_t spatial_idx = 0;
55     size_t temporal_idx = 0;
56     bool inter_layer_predicted = false;
57     bool non_ref_for_inter_layer_pred = true;
58 
59     // H264 specific.
60     size_t max_nalu_size_bytes = 0;
61 
62     // Decoding.
63     int64_t decode_start_ns = 0;
64     int decode_return_code = 0;
65     bool decoding_successful = false;
66     size_t decode_time_us = 0;
67     size_t decoded_width = 0;
68     size_t decoded_height = 0;
69 
70     // Quantization.
71     int qp = -1;
72 
73     // Quality.
74     bool quality_analysis_successful = false;
75     float psnr_y = 0.0f;
76     float psnr_u = 0.0f;
77     float psnr_v = 0.0f;
78     float psnr = 0.0f;  // 10 * log10(255^2 / (mse_y + mse_u + mse_v)).
79     float ssim = 0.0f;  // 0.8 * ssim_y + 0.1 * (ssim_u + ssim_v).
80   };
81 
82   struct VideoStatistics {
83     std::string ToString(std::string prefix) const;
84 
85     // Returns name -> value text map of video statistics.
86     std::map<std::string, std::string> ToMap() const;
87 
88     size_t target_bitrate_kbps = 0;
89     float input_framerate_fps = 0.0f;
90 
91     size_t spatial_idx = 0;
92     size_t temporal_idx = 0;
93 
94     size_t width = 0;
95     size_t height = 0;
96 
97     size_t length_bytes = 0;
98     size_t bitrate_kbps = 0;
99     float framerate_fps = 0;
100 
101     float enc_speed_fps = 0.0f;
102     float dec_speed_fps = 0.0f;
103 
104     float avg_encode_latency_sec = 0.0f;
105     float max_encode_latency_sec = 0.0f;
106     float avg_decode_latency_sec = 0.0f;
107     float max_decode_latency_sec = 0.0f;
108 
109     float avg_delay_sec = 0.0f;
110     float max_key_frame_delay_sec = 0.0f;
111     float max_delta_frame_delay_sec = 0.0f;
112     float time_to_reach_target_bitrate_sec = 0.0f;
113     float avg_bitrate_mismatch_pct = 0.0f;
114     float avg_framerate_mismatch_pct = 0.0f;
115 
116     float avg_key_frame_size_bytes = 0.0f;
117     float avg_delta_frame_size_bytes = 0.0f;
118     float avg_qp = 0.0f;
119 
120     float avg_psnr_y = 0.0f;
121     float avg_psnr_u = 0.0f;
122     float avg_psnr_v = 0.0f;
123     float avg_psnr = 0.0f;
124     float min_psnr = 0.0f;
125     float avg_ssim = 0.0f;
126     float min_ssim = 0.0f;
127 
128     size_t num_input_frames = 0;
129     size_t num_encoded_frames = 0;
130     size_t num_decoded_frames = 0;
131     size_t num_key_frames = 0;
132     size_t num_spatial_resizes = 0;
133     size_t max_nalu_size_bytes = 0;
134   };
135 
136   virtual ~VideoCodecTestStats() = default;
137 
138   virtual std::vector<FrameStatistics> GetFrameStatistics() = 0;
139 
140   virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
141       size_t first_frame_num,
142       size_t last_frame_num) = 0;
143 };
144 
145 }  // namespace test
146 }  // namespace webrtc
147 
148 #endif  // API_TEST_VIDEOCODEC_TEST_STATS_H_
149