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