encoder: h264: only submit packed headers when required.

Make sure to submit the packed headers only if the underlying VA driver
requires those. Currently, only handle packed sequence and picture
headers.

https://bugzilla.gnome.org/show_bug.cgi?id=722737
This commit is contained in:
Gwenole Beauchesne 2014-01-21 18:35:17 +01:00
parent d9cf58e88a
commit 71113e4999
5 changed files with 73 additions and 2 deletions

View file

@ -1005,3 +1005,43 @@ error:
gst_vaapi_context_clear_overlay(context);
return FALSE;
}
/**
* gst_vaapi_context_get_attribute:
* @context: a #GstVaapiContext
* @type: a VA config attribute type
* @out_value_ptr: return location for the config attribute value
*
* Determines the value for the VA config attribute @type.
*
* Note: this function only returns success if the VA driver does
* actually know about this config attribute type and that it returned
* a valid value for it.
*
* Return value: %TRUE if the VA driver knows about the requested
* config attribute and returned a valid value, %FALSE otherwise
*/
gboolean
gst_vaapi_context_get_attribute(GstVaapiContext *context,
VAConfigAttribType type, guint *out_value_ptr)
{
VAConfigAttrib attrib;
VAStatus status;
g_return_val_if_fail(context != NULL, FALSE);
GST_VAAPI_OBJECT_LOCK_DISPLAY(context);
attrib.type = type;
status = vaGetConfigAttributes(GST_VAAPI_OBJECT_VADISPLAY(context),
gst_vaapi_profile_get_va_profile(context->info.profile),
gst_vaapi_entrypoint_get_va_entrypoint(context->info.entrypoint),
&attrib, 1);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(context);
if (!vaapi_check_status(status, "vaGetConfiAttributes()"))
return FALSE;
if (out_value_ptr)
*out_value_ptr = attrib.value;
return TRUE;
}

View file

@ -127,6 +127,11 @@ gst_vaapi_context_apply_composition(
GstVideoOverlayComposition *composition
);
G_GNUC_INTERNAL
gboolean
gst_vaapi_context_get_attribute(GstVaapiContext *context,
VAConfigAttribType type, guint *out_value_ptr);
G_END_DECLS
#endif /* GST_VAAPI_CONTEXT_H */

View file

@ -466,6 +466,16 @@ error_invalid_framerate:
}
}
/* Determines the set of required packed headers */
static void
ensure_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);
}
/* Updates video context */
static void
set_context_info (GstVaapiEncoder * encoder)
@ -520,6 +530,7 @@ 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

@ -1366,7 +1366,8 @@ ensure_sequence (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
goto error;
if (picture->type == GST_VAAPI_PICTURE_TYPE_I &&
!add_packed_sequence_header (encoder, picture, sequence))
(GST_VAAPI_ENCODER_PACKED_HEADERS (encoder) & VAEncPackedHeaderH264_SPS)
&& !add_packed_sequence_header (encoder, picture, sequence))
goto error;
gst_vaapi_enc_picture_set_sequence (picture, sequence);
gst_vaapi_codec_object_replace (&sequence, NULL);
@ -1430,7 +1431,8 @@ ensure_picture (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture,
return FALSE;
if (picture->type == GST_VAAPI_PICTURE_TYPE_I &&
!add_packed_picture_header (encoder, picture)) {
(GST_VAAPI_ENCODER_PACKED_HEADERS (encoder) & VAEncPackedHeaderH264_PPS)
&& !add_packed_picture_header (encoder, picture)) {
GST_ERROR ("set picture packed header failed");
return FALSE;
}

View file

@ -40,6 +40,18 @@ G_BEGIN_DECLS
#define GST_VAAPI_ENCODER_GET_CLASS(obj) \
GST_VAAPI_ENCODER_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(obj))
/**
* GST_VAAPI_ENCODER_PACKED_HEADERS:
* @encoder: a #GstVaapiEncoder
*
* Macro that evaluates to the required set of VA packed headers that
* need to be submitted along with the corresponding param buffers.
* This is an internal macro that does not do any run-time type check.
*/
#undef GST_VAAPI_ENCODER_PACKED_HEADERS
#define GST_VAAPI_ENCODER_PACKED_HEADERS(encoder) \
GST_VAAPI_ENCODER_CAST(encoder)->packed_headers
/**
* GST_VAAPI_ENCODER_DISPLAY:
* @encoder: a #GstVaapiEncoder
@ -191,6 +203,7 @@ struct _GstVaapiEncoder
GstVaapiContext *context;
GstVaapiContextInfo context_info;
GstVaapiEncoderTune tune;
guint packed_headers;
VADisplay va_display;
VAContextID va_context;