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/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/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "content/common/child_thread.h" | 16 #include "content/common/child_thread.h" |
17 #include "content/renderer/media/capture_video_decoder.h" | 17 #include "content/renderer/media/capture_video_decoder.h" |
18 #include "content/renderer/media/local_video_capture.h" | |
18 #include "content/renderer/media/media_stream_extra_data.h" | 19 #include "content/renderer/media/media_stream_extra_data.h" |
19 #include "content/renderer/media/media_stream_dependency_factory.h" | 20 #include "content/renderer/media/media_stream_dependency_factory.h" |
20 #include "content/renderer/media/media_stream_dispatcher.h" | 21 #include "content/renderer/media/media_stream_dispatcher.h" |
21 #include "content/renderer/media/peer_connection_handler_jsep.h" | 22 #include "content/renderer/media/peer_connection_handler_jsep.h" |
23 #include "content/renderer/media/rtc_video_render.h" | |
22 #include "content/renderer/media/video_capture_impl_manager.h" | 24 #include "content/renderer/media/video_capture_impl_manager.h" |
23 #include "content/renderer/media/video_capture_module_impl.h" | 25 #include "content/renderer/media/video_capture_module_impl.h" |
24 #include "content/renderer/media/webrtc_audio_device_impl.h" | 26 #include "content/renderer/media/webrtc_audio_device_impl.h" |
25 #include "content/renderer/p2p/ipc_network_manager.h" | 27 #include "content/renderer/p2p/ipc_network_manager.h" |
26 #include "content/renderer/p2p/ipc_socket_factory.h" | 28 #include "content/renderer/p2p/ipc_socket_factory.h" |
27 #include "jingle/glue/thread_wrapper.h" | 29 #include "jingle/glue/thread_wrapper.h" |
28 #include "media/base/message_loop_factory.h" | 30 #include "media/base/message_loop_factory.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 media_stream_dispatcher_->CancelGenerateStream(it->first); | 194 media_stream_dispatcher_->CancelGenerateStream(it->first); |
193 user_media_requests_.erase(it); | 195 user_media_requests_.erase(it); |
194 } | 196 } |
195 } | 197 } |
196 | 198 |
197 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( | 199 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( |
198 const GURL& url) { | 200 const GURL& url) { |
199 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); | 201 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); |
200 } | 202 } |
201 | 203 |
204 bool MediaStreamImpl::IsMediaStream(const GURL& url) { | |
205 DCHECK(CalledOnValidThread()); | |
206 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); | |
207 | |
208 // TODO(wjia): remove this to switch to VideoFrameProvier. | |
scherkus (not reviewing)
2012/09/07 11:44:03
I'd rather see this disabling w/ TODO + link to bu
wjia(left Chromium)
2012/09/13 01:22:07
Done.
| |
209 return false; | |
210 | |
211 if (descriptor.isNull() || !descriptor.extraData()) | |
212 return false; // This is not a valid stream. | |
213 | |
214 MediaStreamExtraData* extra_data = | |
215 static_cast<MediaStreamExtraData*>(descriptor.extraData()); | |
216 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); | |
217 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) | |
218 return true; | |
219 stream = extra_data->remote_stream(); | |
220 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) | |
221 return true; | |
222 return false; | |
223 } | |
224 | |
225 scoped_refptr<webkit_media::VideoFrameProvider> | |
226 MediaStreamImpl::GetVideoFrameProvider( | |
227 const GURL& url, | |
228 const base::Closure& error_cb, | |
229 const webkit_media::RepaintCB& repaint_cb) { | |
230 DCHECK(CalledOnValidThread()); | |
231 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); | |
232 | |
233 if (descriptor.isNull() || !descriptor.extraData()) | |
234 return NULL; // This is not a valid stream. | |
235 | |
236 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" | |
237 << UTF16ToUTF8(descriptor.label()); | |
238 | |
239 MediaStreamExtraData* extra_data = | |
240 static_cast<MediaStreamExtraData*>(descriptor.extraData()); | |
241 if (extra_data->local_stream()) | |
242 return CreateLocalVideoFrameProvider(extra_data->local_stream(), | |
243 error_cb, repaint_cb); | |
244 if (extra_data->remote_stream()) | |
245 return CreateRemoteVideoFrameProvider(extra_data->remote_stream(), | |
246 error_cb, repaint_cb); | |
247 NOTREACHED(); | |
248 return NULL; | |
249 } | |
250 | |
202 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( | 251 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
203 const GURL& url, | 252 const GURL& url, |
204 media::MessageLoopFactory* message_loop_factory) { | 253 media::MessageLoopFactory* message_loop_factory) { |
205 DCHECK(CalledOnValidThread()); | 254 DCHECK(CalledOnValidThread()); |
206 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); | 255 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
207 | 256 |
208 if (descriptor.isNull() || !descriptor.extraData()) | 257 if (descriptor.isNull() || !descriptor.extraData()) |
209 return NULL; // This is not a valid stream. | 258 return NULL; // This is not a valid stream. |
210 | 259 |
211 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" | 260 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 // processed before returning. We wait for the above task to finish before | 508 // processed before returning. We wait for the above task to finish before |
460 // letting the the function continue to avoid any potential race issues. | 509 // letting the the function continue to avoid any potential race issues. |
461 chrome_worker_thread_.Stop(); | 510 chrome_worker_thread_.Stop(); |
462 } else { | 511 } else { |
463 NOTREACHED() << "Worker thread not running."; | 512 NOTREACHED() << "Worker thread not running."; |
464 } | 513 } |
465 p2p_socket_dispatcher_->RemoveDestructionObserver(this); | 514 p2p_socket_dispatcher_->RemoveDestructionObserver(this); |
466 } | 515 } |
467 } | 516 } |
468 | 517 |
518 scoped_refptr<webkit_media::VideoFrameProvider> | |
519 MediaStreamImpl::CreateLocalVideoFrameProvider( | |
520 webrtc::MediaStreamInterface* stream, | |
521 const base::Closure& error_cb, | |
522 const webkit_media::RepaintCB& repaint_cb) { | |
523 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | |
524 return NULL; | |
525 | |
526 int video_session_id = | |
527 media_stream_dispatcher_->video_session_id(stream->label(), 0); | |
528 media::VideoCaptureCapability capability; | |
529 capability.width = kVideoCaptureWidth; | |
530 capability.height = kVideoCaptureHeight; | |
531 capability.frame_rate = kVideoCaptureFramePerSecond; | |
532 capability.color = media::VideoCaptureCapability::kI420; | |
533 capability.expected_capture_delay = 0; | |
534 capability.interlaced = false; | |
535 | |
536 DVLOG(1) << "MediaStreamImpl::CreateLocalVideoFrameProvider video_session_id:" | |
537 << video_session_id; | |
538 | |
539 return new LocalVideoCapture( | |
540 video_session_id, | |
541 vc_manager_.get(), | |
542 capability, | |
543 error_cb, | |
544 repaint_cb); | |
545 } | |
546 | |
547 scoped_refptr<webkit_media::VideoFrameProvider> | |
548 MediaStreamImpl::CreateRemoteVideoFrameProvider( | |
549 webrtc::MediaStreamInterface* stream, | |
550 const base::Closure& error_cb, | |
551 const webkit_media::RepaintCB& repaint_cb) { | |
552 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | |
553 return NULL; | |
554 | |
555 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" | |
556 << stream->label(); | |
557 | |
558 return new RTCVideoRender( | |
559 stream->video_tracks()->at(0), | |
560 error_cb, | |
561 repaint_cb); | |
562 } | |
563 | |
469 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( | 564 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( |
470 webrtc::MediaStreamInterface* stream, | 565 webrtc::MediaStreamInterface* stream, |
471 media::MessageLoopFactory* message_loop_factory) { | 566 media::MessageLoopFactory* message_loop_factory) { |
472 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | 567 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
473 return NULL; | 568 return NULL; |
474 | 569 |
475 int video_session_id = | 570 int video_session_id = |
476 media_stream_dispatcher_->video_session_id(stream->label(), 0); | 571 media_stream_dispatcher_->video_session_id(stream->label(), 0); |
477 media::VideoCaptureCapability capability; | 572 media::VideoCaptureCapability capability; |
478 capability.width = kVideoCaptureWidth; | 573 capability.width = kVideoCaptureWidth; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 MediaStreamExtraData::MediaStreamExtraData( | 654 MediaStreamExtraData::MediaStreamExtraData( |
560 webrtc::MediaStreamInterface* remote_stream) | 655 webrtc::MediaStreamInterface* remote_stream) |
561 : remote_stream_(remote_stream) { | 656 : remote_stream_(remote_stream) { |
562 } | 657 } |
563 MediaStreamExtraData::MediaStreamExtraData( | 658 MediaStreamExtraData::MediaStreamExtraData( |
564 webrtc::LocalMediaStreamInterface* local_stream) | 659 webrtc::LocalMediaStreamInterface* local_stream) |
565 : local_stream_(local_stream) { | 660 : local_stream_(local_stream) { |
566 } | 661 } |
567 MediaStreamExtraData::~MediaStreamExtraData() { | 662 MediaStreamExtraData::~MediaStreamExtraData() { |
568 } | 663 } |
OLD | NEW |