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 41 42 43
    Q_PROPERTY(VideoSurface*    videoSurface        READ    videoSurface        CONSTANT)
    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 60 61 62
    VideoSurface*   videoSurface    () { return _videoSurface; }
    bool            videoRunning    () { return _videoRunning; }
    QString         imageFile       () { return _imageFile; }
    bool            showFullScreen  () { return _showFullScreen; }
    void            grabImage       (QString imageFile);

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

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

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

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

private:
94
#if defined(QGC_GST_STREAMING)
95

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

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

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

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

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

#endif

134 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