mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
context: introduce concept of usage.
Introduce GstVaapiContextUsage so that to explicitly determine the usage of a VA context. This is useful in view to simplifying the creation of VA context for VPP too.
This commit is contained in:
parent
e3ed05bc52
commit
0eb4070977
4 changed files with 55 additions and 33 deletions
|
@ -144,18 +144,18 @@ 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];
|
||||
guint num_attribs;
|
||||
VAConfigAttrib attribs[2], *attrib = attribs;
|
||||
VAContextID context_id;
|
||||
VASurfaceID surface_id;
|
||||
VAStatus status;
|
||||
GArray *surfaces = NULL;
|
||||
gboolean success = FALSE;
|
||||
guint i;
|
||||
guint i, value;
|
||||
|
||||
if (!context->surfaces && !context_create_surfaces (context))
|
||||
goto cleanup;
|
||||
|
||||
/* Create VA surfaces list for vaCreateContext() */
|
||||
surfaces = g_array_sized_new (FALSE,
|
||||
FALSE, sizeof (VASurfaceID), context->surfaces->len);
|
||||
if (!surfaces)
|
||||
|
@ -170,41 +170,47 @@ context_create (GstVaapiContext * context)
|
|||
}
|
||||
g_assert (surfaces->len == context->surfaces->len);
|
||||
|
||||
/* Reset profile and entrypoint */
|
||||
if (!cip->profile || !cip->entrypoint)
|
||||
goto cleanup;
|
||||
context->va_profile = gst_vaapi_profile_get_va_profile (cip->profile);
|
||||
context->va_entrypoint =
|
||||
gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint);
|
||||
|
||||
num_attribs = 0;
|
||||
attribs[num_attribs++].type = VAConfigAttribRTFormat;
|
||||
if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE)
|
||||
attribs[num_attribs++].type = VAConfigAttribRateControl;
|
||||
|
||||
GST_VAAPI_DISPLAY_LOCK (display);
|
||||
status = vaGetConfigAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
||||
context->va_profile, context->va_entrypoint, attribs, num_attribs);
|
||||
GST_VAAPI_DISPLAY_UNLOCK (display);
|
||||
if (!vaapi_check_status (status, "vaGetConfigAttributes()"))
|
||||
/* Validate VA surface format */
|
||||
attrib->type = VAConfigAttribRTFormat;
|
||||
if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
|
||||
goto cleanup;
|
||||
if (!(attribs[0].value & VA_RT_FORMAT_YUV420))
|
||||
if (!(value & VA_RT_FORMAT_YUV420))
|
||||
goto cleanup;
|
||||
attrib->value = VA_RT_FORMAT_YUV420;
|
||||
attrib++;
|
||||
|
||||
if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) {
|
||||
va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
|
||||
if (va_rate_control == VA_RC_NONE)
|
||||
attribs[1].value = VA_RC_NONE;
|
||||
if ((attribs[1].value & va_rate_control) != va_rate_control) {
|
||||
GST_ERROR ("unsupported %s rate control",
|
||||
string_of_VARateControl (va_rate_control));
|
||||
goto cleanup;
|
||||
switch (cip->usage) {
|
||||
case GST_VAAPI_CONTEXT_USAGE_ENCODE:
|
||||
{
|
||||
/* Rate control */
|
||||
attrib->type = VAConfigAttribRateControl;
|
||||
if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
|
||||
goto cleanup;
|
||||
|
||||
va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
|
||||
if ((value & va_rate_control) != va_rate_control) {
|
||||
GST_ERROR ("unsupported %s rate control",
|
||||
string_of_VARateControl (va_rate_control));
|
||||
goto cleanup;
|
||||
}
|
||||
attrib->value = va_rate_control;
|
||||
attrib++;
|
||||
break;
|
||||
}
|
||||
attribs[1].value = va_rate_control;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
GST_VAAPI_DISPLAY_LOCK (display);
|
||||
status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
||||
context->va_profile, context->va_entrypoint, attribs, num_attribs,
|
||||
context->va_profile, context->va_entrypoint, attribs, attrib - attribs,
|
||||
&context->va_config);
|
||||
GST_VAAPI_DISPLAY_UNLOCK (display);
|
||||
if (!vaapi_check_status (status, "vaCreateConfig()"))
|
||||
|
@ -314,15 +320,14 @@ gst_vaapi_context_reset (GstVaapiContext * context,
|
|||
cip->entrypoint = new_cip->entrypoint;
|
||||
}
|
||||
|
||||
switch (new_cip->entrypoint) {
|
||||
case GST_VAAPI_ENTRYPOINT_SLICE_ENCODE:
|
||||
if (cip->rc_mode != new_cip->rc_mode) {
|
||||
cip->rc_mode = new_cip->rc_mode;
|
||||
config_changed = TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (cip->usage != new_cip->usage) {
|
||||
cip->usage = new_cip->usage;
|
||||
config_changed = TRUE;
|
||||
} else if (new_cip->usage == GST_VAAPI_CONTEXT_USAGE_ENCODE) {
|
||||
if (cip->rc_mode != new_cip->rc_mode) {
|
||||
cip->rc_mode = new_cip->rc_mode;
|
||||
config_changed = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (size_changed)
|
||||
|
|
|
@ -41,6 +41,20 @@ typedef struct _GstVaapiContextInfo GstVaapiContextInfo;
|
|||
typedef struct _GstVaapiContext GstVaapiContext;
|
||||
typedef struct _GstVaapiContextClass GstVaapiContextClass;
|
||||
|
||||
/**
|
||||
* GstVaapiContextUsage:
|
||||
* @GST_VAAPI_CONTEXT_MODE_DECODE: context used for decoding.
|
||||
* @GST_VAAPI_CONTEXT_MODE_ENCODE: context used for encoding.
|
||||
* @GST_VAAPI_CONTEXT_MODE_VPP: context used for video processing.
|
||||
*
|
||||
* The set of supported VA context usages.
|
||||
*/
|
||||
typedef enum {
|
||||
GST_VAAPI_CONTEXT_USAGE_DECODE = 1,
|
||||
GST_VAAPI_CONTEXT_USAGE_ENCODE,
|
||||
GST_VAAPI_CONTEXT_USAGE_VPP,
|
||||
} GstVaapiContextUsage;
|
||||
|
||||
/**
|
||||
* GstVaapiContextInfo:
|
||||
*
|
||||
|
@ -53,6 +67,7 @@ typedef struct _GstVaapiContextClass GstVaapiContextClass;
|
|||
*/
|
||||
struct _GstVaapiContextInfo
|
||||
{
|
||||
GstVaapiContextUsage usage;
|
||||
GstVaapiProfile profile;
|
||||
GstVaapiEntrypoint entrypoint;
|
||||
GstVaapiRateControl rc_mode;
|
||||
|
|
|
@ -952,6 +952,7 @@ gst_vaapi_decoder_ensure_context(
|
|||
{
|
||||
gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
|
||||
|
||||
cip->usage = GST_VAAPI_CONTEXT_USAGE_DECODE;
|
||||
if (decoder->context) {
|
||||
if (!gst_vaapi_context_reset(decoder->context, cip))
|
||||
return FALSE;
|
||||
|
|
|
@ -484,6 +484,7 @@ set_context_info (GstVaapiEncoder * encoder)
|
|||
{
|
||||
GstVaapiContextInfo *const cip = &encoder->context_info;
|
||||
|
||||
cip->usage = GST_VAAPI_CONTEXT_USAGE_ENCODE;
|
||||
cip->profile = encoder->profile;
|
||||
cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
||||
cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
||||
|
|
Loading…
Reference in a new issue