Delete ortc methods using cricket::VideoCapturer.

For testing, introduce new class FakePeriodicVideoSource.

Bug: webrtc:6353
Change-Id: I234dbd4176ea23d21b8f876ee02d3662477f225e
Reviewed-on: https://webrtc-review.googlesource.com/49220
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22554}
This commit is contained in:
Niels Möller
2018-03-21 09:20:21 +01:00
committed by Commit Bot
parent 0d44625b8f
commit 48cca02799
7 changed files with 105 additions and 59 deletions

View File

@ -215,20 +215,6 @@ class OrtcFactoryInterface {
return CreateAudioSource(cricket::AudioOptions());
}
// Creates a video source object wrapping and taking ownership of |capturer|.
//
// |constraints| can be used for selection of resolution and frame rate, and
// may be null if no constraints are desired.
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> capturer,
const MediaConstraintsInterface* constraints) = 0;
// Version of the above method that omits |constraints|.
rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> capturer) {
return CreateVideoSource(std::move(capturer), nullptr);
}
// Creates a new local video track wrapping |source|. The same |source| can
// be used in several tracks.
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(

View File

@ -87,6 +87,7 @@ if (rtc_include_tests) {
"../p2p:p2p_test_utils",
"../p2p:rtc_p2p",
"../pc:pc_test_utils",
"../pc:peerconnection",
"../rtc_base:rtc_base",
"../rtc_base:rtc_base_approved",
"../rtc_base:rtc_base_tests_main",

View File

@ -32,7 +32,6 @@
#include "pc/audiotrack.h"
#include "pc/channelmanager.h"
#include "pc/localaudiosource.h"
#include "pc/videocapturertracksource.h"
#include "pc/videotrack.h"
#include "rtc_base/asyncpacketsocket.h"
#include "rtc_base/bind.h"
@ -114,10 +113,6 @@ PROXY_WORKER_METHOD3(RTCErrorOr<std::unique_ptr<UdpTransportInterface>>,
PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
CreateAudioSource,
const cricket::AudioOptions&)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackSourceInterface>,
CreateVideoSource,
std::unique_ptr<cricket::VideoCapturer>,
const MediaConstraintsInterface*)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
CreateVideoTrack,
const std::string&,
@ -480,17 +475,6 @@ rtc::scoped_refptr<AudioSourceInterface> OrtcFactory::CreateAudioSource(
LocalAudioSource::Create(&options));
}
rtc::scoped_refptr<VideoTrackSourceInterface> OrtcFactory::CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> capturer,
const MediaConstraintsInterface* constraints) {
RTC_DCHECK_RUN_ON(signaling_thread_);
rtc::scoped_refptr<VideoTrackSourceInterface> source(
VideoCapturerTrackSource::Create(
worker_thread_.get(), std::move(capturer), constraints, false));
return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_.get(),
source);
}
rtc::scoped_refptr<VideoTrackInterface> OrtcFactory::CreateVideoTrack(
const std::string& id,
VideoTrackSourceInterface* source) {

View File

@ -81,10 +81,6 @@ class OrtcFactory : public OrtcFactoryInterface {
rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
const cricket::AudioOptions& options) override;
rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> capturer,
const MediaConstraintsInterface* constraints) override;
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
const std::string& id,
VideoTrackSourceInterface* source) override;

View File

