videocodec_test_fixture.h 5.0 KB

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