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

Side by Side Diff: media/video/capture/screen/screen_capture_frame_queue.h

Issue 13983010: Use webrtc::DesktopCapturer for screen capturer implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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 10
11 namespace webrtc {
12 class DesktopFrame;
13 } // namespace webrtc
14
11 namespace media { 15 namespace media {
12 16
13 class ScreenCaptureFrame;
14
15 // Represents a queue of reusable video frames. Provides access to the 'current' 17 // 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 18 // 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 19 // 'previous' frame - the predecessor of the current frame swapped by
18 // DoneWithCurrentFrame() call, if any. 20 // MoveToNext() call, if any. Caller should use EmitCurrentFrame() to emit the
alexeypa (please no reviews) 2013/05/08 22:24:59 nit: MoveToNext() -> MoveToNextFrame()
Sergey Ulanov 2013/05/09 18:49:02 Done.
21 // current frame to the consumer.
19 // 22 //
20 // The caller is expected to (re)allocate frames if current_frame_needs_update() 23 // 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, 24 // 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 25 // say, frame dimensions change). The queue records which frames need updating
alexeypa (please no reviews) 2013/05/08 22:24:59 nit: "dimensions change" -> "dimensions change"
Sergey Ulanov 2013/05/09 18:49:02 Done.
23 // which the caller can query. 26 // which the caller can query.
27 //
28 // Frame consumer is expected to never holds 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).
24 class ScreenCaptureFrameQueue { 31 class ScreenCaptureFrameQueue {
25 public: 32 public:
26 ScreenCaptureFrameQueue(); 33 ScreenCaptureFrameQueue();
27 ~ScreenCaptureFrameQueue(); 34 ~ScreenCaptureFrameQueue();
28 35
29 // Moves to the next frame in the queue, moving the 'current' frame to become 36 // Moves to the next frame in the queue, moving the 'current' frame to become
30 // the 'previous' one. 37 // the 'previous' one.
31 void DoneWithCurrentFrame(); 38 void MoveToNextFrame();
39
40 // Emit the current frame to the consumer. Caller takes ownership of the
41 // result. The returned DesktopFrame object shares ownership of the underlying
42 // buffer with the queue.
43 webrtc::DesktopFrame* EmitCurrentFrame();
32 44
33 // Replaces the current frame with a new one allocated by the caller. 45 // Replaces the current frame with a new one allocated by the caller.
34 // The existing frame (if any) is destroyed. 46 // The existing frame (if any) is destroyed.
35 void ReplaceCurrentFrame(scoped_ptr<ScreenCaptureFrame> frame); 47 void ReplaceCurrentFrame(scoped_ptr<webrtc::DesktopFrame> frame);
36 48
37 // Marks all frames obsolete and resets the previous frame pointer. No 49 // Marks all frames obsolete and resets the previous frame pointer. No
38 // frames are freed though as the caller can still access them. 50 // frames are freed though as the caller can still access them.
39 void SetAllFramesNeedUpdate(); 51 void Reset();
40 52
41 ScreenCaptureFrame* current_frame() const { 53 webrtc::DesktopFrame* current_frame() const {
42 return frames_[current_].get(); 54 return frames_[current_];
43 } 55 }
44 56
45 bool current_frame_needs_update() const { 57 webrtc::DesktopFrame* previous_frame() const {
46 return !current_frame() || needs_update_[current_]; 58 return frames_[(current_ + kQueueLength - 1) % kQueueLength];
47 } 59 }
48 60
49 ScreenCaptureFrame* previous_frame() const { return previous_; } 61 private:
62 class EmittedFrame;
63 friend class EmittedFrame;
50 64
51 private: 65 // Called by EmittedFrame when it's deleted.
66 void ReturnEmittedFrame(webrtc::DesktopFrame* frame, int index);
67
52 // Index of the current frame. 68 // Index of the current frame.
53 int current_; 69 int current_;
54 70
55 static const int kQueueLength = 2; 71 static const int kQueueLength = 2;
56 scoped_ptr<ScreenCaptureFrame> frames_[kQueueLength]; 72 webrtc::DesktopFrame* frames_[kQueueLength];
57 73 EmittedFrame* emitted_frames_[kQueueLength];
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 74
64 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue); 75 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameQueue);
65 }; 76 };
66 77
67 } // namespace media 78 } // namespace media
68 79
69 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURE_FRAME_QUEUE_H_ 80 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURE_FRAME_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698