OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2013 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_FRAME_QUEUE_H_ | |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_ | |
13 | |
14 #include <memory> | |
15 | |
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 | |
22 | |
23 namespace webrtc { | |
24 | |
25 // Represents a queue of reusable video frames. Provides access to the 'current' | |
26 // frame - the frame that the caller is working with at the moment, and to the | |
27 // 'previous' frame - the predecessor of the current frame swapped by | |
28 // MoveToNextFrame() call, if any. | |
29 // | |
30 // The caller is expected to (re)allocate frames if current_frame() returns | |
31 // NULL. The caller can mark all frames in the queue for reallocation (when, | |
32 // say, frame dimensions change). The queue records which frames need updating | |
33 // which the caller can query. | |
34 // | |
35 // Frame consumer is expected to never hold more than kQueueLength frames | |
36 // created by this function and it should release the earliest one before trying | |
37 // to capture a new frame (i.e. before MoveToNextFrame() is called). | |
38 class ScreenCaptureFrameQueue { | |
39 public: | |
40 ScreenCaptureFrameQueue(); | |
41 ~ScreenCaptureFrameQueue(); | |
42 | |
43 // Moves to the next frame in the queue, moving the 'current' frame to become | |
44 // the 'previous' one. | |
45 void MoveToNextFrame(); | |
46 | |
47 // Replaces the current frame with a new one allocated by the caller. The | |
48 // existing frame (if any) is destroyed. Takes ownership of |frame|. | |
49 void ReplaceCurrentFrame(DesktopFrame* frame); | |
50 | |
51 // Marks all frames obsolete and resets the previous frame pointer. No | |
52 // frames are freed though as the caller can still access them. | |
53 void Reset(); | |
54 | |
55 SharedDesktopFrame* current_frame() const { | |
56 return frames_[current_].get(); | |
57 } | |
58 | |
59 SharedDesktopFrame* previous_frame() const { | |
60 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); | |
61 } | |
62 | |
63 private: | |
64 // Index of the current frame. | |
65 int current_; | |
66 | |
67 static const int kQueueLength = 2; | |
68 std::unique_ptr<SharedDesktopFrame> frames_[kQueueLength]; | |
69 | |
70 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); | |
71 }; | |
72 | |
73 } // namespace webrtc | |
74 | |
75 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_ | |
OLD | NEW |