-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudwaredialog.cpp
More file actions
87 lines (67 loc) · 2.45 KB
/
cloudwaredialog.cpp
File metadata and controls
87 lines (67 loc) · 2.45 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
#include <QtGui>
#include <libde265/de265.h>
#include "cloudwaredialog.h"
#include "ui_cloudwaredialog.h"
#include "libyuv/convert_from.h"
CloudwareDialog::CloudwareDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CloudwareDialog)
{
ui->setupUi(this);
this->mImg = new QImage(QSize(this->width() ,this->height()), QImage::Format_ARGB32);
this->qImg = NULL;
WelsCreateDecoder(&this->pSvcDecoder);
SDecodingParam sDecParam = {0};
sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
sDecParam.eOutputColorFormat = videoFormatI420;
//for Parsing only, the assignment is mandatory
sDecParam.bParseOnly = false;
this->pSvcDecoder->Initialize(&sDecParam);
}
CloudwareDialog::~CloudwareDialog()
{
this->pSvcDecoder->Uninitialize();
WelsDestroyDecoder(this->pSvcDecoder);
delete ui;
}
void CloudwareDialog::decode(const unsigned char *buf, int length)
{
qDebug("decoding...");
unsigned char *pData[3];
DECODING_STATE state = this->pSvcDecoder->DecodeFrame2(buf, length, pData, &this->sDstBufInfo);
if (state != 0) {
qDebug("decode error");
}
if (this->sDstBufInfo.iBufferStatus == 1) {
int width = this->sDstBufInfo.UsrData.sSystemBuffer.iWidth;
int height = this->sDstBufInfo.UsrData.sSystemBuffer.iHeight;
int *stride = this->sDstBufInfo.UsrData.sSystemBuffer.iStride;
//QImage qimg = QImage(QSize(width ,height), QImage::Format_ARGB32);
libyuv::I420ToARGB(pData[0], stride[0], pData[1], stride[1], pData[2], stride[2], this->mImg->bits(), this->mImg->bytesPerLine(), width, height);
this->qImg = this->mImg;
repaint();
this->qImg = NULL; /* forbid system repaint use mImg */
}
return;
}
void CloudwareDialog::paintEvent(QPaintEvent *event)
{
qDebug("paintEvent");
QPainter painter(this);
if (this->qImg) {
QRect videoRect = qImg->rect();
// videoRect.moveCenter(this->rect().center());
// if (!videoRect.contains(event->rect())) {
// QRegion region = event->region();
// region = region.subtracted(videoRect);
// QBrush brush = palette().background();
// foreach (const QRect &rect, region.rects()) {
// painter.fillRect(rect, brush);
// }
// }
qDebug("painted!");
painter.drawImage(videoRect, *qImg);
} else {
painter.fillRect(event->rect(), palette().background());
}
}