vaapijpegenc: Add a quantization quirk for iHD driver

iHD driver shifts the value by 50 when calculating quantization for JPEG
encoding, so we should add 50 in this plugin for iHD driver too.
This commit is contained in:
Haihao Xiang 2019-11-25 14:16:30 +08:00 committed by GStreamer Merge Bot
parent bb38055745
commit 61516dd5e1
3 changed files with 27 additions and 5 deletions

View file

@ -806,6 +806,7 @@ set_driver_quirks (GstVaapiDisplay * display)
{ "i965", GST_VAAPI_DRIVER_QUIRK_NO_CHECK_VPP_COLOR_STD },
{ "iHD", GST_VAAPI_DRIVER_QUIRK_NO_RGBYUV_VPP_COLOR_PRIMARY },
{ "i965", GST_VAAPI_DRIVER_QUIRK_MISSING_RGBA_IMAGE_FORMAT },
{ "iHD", GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50 },
};
/* *INDENT-ON* */

View file

@ -105,6 +105,8 @@ typedef struct _GstVaapiDisplay GstVaapiDisplay;
* report to support ARGB format, but if it's forced to create a RGBA
* surface, it works. Driver issue:
* https://github.com/intel/intel-vaapi-driver/issues/500
* @GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50: if the driver shifts
* the value by 50 when calculating quantization from quality level
*/
typedef enum
{
@ -112,6 +114,7 @@ typedef enum
GST_VAAPI_DRIVER_QUIRK_NO_CHECK_VPP_COLOR_STD = (1U << 1),
GST_VAAPI_DRIVER_QUIRK_NO_RGBYUV_VPP_COLOR_PRIMARY = (1U << 2),
GST_VAAPI_DRIVER_QUIRK_MISSING_RGBA_IMAGE_FORMAT = (1U << 3),
GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50 = (1U << 4),
} GstVaapiDriverQuirks;
/**

View file

@ -255,7 +255,7 @@ ensure_picture (GstVaapiEncoderJpeg * encoder, GstVaapiEncPicture * picture,
* is scaling the QM values using the normalized quality factor */
static void
generate_scaled_qm (GstJpegQuantTables * quant_tables,
GstJpegQuantTables * scaled_quant_tables, guint quality)
GstJpegQuantTables * scaled_quant_tables, guint quality, guint shift)
{
guint qt_val, nm_quality, i;
nm_quality = quality == 0 ? 1 : quality;
@ -267,11 +267,15 @@ generate_scaled_qm (GstJpegQuantTables * quant_tables,
for (i = 0; i < GST_JPEG_MAX_QUANT_ELEMENTS; i++) {
/* Luma QM */
qt_val = (quant_tables->quant_tables[0].quant_table[i] * nm_quality) / 100;
qt_val =
(quant_tables->quant_tables[0].quant_table[i] * nm_quality +
shift) / 100;
scaled_quant_tables->quant_tables[0].quant_table[i] =
CLAMP (qt_val, 1, 255);
/* Chroma QM */
qt_val = (quant_tables->quant_tables[1].quant_table[i] * nm_quality) / 100;
qt_val =
(quant_tables->quant_tables[1].quant_table[i] * nm_quality +
shift) / 100;
scaled_quant_tables->quant_tables[1].quant_table[i] =
CLAMP (qt_val, 1, 255);
}
@ -294,10 +298,17 @@ fill_quantization_table (GstVaapiEncoderJpeg * encoder,
q_matrix = picture->q_matrix->param;
if (!encoder->has_quant_tables) {
GstVaapiDisplay *const display = GST_VAAPI_ENCODER_DISPLAY (encoder);
guint shift = 0;
if (gst_vaapi_display_has_driver_quirks (display,
GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50))
shift = 50;
gst_jpeg_get_default_quantization_tables (&encoder->quant_tables);
encoder->has_quant_tables = TRUE;
generate_scaled_qm (&encoder->quant_tables, &encoder->scaled_quant_tables,
encoder->quality);
encoder->quality, shift);
}
q_matrix->load_lum_quantiser_matrix = 1;
for (i = 0; i < GST_JPEG_MAX_QUANT_ELEMENTS; i++) {
@ -507,9 +518,16 @@ bs_write_jpeg_header (GstBitWriter * bs, GstVaapiEncoderJpeg * encoder,
/* Add quantization table */
if (!encoder->has_quant_tables) {
GstVaapiDisplay *const display = GST_VAAPI_ENCODER_DISPLAY (encoder);
guint shift = 0;
if (gst_vaapi_display_has_driver_quirks (display,
GST_VAAPI_DRIVER_QUIRK_JPEG_ENC_SHIFT_VALUE_BY_50))
shift = 50;
gst_jpeg_get_default_quantization_tables (&encoder->quant_tables);
generate_scaled_qm (&encoder->quant_tables, &encoder->scaled_quant_tables,
encoder->quality);
encoder->quality, shift);
encoder->has_quant_tables = TRUE;
}