OLD | NEW |
---|---|
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/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "content/renderer/media/capture_video_decoder.h" | 13 #include "content/renderer/media/capture_video_decoder.h" |
14 #include "content/renderer/media/media_stream_center.h" | |
14 #include "content/renderer/media/media_stream_dependency_factory.h" | 15 #include "content/renderer/media/media_stream_dependency_factory.h" |
15 #include "content/renderer/media/media_stream_dispatcher.h" | 16 #include "content/renderer/media/media_stream_dispatcher.h" |
16 #include "content/renderer/media/peer_connection_handler.h" | 17 #include "content/renderer/media/peer_connection_handler.h" |
17 #include "content/renderer/media/video_capture_impl_manager.h" | 18 #include "content/renderer/media/video_capture_impl_manager.h" |
18 #include "content/renderer/media/video_capture_module_impl.h" | 19 #include "content/renderer/media/video_capture_module_impl.h" |
19 #include "content/renderer/media/webrtc_audio_device_impl.h" | 20 #include "content/renderer/media/webrtc_audio_device_impl.h" |
20 #include "content/renderer/p2p/ipc_network_manager.h" | 21 #include "content/renderer/p2p/ipc_network_manager.h" |
21 #include "content/renderer/p2p/ipc_socket_factory.h" | 22 #include "content/renderer/p2p/ipc_socket_factory.h" |
22 #include "content/renderer/p2p/socket_dispatcher.h" | 23 #include "content/renderer/p2p/socket_dispatcher.h" |
23 #include "jingle/glue/thread_wrapper.h" | 24 #include "jingle/glue/thread_wrapper.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 MediaStreamDispatcher* media_stream_dispatcher, | 75 MediaStreamDispatcher* media_stream_dispatcher, |
75 content::P2PSocketDispatcher* p2p_socket_dispatcher, | 76 content::P2PSocketDispatcher* p2p_socket_dispatcher, |
76 VideoCaptureImplManager* vc_manager, | 77 VideoCaptureImplManager* vc_manager, |
77 MediaStreamDependencyFactory* dependency_factory) | 78 MediaStreamDependencyFactory* dependency_factory) |
78 : dependency_factory_(dependency_factory), | 79 : dependency_factory_(dependency_factory), |
79 media_stream_dispatcher_(media_stream_dispatcher), | 80 media_stream_dispatcher_(media_stream_dispatcher), |
80 p2p_socket_dispatcher_(p2p_socket_dispatcher), | 81 p2p_socket_dispatcher_(p2p_socket_dispatcher), |
81 network_manager_(NULL), | 82 network_manager_(NULL), |
82 vc_manager_(vc_manager), | 83 vc_manager_(vc_manager), |
83 peer_connection_handler_(NULL), | 84 peer_connection_handler_(NULL), |
85 media_stream_center_(NULL), | |
84 message_loop_proxy_(base::MessageLoopProxy::current()), | 86 message_loop_proxy_(base::MessageLoopProxy::current()), |
85 signaling_thread_(NULL), | 87 signaling_thread_(NULL), |
86 worker_thread_(NULL), | 88 worker_thread_(NULL), |
87 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { | 89 chrome_worker_thread_("Chrome_libJingle_WorkerThread") { |
88 } | 90 } |
89 | 91 |
90 MediaStreamImpl::~MediaStreamImpl() { | 92 MediaStreamImpl::~MediaStreamImpl() { |
91 DCHECK(!peer_connection_handler_); | 93 DCHECK(!peer_connection_handler_); |
92 if (dependency_factory_.get()) | 94 if (dependency_factory_.get()) |
93 dependency_factory_->ReleasePeerConnectionFactory(); | 95 dependency_factory_->ReleasePeerConnectionFactory(); |
94 if (network_manager_) { | 96 if (network_manager_) { |
95 // The network manager needs to free its resources on the thread they were | 97 // The network manager needs to free its resources on the thread they were |
96 // created, which is the worked thread. | 98 // created, which is the worked thread. |
97 if (chrome_worker_thread_.IsRunning()) { | 99 if (chrome_worker_thread_.IsRunning()) { |
98 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 100 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
99 &MediaStreamImpl::DeleteIpcNetworkManager, | 101 &MediaStreamImpl::DeleteIpcNetworkManager, |
100 base::Unretained(this))); | 102 base::Unretained(this))); |
101 } else { | 103 } else { |
102 NOTREACHED() << "Worker thread not running."; | 104 NOTREACHED() << "Worker thread not running."; |
103 } | 105 } |
104 } | 106 } |
105 } | 107 } |
106 | 108 |
107 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler( | 109 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler( |
108 WebKit::WebPeerConnectionHandlerClient* client) { | 110 WebKit::WebPeerConnectionHandlerClient* client) { |
109 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
110 if (peer_connection_handler_) { | 112 if (peer_connection_handler_) { |
111 DVLOG(1) << "A PeerConnection already exists"; | 113 DVLOG(1) << "A PeerConnection already exists"; |
tommi (sloooow) - chröme
2012/02/03 14:39:45
should this be a NOTREACHED()? (a question for Hen
tommyw
2012/02/03 14:58:25
No, we need to support more than one PeerConnectio
Henrik Grunell
2012/02/06 20:06:49
Agree, furthermore WebKit should be allowed to cal
| |
112 return NULL; | 114 return NULL; |
113 } | 115 } |
114 EnsurePeerConnectionFactory(); | 116 EnsurePeerConnectionFactory(); |
115 | 117 |
116 peer_connection_handler_ = new PeerConnectionHandler( | 118 peer_connection_handler_ = new PeerConnectionHandler( |
117 client, | 119 client, |
118 this, | 120 this, |
119 dependency_factory_.get()); | 121 dependency_factory_.get()); |
120 | 122 |
121 return peer_connection_handler_; | 123 return peer_connection_handler_; |
122 } | 124 } |
123 | 125 |
126 WebKit::WebMediaStreamCenter* MediaStreamImpl::CreateMediaStreamCenter( | |
127 WebKit::WebMediaStreamCenterClient* client) { | |
128 DCHECK(CalledOnValidThread()); | |
129 DCHECK(!media_stream_center_); | |
130 | |
131 media_stream_center_ = new MediaStreamCenter(client); | |
tommi (sloooow) - chröme
2012/02/03 14:39:45
why do we hold on to the pointer?
Isn't the owners
tommyw
2012/02/03 14:58:25
Eventually MediaStreamImpl (aka the glue code) nee
| |
132 return media_stream_center_; | |
133 } | |
134 | |
124 void MediaStreamImpl::ClosePeerConnection() { | 135 void MediaStreamImpl::ClosePeerConnection() { |
125 DCHECK(CalledOnValidThread()); | 136 DCHECK(CalledOnValidThread()); |
126 video_renderer_ = NULL; | 137 video_renderer_ = NULL; |
127 peer_connection_handler_ = NULL; | 138 peer_connection_handler_ = NULL; |
128 // TODO(grunell): This is a temporary workaround for an error in native | 139 // TODO(grunell): This is a temporary workaround for an error in native |
129 // PeerConnection where added live tracks are not seen on the remote side. | 140 // PeerConnection where added live tracks are not seen on the remote side. |
130 MediaStreamTrackPtrMap::const_iterator it = local_tracks_.begin(); | 141 MediaStreamTrackPtrMap::const_iterator it = local_tracks_.begin(); |
131 for (; it != local_tracks_.end(); ++it) | 142 for (; it != local_tracks_.end(); ++it) |
132 it->second->set_state(webrtc::MediaStreamTrackInterface::kEnded); | 143 it->second->set_state(webrtc::MediaStreamTrackInterface::kEnded); |
133 } | 144 } |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 } | 460 } |
450 | 461 |
451 MediaStreamImpl::VideoRendererWrapper::VideoRendererWrapper() {} | 462 MediaStreamImpl::VideoRendererWrapper::VideoRendererWrapper() {} |
452 | 463 |
453 MediaStreamImpl::VideoRendererWrapper::~VideoRendererWrapper() {} | 464 MediaStreamImpl::VideoRendererWrapper::~VideoRendererWrapper() {} |
454 | 465 |
455 void MediaStreamImpl::VideoRendererWrapper::SetVideoDecoder( | 466 void MediaStreamImpl::VideoRendererWrapper::SetVideoDecoder( |
456 RTCVideoDecoder* decoder) { | 467 RTCVideoDecoder* decoder) { |
457 rtc_video_decoder_ = decoder; | 468 rtc_video_decoder_ = decoder; |
458 } | 469 } |
OLD | NEW |