From fa7ab6a25148e3beeef6977daeb7dd2566b9c448 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Thu, 19 Jul 2018 15:07:43 +0200 Subject: context: Liberate output and capture buffers at ContextDestroy The V4L2 API does not currently provide a way to liberate allocated buffers one by one (which would fit well with DestroySurfaces in VAAPI). Moreover, streaming needs to be off before liberating buffers is allowed. As a result, output an capture buffers can only be liberated when destroying the decoding context, all at once, such as implemented in this patch. Signed-off-by: Paul Kocialkowski --- src/context.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/context.c b/src/context.c index 3c924c8..233bac6 100644 --- a/src/context.c +++ b/src/context.c @@ -196,15 +196,13 @@ VAStatus RequestDestroyContext(VADriverContextP context, VAContextID context_id) { struct request_data *driver_data = context->pDriverData; struct object_context *context_object; + VAStatus status; int rc; context_object = CONTEXT(driver_data, context_id); if (context_object == NULL) return VA_STATUS_ERROR_INVALID_CONTEXT; - object_heap_free(&driver_data->context_heap, - (struct object_base *)context_object); - rc = v4l2_set_stream(driver_data->video_fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, false); if (rc < 0) @@ -215,5 +213,27 @@ VAStatus RequestDestroyContext(VADriverContextP context, VAContextID context_id) if (rc < 0) return VA_STATUS_ERROR_OPERATION_FAILED; + /* Buffers liberation */ + + status = RequestDestroySurfaces(context, context_object->surfaces_ids, + context_object->surfaces_count); + if (status != VA_STATUS_SUCCESS) + return VA_STATUS_ERROR_OPERATION_FAILED; + + free(context_object->surfaces_ids); + + object_heap_free(&driver_data->context_heap, + (struct object_base *)context_object); + + rc = v4l2_request_buffers(driver_data->video_fd, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, 0); + if (rc < 0) + return VA_STATUS_ERROR_OPERATION_FAILED; + + rc = v4l2_request_buffers(driver_data->video_fd, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 0); + if (rc < 0) + return VA_STATUS_ERROR_OPERATION_FAILED; + return VA_STATUS_SUCCESS; } -- cgit v1.2.3