blob: 8bf70cffd532cc2133bbccc10db2f13f81590427 [file] [log] [blame]
Sebastian Jansson53571c72019-07-31 15:30:031/*
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 Titovd77f2212023-04-13 12:34:5912
13#include "test/create_frame_generator_capturer.h"
Sebastian Jansson53571c72019-07-31 15:30:0314#include "test/gmock.h"
15#include "test/gtest.h"
16#include "test/time_controller/simulated_time_controller.h"
17
18namespace webrtc {
19namespace test {
20namespace {
21using ::testing::Eq;
22using ::testing::Property;
23
Asa Persson42eec3d2022-01-13 16:51:1824constexpr int kWidth = 640;
25constexpr int kHeight = 360;
26
Sebastian Jansson53571c72019-07-31 15:30:0327class MockVideoSinkInterfaceVideoFrame
28 : public rtc::VideoSinkInterface<VideoFrame> {
29 public:
Danil Chapovalov54706d62020-05-14 17:50:0130 MOCK_METHOD(void, OnFrame, (const VideoFrame& frame), (override));
31 MOCK_METHOD(void, OnDiscardedFrame, (), (override));
Sebastian Jansson53571c72019-07-31 15:30:0332};
33} // namespace
Asa Persson42eec3d2022-01-13 16:51:1834
Sebastian Jansson53571c72019-07-31 15:30:0335TEST(FrameGeneratorCapturerTest, CreateFromConfig) {
Danil Chapovalov0c626af2020-02-10 10:16:0036 GlobalSimulatedTimeController time(Timestamp::Seconds(1000));
Sebastian Jansson53571c72019-07-31 15:30:0337 FrameGeneratorCapturerConfig config;
38 config.squares_video->width = 300;
39 config.squares_video->height = 200;
40 config.squares_video->framerate = 20;
Artem Titovd77f2212023-04-13 12:34:5941 auto capturer = CreateFrameGeneratorCapturer(
Sebastian Jansson53571c72019-07-31 15:30:0342 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))))
philipeld5727482020-01-03 13:43:1047 .Times(21);
Danil Chapovalov0c626af2020-02-10 10:16:0048 time.AdvanceTime(TimeDelta::Seconds(1));
Sebastian Jansson53571c72019-07-31 15:30:0349}
Asa Persson42eec3d2022-01-13 16:51:1850
51TEST(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 Titovd77f2212023-04-13 12:34:5957 auto capturer = CreateFrameGeneratorCapturer(
Asa Persson42eec3d2022-01-13 16:51:1858 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
68TEST(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 Titovd77f2212023-04-13 12:34:5974 auto capturer = CreateFrameGeneratorCapturer(
Asa Persson42eec3d2022-01-13 16:51:1875 time.GetClock(), *time.GetTaskQueueFactory(), config);
Artem Titov6fd5f33d2023-03-25 20:15:0976 EXPECT_TRUE(capturer->GetResolution());
77 EXPECT_EQ(kWidth, capturer->GetResolution()->width);
78 EXPECT_EQ(kHeight, capturer->GetResolution()->height);
Asa Persson42eec3d2022-01-13 16:51:1879 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 Jansson53571c72019-07-31 15:30:0392} // namespace test
93} // namespace webrtc