From 666eedc2156e29b969de31565189ee90ff01f31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Sun, 4 Oct 2020 16:33:47 +0200 Subject: [PATCH] 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: --- sys/va/gstvacaps.c | 26 ++++++++++++++++++++++++++ sys/va/gstvacaps.h | 3 +++ sys/va/gstvah264dec.c | 26 +++----------------------- sys/va/gstvavp8dec.c | 26 +++----------------------- sys/va/gstvavpp.c | 14 ++------------ 5 files changed, 37 insertions(+), 58 deletions(-) diff --git a/sys/va/gstvacaps.c b/sys/va/gstvacaps.c index b4946297de..1e3d2c9f3d 100644 --- a/sys/va/gstvacaps.c +++ b/sys/va/gstvacaps.c @@ -24,6 +24,8 @@ #include "gstvacaps.h" +#include + #include #include "gstvadisplay.h" @@ -478,3 +480,27 @@ gst_va_caps_from_profiles (GstVaDisplay * display, GArray * profiles, 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"); +} diff --git a/sys/va/gstvacaps.h b/sys/va/gstvacaps.h index b8a2830516..710c9f7d1c 100644 --- a/sys/va/gstvacaps.h +++ b/sys/va/gstvacaps.h @@ -40,5 +40,8 @@ GstCaps * gst_va_create_raw_caps_from_config (GstVaDisplay * displa gboolean gst_caps_set_format_array (GstCaps * caps, GArray * formats); +gboolean gst_caps_is_dmabuf (GstCaps * caps); +gboolean gst_caps_is_vamemory (GstCaps * caps); + G_END_DECLS diff --git a/sys/va/gstvah264dec.c b/sys/va/gstvah264dec.c index 3826ebc69d..96e7a54a1f 100644 --- a/sys/va/gstvah264dec.c +++ b/sys/va/gstvah264dec.c @@ -1048,26 +1048,6 @@ gst_va_h264_dec_negotiate (GstVideoDecoder * 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 _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)) { if (!gst_va_allocator_try (allocator, ¶ms)) return FALSE; - if (!_caps_is_va_memory (caps)) + if (!gst_caps_is_vamemory (caps)) _shall_copy_frames (self, ¶ms.info); } else { return FALSE; @@ -1134,7 +1114,7 @@ _create_allocator (GstVaH264Dec * self, GstCaps * caps, guint * size) 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); else { GArray *surface_formats = @@ -1225,7 +1205,7 @@ gst_va_h264_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) } else { 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"); self->other_pool = gst_video_buffer_pool_new (); config = gst_buffer_pool_get_config (self->other_pool); diff --git a/sys/va/gstvavp8dec.c b/sys/va/gstvavp8dec.c index de87de4c1e..4661a184e3 100644 --- a/sys/va/gstvavp8dec.c +++ b/sys/va/gstvavp8dec.c @@ -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 _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps, guint * size) @@ -418,7 +409,7 @@ _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps, } else if (GST_IS_VA_ALLOCATOR (allocator)) { if (!gst_va_allocator_try (allocator, ¶ms)) return FALSE; - if (!_caps_is_va_memory (caps)) + if (!gst_caps_is_vamemory (caps)) _shall_copy_frames (self, ¶ms.info); } else { return FALSE; @@ -430,17 +421,6 @@ _try_allocator (GstVaVp8Dec * self, GstAllocator * allocator, GstCaps * caps, 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 * _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); - if (_caps_is_dmabuf (self, caps)) + if (gst_caps_is_dmabuf (caps)) allocator = gst_va_dmabuf_allocator_new (display); else { GArray *surface_formats = @@ -537,7 +517,7 @@ gst_va_vp8_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) } else { 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"); self->other_pool = gst_video_buffer_pool_new (); config = gst_buffer_pool_get_config (self->other_pool); diff --git a/sys/va/gstvavpp.c b/sys/va/gstvavpp.c index 61e91430ea..b1301b7655 100644 --- a/sys/va/gstvavpp.c +++ b/sys/va/gstvavpp.c @@ -63,6 +63,7 @@ #include #include "gstvaallocator.h" +#include "gstvacaps.h" #include "gstvadisplay_drm.h" #include "gstvafilter.h" #include "gstvapool.h" @@ -420,24 +421,13 @@ _try_allocator (GstVaVpp * self, GstAllocator * allocator, GstCaps * caps, 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 * _create_allocator (GstVaVpp * self, GstCaps * caps, guint usage_hint, guint * size) { GstAllocator *allocator = NULL; - if (_caps_is_dmabuf (self, caps)) { + if (gst_caps_is_dmabuf (caps)) { allocator = gst_va_dmabuf_allocator_new (self->display); } else { GArray *surface_formats = gst_va_filter_get_surface_formats (self->filter);