va: caps: centralize caps feature discovering

These function were repeated in the different implemented
elements. This patch centralize them.

The side effect is dmabuf memory type is no longer checked with the
current VAContext, but assuming that dmabuf is a consequence of caps
negotiation from dynamic generated caps templates, where the context's
memory types are validated, there's no need to validate them twice.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1644>
This commit is contained in:
Víctor Manuel Jáquez Leal 2020-10-04 16:33:47 +02:00 committed by GStreamer Merge Bot
parent 3653c19de3
commit 666eedc215
5 changed files with 37 additions and 58 deletions

View file

@ -24,6 +24,8 @@
#include "gstvacaps.h" #include "gstvacaps.h"
#include <gst/allocators/allocators.h>
#include <va/va_drmcommon.h> #include <va/va_drmcommon.h>
#include "gstvadisplay.h" #include "gstvadisplay.h"
@ -478,3 +480,27 @@ gst_va_caps_from_profiles (GstVaDisplay * display, GArray * profiles,
return ret; return ret;
} }
static inline gboolean
_caps_is (GstCaps * caps, const gchar * feature)
{
GstCapsFeatures *features;
if (!gst_caps_is_fixed (caps))
return FALSE;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, feature);
}
gboolean
gst_caps_is_dmabuf (GstCaps * caps)
{
return _caps_is (caps, GST_CAPS_FEATURE_MEMORY_DMABUF);
}
gboolean
gst_caps_is_vamemory (GstCaps * caps)
{
return _caps_is (caps, "memory:VAMemory");
}

View file

