VideoReceiver.h 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/****************************************************************************
 *
 * (c) 2009-2020 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.
 *
 ****************************************************************************/

/**
 * @file
 *   @brief QGC Video Receiver
 *   @author Gus Grubba <gus@auterion.com>
 */

#pragma once

#include <QObject>
#include <QSize>
#include <QQuickItem>

#include <atomic>

class VideoReceiver : public QObject
{
    Q_OBJECT

public:
    explicit VideoReceiver(QObject* parent = nullptr)
        : QObject(parent)
        , _streaming(false)
        , _decoding(false)
        , _recording(false)
        , _videoSize(0)
    {}

    virtual ~VideoReceiver(void) {}

    typedef enum {
        FILE_FORMAT_MIN = 0,
        FILE_FORMAT_MKV = FILE_FORMAT_MIN,
        FILE_FORMAT_MOV,
        FILE_FORMAT_MP4,
        FILE_FORMAT_MAX
    } FILE_FORMAT;

    Q_PROPERTY(bool     streaming   READ    streaming   NOTIFY  streamingChanged)
    Q_PROPERTY(bool     decoding    READ    decoding    NOTIFY  decodingChanged)
    Q_PROPERTY(bool     recording   READ    recording   NOTIFY  recordingChanged)
    Q_PROPERTY(QSize    videoSize   READ    videoSize   NOTIFY  videoSizeChanged)

    bool streaming(void) {
        return _streaming;
    }

    bool decoding(void) {
        return _decoding;
    }

    bool recording(void) {
        return _recording;
    }

    QSize videoSize(void) {
        const quint32 size = _videoSize;
        return QSize((size >> 16) & 0xFFFF, size & 0xFFFF);
    }

signals:
    void timeout(void);
    void streamingChanged(void);
    void decodingChanged(void);
    void recordingChanged(void);
    void recordingStarted(void);
    void videoSizeChanged(void);
    void screenshotComplete(void);

78 79 80 81 82 83 84 85 86 87
    // FIXME: AV: I see very big sense to convert 'bool status' into 'enum status' and clearly state what happend during operation
    void onStartComplete(bool status);
    // FIXME: AV: add these signals after completing onStartComplete()
    // void onStopComplete(bool status);
    // void onStartDecodingComplete(bool status);
    // void onStopDecodingComplete(bool status);
    // void onStartRecordingComplete(bool status);
    // void onStopRecordingComplete(bool status);
    // void onTakeScreenshotComplete(bool status);

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
public slots:
    virtual void start(const QString& uri, unsigned timeout) = 0;
    virtual void stop(void) = 0;
    virtual void startDecoding(void* sink) = 0;
    virtual void stopDecoding(void) = 0;
    virtual void startRecording(const QString& videoFile, FILE_FORMAT format) = 0;
    virtual void stopRecording(void) = 0;
    virtual void takeScreenshot(const QString& imageFile) = 0;

protected:
    std::atomic<bool>   _streaming;
    std::atomic<bool>   _decoding;
    std::atomic<bool>   _recording;
    std::atomic<quint32>_videoSize;
};