Chromium Code Reviews

Unified Diff: webrtc/modules/desktop_capture/screen_capture_content_queue.h

Issue 1845113002: DirectX based screen capturer logic (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Several lint formatting Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: webrtc/modules/desktop_capture/screen_capture_content_queue.h
diff --git a/webrtc/modules/desktop_capture/screen_capture_content_queue.h b/webrtc/modules/desktop_capture/screen_capture_content_queue.h
new file mode 100644
index 0000000000000000000000000000000000000000..5eae9ef28726b706d4997d9ee21cc69712e2b6ae
--- /dev/null
+++ b/webrtc/modules/desktop_capture/screen_capture_content_queue.h
@@ -0,0 +1,84 @@
+/*
+ * 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_CAPTURE_CONTENT_QUEUE_H_
+#define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_CONTENT_QUEUE_H_
+
+#include <memory>
+
+#include "webrtc/base/constructormagic.h"
+
+namespace webrtc {
+
+// Represents a queue of reusable video content. Provides access to the
+// 'current' frame - the frame that the caller is working with at the moment,
+// and to the 'previous' frame - the predecessor of the current frame swapped by
+// MoveToNextFrame() call, if any.
+//
+// This is the base class of ScreenCaptureFrameQueue and
+// win/ScreenCaptureSurfaceQueue.
+//
+// The caller is expected to (re)allocate content if current() returns nullptr.
+// The caller can mark all frames in the queue for reallocation (when, say,
+// frame dimensions change). The queue records which content need updating
+// which the caller can query.
+//
+// Content consumer is expected to never hold more than kQueueLength instances
+// created by this function and it should release the earliest one before trying
+// to capture a new frame (i.e. before MoveToNext() is called).
+//
+// This class is not thread-safe.
+template <typename T>
+class ScreenCaptureContentQueue {
+ public:
+ ScreenCaptureContentQueue() : current_(0) {}
+ virtual ~ScreenCaptureContentQueue() = default;
+
+ // Marks all instances obsolete and resets the previous instance pointer.
+ void Reset() {
+ for (int i = 0; i < kQueueLength; i++) {
+ frames_[i].reset();
+ }
+ current_ = 0;
+ }
+
+ // Moves to the next instance in the queue, moving the 'current' instance to
+ // become the 'previous' one.
+ void MoveToNext() {
+ current_ = (current_ + 1) % kQueueLength;
+ }
+
+ // Replaces the current instance with a new one allocated by the caller. The
+ // existing instance (if any) is destroyed. Takes ownership of |instance|.
+ void ReplaceCurrent(T* instance) {
Sergey Ulanov 2016/04/19 23:51:07 use unique_ptr<> to pass ownership of the paramete
+ frames_[current_].reset(instance);
+ }
+
+ T* current() const {
+ return frames_[current_].get();
+ }
+
+ T* previous() const {
+ return frames_[(current_ + kQueueLength - 1) % kQueueLength].get();
+ }
+
+ private:
+ // Index of the current frame.
+ int current_;
+
+ static const int kQueueLength = 2;
+ std::unique_ptr<T> frames_[kQueueLength];
+
+ RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureContentQueue);
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_CONTENT_QUEUE_H_

Powered by Google App Engine