VideoReceiver.h 5.08 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
    bool            running         () { return _running;   }
    bool            recording       () { return _recording; }
    bool            streaming       () { return _streaming; }
    bool            starting        () { return _starting;  }
    bool            stopping        () { return _stopping;  }
57 58
#endif

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

65 66 67
    void            grabImage       (QString imageFile);

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

signals:
70 71
    void videoRunningChanged        ();
    void imageFileChanged           ();
72
    void videoFileChanged           ();
73
    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
    void start                      ();
    void stop                       ();
    void setUri                     (const QString& uri);
    void stopRecording              ();
86
    void startRecording             (const QString& videoFile = QString());
87

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

private:
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
    void                        _detachRecordingBranch  (GstPadProbeInfo* info);
125
    void                        _shutdownRecordingBranch();
126 127 128
    void                        _shutdownPipeline       ();
    void                        _cleanupOldVideos       ();
    void                        _setVideoSink           (GstElement* sink);
129

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

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

#endif

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

#endif // VIDEORECEIVER_H