QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstQgcSinkStats.cc
Go to the documentation of this file.
1#include "GstQgcSinkStats.h"
2
3#include <array>
4
5#include <QtCore/QByteArray>
6
7#include "gstqgcqvideosink.h"
9
10namespace GstQgc {
11
13{
14 static const std::array<QByteArray, GstHw::kPathCount> s_fields = [] {
15 std::array<QByteArray, GstHw::kPathCount> fields;
16 for (std::size_t i = 0; i < fields.size(); ++i) {
17 fields[i] = QByteArray("frames-") + QByteArray(GstHw::toString(HwVideoBufferPath(i))).toLower();
18 }
19 return fields;
20 }();
21 const auto index = static_cast<std::size_t>(path);
22 return (index < s_fields.size()) ? s_fields[index].constData() : nullptr;
23}
24
26{
28 if (sinkOrBin && GST_IS_QGC_VIDEO_SINK_BIN(sinkOrBin)) {
29 inner = GStreamer::adoptElement(gst_qgc_video_sink_bin_get_qvideosink(GST_QGC_VIDEO_SINK_BIN(sinkOrBin)));
30 sinkOrBin = inner.get();
31 }
32 if (!sinkOrBin || !GST_IS_QGC_Q_VIDEO_SINK(sinkOrBin)) {
33 return {};
34 }
35 GstStructure* stats = nullptr;
36 g_object_get(sinkOrBin, "frame-stats", &stats, nullptr);
37 return GStreamer::adoptStructure(stats);
38}
39
40PathStats formatSinkStats(const GstStructure* stats, const GstStructure* since)
41{
42 PathStats out;
43 if (!stats) {
44 return out;
45 }
46 for (std::size_t i = 0; i < GstHw::kPathCount; ++i) {
47 const auto path = HwVideoBufferPath(i);
48 if (const quint64 frames = frameStatsGrowth(stats, since, sinkFramesField(path)); frames > 0) {
49 out.line += QStringLiteral(" %1:%2").arg(QLatin1String(GstHw::toString(path))).arg(frames);
50 if (path != HwVideoBufferPath::None) {
51 out.totalDelivered += frames;
52 }
53 }
54 }
55 for (const char* const field : {kGpuFallbacksField, kStreamDemotionsField, kTiledDropsField}) {
56 if (const quint64 count = frameStatsGrowth(stats, since, field); count > 0) {
57 out.line += QStringLiteral(" %1:%2").arg(QLatin1String(field)).arg(count);
58 }
59 }
60 return out;
61}
62
63} // namespace GstQgc
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
Definition GstHwTypes.h:7
struct _GstElement GstElement
GstElement * gst_qgc_video_sink_bin_get_qvideosink(GstQgcVideoSinkBin *self)
Returns the internal qgcqvideosink element, transfer-full (caller unrefs); NULL if not yet constructe...
GstStructurePtr adoptStructure(GstStructure *structure) noexcept
Definition GstScoped.h:129
std::unique_ptr< GstStructure, GstStructureDeleter > GstStructurePtr
Definition GstScoped.h:70
std::unique_ptr< GstElement, GstObjectDeleter > GstElementPtr
Definition GstScoped.h:60
GstElementPtr adoptElement(GstElement *element) noexcept
Definition GstScoped.h:79
constexpr std::size_t kPathCount
Definition GstHwTypes.h:33
constexpr const char * toString(HwVideoBufferPath path) noexcept
Definition GstHwTypes.h:37
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
const char * sinkFramesField(HwVideoBufferPath path)
quint64 frameStatsGrowth(const GstStructure *stats, const GstStructure *since, const char *field) noexcept
How far the guint64 field grew from since to stats, two "frame-stats" values of the same sink.
PathStats formatSinkStats(const GstStructure *stats, const GstStructure *since)
constexpr const char * kGpuFallbacksField
guint64 "frame-stats" field holding the frames a GPU path was tried for but the CPU delivered.
constexpr const char * kStreamDemotionsField
guint64 "frame-stats" field holding the caps epochs that started on a GPU path and fell back to the C...
GStreamer::GstStructurePtr frameStats(GstElement *sinkOrBin)
The "frame-stats" of sinkOrBin, a qgcqvideosink or the qgcvideosinkbin around one; null for other ele...
constexpr const char * kTiledDropsField
Formatted per-path frame counts + the total delivered through GPU paths.