From 1bcb8f05ad9da00ed6ea579381c8197be3188f32 Mon Sep 17 00:00:00 2001 From: torbjorng Date: Thu, 21 Apr 2016 14:18:19 -0700 Subject: [PATCH] Revert of Modify ScreenCaptureFrameQueue into a template (patchset #10 id:170001 of https://codereview.webrtc.org/1902323002/ ) Reason for revert: Breaks FYI bits, e.g. this one: https://build.chromium.org/p/chromium.webrtc.fyi/builders/Win%20Builder/builds/4430 Original issue's description: > Modify ScreenCaptureFrameQueue into a template > > BUG= > > Committed: https://crrev.com/34cad48cfbd362ae0c9027365550bfe28e2e10ef > Cr-Commit-Position: refs/heads/master@{#12458} TBR=sergeyu@chromium.org,zijiehe@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG= Review URL: https://codereview.webrtc.org/1910203002 Cr-Commit-Position: refs/heads/master@{#12459} --- webrtc/modules/desktop_capture/BUILD.gn | 1 + .../desktop_capture/desktop_capture.gypi | 1 + .../screen_capture_frame_queue.cc | 44 +++++++++++++++++++ .../screen_capture_frame_queue.h | 33 ++++++-------- .../desktop_capture/screen_capturer_mac.mm | 7 +-- .../desktop_capture/screen_capturer_x11.cc | 6 +-- .../desktop_capture/shared_desktop_frame.cc | 3 +- .../win/screen_capturer_win_gdi.cc | 6 +-- .../win/screen_capturer_win_gdi.h | 3 +- .../win/screen_capturer_win_magnifier.cc | 2 +- .../win/screen_capturer_win_magnifier.h | 3 +- 11 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 webrtc/modules/desktop_capture/screen_capture_frame_queue.cc diff --git a/webrtc/modules/desktop_capture/BUILD.gn b/webrtc/modules/desktop_capture/BUILD.gn index 894d9308e3..9451d8be9f 100644 --- a/webrtc/modules/desktop_capture/BUILD.gn +++ b/webrtc/modules/desktop_capture/BUILD.gn @@ -60,6 +60,7 @@ source_set("desktop_capture") { "mouse_cursor_monitor.h", "mouse_cursor_monitor_mac.mm", "mouse_cursor_monitor_win.cc", + "screen_capture_frame_queue.cc", "screen_capture_frame_queue.h", "screen_capturer.h", "screen_capturer_helper.cc", diff --git a/webrtc/modules/desktop_capture/desktop_capture.gypi b/webrtc/modules/desktop_capture/desktop_capture.gypi index c4fbabf6b2..d11cf7680e 100644 --- a/webrtc/modules/desktop_capture/desktop_capture.gypi +++ b/webrtc/modules/desktop_capture/desktop_capture.gypi @@ -56,6 +56,7 @@ "mouse_cursor_monitor_mac.mm", "mouse_cursor_monitor_win.cc", "mouse_cursor_monitor_x11.cc", + "screen_capture_frame_queue.cc", "screen_capture_frame_queue.h", "screen_capturer.h", "screen_capturer_helper.cc", diff --git a/webrtc/modules/desktop_capture/screen_capture_frame_queue.cc b/webrtc/modules/desktop_capture/screen_capture_frame_queue.cc new file mode 100644 index 0000000000..94d8a27b13 --- /dev/null +++ b/webrtc/modules/desktop_capture/screen_capture_frame_queue.cc @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" + +#include +#include + +#include "webrtc/modules/desktop_capture/desktop_frame.h" +#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" +#include "webrtc/system_wrappers/include/logging.h" +#include "webrtc/typedefs.h" + +namespace webrtc { + +ScreenCaptureFrameQueue::ScreenCaptureFrameQueue() : current_(0) {} + +ScreenCaptureFrameQueue::~ScreenCaptureFrameQueue() {} + +void ScreenCaptureFrameQueue::MoveToNextFrame() { + current_ = (current_ + 1) % kQueueLength; + + // Verify that the frame is not shared, i.e. that consumer has released it + // before attempting to capture again. + assert(!frames_[current_].get() || !frames_[current_]->IsShared()); +} + +void ScreenCaptureFrameQueue::ReplaceCurrentFrame(DesktopFrame* frame) { + frames_[current_].reset(SharedDesktopFrame::Wrap(frame)); +} + +void ScreenCaptureFrameQueue::Reset() { + for (int i = 0; i < kQueueLength; ++i) + frames_[i].reset(); +} + +} // namespace webrtc diff --git a/webrtc/modules/desktop_capture/screen_capture_frame_queue.h b/webrtc/modules/desktop_capture/screen_capture_frame_queue.h index c9bd631b59..21af0f320f 100644 --- a/webrtc/modules/desktop_capture/screen_capture_frame_queue.h +++ b/webrtc/modules/desktop_capture/screen_capture_frame_queue.h @@ -13,7 +13,12 @@ #include -#include "webrtc/base/constructormagic.h" +#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" +#include "webrtc/typedefs.h" + +namespace webrtc { +class DesktopFrame; +} // namespace webrtc namespace webrtc { @@ -30,38 +35,28 @@ namespace webrtc { // Frame consumer is expected to never hold more than kQueueLength frames // created by this function and it should release the earliest one before trying // to capture a new frame (i.e. before MoveToNextFrame() is called). -template class ScreenCaptureFrameQueue { public: - ScreenCaptureFrameQueue() : current_(0) {} - ~ScreenCaptureFrameQueue() = default; + ScreenCaptureFrameQueue(); + ~ScreenCaptureFrameQueue(); // Moves to the next frame in the queue, moving the 'current' frame to become // the 'previous' one. - void MoveToNextFrame() { - current_ = (current_ + 1) % kQueueLength; - } + void MoveToNextFrame(); // Replaces the current frame with a new one allocated by the caller. The // existing frame (if any) is destroyed. Takes ownership of |frame|. - void ReplaceCurrentFrame(FrameType* frame) { - frames_[current_].reset(frame); - } + void ReplaceCurrentFrame(DesktopFrame* frame); // Marks all frames obsolete and resets the previous frame pointer. No // frames are freed though as the caller can still access them. - void Reset() { - for (int i = 0; i < kQueueLength; i++) { - frames_[i].reset(); - } - current_ = 0; - } + void Reset(); - FrameType* current_frame() const { + SharedDesktopFrame* current_frame() const { return frames_[current_].get(); } - FrameType* previous_frame() const { + SharedDesktopFrame* previous_frame() const { return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); } @@ -70,7 +65,7 @@ class ScreenCaptureFrameQueue { int current_; static const int kQueueLength = 2; - std::unique_ptr frames_[kQueueLength]; + std::unique_ptr frames_[kQueueLength]; RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); }; diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm index 76de59ef10..c41dc4d7a3 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm @@ -22,7 +22,6 @@ #include #include -#include "webrtc/base/checks.h" #include "webrtc/base/macutils.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" @@ -33,7 +32,6 @@ #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/tick_util.h" @@ -236,7 +234,7 @@ class ScreenCapturerMac : public ScreenCapturer { ScopedPixelBufferObject pixel_buffer_object_; // Queue of the frames buffers. - ScreenCaptureFrameQueue queue_; + ScreenCaptureFrameQueue queue_; // Current display configuration. MacDesktopConfiguration desktop_config_; @@ -386,7 +384,6 @@ void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { TickTime capture_start_time = TickTime::Now(); queue_.MoveToNextFrame(); - RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); desktop_config_monitor_->Lock(); MacDesktopConfiguration new_config = @@ -408,7 +405,7 @@ void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { // Note that we can't reallocate other buffers at this point, since the caller // may still be reading from them. if (!queue_.current_frame()) - queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); + queue_.ReplaceCurrentFrame(CreateFrame()); DesktopFrame* current_frame = queue_.current_frame(); diff --git a/webrtc/modules/desktop_capture/screen_capturer_x11.cc b/webrtc/modules/desktop_capture/screen_capturer_x11.cc index 4848235e3f..65e682b6f8 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_x11.cc +++ b/webrtc/modules/desktop_capture/screen_capturer_x11.cc @@ -26,7 +26,6 @@ #include "webrtc/modules/desktop_capture/differ.h" #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" #include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/tick_util.h" @@ -107,7 +106,7 @@ class ScreenCapturerLinux : public ScreenCapturer, ScreenCapturerHelper helper_; // Queue of the frames buffers. - ScreenCaptureFrameQueue queue_; + ScreenCaptureFrameQueue queue_; // Invalid region from the previous capture. This is used to synchronize the // current with the last buffer used. @@ -238,7 +237,6 @@ void ScreenCapturerLinux::Capture(const DesktopRegion& region) { TickTime capture_start_time = TickTime::Now(); queue_.MoveToNextFrame(); - RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); // Process XEvents for XDamage and cursor shape tracking. options_.x_display()->ProcessPendingXEvents(); @@ -258,7 +256,7 @@ void ScreenCapturerLinux::Capture(const DesktopRegion& region) { if (!queue_.current_frame()) { std::unique_ptr frame( new BasicDesktopFrame(x_server_pixel_buffer_.window_size())); - queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(frame.release())); + queue_.ReplaceCurrentFrame(frame.release()); } // Refresh the Differ helper used by CaptureFrame(), if needed. diff --git a/webrtc/modules/desktop_capture/shared_desktop_frame.cc b/webrtc/modules/desktop_capture/shared_desktop_frame.cc index 13d66c53d7..309bac55ad 100644 --- a/webrtc/modules/desktop_capture/shared_desktop_frame.cc +++ b/webrtc/modules/desktop_capture/shared_desktop_frame.cc @@ -48,7 +48,8 @@ class SharedDesktopFrame::Core { SharedDesktopFrame::~SharedDesktopFrame() {} // static -SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) { +SharedDesktopFrame* SharedDesktopFrame::Wrap( + DesktopFrame* desktop_frame) { rtc::scoped_refptr core(new Core(desktop_frame)); return new SharedDesktopFrame(core); } diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc index 022e1ce9e6..31c79cdda3 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc @@ -14,7 +14,6 @@ #include -#include "webrtc/base/checks.h" #include "webrtc/modules/desktop_capture/desktop_capture_options.h" #include "webrtc/modules/desktop_capture/desktop_frame.h" #include "webrtc/modules/desktop_capture/desktop_frame_win.h" @@ -83,7 +82,6 @@ void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { TickTime capture_start_time = TickTime::Now(); queue_.MoveToNextFrame(); - RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); // Request that the system not power-down the system, or the display hardware. if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { @@ -249,9 +247,9 @@ bool ScreenCapturerWinGdi::CaptureImage() { std::unique_ptr buffer(DesktopFrameWin::Create( size, shared_memory_factory_.get(), desktop_dc_)); - if (!buffer) + if (!buffer.get()) return false; - queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(buffer.release())); + queue_.ReplaceCurrentFrame(buffer.release()); } // Select the target bitmap into the memory dc and copy the rect from desktop diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h index 261a018d5f..17cb0aa194 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h @@ -20,7 +20,6 @@ #include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/modules/desktop_capture/win/scoped_thread_desktop.h" namespace webrtc { @@ -72,7 +71,7 @@ class ScreenCapturerWinGdi : public ScreenCapturer { HDC memory_dc_; // Queue of the frames buffers. - ScreenCaptureFrameQueue queue_; + ScreenCaptureFrameQueue queue_; // Rectangle describing the bounds of the desktop device context, relative to // the primary display's top-left. diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc index 4bcd4d1918..8af9779ce8 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc @@ -433,7 +433,7 @@ void ScreenCapturerWinMagnifier::CreateCurrentFrameIfNecessary( ? SharedMemoryDesktopFrame::Create(size, shared_memory_factory_.get()) : std::unique_ptr(new BasicDesktopFrame(size)); - queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(frame.release())); + queue_.ReplaceCurrentFrame(frame.release()); } } diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h index ad3ddb18fd..d5e3946d62 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h @@ -22,7 +22,6 @@ #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" #include "webrtc/modules/desktop_capture/screen_capturer.h" #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" -#include "webrtc/modules/desktop_capture/shared_desktop_frame.h" #include "webrtc/modules/desktop_capture/win/scoped_thread_desktop.h" #include "webrtc/system_wrappers/include/atomic32.h" @@ -119,7 +118,7 @@ class ScreenCapturerWinMagnifier : public ScreenCapturer { ScreenCapturerHelper helper_; // Queue of the frames buffers. - ScreenCaptureFrameQueue queue_; + ScreenCaptureFrameQueue queue_; // Class to calculate the difference between two screen bitmaps. std::unique_ptr differ_;