/
app.cpp
130 lines (100 loc) · 3.66 KB
/
app.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
#include "app.h"
App::App(QObject *parent) : QObject(parent) {
init();
}
void App::init() {
QGst::init();
m_pipelineOut = QGst::Pipeline::create();
m_pipelineIn = QGst::Pipeline::create();
}
void App::run() {
// startVoice();
startListen(m_pipelineIn, 5000); // TODO settings
m_pipelineOut->setState(QGst::StatePlaying);
m_pipelineIn->setState(QGst::StatePlaying);
QTimer::singleShot(2000, this, SLOT(testSlot()));
QTimer::singleShot(4000, this, SLOT(testSlot2()));
}
void App::startVoice() {
rtpbin = QGst::ElementFactory::make("gstrtpbin");
if (!rtpbin) {
qFatal("Failed to create gstrtpbin");
}
qDebug() << "initn create";
m_pipelineOut->add(rtpbin);
//audio content
//sending side
QGst::ElementPtr audiosrc;
try {
audiosrc = QGst::Bin::fromDescription(
// "alsasrc device=plughw:0 ! queue ! audioconvert ! audiorate ! audio/x-raw-int,rate=8000 "
// "! speexenc ! rtpspeexpay"
// );
"audiotestsrc ! queue ! audioconvert ! audiorate ! audio/x-raw-int,rate=8000 ! audioconvert"
);
// audiosrc = QGst::Bin::fromDescription(
// "audiotestsrc ! audioconvert ! level ! audioconvert ! twolame ! rtpmpapay"
// );
} catch (const QGlib::Error & error) {
qCritical() << error;
qFatal("One ore more required elements are missing. Aborting...");
}
m_pipelineOut->add(audiosrc);
volumeOut = QGst::ElementFactory::make("volume");
m_pipelineOut->add(volumeOut); // TODO settings
audiosrc->link(volumeOut);
QGst::ElementPtr decoder;
try {
decoder = QGst::Bin::fromDescription(
"speexenc vad=false ! rtpspeexpay"
);
} catch (const QGlib::Error & error) {
qCritical() << error;
qFatal("One ore more required elements are missing. Aborting...");
}
m_pipelineOut->add(decoder);
volumeOut->link(decoder);
decoder->link(rtpbin, "send_rtp_sink_1");
rtpudpsink = QGst::ElementFactory::make("udpsink");
if (!rtpudpsink) {
qFatal("Failed to create udpsink. Aborting...");
}
rtpudpsink->setProperty("host", "127.0.0.1"); // desttination 192.168.0.102
rtpudpsink->setProperty("port", 5000); // port
m_pipelineOut->add(rtpudpsink);
rtpbin->link("send_rtp_src_1", rtpudpsink);
}
void App::startListen(QGst::PipelinePtr pipe, int port) {
QGst::ElementPtr rtcpudpsink = QGst::ElementFactory::make("udpsrc");
rtcpudpsink->setProperty("host", "127.0.0.1"); // TODO settings
rtcpudpsink->setProperty("port", port); // source
// rtcpudpsink->setProperty("sync", false);
// rtcpudpsink->setProperty("async", false);
rtcpudpsink->setProperty("caps", QGst::Caps::fromString("application/x-rtp,media=(string)audio, clock-rate=(int)8000, encoding-name=(string)SPEEX,payload=(int)110"));
pipe->add(rtcpudpsink);
QGst::ElementPtr bin;
try {
bin = QGst::Bin::fromDescription(
"rtpspeexdepay ! speexdec ! audioconvert"
);
} catch (const QGlib::Error & error) {
qCritical() << error;
qFatal("One ore more required elements are missing. Aborting...");
}
pipe->add(bin);
rtcpudpsink->link(bin);
volumeIn = QGst::ElementFactory::make("volume"); // TODO settings
pipe->add(volumeIn);
bin->link(volumeIn);
QGst::ElementPtr audioSynk = QGst::ElementFactory::make("autoaudiosink");
pipe->add(audioSynk);
volumeIn->link(audioSynk);
}
void App::testSlot() {
qDebug() << "remove!";
volumeIn->setProperty("mute", true);
}
void App::testSlot2() {
qDebug() << "add again!";
volumeIn->setProperty("mute", false);
}