summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2017-06-05 17:31:10 +0200
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>2017-06-07 11:24:38 +0200
commitacf106e1a718cc273f5684c3e76c4e9da17324eb (patch)
tree7a3f2803e6a131c65732f87e8c5ea6348d159a23
parentdaff4e9fbd7637832ba1c0d1aebca3f4b0e254e2 (diff)
libs: encoder: vp8,h264,h265,mpeg2: refactor misc parameters
This is patch pretends to decouple the assignation of the values in the parameter structures and the VA buffer's parameters setting. It may lead to some issues since HRD, framerate or controlrate may not be handled by the specific encoder, but they are set in the VA buffer's parameters. I leave as it because this patch is just a transitional patch. https://bugzilla.gnome.org/show_bug.cgi?id=783449
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder.c42
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h264.c42
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_h265.c16
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c46
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_priv.h43
-rw-r--r--gst-libs/gst/vaapi/gstvaapiencoder_vp8.c69
6 files changed, 133 insertions, 125 deletions
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c
index 7df61767..563e91c3 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder.c
@@ -206,6 +206,48 @@ gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
return TRUE;
}
+gboolean
+gst_vaapi_encoder_ensure_param_control_rate (GstVaapiEncoder * encoder,
+ GstVaapiEncPicture * picture)
+{
+ GstVaapiEncMiscParam *misc;
+
+ if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
+ return TRUE;
+
+ /* RateControl params */
+ misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
+ if (!misc)
+ return FALSE;
+ memcpy (misc->data, &GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder),
+ sizeof (VAEncMiscParameterRateControl));
+ gst_vaapi_enc_picture_add_misc_param (picture, misc);
+ gst_vaapi_codec_object_replace (&misc, NULL);
+
+ /* HRD params */
+ misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
+ if (!misc)
+ return FALSE;
+ memcpy (misc->data, &GST_VAAPI_ENCODER_VA_HRD (encoder),
+ sizeof (VAEncMiscParameterHRD));
+ gst_vaapi_enc_picture_add_misc_param (picture, misc);
+ gst_vaapi_codec_object_replace (&misc, NULL);
+
+ /* FrameRate params */
+ if (GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder).framerate == 0)
+ return TRUE;
+
+ misc = GST_VAAPI_ENC_MISC_PARAM_NEW (FrameRate, encoder);
+ if (!misc)
+ return FALSE;
+ memcpy (misc->data, &GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder),
+ sizeof (VAEncMiscParameterFrameRate));
+ 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
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
index 085f0f9c..14bb0762 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
@@ -2157,44 +2157,26 @@ static gboolean
ensure_control_rate_params (GstVaapiEncoderH264 * encoder,
GstVaapiEncPicture * picture)
{
- GstVaapiEncMiscParam *misc;
+ GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
+ /* *INDENT-OFF* */
/* RateControl params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
- if (!misc)
- return FALSE;
-
- {
- VAEncMiscParameterRateControl rate_control = {
- .bits_per_second = encoder->bitrate_bits,
- .target_percentage = 70,
- .window_size = encoder->cpb_length,
- .initial_qp = encoder->init_qp,
- .min_qp = encoder->min_qp,
- };
-
- memcpy (misc->data, &rate_control, sizeof (rate_control));
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
+ .bits_per_second = encoder->bitrate_bits,
+ .target_percentage = 70,
+ .window_size = encoder->cpb_length,
+ .initial_qp = encoder->init_qp,
+ .min_qp = encoder->min_qp,
+ };
/* HRD params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
- if (!misc)
- return FALSE;
+ fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
+ /* *INDENT-ON* */
- {
- fill_hrd_params (encoder, misc->data);
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
-
- return TRUE;
+ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
}
/* Generates additional control parameters */
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
index 2aee116a..9513f5c8 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c
@@ -1769,27 +1769,17 @@ static gboolean
ensure_control_rate_params (GstVaapiEncoderH265 * encoder,
GstVaapiEncPicture * picture)
{
- GstVaapiEncMiscParam *misc;
+ GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
/* HRD params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
- if (!misc)
- return FALSE;
-
- {
- fill_hrd_params (encoder, misc->data);
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
- return TRUE;
+ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
}
-
static gboolean
ensure_misc_params (GstVaapiEncoderH265 * encoder, GstVaapiEncPicture * picture)
{
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
index e33956d3..e80443a7 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
@@ -456,47 +456,27 @@ ensure_control_rate_params (GstVaapiEncoderMpeg2 * encoder,
GstVaapiEncPicture * picture)
{
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
- GstVaapiEncMiscParam *misc;
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
+ /* *INDENT-OFF* */
/* RateControl params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
- if (!misc)
- return FALSE;
-
- {
- VAEncMiscParameterRateControl rate_control = {
- .bits_per_second = base_encoder->bitrate * 1000,
- .target_percentage = 70,
- .window_size = 500,
- .initial_qp = encoder->cqp,
- };
-
- memcpy (misc->data, &rate_control, sizeof (rate_control));
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
+ .bits_per_second = base_encoder->bitrate * 1000,
+ .target_percentage = 70,
+ .window_size = 500,
+ .initial_qp = encoder->cqp,
+ };
/* HRD params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
- if (!misc)
- return FALSE;
- {
- VAEncMiscParameterHRD hrd = {
- .buffer_size = base_encoder->bitrate * 1000 * 8,
- .initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
- };
-
- memcpy (misc->data, &hrd, sizeof (hrd));
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
+ .buffer_size = base_encoder->bitrate * 1000 * 8,
+ .initial_buffer_fullness = base_encoder->bitrate * 1000 * 4,
+ };
+ /* *INDENT-ON* */
- return TRUE;
+ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
}
static gboolean
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
index 8de816f2..598aabf2 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h
@@ -175,6 +175,39 @@ G_BEGIN_DECLS
#define GST_VAAPI_ENCODER_QUALITY_LEVEL(encoder) \
(GST_VAAPI_ENCODER_CAST (encoder)->va_quality_level.quality_level)
+/**
+ * GST_VAAPI_ENCODER_VA_RATE_CONTROL:
+ * @encoder: a #GstVaapiEncoder
+ *
+ * Macro that evaluates to #VAEncMiscParameterRateControl
+ * This is an internal macro that does not do any run-time type check.
+ */
+#undef GST_VAAPI_ENCODER_VA_RATE_CONTROL
+#define GST_VAAPI_ENCODER_VA_RATE_CONTROL(encoder) \
+ (GST_VAAPI_ENCODER_CAST (encoder)->va_ratecontrol)
+
+/**
+ * GST_VAAPI_ENCODER_VA_FRAME_RATE:
+ * @encoder: a #GstVaapiEncoder
+ *
+ * Macro that evaluates to #VAEncMiscParameterFrameRate
+ * This is an internal macro that does not do any run-time type check.
+ */
+#undef GST_VAAPI_ENCODER_VA_FRAME_RATE
+#define GST_VAAPI_ENCODER_VA_FRAME_RATE(encoder) \
+ (GST_VAAPI_ENCODER_CAST (encoder)->va_framerate)
+
+/**
+ * GST_VAAPI_ENCODER_VA_HRD:
+ * @encoder: a #GstVaapiEncoder
+ *
+ * Macro that evaluates to #VAEncMiscParameterHRD
+ * This is an internal macro that does not do any run-time type check.
+ */
+#undef GST_VAAPI_ENCODER_VA_HRD
+#define GST_VAAPI_ENCODER_VA_HRD(encoder) \
+ (GST_VAAPI_ENCODER_CAST (encoder)->va_hrd)
+
/* Generate a mask for the supplied tuning option (internal) */
#define GST_VAAPI_ENCODER_TUNE_MASK(TUNE) \
(1U << G_PASTE (GST_VAAPI_ENCODER_TUNE_, TUNE))
@@ -244,6 +277,11 @@ struct _GstVaapiEncoder
/* Region of Interest */
GList *roi_regions;
+
+ /* miscellaneous buffer parameters */
+ VAEncMiscParameterRateControl va_ratecontrol;
+ VAEncMiscParameterFrameRate va_framerate;
+ VAEncMiscParameterHRD va_hrd;
};
struct _GstVaapiEncoderClassData
@@ -364,6 +402,11 @@ gst_vaapi_encoder_ensure_param_quality_level (GstVaapiEncoder * encoder,
G_GNUC_INTERNAL
gboolean
+gst_vaapi_encoder_ensure_param_control_rate (GstVaapiEncoder * encoder,
+ GstVaapiEncPicture * picture);
+
+G_GNUC_INTERNAL
+gboolean
gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder,
GstVaapiProfile profile, GstVaapiEntrypoint entrypoint,
guint media_max_slices, guint * num_slices);
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
index 5c895dbd..11f64492 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c
@@ -262,65 +262,36 @@ ensure_control_rate_params (GstVaapiEncoderVP8 * encoder,
GstVaapiEncPicture * picture)
{
GstVaapiEncoder *const base_encoder = GST_VAAPI_ENCODER_CAST (encoder);
- GstVaapiEncMiscParam *misc;
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE;
+ /* *INDENT-OFF* */
/* RateControl params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (RateControl, encoder);
- if (!misc)
- return FALSE;
-
- {
- VAEncMiscParameterRateControl rate_control = {
- .bits_per_second = base_encoder->bitrate * 1000,
- .target_percentage = 70,
- /* CPB (Coded picture buffer) length in milliseconds, which
- * could be provided as a property */
- .window_size = 500,
- .initial_qp = encoder->yac_qi,
- .min_qp = 1,
- };
-
- memcpy (misc->data, &rate_control, sizeof (rate_control));
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder) = (VAEncMiscParameterRateControl) {
+ .bits_per_second = base_encoder->bitrate * 1000,
+ .target_percentage = 70,
+ /* CPB (Coded picture buffer) length in milliseconds, which
+ * could be provided as a property */
+ .window_size = 500,
+ .initial_qp = encoder->yac_qi,
+ .min_qp = 1,
+ };
/* HRD params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (HRD, encoder);
- if (!misc)
- return FALSE;
-
- {
- VAEncMiscParameterHRD hrd = {
- .buffer_size = base_encoder->bitrate * 1000 * 2,
- .initial_buffer_fullness = base_encoder->bitrate * 1000,
- };
-
- memcpy (misc->data, &hrd, sizeof (hrd));
- }
-
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_HRD (encoder) = (VAEncMiscParameterHRD) {
+ .buffer_size = base_encoder->bitrate * 1000 * 2,
+ .initial_buffer_fullness = base_encoder->bitrate * 1000,
+ };
/* FrameRate params */
- misc = GST_VAAPI_ENC_MISC_PARAM_NEW (FrameRate, encoder);
- if (!misc)
- return FALSE;
- {
- VAEncMiscParameterFrameRate fr = {
- .framerate = (guint) GST_VAAPI_ENCODER_FPS_D (encoder) << 16 |
- GST_VAAPI_ENCODER_FPS_N (encoder),
- };
- memcpy (misc->data, &fr, sizeof (fr));
- }
- gst_vaapi_enc_picture_add_misc_param (picture, misc);
- gst_vaapi_codec_object_replace (&misc, NULL);
+ GST_VAAPI_ENCODER_VA_FRAME_RATE (encoder) = (VAEncMiscParameterFrameRate) {
+ .framerate = (guint) GST_VAAPI_ENCODER_FPS_D (encoder) << 16 |
+ GST_VAAPI_ENCODER_FPS_N (encoder),
+ };
+ /* *INDENT-ON* */
- return TRUE;
+ return gst_vaapi_encoder_ensure_param_control_rate (base_encoder, picture);
}
static gboolean