diff --git a/sys/msdk/gstmsdkh264enc.c b/sys/msdk/gstmsdkh264enc.c index adaf315acf..939b4e76d6 100644 --- a/sys/msdk/gstmsdkh264enc.c +++ b/sys/msdk/gstmsdkh264enc.c @@ -45,12 +45,21 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh264enc_debug); enum { PROP_CABAC = GST_MSDKENC_PROP_MAX, +#ifndef GST_REMOVE_DEPRECATED PROP_LOW_POWER, +#endif PROP_FRAME_PACKING, PROP_RC_LA_DOWNSAMPLING, PROP_TRELLIS, PROP_MAX_SLICE_SIZE, - PROP_B_PYRAMID + PROP_B_PYRAMID, + PROP_TUNE_MODE, +}; + +enum +{ + GST_MSDK_FLAG_LOW_POWER = 1 << 0, + GST_MSDK_FLAG_TUNE_MODE = 1 << 1, }; #define PROP_CABAC_DEFAULT TRUE @@ -60,6 +69,7 @@ enum #define PROP_TRELLIS_DEFAULT _MFX_TRELLIS_NONE #define PROP_MAX_SLICE_SIZE_DEFAULT 0 #define PROP_B_PYRAMID_DEFAULT FALSE +#define PROP_TUNE_MODE_DEFAULT MFX_CODINGOPTION_UNKNOWN static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, @@ -346,8 +356,7 @@ gst_msdkh264enc_configure (GstMsdkEnc * encoder) { GstMsdkH264Enc *thiz = GST_MSDKH264ENC (encoder); - encoder->param.mfx.LowPower = - (thiz->lowpower ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF); + encoder->param.mfx.LowPower = thiz->tune_mode; encoder->param.mfx.CodecId = MFX_CODEC_AVC; encoder->param.mfx.CodecProfile = thiz->profile; encoder->param.mfx.CodecLevel = thiz->level; @@ -517,9 +526,18 @@ gst_msdkh264enc_set_property (GObject * object, guint prop_id, case PROP_CABAC: thiz->cabac = g_value_get_boolean (value); break; +#ifndef GST_REMOVE_DEPRECATED case PROP_LOW_POWER: thiz->lowpower = g_value_get_boolean (value); + thiz->prop_flag |= GST_MSDK_FLAG_LOW_POWER; + + /* Ignore it if user set tune mode explicitly */ + if (!(thiz->prop_flag & GST_MSDK_FLAG_TUNE_MODE)) + thiz->tune_mode = + thiz->lowpower ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; + break; +#endif case PROP_FRAME_PACKING: thiz->frame_packing = g_value_get_enum (value); break; @@ -535,6 +553,10 @@ gst_msdkh264enc_set_property (GObject * object, guint prop_id, case PROP_B_PYRAMID: thiz->b_pyramid = g_value_get_boolean (value); break; + case PROP_TUNE_MODE: + thiz->tune_mode = g_value_get_enum (value); + thiz->prop_flag |= GST_MSDK_FLAG_TUNE_MODE; + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -557,9 +579,11 @@ gst_msdkh264enc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_CABAC: g_value_set_boolean (value, thiz->cabac); break; +#ifndef GST_REMOVE_DEPRECATED case PROP_LOW_POWER: g_value_set_boolean (value, thiz->lowpower); break; +#endif case PROP_FRAME_PACKING: g_value_set_enum (value, thiz->frame_packing); break; @@ -575,6 +599,9 @@ gst_msdkh264enc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_B_PYRAMID: g_value_set_boolean (value, thiz->b_pyramid); break; + case PROP_TUNE_MODE: + g_value_set_enum (value, thiz->tune_mode); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -632,9 +659,13 @@ gst_msdkh264enc_class_init (GstMsdkH264EncClass * klass) g_param_spec_boolean ("cabac", "CABAC", "Enable CABAC entropy coding", PROP_CABAC_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +#ifndef GST_REMOVE_DEPRECATED g_object_class_install_property (gobject_class, PROP_LOW_POWER, - g_param_spec_boolean ("low-power", "Low power", "Enable low power mode", - PROP_LOWPOWER_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_param_spec_boolean ("low-power", "Low power", + "Enable low power mode (DEPRECATED, use tune instead)", + PROP_LOWPOWER_DEFAULT, + G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +#endif g_object_class_install_property (gobject_class, PROP_FRAME_PACKING, g_param_spec_enum ("frame-packing", "Frame Packing", @@ -666,6 +697,12 @@ gst_msdkh264enc_class_init (GstMsdkH264EncClass * klass) "Enable B-Pyramid Reference structure", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_TUNE_MODE, + g_param_spec_enum ("tune", "Encoder tuning", + "Encoder tuning option", + gst_msdkenc_tune_mode_get_type (), PROP_TUNE_MODE_DEFAULT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_set_static_metadata (element_class, "Intel MSDK H264 encoder", "Codec/Encoder/Video/Hardware", "H264 video encoder based on Intel Media SDK", @@ -683,4 +720,5 @@ gst_msdkh264enc_init (GstMsdkH264Enc * thiz) thiz->trellis = PROP_TRELLIS_DEFAULT; thiz->max_slice_size = PROP_MAX_SLICE_SIZE_DEFAULT; thiz->b_pyramid = PROP_B_PYRAMID_DEFAULT; + thiz->tune_mode = PROP_TUNE_MODE_DEFAULT; } diff --git a/sys/msdk/gstmsdkh264enc.h b/sys/msdk/gstmsdkh264enc.h index 230276629f..7e25203380 100644 --- a/sys/msdk/gstmsdkh264enc.h +++ b/sys/msdk/gstmsdkh264enc.h @@ -69,6 +69,8 @@ struct _GstMsdkH264Enc guint trellis; guint max_slice_size; guint b_pyramid; + gint tune_mode; + guint prop_flag; GstH264NalParser *parser; GArray *cc_sei_array; diff --git a/sys/msdk/gstmsdkh265enc.c b/sys/msdk/gstmsdkh265enc.c index 46aa375da3..8a2e88b591 100644 --- a/sys/msdk/gstmsdkh265enc.c +++ b/sys/msdk/gstmsdkh265enc.c @@ -42,16 +42,28 @@ GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265enc_debug); enum { +#ifndef GST_REMOVE_DEPRECATED PROP_LOW_POWER = GST_MSDKENC_PROP_MAX, PROP_TILE_ROW, +#else + PROP_TILE_ROW = GST_MSDKENC_PROP_MAX, +#endif PROP_TILE_COL, PROP_MAX_SLICE_SIZE, + PROP_TUNE_MODE, +}; + +enum +{ + GST_MSDK_FLAG_LOW_POWER = 1 << 0, + GST_MSDK_FLAG_TUNE_MODE = 1 << 1, }; #define PROP_LOWPOWER_DEFAULT FALSE #define PROP_TILE_ROW_DEFAULT 1 #define PROP_TILE_COL_DEFAULT 1 #define PROP_MAX_SLICE_SIZE_DEFAULT 0 +#define PROP_TUNE_MODE_DEFAULT MFX_CODINGOPTION_UNKNOWN #define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, P010_10LE, VUYA" #define PROFILES "main, main-10, main-444" @@ -265,8 +277,7 @@ gst_msdkh265enc_configure (GstMsdkEnc * encoder) h265enc->num_tile_rows * h265enc->num_tile_cols; } - encoder->param.mfx.LowPower = - (h265enc->lowpower ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF); + encoder->param.mfx.LowPower = h265enc->tune_mode; return TRUE; } @@ -387,9 +398,18 @@ gst_msdkh265enc_set_property (GObject * object, guint prop_id, GST_OBJECT_LOCK (thiz); switch (prop_id) { +#ifndef GST_REMOVE_DEPRECATED case PROP_LOW_POWER: thiz->lowpower = g_value_get_boolean (value); + thiz->prop_flag |= GST_MSDK_FLAG_LOW_POWER; + + /* Ignore it if user set tune mode explicitly */ + if (!(thiz->prop_flag & GST_MSDK_FLAG_TUNE_MODE)) + thiz->tune_mode = + thiz->lowpower ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; + break; +#endif case PROP_TILE_ROW: thiz->num_tile_rows = g_value_get_uint (value); @@ -403,6 +423,11 @@ gst_msdkh265enc_set_property (GObject * object, guint prop_id, thiz->max_slice_size = g_value_get_uint (value); break; + case PROP_TUNE_MODE: + thiz->tune_mode = g_value_get_enum (value); + thiz->prop_flag |= GST_MSDK_FLAG_TUNE_MODE; + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -421,9 +446,11 @@ gst_msdkh265enc_get_property (GObject * object, guint prop_id, GValue * value, GST_OBJECT_LOCK (thiz); switch (prop_id) { +#ifndef GST_REMOVE_DEPRECATED case PROP_LOW_POWER: g_value_set_boolean (value, thiz->lowpower); break; +#endif case PROP_TILE_ROW: g_value_set_uint (value, thiz->num_tile_rows); @@ -437,6 +464,10 @@ gst_msdkh265enc_get_property (GObject * object, guint prop_id, GValue * value, g_value_set_uint (value, thiz->max_slice_size); break; + case PROP_TUNE_MODE: + g_value_set_enum (value, thiz->tune_mode); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -483,7 +514,8 @@ gst_msdkh265enc_need_conversion (GstMsdkEnc * encoder, GstVideoInfo * info, case GST_VIDEO_FORMAT_YUY2: #if (MFX_VERSION >= 1027) - if (encoder->codename >= MFX_PLATFORM_ICELAKE && !h265enc->lowpower) + if (encoder->codename >= MFX_PLATFORM_ICELAKE && + h265enc->tune_mode == MFX_CODINGOPTION_OFF) return FALSE; #endif default: @@ -523,9 +555,13 @@ gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass) gst_msdkenc_install_common_properties (encoder_class); +#ifndef GST_REMOVE_DEPRECATED g_object_class_install_property (gobject_class, PROP_LOW_POWER, - g_param_spec_boolean ("low-power", "Low power", "Enable low power mode", - PROP_LOWPOWER_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_param_spec_boolean ("low-power", "Low power", + "Enable low power mode (DEPRECATED, use tune instead)", + PROP_LOWPOWER_DEFAULT, + G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +#endif g_object_class_install_property (gobject_class, PROP_TILE_ROW, g_param_spec_uint ("num-tile-rows", "number of rows for tiled encoding", @@ -545,6 +581,12 @@ gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass) 0, G_MAXUINT32, PROP_MAX_SLICE_SIZE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_TUNE_MODE, + g_param_spec_enum ("tune", "Encoder tuning", + "Encoder tuning option", + gst_msdkenc_tune_mode_get_type (), PROP_TUNE_MODE_DEFAULT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_set_static_metadata (element_class, "Intel MSDK H265 encoder", "Codec/Encoder/Video/Hardware", @@ -563,5 +605,6 @@ gst_msdkh265enc_init (GstMsdkH265Enc * thiz) thiz->num_tile_rows = PROP_TILE_ROW_DEFAULT; thiz->num_tile_cols = PROP_TILE_COL_DEFAULT; thiz->max_slice_size = PROP_MAX_SLICE_SIZE_DEFAULT; + thiz->tune_mode = PROP_TUNE_MODE_DEFAULT; msdk_enc->num_extra_frames = 1; } diff --git a/sys/msdk/gstmsdkh265enc.h b/sys/msdk/gstmsdkh265enc.h index 7b62e4af74..281bdd80d8 100644 --- a/sys/msdk/gstmsdkh265enc.h +++ b/sys/msdk/gstmsdkh265enc.h @@ -59,6 +59,8 @@ struct _GstMsdkH265Enc gushort num_tile_rows; gushort num_tile_cols; guint max_slice_size; + gint tune_mode; + guint prop_flag; mfxExtHEVCTiles ext_tiles; /* roi[0] for current ROI and roi[1] for previous ROI */ diff --git a/sys/msdk/msdk-enums.c b/sys/msdk/msdk-enums.c index a318620104..9a2ac2c684 100644 --- a/sys/msdk/msdk-enums.c +++ b/sys/msdk/msdk-enums.c @@ -176,6 +176,25 @@ gst_msdkenc_adaptive_b_get_type (void) return type; } +GType +gst_msdkenc_tune_mode_get_type (void) +{ + static GType type = 0; + + static const GEnumValue values[] = { + {MFX_CODINGOPTION_UNKNOWN, "Auto ", "auto"}, + {MFX_CODINGOPTION_OFF, "None ", "none"}, + {MFX_CODINGOPTION_ON, "Low power mode ", "low-power"}, + {0, NULL, NULL} + }; + + if (!type) { + type = g_enum_register_static ("GstMsdkEncTuneMode", values); + } + + return type; +} + /*========= MSDK VPP Enums =========================*/ #ifndef GST_REMOVE_DEPRECATED diff --git a/sys/msdk/msdk-enums.h b/sys/msdk/msdk-enums.h index 171938cbde..3c0028a412 100644 --- a/sys/msdk/msdk-enums.h +++ b/sys/msdk/msdk-enums.h @@ -69,6 +69,9 @@ gst_msdkenc_adaptive_i_get_type (void); GType gst_msdkenc_adaptive_b_get_type (void); +GType +gst_msdkenc_tune_mode_get_type (void); + /*========= MSDK VPP Enums =========================*/ GType