TaisyncVideoReceiver.cc 1.7 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "TaisyncVideoReceiver.h"
#include "SettingsManager.h"
#include "QGCApplication.h"
#include "VideoManager.h"

//-----------------------------------------------------------------------------
TaisyncVideoReceiver::TaisyncVideoReceiver(QObject* parent)
    : TaisyncHandler(parent)
{
}

//-----------------------------------------------------------------------------
Gus Grubba's avatar
Gus Grubba committed
22
bool
23 24
TaisyncVideoReceiver::close()
{
Gus Grubba's avatar
Gus Grubba committed
25 26 27 28 29 30 31 32
    if(TaisyncHandler::close() || _udpVideoSocket) {
        qCDebug(TaisyncLog) << "Close Taisync Video Receiver";
        if(_udpVideoSocket) {
            _udpVideoSocket->close();
            _udpVideoSocket->deleteLater();
            _udpVideoSocket = nullptr;
        }
        return true;
33
    }
Gus Grubba's avatar
Gus Grubba committed
34
    return false;
35 36 37
}

//-----------------------------------------------------------------------------
38
bool
39 40
TaisyncVideoReceiver::start()
{
Gus Grubba's avatar
Gus Grubba committed
41 42 43 44 45 46
    qCDebug(TaisyncLog) << "Start Taisync Video Receiver";
    if(_start(TAISYNC_VIDEO_TCP_PORT)) {
        _udpVideoSocket = new QUdpSocket(this);
        return true;
    }
    return false;
47 48 49 50 51 52
}

//-----------------------------------------------------------------------------
void
TaisyncVideoReceiver::_readBytes()
{
Gus Grubba's avatar
Gus Grubba committed
53 54 55 56
    if(_udpVideoSocket) {
        QByteArray bytesIn = _tcpSocket->read(_tcpSocket->bytesAvailable());
        _udpVideoSocket->writeDatagram(bytesIn, QHostAddress::LocalHost, TAISYNC_VIDEO_UDP_PORT);
    }
57
}