diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn index 1279af139d..18f8ba11da 100644 --- a/webrtc/modules/BUILD.gn +++ b/webrtc/modules/BUILD.gn @@ -8,11 +8,10 @@ import("../build/webrtc.gni") import("audio_coding/audio_coding.gni") -import("desktop_capture/desktop_capture.gni") declare_args() { # Desktop capturer is supported only on Windows, OSX and Linux. - rtc_desktop_capture_supported = rtc_desktop_capture_supported + rtc_desktop_capture_supported = is_win || is_mac || is_linux } group("modules") { @@ -561,7 +560,6 @@ if (rtc_include_tests) { "desktop_capture/desktop_capturer_differ_wrapper_unittest.cc", "desktop_capture/mouse_cursor_monitor_unittest.cc", "desktop_capture/rgba_color_unittest.cc", - "desktop_capture/screen_capturer_differ_wrapper_unittest.cc", "desktop_capture/screen_capturer_helper_unittest.cc", "desktop_capture/screen_capturer_mac_unittest.cc", "desktop_capture/screen_capturer_mock_objects.h", diff --git a/webrtc/modules/desktop_capture/BUILD.gn b/webrtc/modules/desktop_capture/BUILD.gn index 1cb421ef35..ebf337d055 100644 --- a/webrtc/modules/desktop_capture/BUILD.gn +++ b/webrtc/modules/desktop_capture/BUILD.gn @@ -8,7 +8,6 @@ import("//build/config/ui.gni") import("../../build/webrtc.gni") -import("desktop_capture.gni") use_desktop_capture_differ_sse2 = !is_ios && (current_cpu == "x86" || current_cpu == "x64") @@ -72,9 +71,8 @@ if (rtc_include_tests) { sources = [ "desktop_frame_generator.cc", "desktop_frame_generator.h", + "fake_desktop_capturer.cc", "fake_desktop_capturer.h", - "fake_screen_capturer.cc", - "fake_screen_capturer.h", "mock_desktop_capturer_callback.h", "screen_capturer_mock_objects.h", ] @@ -112,8 +110,6 @@ 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", "screen_capturer_mac.mm", @@ -151,8 +147,6 @@ 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", ] @@ -186,8 +180,6 @@ rtc_static_library("desktop_capture") { "desktop_capturer_differ_wrapper.h", "differ_block.cc", "differ_block.h", - "screen_capturer_differ_wrapper.cc", - "screen_capturer_differ_wrapper.h", ] } @@ -215,10 +207,6 @@ rtc_static_library("desktop_capture") { if (use_desktop_capture_differ_sse2) { deps += [ ":desktop_capture_differ_sse2" ] } - - if (rtc_desktop_capture_supported) { - defines = [ "RTC_DESKTOP_CAPTURE_SUPPORTED" ] - } } if (use_desktop_capture_differ_sse2) { diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.cc b/webrtc/modules/desktop_capture/cropping_window_capturer.cc index f0382c3e8f..8f1c772c99 100644 --- a/webrtc/modules/desktop_capture/cropping_window_capturer.cc +++ b/webrtc/modules/desktop_capture/cropping_window_capturer.cc @@ -21,8 +21,7 @@ CroppingWindowCapturer::CroppingWindowCapturer( callback_(NULL), window_capturer_(DesktopCapturer::CreateRawWindowCapturer(options)), selected_window_(kNullWindowId), - excluded_window_(kNullWindowId) { -} + excluded_window_(kNullWindowId) {} CroppingWindowCapturer::~CroppingWindowCapturer() {} @@ -103,9 +102,9 @@ void CroppingWindowCapturer::OnCaptureResult( #if !defined(WEBRTC_WIN) // static -WindowCapturer* -CroppingWindowCapturer::Create(const DesktopCaptureOptions& options) { - return WindowCapturer::Create(options); +DesktopCapturer* CroppingWindowCapturer::Create( + const DesktopCaptureOptions& options) { + return DesktopCapturer::CreateWindowCapturer(options).release(); } #endif diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.h b/webrtc/modules/desktop_capture/cropping_window_capturer.h index 7986821bc9..4c7c1dbd92 100644 --- a/webrtc/modules/desktop_capture/cropping_window_capturer.h +++ b/webrtc/modules/desktop_capture/cropping_window_capturer.h @@ -13,19 +13,18 @@ #include +#include "webrtc/modules/desktop_capture/desktop_capturer.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" -#include "webrtc/modules/desktop_capture/screen_capturer.h" -#include "webrtc/modules/desktop_capture/window_capturer.h" namespace webrtc { // WindowCapturer implementation that uses a screen capturer to capture the // whole screen and crops the video frame to the window area when the captured // window is on top. -class CroppingWindowCapturer : public WindowCapturer, +class CroppingWindowCapturer : public DesktopCapturer, public DesktopCapturer::Callback { public: - static WindowCapturer* Create(const DesktopCaptureOptions& options); + static DesktopCapturer* Create(const DesktopCaptureOptions& options); ~CroppingWindowCapturer() override; // DesktopCapturer implementation. diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer_win.cc b/webrtc/modules/desktop_capture/cropping_window_capturer_win.cc index fe696eba67..e191d9f354 100644 --- a/webrtc/modules/desktop_capture/cropping_window_capturer_win.cc +++ b/webrtc/modules/desktop_capture/cropping_window_capturer_win.cc @@ -210,8 +210,8 @@ DesktopRect CroppingWindowCapturerWin::GetWindowRectInVirtualScreen() { } // namespace // static -WindowCapturer* -CroppingWindowCapturer::Create(const DesktopCaptureOptions& options) { +DesktopCapturer* CroppingWindowCapturer::Create( + const DesktopCaptureOptions& options) { return new CroppingWindowCapturerWin(options); } diff --git a/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc b/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc index 77471b8efe..79a30b0d22 100644 --- a/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc +++ b/webrtc/modules/desktop_capture/desktop_and_cursor_composer_unittest.cc @@ -11,14 +11,13 @@ #include #include "webrtc/modules/desktop_capture/desktop_and_cursor_composer.h" - -#include "webrtc/test/gtest.h" +#include "webrtc/modules/desktop_capture/desktop_capturer.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/mouse_cursor.h" #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" -#include "webrtc/modules/desktop_capture/window_capturer.h" #include "webrtc/system_wrappers/include/logging.h" +#include "webrtc/test/gtest.h" namespace webrtc { diff --git a/webrtc/modules/desktop_capture/desktop_capture.gni b/webrtc/modules/desktop_capture/desktop_capture.gni deleted file mode 100644 index 02ad81472f..0000000000 --- a/webrtc/modules/desktop_capture/desktop_capture.gni +++ /dev/null @@ -1,11 +0,0 @@ -# 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. - -import("../../build/webrtc.gni") - -rtc_desktop_capture_supported = is_win || is_mac || is_linux diff --git a/webrtc/modules/desktop_capture/desktop_capture.gypi b/webrtc/modules/desktop_capture/desktop_capture.gypi index b6d6f9992c..ed96eb6d94 100644 --- a/webrtc/modules/desktop_capture/desktop_capture.gypi +++ b/webrtc/modules/desktop_capture/desktop_capture.gypi @@ -59,7 +59,6 @@ 'mouse_cursor_monitor_mac.mm', 'mouse_cursor_monitor_win.cc', 'screen_capture_frame_queue.h', - 'screen_capturer.h', 'screen_capturer_helper.cc', 'screen_capturer_helper.h', 'screen_capturer_mac.mm', @@ -99,7 +98,6 @@ 'win/screen_capturer_win_magnifier.h', 'win/window_capture_utils.cc', 'win/window_capture_utils.h', - 'window_capturer.h', 'window_capturer_mac.mm', 'window_capturer_win.cc', ], @@ -145,8 +143,6 @@ 'desktop_capturer_differ_wrapper.h', 'differ_block.cc', 'differ_block.h', - 'screen_capturer_differ_wrapper.cc', - 'screen_capturer_differ_wrapper.h', ], }], ['OS=="mac"', { diff --git a/webrtc/modules/desktop_capture/desktop_capturer.cc b/webrtc/modules/desktop_capture/desktop_capturer.cc index f28630e9c4..37b3396df9 100644 --- a/webrtc/modules/desktop_capture/desktop_capturer.cc +++ b/webrtc/modules/desktop_capture/desktop_capturer.cc @@ -34,11 +34,6 @@ bool DesktopCapturer::FocusOnSelectedSource() { return false; } -// Some platforms, such as ChromeOS, have their DesktopCapturer implementations -// in Chromium. So even we do not have CreateRawWindowCapturer() or -// CreateRawScreenCapturer() implemented in WebRTC, we still need to build other -// DesktopCapturer components when RTC_DESKTOP_CAPTURE_SUPPORTED is not defined. -#if defined(RTC_DESKTOP_CAPTURE_SUPPORTED) // static std::unique_ptr DesktopCapturer::CreateWindowCapturer( const DesktopCaptureOptions& options) { @@ -60,6 +55,5 @@ std::unique_ptr DesktopCapturer::CreateScreenCapturer( return capturer; } -#endif // defined(RTC_DESKTOP_CAPTURE_SUPPORTED) } // namespace webrtc diff --git a/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper_unittest.cc b/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper_unittest.cc index 594ad13274..eb6012a908 100644 --- a/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper_unittest.cc +++ b/webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper_unittest.cc @@ -20,7 +20,7 @@ #include "webrtc/modules/desktop_capture/desktop_geometry.h" #include "webrtc/modules/desktop_capture/desktop_region.h" #include "webrtc/modules/desktop_capture/differ_block.h" -#include "webrtc/modules/desktop_capture/fake_screen_capturer.h" +#include "webrtc/modules/desktop_capture/fake_desktop_capturer.h" #include "webrtc/modules/desktop_capture/mock_desktop_capturer_callback.h" #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" #include "webrtc/test/gtest.h" @@ -159,7 +159,7 @@ void ExecuteDifferWrapperTest(bool with_hints, BlackWhiteDesktopFramePainter frame_painter; PainterDesktopFrameGenerator frame_generator; frame_generator.set_desktop_frame_painter(&frame_painter); - std::unique_ptr> fake(new FakeDesktopCapturer<>()); + std::unique_ptr fake(new FakeDesktopCapturer()); fake->set_frame_generator(&frame_generator); DesktopCapturerDifferWrapper capturer(std::move(fake)); MockDesktopCapturerCallback callback; diff --git a/webrtc/modules/desktop_capture/fake_desktop_capturer.cc b/webrtc/modules/desktop_capture/fake_desktop_capturer.cc new file mode 100644 index 0000000000..bd4c37e8b5 --- /dev/null +++ b/webrtc/modules/desktop_capture/fake_desktop_capturer.cc @@ -0,0 +1,70 @@ +/* + * 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/fake_desktop_capturer.h" + +#include + +namespace webrtc { + +FakeDesktopCapturer::FakeDesktopCapturer() + : callback_(nullptr), + result_(DesktopCapturer::Result::SUCCESS), + generator_(nullptr) {} + +FakeDesktopCapturer::~FakeDesktopCapturer() = default; + +void FakeDesktopCapturer::set_result(DesktopCapturer::Result result) { + result_ = result; +} + +// Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer +// does +// not take the ownership of |generator|. +void FakeDesktopCapturer::set_frame_generator( + DesktopFrameGenerator* generator) { + generator_ = generator; +} + +void FakeDesktopCapturer::Start(DesktopCapturer::Callback* callback) { + callback_ = callback; +} + +void FakeDesktopCapturer::CaptureFrame() { + if (generator_) { + std::unique_ptr frame( + generator_->GetNextFrame(shared_memory_factory_.get())); + if (frame) { + callback_->OnCaptureResult(result_, std::move(frame)); + } else { + callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_TEMPORARY, + nullptr); + } + return; + } + callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, nullptr); +} + +void FakeDesktopCapturer::SetSharedMemoryFactory( + std::unique_ptr shared_memory_factory) { + shared_memory_factory_ = std::move(shared_memory_factory); +} + +bool FakeDesktopCapturer::GetSourceList(DesktopCapturer::SourceList* sources) { + sources->push_back({kWindowId, "A-Fake-DesktopCapturer-Window"}); + sources->push_back({kScreenId}); + return true; +} + +bool FakeDesktopCapturer::SelectSource(DesktopCapturer::SourceId id) { + return id == kWindowId || id == kScreenId || id == kFullDesktopScreenId; +} + +} // namespace webrtc diff --git a/webrtc/modules/desktop_capture/fake_desktop_capturer.h b/webrtc/modules/desktop_capture/fake_desktop_capturer.h index 3018777540..33073a00f7 100644 --- a/webrtc/modules/desktop_capture/fake_desktop_capturer.h +++ b/webrtc/modules/desktop_capture/fake_desktop_capturer.h @@ -12,12 +12,10 @@ #define WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ #include -#include #include "webrtc/modules/desktop_capture/desktop_capturer.h" #include "webrtc/modules/desktop_capture/desktop_capture_types.h" #include "webrtc/modules/desktop_capture/desktop_frame_generator.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/modules/desktop_capture/shared_memory.h" namespace webrtc { @@ -33,66 +31,25 @@ namespace webrtc { // Double buffering is guaranteed by the FrameGenerator. FrameGenerator // implements in desktop_frame_generator.h guarantee double buffering, they // creates a new instance of DesktopFrame each time. -// -// T must be DesktopCapturer or its derived interfaces. -// -// TODO(zijiehe): Remove template T once we merge ScreenCapturer and -// WindowCapturer. -template -class FakeDesktopCapturer : public T { +class FakeDesktopCapturer : public DesktopCapturer { public: - FakeDesktopCapturer() - : callback_(nullptr), - result_(DesktopCapturer::Result::SUCCESS), - generator_(nullptr) {} - - ~FakeDesktopCapturer() override {} + FakeDesktopCapturer(); + ~FakeDesktopCapturer() override; // Decides the result which will be returned in next Capture() callback. - void set_result(DesktopCapturer::Result result) { result_ = result; } + void set_result(DesktopCapturer::Result result); // Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer - // does - // not take the ownership of |generator|. - void set_frame_generator(DesktopFrameGenerator* generator) { - generator_ = generator; - } + // does not take the ownership of |generator|. + void set_frame_generator(DesktopFrameGenerator* generator); // DesktopCapturer interface - void Start(DesktopCapturer::Callback* callback) override { - callback_ = callback; - } - - void CaptureFrame() override { - if (generator_) { - std::unique_ptr frame( - generator_->GetNextFrame(shared_memory_factory_.get())); - if (frame) { - callback_->OnCaptureResult(result_, std::move(frame)); - } else { - callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_TEMPORARY, - nullptr); - } - return; - } - callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, - nullptr); - } - + void Start(DesktopCapturer::Callback* callback) override; + void CaptureFrame() override; void SetSharedMemoryFactory( - std::unique_ptr shared_memory_factory) override { - shared_memory_factory_ = std::move(shared_memory_factory); - } - - bool GetSourceList(DesktopCapturer::SourceList* sources) override { - sources->push_back({kWindowId, "A-Fake-DesktopCapturer-Window"}); - sources->push_back({kScreenId}); - return true; - } - - bool SelectSource(DesktopCapturer::SourceId id) override { - return id == kWindowId || id == kScreenId || id == kFullDesktopScreenId; - } + std::unique_ptr shared_memory_factory) override; + bool GetSourceList(DesktopCapturer::SourceList* sources) override; + bool SelectSource(DesktopCapturer::SourceId id) override; private: static constexpr DesktopCapturer::SourceId kWindowId = 1378277495; diff --git a/webrtc/modules/desktop_capture/fake_screen_capturer.cc b/webrtc/modules/desktop_capture/fake_screen_capturer.cc deleted file mode 100644 index 192992fcff..0000000000 --- a/webrtc/modules/desktop_capture/fake_screen_capturer.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/fake_screen_capturer.h" - -#include - -#include - -namespace webrtc { - -FakeScreenCapturer::FakeScreenCapturer() - : FakeDesktopCapturer(), - // A random number for the fake screen. - id_(1378277498) {} -FakeScreenCapturer::~FakeScreenCapturer() {} - -bool FakeScreenCapturer::GetScreenList(ScreenList* list) { - list->push_back(Screen{id_}); - return true; -} - -bool FakeScreenCapturer::SelectScreen(ScreenId id) { - return id == kFullDesktopScreenId || id == id_; -} - -} // namespace webrtc diff --git a/webrtc/modules/desktop_capture/fake_screen_capturer.h b/webrtc/modules/desktop_capture/fake_screen_capturer.h deleted file mode 100644 index 3b7c6fc25f..0000000000 --- a/webrtc/modules/desktop_capture/fake_screen_capturer.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ - -#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_SCREEN_CAPTURER_H_ -#define WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_SCREEN_CAPTURER_H_ - -#include "webrtc/modules/desktop_capture/fake_desktop_capturer.h" -#include "webrtc/modules/desktop_capture/screen_capturer.h" - -namespace webrtc { - -class FakeScreenCapturer : public FakeDesktopCapturer { - public: - FakeScreenCapturer(); - ~FakeScreenCapturer() override; - - // ScreenCapturer interface. - bool GetScreenList(ScreenList* list) override; - bool SelectScreen(ScreenId id) override; - - private: - // A random ScreenId. - const ScreenId id_; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_SCREEN_CAPTURER_H_ diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc index fcd870ced7..23b299b4aa 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc +++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc @@ -11,13 +11,12 @@ #include #include "webrtc/modules/desktop_capture/mouse_cursor_monitor.h" - -#include "webrtc/test/gtest.h" +#include "webrtc/modules/desktop_capture/desktop_capturer.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/mouse_cursor.h" -#include "webrtc/modules/desktop_capture/window_capturer.h" #include "webrtc/system_wrappers/include/logging.h" +#include "webrtc/test/gtest.h" namespace webrtc { diff --git a/webrtc/modules/desktop_capture/screen_capturer.cc b/webrtc/modules/desktop_capture/screen_capturer.cc deleted file mode 100644 index a35aa1a014..0000000000 --- a/webrtc/modules/desktop_capture/screen_capturer.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 -#include - -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 diff --git a/webrtc/modules/desktop_capture/screen_capturer.h b/webrtc/modules/desktop_capture/screen_capturer.h deleted file mode 100644 index a6bbde73ee..0000000000 --- a/webrtc/modules/desktop_capture/screen_capturer.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2013 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. - */ - -#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ -#define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ - -#include - -#include "webrtc/modules/desktop_capture/desktop_capture_types.h" -#include "webrtc/modules/desktop_capture/desktop_capturer.h" -#include "webrtc/typedefs.h" - -namespace webrtc { - -class DesktopCaptureOptions; - -// TODO(zijiehe): Remove this class. -// Class used to capture video frames asynchronously. -// -// The full capture sequence is as follows: -// -// (1) Start -// This is when pre-capture steps are executed, such as flagging the -// display to prevent it from sleeping during a session. -// -// (2) CaptureFrame -// This is where the bits for the invalid rects are packaged up and sent -// to the encoder. -// A screen capture is performed if needed. For example, Windows requires -// a capture to calculate the diff from the previous screen, whereas the -// Mac version does not. -// -// Implementation has to ensure the following guarantees: -// 1. Double buffering -// Since data can be read while another capture action is happening. -class ScreenCapturer : public DesktopCapturer { - public: - // Use a struct to represent a screen although it has only an id for now, - // because we may want to add more fields (e.g. description) in the future. - struct Screen { - ScreenId id; - }; - typedef std::vector ScreenList; - - ~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); - - // 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); - - // DesktopCapturer interfaces. - bool GetSourceList(SourceList* sources) override; - bool SelectSource(SourceId id) override; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_H_ diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc deleted file mode 100644 index 6306d0290c..0000000000 --- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * 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_differ_wrapper.h" - -#include - -#include -#include - -#include "webrtc/base/checks.h" -#include "webrtc/base/timeutils.h" -#include "webrtc/modules/desktop_capture/desktop_geometry.h" -#include "webrtc/modules/desktop_capture/differ_block.h" - -namespace webrtc { - -namespace { - -// Returns true if (0, 0) - (|width|, |height|) vector in |old_buffer| and -// |new_buffer| are equal. |width| should be less than 32 -// (defined by kBlockSize), otherwise BlockDifference() should be used. -bool PartialBlockDifference(const uint8_t* old_buffer, - const uint8_t* new_buffer, - int width, - int height, - int stride) { - RTC_DCHECK_LT(width, kBlockSize); - const int width_bytes = width * DesktopFrame::kBytesPerPixel; - for (int i = 0; i < height; i++) { - if (memcmp(old_buffer, new_buffer, width_bytes) != 0) { - return true; - } - old_buffer += stride; - new_buffer += stride; - } - return false; -} - -// Compares columns in the range of [|left|, |right|), in a row in the -// range of [|top|, |top| + |height|), starts from |old_buffer| and -// |new_buffer|, and outputs updated regions into |output|. |stride| is the -// DesktopFrame::stride(). -void CompareRow(const uint8_t* old_buffer, - const uint8_t* new_buffer, - const int left, - const int right, - const int top, - const int bottom, - const int stride, - DesktopRegion* const output) { - const int block_x_offset = kBlockSize * DesktopFrame::kBytesPerPixel; - const int width = right - left; - const int height = bottom - top; - const int block_count = (width - 1) / kBlockSize; - const int last_block_width = width - block_count * kBlockSize; - RTC_DCHECK(last_block_width <= kBlockSize && last_block_width > 0); - - // The first block-column in a continuous dirty area in current block-row. - int first_dirty_x_block = -1; - - // We always need to add dirty area into |output| in the last block, so handle - // it separatedly. - for (int x = 0; x < block_count; x++) { - if (BlockDifference(old_buffer, new_buffer, height, stride)) { - if (first_dirty_x_block == -1) { - // This is the first dirty block in a continuous dirty area. - first_dirty_x_block = x; - } - } else if (first_dirty_x_block != -1) { - // The block on the left is the last dirty block in a continuous - // dirty area. - output->AddRect(DesktopRect::MakeLTRB( - first_dirty_x_block * kBlockSize + left, top, - x * kBlockSize + left, bottom)); - first_dirty_x_block = -1; - } - old_buffer += block_x_offset; - new_buffer += block_x_offset; - } - - bool last_block_diff; - if (last_block_width < kBlockSize) { - // The last one is a partial vector. - last_block_diff = PartialBlockDifference( - old_buffer, new_buffer, last_block_width, height, stride); - } else { - last_block_diff = - BlockDifference(old_buffer, new_buffer, height, stride); - } - if (last_block_diff) { - if (first_dirty_x_block == -1) { - first_dirty_x_block = block_count; - } - output->AddRect( - DesktopRect::MakeLTRB(first_dirty_x_block * kBlockSize + left, - top, right, bottom)); - } else if (first_dirty_x_block != -1) { - output->AddRect(DesktopRect::MakeLTRB( - first_dirty_x_block * kBlockSize + left, top, - block_count * kBlockSize + left, bottom)); - } -} - -// Compares |rect| area in |old_frame| and |new_frame|, and outputs dirty -// regions into |output|. -void CompareFrames(const DesktopFrame& old_frame, - const DesktopFrame& new_frame, - DesktopRect rect, - DesktopRegion* const output) { - RTC_DCHECK(old_frame.size().equals(new_frame.size())); - RTC_DCHECK_EQ(old_frame.stride(), new_frame.stride()); - rect.IntersectWith(DesktopRect::MakeSize(old_frame.size())); - - const int y_block_count = (rect.height() - 1) / kBlockSize; - const int last_y_block_height = rect.height() - y_block_count * kBlockSize; - // Offset from the start of one block-row to the next. - const int block_y_stride = old_frame.stride() * kBlockSize; - const uint8_t* prev_block_row_start = - old_frame.GetFrameDataAtPos(rect.top_left()); - const uint8_t* curr_block_row_start = - new_frame.GetFrameDataAtPos(rect.top_left()); - - int top = rect.top(); - // The last row may have a different height, so we handle it separately. - for (int y = 0; y < y_block_count; y++) { - CompareRow(prev_block_row_start, curr_block_row_start, rect.left(), - rect.right(), top, top + kBlockSize, - old_frame.stride(), output); - top += kBlockSize; - prev_block_row_start += block_y_stride; - curr_block_row_start += block_y_stride; - } - CompareRow(prev_block_row_start, curr_block_row_start, rect.left(), - rect.right(), top, top + last_y_block_height, - old_frame.stride(), output); -} - -} // namespace - -ScreenCapturerDifferWrapper::ScreenCapturerDifferWrapper( - std::unique_ptr base_capturer) - : base_capturer_(std::move(base_capturer)) { - RTC_DCHECK(base_capturer_); -} - -ScreenCapturerDifferWrapper::~ScreenCapturerDifferWrapper() {} - -void ScreenCapturerDifferWrapper::Start(DesktopCapturer::Callback* callback) { - callback_ = callback; - base_capturer_->Start(this); -} - -void ScreenCapturerDifferWrapper::SetSharedMemoryFactory( - std::unique_ptr shared_memory_factory) { - base_capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory)); -} - -void ScreenCapturerDifferWrapper::CaptureFrame() { - base_capturer_->CaptureFrame(); -} - -bool ScreenCapturerDifferWrapper::GetScreenList(ScreenList* screens) { - return base_capturer_->GetScreenList(screens); -} - -bool ScreenCapturerDifferWrapper::SelectScreen(ScreenId id) { - return base_capturer_->SelectScreen(id); -} - -void ScreenCapturerDifferWrapper::OnCaptureResult( - Result result, - std::unique_ptr input_frame) { - int64_t start_time_nanos = rtc::TimeNanos(); - if (!input_frame) { - callback_->OnCaptureResult(result, nullptr); - return; - } - RTC_DCHECK(result == Result::SUCCESS); - - std::unique_ptr frame = - SharedDesktopFrame::Wrap(std::move(input_frame)); - if (last_frame_ && - (last_frame_->size().width() != frame->size().width() || - last_frame_->size().height() != frame->size().height() || - last_frame_->stride() != frame->stride())) { - last_frame_.reset(); - } - - if (last_frame_) { - DesktopRegion hints; - hints.Swap(frame->GetUnderlyingFrame()->mutable_updated_region()); - for (DesktopRegion::Iterator it(hints); !it.IsAtEnd(); it.Advance()) { - CompareFrames(*last_frame_, *frame, it.rect(), - frame->mutable_updated_region()); - } - } else { - frame->mutable_updated_region()->SetRect( - DesktopRect::MakeSize(frame->size())); - } - last_frame_ = frame->Share(); - - frame->set_capture_time_ms(frame->GetUnderlyingFrame()->capture_time_ms() + - (rtc::TimeNanos() - start_time_nanos) / - rtc::kNumNanosecsPerMillisec); - callback_->OnCaptureResult(result, std::move(frame)); -} - -} // namespace webrtc diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h deleted file mode 100644 index 9b430a9212..0000000000 --- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_DIFFER_WRAPPER_H_ -#define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_DIFFER_WRAPPER_H_ - -#include - -#include "webrtc/modules/desktop_capture/screen_capturer.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" - -namespace webrtc { - -// TODO(zijiehe): Remove, use DesktopCapturerDifferWrapper. -// ScreenCapturer wrapper that calculates updated_region() by comparing frames -// content. This class always expects the underlying ScreenCapturer -// implementation returns a superset of updated regions in DestkopFrame. If a -// ScreenCapturer implementation does not know the updated region, it should -// set updated_region() to full frame. -// -// This class marks entire frame as updated if the frame size or frame stride -// has been changed. -class ScreenCapturerDifferWrapper : public ScreenCapturer, - public DesktopCapturer::Callback { - public: - // Creates a ScreenCapturerDifferWrapper with a ScreenCapturer implementation, - // and takes its ownership. - explicit ScreenCapturerDifferWrapper( - std::unique_ptr base_capturer); - ~ScreenCapturerDifferWrapper() override; - - // ScreenCapturer interface. - void Start(DesktopCapturer::Callback* callback) override; - void SetSharedMemoryFactory( - std::unique_ptr shared_memory_factory) override; - void CaptureFrame() override; - bool GetScreenList(ScreenList* screens) override; - bool SelectScreen(ScreenId id) override; - - private: - // DesktopCapturer::Callback interface. - void OnCaptureResult(Result result, - std::unique_ptr frame) override; - - const std::unique_ptr base_capturer_; - DesktopCapturer::Callback* callback_; - std::unique_ptr last_frame_; -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_DIFFER_WRAPPER_H_ diff --git a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc b/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc deleted file mode 100644 index ae7b7d9a85..0000000000 --- a/webrtc/modules/desktop_capture/screen_capturer_differ_wrapper_unittest.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* - * 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_differ_wrapper.h" - -#include -#include -#include -#include - -#include "webrtc/base/random.h" -#include "webrtc/base/timeutils.h" -#include "webrtc/modules/desktop_capture/desktop_geometry.h" -#include "webrtc/modules/desktop_capture/desktop_region.h" -#include "webrtc/modules/desktop_capture/differ_block.h" -#include "webrtc/modules/desktop_capture/fake_screen_capturer.h" -#include "webrtc/modules/desktop_capture/screen_capturer_mock_objects.h" -#include "webrtc/system_wrappers/include/cpu_features_wrapper.h" -#include "webrtc/test/gtest.h" -#include "webrtc/typedefs.h" - -namespace webrtc { - -namespace { - -// Compares and asserts |frame|.updated_region() equals to |rects|. This -// function does not care about the order of the |rects| and it does not expect -// DesktopRegion to return an exact area for each rectangle in |rects|. -template