@ -17,8 +17,9 @@
#include "ortc/testrtpparameters.h"
#include "p2p/base/udptransport.h"
#include "pc/test/fakeaudiocapturemodule.h"
#include "pc/test/fakeperiodicvideocapturer.h"
#include "pc/test/fakeperiodicvideosource.h"
#include "pc/test/fakevideotrackrenderer.h"
#include "pc/videotracksource.h"
#include "rtc_base/criticalsection.h"
#include "rtc_base/fakenetwork.h"
#include "rtc_base/gunit.h"
@ -28,6 +29,7 @@ namespace {
const int kDefaultTimeout = 10000; // 10 seconds.
const int kReceivingDuration = 1000; // 1 second.
// Default number of audio/video frames to wait for before considering a test a
// success.
const int kDefaultNumFrames = 3;
@ -217,18 +219,18 @@ class OrtcFactoryIntegrationTest : public testing::Test {
return ortc_factory->CreateAudioTrack(id, source);
}
// Stores created capturer in |fake_video_capturers_|.
// Stores created video source in |fake_video_sources_|.
rtc::scoped_refptr<webrtc::VideoTrackInterface>
CreateLocalVideoTrackAndFakeCapturer(const std::string& id,
OrtcFactoryInterface* ortc_factory) {
webrtc::FakePeriodicVideoCapturer* fake_capturer =
new webrtc::FakePeriodicVideoCapturer();
fake_video_capturers_.push_back(fake_capturer);
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
ortc_factory->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(fake_capturer));
return rtc::scoped_refptr<webrtc::VideoTrackInterface>(
ortc_factory->CreateVideoTrack(id, source));
CreateLocalVideoTrackAndFakeSource(const std::string& id,
OrtcFactoryInterface* ortc_factory) {
fake_video_sources_.emplace_back(
rtc::MakeUnique<FakePeriodicVideoSource>());
fake_video_track_sources_.emplace_back(
new rtc::RefCountedObject<VideoTrackSource>(
fake_video_sources_.back().get(), false /* remote */));
return rtc::scoped_refptr<VideoTrackInterface>(
ortc_factory->CreateVideoTrack(
id, fake_video_track_sources_.back()));
}
// Helper function used to test two way RTP senders and receivers with basic
@ -283,13 +285,13 @@ class OrtcFactoryIntegrationTest : public testing::Test {
CreateLocalAudioTrack("audio", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
error = video_sender1->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
CreateLocalVideoTrackAndFakeSource("video", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
error = audio_sender2->SetTrack(
CreateLocalAudioTrack("audio", ortc_factory2_.get()));
EXPECT_TRUE(error.ok());
error = video_sender2->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get()));
CreateLocalVideoTrackAndFakeSource("video", ortc_factory2_.get()));
EXPECT_TRUE(error.ok());
// "sent_X_parameters1" are the parameters that endpoint 1 sends with and
@ -350,8 +352,8 @@ class OrtcFactoryIntegrationTest : public testing::Test {
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module2_;
std::unique_ptr<OrtcFactoryInterface> ortc_factory1_;
std::unique_ptr<OrtcFactoryInterface> ortc_factory2_;
// Actually owned by video tracks.
std::vector<webrtc::FakePeriodicVideoCapturer*> fake_video_capturers_;
std::vector<std::unique_ptr<FakePeriodicVideoSource>> fake_video_sources_;
std::vector<rtc::scoped_refptr<VideoTrackSource>> fake_video_track_sources_;
int received_audio_frames1_ = 0;
int received_audio_frames2_ = 0;
int rendered_video_frames1_ = 0;
@ -415,7 +417,7 @@ TEST_F(OrtcFactoryIntegrationTest, BasicOneWayVideoRtpSenderAndReceiver) {
auto receiver = receiver_result.MoveValue();
RTCError error = sender->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
CreateLocalVideoTrackAndFakeSource("video", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
RtpParameters vp8_parameters = MakeMinimalVp8Parameters();
@ -450,7 +452,7 @@ TEST_F(OrtcFactoryIntegrationTest, SetTrackWhileSending) {
auto receiver = receiver_result.MoveValue();
RTCError error = sender->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video_1", ortc_factory1_.get()));
CreateLocalVideoTrackAndFakeSource("video_1", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
RtpParameters vp8_parameters = MakeMinimalVp8Parameters();
EXPECT_TRUE(receiver->Receive(vp8_parameters).ok());
@ -460,13 +462,15 @@ TEST_F(OrtcFactoryIntegrationTest, SetTrackWhileSending) {
// Expect for some initial number of frames to be received.
EXPECT_TRUE_WAIT(fake_renderer.num_rendered_frames() > kDefaultNumFrames,
kDefaultTimeout);
// Stop the old capturer, set a new track, and verify new frames are received
// from the new track. Stopping the old capturer ensures that we aren't
// actually still getting frames from it.
fake_video_capturers_[0]->StopFrameDelivery();
// Destroy old source, set a new track, and verify new frames are received
// from the new track. The VideoTrackSource is reference counted and may live
// a little longer, so tell it that its source is going away now.
fake_video_track_sources_[0]->OnSourceDestroyed();
fake_video_track_sources_[0] = nullptr;
fake_video_sources_[0].reset();
int prev_num_frames = fake_renderer.num_rendered_frames();
error = sender->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video_2", ortc_factory1_.get()));
CreateLocalVideoTrackAndFakeSource("video_2", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
EXPECT_TRUE_WAIT(
fake_renderer.num_rendered_frames() > kDefaultNumFrames + prev_num_frames,
@ -628,13 +632,13 @@ TEST_F(OrtcFactoryIntegrationTest,
CreateLocalAudioTrack("audio", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
error = video_sender1->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory1_.get()));
CreateLocalVideoTrackAndFakeSource("video", ortc_factory1_.get()));
EXPECT_TRUE(error.ok());
error = audio_sender2->SetTrack(
CreateLocalAudioTrack("audio", ortc_factory2_.get()));
EXPECT_TRUE(error.ok());
error = video_sender2->SetTrack(
CreateLocalVideoTrackAndFakeCapturer("video", ortc_factory2_.get()));
CreateLocalVideoTrackAndFakeSource("video", ortc_factory2_.get()));
EXPECT_TRUE(error.ok());
// Use different codecs in different directions for extra challenge.

View File

@ -347,6 +347,7 @@ if (rtc_include_tests) {
"test/fakepeerconnectionbase.h",
"test/fakepeerconnectionforstats.h",
"test/fakeperiodicvideocapturer.h",
"test/fakeperiodicvideosource.h",
"test/fakertccertificategenerator.h",
"test/fakesctptransport.h",
"test/faketransportcontroller.h",

View File

@ -0,0 +1,74 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PC_TEST_FAKEPERIODICVIDEOSOURCE_H_
#define PC_TEST_FAKEPERIODICVIDEOSOURCE_H_
#include "api/videosourceinterface.h"
#include "media/base/fakeframesource.h"
#include "media/base/videobroadcaster.h"
#include "rtc_base/task_queue.h"
namespace webrtc {
class FakePeriodicVideoSource final
: public rtc::VideoSourceInterface<VideoFrame> {
public:
static constexpr int kFrameIntervalMs = 33;
static constexpr int kWidth = 640;
static constexpr int kHeight = 480;
FakePeriodicVideoSource() {
thread_checker_.DetachFromThread();
task_queue_.PostTask(rtc::MakeUnique<FrameTask>(&broadcaster_));
}
void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
broadcaster_.RemoveSink(sink);
}
void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
const rtc::VideoSinkWants& wants) override {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
broadcaster_.AddOrUpdateSink(sink, wants);
}
private:
class FrameTask : public rtc::QueuedTask {
public:
explicit FrameTask(rtc::VideoSinkInterface<VideoFrame>* sink)
: frame_source_(kWidth,
kHeight,
kFrameIntervalMs * rtc::kNumMicrosecsPerMillisec),
sink_(sink) {}
bool Run() override {
sink_->OnFrame(frame_source_.GetFrame());
rtc::TaskQueue::Current()->PostDelayedTask(rtc::WrapUnique(this),
kFrameIntervalMs);
return false;
}
cricket::FakeFrameSource frame_source_;
rtc::VideoSinkInterface<VideoFrame>* sink_;
};
void OnFrame(const webrtc::VideoFrame& frame) { broadcaster_.OnFrame(frame); }
rtc::ThreadChecker thread_checker_;
rtc::VideoBroadcaster broadcaster_;
// Last member, depend on detruction order.
rtc::TaskQueue task_queue_{"FakePeriodicVideoTrackSource"};
};
} // namespace webrtc
#endif // PC_TEST_FAKEPERIODICVIDEOSOURCE_H_