-
Notifications
You must be signed in to change notification settings - Fork 4
/
cambox.cpp
145 lines (118 loc) · 4.36 KB
/
cambox.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
#include "cambox.h"
#include "ui_cambox.h"
CamBox::CamBox(QWidget *parent):
MediaSourceBase(parent),
ui(new Ui::CamBox)
{
ui->setupUi(this);
MediaSourceBase::init(ui->AudioMeterSliderL, ui->AudioMeterSliderR, ui->audioLabel, ui->GOButton, ui->VideoBox, ui->opacitySlider, ui->fadeCheck, ui->MonitorPushButton, ui->volumeSlider, ui->volSync);
connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(disconnectSource()));
ui->disconnectButton->setEnabled(false);
// This is a bit awkward. Somehow, the title gets changed back
// if we just call the SLOT here. So, use a single-shot timer
QTimer::singleShot(200, this, SLOT(updateTitle()));
}
CamBox::~CamBox()
{
delete ui;
}
void CamBox::setDumpDir(QString dir)
{
dumpDir = dir;
}
void CamBox::disconnectSource()
{
setVideoOpacity(0.0);
setVolume(0.0);
if (!pipeline.isNull())
{
pipeline->setState(QGst::StateNull);
pipeline.clear();
}
sourceOffline();
}
void CamBox::onBusMessage(const QGst::MessagePtr &message)
{
//qDebug() << "CamBox::MESSAGE" << message->type() << message->typeName();
switch (message->type()) {
case QGst::MessageStateChanged:
updateTitle();
break;
case QGst::MessageTag:
{
QGst::TagList taglist = message.staticCast<QGst::TagMessage>()->taglist();
if (taglist.comment() != "")
{
name = taglist.comment();
updateTitle();
}
break;
}
default:
break;
}
}
void CamBox::startCam(QHostAddress host, quint16 port, QString videocaps, QString audiocaps)
{
qDebug() << "Starting stream from" << QString("%1:%2").arg(host.toString()).arg(port) << id;
QString dumpFileName = QString("%1/%2_%3.mkv")
.arg(dumpDir)
.arg(QDateTime::currentDateTime().toString("yyyy-mm-dd_hh-mm-ss"))
.arg(id);
QString desc = QString("appsrc name=source !"
" decodebin name=decode ! queue ! videoscale ! videoconvert ! videorate ! "
" gamma name=gamma ! videobalance name=balance ! videoflip name=flip ! "
" appsink name=videosink caps=\"%1\""
" decode. ! queue ! audioconvert ! audioresample ! appsink name=audiosink caps=\"%2\"")
.arg(videocaps)
.arg(audiocaps);
qDebug() << "Pipeline:" << desc;
pipeline = QGst::Parse::launch(desc).dynamicCast<QGst::Pipeline>();
QGlib::connect(pipeline->bus(), "message", (MediaSourceBase*)this, &MediaSourceBase::onBusMessage);
QGlib::connect(pipeline->bus(), "message", this, &CamBox::onBusMessage);
pipeline->bus()->addSignalWatch();
m_tcpsrc.setElement(pipeline->getElementByName("source"));
m_tcpsrc.start(host.toString(), port, dumpFileName);
videoSink.setElement(pipeline->getElementByName("videosink"));
audioSink.setElement(pipeline->getElementByName("audiosink"));
gammaElement = pipeline->getElementByName("gamma");
videoBalanceElement = pipeline->getElementByName("balance");
videoFlipElement = pipeline->getElementByName("flip");
// start playing
pipeline->setState(QGst::StatePlaying);
sourceOnline();
}
void CamBox::sourceOnline() {
MediaSourceBase::sourceOnline();
ui->disconnectButton->setEnabled(true);
}
void CamBox::sourceOffline() {
MediaSourceBase::sourceOffline();
m_tcpsrc.stop();
ui->disconnectButton->setEnabled(false);
}
void CamBox::updateTitle() {
switch (getState())
{
case QGst::StateReady:
case QGst::StatePaused:
// Source online but pipeline not PLAYING ... (Still buffering input)
setTitle(QString("%1 (%2) : Buffering").arg(id).arg(name));
break;
case QGst::StatePlaying:
if ((ui->opacitySlider->value() != 0) || (ui->volumeSlider->value() != 0)) {
// Source online and ONAIR (RED)
setTitle(QString("%1 (%2) : ON AIR").arg(id).arg(name));
} else {
// Source online but not ONAIR (PALE GREEN)
setTitle(QString("%1 (%2) : Bereit").arg(id).arg(name));
}
break;
case QGst::StateNull:
// Source offline (LIGHT GRAY)
setTitle(QString("%1 : Nicht verbunden").arg(id));
break;
default:
break;
}
}