diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-09 06:53:28 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-09 06:53:28 +0000 |
commit | a6cb8bca67f3cf4daf2a9ef86ade994efb7554d4 (patch) | |
tree | bc2f769ee81bc9a97be48e8f6e45f5713fceb42f | |
parent | 6eb4d94bf5cb9c8896c2544eeea9e81c800e38b9 (diff) | |
download | chromium_src-a6cb8bca67f3cf4daf2a9ef86ade994efb7554d4.zip chromium_src-a6cb8bca67f3cf4daf2a9ef86ade994efb7554d4.tar.gz chromium_src-a6cb8bca67f3cf4daf2a9ef86ade994efb7554d4.tar.bz2 |
Add DesktopMediaId type to identify desktop media source.
Also replaced content::MEDIA_SCREEN_VIDEO_CAPTURE with
content::MEDIA_DESKTOP_VIDEO_CAPTURE which will be used to identify all
types of desktop media sources.
BUG=237907
R=jam@chromium.org, xians@chromium.org
Review URL: https://codereview.chromium.org/22370010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216617 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/media/desktop_media_picker.h | 6 | ||||
-rw-r--r-- | chrome/browser/media/desktop_media_picker_model.cc | 39 | ||||
-rw-r--r-- | chrome/browser/media/desktop_media_picker_model.h | 21 | ||||
-rw-r--r-- | chrome/browser/media/desktop_media_picker_model_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/media/media_capture_devices_dispatcher.cc | 62 | ||||
-rw-r--r-- | chrome/browser/ui/views/desktop_media_picker_views.cc | 23 | ||||
-rw-r--r-- | content/browser/renderer_host/media/media_stream_manager.cc | 11 | ||||
-rw-r--r-- | content/browser/renderer_host/media/video_capture_manager.cc | 18 | ||||
-rw-r--r-- | content/content_common.gypi | 2 | ||||
-rw-r--r-- | content/public/common/desktop_media_id.cc | 41 | ||||
-rw-r--r-- | content/public/common/desktop_media_id.h | 57 | ||||
-rw-r--r-- | content/public/common/media_stream_request.cc | 3 | ||||
-rw-r--r-- | content/public/common/media_stream_request.h | 8 | ||||
-rw-r--r-- | content/renderer/media/media_stream_dependency_factory.cc | 2 | ||||
-rw-r--r-- | content/renderer/media/media_stream_impl.cc | 5 |
15 files changed, 202 insertions, 106 deletions
diff --git a/chrome/browser/media/desktop_media_picker.h b/chrome/browser/media/desktop_media_picker.h index 8720698..18f8ab3 100644 --- a/chrome/browser/media/desktop_media_picker.h +++ b/chrome/browser/media/desktop_media_picker.h @@ -8,15 +8,17 @@ #include "base/basictypes.h" #include "base/callback_forward.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/media/desktop_media_picker_model.h" +#include "base/strings/string16.h" +#include "content/public/common/desktop_media_id.h" #include "ui/gfx/native_widget_types.h" +class DesktopMediaPickerModel; // Abstract interface for desktop media picker UI. It's used by Desktop Media // API to let user choose a desktop media source. class DesktopMediaPicker { public: - typedef base::Callback<void(DesktopMediaPickerModel::SourceId)> DoneCallback; + typedef base::Callback<void(content::DesktopMediaID)> DoneCallback; // Creates default implementation of DesktopMediaPicker for the current // platform. diff --git a/chrome/browser/media/desktop_media_picker_model.cc b/chrome/browser/media/desktop_media_picker_model.cc index 37f4959..878d04f 100644 --- a/chrome/browser/media/desktop_media_picker_model.cc +++ b/chrome/browser/media/desktop_media_picker_model.cc @@ -22,6 +22,7 @@ #include "ui/gfx/skia_util.h" using content::BrowserThread; +using content::DesktopMediaID; namespace { @@ -74,34 +75,13 @@ gfx::ImageSkia ScaleDesktopFrame(scoped_ptr<webrtc::DesktopFrame> frame, } // namespace -DesktopMediaPickerModel::SourceId::SourceId() - : type(content::MEDIA_NO_SERVICE), - id(0) { -} - -DesktopMediaPickerModel::SourceId::SourceId(content::MediaStreamType type, - intptr_t id) - : type(type), - id(id) { -} - -DesktopMediaPickerModel::Source::Source(SourceId id, const string16 name) +DesktopMediaPickerModel::Source::Source(DesktopMediaID id, const string16& name) : id(id), name(name) { } -bool DesktopMediaPickerModel::SourceId::operator<( - const DesktopMediaPickerModel::SourceId& other) const { - return type < other.type || (type == other.type && id < other.id); -} - -bool DesktopMediaPickerModel::SourceId::operator==( - const DesktopMediaPickerModel::SourceId& other) const { - return type == other.type && id == other.id; -} - DesktopMediaPickerModel::SourceDescription::SourceDescription( - DesktopMediaPickerModel::SourceId id, + DesktopMediaID id, const string16& name) : id(id), name(name) { @@ -118,7 +98,7 @@ class DesktopMediaPickerModel::Worker void Refresh(const gfx::Size& thumbnail_size); private: - typedef std::map<SourceId, uint32> ImageHashesMap; + typedef std::map<DesktopMediaID, uint32> ImageHashesMap; // webrtc::DesktopCapturer::Callback interface. virtual webrtc::SharedMemory* CreateSharedMemory(size_t size) OVERRIDE; @@ -156,8 +136,8 @@ void DesktopMediaPickerModel::Worker::Refresh(const gfx::Size& thumbnail_size) { if (screen_capturer_) { // TODO(sergeyu): Enumerate each screen when ScreenCapturer supports it. - sources.push_back(SourceDescription(SourceId( - content::MEDIA_SCREEN_VIDEO_CAPTURE, 0), + sources.push_back(SourceDescription(DesktopMediaID( + DesktopMediaID::TYPE_SCREEN, 0), l10n_util::GetStringUTF16(IDS_DESKTOP_MEDIA_PICKER_SCREEN_NAME))); } @@ -167,8 +147,7 @@ void DesktopMediaPickerModel::Worker::Refresh(const gfx::Size& thumbnail_size) { for (webrtc::WindowCapturer::WindowList::iterator it = windows.begin(); it != windows.end(); ++it) { sources.push_back(SourceDescription( - DesktopMediaPickerModel::SourceId( - content::MEDIA_WINDOW_VIDEO_CAPTURE, it->id), + DesktopMediaID(DesktopMediaID::TYPE_WINDOW, it->id), base::UTF8ToUTF16(it->title))); } } @@ -188,12 +167,12 @@ void DesktopMediaPickerModel::Worker::Refresh(const gfx::Size& thumbnail_size) { for (size_t i = 0; i < sources.size(); ++i) { SourceDescription& source = sources[i]; switch (source.id.type) { - case content::MEDIA_SCREEN_VIDEO_CAPTURE: + case DesktopMediaID::TYPE_SCREEN: screen_capturer_->Capture(webrtc::DesktopRegion()); DCHECK(current_frame_); break; - case content::MEDIA_WINDOW_VIDEO_CAPTURE: + case DesktopMediaID::TYPE_WINDOW: if (!window_capturer_->SelectWindow(source.id.id)) continue; window_capturer_->Capture(webrtc::DesktopRegion()); diff --git a/chrome/browser/media/desktop_media_picker_model.h b/chrome/browser/media/desktop_media_picker_model.h index 8dfe9b7..494a325 100644 --- a/chrome/browser/media/desktop_media_picker_model.h +++ b/chrome/browser/media/desktop_media_picker_model.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/sequenced_task_runner.h" -#include "content/public/common/media_stream_request.h" +#include "content/public/common/desktop_media_id.h" #include "ui/gfx/image/image_skia.h" namespace webrtc { @@ -35,23 +35,12 @@ class DesktopMediaPickerModel { virtual void OnSourceThumbnailChanged(int index) = 0; }; - // Type used to identify desktop media sources. - struct SourceId { - SourceId(); - SourceId(content::MediaStreamType type, intptr_t id); - bool operator<(const SourceId& other) const; - bool operator==(const SourceId& other) const; - - content::MediaStreamType type; - intptr_t id; - }; - // Struct used to represent each entry in the model. struct Source { - Source(SourceId id, const string16 name); + Source(content::DesktopMediaID id, const string16& name); // Id of the source. - SourceId id; + content::DesktopMediaID id; // Name of the source that should be shown to the user. string16 name; @@ -97,9 +86,9 @@ class DesktopMediaPickerModel { // Struct used to represent sources list the model gets from the Worker. struct SourceDescription { - SourceDescription(SourceId id, const string16& name); + SourceDescription(content::DesktopMediaID id, const string16& name); - SourceId id; + content::DesktopMediaID id; string16 name; }; diff --git a/chrome/browser/media/desktop_media_picker_model_unittest.cc b/chrome/browser/media/desktop_media_picker_model_unittest.cc index 6cd5fa1..3d2112c5 100644 --- a/chrome/browser/media/desktop_media_picker_model_unittest.cc +++ b/chrome/browser/media/desktop_media_picker_model_unittest.cc @@ -186,9 +186,9 @@ TEST_F(DesktopMediaPickerModelTest, InitialSourceList) { message_loop_.Run(); - EXPECT_EQ(model_.source(0).id.type, content::MEDIA_SCREEN_VIDEO_CAPTURE); + EXPECT_EQ(model_.source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); EXPECT_EQ(model_.source(0).id.id, 0); - EXPECT_EQ(model_.source(1).id.type, content::MEDIA_WINDOW_VIDEO_CAPTURE); + EXPECT_EQ(model_.source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); EXPECT_EQ(model_.source(1).id.id, 0); EXPECT_EQ(model_.source(1).name, UTF8ToUTF16(window.title)); } @@ -217,7 +217,7 @@ TEST_F(DesktopMediaPickerModelTest, WindowsOnly) { message_loop_.Run(); - EXPECT_EQ(model_.source(0).id.type, content::MEDIA_WINDOW_VIDEO_CAPTURE); + EXPECT_EQ(model_.source(0).id.type, content::DesktopMediaID::TYPE_WINDOW); } TEST_F(DesktopMediaPickerModelTest, ScreenOnly) { @@ -236,7 +236,7 @@ TEST_F(DesktopMediaPickerModelTest, ScreenOnly) { message_loop_.Run(); - EXPECT_EQ(model_.source(0).id.type, content::MEDIA_SCREEN_VIDEO_CAPTURE); + EXPECT_EQ(model_.source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); } TEST_F(DesktopMediaPickerModelTest, AddWindow) { @@ -276,7 +276,7 @@ TEST_F(DesktopMediaPickerModelTest, AddWindow) { message_loop_.Run(); - EXPECT_EQ(model_.source(1).id.type, content::MEDIA_WINDOW_VIDEO_CAPTURE); + EXPECT_EQ(model_.source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); EXPECT_EQ(model_.source(1).id.id, 0); } diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc index 03ca4c5..936257e 100644 --- a/chrome/browser/media/media_capture_devices_dispatcher.cc +++ b/chrome/browser/media/media_capture_devices_dispatcher.cc @@ -30,6 +30,7 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" +#include "content/public/common/desktop_media_id.h" #include "content/public/common/media_stream_request.h" #include "extensions/common/constants.h" #include "grit/generated_resources.h" @@ -179,7 +180,7 @@ void MediaCaptureDevicesDispatcher::ProcessMediaAccessRequest( const extensions::Extension* extension) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE || + if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE || request.audio_type == content::MEDIA_SYSTEM_AUDIO_CAPTURE) { ProcessScreenCaptureAccessRequest( web_contents, request, callback, extension); @@ -197,24 +198,22 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback, const extensions::Extension* extension) { - const bool component_extension = - extension && extension->location() == extensions::Manifest::COMPONENT; - content::MediaStreamDevices devices; + scoped_ptr<content::MediaStreamUI> ui; - const bool screen_capture_enabled = - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableUserMediaScreenCapturing) || - IsOriginWhitelistedForScreenCapture(request.security_origin); - - const bool origin_is_secure = - request.security_origin.SchemeIsSecure() || - request.security_origin.SchemeIs(extensions::kExtensionScheme) || - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kAllowHttpScreenCapture); + if (request.video_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + callback.Run(devices, ui.Pass()); + return; + } - const bool screen_video_capture_requested = - request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE; + content::DesktopMediaID media_id = + content::DesktopMediaID::Parse(request.requested_video_device_id); + if (media_id.is_null()) { + LOG(ERROR) << "Invalid desktop media ID: " + << request.requested_video_device_id; + callback.Run(devices, ui.Pass()); + return; + } const bool system_audio_capture_requested = request.audio_type == content::MEDIA_SYSTEM_AUDIO_CAPTURE; @@ -225,15 +224,32 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( const bool system_audio_capture_supported = false; #endif + // Reject request when audio capture was requested but is not supported on + // this system. + if (system_audio_capture_requested && !system_audio_capture_supported) { + callback.Run(devices, ui.Pass()); + return; + } + + const bool component_extension = + extension && extension->location() == extensions::Manifest::COMPONENT; + + const bool screen_capture_enabled = + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableUserMediaScreenCapturing) || + IsOriginWhitelistedForScreenCapture(request.security_origin); + + const bool origin_is_secure = + request.security_origin.SchemeIsSecure() || + request.security_origin.SchemeIs(extensions::kExtensionScheme) || + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kAllowHttpScreenCapture); + // Approve request only when the following conditions are met: // 1. Screen capturing is enabled via command line switch or white-listed for // the given origin. // 2. Request comes from a page with a secure origin or from an extension. - // 3. Video capture is requested for screen video. - // 4. Audio capture is either not requested, or requested for system audio. - if (screen_capture_enabled && origin_is_secure && - screen_video_capture_requested && - (!system_audio_capture_requested || system_audio_capture_supported)) { + if (screen_capture_enabled && origin_is_secure) { // For component extensions, bypass message box. bool user_approved = false; if (!component_extension) { @@ -254,7 +270,7 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( if (user_approved || component_extension) { devices.push_back(content::MediaStreamDevice( - content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); + content::MEDIA_DESKTOP_VIDEO_CAPTURE, media_id.ToString(), "Screen")); if (system_audio_capture_requested) { #if defined(USE_CRAS) // Use the special loopback device ID for system audio capture. @@ -267,7 +283,6 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( } } - scoped_ptr<content::MediaStreamUI> ui; // Unless we're being invoked from a component extension, register to display // the notification for stream capture. if (!devices.empty() && !component_extension) { @@ -282,6 +297,7 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( ui = ScreenCaptureNotificationUI::Create(l10n_util::GetStringFUTF16( IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, UTF8ToUTF16(title))); } + callback.Run(devices, ui.Pass()); } diff --git a/chrome/browser/ui/views/desktop_media_picker_views.cc b/chrome/browser/ui/views/desktop_media_picker_views.cc index 685c155..b21ea7f 100644 --- a/chrome/browser/ui/views/desktop_media_picker_views.cc +++ b/chrome/browser/ui/views/desktop_media_picker_views.cc @@ -23,6 +23,8 @@ #include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_delegate.h" +using content::DesktopMediaID; + namespace { const int kThumbnailWidth = 160; @@ -49,7 +51,7 @@ class DesktopMediaPickerViews; class DesktopMediaSourceView : public views::View { public: DesktopMediaSourceView(DesktopMediaListView* parent, - DesktopMediaPickerModel::SourceId source_id); + DesktopMediaID source_id); virtual ~DesktopMediaSourceView(); // Updates thumbnail and title from |source|. @@ -57,7 +59,7 @@ class DesktopMediaSourceView : public views::View { void SetThumbnail(const gfx::ImageSkia& thumbnail); // Id for the source shown by this View. - const DesktopMediaPickerModel::SourceId& source_id() const { + const DesktopMediaID& source_id() const { return source_id_; } @@ -79,8 +81,7 @@ class DesktopMediaSourceView : public views::View { private: DesktopMediaListView* parent_; - - DesktopMediaPickerModel::SourceId source_id_; + DesktopMediaID source_id_; views::ImageView* image_view_; views::Label* label_; @@ -166,7 +167,7 @@ class DesktopMediaPickerViews : public DesktopMediaPicker { DesktopMediaPickerViews(); virtual ~DesktopMediaPickerViews(); - void NotifyDialogResult(DesktopMediaPickerModel::SourceId source); + void NotifyDialogResult(DesktopMediaID source); // DesktopMediaPicker overrides. virtual void Show(gfx::NativeWindow context, @@ -188,7 +189,7 @@ class DesktopMediaPickerViews : public DesktopMediaPicker { DesktopMediaSourceView::DesktopMediaSourceView( DesktopMediaListView* parent, - DesktopMediaPickerModel::SourceId source_id) + DesktopMediaID source_id) : parent_(parent), source_id_(source_id), image_view_(new views::ImageView()), @@ -491,7 +492,7 @@ bool DesktopMediaPickerDialogView::Accept() { // Ok button should only be enabled when a source is selected. DCHECK(selection); - DesktopMediaPickerModel::SourceId source; + DesktopMediaID source; if (selection) source = selection->source_id(); @@ -504,10 +505,8 @@ bool DesktopMediaPickerDialogView::Accept() { void DesktopMediaPickerDialogView::DeleteDelegate() { // If the dialog is being closed then notify the parent about it. - if (parent_) { - parent_->NotifyDialogResult( - DesktopMediaPickerModel::SourceId(content::MEDIA_NO_SERVICE, 0)); - } + if (parent_) + parent_->NotifyDialogResult(DesktopMediaID()); delete this; } @@ -537,7 +536,7 @@ void DesktopMediaPickerViews::Show(gfx::NativeWindow context, } void DesktopMediaPickerViews::NotifyDialogResult( - DesktopMediaPickerModel::SourceId source) { + DesktopMediaID source) { // Once this method is called the |dialog_| will close and destroy itself. dialog_->DetachParent(); dialog_ = NULL; diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index b5151bc..db7581d 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -263,18 +263,19 @@ std::string MediaStreamManager::GenerateStream( DCHECK(found_match || translated_video_device_id.empty()); } - if (options.video_type == MEDIA_SCREEN_VIDEO_CAPTURE || + if (options.video_type == MEDIA_DESKTOP_VIDEO_CAPTURE || options.audio_type == MEDIA_SYSTEM_AUDIO_CAPTURE) { // For screen capture we only support two valid combinations: // (1) screen video capture only, or // (2) screen video capture with system audio capture. - if (options.video_type != MEDIA_SCREEN_VIDEO_CAPTURE || + if (options.video_type != MEDIA_DESKTOP_VIDEO_CAPTURE || (options.audio_type != MEDIA_NO_SERVICE && options.audio_type != MEDIA_SYSTEM_AUDIO_CAPTURE)) { // TODO(sergeyu): Surface error message to the calling JS code. LOG(ERROR) << "Invalid screen capture request."; return std::string(); } + translated_video_device_id = options.video_device_id; } // Create a new request based on options. @@ -624,11 +625,11 @@ void MediaStreamManager::HandleRequest(const std::string& label) { audio_type == MEDIA_TAB_AUDIO_CAPTURE || video_type == MEDIA_TAB_VIDEO_CAPTURE; - bool is_screen_capure = - video_type == MEDIA_SCREEN_VIDEO_CAPTURE; + bool is_screen_capture = + video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; if (!is_web_contents_capture && - !is_screen_capure && + !is_screen_capture && ((IsAudioMediaType(audio_type) && !audio_enumeration_cache_.valid) || (IsVideoMediaType(video_type) && !video_enumeration_cache_.valid))) { // Enumerate the devices if there is no valid device lists to be used. diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc index aa27e12..d96f08d 100644 --- a/content/browser/renderer_host/media/video_capture_manager.cc +++ b/content/browser/renderer_host/media/video_capture_manager.cc @@ -16,6 +16,7 @@ #include "content/browser/renderer_host/media/web_contents_video_capture_device.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" +#include "content/public/common/desktop_media_id.h" #include "content/public/common/media_stream_request.h" #include "media/base/scoped_histogram_timer.h" #include "media/video/capture/fake_video_capture_device.h" @@ -187,13 +188,16 @@ void VideoCaptureManager::OnOpen(int capture_session_id, device.device.id); break; } - case MEDIA_SCREEN_VIDEO_CAPTURE: { + case MEDIA_DESKTOP_VIDEO_CAPTURE: { #if defined(ENABLE_SCREEN_CAPTURE) - scoped_refptr<base::SequencedWorkerPool> blocking_pool = - BrowserThread::GetBlockingPool(); - video_capture_device = new ScreenCaptureDevice( - blocking_pool->GetSequencedTaskRunner( - blocking_pool->GetSequenceToken())); + DesktopMediaID id = DesktopMediaID::Parse(device.device.id); + if (id.type == DesktopMediaID::TYPE_SCREEN) { + scoped_refptr<base::SequencedWorkerPool> blocking_pool = + BrowserThread::GetBlockingPool(); + video_capture_device = new ScreenCaptureDevice( + blocking_pool->GetSequencedTaskRunner( + blocking_pool->GetSequenceToken())); + } #endif // defined(ENABLE_SCREEN_CAPTURE) break; } @@ -434,7 +438,7 @@ void VideoCaptureManager::GetAvailableDevices( *device_names = video_capture_devices_; break; - case MEDIA_SCREEN_VIDEO_CAPTURE: + case MEDIA_DESKTOP_VIDEO_CAPTURE: device_names->clear(); break; diff --git a/content/content_common.gypi b/content/content_common.gypi index 42a345b..f7413b5 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -37,6 +37,8 @@ 'public/common/context_menu_params.cc', 'public/common/context_menu_params.h', 'public/common/console_message_level.h', + 'public/common/desktop_media_id.cc', + 'public/common/desktop_media_id.h', 'public/common/drop_data.cc', 'public/common/drop_data.h', 'public/common/favicon_url.cc', diff --git a/content/public/common/desktop_media_id.cc b/content/public/common/desktop_media_id.cc new file mode 100644 index 0000000..82ebe9c --- /dev/null +++ b/content/public/common/desktop_media_id.cc @@ -0,0 +1,41 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/common/desktop_media_id.h" + +namespace content { + +// static +DesktopMediaID DesktopMediaID::Parse(const std::string& str) { + if (str == "screen") + return DesktopMediaID(TYPE_SCREEN, 0); + + std::string window_prefix("window:"); + if (StartsWithASCII(str, window_prefix, true)) { + int64 id; + if (!base::StringToInt64(str.substr(window_prefix.size()), &id)) + return DesktopMediaID(TYPE_NONE, 0); + return DesktopMediaID(TYPE_WINDOW, id); + } + + return DesktopMediaID(TYPE_NONE, 0); +} + +std::string DesktopMediaID::ToString() { + switch (type) { + case TYPE_NONE: + NOTREACHED(); + return std::string(); + + case TYPE_SCREEN: + return "screen"; + + case TYPE_WINDOW: + return "window:" + base::Int64ToString(id); + } + NOTREACHED(); + return std::string(); +} + +} // namespace content diff --git a/content/public/common/desktop_media_id.h b/content/public/common/desktop_media_id.h new file mode 100644 index 0000000..a863872 --- /dev/null +++ b/content/public/common/desktop_media_id.h @@ -0,0 +1,57 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_COMMON_DESKTOP_MEDIA_ID_H_ +#define CONTENT_PUBLIC_COMMON_DESKTOP_MEDIA_ID_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/string_util.h" +#include "content/common/content_export.h" + +namespace content { + +// Type used to identify desktop media sources. It's converted to string and +// stored in MediaStreamRequest::requested_video_device_id . +struct CONTENT_EXPORT DesktopMediaID { + public: + enum Type { + TYPE_NONE, + TYPE_SCREEN, + TYPE_WINDOW, + }; + typedef intptr_t Id; + + static DesktopMediaID Parse(const std::string& str); + + DesktopMediaID() + : type(TYPE_NONE), + id(0) { + } + DesktopMediaID(Type type, Id id) + : type(type), + id(id) { + } + + // Operators so that DesktopMediaID can be used with STL containers. + bool operator<(const DesktopMediaID& other) const { + return type < other.type || (type == other.type && id < other.id); + } + bool operator==(const DesktopMediaID& other) const { + return type == other.type && id == other.id; + } + + bool is_null() { return type == TYPE_NONE; } + + std::string ToString(); + + Type type; + Id id; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_COMMON_DESKTOP_MEDIA_ID_H_ diff --git a/content/public/common/media_stream_request.cc b/content/public/common/media_stream_request.cc index 2c2f9d8..e3ad35b 100644 --- a/content/public/common/media_stream_request.cc +++ b/content/public/common/media_stream_request.cc @@ -17,8 +17,7 @@ bool IsAudioMediaType(MediaStreamType type) { bool IsVideoMediaType(MediaStreamType type) { return (type == content::MEDIA_DEVICE_VIDEO_CAPTURE || type == content::MEDIA_TAB_VIDEO_CAPTURE || - type == content::MEDIA_SCREEN_VIDEO_CAPTURE || - type == content::MEDIA_WINDOW_VIDEO_CAPTURE); + type == content::MEDIA_DESKTOP_VIDEO_CAPTURE); } MediaStreamDevice::MediaStreamDevice() : type(MEDIA_NO_SERVICE) {} diff --git a/content/public/common/media_stream_request.h b/content/public/common/media_stream_request.h index d01e7a8..cbbf232 100644 --- a/content/public/common/media_stream_request.h +++ b/content/public/common/media_stream_request.h @@ -26,14 +26,18 @@ enum MediaStreamType { MEDIA_DEVICE_VIDEO_CAPTURE, // Mirroring of a browser tab. + // + // TODO(serygeu): Remove these values and use MEDIA_DESKTOP_VIDEO_CAPTURE and + // MEDIA_DESKTOP_AUDIO_CAPTURE. MEDIA_TAB_AUDIO_CAPTURE, MEDIA_TAB_VIDEO_CAPTURE, // Desktop media sources. - MEDIA_SCREEN_VIDEO_CAPTURE, - MEDIA_WINDOW_VIDEO_CAPTURE, + MEDIA_DESKTOP_VIDEO_CAPTURE, // Capture system audio (post-mix loopback stream). + // + // TODO(sergeyu): Replace with MEDIA_DESKTOP_AUDIO_CAPTURE. MEDIA_SYSTEM_AUDIO_CAPTURE, NUM_MEDIA_TYPES diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc index 7f5e64a..3d07ce8 100644 --- a/content/renderer/media/media_stream_dependency_factory.cc +++ b/content/renderer/media/media_stream_dependency_factory.cc @@ -286,7 +286,7 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources( source_data->device_info().device.type == content::MEDIA_TAB_VIDEO_CAPTURE || source_data->device_info().device.type == - content::MEDIA_SCREEN_VIDEO_CAPTURE; + content::MEDIA_DESKTOP_VIDEO_CAPTURE; source_data->SetVideoSource( CreateLocalVideoSource(source_data->device_info().session_id, is_screencast, diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc index abe68a2..ac66f23 100644 --- a/content/renderer/media/media_stream_impl.cc +++ b/content/renderer/media/media_stream_impl.cc @@ -10,6 +10,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "content/public/common/desktop_media_id.h" #include "content/renderer/media/media_stream_audio_renderer.h" #include "content/renderer/media/media_stream_dependency_factory.h" #include "content/renderer/media/media_stream_dispatcher.h" @@ -71,7 +72,9 @@ void UpdateRequestOptions( user_media_request.videoConstraints(), kMediaStreamSourceId, true); } else if (video_stream_source == kMediaStreamSourceScreen) { - options->video_type = content::MEDIA_SCREEN_VIDEO_CAPTURE; + options->video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; + options->video_device_id = + DesktopMediaID(DesktopMediaID::TYPE_SCREEN, 0).ToString(); } } } |