henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/peerconnectionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 13 | #include <utility> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "api/mediaconstraintsinterface.h" |
| 16 | #include "api/mediastreamproxy.h" |
| 17 | #include "api/mediastreamtrackproxy.h" |
| 18 | #include "api/peerconnectionfactoryproxy.h" |
| 19 | #include "api/peerconnectionproxy.h" |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 20 | #include "api/turncustomizer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/videosourceproxy.h" |
| 22 | #include "logging/rtc_event_log/rtc_event_log.h" |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame^] | 23 | #include "media/sctp/sctptransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "rtc_base/bind.h" |
| 25 | #include "rtc_base/checks.h" |
| 26 | #include "rtc_base/ptr_util.h" |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 27 | // Adding 'nogncheck' to disable the gn include headers check to support modular |
| 28 | // WebRTC build targets. |
| 29 | // TODO(zhihuang): This wouldn't be necessary if the interface and |
| 30 | // implementation of the media engine were in separate build targets. |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "media/engine/webrtcmediaengine.h" // nogncheck |
| 32 | #include "media/engine/webrtcvideodecoderfactory.h" // nogncheck |
| 33 | #include "media/engine/webrtcvideoencoderfactory.h" // nogncheck |
| 34 | #include "modules/audio_device/include/audio_device.h" // nogncheck |
| 35 | #include "p2p/base/basicpacketsocketfactory.h" |
| 36 | #include "p2p/client/basicportallocator.h" |
| 37 | #include "pc/audiotrack.h" |
| 38 | #include "pc/localaudiosource.h" |
| 39 | #include "pc/mediastream.h" |
| 40 | #include "pc/peerconnection.h" |
| 41 | #include "pc/videocapturertracksource.h" |
| 42 | #include "pc/videotrack.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | namespace webrtc { |
| 45 | |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 46 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 47 | CreateModularPeerConnectionFactory( |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 48 | rtc::Thread* network_thread, |
| 49 | rtc::Thread* worker_thread, |
| 50 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 51 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 52 | std::unique_ptr<CallFactoryInterface> call_factory, |
| 53 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) { |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 54 | rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 55 | new rtc::RefCountedObject<PeerConnectionFactory>( |
Magnus Jedvert | 835cc0c | 2017-09-23 16:14:25 +0200 | [diff] [blame] | 56 | network_thread, worker_thread, signaling_thread, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 57 | std::move(media_engine), std::move(call_factory), |
| 58 | std::move(event_log_factory))); |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 59 | |
| 60 | // Call Initialize synchronously but make sure it is executed on |
| 61 | // |signaling_thread|. |
| 62 | MethodCall0<PeerConnectionFactory, bool> call( |
| 63 | pc_factory.get(), &PeerConnectionFactory::Initialize); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 64 | bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread()); |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 65 | |
| 66 | if (!result) { |
| 67 | return nullptr; |
| 68 | } |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 69 | return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), |
| 70 | pc_factory); |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 71 | } |
| 72 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | PeerConnectionFactory::PeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 74 | rtc::Thread* network_thread, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 75 | rtc::Thread* worker_thread, |
| 76 | rtc::Thread* signaling_thread, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 77 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 78 | std::unique_ptr<webrtc::CallFactoryInterface> call_factory, |
| 79 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) |
| 80 | : wraps_current_thread_(false), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 81 | network_thread_(network_thread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | worker_thread_(worker_thread), |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 83 | signaling_thread_(signaling_thread), |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 84 | media_engine_(std::move(media_engine)), |
| 85 | call_factory_(std::move(call_factory)), |
| 86 | event_log_factory_(std::move(event_log_factory)) { |
| 87 | if (!network_thread_) { |
| 88 | owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); |
| 89 | owned_network_thread_->Start(); |
| 90 | network_thread_ = owned_network_thread_.get(); |
| 91 | } |
| 92 | |
| 93 | if (!worker_thread_) { |
| 94 | owned_worker_thread_ = rtc::Thread::Create(); |
| 95 | owned_worker_thread_->Start(); |
| 96 | worker_thread_ = owned_worker_thread_.get(); |
| 97 | } |
| 98 | |
| 99 | if (!signaling_thread_) { |
| 100 | signaling_thread_ = rtc::Thread::Current(); |
| 101 | if (!signaling_thread_) { |
| 102 | // If this thread isn't already wrapped by an rtc::Thread, create a |
| 103 | // wrapper and own it in this class. |
| 104 | signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); |
| 105 | wraps_current_thread_ = true; |
| 106 | } |
| 107 | } |
| 108 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | // TODO: Currently there is no way creating an external adm in |
| 110 | // libjingle source tree. So we can 't currently assert if this is NULL. |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 111 | // RTC_DCHECK(default_adm != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | PeerConnectionFactory::~PeerConnectionFactory() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 115 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 116 | channel_manager_.reset(nullptr); |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 117 | |
| 118 | // Make sure |worker_thread_| and |signaling_thread_| outlive |
Henrik Boström | cebf0a2 | 2016-06-01 15:45:30 +0200 | [diff] [blame] | 119 | // |default_socket_factory_| and |default_network_manager_|. |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 120 | default_socket_factory_ = nullptr; |
| 121 | default_network_manager_ = nullptr; |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 +0000 | [diff] [blame] | 122 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 123 | if (wraps_current_thread_) |
| 124 | rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | bool PeerConnectionFactory::Initialize() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 128 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 129 | rtc::InitRandom(rtc::Time32()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 131 | default_network_manager_.reset(new rtc::BasicNetworkManager()); |
| 132 | if (!default_network_manager_) { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | default_socket_factory_.reset( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 137 | new rtc::BasicPacketSocketFactory(network_thread_)); |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 138 | if (!default_socket_factory_) { |
| 139 | return false; |
| 140 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 142 | channel_manager_.reset(new cricket::ChannelManager( |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 143 | std::move(media_engine_), worker_thread_, network_thread_)); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 144 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 +0000 | [diff] [blame] | 145 | channel_manager_->SetVideoRtxEnabled(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | if (!channel_manager_->Init()) { |
| 147 | return false; |
| 148 | } |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 149 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 153 | void PeerConnectionFactory::SetOptions(const Options& options) { |
| 154 | options_ = options; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 155 | } |
| 156 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 157 | rtc::scoped_refptr<AudioSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 158 | PeerConnectionFactory::CreateAudioSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 159 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 160 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 161 | rtc::scoped_refptr<LocalAudioSource> source( |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 162 | LocalAudioSource::Create(constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | return source; |
| 164 | } |
| 165 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 166 | rtc::scoped_refptr<AudioSourceInterface> |
| 167 | PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) { |
| 168 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 169 | rtc::scoped_refptr<LocalAudioSource> source( |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 170 | LocalAudioSource::Create(&options)); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 171 | return source; |
| 172 | } |
| 173 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 174 | rtc::scoped_refptr<VideoTrackSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 175 | PeerConnectionFactory::CreateVideoSource( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 176 | std::unique_ptr<cricket::VideoCapturer> capturer, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 178 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 179 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 180 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 181 | constraints, false)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 182 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 183 | source); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | } |
| 185 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 186 | rtc::scoped_refptr<VideoTrackSourceInterface> |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 187 | PeerConnectionFactory::CreateVideoSource( |
| 188 | std::unique_ptr<cricket::VideoCapturer> capturer) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 189 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 190 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 191 | VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), |
| 192 | false)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 193 | return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, |
| 194 | source); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 195 | } |
| 196 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 197 | bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file, |
| 198 | int64_t max_size_bytes) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 199 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 200 | return channel_manager_->StartAecDump(file, max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 201 | } |
| 202 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 203 | void PeerConnectionFactory::StopAecDump() { |
| 204 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 205 | channel_manager_->StopAecDump(); |
| 206 | } |
| 207 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 208 | rtc::scoped_refptr<PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | PeerConnectionFactory::CreatePeerConnection( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 210 | const PeerConnectionInterface::RTCConfiguration& configuration_in, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 211 | const MediaConstraintsInterface* constraints, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 212 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 213 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 214 | PeerConnectionObserver* observer) { |
| 215 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 216 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 217 | // We merge constraints and configuration into a single configuration. |
| 218 | PeerConnectionInterface::RTCConfiguration configuration = configuration_in; |
| 219 | CopyConstraintsIntoRtcConfiguration(constraints, &configuration); |
| 220 | |
| 221 | return CreatePeerConnection(configuration, std::move(allocator), |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 222 | std::move(cert_generator), observer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | rtc::scoped_refptr<PeerConnectionInterface> |
| 226 | PeerConnectionFactory::CreatePeerConnection( |
| 227 | const PeerConnectionInterface::RTCConfiguration& configuration, |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 228 | std::unique_ptr<cricket::PortAllocator> allocator, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 229 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 230 | PeerConnectionObserver* observer) { |
| 231 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 232 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 233 | if (!cert_generator.get()) { |
Henrik Boström | cebf0a2 | 2016-06-01 15:45:30 +0200 | [diff] [blame] | 234 | // No certificate generator specified, use the default one. |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 235 | cert_generator.reset( |
Henrik Boström | cebf0a2 | 2016-06-01 15:45:30 +0200 | [diff] [blame] | 236 | new rtc::RTCCertificateGenerator(signaling_thread_, network_thread_)); |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 237 | } |
| 238 | |
jonaso | c251cb1 | 2017-08-29 03:20:58 -0700 | [diff] [blame] | 239 | if (!allocator) { |
| 240 | allocator.reset(new cricket::BasicPortAllocator( |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 241 | default_network_manager_.get(), default_socket_factory_.get(), |
| 242 | configuration.turn_customizer)); |
jonaso | c251cb1 | 2017-08-29 03:20:58 -0700 | [diff] [blame] | 243 | } |
| 244 | network_thread_->Invoke<void>( |
| 245 | RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask, |
| 246 | allocator.get(), options_.network_ignore_mask)); |
| 247 | |
eladalon | 393a9f6 | 2017-09-05 04:30:30 -0700 | [diff] [blame] | 248 | std::unique_ptr<RtcEventLog> event_log = |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 249 | worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>( |
| 250 | RTC_FROM_HERE, |
| 251 | rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this)); |
maxmorin | e9ef907 | 2017-08-29 04:49:00 -0700 | [diff] [blame] | 252 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 253 | std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>( |
| 254 | RTC_FROM_HERE, |
| 255 | rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get())); |
| 256 | |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 257 | rtc::scoped_refptr<PeerConnection> pc( |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 258 | new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log), |
| 259 | std::move(call))); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 260 | |
nisse | c36b31b | 2016-04-11 23:25:29 -0700 | [diff] [blame] | 261 | if (!pc->Initialize(configuration, std::move(allocator), |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 262 | std::move(cert_generator), observer)) { |
deadbeef | 41b0798 | 2015-12-01 15:01:24 -0800 | [diff] [blame] | 263 | return nullptr; |
| 264 | } |
| 265 | return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 266 | } |
| 267 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 268 | rtc::scoped_refptr<MediaStreamInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 269 | PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 270 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | return MediaStreamProxy::Create(signaling_thread_, |
| 272 | MediaStream::Create(label)); |
| 273 | } |
| 274 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 275 | rtc::scoped_refptr<VideoTrackInterface> PeerConnectionFactory::CreateVideoTrack( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 276 | const std::string& id, |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 277 | VideoTrackSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 278 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 279 | rtc::scoped_refptr<VideoTrackInterface> track( |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 280 | VideoTrack::Create(id, source, worker_thread_)); |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 281 | return VideoTrackProxy::Create(signaling_thread_, worker_thread_, track); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 282 | } |
| 283 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 284 | rtc::scoped_refptr<AudioTrackInterface> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 285 | PeerConnectionFactory::CreateAudioTrack(const std::string& id, |
| 286 | AudioSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 287 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 6eca7e3 | 2015-12-15 04:27:11 -0800 | [diff] [blame] | 288 | rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 289 | return AudioTrackProxy::Create(signaling_thread_, track); |
| 290 | } |
| 291 | |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 292 | cricket::TransportController* PeerConnectionFactory::CreateTransportController( |
Honghai Zhang | bfd398c | 2016-08-30 22:07:42 -0700 | [diff] [blame] | 293 | cricket::PortAllocator* port_allocator, |
| 294 | bool redetermine_role_on_ice_restart) { |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 295 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 296 | return new cricket::TransportController( |
| 297 | signaling_thread_, network_thread_, port_allocator, |
| 298 | redetermine_role_on_ice_restart, options_.crypto_options); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame^] | 301 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 302 | PeerConnectionFactory::CreateSctpTransportInternalFactory() { |
| 303 | #ifdef HAVE_SCTP |
| 304 | return rtc::MakeUnique<cricket::SctpTransportFactory>(network_thread()); |
| 305 | #else |
| 306 | return nullptr; |
| 307 | #endif |
| 308 | } |
| 309 | |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 310 | cricket::ChannelManager* PeerConnectionFactory::channel_manager() { |
| 311 | return channel_manager_.get(); |
| 312 | } |
| 313 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 314 | rtc::Thread* PeerConnectionFactory::signaling_thread() { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 315 | // This method can be called on a different thread when the factory is |
| 316 | // created in CreatePeerConnectionFactory(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | return signaling_thread_; |
| 318 | } |
| 319 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 320 | rtc::Thread* PeerConnectionFactory::worker_thread() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | return worker_thread_; |
| 322 | } |
| 323 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 324 | rtc::Thread* PeerConnectionFactory::network_thread() { |
| 325 | return network_thread_; |
| 326 | } |
| 327 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 328 | std::unique_ptr<RtcEventLog> PeerConnectionFactory::CreateRtcEventLog_w() { |
eladalon | 591753b | 2017-09-06 12:33:43 -0700 | [diff] [blame] | 329 | RTC_DCHECK_RUN_ON(worker_thread_); |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 330 | const auto encoding_type = RtcEventLog::EncodingType::Legacy; |
| 331 | return event_log_factory_ |
| 332 | ? event_log_factory_->CreateRtcEventLog(encoding_type) |
| 333 | : rtc::MakeUnique<RtcEventLogNullImpl>(); |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 334 | } |
| 335 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 336 | std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w( |
| 337 | RtcEventLog* event_log) { |
eladalon | 591753b | 2017-09-06 12:33:43 -0700 | [diff] [blame] | 338 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 339 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 340 | const int kMinBandwidthBps = 30000; |
| 341 | const int kStartBandwidthBps = 300000; |
| 342 | const int kMaxBandwidthBps = 2000000; |
| 343 | |
| 344 | webrtc::Call::Config call_config(event_log); |
| 345 | if (!channel_manager_->media_engine() || !call_factory_) { |
| 346 | return nullptr; |
| 347 | } |
| 348 | call_config.audio_state = channel_manager_->media_engine()->GetAudioState(); |
| 349 | call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
| 350 | call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
| 351 | call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
| 352 | |
| 353 | return std::unique_ptr<Call>(call_factory_->CreateCall(call_config)); |
| 354 | } |
| 355 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | } // namespace webrtc |