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_renderer.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/webrtc_audio_device_impl.h" | 25 #include "content/renderer/media/webrtc_audio_device_impl.h" |
24 #include "content/renderer/p2p/ipc_network_manager.h" | 26 #include "content/renderer/p2p/ipc_network_manager.h" |
25 #include "content/renderer/p2p/ipc_socket_factory.h" | 27 #include "content/renderer/p2p/ipc_socket_factory.h" |
26 #include "jingle/glue/thread_wrapper.h" | 28 #include "jingle/glue/thread_wrapper.h" |
27 #include "media/base/message_loop_factory.h" | 29 #include "media/base/message_loop_factory.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.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
amComponent.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 media_stream_dispatcher_->CancelGenerateStream(it->first); | 193 media_stream_dispatcher_->CancelGenerateStream(it->first); |
192 user_media_requests_.erase(it); | 194 user_media_requests_.erase(it); |
193 } | 195 } |
194 } | 196 } |
195 | 197 |
196 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( | 198 WebKit::WebMediaStreamDescriptor MediaStreamImpl::GetMediaStream( |
197 const GURL& url) { | 199 const GURL& url) { |
198 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); | 200 return WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url); |
199 } | 201 } |
200 | 202 |
| 203 bool MediaStreamImpl::IsMediaStream(const GURL& url) { |
| 204 DCHECK(CalledOnValidThread()); |
| 205 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
| 206 |
| 207 if (descriptor.isNull() || !descriptor.extraData()) |
| 208 return false; // This is not a valid stream. |
| 209 |
| 210 MediaStreamExtraData* extra_data = |
| 211 static_cast<MediaStreamExtraData*>(descriptor.extraData()); |
| 212 webrtc::MediaStreamInterface* stream = extra_data->local_stream(); |
| 213 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) |
| 214 return true; |
| 215 stream = extra_data->remote_stream(); |
| 216 if (stream && stream->video_tracks() && stream->video_tracks()->count() > 0) |
| 217 return true; |
| 218 return false; |
| 219 } |
| 220 |
| 221 scoped_refptr<webkit_media::VideoFrameProvider> |
| 222 MediaStreamImpl::GetVideoFrameProvider( |
| 223 const GURL& url, |
| 224 const base::Closure& error_cb, |
| 225 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 226 DCHECK(CalledOnValidThread()); |
| 227 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
| 228 |
| 229 if (descriptor.isNull() || !descriptor.extraData()) |
| 230 return NULL; // This is not a valid stream. |
| 231 |
| 232 DVLOG(1) << "MediaStreamImpl::GetVideoFrameProvider stream:" |
| 233 << UTF16ToUTF8(descriptor.label()); |
| 234 |
| 235 MediaStreamExtraData* extra_data = |
| 236 static_cast<MediaStreamExtraData*>(descriptor.extraData()); |
| 237 if (extra_data->local_stream()) |
| 238 return CreateLocalVideoFrameProvider(extra_data->local_stream(), |
| 239 error_cb, repaint_cb); |
| 240 if (extra_data->remote_stream()) |
| 241 return CreateRemoteVideoFrameProvider(extra_data->remote_stream(), |
| 242 error_cb, repaint_cb); |
| 243 NOTREACHED(); |
| 244 return NULL; |
| 245 } |
| 246 |
201 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( | 247 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
202 const GURL& url, | 248 const GURL& url, |
203 media::MessageLoopFactory* message_loop_factory) { | 249 media::MessageLoopFactory* message_loop_factory) { |
204 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
205 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); | 251 WebKit::WebMediaStreamDescriptor descriptor(GetMediaStream(url)); |
206 | 252 |
207 if (descriptor.isNull() || !descriptor.extraData()) | 253 if (descriptor.isNull() || !descriptor.extraData()) |
208 return NULL; // This is not a valid stream. | 254 return NULL; // This is not a valid stream. |
209 | 255 |
210 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" | 256 DVLOG(1) << "MediaStreamImpl::GetVideoDecoder stream:" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 // processed before returning. We wait for the above task to finish before | 504 // processed before returning. We wait for the above task to finish before |
459 // letting the the function continue to avoid any potential race issues. | 505 // letting the the function continue to avoid any potential race issues. |
460 chrome_worker_thread_.Stop(); | 506 chrome_worker_thread_.Stop(); |
461 } else { | 507 } else { |
462 NOTREACHED() << "Worker thread not running."; | 508 NOTREACHED() << "Worker thread not running."; |
463 } | 509 } |
464 p2p_socket_dispatcher_->RemoveDestructionObserver(this); | 510 p2p_socket_dispatcher_->RemoveDestructionObserver(this); |
465 } | 511 } |
466 } | 512 } |
467 | 513 |
| 514 scoped_refptr<webkit_media::VideoFrameProvider> |
| 515 MediaStreamImpl::CreateLocalVideoFrameProvider( |
| 516 webrtc::MediaStreamInterface* stream, |
| 517 const base::Closure& error_cb, |
| 518 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 519 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 520 return NULL; |
| 521 |
| 522 int video_session_id = |
| 523 media_stream_dispatcher_->video_session_id(stream->label(), 0); |
| 524 media::VideoCaptureCapability capability; |
| 525 capability.width = kVideoCaptureWidth; |
| 526 capability.height = kVideoCaptureHeight; |
| 527 capability.frame_rate = kVideoCaptureFramePerSecond; |
| 528 capability.color = media::VideoCaptureCapability::kI420; |
| 529 capability.expected_capture_delay = 0; |
| 530 capability.interlaced = false; |
| 531 |
| 532 DVLOG(1) << "MediaStreamImpl::CreateLocalVideoFrameProvider video_session_id:" |
| 533 << video_session_id; |
| 534 |
| 535 return new content::LocalVideoCapture( |
| 536 video_session_id, |
| 537 vc_manager_.get(), |
| 538 capability, |
| 539 error_cb, |
| 540 repaint_cb); |
| 541 } |
| 542 |
| 543 scoped_refptr<webkit_media::VideoFrameProvider> |
| 544 MediaStreamImpl::CreateRemoteVideoFrameProvider( |
| 545 webrtc::MediaStreamInterface* stream, |
| 546 const base::Closure& error_cb, |
| 547 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 548 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 549 return NULL; |
| 550 |
| 551 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" |
| 552 << stream->label(); |
| 553 |
| 554 return new content::RTCVideoRenderer( |
| 555 stream->video_tracks()->at(0), |
| 556 error_cb, |
| 557 repaint_cb); |
| 558 } |
| 559 |
468 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( | 560 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( |
469 webrtc::MediaStreamInterface* stream, | 561 webrtc::MediaStreamInterface* stream, |
470 media::MessageLoopFactory* message_loop_factory) { | 562 media::MessageLoopFactory* message_loop_factory) { |
471 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | 563 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
472 return NULL; | 564 return NULL; |
473 | 565 |
474 int video_session_id = | 566 int video_session_id = |
475 media_stream_dispatcher_->video_session_id(stream->label(), 0); | 567 media_stream_dispatcher_->video_session_id(stream->label(), 0); |
476 media::VideoCaptureCapability capability; | 568 media::VideoCaptureCapability capability; |
477 capability.width = kVideoCaptureWidth; | 569 capability.width = kVideoCaptureWidth; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 MediaStreamExtraData::MediaStreamExtraData( | 649 MediaStreamExtraData::MediaStreamExtraData( |
558 webrtc::MediaStreamInterface* remote_stream) | 650 webrtc::MediaStreamInterface* remote_stream) |
559 : remote_stream_(remote_stream) { | 651 : remote_stream_(remote_stream) { |
560 } | 652 } |
561 MediaStreamExtraData::MediaStreamExtraData( | 653 MediaStreamExtraData::MediaStreamExtraData( |
562 webrtc::LocalMediaStreamInterface* local_stream) | 654 webrtc::LocalMediaStreamInterface* local_stream) |
563 : local_stream_(local_stream) { | 655 : local_stream_(local_stream) { |
564 } | 656 } |
565 MediaStreamExtraData::~MediaStreamExtraData() { | 657 MediaStreamExtraData::~MediaStreamExtraData() { |
566 } | 658 } |
OLD | NEW |