libs: encoder: change mbbrc from uint to enum

Instead of handling the macroblock bitrate control as a integer, this
patch changes it as a enum, which is more self documented in the
GStreamer elements.

https://bugzilla.gnome.org/show_bug.cgi?id=787855
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-09-18 19:11:45 +02:00
parent b7c7335238
commit e308b452d6
5 changed files with 59 additions and 12 deletions

View file

@ -1702,3 +1702,25 @@ gst_vaapi_encoder_tune_get_type (void)
} }
return g_type; return g_type;
} }
/** Returns a GType for the #GstVaapiEncoderMbbrc set */
GType
gst_vaapi_encoder_mbbrc_get_type (void)
{
static volatile gsize g_type = 0;
if (g_once_init_enter (&g_type)) {
static const GEnumValue encoder_mbbrc_values[] = {
{GST_VAAPI_ENCODER_MBBRC_AUTO, "Auto", "auto"},
{GST_VAAPI_ENCODER_MBBRC_ON, "On", "on"},
{GST_VAAPI_ENCODER_MBBRC_OFF, "Off", "off"},
{0, NULL, NULL},
};
GType type =
g_enum_register_static (g_intern_static_string ("GstVaapiEncoderMbbrc"),
encoder_mbbrc_values);
g_once_init_leave (&g_type, type);
}
return g_type;
}

View file

