VideoReceiver.h 5.38 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)

33 34
class VideoSettings;

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

Gus Grubba's avatar
Gus Grubba committed
48 49 50
    explicit VideoReceiver(QObject* parent = 0);
    ~VideoReceiver();

51
#if defined(QGC_GST_STREAMING)
52 53 54 55 56
    virtual bool            running         () { return _running;   }
    virtual bool            recording       () { return _recording; }
    virtual bool            streaming       () { return _streaming; }
    virtual bool            starting        () { return _starting;  }
    virtual bool            stopping        () { return _stopping;  }
57 58
#endif

59 60 61 62 63
    virtual VideoSurface*   videoSurface    () { return _videoSurface; }
    virtual bool            videoRunning    () { return _videoRunning; }
    virtual QString         imageFile       () { return _imageFile; }
    virtual QString         videoFile       () { return _videoFile; }
    virtual bool            showFullScreen  () { return _showFullScreen; }
Gus Grubba's avatar
Gus Grubba committed
64

65
    virtual void            grabImage       (QString imageFile);
66

67
    virtual void        setShowFullScreen   (bool show) { _showFullScreen = show; emit showFullScreenChanged(); }
68 69

signals:
70 71 72 73
    void videoRunningChanged                ();
    void imageFileChanged                   ();
    void videoFileChanged                   ();
    void showFullScreenChanged              ();
74
#if defined(QGC_GST_STREAMING)
75 76 77 78
    void recordingChanged                   ();
    void msgErrorReceived                   ();
    void msgEOSReceived                     ();
    void msgStateChangedReceived            ();
79
#endif
80

81
public slots:
82 83 84 85 86 87 88 89
    virtual void start                      ();
    virtual void stop                       ();
    virtual void setUri                     (const QString& uri);
    virtual void stopRecording              ();
    virtual void startRecording             (const QString& videoFile = QString());

protected slots:
    virtual void _updateTimer               ();
90
#if defined(QGC_GST_STREAMING)
91 92 93 94 95 96
    virtual void _timeout                   ();
    virtual void _connected                 ();
    virtual void _socketError               (QAbstractSocket::SocketError socketError);
    virtual void _handleError               ();
    virtual void _handleEOS                 ();
    virtual void _handleStateChanged        ();
97
#endif
Gus Grubba's avatar
Gus Grubba committed
98

99
protected:
100
#if defined(QGC_GST_STREAMING)
101

102 103
    typedef struct
    {
104 105 106 107
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
108
        GstElement*     parse;
109
        gboolean        removing;
110 111
    } Sink;

112
    bool                _running;
113
    bool                _recording;
114
    bool                _streaming;
115 116
    bool                _starting;
    bool                _stopping;
117
    bool                _stop;
118 119
    Sink*               _sink;
    GstElement*         _tee;
120

121 122
    static gboolean             _onBusMessage           (GstBus* bus, GstMessage* message, gpointer user_data);
    static GstPadProbeReturn    _unlinkCallBack         (GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
123
    static GstPadProbeReturn    _keyframeWatch          (GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
124 125 126 127 128 129

    virtual void                _detachRecordingBranch  (GstPadProbeInfo* info);
    virtual void                _shutdownRecordingBranch();
    virtual void                _shutdownPipeline       ();
    virtual void                _cleanupOldVideos       ();
    virtual void                _setVideoSink           (GstElement* sink);
130

131 132 133
    GstElement*     _pipeline;
    GstElement*     _pipelineStopRec;
    GstElement*     _videoSink;
Gus Grubba's avatar
Gus Grubba committed
134

135 136 137 138 139
    //-- Wait for Video Server to show up before starting
    QTimer          _frameTimer;
    QTimer          _timer;
    QTcpSocket*     _socket;
    bool            _serverPresent;
140
    int             _rtspTestInterval_ms;
141 142 143

#endif

144 145
    QString         _uri;
    QString         _imageFile;
146
    QString         _videoFile;
147 148 149
    VideoSurface*   _videoSurface;
    bool            _videoRunning;
    bool            _showFullScreen;
150
    VideoSettings*  _videoSettings;
Gus Grubba's avatar
Gus Grubba committed
151 152 153
};

#endif // VIDEORECEIVER_H