QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstQgcVideoFormats.h
Go to the documentation of this file.
1#pragma once
2
3#include <gst/video/video-format.h>
4#include <string>
5#include <vector>
6
7#include <QtMultimedia/QVideoFrameFormat>
8
9namespace GstQgc {
10
14inline constexpr unsigned kOfferGlUpload = 1u << 0;
16inline constexpr unsigned kOfferDmaDrm = 1u << 1;
17
23{
24 GstVideoFormat gst;
25 QVideoFrameFormat::PixelFormat qt;
26 const char* capsToken;
27 unsigned offers = 0;
28};
29
30inline constexpr VideoFormatEntry kVideoFormatTable[] = {
31 // Advertised set — order is preserved in the generated caps string (negotiation preference order).
32 {GST_VIDEO_FORMAT_NV12, QVideoFrameFormat::Format_NV12, "NV12", kOfferDmaDrm},
33 {GST_VIDEO_FORMAT_NV21, QVideoFrameFormat::Format_NV21, "NV21", kOfferDmaDrm},
34 {GST_VIDEO_FORMAT_I420, QVideoFrameFormat::Format_YUV420P, "I420", kOfferDmaDrm},
35 {GST_VIDEO_FORMAT_YV12, QVideoFrameFormat::Format_YV12, "YV12", kOfferDmaDrm},
36 {GST_VIDEO_FORMAT_Y42B, QVideoFrameFormat::Format_YUV422P, "Y42B"},
37 {GST_VIDEO_FORMAT_P010_10LE, QVideoFrameFormat::Format_P010, "P010_10LE", kOfferDmaDrm},
38 // What software decoders send for 10-bit 4:2:0 (avdec's Main 10): samples in the low bits, as Qt's shader reads
39 // them. Qt has no CPU conversion for it, so QVideoFrame::toImage() needs a QRhi.
40 {GST_VIDEO_FORMAT_I420_10LE, QVideoFrameFormat::Format_YUV420P10, "I420_10LE"},
41 {GST_VIDEO_FORMAT_AYUV, QVideoFrameFormat::Format_AYUV, "AYUV"},
42 {GST_VIDEO_FORMAT_YUY2, QVideoFrameFormat::Format_YUYV, "YUY2"},
43 {GST_VIDEO_FORMAT_UYVY, QVideoFrameFormat::Format_UYVY, "UYVY"},
44 {GST_VIDEO_FORMAT_GRAY8, QVideoFrameFormat::Format_Y8, "GRAY8"},
45 {GST_VIDEO_FORMAT_GRAY16_LE, QVideoFrameFormat::Format_Y16, "GRAY16_LE"},
46 {GST_VIDEO_FORMAT_BGRA, QVideoFrameFormat::Format_BGRA8888, "BGRA", kOfferGlUpload | kOfferDmaDrm},
47 {GST_VIDEO_FORMAT_RGBA, QVideoFrameFormat::Format_RGBA8888, "RGBA", kOfferGlUpload | kOfferDmaDrm},
48 // Accepted but not advertised: mapped defensively if upstream or a GPU path delivers them anyway.
49 {GST_VIDEO_FORMAT_BGRx, QVideoFrameFormat::Format_BGRX8888, nullptr},
50 {GST_VIDEO_FORMAT_RGBx, QVideoFrameFormat::Format_RGBX8888, nullptr},
51 {GST_VIDEO_FORMAT_ARGB, QVideoFrameFormat::Format_ARGB8888, nullptr},
52 {GST_VIDEO_FORMAT_xRGB, QVideoFrameFormat::Format_XRGB8888, nullptr},
53 {GST_VIDEO_FORMAT_P016_LE, QVideoFrameFormat::Format_P016, nullptr},
54 // GST_VIDEO_FORMAT_BGR/RGB intentionally absent: Qt6 has no 24-bit packed format, so they resolve to
55 // Format_Invalid (the lookup default) rather than corrupting stride arithmetic.
56};
57
59inline std::vector<GstVideoFormat> advertisedFormats(unsigned requiredOffers = 0)
60{
61 std::vector<GstVideoFormat> out;
62 for (const auto& e : kVideoFormatTable) {
63 if (e.capsToken && ((e.offers & requiredOffers) == requiredOffers)) {
64 out.push_back(e.gst);
65 }
66 }
67 return out;
68}
69
72inline std::string advertisedFormatList(unsigned requiredOffers = 0)
73{
74 std::string out = "{ ";
75 bool first = true;
76 for (const auto& e : kVideoFormatTable) {
77 if (!e.capsToken || ((e.offers & requiredOffers) != requiredOffers)) {
78 continue;
79 }
80 if (!first) {
81 out += ", ";
82 }
83 out += e.capsToken;
84 first = false;
85 }
86 out += " }";
87 return out;
88}
89
90} // namespace GstQgc
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
constexpr unsigned kOfferDmaDrm
The EGL-derived DMA_DRM caps: formats the DMABuf importer takes with an explicit modifier.
constexpr unsigned kOfferGlUpload
std::vector< GstVideoFormat > advertisedFormats(unsigned requiredOffers=0)
The advertised formats carrying every flag in requiredOffers, in table order.
std::string advertisedFormatList(unsigned requiredOffers=0)
constexpr VideoFormatEntry kVideoFormatTable[]
unsigned offers
kOffer* flags; meaningful for advertised entries only.
const char * capsToken
non-null: advertised in negotiation caps; null: accepted-only (defensive map).
QVideoFrameFormat::PixelFormat qt