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);