Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 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" |
Jeremy Leconte | 0e2cf6c | 2022-11-04 10:10:42 | [diff] [blame] | 17 | #include "api/test/pclf/media_configuration.h" |
Andrey Logvin | 1e83d34 | 2020-05-07 07:19:15 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 19 | #include "test/testsupport/file_utils.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | namespace webrtc_pc_e2e { |
| 23 | |
Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 24 | void 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 Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 28 | // If we have scrolling params, then its `source_width` and `source_heigh` |
Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 29 | // 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 Logvin | 435fb9a | 2020-05-08 08:02:49 | [diff] [blame] | 40 | if (screen_share_config.scrolling_params) { |
Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 41 | 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 | |
| 50 | std::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 | |
| 57 | std::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 | |
| 65 | std::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 Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 91 | TimeDelta pause_duration = screen_share_config.slide_change_interval - |
| 92 | screen_share_config.scrolling_params->duration; |
Andrey Logvin | 1e83d34 | 2020-05-07 07:19:15 | [diff] [blame] | 93 | RTC_DCHECK(pause_duration >= TimeDelta::Zero()); |
Andrey Logvin | dad6a94 | 2020-05-04 17:27:09 | [diff] [blame] | 94 | 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 |