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

View file

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