Commit ac3e8c7c authored by He Junyan's avatar He Junyan Committed by Víctor Manuel Jáquez Leal

libs: decoder: context: remove surfaces binding from context.

The vaCreateContext do not need to specify the surfaces for the
context creation now. So we do not need to bind any surface to the
context anymore. Surfaces should be the resource belong to display
and just be used in encoder/decoder context.

The previous manner has big limitation for decoder. The context's
surface number is decided by dpb size. All the surfaces in dpb will
be attached to a gstbuffer and be pushed to down stream, and the
decoder need to wait down stream free the surface and go on if not
enough surface available. For more and more use cases, this causes
deadlock. For example,

gst-launch-1.0 filesrc location=a.h264 ! h264parse ! vaapih264dec
! x264enc ! filesink location=./output.h264

will cause deadlock and make the whole pipeline hang.
the x264enc encoder need to cache more than dpb size surfaces.

The best solution is seperating the surfaces number and the dpb size.
dpb and dpb size shoule be virtual concepts maintained by the decoder.
And let the surfaces_pool in context maintain the re-use of all surfaces.

For encoder, the situation is better, all the surfaces are just used
as reference frame and no need to be pushed to down stream. We can
just reserve and set the capacity of the surfaces_pool to meet the
request.

Fix: #147
Fix: #88

Co-Author: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Part-of: <!353>
parent 60c18333
......@@ -165,7 +165,7 @@ context_ensure_surfaces (GstVaapiContext * context)
const guint num_surfaces = cip->ref_frames + SCRATCH_SURFACES_COUNT;
GstVaapiSurface *surface;
GstVideoFormat format;
guint i;
guint i, capacity;
format = get_preferred_format (context);
for (i = context->surfaces->len; i < num_surfaces; i++) {
......@@ -182,7 +182,9 @@ context_ensure_surfaces (GstVaapiContext * context)
if (!gst_vaapi_video_pool_add_object (context->surfaces_pool, surface))
return FALSE;
}
gst_vaapi_video_pool_set_capacity (context->surfaces_pool, num_surfaces);
capacity = cip->usage == GST_VAAPI_CONTEXT_USAGE_DECODE ? 0 : num_surfaces;
gst_vaapi_video_pool_set_capacity (context->surfaces_pool, capacity);
return TRUE;
}
......@@ -219,10 +221,12 @@ context_create (GstVaapiContext * context)
GstVaapiDisplay *const display = GST_VAAPI_CONTEXT_DISPLAY (context);
VAContextID context_id;
VASurfaceID surface_id;
VASurfaceID *surfaces_data = NULL;
VAStatus status;
GArray *surfaces = NULL;
gboolean success = FALSE;
guint i;
gint num_surfaces = 0;
if (!context->surfaces && !context_create_surfaces (context))
goto cleanup;
......@@ -240,12 +244,22 @@ context_create (GstVaapiContext * context)
surface_id = GST_VAAPI_SURFACE_ID (surface);
g_array_append_val (surfaces, surface_id);
}
g_assert (surfaces->len == context->surfaces->len);
/* vaCreateContext() doesn't really need an array of VASurfaceIDs (see
* https://lists.01.org/pipermail/intel-vaapi-media/2017-July/000052.html and
* https://github.com/intel/libva/issues/251); pass a dummy list of valid
* (non-null) IDs until the signature gets updated. */
if (cip->usage != GST_VAAPI_CONTEXT_USAGE_DECODE) {
surfaces_data = (VASurfaceID *) surfaces->data;
num_surfaces = surfaces->len;
}
GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateContext (GST_VAAPI_DISPLAY_VADISPLAY (display),
context->va_config, cip->width, cip->height, VA_PROGRESSIVE,
(VASurfaceID *) surfaces->data, surfaces->len, &context_id);
surfaces_data, num_surfaces, &context_id);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaCreateContext()"))
goto cleanup;
......@@ -627,6 +641,8 @@ gst_vaapi_context_get_surface_count (GstVaapiContext * context)
{
g_return_val_if_fail (context != NULL, 0);
if (gst_vaapi_video_pool_get_capacity (context->surfaces_pool) == 0)
return G_MAXUINT;
return gst_vaapi_video_pool_get_size (context->surfaces_pool);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment