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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amSource.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 static const int kVideoCaptureWidth = 352; | 36 static const int kVideoCaptureWidth = 352; |
37 static const int kVideoCaptureHeight = 288; | 37 static const int kVideoCaptureHeight = 288; |
38 static const int kVideoCaptureFramePerSecond = 30; | 38 static const int kVideoCaptureFramePerSecond = 30; |
39 | 39 |
| 40 static const int kVideoCaptureWidthLarge = 640; |
| 41 static const int kVideoCaptureHeightLarge = 480; |
| 42 |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 int MediaStreamImpl::next_request_id_ = 0; | 45 int MediaStreamImpl::next_request_id_ = 0; |
43 | 46 |
44 MediaStreamImpl::MediaStreamImpl( | 47 MediaStreamImpl::MediaStreamImpl( |
45 MediaStreamDispatcher* media_stream_dispatcher, | 48 MediaStreamDispatcher* media_stream_dispatcher, |
46 content::P2PSocketDispatcher* p2p_socket_dispatcher, | 49 content::P2PSocketDispatcher* p2p_socket_dispatcher, |
47 VideoCaptureImplManager* vc_manager, | 50 VideoCaptureImplManager* vc_manager, |
48 MediaStreamDependencyFactory* dependency_factory) | 51 MediaStreamDependencyFactory* dependency_factory) |
49 : dependency_factory_(dependency_factory), | 52 : dependency_factory_(dependency_factory), |
50 media_stream_dispatcher_(media_stream_dispatcher), | 53 media_stream_dispatcher_(media_stream_dispatcher), |
51 media_engine_(NULL), | 54 media_engine_(NULL), |
52 p2p_socket_dispatcher_(p2p_socket_dispatcher), | 55 p2p_socket_dispatcher_(p2p_socket_dispatcher), |
53 network_manager_(NULL), | 56 network_manager_(NULL), |
54 vc_manager_(vc_manager), | 57 vc_manager_(vc_manager), |
55 peer_connection_handler_(NULL), | 58 peer_connection_handler_(NULL), |
56 message_loop_proxy_(base::MessageLoopProxy::current()), | 59 message_loop_proxy_(base::MessageLoopProxy::current()), |
57 signaling_thread_(NULL), | 60 signaling_thread_(NULL), |
58 worker_thread_(NULL), | 61 worker_thread_(NULL), |
59 chrome_worker_thread_("Chrome_libJingle_WorkerThread"), | 62 chrome_worker_thread_("Chrome_libJingle_WorkerThread"), |
| 63 desired_size_(0), |
60 vcm_created_(false) { | 64 vcm_created_(false) { |
61 } | 65 } |
62 | 66 |
63 MediaStreamImpl::~MediaStreamImpl() { | 67 MediaStreamImpl::~MediaStreamImpl() { |
64 DCHECK(!peer_connection_handler_); | 68 DCHECK(!peer_connection_handler_); |
65 if (dependency_factory_.get()) | 69 if (dependency_factory_.get()) |
66 dependency_factory_->DeletePeerConnectionFactory(); | 70 dependency_factory_->DeletePeerConnectionFactory(); |
67 if (network_manager_) { | 71 if (network_manager_) { |
68 // The network manager needs to free its resources on the thread they were | 72 // The network manager needs to free its resources on the thread they were |
69 // created, which is the worked thread. | 73 // created, which is the worked thread. |
70 if (chrome_worker_thread_.IsRunning()) { | 74 if (chrome_worker_thread_.IsRunning()) { |
71 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 75 chrome_worker_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
72 &MediaStreamImpl::DeleteIpcNetworkManager, | 76 &MediaStreamImpl::DeleteIpcNetworkManager, |
73 base::Unretained(this))); | 77 base::Unretained(this))); |
74 } else { | 78 } else { |
75 NOTREACHED() << "Worker thread not running."; | 79 NOTREACHED() << "Worker thread not running."; |
76 } | 80 } |
77 } | 81 } |
78 } | 82 } |
79 | 83 |
| 84 void MediaStreamImpl::GetVideoDevice(int size) { |
| 85 desired_size_ = size; |
| 86 media_stream_dispatcher_->EnumerateDevices(next_request_id_++, this, |
| 87 media_stream::kVideoCapture, ""); |
| 88 } |
| 89 |
80 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler( | 90 WebKit::WebPeerConnectionHandler* MediaStreamImpl::CreatePeerConnectionHandler( |
81 WebKit::WebPeerConnectionHandlerClient* client) { | 91 WebKit::WebPeerConnectionHandlerClient* client) { |
82 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
83 if (peer_connection_handler_) { | 93 if (peer_connection_handler_) { |
84 DVLOG(1) << "A PeerConnection already exists"; | 94 DVLOG(1) << "A PeerConnection already exists"; |
85 return NULL; | 95 return NULL; |
86 } | 96 } |
87 | 97 |
88 if (!media_engine_) { | 98 if (!media_engine_) { |
89 media_engine_ = dependency_factory_->CreateWebRtcMediaEngine(); | 99 media_engine_ = dependency_factory_->CreateWebRtcMediaEngine(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void MediaStreamImpl::cancelUserMediaRequest( | 225 void MediaStreamImpl::cancelUserMediaRequest( |
216 const WebKit::WebUserMediaRequest& user_media_request) { | 226 const WebKit::WebUserMediaRequest& user_media_request) { |
217 // TODO(grunell): Implement. | 227 // TODO(grunell): Implement. |
218 NOTIMPLEMENTED(); | 228 NOTIMPLEMENTED(); |
219 } | 229 } |
220 | 230 |
221 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( | 231 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
222 const GURL& url, | 232 const GURL& url, |
223 media::MessageLoopFactory* message_loop_factory) { | 233 media::MessageLoopFactory* message_loop_factory) { |
224 DCHECK(CalledOnValidThread()); | 234 DCHECK(CalledOnValidThread()); |
225 WebKit::WebMediaStreamDescriptor descriptor( | 235 std::string label = local_label_; |
226 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); | |
227 if (descriptor.isNull()) | |
228 return NULL; // This is not a valid stream. | |
229 WebKit::WebVector<WebKit::WebMediaStreamSource> source_vector; | |
230 descriptor.sources(source_vector); | |
231 std::string label; | |
232 for (size_t i = 0; i < source_vector.size(); ++i) { | |
233 if (source_vector[i].type() == WebKit::WebMediaStreamSource::TypeVideo) { | |
234 label = UTF16ToUTF8(source_vector[i].id()); | |
235 break; | |
236 } | |
237 } | |
238 if (label.empty()) | 236 if (label.empty()) |
239 return NULL; | 237 return NULL; |
240 | 238 |
241 scoped_refptr<media::VideoDecoder> decoder; | 239 scoped_refptr<media::VideoDecoder> decoder; |
242 if (media_stream_dispatcher_->IsStream(label)) { | 240 if (media_stream_dispatcher_->IsStream(label)) { |
243 // It's a local stream. | 241 // It's a local stream. |
244 int video_session_id = media_stream_dispatcher_->video_session_id(label, 0); | 242 int video_session_id = media_stream_dispatcher_->video_session_id(label, 0); |
| 243 printf("MediaStreamImpl::GetVideoDecoder: use session_id = %d\n", video_session_
id); |
| 244 |
245 media::VideoCapture::VideoCaptureCapability capability; | 245 media::VideoCapture::VideoCaptureCapability capability; |
246 capability.width = kVideoCaptureWidth; | 246 if (desired_size_ == 0) { |
247 capability.height = kVideoCaptureHeight; | 247 printf("MediaStreamImpl::GetVideoDecoder: use small size\n"); |
| 248 capability.width = kVideoCaptureWidth; |
| 249 capability.height = kVideoCaptureHeight; |
| 250 } else { |
| 251 printf("MediaStreamImpl::GetVideoDecoder: use large size\n"); |
| 252 capability.width = kVideoCaptureWidthLarge; |
| 253 capability.height = kVideoCaptureHeightLarge; |
| 254 } |
248 capability.max_fps = kVideoCaptureFramePerSecond; | 255 capability.max_fps = kVideoCaptureFramePerSecond; |
249 capability.expected_capture_delay = 0; | 256 capability.expected_capture_delay = 0; |
250 capability.raw_type = media::VideoFrame::I420; | 257 capability.raw_type = media::VideoFrame::I420; |
251 capability.interlaced = false; | 258 capability.interlaced = false; |
252 decoder = new CaptureVideoDecoder( | 259 decoder = new CaptureVideoDecoder( |
253 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoderThread"), | 260 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoderThread"), |
254 video_session_id, | 261 video_session_id, |
255 vc_manager_.get(), | 262 vc_manager_.get(), |
256 capability); | 263 capability); |
257 } else { | 264 } else { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 351 |
345 void MediaStreamImpl::OnAudioDeviceFailed(const std::string& label, | 352 void MediaStreamImpl::OnAudioDeviceFailed(const std::string& label, |
346 int index) { | 353 int index) { |
347 DCHECK(CalledOnValidThread()); | 354 DCHECK(CalledOnValidThread()); |
348 DVLOG(1) << "MediaStreamImpl::OnAudioDeviceFailed(" | 355 DVLOG(1) << "MediaStreamImpl::OnAudioDeviceFailed(" |
349 << label << ", " << index << ")"; | 356 << label << ", " << index << ")"; |
350 // TODO(grunell): Implement. Currently not supported in WebKit. | 357 // TODO(grunell): Implement. Currently not supported in WebKit. |
351 NOTIMPLEMENTED(); | 358 NOTIMPLEMENTED(); |
352 } | 359 } |
353 | 360 |
| 361 void MediaStreamImpl::OnDevicesEnumerated( |
| 362 int request_id, |
| 363 const media_stream::StreamDeviceInfoArray& device_array) { |
| 364 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerated(" |
| 365 << request_id << ")"; |
| 366 media_stream::StreamDeviceInfoArray::const_iterator it; |
| 367 for (it = device_array.begin(); it != device_array.end(); it++) { |
| 368 } |
| 369 if (!device_array.empty()) { |
| 370 media_stream_dispatcher_->OpenDevice( |
| 371 next_request_id_++, this, |
| 372 device_array[0].device_id, |
| 373 media_stream::kVideoCapture, ""); |
| 374 } |
| 375 } |
| 376 |
| 377 void MediaStreamImpl::OnDevicesEnumerationFailed(int request_id) { |
| 378 DVLOG(1) << "MediaStreamImpl::OnDevicesEnumerationFailed(" |
| 379 << request_id << ")"; |
| 380 NOTIMPLEMENTED(); |
| 381 } |
| 382 |
| 383 void MediaStreamImpl::OnDeviceOpened( |
| 384 int request_id, |
| 385 const std::string& label, |
| 386 const media_stream::StreamDeviceInfo& video_device) { |
| 387 DVLOG(1) << "MediaStreamImpl::OnDeviceOpened(" |
| 388 << request_id << ", " << label << ")"; |
| 389 local_label_ = label; |
| 390 } |
| 391 |
| 392 void MediaStreamImpl::OnDeviceOpenFailed(int request_id) { |
| 393 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" |
| 394 << request_id << ")"; |
| 395 NOTIMPLEMENTED(); |
| 396 } |
| 397 |
354 void MediaStreamImpl::InitializeWorkerThread(talk_base::Thread** thread, | 398 void MediaStreamImpl::InitializeWorkerThread(talk_base::Thread** thread, |
355 base::WaitableEvent* event) { | 399 base::WaitableEvent* event) { |
356 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread(); | 400 jingle_glue::JingleThreadWrapper::EnsureForCurrentThread(); |
357 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); | 401 jingle_glue::JingleThreadWrapper::current()->set_send_allowed(true); |
358 *thread = jingle_glue::JingleThreadWrapper::current(); | 402 *thread = jingle_glue::JingleThreadWrapper::current(); |
359 event->Signal(); | 403 event->Signal(); |
360 } | 404 } |
361 | 405 |
362 void MediaStreamImpl::DeleteIpcNetworkManager() { | 406 void MediaStreamImpl::DeleteIpcNetworkManager() { |
363 DCHECK_EQ(MessageLoop::current(), chrome_worker_thread_.message_loop()); | 407 DCHECK_EQ(MessageLoop::current(), chrome_worker_thread_.message_loop()); |
364 delete network_manager_; | 408 delete network_manager_; |
365 network_manager_ = NULL; | 409 network_manager_ = NULL; |
366 } | 410 } |
OLD | NEW |