forked from c12121234/MyFFmpegPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpegdecodethread.cpp
More file actions
78 lines (70 loc) · 1.41 KB
/
ffmpegdecodethread.cpp
File metadata and controls
78 lines (70 loc) · 1.41 KB
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
#include "ffmpegdecode.h"
#include "ffmpegdecodethread.h"
extern void FFmpegFreePacket(AVPacket** pPkt);
FFmpegDecodeThread::FFmpegDecodeThread():
m_pDecode(nullptr)
{
if(!m_pDecode)
m_pDecode = new FFmpegDeCode();
}
FFmpegDecodeThread::~FFmpegDecodeThread()
{
m_bIsExit = true;
wait();
}
void FFmpegDecodeThread::Push(AVPacket *pPkt)
{
if(!pPkt)
return;
while(!m_bIsExit)
{
m_Mutex.lock();
if(m_PacketsList.size()<m_nMaxBuffer)
{
m_PacketsList.push_back(pPkt);
m_Mutex.unlock();
break;
}
m_Mutex.unlock();
msleep(1);
}
}
AVPacket *FFmpegDecodeThread::Pop()
{
m_Mutex.lock();
if(m_PacketsList.empty())
{
m_Mutex.unlock();
return nullptr;
}
AVPacket* pPkt = m_PacketsList.front();
m_PacketsList.pop_front();
m_Mutex.unlock();
return pPkt;
}
void FFmpegDecodeThread::Clear()
{
m_Mutex.lock();
m_pDecode->Clear();
while(!m_PacketsList.empty())
{
AVPacket* pPkt = m_PacketsList.front();
FFmpegFreePacket(&pPkt);
m_PacketsList.pop_front();
}
m_Mutex.unlock();
}
void FFmpegDecodeThread::Close()
{
Clear();
m_bIsExit = true;
wait();
if(m_pDecode)
{
m_pDecode->Close();
m_Mutex.lock();
delete m_pDecode;
m_pDecode = nullptr;
m_Mutex.unlock();
}
}