diff --git a/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c b/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c index 3659b354e9..43e7edb7dc 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvaav1dec.c @@ -1107,22 +1107,9 @@ gst_va_av1_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vaav1dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaAV1Dec"); - feature_name = g_strdup ("vaav1dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sAV1Dec", basename); - feature_name = g_strdup_printf ("va%sav1dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaAV1Dec", "GstVa%sAV1Dec", + &type_name, "vaav1dec", "va%sav1dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabasedec.h b/subprojects/gst-plugins-bad/sys/va/gstvabasedec.h index 411a7072bf..35121c4c06 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabasedec.h +++ b/subprojects/gst-plugins-bad/sys/va/gstvabasedec.h @@ -32,6 +32,7 @@ #include "gstvadecoder.h" #include "gstvadevice.h" #include "gstvaprofile.h" +#include "gstvapluginutils.h" G_BEGIN_DECLS diff --git a/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c b/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c index 868ae52758..f54267eb08 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvacompositor.c @@ -1515,24 +1515,9 @@ gst_va_compositor_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - type_name = g_strdup ("GstVaCompositor"); - feature_name = g_strdup ("vacompositor"); - - /* The first compositor to be registered should use a constant - * name, like vacompositor, for any additional compositors, we - * create unique names, using the render device name. */ - if (g_type_from_name (type_name)) { - gchar *basename = g_path_get_basename (device->render_device_path); - g_free (type_name); - g_free (feature_name); - type_name = g_strdup_printf ("GstVa%sCompositor", basename); - feature_name = g_strdup_printf ("va%scompositor", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaCompositor", "GstVa%sCompositor", + &type_name, "vacompositor", "va%scompositor", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c b/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c index 9a56dea8c3..5337c32862 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c @@ -829,24 +829,9 @@ gst_va_deinterlace_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - type_name = g_strdup ("GstVaDeinterlace"); - feature_name = g_strdup ("vadeinterlace"); - - /* The first postprocessor to be registered should use a constant - * name, like vadeinterlace, for any additional postprocessors, we - * create unique names, using inserting the render device name. */ - if (g_type_from_name (type_name)) { - gchar *basename = g_path_get_basename (device->render_device_path); - g_free (type_name); - g_free (feature_name); - type_name = g_strdup_printf ("GstVa%sDeinterlace", basename); - feature_name = g_strdup_printf ("va%sdeinterlace", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaDeinterlace", "GstVa%sDeinterlace", + &type_name, "vadeinterlace", "va%sdeinterlace", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c b/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c index a899f6d72a..44a1ba6d5d 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264dec.c @@ -967,22 +967,9 @@ gst_va_h264_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vah264dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaH264Dec"); - feature_name = g_strdup ("vah264dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sH264Dec", basename); - feature_name = g_strdup_printf ("va%sh264dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaH264Dec", "GstVa%sH264Dec", + &type_name, "vah264dec", "va%sh264dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c index fc031e87c6..55ed703f66 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c @@ -3819,30 +3819,14 @@ gst_va_h264_enc_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first encoder to be registered should use a constant name, - * like vah264enc, for any additional encoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - if (entrypoint == VAEntrypointEncSlice) { - type_name = g_strdup ("GstVaH264Enc"); - feature_name = g_strdup ("vah264enc"); - } else { - type_name = g_strdup ("GstVaH264LPEnc"); - feature_name = g_strdup ("vah264lpenc"); - } + if (entrypoint == VAEntrypointEncSlice) { + gst_va_create_feature_name (device, "GstVaH264Enc", "GstVa%sH264Enc", + &type_name, "vah264enc", "va%sh264enc", &feature_name, + &cdata->description, &rank); } else { - gchar *basename = g_path_get_basename (device->render_device_path); - if (entrypoint == VAEntrypointEncSlice) { - type_name = g_strdup_printf ("GstVa%sH264Enc", basename); - feature_name = g_strdup_printf ("va%sh264enc", basename); - } else { - type_name = g_strdup_printf ("GstVa%sH264LPEnc", basename); - feature_name = g_strdup_printf ("va%sh264lpenc", basename); - } - cdata->description = basename; - /* lower rank for non-first device */ - if (rank > 0) - rank--; + gst_va_create_feature_name (device, "GstVaH264LPEnc", "GstVa%sH264LPEnc", + &type_name, "vah264lpenc", "va%sh264lpenc", &feature_name, + &cdata->description, &rank); } g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c b/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c index 7f17516bba..dd31003f13 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah265dec.c @@ -1323,22 +1323,9 @@ gst_va_h265_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vah265dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaH265Dec"); - feature_name = g_strdup ("vah265dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sH265Dec", basename); - feature_name = g_strdup_printf ("va%sh265dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaH265Dec", "GstVa%sH265Dec", + &type_name, "vah265dec", "va%sh265dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c index 0c4ab63a70..da0bebf044 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah265enc.c @@ -5292,31 +5292,14 @@ gst_va_h265_enc_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first encoder to be registered should use a constant name, - * like vah265enc, for any additional encoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - if (entrypoint == VAEntrypointEncSlice) { - type_name = g_strdup ("GstVaH265Enc"); - feature_name = g_strdup ("vah265enc"); - } else { - type_name = g_strdup ("GstVaH265LPEnc"); - feature_name = g_strdup ("vah265lpenc"); - } + if (entrypoint == VAEntrypointEncSlice) { + gst_va_create_feature_name (device, "GstVaH265Enc", "GstVa%sH265Enc", + &type_name, "vah265enc", "va%sh265enc", &feature_name, + &cdata->description, &rank); } else { - gchar *basename = g_path_get_basename (device->render_device_path); - if (entrypoint == VAEntrypointEncSlice) { - type_name = g_strdup_printf ("GstVa%sH265Enc", basename); - feature_name = g_strdup_printf ("va%sh265enc", basename); - } else { - type_name = g_strdup_printf ("GstVa%sH265LPEnc", basename); - feature_name = g_strdup_printf ("va%sh265lpenc", basename); - } - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; + gst_va_create_feature_name (device, "GstVaH265LPEnc", "GstVa%sH265LPEnc", + &type_name, "vah265lpenc", "va%sh265lpenc", &feature_name, + &cdata->description, &rank); } g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvajpegdec.c b/subprojects/gst-plugins-bad/sys/va/gstvajpegdec.c index 33d2b8db8f..6aeca2a619 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvajpegdec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvajpegdec.c @@ -619,23 +619,9 @@ gst_va_jpeg_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - - /* The first decoder to be registered should use a constant name, - * like vajpegdec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaJpegDec"); - feature_name = g_strdup ("vajpegdec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sJpegDec", basename); - feature_name = g_strdup_printf ("va%sjpegdec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaJpegDec", "GstVa%sJpegDec", + &type_name, "vajpegdec", "va%sjpegdec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c b/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c index 010c5d0dfd..5e67b48a49 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvampeg2dec.c @@ -646,22 +646,9 @@ gst_va_mpeg2_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vampeg2dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaMpeg2Dec"); - feature_name = g_strdup ("vampeg2dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sMpeg2Dec", basename); - feature_name = g_strdup_printf ("va%smpeg2dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaMpeg2Dec", "GstVa%sMpeg2Dec", + &type_name, "vampeg2dec", "va%smpeg2dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.c b/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.c new file mode 100644 index 0000000000..d47c5b44c9 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.c @@ -0,0 +1,74 @@ +/* GStreamer + * Copyright (C) 2023 Seungha Yang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstvapluginutils.h" + +GstVaDisplay * +gst_va_display_platform_new (const gchar * path) +{ +#ifdef G_OS_WIN32 + return gst_va_display_win32_new (path); +#else + return gst_va_display_drm_new_from_path (path); +#endif +} + +void +gst_va_create_feature_name (GstVaDevice * device, + const gchar * type_name_default, const gchar * type_name_templ, + gchar ** type_name, const gchar * feature_name_default, + const gchar * feature_name_templ, gchar ** feature_name, + gchar ** desc, guint * rank) +{ + gchar *basename; + + /* The first element to be registered should use a constant name, + * like vah264dec, for any additional elements, we create unique + * names, using inserting the render device name. */ + if (device->index == 0) { + *type_name = g_strdup (type_name_default); + *feature_name = g_strdup (feature_name_default); +#ifdef G_OS_WIN32 + g_object_get (device->display, "description", desc, NULL); +#endif + return; + } +#ifdef G_OS_WIN32 + basename = g_strdup_printf ("device%d", device->index); +#else + basename = g_path_get_basename (device->render_device_path); +#endif + + *type_name = g_strdup_printf (type_name_templ, basename); + *feature_name = g_strdup_printf (feature_name_templ, basename); + +#ifdef G_OS_WIN32 + g_object_get (device->display, "description", desc, NULL); + g_free (basename); +#else + *desc = basename; +#endif + + if (*rank > 0) + *rank -= 1; +} diff --git a/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.h b/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.h index ead92da8b9..5852d77041 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.h +++ b/subprojects/gst-plugins-bad/sys/va/gstvapluginutils.h @@ -21,6 +21,7 @@ #include #include +#include "gstvadevice.h" G_BEGIN_DECLS @@ -30,14 +31,16 @@ G_BEGIN_DECLS #define GST_IS_VA_DISPLAY_PLATFORM(dpy) GST_IS_VA_DISPLAY_DRM(dpy) #endif -static GstVaDisplay * -gst_va_display_platform_new (const gchar * path) -{ -#ifdef G_OS_WIN32 - return gst_va_display_win32_new (path); -#else - return gst_va_display_drm_new_from_path (path); -#endif -} +GstVaDisplay * gst_va_display_platform_new (const gchar * path); + +void gst_va_create_feature_name (GstVaDevice * device, + const gchar * type_name_default, + const gchar * type_name_templ, + gchar ** type_name, + const gchar * feature_name_default, + const gchar * feature_name_templ, + gchar ** feature_name, + gchar ** desc, + guint * rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c b/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c index 1871622bca..cbdef02054 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp8dec.c @@ -520,22 +520,9 @@ gst_va_vp8_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vavp8dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaVp8Dec"); - feature_name = g_strdup ("vavp8dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sVp8Dec", basename); - feature_name = g_strdup_printf ("va%svp8dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaVp8Dec", "GstVa%sVp8Dec", + &type_name, "vavp8dec", "va%svp8dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c index b35bd66f30..ec1c7037d4 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavp9dec.c @@ -718,22 +718,9 @@ gst_va_vp9_dec_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - /* The first decoder to be registered should use a constant name, - * like vavp9dec, for any additional decoders, we create unique - * names, using inserting the render device name. */ - if (device->index == 0) { - type_name = g_strdup ("GstVaVp9Dec"); - feature_name = g_strdup ("vavp9dec"); - } else { - gchar *basename = g_path_get_basename (device->render_device_path); - type_name = g_strdup_printf ("GstVa%sVp9Dec", basename); - feature_name = g_strdup_printf ("va%svp9dec", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaVp9Dec", "GstVa%sVp9Dec", + &type_name, "vavp9dec", "va%svp9dec", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c index fc03922d17..c5dc7121ca 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c @@ -2321,24 +2321,9 @@ gst_va_vpp_register (GstPlugin * plugin, GstVaDevice * device, type_info.class_data = cdata; - type_name = g_strdup ("GstVaPostProc"); - feature_name = g_strdup ("vapostproc"); - - /* The first postprocessor to be registered should use a constant - * name, like vapostproc, for any additional postprocessors, we - * create unique names, using inserting the render device name. */ - if (g_type_from_name (type_name)) { - gchar *basename = g_path_get_basename (device->render_device_path); - g_free (type_name); - g_free (feature_name); - type_name = g_strdup_printf ("GstVa%sPostProc", basename); - feature_name = g_strdup_printf ("va%spostproc", basename); - cdata->description = basename; - - /* lower rank for non-first device */ - if (rank > 0) - rank--; - } + gst_va_create_feature_name (device, "GstVaPostProc", "GstVa%sPostProc", + &type_name, "vapostproc", "va%spostproc", &feature_name, + &cdata->description, &rank); g_once (&debug_once, _register_debug_category, NULL); diff --git a/subprojects/gst-plugins-bad/sys/va/meson.build b/subprojects/gst-plugins-bad/sys/va/meson.build index a99cdfe01c..6315217a1f 100644 --- a/subprojects/gst-plugins-bad/sys/va/meson.build +++ b/subprojects/gst-plugins-bad/sys/va/meson.build @@ -17,6 +17,7 @@ va_sources = [ 'gstvah265enc.c', 'gstvajpegdec.c', 'gstvampeg2dec.c', + 'gstvapluginutils.c', 'gstvaprofile.c', 'gstvavp8dec.c', 'gstvavp9dec.c',