@ -93,6 +93,23 @@ typedef enum {
GST_VAAPI_ENCODER_TUNE_LOW_POWER, GST_VAAPI_ENCODER_TUNE_LOW_POWER,
} GstVaapiEncoderTune; } GstVaapiEncoderTune;
/**
* GstVaapiEncoderMbbrc:
* @GST_VAAPI_ENCODER_MBBRC_AUTO: bitrate control auto
* @GST_VAAPI_ENCODER_MBBRC_ON: bitrate control on
* @GST_VAAPI_ENCODER_MBBRC_OFF: bitrate control off
*
* Values for the macroblock level bitrate control.
*
* This property values are only available for H264 and H265 (HEVC)
* encoders, when rate control is not Constant QP.
**/
typedef enum {
GST_VAAPI_ENCODER_MBBRC_AUTO = 0,
GST_VAAPI_ENCODER_MBBRC_ON = 1,
GST_VAAPI_ENCODER_MBBRC_OFF = 2,
} GstVaapiEncoderMbbrc;
/** /**
* GstVaapiEncoderProp: * GstVaapiEncoderProp:
* @GST_VAAPI_ENCODER_PROP_RATECONTROL: Rate control (#GstVaapiRateControl). * @GST_VAAPI_ENCODER_PROP_RATECONTROL: Rate control (#GstVaapiRateControl).
@ -131,6 +148,9 @@ typedef struct _GstVaapiROI {
GType GType
gst_vaapi_encoder_tune_get_type (void) G_GNUC_CONST; gst_vaapi_encoder_tune_get_type (void) G_GNUC_CONST;
GType
gst_vaapi_encoder_mbbrc_get_type (void) G_GNUC_CONST;
GstVaapiEncoder * GstVaapiEncoder *
gst_vaapi_encoder_ref (GstVaapiEncoder * encoder); gst_vaapi_encoder_ref (GstVaapiEncoder * encoder);

View file

@ -737,7 +737,7 @@ struct _GstVaapiEncoderH264
guint bitrate_bits; // bitrate (bits) guint bitrate_bits; // bitrate (bits)
guint cpb_length; // length of CPB buffer (ms) guint cpb_length; // length of CPB buffer (ms)
guint cpb_length_bits; // length of CPB buffer (bits) guint cpb_length_bits; // length of CPB buffer (bits)
guint mbbrc; // macroblock bitrate control GstVaapiEncoderMbbrc mbbrc; // macroblock bitrate control
/* MVC */ /* MVC */
gboolean is_mvc; gboolean is_mvc;
@ -2288,7 +2288,7 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder)
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp;
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control = GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control =
encoder->mbbrc; (guint) encoder->mbbrc;
/* HRD params */ /* HRD params */
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
@ -3117,7 +3117,7 @@ gst_vaapi_encoder_h264_set_property (GstVaapiEncoder * base_encoder,
encoder->num_ref_frames = g_value_get_uint (value); encoder->num_ref_frames = g_value_get_uint (value);
break; break;
case GST_VAAPI_ENCODER_H264_PROP_MBBRC: case GST_VAAPI_ENCODER_H264_PROP_MBBRC:
encoder->mbbrc = g_value_get_uint (value); encoder->mbbrc = g_value_get_enum (value);
break; break;
default: default:
@ -3294,10 +3294,11 @@ gst_vaapi_encoder_h264_get_default_properties (void)
*/ */
GST_VAAPI_ENCODER_PROPERTIES_APPEND (props, GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
GST_VAAPI_ENCODER_H264_PROP_MBBRC, GST_VAAPI_ENCODER_H264_PROP_MBBRC,
g_param_spec_uint ("mbbrc", g_param_spec_enum ("mbbrc",
"Macroblock level Bitrate Control", "Macroblock level Bitrate Control",
"Macroblock level Bitrate Control (0: auto, 1: on, 2: off)", 0, 2, "Macroblock level Bitrate Control",
0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GST_VAAPI_TYPE_ENCODER_MBBRC, GST_VAAPI_ENCODER_MBBRC_AUTO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/** /**
* GstVaapiEncoderH264:cpb-length: * GstVaapiEncoderH264:cpb-length:

View file

@ -130,7 +130,7 @@ struct _GstVaapiEncoderH265
guint bitrate_bits; // bitrate (bits) guint bitrate_bits; // bitrate (bits)
guint cpb_length; // length of CPB buffer (ms) guint cpb_length; // length of CPB buffer (ms)
guint cpb_length_bits; // length of CPB buffer (bits) guint cpb_length_bits; // length of CPB buffer (bits)
guint mbbrc; // macroblock bitrate control GstVaapiEncoderMbbrc mbbrc; // macroblock bitrate control
/* Crop rectangle */ /* Crop rectangle */
guint conformance_window_flag:1; guint conformance_window_flag:1;
@ -1834,7 +1834,7 @@ ensure_control_rate_params (GstVaapiEncoderH265 * encoder)
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp;
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control = GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control =
encoder->mbbrc; (guint) encoder->mbbrc;
/* HRD params */ /* HRD params */
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
@ -2576,7 +2576,7 @@ gst_vaapi_encoder_h265_set_property (GstVaapiEncoder * base_encoder,
encoder->num_ref_frames = g_value_get_uint (value); encoder->num_ref_frames = g_value_get_uint (value);
break; break;
case GST_VAAPI_ENCODER_H265_PROP_MBBRC: case GST_VAAPI_ENCODER_H265_PROP_MBBRC:
encoder->mbbrc = g_value_get_uint (value); encoder->mbbrc = g_value_get_enum (value);
break; break;
default: default:
return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER; return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
@ -2737,10 +2737,11 @@ gst_vaapi_encoder_h265_get_default_properties (void)
*/ */
GST_VAAPI_ENCODER_PROPERTIES_APPEND (props, GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
GST_VAAPI_ENCODER_H265_PROP_MBBRC, GST_VAAPI_ENCODER_H265_PROP_MBBRC,
g_param_spec_uint ("mbbrc", g_param_spec_enum ("mbbrc",
"Macroblock level Bitrate Control", "Macroblock level Bitrate Control",
"Macroblock level Bitrate Control (0: auto, 1: on, 2: off)", 0, 2, "Macroblock level Bitrate Control",
0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GST_VAAPI_TYPE_ENCODER_MBBRC, GST_VAAPI_ENCODER_MBBRC_AUTO,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
return props; return props;
} }

View file

@ -215,6 +215,9 @@ G_BEGIN_DECLS
#define GST_VAAPI_TYPE_ENCODER_TUNE \ #define GST_VAAPI_TYPE_ENCODER_TUNE \
(gst_vaapi_encoder_tune_get_type ()) (gst_vaapi_encoder_tune_get_type ())
#define GST_VAAPI_TYPE_ENCODER_MBBRC \
(gst_vaapi_encoder_mbbrc_get_type ())
typedef struct _GstVaapiEncoderClass GstVaapiEncoderClass; typedef struct _GstVaapiEncoderClass GstVaapiEncoderClass;
typedef struct _GstVaapiEncoderClassData GstVaapiEncoderClassData; typedef struct _GstVaapiEncoderClassData GstVaapiEncoderClassData;