1 /*
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"
17 #include "api/test/peerconnection_quality_test_fixture.h"
18 #include "rtc_base/checks.h"
19 #include "test/testsupport/file_utils.h"
20
21 namespace webrtc {
22 namespace webrtc_pc_e2e {
23
24 using VideoConfig =
25 ::webrtc::webrtc_pc_e2e::PeerConnectionE2EQualityTestFixture::VideoConfig;
26 using ScreenShareConfig = ::webrtc::webrtc_pc_e2e::
27 PeerConnectionE2EQualityTestFixture::ScreenShareConfig;
28
ValidateScreenShareConfig(const VideoConfig & video_config,const ScreenShareConfig & screen_share_config)29 void ValidateScreenShareConfig(const VideoConfig& video_config,
30 const ScreenShareConfig& screen_share_config) {
31 if (screen_share_config.slides_yuv_file_names.empty()) {
32 if (screen_share_config.scrolling_params) {
33 // If we have scrolling params, then its |source_width| and |source_heigh|
34 // will be used as width and height of video input, so we have to validate
35 // it against width and height of default input.
36 RTC_CHECK_EQ(screen_share_config.scrolling_params->source_width,
37 kDefaultSlidesWidth);
38 RTC_CHECK_EQ(screen_share_config.scrolling_params->source_height,
39 kDefaultSlidesHeight);
40 } else {
41 RTC_CHECK_EQ(video_config.width, kDefaultSlidesWidth);
42 RTC_CHECK_EQ(video_config.height, kDefaultSlidesHeight);
43 }
44 }
45 if (screen_share_config.scrolling_params) {
46 RTC_CHECK_LE(screen_share_config.scrolling_params->duration,
47 screen_share_config.slide_change_interval);
48 RTC_CHECK_GE(screen_share_config.scrolling_params->source_width,
49 video_config.width);
50 RTC_CHECK_GE(screen_share_config.scrolling_params->source_height,
51 video_config.height);
52 }
53 }
54
CreateSquareFrameGenerator(const VideoConfig & video_config,absl::optional<test::FrameGeneratorInterface::OutputType> type)55 std::unique_ptr<test::FrameGeneratorInterface> CreateSquareFrameGenerator(
56 const VideoConfig& video_config,
57 absl::optional<test::FrameGeneratorInterface::OutputType> type) {
58 return test::CreateSquareFrameGenerator(
59 video_config.width, video_config.height, std::move(type), absl::nullopt);
60 }
61
CreateFromYuvFileFrameGenerator(const VideoConfig & video_config,std::string filename)62 std::unique_ptr<test::FrameGeneratorInterface> CreateFromYuvFileFrameGenerator(
63 const VideoConfig& video_config,
64 std::string filename) {
65 return test::CreateFromYuvFileFrameGenerator(
66 {std::move(filename)}, video_config.width, video_config.height,
67 /*frame_repeat_count=*/1);
68 }
69
CreateScreenShareFrameGenerator(const VideoConfig & video_config,const ScreenShareConfig & screen_share_config)70 std::unique_ptr<test::FrameGeneratorInterface> CreateScreenShareFrameGenerator(
71 const VideoConfig& video_config,
72 const ScreenShareConfig& screen_share_config) {
73 ValidateScreenShareConfig(video_config, screen_share_config);
74 if (screen_share_config.generate_slides) {
75 return test::CreateSlideFrameGenerator(
76 video_config.width, video_config.height,
77 screen_share_config.slide_change_interval.seconds() * video_config.fps);
78 }
79 std::vector<std::string> slides = screen_share_config.slides_yuv_file_names;
80 if (slides.empty()) {
81 // If slides is empty we need to add default slides as source. In such case
82 // video width and height is validated to be equal to kDefaultSlidesWidth
83 // and kDefaultSlidesHeight.
84 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
85 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
86 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
87 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
88 }
89 if (!screen_share_config.scrolling_params) {
90 // Cycle image every slide_change_interval seconds.
91 return test::CreateFromYuvFileFrameGenerator(
92 slides, video_config.width, video_config.height,
93 screen_share_config.slide_change_interval.seconds() * video_config.fps);
94 }
95
96 TimeDelta pause_duration = screen_share_config.slide_change_interval -
97 screen_share_config.scrolling_params->duration;
98 RTC_DCHECK(pause_duration >= TimeDelta::Zero());
99 return test::CreateScrollingInputFromYuvFilesFrameGenerator(
100 Clock::GetRealTimeClock(), slides,
101 screen_share_config.scrolling_params->source_width,
102 screen_share_config.scrolling_params->source_height, video_config.width,
103 video_config.height, screen_share_config.scrolling_params->duration.ms(),
104 pause_duration.ms());
105 }
106
107 } // namespace webrtc_pc_e2e
108 } // namespace webrtc
109