Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 "test/frame_generator_capturer.h" |
Artem Titov | d77f221 | 2023-04-13 12:34:59 | [diff] [blame] | 12 | |
| 13 | #include "test/create_frame_generator_capturer.h" |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 14 | #include "test/gmock.h" |
| 15 | #include "test/gtest.h" |
| 16 | #include "test/time_controller/simulated_time_controller.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | namespace { |
| 21 | using ::testing::Eq; |
| 22 | using ::testing::Property; |
| 23 | |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 24 | constexpr int kWidth = 640; |
| 25 | constexpr int kHeight = 360; |
| 26 | |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 27 | class MockVideoSinkInterfaceVideoFrame |
| 28 | : public rtc::VideoSinkInterface<VideoFrame> { |
| 29 | public: |
Danil Chapovalov | 54706d6 | 2020-05-14 17:50:01 | [diff] [blame] | 30 | MOCK_METHOD(void, OnFrame, (const VideoFrame& frame), (override)); |
| 31 | MOCK_METHOD(void, OnDiscardedFrame, (), (override)); |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 32 | }; |
| 33 | } // namespace |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 34 | |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 35 | TEST(FrameGeneratorCapturerTest, CreateFromConfig) { |
Danil Chapovalov | 0c626af | 2020-02-10 10:16:00 | [diff] [blame] | 36 | GlobalSimulatedTimeController time(Timestamp::Seconds(1000)); |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 37 | FrameGeneratorCapturerConfig config; |
| 38 | config.squares_video->width = 300; |
| 39 | config.squares_video->height = 200; |
| 40 | config.squares_video->framerate = 20; |
Artem Titov | d77f221 | 2023-04-13 12:34:59 | [diff] [blame] | 41 | auto capturer = CreateFrameGeneratorCapturer( |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 42 | time.GetClock(), *time.GetTaskQueueFactory(), config); |
| 43 | testing::StrictMock<MockVideoSinkInterfaceVideoFrame> mock_sink; |
| 44 | capturer->AddOrUpdateSink(&mock_sink, rtc::VideoSinkWants()); |
| 45 | capturer->Start(); |
| 46 | EXPECT_CALL(mock_sink, OnFrame(Property(&VideoFrame::width, Eq(300)))) |
philipel | d572748 | 2020-01-03 13:43:10 | [diff] [blame] | 47 | .Times(21); |
Danil Chapovalov | 0c626af | 2020-02-10 10:16:00 | [diff] [blame] | 48 | time.AdvanceTime(TimeDelta::Seconds(1)); |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 49 | } |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 50 | |
| 51 | TEST(FrameGeneratorCapturerTest, OnOutputFormatRequest) { |
| 52 | GlobalSimulatedTimeController time(Timestamp::Seconds(1000)); |
| 53 | FrameGeneratorCapturerConfig config; |
| 54 | config.squares_video->width = kWidth; |
| 55 | config.squares_video->height = kHeight; |
| 56 | config.squares_video->framerate = 20; |
Artem Titov | d77f221 | 2023-04-13 12:34:59 | [diff] [blame] | 57 | auto capturer = CreateFrameGeneratorCapturer( |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 58 | time.GetClock(), *time.GetTaskQueueFactory(), config); |
| 59 | testing::StrictMock<MockVideoSinkInterfaceVideoFrame> mock_sink; |
| 60 | capturer->AddOrUpdateSink(&mock_sink, rtc::VideoSinkWants()); |
| 61 | capturer->OnOutputFormatRequest(kWidth / 2, kHeight / 2, /*max_fps=*/10); |
| 62 | capturer->Start(); |
| 63 | EXPECT_CALL(mock_sink, OnFrame(Property(&VideoFrame::width, Eq(kWidth / 2)))) |
| 64 | .Times(11); |
| 65 | time.AdvanceTime(TimeDelta::Seconds(1)); |
| 66 | } |
| 67 | |
| 68 | TEST(FrameGeneratorCapturerTest, ChangeResolution) { |
| 69 | GlobalSimulatedTimeController time(Timestamp::Seconds(1000)); |
| 70 | FrameGeneratorCapturerConfig config; |
| 71 | config.squares_video->width = kWidth; |
| 72 | config.squares_video->height = kHeight; |
| 73 | config.squares_video->framerate = 20; |
Artem Titov | d77f221 | 2023-04-13 12:34:59 | [diff] [blame] | 74 | auto capturer = CreateFrameGeneratorCapturer( |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 75 | time.GetClock(), *time.GetTaskQueueFactory(), config); |
Artem Titov | 6fd5f33d | 2023-03-25 20:15:09 | [diff] [blame] | 76 | EXPECT_TRUE(capturer->GetResolution()); |
| 77 | EXPECT_EQ(kWidth, capturer->GetResolution()->width); |
| 78 | EXPECT_EQ(kHeight, capturer->GetResolution()->height); |
Asa Persson | 42eec3d | 2022-01-13 16:51:18 | [diff] [blame] | 79 | capturer->Start(); |
| 80 | time.AdvanceTime(TimeDelta::Seconds(1)); |
| 81 | ASSERT_TRUE(capturer->GetResolution()); |
| 82 | EXPECT_EQ(kWidth, capturer->GetResolution()->width); |
| 83 | EXPECT_EQ(kHeight, capturer->GetResolution()->height); |
| 84 | |
| 85 | capturer->ChangeResolution(kWidth / 2, kHeight / 2); |
| 86 | time.AdvanceTime(TimeDelta::Seconds(1)); |
| 87 | ASSERT_TRUE(capturer->GetResolution()); |
| 88 | EXPECT_EQ(kWidth / 2, capturer->GetResolution()->width); |
| 89 | EXPECT_EQ(kHeight / 2, capturer->GetResolution()->height); |
| 90 | } |
| 91 | |
Sebastian Jansson | 53571c7 | 2019-07-31 15:30:03 | [diff] [blame] | 92 | } // namespace test |
| 93 | } // namespace webrtc |