forked from olive-editor/olive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipqueue.h
185 lines (159 loc) · 4.17 KB
/
clipqueue.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef CLIPQUEUE_H
#define CLIPQUEUE_H
extern "C" {
#include <libavformat/avformat.h>
}
#include <QVector>
#include <QMutex>
/**
* @brief The ClipQueue class
*
* A fairly simple wrapper for a QVector and QMutex that cleans up AVFrames automatically when removing them.
*/
class ClipQueue {
public:
/**
* @brief ClipQueue Constructor
*/
ClipQueue();
/**
* @brief ClipQueue Destructor
*
* Automatically clears queue freeing any memory consumed by any AVFrames
*/
~ClipQueue();
// Thread safety (QMutex compatible)
/**
* @brief Lock queue mutex
*
* Used for multithreading to ensure queue is only accessed by one thread at a time. See QMutex::lock() for more
* information.
*/
void lock();
/**
* @brief Try to lock queue mutex
*
* Used for multithreading to ensure queue is only accessed by one thread at a time. Tries to lock, but doesn't block
* the calling thread and wait if it can't lock it. See QMutex::tryLock() for more information.
*
* @return
*
* **TRUE** if the lock succeeded, **FALSE** if not.
*/
bool tryLock();
/**
* @brief Unlock queue mutex
*
* Used for multithreading to ensure queue is only accessed by one thread at a time. See QMutex::unlock() for more
* information.
*/
void unlock();
// Array handling (QVector compatible)
/**
* @brief Add a frame to the end of the queue
*
* @param frame
*
* The frame to add
*/
void append(AVFrame* frame);
/**
* @brief Retrieve a frame at a certain index
*
* @param i
*
* Index to retrieve frame from
*
* @return
*
* AVFrame at this index
*/
AVFrame* at(int i);
/**
* @brief Retrieve first frame in the queue
*
* @return
*
* The first AVFrame in the queue
*/
AVFrame* first();
/**
* @brief Retrieve last frame in the queue
*
* @return
*
* The last AVFrame in the queue
*/
AVFrame* last();
/**
* @brief Remove first frame in the queue
*
* Frees all memory occupied by this frame and removes it from the queue
*/
void removeFirst();
/**
* @brief Remove last frame in the queue
*
* Frees all memory occupied by this frame and removes it from the queue
*/
void removeLast();
/**
* @brief Remove frame in the queue at a certain index
*
* Frees all memory occupied by this frame and removes it from the queue
*
* @param i
*
* Index to remove a frame at
*/
void removeAt(int i);
/**
* @brief Clear entire queue
*
* Frees all memory occupied by all frames and clears the entire queue
*/
void clear();
/**
* @brief Retrieve current size of the queue
*
* @return
*
* Current the current size of the queue. All indexes in the queue are guaranteed to be valid references to an
* AVFrame.
*/
int size();
/**
* @brief Returns whether the queue is empty of not.
*
* @return
*
* **TRUE** if the queue is empty and contains no frames, **FALSE** if not.
*/
bool isEmpty();
/**
* @brief Returns whether the queue contains a frame or not
*
* @return
*
* **TRUE** if the queue contains the specified frame, **FALSE** if not.
*/
bool contains(AVFrame* frame);
private:
QVector<AVFrame*> queue;
QMutex queue_lock;
};
#endif // CLIPQUEUE_H