summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi
diff options
context:
space:
mode:
Diffstat (limited to 'gst-libs/gst/vaapi')
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder.c87
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder.h5
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h264.c5
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h265.c3
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c3
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_objects.h6
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_priv.h17
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_vp8.c2
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_vp9.c12
9 files changed, 139 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)
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.h b/gst-libs/gst/vaapi/gstvaapiencoder.h
index 1c7cd473..7d1ebe4e 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder.h
+++ b/gst-libs/gst/vaapi/gstvaapiencoder.h
@@ -108,6 +108,7 @@ typedef enum {
GST_VAAPI_ENCODER_PROP_BITRATE,
GST_VAAPI_ENCODER_PROP_KEYFRAME_PERIOD,
GST_VAAPI_ENCODER_PROP_TUNE,
+ GST_VAAPI_ENCODER_PROP_QUALITY_LEVEL
} GstVaapiEncoderProp;
/**
@@ -167,6 +168,10 @@ gst_vaapi_encoder_set_tuning (GstVaapiEncoder * encoder,
GstVaapiEncoderTune tuning);
GstVaapiEncoderStatus
+gst_vaapi_encoder_set_quality_level (GstVaapiEncoder * encoder,
+ guint quality_level);
+
+GstVaapiEncoderStatus
gst_vaapi_encoder_get_buffer_with_timeout (GstVaapiEncoder * encoder,
GstVaapiCodedBufferProxy ** out_codedbuf_proxy_ptr, guint64 timeout);
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
index 16e5b438..dc96b646 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
@@ -2157,6 +2157,7 @@ error_create_packed_seq_hdr:
static gboolean
ensure_misc_params (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
{
+ GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc = NULL;
VAEncMiscParameterRateControl *rate_control;
@@ -2204,6 +2205,10 @@ ensure_misc_params (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
}
}
+
+ if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
+ return FALSE;
+
return TRUE;
error_create_packed_sei_hdr:
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
index f49121ce..ba055632 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
@@ -1765,6 +1765,7 @@ error_create_packed_seq_hdr:
static gboolean
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
{
+ GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
GstVaapiEncMiscParam *misc = NULL;
/* HRD params for rate control */
@@ -1778,6 +1779,8 @@ ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
gst_vaapi_codec_object_replace (&misc, NULL);
}
+ if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
+ return FALSE;
return TRUE;
}
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
index ccb495d7..251b9a5c 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
@@ -496,6 +496,9 @@ set_misc_parameters (GstVaapiEncoderMpeg2 * encoder,
rate_control->basic_unit_size = 0;
gst_vaapi_codec_object_replace (&misc, NULL);
}
+
+ if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
+ return FALSE;
return TRUE;
}
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_objects.h b/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
index 6e8945cd..90c31e00 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
@@ -319,6 +319,12 @@ gst_vaapi_enc_picture_encode (GstVaapiEncPicture * picture);
G_PASTE (VAEncMiscParameterType, type), \
sizeof (G_PASTE (VAEncMiscParameter, type)))
+/* GstVaapiEncFeiMiscParam */
+#define GST_VAAPI_ENC_QUALITY_LEVEL_MISC_PARAM_NEW(encoder) \
+ gst_vaapi_enc_misc_param_new (GST_VAAPI_ENCODER_CAST (encoder), \
+ VAEncMiscParameterTypeQualityLevel, \
+ sizeof (VAEncMiscParameterBufferQualityLevel))
+
/* GstVaapiEncPicture */
#define GST_VAAPI_ENC_PICTURE_NEW(codec, encoder, frame) \
gst_vaapi_enc_picture_new (GST_VAAPI_ENCODER_CAST (encoder), \
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
index 5cf748a7..a80ba76f 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
@@ -164,6 +164,17 @@ G_BEGIN_DECLS
#define GST_VAAPI_ENCODER_TUNE(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->tune)
+/**
+ * GST_VAAPI_ENCODER_QUALITY_LEVEL:
+ * @encoder: a #GstVaapiEncoder
+ *
+ * Macro that evaluates to the quality level
+ * This is an internal macro that does not do any run-time type check.
+ */
+#undef GST_VAAPI_ENCODER_QUALITY_LEVEL
+#define GST_VAAPI_ENCODER_QUALITY_LEVEL(encoder) \
+ (GST_VAAPI_ENCODER_CAST (encoder)->quality_level)
+
/* Generate a mask for the supplied tuning option (internal) */
#define GST_VAAPI_ENCODER_TUNE_MASK(TUNE) \
(1U << G_PASTE (GST_VAAPI_ENCODER_TUNE_, TUNE))
@@ -216,6 +227,7 @@ struct _GstVaapiEncoder
guint32 rate_control_mask;
guint bitrate; /* kbps */
guint keyframe_period;
+ guint quality_level;
GMutex mutex;
GCond surface_free;
@@ -340,6 +352,11 @@ gst_vaapi_encoder_release_surface (GstVaapiEncoder * encoder,
gst_vaapi_surface_proxy_unref (proxy);
}
+G_GNUC_INTERNAL
+gboolean
+gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
+ GstVaapiEncPicture * picture);
+
G_END_DECLS
#endif /* GST_VAAPI_ENCODER_PRIV_H */
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
index 56a19438..9ced12bb 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
@@ -313,6 +313,8 @@ ensure_misc_params (GstVaapiEncoderVP8 * encoder, GstVaapiEncPicture * picture)
gst_vaapi_enc_picture_add_misc_param (picture, misc);
gst_vaapi_codec_object_replace (&misc, NULL);
+ if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
+ return FALSE;
return TRUE;
}
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c
index b9af7855..437ce16e 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp9.c
@@ -215,6 +215,16 @@ error:
}
}
+static gboolean
+ensure_misc_params (GstVaapiEncoderVP9 * encoder, GstVaapiEncPicture * picture)
+{
+ GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
+
+ if (!gst_vaapi_encoder_ensure_param_quality_level (base_encoder, picture))
+ return FALSE;
+ return TRUE;
+}
+
static void
get_ref_indices (guint ref_pic_mode, guint ref_list_idx, guint * last_idx,
guint * gf_idx, guint * arf_idx, guint8 * refresh_frame_flags)
@@ -359,6 +369,8 @@ gst_vaapi_encoder_vp9_encode (GstVaapiEncoder * base_encoder,
if (!ensure_sequence (encoder, picture))
goto error;
+ if (!ensure_misc_params (encoder, picture))
+ goto error;
if (!ensure_picture (encoder, picture, codedbuf, reconstruct))
goto error;
if (!gst_vaapi_enc_picture_encode (picture))