xref: /aosp_15_r20/external/webrtc/api/test/peerconnection_quality_test_fixture_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2022 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 #include "api/test/peerconnection_quality_test_fixture.h"
12 
13 #include <vector>
14 
15 #include "absl/types/optional.h"
16 #include "api/test/pclf/media_configuration.h"
17 #include "api/test/video/video_frame_writer.h"
18 #include "rtc_base/gunit.h"
19 #include "test/gmock.h"
20 #include "test/testsupport/file_utils.h"
21 
22 namespace webrtc {
23 namespace webrtc_pc_e2e {
24 namespace {
25 
26 using ::testing::Eq;
27 
TEST(PclfVideoSubscriptionTest,MaxFromSenderSpecEqualIndependentOfOtherFields)28 TEST(PclfVideoSubscriptionTest,
29      MaxFromSenderSpecEqualIndependentOfOtherFields) {
30   VideoResolution r1(VideoResolution::Spec::kMaxFromSender);
31   r1.set_width(1);
32   r1.set_height(2);
33   r1.set_fps(3);
34   VideoResolution r2(VideoResolution::Spec::kMaxFromSender);
35   r1.set_width(4);
36   r1.set_height(5);
37   r1.set_fps(6);
38   EXPECT_EQ(r1, r2);
39 }
40 
TEST(PclfVideoSubscriptionTest,WhenSpecIsNotSetFieldsAreCompared)41 TEST(PclfVideoSubscriptionTest, WhenSpecIsNotSetFieldsAreCompared) {
42   VideoResolution test_resolution(/*width=*/1, /*height=*/2,
43                                   /*fps=*/3);
44   VideoResolution equal_resolution(/*width=*/1, /*height=*/2,
45                                    /*fps=*/3);
46   VideoResolution different_width(/*width=*/10, /*height=*/2,
47                                   /*fps=*/3);
48   VideoResolution different_height(/*width=*/1, /*height=*/20,
49                                    /*fps=*/3);
50   VideoResolution different_fps(/*width=*/1, /*height=*/20,
51                                 /*fps=*/30);
52 
53   EXPECT_EQ(test_resolution, equal_resolution);
54   EXPECT_NE(test_resolution, different_width);
55   EXPECT_NE(test_resolution, different_height);
56   EXPECT_NE(test_resolution, different_fps);
57 }
58 
TEST(PclfVideoSubscriptionTest,GetMaxResolutionForEmptyReturnsNullopt)59 TEST(PclfVideoSubscriptionTest, GetMaxResolutionForEmptyReturnsNullopt) {
60   absl::optional<VideoResolution> resolution =
61       VideoSubscription::GetMaxResolution(std::vector<VideoConfig>{});
62   ASSERT_FALSE(resolution.has_value());
63 }
64 
TEST(PclfVideoSubscriptionTest,GetMaxResolutionSelectMaxForEachDimention)65 TEST(PclfVideoSubscriptionTest, GetMaxResolutionSelectMaxForEachDimention) {
66   VideoConfig max_width(/*width=*/1000, /*height=*/1, /*fps=*/1);
67   VideoConfig max_height(/*width=*/1, /*height=*/100, /*fps=*/1);
68   VideoConfig max_fps(/*width=*/1, /*height=*/1, /*fps=*/10);
69 
70   absl::optional<VideoResolution> resolution =
71       VideoSubscription::GetMaxResolution(
72           std::vector<VideoConfig>{max_width, max_height, max_fps});
73   ASSERT_TRUE(resolution.has_value());
74   EXPECT_EQ(resolution->width(), static_cast<size_t>(1000));
75   EXPECT_EQ(resolution->height(), static_cast<size_t>(100));
76   EXPECT_EQ(resolution->fps(), 10);
77 }
78 
79 struct TestVideoFrameWriter : public test::VideoFrameWriter {
80  public:
TestVideoFrameWriterwebrtc::webrtc_pc_e2e::__anon6a4cc3510111::TestVideoFrameWriter81   TestVideoFrameWriter(absl::string_view file_name_prefix,
82                        const VideoResolution& resolution)
83       : file_name_prefix(file_name_prefix), resolution(resolution) {}
84 
WriteFramewebrtc::webrtc_pc_e2e::__anon6a4cc3510111::TestVideoFrameWriter85   bool WriteFrame(const VideoFrame& frame) override { return true; }
86 
Closewebrtc::webrtc_pc_e2e::__anon6a4cc3510111::TestVideoFrameWriter87   void Close() override {}
88 
89   std::string file_name_prefix;
90   VideoResolution resolution;
91 };
92 
TEST(VideoDumpOptionsTest,InputVideoWriterHasCorrectFileName)93 TEST(VideoDumpOptionsTest, InputVideoWriterHasCorrectFileName) {
94   VideoResolution resolution(/*width=*/1280, /*height=*/720, /*fps=*/30);
95 
96   TestVideoFrameWriter* writer = nullptr;
97   VideoDumpOptions options("foo", /*sampling_modulo=*/1,
98                            /*export_frame_ids=*/false,
99                            /*video_frame_writer_factory=*/
100                            [&](absl::string_view file_name_prefix,
101                                const VideoResolution& resolution) {
102                              auto out = std::make_unique<TestVideoFrameWriter>(
103                                  file_name_prefix, resolution);
104                              writer = out.get();
105                              return out;
106                            });
107   std::unique_ptr<test::VideoFrameWriter> created_writer =
108       options.CreateInputDumpVideoFrameWriter("alice-video", resolution);
109 
110   ASSERT_TRUE(writer != nullptr);
111   ASSERT_THAT(writer->file_name_prefix,
112               Eq(test::JoinFilename("foo", "alice-video_1280x720_30")));
113   ASSERT_THAT(writer->resolution, Eq(resolution));
114 }
115 
TEST(VideoDumpOptionsTest,OutputVideoWriterHasCorrectFileName)116 TEST(VideoDumpOptionsTest, OutputVideoWriterHasCorrectFileName) {
117   VideoResolution resolution(/*width=*/1280, /*height=*/720, /*fps=*/30);
118 
119   TestVideoFrameWriter* writer = nullptr;
120   VideoDumpOptions options("foo", /*sampling_modulo=*/1,
121                            /*export_frame_ids=*/false,
122                            /*video_frame_writer_factory=*/
123                            [&](absl::string_view file_name_prefix,
124                                const VideoResolution& resolution) {
125                              auto out = std::make_unique<TestVideoFrameWriter>(
126                                  file_name_prefix, resolution);
127                              writer = out.get();
128                              return out;
129                            });
130   std::unique_ptr<test::VideoFrameWriter> created_writer =
131       options.CreateOutputDumpVideoFrameWriter("alice-video", "bob",
132                                                resolution);
133 
134   ASSERT_TRUE(writer != nullptr);
135   ASSERT_THAT(writer->file_name_prefix,
136               Eq(test::JoinFilename("foo", "alice-video_bob_1280x720_30")));
137   ASSERT_THAT(writer->resolution, Eq(resolution));
138 }
139 
140 }  // namespace
141 }  // namespace webrtc_pc_e2e
142 }  // namespace webrtc
143