-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoform.cpp
99 lines (84 loc) · 3.18 KB
/
videoform.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
89
90
91
92
93
94
95
96
97
98
99
#include "videoform.h"
#include "ui_videoform.h"
#define HEIGHT 950
#define WIDTH 420
VideoForm::VideoForm(const QString &serial, QWidget *parent): QWidget(parent), ui(new Ui::VideoForm), serial(serial) {
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(&server, &Server::serverStartResult, this, [this](bool success) {
qDebug() << "server start: " << success;
});
connect(&server, &Server::connectionResult, this, [this](bool success, const QString &deviceName, const QSize &size) {
qDebug() << "connection result: " << success << deviceName << size;
if (success) {
this->setWindowTitle(deviceName);
updateShowSize(size);
decoder.setDeviceSocket(server.getDeviceSocket());
decoder.startDecode();
inputConverter.setControlSocket(server.getDeviceSocket());
}
});
frames.init();
decoder.setFrames(&frames);
connect(&server, &Server::onServerStop, this, [this](){
close();
#ifdef QT_DEBUG
qDebug() << "server process stop.";
#endif
});
connect(&decoder, &Decoder::onDecodeStop, this, [this]() {
close();
#ifdef QT_DEBUG
qDebug() << "decoder thread stop.";
#endif
});
connect(&decoder, &Decoder::onNewFrame, this, [this]() {
#ifdef QT_DEBUG
qDebug() << "Signal: Decoder::onNewFrame.";
#endif
frames.lock();
// 读取frame, 传入OpenGL进行渲染
const AVFrame *frame = frames.consumeRenderedFrame();
// 更新窗口大小
updateShowSize(QSize(frame->width, frame->height));
ui->videoWidget->setFrameSize(QSize(frame->width, frame->height));
ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]);
frames.unlock();
});
updateShowSize(this->size());
server.start(serial, 27183, 1080, 8e6);
}
VideoForm::~VideoForm() {
server.stop();
decoder.stopDecode();
frames.destroy();
delete ui;
}
void VideoForm::mousePressEvent(QMouseEvent *event) {
inputConverter.mouseEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::mouseReleaseEvent(QMouseEvent *event) {
inputConverter.mouseEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::mouseMoveEvent(QMouseEvent *event) {
inputConverter.mouseEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::wheelEvent(QWheelEvent *event) {
inputConverter.wheelEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::keyPressEvent(QKeyEvent *event) {
inputConverter.keyEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::keyReleaseEvent(QKeyEvent *event) {
inputConverter.keyEvent(event, ui->videoWidget->getFrameSize(), ui->videoWidget->size());
}
void VideoForm::updateShowSize(const QSize &newSize) {
if (frameSize != newSize) {
frameSize = newSize;
bool vertical = newSize.height() > newSize.width();
if (vertical)
resize(WIDTH, HEIGHT);
else
resize(HEIGHT, WIDTH);
}
}