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..b7d58c6bcd163c9246abe8afd0f406721d3f08ce 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" |
|
perkj_chrome
2012/10/09 11:10:02
Get rid of this include. It does not belong here.
justinlin
2012/10/11 07:19:21
Done.
|
| #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" |
| @@ -31,9 +33,23 @@ |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| namespace { |
| + |
| const int kVideoCaptureWidth = 640; |
| const int kVideoCaptureHeight = 480; |
| const int kVideoCaptureFramePerSecond = 30; |
| + |
| +const char kExtensionScheme[] = "chrome-extension"; |
| + |
| +std::string GetMandatoryStreamConstraint( |
| + const WebKit::WebMediaConstraints constraints, const std::string& key) { |
|
perkj_chrome
2012/10/09 11:10:02
const WebKit::WebMediaConstraints&
justinlin
2012/10/11 07:19:21
Done.
|
| + if (constraints.isNull()) |
| + return ""; |
| + |
| + WebKit::WebString value; |
| + constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); |
| + return UTF16ToUTF8(value); |
| +} |
| + |
| } // namespace |
| static int g_next_request_id = 0; |
| @@ -87,10 +103,11 @@ void MediaStreamImpl::requestUserMedia( |
| // The histogram counts the number of calls to the JS API |
| // webGetUserMedia. |
| 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 +115,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 |
| @@ -110,20 +132,58 @@ void MediaStreamImpl::requestUserMedia( |
| frame = user_media_request.ownerDocument().frame(); |
| DCHECK(frame); |
| } |
| + if (audio != content::MEDIA_NO_SERVICE && |
| + GetMandatoryStreamConstraint(user_media_request.audioConstraints(), |
| + media_stream::kMediaStreamSource) == "tab") { |
|
perkj_chrome
2012/10/09 11:10:02
define "tab" as media_stream::kMediaStreamSourceTa
justinlin
2012/10/11 07:19:21
Done.
|
| + audio = content::MEDIA_TAB_AUDIO_CAPTURE; |
| + } |
| - DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " |
| - << (audio ? "audio" : "") |
| - << (user_media_request.video() ? " video" : "") << "], " |
| - << security_origin.spec() << ")"; |
| + if (video != content::MEDIA_NO_SERVICE && |
| + GetMandatoryStreamConstraint(user_media_request.videoConstraints(), |
| + media_stream::kMediaStreamSource) == "tab") { |
| + video = content::MEDIA_TAB_VIDEO_CAPTURE; |
| + } |
| + |
| + if (audio == content::MEDIA_TAB_AUDIO_CAPTURE || |
| + video == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| + const GURL& url = user_media_request.ownerDocument().url(); |
| + if (!url.SchemeIs(kExtensionScheme)) { |
| + DVLOG(1) << "Tried to use tab capture outside extension API."; |
|
perkj_chrome
2012/10/09 11:10:02
Change to error log
justinlin
2012/10/11 07:19:21
Done.
|
| + return; |
| + } |
| + } |
| 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 (audio == content::MEDIA_TAB_AUDIO_CAPTURE || |
|
perkj_chrome
2012/10/09 11:10:02
So it looks like you need video == content::MEDIA
justinlin
2012/10/11 07:19:21
Done.
|
| + video == content::MEDIA_TAB_VIDEO_CAPTURE) { |
| + DVLOG(1) << "MediaStreamImpl::generateStreamForDevice(" |
| + << request_id << ", [ " |
| + << (audio ? "audio" : "") |
| + << (video ? " video" : "") << "], " |
| + << security_origin.spec() << ")"; |
| + |
| + // TODO(justinlin): Right now we only use the mediaSourceId of the video. |
| + media_stream_dispatcher_->GenerateStreamForDevice( |
| + request_id, |
| + AsWeakPtr(), |
| + media_stream::StreamOptions(audio, video), |
| + GetMandatoryStreamConstraint(user_media_request.videoConstraints(), |
| + media_stream::kMediaStreamSourceId), |
| + 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( |