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

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 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 648fe2a5a55accf56157f4e014c10277029387d3..66054eb9e908a54aa181d2ffa60035195cbade90 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,53 @@
#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 "";
no longer working on chromium 2012/10/11 09:07:25 I know both ways work, but what about using std::s
justinlin 2012/10/11 19:41:51 Done.
+
+ WebKit::WebString value;
+ constraints.getMandatoryConstraintValue(UTF8ToUTF16(key), value);
+ return UTF16ToUTF8(value);
+}
+
+bool CheckAndUpdateAsTabMediaRequest(
+ const WebKit::WebUserMediaRequest& user_media_request,
+ content::MediaStreamDeviceType* audio,
no longer working on chromium 2012/10/11 09:07:25 pass a StreamOptions* as input param here.
justinlin 2012/10/11 19:41:51 Done.
+ std::string* audio_device_id,
+ content::MediaStreamDeviceType* video,
+ std::string* video_device_id) {
+ if (*audio != content::MEDIA_NO_SERVICE &&
+ GetMandatoryStreamConstraint(user_media_request.audioConstraints(),
+ media_stream::kMediaStreamSource) ==
no longer working on chromium 2012/10/11 09:07:25 odd indentation. if it fits 80 chars, it should be
justinlin 2012/10/11 19:41:51 Done.
+ media_stream::kMediaStreamSourceTab) {
+ *audio = content::MEDIA_TAB_AUDIO_CAPTURE;
+ *audio_device_id = GetMandatoryStreamConstraint(
+ user_media_request.audioConstraints(),
+ media_stream::kMediaStreamSourceId);
+ }
+
+ if (*video != content::MEDIA_NO_SERVICE &&
+ GetMandatoryStreamConstraint(user_media_request.videoConstraints(),
+ media_stream::kMediaStreamSource) ==
no longer working on chromium 2012/10/11 09:07:25 ditto
justinlin 2012/10/11 19:41:51 Done.
+ media_stream::kMediaStreamSourceTab) {
+ *video = content::MEDIA_TAB_VIDEO_CAPTURE;
+ *video_device_id = GetMandatoryStreamConstraint(
+ user_media_request.videoConstraints(),
+ media_stream::kMediaStreamSourceId);
+ }
+
+ return *audio == content::MEDIA_TAB_VIDEO_CAPTURE ||
+ *video == content::MEDIA_TAB_AUDIO_CAPTURE;
+}
+
} // namespace
static int g_next_request_id = 0;
@@ -87,10 +132,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;
no longer working on chromium 2012/10/11 09:07:25 we should simply use a media_stream::StreamOptions
justinlin 2012/10/11 19:41:51 Done. Thanks, looks better.
+ content::MediaStreamDeviceType video = content::MEDIA_NO_SERVICE;
WebKit::WebFrame* frame = NULL;
GURL security_origin;
@@ -98,11 +144,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,9 +162,21 @@ void MediaStreamImpl::requestUserMedia(
DCHECK(frame);
}
+ std::string audio_device_id, video_device_id;
+ bool isTabMediaRequest = CheckAndUpdateAsTabMediaRequest(user_media_request,
perkj_chrome 2012/10/11 08:01:54 camel case is not used in chrome. change to is_tab
justinlin 2012/10/11 19:41:51 Done.
+ &audio, &audio_device_id, &video, &video_device_id);
+
+ if (isTabMediaRequest) {
+ const GURL& url = user_media_request.ownerDocument().url();
+ if (!url.SchemeIs(kExtensionScheme)) {
+ LOG(ERROR) << "Tried to use tab capture outside extension API.";
+ return;
perkj_chrome 2012/10/11 08:01:54 I realized you can not just return here. You need
justinlin 2012/10/11 19:41:51 Done. Thanks, this is cleaner.
+ }
+ }
+
DVLOG(1) << "MediaStreamImpl::generateStream(" << request_id << ", [ "
<< (audio ? "audio" : "")
- << (user_media_request.video() ? " video" : "") << "], "
+ << (video ? " video" : "") << "], "
<< security_origin.spec() << ")";
user_media_requests_[request_id] =
@@ -122,7 +185,8 @@ void MediaStreamImpl::requestUserMedia(
media_stream_dispatcher_->GenerateStream(
perkj_chrome 2012/10/11 08:01:54 nice
request_id,
AsWeakPtr(),
- media_stream::StreamOptions(audio, video),
+ media_stream::StreamOptions(
+ audio, audio_device_id, video, video_device_id),
security_origin);
}

Powered by Google App Engine
This is Rietveld 408576698