New PeerConnectionFactory::CreateVideoTrack with refcounted source

Bug: webrtc:15017
Change-Id: I04c794d8959583bb4cc5c3898f4175783ec49f16
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249363
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39635}
This commit is contained in:
Harald Alvestrand 2023-03-20 14:13:42 +00:00 committed by WebRTC LUCI CQ
parent 3e224c7fe1
commit 041ecb87f5
21 changed files with 48 additions and 40 deletions

View file

@ -1552,9 +1552,18 @@ class RTC_EXPORT PeerConnectionFactoryInterface
// Creates a new local VideoTrack. The same `source` can be used in several
// tracks.
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
rtc::scoped_refptr<VideoTrackSourceInterface> source,
absl::string_view label) = 0;
// TODO(bugs.webrtc.org/15017): Deprecate this function once Chrome
// has been updated - it can't land as deprecated.
// ABSL_DEPRECATED("Use version with scoped_refptr")
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
const std::string& label,
VideoTrackSourceInterface* source) = 0;
VideoTrackSourceInterface* source) {
return CreateVideoTrack(
rtc::scoped_refptr<VideoTrackSourceInterface>(source), label);
}
// Creates an new AudioTrack. At the moment `source` can be null.
virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(

View file

@ -65,6 +65,11 @@ class MockPeerConnectionFactoryInterface
CreateVideoTrack,
(const std::string&, VideoTrackSourceInterface*),
(override));
MOCK_METHOD(rtc::scoped_refptr<VideoTrackInterface>,
CreateVideoTrack,
(rtc::scoped_refptr<VideoTrackSourceInterface>,
absl::string_view),
(override));
MOCK_METHOD(rtc::scoped_refptr<AudioTrackInterface>,
CreateAudioTrack,
(const std::string&, AudioSourceInterface*),

View file

@ -186,8 +186,8 @@ void AndroidCallClient::CreatePeerConnection() {
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track(
pcf_->CreateVideoTrack("video", video_source_.get()));
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
pcf_->CreateVideoTrack(video_source_, "video");
local_video_track->AddOrUpdateSink(local_sink_.get(), rtc::VideoSinkWants());
pc_->AddTransceiver(local_video_track);
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();

View file

@ -149,7 +149,7 @@ void ObjCCallClient::CreatePeerConnection() {
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
pcf_->CreateVideoTrack("video", video_source_.get());
pcf_->CreateVideoTrack(video_source_, "video");
pc_->AddTransceiver(local_video_track);
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();

View file

@ -468,8 +468,7 @@ void Conductor::AddTracks() {
CapturerTrackSource::Create();
if (video_device) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
peer_connection_factory_->CreateVideoTrack(kVideoLabel,
video_device.get()));
peer_connection_factory_->CreateVideoTrack(video_device, kVideoLabel));
main_wnd_->StartLocalRenderer(video_track_.get());
result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId});

View file

@ -460,16 +460,15 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
g_camera = (jobject)env->NewGlobalRef(camera_tmp);
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
source.release()));
g_peer_connection_factory->CreateVideoTrack(source, kVideoLabel));
stream->AddTrack(video_track);
#else
rtc::scoped_refptr<CapturerTrackSource> video_device =
CapturerTrackSource::Create();
if (video_device) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
video_device.get()));
g_peer_connection_factory->CreateVideoTrack(video_device,
kVideoLabel));
stream->AddTrack(video_track);
}

View file

@ -64,7 +64,7 @@ TrackWithPeriodicSource CreateTrackWithPeriodicSource(
periodic_track_source_config, /* remote */ false);
TrackWithPeriodicSource track_with_source;
track_with_source.track =
factory->CreateVideoTrack("PeriodicTrack", periodic_track_source.get());
factory->CreateVideoTrack(periodic_track_source, "PeriodicTrack");
track_with_source.periodic_track_source = periodic_track_source;
return track_with_source;
}

View file

@ -273,12 +273,11 @@ PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) {
}
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
const std::string& id,
VideoTrackSourceInterface* source) {
rtc::scoped_refptr<VideoTrackSourceInterface> source,
absl::string_view id) {
RTC_DCHECK(signaling_thread()->IsCurrent());
rtc::scoped_refptr<VideoTrackInterface> track = VideoTrack::Create(
id, rtc::scoped_refptr<VideoTrackSourceInterface>(source),
worker_thread());
rtc::scoped_refptr<VideoTrackInterface> track =
VideoTrack::Create(id, source, worker_thread());
return VideoTrackProxy::Create(signaling_thread(), worker_thread(), track);
}

View file

@ -85,8 +85,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
const cricket::AudioOptions& options) override;
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
const std::string& id,
VideoTrackSourceInterface* video_source) override;
rtc::scoped_refptr<VideoTrackSourceInterface> video_source,
absl::string_view id) override;
rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
const std::string& id,

View file

@ -43,8 +43,8 @@ PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
const cricket::AudioOptions&)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
CreateVideoTrack,
const std::string&,
VideoTrackSourceInterface*)
rtc::scoped_refptr<VideoTrackSourceInterface>,
absl::string_view)
PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
CreateAudioTrack,
const std::string&,

View file

