WindowCapturer and ScreenCapturer are merged to DesktopCapturer

This commit is contained in:
Cheng Zhao 2017-01-23 18:47:30 +09:00 committed by Kevin Sawicki
parent 7a7b72ce04
commit d4e3dade39
3 changed files with 30 additions and 32 deletions

View file

@ -10,8 +10,7 @@
#include "chrome/browser/media/desktop_media_list.h"
#include "native_mate/dictionary.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/window_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
#include "atom/common/node_includes.h"
@ -61,10 +60,12 @@ void DesktopCapturer::StartHandling(bool capture_window,
options.set_disable_effects(false);
#endif
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer(
capture_screen ? webrtc::ScreenCapturer::Create(options) : nullptr);
std::unique_ptr<webrtc::WindowCapturer> window_capturer(
capture_window ? webrtc::WindowCapturer::Create(options) : nullptr);
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer(
capture_screen ? webrtc::DesktopCapturer::CreateScreenCapturer(options)
: nullptr);
std::unique_ptr<webrtc::DesktopCapturer> window_capturer(
capture_window ? webrtc::DesktopCapturer::CreateWindowCapturer(options)
: nullptr);
media_list_.reset(new NativeDesktopMediaList(
std::move(screen_capturer), std::move(window_capturer)));

View file

@ -19,8 +19,7 @@
#include "third_party/libyuv/include/libyuv/scale_argb.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
#include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/window_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/skia_util.h"
@ -86,8 +85,8 @@ class NativeDesktopMediaList::Worker
: public webrtc::DesktopCapturer::Callback {
public:
Worker(base::WeakPtr<NativeDesktopMediaList> media_list,
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer,
std::unique_ptr<webrtc::WindowCapturer> window_capturer);
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer,
std::unique_ptr<webrtc::DesktopCapturer> window_capturer);
~Worker() override;
void Refresh(const gfx::Size& thumbnail_size,
@ -102,8 +101,8 @@ class NativeDesktopMediaList::Worker
base::WeakPtr<NativeDesktopMediaList> media_list_;
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer_;
std::unique_ptr<webrtc::WindowCapturer> window_capturer_;
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer_;
std::unique_ptr<webrtc::DesktopCapturer> window_capturer_;
std::unique_ptr<webrtc::DesktopFrame> current_frame_;
@ -114,8 +113,8 @@ class NativeDesktopMediaList::Worker
NativeDesktopMediaList::Worker::Worker(
base::WeakPtr<NativeDesktopMediaList> media_list,
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer,
std::unique_ptr<webrtc::WindowCapturer> window_capturer)
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer,
std::unique_ptr<webrtc::DesktopCapturer> window_capturer)
: media_list_(media_list),
screen_capturer_(std::move(screen_capturer)),
window_capturer_(std::move(window_capturer)) {
@ -133,8 +132,8 @@ void NativeDesktopMediaList::Worker::Refresh(
std::vector<SourceDescription> sources;
if (screen_capturer_) {
webrtc::ScreenCapturer::ScreenList screens;
if (screen_capturer_->GetScreenList(&screens)) {
webrtc::DesktopCapturer::SourceList screens;
if (screen_capturer_->GetSourceList(&screens)) {
bool mutiple_screens = screens.size() > 1;
base::string16 title;
for (size_t i = 0; i < screens.size(); ++i) {
@ -150,10 +149,9 @@ void NativeDesktopMediaList::Worker::Refresh(
}
if (window_capturer_) {
webrtc::WindowCapturer::WindowList windows;
if (window_capturer_->GetWindowList(&windows)) {
for (webrtc::WindowCapturer::WindowList::iterator it = windows.begin();
it != windows.end(); ++it) {
webrtc::DesktopCapturer::SourceList windows;
if (window_capturer_->GetSourceList(&windows)) {
for (auto it = windows.begin(); it != windows.end(); ++it) {
// Skip the picker dialog window.
if (it->id != view_dialog_id) {
sources.push_back(SourceDescription(
@ -176,15 +174,15 @@ void NativeDesktopMediaList::Worker::Refresh(
SourceDescription& source = sources[i];
switch (source.id.type) {
case DesktopMediaID::TYPE_SCREEN:
if (!screen_capturer_->SelectScreen(source.id.id))
if (!screen_capturer_->SelectSource(source.id.id))
continue;
screen_capturer_->Capture(webrtc::DesktopRegion());
screen_capturer_->CaptureFrame();
break;
case DesktopMediaID::TYPE_WINDOW:
if (!window_capturer_->SelectWindow(source.id.id))
if (!window_capturer_->SelectSource(source.id.id))
continue;
window_capturer_->Capture(webrtc::DesktopRegion());
window_capturer_->CaptureFrame();
break;
default:
@ -225,8 +223,8 @@ void NativeDesktopMediaList::Worker::OnCaptureResult(
}
NativeDesktopMediaList::NativeDesktopMediaList(
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer,
std::unique_ptr<webrtc::WindowCapturer> window_capturer)
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer,
std::unique_ptr<webrtc::DesktopCapturer> window_capturer)
: screen_capturer_(std::move(screen_capturer)),
window_capturer_(std::move(window_capturer)),
update_period_(base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)),

View file

@ -12,8 +12,7 @@
#include "ui/gfx/image/image_skia.h"
namespace webrtc {
class ScreenCapturer;
class WindowCapturer;
class DesktopCapturer;
}
// Implementation of DesktopMediaList that shows native screens and
@ -24,8 +23,8 @@ class NativeDesktopMediaList : public DesktopMediaList {
// types of sources the model should be populated with (e.g. it will only
// contain windows, if |screen_capturer| is NULL).
NativeDesktopMediaList(
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer,
std::unique_ptr<webrtc::WindowCapturer> window_capturer);
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer,
std::unique_ptr<webrtc::DesktopCapturer> window_capturer);
~NativeDesktopMediaList() override;
// DesktopMediaList interface.
@ -65,8 +64,8 @@ class NativeDesktopMediaList : public DesktopMediaList {
void OnRefreshFinished();
// Capturers specified in SetCapturers() and passed to the |worker_| later.
std::unique_ptr<webrtc::ScreenCapturer> screen_capturer_;
std::unique_ptr<webrtc::WindowCapturer> window_capturer_;
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer_;
std::unique_ptr<webrtc::DesktopCapturer> window_capturer_;
// Time interval between mode updates.
base::TimeDelta update_period_;