Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 1 | /* |
| 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 "api/test/create_frame_generator.h" |
| 12 | |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 13 | #include <cstdio> |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 14 | #include <utility> |
| 15 | |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 17 | #include "test/frame_generator.h" |
Artem Titov | fd76b5f | 2019-12-04 22:06:35 | [diff] [blame] | 18 | #include "test/testsupport/ivf_video_frame_generator.h" |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
| 23 | std::unique_ptr<FrameGeneratorInterface> CreateSquareFrameGenerator( |
| 24 | int width, |
| 25 | int height, |
| 26 | absl::optional<FrameGeneratorInterface::OutputType> type, |
| 27 | absl::optional<int> num_squares) { |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 28 | return std::make_unique<SquareGenerator>( |
| 29 | width, height, type.value_or(FrameGeneratorInterface::OutputType::kI420), |
| 30 | num_squares.value_or(10)); |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | std::unique_ptr<FrameGeneratorInterface> CreateFromYuvFileFrameGenerator( |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 34 | std::vector<std::string> filenames, |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 35 | size_t width, |
| 36 | size_t height, |
| 37 | int frame_repeat_count) { |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 38 | RTC_DCHECK(!filenames.empty()); |
| 39 | std::vector<FILE*> files; |
| 40 | for (const std::string& filename : filenames) { |
| 41 | FILE* file = fopen(filename.c_str(), "rb"); |
| 42 | RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n"; |
| 43 | files.push_back(file); |
| 44 | } |
| 45 | |
| 46 | return std::make_unique<YuvFileGenerator>(files, width, height, |
| 47 | frame_repeat_count); |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 48 | } |
| 49 | |
Artem Titov | 9b73159 | 2022-10-07 13:01:32 | [diff] [blame] | 50 | std::unique_ptr<FrameGeneratorInterface> CreateFromNV12FileFrameGenerator( |
| 51 | std::vector<std::string> filenames, |
| 52 | size_t width, |
| 53 | size_t height, |
| 54 | int frame_repeat_count) { |
| 55 | RTC_DCHECK(!filenames.empty()); |
| 56 | std::vector<FILE*> files; |
| 57 | for (const std::string& filename : filenames) { |
| 58 | FILE* file = fopen(filename.c_str(), "rb"); |
| 59 | RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n"; |
| 60 | files.push_back(file); |
| 61 | } |
| 62 | |
| 63 | return std::make_unique<NV12FileGenerator>(files, width, height, |
| 64 | frame_repeat_count); |
| 65 | } |
| 66 | |
Artem Titov | 78782a8 | 2019-12-05 09:38:05 | [diff] [blame] | 67 | std::unique_ptr<FrameGeneratorInterface> CreateFromIvfFileFrameGenerator( |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 68 | std::string filename) { |
| 69 | return std::make_unique<IvfVideoFrameGenerator>(std::move(filename)); |
Artem Titov | fd76b5f | 2019-12-04 22:06:35 | [diff] [blame] | 70 | } |
| 71 | |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 72 | std::unique_ptr<FrameGeneratorInterface> |
| 73 | CreateScrollingInputFromYuvFilesFrameGenerator( |
| 74 | Clock* clock, |
| 75 | std::vector<std::string> filenames, |
| 76 | size_t source_width, |
| 77 | size_t source_height, |
| 78 | size_t target_width, |
| 79 | size_t target_height, |
| 80 | int64_t scroll_time_ms, |
| 81 | int64_t pause_time_ms) { |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 82 | RTC_DCHECK(!filenames.empty()); |
| 83 | std::vector<FILE*> files; |
| 84 | for (const std::string& filename : filenames) { |
| 85 | FILE* file = fopen(filename.c_str(), "rb"); |
| 86 | RTC_DCHECK(file != nullptr); |
| 87 | files.push_back(file); |
| 88 | } |
| 89 | |
| 90 | return std::make_unique<ScrollingImageFrameGenerator>( |
| 91 | clock, files, source_width, source_height, target_width, target_height, |
| 92 | scroll_time_ms, pause_time_ms); |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | std::unique_ptr<FrameGeneratorInterface> |
| 96 | CreateSlideFrameGenerator(int width, int height, int frame_repeat_count) { |
Artem Titov | 33f9d2b | 2019-12-05 14:59:00 | [diff] [blame] | 97 | return std::make_unique<SlideGenerator>(width, height, frame_repeat_count); |
Artem Titov | 503d723 | 2019-12-04 11:37:13 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace test |
| 101 | } // namespace webrtc |