create_frame_generator.cc (3724B)
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 13 #include <cstdint> 14 #include <cstdio> 15 #include <memory> 16 #include <optional> 17 #include <string> 18 #include <vector> 19 20 #include "absl/base/nullability.h" 21 #include "absl/strings/string_view.h" 22 #include "api/environment/environment.h" 23 #include "api/test/frame_generator_interface.h" 24 #include "rtc_base/checks.h" 25 #include "system_wrappers/include/clock.h" 26 #include "test/frame_generator.h" 27 #include "test/testsupport/ivf_video_frame_generator.h" 28 29 namespace webrtc { 30 namespace test { 31 32 std::unique_ptr<FrameGeneratorInterface> CreateSquareFrameGenerator( 33 int width, 34 int height, 35 std::optional<FrameGeneratorInterface::OutputType> type, 36 std::optional<int> num_squares) { 37 return std::make_unique<SquareGenerator>( 38 width, height, type.value_or(FrameGeneratorInterface::OutputType::kI420), 39 num_squares.value_or(10)); 40 } 41 42 std::unique_ptr<FrameGeneratorInterface> CreateFromYuvFileFrameGenerator( 43 std::vector<std::string> filenames, 44 size_t width, 45 size_t height, 46 int frame_repeat_count) { 47 RTC_DCHECK(!filenames.empty()); 48 std::vector<FILE*> files; 49 for (const std::string& filename : filenames) { 50 FILE* file = fopen(filename.c_str(), "rb"); 51 RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n"; 52 files.push_back(file); 53 } 54 55 return std::make_unique<YuvFileGenerator>(files, width, height, 56 frame_repeat_count); 57 } 58 59 std::unique_ptr<FrameGeneratorInterface> CreateFromNV12FileFrameGenerator( 60 std::vector<std::string> filenames, 61 size_t width, 62 size_t height, 63 int frame_repeat_count) { 64 RTC_DCHECK(!filenames.empty()); 65 std::vector<FILE*> files; 66 for (const std::string& filename : filenames) { 67 FILE* file = fopen(filename.c_str(), "rb"); 68 RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n"; 69 files.push_back(file); 70 } 71 72 return std::make_unique<NV12FileGenerator>(files, width, height, 73 frame_repeat_count); 74 } 75 76 absl_nonnull std::unique_ptr<FrameGeneratorInterface> 77 CreateFromIvfFileFrameGenerator(const Environment& env, 78 absl::string_view filename, 79 std::optional<int> fps_hint) { 80 return std::make_unique<IvfVideoFrameGenerator>(env, filename, fps_hint); 81 } 82 83 std::unique_ptr<FrameGeneratorInterface> 84 CreateScrollingInputFromYuvFilesFrameGenerator( 85 Clock* clock, 86 std::vector<std::string> filenames, 87 size_t source_width, 88 size_t source_height, 89 size_t target_width, 90 size_t target_height, 91 int64_t scroll_time_ms, 92 int64_t pause_time_ms) { 93 RTC_DCHECK(!filenames.empty()); 94 std::vector<FILE*> files; 95 for (const std::string& filename : filenames) { 96 FILE* file = fopen(filename.c_str(), "rb"); 97 RTC_DCHECK(file != nullptr); 98 files.push_back(file); 99 } 100 101 return std::make_unique<ScrollingImageFrameGenerator>( 102 clock, files, source_width, source_height, target_width, target_height, 103 scroll_time_ms, pause_time_ms); 104 } 105 106 std::unique_ptr<FrameGeneratorInterface> 107 CreateSlideFrameGenerator(int width, int height, int frame_repeat_count) { 108 return std::make_unique<SlideGenerator>(width, height, frame_repeat_count); 109 } 110 111 } // namespace test 112 } // namespace webrtc