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}
This commit is contained in:
torbjorng 2016-04-21 14:18:19 -07:00 committed by Commit bot
parent 34cad48cfb
commit 1bcb8f05ad
11 changed files with 71 additions and 38 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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 <assert.h>
#include <algorithm>
#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

View File

@ -13,7 +13,12 @@
#include <memory>
#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 <typename FrameType>
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<FrameType> frames_[kQueueLength];
std::unique_ptr<SharedDesktopFrame> frames_[kQueueLength];
RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue);
};

View File

@ -22,7 +22,6 @@
#include <OpenGL/CGLMacro.h>
#include <OpenGL/OpenGL.h>
#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<SharedDesktopFrame> 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();

View File

@ -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<SharedDesktopFrame> 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<DesktopFrame> 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.

View File

@ -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> core(new Core(desktop_frame));
return new SharedDesktopFrame(core);
}

View File

@ -14,7 +14,6 @@
#include <utility>
#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<DesktopFrame> 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

View File

@ -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<SharedDesktopFrame> queue_;
ScreenCaptureFrameQueue queue_;
// Rectangle describing the bounds of the desktop device context, relative to
// the primary display's top-left.

View File

@ -433,7 +433,7 @@ void ScreenCapturerWinMagnifier::CreateCurrentFrameIfNecessary(
? SharedMemoryDesktopFrame::Create(size,
shared_memory_factory_.get())
: std::unique_ptr<DesktopFrame>(new BasicDesktopFrame(size));
queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(frame.release()));
queue_.ReplaceCurrentFrame(frame.release());
}
}

View File

@ -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<SharedDesktopFrame> queue_;
ScreenCaptureFrameQueue queue_;
// Class to calculate the difference between two screen bitmaps.
std::unique_ptr<Differ> differ_;