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

Side by Side Diff: content/renderer/media/webrtc/peer_connection_dependency_factory.cc

Issue 503683003: Remove implicit conversions from scoped_refptr to T* in content/renderer/media/webrtc* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" 5 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 P2PSocketDispatcher* p2p_socket_dispatcher) 173 P2PSocketDispatcher* p2p_socket_dispatcher)
174 : network_manager_(NULL), 174 : network_manager_(NULL),
175 p2p_socket_dispatcher_(p2p_socket_dispatcher), 175 p2p_socket_dispatcher_(p2p_socket_dispatcher),
176 signaling_thread_(NULL), 176 signaling_thread_(NULL),
177 worker_thread_(NULL), 177 worker_thread_(NULL),
178 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { 178 chrome_worker_thread_("Chrome_libJingle_WorkerThread") {
179 } 179 }
180 180
181 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() { 181 PeerConnectionDependencyFactory::~PeerConnectionDependencyFactory() {
182 CleanupPeerConnectionFactory(); 182 CleanupPeerConnectionFactory();
183 if (aec_dump_message_filter_) 183 if (aec_dump_message_filter_.get())
184 aec_dump_message_filter_->RemoveDelegate(this); 184 aec_dump_message_filter_->RemoveDelegate(this);
185 } 185 }
186 186
187 blink::WebRTCPeerConnectionHandler* 187 blink::WebRTCPeerConnectionHandler*
188 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler( 188 PeerConnectionDependencyFactory::CreateRTCPeerConnectionHandler(
189 blink::WebRTCPeerConnectionHandlerClient* client) { 189 blink::WebRTCPeerConnectionHandlerClient* client) {
190 // Save histogram data so we can see how much PeerConnetion is used. 190 // Save histogram data so we can see how much PeerConnetion is used.
191 // The histogram counts the number of calls to the JS API 191 // The histogram counts the number of calls to the JS API
192 // webKitRTCPeerConnection. 192 // webKitRTCPeerConnection.
193 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION); 193 UpdateWebRTCMethodCount(WEBKIT_RTC_PEER_CONNECTION);
(...skipping 23 matching lines...) Expand all
217 source_data)); 217 source_data));
218 if (!capturer.get()) { 218 if (!capturer.get()) {
219 DLOG(WARNING) << "Failed to create the capturer for device " 219 DLOG(WARNING) << "Failed to create the capturer for device "
220 << device_info.device.id; 220 << device_info.device.id;
221 // TODO(xians): Don't we need to check if source_observer is observing 221 // TODO(xians): Don't we need to check if source_observer is observing
222 // something? If not, then it looks like we have a leak here. 222 // something? If not, then it looks like we have a leak here.
223 // OTOH, if it _is_ observing something, then the callback might 223 // OTOH, if it _is_ observing something, then the callback might
224 // be called multiple times which is likely also a bug. 224 // be called multiple times which is likely also a bug.
225 return false; 225 return false;
226 } 226 }
227 source_data->SetAudioCapturer(capturer); 227 source_data->SetAudioCapturer(capturer.get());
228 228
229 // Creates a LocalAudioSource object which holds audio options. 229 // Creates a LocalAudioSource object which holds audio options.
230 // TODO(xians): The option should apply to the track instead of the source. 230 // TODO(xians): The option should apply to the track instead of the source.
231 // TODO(perkj): Move audio constraints parsing to Chrome. 231 // TODO(perkj): Move audio constraints parsing to Chrome.
232 // Currently there are a few constraints that are parsed by libjingle and 232 // Currently there are a few constraints that are parsed by libjingle and
233 // the state is set to ended if parsing fails. 233 // the state is set to ended if parsing fails.
234 scoped_refptr<webrtc::AudioSourceInterface> rtc_source( 234 scoped_refptr<webrtc::AudioSourceInterface> rtc_source(
235 CreateLocalAudioSource(&constraints).get()); 235 CreateLocalAudioSource(&constraints).get());
236 if (rtc_source->state() != webrtc::MediaSourceInterface::kLive) { 236 if (rtc_source->state() != webrtc::MediaSourceInterface::kLive) {
237 DLOG(WARNING) << "Failed to create rtc LocalAudioSource."; 237 DLOG(WARNING) << "Failed to create rtc LocalAudioSource.";
238 return false; 238 return false;
239 } 239 }
240 source_data->SetLocalAudioSource(rtc_source); 240 source_data->SetLocalAudioSource(rtc_source.get());
241 return true; 241 return true;
242 } 242 }
243 243
244 WebRtcVideoCapturerAdapter* 244 WebRtcVideoCapturerAdapter*
245 PeerConnectionDependencyFactory::CreateVideoCapturer( 245 PeerConnectionDependencyFactory::CreateVideoCapturer(
246 bool is_screeencast) { 246 bool is_screeencast) {
247 // We need to make sure the libjingle thread wrappers have been created 247 // We need to make sure the libjingle thread wrappers have been created
248 // before we can use an instance of a WebRtcVideoCapturerAdapter. This is 248 // before we can use an instance of a WebRtcVideoCapturerAdapter. This is
249 // since the base class of WebRtcVideoCapturerAdapter is a 249 // since the base class of WebRtcVideoCapturerAdapter is a
250 // cricket::VideoCapturer and it uses the libjingle thread wrappers. 250 // cricket::VideoCapturer and it uses the libjingle thread wrappers.
251 if (!GetPcFactory()) 251 if (!GetPcFactory().get())
252 return NULL; 252 return NULL;
253 return new WebRtcVideoCapturerAdapter(is_screeencast); 253 return new WebRtcVideoCapturerAdapter(is_screeencast);
254 } 254 }
255 255
256 scoped_refptr<webrtc::VideoSourceInterface> 256 scoped_refptr<webrtc::VideoSourceInterface>
257 PeerConnectionDependencyFactory::CreateVideoSource( 257 PeerConnectionDependencyFactory::CreateVideoSource(
258 cricket::VideoCapturer* capturer, 258 cricket::VideoCapturer* capturer,
259 const blink::WebMediaConstraints& constraints) { 259 const blink::WebMediaConstraints& constraints) {
260 RTCMediaConstraints webrtc_constraints(constraints); 260 RTCMediaConstraints webrtc_constraints(constraints);
261 scoped_refptr<webrtc::VideoSourceInterface> source = 261 scoped_refptr<webrtc::VideoSourceInterface> source =
262 GetPcFactory()->CreateVideoSource(capturer, &webrtc_constraints).get(); 262 GetPcFactory()->CreateVideoSource(capturer, &webrtc_constraints).get();
263 return source; 263 return source;
264 } 264 }
265 265
266 const scoped_refptr<webrtc::PeerConnectionFactoryInterface>& 266 const scoped_refptr<webrtc::PeerConnectionFactoryInterface>&
267 PeerConnectionDependencyFactory::GetPcFactory() { 267 PeerConnectionDependencyFactory::GetPcFactory() {
268 if (!pc_factory_) 268 if (!pc_factory_.get())
269 CreatePeerConnectionFactory(); 269 CreatePeerConnectionFactory();
270 CHECK(pc_factory_); 270 CHECK(pc_factory_.get());
271 return pc_factory_; 271 return pc_factory_;
272 } 272 }
273 273
274 void PeerConnectionDependencyFactory::CreatePeerConnectionFactory() { 274 void PeerConnectionDependencyFactory::CreatePeerConnectionFactory() {
275 DCHECK(!pc_factory_.get()); 275 DCHECK(!pc_factory_.get());
276 DCHECK(!signaling_thread_); 276 DCHECK(!signaling_thread_);
277 DCHECK(!worker_thread_); 277 DCHECK(!worker_thread_);
278 DCHECK(!network_manager_); 278 DCHECK(!network_manager_);
279 DCHECK(!socket_factory_); 279 DCHECK(!socket_factory_);
280 DCHECK(!chrome_worker_thread_.IsRunning()); 280 DCHECK(!chrome_worker_thread_.IsRunning());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 net::EnsureNSSSSLInit(); 319 net::EnsureNSSSSLInit();
320 #endif 320 #endif
321 321
322 scoped_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory; 322 scoped_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory;
323 scoped_ptr<cricket::WebRtcVideoEncoderFactory> encoder_factory; 323 scoped_ptr<cricket::WebRtcVideoEncoderFactory> encoder_factory;
324 324
325 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 325 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
326 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories = 326 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories =
327 RenderThreadImpl::current()->GetGpuFactories(); 327 RenderThreadImpl::current()->GetGpuFactories();
328 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWDecoding)) { 328 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWDecoding)) {
329 if (gpu_factories) 329 if (gpu_factories.get())
330 decoder_factory.reset(new RTCVideoDecoderFactory(gpu_factories)); 330 decoder_factory.reset(new RTCVideoDecoderFactory(gpu_factories));
331 } 331 }
332 332
333 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding)) { 333 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding)) {
334 if (gpu_factories) 334 if (gpu_factories.get())
335 encoder_factory.reset(new RTCVideoEncoderFactory(gpu_factories)); 335 encoder_factory.reset(new RTCVideoEncoderFactory(gpu_factories));
336 } 336 }
337 337
338 #if defined(OS_ANDROID) 338 #if defined(OS_ANDROID)
339 if (!media::MediaCodecBridge::SupportsSetParameters()) 339 if (!media::MediaCodecBridge::SupportsSetParameters())
340 encoder_factory.reset(); 340 encoder_factory.reset();
341 #endif 341 #endif
342 342
343 EnsureWebRtcAudioDeviceImpl(); 343 EnsureWebRtcAudioDeviceImpl();
344 344
345 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 345 scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
346 webrtc::CreatePeerConnectionFactory(worker_thread_, 346 webrtc::CreatePeerConnectionFactory(worker_thread_,
347 signaling_thread_, 347 signaling_thread_,
348 audio_device_.get(), 348 audio_device_.get(),
349 encoder_factory.release(), 349 encoder_factory.release(),
350 decoder_factory.release())); 350 decoder_factory.release()));
351 CHECK(factory); 351 CHECK(factory.get());
352 352
353 pc_factory_ = factory; 353 pc_factory_ = factory;
354 webrtc::PeerConnectionFactoryInterface::Options factory_options; 354 webrtc::PeerConnectionFactoryInterface::Options factory_options;
355 factory_options.disable_sctp_data_channels = false; 355 factory_options.disable_sctp_data_channels = false;
356 factory_options.disable_encryption = 356 factory_options.disable_encryption =
357 cmd_line->HasSwitch(switches::kDisableWebRtcEncryption); 357 cmd_line->HasSwitch(switches::kDisableWebRtcEncryption);
358 pc_factory_->SetOptions(factory_options); 358 pc_factory_->SetOptions(factory_options);
359 359
360 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing 360 // TODO(xians): Remove the following code after kDisableAudioTrackProcessing
361 // is removed. 361 // is removed.
362 if (!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) { 362 if (!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()) {
363 aec_dump_message_filter_ = AecDumpMessageFilter::Get(); 363 aec_dump_message_filter_ = AecDumpMessageFilter::Get();
364 // In unit tests not creating a message filter, |aec_dump_message_filter_| 364 // In unit tests not creating a message filter, |aec_dump_message_filter_|
365 // will be NULL. We can just ignore that. Other unit tests and browser tests 365 // will be NULL. We can just ignore that. Other unit tests and browser tests
366 // ensure that we do get the filter when we should. 366 // ensure that we do get the filter when we should.
367 if (aec_dump_message_filter_) 367 if (aec_dump_message_filter_.get())
368 aec_dump_message_filter_->AddDelegate(this); 368 aec_dump_message_filter_->AddDelegate(this);
369 } 369 }
370 } 370 }
371 371
372 bool PeerConnectionDependencyFactory::PeerConnectionFactoryCreated() { 372 bool PeerConnectionDependencyFactory::PeerConnectionFactoryCreated() {
373 return pc_factory_.get() != NULL; 373 return pc_factory_.get() != NULL;
374 } 374 }
375 375
376 scoped_refptr<webrtc::PeerConnectionInterface> 376 scoped_refptr<webrtc::PeerConnectionInterface>
377 PeerConnectionDependencyFactory::CreatePeerConnection( 377 PeerConnectionDependencyFactory::CreatePeerConnection(
378 const webrtc::PeerConnectionInterface::RTCConfiguration& config, 378 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
379 const webrtc::MediaConstraintsInterface* constraints, 379 const webrtc::MediaConstraintsInterface* constraints,
380 blink::WebFrame* web_frame, 380 blink::WebFrame* web_frame,
381 webrtc::PeerConnectionObserver* observer) { 381 webrtc::PeerConnectionObserver* observer) {
382 CHECK(web_frame); 382 CHECK(web_frame);
383 CHECK(observer); 383 CHECK(observer);
384 if (!GetPcFactory()) 384 if (!GetPcFactory().get())
385 return NULL; 385 return NULL;
386 386
387 scoped_refptr<P2PPortAllocatorFactory> pa_factory = 387 scoped_refptr<P2PPortAllocatorFactory> pa_factory =
388 new rtc::RefCountedObject<P2PPortAllocatorFactory>( 388 new rtc::RefCountedObject<P2PPortAllocatorFactory>(
389 p2p_socket_dispatcher_.get(), 389 p2p_socket_dispatcher_.get(),
390 network_manager_, 390 network_manager_,
391 socket_factory_.get(), 391 socket_factory_.get(),
392 web_frame); 392 web_frame);
393 393
394 PeerConnectionIdentityService* identity_service = 394 PeerConnectionIdentityService* identity_service =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Creates an adapter to hold all the libjingle objects. 442 // Creates an adapter to hold all the libjingle objects.
443 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 443 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
444 WebRtcLocalAudioTrackAdapter::Create(track.id().utf8(), 444 WebRtcLocalAudioTrackAdapter::Create(track.id().utf8(),
445 source_data->local_audio_source())); 445 source_data->local_audio_source()));
446 static_cast<webrtc::AudioTrackInterface*>(adapter.get())->set_enabled( 446 static_cast<webrtc::AudioTrackInterface*>(adapter.get())->set_enabled(
447 track.isEnabled()); 447 track.isEnabled());
448 448
449 // TODO(xians): Merge |source| to the capturer(). We can't do this today 449 // TODO(xians): Merge |source| to the capturer(). We can't do this today
450 // because only one capturer() is supported while one |source| is created 450 // because only one capturer() is supported while one |source| is created
451 // for each audio track. 451 // for each audio track.
452 scoped_ptr<WebRtcLocalAudioTrack> audio_track( 452 scoped_ptr<WebRtcLocalAudioTrack> audio_track(new WebRtcLocalAudioTrack(
453 new WebRtcLocalAudioTrack(adapter, 453 adapter.get(), source_data->GetAudioCapturer(), webaudio_source.get()));
454 source_data->GetAudioCapturer(),
455 webaudio_source));
456 454
457 StartLocalAudioTrack(audio_track.get()); 455 StartLocalAudioTrack(audio_track.get());
458 456
459 // Pass the ownership of the native local audio track to the blink track. 457 // Pass the ownership of the native local audio track to the blink track.
460 blink::WebMediaStreamTrack writable_track = track; 458 blink::WebMediaStreamTrack writable_track = track;
461 writable_track.setExtraData(audio_track.release()); 459 writable_track.setExtraData(audio_track.release());
462 } 460 }
463 461
464 void PeerConnectionDependencyFactory::StartLocalAudioTrack( 462 void PeerConnectionDependencyFactory::StartLocalAudioTrack(
465 WebRtcLocalAudioTrack* audio_track) { 463 WebRtcLocalAudioTrack* audio_track) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled()); 647 DCHECK(!MediaStreamAudioProcessor::IsAudioTrackProcessingEnabled());
650 // Do nothing. We never disable AEC dump for non-track-processing case. 648 // Do nothing. We never disable AEC dump for non-track-processing case.
651 } 649 }
652 650
653 void PeerConnectionDependencyFactory::OnIpcClosing() { 651 void PeerConnectionDependencyFactory::OnIpcClosing() {
654 DCHECK(CalledOnValidThread()); 652 DCHECK(CalledOnValidThread());
655 aec_dump_message_filter_ = NULL; 653 aec_dump_message_filter_ = NULL;
656 } 654 }
657 655
658 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { 656 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() {
659 if (audio_device_) 657 if (audio_device_.get())
660 return; 658 return;
661 659
662 audio_device_ = new WebRtcAudioDeviceImpl(); 660 audio_device_ = new WebRtcAudioDeviceImpl();
663 } 661 }
664 662
665 } // namespace content 663 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698