encoder: notify the encoder of the submitted packed headers.

Make sure to configure the encoder with the set of packed headers we
intend to generate and submit. i.e. make selection of packed headers
to submit more robust.
This commit is contained in:
Gwenole Beauchesne 2014-01-23 15:13:06 +01:00
parent 1dc9837dd9
commit 4481c155b8
6 changed files with 54 additions and 9 deletions

View file

@ -144,7 +144,7 @@ context_create (GstVaapiContext * context)
const GstVaapiContextInfo *const cip = &context->info;
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
guint va_rate_control;
VAConfigAttrib attribs[2], *attrib = attribs;
VAConfigAttrib attribs[3], *attrib = attribs;
VAContextID context_id;
VASurfaceID surface_id;
VAStatus status;
@ -204,6 +204,21 @@ context_create (GstVaapiContext * context)
}
attrib->value = va_rate_control;
attrib++;
/* Packed headers */
if (config->packed_headers) {
attrib->type = VAConfigAttribEncPackedHeaders;
if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
goto cleanup;
if ((value & config->packed_headers) != config->packed_headers) {
GST_ERROR ("unsupported packed headers 0x%08x",
config->packed_headers & ~(value & config->packed_headers));
goto cleanup;
}
attrib->value = config->packed_headers;
attrib++;
}
break;
}
default:
@ -250,6 +265,11 @@ context_update_config_encoder (GstVaapiContext * context,
config->rc_mode = new_config->rc_mode;
config_changed = TRUE;
}
if (config->packed_headers != new_config->packed_headers) {
config->packed_headers = new_config->packed_headers;
config_changed = TRUE;
}
return config_changed;
}

View file

@ -59,12 +59,14 @@ typedef enum {
/**
* GstVaapiConfigInfoEncoder:
* @rc_mode: rate-control mode (#GstVaapiRateControl).
* @packed_headers: notify encoder that packed headers are submitted (mask).
*
* Extra configuration for encoding.
*/
struct _GstVaapiConfigInfoEncoder
{
GstVaapiRateControl rc_mode;
guint packed_headers;
};
/**

View file

@ -534,14 +534,24 @@ get_config_attribute (GstVaapiEncoder * encoder, VAConfigAttribType type,
return TRUE;
}
/* Determines the set of required packed headers */
static void
ensure_packed_headers (GstVaapiEncoder * encoder)
/* Determines the set of supported packed headers */
static guint
get_packed_headers (GstVaapiEncoder * encoder)
{
if (!gst_vaapi_context_get_attribute (encoder->context,
VAConfigAttribEncPackedHeaders, &encoder->packed_headers))
encoder->packed_headers = 0;
GST_INFO ("packed headers mask: 0x%08x", encoder->packed_headers);
const GstVaapiEncoderClassData *const cdata =
GST_VAAPI_ENCODER_GET_CLASS (encoder)->class_data;
guint value;
if (encoder->got_packed_headers)
return encoder->packed_headers;
if (!get_config_attribute (encoder, VAConfigAttribEncPackedHeaders, &value))
value = 0;
GST_INFO ("supported packed headers: 0x%08x", value);
encoder->got_packed_headers = TRUE;
encoder->packed_headers = cdata->packed_headers & value;
return encoder->packed_headers;
}
/* Updates video context */
@ -560,6 +570,7 @@ set_context_info (GstVaapiEncoder * encoder)
memset (config, 0, sizeof (*config));
config->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
config->packed_headers = get_packed_headers (encoder);
}
/* Ensures the underlying VA context for encoding is created */
@ -602,7 +613,6 @@ gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder)
if (!gst_vaapi_encoder_ensure_context (encoder))
goto error_reset_context;
ensure_packed_headers (encoder);
codedbuf_size = encoder->codedbuf_pool ?
gst_vaapi_coded_buffer_pool_get_buffer_size (GST_VAAPI_CODED_BUFFER_POOL

View file

@ -63,6 +63,11 @@
(GST_VAAPI_ENCODER_TUNE_MASK (NONE) | \
GST_VAAPI_ENCODER_TUNE_MASK (HIGH_COMPRESSION))
/* Supported set of VA packed headers, within this implementation */
#define SUPPORTED_PACKED_HEADERS \
(VA_ENC_PACKED_HEADER_SEQUENCE | \
VA_ENC_PACKED_HEADER_PICTURE)
#define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_NONE 0
#define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_LOW 1
#define GST_VAAPI_ENCODER_H264_NAL_REF_IDC_MEDIUM 2

View file

@ -50,6 +50,11 @@
#define SUPPORTED_TUNE_OPTIONS \
(GST_VAAPI_ENCODER_TUNE_MASK (NONE))
/* Supported set of VA packed headers, within this implementation */
#define SUPPORTED_PACKED_HEADERS \
(VA_ENC_PACKED_HEADER_SEQUENCE | \
VA_ENC_PACKED_HEADER_PICTURE)
static gboolean
gst_bit_writer_write_sps (GstBitWriter * bitwriter,
const VAEncSequenceParameterBufferMPEG2 * seq_param);

View file

@ -225,6 +225,7 @@ struct _GstVaapiEncoder
GAsyncQueue *codedbuf_queue;
guint32 num_codedbuf_queued;
guint got_packed_headers:1;
guint got_rate_control_mask:1;
};
@ -232,6 +233,7 @@ struct _GstVaapiEncoderClassData
{
/*< private >*/
GstVaapiCodec codec;
guint32 packed_headers;
GType (*rate_control_get_type)(void);
GstVaapiRateControl default_rate_control;
@ -255,6 +257,7 @@ struct _GstVaapiEncoderClassData
\
static const GstVaapiEncoderClassData g_class_data = { \
.codec = G_PASTE (GST_VAAPI_CODEC_, CODEC), \
.packed_headers = SUPPORTED_PACKED_HEADERS, \
.rate_control_get_type = \
G_PASTE (G_PASTE (gst_vaapi_rate_control_, CODEC), _get_type), \
.default_rate_control = DEFAULT_RATECONTROL, \