blob: d8371f4efd4fa33906579a23ade13ba25ea449c4 [file] [log] [blame]
Sebastian Jansson53571c72019-07-31 17:30:03 +02001/*
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
16namespace webrtc {
17namespace test {
18namespace {
19using ::testing::Eq;
20using ::testing::Property;
21
Asa Persson42eec3d2022-01-13 17:51:18 +010022constexpr int kWidth = 640;
23constexpr int kHeight = 360;
24
Sebastian Jansson53571c72019-07-31 17:30:03 +020025class MockVideoSinkInterfaceVideoFrame
26 : public rtc::VideoSinkInterface<VideoFrame> {
27 public:
Danil Chapovalov54706d62020-05-14 19:50:01 +020028 MOCK_METHOD(void, OnFrame, (const VideoFrame& frame), (override));
29 MOCK_METHOD(void, OnDiscardedFrame, (), (override));
Sebastian Jansson53571c72019-07-31 17:30:03 +020030};
31} // namespace
Asa Persson42eec3d2022-01-13 17:51:18 +010032
Sebastian Jansson53571c72019-07-31 17:30:03 +020033TEST(FrameGeneratorCapturerTest, CreateFromConfig) {
Danil Chapovalov0c626af2020-02-10 11:16:00 +010034 GlobalSimulatedTimeController time(Timestamp::Seconds(1000));
Sebastian Jansson53571c72019-07-31 17:30:03 +020035 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))))
philipeld5727482020-01-03 14:43:10 +010045 .Times(21);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010046 time.AdvanceTime(TimeDelta::Seconds(1));
Sebastian Jansson53571c72019-07-31 17:30:03 +020047}
Asa Persson42eec3d2022-01-13 17:51:18 +010048
49TEST(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
66TEST(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 Jansson53571c72019-07-31 17:30:03 +020088} // namespace test
89} // namespace webrtc