Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: talk/app/webrtc/peerconnectionfactory.cc

Issue 1176383004: DtlsIdentityStore[Interface/Impl] updated, DtlsIdentityService to be removed (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed dtlsidentitystore_unittest and made RequestIdentity etc take scoped_refptr instead of ptr Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004--2011 Google Inc. 3 * Copyright 2004--2011 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 10 matching lines...) Expand all
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 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, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 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 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/peerconnectionfactory.h" 28 #include "talk/app/webrtc/peerconnectionfactory.h"
29 29
30 #include "talk/app/webrtc/audiotrack.h" 30 #include "talk/app/webrtc/audiotrack.h"
31 #include "talk/app/webrtc/dtlsidentityservice.h"
32 #include "talk/app/webrtc/dtlsidentitystore.h"
33 #include "talk/app/webrtc/localaudiosource.h" 31 #include "talk/app/webrtc/localaudiosource.h"
34 #include "talk/app/webrtc/mediastreamproxy.h" 32 #include "talk/app/webrtc/mediastreamproxy.h"
35 #include "talk/app/webrtc/mediastreamtrackproxy.h" 33 #include "talk/app/webrtc/mediastreamtrackproxy.h"
36 #include "talk/app/webrtc/peerconnection.h" 34 #include "talk/app/webrtc/peerconnection.h"
37 #include "talk/app/webrtc/peerconnectionfactoryproxy.h" 35 #include "talk/app/webrtc/peerconnectionfactoryproxy.h"
38 #include "talk/app/webrtc/peerconnectionproxy.h" 36 #include "talk/app/webrtc/peerconnectionproxy.h"
39 #include "talk/app/webrtc/portallocatorfactory.h" 37 #include "talk/app/webrtc/portallocatorfactory.h"
40 #include "talk/app/webrtc/videosource.h" 38 #include "talk/app/webrtc/videosource.h"
41 #include "talk/app/webrtc/videosourceproxy.h" 39 #include "talk/app/webrtc/videosourceproxy.h"
42 #include "talk/app/webrtc/videotrack.h" 40 #include "talk/app/webrtc/videotrack.h"
43 #include "talk/media/devices/dummydevicemanager.h" 41 #include "talk/media/devices/dummydevicemanager.h"
44 #include "talk/media/webrtc/webrtcmediaengine.h" 42 #include "talk/media/webrtc/webrtcmediaengine.h"
45 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" 43 #include "talk/media/webrtc/webrtcvideodecoderfactory.h"
46 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" 44 #include "talk/media/webrtc/webrtcvideoencoderfactory.h"
47 #include "webrtc/base/bind.h" 45 #include "webrtc/base/bind.h"
48 #include "webrtc/modules/audio_device/include/audio_device.h" 46 #include "webrtc/modules/audio_device/include/audio_device.h"
49 47
50 namespace webrtc { 48 namespace webrtc {
51 49
50 namespace {
51
52 // Passes down the calls to |store_|. See usage in CreatePeerConnection.
53 class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface {
54 public:
55 DtlsIdentityStoreWrapper(
56 const rtc::scoped_refptr<RefCountedDtlsIdentityStore>& store)
57 : store_(store) {
58 DCHECK(store_);
59 }
60
61 void Initialize() override {
62 store_->Initialize();
63 }
64 void RequestIdentity(rtc::KeyType key_type,
65 ScopedRefPtrObserver observer) override {
66 store_->RequestIdentity(key_type, observer);
67 }
68
69 private:
70 rtc::scoped_refptr<RefCountedDtlsIdentityStore> store_;
71 };
72
73 } // anonymous namespace
74
52 rtc::scoped_refptr<PeerConnectionFactoryInterface> 75 rtc::scoped_refptr<PeerConnectionFactoryInterface>
53 CreatePeerConnectionFactory() { 76 CreatePeerConnectionFactory() {
54 rtc::scoped_refptr<PeerConnectionFactory> pc_factory( 77 rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
55 new rtc::RefCountedObject<PeerConnectionFactory>()); 78 new rtc::RefCountedObject<PeerConnectionFactory>());
56 79
57 80
58 // Call Initialize synchronously but make sure its executed on 81 // Call Initialize synchronously but make sure its executed on
59 // |signaling_thread|. 82 // |signaling_thread|.
60 MethodCall0<PeerConnectionFactory, bool> call( 83 MethodCall0<PeerConnectionFactory, bool> call(
61 pc_factory.get(), 84 pc_factory.get(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 video_decoder_factory_(video_decoder_factory) { 146 video_decoder_factory_(video_decoder_factory) {
124 ASSERT(worker_thread != NULL); 147 ASSERT(worker_thread != NULL);
125 ASSERT(signaling_thread != NULL); 148 ASSERT(signaling_thread != NULL);
126 // TODO: Currently there is no way creating an external adm in 149 // TODO: Currently there is no way creating an external adm in
127 // libjingle source tree. So we can 't currently assert if this is NULL. 150 // libjingle source tree. So we can 't currently assert if this is NULL.
128 // ASSERT(default_adm != NULL); 151 // ASSERT(default_adm != NULL);
129 } 152 }
130 153
131 PeerConnectionFactory::~PeerConnectionFactory() { 154 PeerConnectionFactory::~PeerConnectionFactory() {
132 DCHECK(signaling_thread_->IsCurrent()); 155 DCHECK(signaling_thread_->IsCurrent());
133 channel_manager_.reset(NULL); 156 channel_manager_.reset(nullptr);
134 default_allocator_factory_ = NULL; 157 default_allocator_factory_ = nullptr;
135 158
136 // Make sure |worker_thread_| and |signaling_thread_| outlive 159 // Make sure |worker_thread_| and |signaling_thread_| outlive
137 // |dtls_identity_store_|. 160 // |dtls_identity_store_|.
138 dtls_identity_store_.reset(NULL); 161 dtls_identity_store_ = nullptr;
139 162
140 if (owns_ptrs_) { 163 if (owns_ptrs_) {
141 if (wraps_current_thread_) 164 if (wraps_current_thread_)
142 rtc::ThreadManager::Instance()->UnwrapCurrentThread(); 165 rtc::ThreadManager::Instance()->UnwrapCurrentThread();
143 delete worker_thread_; 166 delete worker_thread_;
144 } 167 }
145 } 168 }
146 169
147 bool PeerConnectionFactory::Initialize() { 170 bool PeerConnectionFactory::Initialize() {
148 DCHECK(signaling_thread_->IsCurrent()); 171 DCHECK(signaling_thread_->IsCurrent());
(...skipping 13 matching lines...) Expand all
162 &PeerConnectionFactory::CreateMediaEngine_w, this)); 185 &PeerConnectionFactory::CreateMediaEngine_w, this));
163 186
164 channel_manager_.reset(new cricket::ChannelManager( 187 channel_manager_.reset(new cricket::ChannelManager(
165 media_engine, device_manager, worker_thread_)); 188 media_engine, device_manager, worker_thread_));
166 189
167 channel_manager_->SetVideoRtxEnabled(true); 190 channel_manager_->SetVideoRtxEnabled(true);
168 if (!channel_manager_->Init()) { 191 if (!channel_manager_->Init()) {
169 return false; 192 return false;
170 } 193 }
171 194
172 dtls_identity_store_.reset( 195 dtls_identity_store_ = new RefCountedDtlsIdentityStore(
173 new DtlsIdentityStore(signaling_thread_, worker_thread_)); 196 signaling_thread_, worker_thread_);
174 dtls_identity_store_->Initialize(); 197 dtls_identity_store_->Initialize();
175 198
176 return true; 199 return true;
177 } 200 }
178 201
179 rtc::scoped_refptr<AudioSourceInterface> 202 rtc::scoped_refptr<AudioSourceInterface>
180 PeerConnectionFactory::CreateAudioSource( 203 PeerConnectionFactory::CreateAudioSource(
181 const MediaConstraintsInterface* constraints) { 204 const MediaConstraintsInterface* constraints) {
182 DCHECK(signaling_thread_->IsCurrent()); 205 DCHECK(signaling_thread_->IsCurrent());
183 rtc::scoped_refptr<LocalAudioSource> source( 206 rtc::scoped_refptr<LocalAudioSource> source(
(...skipping 14 matching lines...) Expand all
198 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) { 221 bool PeerConnectionFactory::StartAecDump(rtc::PlatformFile file) {
199 DCHECK(signaling_thread_->IsCurrent()); 222 DCHECK(signaling_thread_->IsCurrent());
200 return channel_manager_->StartAecDump(file); 223 return channel_manager_->StartAecDump(file);
201 } 224 }
202 225
203 rtc::scoped_refptr<PeerConnectionInterface> 226 rtc::scoped_refptr<PeerConnectionInterface>
204 PeerConnectionFactory::CreatePeerConnection( 227 PeerConnectionFactory::CreatePeerConnection(
205 const PeerConnectionInterface::RTCConfiguration& configuration, 228 const PeerConnectionInterface::RTCConfiguration& configuration,
206 const MediaConstraintsInterface* constraints, 229 const MediaConstraintsInterface* constraints,
207 PortAllocatorFactoryInterface* allocator_factory, 230 PortAllocatorFactoryInterface* allocator_factory,
208 DTLSIdentityServiceInterface* dtls_identity_service, 231 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
209 PeerConnectionObserver* observer) { 232 PeerConnectionObserver* observer) {
210 DCHECK(signaling_thread_->IsCurrent()); 233 DCHECK(signaling_thread_->IsCurrent());
211 DCHECK(allocator_factory || default_allocator_factory_); 234 DCHECK(allocator_factory || default_allocator_factory_);
212 235
213 if (!dtls_identity_service) { 236 if (!dtls_identity_store.get()) {
214 dtls_identity_service = new DtlsIdentityService(dtls_identity_store_.get()); 237 // Because |pc|->Initialize takes ownership of the store we need a new
238 // wrapper object that can be deleted without deleting the underlying
239 // |dtls_identity_store_|, protecting it from being deleted multiple times.
240 dtls_identity_store.reset(
241 new DtlsIdentityStoreWrapper(dtls_identity_store_));
215 } 242 }
216 243
217 PortAllocatorFactoryInterface* chosen_allocator_factory = 244 PortAllocatorFactoryInterface* chosen_allocator_factory =
218 allocator_factory ? allocator_factory : default_allocator_factory_.get(); 245 allocator_factory ? allocator_factory : default_allocator_factory_.get();
219 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask); 246 chosen_allocator_factory->SetNetworkIgnoreMask(options_.network_ignore_mask);
220 247
221 rtc::scoped_refptr<PeerConnection> pc( 248 rtc::scoped_refptr<PeerConnection> pc(
222 new rtc::RefCountedObject<PeerConnection>(this)); 249 new rtc::RefCountedObject<PeerConnection>(this));
223 if (!pc->Initialize( 250 if (!pc->Initialize(
224 configuration, 251 configuration,
225 constraints, 252 constraints,
226 chosen_allocator_factory, 253 chosen_allocator_factory,
227 dtls_identity_service, 254 dtls_identity_store.Pass(),
228 observer)) { 255 observer)) {
229 return NULL; 256 return NULL;
230 } 257 }
231 return PeerConnectionProxy::Create(signaling_thread(), pc); 258 return PeerConnectionProxy::Create(signaling_thread(), pc);
232 } 259 }
233 260
234 rtc::scoped_refptr<MediaStreamInterface> 261 rtc::scoped_refptr<MediaStreamInterface>
235 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { 262 PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) {
236 DCHECK(signaling_thread_->IsCurrent()); 263 DCHECK(signaling_thread_->IsCurrent());
237 return MediaStreamProxy::Create(signaling_thread_, 264 return MediaStreamProxy::Create(signaling_thread_,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 301 }
275 302
276 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { 303 cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() {
277 ASSERT(worker_thread_ == rtc::Thread::Current()); 304 ASSERT(worker_thread_ == rtc::Thread::Current());
278 return cricket::WebRtcMediaEngineFactory::Create( 305 return cricket::WebRtcMediaEngineFactory::Create(
279 default_adm_.get(), video_encoder_factory_.get(), 306 default_adm_.get(), video_encoder_factory_.get(),
280 video_decoder_factory_.get()); 307 video_decoder_factory_.get());
281 } 308 }
282 309
283 } // namespace webrtc 310 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698