OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURE_FRAME_QUEUE_H_ | |
6 #define MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURE_FRAME_QUEUE_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "media/video/capture/screen/shared_desktop_frame.h" | |
11 | |
12 namespace webrtc { | |
13 class DesktopFrame; | |
14 } // namespace webrtc | |
15 | |
16 namespace media { | |
17 | |
18 // Represents a queue of reusable video frames. Provides access to the 'current' | |
19 // frame - the frame that the caller is working with at the moment, and to the | |
20 // 'previous' frame - the predecessor of the current frame swapped by | |
21 // MoveToNextFrame() call, if any. | |
22 // | |
23 // The caller is expected to (re)allocate frames if current_frame() returns | |
24 // NULL. The caller can mark all frames in the queue for reallocation (when, | |
25 // say, frame dimensions change). The queue records which frames need updating | |
26 // which the caller can query. | |
27 // | |
28 // Frame consumer is expected to never hold more than kQueueLength frames | |
29 // created by this function and it should release the earliest one before trying | |
30 // to capture a new frame (i.e. before MoveToNextFrame() is called). | |
31 class ScreenCaptureFrameQueue { | |
32 public: | |
33 ScreenCaptureFrameQueue(); | |
34 ~ScreenCaptureFrameQueue(); | |
35 | |
36 // Moves to the next frame in the queue, moving the 'current' frame to become | |
37 // the 'previous' one. | |
38 void MoveToNextFrame(); | |
39 | |
40 // Replaces the current frame with a new one allocated by the caller. | |
41 // The existing frame (if any) is destroyed. | |
42 void ReplaceCurrentFrame(scoped_ptr<webrtc::DesktopFrame> frame); | |
43 | |
44 // Marks all frames obsolete and resets the previous frame pointer. No | |
45 // frames are freed though as the caller can still access them. | |
46 void Reset(); | |
47 | |
48 SharedDesktopFrame* current_frame() const { | |
49 return frames_[current_].get(); | |
50 } | |
51 | |
52 SharedDesktopFrame* previous_frame() const { | |
53 return frames_[(current_ + kQueueLength - 1) % kQueueLength].get(); | |
54 } | |
55 | |
56 private: | |
57 // Index of the current frame. | |
58 int current_; | |
59 | |
60 static const int kQueueLength = 2; | |
61 scoped_ptr<SharedDesktopFrame> frames_[kQueueLength]; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); | |
64 }; | |
65 | |
66 } // namespace media | |
67 | |
68 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURE_FRAME_QUEUE_H_ | |
OLD | NEW |