From 30d3ce3a9ef8e85c8b82df1ec9c2ddb6da9bbf4c Mon Sep 17 00:00:00 2001 From: Yinhang Liu Date: Wed, 22 Feb 2023 16:46:23 +0800 Subject: [PATCH] msdkenc: Enable dynamic capability support Enable dynamic capability support for msdkav1enc, msdkh264enc, msdkh265enc, msdkmjpegenc, msdkvp9enc, msdkmpeg2enc. The gstmsdkenc elements can create the sink caps and src caps dynamically for different platforms. Part-of: --- .../gst-plugins-bad/sys/msdk/gstmsdk.c | 62 +++++-- .../gst-plugins-bad/sys/msdk/gstmsdkav1enc.c | 130 ++++++++++---- .../gst-plugins-bad/sys/msdk/gstmsdkav1enc.h | 16 +- .../gst-plugins-bad/sys/msdk/gstmsdkenc.c | 20 --- .../gst-plugins-bad/sys/msdk/gstmsdkenc.h | 7 + .../gst-plugins-bad/sys/msdk/gstmsdkh264enc.c | 132 ++++++++++---- .../gst-plugins-bad/sys/msdk/gstmsdkh264enc.h | 16 +- .../gst-plugins-bad/sys/msdk/gstmsdkh265enc.c | 162 ++++++++++++------ .../gst-plugins-bad/sys/msdk/gstmsdkh265enc.h | 16 +- .../sys/msdk/gstmsdkmjpegenc.c | 80 +++++++-- .../sys/msdk/gstmsdkmjpegenc.h | 16 +- .../sys/msdk/gstmsdkmpeg2enc.c | 75 +++++++- .../sys/msdk/gstmsdkmpeg2enc.h | 16 +- .../gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c | 96 ++++++++--- .../gst-plugins-bad/sys/msdk/gstmsdkvp9enc.h | 16 +- 15 files changed, 589 insertions(+), 271 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdk.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdk.c index a2774190ea..9af87929fd 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdk.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdk.c @@ -112,38 +112,40 @@ plugin_add_dependencies (GstPlugin * plugin) } static gboolean -_register_encoder (GstPlugin * plugin, guint codec_id) +_register_encoder (GstPlugin * plugin, + GstMsdkContext * context, guint codec_id, + GstCaps * sink_caps, GstCaps * src_caps) { gboolean ret = TRUE; switch (codec_id) { case MFX_CODEC_AVC: - ret = gst_element_register (plugin, "msdkh264enc", GST_RANK_NONE, - GST_TYPE_MSDKH264ENC); + ret = gst_msdkh264enc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE); break; case MFX_CODEC_HEVC: - ret = gst_element_register (plugin, "msdkh265enc", GST_RANK_NONE, - GST_TYPE_MSDKH265ENC); + ret = gst_msdkh265enc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE);; break; case MFX_CODEC_MPEG2: - ret = gst_element_register (plugin, "msdkmpeg2enc", GST_RANK_NONE, - GST_TYPE_MSDKMPEG2ENC); + ret = gst_msdkmpeg2enc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE); break; #ifdef USE_MSDK_VP9_ENC case MFX_CODEC_VP9: - ret = gst_element_register (plugin, "msdkvp9enc", GST_RANK_NONE, - GST_TYPE_MSDKVP9ENC); + ret = gst_msdkvp9enc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE); break; #endif #ifdef USE_MSDK_AV1_ENC case MFX_CODEC_AV1: - ret = gst_element_register (plugin, "msdkav1enc", GST_RANK_NONE, - GST_TYPE_MSDKAV1ENC); + ret = gst_msdkav1enc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE); break; #endif case MFX_CODEC_JPEG: - ret = gst_element_register (plugin, "msdkmjpegenc", GST_RANK_NONE, - GST_TYPE_MSDKMJPEGENC); + ret = gst_msdkmjpegenc_register (plugin, + context, sink_caps, src_caps, GST_RANK_NONE); break; default: ret = FALSE; @@ -209,11 +211,26 @@ static void _register_encoders (GstPlugin * plugin, GstMsdkContext * context, mfxEncoderDescription * enc_desc) { + GstCaps *sink_caps = NULL; + GstCaps *src_caps = NULL; + for (guint c = 0; c < enc_desc->NumCodecs; c++) { - if (!_register_encoder (plugin, enc_desc->Codecs[c].CodecID)) { + if (!gst_msdkcaps_enc_create_caps (context, enc_desc, + enc_desc->Codecs[c].CodecID, &sink_caps, &src_caps)) { + GST_WARNING ("Failed to create caps for %" GST_FOURCC_FORMAT " ENC", + GST_FOURCC_ARGS (enc_desc->Codecs[c].CodecID)); + continue; + } + + if (!_register_encoder (plugin, + context, enc_desc->Codecs[c].CodecID, sink_caps, src_caps)) { GST_WARNING ("Failed to register %" GST_FOURCC_FORMAT " ENC", GST_FOURCC_ARGS (enc_desc->Codecs[c].CodecID)); + continue; } + + gst_caps_unref (sink_caps); + gst_caps_unref (src_caps); } } @@ -269,11 +286,26 @@ static const guint dec_codecs[] = { static void _register_encoders (GstPlugin * plugin, GstMsdkContext * context) { + GstCaps *sink_caps = NULL; + GstCaps *src_caps = NULL; + for (guint c = 0; c < G_N_ELEMENTS (enc_codecs); c++) { - if (!_register_encoder (plugin, 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])); + continue; + } + + if (!_register_encoder (plugin, context, + enc_codecs[c], sink_caps, src_caps)) { GST_WARNING ("Failed to register %" GST_FOURCC_FORMAT " ENC", GST_FOURCC_ARGS (enc_codecs[c])); + continue; } + + gst_caps_unref (sink_caps); + gst_caps_unref (src_caps); } } diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c index 27327e05f0..7f4ad5a506 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.c @@ -56,6 +56,15 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkav1enc_debug); #define GST_CAT_DEFAULT gst_msdkav1enc_debug +#define GST_MSDKAV1ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkAV1Enc)) +#define GST_MSDKAV1ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkAV1EncClass)) +#define GST_IS_MSDKAV1ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#define GST_IS_MSDKAV1ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) + enum { PROP_TILE_ROW = GST_MSDKENC_PROP_MAX, @@ -69,29 +78,16 @@ enum #define PROP_B_PYRAMID_DEFAULT MFX_B_REF_UNKNOWN #define PROP_P_PYRAMID_DEFAULT MFX_P_REF_DEFAULT -#define RAW_FORMATS "NV12, P010_10LE" -#define PROFILES "main" - -#define COMMON_FORMAT "{ " RAW_FORMATS " }" -#define SRC_PROFILES "{ " PROFILES " }" - -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, - COMMON_FORMAT))); - 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) " SRC_PROFILES) + "profile = (string) main") ); -#define gst_msdkav1enc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkAV1Enc, gst_msdkav1enc, GST_TYPE_MSDKENC); +static GstElementClass *parent_class = NULL; static gboolean gst_msdkav1enc_set_format (GstMsdkEnc * encoder) @@ -314,26 +310,9 @@ gst_msdkav1enc_finalize (GObject * object) } static void -gst_msdkav1enc_class_init (GstMsdkAV1EncClass * klass) +_msdkav1enc_install_properties (GObjectClass * gobject_class, + GstMsdkEncClass * encoder_class) { - GObjectClass *gobject_class; - GstElementClass *element_class; - GstMsdkEncClass *encoder_class; - - gobject_class = G_OBJECT_CLASS (klass); - element_class = GST_ELEMENT_CLASS (klass); - encoder_class = GST_MSDKENC_CLASS (klass); - - gobject_class->finalize = gst_msdkav1enc_finalize; - gobject_class->set_property = gst_msdkav1enc_set_property; - gobject_class->get_property = gst_msdkav1enc_get_property; - - encoder_class->set_format = gst_msdkav1enc_set_format; - encoder_class->configure = gst_msdkav1enc_configure; - encoder_class->set_src_caps = gst_msdkav1enc_set_src_caps; - encoder_class->qp_max = 255; - encoder_class->qp_min = 0; - gst_msdkenc_install_common_properties (encoder_class); g_object_class_install_property (gobject_class, PROP_TILE_ROW, @@ -357,6 +336,33 @@ gst_msdkav1enc_class_init (GstMsdkAV1EncClass * klass) g_param_spec_boolean ("p-pyramid", "P-pyramid", "Enable P-Pyramid Reference structure", PROP_P_PYRAMID_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} + +static void +gst_msdkav1enc_class_init (gpointer klass, gpointer data) +{ + GObjectClass *gobject_class; + GstElementClass *element_class; + GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); + + gobject_class = G_OBJECT_CLASS (klass); + element_class = GST_ELEMENT_CLASS (klass); + encoder_class = GST_MSDKENC_CLASS (klass); + + gobject_class->finalize = gst_msdkav1enc_finalize; + gobject_class->set_property = gst_msdkav1enc_set_property; + gobject_class->get_property = gst_msdkav1enc_get_property; + + encoder_class->set_format = gst_msdkav1enc_set_format; + encoder_class->configure = gst_msdkav1enc_configure; + encoder_class->set_src_caps = gst_msdkav1enc_set_src_caps; + encoder_class->qp_max = 255; + encoder_class->qp_min = 0; + + _msdkav1enc_install_properties (gobject_class, encoder_class); gst_element_class_set_static_metadata (element_class, "Intel MSDK AV1 encoder", @@ -365,15 +371,65 @@ gst_msdkav1enc_class_init (GstMsdkAV1EncClass * klass) "Haihao Xiang , " "Mengkejiergeli Ba "); - gst_element_class_add_static_pad_template (element_class, &sink_factory); - gst_element_class_add_static_pad_template (element_class, &src_factory); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkav1enc_init (GstMsdkAV1Enc * thiz) +gst_msdkav1enc_init (GTypeInstance * instance, gpointer g_class) { + GstMsdkAV1Enc *thiz = GST_MSDKAV1ENC (instance); thiz->num_tile_rows = PROP_TILE_ROW_DEFAULT; thiz->num_tile_cols = PROP_TILE_COL_DEFAULT; thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT; thiz->p_pyramid = PROP_P_PYRAMID_DEFAULT; } + +gboolean +gst_msdkav1enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkAV1EncClass), + .class_init = gst_msdkav1enc_class_init, + .instance_size = sizeof (GstMsdkAV1Enc), + .instance_init = gst_msdkav1enc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_ref (sink_caps); + cdata->src_caps = gst_caps_ref (src_caps); + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkAV1Enc"); + feature_name = g_strdup ("msdkav1enc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.h index 6f3335dc37..b5f324c068 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkav1enc.h @@ -37,17 +37,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKAV1ENC \ - (gst_msdkav1enc_get_type()) -#define GST_MSDKAV1ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKAV1ENC,GstMsdkAV1Enc)) -#define GST_MSDKAV1ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKAV1ENC,GstMsdkAV1EncClass)) -#define GST_IS_MSDKAV1ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKAV1ENC)) -#define GST_IS_MSDKAV1ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKAV1ENC)) - typedef struct _GstMsdkAV1Enc GstMsdkAV1Enc; typedef struct _GstMsdkAV1EncClass GstMsdkAV1EncClass; @@ -71,7 +60,10 @@ struct _GstMsdkAV1EncClass GstMsdkEncClass parent_class; }; -GType gst_msdkav1enc_get_type (void); +gboolean +gst_msdkav1enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c index abeeb6c784..b7de9062fc 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c @@ -78,24 +78,6 @@ static void gst_msdkenc_close_encoder (GstMsdkEnc * thiz); GST_DEBUG_CATEGORY_EXTERN (gst_msdkenc_debug); #define GST_CAT_DEFAULT gst_msdkenc_debug -#ifdef _WIN32 -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR - ("{ NV12, I420, YV12, YUY2, UYVY, BGRA }", "NV12") "; " - GST_MSDK_CAPS_MAKE_WITH_D3D11_FEATURE ("NV12")) - ); -#else -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR - ("{ NV12, I420, YV12, YUY2, UYVY, BGRA }", "{ NV12, BGRx }") "; " - GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("NV12")) - ); -#endif - #define PROP_HARDWARE_DEFAULT TRUE #define PROP_ASYNC_DEPTH_DEFAULT 4 #define PROP_TARGET_USAGE_DEFAULT (MFX_TARGETUSAGE_BALANCED) @@ -2276,8 +2258,6 @@ gst_msdkenc_class_init (GstMsdkEncClass * klass) GST_DEBUG_FUNCPTR (gst_msdkenc_propose_allocation); gstencoder_class->src_query = GST_DEBUG_FUNCPTR (gst_msdkenc_src_query); gstencoder_class->sink_query = GST_DEBUG_FUNCPTR (gst_msdkenc_sink_query); - - gst_element_class_add_static_pad_template (element_class, &sink_factory); } static void diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h index abefdbe2d7..123dabd7e3 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h @@ -59,6 +59,7 @@ G_BEGIN_DECLS typedef struct _GstMsdkEnc GstMsdkEnc; typedef struct _GstMsdkEncClass GstMsdkEncClass; typedef struct _MsdkEncTask MsdkEncTask; +typedef struct _MsdkEncCData MsdkEncCData; enum { @@ -209,6 +210,12 @@ struct _MsdkEncTask mfxBitstream output_bitstream; }; +struct _MsdkEncCData +{ + GstCaps *sink_caps; + GstCaps *src_caps; +}; + GType gst_msdkenc_get_type (void); void gst_msdkenc_add_extra_param (GstMsdkEnc * thiz, mfxExtBuffer * param); diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c index effcb3935c..cf8a070202 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.c @@ -58,6 +58,15 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh264enc_debug); #define GST_CAT_DEFAULT gst_msdkh264enc_debug +#define GST_MSDKH264ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkH264Enc)) +#define GST_MSDKH264ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkH264EncClass)) +#define GST_IS_MSDKH264ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#define GST_IS_MSDKH264ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) + enum { PROP_CABAC = GST_MSDKENC_PROP_MAX, @@ -113,6 +122,8 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "profile = (string) { high, main, baseline, constrained-baseline }") ); +static GstElementClass *parent_class = NULL; + static GType gst_msdkh264enc_frame_packing_get_type (void) { @@ -133,9 +144,6 @@ gst_msdkh264enc_frame_packing_get_type (void) return format_type; } -#define gst_msdkh264enc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkH264Enc, gst_msdkh264enc, GST_TYPE_MSDKENC); - static void gst_msdkh264enc_insert_sei (GstMsdkH264Enc * thiz, GstVideoCodecFrame * frame, GstMemory * sei_mem) @@ -733,31 +741,9 @@ gst_msdkh264enc_set_extra_params (GstMsdkEnc * encoder, } static void -gst_msdkh264enc_class_init (GstMsdkH264EncClass * klass) +_msdkh264enc_install_properties (GObjectClass * gobject_class, + GstMsdkEncClass * encoder_class) { - GObjectClass *gobject_class; - GstElementClass *element_class; - GstVideoEncoderClass *videoencoder_class; - GstMsdkEncClass *encoder_class; - - gobject_class = G_OBJECT_CLASS (klass); - element_class = GST_ELEMENT_CLASS (klass); - videoencoder_class = GST_VIDEO_ENCODER_CLASS (klass); - encoder_class = GST_MSDKENC_CLASS (klass); - - gobject_class->dispose = gst_msdkh264enc_dispose; - gobject_class->finalize = gst_msdkh264enc_finalize; - gobject_class->set_property = gst_msdkh264enc_set_property; - gobject_class->get_property = gst_msdkh264enc_get_property; - - videoencoder_class->pre_push = gst_msdkh264enc_pre_push; - - encoder_class->set_format = gst_msdkh264enc_set_format; - encoder_class->configure = gst_msdkh264enc_configure; - encoder_class->set_src_caps = gst_msdkh264enc_set_src_caps; - encoder_class->need_reconfig = gst_msdkh264enc_need_reconfig; - encoder_class->set_extra_params = gst_msdkh264enc_set_extra_params; - gst_msdkenc_install_common_properties (encoder_class); g_object_class_install_property (gobject_class, PROP_CABAC, @@ -855,17 +841,60 @@ gst_msdkh264enc_class_init (GstMsdkH264EncClass * klass) "Option of disable deblocking idc", 0, 2, PROP_DBLK_IDC_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} + +static void +gst_msdkh264enc_class_init (gpointer klass, gpointer data) +{ + GObjectClass *gobject_class; + GstElementClass *element_class; + GstVideoEncoderClass *videoencoder_class; + GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); + + gobject_class = G_OBJECT_CLASS (klass); + element_class = GST_ELEMENT_CLASS (klass); + videoencoder_class = GST_VIDEO_ENCODER_CLASS (klass); + encoder_class = GST_MSDKENC_CLASS (klass); + + gobject_class->dispose = gst_msdkh264enc_dispose; + gobject_class->finalize = gst_msdkh264enc_finalize; + gobject_class->set_property = gst_msdkh264enc_set_property; + gobject_class->get_property = gst_msdkh264enc_get_property; + + videoencoder_class->pre_push = gst_msdkh264enc_pre_push; + + encoder_class->set_format = gst_msdkh264enc_set_format; + encoder_class->configure = gst_msdkh264enc_configure; + encoder_class->set_src_caps = gst_msdkh264enc_set_src_caps; + encoder_class->need_reconfig = gst_msdkh264enc_need_reconfig; + encoder_class->set_extra_params = gst_msdkh264enc_set_extra_params; + + _msdkh264enc_install_properties (gobject_class, encoder_class); gst_element_class_set_static_metadata (element_class, "Intel MSDK H264 encoder", "Codec/Encoder/Video/Hardware", "H264 video encoder based on " MFX_API_SDK, "Josep Torra "); - gst_element_class_add_static_pad_template (element_class, &src_factory); + + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkh264enc_init (GstMsdkH264Enc * thiz) +gst_msdkh264enc_init (GTypeInstance * instance, gpointer g_class) { + GstMsdkH264Enc *thiz = GST_MSDKH264ENC (instance); thiz->cabac = PROP_CABAC_DEFAULT; thiz->lowpower = PROP_LOWPOWER_DEFAULT; thiz->frame_packing = PROP_FRAME_PACKING_DEFAULT; @@ -883,3 +912,48 @@ gst_msdkh264enc_init (GstMsdkH264Enc * thiz) thiz->intra_refresh_cycle_dist = PROP_INTRA_REFRESH_CYCLE_DIST_DEFAULT; thiz->dblk_idc = PROP_DBLK_IDC_DEFAULT; } + +gboolean +gst_msdkh264enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkH264EncClass), + .class_init = gst_msdkh264enc_class_init, + .instance_size = sizeof (GstMsdkH264Enc), + .instance_init = gst_msdkh264enc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_ref (sink_caps); + cdata->src_caps = gst_caps_copy (src_caps); + + gst_caps_set_simple (cdata->src_caps, + "alignment", G_TYPE_STRING, "au", + "stream-format", G_TYPE_STRING, "byte-stream", NULL); + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkH264Enc"); + feature_name = g_strdup ("msdkh264enc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.h index 7d5102c9d2..e003b4c993 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh264enc.h @@ -37,17 +37,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKH264ENC \ - (gst_msdkh264enc_get_type()) -#define GST_MSDKH264ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKH264ENC,GstMsdkH264Enc)) -#define GST_MSDKH264ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKH264ENC,GstMsdkH264EncClass)) -#define GST_IS_MSDKH264ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKH264ENC)) -#define GST_IS_MSDKH264ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKH264ENC)) - typedef struct _GstMsdkH264Enc GstMsdkH264Enc; typedef struct _GstMsdkH264EncClass GstMsdkH264EncClass; @@ -90,7 +79,10 @@ struct _GstMsdkH264EncClass GstMsdkEncClass parent_class; }; -GType gst_msdkh264enc_get_type (void); +gboolean +gst_msdkh264enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c index 0a27e6dff9..a93adc6050 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.c @@ -56,6 +56,15 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265enc_debug); #define GST_CAT_DEFAULT gst_msdkh265enc_debug +#define GST_MSDKH265ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkH265Enc)) +#define GST_MSDKH265ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkH265EncClass)) +#define GST_IS_MSDKH265ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#define GST_IS_MSDKH265ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) + enum { #ifndef GST_REMOVE_DEPRECATED @@ -101,57 +110,32 @@ enum #define PROP_INTRA_REFRESH_CYCLE_DIST_DEFAULT 0 #define PROP_DBLK_IDC_DEFAULT 0 -#define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, BGR10A2_LE, P010_10LE, VUYA" #define PROFILES "main, main-10, main-444, main-still-picture, main-10-still-picture" -#define COMMON_FORMAT "{ " RAW_FORMATS " }" #define PRFOLIE_STR "{ " PROFILES " }" - #if (MFX_VERSION >= 1027) #undef COMMON_FORMAT #undef PRFOLIE_STR -#define FORMATS_1027 RAW_FORMATS ", Y410, Y210" #define PROFILES_1027 PROFILES ", main-444-10, main-422-10" -#define COMMON_FORMAT "{ " FORMATS_1027 " }" #define PRFOLIE_STR "{ " PROFILES_1027 " }" #endif #if (MFX_VERSION >= 1031) #undef COMMON_FORMAT #undef PRFOLIE_STR -#define FORMATS_1031 FORMATS_1027 ", P012_LE" #define PROFILES_1031 PROFILES_1027 ", main-12" -#define COMMON_FORMAT "{ " FORMATS_1031 " }" #define PRFOLIE_STR "{ " PROFILES_1031 " }" #endif #if (MFX_VERSION >= 1032) #undef COMMON_FORMAT #undef PRFOLIE_STR -#define FORMATS_1032 FORMATS_1031 #define PROFILES_1032 PROFILES_1031 ", screen-extended-main, " \ "screen-extended-main-10, screen-extended-main-444, " \ "screen-extended-main-444-10" -#define COMMON_FORMAT "{ " FORMATS_1032 " }" #define PRFOLIE_STR "{ " PROFILES_1032 " }" #endif -#ifdef _WIN32 -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, - "{ NV12, P010_10LE }") "; " - GST_MSDK_CAPS_MAKE_WITH_D3D11_FEATURE ("{ NV12, P010_10LE }"))); -#else -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, - "{ NV12, P010_10LE }") "; " - GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("NV12"))); -#endif - static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -162,8 +146,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "profile = (string) " PRFOLIE_STR) ); -#define gst_msdkh265enc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkH265Enc, gst_msdkh265enc, GST_TYPE_MSDKENC); +static GstElementClass *parent_class = NULL; static void gst_msdkh265enc_insert_sei (GstMsdkH265Enc * thiz, GstVideoCodecFrame * frame, @@ -911,31 +894,9 @@ gst_msdkh265enc_need_conversion (GstMsdkEnc * encoder, GstVideoInfo * info, } static void -gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass) +_msdkh265enc_install_properties (GObjectClass * gobject_class, + GstMsdkEncClass * encoder_class) { - GObjectClass *gobject_class; - GstElementClass *element_class; - GstVideoEncoderClass *videoencoder_class; - GstMsdkEncClass *encoder_class; - - gobject_class = G_OBJECT_CLASS (klass); - element_class = GST_ELEMENT_CLASS (klass); - videoencoder_class = GST_VIDEO_ENCODER_CLASS (klass); - encoder_class = GST_MSDKENC_CLASS (klass); - - gobject_class->finalize = gst_msdkh265enc_finalize; - gobject_class->set_property = gst_msdkh265enc_set_property; - gobject_class->get_property = gst_msdkh265enc_get_property; - - videoencoder_class->pre_push = gst_msdkh265enc_pre_push; - - encoder_class->set_format = gst_msdkh265enc_set_format; - encoder_class->configure = gst_msdkh265enc_configure; - encoder_class->set_src_caps = gst_msdkh265enc_set_src_caps; - encoder_class->need_reconfig = gst_msdkh265enc_need_reconfig; - encoder_class->set_extra_params = gst_msdkh265enc_set_extra_params; - encoder_class->need_conversion = gst_msdkh265enc_need_conversion; - gst_msdkenc_install_common_properties (encoder_class); #ifndef GST_REMOVE_DEPRECATED @@ -1028,6 +989,38 @@ gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass) "Option of disable deblocking idc", 0, 2, PROP_DBLK_IDC_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} + +static void +gst_msdkh265enc_class_init (gpointer klass, gpointer data) +{ + GObjectClass *gobject_class; + GstElementClass *element_class; + GstVideoEncoderClass *videoencoder_class; + GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); + + gobject_class = G_OBJECT_CLASS (klass); + element_class = GST_ELEMENT_CLASS (klass); + videoencoder_class = GST_VIDEO_ENCODER_CLASS (klass); + encoder_class = GST_MSDKENC_CLASS (klass); + + gobject_class->finalize = gst_msdkh265enc_finalize; + gobject_class->set_property = gst_msdkh265enc_set_property; + gobject_class->get_property = gst_msdkh265enc_get_property; + + videoencoder_class->pre_push = gst_msdkh265enc_pre_push; + + encoder_class->set_format = gst_msdkh265enc_set_format; + encoder_class->configure = gst_msdkh265enc_configure; + encoder_class->set_src_caps = gst_msdkh265enc_set_src_caps; + encoder_class->need_reconfig = gst_msdkh265enc_need_reconfig; + encoder_class->set_extra_params = gst_msdkh265enc_set_extra_params; + encoder_class->need_conversion = gst_msdkh265enc_need_conversion; + + _msdkh265enc_install_properties (gobject_class, encoder_class); gst_element_class_set_static_metadata (element_class, "Intel MSDK H265 encoder", @@ -1035,14 +1028,23 @@ gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass) "H265 video encoder based on " MFX_API_SDK, "Josep Torra "); - gst_element_class_add_static_pad_template (element_class, &sink_factory); - gst_element_class_add_static_pad_template (element_class, &src_factory); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkh265enc_init (GstMsdkH265Enc * thiz) +gst_msdkh265enc_init (GTypeInstance * instance, gpointer g_class) { - GstMsdkEnc *msdk_enc = (GstMsdkEnc *) thiz; + GstMsdkH265Enc *thiz = GST_MSDKH265ENC (instance); + GstMsdkEnc *msdk_enc = (GstMsdkEnc *) instance; thiz->lowpower = PROP_LOWPOWER_DEFAULT; thiz->num_tile_rows = PROP_TILE_ROW_DEFAULT; thiz->num_tile_cols = PROP_TILE_COL_DEFAULT; @@ -1060,3 +1062,53 @@ gst_msdkh265enc_init (GstMsdkH265Enc * thiz) thiz->dblk_idc = PROP_DBLK_IDC_DEFAULT; msdk_enc->num_extra_frames = 1; } + +gboolean +gst_msdkh265enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkH265EncClass), + .class_init = gst_msdkh265enc_class_init, + .instance_size = sizeof (GstMsdkH265Enc), + .instance_init = gst_msdkh265enc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_copy (sink_caps); + cdata->src_caps = gst_caps_copy (src_caps); + +#ifdef _WIN32 + gst_msdkcaps_set_strings (cdata->sink_caps, + "memory:D3D11Memory", "format", "NV12, P010_10LE"); +#endif + + gst_caps_set_simple (cdata->src_caps, + "alignment", G_TYPE_STRING, "au", + "stream-format", G_TYPE_STRING, "byte-stream", NULL); + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkH265Enc"); + feature_name = g_strdup ("msdkh265enc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.h index ef241a7cc2..902b42f50d 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkh265enc.h @@ -37,17 +37,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKH265ENC \ - (gst_msdkh265enc_get_type()) -#define GST_MSDKH265ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKH265ENC,GstMsdkH265Enc)) -#define GST_MSDKH265ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKH265ENC,GstMsdkH265EncClass)) -#define GST_IS_MSDKH265ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKH265ENC)) -#define GST_IS_MSDKH265ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKH265ENC)) - typedef struct _GstMsdkH265Enc GstMsdkH265Enc; typedef struct _GstMsdkH265EncClass GstMsdkH265EncClass; @@ -89,7 +78,10 @@ struct _GstMsdkH265EncClass GstMsdkEncClass parent_class; }; -GType gst_msdkh265enc_get_type (void); +gboolean +gst_msdkh265enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.c index 0ed7d98afe..1652a79401 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.c @@ -62,6 +62,15 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkmjpegenc_debug); #define GST_CAT_DEFAULT gst_msdkmjpegenc_debug +#define GST_MSDKMJPEGENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkMJPEGEnc)) +#define GST_MSDKMJPEGENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkMJPEGEncClass)) +#define GST_IS_MSDKMJPEGENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#define GST_IS_MSDKMJPEGENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_FROM_CLASS (klass))) + enum { PROP_0, @@ -70,16 +79,7 @@ enum #define DEFAULT_QUALITY 85 -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("image/jpeg, " - "framerate = (fraction) [0/1, MAX], " - "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ]") - ); - -#define gst_msdkmjpegenc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkMJPEGEnc, gst_msdkmjpegenc, GST_TYPE_MSDKENC); +static GstElementClass *parent_class = NULL; static gboolean gst_msdkmjpegenc_set_format (GstMsdkEnc * encoder) @@ -168,11 +168,14 @@ gst_msdkmjpegenc_need_conversion (GstMsdkEnc * encoder, GstVideoInfo * info, } static void -gst_msdkmjpegenc_class_init (GstMsdkMJPEGEncClass * klass) +gst_msdkmjpegenc_class_init (gpointer klass, gpointer data) { GObjectClass *gobject_class; GstElementClass *element_class; GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); gobject_class = G_OBJECT_CLASS (klass); element_class = GST_ELEMENT_CLASS (klass); @@ -196,11 +199,62 @@ gst_msdkmjpegenc_class_init (GstMsdkMJPEGEncClass * klass) "MJPEG video encoder based on " MFX_API_SDK, "Scott D Phillips "); - gst_element_class_add_static_pad_template (element_class, &src_factory); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkmjpegenc_init (GstMsdkMJPEGEnc * thiz) +gst_msdkmjpegenc_init (GTypeInstance * instance, gpointer g_class) { + GstMsdkMJPEGEnc *thiz = GST_MSDKMJPEGENC (instance); thiz->quality = DEFAULT_QUALITY; } + +gboolean +gst_msdkmjpegenc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkMJPEGEncClass), + .class_init = gst_msdkmjpegenc_class_init, + .instance_size = sizeof (GstMsdkMJPEGEnc), + .instance_init = gst_msdkmjpegenc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_ref (sink_caps); + cdata->src_caps = gst_caps_ref (src_caps); + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkMJPEGEnc"); + feature_name = g_strdup ("msdkmjpegenc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.h index f8cd56e546..ba19f0b01f 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmjpegenc.h @@ -36,17 +36,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKMJPEGENC \ - (gst_msdkmjpegenc_get_type()) -#define GST_MSDKMJPEGENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKMJPEGENC,GstMsdkMJPEGEnc)) -#define GST_MSDKMJPEGENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKMJPEGENC,GstMsdkMJPEGEncClass)) -#define GST_IS_MSDKMJPEGENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKMJPEGENC)) -#define GST_IS_MSDKMJPEGENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKMJPEGENC)) - typedef struct _GstMsdkMJPEGEnc GstMsdkMJPEGEnc; typedef struct _GstMsdkMJPEGEncClass GstMsdkMJPEGEncClass; @@ -61,7 +50,10 @@ struct _GstMsdkMJPEGEncClass GstMsdkEncClass parent_class; }; -GType gst_msdkmjpegenc_get_type (void); +gboolean +gst_msdkmjpegenc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c index 1de428411b..656085e710 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.c @@ -54,6 +54,15 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkmpeg2enc_debug); #define GST_CAT_DEFAULT gst_msdkmpeg2enc_debug +#define GST_MSDKMPEG2ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkMPEG2Enc)) +#define GST_MSDKMPEG2ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkMPEG2EncClass)) +#define GST_IS_MSDKMPEG2ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#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, @@ -64,8 +73,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "profile = (string) { high, main, simple }") ); -#define gst_msdkmpeg2enc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkMPEG2Enc, gst_msdkmpeg2enc, GST_TYPE_MSDKENC); +static GstElementClass *parent_class = NULL; static gboolean gst_msdkmpeg2enc_set_format (GstMsdkEnc * encoder) @@ -188,11 +196,14 @@ gst_msdkmpeg2enc_get_property (GObject * object, guint prop_id, GValue * value, } static void -gst_msdkmpeg2enc_class_init (GstMsdkMPEG2EncClass * klass) +gst_msdkmpeg2enc_class_init (gpointer klass, gpointer data) { GObjectClass *gobject_class; GstElementClass *element_class; GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); gobject_class = G_OBJECT_CLASS (klass); element_class = GST_ELEMENT_CLASS (klass); @@ -213,10 +224,64 @@ gst_msdkmpeg2enc_class_init (GstMsdkMPEG2EncClass * klass) "MPEG2 video encoder based on " MFX_API_SDK, "Josep Torra "); - gst_element_class_add_static_pad_template (element_class, &src_factory); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkmpeg2enc_init (GstMsdkMPEG2Enc * thiz) +gst_msdkmpeg2enc_init (GTypeInstance * instance, gpointer g_class) { } + +gboolean +gst_msdkmpeg2enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkMPEG2EncClass), + .class_init = gst_msdkmpeg2enc_class_init, + .instance_size = sizeof (GstMsdkMPEG2Enc), + .instance_init = gst_msdkmpeg2enc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_ref (sink_caps); + cdata->src_caps = gst_caps_copy (src_caps); + + gst_caps_set_simple (cdata->src_caps, + "mpegversion", G_TYPE_INT, 2, + "systemstream", G_TYPE_BOOLEAN, FALSE, NULL); + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkMPEG2Enc"); + feature_name = g_strdup ("msdkmpeg2enc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.h index 0439ba4a3f..71520c3428 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkmpeg2enc.h @@ -36,17 +36,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKMPEG2ENC \ - (gst_msdkmpeg2enc_get_type()) -#define GST_MSDKMPEG2ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKMPEG2ENC,GstMsdkMPEG2Enc)) -#define GST_MSDKMPEG2ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKMPEG2ENC,GstMsdkMPEG2EncClass)) -#define GST_IS_MSDKMPEG2ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKMPEG2ENC)) -#define GST_IS_MSDKMPEG2ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKMPEG2ENC)) - typedef struct _GstMsdkMPEG2Enc GstMsdkMPEG2Enc; typedef struct _GstMsdkMPEG2EncClass GstMsdkMPEG2EncClass; @@ -62,7 +51,10 @@ struct _GstMsdkMPEG2EncClass GstMsdkEncClass parent_class; }; -GType gst_msdkmpeg2enc_get_type (void); +gboolean +gst_msdkmpeg2enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c index c2c0d00f15..35677217ba 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.c @@ -56,33 +56,23 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9enc_debug); #define GST_CAT_DEFAULT gst_msdkvp9enc_debug -#define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, P010_10LE, VUYA" +#define GST_MSDKVP9ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_FROM_INSTANCE (obj), GstMsdkVP9Enc)) +#define GST_MSDKVP9ENC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_FROM_CLASS (klass), GstMsdkVP9EncClass)) +#define GST_IS_MSDKVP9ENC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_FROM_INSTANCE (obj))) +#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 COMMON_FORMAT "{ " RAW_FORMATS ", Y410 }" #define SRC_PROFILES "{ " PROFILES ", 3 }" #else -#define COMMON_FORMAT "{ " RAW_FORMATS " }" #define SRC_PROFILES "{ " PROFILES " }" #endif -#ifdef _WIN32 -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, - "{ NV12, P010_10LE }") "; " - GST_MSDK_CAPS_MAKE_WITH_D3D11_FEATURE ("{ NV12, P010_10LE }"))); -#else -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, - "{ NV12, P010_10LE }") "; " - GST_MSDK_CAPS_MAKE_WITH_VA_FEATURE ("NV12"))); -#endif - static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -92,8 +82,7 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", "profile = (string) " SRC_PROFILES) ); -#define gst_msdkvp9enc_parent_class parent_class -G_DEFINE_TYPE (GstMsdkVP9Enc, gst_msdkvp9enc, GST_TYPE_MSDKENC); +static GstElementClass *parent_class = NULL; static gboolean gst_msdkvp9enc_set_format (GstMsdkEnc * encoder) @@ -266,11 +255,14 @@ gst_msdkvp9enc_get_property (GObject * object, guint prop_id, GValue * value, } static void -gst_msdkvp9enc_class_init (GstMsdkVP9EncClass * klass) +gst_msdkvp9enc_class_init (gpointer klass, gpointer data) { GObjectClass *gobject_class; GstElementClass *element_class; GstMsdkEncClass *encoder_class; + MsdkEncCData *cdata = data; + + parent_class = g_type_class_peek_parent (klass); gobject_class = G_OBJECT_CLASS (klass); element_class = GST_ELEMENT_CLASS (klass); @@ -293,11 +285,65 @@ gst_msdkvp9enc_class_init (GstMsdkVP9EncClass * klass) "VP9 video encoder based on " MFX_API_SDK, "Haihao Xiang "); - gst_element_class_add_static_pad_template (element_class, &sink_factory); - gst_element_class_add_static_pad_template (element_class, &src_factory); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, + cdata->sink_caps)); + gst_element_class_add_pad_template (element_class, + gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, + cdata->src_caps)); + + gst_caps_unref (cdata->sink_caps); + gst_caps_unref (cdata->src_caps); + g_free (cdata); } static void -gst_msdkvp9enc_init (GstMsdkVP9Enc * thiz) +gst_msdkvp9enc_init (GTypeInstance * instance, gpointer g_class) { } + +gboolean +gst_msdkvp9enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank) +{ + GType type; + MsdkEncCData *cdata; + gchar *type_name, *feature_name; + gboolean ret = FALSE; + + GTypeInfo type_info = { + .class_size = sizeof (GstMsdkVP9EncClass), + .class_init = gst_msdkvp9enc_class_init, + .instance_size = sizeof (GstMsdkVP9Enc), + .instance_init = gst_msdkvp9enc_init + }; + + cdata = g_new (MsdkEncCData, 1); + cdata->sink_caps = gst_caps_copy (sink_caps); + cdata->src_caps = gst_caps_ref (src_caps); + +#ifdef _WIN32 + gst_msdkcaps_set_strings (cdata->sink_caps, + "memory:D3D11Memory", "format", "NV12, P010_10LE"); +#endif + + GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + GST_MINI_OBJECT_FLAG_SET (cdata->src_caps, + GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); + + type_info.class_data = cdata; + + type_name = g_strdup ("GstMsdkVP9Enc"); + feature_name = g_strdup ("msdkvp9enc"); + + type = g_type_register_static (GST_TYPE_MSDKENC, type_name, &type_info, 0); + if (type) + ret = gst_element_register (plugin, feature_name, rank, type); + + g_free (type_name); + g_free (feature_name); + + return ret; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.h index f784347c44..441970e97f 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvp9enc.h @@ -36,17 +36,6 @@ G_BEGIN_DECLS -#define GST_TYPE_MSDKVP9ENC \ - (gst_msdkvp9enc_get_type()) -#define GST_MSDKVP9ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKVP9ENC,GstMsdkVP9Enc)) -#define GST_MSDKVP9ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKVP9ENC,GstMsdkVP9EncClass)) -#define GST_IS_MSDKVP9ENC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKVP9ENC)) -#define GST_IS_MSDKVP9ENC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKVP9ENC)) - typedef struct _GstMsdkVP9Enc GstMsdkVP9Enc; typedef struct _GstMsdkVP9EncClass GstMsdkVP9EncClass; @@ -64,7 +53,10 @@ struct _GstMsdkVP9EncClass GstMsdkEncClass parent_class; }; -GType gst_msdkvp9enc_get_type (void); +gboolean +gst_msdkvp9enc_register (GstPlugin * plugin, + GstMsdkContext * context, GstCaps * sink_caps, + GstCaps * src_caps, guint rank); G_END_DECLS