Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_CONTENT_QUEUE_H_ | |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_CONTENT_QUEUE_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/base/constructormagic.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 // Represents a queue of reusable video content. Provides access to the | |
| 21 // 'current' frame - the frame that the caller is working with at the moment, | |
| 22 // and to the 'previous' frame - the predecessor of the current frame swapped by | |
| 23 // MoveToNextFrame() call, if any. | |
| 24 // | |
| 25 // This is the base class of ScreenCaptureFrameQueue and | |
| 26 // win/ScreenCaptureSurfaceQueue. | |
| 27 // | |
| 28 // The caller is expected to (re)allocate content if current() returns nullptr. | |
| 29 // The caller can mark all frames in the queue for reallocation (when, say, | |
| 30 // frame dimensions change). The queue records which content need updating | |
| 31 // which the caller can query. | |
| 32 // | |
| 33 // Content consumer is expected to never hold more than kQueueLength instances | |
| 34 // created by this function and it should release the earliest one before trying | |
| 35 // to capture a new frame (i.e. before MoveToNext() is called). | |
| 36 // | |
| 37 // This class is not thread-safe. | |
| 38 template <typename T> | |
| 39 class ScreenCaptureContentQueue { | |
| 40 public: | |
| 41 ScreenCaptureContentQueue() : current_(0) {} | |
| 42 virtual ~ScreenCaptureContentQueue() = default; | |
| 43 | |
| 44 // Marks all instances obsolete and resets the previous instance pointer. | |
| 45 void Reset() { | |
| 46 for (int i = 0; i < kQueueLength; i++) { | |
| 47 frames_[i].reset(); | |
| 48 } | |
| 49 current_ = 0; | |
| 50 } | |
| 51 | |
| 52 // Moves to the next instance in the queue, moving the 'current' instance to | |
| 53 // become the 'previous' one. | |
| 54 void MoveToNext() { | |
| 55 current_ = (current_ + 1) % kQueueLength; | |
| 56 } | |
| 57 | |
| 58 // Replaces the current instance with a new one allocated by the caller. The | |
| 59 // existing instance (if any) is destroyed. Takes ownership of |instance|. | |
| 60 void ReplaceCurrent(T* instance) { | |
|
Sergey Ulanov
2016/04/19 23:51:07
use unique_ptr<> to pass ownership of the paramete
| |
| 61 frames_[current_].reset(instance); | |
| 62 } | |
| 63 | |
| 64 T* current() const { | |
| 65 return frames_[current_].get(); | |
| 66 } | |
| 67 | |
| 68 T* previous() const { | |
| 69 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 // Index of the current frame. | |
| 74 int current_; | |
| 75 | |
| 76 static const int kQueueLength = 2; | |
| 77 std::unique_ptr<T> frames_[kQueueLength]; | |
| 78 | |
| 79 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureContentQueue); | |
| 80 }; | |
| 81 | |
| 82 } // namespace webrtc | |
| 83 | |
| 84 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_CONTENT_QUEUE_H_ | |
| OLD | NEW |