tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

videocodec_test_stats.h (4488B)


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