VideoSettings.cc 5.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/****************************************************************************
 *
 *   (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"
11 12
#include "QGCApplication.h"
#include "VideoManager.h"
13 14

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
15
#include <QtQml>
16
#include <QVariantList>
Don Gagne's avatar
Don Gagne committed
17 18

#ifndef QGC_DISABLE_UVC
19
#include <QCameraInfo>
Don Gagne's avatar
Don Gagne committed
20
#endif
21

22 23 24 25 26 27
const char* VideoSettings::videoSourceNoVideo   = "No Video Available";
const char* VideoSettings::videoDisabled        = "Video Stream Disabled";
const char* VideoSettings::videoSourceAuto      = "Automatic Video Stream";
const char* VideoSettings::videoSourceRTSP      = "RTSP Video Stream";
const char* VideoSettings::videoSourceUDP       = "UDP Video Stream";
const char* VideoSettings::videoSourceTCP       = "TCP-MPEG2 Video Stream";
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

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

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

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

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

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

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

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
    //-- 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();
    }
146 147 148 149 150
    //-- If Auto, check for URL
    if(vSource == videoSourceAuto) {
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
    //-- If Auto, check for received URL
151
    if(vSource == videoSourceTCP) {
152
        return !qgcApp()->toolbox()->videoManager()->autoURL().isEmpty();
153 154 155 156 157 158 159 160
    }
    return false;
}

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