mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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:
parent
3e224c7fe1
commit
041ecb87f5
21 changed files with 48 additions and 40 deletions
|
@ -1552,9 +1552,18 @@ class RTC_EXPORT PeerConnectionFactoryInterface
|
||||||
|
|
||||||
// Creates a new local VideoTrack. The same `source` can be used in several
|
// Creates a new local VideoTrack. The same `source` can be used in several
|
||||||
// tracks.
|
// 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(
|
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
||||||
const std::string& label,
|
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.
|
// Creates an new AudioTrack. At the moment `source` can be null.
|
||||||
virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
|
virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
|
||||||
|
|
|
@ -65,6 +65,11 @@ class MockPeerConnectionFactoryInterface
|
||||||
CreateVideoTrack,
|
CreateVideoTrack,
|
||||||
(const std::string&, VideoTrackSourceInterface*),
|
(const std::string&, VideoTrackSourceInterface*),
|
||||||
(override));
|
(override));
|
||||||
|
MOCK_METHOD(rtc::scoped_refptr<VideoTrackInterface>,
|
||||||
|
CreateVideoTrack,
|
||||||
|
(rtc::scoped_refptr<VideoTrackSourceInterface>,
|
||||||
|
absl::string_view),
|
||||||
|
(override));
|
||||||
MOCK_METHOD(rtc::scoped_refptr<AudioTrackInterface>,
|
MOCK_METHOD(rtc::scoped_refptr<AudioTrackInterface>,
|
||||||
CreateAudioTrack,
|
CreateAudioTrack,
|
||||||
(const std::string&, AudioSourceInterface*),
|
(const std::string&, AudioSourceInterface*),
|
||||||
|
|
|
@ -186,8 +186,8 @@ void AndroidCallClient::CreatePeerConnection() {
|
||||||
|
|
||||||
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
|
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
|
||||||
pcf_->CreateVideoTrack("video", video_source_.get()));
|
pcf_->CreateVideoTrack(video_source_, "video");
|
||||||
local_video_track->AddOrUpdateSink(local_sink_.get(), rtc::VideoSinkWants());
|
local_video_track->AddOrUpdateSink(local_sink_.get(), rtc::VideoSinkWants());
|
||||||
pc_->AddTransceiver(local_video_track);
|
pc_->AddTransceiver(local_video_track);
|
||||||
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
|
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
|
||||||
|
|
|
@ -149,7 +149,7 @@ void ObjCCallClient::CreatePeerConnection() {
|
||||||
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
|
RTC_LOG(LS_INFO) << "PeerConnection created: " << pc_.get();
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> local_video_track =
|
||||||
pcf_->CreateVideoTrack("video", video_source_.get());
|
pcf_->CreateVideoTrack(video_source_, "video");
|
||||||
pc_->AddTransceiver(local_video_track);
|
pc_->AddTransceiver(local_video_track);
|
||||||
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
|
RTC_LOG(LS_INFO) << "Local video sink set up: " << local_video_track.get();
|
||||||
|
|
||||||
|
|
|
@ -468,8 +468,7 @@ void Conductor::AddTracks() {
|
||||||
CapturerTrackSource::Create();
|
CapturerTrackSource::Create();
|
||||||
if (video_device) {
|
if (video_device) {
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track_(
|
||||||
peer_connection_factory_->CreateVideoTrack(kVideoLabel,
|
peer_connection_factory_->CreateVideoTrack(video_device, kVideoLabel));
|
||||||
video_device.get()));
|
|
||||||
main_wnd_->StartLocalRenderer(video_track_.get());
|
main_wnd_->StartLocalRenderer(video_track_.get());
|
||||||
|
|
||||||
result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId});
|
result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId});
|
||||||
|
|
|
@ -460,16 +460,15 @@ void SimplePeerConnection::AddStreams(bool audio_only) {
|
||||||
g_camera = (jobject)env->NewGlobalRef(camera_tmp);
|
g_camera = (jobject)env->NewGlobalRef(camera_tmp);
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
||||||
g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
|
g_peer_connection_factory->CreateVideoTrack(source, kVideoLabel));
|
||||||
source.release()));
|
|
||||||
stream->AddTrack(video_track);
|
stream->AddTrack(video_track);
|
||||||
#else
|
#else
|
||||||
rtc::scoped_refptr<CapturerTrackSource> video_device =
|
rtc::scoped_refptr<CapturerTrackSource> video_device =
|
||||||
CapturerTrackSource::Create();
|
CapturerTrackSource::Create();
|
||||||
if (video_device) {
|
if (video_device) {
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
||||||
g_peer_connection_factory->CreateVideoTrack(kVideoLabel,
|
g_peer_connection_factory->CreateVideoTrack(video_device,
|
||||||
video_device.get()));
|
kVideoLabel));
|
||||||
|
|
||||||
stream->AddTrack(video_track);
|
stream->AddTrack(video_track);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ TrackWithPeriodicSource CreateTrackWithPeriodicSource(
|
||||||
periodic_track_source_config, /* remote */ false);
|
periodic_track_source_config, /* remote */ false);
|
||||||
TrackWithPeriodicSource track_with_source;
|
TrackWithPeriodicSource track_with_source;
|
||||||
track_with_source.track =
|
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;
|
track_with_source.periodic_track_source = periodic_track_source;
|
||||||
return track_with_source;
|
return track_with_source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,12 +273,11 @@ PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
|
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
|
||||||
const std::string& id,
|
rtc::scoped_refptr<VideoTrackSourceInterface> source,
|
||||||
VideoTrackSourceInterface* source) {
|
absl::string_view id) {
|
||||||
RTC_DCHECK(signaling_thread()->IsCurrent());
|
RTC_DCHECK(signaling_thread()->IsCurrent());
|
||||||
rtc::scoped_refptr<VideoTrackInterface> track = VideoTrack::Create(
|
rtc::scoped_refptr<VideoTrackInterface> track =
|
||||||
id, rtc::scoped_refptr<VideoTrackSourceInterface>(source),
|
VideoTrack::Create(id, source, worker_thread());
|
||||||
worker_thread());
|
|
||||||
return VideoTrackProxy::Create(signaling_thread(), worker_thread(), track);
|
return VideoTrackProxy::Create(signaling_thread(), worker_thread(), track);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,8 +85,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
|
||||||
const cricket::AudioOptions& options) override;
|
const cricket::AudioOptions& options) override;
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
||||||
const std::string& id,
|
rtc::scoped_refptr<VideoTrackSourceInterface> video_source,
|
||||||
VideoTrackSourceInterface* video_source) override;
|
absl::string_view id) override;
|
||||||
|
|
||||||
rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
|
rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
|
||||||
const std::string& id,
|
const std::string& id,
|
||||||
|
|
|
@ -43,8 +43,8 @@ PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
|
||||||
const cricket::AudioOptions&)
|
const cricket::AudioOptions&)
|
||||||
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
|
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
|
||||||
CreateVideoTrack,
|
CreateVideoTrack,
|
||||||
const std::string&,
|
rtc::scoped_refptr<VideoTrackSourceInterface>,
|
||||||
VideoTrackSourceInterface*)
|
absl::string_view)
|
||||||
PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
|
PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>,
|
||||||
CreateAudioTrack,
|
CreateAudioTrack,
|
||||||
const std::string&,
|
const std::string&,
|
||||||
|
|
|
@ -567,7 +567,7 @@ TEST_F(PeerConnectionFactoryTest, LocalRendering) {
|
||||||
|
|
||||||
ASSERT_TRUE(source.get() != NULL);
|
ASSERT_TRUE(source.get() != NULL);
|
||||||
rtc::scoped_refptr<VideoTrackInterface> track(
|
rtc::scoped_refptr<VideoTrackInterface> track(
|
||||||
factory_->CreateVideoTrack("testlabel", source.get()));
|
factory_->CreateVideoTrack(source, "testlabel"));
|
||||||
ASSERT_TRUE(track.get() != NULL);
|
ASSERT_TRUE(track.get() != NULL);
|
||||||
FakeVideoTrackRenderer local_renderer(track.get());
|
FakeVideoTrackRenderer local_renderer(track.get());
|
||||||
|
|
||||||
|
|
|
@ -237,8 +237,7 @@ TEST_F(PeerConnectionFieldTrialTest, ApplyFakeNetworkConfig) {
|
||||||
auto video_track_source =
|
auto video_track_source =
|
||||||
rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
|
rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
|
||||||
config, clock_, /*is_screencast=*/false);
|
config, clock_, /*is_screencast=*/false);
|
||||||
caller->AddTrack(
|
caller->AddTrack(pc_factory_->CreateVideoTrack(video_track_source, "v"));
|
||||||
pc_factory_->CreateVideoTrack("v", video_track_source.get()));
|
|
||||||
WrapperPtr callee = CreatePeerConnection();
|
WrapperPtr callee = CreatePeerConnection();
|
||||||
|
|
||||||
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
|
ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
|
||||||
|
|
|
@ -814,8 +814,7 @@ class PeerConnectionInterfaceBaseTest : public ::testing::Test {
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
|
||||||
const std::string& label) {
|
const std::string& label) {
|
||||||
return pc_factory_->CreateVideoTrack(label,
|
return pc_factory_->CreateVideoTrack(FakeVideoTrackSource::Create(), label);
|
||||||
FakeVideoTrackSource::Create().get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddVideoTrack(const std::string& track_label,
|
void AddVideoTrack(const std::string& track_label,
|
||||||
|
|
|
@ -127,8 +127,8 @@ class PeerConnectionWrapperForRampUpTest : public PeerConnectionWrapper {
|
||||||
config, clock, /*is_screencast=*/false));
|
config, clock, /*is_screencast=*/false));
|
||||||
video_track_sources_.back()->Start();
|
video_track_sources_.back()->Start();
|
||||||
return rtc::scoped_refptr<VideoTrackInterface>(
|
return rtc::scoped_refptr<VideoTrackInterface>(
|
||||||
pc_factory()->CreateVideoTrack(rtc::CreateRandomUuid(),
|
pc_factory()->CreateVideoTrack(video_track_sources_.back(),
|
||||||
video_track_sources_.back().get()));
|
rtc::CreateRandomUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<AudioTrackInterface> CreateLocalAudioTrack(
|
rtc::scoped_refptr<AudioTrackInterface> CreateLocalAudioTrack(
|
||||||
|
|
|
@ -277,8 +277,7 @@ rtc::scoped_refptr<AudioTrackInterface> PeerConnectionWrapper::CreateAudioTrack(
|
||||||
|
|
||||||
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionWrapper::CreateVideoTrack(
|
rtc::scoped_refptr<VideoTrackInterface> PeerConnectionWrapper::CreateVideoTrack(
|
||||||
const std::string& label) {
|
const std::string& label) {
|
||||||
return pc_factory()->CreateVideoTrack(label,
|
return pc_factory()->CreateVideoTrack(FakeVideoTrackSource::Create(), label);
|
||||||
FakeVideoTrackSource::Create().get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddTrack(
|
rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddTrack(
|
||||||
|
|
|
@ -868,9 +868,9 @@ class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver,
|
||||||
video_track_sources_.emplace_back(
|
video_track_sources_.emplace_back(
|
||||||
rtc::make_ref_counted<webrtc::FakePeriodicVideoTrackSource>(
|
rtc::make_ref_counted<webrtc::FakePeriodicVideoTrackSource>(
|
||||||
config, false /* remote */));
|
config, false /* remote */));
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
|
||||||
peer_connection_factory_->CreateVideoTrack(
|
peer_connection_factory_->CreateVideoTrack(video_track_sources_.back(),
|
||||||
rtc::CreateRandomUuid(), video_track_sources_.back().get()));
|
rtc::CreateRandomUuid());
|
||||||
if (!local_video_renderer_) {
|
if (!local_video_renderer_) {
|
||||||
local_video_renderer_.reset(
|
local_video_renderer_.reset(
|
||||||
new webrtc::FakeVideoTrackRenderer(track.get()));
|
new webrtc::FakeVideoTrackRenderer(track.get()));
|
||||||
|
|
|
@ -350,8 +350,7 @@ PeerConnectionTestWrapper::GetUserMedia(
|
||||||
|
|
||||||
std::string videotrack_label = stream_id + kVideoTrackLabelBase;
|
std::string videotrack_label = stream_id + kVideoTrackLabelBase;
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
|
||||||
peer_connection_factory_->CreateVideoTrack(videotrack_label,
|
peer_connection_factory_->CreateVideoTrack(source, videotrack_label));
|
||||||
source.get()));
|
|
||||||
|
|
||||||
stream->AddTrack(video_track);
|
stream->AddTrack(video_track);
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,8 +487,9 @@ static jlong JNI_PeerConnectionFactory_CreateVideoTrack(
|
||||||
rtc::scoped_refptr<VideoTrackInterface> track =
|
rtc::scoped_refptr<VideoTrackInterface> track =
|
||||||
PeerConnectionFactoryFromJava(native_factory)
|
PeerConnectionFactoryFromJava(native_factory)
|
||||||
->CreateVideoTrack(
|
->CreateVideoTrack(
|
||||||
JavaToStdString(jni, id),
|
rtc::scoped_refptr<VideoTrackSourceInterface>(
|
||||||
reinterpret_cast<VideoTrackSourceInterface*>(native_source));
|
reinterpret_cast<VideoTrackSourceInterface*>(native_source)),
|
||||||
|
JavaToStdString(jni, id));
|
||||||
return jlongFromPointer(track.release());
|
return jlongFromPointer(track.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
NSParameterAssert(trackId.length);
|
NSParameterAssert(trackId.length);
|
||||||
std::string nativeId = [NSString stdStringForString:trackId];
|
std::string nativeId = [NSString stdStringForString:trackId];
|
||||||
rtc::scoped_refptr<webrtc::VideoTrackInterface> track =
|
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]) {
|
if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeVideo]) {
|
||||||
_source = source;
|
_source = source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ MediaHelper::MaybeAddVideo(TestPeer* peer) {
|
||||||
RTC_LOG(LS_INFO) << "Adding video with video_config.stream_label="
|
RTC_LOG(LS_INFO) << "Adding video with video_config.stream_label="
|
||||||
<< video_config.stream_label.value();
|
<< video_config.stream_label.value();
|
||||||
rtc::scoped_refptr<VideoTrackInterface> track =
|
rtc::scoped_refptr<VideoTrackInterface> track =
|
||||||
peer->pc_factory()->CreateVideoTrack(video_config.stream_label.value(),
|
peer->pc_factory()->CreateVideoTrack(source,
|
||||||
source.get());
|
video_config.stream_label.value());
|
||||||
if (video_config.content_hint.has_value()) {
|
if (video_config.content_hint.has_value()) {
|
||||||
track->set_content_hint(video_config.content_hint.value());
|
track->set_content_hint(video_config.content_hint.value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,7 +323,7 @@ PeerScenarioClient::VideoSendTrack PeerScenarioClient::CreateVideo(
|
||||||
capturer->Init();
|
capturer->Init();
|
||||||
res.source = rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
|
res.source = rtc::make_ref_counted<FrameGeneratorCapturerVideoTrackSource>(
|
||||||
std::move(capturer), config.screencast);
|
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.track = track.get();
|
||||||
res.sender =
|
res.sender =
|
||||||
peer_connection_->AddTrack(track, {kCommonStreamId}).MoveValue().get();
|
peer_connection_->AddTrack(track, {kCommonStreamId}).MoveValue().get();
|
||||||
|
|
Loading…
Reference in a new issue