-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathavpacketqueue.cpp
More file actions
54 lines (45 loc) · 962 Bytes
/
Copy pathavpacketqueue.cpp
File metadata and controls
54 lines (45 loc) · 962 Bytes
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
#include "avpacketqueue.h"
AvPacketQueue::AvPacketQueue()
{
mutex = SDL_CreateMutex();
cond = SDL_CreateCond();
}
void AvPacketQueue::enqueue(AVPacket *packet)
{
SDL_LockMutex(mutex);
queue.enqueue(*packet);
SDL_CondSignal(cond);
SDL_UnlockMutex(mutex);
}
void AvPacketQueue::dequeue(AVPacket *packet, bool isBlock)
{
SDL_LockMutex(mutex);
while (1) {
if (!queue.isEmpty()) {
*packet = queue.dequeue();
break;
} else if (!isBlock) {
break;
} else {
SDL_CondWait(cond, mutex);
}
}
SDL_UnlockMutex(mutex);
}
void AvPacketQueue::empty()
{
SDL_LockMutex(mutex);
while (queue.size() > 0) {
AVPacket packet = queue.dequeue();
av_packet_unref(&packet);
}
SDL_UnlockMutex(mutex);
}
bool AvPacketQueue::isEmpty()
{
return queue.isEmpty();
}
int AvPacketQueue::queueSize()
{
return queue.size();
}