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 1727460d99f612a964711f6f9d06ab00138042dc..19d5940545f17b33b995f4383200d92ffb4082d7 100644 |
| --- a/content/renderer/media/media_stream_impl.cc |
| +++ b/content/renderer/media/media_stream_impl.cc |
| @@ -21,6 +21,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 +32,47 @@ |
| #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) { |
| + if (constraints.isNull()) |
| + return std::string(); |
| + |
| + WebKit::WebString value; |
| + constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value); |
| + return UTF16ToUTF8(value); |
| +} |
| + |
| +void UpdateOptionsIfTabMediaRequest( |
| + const WebKit::WebUserMediaRequest& user_media_request, |
| + media_stream::StreamOptions* options) { |
| + if (options->audio_type != content::MEDIA_NO_SERVICE && |
| + GetMandatoryStreamConstraint(user_media_request.audioConstraints(), |
| + media_stream::kMediaStreamSource) == |
| + media_stream::kMediaStreamSourceTab) { |
|
miu
2012/10/12 01:10:50
nit: Indentation. Consider putting this 4 chars t
justinlin
2012/10/12 03:02:31
Done.
|
| + options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; |
| + options->audio_device_id = GetMandatoryStreamConstraint( |
| + user_media_request.audioConstraints(), |
| + media_stream::kMediaStreamSourceId); |
| + } |
| + |
| + if (options->video_type != content::MEDIA_NO_SERVICE && |
| + GetMandatoryStreamConstraint(user_media_request.videoConstraints(), |
| + media_stream::kMediaStreamSource) == |
| + media_stream::kMediaStreamSourceTab) { |
|
miu
2012/10/12 01:10:50
nit: ditto on indentation.
justinlin
2012/10/12 03:02:31
Done.
|
| + options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; |
| + options->video_device_id = GetMandatoryStreamConstraint( |
| + user_media_request.videoConstraints(), |
| + media_stream::kMediaStreamSourceId); |
| + } |
| +} |
| + |
| } // namespace |
| static int g_next_request_id = 0; |
| @@ -89,8 +128,8 @@ void MediaStreamImpl::requestUserMedia( |
| UpdateWebRTCMethodCount(WEBKIT_GET_USER_MEDIA); |
| DCHECK(CalledOnValidThread()); |
| int request_id = g_next_request_id++; |
| - bool audio = false; |
| - bool video = false; |
| + media_stream::StreamOptions options(content::MEDIA_NO_SERVICE, |
| + content::MEDIA_NO_SERVICE); |
| WebKit::WebFrame* frame = NULL; |
| GURL security_origin; |
| @@ -98,11 +137,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) |
| + options.audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| + if (video_sources.size() > 0) |
| + options.video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| } else { |
| - audio = user_media_request.audio(); |
| - video = user_media_request.video(); |
| + if (user_media_request.audio()) |
| + options.audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| + if (user_media_request.video()) |
| + options.video_type = 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,9 +155,11 @@ void MediaStreamImpl::requestUserMedia( |
| DCHECK(frame); |
| } |
| + UpdateOptionsIfTabMediaRequest(user_media_request, &options); |
|
wjia(left Chromium)
2012/10/11 22:13:27
Do we need any check after this function returns?
justinlin
2012/10/12 00:50:22
Good observation! Right now, this can't really hap
|
| + |
| DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ " |
| - << (audio ? "audio" : "") |
| - << (user_media_request.video() ? " video" : "") << "], " |
| + << (options.audio_type ? "audio" : "") |
|
miu
2012/10/12 01:10:50
nit: Consider replacing these with the following s
justinlin
2012/10/12 03:02:31
Done. Thanks.
|
| + << (options.video_type ? " video" : "") << "], " |
| << security_origin.spec() << ")"; |
| user_media_requests_[request_id] = |
| @@ -122,7 +168,7 @@ void MediaStreamImpl::requestUserMedia( |
| media_stream_dispatcher_->GenerateStream( |
| request_id, |
| AsWeakPtr(), |
| - media_stream::StreamOptions(audio, video), |
| + options, |
| security_origin); |
| } |