Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

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

Issue 1902323002: Modify ScreenCaptureFrameQueue into a template (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix build break in linux Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/screen_capture_queue.h
diff --git a/webrtc/modules/desktop_capture/screen_capture_queue.h b/webrtc/modules/desktop_capture/screen_capture_queue.h
new file mode 100644
index 0000000000000000000000000000000000000000..d108ec0574e50e44635d7d32b4dfe10925f193a0
--- /dev/null
+++ b/webrtc/modules/desktop_capture/screen_capture_queue.h
@@ -0,0 +1,81 @@
+/*
+ * 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_QUEUE_H_
+#define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_QUEUE_H_
+
+#include <memory>
+
+#include "webrtc/base/constructormagic.h"
+
+namespace webrtc {
+
+// Represents a queue of reusable resources. Provides access to the 'current'
Sergey Ulanov 2016/04/20 21:22:34 we use it for a queue of frames, so it should be c
Hzj_jie 2016/04/20 23:56:15 Done.
+// instance - the instance that the caller is working with at the moment, and to
+// the 'previous' instance - the predecessor of the current instance swapped by
+// MoveToNext() call, if any.
+//
+// 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 instance 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>
Sergey Ulanov 2016/04/20 21:22:34 s/T/FrameType/
Hzj_jie 2016/04/21 18:44:54 Done.
+class ScreenCaptureQueue {
Sergey Ulanov 2016/04/20 21:22:34 Do we need to rename this class? In the DX capture
Hzj_jie 2016/04/20 23:56:15 I thought this is the main point we need this chan
Sergey Ulanov 2016/04/21 17:16:17 We need this change to allow types other than Desk
Hzj_jie 2016/04/21 18:44:54 Done.
+ public:
+ ScreenCaptureQueue() : current_(0) {}
+ virtual ~ScreenCaptureQueue() = 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(std::unique_ptr<T>&& instance) {
+ frames_[current_].reset(instance.release());
+ }
+
+ 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(ScreenCaptureQueue);
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_QUEUE_H_

Powered by Google App Engine
This is Rietveld 408576698