Skip to content

Commit

Permalink
Migrate WebRTC on FrameGeneratorInterface and remove FrameGenerator c…
Browse files Browse the repository at this point in the history
…lass

Bug: webrtc:10138
Change-Id: If85290581a72f81cf60181de7a7134cc9db7716e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/161327
Reviewed-by: Niels Moller <[email protected]>
Reviewed-by: Karl Wiberg <[email protected]>
Commit-Queue: Artem Titov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#30033}
  • Loading branch information
titov-artem authored and Commit Bot committed Dec 7, 2019
1 parent af51be7 commit 33f9d2b
Show file tree
Hide file tree
Showing 43 changed files with 771 additions and 670 deletions.
30 changes: 15 additions & 15 deletions api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -449,22 +449,22 @@ if (rtc_include_tests) {
"../test/pc/e2e:peerconnection_quality_test",
]
}
}

rtc_library("create_frame_generator") {
visibility = [ "*" ]
testonly = true
sources = [
"test/create_frame_generator.cc",
"test/create_frame_generator.h",
]
deps = [
":frame_generator_api",
"../system_wrappers",
"../test:video_test_common",
"../test:video_test_support",
"//third_party/abseil-cpp/absl/types:optional",
]
}
rtc_library("create_frame_generator") {
visibility = [ "*" ]
testonly = true
sources = [
"test/create_frame_generator.cc",
"test/create_frame_generator.h",
]
deps = [
":frame_generator_api",
"../rtc_base:checks",
"../system_wrappers",
"../test:frame_generator_impl",
"//third_party/abseil-cpp/absl/types:optional",
]
}

rtc_source_set("libjingle_logging_api") {
Expand Down
42 changes: 30 additions & 12 deletions api/test/create_frame_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

#include "api/test/create_frame_generator.h"

#include <cstdio>
#include <utility>

#include "rtc_base/checks.h"
#include "test/frame_generator.h"
#include "test/testsupport/ivf_video_frame_generator.h"

Expand All @@ -23,22 +25,31 @@ std::unique_ptr<FrameGeneratorInterface> CreateSquareFrameGenerator(
int height,
absl::optional<FrameGeneratorInterface::OutputType> type,
absl::optional<int> num_squares) {
return FrameGenerator::CreateSquareGenerator(width, height, type,
num_squares);
return std::make_unique<SquareGenerator>(
width, height, type.value_or(FrameGeneratorInterface::OutputType::kI420),
num_squares.value_or(10));
}

std::unique_ptr<FrameGeneratorInterface> CreateFromYuvFileFrameGenerator(
std::vector<std::string> files,
std::vector<std::string> filenames,
size_t width,
size_t height,
int frame_repeat_count) {
return FrameGenerator::CreateFromYuvFile(std::move(files), width, height,
frame_repeat_count);
RTC_DCHECK(!filenames.empty());
std::vector<FILE*> files;
for (const std::string& filename : filenames) {
FILE* file = fopen(filename.c_str(), "rb");
RTC_DCHECK(file != nullptr) << "Failed to open: '" << filename << "'\n";
files.push_back(file);
}

return std::make_unique<YuvFileGenerator>(files, width, height,
frame_repeat_count);
}

std::unique_ptr<FrameGeneratorInterface> CreateFromIvfFileFrameGenerator(
std::string file) {
return std::make_unique<IvfVideoFrameGenerator>(std::move(file));
std::string filename) {
return std::make_unique<IvfVideoFrameGenerator>(std::move(filename));
}

std::unique_ptr<FrameGeneratorInterface>
Expand All @@ -51,15 +62,22 @@ CreateScrollingInputFromYuvFilesFrameGenerator(
size_t target_height,
int64_t scroll_time_ms,
int64_t pause_time_ms) {
return FrameGenerator::CreateScrollingInputFromYuvFiles(
clock, std::move(filenames), source_width, source_height, target_width,
target_height, scroll_time_ms, pause_time_ms);
RTC_DCHECK(!filenames.empty());
std::vector<FILE*> files;
for (const std::string& filename : filenames) {
FILE* file = fopen(filename.c_str(), "rb");
RTC_DCHECK(file != nullptr);
files.push_back(file);
}

return std::make_unique<ScrollingImageFrameGenerator>(
clock, files, source_width, source_height, target_width, target_height,
scroll_time_ms, pause_time_ms);
}

std::unique_ptr<FrameGeneratorInterface>
CreateSlideFrameGenerator(int width, int height, int frame_repeat_count) {
return FrameGenerator::CreateSlideGenerator(width, height,
frame_repeat_count);
return std::make_unique<SlideGenerator>(width, height, frame_repeat_count);
}

} // namespace test
Expand Down
4 changes: 2 additions & 2 deletions api/test/create_frame_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ std::unique_ptr<FrameGeneratorInterface> CreateSquareFrameGenerator(
// The frame_repeat_count determines how many times each frame is shown,
// with 1 = show each frame once, etc.
std::unique_ptr<FrameGeneratorInterface> CreateFromYuvFileFrameGenerator(
std::vector<std::string> files,
std::vector<std::string> filenames,
size_t width,
size_t height,
int frame_repeat_count);

// Creates a frame generator that repeatedly plays an ivf file.
std::unique_ptr<FrameGeneratorInterface> CreateFromIvfFileFrameGenerator(
std::string file);
std::string filename);

