forked from c12121234/MyFFmpegPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpegvideo.cpp
More file actions
144 lines (131 loc) · 2.96 KB
/
ffmpegvideo.cpp
File metadata and controls
144 lines (131 loc) · 2.96 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
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
#include "ffmpegvideo.h"
#include "ffmpegdecode.h"
#include <QDebug>
FFmpegVideo::FFmpegVideo():
m_pVideoCall(nullptr)
, m_nSynPts(0)
,m_bIsPause(false)
{
}
FFmpegVideo::~FFmpegVideo()
{
}
bool FFmpegVideo::Open(AVCodecParameters *pPara, IVideoCall *pVideoCall, int nWidth, int nHeight)
{
if(!pPara)
return false;
Clear();
m_VideoMutex.lock();
m_nSynPts = 0;
m_pVideoCall = pVideoCall;
if(pVideoCall)
{
pVideoCall-> Init(nWidth,nHeight);
}
m_VideoMutex.unlock();
bool bRet = true;
if(!m_pDecode->Open(pPara))
{
qInfo()<<"audio FFmpegDecode open failed.";
bRet = false;
}
qInfo()<<"FFmpegAudio open:"<<bRet;
return bRet;
}
bool FFmpegVideo::RepaintPts(AVPacket *pPkt, long long nSeekPts)
{
m_VideoMutex.lock();
bool bRet = m_pDecode->Send(pPkt);
if(!bRet)
{
m_VideoMutex.unlock();
return true;//return true 結束解碼
}
AVFrame* pFrame = m_pDecode->Recv();
if(!pFrame)
{
m_VideoMutex.unlock();
return false;
}
if(m_pDecode->GetPts() >= nSeekPts)
{
if(m_pVideoCall)
m_pVideoCall->Repaint(pFrame);
m_VideoMutex.unlock();
return true;
}
FFmpegFreeFrame(&pFrame);
m_VideoMutex.unlock();
return false;
}
void FFmpegVideo::run()
{
while(!m_bIsExit)
{
m_VideoMutex.lock();
if(m_bIsPause)
{
m_VideoMutex.unlock();
msleep(5);
continue;
}
long long nPts = m_pDecode->GetPts();
if(m_nSynPts>0 && m_nSynPts <nPts)
{
m_VideoMutex.unlock();
msleep(1);
continue;
}
// if(m_PacketsList.empty() || !m_pDecode)
// {
// m_VideoMutex.unlock();
// msleep(1);
// continue;
// }
//音視訊同步
// AVPacket* pPkt = m_PacketsList.front();
// m_PacketsList.pop_front();
AVPacket* pPkt = Pop();
bool bRet = m_pDecode->Send(pPkt);
// if(!bRet)
// {
// m_VideoMutex.unlock();
// msleep(1);
// continue;
// }
//可能一次send 多個recv
while(!m_bIsExit)
{
AVFrame* pFrame = m_pDecode->Recv();
if(!pFrame)
break;
//show video frame
//qDebug()<<"audio diff video pts:"<<m_nSynPts-nPts;
if(m_pVideoCall)
{
m_pVideoCall->Repaint(pFrame);
msleep(10);
}
else
msleep(1);
}
m_VideoMutex.unlock();
msleep(1);
}
}
void FFmpegVideo::SetSynPts(long long nPts)
{
m_VideoMutex.lock();
m_nSynPts = nPts;
m_VideoMutex.unlock();
}
void FFmpegVideo::SetPause(bool bIsPause)
{
m_VideoMutex.lock();
m_bIsPause = bIsPause;
m_VideoMutex.unlock();
}
bool FFmpegVideo::GetPauseState()
{
return m_bIsPause;
}