-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathQFFmpegVideoRender.cpp
83 lines (63 loc) · 1.45 KB
/
QFFmpegVideoRender.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
#include "QFFmpegVideoRender.h"
QFFmpegVideoRender::QFFmpegVideoRender(QObject *parent) : QThread(parent)
{
bufpos=0;
}
QFFmpegVideoRender::~QFFmpegVideoRender()
{
}
void QFFmpegVideoRender::setGLWidget(QFFmpegGLWidget *mGLWidget)
{
this->mGLWidget=mGLWidget;
}
void QFFmpegVideoRender::setClock(QFFmpegClock *mClock)
{
this->mClock=mClock;
}
void QFFmpegVideoRender::run()
{
while(true)
{
if(queue.length()>0)
{
PICTURE pic=queue.front();
if(pic.time>=mClock->getClockTime())
{
mGLWidget->updateData(pic.data);
queue.dequeue();
}
}
QThread::msleep(10);
}
}
void QFFmpegVideoRender::setSize(int w,int h)
{
width=w;
height=h;
int size=w*h*3/2;
if(size>0){
buffer[0]=(uint8_t*)malloc(size);
buffer[1]=(uint8_t*)malloc(size);
buffer[2]=(uint8_t*)malloc(size);
mGLWidget->initShader(w,h);
}
else{
}
}
int QFFmpegVideoRender::getQueueSize()
{
return queue.length();
}
void QFFmpegVideoRender::addPicture(uint8_t **data,double time)
{
PICTURE picture;
picture.data=buffer[bufpos];
picture.time=time;
memcpy(picture.data,data[0],width*height);
memcpy(picture.data+width*height,data[1],width*height/4);
memcpy(picture.data+width*height*5/4,data[2],width*height/4);
queue.enqueue(picture);
bufpos++;
if(bufpos>2)
bufpos=0;
}