Grab the base index when allocating buffers and mapping them

Because there might be more than a single call to CreateSurfaces,
we cannot assume that the index relative to the number of surfaces
requested in a single call matches the v4l2 index.

Grab the base index (as returned by the kernel) when allocating
buffers and use it for memory mapping and addressing them in v4l2.
This avoids memory-mapping the first (index 0) buffer multiple times
in that scenario instead of the n-th allocated buffer (in the n-th
call in the sequence).

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
This commit is contained in:
Paul Kocialkowski
2018-07-20 13:48:51 +02:00
parent 3b0e7dbf12
commit c9327dd55a
4 changed files with 20 additions and 9 deletions
+7 -4
View File
@@ -57,6 +57,8 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
VAContextID id; VAContextID id;
VAStatus status; VAStatus status;
unsigned int pixelformat; unsigned int pixelformat;
unsigned int index_base;
unsigned int index;
unsigned int i; unsigned int i;
int rc; int rc;
@@ -103,7 +105,7 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
rc = v4l2_create_buffers(driver_data->video_fd, rc = v4l2_create_buffers(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
surfaces_count); surfaces_count, &index_base);
if (rc < 0) { if (rc < 0) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED; status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error; goto error;
@@ -123,6 +125,8 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
memcpy(ids, surfaces_ids, surfaces_count * sizeof(VASurfaceID)); memcpy(ids, surfaces_ids, surfaces_count * sizeof(VASurfaceID));
for (i = 0; i < surfaces_count; i++) { for (i = 0; i < surfaces_count; i++) {
index = index_base + i;
surface_object = SURFACE(driver_data, surfaces_ids[i]); surface_object = SURFACE(driver_data, surfaces_ids[i]);
if (surface_object == NULL) { if (surface_object == NULL) {
status = VA_STATUS_ERROR_INVALID_SURFACE; status = VA_STATUS_ERROR_INVALID_SURFACE;
@@ -130,7 +134,7 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
} }
rc = v4l2_query_buffer(driver_data->video_fd, rc = v4l2_query_buffer(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, i, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, index,
&length, &offset, 1); &length, &offset, 1);
if (rc < 0) { if (rc < 0) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED; status = VA_STATUS_ERROR_ALLOCATION_FAILED;
@@ -144,8 +148,7 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
goto error; goto error;
} }
surface_object->source_index = i; surface_object->source_index = index;
surface_object->destination_index = i;
surface_object->source_data = source_data; surface_object->source_data = source_data;
surface_object->source_size = length; surface_object->source_size = length;
} }
+8 -3
View File
@@ -58,6 +58,8 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
unsigned int destination_sizes[VIDEO_MAX_PLANES]; unsigned int destination_sizes[VIDEO_MAX_PLANES];
unsigned int destination_bytesperlines[VIDEO_MAX_PLANES]; unsigned int destination_bytesperlines[VIDEO_MAX_PLANES];
unsigned int destination_planes_count; unsigned int destination_planes_count;
unsigned int index_base;
unsigned int index;
unsigned int i, j; unsigned int i, j;
VASurfaceID id; VASurfaceID id;
bool found; bool found;
@@ -93,18 +95,21 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
rc = v4l2_create_buffers(driver_data->video_fd, rc = v4l2_create_buffers(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
surfaces_count); surfaces_count, &index_base);
if (rc < 0) if (rc < 0)
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
for (i = 0; i < surfaces_count; i++) { for (i = 0; i < surfaces_count; i++) {
index = index_base + i;
id = object_heap_allocate(&driver_data->surface_heap); id = object_heap_allocate(&driver_data->surface_heap);
surface_object = SURFACE(driver_data, id); surface_object = SURFACE(driver_data, id);
if (surface_object == NULL) if (surface_object == NULL)
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
rc = v4l2_query_buffer(driver_data->video_fd, rc = v4l2_query_buffer(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, i, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
index,
surface_object->destination_map_lengths, surface_object->destination_map_lengths,
surface_object->destination_map_offsets, surface_object->destination_map_offsets,
video_format->v4l2_buffers_count); video_format->v4l2_buffers_count);
@@ -157,7 +162,7 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
surface_object->source_data = NULL; surface_object->source_data = NULL;
surface_object->source_size = 0; surface_object->source_size = 0;
surface_object->destination_index = 0; surface_object->destination_index = index;
surface_object->destination_planes_count = surface_object->destination_planes_count =
destination_planes_count; destination_planes_count;
+4 -1
View File
@@ -126,7 +126,7 @@ int v4l2_get_format(int video_fd, unsigned int type, unsigned int *width,
} }
int v4l2_create_buffers(int video_fd, unsigned int type, int v4l2_create_buffers(int video_fd, unsigned int type,
unsigned int buffers_count) unsigned int buffers_count, unsigned int *index_base)
{ {
struct v4l2_create_buffers buffers; struct v4l2_create_buffers buffers;
int rc; int rc;
@@ -150,6 +150,9 @@ int v4l2_create_buffers(int video_fd, unsigned int type,
return -1; return -1;
} }
if (index_base != NULL)
*index_base = buffers.index;
return 0; return 0;
} }
+1 -1
View File
@@ -37,7 +37,7 @@ int v4l2_get_format(int video_fd, unsigned int type, unsigned int *width,
unsigned int *height, unsigned int *bytesperline, unsigned int *height, unsigned int *bytesperline,
unsigned int *sizes, unsigned int *planes_count); unsigned int *sizes, unsigned int *planes_count);
int v4l2_create_buffers(int video_fd, unsigned int type, int v4l2_create_buffers(int video_fd, unsigned int type,
unsigned int buffers_count); unsigned int buffers_count, unsigned int *index_base);
int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index, int v4l2_query_buffer(int video_fd, unsigned int type, unsigned int index,
unsigned int *lengths, unsigned int *offsets, unsigned int *lengths, unsigned int *offsets,
unsigned int buffers_count); unsigned int buffers_count);