msdkdec: Enable va caps at srcpad

Set caps with VA memory at src pad with a higher priority, then comes
dmabuf caps.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3439>
This commit is contained in:
Mengkejiergeli Ba 2022-06-08 17:13:47 +08:00 committed by Haihao Xiang
parent 68425e8241
commit 3b0d300759
8 changed files with 98 additions and 21 deletions

View file

@ -57,6 +57,13 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkav1dec_debug);
#define COMMON_FORMAT "{ NV12, P010_10LE, VUYA, Y410 }"
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
";" GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
@ -66,8 +73,8 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
);
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT)
VA_SRC_CAPS_STR));
#define gst_msdkav1dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkAV1Dec, gst_msdkav1dec, GST_TYPE_MSDKDEC);

View file

@ -41,6 +41,10 @@
#include "gstmsdksystemmemory.h"
#include "gstmsdkcontextutil.h"
#ifndef _WIN32
#include <gst/va/gstvaallocator.h>
#endif
GST_DEBUG_CATEGORY_EXTERN (gst_msdkdec_debug);
#define GST_CAT_DEFAULT gst_msdkdec_debug
@ -567,26 +571,28 @@ _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
}
static gboolean
srcpad_can_dmabuf (GstMsdkDec * thiz)
pad_accept_memory (GstMsdkDec * thiz, const gchar * mem_type, GstCaps * filter)
{
gboolean ret = FALSE;
GstCaps *caps, *out_caps;
GstPad *srcpad;
GstPad *pad;
srcpad = GST_VIDEO_DECODER_SRC_PAD (thiz);
caps = gst_pad_get_pad_template_caps (srcpad);
pad = GST_VIDEO_DECODER_SRC_PAD (thiz);
out_caps = gst_pad_peer_query_caps (srcpad, caps);
/* make a copy of filter caps since we need to alter the structure
* by adding dmabuf-capsfeatures */
caps = gst_caps_copy (filter);
gst_caps_set_features (caps, 0, gst_caps_features_from_string (mem_type));
out_caps = gst_pad_peer_query_caps (pad, caps);
if (!out_caps)
goto done;
if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
|| out_caps == caps)
if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps))
goto done;
if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
if (_gst_caps_has_feature (out_caps, mem_type))
ret = TRUE;
done:
if (caps)
gst_caps_unref (caps);
@ -748,10 +754,16 @@ gst_msdkdec_set_src_caps (GstMsdkDec * thiz, gboolean need_allocation)
gst_msdk_set_video_alignment (vinfo, alloc_w, alloc_h, &align);
gst_video_info_align (vinfo, &align);
output_state->caps = gst_video_info_to_caps (vinfo);
if (srcpad_can_dmabuf (thiz))
#ifndef _WIN32
if (pad_accept_memory (thiz, GST_CAPS_FEATURE_MEMORY_VA, output_state->caps)) {
gst_caps_set_features (output_state->caps, 0,
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_VA, NULL));
} else if (pad_accept_memory (thiz, GST_CAPS_FEATURE_MEMORY_DMABUF,
output_state->caps)) {
gst_caps_set_features (output_state->caps, 0,
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
}
#endif
if (need_allocation) {
/* Find allocation width and height */

View file

@ -56,6 +56,13 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh264dec_debug);
#define COMMON_FORMAT "{ NV12, BGRA, BGRx }"
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
@ -68,8 +75,8 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
);
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT)
VA_SRC_CAPS_STR));
#define gst_msdkh264dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkH264Dec, gst_msdkh264dec, GST_TYPE_MSDKDEC);

View file

@ -58,6 +58,13 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265dec_debug);
#define COMMON_FORMAT \
"{ NV12, P010_10LE, YUY2, Y210, VUYA, Y410, P012_LE, Y212_LE, Y412_LE, BGRA, BGRx }"
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
/* TODO: update both sink and src dynamically */
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
@ -70,8 +77,8 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
);
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT)
VA_SRC_CAPS_STR));
#define gst_msdkh265dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkH265Dec, gst_msdkh265dec, GST_TYPE_MSDKDEC);

View file

@ -67,11 +67,18 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
"width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], parsed = true ")
);
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR ("{ NV12, YUY2 }", "{ NV12, YUY2 }"))
);
GST_STATIC_CAPS (GST_MSDK_CAPS_STR ("{ NV12, YUY2 }", "{ NV12, YUY2 }")
VA_SRC_CAPS_STR));
#define gst_msdkmjpegdec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkMJPEGDec, gst_msdkmjpegdec, GST_TYPE_MSDKDEC);

View file

@ -57,6 +57,13 @@
GST_DEBUG_CATEGORY_EXTERN (gst_msdkmpeg2dec_debug);
#define GST_CAT_DEFAULT gst_msdkmpeg2dec_debug
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
@ -65,6 +72,12 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
"mpegversion = (int) 2, " "systemstream = (boolean) false")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR ("{ NV12 }", "{ NV12 }")
VA_SRC_CAPS_STR));
#define gst_msdkmpeg2dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkMPEG2Dec, gst_msdkmpeg2dec, GST_TYPE_MSDKDEC);
@ -151,6 +164,7 @@ gst_msdkmpeg2dec_class_init (GstMsdkMPEG2DecClass * klass)
gst_msdkdec_prop_install_output_oder_property (gobject_class);
gst_element_class_add_static_pad_template (element_class, &sink_factory);
gst_element_class_add_static_pad_template (element_class, &src_factory);
}
static void

View file

@ -56,6 +56,13 @@
GST_DEBUG_CATEGORY_EXTERN (gst_msdkvc1dec_debug);
#define GST_CAT_DEFAULT gst_msdkvc1dec_debug
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("{ NV12 }")
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
@ -76,6 +83,12 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
"stream-format= (string) bdu, " "profile = (string) advanced" ";")
);
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR ("{ NV12 }", "{ NV12 }")
VA_SRC_CAPS_STR));
#define gst_msdkvc1dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkVC1Dec, gst_msdkvc1dec, GST_TYPE_MSDKDEC);
@ -209,6 +222,8 @@ gst_msdkvc1dec_class_init (GstMsdkVC1DecClass * klass)
gst_msdkdec_prop_install_output_oder_property (gobject_class);
gst_element_class_add_static_pad_template (element_class, &sink_factory);
gst_element_class_add_static_pad_template (element_class, &src_factory);
}
static void

View file

@ -58,6 +58,14 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9dec_debug);
#define GST_CAT_DEFAULT gst_msdkvp9dec_debug
#define COMMON_FORMAT "{ NV12, P010_10LE, VUYA, Y410, P012_LE, Y412_LE }"
#define SUPPORTED_VA_FORMAT "{ NV12 }"
#ifndef _WIN32
#define VA_SRC_CAPS_STR \
"; " GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE (SUPPORTED_VA_FORMAT)
#else
#define VA_SRC_CAPS_STR ""
#endif
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
@ -68,8 +76,8 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
);
GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT)
VA_SRC_CAPS_STR));
#define gst_msdkvp9dec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkVP9Dec, gst_msdkvp9dec, GST_TYPE_MSDKDEC);