From 9de2ba88b5245089202e36717175fcdcec311056 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Tue, 24 Apr 2018 17:00:50 +0200 Subject: [PATCH] Introduce and use media helpers, updated to the latest media request API Signed-off-by: Paul Kocialkowski --- src/media.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ src/media.h | 33 +++++++++++++++++ src/picture.c | 8 ++--- src/sunxi_cedrus.c | 35 ++++++++++++------ src/sunxi_cedrus.h | 1 + src/surface.c | 13 +++---- 6 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 src/media.c create mode 100644 src/media.h diff --git a/src/media.c b/src/media.c new file mode 100644 index 0000000..bfe4af7 --- /dev/null +++ b/src/media.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2018 Paul Kocialkowski + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include + +#include + +#include "sunxi_cedrus.h" +#include "v4l2.h" + +int media_request_alloc(int media_fd) +{ + int rc; + + rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &request_alloc); + if (rc < 0) { + sunxi_cedrus_msg("Unable to allocate media request: %s\n", strerror(errno)); + return -1; + } + + return request_alloc.fd; +} + +int media_request_reinit(int request_fd) +{ + int rc; + + rc = ioctl(request_fd, MEDIA_REQUEST_IOC_REINIT, NULL); + if (rc < 0) { + sunxi_cedrus_msg("Unable to reinit media request: %s\n", strerror(errno)); + return -1; + } + + return 0; +} + +int media_request_queue(int request_fd) +{ + int rc; + + rc = ioctl(request_fd, MEDIA_REQUEST_IOC_QUEUE, NULL); + if (rc < 0) { + sunxi_cedrus_msg("Unable to queue media request: %s\n", strerror(errno)); + return -1; + } + + return 0; +} + +int media_request_wait_completion(int request_fd) +{ + struct timeval tv = { 0, 300000 }; + fd_set except_fds; + + FD_ZERO(&except_fds); + FD_SET(request_fd, &except_fds); + + rc = select(request_fd + 1, NULL, NULL, &except_fds, &tv); + if (rc == 0) { + sunxi_cedrus_msg("Timeout when waiting for media request\n"); + return -1; + } else if (rc < 0) { + sunxi_cedrus_msg("Unable to select media request: %s\n", strerror(errno)); + return -1; + } + + return 0; +} diff --git a/src/media.h b/src/media.h new file mode 100644 index 0000000..2d0436f --- /dev/null +++ b/src/media.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2018 Paul Kocialkowski + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _MEDIA_H_ +#define _MEDIA_H_ + +int media_request_alloc(int media_fd); +int media_request_reinit(int request_fd); +int media_request_queue(int request_fd); +int media_request_wait_completion(int request_fd); + +#endif diff --git a/src/picture.c b/src/picture.c index 30fc5e6..0a1e1f4 100644 --- a/src/picture.c +++ b/src/picture.c @@ -139,7 +139,6 @@ VAStatus SunxiCedrusEndPicture(VADriverContextP context, (struct sunxi_cedrus_driver_data *) context->pDriverData; struct object_context *context_object; struct object_surface *surface_object; - struct media_request_new media_request; void *control_data; unsigned int control_size; unsigned int control_id; @@ -156,12 +155,11 @@ VAStatus SunxiCedrusEndPicture(VADriverContextP context, request_fd = driver_data->request_fds[surface_object->input_buf_index]; if (request_fd < 0) { - rc = ioctl(driver_data->video_fd, VIDIOC_NEW_REQUEST, &media_request); - if (rc < 0) + request_fd = media_request_alloc(driver_data->media_fd); + if (request_fd < 0) return VA_STATUS_ERROR_OPERATION_FAILED; - driver_data->request_fds[surface_object->input_buf_index] = media_request.fd; - request_fd = media_request.fd; + driver_data->request_fds[surface_object->input_buf_index] = request_fd; } switch (config_object->profile) { diff --git a/src/sunxi_cedrus.c b/src/sunxi_cedrus.c index abc042a..c45b163 100644 --- a/src/sunxi_cedrus.c +++ b/src/sunxi_cedrus.c @@ -71,8 +71,10 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context) struct v4l2_capability capability; VAStatus status; unsigned int i; - int fd = -1; - char *path; + int video_fd = -1; + int media_fd = -1; + char *video_path; + char *media_path; int rc; context->version_major = VA_MAJOR_VERSION; @@ -141,12 +143,12 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context) object_heap_init(&driver_data->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET); object_heap_init(&driver_data->image_heap, sizeof(struct object_image), IMAGE_ID_OFFSET); - path = getenv("LIBVA_CEDRUS_DEV"); - if (path == NULL) - path = "/dev/video0"; + video_path = getenv("LIBVA_CEDRUS_VIDEO_PATH"); + if (video_path == NULL) + video_path = "/dev/video0"; - fd = open(PATH, O_RDWR | O_NONBLOCK); - if (fd < 0) + video_fd = open(video_path, O_RDWR | O_NONBLOCK); + if (video_fd < 0) return VA_STATUS_ERROR_OPERATION_FAILED; rc = ioctl(driver_data->video_fd, VIDIOC_QUERYCAP, &capability); @@ -155,7 +157,16 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context) return VA_STATUS_ERROR_OPERATION_FAILED; } - driver_data->video_fd = fd; + media_path = getenv("LIBVA_CEDRUS_MEDIA_PATH"); + if (media_path == NULL) + media_path = "/dev/media0"; + + media_fd = open(video_path, O_RDWR | O_NONBLOCK); + if (media_fd < 0) + return VA_STATUS_ERROR_OPERATION_FAILED; + + driver_data->video_fd = video_fd; + driver_data->media_fd = media_fd; for (i = 0; i < INPUT_BUFFERS_NB; i++) { driver_data->request_fds[i] = -1; @@ -168,8 +179,11 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context) error: status = VA_STATUS_ERROR_OPERATION_FAILED; - if (fd >= 0) - close(fd); + if (video_fd >= 0) + close(video_fd); + + if (media_fd >= 0) + close(media_fd); complete: return status; @@ -192,6 +206,7 @@ VAStatus SunxiCedrusTerminate(VADriverContextP context) close(driver_data->request_fds[i]); close(driver_data->video_fd); + close(driver_data->media_fd); /* Cleanup leftover buffers. */ diff --git a/src/sunxi_cedrus.h b/src/sunxi_cedrus.h index 15c1500..d31f74a 100644 --- a/src/sunxi_cedrus.h +++ b/src/sunxi_cedrus.h @@ -51,6 +51,7 @@ struct sunxi_cedrus_driver_data { char *chroma_bufs[VIDEO_MAX_FRAME]; unsigned int num_dst_bufs; int video_fd; + int media_fd; int request_fds[INPUT_BUFFERS_NB]; int slice_offset[INPUT_BUFFERS_NB]; }; diff --git a/src/surface.c b/src/surface.c index c6e1014..8e10111 100644 --- a/src/surface.c +++ b/src/surface.c @@ -138,18 +138,15 @@ VAStatus SunxiCedrusSyncSurface(VADriverContextP context, if (request_fd < 0) return VA_STATUS_ERROR_UNKNOWN; - rc = ioctl(request_fd, MEDIA_REQUEST_IOC_SUBMIT, NULL); + rc = media_request_queue(request_fd); if (rc < 0) return VA_STATUS_ERROR_OPERATION_FAILED; - FD_ZERO(&read_fds); - FD_SET(request_fd, &read_fds); + rc = media_request_wait_completion(request_fd); + if (rc < 0) + return VA_STATUS_ERROR_OPERATION_FAILED; - rc = select(request_fd + 1, &read_fds, NULL, NULL, NULL); - if(rc <= 0) - return VA_STATUS_ERROR_UNKNOWN; - - rc = ioctl(request_fd, MEDIA_REQUEST_IOC_REINIT, NULL); + rc = media_request_reinit(request_fd); if (rc < 0) return VA_STATUS_ERROR_OPERATION_FAILED;