henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "pc/peerconnectionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
kwiberg | 0eb15ed | 2015-12-17 11:04:15 | [diff] [blame] | 13 | #include <utility> |
Florent Castelli | 72b751a | 2018-06-28 12:09:33 | [diff] [blame] | 14 | #include <vector> |
kwiberg | 0eb15ed | 2015-12-17 11:04:15 | [diff] [blame] | 15 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 16 | #include "absl/memory/memory.h" |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 17 | #include "api/fec_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "api/mediaconstraintsinterface.h" |
| 19 | #include "api/mediastreamproxy.h" |
| 20 | #include "api/mediastreamtrackproxy.h" |
| 21 | #include "api/peerconnectionfactoryproxy.h" |
| 22 | #include "api/peerconnectionproxy.h" |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 23 | #include "api/turncustomizer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 24 | #include "api/videosourceproxy.h" |
| 25 | #include "logging/rtc_event_log/rtc_event_log.h" |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 26 | #include "media/base/rtpdataengine.h" |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 27 | #include "media/sctp/sctptransport.h" |
Florent Castelli | 72b751a | 2018-06-28 12:09:33 | [diff] [blame] | 28 | #include "pc/rtpparametersconversion.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 29 | #include "rtc_base/bind.h" |
| 30 | #include "rtc_base/checks.h" |
Patrik Höglund | 42805f3 | 2018-01-18 19:15:38 | [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 16:05:10 | [diff] [blame] | 39 | #include "modules/congestion_controller/bbr/bbr_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [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 16:05:10 | [diff] [blame] | 48 | #include "rtc_base/experiments/congestion_controller_experiment.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 49 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 50 | namespace webrtc { |
| 51 | |
kwiberg | 1e4e8cb | 2017-01-31 09:48:08 | [diff] [blame] | 52 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 53 | CreateModularPeerConnectionFactory( |
gyzhou | 95aa964 | 2016-12-13 22:06:26 | [diff] [blame] | 54 | rtc::Thread* network_thread, |
| 55 | rtc::Thread* worker_thread, |
| 56 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [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 22:04:32 | [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 11:50:27 | [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 16:05:10 | [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 22:04:32 | [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 22:06:26 | [diff] [blame] | 97 | rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 98 | new rtc::RefCountedObject<PeerConnectionFactory>( |
Benjamin Wright | 5234a49 | 2018-05-29 22:04:32 | [diff] [blame] | 99 | std::move(dependencies))); |
gyzhou | 95aa964 | 2016-12-13 22:06:26 | [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 19:52:32 | [diff] [blame] | 104 | bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread()); |
gyzhou | 95aa964 | 2016-12-13 22:06:26 | [diff] [blame] | 105 | |
| 106 | if (!result) { |
| 107 | return nullptr; |
| 108 | } |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 109 | return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), |
| 110 | pc_factory); |
kwiberg | 1e4e8cb | 2017-01-31 09:48:08 | [diff] [blame] | 111 | } |
| 112 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 113 | PeerConnectionFactory::PeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 114 | rtc::Thread* network_thread, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 115 | rtc::Thread* worker_thread, |
| 116 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [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 11:50:27 | [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 16:05:10 | [diff] [blame] | 126 | nullptr, |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [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 16:05:10 | [diff] [blame] | 136 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, |
| 137 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 138 | network_controller_factory) |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 139 | : wraps_current_thread_(false), |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 140 | network_thread_(network_thread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 141 | worker_thread_(worker_thread), |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 142 | signaling_thread_(signaling_thread), |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 143 | media_engine_(std::move(media_engine)), |
| 144 | call_factory_(std::move(call_factory)), |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 145 | event_log_factory_(std::move(event_log_factory)), |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [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_( |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 150 | absl::make_unique<BbrNetworkControllerFactory>()) { |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 151 | if (!network_thread_) { |
| 152 | owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); |
Sebastian Jansson | 13f35ec3 | 2017-11-13 09:54:45 | [diff] [blame] | 153 | owned_network_thread_->SetName("pc_network_thread", nullptr); |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [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 | 13f35ec3 | 2017-11-13 09:54:45 | [diff] [blame] | 160 | owned_worker_thread_->SetName("pc_worker_thread", nullptr); |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [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 16:57:42 | [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 | [diff] [blame] | 176 | // libjingle source tree. So we can 't currently assert if this is NULL. |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 177 | // RTC_DCHECK(default_adm != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 178 | } |
| 179 | |
Benjamin Wright | 5234a49 | 2018-05-29 22:04:32 | [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 | [diff] [blame] | 192 | PeerConnectionFactory::~PeerConnectionFactory() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 193 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 194 | channel_manager_.reset(nullptr); |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 | [diff] [blame] | 195 | |
| 196 | // Make sure |worker_thread_| and |signaling_thread_| outlive |
Henrik Boström | cebf0a2 | 2016-06-01 13:45:30 | [diff] [blame] | 197 | // |default_socket_factory_| and |default_network_manager_|. |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 198 | default_socket_factory_ = nullptr; |
| 199 | default_network_manager_ = nullptr; |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 | [diff] [blame] | 200 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 201 | if (wraps_current_thread_) |
| 202 | rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | bool PeerConnectionFactory::Initialize() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 206 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Honghai Zhang | 82d7862 | 2016-05-06 18:29:15 | [diff] [blame] | 207 | rtc::InitRandom(rtc::Time32()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 208 | |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [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 08:52:02 | [diff] [blame] | 215 | new rtc::BasicPacketSocketFactory(network_thread_)); |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 216 | if (!default_socket_factory_) { |
| 217 | return false; |
| 218 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 219 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 220 | channel_manager_ = absl::make_unique<cricket::ChannelManager>( |
| 221 | std::move(media_engine_), absl::make_unique<cricket::RtpDataEngine>(), |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 222 | worker_thread_, network_thread_); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 223 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 224 | channel_manager_->SetVideoRtxEnabled(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 225 | if (!channel_manager_->Init()) { |
| 226 | return false; |
| 227 | } |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 228 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 232 | void PeerConnectionFactory::SetOptions(const Options& options) { |
| 233 | options_ = options; |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 234 | } |
| 235 | |
Florent Castelli | 72b751a | 2018-06-28 12:09:33 | [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 | [diff] [blame] | 290 | rtc::scoped_refptr<AudioSourceInterface> |
hta | a2a49d9 | 2016-03-04 10:51:39 | [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-11 05:26:48 | [diff] [blame] | 294 | LocalAudioSource::Create(&options)); |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 295 | return source; |
| 296 | } |
| 297 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 298 | rtc::scoped_refptr<VideoTrackSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 299 | PeerConnectionFactory::CreateVideoSource( |
deadbeef | 112b2e9 | 2017-02-11 04:13:37 | [diff] [blame] | 300 | std::unique_ptr<cricket::VideoCapturer> capturer, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 301 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 302 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 303 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-11 04:13:37 | [diff] [blame] | 304 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 305 | constraints, false)); |
nisse | 5b68ab5 | 2016-04-07 14:45:54 | [diff] [blame] | 306 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 307 | source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 308 | } |
| 309 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 310 | rtc::scoped_refptr<VideoTrackSourceInterface> |
deadbeef | 112b2e9 | 2017-02-11 04:13:37 | [diff] [blame] | 311 | PeerConnectionFactory::CreateVideoSource( |
| 312 | std::unique_ptr<cricket::VideoCapturer> capturer) { |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 313 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 314 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-11 04:13:37 | [diff] [blame] | 315 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 316 | false)); |
nisse | 5b68ab5 | 2016-04-07 14:45:54 | [diff] [blame] | 317 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 318 | source); |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 319 | } |
| 320 | |
ivoc | d66b44d | 2016-01-15 11:06:36 | [diff] [blame] | 321 | bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file, |
| 322 | int64_t max_size_bytes) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 323 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
ivoc | d66b44d | 2016-01-15 11:06:36 | [diff] [blame] | 324 | return channel_manager_->StartAecDump(file, max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 325 | } |
| 326 | |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [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 | [diff] [blame] | 332 | rtc::scoped_refptr<PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 333 | PeerConnectionFactory::CreatePeerConnection( |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 334 | const PeerConnectionInterface::RTCConfiguration& configuration_in, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 335 | const MediaConstraintsInterface* constraints, |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 336 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 337 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 338 | PeerConnectionObserver* observer) { |
| 339 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 340 | |
hta | a2a49d9 | 2016-03-04 10:51:39 | [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 09:44:18 | [diff] [blame] | 346 | std::move(cert_generator), observer); |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | rtc::scoped_refptr<PeerConnectionInterface> |
| 350 | PeerConnectionFactory::CreatePeerConnection( |
| 351 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 352 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 353 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 354 | PeerConnectionObserver* observer) { |
Benjamin Wright | 6f7e6d6 | 2018-05-02 20:46:31 | [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 10:51:39 | [diff] [blame] | 367 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 368 | |
Benjamin Wright | 6f7e6d6 | 2018-05-02 20:46:31 | [diff] [blame] | 369 | // Set internal defaults if optional dependencies are not set. |
| 370 | if (!dependencies.cert_generator) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 371 | dependencies.cert_generator = |
| 372 | absl::make_unique<rtc::RTCCertificateGenerator>(signaling_thread_, |
| 373 | network_thread_); |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 374 | } |
Benjamin Wright | 6f7e6d6 | 2018-05-02 20:46:31 | [diff] [blame] | 375 | if (!dependencies.allocator) { |
| 376 | dependencies.allocator.reset(new cricket::BasicPortAllocator( |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 377 | default_network_manager_.get(), default_socket_factory_.get(), |
| 378 | configuration.turn_customizer)); |
jonaso | c251cb1 | 2017-08-29 10:20:58 | [diff] [blame] | 379 | } |
Benjamin Wright | 6f7e6d6 | 2018-05-02 20:46:31 | [diff] [blame] | 380 | |
jonaso | c251cb1 | 2017-08-29 10:20:58 | [diff] [blame] | 381 | network_thread_->Invoke<void>( |
Benjamin Wright | 6f7e6d6 | 2018-05-02 20:46:31 | [diff] [blame] | 382 | RTC_FROM_HERE, |
| 383 | rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask, |
| 384 | dependencies.allocator.get(), options_.network_ignore_mask)); |
jonaso | c251cb1 | 2017-08-29 10:20:58 | [diff] [blame] | 385 | |
eladalon | 393a9f6 | 2017-09-05 11:30:30 | [diff] [blame] | 386 | std::unique_ptr<RtcEventLog> event_log = |
eladalon | 248fd4f | 2017-09-06 12:18:15 | [diff] [blame] | 387 | worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>( |
| 388 | RTC_FROM_HERE, |
| 389 | rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this)); |
maxmorin | e9ef907 | 2017-08-29 11:49:00 | [diff] [blame] | 390 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 391 | std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>( |
| 392 | RTC_FROM_HERE, |
| 393 | rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get())); |
| 394 | |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 395 | rtc::scoped_refptr<PeerConnection> pc( |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 396 | new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log), |
| 397 | std::move(call))); |
Harald Alvestrand | 1979384 | 2018-06-25 10:03:50 | [diff] [blame] | 398 | ActionsBeforeInitializeForTesting(pc); |
Benjamin Wright | cab58888 | 2018-05-02 22:12:47 | [diff] [blame] | 399 | if (!pc->Initialize(configuration, std::move(dependencies))) { |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 400 | return nullptr; |
| 401 | } |
| 402 | return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 403 | } |
| 404 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 405 | rtc::scoped_refptr<MediaStreamInterface> |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 406 | PeerConnectionFactory::CreateLocalMediaStream(const std::string& stream_id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 407 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 408 | return MediaStreamProxy::Create(signaling_thread_, |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 409 | MediaStream::Create(stream_id)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 410 | } |
| 411 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 412 | rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 413 | const std::string& id, |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 414 | VideoTrackSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 415 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 416 | rtc::scoped_refptr<VideoTrackInterface> track( |
perkj | 773be36 | 2017-08-01 06:22:01 | [diff] [blame] | 417 | VideoTrack::Create(id, source, worker_thread_)); |
nisse | 5b68ab5 | 2016-04-07 14:45:54 | [diff] [blame] | 418 | return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 419 | } |
| 420 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 421 | rtc::scoped_refptr<AudioTrackInterface> PeerConnectionFactory::CreateAudioTrack( |
| 422 | const std::string& id, |
| 423 | AudioSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 424 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame] | 425 | rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 426 | return AudioTrackProxy::Create(signaling_thread_, track); |
| 427 | } |
| 428 | |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 429 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 430 | PeerConnectionFactory::CreateSctpTransportInternalFactory() { |
| 431 | #ifdef HAVE_SCTP |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 432 | return absl::make_unique<cricket::SctpTransportFactory>(network_thread()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 433 | #else |
| 434 | return nullptr; |
| 435 | #endif |
| 436 | } |
| 437 | |
nisse | eaabdf6 | 2017-05-05 09:23:02 | [diff] [blame] | 438 | cricket::ChannelManager* PeerConnectionFactory::channel_manager() { |
| 439 | return channel_manager_.get(); |
| 440 | } |
| 441 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 442 | rtc::Thread* PeerConnectionFactory::signaling_thread() { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 443 | // This method can be called on a different thread when the factory is |
| 444 | // created in CreatePeerConnectionFactory(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 445 | return signaling_thread_; |
| 446 | } |
| 447 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 448 | rtc::Thread* PeerConnectionFactory::worker_thread() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 449 | return worker_thread_; |
| 450 | } |
| 451 | |
danilchap | e9021a3 | 2016-05-17 08:52:02 | [diff] [blame] | 452 | rtc::Thread* PeerConnectionFactory::network_thread() { |
| 453 | return network_thread_; |
| 454 | } |
| 455 | |
eladalon | 248fd4f | 2017-09-06 12:18:15 | [diff] [blame] | 456 | std::unique_ptr<RtcEventLog> PeerConnectionFactory::CreateRtcEventLog_w() { |
eladalon | 591753b | 2017-09-06 19:33:43 | [diff] [blame] | 457 | RTC_DCHECK_RUN_ON(worker_thread_); |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 458 | const auto encoding_type = RtcEventLog::EncodingType::Legacy; |
| 459 | return event_log_factory_ |
| 460 | ? event_log_factory_->CreateRtcEventLog(encoding_type) |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame^] | 461 | : absl::make_unique<RtcEventLogNullImpl>(); |
eladalon | 248fd4f | 2017-09-06 12:18:15 | [diff] [blame] | 462 | } |
| 463 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 464 | std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w( |
| 465 | RtcEventLog* event_log) { |
eladalon | 591753b | 2017-09-06 19:33:43 | [diff] [blame] | 466 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 467 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 468 | const int kMinBandwidthBps = 30000; |
| 469 | const int kStartBandwidthBps = 300000; |
| 470 | const int kMaxBandwidthBps = 2000000; |
| 471 | |
| 472 | webrtc::Call::Config call_config(event_log); |
| 473 | if (!channel_manager_->media_engine() || !call_factory_) { |
| 474 | return nullptr; |
| 475 | } |
| 476 | call_config.audio_state = channel_manager_->media_engine()->GetAudioState(); |
| 477 | call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
| 478 | call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
| 479 | call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
| 480 | |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 481 | call_config.fec_controller_factory = fec_controller_factory_.get(); |
| 482 | |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [diff] [blame] | 483 | if (CongestionControllerExperiment::BbrControllerEnabled()) { |
| 484 | RTC_LOG(LS_INFO) << "Using BBR network controller factory"; |
| 485 | call_config.network_controller_factory = |
| 486 | bbr_network_controller_factory_.get(); |
| 487 | } else if (CongestionControllerExperiment::InjectedControllerEnabled()) { |
| 488 | RTC_LOG(LS_INFO) << "Using injected network controller factory"; |
| 489 | call_config.network_controller_factory = |
| 490 | injected_network_controller_factory_.get(); |
| 491 | } else { |
| 492 | RTC_LOG(LS_INFO) << "Using default network controller factory"; |
| 493 | } |
| 494 | |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 495 | return std::unique_ptr<Call>(call_factory_->CreateCall(call_config)); |
| 496 | } |
| 497 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 498 | } // namespace webrtc |