blob: 9fd8b73d66fef94572b27c3aab2aa525d4fe236a [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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "pc/peer_connection_factory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
kwiberg0eb15ed2015-12-17 03:04:15 -080013#include <utility>
Florent Castelli72b751a2018-06-28 14:09:33 +020014#include <vector>
kwiberg0eb15ed2015-12-17 03:04:15 -080015
Karl Wiberg918f50c2018-07-05 11:40:33 +020016#include "absl/memory/memory.h"
Ying Wang0dd1b0a2018-02-20 12:50:27 +010017#include "api/fec_controller.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/media_stream_proxy.h"
19#include "api/media_stream_track_proxy.h"
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070020#include "api/media_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/peer_connection_factory_proxy.h"
22#include "api/peer_connection_proxy.h"
23#include "api/turn_customizer.h"
24#include "api/video_track_source_proxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "logging/rtc_event_log/rtc_event_log.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "media/base/rtp_data_engine.h"
27#include "media/sctp/sctp_transport.h"
28#include "pc/rtp_parameters_conversion.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/bind.h"
30#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "p2p/base/basic_packet_socket_factory.h"
32#include "p2p/client/basic_port_allocator.h"
33#include "pc/audio_track.h"
34#include "pc/local_audio_source.h"
35#include "pc/media_stream.h"
36#include "pc/peer_connection.h"
Steve Anton10542f22019-01-11 09:11:00 -080037#include "pc/video_track.h"
Bjorn Tereliusb26cf2f2018-10-26 20:39:33 +020038#include "system_wrappers/include/field_trial.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040namespace webrtc {
41
kwiberg1e4e8cb2017-01-31 01:48:08 -080042rtc::scoped_refptr<PeerConnectionFactoryInterface>
zhihuang38ede132017-06-15 12:52:32 -070043CreateModularPeerConnectionFactory(
gyzhou95aa9642016-12-13 14:06:26 -080044 rtc::Thread* network_thread,
45 rtc::Thread* worker_thread,
46 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -070047 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
48 std::unique_ptr<CallFactoryInterface> call_factory,
49 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
Benjamin Wright5234a492018-05-29 15:04:32 -070050 PeerConnectionFactoryDependencies dependencies;
51 dependencies.network_thread = network_thread;
52 dependencies.worker_thread = worker_thread;
53 dependencies.signaling_thread = signaling_thread;
54 dependencies.media_engine = std::move(media_engine);
55 dependencies.call_factory = std::move(call_factory);
56 dependencies.event_log_factory = std::move(event_log_factory);
57 return CreateModularPeerConnectionFactory(std::move(dependencies));
Ying Wang0dd1b0a2018-02-20 12:50:27 +010058}
59
60rtc::scoped_refptr<PeerConnectionFactoryInterface>
61CreateModularPeerConnectionFactory(
62 rtc::Thread* network_thread,
63 rtc::Thread* worker_thread,
64 rtc::Thread* signaling_thread,
65 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
66 std::unique_ptr<CallFactoryInterface> call_factory,
67 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
Sebastian Janssondfce03a2018-05-18 18:05:10 +020068 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
69 std::unique_ptr<NetworkControllerFactoryInterface>
70 network_controller_factory) {
Benjamin Wright5234a492018-05-29 15:04:32 -070071 PeerConnectionFactoryDependencies dependencies;
72 dependencies.network_thread = network_thread;
73 dependencies.worker_thread = worker_thread;
74 dependencies.signaling_thread = signaling_thread;
75 dependencies.media_engine = std::move(media_engine);
76 dependencies.call_factory = std::move(call_factory);
77 dependencies.event_log_factory = std::move(event_log_factory);
78 dependencies.fec_controller_factory = std::move(fec_controller_factory);
79 dependencies.network_controller_factory =
80 std::move(network_controller_factory);
81 return CreateModularPeerConnectionFactory(std::move(dependencies));
82}
83
84rtc::scoped_refptr<PeerConnectionFactoryInterface>
85CreateModularPeerConnectionFactory(
86 PeerConnectionFactoryDependencies dependencies) {
gyzhou95aa9642016-12-13 14:06:26 -080087 rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
88 new rtc::RefCountedObject<PeerConnectionFactory>(
Benjamin Wright5234a492018-05-29 15:04:32 -070089 std::move(dependencies)));
gyzhou95aa9642016-12-13 14:06:26 -080090 // Call Initialize synchronously but make sure it is executed on
91 // |signaling_thread|.
92 MethodCall0<PeerConnectionFactory, bool> call(
93 pc_factory.get(), &PeerConnectionFactory::Initialize);
zhihuang38ede132017-06-15 12:52:32 -070094 bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread());
gyzhou95aa9642016-12-13 14:06:26 -080095
96 if (!result) {
97 return nullptr;
98 }
zhihuang38ede132017-06-15 12:52:32 -070099 return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
100 pc_factory);
kwiberg1e4e8cb2017-01-31 01:48:08 -0800101}
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103PeerConnectionFactory::PeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700104 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000105 rtc::Thread* worker_thread,
106 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700107 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
108 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
109 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100110 : PeerConnectionFactory(network_thread,
111 worker_thread,
112 signaling_thread,
113 std::move(media_engine),
114 std::move(call_factory),
115 std::move(event_log_factory),
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200116 nullptr,
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100117 nullptr) {}
118
119PeerConnectionFactory::PeerConnectionFactory(
120 rtc::Thread* network_thread,
121 rtc::Thread* worker_thread,
122 rtc::Thread* signaling_thread,
123 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
124 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
125 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200126 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
127 std::unique_ptr<NetworkControllerFactoryInterface>
128 network_controller_factory)
zhihuang38ede132017-06-15 12:52:32 -0700129 : wraps_current_thread_(false),
danilchape9021a32016-05-17 01:52:02 -0700130 network_thread_(network_thread),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 worker_thread_(worker_thread),
danilchape9021a32016-05-17 01:52:02 -0700132 signaling_thread_(signaling_thread),
zhihuang38ede132017-06-15 12:52:32 -0700133 media_engine_(std::move(media_engine)),
134 call_factory_(std::move(call_factory)),
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100135 event_log_factory_(std::move(event_log_factory)),
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200136 fec_controller_factory_(std::move(fec_controller_factory)),
137 injected_network_controller_factory_(
Sebastian Jansson7f577882018-12-20 09:46:29 +0100138 std::move(network_controller_factory)) {
zhihuang38ede132017-06-15 12:52:32 -0700139 if (!network_thread_) {
140 owned_network_thread_ = rtc::Thread::CreateWithSocketServer();
Sebastian Jansson13f35ec2017-11-13 10:54:45 +0100141 owned_network_thread_->SetName("pc_network_thread", nullptr);
zhihuang38ede132017-06-15 12:52:32 -0700142 owned_network_thread_->Start();
143 network_thread_ = owned_network_thread_.get();
144 }
145
146 if (!worker_thread_) {
147 owned_worker_thread_ = rtc::Thread::Create();
Sebastian Jansson13f35ec2017-11-13 10:54:45 +0100148 owned_worker_thread_->SetName("pc_worker_thread", nullptr);
zhihuang38ede132017-06-15 12:52:32 -0700149 owned_worker_thread_->Start();
150 worker_thread_ = owned_worker_thread_.get();
151 }
152
153 if (!signaling_thread_) {
154 signaling_thread_ = rtc::Thread::Current();
155 if (!signaling_thread_) {
156 // If this thread isn't already wrapped by an rtc::Thread, create a
157 // wrapper and own it in this class.
158 signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
159 wraps_current_thread_ = true;
160 }
161 }
162
Steve Anton36b29d12017-10-30 09:57:42 -0700163 // TODO(deadbeef): Currently there is no way to create an external adm in
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 // libjingle source tree. So we can 't currently assert if this is NULL.
nisseede5da42017-01-12 05:15:36 -0800165 // RTC_DCHECK(default_adm != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166}
167
Benjamin Wright5234a492018-05-29 15:04:32 -0700168PeerConnectionFactory::PeerConnectionFactory(
169 PeerConnectionFactoryDependencies dependencies)
170 : PeerConnectionFactory(
171 dependencies.network_thread,
172 dependencies.worker_thread,
173 dependencies.signaling_thread,
174 std::move(dependencies.media_engine),
175 std::move(dependencies.call_factory),
176 std::move(dependencies.event_log_factory),
177 std::move(dependencies.fec_controller_factory),
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700178 std::move(dependencies.network_controller_factory)) {
179 media_transport_factory_ = std::move(dependencies.media_transport_factory);
180}
Benjamin Wright5234a492018-05-29 15:04:32 -0700181
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182PeerConnectionFactory::~PeerConnectionFactory() {
henrikg91d6ede2015-09-17 00:24:34 -0700183 RTC_DCHECK(signaling_thread_->IsCurrent());
Henrik Boström5e56c592015-08-11 10:33:13 +0200184 channel_manager_.reset(nullptr);
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000185
186 // Make sure |worker_thread_| and |signaling_thread_| outlive
Henrik Boströmcebf0a22016-06-01 15:45:30 +0200187 // |default_socket_factory_| and |default_network_manager_|.
deadbeef41b07982015-12-01 15:01:24 -0800188 default_socket_factory_ = nullptr;
189 default_network_manager_ = nullptr;
jiayl@webrtc.orgd83f4ef2015-03-13 21:26:12 +0000190
zhihuang38ede132017-06-15 12:52:32 -0700191 if (wraps_current_thread_)
192 rtc::ThreadManager::Instance()->UnwrapCurrentThread();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193}
194
195bool PeerConnectionFactory::Initialize() {
henrikg91d6ede2015-09-17 00:24:34 -0700196 RTC_DCHECK(signaling_thread_->IsCurrent());
Honghai Zhang82d78622016-05-06 11:29:15 -0700197 rtc::InitRandom(rtc::Time32());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198
deadbeef41b07982015-12-01 15:01:24 -0800199 default_network_manager_.reset(new rtc::BasicNetworkManager());
200 if (!default_network_manager_) {
201 return false;
202 }
203
204 default_socket_factory_.reset(
danilchape9021a32016-05-17 01:52:02 -0700205 new rtc::BasicPacketSocketFactory(network_thread_));
deadbeef41b07982015-12-01 15:01:24 -0800206 if (!default_socket_factory_) {
207 return false;
208 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209
Karl Wiberg918f50c2018-07-05 11:40:33 +0200210 channel_manager_ = absl::make_unique<cricket::ChannelManager>(
211 std::move(media_engine_), absl::make_unique<cricket::RtpDataEngine>(),
Steve Antonc9e15602017-11-06 15:40:09 -0800212 worker_thread_, network_thread_);
henrika@webrtc.org62f6e752015-02-11 08:38:35 +0000213
stefan@webrtc.org85d27942014-06-09 12:51:39 +0000214 channel_manager_->SetVideoRtxEnabled(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 if (!channel_manager_->Init()) {
216 return false;
217 }
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000218
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 return true;
220}
221
jbauchcb560652016-08-04 05:20:32 -0700222void PeerConnectionFactory::SetOptions(const Options& options) {
223 options_ = options;
jbauchcb560652016-08-04 05:20:32 -0700224}
225
Florent Castelli72b751a2018-06-28 14:09:33 +0200226RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities(
227 cricket::MediaType kind) const {
228 RTC_DCHECK_RUN_ON(signaling_thread_);
229 switch (kind) {
230 case cricket::MEDIA_TYPE_AUDIO: {
231 cricket::AudioCodecs cricket_codecs;
232 cricket::RtpHeaderExtensions cricket_extensions;
233 channel_manager_->GetSupportedAudioSendCodecs(&cricket_codecs);
234 channel_manager_->GetSupportedAudioRtpHeaderExtensions(
235 &cricket_extensions);
236 return ToRtpCapabilities(cricket_codecs, cricket_extensions);
237 }
238 case cricket::MEDIA_TYPE_VIDEO: {
239 cricket::VideoCodecs cricket_codecs;
240 cricket::RtpHeaderExtensions cricket_extensions;
241 channel_manager_->GetSupportedVideoCodecs(&cricket_codecs);
242 channel_manager_->GetSupportedVideoRtpHeaderExtensions(
243 &cricket_extensions);
244 return ToRtpCapabilities(cricket_codecs, cricket_extensions);
245 }
246 case cricket::MEDIA_TYPE_DATA:
247 return RtpCapabilities();
248 }
249 // Not reached; avoids compile warning.
250 FATAL();
251}
252
253RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities(
254 cricket::MediaType kind) const {
255 RTC_DCHECK_RUN_ON(signaling_thread_);
256 switch (kind) {
257 case cricket::MEDIA_TYPE_AUDIO: {
258 cricket::AudioCodecs cricket_codecs;
259 cricket::RtpHeaderExtensions cricket_extensions;
260 channel_manager_->GetSupportedAudioReceiveCodecs(&cricket_codecs);
261 channel_manager_->GetSupportedAudioRtpHeaderExtensions(
262 &cricket_extensions);
263 return ToRtpCapabilities(cricket_codecs, cricket_extensions);
264 }
265 case cricket::MEDIA_TYPE_VIDEO: {
266 cricket::VideoCodecs cricket_codecs;
267 cricket::RtpHeaderExtensions cricket_extensions;
268 channel_manager_->GetSupportedVideoCodecs(&cricket_codecs);
269 channel_manager_->GetSupportedVideoRtpHeaderExtensions(
270 &cricket_extensions);
271 return ToRtpCapabilities(cricket_codecs, cricket_extensions);
272 }
273 case cricket::MEDIA_TYPE_DATA:
274 return RtpCapabilities();
275 }
276 // Not reached; avoids compile warning.
277 FATAL();
278}
279
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000280rtc::scoped_refptr<AudioSourceInterface>
htaa2a49d92016-03-04 02:51:39 -0800281PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) {
282 RTC_DCHECK(signaling_thread_->IsCurrent());
283 rtc::scoped_refptr<LocalAudioSource> source(
deadbeef757146b2017-02-10 21:26:48 -0800284 LocalAudioSource::Create(&options));
htaa2a49d92016-03-04 02:51:39 -0800285 return source;
286}
287
ivocd66b44d2016-01-15 03:06:36 -0800288bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file,
289 int64_t max_size_bytes) {
henrikg91d6ede2015-09-17 00:24:34 -0700290 RTC_DCHECK(signaling_thread_->IsCurrent());
ivocd66b44d2016-01-15 03:06:36 -0800291 return channel_manager_->StartAecDump(file, max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000292}
293
ivoc797ef122015-10-22 03:25:41 -0700294void PeerConnectionFactory::StopAecDump() {
295 RTC_DCHECK(signaling_thread_->IsCurrent());
296 channel_manager_->StopAecDump();
297}
298
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000299rtc::scoped_refptr<PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300PeerConnectionFactory::CreatePeerConnection(
htaa2a49d92016-03-04 02:51:39 -0800301 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -0700302 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200303 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
htaa2a49d92016-03-04 02:51:39 -0800304 PeerConnectionObserver* observer) {
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700305 // Convert the legacy API into the new depnedency structure.
306 PeerConnectionDependencies dependencies(observer);
307 dependencies.allocator = std::move(allocator);
308 dependencies.cert_generator = std::move(cert_generator);
309 // Pass that into the new API.
310 return CreatePeerConnection(configuration, std::move(dependencies));
311}
312
313rtc::scoped_refptr<PeerConnectionInterface>
314PeerConnectionFactory::CreatePeerConnection(
315 const PeerConnectionInterface::RTCConfiguration& configuration,
316 PeerConnectionDependencies dependencies) {
htaa2a49d92016-03-04 02:51:39 -0800317 RTC_DCHECK(signaling_thread_->IsCurrent());
318
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700319 // Set internal defaults if optional dependencies are not set.
320 if (!dependencies.cert_generator) {
Karl Wiberg918f50c2018-07-05 11:40:33 +0200321 dependencies.cert_generator =
322 absl::make_unique<rtc::RTCCertificateGenerator>(signaling_thread_,
323 network_thread_);
deadbeef41b07982015-12-01 15:01:24 -0800324 }
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700325 if (!dependencies.allocator) {
Qingsi Wang7852d292018-10-31 11:17:07 -0700326 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, &configuration,
327 &dependencies]() {
328 dependencies.allocator = absl::make_unique<cricket::BasicPortAllocator>(
329 default_network_manager_.get(), default_socket_factory_.get(),
330 configuration.turn_customizer);
331 });
jonasoc251cb12017-08-29 03:20:58 -0700332 }
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700333
Zach Steine20867f2018-08-02 13:20:15 -0700334 // TODO(zstein): Once chromium injects its own AsyncResolverFactory, set
335 // |dependencies.async_resolver_factory| to a new
336 // |rtc::BasicAsyncResolverFactory| if no factory is provided.
337
jonasoc251cb12017-08-29 03:20:58 -0700338 network_thread_->Invoke<void>(
Benjamin Wright6f7e6d62018-05-02 13:46:31 -0700339 RTC_FROM_HERE,
340 rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
341 dependencies.allocator.get(), options_.network_ignore_mask));
jonasoc251cb12017-08-29 03:20:58 -0700342
eladalon393a9f62017-09-05 04:30:30 -0700343 std::unique_ptr<RtcEventLog> event_log =
eladalon248fd4f2017-09-06 05:18:15 -0700344 worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>(
345 RTC_FROM_HERE,
346 rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this));
maxmorine9ef9072017-08-29 04:49:00 -0700347
zhihuang38ede132017-06-15 12:52:32 -0700348 std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>(
349 RTC_FROM_HERE,
350 rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get()));
351
deadbeef41b07982015-12-01 15:01:24 -0800352 rtc::scoped_refptr<PeerConnection> pc(
zhihuang38ede132017-06-15 12:52:32 -0700353 new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
354 std::move(call)));
Harald Alvestrand19793842018-06-25 12:03:50 +0200355 ActionsBeforeInitializeForTesting(pc);
Benjamin Wrightcab58882018-05-02 15:12:47 -0700356 if (!pc->Initialize(configuration, std::move(dependencies))) {
deadbeef41b07982015-12-01 15:01:24 -0800357 return nullptr;
358 }
359 return PeerConnectionProxy::Create(signaling_thread(), pc);
360}
361
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000362rtc::scoped_refptr<MediaStreamInterface>
Seth Hampson845e8782018-03-02 11:34:10 -0800363PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) {
henrikg91d6ede2015-09-17 00:24:34 -0700364 RTC_DCHECK(signaling_thread_->IsCurrent());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 return MediaStreamProxy::Create(signaling_thread_,
Seth Hampson845e8782018-03-02 11:34:10 -0800366 MediaStream::Create(stream_id));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367}
368
perkja3ede6c2016-03-08 01:27:48 +0100369rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 const std::string& id,
perkja3ede6c2016-03-08 01:27:48 +0100371 VideoTrackSourceInterface* source) {
henrikg91d6ede2015-09-17 00:24:34 -0700372 RTC_DCHECK(signaling_thread_->IsCurrent());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000373 rtc::scoped_refptr<VideoTrackInterface> track(
perkj773be362017-07-31 23:22:01 -0700374 VideoTrack::Create(id, source, worker_thread_));
nisse5b68ab52016-04-07 07:45:54 -0700375 return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376}
377
Yves Gerey665174f2018-06-19 15:03:05 +0200378rtc::scoped_refptr<AudioTrackInterface> PeerConnectionFactory::CreateAudioTrack(
379 const std::string& id,
380 AudioSourceInterface* source) {
henrikg91d6ede2015-09-17 00:24:34 -0700381 RTC_DCHECK(signaling_thread_->IsCurrent());
tommi6eca7e32015-12-15 04:27:11 -0800382 rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 return AudioTrackProxy::Create(signaling_thread_, track);
384}
385
Steve Antonda6c0952017-10-23 11:41:54 -0700386std::unique_ptr<cricket::SctpTransportInternalFactory>
387PeerConnectionFactory::CreateSctpTransportInternalFactory() {
388#ifdef HAVE_SCTP
Karl Wiberg918f50c2018-07-05 11:40:33 +0200389 return absl::make_unique<cricket::SctpTransportFactory>(network_thread());
Steve Antonda6c0952017-10-23 11:41:54 -0700390#else
391 return nullptr;
392#endif
393}
394
nisseeaabdf62017-05-05 02:23:02 -0700395cricket::ChannelManager* PeerConnectionFactory::channel_manager() {
396 return channel_manager_.get();
397}
398
eladalon248fd4f2017-09-06 05:18:15 -0700399std::unique_ptr<RtcEventLog> PeerConnectionFactory::CreateRtcEventLog_w() {
eladalon591753b2017-09-06 12:33:43 -0700400 RTC_DCHECK_RUN_ON(worker_thread_);
Bjorn Tereliusb26cf2f2018-10-26 20:39:33 +0200401
402 auto encoding_type = RtcEventLog::EncodingType::Legacy;
403 if (field_trial::IsEnabled("WebRTC-RtcEventLogNewFormat"))
404 encoding_type = RtcEventLog::EncodingType::NewFormat;
Elad Alon4a87e1c2017-10-03 16:11:34 +0200405 return event_log_factory_
406 ? event_log_factory_->CreateRtcEventLog(encoding_type)
Karl Wiberg918f50c2018-07-05 11:40:33 +0200407 : absl::make_unique<RtcEventLogNullImpl>();
eladalon248fd4f2017-09-06 05:18:15 -0700408}
409
zhihuang38ede132017-06-15 12:52:32 -0700410std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
411 RtcEventLog* event_log) {
eladalon591753b2017-09-06 12:33:43 -0700412 RTC_DCHECK_RUN_ON(worker_thread_);
413
zhihuang38ede132017-06-15 12:52:32 -0700414 const int kMinBandwidthBps = 30000;
415 const int kStartBandwidthBps = 300000;
416 const int kMaxBandwidthBps = 2000000;
417
418 webrtc::Call::Config call_config(event_log);
419 if (!channel_manager_->media_engine() || !call_factory_) {
420 return nullptr;
421 }
Sebastian Jansson6eb8a162018-11-16 11:29:55 +0100422 call_config.audio_state =
423 channel_manager_->media_engine()->voice().GetAudioState();
zhihuang38ede132017-06-15 12:52:32 -0700424 call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
425 call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
426 call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
427
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100428 call_config.fec_controller_factory = fec_controller_factory_.get();
429
Sebastian Jansson7f577882018-12-20 09:46:29 +0100430 if (field_trial::IsEnabled("WebRTC-Bwe-InjectedCongestionController")) {
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200431 RTC_LOG(LS_INFO) << "Using injected network controller factory";
432 call_config.network_controller_factory =
433 injected_network_controller_factory_.get();
434 } else {
435 RTC_LOG(LS_INFO) << "Using default network controller factory";
436 }
437
zhihuang38ede132017-06-15 12:52:32 -0700438 return std::unique_ptr<Call>(call_factory_->CreateCall(call_config));
439}
440
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441} // namespace webrtc