1 /* 2 * Copyright (c) 2017 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 MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_FIXTURE_IMPL_H_ 12 #define MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_FIXTURE_IMPL_H_ 13 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "api/test/videocodec_test_fixture.h" 19 #include "api/video_codecs/video_decoder_factory.h" 20 #include "api/video_codecs/video_encoder_factory.h" 21 #include "common_video/h264/h264_common.h" 22 #include "modules/video_coding/codecs/test/videocodec_test_stats_impl.h" 23 #include "modules/video_coding/codecs/test/videoprocessor.h" 24 #include "modules/video_coding/utility/ivf_file_writer.h" 25 #include "rtc_base/task_queue_for_test.h" 26 #include "test/testsupport/frame_reader.h" 27 #include "test/testsupport/frame_writer.h" 28 29 namespace webrtc { 30 namespace test { 31 32 // Integration test for video processor. It does rate control and frame quality 33 // analysis using frame statistics collected by video processor and logs the 34 // results. If thresholds are specified it checks that corresponding metrics 35 // are in desirable range. 36 class VideoCodecTestFixtureImpl : public VideoCodecTestFixture { 37 // Verifies that all H.264 keyframes contain SPS/PPS/IDR NALUs. 38 public: 39 class H264KeyframeChecker : public EncodedFrameChecker { 40 public: 41 void CheckEncodedFrame(webrtc::VideoCodecType codec, 42 const EncodedImage& encoded_frame) const override; 43 }; 44 45 explicit VideoCodecTestFixtureImpl(Config config); 46 VideoCodecTestFixtureImpl( 47 Config config, 48 std::unique_ptr<VideoDecoderFactory> decoder_factory, 49 std::unique_ptr<VideoEncoderFactory> encoder_factory); 50 ~VideoCodecTestFixtureImpl() override; 51 52 void RunTest(const std::vector<RateProfile>& rate_profiles, 53 const std::vector<RateControlThresholds>* rc_thresholds, 54 const std::vector<QualityThresholds>* quality_thresholds, 55 const BitstreamThresholds* bs_thresholds) override; 56 57 VideoCodecTestStats& GetStats() override; 58 59 private: 60 class CpuProcessTime; 61 62 void CreateEncoderAndDecoder(); 63 void DestroyEncoderAndDecoder(); 64 void SetUpAndInitObjects(TaskQueueForTest* task_queue, 65 size_t initial_bitrate_kbps, 66 double initial_framerate_fps); 67 void ReleaseAndCloseObjects(TaskQueueForTest* task_queue); 68 69 void ProcessAllFrames(TaskQueueForTest* task_queue, 70 const std::vector<RateProfile>& rate_profiles); 71 void AnalyzeAllFrames( 72 const std::vector<RateProfile>& rate_profiles, 73 const std::vector<RateControlThresholds>* rc_thresholds, 74 const std::vector<QualityThresholds>* quality_thresholds, 75 const BitstreamThresholds* bs_thresholds); 76 77 void VerifyVideoStatistic( 78 const VideoCodecTestStats::VideoStatistics& video_stat, 79 const RateControlThresholds* rc_thresholds, 80 const QualityThresholds* quality_thresholds, 81 const BitstreamThresholds* bs_thresholds, 82 size_t target_bitrate_kbps, 83 double input_framerate_fps); 84 85 void PrintSettings(TaskQueueForTest* task_queue) const; 86 87 // Codecs. 88 const std::unique_ptr<VideoEncoderFactory> encoder_factory_; 89 std::unique_ptr<VideoEncoder> encoder_; 90 const std::unique_ptr<VideoDecoderFactory> decoder_factory_; 91 VideoProcessor::VideoDecoderList decoders_; 92 93 // Helper objects. 94 Config config_; 95 VideoCodecTestStatsImpl stats_; 96 std::unique_ptr<FrameReader> source_frame_reader_; 97 VideoProcessor::IvfFileWriterMap encoded_frame_writers_; 98 VideoProcessor::FrameWriterList decoded_frame_writers_; 99 std::unique_ptr<VideoProcessor> processor_; 100 std::unique_ptr<CpuProcessTime> cpu_process_time_; 101 }; 102 103 } // namespace test 104 } // namespace webrtc 105 106 #endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_FIXTURE_IMPL_H_ 107