Use VideoSourceInterface for owning test video sources

CallTest, VideoQualityTest and VideoAnalyzer used test::TestVideoCapturer
as an interface for video sources. Change to use VideoSourceInterface instead,
since that's all they need.

This is a preparation for making test::VcmCapturer usable as a
VideoTrackSource, and replace use of cricket::VideoCapturer in example code.

Bug: webrtc:6353
Change-Id: I445f5f6f9b7342230b89f53a5722df9c9e92834f
Reviewed-on: https://webrtc-review.googlesource.com/c/114881
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26047}
This commit is contained in:
Niels Möller 2018-12-18 16:08:11 +01:00 committed by Commit Bot
parent f0d031240c
commit 1c931c4f00
8 changed files with 49 additions and 54 deletions

View File

@ -47,15 +47,13 @@ struct RTC_EXPORT VideoSinkWants {
template <typename VideoFrameT>
class VideoSourceInterface {
public:
virtual ~VideoSourceInterface() = default;
virtual void AddOrUpdateSink(VideoSinkInterface<VideoFrameT>* sink,
const VideoSinkWants& wants) = 0;
// RemoveSink must guarantee that at the time the method returns,
// there is no current and no future calls to VideoSinkInterface::OnFrame.
virtual void RemoveSink(VideoSinkInterface<VideoFrameT>* sink) = 0;
protected:
// Non-public, since one shouldn't own sources via this interface.
virtual ~VideoSourceInterface() {}
};
} // namespace rtc

View File

