| 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/modules/desktop_capture/screen_capture_content_queue.h" |
| 16 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 17 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
| 17 #include "webrtc/typedefs.h" | |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 class DesktopFrame; | 20 class DesktopFrame; |
| 21 } // namespace webrtc | 21 } // namespace webrtc |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 | 24 |
| 25 // 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' |
| 26 // 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 |
| 27 // 'previous' frame - the predecessor of the current frame swapped by | 27 // 'previous' frame - the predecessor of the current frame swapped by |
| 28 // MoveToNextFrame() call, if any. | 28 // MoveToNextFrame() call, if any. |
| 29 // | 29 // |
| 30 // 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 |
| 31 // 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, |
| 32 // say, frame dimensions change). The queue records which frames need updating | 32 // say, frame dimensions change). The queue records which frames need updating |
| 33 // which the caller can query. | 33 // which the caller can query. |
| 34 // | 34 // |
| 35 // Frame consumer is expected to never hold more than kQueueLength frames | 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 | 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). | 37 // to capture a new frame (i.e. before MoveToNextFrame() is called). |
| 38 class ScreenCaptureFrameQueue { | 38 // |
| 39 // Users do not expect to call functions from |
| 40 // ScreenCaptureContentQueue<SharedDesktopFrame>, since extra assertions or |
| 41 // wrappers are applied. |
| 42 class ScreenCaptureFrameQueue : ScreenCaptureContentQueue<SharedDesktopFrame> { |
| 39 public: | 43 public: |
| 40 ScreenCaptureFrameQueue(); | 44 ScreenCaptureFrameQueue() = default; |
| 41 ~ScreenCaptureFrameQueue(); | 45 virtual ~ScreenCaptureFrameQueue() = default; |
| 46 |
| 47 using ScreenCaptureContentQueue<SharedDesktopFrame>::Reset; |
| 42 | 48 |
| 43 // Moves to the next frame in the queue, moving the 'current' frame to become | 49 // Moves to the next frame in the queue, moving the 'current' frame to become |
| 44 // the 'previous' one. | 50 // the 'previous' one. |
| 45 void MoveToNextFrame(); | 51 void MoveToNextFrame(); |
| 46 | 52 |
| 47 // Replaces the current frame with a new one allocated by the caller. The | 53 // Replaces the current frame with a new one allocated by the caller. The |
| 48 // existing frame (if any) is destroyed. Takes ownership of |frame|. | 54 // existing frame (if any) is destroyed. Takes ownership of |frame|. |
| 49 void ReplaceCurrentFrame(DesktopFrame* frame); | 55 void ReplaceCurrentFrame(DesktopFrame* frame); |
| 50 | 56 |
| 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 { | 57 SharedDesktopFrame* current_frame() const { |
| 56 return frames_[current_].get(); | 58 return current(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 SharedDesktopFrame* previous_frame() const { | 61 SharedDesktopFrame* previous_frame() const { |
| 60 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); | 62 return previous(); |
| 61 } | 63 } |
| 62 | 64 |
| 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); | 65 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); |
| 71 }; | 66 }; |
| 72 | 67 |
| 73 } // namespace webrtc | 68 } // namespace webrtc |
| 74 | 69 |
| 75 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_ | 70 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_ |
| OLD | NEW |