QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstDmaBufVulkanImport.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/qglobal.h>
4
5#if defined(QGC_HAS_GST_DMABUF_VULKAN_IMPORT)
6
7#include <array>
8#include <functional>
9#include <gst/gst.h>
10#include <span>
11#include <vector>
12#include <vulkan/vulkan.h>
13
14#include <QtCore/QSize>
15#include <QtMultimedia/QVideoFrameFormat>
16
18#include "GstQtDmaBufImport.h"
19
24namespace GstDmaBufVulkan {
25
28void requestDeviceExtensions();
29
33void probeDevice(QRhi& rhi);
34
37void* importDevice() noexcept;
38
42bool canImport(const GstQtDmaBufImport::PlaneFourccs& planeFourccs, quint64 modifier);
43
45std::vector<quint64> importableModifiers(quint32 planeFourcc);
46
50QVideoFrameTexturesUPtr importTextures(GstHwVideoBuffer& source, QRhi& rhi, QVideoFrameTexturesUPtr& old,
51 std::span<const GstQtDmaBufImport::Plane> planes,
52 QVideoFrameFormat::PixelFormat pixelFormat, QSize frameSize, GstBuffer* buffer,
53 bool& rejected);
54
56void resetCachedState() noexcept;
57
58} // namespace GstDmaBufVulkan
59
61class GstVulkanOwnedFrameTextures final : public GstHwFrameTexturesBase
62{
63public:
64 GstVulkanOwnedFrameTextures(QRhi* rhi, QSize size, QVideoFrameFormat::PixelFormat pixelFormat,
65 std::span<const VkImage> images)
66 {
67 // QRhi's first barrier transitions from this layout; UNDEFINED would let the driver discard the imported
68 // contents, GENERAL preserves them.
69 wrapPlanes(rhi, size, pixelFormat, images, VK_IMAGE_LAYOUT_GENERAL);
70 }
71
72 ~GstVulkanOwnedFrameTextures() override
73 {
74 // The QRhiTextures must be gone before the VkImages they wrap.
75 for (auto& texture : _textures) {
76 texture.reset();
77 }
78 if (_release) {
79 _release();
80 }
81 }
82
84 void adoptVulkanResources(std::function<void()> release) noexcept { _release = std::move(release); }
85
86private:
87 std::function<void()> _release;
88};
89
90#endif // QGC_HAS_GST_DMABUF_VULKAN_IMPORT