3#if defined(QGC_HAS_GST_CUDA_GPU_PATH)
5#include <gst/allocators/gstdmabuf.h>
6#include <gst/cuda/gstcuda.h>
7#include <gst/video/video.h>
13namespace GstCudaVideoBuffer {
18int exportCudaMemoryToFd(GstMemory* mem)
20 if (!gst_is_cuda_memory(mem)) {
23 auto* cudaMem =
reinterpret_cast<GstCudaMemory*
>(mem);
28 if (!gst_cuda_memory_export(cudaMem, &fd) || fd < 0) {
36std::unique_ptr<GstHwVideoBuffer> exportToDmaBuf(GstSample* sample,
const GstVideoInfo& info, QVideoFrameFormat format,
39 if (context.dmaBufEglDisplay == EGL_NO_DISPLAY) {
43 GstBuffer* buffer = gst_sample_get_buffer(sample);
50 GstMemory* mem0 = gst_buffer_peek_memory(buffer, 0);
51 const int fd = exportCudaMemoryToFd(mem0);
56 GstAllocator* allocator = gst_dmabuf_allocator_new();
63 GstMemory* dmaMem = gst_dmabuf_allocator_alloc(allocator, fd, gst_memory_get_sizes(mem0,
nullptr,
nullptr));
66 gst_object_unref(allocator);
70 GstBuffer* dmaBuffer = gst_buffer_new();
72 gst_memory_unref(dmaMem);
73 gst_object_unref(allocator);
76 gst_buffer_append_memory(dmaBuffer, dmaMem);
79 if (GstVideoMeta* srcMeta = gst_buffer_get_video_meta(buffer)) {
80 gst_buffer_add_video_meta_full(dmaBuffer, GST_VIDEO_FRAME_FLAG_NONE, srcMeta->format, srcMeta->width,
81 srcMeta->height, srcMeta->n_planes, srcMeta->offset, srcMeta->stride);
83 gst_buffer_add_video_meta(dmaBuffer, GST_VIDEO_FRAME_FLAG_NONE, GST_VIDEO_INFO_FORMAT(&info),
84 GST_VIDEO_INFO_WIDTH(&info), GST_VIDEO_INFO_HEIGHT(&info));
89 GstCaps* caps = gst_sample_get_caps(sample);
90 GstSample* dmaSample = gst_sample_new(dmaBuffer, caps,
nullptr,
nullptr);
91 gst_buffer_unref(dmaBuffer);
93 gst_object_unref(allocator);
98 auto buf = std::make_unique<GstDmaBufVideoBuffer>(dmaSample, info, format, context.dmaBufEglDisplay);
99 gst_sample_unref(dmaSample);
100 gst_object_unref(allocator);
Platform context for the factory; encapsulates EGL handles so callers don't need path-specific ifdefs...