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