Skip to content
Snippets Groups Projects
VideoSettings.cc 6.08 KiB
Newer Older
  • Learn to ignore specific revisions
  • /****************************************************************************
     *
     *   (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 "QGCApplication.h"
    #include "VideoManager.h"
    
    
    #include <QQmlEngine>
    
    Don Gagne's avatar
    Don Gagne committed
    #include <QtQml>
    
    #include <QVariantList>
    
    Don Gagne's avatar
    Don Gagne committed
    
    #ifndef QGC_DISABLE_UVC
    
    #include <QCameraInfo>
    
    Don Gagne's avatar
    Don Gagne committed
    #endif
    
    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";
    
    const char* VideoSettings::videoSourceMPEGTS    = "MPEG-TS (h.264) Video Stream";
    
    DECLARE_SETTINGGROUP(Video, "Video")
    
    {
        QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
        qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
    
    
        // Setup enum values for videoSource settings into meta data
        QStringList videoSourceList;
    #ifdef QGC_GST_STREAMING
    
        videoSourceList.append(videoSourceAuto);
        videoSourceList.append(videoSourceRTSP);
    
    #ifndef NO_UDP_VIDEO
        videoSourceList.append(videoSourceUDP);
    #endif
    
        videoSourceList.append(videoSourceTCP);
    
        videoSourceList.append(videoSourceMPEGTS);
    
    #endif
    #ifndef QGC_DISABLE_UVC
        QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    
        for (const QCameraInfo &cameraInfo: cameras) {
    
            videoSourceList.append(cameraInfo.description());
        }
    #endif
        if (videoSourceList.count() == 0) {
    
    Gus Grubba's avatar
    Gus Grubba committed
            _noVideo = true;
    
            videoSourceList.append(videoSourceNoVideo);
    
        } else {
            videoSourceList.insert(0, videoDisabled);
    
        }
        QVariantList videoSourceVarList;
    
        for (const QString& videoSource: videoSourceList) {
    
            videoSourceVarList.append(QVariant::fromValue(videoSource));
        }
        _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);
        // Set default value for videoSource
    
    Gus Grubba's avatar
    Gus Grubba committed
        _setDefaults();
    }
    
    void VideoSettings::_setDefaults()
    {
        if (_noVideo) {
    
            _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
        } else {
            _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
        }
    
    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)
    
    {
        if (!_videoSourceFact) {
            _videoSourceFact = _createSettingsFact(videoSourceName);
    
    Gus Grubba's avatar
    Gus Grubba committed
            //-- Check for sources no longer available
    
            if(!_videoSourceFact->enumStrings().contains(_videoSourceFact->rawValue().toString())) {
    
    Gus Grubba's avatar
    Gus Grubba committed
                if (_noVideo) {
                    _videoSourceFact->setRawValue(videoSourceNoVideo);
                } else {
                    _videoSourceFact->setRawValue(videoDisabled);
                }
            }
    
            connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
    
    DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
    
    {
        if (!_udpPortFact) {
            _udpPortFact = _createSettingsFact(udpPortName);
    
            connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
    
    DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
    
    {
        if (!_rtspUrlFact) {
            _rtspUrlFact = _createSettingsFact(rtspUrlName);
    
            connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
    
    DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
    
    {
        if (!_tcpUrlFact) {
            _tcpUrlFact = _createSettingsFact(tcpUrlName);
    
            connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
    
    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) {
    
            qCDebug(VideoManagerLog) << "Testing configuration for UDP Stream:" << udpPort()->rawValue().toInt();
    
            return udpPort()->rawValue().toInt() != 0;
        }
        //-- If RTSP, check for URL
        if(vSource == videoSourceRTSP) {
    
            qCDebug(VideoManagerLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString();
    
            return !rtspUrl()->rawValue().toString().isEmpty();
        }
    
        //-- If TCP, check for URL
        if(vSource == videoSourceTCP) {
            qCDebug(VideoManagerLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString();
            return !tcpUrl()->rawValue().toString().isEmpty();
    
        //-- If MPEG-TS, check if port is set
        if(vSource == videoSourceMPEGTS) {
            qCDebug(VideoManagerLog) << "Testing configuration for MPEG-TS Stream:" << udpPort()->rawValue().toInt();
            return udpPort()->rawValue().toInt() != 0;
        }
    
        //-- If Auto, check for received URL
    
        if(vSource == videoSourceAuto) {
            qCDebug(VideoManagerLog) << "Testing configuration for Auto Stream:" << qgcApp()->toolbox()->videoManager()->autoURL();
    
            return !qgcApp()->toolbox()->videoManager()->autoURL().isEmpty();
    
        }
        return false;
    }
    
    void VideoSettings::_configChanged(QVariant)
    {
        emit streamConfiguredChanged();
    }