From 25a8ac4d7eaee3d69361721db33a50b5c3119194 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Fri, 7 Sep 2018 12:46:52 +0200 Subject: Register video format directly instead of tiled indicator Signed-off-by: Paul Kocialkowski --- src/buffer.c | 4 ++-- src/image.c | 3 ++- src/request.h | 2 +- src/surface.c | 19 ++++++++++++------- src/video.c | 18 +++++++++--------- src/video.h | 3 ++- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index aacf98f..641e286 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -27,6 +27,7 @@ #include "context.h" #include "request.h" #include "surface.h" +#include "video.h" #include #include @@ -37,7 +38,6 @@ #include #include - #include #include "utils.h" @@ -201,7 +201,7 @@ VAStatus RequestAcquireBufferHandle(VADriverContextP context, int rc; if (buffer_info->mem_type != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME || - driver_data->tiled_format) + !video_format_is_linear(driver_data->video_format)) return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE; buffer_object = BUFFER(driver_data, buffer_id); diff --git a/src/image.c b/src/image.c index 6223c0a..1beac88 100644 --- a/src/image.c +++ b/src/image.c @@ -27,6 +27,7 @@ #include "buffer.h" #include "request.h" #include "surface.h" +#include "video.h" #include #include @@ -148,7 +149,7 @@ VAStatus RequestDeriveImage(VADriverContextP context, VASurfaceID surface_id, return VA_STATUS_ERROR_INVALID_BUFFER; for (i = 0; i < surface_object->destination_planes_count; i++) { - if (driver_data->tiled_format) + if (!video_format_is_linear(driver_data->video_format)) tiled_to_planar(surface_object->destination_data[i], buffer_object->data + image->offsets[i], image->pitches[i], image->width, diff --git a/src/request.h b/src/request.h index 2e905da..37c7d2f 100644 --- a/src/request.h +++ b/src/request.h @@ -52,7 +52,7 @@ struct request_data { int video_fd; int media_fd; - bool tiled_format; + struct video_format *video_format; }; VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context); diff --git a/src/surface.c b/src/surface.c index e5c7c61..a400ec6 100644 --- a/src/surface.c +++ b/src/surface.c @@ -37,7 +37,7 @@ #include #include - +#include #include #include "media.h" @@ -54,7 +54,7 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format, { struct request_data *driver_data = context->pDriverData; struct object_surface *surface_object; - struct video_format *video_format; + struct video_format *video_format = NULL; unsigned int destination_sizes[VIDEO_MAX_PLANES]; unsigned int destination_bytesperlines[VIDEO_MAX_PLANES]; unsigned int destination_planes_count; @@ -68,18 +68,23 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format, if (format != VA_RT_FORMAT_YUV420) return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT; - driver_data->tiled_format = true; + found = v4l2_find_format(driver_data->video_fd, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, + V4L2_PIX_FMT_SUNXI_TILED_NV12); + if (found) + video_format = video_format_find(V4L2_PIX_FMT_SUNXI_TILED_NV12); found = v4l2_find_format(driver_data->video_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, V4L2_PIX_FMT_NV12); if (found) - driver_data->tiled_format = false; + video_format = video_format_find(V4L2_PIX_FMT_NV12); - video_format = video_format_find(driver_data->tiled_format); if (video_format == NULL) return VA_STATUS_ERROR_OPERATION_FAILED; + driver_data->video_format = video_format; + rc = v4l2_set_format(driver_data->video_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, video_format->v4l2_format, width, height); @@ -356,7 +361,7 @@ VAStatus RequestQuerySurfaceAttributes(VADriverContextP context, * that are required for supporting the tiled output format. */ - if (!driver_data->tiled_format) + if (video_format_is_linear(driver_data->video_format)) memory_types |= VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME; attributes_list[i].value.value.i = memory_types; @@ -454,7 +459,7 @@ VAStatus RequestExportSurfaceHandle(VADriverContextP context, planes_count = surface_object->destination_planes_count; - video_format = video_format_find(driver_data->tiled_format); + video_format = driver_data->video_format; if (video_format == NULL) { status = VA_STATUS_ERROR_OPERATION_FAILED; goto error; diff --git a/src/video.c b/src/video.c index 619fcf1..116e025 100644 --- a/src/video.c +++ b/src/video.c @@ -34,11 +34,6 @@ #include "utils.h" #include "video.h" -static inline unsigned int video_v4l2_format(bool tiled_format) -{ - return tiled_format ? V4L2_PIX_FMT_SUNXI_TILED_NV12 : V4L2_PIX_FMT_NV12; -} - static struct video_format formats[] = { { .description = "NV12 YUV", @@ -62,16 +57,21 @@ static struct video_format formats[] = { static unsigned int formats_count = sizeof(formats) / sizeof(formats[0]); -struct video_format *video_format_find(bool tiled_format) +struct video_format *video_format_find(unsigned int pixelformat) { - unsigned int pixelformat; unsigned int i; - pixelformat = video_v4l2_format(tiled_format); - for (i = 0; i < formats_count; i++) if (formats[i].v4l2_format == pixelformat) return &formats[i]; return NULL; } + +bool video_format_is_linear(struct video_format *format) +{ + if (format == NULL) + return true; + + return format->drm_modifier == DRM_FORMAT_MOD_NONE; +} diff --git a/src/video.h b/src/video.h index e1cdcb8..124c46f 100644 --- a/src/video.h +++ b/src/video.h @@ -37,6 +37,7 @@ struct video_format { unsigned int bpp; }; -struct video_format *video_format_find(bool tiled_format); +struct video_format *video_format_find(unsigned int pixelformat); +bool video_format_is_linear(struct video_format *format); #endif -- cgit v1.2.3