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