summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapiencoder.c
diff options
context:
space:
mode:
authorSreerenj Balachandran <sreerenj.balachandran@intel.com>2017-04-19 13:04:44 -0700
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2017-05-11 11:51:56 +0200
commit4f343f82e3e9051b3d5759290c1a9aa418d8559d (patch)
treeb71378122b8579243985636c26f88b683e8a06f9 /gst-libs/gst/vaapi/gstvaapiencoder.c
parent10eb6efb30c0fde968ba0bacdd032219a2c485be (diff)
encoders: add quality level tuning
This patch adds the handling of VAEncMiscParameterTypeQualityLevel, in gstreamer-vaapi encoders: The encoding quality could be set through this structure, if the implementation supports multiple quality levels. The quality level set through this structure is persistent over the entire coded sequence, or until a new structure is being sent. The quality level range can be queried through the VAConfigAttribEncQualityRange attribute. A lower value means higher quality, and a value of 1 represents the highest quality. The quality level setting is used as a trade-off between quality and speed/power consumption, with higher quality corresponds to lower speed and higher power consumption. The quality level is set by the element's parameter "quality-level" with a hard-coded range of 1 to 8. Later, when the encoder is configured in run time, just before start processing, the quality level is scaled to the codec range. If VAConfigAttribEncQualityRange is not available in the used VA backend, then the quality level is set to zero, which means "disabled". All the available codecs now process this parameter if it is available. https://bugzilla.gnome.org/show_bug.cgi?id=778733 Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Diffstat (limited to 'gst-libs/gst/vaapi/gstvaapiencoder.c')
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder.c87
1 files changed, 86 insertions, 1 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c
index 0a87c1b3..6727cbb9 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder.c
@@ -169,9 +169,44 @@ gst_vaapi_encoder_properties_get_default (const GstVaapiEncoderClass * klass)
cdata->encoder_tune_get_type (), cdata->default_encoder_tune,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GstVaapiEncoder:quality-level:
+ *
+ * The Encoding quality level.
+ */
+ GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
+ GST_VAAPI_ENCODER_PROP_QUALITY_LEVEL,
+ g_param_spec_uint ("quality-level",
+ "Quality Level",
+ "Encoding Quality Level ", 1, 8,
+ 4, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
return props;
}
+gboolean
+gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
+ GstVaapiEncPicture * picture)
+{
+ GstVaapiEncMiscParam *misc;
+ VAEncMiscParameterBufferQualityLevel *quality_level;
+
+ /* quality level param is not supported */
+ if (GST_VAAPI_ENCODER_QUALITY_LEVEL (encoder) == 0)
+ return TRUE;
+
+ misc = GST_VAAPI_ENC_QUALITY_LEVEL_MISC_PARAM_NEW (encoder);
+ if (!misc)
+ return FALSE;
+ quality_level = misc->data;
+ memset (quality_level, 0, sizeof (VAEncMiscParameterBufferQualityLevel));
+ quality_level->quality_level = encoder->quality_level;
+ gst_vaapi_enc_picture_add_misc_param (picture, misc);
+ gst_vaapi_codec_object_replace (&misc, NULL);
+
+ return TRUE;
+}
+
/**
* gst_vaapi_encoder_ref:
* @encoder: a #GstVaapiEncoder
@@ -686,7 +721,7 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
GstVideoInfo *const vip = GST_VAAPI_ENCODER_VIDEO_INFO (encoder);
GstVaapiEncoderStatus status;
GstVaapiVideoPool *pool;
- guint codedbuf_size;
+ guint codedbuf_size, quality_level_max = 0;
/* Generate a keyframe every second */
if (!encoder->keyframe_period)
@@ -699,6 +734,16 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
if (!gst_vaapi_encoder_ensure_context (encoder))
goto error_reset_context;
+ if (get_config_attribute (encoder, VAConfigAttribEncQualityRange,
+ &quality_level_max) && quality_level_max > 0) {
+ encoder->quality_level =
+ gst_util_uint64_scale_int_ceil (encoder->quality_level,
+ quality_level_max, 8);
+ } else {
+ encoder->quality_level = 0;
+ }
+ GST_INFO ("Quality level is fixed to %d", encoder->quality_level);
+
codedbuf_size = encoder->codedbuf_pool ?
gst_vaapi_coded_buffer_pool_get_buffer_size (GST_VAAPI_CODED_BUFFER_POOL
(encoder)) : 0;
@@ -810,6 +855,10 @@ set_property (GstVaapiEncoder * encoder, gint prop_id, const GValue * value)
case GST_VAAPI_ENCODER_PROP_TUNE:
status = gst_vaapi_encoder_set_tuning (encoder, g_value_get_enum (value));
break;
+ case GST_VAAPI_ENCODER_PROP_QUALITY_LEVEL:
+ status = gst_vaapi_encoder_set_quality_level (encoder,
+ g_value_get_uint (value));
+ break;
}
return status;
@@ -1035,6 +1084,42 @@ error_operation_failed:
}
}
+/**
+ * gst_vaapi_encoder_set_quality_level:
+ * @encoder: a #GstVaapiEncoder
+ * @quality_level: the encoder quality level
+ *
+ * Notifies the @encoder to use the supplied @quality_level value.
+ *
+ * Note: currently, the quality_level can only be specified before
+ * the last call to gst_vaapi_encoder_set_codec_state(), which shall
+ * occur before the first frame is encoded. Afterwards, any change to
+ * this parameter causes gst_vaapi_encoder_set_quality_level() to
+ * return @GST_VAAPI_ENCODER_STATUS_ERROR_OPERATION_FAILED.
+ *
+ * Return value: a #GstVaapiEncoderStatus
+ */
+GstVaapiEncoderStatus
+gst_vaapi_encoder_set_quality_level (GstVaapiEncoder * encoder,
+ guint quality_level)
+{
+ g_return_val_if_fail (encoder != NULL, 0);
+
+ if (encoder->quality_level != quality_level
+ && encoder->num_codedbuf_queued > 0)
+ goto error_operation_failed;
+
+ encoder->quality_level = quality_level;
+ return GST_VAAPI_ENCODER_STATUS_SUCCESS;
+
+ /* ERRORS */
+error_operation_failed:
+ {
+ GST_ERROR ("could not change quality level after encoding started");
+ return GST_VAAPI_ENCODER_STATUS_ERROR_OPERATION_FAILED;
+ }
+}
+
/* Initialize default values for configurable properties */
static gboolean
gst_vaapi_encoder_init_properties (GstVaapiEncoder * encoder)