VideoReceiver.h 4.61 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
Gus Grubba's avatar
Gus Grubba committed
9 10 11 12 13 14 15 16 17 18 19


/**
 * @file
 *   @brief QGC Video Receiver
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#ifndef VIDEORECEIVER_H
#define VIDEORECEIVER_H

20
#include "QGCLoggingCategory.h"
Gus Grubba's avatar
Gus Grubba committed
21
#include <QObject>
22 23 24
#include <QTimer>
#include <QTcpSocket>

25 26
#include "VideoSurface.h"

27
#if defined(QGC_GST_STREAMING)
Gus Grubba's avatar
Gus Grubba committed
28
#include <gst/gst.h>
29
#endif
Gus Grubba's avatar
Gus Grubba committed
30

31 32
Q_DECLARE_LOGGING_CATEGORY(VideoReceiverLog)

Gus Grubba's avatar
Gus Grubba committed
33 34 35 36
class VideoReceiver : public QObject
{
    Q_OBJECT
public:
37
#if defined(QGC_GST_STREAMING)
38
    Q_PROPERTY(bool             recording           READ    recording           NOTIFY recordingChanged)
39
#endif
40
    Q_PROPERTY(VideoSurface*    videoSurface        READ    videoSurface        CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
41 42 43
    Q_PROPERTY(bool             videoRunning        READ    videoRunning        NOTIFY  videoRunningChanged)
    Q_PROPERTY(QString          imageFile           READ    imageFile           NOTIFY  imageFileChanged)
    Q_PROPERTY(bool             showFullScreen      READ    showFullScreen      WRITE   setShowFullScreen     NOTIFY showFullScreenChanged)
44

Gus Grubba's avatar
Gus Grubba committed
45 46 47
    explicit VideoReceiver(QObject* parent = 0);
    ~VideoReceiver();

48
#if defined(QGC_GST_STREAMING)
49 50 51 52 53
    bool            running         () { return _running;   }
    bool            recording       () { return _recording; }
    bool            streaming       () { return _streaming; }
    bool            starting        () { return _starting;  }
    bool            stopping        () { return _stopping;  }
54 55
#endif

56 57 58 59
    VideoSurface*   videoSurface    () { return _videoSurface; }
    bool            videoRunning    () { return _videoRunning; }
    QString         imageFile       () { return _imageFile; }
    bool            showFullScreen  () { return _showFullScreen; }
Gus Grubba's avatar
Gus Grubba committed
60

61 62 63
    void            grabImage       (QString imageFile);

    void        setShowFullScreen   (bool show) { _showFullScreen = show; emit showFullScreenChanged(); }
64 65

signals:
66 67 68
    void videoRunningChanged        ();
    void imageFileChanged           ();
    void showFullScreenChanged      ();
69
#if defined(QGC_GST_STREAMING)
70 71 72 73
    void recordingChanged           ();
    void msgErrorReceived           ();
    void msgEOSReceived             ();
    void msgStateChangedReceived    ();
74
#endif
75

76
public slots:
77 78 79 80 81
    void start                      ();
    void stop                       ();
    void setUri                     (const QString& uri);
    void stopRecording              ();
    void startRecording             ();
82

83
private slots:
84
    void _updateTimer               ();
85
#if defined(QGC_GST_STREAMING)
86 87 88 89 90 91
    void _timeout                   ();
    void _connected                 ();
    void _socketError               (QAbstractSocket::SocketError socketError);
    void _handleError               ();
    void _handleEOS                 ();
    void _handleStateChanged        ();
92
#endif
Gus Grubba's avatar
Gus Grubba committed
93 94

private:
95
#if defined(QGC_GST_STREAMING)
96

97 98
    typedef struct
    {
99 100 101 102
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
103
        GstElement*     parse;
104
        gboolean        removing;
105 106
    } Sink;

107
    bool                _running;
108
    bool                _recording;
109
    bool                _streaming;
110 111
    bool                _starting;
    bool                _stopping;
112 113
    Sink*               _sink;
    GstElement*         _tee;
114

115 116 117
    static gboolean             _onBusMessage           (GstBus* bus, GstMessage* message, gpointer user_data);
    static GstPadProbeReturn    _unlinkCallBack         (GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
    void                        _detachRecordingBranch  (GstPadProbeInfo* info);
118
    void                        _shutdownRecordingBranch();
119 120 121
    void                        _shutdownPipeline       ();
    void                        _cleanupOldVideos       ();
    void                        _setVideoSink           (GstElement* sink);
122

123 124 125
    GstElement*     _pipeline;
    GstElement*     _pipelineStopRec;
    GstElement*     _videoSink;
Gus Grubba's avatar
Gus Grubba committed
126

127 128 129 130 131
    //-- Wait for Video Server to show up before starting
    QTimer          _frameTimer;
    QTimer          _timer;
    QTcpSocket*     _socket;
    bool            _serverPresent;
132 133 134

#endif

135 136 137 138 139
    QString         _uri;
    QString         _imageFile;
    VideoSurface*   _videoSurface;
    bool            _videoRunning;
    bool            _showFullScreen;
Gus Grubba's avatar
Gus Grubba committed
140 141 142
};

#endif // VIDEORECEIVER_H