-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyper.cpp
260 lines (215 loc) · 7.97 KB
/
hyper.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "hyper.h"
CuteHyper::CuteHyper(QObject *parent) :
QObject(parent),
m_connections(0),
m_tc(0),
m_clips(0),
m_clip_len(0),
m_loop(0)
{
m_playlist = new QMediaPlaylist(this);
m_server = new QTcpServer(this);
if (!m_server->listen(QHostAddress::AnyIPv4, 9993)) {
qWarning() << "Unable to start the server: " << m_server->errorString();
} else {
qDebug() << m_server->serverAddress() << m_server->serverPort();
}
connect(m_server, SIGNAL(newConnection()), this, SLOT(newConnection()));
}
void CuteHyper::setStatus(QString status)
{
m_status=status;
emit statusChanged();
}
void CuteHyper::setTimecode(int tc)
{
m_tc=tc;
}
void CuteHyper::setDuration(int du)
{
m_clip_len=du;
}
void CuteHyper::setClips(int clips)
{
m_clips=clips;
}
void CuteHyper::writeResponse(QTcpSocket *con, QString key, QString val)
{
con->write(key.toLocal8Bit());
con->write(": ");
con->write(val.toLocal8Bit());
con->write("\r\n");
}
void CuteHyper::writeResponse(QTcpSocket *con, QString key, bool val)
{
con->write(key.toLocal8Bit());
con->write(": ");
con->write(val ? "true" : "false");
con->write("\r\n");
}
void CuteHyper::writeResponse(QTcpSocket *con, QString key, int val)
{
con->write(key.toLocal8Bit());
con->write(": ");
con->write(QByteArray::number(val));
con->write("\r\n");
}
void CuteHyper::onReadyRead()
{
QTcpSocket *con = qobject_cast<QTcpSocket*>(sender());
while (con->canReadLine()) {
QByteArray ba = con->readLine();
qDebug() << ba;
auto cmdp= ba.split(' ');
QByteArray cmd=cmdp.at(0);
qDebug() << cmd << cmdp;
if (cmd.startsWith("quit")) {
con->write("200 ok\r\n");
disconnectRemoteAccess();
m_server->close();
return;
} else if (cmd.startsWith("ping")) {
qDebug() << "ping";
con->write("200 ok\r\n");
} else if (cmd.startsWith("play")) {
qDebug() << "play";
emit play();
con->write("200 ok\r\n");
} else if (cmd.startsWith("record")) {
qDebug() << "record";
emit record();
con->write("200 ok\r\n");
} else if (cmd.startsWith("stop")) {
qDebug() << "stop";
emit stop();
con->write("200 ok\r\n");
} else if (cmd.startsWith("notify:")) {
qDebug() << "notify response";
con->write("209 notify:\r\n");
con->write("transport: true\r\n");
con->write("slot: true\r\n");
con->write("remote: true\r\n");
con->write("configuration: false\r\n");
con->write("\r\n");
} else if (cmd.startsWith("transport info")) {
qDebug() << "transport response";
QTime tc(0,0,0);
tc=tc.addSecs(m_tc);
QString stc=tc.toString("00:hh:mm:ss");
qDebug() << "tc" << stc << m_status;
con->write("208 transport info:\r\n");
writeResponse(con, "status", m_status);
writeResponse(con, "speed", m_speed);
con->write("slot id: 1\r\n");
writeResponse(con, "display timecode: ", stc);
writeResponse(con, "timecode: ", stc);
if (m_clips>0)
writeResponse(con, "clip id", 1);
else
writeResponse(con, "clip id", "none");
con->write("single clip: true\r\n");
con->write("video format: 1080p30\r\n");
con->write("loop: false\r\n");
con->write("\r\n");
} else if (cmd.startsWith("clips count")) {
qDebug() << "clips count response";
con->write("214 clips count:\r\n");
writeResponse(con, "clip count", m_clips);
con->write("\r\n");
} else if (cmd.startsWith("clips get")) {
QTime tc(0,0,0);
tc=tc.addSecs(m_clip_len);
QString stc=tc.toString("00:hh:mm:ss");
qDebug() << "clips get response" << m_clip_len << stc;
con->write("205 clips info:\r\n");
writeResponse(con, "clip count", m_clips);
if (m_clips>0) {
con->write("1: media.mov H.264High 1080p30 00:00:00:00 ");
con->write(stc.toLocal8Bit());
con->write("\r\n");
}
con->write("\r\n");
} else if (cmd.startsWith("disk list")) {
qDebug() << "disk response";
QTime tc(0,0,0);
tc=tc.addSecs(m_clip_len);
QString stc=tc.toString("00:hh:mm:ss");
con->write("206 disk list:\r\n");
con->write("slot id: 1\r\n");
con->write("1: media.mov H.264High 1080p30 00:00:00:00 ");
con->write(stc.toLocal8Bit());
con->write("\r\n");
con->write("\r\n");
} else if (cmd.startsWith("slot info: slot id: 1")) {
qDebug() << "slot 1 response";
con->write("202 slot info:\r\n");
con->write("slot id: 1\r\n");
con->write("status: mounted\r\n");
con->write("volume name: CUTEHYPER\r\n");
con->write("recording time: 36000\r\n");
con->write("video format: 1080p30\r\n");
con->write("\r\n");
} else if (cmd.startsWith("slot info: slot id: 2")) {
qDebug() << "slot 2 response";
con->write("202 slot info:\r\n");
con->write("slot id: 2\r\n");
con->write("status: empty\r\n");
con->write("volume name: \r\n");
con->write("recording time: 0\r\n");
con->write("video format: 1080p30\r\n");
con->write("\r\n");
} else if (cmd.startsWith("slot info")) {
qDebug() << "slot 0 response";
con->write("202 slot info:\r\n");
con->write("slot id: 1\r\n");
con->write("status: mounted\r\n");
con->write("volume name: CUTEHYPER\r\n");
con->write("recording time: 36000\r\n");
con->write("video format: 1080p30\r\n");
con->write("\r\n");
} else if (cmd.startsWith("goto")) {
con->write("200 ok\r\n");
} else if (cmd.startsWith("help")) {
con->write("200 ok\r\n");
} else if (cmd.startsWith("remote")) {
qDebug() << "remote response";
con->write("210 remote info:\r\n");
con->write("enabled: true\r\n");
con->write("override: false\r\n");
con->write("\r\n");
} else if (cmd.startsWith("configuration")) {
con->write("211 configuration:\r\n");
con->write("audio input: embedded\r\n");
con->write("video input: HDMI\r\n");
con->write("\r\n");
} else {
con->write("103 unsupported\r\n");
}
}
}
void CuteHyper::disconnectRemoteAccess() {
QTcpSocket *con = qobject_cast<QTcpSocket*>(sender());
qDebug() << "Remote disconnected" << con->peerAddress();
con->deleteLater();
m_connections--;
}
void CuteHyper::newConnection() {
if (m_connections<10) {
QTcpSocket *tmp = m_server->nextPendingConnection();
qDebug() << "Remote connection accepted" << m_connections << tmp->peerAddress();
tmp->write("500 connection info:\r\n");
tmp->write("protocol version: 1.11\r\n");
tmp->write("model: HyperDeck Studio Mini\r\n");
tmp->write("unique id: 123456789\r\n");
tmp->write("\r\n");
connect(tmp, SIGNAL(disconnected()), this, SLOT(disconnectRemoteAccess()));
connect(tmp, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
m_connections++;
} else {
qDebug("Max remote connections already exists, deny.");
QTcpSocket *tmp = m_server->nextPendingConnection();
connect(tmp, SIGNAL(disconnected()), tmp, SLOT(deleteLater()));
tmp->write("120 connection rejected\n");
tmp->disconnectFromHost();
}
}