summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>2018-07-20 13:48:51 +0200
committerPaul Kocialkowski <paul.kocialkowski@bootlin.com>2018-07-20 13:48:51 +0200
commitc9327dd55a3dd68f161eae0c5086b05d22abd116 (patch)
treecf4227ab6beaf44b6f2a5fbef7b8b6924b5e4159 /src
parent3b0e7dbf12b6dce863ea4103d2e80c148a420cd2 (diff)
downloadlibva-v4l2-request-c9327dd55a3dd68f161eae0c5086b05d22abd116.tar.gz
libva-v4l2-request-c9327dd55a3dd68f161eae0c5086b05d22abd116.tar.bz2
libva-v4l2-request-c9327dd55a3dd68f161eae0c5086b05d22abd116.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/context.c11
-rw-r--r--src/surface.c11
-rw-r--r--src/v4l2.c5
-rw-r--r--src/v4l2.h2
4 files changed, 20 insertions, 9 deletions
diff --git a/src/context.c b/src/context.c
index 233bac6..2ed199f 100644
--- a/src/context.c
+++ b/src/context.c
@@ -57,6 +57,8 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
VAContextID id;
VAStatus status;
unsigned int pixelformat;
+ unsigned int index_base;
+ unsigned int index;
unsigned int i;
int rc;
@@ -103,7 +105,7 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
rc = v4l2_create_buffers(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
- surfaces_count);
+ surfaces_count, &index_base);
if (rc < 0) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error;
@@ -123,6 +125,8 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
memcpy(ids, surfaces_ids, surfaces_count * sizeof(VASurfaceID));
for (i = 0; i < surfaces_count; i++) {
+ index = index_base + i;
+
surface_object = SURFACE(driver_data, surfaces_ids[i]);
if (surface_object == NULL) {
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,
- V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, i,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, index,
&length, &offset, 1);
if (rc < 0) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
@@ -144,8 +148,7 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
goto error;
}
- surface_object->source_index = i;
- surface_object->destination_index = i;
+ surface_object->source_index = index;
surface_object->source_data = source_data;
surface_object->source_size = length;
}
diff --git a/src/surface.c b/src/surface.c
index f6b9935..e5c7c61 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -58,6 +58,8 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
unsigned int destination_sizes[VIDEO_MAX_PLANES];
unsigned int destination_bytesperlines[VIDEO_MAX_PLANES];
unsigned int destination_planes_count;
+ unsigned int index_base;
+ unsigned int index;
unsigned int i, j;
VASurfaceID id;
bool found;
@@ -93,18 +95,21 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
rc = v4l2_create_buffers(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
- surfaces_count);
+ surfaces_count, &index_base);
if (rc < 0)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
for (i = 0; i < surfaces_count; i++) {
+ index = index_base + i;
+
id = object_heap_allocate(&driver_data->surface_heap);
surface_object = SURFACE(driver_data, id);
if (surface_object == NULL)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
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_offsets,
video_format->v4l2_buffers_count);
@@ -157,7 +162,7 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
surface_object->source_data = NULL;
surface_object->source_size = 0;
- surface_object->destination_index = 0;
+ surface_object->destination_index = index;
surface_object->destination_planes_count =
destination_planes_count;
diff --git a/src/v4l2.c b/src/v4l2.c
index 64635fa..0e6f239 100644
--- a/src/v4l2.c
+++ b/src/v4l2.c
@@ -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,
- unsigned int buffers_count)
+ unsigned int buffers_count, unsigned int *index_base)
{
struct v4l2_create_buffers buffers;
int rc;
@@ -150,6 +150,9 @@ int v4l2_create_buffers(int video_fd, unsigned int type,
return -1;
}
+ if (index_base != NULL)
+ *index_base = buffers.index;
+
return 0;
}
diff --git a/src/v4l2.h b/src/v4l2.h
index 6265ece..52b9604 100644
--- a/src/v4l2.h
+++ b/src/v4l2.h
@@ -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 *sizes, unsigned int *planes_count);
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,
unsigned int *lengths, unsigned int *offsets,
unsigned int buffers_count);