henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/peerconnectionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 13 | #include <utility> |
Florent Castelli | 72b751a | 2018-06-28 14:09:33 +0200 | [diff] [blame^] | 14 | #include <vector> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 15 | |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 16 | #include "api/fec_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/mediaconstraintsinterface.h" |
| 18 | #include "api/mediastreamproxy.h" |
| 19 | #include "api/mediastreamtrackproxy.h" |
| 20 | #include "api/peerconnectionfactoryproxy.h" |
| 21 | #include "api/peerconnectionproxy.h" |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 22 | #include "api/turncustomizer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/videosourceproxy.h" |
| 24 | #include "logging/rtc_event_log/rtc_event_log.h" |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 25 | #include "media/base/rtpdataengine.h" |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 26 | #include "media/sctp/sctptransport.h" |
Florent Castelli | 72b751a | 2018-06-28 14:09:33 +0200 | [diff] [blame^] | 27 | #include "pc/rtpparametersconversion.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "rtc_base/bind.h" |
| 29 | #include "rtc_base/checks.h" |
| 30 | #include "rtc_base/ptr_util.h" |
Patrik Höglund | 42805f3 | 2018-01-18 19:15:38 +0000 | [diff] [blame] | 31 | // Adding 'nogncheck' to disable the gn include headers check to support modular |
| 32 | // WebRTC build targets. |
| 33 | // TODO(zhihuang): This wouldn't be necessary if the interface and |
| 34 | // implementation of the media engine were in separate build targets. |
| 35 | #include "media/engine/webrtcmediaengine.h" // nogncheck |
| 36 | #include "media/engine/webrtcvideodecoderfactory.h" // nogncheck |
| 37 | #include "media/engine/webrtcvideoencoderfactory.h" // nogncheck |
| 38 | #include "modules/audio_device/include/audio_device.h" // nogncheck |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 39 | #include "modules/congestion_controller/bbr/bbr_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "p2p/base/basicpacketsocketfactory.h" |
| 41 | #include "p2p/client/basicportallocator.h" |
| 42 | #include "pc/audiotrack.h" |
| 43 | #include "pc/localaudiosource.h" |
| 44 | #include "pc/mediastream.h" |
| 45 | #include "pc/peerconnection.h" |
| 46 | #include "pc/videocapturertracksource.h" |
| 47 | #include "pc/videotrack.h" |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 48 | #include "rtc_base/experiments/congestion_controller_experiment.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | namespace webrtc { |
| 51 | |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 52 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 53 | CreateModularPeerConnectionFactory( |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 54 | rtc::Thread* network_thread, |
| 55 | rtc::Thread* worker_thread, |
| 56 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 57 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 58 | std::unique_ptr<CallFactoryInterface> call_factory, |
| 59 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) { |
Benjamin Wright | 5234a49 | 2018-05-29 15:04:32 -0700 | [diff] [blame] | 60 | PeerConnectionFactoryDependencies dependencies; |
| 61 | dependencies.network_thread = network_thread; |
| 62 | dependencies.worker_thread = worker_thread; |
| 63 | dependencies.signaling_thread = signaling_thread; |
| 64 | dependencies.media_engine = std::move(media_engine); |
| 65 | dependencies.call_factory = std::move(call_factory); |
| 66 | dependencies.event_log_factory = std::move(event_log_factory); |
| 67 | return CreateModularPeerConnectionFactory(std::move(dependencies)); |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 71 | CreateModularPeerConnectionFactory( |
| 72 | rtc::Thread* network_thread, |
| 73 | rtc::Thread* worker_thread, |
| 74 | rtc::Thread* signaling_thread, |
| 75 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 76 | std::unique_ptr<CallFactoryInterface> call_factory, |
| 77 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory, |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 78 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, |
| 79 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 80 | network_controller_factory) { |
Benjamin Wright | 5234a49 | 2018-05-29 15:04:32 -0700 | [diff] [blame] | 81 | PeerConnectionFactoryDependencies dependencies; |
| 82 | dependencies.network_thread = network_thread; |
| 83 | dependencies.worker_thread = worker_thread; |
| 84 | dependencies.signaling_thread = signaling_thread; |
| 85 | dependencies.media_engine = std::move(media_engine); |
| 86 | dependencies.call_factory = std::move(call_factory); |
| 87 | dependencies.event_log_factory = std::move(event_log_factory); |
| 88 | dependencies.fec_controller_factory = std::move(fec_controller_factory); |
| 89 | dependencies.network_controller_factory = |
| 90 | std::move(network_controller_factory); |
| 91 | return CreateModularPeerConnectionFactory(std::move(dependencies)); |
| 92 | } |
| 93 | |
| 94 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 95 | CreateModularPeerConnectionFactory( |
| 96 | PeerConnectionFactoryDependencies dependencies) { |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 97 | rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 98 | new rtc::RefCountedObject<PeerConnectionFactory>( |
Benjamin Wright | 5234a49 | 2018-05-29 15:04:32 -0700 | [diff] [blame] | 99 | std::move(dependencies))); |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 100 | // Call Initialize synchronously but make sure it is executed on |
| 101 | // |signaling_thread|. |
| 102 | MethodCall0<PeerConnectionFactory, bool> call( |
| 103 | pc_factory.get(), &PeerConnectionFactory::Initialize); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 104 | bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread()); |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 105 | |
| 106 | if (!result) { |
| 107 | return nullptr; |
| 108 | } |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 109 | return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), |
| 110 | pc_factory); |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 111 | } |
| 112 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | PeerConnectionFactory::PeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 114 | rtc::Thread* network_thread, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 115 | rtc::Thread* worker_thread, |
| 116 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 117 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 118 | std::unique_ptr<webrtc::CallFactoryInterface> call_factory, |
| 119 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 120 | : PeerConnectionFactory(network_thread, |
| 121 | worker_thread, |
| 122 | signaling_thread, |
| 123 | std::move(media_engine), |
| 124 | std::move(call_factory), |
| 125 | std::move(event_log_factory), |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 126 | nullptr, |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 127 | nullptr) {} |
| 128 | |
| 129 | PeerConnectionFactory::PeerConnectionFactory( |
| 130 | rtc::Thread* network_thread, |
| 131 | rtc::Thread* worker_thread, |
| 132 | rtc::Thread* signaling_thread, |
| 133 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 134 | std::unique_ptr<webrtc::CallFactoryInterface> call_factory, |
| 135 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory, |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 136 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, |
| 137 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 138 | network_controller_factory) |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 139 | : wraps_current_thread_(false), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 140 | network_thread_(network_thread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | worker_thread_(worker_thread), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 142 | signaling_thread_(signaling_thread), |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 143 | media_engine_(std::move(media_engine)), |
| 144 | call_factory_(std::move(call_factory)), |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 145 | event_log_factory_(std::move(event_log_factory)), |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 146 | fec_controller_factory_(std::move(fec_controller_factory)), |
| 147 | injected_network_controller_factory_( |
| 148 | std::move(network_controller_factory)), |
| 149 | bbr_network_controller_factory_( |
| 150 | rtc::MakeUnique<BbrNetworkControllerFactory>()) { |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 151 | if (!network_thread_) { |
| 152 | owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); |
Sebastian Jansson | 13f35ec | 2017-11-13 10:54:45 +0100 | [diff] [blame] | 153 | owned_network_thread_->SetName("pc_network_thread", nullptr); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 154 | owned_network_thread_->Start(); |
| 155 | network_thread_ = owned_network_thread_.get(); |
| 156 | } |
| 157 | |
| 158 | if (!worker_thread_) { |
| 159 | owned_worker_thread_ = rtc::Thread::Create(); |
Sebastian Jansson | 13f35ec | 2017-11-13 10:54:45 +0100 | [diff] [blame] | 160 | owned_worker_thread_->SetName("pc_worker_thread", nullptr); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 161 | owned_worker_thread_->Start(); |
| 162 | worker_thread_ = owned_worker_thread_.get(); |
| 163 | } |
| 164 | |
| 165 | if (!signaling_thread_) { |
| 166 | signaling_thread_ = rtc::Thread::Current(); |
| 167 | if (!signaling_thread_) { |
| 168 | // If this thread isn't already wrapped by an rtc::Thread, create a |
| 169 | // wrapper and own it in this class. |
| 170 | signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); |
| 171 | wraps_current_thread_ = true; |
| 172 | } |
| 173 | } |
| 174 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 175 | // TODO(deadbeef): Currently there is no way to create an external adm in |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | // libjingle source tree. So we can 't currently assert if this is NULL. |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 177 | // RTC_DCHECK(default_adm != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Benjamin Wright | 5234a49 | 2018-05-29 15:04:32 -0700 | [diff] [blame] | 180 | PeerConnectionFactory::PeerConnectionFactory( |
| 181 | PeerConnectionFactoryDependencies dependencies) |
| 182 | : PeerConnectionFactory( |
| 183 | dependencies.network_thread, |
| 184 | dependencies.worker_thread, |
| 185 | dependencies.signaling_thread, |
| 186 | std::move(dependencies.media_engine), |
| 187 | std::move(dependencies.call_factory), |
| 188 | std::move(dependencies.event_log_factory), |
| 189 | std::move(dependencies.fec_controller_factory), |
| 190 | std::move(dependencies.network_controller_factory)) {} |
| 191 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | PeerConnectionFactory::~PeerConnectionFactory() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 193 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 194 | channel_manager_.reset(nullptr); |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 195 | |
| 196 | // Make sure |worker_thread_| and |signaling_thread_| outlive |
Henrik Boström | cebf0a2 | 2016-06-01 15:45:30 +0200 | [diff] [blame] | 197 | // |default_socket_factory_| and |default_network_manager_|. |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 198 | default_socket_factory_ = nullptr; |
| 199 | default_network_manager_ = nullptr; |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 200 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 201 | if (wraps_current_thread_) |
| 202 | rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | bool PeerConnectionFactory::Initialize() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 206 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 207 | rtc::InitRandom(rtc::Time32()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 209 | default_network_manager_.reset(new rtc::BasicNetworkManager()); |
| 210 | if (!default_network_manager_) { |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | default_socket_factory_.reset( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 215 | new rtc::BasicPacketSocketFactory(network_thread_)); |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 216 | if (!default_socket_factory_) { |
| 217 | return false; |
| 218 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 219 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 220 | channel_manager_ = rtc::MakeUnique<cricket::ChannelManager>( |
| 221 | std::move(media_engine_), rtc::MakeUnique<cricket::RtpDataEngine>(), |
| 222 | worker_thread_, network_thread_); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 223 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 224 | channel_manager_->SetVideoRtxEnabled(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | if (!channel_manager_->Init()) { |
| 226 | return false; |
| 227 | } |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 228 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 232 | void PeerConnectionFactory::SetOptions(const Options& options) { |
| 233 | options_ = options; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Florent Castelli | 72b751a | 2018-06-28 14:09:33 +0200 | [diff] [blame^] | 236 | RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities( |
| 237 | cricket::MediaType kind) const { |
| 238 | RTC_DCHECK_RUN_ON(signaling_thread_); |
| 239 | switch (kind) { |
| 240 | case cricket::MEDIA_TYPE_AUDIO: { |
| 241 | cricket::AudioCodecs cricket_codecs; |
| 242 | cricket::RtpHeaderExtensions cricket_extensions; |
| 243 | channel_manager_->GetSupportedAudioSendCodecs(&cricket_codecs); |
| 244 | channel_manager_->GetSupportedAudioRtpHeaderExtensions( |
| 245 | &cricket_extensions); |
| 246 | return ToRtpCapabilities(cricket_codecs, cricket_extensions); |
| 247 | } |
| 248 | case cricket::MEDIA_TYPE_VIDEO: { |
| 249 | cricket::VideoCodecs cricket_codecs; |
| 250 | cricket::RtpHeaderExtensions cricket_extensions; |
| 251 | channel_manager_->GetSupportedVideoCodecs(&cricket_codecs); |
| 252 | channel_manager_->GetSupportedVideoRtpHeaderExtensions( |
| 253 | &cricket_extensions); |
| 254 | return ToRtpCapabilities(cricket_codecs, cricket_extensions); |
| 255 | } |
| 256 | case cricket::MEDIA_TYPE_DATA: |
| 257 | return RtpCapabilities(); |
| 258 | } |
| 259 | // Not reached; avoids compile warning. |
| 260 | FATAL(); |
| 261 | } |
| 262 | |
| 263 | RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities( |
| 264 | cricket::MediaType kind) const { |
| 265 | RTC_DCHECK_RUN_ON(signaling_thread_); |
| 266 | switch (kind) { |
| 267 | case cricket::MEDIA_TYPE_AUDIO: { |
| 268 | cricket::AudioCodecs cricket_codecs; |
| 269 | cricket::RtpHeaderExtensions cricket_extensions; |
| 270 | channel_manager_->GetSupportedAudioReceiveCodecs(&cricket_codecs); |
| 271 | channel_manager_->GetSupportedAudioRtpHeaderExtensions( |
| 272 | &cricket_extensions); |
| 273 | return ToRtpCapabilities(cricket_codecs, cricket_extensions); |
| 274 | } |
| 275 | case cricket::MEDIA_TYPE_VIDEO: { |
| 276 | cricket::VideoCodecs cricket_codecs; |
| 277 | cricket::RtpHeaderExtensions cricket_extensions; |
| 278 | channel_manager_->GetSupportedVideoCodecs(&cricket_codecs); |
| 279 | channel_manager_->GetSupportedVideoRtpHeaderExtensions( |
| 280 | &cricket_extensions); |
| 281 | return ToRtpCapabilities(cricket_codecs, cricket_extensions); |
| 282 | } |
| 283 | case cricket::MEDIA_TYPE_DATA: |
| 284 | return RtpCapabilities(); |
| 285 | } |
| 286 | // Not reached; avoids compile warning. |
| 287 | FATAL(); |
| 288 | } |
| 289 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 290 | rtc::scoped_refptr<AudioSourceInterface> |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 291 | PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) { |
| 292 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 293 | rtc::scoped_refptr<LocalAudioSource> source( |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 294 | LocalAudioSource::Create(&options)); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 295 | return source; |
| 296 | } |
| 297 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 298 | rtc::scoped_refptr<VideoTrackSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 299 | PeerConnectionFactory::CreateVideoSource( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 300 | std::unique_ptr<cricket::VideoCapturer> capturer, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 301 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 302 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 303 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 304 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 305 | constraints, false)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 306 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 307 | source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 308 | } |
| 309 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 310 | rtc::scoped_refptr<VideoTrackSourceInterface> |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 311 | PeerConnectionFactory::CreateVideoSource( |
| 312 | std::unique_ptr<cricket::VideoCapturer> capturer) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 313 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 314 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 315 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 316 | false)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 317 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 318 | source); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 319 | } |
| 320 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 321 | bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file, |
| 322 | int64_t max_size_bytes) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 323 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 324 | return channel_manager_->StartAecDump(file, max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 325 | } |
| 326 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 327 | void PeerConnectionFactory::StopAecDump() { |
| 328 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 329 | channel_manager_->StopAecDump(); |
| 330 | } |
| 331 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 332 | rtc::scoped_refptr<PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | PeerConnectionFactory::CreatePeerConnection( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 334 | const PeerConnectionInterface::RTCConfiguration& configuration_in, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 335 | const MediaConstraintsInterface* constraints, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 336 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 337 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 338 | PeerConnectionObserver* observer) { |
| 339 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 340 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 341 | // We merge constraints and configuration into a single configuration. |
| 342 | PeerConnectionInterface::RTCConfiguration configuration = configuration_in; |
| 343 | CopyConstraintsIntoRtcConfiguration(constraints, &configuration); |
| 344 | |
| 345 | return CreatePeerConnection(configuration, std::move(allocator), |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 346 | std::move(cert_generator), observer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | rtc::scoped_refptr<PeerConnectionInterface> |
| 350 | PeerConnectionFactory::CreatePeerConnection( |
| 351 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 352 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 353 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 354 | PeerConnectionObserver* observer) { |
Benjamin Wright | 6f7e6d6 | 2018-05-02 13:46:31 -0700 | [diff] [blame] | 355 | // Convert the legacy API into the new depnedency structure. |
| 356 | PeerConnectionDependencies dependencies(observer); |
| 357 | dependencies.allocator = std::move(allocator); |
| 358 | dependencies.cert_generator = std::move(cert_generator); |
| 359 | // Pass that into the new API. |
| 360 | return CreatePeerConnection(configuration, std::move(dependencies)); |
| 361 | } |
| 362 | |
| 363 | rtc::scoped_refptr<PeerConnectionInterface> |
| 364 | PeerConnectionFactory::CreatePeerConnection( |
| 365 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 366 | PeerConnectionDependencies dependencies) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 367 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 368 | |
Benjamin Wright | 6f7e6d6 | 2018-05-02 13:46:31 -0700 | [diff] [blame] | 369 | // Set internal defaults if optional dependencies are not set. |
| 370 | if (!dependencies.cert_generator) { |
| 371 | dependencies.cert_generator = rtc::MakeUnique<rtc::RTCCertificateGenerator>( |
| 372 | signaling_thread_, network_thread_); |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 373 | } |
Benjamin Wright | 6f7e6d6 | 2018-05-02 13:46:31 -0700 | [diff] [blame] | 374 | if (!dependencies.allocator) { |
| 375 | dependencies.allocator.reset(new cricket::BasicPortAllocator( |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 376 | default_network_manager_.get(), default_socket_factory_.get(), |
| 377 | configuration.turn_customizer)); |
jonaso | c251cb1 | 2017-08-29 03:20:58 -0700 | [diff] [blame] | 378 | } |
Benjamin Wright | 6f7e6d6 | 2018-05-02 13:46:31 -0700 | [diff] [blame] | 379 | |
jonaso | c251cb1 | 2017-08-29 03:20:58 -0700 | [diff] [blame] | 380 | network_thread_->Invoke<void>( |
Benjamin Wright | 6f7e6d6 | 2018-05-02 13:46:31 -0700 | [diff] [blame] | 381 | RTC_FROM_HERE, |
| 382 | rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask, |
| 383 | dependencies.allocator.get(), options_.network_ignore_mask)); |
jonaso | c251cb1 | 2017-08-29 03:20:58 -0700 | [diff] [blame] | 384 | |
eladalon | 393a9f6 | 2017-09-05 04:30:30 -0700 | [diff] [blame] | 385 | std::unique_ptr<RtcEventLog> event_log = |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 386 | worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>( |
| 387 | RTC_FROM_HERE, |
| 388 | rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this)); |
maxmorin | e9ef907 | 2017-08-29 04:49:00 -0700 | [diff] [blame] | 389 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 390 | std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>( |
| 391 | RTC_FROM_HERE, |
| 392 | rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get())); |
| 393 | |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 394 | rtc::scoped_refptr<PeerConnection> pc( |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 395 | new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log), |
| 396 | std::move(call))); |
Harald Alvestrand | 1979384 | 2018-06-25 12:03:50 +0200 | [diff] [blame] | 397 | ActionsBeforeInitializeForTesting(pc); |
Benjamin Wright | cab5888 | 2018-05-02 15:12:47 -0700 | [diff] [blame] | 398 | if (!pc->Initialize(configuration, std::move(dependencies))) { |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 399 | return nullptr; |
| 400 | } |
| 401 | return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 402 | } |
| 403 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 404 | rtc::scoped_refptr<MediaStreamInterface> |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 405 | PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 406 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | return MediaStreamProxy::Create(signaling_thread_, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 408 | MediaStream::Create(stream_id)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 409 | } |
| 410 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 411 | rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 412 | const std::string& id, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 413 | VideoTrackSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 414 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 415 | rtc::scoped_refptr<VideoTrackInterface> track( |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 416 | VideoTrack::Create(id, source, worker_thread_)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 417 | return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 420 | rtc::scoped_refptr<AudioTrackInterface> PeerConnectionFactory::CreateAudioTrack( |
| 421 | const std::string& id, |
| 422 | AudioSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 423 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 424 | rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 425 | return AudioTrackProxy::Create(signaling_thread_, track); |
| 426 | } |
| 427 | |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 428 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 429 | PeerConnectionFactory::CreateSctpTransportInternalFactory() { |
| 430 | #ifdef HAVE_SCTP |
| 431 | return rtc::MakeUnique<cricket::SctpTransportFactory>(network_thread()); |
| 432 | #else |
| 433 | return nullptr; |
| 434 | #endif |
| 435 | } |
| 436 | |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 437 | cricket::ChannelManager* PeerConnectionFactory::channel_manager() { |
| 438 | return channel_manager_.get(); |
| 439 | } |
| 440 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 441 | rtc::Thread* PeerConnectionFactory::signaling_thread() { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 442 | // This method can be called on a different thread when the factory is |
| 443 | // created in CreatePeerConnectionFactory(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | return signaling_thread_; |
| 445 | } |
| 446 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 447 | rtc::Thread* PeerConnectionFactory::worker_thread() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 448 | return worker_thread_; |
| 449 | } |
| 450 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 451 | rtc::Thread* PeerConnectionFactory::network_thread() { |
| 452 | return network_thread_; |
| 453 | } |
| 454 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 455 | std::unique_ptr<RtcEventLog> PeerConnectionFactory::CreateRtcEventLog_w() { |
eladalon | 591753b | 2017-09-06 12:33:43 -0700 | [diff] [blame] | 456 | RTC_DCHECK_RUN_ON(worker_thread_); |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 457 | const auto encoding_type = RtcEventLog::EncodingType::Legacy; |
| 458 | return event_log_factory_ |
| 459 | ? event_log_factory_->CreateRtcEventLog(encoding_type) |
| 460 | : rtc::MakeUnique<RtcEventLogNullImpl>(); |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 461 | } |
| 462 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 463 | std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w( |
| 464 | RtcEventLog* event_log) { |
eladalon | 591753b | 2017-09-06 12:33:43 -0700 | [diff] [blame] | 465 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 466 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 467 | const int kMinBandwidthBps = 30000; |
| 468 | const int kStartBandwidthBps = 300000; |
| 469 | const int kMaxBandwidthBps = 2000000; |
| 470 | |
| 471 | webrtc::Call::Config call_config(event_log); |
| 472 | if (!channel_manager_->media_engine() || !call_factory_) { |
| 473 | return nullptr; |
| 474 | } |
| 475 | call_config.audio_state = channel_manager_->media_engine()->GetAudioState(); |
| 476 | call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
| 477 | call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
| 478 | call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
| 479 | |
Ying Wang | 0dd1b0a | 2018-02-20 12:50:27 +0100 | [diff] [blame] | 480 | call_config.fec_controller_factory = fec_controller_factory_.get(); |
| 481 | |
Sebastian Jansson | dfce03a | 2018-05-18 18:05:10 +0200 | [diff] [blame] | 482 | if (CongestionControllerExperiment::BbrControllerEnabled()) { |
| 483 | RTC_LOG(LS_INFO) << "Using BBR network controller factory"; |
| 484 | call_config.network_controller_factory = |
| 485 | bbr_network_controller_factory_.get(); |
| 486 | } else if (CongestionControllerExperiment::InjectedControllerEnabled()) { |
| 487 | RTC_LOG(LS_INFO) << "Using injected network controller factory"; |
| 488 | call_config.network_controller_factory = |
| 489 | injected_network_controller_factory_.get(); |
| 490 | } else { |
| 491 | RTC_LOG(LS_INFO) << "Using default network controller factory"; |
| 492 | } |
| 493 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 494 | return std::unique_ptr<Call>(call_factory_->CreateCall(call_config)); |
| 495 | } |
| 496 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 497 | } // namespace webrtc |