Add DesktopCapturer GetSourceList SelectSource FocusOnSelectedSource functions

I have chosen part of 2435603010 changes to compose this change.
According to the discussion we have made in previous change, this CL contains,
1. Source structure to represent a source of a DesktopCapturer.
2. GetSourceList / SelectSource / FocusOnSelectedSource functions in
DesktopCapturer.
3. ScreenCapturer and WindowCapturer forward corresponding functions to the new
DesktopCapturer APIs.

After this change, We can remove WindowCapturer & ScreenCapturer references from
Chromium, and use the new APIs.

BUG=webrtc:6513

Review-Url: https://codereview.webrtc.org/2452263003
Cr-Commit-Position: refs/heads/master@{#14830}
This commit is contained in:
zijiehe
2016-10-28 17:06:50 -07:00
committed by Commit bot
parent 05a55b500d
commit 9cb0b3b4ac
9 changed files with 218 additions and 13 deletions

View File

@ -61,6 +61,7 @@ rtc_static_library("desktop_capture") {
"desktop_and_cursor_composer.h",
"desktop_capture_options.cc",
"desktop_capture_options.h",
"desktop_capturer.cc",
"desktop_capturer.h",
"desktop_frame_win.cc",
"desktop_frame_win.h",
@ -80,6 +81,7 @@ rtc_static_library("desktop_capture") {
"mouse_cursor_monitor_mac.mm",
"mouse_cursor_monitor_win.cc",
"screen_capture_frame_queue.h",
"screen_capturer.cc",
"screen_capturer.h",
"screen_capturer_helper.cc",
"screen_capturer_helper.h",
@ -118,6 +120,7 @@ rtc_static_library("desktop_capture") {
"win/screen_capturer_win_magnifier.h",
"win/window_capture_utils.cc",
"win/window_capture_utils.h",
"window_capturer.cc",
"window_capturer.h",
"window_capturer_mac.mm",
"window_capturer_win.cc",

View File

@ -39,6 +39,7 @@
'desktop_and_cursor_composer.h',
'desktop_capture_options.h',
'desktop_capture_options.cc',
'desktop_capturer.cc',
'desktop_capturer.h',
'desktop_frame_win.cc',
'desktop_frame_win.h',

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/desktop_capture/desktop_capturer.h"
#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h"
namespace webrtc {
DesktopCapturer::~DesktopCapturer() = default;
void DesktopCapturer::SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
void DesktopCapturer::SetExcludedWindow(WindowId window) {}
bool DesktopCapturer::GetSourceList(SourceList* sources) {
return true;
}
bool DesktopCapturer::SelectSource(SourceId id) {
return false;
}
bool DesktopCapturer::FocusOnSelectedSource() {
return false;
}
} // namespace webrtc

View File

@ -12,8 +12,11 @@
#define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "webrtc/modules/desktop_capture/desktop_frame.h"
#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
@ -21,6 +24,7 @@
namespace webrtc {
class DesktopCaptureOptions;
class DesktopFrame;
// Abstract interface for screen and window capturers.
@ -53,7 +57,20 @@ class DesktopCapturer {
virtual ~Callback() {}
};
virtual ~DesktopCapturer() {}
typedef intptr_t SourceId;
struct Source {
// The unique id to represent a Source of current DesktopCapturer.
SourceId id;
// Title of the window or screen in UTF-8 encoding, maybe empty. This field
// should not be used to identify a source.
std::string title;
};
typedef std::vector<Source> SourceList;
virtual ~DesktopCapturer();
// Called at the beginning of a capturing session. |callback| must remain
// valid until capturer is destroyed.
@ -65,7 +82,7 @@ class DesktopCapturer {
// Shared memory is currently supported only by some DesktopCapturer
// implementations.
virtual void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
std::unique_ptr<SharedMemoryFactory> shared_memory_factory);
// Captures next frame, and involve callback provided by Start() function.
// Pending capture requests are canceled when DesktopCapturer is deleted.
@ -74,7 +91,25 @@ class DesktopCapturer {
// Sets the window to be excluded from the captured image in the future
// Capture calls. Used to exclude the screenshare notification window for
// screen capturing.
virtual void SetExcludedWindow(WindowId window) {}
virtual void SetExcludedWindow(WindowId window);
// TODO(zijiehe): Following functions should be pure virtual. The default
// implementations are for backward compatibility only. Remove default
// implementations once all DesktopCapturer implementations in Chromium have
// implemented these functions.
// Gets a list of sources current capturer supports. Returns false in case of
// a failure.
virtual bool GetSourceList(SourceList* sources);
// Selects a source to be captured. Returns false in case of a failure (e.g.
// if there is no source with the specified type and id.)
virtual bool SelectSource(SourceId id);
// Brings the selected source to the front and sets the input focus on it.
// Returns false in case of a failure or no source has been selected or the
// implementation does not support this functionality.
virtual bool FocusOnSelectedSource();
};
} // namespace webrtc

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/desktop_capture/screen_capturer.h"
#include <memory>
#include <utility>
namespace webrtc {
ScreenCapturer::~ScreenCapturer() = default;
bool ScreenCapturer::GetScreenList(ScreenList* screens) {
SourceList sources;
if (!GetSourceList(&sources)) {
return false;
}
for (const Source& source : sources) {
screens->push_back({source.id});
}
return true;
}
bool ScreenCapturer::SelectScreen(ScreenId id) {
return SelectSource(id);
}
bool ScreenCapturer::GetSourceList(SourceList* sources) {
ScreenList screens;
if (!GetScreenList(&screens)) {
return false;
}
for (const Screen& screen : screens) {
sources->push_back({screen.id});
}
return true;
}
bool ScreenCapturer::SelectSource(SourceId id) {
return SelectScreen(id);
}
} // namespace webrtc

View File

@ -21,6 +21,7 @@ namespace webrtc {
class DesktopCaptureOptions;
// TODO(zijiehe): Remove this class.
// Class used to capture video frames asynchronously.
//
// The full capture sequence is as follows:
@ -48,19 +49,25 @@ class ScreenCapturer : public DesktopCapturer {
};
typedef std::vector<Screen> ScreenList;
~ScreenCapturer() override {}
~ScreenCapturer() override;
// Creates a platform-specific capturer.
static ScreenCapturer* Create(const DesktopCaptureOptions& options);
// Deprecated, use GetSourceList().
// Get the list of screens (not containing kFullDesktopScreenId). Returns
// false in case of a failure.
virtual bool GetScreenList(ScreenList* screens) = 0;
virtual bool GetScreenList(ScreenList* screens);
// Deprecated, use SelectSource().
// Select the screen to be captured. Returns false in case of a failure (e.g.
// if there is no screen with the specified id). If this is never called, the
// full desktop is captured.
virtual bool SelectScreen(ScreenId id) = 0;
virtual bool SelectScreen(ScreenId id);
// DesktopCapturer interfaces.
bool GetSourceList(SourceList* sources) override;
bool SelectSource(SourceId id) override;
};
} // namespace webrtc

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/desktop_capture/window_capturer.h"
#include <string>
#include <utility>
namespace webrtc {
WindowCapturer::~WindowCapturer() = default;
bool WindowCapturer::GetWindowList(WindowList* windows) {
SourceList sources;
if (!GetSourceList(&sources)) {
return false;
}
for (const Source& source : sources) {
windows->push_back({source.id, std::move(source.title)});
}
return true;
}
bool WindowCapturer::SelectWindow(WindowId id) {
return SelectSource(id);
}
bool WindowCapturer::BringSelectedWindowToFront() {
return FocusOnSelectedSource();
}
bool WindowCapturer::GetSourceList(SourceList* sources) {
WindowList windows;
if (!GetWindowList(&windows)) {
return false;
}
for (const Window& window : windows) {
sources->push_back({window.id, std::move(window.title)});
}
return true;
}
bool WindowCapturer::SelectSource(SourceId id) {
return SelectWindow(id);
}
bool WindowCapturer::FocusOnSelectedSource() {
return BringSelectedWindowToFront();
}
} // namespace webrtc

View File

@ -23,10 +23,9 @@ namespace webrtc {
class DesktopCaptureOptions;
// TODO(zijiehe): Remove this class.
class WindowCapturer : public DesktopCapturer {
public:
typedef webrtc::WindowId WindowId;
struct Window {
WindowId id;
@ -36,20 +35,29 @@ class WindowCapturer : public DesktopCapturer {
typedef std::vector<Window> WindowList;
// Consumers should use DesktopCapturer::CreateWindowCapturer.
static WindowCapturer* Create(const DesktopCaptureOptions& options);
~WindowCapturer() override {}
~WindowCapturer() override;
// Deprecated, use GetSourceList().
// Get list of windows. Returns false in case of a failure.
virtual bool GetWindowList(WindowList* windows) = 0;
virtual bool GetWindowList(WindowList* windows);
// Deprecated, use SelectSource().
// Select window to be captured. Returns false in case of a failure (e.g. if
// there is no window with the specified id).
virtual bool SelectWindow(WindowId id) = 0;
virtual bool SelectWindow(WindowId id);
// Deprecated, use FocusOnSelectedSource().
// Bring the selected window to the front. Returns false in case of a
// failure or no window selected.
virtual bool BringSelectedWindowToFront() = 0;
virtual bool BringSelectedWindowToFront();
// DesktopCapturer interfaces.
bool GetSourceList(SourceList* sources) override;
bool SelectSource(SourceId id) override;
bool FocusOnSelectedSource() override;
};
} // namespace webrtc

View File

@ -63,7 +63,7 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
}
WindowCapturer::Window window;
window.id = reinterpret_cast<WindowCapturer::WindowId>(hwnd);
window.id = reinterpret_cast<WindowId>(hwnd);
const size_t kTitleLength = 500;
WCHAR window_title[kTitleLength];