@ -567,7 +567,7 @@ TEST_F(PeerConnectionFactoryTest, LocalRendering) {
ASSERT_TRUE(source.get() != NULL);
rtc::scoped_refptr<VideoTrackInterface> track(
factory_->CreateVideoTrack("testlabel", source.get()));
factory_->CreateVideoTrack(source, "testlabel"));
ASSERT_TRUE(track.get() != NULL);
FakeVideoTrackRenderer local_renderer(track.get());

View file

@ -237,8 +237,7 @@ TEST_F(PeerConnectionFieldTrialTest, ApplyFakeNetworkConfig) {
auto video_track_source =
rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
config, clock_, /*is_screencast=*/false);
caller->AddTrack(
pc_factory_->CreateVideoTrack("v", video_track_source.get()));
caller->AddTrack(pc_factory_->CreateVideoTrack(video_track_source, "v"));
WrapperPtr callee = CreatePeerConnection();
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));

View file

@ -814,8 +814,7 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
const std::string& label) {
return pc_factory_->CreateVideoTrack(label,
FakeVideoTrackSource::Create().get());
return pc_factory_->CreateVideoTrack(FakeVideoTrackSource::Create(), label);
}
void AddVideoTrack(const std::string& track_label,

View file

@ -127,8 +127,8 @@ class PeerConnectionWrapperForRampUpTest : public PeerConnectionWrapper {
config, clock, /*is_screencast=*/false));
video_track_sources_.back()->Start();
return rtc::scoped_refptr<VideoTrackInterface>(
pc_factory()->CreateVideoTrack(rtc::CreateRandomUuid(),
video_track_sources_.back().get()));
pc_factory()->CreateVideoTrack(video_track_sources_.back(),
rtc::CreateRandomUuid()));
}
rtc::scoped_refptr<AudioTrackInterface> CreateLocalAudioTrack(

View file

@ -277,8 +277,7 @@ rtc::scoped_refptr<AudioTrackInterface> PeerConnectionWrapper::CreateAudioTrack(
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionWrapper::CreateVideoTrack(
const std::string& label) {
return pc_factory()->CreateVideoTrack(label,
FakeVideoTrackSource::Create().get());
return pc_factory()->CreateVideoTrack(FakeVideoTrackSource::Create(), label);
}
rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddTrack(

View file

@ -868,9 +868,9 @@ class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver,
video_track_sources_.emplace_back(
rtc::make_ref_counted<webrtc::FakePeriodicVideoTrackSource>(
config, false /* remote */));
rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
peer_connection_factory_->CreateVideoTrack(
rtc::CreateRandomUuid(), video_track_sources_.back().get()));
rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
peer_connection_factory_->CreateVideoTrack(video_track_sources_.back(),
rtc::CreateRandomUuid());
if (!local_video_renderer_) {
local_video_renderer_.reset(
new webrtc::FakeVideoTrackRenderer(track.get()));

View file

@ -350,8 +350,7 @@ PeerConnectionTestWrapper::GetUserMedia(
std::string videotrack_label = stream_id + kVideoTrackLabelBase;
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
peer_connection_factory_->CreateVideoTrack(videotrack_label,
source.get()));
peer_connection_factory_->CreateVideoTrack(source, videotrack_label));
stream->AddTrack(video_track);
}

View file

@ -487,8 +487,9 @@ static jlong JNI_PeerConnectionFactory_CreateVideoTrack(
rtc::scoped_refptr<VideoTrackInterface> track =
PeerConnectionFactoryFromJava(native_factory)
->CreateVideoTrack(
JavaToStdString(jni, id),
reinterpret_cast<VideoTrackSourceInterface*>(native_source));
rtc::scoped_refptr<VideoTrackSourceInterface>(
reinterpret_cast<VideoTrackSourceInterface*>(native_source)),
JavaToStdString(jni, id));
return jlongFromPointer(track.release());
}

View file

@ -31,7 +31,7 @@
NSParameterAssert(trackId.length);
std::string nativeId = [NSString stdStringForString:trackId];
rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
factory.nativeFactory->CreateVideoTrack(nativeId, source.nativeVideoSource.get());
factory.nativeFactory->CreateVideoTrack(source.nativeVideoSource, nativeId);
if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeVideo]) {
_source = source;
}

View file

@ -64,8 +64,8 @@ MediaHelper::MaybeAddVideo(TestPeer* peer) {
RTC_LOG(LS_INFO) << "Adding video with video_config.stream_label="
<< video_config.stream_label.value();
rtc::scoped_refptr<VideoTrackInterface> track =
peer->pc_factory()->CreateVideoTrack(video_config.stream_label.value(),
source.get());
peer->pc_factory()->CreateVideoTrack(source,
video_config.stream_label.value());
if (video_config.content_hint.has_value()) {
track->set_content_hint(video_config.content_hint.value());
}

View file

@ -323,7 +323,7 @@ PeerScenarioClient::VideoSendTrack PeerScenarioClient::CreateVideo(
capturer->Init();
res.source = rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
std::move(capturer), config.screencast);
auto track = pc_factory_->CreateVideoTrack(track_id, res.source.get());
auto track = pc_factory_->CreateVideoTrack(res.source, track_id);
res.track = track.get();
res.sender =
peer_connection_->AddTrack(track, {kCommonStreamId}).MoveValue().get();