msdk: Fix segfault for OneVPL dispatcher + legacy MSDK runtime path

From the spec, the OneVPL dispatcher should be able to work with
legacy MSDK runtime:
https://www.intel.com/content/www/us/en/docs/onevpl/upgrade-from-msdk/2023-1/onevpl-hardware-support-details.html

Currently supported capabilities:
  OneVPL dispatcher + OneVPL runtime: dynamic capability
  MSDK dispatcher + MSDK runtime: static capability
  MSDK dispatcher + OneVPL runtime: static capability
  OneVPL dispatcher + legacy MSDK runtime: static capability

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2506

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4466>
This commit is contained in:
Yinhang Liu 2023-04-21 13:52:50 +08:00 committed by GStreamer Marge Bot
parent e97b5ad355
commit 35177b81b3
3 changed files with 99 additions and 56 deletions

View file

@ -284,9 +284,9 @@ _register_vpp (GstPlugin * plugin,
gst_caps_unref (src_caps);
}
#else
#endif
static const guint enc_codecs[] = {
static const guint enc_static_codecs[] = {
MFX_CODEC_AVC,
MFX_CODEC_HEVC,
MFX_CODEC_MPEG2,
@ -299,7 +299,7 @@ static const guint enc_codecs[] = {
MFX_CODEC_JPEG
};
static const guint dec_codecs[] = {
static const guint dec_static_codecs[] = {
MFX_CODEC_AVC,
MFX_CODEC_HEVC,
MFX_CODEC_MPEG2,
@ -315,23 +315,24 @@ static const guint dec_codecs[] = {
};
static void
_register_encoders (GstPlugin * plugin, GstMsdkContext * context)
_register_encoders_with_static_caps (GstPlugin * plugin,
GstMsdkContext * context)
{
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
for (guint c = 0; c < G_N_ELEMENTS (enc_codecs); c++) {
if (!gst_msdkcaps_enc_create_caps (context,
NULL, enc_codecs[c], &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create caps for %" GST_FOURCC_FORMAT " ENC",
GST_FOURCC_ARGS (enc_codecs[c]));
for (guint c = 0; c < G_N_ELEMENTS (enc_static_codecs); c++) {
if (!gst_msdkcaps_enc_create_static_caps (context,
enc_static_codecs[c], &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create static caps for %" GST_FOURCC_FORMAT
" ENC", GST_FOURCC_ARGS (enc_static_codecs[c]));
continue;
}
if (!_register_encoder (plugin, context,
enc_codecs[c], sink_caps, src_caps)) {
enc_static_codecs[c], sink_caps, src_caps)) {
GST_WARNING ("Failed to register %" GST_FOURCC_FORMAT " ENC",
GST_FOURCC_ARGS (enc_codecs[c]));
GST_FOURCC_ARGS (enc_static_codecs[c]));
continue;
}
@ -341,23 +342,24 @@ _register_encoders (GstPlugin * plugin, GstMsdkContext * context)
}
static void
_register_decoders (GstPlugin * plugin, GstMsdkContext * context)
_register_decoders_with_static_caps (GstPlugin * plugin,
GstMsdkContext * context)
{
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
for (guint c = 0; c < G_N_ELEMENTS (dec_codecs); c++) {
if (!gst_msdkcaps_dec_create_caps (context,
NULL, dec_codecs[c], &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create caps for %" GST_FOURCC_FORMAT " DEC",
GST_FOURCC_ARGS (dec_codecs[c]));
for (guint c = 0; c < G_N_ELEMENTS (dec_static_codecs); c++) {
if (!gst_msdkcaps_dec_create_static_caps (context,
dec_static_codecs[c], &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create static caps for %" GST_FOURCC_FORMAT
" DEC", GST_FOURCC_ARGS (dec_static_codecs[c]));
continue;
}
if (!_register_decoder (plugin, context,
dec_codecs[c], sink_caps, src_caps)) {
dec_static_codecs[c], sink_caps, src_caps)) {
GST_WARNING ("Failed to register %" GST_FOURCC_FORMAT " DEC",
GST_FOURCC_ARGS (dec_codecs[c]));
GST_FOURCC_ARGS (dec_static_codecs[c]));
continue;
}
@ -367,13 +369,13 @@ _register_decoders (GstPlugin * plugin, GstMsdkContext * context)
}
static void
_register_vpp (GstPlugin * plugin, GstMsdkContext * context)
_register_vpp_with_static_caps (GstPlugin * plugin, GstMsdkContext * context)
{
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
if (!gst_msdkcaps_vpp_create_caps (context, NULL, &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create caps for VPP");
if (!gst_msdkcaps_vpp_create_static_caps (context, &sink_caps, &src_caps)) {
GST_WARNING ("Failed to create static caps for VPP");
return;
}
@ -386,8 +388,6 @@ _register_vpp (GstPlugin * plugin, GstMsdkContext * context)
gst_caps_unref (src_caps);
}
#endif
static gboolean
plugin_init (GstPlugin * plugin)
{
@ -431,17 +431,27 @@ plugin_init (GstPlugin * plugin)
msdk_get_impl_description (gst_msdk_context_get_loader (context),
gst_msdk_context_get_impl_idx (context));
if (desc) {
if (desc && desc->Enc.NumCodecs > 0)
_register_encoders (plugin, context, &desc->Enc);
_register_decoders (plugin, context, &desc->Dec);
_register_vpp (plugin, context, &desc->VPP);
else
_register_encoders_with_static_caps (plugin, context);
if (desc && desc->Dec.NumCodecs > 0)
_register_decoders (plugin, context, &desc->Dec);
else
_register_decoders_with_static_caps (plugin, context);
if (desc && desc->VPP.NumFilters > 0)
_register_vpp (plugin, context, &desc->VPP);
else
_register_vpp_with_static_caps (plugin, context);
if (desc)
msdk_release_impl_description (gst_msdk_context_get_loader (context), desc);
}
#else
_register_encoders (plugin, context);
_register_decoders (plugin, context);
_register_vpp (plugin, context);
_register_encoders_with_static_caps (plugin, context);
_register_decoders_with_static_caps (plugin, context);
_register_vpp_with_static_caps (plugin, context);
#endif
gst_object_unref (context);

View file

@ -1409,6 +1409,31 @@ failed:
#else
gboolean
gst_msdkcaps_enc_create_caps (GstMsdkContext * context,
gpointer enc_description, guint codec_id,
GstCaps ** sink_caps, GstCaps ** src_caps)
{
return FALSE;
}
gboolean
gst_msdkcaps_dec_create_caps (GstMsdkContext * context,
gpointer dec_description, guint codec_id,
GstCaps ** sink_caps, GstCaps ** src_caps)
{
return FALSE;
}
gboolean
gst_msdkcaps_vpp_create_caps (GstMsdkContext * context,
gpointer vpp_description, GstCaps ** sink_caps, GstCaps ** src_caps)
{
return FALSE;
}
#endif
static gboolean
_get_profiles (guint codec_id, GValue * supported_profs)
{
@ -1437,7 +1462,7 @@ _get_profiles (guint codec_id, GValue * supported_profs)
}
static const char *
_enc_get_raw_formats (guint codec_id)
_enc_get_static_raw_formats (guint codec_id)
{
switch (codec_id) {
case MFX_CODEC_AVC:
@ -1464,7 +1489,7 @@ _enc_get_raw_formats (guint codec_id)
#ifndef _WIN32
static const char *
_enc_get_dma_formats (guint codec_id)
_enc_get_static_dma_formats (guint codec_id)
{
switch (codec_id) {
case MFX_CODEC_AVC:
@ -1490,9 +1515,8 @@ _enc_get_dma_formats (guint codec_id)
#endif
gboolean
gst_msdkcaps_enc_create_caps (GstMsdkContext * context,
gpointer enc_description, guint codec_id,
GstCaps ** sink_caps, GstCaps ** src_caps)
gst_msdkcaps_enc_create_static_caps (GstMsdkContext * context,
guint codec_id, GstCaps ** sink_caps, GstCaps ** src_caps)
{
GstCaps *in_caps = NULL, *out_caps = NULL;
GstCaps *dma_caps = NULL;
@ -1502,7 +1526,7 @@ gst_msdkcaps_enc_create_caps (GstMsdkContext * context,
const char *dma_fmts = NULL;
GValue supported_profs = G_VALUE_INIT;
raw_fmts = _enc_get_raw_formats (codec_id);
raw_fmts = _enc_get_static_raw_formats (codec_id);
if (!raw_fmts)
goto failed;
raw_caps_str = g_strdup_printf ("video/x-raw, format=(string){ %s }",
@ -1511,7 +1535,7 @@ gst_msdkcaps_enc_create_caps (GstMsdkContext * context,
g_free (raw_caps_str);
#ifndef _WIN32
dma_fmts = _enc_get_dma_formats (codec_id);
dma_fmts = _enc_get_static_dma_formats (codec_id);
if (!dma_fmts)
goto failed;
dma_caps_str =
@ -1577,7 +1601,7 @@ failed:
}
static const char *
_dec_get_raw_formats (guint codec_id)
_dec_get_static_raw_formats (guint codec_id)
{
switch (codec_id) {
case MFX_CODEC_AVC:
@ -1608,7 +1632,7 @@ _dec_get_raw_formats (guint codec_id)
#ifndef _WIN32
static const char *
_dec_get_dma_formats (guint codec_id)
_dec_get_static_dma_formats (guint codec_id)
{
switch (codec_id) {
case MFX_CODEC_AVC:
@ -1639,9 +1663,8 @@ _dec_get_dma_formats (guint codec_id)
#endif
gboolean
gst_msdkcaps_dec_create_caps (GstMsdkContext * context,
gpointer dec_description, guint codec_id,
GstCaps ** sink_caps, GstCaps ** src_caps)
gst_msdkcaps_dec_create_static_caps (GstMsdkContext * context,
guint codec_id, GstCaps ** sink_caps, GstCaps ** src_caps)
{
GstCaps *in_caps = NULL, *out_caps = NULL;
GstCaps *dma_caps = NULL;
@ -1656,7 +1679,7 @@ gst_msdkcaps_dec_create_caps (GstMsdkContext * context,
in_caps = gst_caps_new_empty_simple (media_type);
raw_fmts = _dec_get_raw_formats (codec_id);
raw_fmts = _dec_get_static_raw_formats (codec_id);
if (!raw_fmts)
goto failed;
raw_caps_str = g_strdup_printf ("video/x-raw, format=(string){ %s }",
@ -1665,7 +1688,7 @@ gst_msdkcaps_dec_create_caps (GstMsdkContext * context,
g_free (raw_caps_str);
#ifndef _WIN32
dma_fmts = _dec_get_dma_formats (codec_id);
dma_fmts = _dec_get_static_dma_formats (codec_id);
if (!dma_fmts)
goto failed;
dma_caps_str =
@ -1712,7 +1735,7 @@ failed:
}
static const char *
_vpp_get_raw_formats (GstPadDirection direction)
_vpp_get_static_raw_formats (GstPadDirection direction)
{
switch (direction) {
case GST_PAD_SINK:
@ -1731,7 +1754,7 @@ _vpp_get_raw_formats (GstPadDirection direction)
#ifndef _WIN32
static const char *
_vpp_get_dma_formats (GstPadDirection direction)
_vpp_get_static_dma_formats (GstPadDirection direction)
{
switch (direction) {
case GST_PAD_SINK:
@ -1750,20 +1773,20 @@ _vpp_get_dma_formats (GstPadDirection direction)
#endif
static GstCaps *
_vpp_create_caps (GstMsdkContext * context, GstPadDirection direction)
_vpp_create_static_caps (GstMsdkContext * context, GstPadDirection direction)
{
GstCaps *caps = NULL, *dma_caps = NULL;
gchar *caps_str;
caps_str = g_strdup_printf ("video/x-raw, format=(string){ %s }",
_vpp_get_raw_formats (direction));
_vpp_get_static_raw_formats (direction));
caps = gst_caps_from_string (caps_str);
g_free (caps_str);
#ifndef _WIN32
caps_str =
g_strdup_printf ("video/x-raw(memory:DMABuf), format=(string){ %s }",
_vpp_get_dma_formats (direction));
_vpp_get_static_dma_formats (direction));
dma_caps = gst_caps_from_string (caps_str);
g_free (caps_str);
gst_caps_append (caps, dma_caps);
@ -1791,17 +1814,15 @@ _vpp_create_caps (GstMsdkContext * context, GstPadDirection direction)
}
gboolean
gst_msdkcaps_vpp_create_caps (GstMsdkContext * context,
gpointer vpp_description, GstCaps ** sink_caps, GstCaps ** src_caps)
gst_msdkcaps_vpp_create_static_caps (GstMsdkContext * context,
GstCaps ** sink_caps, GstCaps ** src_caps)
{
*sink_caps = _vpp_create_caps (context, GST_PAD_SINK);
*src_caps = _vpp_create_caps (context, GST_PAD_SRC);
*sink_caps = _vpp_create_static_caps (context, GST_PAD_SINK);
*src_caps = _vpp_create_static_caps (context, GST_PAD_SRC);
return TRUE;
}
#endif
static void
_pad_template_init (GstElementClass * klass,
const gchar * name_template, GstPadDirection direction,

View file

@ -57,6 +57,18 @@ gboolean
gst_msdkcaps_vpp_create_caps (GstMsdkContext * context,
gpointer vpp_description, GstCaps ** sink_caps, GstCaps ** src_caps);
gboolean
gst_msdkcaps_enc_create_static_caps (GstMsdkContext * context,
guint codec_id, GstCaps ** sink_caps, GstCaps ** src_caps);
gboolean
gst_msdkcaps_dec_create_static_caps (GstMsdkContext * context,
guint codec_id, GstCaps ** sink_caps, GstCaps ** src_caps);
gboolean
gst_msdkcaps_vpp_create_static_caps (GstMsdkContext * context,
GstCaps ** sink_caps, GstCaps ** src_caps);
void
gst_msdkcaps_pad_template_init (GstElementClass * klass,
GstCaps * sink_caps, GstCaps * src_caps,