From 3cb9c34030b0cf35b587023d835dff908b3cecfb Mon Sep 17 00:00:00 2001 From: Yinhang Liu Date: Thu, 23 Feb 2023 13:20:28 +0800 Subject: [PATCH] msdkenc: Remove static templates in format setting The elements have supported dynamic capability query, and it is not necessary to refer the static templates. Part-of: --- .../gst-plugins-bad/sys/msdk/gstmsdkav1enc.c | 15 ++----- .../gst-plugins-bad/sys/msdk/gstmsdkh264enc.c | 16 ++----- .../gst-plugins-bad/sys/msdk/gstmsdkh265enc.c | 42 ++----------------- .../sys/msdk/gstmsdkmpeg2enc.c | 16 ++----- .../gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c | 24 +++-------- 5 files changed, 21 insertions(+), 92 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c index 7f4ad5a506..0c592c3839 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c @@ -78,35 +78,28 @@ enum #define PROP_B_PYRAMID_DEFAULT MFX_B_REF_UNKNOWN #define PROP_P_PYRAMID_DEFAULT MFX_P_REF_DEFAULT -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-av1, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], " - "profile = (string) main") - ); - static GstElementClass *parent_class = NULL; static gboolean gst_msdkav1enc_set_format (GstMsdkEnc * encoder) { GstMsdkAV1Enc *thiz = GST_MSDKAV1ENC (encoder); + GstPad *srcpad; GstCaps *template_caps; GstCaps *allowed_caps = NULL; thiz->profile = MFX_PROFILE_AV1_MAIN; - allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); + srcpad = GST_VIDEO_ENCODER_SRC_PAD (encoder); + allowed_caps = gst_pad_get_allowed_caps (srcpad); if (!allowed_caps || gst_caps_is_empty (allowed_caps)) { if (allowed_caps) gst_caps_unref (allowed_caps); return FALSE; } - template_caps = gst_static_pad_template_get_caps (&src_factory); + template_caps = gst_pad_get_pad_template_caps (srcpad); /* If downstream has ANY caps let encoder decide profile and level */ if (gst_caps_is_equal (allowed_caps, template_caps)) { diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c index cf8a070202..bb756fe1d4 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c @@ -112,16 +112,6 @@ enum #define PROP_INTRA_REFRESH_CYCLE_DIST_DEFAULT 0 #define PROP_DBLK_IDC_DEFAULT 0 -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-h264, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], " - "stream-format = (string) byte-stream , alignment = (string) au , " - "profile = (string) { high, main, baseline, constrained-baseline }") - ); - static GstElementClass *parent_class = NULL; static GType @@ -266,14 +256,16 @@ static gboolean gst_msdkh264enc_set_format (GstMsdkEnc * encoder) { GstMsdkH264Enc *thiz = GST_MSDKH264ENC (encoder); + GstPad *srcpad; GstCaps *template_caps; GstCaps *allowed_caps = NULL; thiz->profile = 0; thiz->level = 0; - template_caps = gst_static_pad_template_get_caps (&src_factory); - allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); + srcpad = GST_VIDEO_ENCODER_SRC_PAD (encoder); + template_caps = gst_pad_get_pad_template_caps (srcpad); + allowed_caps = gst_pad_get_allowed_caps (srcpad); /* If downstream has ANY caps let encoder decide profile and level */ if (allowed_caps == template_caps) { diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c index a93adc6050..5316b76172 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c @@ -110,42 +110,6 @@ enum #define PROP_INTRA_REFRESH_CYCLE_DIST_DEFAULT 0 #define PROP_DBLK_IDC_DEFAULT 0 -#define PROFILES "main, main-10, main-444, main-still-picture, main-10-still-picture" -#define PRFOLIE_STR "{ " PROFILES " }" - -#if (MFX_VERSION >= 1027) -#undef COMMON_FORMAT -#undef PRFOLIE_STR -#define PROFILES_1027 PROFILES ", main-444-10, main-422-10" -#define PRFOLIE_STR "{ " PROFILES_1027 " }" -#endif - -#if (MFX_VERSION >= 1031) -#undef COMMON_FORMAT -#undef PRFOLIE_STR -#define PROFILES_1031 PROFILES_1027 ", main-12" -#define PRFOLIE_STR "{ " PROFILES_1031 " }" -#endif - -#if (MFX_VERSION >= 1032) -#undef COMMON_FORMAT -#undef PRFOLIE_STR -#define PROFILES_1032 PROFILES_1031 ", screen-extended-main, " \ - "screen-extended-main-10, screen-extended-main-444, " \ - "screen-extended-main-444-10" -#define PRFOLIE_STR "{ " PROFILES_1032 " }" -#endif - -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-h265, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], " - "stream-format = (string) byte-stream , alignment = (string) au , " - "profile = (string) " PRFOLIE_STR) - ); - static GstElementClass *parent_class = NULL; static void @@ -367,20 +331,22 @@ static gboolean gst_msdkh265enc_set_format (GstMsdkEnc * encoder) { GstMsdkH265Enc *thiz = GST_MSDKH265ENC (encoder); + GstPad *srcpad; GstCaps *template_caps, *allowed_caps; g_free (thiz->profile_name); thiz->profile_name = NULL; - allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); + srcpad = GST_VIDEO_ENCODER_SRC_PAD (encoder); + allowed_caps = gst_pad_get_allowed_caps (srcpad); if (!allowed_caps || gst_caps_is_empty (allowed_caps)) { if (allowed_caps) gst_caps_unref (allowed_caps); return FALSE; } - template_caps = gst_static_pad_template_get_caps (&src_factory); + template_caps = gst_pad_get_pad_template_caps (srcpad); if (gst_caps_is_equal (allowed_caps, template_caps)) { GST_INFO_OBJECT (thiz, diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c index 656085e710..a551ec55de 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c @@ -63,29 +63,21 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkmpeg2enc_debug); #define GST_IS_MSDKMPEG2ENC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/mpeg, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], " - "mpegversion = (int) 2 , systemstream = (bool) false, " - "profile = (string) { high, main, simple }") - ); - static GstElementClass *parent_class = NULL; static gboolean gst_msdkmpeg2enc_set_format (GstMsdkEnc * encoder) { GstMsdkMPEG2Enc *thiz = GST_MSDKMPEG2ENC (encoder); + GstPad *srcpad; GstCaps *template_caps; GstCaps *allowed_caps = NULL; thiz->profile = 0; - template_caps = gst_static_pad_template_get_caps (&src_factory); - allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); + srcpad = GST_VIDEO_ENCODER_SRC_PAD (encoder); + template_caps = gst_pad_get_pad_template_caps (srcpad); + allowed_caps = gst_pad_get_allowed_caps (srcpad); /* If downstream has ANY caps let encoder decide profile and level */ if (allowed_caps == template_caps) { diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c index 35677217ba..d5196ed7ab 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c @@ -65,35 +65,21 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9enc_debug); #define GST_IS_MSDKVP9ENC_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) -#define PROFILES "0, 1, 2" - -#if (MFX_VERSION >= 1027) -#define SRC_PROFILES "{ " PROFILES ", 3 }" -#else -#define SRC_PROFILES "{ " PROFILES " }" -#endif - -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-vp9, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], " - "profile = (string) " SRC_PROFILES) - ); - static GstElementClass *parent_class = NULL; static gboolean gst_msdkvp9enc_set_format (GstMsdkEnc * encoder) { GstMsdkVP9Enc *thiz = GST_MSDKVP9ENC (encoder); + GstPad *srcpad; GstCaps *template_caps; GstCaps *allowed_caps = NULL; thiz->profile = MFX_PROFILE_VP9_0; - template_caps = gst_static_pad_template_get_caps (&src_factory); - allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder)); + + srcpad = GST_VIDEO_ENCODER_SRC_PAD (encoder); + template_caps = gst_pad_get_pad_template_caps (srcpad); + allowed_caps = gst_pad_get_allowed_caps (srcpad); /* If downstream has ANY caps let encoder decide profile and level */ if (allowed_caps == template_caps) {