xref: /aosp_15_r20/external/webrtc/modules/video_coding/utility/simulcast_test_fixture_impl.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
11 #ifndef MODULES_VIDEO_CODING_UTILITY_SIMULCAST_TEST_FIXTURE_IMPL_H_
12 #define MODULES_VIDEO_CODING_UTILITY_SIMULCAST_TEST_FIXTURE_IMPL_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/test/mock_video_decoder.h"
18 #include "api/test/mock_video_encoder.h"
19 #include "api/test/simulcast_test_fixture.h"
20 #include "api/video/i420_buffer.h"
21 #include "api/video/video_frame.h"
22 #include "api/video_codecs/video_decoder_factory.h"
23 #include "api/video_codecs/video_encoder_factory.h"
24 #include "modules/video_coding/utility/simulcast_rate_allocator.h"
25 
26 namespace webrtc {
27 namespace test {
28 
29 class SimulcastTestFixtureImpl final : public SimulcastTestFixture {
30  public:
31   SimulcastTestFixtureImpl(std::unique_ptr<VideoEncoderFactory> encoder_factory,
32                            std::unique_ptr<VideoDecoderFactory> decoder_factory,
33                            SdpVideoFormat video_format);
34   ~SimulcastTestFixtureImpl() final;
35 
36   // Implements SimulcastTestFixture.
37   void TestKeyFrameRequestsOnAllStreams() override;
38   void TestPaddingAllStreams() override;
39   void TestPaddingTwoStreams() override;
40   void TestPaddingTwoStreamsOneMaxedOut() override;
41   void TestPaddingOneStream() override;
42   void TestPaddingOneStreamTwoMaxedOut() override;
43   void TestSendAllStreams() override;
44   void TestDisablingStreams() override;
45   void TestActiveStreams() override;
46   void TestSwitchingToOneStream() override;
47   void TestSwitchingToOneOddStream() override;
48   void TestSwitchingToOneSmallStream() override;
49   void TestSpatioTemporalLayers333PatternEncoder() override;
50   void TestSpatioTemporalLayers321PatternEncoder() override;
51   void TestStrideEncodeDecode() override;
52   void TestDecodeWidthHeightSet() override;
53   void TestEncoderInfoForDefaultTemporalLayerProfileHasFpsAllocation() override;
54 
55   static void DefaultSettings(VideoCodec* settings,
56                               const int* temporal_layer_profile,
57                               VideoCodecType codec_type,
58                               bool reverse_layer_order = false);
59 
60  private:
61   class TestEncodedImageCallback;
62   class TestDecodedImageCallback;
63 
64   void SetUpCodec(const int* temporal_layer_profile);
65   void SetUpRateAllocator();
66   void SetRates(uint32_t bitrate_kbps, uint32_t fps);
67   void RunActiveStreamsTest(std::vector<bool> active_streams);
68   void UpdateActiveStreams(std::vector<bool> active_streams);
69   void ExpectStream(VideoFrameType frame_type, int scaleResolutionDownBy);
70   void ExpectStreams(VideoFrameType frame_type,
71                      std::vector<bool> expected_streams_active);
72   void ExpectStreams(VideoFrameType frame_type, int expected_video_streams);
73   void VerifyTemporalIdxAndSyncForAllSpatialLayers(
74       TestEncodedImageCallback* encoder_callback,
75       const int* expected_temporal_idx,
76       const bool* expected_layer_sync,
77       int num_spatial_layers);
78   void SwitchingToOneStream(int width, int height);
79 
80   std::unique_ptr<VideoEncoder> encoder_;
81   MockEncodedImageCallback encoder_callback_;
82   std::unique_ptr<VideoDecoder> decoder_;
83   MockDecodedImageCallback decoder_callback_;
84   VideoCodec settings_;
85   rtc::scoped_refptr<I420Buffer> input_buffer_;
86   std::unique_ptr<VideoFrame> input_frame_;
87   std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
88   VideoCodecType codec_type_;
89 };
90 
91 }  // namespace test
92 }  // namespace webrtc
93 
94 #endif  // MODULES_VIDEO_CODING_UTILITY_SIMULCAST_TEST_FIXTURE_IMPL_H_
95