13std::unique_ptr<QHwVideoBuffer>
makeHwVideoBuffer(GstBuffer* buffer, GstCaps* caps, const GstVideoInfo& info,
18 if (!context.gpuEnabled || !buffer) {
24 GstMemory* mem0 = gst_buffer_peek_memory(buffer, 0);
28 const GType allocatorType = mem0->allocator ? G_OBJECT_TYPE(mem0->allocator) : G_TYPE_INVALID;
29 if (cache && (allocatorType != G_TYPE_INVALID) && (allocatorType == cache->unmatchedAllocator)) {
34 auto buildOrFallback = [&matchedPath, &info, cache](
auto&& buf) -> std::unique_ptr<QHwVideoBuffer> {
35 if (!buf || !buf->validatePlaneHandles()) {
39 if (!cache || !std::exchange(cache->validationFailureLogged,
true)) {
40 qCWarning(GstHwBufFactoryLog)
41 <<
GstHw::toString(matchedPath) <<
"buffer failed plane-handle validation — CPU fallback";
44 cache->validated =
false;
49 if (cache && !cache->validated) {
50 qCDebug(GstHwBufFactoryLog).noquote()
52 <<
"format=" << gst_video_format_to_string(GST_VIDEO_INFO_FORMAT(&info)) << GST_VIDEO_INFO_WIDTH(&info)
53 <<
"x" << GST_VIDEO_INFO_HEIGHT(&info);
56 cache->path = matchedPath;
57 cache->validated =
true;
63 auto importThrough = [&](
const HwPathDescriptor& path) -> std::unique_ptr<QHwVideoBuffer> {
64 if (path.admits && !path.admits(mem0, context)) {
66 cache->validated =
false;
70 matchedPath = path.path;
72 GstSample*
const sample = gst_sample_new(buffer, caps,
nullptr,
nullptr);
73 auto imported = buildOrFallback(path.construct(sample, info, format, context));
74 gst_sample_unref(sample);
83 for (
const HwPathDescriptor* path : paths) {
84 if ((path->path == cache->path) && path->matches(mem0)) {
85 return importThrough(*path);
88 cache->validated =
false;
91 for (
const HwPathDescriptor* path : paths) {
92 if (path->matches(mem0)) {
93 return importThrough(*path);
99 cache->unmatchedAllocator = allocatorType;
101 qCDebug(GstHwBufFactoryLog) <<
"no zero-copy path for memory type"
102 << (mem0->allocator ? mem0->allocator->mem_type :
"<no-allocator>")
103 <<
"— falling back to CPU";
std::unique_ptr< QHwVideoBuffer > makeHwVideoBuffer(GstBuffer *buffer, GstCaps *caps, const GstVideoInfo &info, QVideoFrameFormat format, const HwVideoBufferContext &context, HwVideoBufferPath &matchedPath, HwResolvedPathCache *cache)