henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 | [diff] [blame] | 3 | * Copyright 2004--2011 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "talk/app/webrtc/peerconnectionfactory.h" |
| 29 | |
| 30 | #include "talk/app/webrtc/audiotrack.h" |
| 31 | #include "talk/app/webrtc/localaudiosource.h" |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 32 | #include "talk/app/webrtc/mediastream.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 33 | #include "talk/app/webrtc/mediastreamproxy.h" |
| 34 | #include "talk/app/webrtc/mediastreamtrackproxy.h" |
| 35 | #include "talk/app/webrtc/peerconnection.h" |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 36 | #include "talk/app/webrtc/peerconnectionfactoryproxy.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 37 | #include "talk/app/webrtc/peerconnectionproxy.h" |
| 38 | #include "talk/app/webrtc/portallocatorfactory.h" |
wu@webrtc.org | 967bfff | 2013-09-19 05:49:50 | [diff] [blame] | 39 | #include "talk/app/webrtc/videosource.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 40 | #include "talk/app/webrtc/videosourceproxy.h" |
| 41 | #include "talk/app/webrtc/videotrack.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 42 | #include "talk/media/webrtc/webrtcmediaengine.h" |
| 43 | #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
| 44 | #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
jiayl@webrtc.org | 3987b6d | 2014-09-24 17:14:05 | [diff] [blame] | 45 | #include "webrtc/base/bind.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 46 | #include "webrtc/modules/audio_device/include/audio_device.h" |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 47 | #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
| 48 | #include "webrtc/p2p/client/basicportallocator.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 | |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 52 | namespace { |
| 53 | |
| 54 | // Passes down the calls to |store_|. See usage in CreatePeerConnection. |
| 55 | class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface { |
| 56 | public: |
| 57 | DtlsIdentityStoreWrapper( |
| 58 | const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store) |
| 59 | : store_(store) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 60 | RTC_DCHECK(store_); |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void RequestIdentity( |
| 64 | rtc::KeyType key_type, |
| 65 | const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& |
| 66 | observer) override { |
| 67 | store_->RequestIdentity(key_type, observer); |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | rtc::scoped_refptr<RefCountedDtlsIdentityStore> store_; |
| 72 | }; |
| 73 | |
| 74 | } // anonymous namespace |
| 75 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 76 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 77 | CreatePeerConnectionFactory() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 78 | rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 79 | new rtc::RefCountedObject<PeerConnectionFactory>()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 80 | |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 81 | |
| 82 | // Call Initialize synchronously but make sure its executed on |
| 83 | // |signaling_thread|. |
| 84 | MethodCall0<PeerConnectionFactory, bool> call( |
| 85 | pc_factory.get(), |
| 86 | &PeerConnectionFactory::Initialize); |
| 87 | bool result = call.Marshal(pc_factory->signaling_thread()); |
| 88 | |
| 89 | if (!result) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 90 | return NULL; |
| 91 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 92 | return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), |
| 93 | pc_factory); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | } |
| 95 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 96 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 97 | CreatePeerConnectionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 98 | rtc::Thread* worker_thread, |
| 99 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 100 | AudioDeviceModule* default_adm, |
| 101 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 102 | cricket::WebRtcVideoDecoderFactory* decoder_factory) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 103 | rtc::scoped_refptr<PeerConnectionFactory> pc_factory( |
| 104 | new rtc::RefCountedObject<PeerConnectionFactory>(worker_thread, |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 105 | signaling_thread, |
| 106 | default_adm, |
| 107 | encoder_factory, |
| 108 | decoder_factory)); |
| 109 | |
| 110 | // Call Initialize synchronously but make sure its executed on |
| 111 | // |signaling_thread|. |
| 112 | MethodCall0<PeerConnectionFactory, bool> call( |
| 113 | pc_factory.get(), |
| 114 | &PeerConnectionFactory::Initialize); |
| 115 | bool result = call.Marshal(signaling_thread); |
| 116 | |
| 117 | if (!result) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 118 | return NULL; |
| 119 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 120 | return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | PeerConnectionFactory::PeerConnectionFactory() |
| 124 | : owns_ptrs_(true), |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 125 | wraps_current_thread_(false), |
| 126 | signaling_thread_(rtc::ThreadManager::Instance()->CurrentThread()), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 127 | worker_thread_(new rtc::Thread) { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 128 | if (!signaling_thread_) { |
| 129 | signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread(); |
| 130 | wraps_current_thread_ = true; |
| 131 | } |
| 132 | worker_thread_->Start(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | PeerConnectionFactory::PeerConnectionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 136 | rtc::Thread* worker_thread, |
| 137 | rtc::Thread* signaling_thread, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 138 | AudioDeviceModule* default_adm, |
| 139 | cricket::WebRtcVideoEncoderFactory* video_encoder_factory, |
| 140 | cricket::WebRtcVideoDecoderFactory* video_decoder_factory) |
| 141 | : owns_ptrs_(false), |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 142 | wraps_current_thread_(false), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 143 | signaling_thread_(signaling_thread), |
| 144 | worker_thread_(worker_thread), |
| 145 | default_adm_(default_adm), |
| 146 | video_encoder_factory_(video_encoder_factory), |
| 147 | video_decoder_factory_(video_decoder_factory) { |
| 148 | ASSERT(worker_thread != NULL); |
| 149 | ASSERT(signaling_thread != NULL); |
| 150 | // TODO: Currently there is no way creating an external adm in |
| 151 | // libjingle source tree. So we can 't currently assert if this is NULL. |
| 152 | // ASSERT(default_adm != NULL); |
| 153 | } |
| 154 | |
| 155 | PeerConnectionFactory::~PeerConnectionFactory() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 156 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 157 | channel_manager_.reset(nullptr); |
| 158 | default_allocator_factory_ = nullptr; |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 | [diff] [blame] | 159 | |
| 160 | // Make sure |worker_thread_| and |signaling_thread_| outlive |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 161 | // |dtls_identity_store_|, |default_socket_factory_| and |
| 162 | // |default_network_manager_|. |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 163 | dtls_identity_store_ = nullptr; |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 164 | default_socket_factory_ = nullptr; |
| 165 | default_network_manager_ = nullptr; |
jiayl@webrtc.org | d83f4ef | 2015-03-13 21:26:12 | [diff] [blame] | 166 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 167 | if (owns_ptrs_) { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 168 | if (wraps_current_thread_) |
| 169 | rtc::ThreadManager::Instance()->UnwrapCurrentThread(); |
fischman@webrtc.org | 29540b1 | 2014-04-17 22:54:30 | [diff] [blame] | 170 | delete worker_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| 174 | bool PeerConnectionFactory::Initialize() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 175 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 176 | rtc::InitRandom(rtc::Time()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 177 | |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 | [diff] [blame] | 178 | default_allocator_factory_ = PortAllocatorFactory::Create(worker_thread_); |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 179 | if (!default_allocator_factory_) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 180 | return false; |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | default_network_manager_.reset(new rtc::BasicNetworkManager()); |
| 184 | if (!default_network_manager_) { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | default_socket_factory_.reset( |
| 189 | new rtc::BasicPacketSocketFactory(worker_thread_)); |
| 190 | if (!default_socket_factory_) { |
| 191 | return false; |
| 192 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 193 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 194 | // TODO: Need to make sure only one VoE is created inside |
| 195 | // WebRtcMediaEngine. |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 196 | cricket::MediaEngineInterface* media_engine = |
| 197 | worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind( |
| 198 | &PeerConnectionFactory::CreateMediaEngine_w, this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 199 | |
solenberg | facbbec | 2015-09-24 07:41:50 | [diff] [blame] | 200 | channel_manager_.reset( |
| 201 | new cricket::ChannelManager(media_engine, worker_thread_)); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 202 | |
stefan@webrtc.org | 85d2794 | 2014-06-09 12:51:39 | [diff] [blame] | 203 | channel_manager_->SetVideoRtxEnabled(true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 204 | if (!channel_manager_->Init()) { |
| 205 | return false; |
| 206 | } |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 207 | |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 208 | dtls_identity_store_ = new RefCountedDtlsIdentityStore( |
| 209 | signaling_thread_, worker_thread_); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 210 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 211 | return true; |
| 212 | } |
| 213 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 214 | rtc::scoped_refptr<AudioSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 215 | PeerConnectionFactory::CreateAudioSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 216 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 217 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 218 | rtc::scoped_refptr<LocalAudioSource> source( |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 219 | LocalAudioSource::Create(options_, constraints)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 220 | return source; |
| 221 | } |
| 222 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 223 | rtc::scoped_refptr<VideoSourceInterface> |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 224 | PeerConnectionFactory::CreateVideoSource( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 225 | cricket::VideoCapturer* capturer, |
| 226 | const MediaConstraintsInterface* constraints) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 227 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame^] | 228 | rtc::scoped_refptr<VideoSource> source(VideoSource::Create( |
| 229 | channel_manager_.get(), capturer, constraints, false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 230 | return VideoSourceProxy::Create(signaling_thread_, source); |
| 231 | } |
| 232 | |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 233 | bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 234 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 235 | return channel_manager_->StartAecDump(file); |
| 236 | } |
| 237 | |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 238 | void PeerConnectionFactory::StopAecDump() { |
| 239 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 240 | channel_manager_->StopAecDump(); |
| 241 | } |
| 242 | |
ivoc | 112a3d8 | 2015-10-16 09:22:18 | [diff] [blame] | 243 | bool PeerConnectionFactory::StartRtcEventLog(rtc::PlatformFile file) { |
| 244 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 245 | return channel_manager_->StartRtcEventLog(file); |
| 246 | } |
| 247 | |
| 248 | void PeerConnectionFactory::StopRtcEventLog() { |
| 249 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 250 | channel_manager_->StopRtcEventLog(); |
| 251 | } |
| 252 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 253 | rtc::scoped_refptr<PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 254 | PeerConnectionFactory::CreatePeerConnection( |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 | [diff] [blame] | 255 | const PeerConnectionInterface::RTCConfiguration& configuration, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 256 | const MediaConstraintsInterface* constraints, |
| 257 | PortAllocatorFactoryInterface* allocator_factory, |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 258 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 259 | PeerConnectionObserver* observer) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 260 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 261 | RTC_DCHECK(allocator_factory || default_allocator_factory_); |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 | [diff] [blame] | 262 | |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 263 | if (!dtls_identity_store.get()) { |
| 264 | // Because |pc|->Initialize takes ownership of the store we need a new |
| 265 | // wrapper object that can be deleted without deleting the underlying |
| 266 | // |dtls_identity_store_|, protecting it from being deleted multiple times. |
| 267 | dtls_identity_store.reset( |
| 268 | new DtlsIdentityStoreWrapper(dtls_identity_store_)); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 269 | } |
| 270 | |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 | [diff] [blame] | 271 | PortAllocatorFactoryInterface* chosen_allocator_factory = |
| 272 | allocator_factory ? allocator_factory : default_allocator_factory_.get(); |
| 273 | chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); |
| 274 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 275 | rtc::scoped_refptr<PeerConnection> pc( |
| 276 | new rtc::RefCountedObject<PeerConnection>(this)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 277 | if (!pc->Initialize( |
| 278 | configuration, |
| 279 | constraints, |
phoglund@webrtc.org | 006521d | 2015-02-12 09:23:59 | [diff] [blame] | 280 | chosen_allocator_factory, |
Henrik Boström | 5e56c59 | 2015-08-11 08:33:13 | [diff] [blame] | 281 | dtls_identity_store.Pass(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 282 | observer)) { |
| 283 | return NULL; |
| 284 | } |
| 285 | return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 286 | } |
| 287 | |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 288 | rtc::scoped_refptr<PeerConnectionInterface> |
| 289 | PeerConnectionFactory::CreatePeerConnection( |
| 290 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 291 | const MediaConstraintsInterface* constraints, |
| 292 | rtc::scoped_ptr<cricket::PortAllocator> allocator, |
| 293 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 294 | PeerConnectionObserver* observer) { |
| 295 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 296 | |
| 297 | if (!dtls_identity_store.get()) { |
| 298 | // Because |pc|->Initialize takes ownership of the store we need a new |
| 299 | // wrapper object that can be deleted without deleting the underlying |
| 300 | // |dtls_identity_store_|, protecting it from being deleted multiple times. |
| 301 | dtls_identity_store.reset( |
| 302 | new DtlsIdentityStoreWrapper(dtls_identity_store_)); |
| 303 | } |
| 304 | |
| 305 | if (!allocator) { |
| 306 | allocator.reset(new cricket::BasicPortAllocator( |
| 307 | default_network_manager_.get(), default_socket_factory_.get())); |
| 308 | } |
| 309 | default_network_manager_->set_network_ignore_mask( |
| 310 | options_.network_ignore_mask); |
| 311 | |
| 312 | rtc::scoped_refptr<PeerConnection> pc( |
| 313 | new rtc::RefCountedObject<PeerConnection>(this)); |
| 314 | if (!pc->Initialize(configuration, constraints, std::move(allocator), |
| 315 | std::move(dtls_identity_store), observer)) { |
| 316 | return nullptr; |
| 317 | } |
| 318 | return PeerConnectionProxy::Create(signaling_thread(), pc); |
| 319 | } |
| 320 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 321 | rtc::scoped_refptr<MediaStreamInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 322 | PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 323 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 324 | return MediaStreamProxy::Create(signaling_thread_, |
| 325 | MediaStream::Create(label)); |
| 326 | } |
| 327 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 328 | rtc::scoped_refptr<VideoTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 329 | PeerConnectionFactory::CreateVideoTrack( |
| 330 | const std::string& id, |
| 331 | VideoSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 332 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 333 | rtc::scoped_refptr<VideoTrackInterface> track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 334 | VideoTrack::Create(id, source)); |
| 335 | return VideoTrackProxy::Create(signaling_thread_, track); |
| 336 | } |
| 337 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 338 | rtc::scoped_refptr<AudioTrackInterface> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 | [diff] [blame] | 339 | PeerConnectionFactory::CreateAudioTrack(const std::string& id, |
| 340 | AudioSourceInterface* source) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 341 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 6eca7e3 | 2015-12-15 12:27:11 | [diff] [blame^] | 342 | rtc::scoped_refptr<AudioTrackInterface> track(AudioTrack::Create(id, source)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 343 | return AudioTrackProxy::Create(signaling_thread_, track); |
| 344 | } |
| 345 | |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 346 | webrtc::MediaControllerInterface* PeerConnectionFactory::CreateMediaController() |
| 347 | const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 348 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 349 | return MediaControllerInterface::Create(worker_thread_, |
| 350 | channel_manager_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 351 | } |
| 352 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 353 | rtc::Thread* PeerConnectionFactory::signaling_thread() { |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 354 | // This method can be called on a different thread when the factory is |
| 355 | // created in CreatePeerConnectionFactory(). |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 356 | return signaling_thread_; |
| 357 | } |
| 358 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 359 | rtc::Thread* PeerConnectionFactory::worker_thread() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 360 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 361 | return worker_thread_; |
| 362 | } |
| 363 | |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 364 | cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { |
| 365 | ASSERT(worker_thread_ == rtc::Thread::Current()); |
| 366 | return cricket::WebRtcMediaEngineFactory::Create( |
Fredrik Solenberg | ccb49e7 | 2015-05-19 09:37:56 | [diff] [blame] | 367 | default_adm_.get(), video_encoder_factory_.get(), |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 | [diff] [blame] | 368 | video_decoder_factory_.get()); |
| 369 | } |
| 370 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 371 | } // namespace webrtc |