blob: 508443554b7f6afd7d9a63f34a9c711f59d9d0b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_HOST_VIDEO_FRAME_QUEUE_H_
#define REMOTING_HOST_VIDEO_FRAME_QUEUE_H_
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
namespace remoting {
class VideoFrame;
// Represents a queue of reusable video frames. Provides access to the 'current'
// frame - the frame that the caller is working with at the moment, and to
// the 'previous' frame - the predecessor of the current frame swapped by
// DoneWithCurrentFrame() call, if any.
//
// The caller is expected to (re)allocate frames if current_frame_needs_update()
// is set. The caller can mark all frames in the queue for reallocation (when,
// say, frame dimensions change). The queue records which frames need updating
// which the caller can query.
class VideoFrameQueue {
public:
VideoFrameQueue();
~VideoFrameQueue();
// Moves to the next frame in the queue, moving the 'current' frame to become
// the 'previous' one.
void DoneWithCurrentFrame();
// Replaces the current frame with a new one allocated by the caller.
// The existing frame (if any) is destroyed.
void ReplaceCurrentFrame(scoped_ptr<VideoFrame> frame);
// Marks all frames obsolete and resets the previous frame pointer. No
// frames are freed though as the caller can still access them.
void SetAllFramesNeedUpdate();
VideoFrame* current_frame() const {
return frames_[current_].get();
}
bool current_frame_needs_update() const {
return !current_frame() || needs_update_[current_];
}
VideoFrame* previous_frame() const { return previous_; }
private:
// Index of the current frame.
int current_;
static const int kQueueLength = 2;
scoped_ptr<VideoFrame> frames_[kQueueLength];
// True if the corresponding frame needs to be re-allocated.
bool needs_update_[kQueueLength];
// Points to the previous frame if any.
VideoFrame* previous_;
DISALLOW_COPY_AND_ASSIGN(VideoFrameQueue);
};
} // namespace remoting
#endif // REMOTING_HOST_VIDEO_FRAME_QUEUE_H_
|