• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   bool CreateEncoderAndDecoder();
63   void DestroyEncoderAndDecoder();
64   bool 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   std::string GetCodecName(TaskQueueForTest* task_queue, bool is_encoder) const;
86   void PrintSettings(TaskQueueForTest* task_queue) const;
87 
88   // Codecs.
89   const std::unique_ptr<VideoEncoderFactory> encoder_factory_;
90   std::unique_ptr<VideoEncoder> encoder_;
91   const std::unique_ptr<VideoDecoderFactory> decoder_factory_;
92   VideoProcessor::VideoDecoderList decoders_;
93 
94   // Helper objects.
95   Config config_;
96   VideoCodecTestStatsImpl stats_;
97   std::unique_ptr<FrameReader> source_frame_reader_;
98   VideoProcessor::IvfFileWriterMap encoded_frame_writers_;
99   VideoProcessor::FrameWriterList decoded_frame_writers_;
100   std::unique_ptr<VideoProcessor> processor_;
101   std::unique_ptr<CpuProcessTime> cpu_process_time_;
102 };
103 
104 }  // namespace test
105 }  // namespace webrtc
106 
107 #endif  // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_FIXTURE_IMPL_H_
108