@ -40,5 +40,8 @@ GstCaps * gst_va_create_raw_caps_from_config (GstVaDisplay * displa
gboolean gst_caps_set_format_array (GstCaps * caps, gboolean gst_caps_set_format_array (GstCaps * caps,
GArray * formats); GArray * formats);
gboolean gst_caps_is_dmabuf (GstCaps * caps);
gboolean gst_caps_is_vamemory (GstCaps * caps);
G_END_DECLS G_END_DECLS

View file

@ -1048,26 +1048,6 @@ gst_va_h264_dec_negotiate (GstVideoDecoder * decoder)
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder); return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
} }
static inline gboolean
_caps_is_dmabuf (GstVaH264Dec * self, GstCaps * caps)
{
GstCapsFeatures *features;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF)
&& (gst_va_decoder_get_mem_types (self->decoder)
& VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME);
}
static inline gboolean
_caps_is_va_memory (GstCaps * caps)
{
GstCapsFeatures *features;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, "memory:VAMemory");
}
static inline void static inline void
_shall_copy_frames (GstVaH264Dec * self, GstVideoInfo * info) _shall_copy_frames (GstVaH264Dec * self, GstVideoInfo * info)
{ {
@ -1114,7 +1094,7 @@ _try_allocator (GstVaH264Dec * self, GstAllocator * allocator, GstCaps * caps,
} else if (GST_IS_VA_ALLOCATOR (allocator)) { } else if (GST_IS_VA_ALLOCATOR (allocator)) {
if (!gst_va_allocator_try (allocator, &params)) if (!gst_va_allocator_try (allocator, &params))
return FALSE; return FALSE;
if (!_caps_is_va_memory (caps)) if (!gst_caps_is_vamemory (caps))
_shall_copy_frames (self, &params.info); _shall_copy_frames (self, &params.info);
} else { } else {
return FALSE; return FALSE;
@ -1134,7 +1114,7 @@ _create_allocator (GstVaH264Dec * self, GstCaps * caps, guint * size)
g_object_get (self->decoder, "display", &display, NULL); g_object_get (self->decoder, "display", &display, NULL);
if (_caps_is_dmabuf (self, caps)) if (gst_caps_is_dmabuf (caps))
allocator = gst_va_dmabuf_allocator_new (display); allocator = gst_va_dmabuf_allocator_new (display);
else { else {
GArray *surface_formats = GArray *surface_formats =
@ -1225,7 +1205,7 @@ gst_va_h264_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
} else { } else {
size = GST_VIDEO_INFO_SIZE (&info); size = GST_VIDEO_INFO_SIZE (&info);
if (!self->has_videometa && !_caps_is_va_memory (caps)) { if (!self->has_videometa && !gst_caps_is_vamemory (caps)) {
GST_DEBUG_OBJECT (self, "making new other pool for copy"); GST_DEBUG_OBJECT (self, "making new other pool for copy");
self->other_pool = gst_video_buffer_pool_new (); self->other_pool = gst_video_buffer_pool_new ();
config = gst_buffer_pool_get_config (self->other_pool); config = gst_buffer_pool_get_config (self->other_pool);

View file

@ -392,15 +392,6 @@ _shall_copy_frames (GstVaVp8Dec * self, GstVideoInfo * info)
} }
} }
static inline gboolean
_caps_is_va_memory (GstCaps * caps)
{
GstCapsFeatures *features;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, "memory:VAMemory");
}
static gboolean static gboolean
_try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps, _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps,
guint * size) guint * size)
@ -418,7 +409,7 @@ _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps,
} else if (GST_IS_VA_ALLOCATOR (allocator)) { } else if (GST_IS_VA_ALLOCATOR (allocator)) {
if (!gst_va_allocator_try (allocator, &params)) if (!gst_va_allocator_try (allocator, &params))
return FALSE; return FALSE;
if (!_caps_is_va_memory (caps)) if (!gst_caps_is_vamemory (caps))
_shall_copy_frames (self, &params.info); _shall_copy_frames (self, &params.info);
} else { } else {
return FALSE; return FALSE;
@ -430,17 +421,6 @@ _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps,
return TRUE; return TRUE;
} }
static inline gboolean
_caps_is_dmabuf (GstVaVp8Dec * self, GstCaps * caps)
{
GstCapsFeatures *features;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF)
&& (gst_va_decoder_get_mem_types (self->decoder)
& VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME);
}
static GstAllocator * static GstAllocator *
_create_allocator (GstVaVp8Dec * self, GstCaps * caps, guint * size) _create_allocator (GstVaVp8Dec * self, GstCaps * caps, guint * size)
{ {
@ -449,7 +429,7 @@ _create_allocator (GstVaVp8Dec * self, GstCaps * caps, guint * size)
g_object_get (self->decoder, "display", &display, NULL); g_object_get (self->decoder, "display", &display, NULL);
if (_caps_is_dmabuf (self, caps)) if (gst_caps_is_dmabuf (caps))
allocator = gst_va_dmabuf_allocator_new (display); allocator = gst_va_dmabuf_allocator_new (display);
else { else {
GArray *surface_formats = GArray *surface_formats =
@ -537,7 +517,7 @@ gst_va_vp8_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
} else { } else {
size = GST_VIDEO_INFO_SIZE (&info); size = GST_VIDEO_INFO_SIZE (&info);
if (!self->has_videometa && !_caps_is_va_memory (caps)) { if (!self->has_videometa && !gst_caps_is_vamemory (caps)) {
GST_DEBUG_OBJECT (self, "making new other pool for copy"); GST_DEBUG_OBJECT (self, "making new other pool for copy");
self->other_pool = gst_video_buffer_pool_new (); self->other_pool = gst_video_buffer_pool_new ();
config = gst_buffer_pool_get_config (self->other_pool); config = gst_buffer_pool_get_config (self->other_pool);

View file

@ -63,6 +63,7 @@
#include <va/va_drmcommon.h> #include <va/va_drmcommon.h>
#include "gstvaallocator.h" #include "gstvaallocator.h"
#include "gstvacaps.h"
#include "gstvadisplay_drm.h" #include "gstvadisplay_drm.h"
#include "gstvafilter.h" #include "gstvafilter.h"
#include "gstvapool.h" #include "gstvapool.h"
@ -420,24 +421,13 @@ _try_allocator (GstVaVpp * self, GstAllocator * allocator, GstCaps * caps,
return TRUE; return TRUE;
} }
static inline gboolean
_caps_is_dmabuf (GstVaVpp * self, GstCaps * caps)
{
GstCapsFeatures *features;
features = gst_caps_get_features (caps, 0);
return gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_DMABUF)
&& (gst_va_filter_get_mem_types (self->filter)
& VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME);
}
static GstAllocator * static GstAllocator *
_create_allocator (GstVaVpp * self, GstCaps * caps, guint usage_hint, _create_allocator (GstVaVpp * self, GstCaps * caps, guint usage_hint,
guint * size) guint * size)
{ {
GstAllocator *allocator = NULL; GstAllocator *allocator = NULL;
if (_caps_is_dmabuf (self, caps)) { if (gst_caps_is_dmabuf (caps)) {
allocator = gst_va_dmabuf_allocator_new (self->display); allocator = gst_va_dmabuf_allocator_new (self->display);
} else { } else {
GArray *surface_formats = gst_va_filter_get_surface_formats (self->filter); GArray *surface_formats = gst_va_filter_get_surface_formats (self->filter);