Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: content/renderer/media/media_stream_impl.cc

Issue 10928043: Media Related changes for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes, fix unit tests. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..da7efc7700fe6e2f6f10105a66a6b92f1f32ef3c 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,45 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
namespace {
+
const int kVideoCaptureWidth = 640;
const int kVideoCaptureHeight = 480;
const int kVideoCaptureFramePerSecond = 30;
+
+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) {
+ 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) {
+ 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 +126,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,22 +135,29 @@ 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
// out of scope.
frame = user_media_request.ownerDocument().frame();
DCHECK(frame);
+
+ UpdateOptionsIfTabMediaRequest(user_media_request, &options);
}
DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ "
- << (audio ? "audio" : "")
- << (user_media_request.video() ? " video" : "") << "], "
+ << "audio=" << (options.audio_type)
+ << ", video=" << (options.video_type) << " ], "
<< security_origin.spec() << ")";
user_media_requests_[request_id] =
@@ -122,7 +166,7 @@ void MediaStreamImpl::requestUserMedia(
media_stream_dispatcher_->GenerateStream(
request_id,
AsWeakPtr(),
- media_stream::StreamOptions(audio, video),
+ options,
security_origin);
}

Powered by Google App Engine
This is Rietveld 408576698