Chromium Code Reviews| Index: content/renderer/media/media_stream_impl.cc |
| diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc |
| index 648fe2a5a55accf56157f4e014c10277029387d3..009afd05c0f5de29bdb813cc5f0fade8f867a004 100644 |
| --- a/content/renderer/media/media_stream_impl.cc |
| +++ b/content/renderer/media/media_stream_impl.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/string_number_conversions.h" |
| #include "base/stringprintf.h" |
| #include "base/utf_string_conversions.h" |
| +#include "content/public/common/media_stream_request.h" |
| #include "content/renderer/media/capture_video_decoder.h" |
| #include "content/renderer/media/local_video_capture.h" |
| #include "content/renderer/media/media_stream_extra_data.h" |
| @@ -21,6 +22,7 @@ |
| #include "content/renderer/media/video_capture_impl_manager.h" |
| #include "content/renderer/media/webrtc_uma_histograms.h" |
| #include "media/base/message_loop_factory.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistry.h" |
| @@ -89,8 +91,8 @@ void MediaStreamImpl::requestUserMedia( |
| UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| DCHECK(CalledOnValidThread()); |
| int request_id = g_next_request_id++; |
| - bool audio = false; |
| - bool video = false; |
| + content::MediaStreamDeviceType audio = content::MEDIA_NO_SERVICE; |
| + content::MediaStreamDeviceType video = content::MEDIA_NO_SERVICE; |
| WebKit::WebFrame* frame = NULL; |
| GURL security_origin; |
| @@ -98,11 +100,16 @@ void MediaStreamImpl::requestUserMedia( |
| // if it isNull. |
| if (user_media_request.isNull()) { |
| // We are in a test. |
| - audio = audio_sources.size() > 0; |
| - video = video_sources.size() > 0; |
| + if (audio_sources.size() > 0) |
| + audio = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| + if (video_sources.size() > 0) |
| + video = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| } else { |
| - audio = user_media_request.audio(); |
| - video = user_media_request.video(); |
| + if (user_media_request.audio()) |
| + audio = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| + if (user_media_request.video()) |
| + video = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| + |
| security_origin = GURL(user_media_request.securityOrigin().toString()); |
| // Get the WebFrame that requested a MediaStream. |
| // The frame is needed to tell the MediaStreamDispatcher when a stream goes |
| @@ -111,19 +118,64 @@ void MediaStreamImpl::requestUserMedia( |
| DCHECK(frame); |
| } |
| - DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " |
| - << (audio ? "audio" : "") |
| - << (user_media_request.video() ? " video" : "") << "], " |
| - << security_origin.spec() << ")"; |
| + 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
|
| + WebKit::WebMediaConstraints videoConstraints = |
| + user_media_request.videoConstraints(); |
| + WebKit::WebMediaConstraints audioConstraints = |
| + user_media_request.audioConstraints(); |
| + |
| + WebKit::WebString videoSource; |
| + WebKit::WebString audioSource; |
| + if (!audioConstraints.isNull()) |
| + audioConstraints.getMandatoryConstraintValue( |
| + UTF8ToUTF16(content::kMediaStreamSource), audioSource); |
|
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
|
| + if (!videoConstraints.isNull()) |
| + videoConstraints.getMandatoryConstraintValue( |
| + UTF8ToUTF16(content::kMediaStreamSource), videoSource); |
| + |
| + WebKit::WebString source_id; |
| + // If either source is tab, we use tab media for both for now. |
| + if (UTF16ToUTF8(audioSource) == "tab" || UTF16ToUTF8(videoSource) == "tab") { |
| + isTabCapture = true; |
| + |
| + if (audio != content::MEDIA_NO_SERVICE) |
| + audio = content::MEDIA_TAB_AUDIO_CAPTURE; |
| + if (video != content::MEDIA_NO_SERVICE) |
| + video = content::MEDIA_TAB_VIDEO_CAPTURE; |
| + |
| + // TODO(justinlin): Ignores id provided for audio for now. |
| + videoConstraints.getMandatoryConstraintValue( |
| + UTF8ToUTF16(content::kMediaStreamSourceId), source_id); |
|
perkj_chrome
2012/10/04 08:19:25
indentation
justinlin
2012/10/08 08:59:45
Done.
|
| + } |
| user_media_requests_[request_id] = |
| UserMediaRequestInfo(frame, user_media_request); |
| - media_stream_dispatcher_->GenerateStream( |
| - request_id, |
| - AsWeakPtr(), |
| - media_stream::StreamOptions(audio, video), |
| - security_origin); |
| + if (isTabCapture) { |
| + DVLOG(1) << "MediaStreamImpl::generateStreamForDevice(" |
| + << request_id << ", [ " |
| + << (audio ? "audio" : "") |
| + << (video ? " video" : "") << "], " |
| + << security_origin.spec() << ")"; |
| + |
| + media_stream_dispatcher_->GenerateStreamForDevice( |
| + request_id, |
| + AsWeakPtr(), |
| + media_stream::StreamOptions(audio, video), |
| + 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
|
| + security_origin); |
| + } else { |
| + DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " |
| + << (audio ? "audio" : "") |
| + << (video ? " video" : "") << "], " |
| + << security_origin.spec() << ")"; |
| + |
| + media_stream_dispatcher_->GenerateStream( |
| + request_id, |
| + AsWeakPtr(), |
| + media_stream::StreamOptions(audio, video), |
| + security_origin); |
| + } |
| } |
| void MediaStreamImpl::cancelUserMediaRequest( |
| @@ -223,7 +275,7 @@ void MediaStreamImpl::OnStreamGenerated( |
| DCHECK(CalledOnValidThread()); |
| WebKit::WebVector<WebKit::WebMediaStreamSource> audio_source_vector( |
| - audio_array.size()); |
| + 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.
|
| CreateWebKitSourceVector(label, audio_array, |
| WebKit::WebMediaStreamSource::TypeAudio, |
| audio_source_vector); |