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 /content | |
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
Diffstat (limited to 'content')
-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 |
9 files changed, 129 insertions, 18 deletions
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(); } } } |