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