-
Notifications
You must be signed in to change notification settings - Fork 4
/
tcpappsrc.cpp
65 lines (53 loc) · 1.28 KB
/
tcpappsrc.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
#include "tcpappsrc.h"
TcpAppSrc::TcpAppSrc(QObject *parent) :
QObject(parent), QGst::Utils::ApplicationSource()
{
connect(&sock, SIGNAL(readyRead()), this, SLOT(readyRead()));
}
TcpAppSrc::~TcpAppSrc()
{
stop();
}
bool TcpAppSrc::start(QString host, quint16 port, QString dumpFileName)
{
if (dumpFileName != "")
{
file.setFileName(dumpFileName);
file.open(QFile::ReadWrite);
}
sock.connectToHost(host, port);
// TODO: Wait until error or connected and return accordingly
return true;
}
void TcpAppSrc::stop()
{
qDebug() << "TcpAppSrc STOP";
sock.abort();
if (file.isOpen())
{
file.close();
}
}
void TcpAppSrc::needData(uint length)
{
Q_UNUSED(length)
//qDebug() << "TCPAPPSOURCE NEED DATA. Length:" << length;
}
void TcpAppSrc::enoughData()
{
//qDebug() << "TCPAPPSOURCE ENOUGH DATA";
}
void TcpAppSrc::readyRead()
{
//qDebug() << "TCPAPPSRC: readyRead WITH BYTES:" << sock.bytesAvailable();
QGst::BufferPtr buf = QGst::Buffer::create(sock.bytesAvailable());
QGst::MapInfo map;
buf->map(map, QGst::MapWrite);
sock.read((char*)map.data(), map.size());
if (file.isOpen())
{
file.write((char*)map.data(), map.size());
}
buf->unmap(map);
pushBuffer(buf);
}