// Creates a frame generator which takes a set of yuv files (wrapping a
// frame generator created by CreateFromYuvFile() above), but outputs frames
Expand Down
1 change: 1 addition & 0 deletions call/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ if (rtc_include_tests) {
":rtp_sender",
":simulated_network",
"../api:array_view",
"../api:create_frame_generator",
"../api:mock_audio_mixer",
"../api:rtp_headers",
"../api:rtp_parameters",
Expand Down
5 changes: 3 additions & 2 deletions call/bitrate_estimator_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <memory>
#include <string>

#include "api/test/create_frame_generator.h"
#include "call/call.h"
#include "call/fake_network_pipe.h"
#include "call/simulated_network.h"
Expand Down Expand Up @@ -180,8 +181,8 @@ class BitrateEstimatorTest : public test::CallTest {
frame_generator_capturer_ =
std::make_unique<test::FrameGeneratorCapturer>(
test->clock_,
test::FrameGenerator::CreateSquareGenerator(
kDefaultWidth, kDefaultHeight, absl::nullopt, absl::nullopt),
test::CreateSquareFrameGenerator(kDefaultWidth, kDefaultHeight,
absl::nullopt, absl::nullopt),
kDefaultFramerate, *test->task_queue_factory_);
frame_generator_capturer_->Init();
send_stream_->SetSource(frame_generator_capturer_.get(),
Expand Down
1 change: 0 additions & 1 deletion call/call_perf_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "test/encoder_settings.h"
#include "test/fake_encoder.h"
#include "test/field_trial.h"
#include "test/frame_generator.h"
#include "test/frame_generator_capturer.h"
#include "test/gtest.h"
#include "test/null_transport.h"
Expand Down
1 change: 1 addition & 0 deletions common_video/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_base_tests_utils",
"../system_wrappers:system_wrappers",
"../test:fileutils",
"../test:frame_utils",
"../test:test_main",
"../test:test_support",
"../test:video_test_common",
Expand Down
2 changes: 1 addition & 1 deletion media/engine/webrtc_video_engine_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#include "rtc_base/time_utils.h"
#include "test/fake_decoder.h"
#include "test/field_trial.h"
#include "test/frame_generator.h"
#include "test/frame_forwarder.h"
#include "test/gmock.h"
#include "test/rtp_header_parser.h"

Expand Down
1 change: 1 addition & 0 deletions modules/video_capture/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ if (!build_with_chromium) {
"../../common_video",
"../../rtc_base:rtc_base_approved",
"../../system_wrappers",
"../../test:frame_utils",
"../../test:test_support",
"../../test:video_test_common",
"../utility",
Expand Down
4 changes: 4 additions & 0 deletions modules/video_coding/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ if (rtc_include_tests) {
":videocodec_test_stats_impl",
":webrtc_vp9_helpers",
"..:module_api",
"../../api:create_frame_generator",
"../../api:frame_generator_api",
"../../api:scoped_refptr",
"../../api:videocodec_test_fixture_api",
"../../api/task_queue",
Expand Down Expand Up @@ -759,7 +761,9 @@ if (rtc_include_tests) {
":webrtc_vp9",
":webrtc_vp9_helpers",
"../..:webrtc_common",
"../../api:create_frame_generator",
"../../api:create_videocodec_test_fixture_api",
"../../api:frame_generator_api",
"../../api:mock_video_codec_factory",
"../../api:mock_video_decoder",
"../../api:mock_video_encoder",
Expand Down
7 changes: 4 additions & 3 deletions modules/video_coding/codecs/test/video_codec_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <utility>

#include "api/test/create_frame_generator.h"
#include "api/video_codecs/video_encoder.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/video_coding/include/video_error_codes.h"
Expand Down Expand Up @@ -73,9 +74,9 @@ void VideoCodecUnitTest::SetUp() {

ModifyCodecSettings(&codec_settings_);

input_frame_generator_ = test::FrameGenerator::CreateSquareGenerator(
input_frame_generator_ = test::CreateSquareFrameGenerator(
codec_settings_.width, codec_settings_.height,
test::FrameGenerator::OutputType::kI420, absl::optional<int>());
test::FrameGeneratorInterface::OutputType::kI420, absl::optional<int>());

encoder_ = CreateEncoder();
decoder_ = CreateDecoder();
Expand All @@ -94,7 +95,7 @@ void VideoCodecUnitTest::SetUp() {
void VideoCodecUnitTest::ModifyCodecSettings(VideoCodec* codec_settings) {}

VideoFrame VideoCodecUnitTest::NextInputFrame() {
test::FrameGenerator::VideoFrameData frame_data =
test::FrameGeneratorInterface::VideoFrameData frame_data =
input_frame_generator_->NextFrame();
VideoFrame input_frame = VideoFrame::Builder()
.set_video_frame_buffer(frame_data.buffer)
Expand Down
4 changes: 2 additions & 2 deletions modules/video_coding/codecs/test/video_codec_unittest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <memory>
#include <vector>

#include "api/test/frame_generator_interface.h"
#include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_encoder.h"
#include "modules/video_coding/include/video_codec_interface.h"
Expand All @@ -22,7 +23,6 @@
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/thread_annotations.h"
#include "test/frame_generator.h"
#include "test/gtest.h"

namespace webrtc {
Expand Down Expand Up @@ -101,7 +101,7 @@ class VideoCodecUnitTest : public ::testing::Test {

std::unique_ptr<VideoEncoder> encoder_;
std::unique_ptr<VideoDecoder> decoder_;
std::unique_ptr<test::FrameGenerator> input_frame_generator_;
std::unique_ptr<test::FrameGeneratorInterface> input_frame_generator_;

private:
FakeEncodeCompleteCallback encode_complete_callback_;
Expand Down
6 changes: 4 additions & 2 deletions modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <memory>

#include "api/test/create_frame_generator.h"
#include "api/test/frame_generator_interface.h"
#include "api/test/mock_video_decoder.h"
#include "api/test/mock_video_encoder.h"
#include "api/video_codecs/video_encoder.h"
Expand Down Expand Up @@ -487,9 +489,9 @@ TEST_F(TestVp8Impl, DontDropKeyframes) {

// Reset the frame generator with large number of squares, leading to lots of
// details and high probability of overshoot.
input_frame_generator_ = test::FrameGenerator::CreateSquareGenerator(
input_frame_generator_ = test::CreateSquareFrameGenerator(
codec_settings_.width, codec_settings_.height,
test::FrameGenerator::OutputType::kI420,
test::FrameGeneratorInterface::OutputType::kI420,
/* num_squares = */ absl::optional<int>(300));

EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
Expand Down
7 changes: 5 additions & 2 deletions modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/

#include "api/test/create_frame_generator.h"
#include "api/test/frame_generator_interface.h"
#include "api/video/color_space.h"
#include "api/video/i420_buffer.h"
#include "api/video_codecs/video_encoder.h"
Expand Down Expand Up @@ -1616,9 +1618,10 @@ class TestVp9ImplProfile2 : public TestVp9Impl {
return;

TestVp9Impl::SetUp();
input_frame_generator_ = test::FrameGenerator::CreateSquareGenerator(
input_frame_generator_ = test::CreateSquareFrameGenerator(
codec_settings_.width, codec_settings_.height,
test::FrameGenerator::OutputType::kI010, absl::optional<int>());
test::FrameGeneratorInterface::OutputType::kI010,
absl::optional<int>());
}

std::unique_ptr<VideoEncoder> CreateEncoder() override {
Expand Down
1 change: 1 addition & 0 deletions modules/video_processing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ if (rtc_include_tests) {
"../../api/video:video_rtp_headers",
"../../common_video",
"../../test:fileutils",
"../../test:frame_utils",
"../../test:test_support",
"../../test:video_test_common",
]
Expand Down
1 change: 1 addition & 0 deletions pc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ if (rtc_include_tests) {
":peerconnection",
":rtc_pc_base",
"../api:audio_options_api",
"../api:create_frame_generator",
"../api:create_peerconnection_factory",
"../api:libjingle_peerconnection_api",
"../api:media_stream_interface",
Expand Down
7 changes: 4 additions & 3 deletions pc/test/frame_generator_capturer_video_track_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/test/create_frame_generator.h"
#include "pc/video_track_source.h"
#include "test/frame_generator_capturer.h"

Expand Down Expand Up @@ -47,9 +48,9 @@ class FrameGeneratorCapturerVideoTrackSource : public VideoTrackSource {
is_screencast_(is_screencast) {
video_capturer_ = std::make_unique<test::FrameGeneratorCapturer>(
clock,
test::FrameGenerator::CreateSquareGenerator(
config.width, config.height, absl::nullopt,
config.num_squares_generated),
test::CreateSquareFrameGenerator(config.width, config.height,
absl::nullopt,
config.num_squares_generated),
config.frames_per_second, *task_queue_factory_);
video_capturer_->Init();
}
Expand Down
1 change: 1 addition & 0 deletions rtc_tools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ if (!build_with_chromium) {
]

deps = [
"../api:create_frame_generator",
"../api:rtp_parameters",
"../api:transport_api",
"../api/rtc_event_log",
Expand Down
7 changes: 4 additions & 3 deletions rtc_tools/rtp_generator/rtp_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <utility>

#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/create_frame_generator.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_codecs/video_encoder.h"
Expand Down Expand Up @@ -224,9 +225,9 @@ RtpGenerator::RtpGenerator(const RtpGeneratorOptions& options)
std::unique_ptr<test::FrameGeneratorCapturer> frame_generator =
std::make_unique<test::FrameGeneratorCapturer>(
Clock::GetRealTimeClock(),
test::FrameGenerator::CreateSquareGenerator(
send_config.video_width, send_config.video_height,
absl::nullopt, absl::nullopt),
test::CreateSquareFrameGenerator(send_config.video_width,
send_config.video_height,
absl::nullopt, absl::nullopt),
send_config.video_fps, *task_queue_);
frame_generator->Init();

Expand Down
1 change: 0 additions & 1 deletion rtc_tools/rtp_generator/rtp_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "call/video_send_stream.h"
#include "media/engine/webrtc_video_engine.h"
#include "rtc_base/constructor_magic.h"
#include "test/frame_generator.h"
#include "test/frame_generator_capturer.h"
#include "test/rtp_file_reader.h"
#include "test/rtp_file_writer.h"
Expand Down
Loading

0 comments on commit 33f9d2b

Please sign in to comment.