videocodec_test_stats.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef API_TEST_VIDEOCODEC_TEST_STATS_H_
  11. #define API_TEST_VIDEOCODEC_TEST_STATS_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include <vector>
  16. #include "api/video/video_frame_type.h"
  17. namespace webrtc {
  18. namespace test {
  19. // Statistics for a sequence of processed frames. This class is not thread safe.
  20. class VideoCodecTestStats {
  21. public:
  22. // Statistics for one processed frame.
  23. struct FrameStatistics {
  24. FrameStatistics(size_t frame_number,
  25. size_t rtp_timestamp,
  26. size_t spatial_idx);
  27. std::string ToString() const;
  28. size_t frame_number = 0;
  29. size_t rtp_timestamp = 0;
  30. // Encoding.
  31. int64_t encode_start_ns = 0;
  32. int encode_return_code = 0;
  33. bool encoding_successful = false;
  34. size_t encode_time_us = 0;
  35. size_t target_bitrate_kbps = 0;
  36. double target_framerate_fps = 0.0;
  37. size_t length_bytes = 0;
  38. VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta;
  39. // Layering.
  40. size_t spatial_idx = 0;
  41. size_t temporal_idx = 0;
  42. bool inter_layer_predicted = false;
  43. bool non_ref_for_inter_layer_pred = true;
  44. // H264 specific.
  45. size_t max_nalu_size_bytes = 0;
  46. // Decoding.
  47. int64_t decode_start_ns = 0;
  48. int decode_return_code = 0;
  49. bool decoding_successful = false;
  50. size_t decode_time_us = 0;
  51. size_t decoded_width = 0;
  52. size_t decoded_height = 0;
  53. // Quantization.
  54. int qp = -1;
  55. // Quality.
  56. float psnr_y = 0.0f;
  57. float psnr_u = 0.0f;
  58. float psnr_v = 0.0f;
  59. float psnr = 0.0f; // 10 * log10(255^2 / (mse_y + mse_u + mse_v)).
  60. float ssim = 0.0f; // 0.8 * ssim_y + 0.1 * (ssim_u + ssim_v).
  61. };
  62. struct VideoStatistics {
  63. std::string ToString(std::string prefix) const;
  64. size_t target_bitrate_kbps = 0;
  65. float input_framerate_fps = 0.0f;
  66. size_t spatial_idx = 0;
  67. size_t temporal_idx = 0;
  68. size_t width = 0;
  69. size_t height = 0;
  70. size_t length_bytes = 0;
  71. size_t bitrate_kbps = 0;
  72. float framerate_fps = 0;
  73. float enc_speed_fps = 0.0f;
  74. float dec_speed_fps = 0.0f;
  75. float avg_delay_sec = 0.0f;
  76. float max_key_frame_delay_sec = 0.0f;
  77. float max_delta_frame_delay_sec = 0.0f;
  78. float time_to_reach_target_bitrate_sec = 0.0f;
  79. float avg_key_frame_size_bytes = 0.0f;
  80. float avg_delta_frame_size_bytes = 0.0f;
  81. float avg_qp = 0.0f;
  82. float avg_psnr_y = 0.0f;
  83. float avg_psnr_u = 0.0f;
  84. float avg_psnr_v = 0.0f;
  85. float avg_psnr = 0.0f;
  86. float min_psnr = 0.0f;
  87. float avg_ssim = 0.0f;
  88. float min_ssim = 0.0f;
  89. size_t num_input_frames = 0;
  90. size_t num_encoded_frames = 0;
  91. size_t num_decoded_frames = 0;
  92. size_t num_key_frames = 0;
  93. size_t num_spatial_resizes = 0;
  94. size_t max_nalu_size_bytes = 0;
  95. };
  96. virtual ~VideoCodecTestStats() = default;
  97. virtual std::vector<FrameStatistics> GetFrameStatistics() = 0;
  98. virtual std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
  99. size_t first_frame_num,
  100. size_t last_frame_num) = 0;
  101. };
  102. } // namespace test
  103. } // namespace webrtc
  104. #endif // API_TEST_VIDEOCODEC_TEST_STATS_H_