forked from huimingli/QTFFmpegSDLPlayer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PacketQueue.cpp
88 lines (83 loc) · 1.71 KB
/
PacketQueue.cpp
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
#include "PacketQueue.h"
#include <iostream>
#include <QMutexLocker>
static bool isExit = false;
PacketQueue::PacketQueue()
{
size = 0;
}
PacketQueue::~PacketQueue() {
QMutexLocker locker(&mutex);
isExit = true;
}
//************************************
// Method: enQueue
// FullName: PacketQueue::enQueue
// Access: public
// Returns: bool
// Qualifier:관뚠죗흙뚠
// Parameter: const AVPacket packet
//************************************
bool PacketQueue::enQueue(const AVPacket packet)
{
QMutexLocker locker(&mutex);
queue.push(packet);
size += packet.size;
cond.wakeOne();
return true;
}
//************************************
// Method: deQueue
// FullName: PacketQueue::deQueue
// Access: public
// Returns: AVPacket
// Qualifier:관뚠죗놔뚠
//************************************
AVPacket PacketQueue::deQueue()
{
bool ret = false;
AVPacket pkt;
QMutexLocker locker(&mutex);
while (true)
{
if (!queue.empty())
{
pkt = queue.front();
queue.pop();
size -= pkt.size;
ret = true;
break;
}
else
{
cond.wait(&mutex);
}
}
return pkt;
}
//************************************
// Method: getPacketSize
// FullName: PacketQueue::getPacketSize
// Access: public
// Returns: Uint32
// Qualifier:삿혤관댕鬼
//************************************
Uint32 PacketQueue::getPacketSize()
{
QMutexLocker locker(&mutex);
return size;
}
//************************************
// Method: queueFlush
// FullName: PacketQueue::queueFlush
// Access: public
// Returns: void
// Qualifier:헌왕뚠죗
//************************************
void PacketQueue::queueFlush() {
while (!queue.empty())
{
AVPacket pkt = deQueue();
av_free_packet(&pkt);
}
}