Chromium Code Reviews| 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" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "content/public/common/media_stream_request.h" | |
| 13 #include "content/renderer/media/capture_video_decoder.h" | 14 #include "content/renderer/media/capture_video_decoder.h" |
| 14 #include "content/renderer/media/local_video_capture.h" | 15 #include "content/renderer/media/local_video_capture.h" |
| 15 #include "content/renderer/media/media_stream_extra_data.h" | 16 #include "content/renderer/media/media_stream_extra_data.h" |
| 16 #include "content/renderer/media/media_stream_source_extra_data.h" | 17 #include "content/renderer/media/media_stream_source_extra_data.h" |
| 17 #include "content/renderer/media/media_stream_dependency_factory.h" | 18 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 18 #include "content/renderer/media/media_stream_dispatcher.h" | 19 #include "content/renderer/media/media_stream_dispatcher.h" |
| 19 #include "content/renderer/media/rtc_video_decoder.h" | 20 #include "content/renderer/media/rtc_video_decoder.h" |
| 20 #include "content/renderer/media/rtc_video_renderer.h" | 21 #include "content/renderer/media/rtc_video_renderer.h" |
| 21 #include "content/renderer/media/video_capture_impl_manager.h" | 22 #include "content/renderer/media/video_capture_impl_manager.h" |
| 22 #include "content/renderer/media/webrtc_uma_histograms.h" | 23 #include "content/renderer/media/webrtc_uma_histograms.h" |
| 23 #include "media/base/message_loop_factory.h" | 24 #include "media/base/message_loop_factory.h" |
| 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h" | |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 void MediaStreamImpl::requestUserMedia( | 84 void MediaStreamImpl::requestUserMedia( |
| 83 const WebKit::WebUserMediaRequest& user_media_request, | 85 const WebKit::WebUserMediaRequest& user_media_request, |
| 84 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, | 86 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, |
| 85 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { | 87 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) { |
| 86 // Save histogram data so we can see how much GetUserMedia is used. | 88 // Save histogram data so we can see how much GetUserMedia is used. |
| 87 // The histogram counts the number of calls to the JS API | 89 // The histogram counts the number of calls to the JS API |
| 88 // webGetUserMedia. | 90 // webGetUserMedia. |
| 89 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); | 91 UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| 90 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
| 91 int request_id = g_next_request_id++; | 93 int request_id = g_next_request_id++; |
| 92 bool audio = false; | 94 content::MediaStreamDeviceType audio = content::MEDIA_NO_SERVICE; |
| 93 bool video = false; | 95 content::MediaStreamDeviceType video = content::MEDIA_NO_SERVICE; |
| 94 WebKit::WebFrame* frame = NULL; | 96 WebKit::WebFrame* frame = NULL; |
| 95 GURL security_origin; | 97 GURL security_origin; |
| 96 | 98 |
| 97 // |user_media_request| can't be mocked. So in order to test at all we check | 99 // |user_media_request| can't be mocked. So in order to test at all we check |
| 98 // if it isNull. | 100 // if it isNull. |
| 99 if (user_media_request.isNull()) { | 101 if (user_media_request.isNull()) { |
| 100 // We are in a test. | 102 // We are in a test. |
| 101 audio = audio_sources.size() > 0; | 103 if (audio_sources.size() > 0) |
| 102 video = video_sources.size() > 0; | 104 audio = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 105 if (video_sources.size() > 0) | |
| 106 video = content::MEDIA_DEVICE_VIDEO_CAPTURE; | |
| 103 } else { | 107 } else { |
| 104 audio = user_media_request.audio(); | 108 if (user_media_request.audio()) |
| 105 video = user_media_request.video(); | 109 audio = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 110 if (user_media_request.video()) | |
| 111 video = content::MEDIA_DEVICE_VIDEO_CAPTURE; | |
| 112 | |
| 106 security_origin = GURL(user_media_request.securityOrigin().toString()); | 113 security_origin = GURL(user_media_request.securityOrigin().toString()); |
| 107 // Get the WebFrame that requested a MediaStream. | 114 // Get the WebFrame that requested a MediaStream. |
| 108 // The frame is needed to tell the MediaStreamDispatcher when a stream goes | 115 // The frame is needed to tell the MediaStreamDispatcher when a stream goes |
| 109 // out of scope. | 116 // out of scope. |
| 110 frame = user_media_request.ownerDocument().frame(); | 117 frame = user_media_request.ownerDocument().frame(); |
| 111 DCHECK(frame); | 118 DCHECK(frame); |
| 112 } | 119 } |
| 113 | 120 |
| 114 DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " | 121 bool isTabCapture = false; |
|
perkj_chrome
2012/10/04 08:19:25
Can this whole thing be broken out to a new functi
justinlin
2012/10/08 08:59:45
I cleaned this up a bit with helper function. Do y
| |
| 115 << (audio ? "audio" : "") | 122 WebKit::WebMediaConstraints videoConstraints = |
| 116 << (user_media_request.video() ? " video" : "") << "], " | 123 user_media_request.videoConstraints(); |
| 117 << security_origin.spec() << ")"; | 124 WebKit::WebMediaConstraints audioConstraints = |
| 125 user_media_request.audioConstraints(); | |
| 126 | |
| 127 WebKit::WebString videoSource; | |
| 128 WebKit::WebString audioSource; | |
| 129 if (!audioConstraints.isNull()) | |
| 130 audioConstraints.getMandatoryConstraintValue( | |
| 131 UTF8ToUTF16(content::kMediaStreamSource), audioSource); | |
|
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
| |
| 132 if (!videoConstraints.isNull()) | |
| 133 videoConstraints.getMandatoryConstraintValue( | |
| 134 UTF8ToUTF16(content::kMediaStreamSource), videoSource); | |
| 135 | |
| 136 WebKit::WebString source_id; | |
| 137 // If either source is tab, we use tab media for both for now. | |
| 138 if (UTF16ToUTF8(audioSource) == "tab" || UTF16ToUTF8(videoSource) == "tab") { | |
| 139 isTabCapture = true; | |
| 140 | |
| 141 if (audio != content::MEDIA_NO_SERVICE) | |
| 142 audio = content::MEDIA_TAB_AUDIO_CAPTURE; | |
| 143 if (video != content::MEDIA_NO_SERVICE) | |
| 144 video = content::MEDIA_TAB_VIDEO_CAPTURE; | |
| 145 | |
| 146 // TODO(justinlin): Ignores id provided for audio for now. | |
| 147 videoConstraints.getMandatoryConstraintValue( | |
| 148 UTF8ToUTF16(content::kMediaStreamSourceId), source_id); | |
|
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
| |
| 149 } | |
| 118 | 150 |
| 119 user_media_requests_[request_id] = | 151 user_media_requests_[request_id] = |
| 120 UserMediaRequestInfo(frame, user_media_request); | 152 UserMediaRequestInfo(frame, user_media_request); |
| 121 | 153 |
| 122 media_stream_dispatcher_->GenerateStream( | 154 if (isTabCapture) { |
| 123 request_id, | 155 DVLOG(1) << "MediaStreamImpl::generateStreamForDevice(" |
| 124 AsWeakPtr(), | 156 << request_id << ", [ " |
| 125 media_stream::StreamOptions(audio, video), | 157 << (audio ? "audio" : "") |
| 126 security_origin); | 158 << (video ? " video" : "") << "], " |
| 159 << security_origin.spec() << ")"; | |
| 160 | |
| 161 media_stream_dispatcher_->GenerateStreamForDevice( | |
| 162 request_id, | |
| 163 AsWeakPtr(), | |
| 164 media_stream::StreamOptions(audio, video), | |
| 165 UTF16ToUTF8(source_id), | |
|
perkj_chrome
2012/10/04 08:19:25
The source_id should be per StreamComponent in Str
justinlin
2012/10/08 08:59:45
I think we still may need separate GenerateStream
| |
| 166 security_origin); | |
| 167 } else { | |
| 168 DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " | |
| 169 << (audio ? "audio" : "") | |
| 170 << (video ? " video" : "") << "], " | |
| 171 << security_origin.spec() << ")"; | |
| 172 | |
| 173 media_stream_dispatcher_->GenerateStream( | |
| 174 request_id, | |
| 175 AsWeakPtr(), | |
| 176 media_stream::StreamOptions(audio, video), | |
| 177 security_origin); | |
| 178 } | |
| 127 } | 179 } |
| 128 | 180 |
| 129 void MediaStreamImpl::cancelUserMediaRequest( | 181 void MediaStreamImpl::cancelUserMediaRequest( |
| 130 const WebKit::WebUserMediaRequest& user_media_request) { | 182 const WebKit::WebUserMediaRequest& user_media_request) { |
| 131 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
| 132 MediaRequestMap::iterator it = user_media_requests_.begin(); | 184 MediaRequestMap::iterator it = user_media_requests_.begin(); |
| 133 for (; it != user_media_requests_.end(); ++it) { | 185 for (; it != user_media_requests_.end(); ++it) { |
| 134 if (it->second.request_ == user_media_request) | 186 if (it->second.request_ == user_media_request) |
| 135 break; | 187 break; |
| 136 } | 188 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 // Callback from MediaStreamDispatcher. | 268 // Callback from MediaStreamDispatcher. |
| 217 // The requested stream have been generated. | 269 // The requested stream have been generated. |
| 218 void MediaStreamImpl::OnStreamGenerated( | 270 void MediaStreamImpl::OnStreamGenerated( |
| 219 int request_id, | 271 int request_id, |
| 220 const std::string& label, | 272 const std::string& label, |
| 221 const media_stream::StreamDeviceInfoArray& audio_array, | 273 const media_stream::StreamDeviceInfoArray& audio_array, |
| 222 const media_stream::StreamDeviceInfoArray& video_array) { | 274 const media_stream::StreamDeviceInfoArray& video_array) { |
| 223 DCHECK(CalledOnValidThread()); | 275 DCHECK(CalledOnValidThread()); |
| 224 | 276 |
| 225 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector( | 277 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector( |
| 226 audio_array.size()); | 278 audio_array.size()); |
|
perkj_chrome
2012/10/04 08:19:25
indentation - should be 4 if you break a line. Her
justinlin
2012/10/08 08:59:45
Reverted this.
| |
| 227 CreateWebKitSourceVector(label, audio_array, | 279 CreateWebKitSourceVector(label, audio_array, |
| 228 WebKit::WebMediaStreamSource::TypeAudio, | 280 WebKit::WebMediaStreamSource::TypeAudio, |
| 229 audio_source_vector); | 281 audio_source_vector); |
| 230 WebKit::WebVector<WebKit::WebMediaStreamSource> video_source_vector( | 282 WebKit::WebVector<WebKit::WebMediaStreamSource> video_source_vector( |
| 231 video_array.size()); | 283 video_array.size()); |
| 232 CreateWebKitSourceVector(label, video_array, | 284 CreateWebKitSourceVector(label, video_array, |
| 233 WebKit::WebMediaStreamSource::TypeVideo, | 285 WebKit::WebMediaStreamSource::TypeVideo, |
| 234 video_source_vector); | 286 video_source_vector); |
| 235 | 287 |
| 236 MediaRequestMap::iterator it = user_media_requests_.find(request_id); | 288 MediaRequestMap::iterator it = user_media_requests_.find(request_id); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 508 |
| 457 void MediaStreamExtraData::SetLocalStreamStopCallback( | 509 void MediaStreamExtraData::SetLocalStreamStopCallback( |
| 458 const StreamStopCallback& stop_callback) { | 510 const StreamStopCallback& stop_callback) { |
| 459 stream_stop_callback_ = stop_callback; | 511 stream_stop_callback_ = stop_callback; |
| 460 } | 512 } |
| 461 | 513 |
| 462 void MediaStreamExtraData::OnLocalStreamStop() { | 514 void MediaStreamExtraData::OnLocalStreamStop() { |
| 463 if (!stream_stop_callback_.is_null()) | 515 if (!stream_stop_callback_.is_null()) |
| 464 stream_stop_callback_.Run(local_stream_->label()); | 516 stream_stop_callback_.Run(local_stream_->label()); |
| 465 } | 517 } |
| OLD | NEW |