forked from loulou784/UGV_AUVSI_2020_GroundStation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpvideowidget.cpp
More file actions
55 lines (47 loc) · 1.67 KB
/
Copy pathtcpvideowidget.cpp
File metadata and controls
55 lines (47 loc) · 1.67 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
#if !defined(Q_OS_WASM)
#include "tcpvideowidget.h"
TCPVideoWidget::TCPVideoWidget(QWidget *parent) : QWidget(parent)
{
m_server = new QTcpServer(this);
connect(m_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
m_server->listen(QHostAddress::Any, 2222);
m_label = new QLabel();
m_label->setAlignment(Qt::AlignCenter);
m_label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget(m_label);
this->setLayout(vLayout);
}
void TCPVideoWidget::readyRead() {
// START: FF D8 FF
// END: FF D9
m_incomingData.append(m_socket->readAll());
switch (m_state) {
case STATE_HEADER:
startIdx = m_incomingData.indexOf(header);
if(startIdx != -1) {
m_state = STATE_FOOTER;
}
break;
case STATE_FOOTER:
endIdx = m_incomingData.indexOf(footer);
if(endIdx != -1) {
// We have a picture
m_currentImage.replace(startIdx, endIdx + footer.size(), m_incomingData);
m_pixmap.loadFromData(m_currentImage,"JPG");
m_label->setPixmap(m_pixmap.scaled(m_label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_incomingData.remove(startIdx, endIdx + footer.size());
}
if(endIdx != -1) {
m_state = STATE_HEADER;
}
break;
}
m_socket->flush();
}
void TCPVideoWidget::newConnection() {
m_socket = m_server->nextPendingConnection();
connect(m_socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
qDebug() << "New Connection!";
}
#endif