blob: 0fc6af2557fcc6417f46e08da574c962e1dec9ec [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "pc/peerconnectionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
kwiberg0eb15ed2015-12-17 03:04:15 -080013#include <utility>
14
Ying Wang0dd1b0a2018-02-20 12:50:27 +010015#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/mediaconstraintsinterface.h"
17#include "api/mediastreamproxy.h"
18#include "api/mediastreamtrackproxy.h"
19#include "api/peerconnectionfactoryproxy.h"
20#include "api/peerconnectionproxy.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020021#include "api/turncustomizer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/videosourceproxy.h"
23#include "logging/rtc_event_log/rtc_event_log.h"
Steve Antonc9e15602017-11-06 15:40:09 -080024#include "media/base/rtpdataengine.h"
Steve Antonda6c0952017-10-23 11:41:54 -070025#include "media/sctp/sctptransport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/bind.h"
27#include "rtc_base/checks.h"
28#include "rtc_base/ptr_util.h"
Patrik Höglund42805f32018-01-18 19:15:38 +000029// Adding 'nogncheck' to disable the gn include headers check to support modular
30// WebRTC build targets.
31// TODO(zhihuang): This wouldn't be necessary if the interface and
32// implementation of the media engine were in separate build targets.
33#include "media/engine/webrtcmediaengine.h" // nogncheck
34#include "media/engine/webrtcvideodecoderfactory.h" // nogncheck
35#include "media/engine/webrtcvideoencoderfactory.h" // nogncheck
36#include "modules/audio_device/include/audio_device.h" // nogncheck
Sebastian Janssondfce03a2018-05-18 18:05:10 +020037#include "modules/congestion_controller/bbr/bbr_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "p2p/base/basicpacketsocketfactory.h"
39#include "p2p/client/basicportallocator.h"
40#include "pc/audiotrack.h"
41#include "pc/localaudiosource.h"
42#include "pc/mediastream.h"
43#include "pc/peerconnection.h"
44#include "pc/videocapturertracksource.h"
45#include "pc/videotrack.h"
Sebastian Janssondfce03a2018-05-18 18:05:10 +020046#include "rtc_base/experiments/congestion_controller_experiment.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048namespace webrtc {
49
kwiberg1e4e8cb2017-01-31 01:48:08 -080050rtc::scoped_refptr<PeerConnectionFactoryInterface>
zhihuang38ede132017-06-15 12:52:32 -070051CreateModularPeerConnectionFactory(
gyzhou95aa9642016-12-13 14:06:26 -080052 rtc::Thread* network_thread,
53 rtc::Thread* worker_thread,
54 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -070055 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
56 std::unique_ptr<CallFactoryInterface> call_factory,
57 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
Ying Wang0dd1b0a2018-02-20 12:50:27 +010058 return CreateModularPeerConnectionFactory(
59 network_thread, worker_thread, signaling_thread, std::move(media_engine),
Sebastian Janssondfce03a2018-05-18 18:05:10 +020060 std::move(call_factory), std::move(event_log_factory), nullptr, nullptr);
Ying Wang0dd1b0a2018-02-20 12:50:27 +010061}
62
63rtc::scoped_refptr<PeerConnectionFactoryInterface>
64CreateModularPeerConnectionFactory(
65 rtc::Thread* network_thread,
66 rtc::Thread* worker_thread,
67 rtc::Thread* signaling_thread,
68 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
69 std::unique_ptr<CallFactoryInterface> call_factory,
70 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
Sebastian Janssondfce03a2018-05-18 18:05:10 +020071 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
72 std::unique_ptr<NetworkControllerFactoryInterface>
73 network_controller_factory) {
gyzhou95aa9642016-12-13 14:06:26 -080074 rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
75 new rtc::RefCountedObject<PeerConnectionFactory>(
Magnus Jedvert835cc0c2017-09-23 16:14:25 +020076 network_thread, worker_thread, signaling_thread,
Magnus Jedvert02e7a192017-09-23 17:21:32 +020077 std::move(media_engine), std::move(call_factory),
Sebastian Janssondfce03a2018-05-18 18:05:10 +020078 std::move(event_log_factory), std::move(fec_controller_factory),
79 std::move(network_controller_factory)));
gyzhou95aa9642016-12-13 14:06:26 -080080
81 // Call Initialize synchronously but make sure it is executed on
82 // |signaling_thread|.
83 MethodCall0<PeerConnectionFactory, bool> call(
84 pc_factory.get(), &PeerConnectionFactory::Initialize);
zhihuang38ede132017-06-15 12:52:32 -070085 bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread());
gyzhou95aa9642016-12-13 14:06:26 -080086
87 if (!result) {
88 return nullptr;
89 }
zhihuang38ede132017-06-15 12:52:32 -070090 return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
91 pc_factory);
kwiberg1e4e8cb2017-01-31 01:48:08 -080092}
93
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094PeerConnectionFactory::PeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -070095 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000096 rtc::Thread* worker_thread,
97 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -070098 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
99 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
100 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100101 : PeerConnectionFactory(network_thread,
102 worker_thread,
103 signaling_thread,
104 std::move(media_engine),
105 std::move(call_factory),
106 std::move(event_log_factory),
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200107 nullptr,
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100108 nullptr) {}
109
110PeerConnectionFactory::PeerConnectionFactory(
111 rtc::Thread* network_thread,
112 rtc::Thread* worker_thread,
113 rtc::Thread* signaling_thread,
114 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
115 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
116 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200117 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
118 std::unique_ptr<NetworkControllerFactoryInterface>
119 network_controller_factory)
zhihuang38ede132017-06-15 12:52:32 -0700120 : wraps_current_thread_(false),
danilchape9021a32016-05-17 01:52:02 -0700121 network_thread_(network_thread),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 worker_thread_(worker_thread),
danilchape9021a32016-05-17 01:52:02 -0700123 signaling_thread_(signaling_thread),
zhihuang38ede132017-06-15 12:52:32 -0700124 media_engine_(std::move(media_engine)),
125 call_factory_(std::move(call_factory)),
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100126 event_log_factory_(std::move(event_log_factory)),
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200127 fec_controller_factory_(std::move(fec_controller_factory)),
128 injected_network_controller_factory_(
129 std::move(network_controller_factory)),
130 bbr_network_controller_factory_(
131 rtc::MakeUnique<BbrNetworkControllerFactory>()) {
zhihuang38ede132017-06-15 12:52:32 -0700132 if (!network_thread_) {
133 owned_network_thread_ = rtc::Thread::CreateWithSocketServer();
Sebastian Jansson13f35ec2017-11-13 10:54:45 +0100134 owned_network_thread_->SetName("pc_network_thread", nullptr);
zhihuang38ede132017-06-15 12:52:32 -0700135 owned_network_thread_->Start();
136 network_thread_ = owned_network_thread_.get();
137 }
138
139 if (!worker_thread_) {
140 owned_worker_thread_ = rtc::Thread::Create();
Sebastian Jansson13f35ec2017-11-13 10:54:45 +0100141 owned_worker_thread_->SetName("pc_worker_thread", nullptr);
zhihuang38ede132017-06-15 12:52:32 -0700142 owned_worker_thread_->Start();
143 worker_thread_ = owned_worker_thread_.get();
144 }
145
146 if (!signaling_thread_) {
147 signaling_thread_ = rtc::Thread::Current();
148 if (!signaling_thread_) {
149 // If this thread isn't already wrapped by an rtc::Thread, create a
150 // wrapper and own it in this class.
151 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
152 wraps_current_thread_ = true;
153 }
154 }
155
Steve Anton36b29d12017-10-30 09:57:42 -0700156 // TODO(deadbeef): Currently there is no way to create an external adm in
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 // libjingle source tree. So we can 't currently assert if this is NULL.
nisseede5da42017-01-12 05:15:36 -0800158 // RTC_DCHECK(default_adm != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159}
160
161PeerConnectionFactory::~PeerConnectionFactory() {
henrikg91d6ede2015-09-17 00:24:34 -0700162 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström5e56c592015-08-11 10:33:13 +0200163 channel_manager_.reset(nullptr);
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000164
165 // Make sure |worker_thread_| and |signaling_thread_| outlive
Henrik Boströmcebf0a22016-06-01 15:45:30 +0200166 // |default_socket_factory_| and |default_network_manager_|.
deadbeef41b07982015-12-01 15:01:24 -0800167 default_socket_factory_ = nullptr;
168 default_network_manager_ = nullptr;
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000169
zhihuang38ede132017-06-15 12:52:32 -0700170 if (wraps_current_thread_)
171 rtc::ThreadManager::Instance()->UnwrapCurrentThread();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172}
173
174bool PeerConnectionFactory::Initialize() {
henrikg91d6ede2015-09-17 00:24:34 -0700175 RTC_DCHECK(signaling_thread_->IsCurrent());
Honghai Zhang82d78622016-05-06 11:29:15 -0700176 rtc::InitRandom(rtc::Time32());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177
deadbeef41b07982015-12-01 15:01:24 -0800178 default_network_manager_.reset(new rtc::BasicNetworkManager());
179 if (!default_network_manager_) {
180 return false;
181 }
182
183 default_socket_factory_.reset(
danilchape9021a32016-05-17 01:52:02 -0700184 new rtc::BasicPacketSocketFactory(network_thread_));
deadbeef41b07982015-12-01 15:01:24 -0800185 if (!default_socket_factory_) {
186 return false;
187 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188
Steve Antonc9e15602017-11-06 15:40:09 -0800189 channel_manager_ = rtc::MakeUnique<cricket::ChannelManager>(
190 std::move(media_engine_), rtc::MakeUnique<cricket::RtpDataEngine>(),
191 worker_thread_, network_thread_);
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000192
stefan@webrtc.org85d27942014-06-09 12:51:39 +0000193 channel_manager_->SetVideoRtxEnabled(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 if (!channel_manager_->Init()) {
195 return false;
196 }
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000197
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 return true;
199}
200
jbauchcb560652016-08-04 05:20:32 -0700201void PeerConnectionFactory::SetOptions(const Options& options) {
202 options_ = options;
jbauchcb560652016-08-04 05:20:32 -0700203}
204
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000205rtc::scoped_refptr<AudioSourceInterface>
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000206PeerConnectionFactory::CreateAudioSource(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 const MediaConstraintsInterface* constraints) {
henrikg91d6ede2015-09-17 00:24:34 -0700208 RTC_DCHECK(signaling_thread_->IsCurrent());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000209 rtc::scoped_refptr<LocalAudioSource> source(
deadbeef757146b2017-02-10 21:26:48 -0800210 LocalAudioSource::Create(constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 return source;
212}
213
htaa2a49d92016-03-04 02:51:39 -0800214rtc::scoped_refptr<AudioSourceInterface>
215PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) {
216 RTC_DCHECK(signaling_thread_->IsCurrent());
217 rtc::scoped_refptr<LocalAudioSource> source(
deadbeef757146b2017-02-10 21:26:48 -0800218 LocalAudioSource::Create(&options));
htaa2a49d92016-03-04 02:51:39 -0800219 return source;
220}
221
perkja3ede6c2016-03-08 01:27:48 +0100222rtc::scoped_refptr<VideoTrackSourceInterface>
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000223PeerConnectionFactory::CreateVideoSource(
deadbeef112b2e92017-02-10 20:13:37 -0800224 std::unique_ptr<cricket::VideoCapturer> capturer,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 const MediaConstraintsInterface* constraints) {
henrikg91d6ede2015-09-17 00:24:34 -0700226 RTC_DCHECK(signaling_thread_->IsCurrent());
perkja3ede6c2016-03-08 01:27:48 +0100227 rtc::scoped_refptr<VideoTrackSourceInterface> source(
deadbeef112b2e92017-02-10 20:13:37 -0800228 VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer),
229 constraints, false));
nisse5b68ab52016-04-07 07:45:54 -0700230 return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_,
231 source);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232}
233
perkja3ede6c2016-03-08 01:27:48 +0100234rtc::scoped_refptr<VideoTrackSourceInterface>
deadbeef112b2e92017-02-10 20:13:37 -0800235PeerConnectionFactory::CreateVideoSource(
236 std::unique_ptr<cricket::VideoCapturer> capturer) {
htaa2a49d92016-03-04 02:51:39 -0800237 RTC_DCHECK(signaling_thread_->IsCurrent());
perkja3ede6c2016-03-08 01:27:48 +0100238 rtc::scoped_refptr<VideoTrackSourceInterface> source(
deadbeef112b2e92017-02-10 20:13:37 -0800239 VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer),
240 false));
nisse5b68ab52016-04-07 07:45:54 -0700241 return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_,
242 source);
htaa2a49d92016-03-04 02:51:39 -0800243}
244
ivocd66b44d2016-01-15 03:06:36 -0800245bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file,
246 int64_t max_size_bytes) {
henrikg91d6ede2015-09-17 00:24:34 -0700247 RTC_DCHECK(signaling_thread_->IsCurrent());
ivocd66b44d2016-01-15 03:06:36 -0800248 return channel_manager_->StartAecDump(file, max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000249}
250
ivoc797ef122015-10-22 03:25:41 -0700251void PeerConnectionFactory::StopAecDump() {
252 RTC_DCHECK(signaling_thread_->IsCurrent());
253 channel_manager_->StopAecDump();
254}
255
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257PeerConnectionFactory::CreatePeerConnection(
htaa2a49d92016-03-04 02:51:39 -0800258 const PeerConnectionInterface::RTCConfiguration& configuration_in,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 const MediaConstraintsInterface* constraints,
kwibergd1fe2812016-04-27 06:47:29 -0700260 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200261 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef41b07982015-12-01 15:01:24 -0800262 PeerConnectionObserver* observer) {
263 RTC_DCHECK(signaling_thread_->IsCurrent());
264
htaa2a49d92016-03-04 02:51:39 -0800265 // We merge constraints and configuration into a single configuration.
266 PeerConnectionInterface::RTCConfiguration configuration = configuration_in;
267 CopyConstraintsIntoRtcConfiguration(constraints, &configuration);
268
269 return CreatePeerConnection(configuration, std::move(allocator),
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200270 std::move(cert_generator), observer);
htaa2a49d92016-03-04 02:51:39 -0800271}
272
273rtc::scoped_refptr<PeerConnectionInterface>
274PeerConnectionFactory::CreatePeerConnection(
275 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -0700276 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200277 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
htaa2a49d92016-03-04 02:51:39 -0800278 PeerConnectionObserver* observer) {
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700279 // Convert the legacy API into the new depnedency structure.
280 PeerConnectionDependencies dependencies(observer);
281 dependencies.allocator = std::move(allocator);
282 dependencies.cert_generator = std::move(cert_generator);
283 // Pass that into the new API.
284 return CreatePeerConnection(configuration, std::move(dependencies));
285}
286
287rtc::scoped_refptr<PeerConnectionInterface>
288PeerConnectionFactory::CreatePeerConnection(
289 const PeerConnectionInterface::RTCConfiguration& configuration,
290 PeerConnectionDependencies dependencies) {
htaa2a49d92016-03-04 02:51:39 -0800291 RTC_DCHECK(signaling_thread_->IsCurrent());
292
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700293 // Set internal defaults if optional dependencies are not set.
294 if (!dependencies.cert_generator) {
295 dependencies.cert_generator = rtc::MakeUnique<rtc::RTCCertificateGenerator>(
296 signaling_thread_, network_thread_);
deadbeef41b07982015-12-01 15:01:24 -0800297 }
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700298 if (!dependencies.allocator) {
299 dependencies.allocator.reset(new cricket::BasicPortAllocator(
Jonas Orelandbdcee282017-10-10 14:01:40 +0200300 default_network_manager_.get(), default_socket_factory_.get(),
301 configuration.turn_customizer));
jonasoc251cb12017-08-29 03:20:58 -0700302 }
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700303
jonasoc251cb12017-08-29 03:20:58 -0700304 network_thread_->Invoke<void>(
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700305 RTC_FROM_HERE,
306 rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
307 dependencies.allocator.get(), options_.network_ignore_mask));
jonasoc251cb12017-08-29 03:20:58 -0700308
eladalon393a9f62017-09-05 04:30:30 -0700309 std::unique_ptr<RtcEventLog> event_log =
eladalon248fd4f2017-09-06 05:18:15 -0700310 worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>(
311 RTC_FROM_HERE,
312 rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this));
maxmorine9ef9072017-08-29 04:49:00 -0700313
zhihuang38ede132017-06-15 12:52:32 -0700314 std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>(
315 RTC_FROM_HERE,
316 rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get()));
317
deadbeef41b07982015-12-01 15:01:24 -0800318 rtc::scoped_refptr<PeerConnection> pc(
zhihuang38ede132017-06-15 12:52:32 -0700319 new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
320 std::move(call)));
htaa2a49d92016-03-04 02:51:39 -0800321
Benjamin Wrightcab58882018-05-02 15:12:47 -0700322 if (!pc->Initialize(configuration, std::move(dependencies))) {
deadbeef41b07982015-12-01 15:01:24 -0800323 return nullptr;
324 }
325 return PeerConnectionProxy::Create(signaling_thread(), pc);
326}
327
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000328rtc::scoped_refptr<MediaStreamInterface>
Seth Hampson845e8782018-03-02 11:34:10 -0800329PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) {
henrikg91d6ede2015-09-17 00:24:34 -0700330 RTC_DCHECK(signaling_thread_->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 return MediaStreamProxy::Create(signaling_thread_,
Seth Hampson845e8782018-03-02 11:34:10 -0800332 MediaStream::Create(stream_id));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333}
334
perkja3ede6c2016-03-08 01:27:48 +0100335rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 const std::string& id,
perkja3ede6c2016-03-08 01:27:48 +0100337 VideoTrackSourceInterface* source) {
henrikg91d6ede2015-09-17 00:24:34 -0700338 RTC_DCHECK(signaling_thread_->IsCurrent());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000339 rtc::scoped_refptr<VideoTrackInterface> track(
perkj773be362017-07-31 23:22:01 -0700340 VideoTrack::Create(id, source, worker_thread_));
nisse5b68ab52016-04-07 07:45:54 -0700341 return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342}
343
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000344rtc::scoped_refptr<AudioTrackInterface>
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000345PeerConnectionFactory::CreateAudioTrack(const std::string& id,
346 AudioSourceInterface* source) {
henrikg91d6ede2015-09-17 00:24:34 -0700347 RTC_DCHECK(signaling_thread_->IsCurrent());
tommi6eca7e32015-12-15 04:27:11 -0800348 rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 return AudioTrackProxy::Create(signaling_thread_, track);
350}
351
Steve Antonda6c0952017-10-23 11:41:54 -0700352std::unique_ptr<cricket::SctpTransportInternalFactory>
353PeerConnectionFactory::CreateSctpTransportInternalFactory() {
354#ifdef HAVE_SCTP
355 return rtc::MakeUnique<cricket::SctpTransportFactory>(network_thread());
356#else
357 return nullptr;
358#endif
359}
360
nisseeaabdf62017-05-05 02:23:02 -0700361cricket::ChannelManager* PeerConnectionFactory::channel_manager() {
362 return channel_manager_.get();
363}
364
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365rtc::Thread* PeerConnectionFactory::signaling_thread() {
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000366 // This method can be called on a different thread when the factory is
367 // created in CreatePeerConnectionFactory().
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 return signaling_thread_;
369}
370
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000371rtc::Thread* PeerConnectionFactory::worker_thread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 return worker_thread_;
373}
374
danilchape9021a32016-05-17 01:52:02 -0700375rtc::Thread* PeerConnectionFactory::network_thread() {
376 return network_thread_;
377}
378
eladalon248fd4f2017-09-06 05:18:15 -0700379std::unique_ptr<RtcEventLog> PeerConnectionFactory::CreateRtcEventLog_w() {
eladalon591753b2017-09-06 12:33:43 -0700380 RTC_DCHECK_RUN_ON(worker_thread_);
Elad Alon4a87e1c2017-10-03 16:11:34 +0200381 const auto encoding_type = RtcEventLog::EncodingType::Legacy;
382 return event_log_factory_
383 ? event_log_factory_->CreateRtcEventLog(encoding_type)
384 : rtc::MakeUnique<RtcEventLogNullImpl>();
eladalon248fd4f2017-09-06 05:18:15 -0700385}
386
zhihuang38ede132017-06-15 12:52:32 -0700387std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
388 RtcEventLog* event_log) {
eladalon591753b2017-09-06 12:33:43 -0700389 RTC_DCHECK_RUN_ON(worker_thread_);
390
zhihuang38ede132017-06-15 12:52:32 -0700391 const int kMinBandwidthBps = 30000;
392 const int kStartBandwidthBps = 300000;
393 const int kMaxBandwidthBps = 2000000;
394
395 webrtc::Call::Config call_config(event_log);
396 if (!channel_manager_->media_engine() || !call_factory_) {
397 return nullptr;
398 }
399 call_config.audio_state = channel_manager_->media_engine()->GetAudioState();
400 call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
401 call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
402 call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
403
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100404 call_config.fec_controller_factory = fec_controller_factory_.get();
405
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200406 if (CongestionControllerExperiment::BbrControllerEnabled()) {
407 RTC_LOG(LS_INFO) << "Using BBR network controller factory";
408 call_config.network_controller_factory =
409 bbr_network_controller_factory_.get();
410 } else if (CongestionControllerExperiment::InjectedControllerEnabled()) {
411 RTC_LOG(LS_INFO) << "Using injected network controller factory";
412 call_config.network_controller_factory =
413 injected_network_controller_factory_.get();
414 } else {
415 RTC_LOG(LS_INFO) << "Using default network controller factory";
416 }
417
zhihuang38ede132017-06-15 12:52:32 -0700418 return std::unique_ptr<Call>(call_factory_->CreateCall(call_config));
419}
420
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421} // namespace webrtc