| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr
y.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amComponent.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amDescriptor.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre
amDescriptor.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 content { |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 const int kVideoCaptureWidth = 640; | 37 const int kVideoCaptureWidth = 640; |
| 37 const int kVideoCaptureHeight = 480; | 38 const int kVideoCaptureHeight = 480; |
| 38 const int kVideoCaptureFramePerSecond = 30; | 39 const int kVideoCaptureFramePerSecond = 30; |
| 39 | 40 |
| 40 std::string GetMandatoryStreamConstraint( | 41 std::string GetMandatoryStreamConstraint( |
| 41 const WebKit::WebMediaConstraints& constraints, const std::string& key) { | 42 const WebKit::WebMediaConstraints& constraints, const std::string& key) { |
| 42 if (constraints.isNull()) | 43 if (constraints.isNull()) |
| 43 return std::string(); | 44 return std::string(); |
| 44 | 45 |
| 45 WebKit::WebString value; | 46 WebKit::WebString value; |
| 46 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); | 47 constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); |
| 47 return UTF16ToUTF8(value); | 48 return UTF16ToUTF8(value); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void UpdateOptionsIfTabMediaRequest( | 51 void UpdateOptionsIfTabMediaRequest( |
| 51 const WebKit::WebUserMediaRequest& user_media_request, | 52 const WebKit::WebUserMediaRequest& user_media_request, |
| 52 media_stream::StreamOptions* options) { | 53 media_stream::StreamOptions* options) { |
| 53 if (options->audio_type != content::MEDIA_NO_SERVICE && | 54 if (options->audio_type != MEDIA_NO_SERVICE && |
| 54 GetMandatoryStreamConstraint(user_media_request.audioConstraints(), | 55 GetMandatoryStreamConstraint(user_media_request.audioConstraints(), |
| 55 media_stream::kMediaStreamSource) == | 56 media_stream::kMediaStreamSource) == |
| 56 media_stream::kMediaStreamSourceTab) { | 57 media_stream::kMediaStreamSourceTab) { |
| 57 options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; | 58 options->audio_type = MEDIA_TAB_AUDIO_CAPTURE; |
| 58 options->audio_device_id = GetMandatoryStreamConstraint( | 59 options->audio_device_id = GetMandatoryStreamConstraint( |
| 59 user_media_request.audioConstraints(), | 60 user_media_request.audioConstraints(), |
| 60 media_stream::kMediaStreamSourceId); | 61 media_stream::kMediaStreamSourceId); |
| 61 } | 62 } |
| 62 | 63 |
| 63 if (options->video_type != content::MEDIA_NO_SERVICE && | 64 if (options->video_type != MEDIA_NO_SERVICE && |
| 64 GetMandatoryStreamConstraint(user_media_request.videoConstraints(), | 65 GetMandatoryStreamConstraint(user_media_request.videoConstraints(), |
| 65 media_stream::kMediaStreamSource) == | 66 media_stream::kMediaStreamSource) == |
| 66 media_stream::kMediaStreamSourceTab) { | 67 media_stream::kMediaStreamSourceTab) { |
| 67 options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; | 68 options->video_type = MEDIA_TAB_VIDEO_CAPTURE; |
| 68 options->video_device_id = GetMandatoryStreamConstraint( | 69 options->video_device_id = GetMandatoryStreamConstraint( |
| 69 user_media_request.videoConstraints(), | 70 user_media_request.videoConstraints(), |
| 70 media_stream::kMediaStreamSourceId); | 71 media_stream::kMediaStreamSourceId); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 } // namespace | 75 } // namespace |
| 75 | 76 |
| 76 static int g_next_request_id = 0; | 77 static int g_next_request_id = 0; |
| 77 | 78 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 webkit_sources[i].initialize( | 90 webkit_sources[i].initialize( |
| 90 UTF8ToUTF16(source_id), | 91 UTF8ToUTF16(source_id), |
| 91 type, | 92 type, |
| 92 UTF8ToUTF16(devices[i].name)); | 93 UTF8ToUTF16(devices[i].name)); |
| 93 webkit_sources[i].setExtraData( | 94 webkit_sources[i].setExtraData( |
| 94 new MediaStreamSourceExtraData(devices[i])); | 95 new MediaStreamSourceExtraData(devices[i])); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 MediaStreamImpl::MediaStreamImpl( | 99 MediaStreamImpl::MediaStreamImpl( |
| 99 content::RenderView* render_view, | 100 RenderView* render_view, |
| 100 MediaStreamDispatcher* media_stream_dispatcher, | 101 MediaStreamDispatcher* media_stream_dispatcher, |
| 101 VideoCaptureImplManager* vc_manager, | 102 VideoCaptureImplManager* vc_manager, |
| 102 MediaStreamDependencyFactory* dependency_factory) | 103 MediaStreamDependencyFactory* dependency_factory) |
| 103 : content::RenderViewObserver(render_view), | 104 : RenderViewObserver(render_view), |
| 104 dependency_factory_(dependency_factory), | 105 dependency_factory_(dependency_factory), |
| 105 media_stream_dispatcher_(media_stream_dispatcher), | 106 media_stream_dispatcher_(media_stream_dispatcher), |
| 106 vc_manager_(vc_manager) { | 107 vc_manager_(vc_manager) { |
| 107 } | 108 } |
| 108 | 109 |
| 109 MediaStreamImpl::~MediaStreamImpl() { | 110 MediaStreamImpl::~MediaStreamImpl() { |
| 110 } | 111 } |
| 111 | 112 |
| 112 void MediaStreamImpl::OnLocalMediaStreamStop( | 113 void MediaStreamImpl::OnLocalMediaStreamStop( |
| 113 const std::string& label) { | 114 const std::string& label) { |
| 114 DVLOG(1) << "MediaStreamImpl::OnLocalMediaStreamStop"; | 115 DVLOG(1) << "MediaStreamImpl::OnLocalMediaStreamStop"; |
| 115 media_stream_dispatcher_->StopStream(label); | 116 media_stream_dispatcher_->StopStream(label); |
| 116 local_media_streams_.erase(label); | 117 local_media_streams_.erase(label); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void MediaStreamImpl::requestUserMedia( | 120 void MediaStreamImpl::requestUserMedia( |
| 120 const WebKit::WebUserMediaRequest& user_media_request, | 121 const WebKit::WebUserMediaRequest& user_media_request, |
| 121 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, | 122 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, |
| 122 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { | 123 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { |
| 123 // Save histogram data so we can see how much GetUserMedia is used. | 124 // Save histogram data so we can see how much GetUserMedia is used. |
| 124 // The histogram counts the number of calls to the JS API | 125 // The histogram counts the number of calls to the JS API |
| 125 // webGetUserMedia. | 126 // webGetUserMedia. |
| 126 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 127 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| 127 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
| 128 int request_id = g_next_request_id++; | 129 int request_id = g_next_request_id++; |
| 129 media_stream::StreamOptions options(content::MEDIA_NO_SERVICE, | 130 media_stream::StreamOptions options(MEDIA_NO_SERVICE, MEDIA_NO_SERVICE); |
| 130 content::MEDIA_NO_SERVICE); | |
| 131 WebKit::WebFrame* frame = NULL; | 131 WebKit::WebFrame* frame = NULL; |
| 132 GURL security_origin; | 132 GURL security_origin; |
| 133 | 133 |
| 134 // |user_media_request| can't be mocked. So in order to test at all we check | 134 // |user_media_request| can't be mocked. So in order to test at all we check |
| 135 // if it isNull. | 135 // if it isNull. |
| 136 if (user_media_request.isNull()) { | 136 if (user_media_request.isNull()) { |
| 137 // We are in a test. | 137 // We are in a test. |
| 138 if (audio_sources.size() > 0) | 138 if (audio_sources.size() > 0) |
| 139 options.audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 139 options.audio_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 140 if (video_sources.size() > 0) | 140 if (video_sources.size() > 0) |
| 141 options.video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 141 options.video_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 142 } else { | 142 } else { |
| 143 if (user_media_request.audio()) | 143 if (user_media_request.audio()) |
| 144 options.audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 144 options.audio_type = MEDIA_DEVICE_AUDIO_CAPTURE; |
| 145 if (user_media_request.video()) | 145 if (user_media_request.video()) |
| 146 options.video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 146 options.video_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 147 | 147 |
| 148 security_origin = GURL(user_media_request.securityOrigin().toString()); | 148 security_origin = GURL(user_media_request.securityOrigin().toString()); |
| 149 // Get the WebFrame that requested a MediaStream. | 149 // Get the WebFrame that requested a MediaStream. |
| 150 // The frame is needed to tell the MediaStreamDispatcher when a stream goes | 150 // The frame is needed to tell the MediaStreamDispatcher when a stream goes |
| 151 // out of scope. | 151 // out of scope. |
| 152 frame = user_media_request.ownerDocument().frame(); | 152 frame = user_media_request.ownerDocument().frame(); |
| 153 DCHECK(frame); | 153 DCHECK(frame); |
| 154 | 154 |
| 155 UpdateOptionsIfTabMediaRequest(user_media_request, &options); | 155 UpdateOptionsIfTabMediaRequest(user_media_request, &options); |
| 156 } | 156 } |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 capability.width = kVideoCaptureWidth; | 398 capability.width = kVideoCaptureWidth; |
| 399 capability.height = kVideoCaptureHeight; | 399 capability.height = kVideoCaptureHeight; |
| 400 capability.frame_rate = kVideoCaptureFramePerSecond; | 400 capability.frame_rate = kVideoCaptureFramePerSecond; |
| 401 capability.color = media::VideoCaptureCapability::kI420; | 401 capability.color = media::VideoCaptureCapability::kI420; |
| 402 capability.expected_capture_delay = 0; | 402 capability.expected_capture_delay = 0; |
| 403 capability.interlaced = false; | 403 capability.interlaced = false; |
| 404 | 404 |
| 405 DVLOG(1) << "MediaStreamImpl::CreateLocalVideoFrameProvider video_session_id:" | 405 DVLOG(1) << "MediaStreamImpl::CreateLocalVideoFrameProvider video_session_id:" |
| 406 << video_session_id; | 406 << video_session_id; |
| 407 | 407 |
| 408 return new content::LocalVideoCapture( | 408 return new LocalVideoCapture( |
| 409 video_session_id, | 409 video_session_id, |
| 410 vc_manager_.get(), | 410 vc_manager_.get(), |
| 411 capability, | 411 capability, |
| 412 error_cb, | 412 error_cb, |
| 413 repaint_cb); | 413 repaint_cb); |
| 414 } | 414 } |
| 415 | 415 |
| 416 scoped_refptr<webkit_media::VideoFrameProvider> | 416 scoped_refptr<webkit_media::VideoFrameProvider> |
| 417 MediaStreamImpl::CreateRemoteVideoFrameProvider( | 417 MediaStreamImpl::CreateRemoteVideoFrameProvider( |
| 418 webrtc::MediaStreamInterface* stream, | 418 webrtc::MediaStreamInterface* stream, |
| 419 const base::Closure& error_cb, | 419 const base::Closure& error_cb, |
| 420 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { | 420 const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) { |
| 421 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | 421 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 422 return NULL; | 422 return NULL; |
| 423 | 423 |
| 424 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" | 424 DVLOG(1) << "MediaStreamImpl::CreateRemoteVideoFrameProvider label:" |
| 425 << stream->label(); | 425 << stream->label(); |
| 426 | 426 |
| 427 return new content::RTCVideoRenderer( | 427 return new RTCVideoRenderer( |
| 428 stream->video_tracks()->at(0), | 428 stream->video_tracks()->at(0), |
| 429 error_cb, | 429 error_cb, |
| 430 repaint_cb); | 430 repaint_cb); |
| 431 } | 431 } |
| 432 | 432 |
| 433 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( | 433 scoped_refptr<media::VideoDecoder> MediaStreamImpl::CreateLocalVideoDecoder( |
| 434 webrtc::MediaStreamInterface* stream, | 434 webrtc::MediaStreamInterface* stream, |
| 435 media::MessageLoopFactory* message_loop_factory) { | 435 media::MessageLoopFactory* message_loop_factory) { |
| 436 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) | 436 if (!stream->video_tracks() || stream->video_tracks()->count() == 0) |
| 437 return NULL; | 437 return NULL; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 487 |
| 488 void MediaStreamExtraData::SetLocalStreamStopCallback( | 488 void MediaStreamExtraData::SetLocalStreamStopCallback( |
| 489 const StreamStopCallback& stop_callback) { | 489 const StreamStopCallback& stop_callback) { |
| 490 stream_stop_callback_ = stop_callback; | 490 stream_stop_callback_ = stop_callback; |
| 491 } | 491 } |
| 492 | 492 |
| 493 void MediaStreamExtraData::OnLocalStreamStop() { | 493 void MediaStreamExtraData::OnLocalStreamStop() { |
| 494 if (!stream_stop_callback_.is_null()) | 494 if (!stream_stop_callback_.is_null()) |
| 495 stream_stop_callback_.Run(local_stream_->label()); | 495 stream_stop_callback_.Run(local_stream_->label()); |
| 496 } | 496 } |
| 497 |
| 498 } // namespace content |
| OLD | NEW |