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

Side by Side Diff: content/renderer/media/media_stream_impl.cc

Issue 10387135: Add deletion observer to P2PSocketDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix dll export. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/media_stream_impl.h ('k') | content/renderer/p2p/socket_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/media_stream_impl.h" 5 #include "content/renderer/media/media_stream_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "content/renderer/media/capture_video_decoder.h" 15 #include "content/renderer/media/capture_video_decoder.h"
16 #include "content/renderer/media/media_stream_extra_data.h" 16 #include "content/renderer/media/media_stream_extra_data.h"
17 #include "content/renderer/media/media_stream_dependency_factory.h" 17 #include "content/renderer/media/media_stream_dependency_factory.h"
18 #include "content/renderer/media/media_stream_dispatcher.h" 18 #include "content/renderer/media/media_stream_dispatcher.h"
19 #include "content/renderer/media/peer_connection_handler.h" 19 #include "content/renderer/media/peer_connection_handler.h"
20 #include "content/renderer/media/peer_connection_handler_jsep.h" 20 #include "content/renderer/media/peer_connection_handler_jsep.h"
21 #include "content/renderer/media/video_capture_impl_manager.h" 21 #include "content/renderer/media/video_capture_impl_manager.h"
22 #include "content/renderer/media/video_capture_module_impl.h" 22 #include "content/renderer/media/video_capture_module_impl.h"
23 #include "content/renderer/media/webrtc_audio_device_impl.h" 23 #include "content/renderer/media/webrtc_audio_device_impl.h"
24 #include "content/renderer/p2p/ipc_network_manager.h" 24 #include "content/renderer/p2p/ipc_network_manager.h"
25 #include "content/renderer/p2p/ipc_socket_factory.h" 25 #include "content/renderer/p2p/ipc_socket_factory.h"
26 #include "content/renderer/p2p/socket_dispatcher.h"
27 #include "jingle/glue/thread_wrapper.h" 26 #include "jingle/glue/thread_wrapper.h"
28 #include "media/base/message_loop_factory.h" 27 #include "media/base/message_loop_factory.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
36 35
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 media_stream_dispatcher_(media_stream_dispatcher), 83 media_stream_dispatcher_(media_stream_dispatcher),
85 p2p_socket_dispatcher_(p2p_socket_dispatcher), 84 p2p_socket_dispatcher_(p2p_socket_dispatcher),
86 network_manager_(NULL), 85 network_manager_(NULL),
87 vc_manager_(vc_manager), 86 vc_manager_(vc_manager),
88 signaling_thread_(NULL), 87 signaling_thread_(NULL),
89 worker_thread_(NULL), 88 worker_thread_(NULL),
90 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { 89 chrome_worker_thread_("Chrome_libJingle_WorkerThread") {
91 } 90 }
92 91
93 MediaStreamImpl::~MediaStreamImpl() { 92 MediaStreamImpl::~MediaStreamImpl() {
94 DCHECK(local_media_streams_.empty()); 93 CleanupPeerConnectionFactory();
95 if (dependency_factory_.get())
96 dependency_factory_->ReleasePeerConnectionFactory();
97 if (network_manager_) {
98 // The network manager needs to free its resources on the thread they were
99 // created, which is the worked thread.
100 if (chrome_worker_thread_.IsRunning()) {
101 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
102 &MediaStreamImpl::DeleteIpcNetworkManager,
103 base::Unretained(this)));
104 // Stopping the thread will wait until all tasks have been
105 // processed before returning. We wait for the above task to finish before
106 // letting the destructor continue to avoid any potential race issues.
107 chrome_worker_thread_.Stop();
108 } else {
109 NOTREACHED() << "Worker thread not running.";
110 }
111 }
112 } 94 }
113 95
114 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler( 96 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler(
115 WebKit::WebPeerConnectionHandlerClient* client) { 97 WebKit::WebPeerConnectionHandlerClient* client) {
116 // Save histogram data so we can see how much PeerConnetion is used. 98 // Save histogram data so we can see how much PeerConnetion is used.
117 // The histogram counts the number of calls to the JS API 99 // The histogram counts the number of calls to the JS API
118 // webKitDeprecatedPeerConnection. 100 // webKitDeprecatedPeerConnection.
119 UpdateWebRTCMethodCount(kWebkitDeprecatedPeerConnection); 101 UpdateWebRTCMethodCount(kWebkitDeprecatedPeerConnection);
120 DCHECK(CalledOnValidThread()); 102 DCHECK(CalledOnValidThread());
121 if (!EnsurePeerConnectionFactory()) 103 if (!EnsurePeerConnectionFactory())
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 << "Stopping stream " << it->first; 355 << "Stopping stream " << it->first;
374 media_stream_dispatcher_->StopStream(it->first); 356 media_stream_dispatcher_->StopStream(it->first);
375 local_media_streams_.erase(it); 357 local_media_streams_.erase(it);
376 it = local_media_streams_.begin(); 358 it = local_media_streams_.begin();
377 } else { 359 } else {
378 ++it; 360 ++it;
379 } 361 }
380 } 362 }
381 } 363 }
382 364
365 void MediaStreamImpl::OnSocketDispatcherDestroyed() {
366 CleanupPeerConnectionFactory();
367 }
368
383 void MediaStreamImpl::InitializeWorkerThread(talk_base::Thread** thread, 369 void MediaStreamImpl::InitializeWorkerThread(talk_base::Thread** thread,
384 base::WaitableEvent* event) { 370 base::WaitableEvent* event) {
385 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread(); 371 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread();
386 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); 372 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true);
387 *thread = jingle_glue::JingleThreadWrapper::current(); 373 *thread = jingle_glue::JingleThreadWrapper::current();
388 event->Signal(); 374 event->Signal();
389 } 375 }
390 376
391 void MediaStreamImpl::CreateIpcNetworkManagerOnWorkerThread( 377 void MediaStreamImpl::CreateIpcNetworkManagerOnWorkerThread(
392 base::WaitableEvent* event) { 378 base::WaitableEvent* event) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DCHECK(worker_thread_); 413 DCHECK(worker_thread_);
428 } 414 }
429 415
430 if (!network_manager_) { 416 if (!network_manager_) {
431 base::WaitableEvent event(true, false); 417 base::WaitableEvent event(true, false);
432 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 418 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
433 &MediaStreamImpl::CreateIpcNetworkManagerOnWorkerThread, 419 &MediaStreamImpl::CreateIpcNetworkManagerOnWorkerThread,
434 base::Unretained(this), 420 base::Unretained(this),
435 &event)); 421 &event));
436 event.Wait(); 422 event.Wait();
423 p2p_socket_dispatcher_->AddDestructionObserver(this);
437 } 424 }
438 425
439 if (!socket_factory_.get()) { 426 if (!socket_factory_.get()) {
440 socket_factory_.reset( 427 socket_factory_.reset(
441 new content::IpcPacketSocketFactory(p2p_socket_dispatcher_)); 428 new content::IpcPacketSocketFactory(p2p_socket_dispatcher_));
442 } 429 }
443 430
444 if (!dependency_factory_->PeerConnectionFactoryCreated()) { 431 if (!dependency_factory_->PeerConnectionFactoryCreated()) {
445 if (!dependency_factory_->CreatePeerConnectionFactory( 432 if (!dependency_factory_->CreatePeerConnectionFactory(
446 worker_thread_, 433 worker_thread_,
447 signaling_thread_, 434 signaling_thread_,
448 p2p_socket_dispatcher_, 435 p2p_socket_dispatcher_,
449 network_manager_, 436 network_manager_,
450 socket_factory_.get())) { 437 socket_factory_.get())) {
451 LOG(ERROR) << "Could not create PeerConnection factory"; 438 LOG(ERROR) << "Could not create PeerConnection factory";
452 return false; 439 return false;
453 } 440 }
454 } 441 }
455 442
456 return true; 443 return true;
457 } 444 }
458 445
446 void MediaStreamImpl::CleanupPeerConnectionFactory() {
447 if (dependency_factory_.get())
448 dependency_factory_->ReleasePeerConnectionFactory();
449 if (network_manager_) {
450 // The network manager needs to free its resources on the thread they were
451 // created, which is the worked thread.
452 if (chrome_worker_thread_.IsRunning()) {
453 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
454 &MediaStreamImpl::DeleteIpcNetworkManager,
455 base::Unretained(this)));
456 // Stopping the thread will wait until all tasks have been
457 // processed before returning. We wait for the above task to finish before
458 // letting the the function continue to avoid any potential race issues.
459 chrome_worker_thread_.Stop();
460 } else {
461 NOTREACHED() << "Worker thread not running.";
462 }
463 p2p_socket_dispatcher_->RemoveDestructionObserver(this);
464 }
465 }
466
459 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( 467 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder(
460 webrtc::MediaStreamInterface* stream, 468 webrtc::MediaStreamInterface* stream,
461 media::MessageLoopFactory* message_loop_factory) { 469 media::MessageLoopFactory* message_loop_factory) {
462 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) 470 if (!stream->video_tracks() || stream->video_tracks()->count() == 0)
463 return NULL; 471 return NULL;
464 472
465 int video_session_id = 473 int video_session_id =
466 media_stream_dispatcher_->video_session_id(stream->label(), 0); 474 media_stream_dispatcher_->video_session_id(stream->label(), 0);
467 media::VideoCaptureCapability capability; 475 media::VideoCaptureCapability capability;
468 capability.width = kVideoCaptureWidth; 476 capability.width = kVideoCaptureWidth;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 MediaStreamExtraData::MediaStreamExtraData( 563 MediaStreamExtraData::MediaStreamExtraData(
556 webrtc::MediaStreamInterface* remote_stream) 564 webrtc::MediaStreamInterface* remote_stream)
557 : remote_stream_(remote_stream) { 565 : remote_stream_(remote_stream) {
558 } 566 }
559 MediaStreamExtraData::MediaStreamExtraData( 567 MediaStreamExtraData::MediaStreamExtraData(
560 webrtc::LocalMediaStreamInterface* local_stream) 568 webrtc::LocalMediaStreamInterface* local_stream)
561 : local_stream_(local_stream) { 569 : local_stream_(local_stream) {
562 } 570 }
563 MediaStreamExtraData::~MediaStreamExtraData() { 571 MediaStreamExtraData::~MediaStreamExtraData() {
564 } 572 }
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_impl.h ('k') | content/renderer/p2p/socket_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698