Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capture_frame_queue.h

Issue 1902323002: Modify ScreenCaptureFrameQueue into a template (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix build break in Chromium Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/shared_desktop_frame.h" 16 #include "webrtc/base/constructormagic.h"
17 #include "webrtc/typedefs.h" 17 // TODO(zijiehe): These headers are not used in this file, but to avoid build
18 // break in remoting/host. We should add headers in each individual files.
19 #include "webrtc/modules/desktop_capture/desktop_frame.h" // Remove
20 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" // Remove
18 21
19 namespace webrtc {
20 class DesktopFrame;
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 template <typename FrameType>
38 class ScreenCaptureFrameQueue { 39 class ScreenCaptureFrameQueue {
39 public: 40 public:
40 ScreenCaptureFrameQueue(); 41 ScreenCaptureFrameQueue() : current_(0) {}
41 ~ScreenCaptureFrameQueue(); 42 ~ScreenCaptureFrameQueue() = default;
42 43
43 // Moves to the next frame in the queue, moving the 'current' frame to become 44 // Moves to the next frame in the queue, moving the 'current' frame to become
44 // the 'previous' one. 45 // the 'previous' one.
45 void MoveToNextFrame(); 46 void MoveToNextFrame() {
47 current_ = (current_ + 1) % kQueueLength;
48 }
46 49
47 // Replaces the current frame with a new one allocated by the caller. The 50 // Replaces the current frame with a new one allocated by the caller. The
48 // existing frame (if any) is destroyed. Takes ownership of |frame|. 51 // existing frame (if any) is destroyed. Takes ownership of |frame|.
49 void ReplaceCurrentFrame(DesktopFrame* frame); 52 void ReplaceCurrentFrame(FrameType* frame) {
53 frames_[current_].reset(frame);
54 }
50 55
51 // Marks all frames obsolete and resets the previous frame pointer. No 56 // Marks all frames obsolete and resets the previous frame pointer. No
52 // frames are freed though as the caller can still access them. 57 // frames are freed though as the caller can still access them.
53 void Reset(); 58 void Reset() {
59 for (int i = 0; i < kQueueLength; i++) {
60 frames_[i].reset();
61 }
62 current_ = 0;
63 }
54 64
55 SharedDesktopFrame* current_frame() const { 65 FrameType* current_frame() const {
56 return frames_[current_].get(); 66 return frames_[current_].get();
57 } 67 }
58 68
59 SharedDesktopFrame* previous_frame() const { 69 FrameType* previous_frame() const {
60 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); 70 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get();
61 } 71 }
62 72
63 private: 73 private:
64 // Index of the current frame. 74 // Index of the current frame.
65 int current_; 75 int current_;
66 76
67 static const int kQueueLength = 2; 77 static const int kQueueLength = 2;
68 std::unique_ptr<SharedDesktopFrame> frames_[kQueueLength]; 78 std::unique_ptr<FrameType> frames_[kQueueLength];
69 79
70 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); 80 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue);
71 }; 81 };
72 82
73 } // namespace webrtc 83 } // namespace webrtc
74 84
75 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_ 85 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURE_FRAME_QUEUE_H_
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/desktop_capture.gypi ('k') | webrtc/modules/desktop_capture/screen_capture_frame_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698