videocodec_test_fixture.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_FIXTURE_H_
  11. #define API_TEST_VIDEOCODEC_TEST_FIXTURE_H_
  12. #include <string>
  13. #include <vector>
  14. #include "api/test/videocodec_test_stats.h"
  15. #include "api/video_codecs/video_decoder_factory.h"
  16. #include "api/video_codecs/video_encoder_factory.h"
  17. #include "modules/video_coding/include/video_codec_interface.h"
  18. namespace webrtc {
  19. namespace test {
  20. // Rates for the encoder and the frame number when to apply profile.
  21. struct RateProfile {
  22. size_t target_kbps;
  23. double input_fps;
  24. size_t frame_num;
  25. };
  26. struct RateControlThresholds {
  27. double max_avg_bitrate_mismatch_percent;
  28. double max_time_to_reach_target_bitrate_sec;
  29. // TODO(ssilkin): Use absolute threshold for framerate.
  30. double max_avg_framerate_mismatch_percent;
  31. double max_avg_buffer_level_sec;
  32. double max_max_key_frame_delay_sec;
  33. double max_max_delta_frame_delay_sec;
  34. size_t max_num_spatial_resizes;
  35. size_t max_num_key_frames;
  36. };
  37. struct QualityThresholds {
  38. double min_avg_psnr;
  39. double min_min_psnr;
  40. double min_avg_ssim;
  41. double min_min_ssim;
  42. };
  43. struct BitstreamThresholds {
  44. size_t max_max_nalu_size_bytes;
  45. };
  46. // NOTE: This class is still under development and may change without notice.
  47. class VideoCodecTestFixture {
  48. public:
  49. class EncodedFrameChecker {
  50. public:
  51. virtual ~EncodedFrameChecker() = default;
  52. virtual void CheckEncodedFrame(webrtc::VideoCodecType codec,
  53. const EncodedImage& encoded_frame) const = 0;
  54. };
  55. struct Config {
  56. Config();
  57. void SetCodecSettings(std::string codec_name,
  58. size_t num_simulcast_streams,
  59. size_t num_spatial_layers,
  60. size_t num_temporal_layers,
  61. bool denoising_on,
  62. bool frame_dropper_on,
  63. bool spatial_resize_on,
  64. size_t width,
  65. size_t height);
  66. size_t NumberOfCores() const;
  67. size_t NumberOfTemporalLayers() const;
  68. size_t NumberOfSpatialLayers() const;
  69. size_t NumberOfSimulcastStreams() const;
  70. std::string ToString() const;
  71. std::string CodecName() const;
  72. // Name of this config, to be used for accounting by the test runner.
  73. std::string test_name;
  74. // Plain name of YUV file to process without file extension.
  75. std::string filename;
  76. // File to process. This must be a video file in the YUV format.
  77. std::string filepath;
  78. // Number of frames to process.
  79. size_t num_frames = 0;
  80. // Bitstream constraints.
  81. size_t max_payload_size_bytes = 1440;
  82. // Should we decode the encoded frames?
  83. bool decode = true;
  84. // Force the encoder and decoder to use a single core for processing.
  85. bool use_single_core = false;
  86. // Should cpu usage be measured?
  87. // If set to true, the encoding will run in real-time.
  88. bool measure_cpu = false;
  89. // Simulate frames arriving in real-time by adding delays between frames.
  90. bool encode_in_real_time = false;
  91. // Codec settings to use.
  92. webrtc::VideoCodec codec_settings;
  93. // Name of the codec being tested.
  94. std::string codec_name;
  95. // H.264 specific settings.
  96. struct H264CodecSettings {
  97. H264::Profile profile = H264::kProfileConstrainedBaseline;
  98. H264PacketizationMode packetization_mode =
  99. webrtc::H264PacketizationMode::NonInterleaved;
  100. } h264_codec_settings;
  101. // Custom checker that will be called for each frame.
  102. const EncodedFrameChecker* encoded_frame_checker = nullptr;
  103. // Print out frame level stats.
  104. bool print_frame_level_stats = false;
  105. // Path to a directory where encoded or/and decoded video should be saved.
  106. std::string output_path;
  107. // Should video be saved persistently to disk for post-run visualization?
  108. struct VisualizationParams {
  109. bool save_encoded_ivf = false;
  110. bool save_decoded_y4m = false;
  111. } visualization_params;
  112. };
  113. virtual ~VideoCodecTestFixture() = default;
  114. virtual void RunTest(const std::vector<RateProfile>& rate_profiles,
  115. const std::vector<RateControlThresholds>* rc_thresholds,
  116. const std::vector<QualityThresholds>* quality_thresholds,
  117. const BitstreamThresholds* bs_thresholds) = 0;
  118. virtual VideoCodecTestStats& GetStats() = 0;
  119. };
  120. } // namespace test
  121. } // namespace webrtc
  122. #endif // API_TEST_VIDEOCODEC_TEST_FIXTURE_H_