QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstVideoReceiver.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QMutex>
5#include <QtCore/QQueue>
6#include <QtCore/QThread>
7#include <QtCore/QTimer>
8#include <QtCore/QWaitCondition>
9
10#include <glib.h>
11#include <gst/gstelement.h>
12#include <gst/gstpad.h>
13
14#include "VideoReceiver.h"
15
16Q_DECLARE_LOGGING_CATEGORY(GstVideoReceiverLog)
17
18typedef std::function<void()> Task;
19
20/*===========================================================================*/
21
22class GstVideoWorker : public QThread
23{
24 Q_OBJECT
25
26public:
27 explicit GstVideoWorker(QObject *parent = nullptr);
29 bool needDispatch() const;
30 void dispatch(Task task);
31 void shutdown();
32
33private:
34 void run() final;
35
36 QWaitCondition _taskQueueUpdate;
37 QMutex _taskQueueSync;
38 QQueue<Task> _taskQueue;
39 bool _shutdown = false;
40};
41
42/*===========================================================================*/
43
44typedef struct _GstElement GstElement;
45
47{
48 Q_OBJECT
49
50public:
51 explicit GstVideoReceiver(QObject *parent = nullptr);
53
54public slots:
55 void start(uint32_t timeout) override;
56 void stop() override;
57 void startDecoding(void *sink) override;
58 void stopDecoding() override;
59 void startRecording(const QString &videoFile, FILE_FORMAT format) override;
60 void stopRecording() override;
61 void takeScreenshot(const QString &imageFile) override;
62
63private slots:
64 void _watchdog();
65 void _handleEOS();
66
67private:
68 GstElement *_makeSource(const QString &input);
69 GstElement *_makeDecoder(GstCaps *caps = nullptr, GstElement *videoSink = nullptr);
70 GstElement *_makeFileSink(const QString &videoFile, FILE_FORMAT format);
71
72 void _onNewSourcePad(GstPad *pad);
73 void _onNewDecoderPad(GstPad *pad);
74 bool _addDecoder(GstElement *src);
75 bool _addVideoSink(GstPad *pad);
76 void _noteTeeFrame();
77 void _noteVideoSinkFrame();
78 void _noteEndOfStream();
81 bool _unlinkBranch(GstElement *from);
82 void _shutdownDecodingBranch();
83 void _shutdownRecordingBranch();
84 void _logDecodebin3SelectedCodec(GstElement *decodebin3);
85
86 bool _needDispatch();
87 void _dispatchSignal(Task emitter);
88
89 static gboolean _onBusMessage(GstBus *bus, GstMessage *message, gpointer user_data);
90 static void _onNewPad(GstElement *element, GstPad *pad, gpointer data);
91 static void _wrapWithGhostPad(GstElement *element, GstPad *pad, gpointer data);
92 static void _linkPad(GstElement *element, GstPad *pad, gpointer data);
93 static gboolean _padProbe(GstElement *element, GstPad *pad, gpointer user_data);
94 static gboolean _filterParserCaps(GstElement *bin, GstPad *pad, GstElement *element, GstQuery *query, gpointer data);
95 static GstPadProbeReturn _teeProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
96 static GstPadProbeReturn _videoSinkProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
97 static GstPadProbeReturn _eosProbe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
98 static GstPadProbeReturn _keyframeWatch(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
99
100 GstElement *_decoder = nullptr;
101 GstElement *_decoderValve = nullptr;
102 GstElement *_fileSink = nullptr;
103 GstElement *_pipeline = nullptr;
104 GstElement *_recorderValve = nullptr;
105 GstElement *_source = nullptr;
106 GstElement *_tee = nullptr;
107 GstElement *_videoSink = nullptr;
108 GstVideoWorker *_worker = nullptr;
109 gulong _teeProbeId = 0;
110 gulong _videoSinkProbeId = 0;
111
112 static constexpr const char *_kFileMux[FILE_FORMAT_MAX + 1] = {
113 "matroskamux",
114 "qtmux",
115 "mp4mux"
116 };
117};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
std::function< void()> Task
struct _GstElement GstElement
void stopDecoding() override
void takeScreenshot(const QString &imageFile) override
void start(uint32_t timeout) override
void stopRecording() override
void startRecording(const QString &videoFile, FILE_FORMAT format) override
void stop() override
void startDecoding(void *sink) override