-
Notifications
You must be signed in to change notification settings - Fork 28
/
qatemuploader.cpp
112 lines (94 loc) · 2.85 KB
/
qatemuploader.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
#include "qatemuploader.h"
#include <qatemconnection.h>
#include <QTextStream>
#include <QCoreApplication>
#include <QHostAddress>
#include <QImage>
#include <QFileInfo>
QAtemUploader::QAtemUploader(QObject *parent) :
QObject(parent), m_state(NotConnected), m_mediaplayer (-1)
{
m_connection = new QAtemConnection(this);
connect(m_connection, SIGNAL(socketError(QString)),
this, SLOT(handleError(QString)));
connect(m_connection, SIGNAL(connected()),
this, SLOT(requestLock()));
connect(m_connection, SIGNAL(mediaLockStateChanged(quint8,bool)),
this, SLOT(handleMediaLockState(quint8,bool)));
connect(m_connection, SIGNAL(dataTransferFinished(quint16)),
this, SLOT(handleDataTransferFinished(quint16)));
}
void QAtemUploader::upload(const QString &filename, const QString &address, quint8 position)
{
QHostAddress host(address);
if(host.isNull())
{
handleError(tr("Invalid switcher address"));
return;
}
m_connection->connectToSwitcher(host);
m_filename = filename;
m_position = position;
}
void QAtemUploader::handleError(const QString &errorString)
{
QTextStream out(stderr);
out << errorString << endl << endl;
QCoreApplication::exit(-1);
}
void QAtemUploader::requestLock()
{
m_state = AquiringLock;
if(!m_connection->mediaLockState(0))
{
m_connection->aquireMediaLock(0, m_position);
}
else
{
QTextStream out(stdout);
out << tr("Waiting for lock to be released... ");
}
}
void QAtemUploader::handleMediaLockState(quint8 id, bool locked)
{
QTextStream out(stdout);
if (id == 0 && locked && m_state == AquiringLock)
{
QImage image(m_filename);
if(image.isNull())
{
handleError(tr ("Failed to load image"));
return;
}
QSize size = m_connection->availableVideoModes().value(m_connection->videoFormat()).size;
QFileInfo info(m_filename);
out << tr ("Uploading... ");
m_connection->sendDataToSwitcher(0, m_position, info.baseName().toUtf8(), QAtemConnection::prepImageForSwitcher(image, size.width(), size.height()));
m_state = Inprogress;
}
else if(id == 0 && !locked)
{
if(m_state == AquiringLock)
{
out << tr ("Trying") << endl;
requestLock();
}
else if (m_state == Inprogress)
{
out << tr ("Done.") << endl << endl;
m_state = Done;
QCoreApplication::exit();
}
}
}
void QAtemUploader::handleDataTransferFinished(quint16 transferId)
{
if(transferId == 1)
{
m_connection->unlockMediaLock(0);
if(m_mediaplayer == 0 || m_mediaplayer == 1)
{
m_connection->setMediaPlayerSource(static_cast<quint8>(m_mediaplayer), false, m_position);
}
}
}