diff options
author | Hyunjun Ko <zzoon@igalia.com> | 2017-09-13 12:22:07 +0900 |
---|---|---|
committer | Víctor Manuel Jáquez Leal <vjaquez@igalia.com> | 2017-09-13 10:47:22 +0200 |
commit | 64a38a16f15b3fbc7051c489b06f3816fdfa7709 (patch) | |
tree | 93dbb3fb034f0a0145754a722c774cf5d6b9586d | |
parent | 5796750604c0a93a4050c31d0d79a830b3c3ed7c (diff) |
libs: encoder: h264: support I/P/B QP setting seperatedly
Creates 2 properties, qp-ip and qp-ib for setting different QP for P/B
frames
and set slice_qp_delta for each frame according to the value provided.
In addition, remove the limitation of (<= 4) when setting
slice_qp_delta.
https://bugzilla.gnome.org/show_bug.cgi?id=785923
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapiencoder_h264.c | 52 | ||||
-rw-r--r-- | gst-libs/gst/vaapi/gstvaapiencoder_h264.h | 4 |
2 files changed, 53 insertions, 3 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index 635c9110..05edb12f 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -709,6 +709,8 @@ struct _GstVaapiEncoderH264 guint32 init_qp; guint32 min_qp; guint32 qp_i; + guint32 qp_ip; + guint32 qp_ib; guint32 num_slices; guint32 num_bframes; guint32 mb_width; @@ -2154,9 +2156,21 @@ add_slice_headers (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture, slice_param->cabac_init_idc = 0; slice_param->slice_qp_delta = encoder->qp_i - encoder->init_qp; - if (slice_param->slice_qp_delta > 4) - slice_param->slice_qp_delta = 4; - + if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) { + if (picture->type == GST_VAAPI_PICTURE_TYPE_P) { + slice_param->slice_qp_delta += encoder->qp_ip; + } else if (picture->type == GST_VAAPI_PICTURE_TYPE_B) { + slice_param->slice_qp_delta += encoder->qp_ib; + } + if ((gint) encoder->init_qp + slice_param->slice_qp_delta < + (gint) encoder->min_qp) { + slice_param->slice_qp_delta = encoder->min_qp - encoder->init_qp; + } + /* TODO: max_qp might be provided as a property in the future */ + if ((gint) encoder->init_qp + slice_param->slice_qp_delta > 51) { + slice_param->slice_qp_delta = 51 - encoder->init_qp; + } + } slice_param->disable_deblocking_filter_idc = 0; slice_param->slice_alpha_c0_offset_div2 = 2; slice_param->slice_beta_offset_div2 = 2; @@ -3055,6 +3069,12 @@ gst_vaapi_encoder_h264_set_property (GstVaapiEncoder * base_encoder, case GST_VAAPI_ENCODER_H264_PROP_MIN_QP: encoder->min_qp = g_value_get_uint (value); break; + case GST_VAAPI_ENCODER_H264_PROP_QP_IP: + encoder->qp_ip = g_value_get_int (value); + break; + case GST_VAAPI_ENCODER_H264_PROP_QP_IB: + encoder->qp_ib = g_value_get_int (value); + break; case GST_VAAPI_ENCODER_H264_PROP_NUM_SLICES: encoder->num_slices = g_value_get_uint (value); break; @@ -3201,6 +3221,32 @@ gst_vaapi_encoder_h264_get_default_properties (void) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** + * GstVaapiEncoderH264:qp-ip: + * + * The difference of QP between I and P Frame. + * This is available only on CQP mode. + */ + GST_VAAPI_ENCODER_PROPERTIES_APPEND (props, + GST_VAAPI_ENCODER_H264_PROP_QP_IP, + g_param_spec_int ("qp-ip", + "Difference of QP between I and P frame", + "Difference of QP between I and P frame (available only on CQP)", + -51, 51, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** + * GstVaapiEncoderH264:qp-ib: + * + * The difference of QP between I and B Frame. + * This is available only on CQP mode. + */ + GST_VAAPI_ENCODER_PROPERTIES_APPEND (props, + GST_VAAPI_ENCODER_H264_PROP_QP_IB, + g_param_spec_int ("qp-ib", + "Difference of QP between I and B frame", + "Difference of QP between I and B frame (available only on CQP)", + -51, 51, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + /** * GstVaapiEncoderH264:num-slices: * * The number of slices per frame. diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.h b/gst-libs/gst/vaapi/gstvaapiencoder_h264.h index b56416a2..42cb08f1 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.h +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.h @@ -52,6 +52,8 @@ typedef struct _GstVaapiEncoderH264 GstVaapiEncoderH264; * @GST_VAAPI_ENCODER_H264_PROP_COMPLIANCE_MODE: Relax Compliance restrictions * @GST_VAAPI_ENCODER_H264_PROP_NUM_REF_FRAMES: Maximum number of reference frames. * @GST_VAAPI_ENCODER_H264_PROP_MBBRC: Macroblock level Bitrate Control. + * @GST_VAAPI_ENCODER_H264_PROP_QP_IP: Difference of QP between I and P frame. + * @GST_VAAPI_ENCODER_H264_PROP_QP_IB: Difference of QP between I and B frame. * * The set of H.264 encoder specific configurable properties. */ @@ -69,6 +71,8 @@ typedef enum { GST_VAAPI_ENCODER_H264_PROP_COMPLIANCE_MODE = -11, GST_VAAPI_ENCODER_H264_PROP_NUM_REF_FRAMES = -12, GST_VAAPI_ENCODER_H264_PROP_MBBRC = -13, + GST_VAAPI_ENCODER_H264_PROP_QP_IP = -14, + GST_VAAPI_ENCODER_H264_PROP_QP_IB = -15, } GstVaapiEncoderH264Prop; GstVaapiEncoder * |