106 lines
2.3 KiB
C++
Executable File
106 lines
2.3 KiB
C++
Executable File
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* UVC gadget rga process
|
|
*
|
|
* Copyright (C) 2022 Rockchip Electronics Co., Ltd.
|
|
*
|
|
* Author: Bin Yang <yangbin@rock-chips.com>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include <fcntl.h>
|
|
#include <pthread.h>
|
|
#include <errno.h>
|
|
#include <linux/videodev2.h>
|
|
#include "im2d_api/im2d.h"
|
|
#include "rga.h"
|
|
#include "uvc-rga.h"
|
|
#include "uvc-log.h"
|
|
#include "tools.h"
|
|
|
|
struct uvc_rga_handle {
|
|
rga_buffer_handle_t rga_handle;
|
|
rga_buffer_t rga_buffer;
|
|
};
|
|
|
|
void *uvc_rga_buffer_create(int fd, struct v4l2_pix_format *fmt)
|
|
{
|
|
struct uvc_rga_handle *uvc_rga = NULL;
|
|
im_handle_param_t param;
|
|
|
|
if (!fd) {
|
|
uvc_warn("uvc rga buffer create fail, fd invalid!");
|
|
return NULL;
|
|
}
|
|
|
|
memset(¶m, 0, sizeof(im_handle_param_t));
|
|
param.width = fmt->width;
|
|
param.height = fmt->height;
|
|
|
|
if (fmt->pixelformat == V4L2_PIX_FMT_NV12) {
|
|
param.format = RK_FORMAT_YCbCr_420_SP;
|
|
} else if (fmt->pixelformat == V4L2_PIX_FMT_YUYV) {
|
|
param.format = RK_FORMAT_YUYV_422;
|
|
} else {
|
|
uvc_err("uvc rga buffer create fail, %c%c%c%c is not support!",
|
|
PIX_FMT_STR(fmt->pixelformat));
|
|
return NULL;
|
|
}
|
|
|
|
uvc_rga = (struct uvc_rga_handle*)malloc(sizeof *uvc_rga);
|
|
if (!uvc_rga)
|
|
return NULL;
|
|
|
|
uvc_rga->rga_handle = importbuffer_fd(fd, ¶m);
|
|
if (uvc_rga->rga_handle < 0) {
|
|
uvc_err("uvc source rga import buffer fd failed!\n");
|
|
goto INIT_ERR;
|
|
}
|
|
|
|
uvc_rga->rga_buffer = wrapbuffer_handle(uvc_rga->rga_handle,
|
|
param.width, param.height, param.format);
|
|
if(uvc_rga->rga_buffer.width == 0) {
|
|
uvc_err("uvc source rga wrapbuffer failed!\n");
|
|
goto INIT_ERR;
|
|
}
|
|
|
|
return (void *)uvc_rga;
|
|
|
|
INIT_ERR:
|
|
if (uvc_rga->rga_handle > 0)
|
|
releasebuffer_handle(uvc_rga->rga_handle);
|
|
|
|
free(uvc_rga);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int uvc_rga_buffer_destroy(void *data)
|
|
{
|
|
struct uvc_rga_handle *uvc_rga = (struct uvc_rga_handle *)data;
|
|
|
|
if (uvc_rga->rga_handle > 0)
|
|
releasebuffer_handle(uvc_rga->rga_handle);
|
|
|
|
if (uvc_rga)
|
|
free(uvc_rga);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int uvc_rga_buffer_process(void *src, struct v4l2_pix_format *src_fmt,
|
|
void *dest, struct v4l2_pix_format *dest_fmt)
|
|
{
|
|
struct uvc_rga_handle *src_rga = (struct uvc_rga_handle *)src;
|
|
struct uvc_rga_handle *dest_rga = (struct uvc_rga_handle *)dest;
|
|
|
|
/* TODO */
|
|
imresize(src_rga->rga_buffer, dest_rga->rga_buffer);
|
|
|
|
return 0;
|
|
}
|