@ -63,7 +63,7 @@ CallTest::~CallTest() {
task_queue_.SendTask([this]() {
fake_send_audio_device_ = nullptr;
fake_recv_audio_device_ = nullptr;
video_capturers_.clear();
video_sources_.clear();
});
}
@ -454,12 +454,10 @@ void CallTest::CreateFrameGeneratorCapturerWithDrift(Clock* clock,
int width,
int height) {
video_sources_.clear();
video_capturers_.clear();
frame_generator_capturer_ = test::FrameGeneratorCapturer::Create(
width, height, absl::nullopt, absl::nullopt, framerate * speed, clock);
video_capturers_.emplace_back(
video_sources_.emplace_back(
std::unique_ptr<FrameGeneratorCapturer>(frame_generator_capturer_));
video_sources_.push_back(video_capturers_.back().get());
ConnectVideoSourcesToStreams();
}
@ -467,12 +465,10 @@ void CallTest::CreateFrameGeneratorCapturer(int framerate,
int width,
int height) {
video_sources_.clear();
video_capturers_.clear();
frame_generator_capturer_ = test::FrameGeneratorCapturer::Create(
width, height, absl::nullopt, absl::nullopt, framerate, clock_);
video_capturers_.emplace_back(
video_sources_.emplace_back(
std::unique_ptr<FrameGeneratorCapturer>(frame_generator_capturer_));
video_sources_.push_back(video_capturers_.back().get());
ConnectVideoSourcesToStreams();
}
@ -560,7 +556,7 @@ void CallTest::CreateFlexfecStreams() {
void CallTest::ConnectVideoSourcesToStreams() {
for (size_t i = 0; i < video_sources_.size(); ++i)
video_send_streams_[i]->SetSource(video_sources_[i],
video_send_streams_[i]->SetSource(video_sources_[i].get(),
degradation_preference_);
}

View File

@ -192,8 +192,8 @@ class CallTest : public ::testing::Test {
std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
test::FrameGeneratorCapturer* frame_generator_capturer_;
std::vector<rtc::VideoSourceInterface<VideoFrame>*> video_sources_;
std::vector<std::unique_ptr<TestVideoCapturer>> video_capturers_;
std::vector<std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>>
video_sources_;
DegradationPreference degradation_preference_ =
DegradationPreference::MAINTAIN_FRAMERATE;

View File

@ -240,8 +240,10 @@ if (rtc_include_tests) {
"../api:video_quality_test_fixture_api",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:video_bitrate_allocator_factory",
"../api/video:video_frame",
"../call:fake_network",
"../call:simulated_network",
"../common_video",
"../logging:rtc_event_log_api",
"../logging:rtc_event_log_impl_output",
"../media:rtc_audio_video",

View File

@ -12,6 +12,7 @@
#include <algorithm>
#include <utility>
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "modules/rtp_rtcp/source/rtp_format.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "rtc_base/cpu_time.h"
@ -138,12 +139,13 @@ void VideoAnalyzer::SetReceiver(PacketReceiver* receiver) {
receiver_ = receiver;
}
void VideoAnalyzer::SetSource(test::TestVideoCapturer* video_capturer,
bool respect_sink_wants) {
void VideoAnalyzer::SetSource(
rtc::VideoSourceInterface<VideoFrame>* video_source,
bool respect_sink_wants) {
if (respect_sink_wants)
captured_frame_forwarder_.SetSource(video_capturer);
captured_frame_forwarder_.SetSource(video_source);
rtc::VideoSinkWants wants;
video_capturer->AddOrUpdateSink(InputInterface(), wants);
video_source->AddOrUpdateSink(InputInterface(), wants);
}
void VideoAnalyzer::SetCall(Call* call) {
@ -841,12 +843,12 @@ VideoAnalyzer::CapturedFrameForwarder::CapturedFrameForwarder(
Clock* clock)
: analyzer_(analyzer),
send_stream_input_(nullptr),
video_capturer_(nullptr),
video_source_(nullptr),
clock_(clock) {}
void VideoAnalyzer::CapturedFrameForwarder::SetSource(
test::TestVideoCapturer* video_capturer) {
video_capturer_ = video_capturer;
VideoSourceInterface<VideoFrame>* video_source) {
video_source_ = video_source;
}
void VideoAnalyzer::CapturedFrameForwarder::OnFrame(
@ -872,8 +874,8 @@ void VideoAnalyzer::CapturedFrameForwarder::AddOrUpdateSink(
RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
send_stream_input_ = sink;
}
if (video_capturer_) {
video_capturer_->AddOrUpdateSink(this, wants);
if (video_source_) {
video_source_->AddOrUpdateSink(this, wants);
}
}

View File

@ -16,10 +16,10 @@
#include <string>
#include <vector>
#include "api/video/video_source_interface.h"
#include "test/layer_filtering_transport.h"
#include "test/rtp_file_writer.h"
#include "test/statistics.h"
#include "test/vcm_capturer.h"
namespace webrtc {
@ -45,7 +45,7 @@ class VideoAnalyzer : public PacketReceiver,
~VideoAnalyzer();
virtual void SetReceiver(PacketReceiver* receiver);
void SetSource(test::TestVideoCapturer* video_capturer,
void SetSource(rtc::VideoSourceInterface<VideoFrame>* video_source,
bool respect_sink_wants);
void SetCall(Call* call);
void SetSendStream(VideoSendStream* stream);
@ -136,7 +136,7 @@ class VideoAnalyzer : public PacketReceiver,
public rtc::VideoSourceInterface<VideoFrame> {
public:
explicit CapturedFrameForwarder(VideoAnalyzer* analyzer, Clock* clock);
void SetSource(test::TestVideoCapturer* video_capturer);
void SetSource(rtc::VideoSourceInterface<VideoFrame>* video_source);
private:
void OnFrame(const VideoFrame& video_frame) override;
@ -152,7 +152,7 @@ class VideoAnalyzer : public PacketReceiver,
rtc::CriticalSection crit_;
rtc::VideoSinkInterface<VideoFrame>* send_stream_input_
RTC_GUARDED_BY(crit_);
test::TestVideoCapturer* video_capturer_;
VideoSourceInterface<VideoFrame>* video_source_;
Clock* clock_;
};

View File

@ -36,6 +36,7 @@
#include "rtc_base/strings/string_builder.h"
#include "test/run_loop.h"
#include "test/testsupport/fileutils.h"
#include "test/vcm_capturer.h"
#include "test/video_renderer.h"
#include "video/frame_dumping_decoder.h"
#ifdef WEBRTC_WIN
@ -823,9 +824,9 @@ void VideoQualityTest::DestroyThumbnailStreams() {
}
thumbnail_send_streams_.clear();
thumbnail_receive_streams_.clear();
for (std::unique_ptr<test::TestVideoCapturer>& video_caputurer :
for (std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>& video_capturer :
thumbnail_capturers_) {
video_caputurer.reset();
video_capturer.reset();
}
}
@ -887,8 +888,7 @@ std::unique_ptr<test::FrameGenerator> VideoQualityTest::CreateFrameGenerator(
void VideoQualityTest::CreateCapturers() {
RTC_DCHECK(video_sources_.empty());
RTC_DCHECK(video_capturers_.empty());
video_capturers_.resize(num_video_streams_);
video_sources_.resize(num_video_streams_);
for (size_t video_idx = 0; video_idx < num_video_streams_; ++video_idx) {
if (params_.screenshare[video_idx].enabled) {
std::unique_ptr<test::FrameGenerator> frame_generator =
@ -897,53 +897,50 @@ void VideoQualityTest::CreateCapturers() {
new test::FrameGeneratorCapturer(clock_, std::move(frame_generator),
params_.video[video_idx].fps);
EXPECT_TRUE(frame_generator_capturer->Init());
video_capturers_[video_idx].reset(frame_generator_capturer);
video_sources_[video_idx].reset(frame_generator_capturer);
} else {
if (params_.video[video_idx].clip_name == "Generator") {
video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create(
video_sources_[video_idx].reset(test::FrameGeneratorCapturer::Create(
static_cast<int>(params_.video[video_idx].width),
static_cast<int>(params_.video[video_idx].height), absl::nullopt,
absl::nullopt, params_.video[video_idx].fps, clock_));
} else if (params_.video[video_idx].clip_name == "GeneratorI420A") {
video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create(
video_sources_[video_idx].reset(test::FrameGeneratorCapturer::Create(
static_cast<int>(params_.video[video_idx].width),
static_cast<int>(params_.video[video_idx].height),
test::FrameGenerator::OutputType::I420A, absl::nullopt,
params_.video[video_idx].fps, clock_));
} else if (params_.video[video_idx].clip_name == "GeneratorI010") {
video_capturers_[video_idx].reset(test::FrameGeneratorCapturer::Create(
video_sources_[video_idx].reset(test::FrameGeneratorCapturer::Create(
static_cast<int>(params_.video[video_idx].width),
static_cast<int>(params_.video[video_idx].height),
test::FrameGenerator::OutputType::I010, absl::nullopt,
params_.video[video_idx].fps, clock_));
} else if (params_.video[video_idx].clip_name.empty()) {
video_capturers_[video_idx].reset(test::VcmCapturer::Create(
video_sources_[video_idx].reset(test::VcmCapturer::Create(
params_.video[video_idx].width, params_.video[video_idx].height,
params_.video[video_idx].fps,
params_.video[video_idx].capture_device_index));
if (!video_capturers_[video_idx]) {
if (!video_sources_[video_idx]) {
// Failed to get actual camera, use chroma generator as backup.
video_capturers_[video_idx].reset(
test::FrameGeneratorCapturer::Create(
static_cast<int>(params_.video[video_idx].width),
static_cast<int>(params_.video[video_idx].height),
absl::nullopt, absl::nullopt, params_.video[video_idx].fps,
clock_));
video_sources_[video_idx].reset(test::FrameGeneratorCapturer::Create(
static_cast<int>(params_.video[video_idx].width),
static_cast<int>(params_.video[video_idx].height), absl::nullopt,
absl::nullopt, params_.video[video_idx].fps, clock_));
}
} else {
video_capturers_[video_idx].reset(
video_sources_[video_idx].reset(
test::FrameGeneratorCapturer::CreateFromYuvFile(
test::ResourcePath(params_.video[video_idx].clip_name, "yuv"),
params_.video[video_idx].width, params_.video[video_idx].height,
params_.video[video_idx].fps, clock_));
ASSERT_TRUE(video_capturers_[video_idx])
ASSERT_TRUE(video_sources_[video_idx])
<< "Could not create capturer for "
<< params_.video[video_idx].clip_name
<< ".yuv. Is this resource file present?";
}
}
RTC_DCHECK(video_capturers_[video_idx].get());
video_sources_.push_back(video_capturers_[video_idx].get());
RTC_DCHECK(video_sources_[video_idx]);
}
}
@ -1102,12 +1099,11 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) {
CreateCapturers();
analyzer_->SetSource(video_capturers_[0].get(),
params_.ss[0].infer_streams);
analyzer_->SetSource(video_sources_[0].get(), params_.ss[0].infer_streams);
for (size_t video_idx = 1; video_idx < num_video_streams_; ++video_idx) {
video_send_streams_[video_idx]->SetSource(
video_capturers_[video_idx].get(), degradation_preference_);
video_send_streams_[video_idx]->SetSource(video_sources_[video_idx].get(),
degradation_preference_);
}
if (params_.audio.enabled) {
@ -1132,7 +1128,7 @@ void VideoQualityTest::RunWithAnalyzer(const Params& params) {
if (graph_data_output_file)
fclose(graph_data_output_file);
video_capturers_.clear();
video_sources_.clear();
send_transport.reset();
recv_transport.reset();
@ -1350,7 +1346,7 @@ void VideoQualityTest::RunWithRenderers(const Params& params) {
Stop();
DestroyStreams();
video_capturers_.clear();
video_sources_.clear();
send_transport.reset();
recv_transport.reset();

View File

@ -97,7 +97,8 @@ class VideoQualityTest :
virtual std::unique_ptr<test::LayerFilteringTransport> CreateSendTransport();
virtual std::unique_ptr<test::DirectTransport> CreateReceiveTransport();
std::vector<std::unique_ptr<test::TestVideoCapturer>> thumbnail_capturers_;
std::vector<std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>>
thumbnail_capturers_;
Clock* const clock_;
test::FunctionVideoDecoderFactory video_decoder_factory_;