libs: encoder: h264,h265: add new property "max-qp"
authorWangfei <fei.w.wang@intel.com>
Sat, 18 May 2019 05:24:35 +0000 (13:24 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 24 Jul 2019 17:07:28 +0000 (17:07 +0000)
Add new property "max-qp" to allow set the maximum quantisation
parameter values.

gst-libs/gst/vaapi/gstvaapiencoder_h264.c
gst-libs/gst/vaapi/gstvaapiencoder_h264.h
gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c
gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.h
gst-libs/gst/vaapi/gstvaapiencoder_h265.c
gst-libs/gst/vaapi/gstvaapiencoder_h265.h

index e3c391d..3abd23c 100644 (file)
@@ -745,6 +745,7 @@ struct _GstVaapiEncoderH264
   guint32 ip_period;
   guint32 init_qp;
   guint32 min_qp;
+  guint32 max_qp;
   guint32 qp_i;
   guint32 qp_ip;
   guint32 qp_ib;
@@ -2398,9 +2399,9 @@ add_slice_headers (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture,
           (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;
+      if ((gint) encoder->init_qp + slice_param->slice_qp_delta >
+          (gint) encoder->max_qp) {
+        slice_param->slice_qp_delta = encoder->max_qp - encoder->init_qp;
       }
     }
     slice_param->disable_deblocking_filter_idc = 0;
@@ -2521,10 +2522,7 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder)
   GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
 
 #if VA_CHECK_VERSION(1,1,0)
-  /* @FIXME: should not set this value, should be ignored if set to zero *
-   * https://github.com/intel/media-driver/issues/587 */
-  if (encoder->min_qp > 0)
-    GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = 51;
+  GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = encoder->max_qp;
 #endif
 
 #if VA_CHECK_VERSION(1,0,0)
@@ -2753,8 +2751,12 @@ reset_properties (GstVaapiEncoderH264 * encoder)
   if (encoder->idr_period < base_encoder->keyframe_period)
     encoder->idr_period = base_encoder->keyframe_period;
 
+  g_assert (encoder->min_qp <= encoder->max_qp);
   if (encoder->min_qp > encoder->init_qp)
     encoder->min_qp = encoder->init_qp;
+  if (encoder->max_qp < encoder->init_qp)
+    encoder->max_qp = encoder->init_qp;
+
   encoder->qp_i = encoder->init_qp;
 
   mb_size = encoder->mb_width * encoder->mb_height;
@@ -3547,6 +3549,9 @@ gst_vaapi_encoder_h264_set_property (GstVaapiEncoder * base_encoder,
     case GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE:
       encoder->prediction_type = g_value_get_enum (value);
       break;
+    case GST_VAAPI_ENCODER_H264_PROP_MAX_QP:
+      encoder->max_qp = g_value_get_uint (value);
+      break;
 
     default:
       return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
@@ -3650,6 +3655,19 @@ gst_vaapi_encoder_h264_get_default_properties (void)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   /**
+   * GstVaapiEncoderH264:max-qp:
+   *
+   * The maximum quantizer value.
+   *
+   * Since: 1.18
+   */
+  GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
+      GST_VAAPI_ENCODER_H264_PROP_MAX_QP,
+      g_param_spec_uint ("max-qp",
+          "Maximum QP", "Maximum quantizer value", 0, 51, 51,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
    * GstVaapiEncoderH264:qp-ip:
    *
    * The difference of QP between I and P Frame.
index eb26278..ab56d29 100644 (file)
@@ -56,6 +56,7 @@ typedef struct _GstVaapiEncoderH264 GstVaapiEncoderH264;
  * @GST_VAAPI_ENCODER_H264_PROP_QP_IB: Difference of QP between I and B frame.
  * @GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS: Number of temporal levels
  * @GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE: Reference picture selection modes
+ * @GST_VAAPI_ENCODER_H264_PROP_MAX_QP: Maximal quantizer value (uint).
  *
  * The set of H.264 encoder specific configurable properties.
  */
@@ -77,6 +78,7 @@ typedef enum {
   GST_VAAPI_ENCODER_H264_PROP_QP_IB = -15,
   GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS = -16,
   GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE = -17,
+  GST_VAAPI_ENCODER_H264_PROP_MAX_QP = -18,
 } GstVaapiEncoderH264Prop;
 
 GstVaapiEncoder *
index 9115281..f8be64f 100644 (file)
@@ -766,6 +766,7 @@ struct _GstVaapiEncoderH264Fei
   guint32 idr_period;
   guint32 init_qp;
   guint32 min_qp;
+  guint32 max_qp;
   guint32 num_slices;
   guint32 num_bframes;
   guint32 mb_width;
@@ -2175,6 +2176,10 @@ add_slice_headers (GstVaapiEncoderH264Fei * encoder,
     slice_param->slice_qp_delta = encoder->init_qp - encoder->min_qp;
     if (slice_param->slice_qp_delta > 4)
       slice_param->slice_qp_delta = 4;
+    if ((gint) encoder->init_qp + slice_param->slice_qp_delta >
+        (gint) encoder->max_qp) {
+      slice_param->slice_qp_delta = encoder->max_qp - 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;
@@ -2451,10 +2456,7 @@ ensure_misc_params (GstVaapiEncoderH264Fei * encoder,
     rate_control->min_qp = encoder->min_qp;
 
 #if VA_CHECK_VERSION(1,1,0)
-    /* @FIXME: should not set this value, should be ignored if set to zero *
-     * https://github.com/intel/media-driver/issues/587 */
-    if (rate_control->min_qp > 0)
-      rate_control->max_qp = 51;
+    rate_control->max_qp = encoder->max_qp;
 #endif
 
     rate_control->basic_unit_size = 0;
@@ -2655,10 +2657,13 @@ reset_properties (GstVaapiEncoderH264Fei * encoder)
   if (encoder->idr_period < base_encoder->keyframe_period)
     encoder->idr_period = base_encoder->keyframe_period;
 
+  g_assert (encoder->min_qp <= encoder->max_qp);
   if (encoder->min_qp > encoder->init_qp ||
       (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP &&
           encoder->min_qp < encoder->init_qp))
     encoder->min_qp = encoder->init_qp;
+  if (encoder->max_qp < encoder->init_qp)
+    encoder->max_qp = encoder->init_qp;
 
   mb_size = encoder->mb_width * encoder->mb_height;
   if (encoder->num_slices > (mb_size + 1) / 2)
@@ -3565,6 +3570,9 @@ gst_vaapi_encoder_h264_fei_set_property (GstVaapiEncoder * base_encoder,
       }
 
       break;
+    case GST_VAAPI_ENCODER_H264_FEI_PROP_MAX_QP:
+      encoder->max_qp = g_value_get_uint (value);
+      break;
 
     default:
       return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
@@ -4073,6 +4081,19 @@ gst_vaapi_encoder_h264_fei_get_default_properties (void)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   /**
+   * GstVaapiEncoderH264Fei:max-qp:
+   *
+   * The maximum quantizer value.
+   *
+   * Since: 1.18
+   */
+  GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
+      GST_VAAPI_ENCODER_H264_FEI_PROP_MAX_QP,
+      g_param_spec_uint ("max-qp",
+          "Maximum QP", "Maximum quantizer value", 0, 51, 51,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
    * GstVaapiEncoderH264Fei:num-slices:
    *
    * The number of slices per frame.
index 3622ed2..cd69580 100644 (file)
@@ -49,6 +49,7 @@ typedef struct _GstVaapiEncoderH264Fei GstVaapiEncoderH264Fei;
  *   in milliseconds (uint).
  * @GST_VAAPI_ENCODER_H264_FEI_PROP_NUM_VIEWS: Number of views per frame.
  * @GST_VAAPI_ENCODER_H264_FEI_PROP_VIEW_IDS: View IDs
+ * @GST_VAAPI_ENCODER_H264_FEI_PROP_MAX_QP: Maximal quantizer value (uint).
  *
  * The set of H.264 encoder specific configurable properties.
  */
@@ -79,7 +80,8 @@ typedef enum {
   GST_VAAPI_ENCODER_H264_PROP_MULTI_PRED_L0 = -25,
   GST_VAAPI_ENCODER_H264_PROP_MULTI_PRED_L1 = -26,
   GST_VAAPI_ENCODER_H264_PROP_ENABLE_STATS_OUT = -27,
-  GST_VAAPI_ENCODER_H264_PROP_FEI_MODE = -28
+  GST_VAAPI_ENCODER_H264_PROP_FEI_MODE = -28,
+  GST_VAAPI_ENCODER_H264_FEI_PROP_MAX_QP = -29,
 
 } GstVaapiEncoderH264FeiProp;
 
index 972dcab..bcfa08a 100644 (file)
@@ -101,6 +101,7 @@ struct _GstVaapiEncoderH265
   guint32 idr_period;
   guint32 init_qp;
   guint32 min_qp;
+  guint32 max_qp;
   guint32 qp_i;
   guint32 qp_ip;
   guint32 qp_ib;
@@ -1780,9 +1781,9 @@ add_slice_headers (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture,
           (gint) encoder->min_qp) {
         slice_param->slice_qp_delta = encoder->min_qp - encoder->init_qp;
       }
-      /* TODO: max_qp could 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;
+      if ((gint) encoder->init_qp + slice_param->slice_qp_delta >
+          (gint) encoder->max_qp) {
+        slice_param->slice_qp_delta = encoder->max_qp - encoder->init_qp;
       }
     }
 
@@ -1880,10 +1881,7 @@ ensure_control_rate_params (GstVaapiEncoderH265 * encoder)
   GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp;
 
 #if VA_CHECK_VERSION(1,1,0)
-  /* @FIXME: should not set this value, should be ignored if set to zero *
-   * https://github.com/intel/media-driver/issues/587 */
-  if (encoder->min_qp > 0)
-    GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = 51;
+  GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = encoder->max_qp;
 #endif
 
 #if VA_CHECK_VERSION(1,0,0)
@@ -2078,6 +2076,9 @@ reset_properties (GstVaapiEncoderH265 * encoder)
 
   if (encoder->min_qp > encoder->init_qp)
     encoder->min_qp = encoder->init_qp;
+  if (encoder->max_qp < encoder->init_qp)
+    encoder->max_qp = encoder->init_qp;
+
   encoder->qp_i = encoder->init_qp;
 
   ctu_size = encoder->ctu_width * encoder->ctu_height;
@@ -2692,6 +2693,9 @@ gst_vaapi_encoder_h265_set_property (GstVaapiEncoder * base_encoder,
     case GST_VAAPI_ENCODER_H265_PROP_LOW_DELAY_B:
       encoder->low_delay_b = g_value_get_boolean (value);
       break;
+    case GST_VAAPI_ENCODER_H265_PROP_MAX_QP:
+      encoder->max_qp = g_value_get_uint (value);
+      break;
 
     default:
       return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
@@ -2795,6 +2799,19 @@ gst_vaapi_encoder_h265_get_default_properties (void)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   /**
+   * GstVaapiEncoderH265:max-qp:
+   *
+   * The maximum quantizer value.
+   *
+   * Since: 1.18
+   */
+  GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
+      GST_VAAPI_ENCODER_H265_PROP_MAX_QP,
+      g_param_spec_uint ("max-qp",
+          "Maximum QP", "Maximum quantizer value", 0, 51, 51,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  /**
    * GstVaapiEncoderH265:qp-ip:
    *
    * The difference of QP between I and P Frame.
index 2e594f7..9004e90 100644 (file)
@@ -47,6 +47,7 @@ typedef struct _GstVaapiEncoderH265 GstVaapiEncoderH265;
  * @GST_VAAPI_ENCODER_H265_PROP_QP_IP: Difference of QP between I and P frame.
  * @GST_VAAPI_ENCODER_H265_PROP_QP_IB: Difference of QP between I and B frame.
  * @GST_VAAPI_ENCODER_H265_PROP_LOW_DELAY_B: use low delay b feature.
+ * @GST_VAAPI_ENCODER_H265_PROP_MAX_QP: Maximal quantizer value (uint).
  *
  * The set of H.265 encoder specific configurable properties.
  */
@@ -61,6 +62,7 @@ typedef enum {
   GST_VAAPI_ENCODER_H265_PROP_QP_IP = -9,
   GST_VAAPI_ENCODER_H265_PROP_QP_IB = -10,
   GST_VAAPI_ENCODER_H265_PROP_LOW_DELAY_B = -11,
+  GST_VAAPI_ENCODER_H265_PROP_MAX_QP = -12,
 } GstVaapiEncoderH265Prop;
 
 GstVaapiEncoder *