blob: 7ed06473a19d329693a89d118db981069db0e45e [file] [log] [blame]
Artem Titov503d7232019-12-04 12:37:13 +01001/*
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 Titov33f9d2b2019-12-05 15:59:00 +010013#include <cstdio>
Artem Titov503d7232019-12-04 12:37:13 +010014#include <utility>
15
Artem Titov33f9d2b2019-12-05 15:59:00 +010016#include "rtc_base/checks.h"
Artem Titov503d7232019-12-04 12:37:13 +010017#include "test/frame_generator.h"
Artem Titovfd76b5f2019-12-04 23:06:35 +010018#include "test/testsupport/ivf_video_frame_generator.h"
Artem Titov503d7232019-12-04 12:37:13 +010019
20namespace webrtc {
21namespace test {
22
23std::unique_ptr<FrameGeneratorInterface> CreateSquareFrameGenerator(
24 int width,
25 int height,
26 absl::optional<FrameGeneratorInterface::OutputType> type,
27 absl::optional<int> num_squares) {
Artem Titov33f9d2b2019-12-05 15:59:00 +010028 return std::make_unique<SquareGenerator>(
29 width, height, type.value_or(FrameGeneratorInterface::OutputType::kI420),
30 num_squares.value_or(10));
Artem Titov503d7232019-12-04 12:37:13 +010031}
32
33std::unique_ptr<FrameGeneratorInterface> CreateFromYuvFileFrameGenerator(
Artem Titov33f9d2b2019-12-05 15:59:00 +010034 std::vector<std::string> filenames,
Artem Titov503d7232019-12-04 12:37:13 +010035 size_t width,
36 size_t height,
37 int frame_repeat_count) {
Artem Titov33f9d2b2019-12-05 15:59:00 +010038 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 Titov503d7232019-12-04 12:37:13 +010048}
49
Artem Titov78782a82019-12-05 10:38:05 +010050std::unique_ptr<FrameGeneratorInterface> CreateFromIvfFileFrameGenerator(
Artem Titov33f9d2b2019-12-05 15:59:00 +010051 std::string filename) {
52 return std::make_unique<IvfVideoFrameGenerator>(std::move(filename));
Artem Titovfd76b5f2019-12-04 23:06:35 +010053}
54
Artem Titov503d7232019-12-04 12:37:13 +010055std::unique_ptr<FrameGeneratorInterface>
56CreateScrollingInputFromYuvFilesFrameGenerator(
57 Clock* clock,
58 std::vector<std::string> filenames,
59 size_t source_width,
60 size_t source_height,
61 size_t target_width,
62 size_t target_height,
63 int64_t scroll_time_ms,
64 int64_t pause_time_ms) {
Artem Titov33f9d2b2019-12-05 15:59:00 +010065 RTC_DCHECK(!filenames.empty());
66 std::vector<FILE*> files;
67 for (const std::string& filename : filenames) {
68 FILE* file = fopen(filename.c_str(), "rb");
69 RTC_DCHECK(file != nullptr);
70 files.push_back(file);
71 }
72
73 return std::make_unique<ScrollingImageFrameGenerator>(
74 clock, files, source_width, source_height, target_width, target_height,
75 scroll_time_ms, pause_time_ms);
Artem Titov503d7232019-12-04 12:37:13 +010076}
77
78std::unique_ptr<FrameGeneratorInterface>
79CreateSlideFrameGenerator(int width, int height, int frame_repeat_count) {
Artem Titov33f9d2b2019-12-05 15:59:00 +010080 return std::make_unique<SlideGenerator>(width, height, frame_repeat_count);
Artem Titov503d7232019-12-04 12:37:13 +010081}
82
83} // namespace test
84} // namespace webrtc