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_QUEUE_H_ | |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_QUEUE_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/base/constructormagic.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 // 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.
| |
| 21 // instance - the instance that the caller is working with at the moment, and to | |
| 22 // the 'previous' instance - the predecessor of the current instance swapped by | |
| 23 // MoveToNext() call, if any. | |
| 24 // | |
| 25 // The caller is expected to (re)allocate content if current() returns nullptr. | |
| 26 // The caller can mark all frames in the queue for reallocation (when, say, | |
| 27 // frame dimensions change). The queue records which instance need updating | |
| 28 // which the caller can query. | |
| 29 // | |
| 30 // Content consumer is expected to never hold more than kQueueLength instances | |
| 31 // created by this function and it should release the earliest one before trying | |
| 32 // to capture a new frame (i.e. before MoveToNext() is called). | |
| 33 // | |
| 34 // This class is not thread-safe. | |
| 35 template <typename T> | |
|
Sergey Ulanov
2016/04/20 21:22:34
s/T/FrameType/
Hzj_jie
2016/04/21 18:44:54
Done.
| |
| 36 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.
| |
| 37 public: | |
| 38 ScreenCaptureQueue() : current_(0) {} | |
| 39 virtual ~ScreenCaptureQueue() = default; | |
| 40 | |
| 41 // Marks all instances obsolete and resets the previous instance pointer. | |
| 42 void Reset() { | |
| 43 for (int i = 0; i < kQueueLength; i++) { | |
| 44 frames_[i].reset(); | |
| 45 } | |
| 46 current_ = 0; | |
| 47 } | |
| 48 | |
| 49 // Moves to the next instance in the queue, moving the 'current' instance to | |
| 50 // become the 'previous' one. | |
| 51 void MoveToNext() { | |
| 52 current_ = (current_ + 1) % kQueueLength; | |
| 53 } | |
| 54 | |
| 55 // Replaces the current instance with a new one allocated by the caller. The | |
| 56 // existing instance (if any) is destroyed. Takes ownership of |instance|. | |
| 57 void ReplaceCurrent(std::unique_ptr<T>&& instance) { | |
| 58 frames_[current_].reset(instance.release()); | |
| 59 } | |
| 60 | |
| 61 T* current() const { | |
| 62 return frames_[current_].get(); | |
| 63 } | |
| 64 | |
| 65 T* previous() const { | |
| 66 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 // Index of the current frame. | |
| 71 int current_; | |
| 72 | |
| 73 static const int kQueueLength = 2; | |
| 74 std::unique_ptr<T> frames_[kQueueLength]; | |
| 75 | |
| 76 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureQueue); | |
| 77 }; | |
| 78 | |
| 79 } // namespace webrtc | |
| 80 | |
| 81 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_QUEUE_H_ | |
| OLD | NEW |