VideoSettings.cc 5.21 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 35 36 37 38 39 40

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

    // Set default value for videoSource
Gus Grubba's avatar
Gus Grubba committed
65 66 67 68 69 70
    _setDefaults();
}

void VideoSettings::_setDefaults()
{
    if (_noVideo) {
71 72 73 74
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
75 76
}

77 78 79 80 81 82 83 84 85 86 87 88
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)
89 90 91
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
Gus Grubba's avatar
Gus Grubba committed
92 93 94 95 96 97 98 99
        //-- Check for sources no longer available
        if(!_nameToMetaDataMap.contains(_videoSourceFact->rawValue().toString())) {
            if (_noVideo) {
                _videoSourceFact->setRawValue(videoSourceNoVideo);
            } else {
                _videoSourceFact->setRawValue(videoDisabled);
            }
        }
100
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
101 102 103 104
    }
    return _videoSourceFact;
}

105
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
106 107 108
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
109
        connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
110 111 112 113
    }
    return _udpPortFact;
}

114
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
115 116 117
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
118
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
119 120 121 122
    }
    return _rtspUrlFact;
}

123
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
124 125 126
{
    if (!_tcpUrlFact) {
        _tcpUrlFact = _createSettingsFact(tcpUrlName);
127
        connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
128 129 130 131
    }
    return _tcpUrlFact;
}

132 133 134 135 136 137 138 139 140
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
141 142 143 144 145
#ifdef QGC_GST_TAISYNC_USB
    if(vSource == videoSourceTaiSyncUSB) {
        return true;
    }
#endif
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    //-- 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();
}