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
22 constexpr int kWidth = 640;
23 constexpr int kHeight = 360;
24
25 class MockVideoSinkInterfaceVideoFrame
26 : public rtc::VideoSinkInterface<VideoFrame> {
27 public:
28 MOCK_METHOD(void, OnFrame, (const VideoFrame& frame), (override));
29 MOCK_METHOD(void, OnDiscardedFrame, (), (override));
30 };
31 } // namespace
32
TEST(FrameGeneratorCapturerTest,CreateFromConfig)33 TEST(FrameGeneratorCapturerTest, CreateFromConfig) {
34 GlobalSimulatedTimeController time(Timestamp::Seconds(1000));
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))))
45 .Times(21);
46 time.AdvanceTime(TimeDelta::Seconds(1));
47 }
48
TEST(FrameGeneratorCapturerTest,OnOutputFormatRequest)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
TEST(FrameGeneratorCapturerTest,ChangeResolution)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
88 } // namespace test
89 } // namespace webrtc
90