VideoSettings.cc 4.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "VideoSettings.h"

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
13
#include <QtQml>
14
#include <QVariantList>
Don Gagne's avatar
Don Gagne committed
15 16

#ifndef QGC_DISABLE_UVC
17
#include <QCameraInfo>
Don Gagne's avatar
Don Gagne committed
18
#endif
19

20
const char* VideoSettings::videoSourceNoVideo =     "No Video Available";
21
const char* VideoSettings::videoDisabled =          "Video Stream Disabled";
22 23
const char* VideoSettings::videoSourceUDP =         "UDP Video Stream";
const char* VideoSettings::videoSourceRTSP =        "RTSP Video Stream";
24
const char* VideoSettings::videoSourceTCP =         "TCP-MPEG2 Video Stream";
25 26 27
#ifdef QGC_GST_TAISYNC_USB
const char* VideoSettings::videoSourceTaiSyncUSB =  "Taisync USB";
#endif
28

29
DECLARE_SETTINGGROUP(Video, "Video")
30 31 32
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
33 34

    // Setup enum values for videoSource settings into meta data
35
    bool noVideo = false;
36 37 38 39 40 41
    QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
#ifndef NO_UDP_VIDEO
    videoSourceList.append(videoSourceUDP);
#endif
    videoSourceList.append(videoSourceRTSP);
42
    videoSourceList.append(videoSourceTCP);
43 44 45
#ifdef QGC_GST_TAISYNC_USB
    videoSourceList.append(videoSourceTaiSyncUSB);
#endif
46 47 48
#endif
#ifndef QGC_DISABLE_UVC
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
49
    for (const QCameraInfo &cameraInfo: cameras) {
50 51 52 53
        videoSourceList.append(cameraInfo.description());
    }
#endif
    if (videoSourceList.count() == 0) {
54
        noVideo = true;
55
        videoSourceList.append(videoSourceNoVideo);
56 57
    } else {
        videoSourceList.insert(0, videoDisabled);
58 59
    }
    QVariantList videoSourceVarList;
60
    for (const QString& videoSource: videoSourceList) {
61 62 63 64 65
        videoSourceVarList.append(QVariant::fromValue(videoSource));
    }
    _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);

    // Set default value for videoSource
66 67 68 69 70
    if (noVideo) {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
71 72
}

73 74 75 76 77 78 79 80 81 82 83 84
DECLARE_SETTINGSFACT(VideoSettings, aspectRatio)
DECLARE_SETTINGSFACT(VideoSettings, videoFit)
DECLARE_SETTINGSFACT(VideoSettings, gridLines)
DECLARE_SETTINGSFACT(VideoSettings, showRecControl)
DECLARE_SETTINGSFACT(VideoSettings, recordingFormat)
DECLARE_SETTINGSFACT(VideoSettings, maxVideoSize)
DECLARE_SETTINGSFACT(VideoSettings, enableStorageLimit)
DECLARE_SETTINGSFACT(VideoSettings, rtspTimeout)
DECLARE_SETTINGSFACT(VideoSettings, streamEnabled)
DECLARE_SETTINGSFACT(VideoSettings, disableWhenDisarmed)

DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
85 86 87
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
88
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
89 90 91 92
    }
    return _videoSourceFact;
}

93
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
94 95 96
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
97
        connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
98 99 100 101
    }
    return _udpPortFact;
}

102
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
103 104 105
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
106
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
107 108 109 110
    }
    return _rtspUrlFact;
}

111
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
112 113 114
{
    if (!_tcpUrlFact) {
        _tcpUrlFact = _createSettingsFact(tcpUrlName);
115
        connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
116 117 118 119
    }
    return _tcpUrlFact;
}

120 121 122 123 124 125 126 127 128
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
129 130 131 132 133
#ifdef QGC_GST_TAISYNC_USB
    if(vSource == videoSourceTaiSyncUSB) {
        return true;
    }
#endif
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    //-- If UDP, check if port is set
    if(vSource == videoSourceUDP) {
        return udpPort()->rawValue().toInt() != 0;
    }
    //-- If RTSP, check for URL
    if(vSource == videoSourceRTSP) {
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
    //-- If TCP, check for URL
    if(vSource == videoSourceTCP) {
        return !tcpUrl()->rawValue().toString().isEmpty();
    }
    return false;
}

void VideoSettings::_configChanged(QVariant)
{
    emit streamConfiguredChanged();
}