mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-06 02:32: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;
|
const GstVaapiContextInfo *const cip = &context->info;
|
||||||
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
|
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
|
||||||
guint va_rate_control;
|
guint va_rate_control;
|
||||||
VAConfigAttrib attribs[2];
|
VAConfigAttrib attribs[2], *attrib = attribs;
|
||||||
guint num_attribs;
|
|
||||||
VAContextID context_id;
|
VAContextID context_id;
|
||||||
VASurfaceID surface_id;
|
VASurfaceID surface_id;
|
||||||
VAStatus status;
|
VAStatus status;
|
||||||
GArray *surfaces = NULL;
|
GArray *surfaces = NULL;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
guint i;
|
guint i, value;
|
||||||
|
|
||||||
if (!context->surfaces && !context_create_surfaces (context))
|
if (!context->surfaces && !context_create_surfaces (context))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
/* Create VA surfaces list for vaCreateContext() */
|
||||||
surfaces = g_array_sized_new (FALSE,
|
surfaces = g_array_sized_new (FALSE,
|
||||||
FALSE, sizeof (VASurfaceID), context->surfaces->len);
|
FALSE, sizeof (VASurfaceID), context->surfaces->len);
|
||||||
if (!surfaces)
|
if (!surfaces)
|
||||||
|
@ -170,41 +170,47 @@ context_create (GstVaapiContext * context)
|
||||||
}
|
}
|
||||||
g_assert (surfaces->len == context->surfaces->len);
|
g_assert (surfaces->len == context->surfaces->len);
|
||||||
|
|
||||||
|
/* Reset profile and entrypoint */
|
||||||
if (!cip->profile || !cip->entrypoint)
|
if (!cip->profile || !cip->entrypoint)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
context->va_profile = gst_vaapi_profile_get_va_profile (cip->profile);
|
context->va_profile = gst_vaapi_profile_get_va_profile (cip->profile);
|
||||||
context->va_entrypoint =
|
context->va_entrypoint =
|
||||||
gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint);
|
gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint);
|
||||||
|
|
||||||
num_attribs = 0;
|
/* Validate VA surface format */
|
||||||
attribs[num_attribs++].type = VAConfigAttribRTFormat;
|
attrib->type = VAConfigAttribRTFormat;
|
||||||
if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE)
|
if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
|
||||||
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()"))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (!(attribs[0].value & VA_RT_FORMAT_YUV420))
|
if (!(value & VA_RT_FORMAT_YUV420))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
attrib->value = VA_RT_FORMAT_YUV420;
|
||||||
|
attrib++;
|
||||||
|
|
||||||
if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) {
|
switch (cip->usage) {
|
||||||
va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
|
case GST_VAAPI_CONTEXT_USAGE_ENCODE:
|
||||||
if (va_rate_control == VA_RC_NONE)
|
{
|
||||||
attribs[1].value = VA_RC_NONE;
|
/* Rate control */
|
||||||
if ((attribs[1].value & va_rate_control) != va_rate_control) {
|
attrib->type = VAConfigAttribRateControl;
|
||||||
GST_ERROR ("unsupported %s rate control",
|
if (!gst_vaapi_context_get_attribute (context, attrib->type, &value))
|
||||||
string_of_VARateControl (va_rate_control));
|
goto cleanup;
|
||||||
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);
|
GST_VAAPI_DISPLAY_LOCK (display);
|
||||||
status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (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);
|
&context->va_config);
|
||||||
GST_VAAPI_DISPLAY_UNLOCK (display);
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
||||||
if (!vaapi_check_status (status, "vaCreateConfig()"))
|
if (!vaapi_check_status (status, "vaCreateConfig()"))
|
||||||
|
@ -314,15 +320,14 @@ gst_vaapi_context_reset (GstVaapiContext * context,
|
||||||
cip->entrypoint = new_cip->entrypoint;
|
cip->entrypoint = new_cip->entrypoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (new_cip->entrypoint) {
|
if (cip->usage != new_cip->usage) {
|
||||||
case GST_VAAPI_ENTRYPOINT_SLICE_ENCODE:
|
cip->usage = new_cip->usage;
|
||||||
if (cip->rc_mode != new_cip->rc_mode) {
|
config_changed = TRUE;
|
||||||
cip->rc_mode = new_cip->rc_mode;
|
} else if (new_cip->usage == GST_VAAPI_CONTEXT_USAGE_ENCODE) {
|
||||||
config_changed = TRUE;
|
if (cip->rc_mode != new_cip->rc_mode) {
|
||||||
}
|
cip->rc_mode = new_cip->rc_mode;
|
||||||
break;
|
config_changed = TRUE;
|
||||||
default:
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_changed)
|
if (size_changed)
|
||||||
|
|
|
@ -41,6 +41,20 @@ typedef struct _GstVaapiContextInfo GstVaapiContextInfo;
|
||||||
typedef struct _GstVaapiContext GstVaapiContext;
|
typedef struct _GstVaapiContext GstVaapiContext;
|
||||||
typedef struct _GstVaapiContextClass GstVaapiContextClass;
|
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:
|
* GstVaapiContextInfo:
|
||||||
*
|
*
|
||||||
|
@ -53,6 +67,7 @@ typedef struct _GstVaapiContextClass GstVaapiContextClass;
|
||||||
*/
|
*/
|
||||||
struct _GstVaapiContextInfo
|
struct _GstVaapiContextInfo
|
||||||
{
|
{
|
||||||
|
GstVaapiContextUsage usage;
|
||||||
GstVaapiProfile profile;
|
GstVaapiProfile profile;
|
||||||
GstVaapiEntrypoint entrypoint;
|
GstVaapiEntrypoint entrypoint;
|
||||||
GstVaapiRateControl rc_mode;
|
GstVaapiRateControl rc_mode;
|
||||||
|
|
|
@ -952,6 +952,7 @@ gst_vaapi_decoder_ensure_context(
|
||||||
{
|
{
|
||||||
gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
|
gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
|
||||||
|
|
||||||
|
cip->usage = GST_VAAPI_CONTEXT_USAGE_DECODE;
|
||||||
if (decoder->context) {
|
if (decoder->context) {
|
||||||
if (!gst_vaapi_context_reset(decoder->context, cip))
|
if (!gst_vaapi_context_reset(decoder->context, cip))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -484,6 +484,7 @@ set_context_info (GstVaapiEncoder * encoder)
|
||||||
{
|
{
|
||||||
GstVaapiContextInfo *const cip = &encoder->context_info;
|
GstVaapiContextInfo *const cip = &encoder->context_info;
|
||||||
|
|
||||||
|
cip->usage = GST_VAAPI_CONTEXT_USAGE_ENCODE;
|
||||||
cip->profile = encoder->profile;
|
cip->profile = encoder->profile;
|
||||||
cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
|
||||||
cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder);
|
||||||
|
|
Loading…
Reference in a new issue