QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstHwImportPreflight.cc
Go to the documentation of this file.
2
3#include <private/qvideotexturehelper_p.h>
4
6
7namespace {
8
9bool canImportTexture(QRhi& rhi, QRhiTexture::Format fmt, const QSize& size, QRhiTexture::Flags flags)
10{
11 if (fmt == QRhiTexture::UnknownFormat) {
12 return false;
13 }
14 if (!rhi.isTextureFormatSupported(fmt, flags)) {
15 return false;
16 }
17 const int maxDim = rhi.resourceLimit(QRhi::TextureSizeMax);
18 if (maxDim > 0 && (size.width() > maxDim || size.height() > maxDim)) {
19 return false;
20 }
21 return true;
22}
23
24bool canImportPlanes(QRhi& rhi, QVideoFrameFormat::PixelFormat pixelFormat, const QSize& size, QRhiTexture::Flags flags)
25{
26 const auto* desc = QVideoTextureHelper::textureDescription(pixelFormat);
27 if (!desc) {
28 return false;
29 }
30 // Disable the helper's own format fallback chain so the pre-flight tests the exact format createFrom() will use.
31 using FallbackPolicy = QVideoTextureHelper::TextureDescription::FallbackPolicy;
32 for (int plane = 0; plane < desc->nplanes; ++plane) {
33 const QRhiTexture::Format fmt = desc->rhiTextureFormat(plane, &rhi, FallbackPolicy::Disable);
34 const QSize planeSize = desc->rhiPlaneSize(size, plane, &rhi);
35 if (!canImportTexture(rhi, fmt, planeSize, flags)) {
36 return false;
37 }
38 }
39 return true;
40}
41
42} // namespace
43
45
46bool preflightOrRecord(QRhi& rhi, HwVideoBufferPath path, QVideoFrameFormat::PixelFormat pixelFormat, const QSize& size,
47 QRhiTexture::Flags flags)
48{
49 if (canImportPlanes(rhi, pixelFormat, size, flags)) {
50 return true;
51 }
52 // Recorded per call (not per epoch) to keep fallback counts frame-accurate.
54 return false;
55}
56
57} // namespace GstHwImportPreflight
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
Definition GstHwTypes.h:7
bool preflightOrRecord(QRhi &rhi, HwVideoBufferPath path, QVideoFrameFormat::PixelFormat pixelFormat, const QSize &size, QRhiTexture::Flags flags)
void recordFallbackReason(HwVideoBufferPath attemptedPath, HwFallbackReason reason) noexcept
Per-(path,reason) fallback accounting; lets a bug report show why a path demoted to CPU.