Introduce and use media helpers, updated to the latest media request API
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Paul Kocialkowski <paul.kocialkowski@bootlin.com>
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
|
||||||
|
#include <linux/media.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Paul Kocialkowski <paul.kocialkowski@bootlin.com>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
+3
-5
@@ -139,7 +139,6 @@ VAStatus SunxiCedrusEndPicture(VADriverContextP context,
|
|||||||
(struct sunxi_cedrus_driver_data *) context->pDriverData;
|
(struct sunxi_cedrus_driver_data *) context->pDriverData;
|
||||||
struct object_context *context_object;
|
struct object_context *context_object;
|
||||||
struct object_surface *surface_object;
|
struct object_surface *surface_object;
|
||||||
struct media_request_new media_request;
|
|
||||||
void *control_data;
|
void *control_data;
|
||||||
unsigned int control_size;
|
unsigned int control_size;
|
||||||
unsigned int control_id;
|
unsigned int control_id;
|
||||||
@@ -156,12 +155,11 @@ VAStatus SunxiCedrusEndPicture(VADriverContextP context,
|
|||||||
|
|
||||||
request_fd = driver_data->request_fds[surface_object->input_buf_index];
|
request_fd = driver_data->request_fds[surface_object->input_buf_index];
|
||||||
if (request_fd < 0) {
|
if (request_fd < 0) {
|
||||||
rc = ioctl(driver_data->video_fd, VIDIOC_NEW_REQUEST, &media_request);
|
request_fd = media_request_alloc(driver_data->media_fd);
|
||||||
if (rc < 0)
|
if (request_fd < 0)
|
||||||
return VA_STATUS_ERROR_OPERATION_FAILED;
|
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
driver_data->request_fds[surface_object->input_buf_index] = media_request.fd;
|
driver_data->request_fds[surface_object->input_buf_index] = request_fd;
|
||||||
request_fd = media_request.fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (config_object->profile) {
|
switch (config_object->profile) {
|
||||||
|
|||||||
+25
-10
@@ -71,8 +71,10 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context)
|
|||||||
struct v4l2_capability capability;
|
struct v4l2_capability capability;
|
||||||
VAStatus status;
|
VAStatus status;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int fd = -1;
|
int video_fd = -1;
|
||||||
char *path;
|
int media_fd = -1;
|
||||||
|
char *video_path;
|
||||||
|
char *media_path;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
context->version_major = VA_MAJOR_VERSION;
|
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->buffer_heap, sizeof(struct object_buffer), BUFFER_ID_OFFSET);
|
||||||
object_heap_init(&driver_data->image_heap, sizeof(struct object_image), IMAGE_ID_OFFSET);
|
object_heap_init(&driver_data->image_heap, sizeof(struct object_image), IMAGE_ID_OFFSET);
|
||||||
|
|
||||||
path = getenv("LIBVA_CEDRUS_DEV");
|
video_path = getenv("LIBVA_CEDRUS_VIDEO_PATH");
|
||||||
if (path == NULL)
|
if (video_path == NULL)
|
||||||
path = "/dev/video0";
|
video_path = "/dev/video0";
|
||||||
|
|
||||||
fd = open(PATH, O_RDWR | O_NONBLOCK);
|
video_fd = open(video_path, O_RDWR | O_NONBLOCK);
|
||||||
if (fd < 0)
|
if (video_fd < 0)
|
||||||
return VA_STATUS_ERROR_OPERATION_FAILED;
|
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
rc = ioctl(driver_data->video_fd, VIDIOC_QUERYCAP, &capability);
|
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;
|
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++) {
|
for (i = 0; i < INPUT_BUFFERS_NB; i++) {
|
||||||
driver_data->request_fds[i] = -1;
|
driver_data->request_fds[i] = -1;
|
||||||
@@ -168,8 +179,11 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context)
|
|||||||
error:
|
error:
|
||||||
status = VA_STATUS_ERROR_OPERATION_FAILED;
|
status = VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
if (fd >= 0)
|
if (video_fd >= 0)
|
||||||
close(fd);
|
close(video_fd);
|
||||||
|
|
||||||
|
if (media_fd >= 0)
|
||||||
|
close(media_fd);
|
||||||
|
|
||||||
complete:
|
complete:
|
||||||
return status;
|
return status;
|
||||||
@@ -192,6 +206,7 @@ VAStatus SunxiCedrusTerminate(VADriverContextP context)
|
|||||||
close(driver_data->request_fds[i]);
|
close(driver_data->request_fds[i]);
|
||||||
|
|
||||||
close(driver_data->video_fd);
|
close(driver_data->video_fd);
|
||||||
|
close(driver_data->media_fd);
|
||||||
|
|
||||||
/* Cleanup leftover buffers. */
|
/* Cleanup leftover buffers. */
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ struct sunxi_cedrus_driver_data {
|
|||||||
char *chroma_bufs[VIDEO_MAX_FRAME];
|
char *chroma_bufs[VIDEO_MAX_FRAME];
|
||||||
unsigned int num_dst_bufs;
|
unsigned int num_dst_bufs;
|
||||||
int video_fd;
|
int video_fd;
|
||||||
|
int media_fd;
|
||||||
int request_fds[INPUT_BUFFERS_NB];
|
int request_fds[INPUT_BUFFERS_NB];
|
||||||
int slice_offset[INPUT_BUFFERS_NB];
|
int slice_offset[INPUT_BUFFERS_NB];
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-8
@@ -138,18 +138,15 @@ VAStatus SunxiCedrusSyncSurface(VADriverContextP context,
|
|||||||
if (request_fd < 0)
|
if (request_fd < 0)
|
||||||
return VA_STATUS_ERROR_UNKNOWN;
|
return VA_STATUS_ERROR_UNKNOWN;
|
||||||
|
|
||||||
rc = ioctl(request_fd, MEDIA_REQUEST_IOC_SUBMIT, NULL);
|
rc = media_request_queue(request_fd);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return VA_STATUS_ERROR_OPERATION_FAILED;
|
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
FD_ZERO(&read_fds);
|
rc = media_request_wait_completion(request_fd);
|
||||||
FD_SET(request_fd, &read_fds);
|
if (rc < 0)
|
||||||
|
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
rc = select(request_fd + 1, &read_fds, NULL, NULL, NULL);
|
rc = media_request_reinit(request_fd);
|
||||||
if(rc <= 0)
|
|
||||||
return VA_STATUS_ERROR_UNKNOWN;
|
|
||||||
|
|
||||||
rc = ioctl(request_fd, MEDIA_REQUEST_IOC_REINIT, NULL);
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return VA_STATUS_ERROR_OPERATION_FAILED;
|
return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user