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