blob: a1c53635f9dcbc2f5c4396dd59227cfae35a370d [file] [log] [blame]
Andrey Logvindad6a942020-05-04 17:27:091/*
2 * Copyright (c) 2020 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 "api/test/create_peer_connection_quality_test_frame_generator.h"
12
13#include <utility>
14#include <vector>
15
16#include "api/test/create_frame_generator.h"
Jeremy Leconte0e2cf6c2022-11-04 10:10:4217#include "api/test/pclf/media_configuration.h"
Andrey Logvin1e83d342020-05-07 07:19:1518#include "rtc_base/checks.h"
Andrey Logvindad6a942020-05-04 17:27:0919#include "test/testsupport/file_utils.h"
20
21namespace webrtc {
22namespace webrtc_pc_e2e {
23
Andrey Logvindad6a942020-05-04 17:27:0924void ValidateScreenShareConfig(const VideoConfig& video_config,
25 const ScreenShareConfig& screen_share_config) {
26 if (screen_share_config.slides_yuv_file_names.empty()) {
27 if (screen_share_config.scrolling_params) {
Artem Titov0e61fdd2021-07-25 19:50:1428 // If we have scrolling params, then its `source_width` and `source_heigh`
Andrey Logvindad6a942020-05-04 17:27:0929 // will be used as width and height of video input, so we have to validate
30 // it against width and height of default input.
31 RTC_CHECK_EQ(screen_share_config.scrolling_params->source_width,
32 kDefaultSlidesWidth);
33 RTC_CHECK_EQ(screen_share_config.scrolling_params->source_height,
34 kDefaultSlidesHeight);
35 } else {
36 RTC_CHECK_EQ(video_config.width, kDefaultSlidesWidth);
37 RTC_CHECK_EQ(video_config.height, kDefaultSlidesHeight);
38 }
39 }
Andrey Logvin435fb9a2020-05-08 08:02:4940 if (screen_share_config.scrolling_params) {
Andrey Logvindad6a942020-05-04 17:27:0941 RTC_CHECK_LE(screen_share_config.scrolling_params->duration,
42 screen_share_config.slide_change_interval);
43 RTC_CHECK_GE(screen_share_config.scrolling_params->source_width,
44 video_config.width);
45 RTC_CHECK_GE(screen_share_config.scrolling_params->source_height,
46 video_config.height);
47 }
48}
49
50std::unique_ptr<test::FrameGeneratorInterface> CreateSquareFrameGenerator(
51 const VideoConfig& video_config,
52 absl::optional<test::FrameGeneratorInterface::OutputType> type) {
53 return test::CreateSquareFrameGenerator(
54 video_config.width, video_config.height, std::move(type), absl::nullopt);
55}
56
57std::unique_ptr<test::FrameGeneratorInterface> CreateFromYuvFileFrameGenerator(
58 const VideoConfig& video_config,
59 std::string filename) {
60 return test::CreateFromYuvFileFrameGenerator(
61 {std::move(filename)}, video_config.width, video_config.height,
62 /*frame_repeat_count=*/1);
63}
64
65std::unique_ptr<test::FrameGeneratorInterface> CreateScreenShareFrameGenerator(
66 const VideoConfig& video_config,
67 const ScreenShareConfig& screen_share_config) {
68 ValidateScreenShareConfig(video_config, screen_share_config);
69 if (screen_share_config.generate_slides) {
70 return test::CreateSlideFrameGenerator(
71 video_config.width, video_config.height,
72 screen_share_config.slide_change_interval.seconds() * video_config.fps);
73 }
74 std::vector<std::string> slides = screen_share_config.slides_yuv_file_names;
75 if (slides.empty()) {
76 // If slides is empty we need to add default slides as source. In such case
77 // video width and height is validated to be equal to kDefaultSlidesWidth
78 // and kDefaultSlidesHeight.
79 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
80 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
81 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
82 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
83 }
84 if (!screen_share_config.scrolling_params) {
85 // Cycle image every slide_change_interval seconds.
86 return test::CreateFromYuvFileFrameGenerator(
87 slides, video_config.width, video_config.height,
88 screen_share_config.slide_change_interval.seconds() * video_config.fps);
89 }
90
Andrey Logvindad6a942020-05-04 17:27:0991 TimeDelta pause_duration = screen_share_config.slide_change_interval -
92 screen_share_config.scrolling_params->duration;
Andrey Logvin1e83d342020-05-07 07:19:1593 RTC_DCHECK(pause_duration >= TimeDelta::Zero());
Andrey Logvindad6a942020-05-04 17:27:0994 return test::CreateScrollingInputFromYuvFilesFrameGenerator(
95 Clock::GetRealTimeClock(), slides,
96 screen_share_config.scrolling_params->source_width,
97 screen_share_config.scrolling_params->source_height, video_config.width,
98 video_config.height, screen_share_config.scrolling_params->duration.ms(),
99 pause_duration.ms());
100}
101
102} // namespace webrtc_pc_e2e
103} // namespace webrtc