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