Merged in f5soh/librepilot/LP-575_fedora_package (pull request #491)
[librepilot.git] / ground / gcs / src / libs / gstreamer / pipelineevent.h
blob3dfdc0a4e78616384ab557b6b3780ab9d53ce116
1 /**
2 ******************************************************************************
4 * @file pipelineevent.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 * @brief
7 * @see The GNU Public License (GPL) Version 3
8 * @defgroup
9 * @{
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef PIPELINEEVENT_H_
28 #define PIPELINEEVENT_H_
30 #include <QEvent>
31 #include <QString>
33 #include "pipeline.h"
34 #include "overlay.h"
36 class PipelineEvent : public QEvent {
37 public:
38 // event types
39 static const QEvent::Type PrepareWindowId;
40 static const QEvent::Type StateChange;
41 static const QEvent::Type StreamStatus;
42 static const QEvent::Type NewClock;
43 static const QEvent::Type ClockProvide;
44 static const QEvent::Type ClockLost;
45 static const QEvent::Type Progress;
46 static const QEvent::Type Latency;
47 static const QEvent::Type Qos;
48 static const QEvent::Type Eos;
49 static const QEvent::Type Error;
50 static const QEvent::Type Warning;
51 static const QEvent::Type Info;
53 PipelineEvent(QEvent::Type type, QString src) :
54 QEvent(type), src(src)
56 virtual ~PipelineEvent()
58 public:
59 QString src;
62 const QEvent::Type PipelineEvent::PrepareWindowId = static_cast<QEvent::Type>(QEvent::registerEventType());
63 const QEvent::Type PipelineEvent::StateChange = static_cast<QEvent::Type>(QEvent::registerEventType());
64 const QEvent::Type PipelineEvent::StreamStatus = static_cast<QEvent::Type>(QEvent::registerEventType());
65 const QEvent::Type PipelineEvent::NewClock = static_cast<QEvent::Type>(QEvent::registerEventType());
66 const QEvent::Type PipelineEvent::ClockProvide = static_cast<QEvent::Type>(QEvent::registerEventType());
67 const QEvent::Type PipelineEvent::ClockLost = static_cast<QEvent::Type>(QEvent::registerEventType());
68 const QEvent::Type PipelineEvent::Progress = static_cast<QEvent::Type>(QEvent::registerEventType());
69 const QEvent::Type PipelineEvent::Latency = static_cast<QEvent::Type>(QEvent::registerEventType());
70 const QEvent::Type PipelineEvent::Qos = static_cast<QEvent::Type>(QEvent::registerEventType());
71 const QEvent::Type PipelineEvent::Eos = static_cast<QEvent::Type>(QEvent::registerEventType());
72 const QEvent::Type PipelineEvent::Error = static_cast<QEvent::Type>(QEvent::registerEventType());
73 const QEvent::Type PipelineEvent::Warning = static_cast<QEvent::Type>(QEvent::registerEventType());
74 const QEvent::Type PipelineEvent::Info = static_cast<QEvent::Type>(QEvent::registerEventType());
76 class PrepareWindowIdEvent : public PipelineEvent {
77 public:
78 PrepareWindowIdEvent(QString src, Overlay *overlay) :
79 PipelineEvent(PrepareWindowId, src), overlay(overlay)
81 Overlay *getOverlay()
83 return overlay;
85 static QEvent::Type type()
87 return PrepareWindowId;
89 private:
90 Overlay *overlay;
93 class StateChangedEvent : public PipelineEvent {
94 public:
95 StateChangedEvent(QString src, Pipeline::State oldState, Pipeline::State newState, Pipeline::State pendingState) :
96 PipelineEvent(StateChange, src), oldState(oldState), newState(newState), pendingState(pendingState)
98 static QEvent::Type type()
100 return StateChange;
102 Pipeline::State getOldState()
104 return oldState;
106 Pipeline::State getNewState()
108 return newState;
110 Pipeline::State getPendingState()
112 return pendingState;
114 static const char *stateName(Pipeline::State state)
116 switch (state) {
117 case Pipeline::VoidPending:
118 return "VoidPending";
120 case Pipeline::Null:
121 return "Null";
123 case Pipeline::Ready:
124 return "Ready";
126 case Pipeline::Paused:
127 return "Paused";
129 case Pipeline::Playing:
130 return "Playing";
132 return "<unknown>";
134 private:
135 Pipeline::State oldState;
136 Pipeline::State newState;
137 Pipeline::State pendingState;
140 class StreamStatusEvent : public PipelineEvent {
141 public:
142 enum StreamStatusType {
143 Create, Enter, Leave, Destroy, Start, Pause, Stop, Null
145 StreamStatusEvent(QString src, StreamStatusType status, QString owner) :
146 PipelineEvent(StreamStatus, src), status(status), owner(owner)
148 static QEvent::Type type()
150 return StreamStatus;
152 StreamStatusType getStatus()
154 return status;
156 const char *getStatusName()
158 return statusName(status);
160 static const char *statusName(StreamStatusType status)
162 switch (status) {
163 case StreamStatusEvent::Create:
164 return "Create";
166 case StreamStatusEvent::Enter:
167 return "Enter";
169 case StreamStatusEvent::Leave:
170 return "Leave";
172 case StreamStatusEvent::Destroy:
173 return "Destroy";
175 case StreamStatusEvent::Start:
176 return "Start";
178 case StreamStatusEvent::Pause:
179 return "Pause";
181 case StreamStatusEvent::Stop:
182 return "Stop";
184 case StreamStatusEvent::Null:
185 return "Null";
187 return "<unknown>";
189 QString getOwner()
191 return owner;
193 private:
194 StreamStatusType status;
195 QString owner;
198 class ClockEvent : public PipelineEvent {
199 public:
200 ClockEvent(QEvent::Type type, QString src, QString name) : PipelineEvent(type, src), name(name)
202 QString getName()
204 return name;
206 private:
207 QString name;
210 class NewClockEvent : public ClockEvent {
211 public:
212 NewClockEvent(QString src, QString name) : ClockEvent(NewClock, src, name)
214 static QEvent::Type type()
216 return NewClock;
220 class ClockProvideEvent : public ClockEvent {
221 public:
222 ClockProvideEvent(QString src, QString name, bool ready) : ClockEvent(ClockProvide, src, name), ready(ready)
224 static QEvent::Type type()
226 return ClockProvide;
228 bool isReady()
230 return ready;
232 private:
233 bool ready;
237 class ClockLostEvent : public ClockEvent {
238 public:
239 ClockLostEvent(QString src, QString name) : ClockEvent(ClockLost, src, name)
241 static QEvent::Type type()
243 return ClockLost;
247 class ProgressEvent : public PipelineEvent {
248 public:
249 enum ProgressType {
250 Start, Continue, Complete, Cancelled, Error
253 ProgressEvent(QString src, ProgressType progressType, QString code, QString text) :
254 PipelineEvent(Progress, src), progressType(progressType), code(code), text(text)
256 static QEvent::Type type()
258 return Progress;
260 ProgressType getProgressType()
262 return progressType;
264 QString getCode()
266 return code;
268 QString getText()
270 return text;
272 private:
273 ProgressType progressType;
274 QString code;
275 QString text;
278 class LatencyEvent : public PipelineEvent {
279 public:
280 LatencyEvent(QString src) :
281 PipelineEvent(Latency, src)
283 static QEvent::Type type()
285 return Latency;
289 class QosData {
290 public:
291 // timestamps and live status
292 // If the message was generated by a live element
293 bool live;
294 // running_time, stream_time, timestamp and duration of the dropped buffer.
295 // Values of GST_CLOCK_TIME_NONE mean unknown values.
296 quint64 running_time;
297 quint64 stream_time;
298 quint64 timestamp;
299 quint64 duration;
301 // values
302 // The difference of the running-time against the deadline.
303 qint64 jitter;
304 // Long term prediction of the ideal rate relative to normal rate to get optimal quality.
305 qreal proportion; // won't work on ARM?
306 // An element dependent integer value that specifies the current quality level of the element.
307 // The default maximum quality is 1000000.
308 qint32 quality;
310 // stats
311 // QoS stats representing the history of the current continuous pipeline playback period.
312 // When format is GST_FORMAT_UNDEFINED both dropped and processed are invalid.
313 // Values of -1 for either processed or dropped mean unknown values.
315 // Units of the 'processed' and 'dropped' fields.
316 // Video sinks and video filters will use GST_FORMAT_BUFFERS (frames).
317 // Audio sinks and audio filters will likely use GST_FORMAT_DEFAULT (samples)
318 // GstFormat format;
319 // Total number of units correctly processed since the last state change to READY or a flushing operation.
320 quint64 processed;
321 // Total number of units dropped since the last state change to READY or a flushing operation.
322 quint64 dropped;
324 QString timestamps()
326 return QString("live: %0; running time: %1; stream time: %2; timestamp: %3; duration: %4").arg(live).arg(
327 running_time).arg(stream_time).arg(timestamp).arg(duration);
329 QString values()
331 return QString("jitter: %0; proportion: %1; quality: %2;").arg(jitter).arg(proportion).arg(quality);
333 QString stats()
335 return QString("format: %0; processed: %1; dropped: %2;").arg("").arg(processed).arg(dropped);
339 class QosEvent : public PipelineEvent {
340 public:
341 QosEvent(QString src, QosData data) : PipelineEvent(Qos, src), data(data)
343 static QEvent::Type type()
345 return Qos;
347 QosData getData()
349 return data;
351 private:
352 QosData data;
355 class EosEvent : public PipelineEvent {
356 public:
357 EosEvent(QString src) : PipelineEvent(Eos, src)
359 static QEvent::Type type()
361 return Eos;
365 class MessageEvent : public PipelineEvent {
366 public:
367 MessageEvent(QEvent::Type type, QString src, QString message, QString debug) :
368 PipelineEvent(type, src), message(message), debug(debug)
370 QString getMessage()
372 return message;
374 QString getDebug()
376 return debug;
378 private:
379 QString message;
380 QString debug;
383 class ErrorEvent : public MessageEvent {
384 public:
385 ErrorEvent(QString src, QString message, QString debug) : MessageEvent(Error, src, message, debug)
387 static QEvent::Type type()
389 return Error;
393 class WarningEvent : public MessageEvent {
394 public:
395 WarningEvent(QString src, QString message, QString debug) : MessageEvent(Warning, src, message, debug)
397 static QEvent::Type type()
399 return Warning;
403 class InfoEvent : public MessageEvent {
404 public:
405 InfoEvent(QString src, QString message, QString debug) : MessageEvent(Info, src, message, debug)
407 static QEvent::Type type()
409 return Info;
413 #endif /* PIPELINEEVENT_H_ */