VideoReceiver.h 4.67 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 45
    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)
46

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

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

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

63 64 65
    void            grabImage       (QString imageFile);

    void        setShowFullScreen   (bool show) { _showFullScreen = show; emit showFullScreenChanged(); }
66 67

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

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

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

private:
97
#if defined(QGC_GST_STREAMING)
98

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

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

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

125 126 127
    GstElement*     _pipeline;
    GstElement*     _pipelineStopRec;
    GstElement*     _videoSink;
Gus Grubba's avatar
Gus Grubba committed
128

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

#endif

137 138 139 140 141
    QString         _uri;
    QString         _imageFile;
    VideoSurface*   _videoSurface;
    bool            _videoRunning;
    bool            _showFullScreen;
142
    VideoSettings*  _videoSettings;
Gus Grubba's avatar
Gus Grubba committed
143 144 145
};

#endif // VIDEORECEIVER_H