mirror of
https://github.com/nyanmisaka/mpp.git
synced 2026-01-24 05:10:39 +01:00
chore[vproc]: Remove rga support
Use librga to run rga hardware. Official librga repo: https://github.com/airockchip/librga Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: Icbc8a51a43adf551ed69f1654b0e8e409ac1d34b
This commit is contained in:
parent
e8e44aa0bf
commit
b8c821256d
11 changed files with 3 additions and 1026 deletions
|
|
@ -12,13 +12,6 @@ if( ENABLE_VPROC )
|
|||
add_definitions(-DHAVE_VPROC_IEP2)
|
||||
endif()
|
||||
|
||||
option(ENABLE_VPROC_RGA "Enable rga processor" ON)
|
||||
if( ENABLE_VPROC_RGA )
|
||||
set(HAVE_VPROC_RGA true)
|
||||
set(VPROC_RGA vproc_rga)
|
||||
add_definitions(-DHAVE_VPROC_RGA)
|
||||
endif()
|
||||
|
||||
option(ENABLE_VPROC_VDPP "Enable video display post processor" OFF)
|
||||
if( ENABLE_VPROC_VDPP )
|
||||
set(HAVE_VPROC_VDPP true)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@
|
|||
|
||||
add_library(mpp_vproc STATIC mpp_dec_vproc.c mpp_vproc_dev.c)
|
||||
|
||||
target_link_libraries(mpp_vproc ${VPROC_RGA} ${VPROC_IEP} ${VPROC_IEP2} ${VPROC_VDPP} mpp_base)
|
||||
|
||||
if( HAVE_VPROC_RGA )
|
||||
add_subdirectory(rga)
|
||||
endif()
|
||||
target_link_libraries(mpp_vproc ${VPROC_IEP} ${VPROC_IEP2} ${VPROC_VDPP} mpp_base)
|
||||
|
||||
if( HAVE_VPROC_IEP )
|
||||
add_subdirectory(iep)
|
||||
|
|
@ -22,4 +18,4 @@ endif()
|
|||
|
||||
if( HAVE_VPROC_VDPP )
|
||||
add_subdirectory(vdpp)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Rockchip Electronics Co. LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RGA_API_H
|
||||
#define RGA_API_H
|
||||
|
||||
#include "rk_type.h"
|
||||
#include "mpp_err.h"
|
||||
#include "mpp_frame.h"
|
||||
|
||||
/*
|
||||
* NOTE: Normal rga usage should consider address align issue.
|
||||
* But memory in mpp is always aligned. So we do not tak align issue into
|
||||
* consideration.
|
||||
*/
|
||||
typedef enum RgaCmd_e {
|
||||
RGA_CMD_INIT, // reset msg to all zero
|
||||
RGA_CMD_SET_SRC, // config source image info
|
||||
RGA_CMD_SET_DST, // config destination image info
|
||||
|
||||
RGA_CMD_SET_SCALE_CFG = 0x0100, // config copy parameter
|
||||
|
||||
RGA_CMD_SET_COLOR_CONVERT = 0x0200, // config color convert parameter
|
||||
|
||||
RGA_CMD_SET_ROTATION = 0x0300, // config rotation parameter
|
||||
|
||||
// hardware trigger command
|
||||
RGA_CMD_RUN_SYNC = 0x1000, // start sync mode process
|
||||
RGA_CMD_RUN_ASYNC, // start async mode process
|
||||
} RgaCmd;
|
||||
|
||||
typedef void* RgaCtx;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MPP_RET rga_init(RgaCtx *ctx);
|
||||
MPP_RET rga_deinit(RgaCtx ctx);
|
||||
|
||||
MPP_RET rga_control(RgaCtx ctx, RgaCmd cmd, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RGA_API_H */
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
# vim: syntax=cmake
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# add vidoe process IEP (Image Enhancement Processor) implement
|
||||
# ----------------------------------------------------------------------------
|
||||
add_library(vproc_rga STATIC rga.c)
|
||||
set_target_properties(vproc_rga PROPERTIES FOLDER "mpp/vproc/rga")
|
||||
target_link_libraries(vproc_rga mpp_base)
|
||||
|
||||
add_subdirectory(test)
|
||||
|
|
@ -1,398 +0,0 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
|
||||
/*
|
||||
* Copyright (c) 2015 Rockchip Electronics Co., Ltd.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mpp_mem.h"
|
||||
#include "mpp_debug.h"
|
||||
#include "mpp_common.h"
|
||||
|
||||
#include "rga.h"
|
||||
#include "rga_api.h"
|
||||
|
||||
static RK_U32 rga_debug = 0;
|
||||
|
||||
#define RGB_DBG_FUNCTION (0x00000001)
|
||||
#define RGB_DBG_COPY (0x00000002)
|
||||
#define RGB_DBG_DUP_FIELD (0x00000004)
|
||||
|
||||
#define rga_dbg(flag, fmt, ...) mpp_dbg(rga_debug, flag, fmt, ## __VA_ARGS__)
|
||||
#define rga_dbg_func(fmt, ...) mpp_dbg_f(rga_debug, RGB_DBG_FUNCTION, fmt, ## __VA_ARGS__)
|
||||
#define rga_dbg_copy(fmt, ...) mpp_dbg(rga_debug, RGB_DBG_COPY, fmt, ## __VA_ARGS__)
|
||||
#define rga_dbg_dup(fmt, ...) mpp_dbg(rga_debug, RGB_DBG_COPY, fmt, ## __VA_ARGS__)
|
||||
|
||||
#define DEFAULT_RGA_DEV "/dev/rga"
|
||||
|
||||
typedef struct RgaCtxImpl_t {
|
||||
RK_S32 rga_fd;
|
||||
|
||||
// context holds only one request structure and serial process all input
|
||||
RgaReq request;
|
||||
} RgaCtxImpl;
|
||||
|
||||
static int is_yuv_format(int fmt)
|
||||
{
|
||||
if (fmt >= RGA_FMT_YCbCr_422_SP && fmt <= RGA_FMT_YCrCb_420_P) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_rgb_format(int fmt)
|
||||
{
|
||||
if (fmt >= RGA_FMT_RGBA_8888 && fmt <= RGA_FMT_BGR_888) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RgaFormat rga_fmt_map(MppFrameFormat fmt)
|
||||
{
|
||||
RgaFormat ret;
|
||||
|
||||
switch (fmt) {
|
||||
case MPP_FMT_YUV420P:
|
||||
ret = RGA_FMT_YCbCr_420_P;
|
||||
break;
|
||||
case MPP_FMT_YUV420SP:
|
||||
ret = RGA_FMT_YCbCr_420_SP;
|
||||
break;
|
||||
case MPP_FMT_YUV422P:
|
||||
ret = RGA_FMT_YCbCr_422_P;
|
||||
break;
|
||||
case MPP_FMT_YUV422SP:
|
||||
ret = RGA_FMT_YCrCb_422_SP;
|
||||
break;
|
||||
case MPP_FMT_RGB565:
|
||||
ret = RGA_FMT_RGB_565;
|
||||
break;
|
||||
case MPP_FMT_RGB888:
|
||||
ret = RGA_FMT_RGB_888;
|
||||
break;
|
||||
case MPP_FMT_ARGB8888:
|
||||
ret = RGA_FMT_RGBA_8888;
|
||||
break;
|
||||
default:
|
||||
ret = RGA_FMT_BUTT;
|
||||
mpp_err("unsupport mpp fmt %d found\n", fmt);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
MPP_RET rga_init(RgaCtx *ctx)
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
RgaCtxImpl *impl = NULL;
|
||||
|
||||
rga_dbg_func("in\n");
|
||||
|
||||
*ctx = NULL;
|
||||
|
||||
impl = mpp_malloc(RgaCtxImpl, 1);
|
||||
if (!impl) {
|
||||
mpp_err_f("malloc context failed\n");
|
||||
ret = MPP_ERR_NULL_PTR;
|
||||
goto END;
|
||||
}
|
||||
|
||||
impl->rga_fd = open(DEFAULT_RGA_DEV, O_RDWR | O_CLOEXEC, 0);
|
||||
if (impl->rga_fd < 0) {
|
||||
mpp_err_f("open device failed\n");
|
||||
mpp_free(impl);
|
||||
impl = NULL;
|
||||
ret = MPP_ERR_OPEN_FILE;
|
||||
goto END;
|
||||
}
|
||||
|
||||
END:
|
||||
*ctx = impl;
|
||||
rga_dbg_func("out\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
MPP_RET rga_deinit(RgaCtx ctx)
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
RgaCtxImpl *impl = NULL;
|
||||
|
||||
rga_dbg_func("in\n");
|
||||
|
||||
impl = (RgaCtxImpl *)ctx;
|
||||
if (!impl) {
|
||||
mpp_err_f("invalid input");
|
||||
ret = MPP_ERR_NULL_PTR;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (impl->rga_fd >= 0) {
|
||||
close(impl->rga_fd);
|
||||
impl->rga_fd = -1;
|
||||
}
|
||||
|
||||
mpp_free(impl);
|
||||
END:
|
||||
rga_dbg_func("out\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
static MPP_RET rga_ioctl(RgaCtxImpl *impl)
|
||||
{
|
||||
int io_ret = ioctl(impl->rga_fd, RGA_BLIT_SYNC, &impl->request);
|
||||
if (io_ret) {
|
||||
mpp_err("rga ioctl failed errno:%d %s", errno, strerror(errno));
|
||||
return MPP_NOK;
|
||||
}
|
||||
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
static MPP_RET config_rga_image(RgaImg *img, MppFrame frame)
|
||||
{
|
||||
RgaFormat fmt = rga_fmt_map(mpp_frame_get_fmt(frame));
|
||||
MppBuffer buf = mpp_frame_get_buffer(frame);
|
||||
RK_U32 width = mpp_frame_get_width(frame);
|
||||
RK_U32 height = mpp_frame_get_height(frame);
|
||||
RK_U32 h_str = mpp_frame_get_hor_stride(frame);
|
||||
RK_U32 v_str = mpp_frame_get_ver_stride(frame);
|
||||
RK_S32 fd = mpp_buffer_get_fd(buf);
|
||||
|
||||
if (fmt >= RGA_FMT_BUTT) {
|
||||
mpp_err("invalid input format for rga process %d\n", fmt);
|
||||
return MPP_NOK;
|
||||
}
|
||||
|
||||
memset(img, 0, sizeof(RgaImg));
|
||||
img->yrgb_addr = fd;
|
||||
img->format = (RK_U32)fmt;
|
||||
img->act_w = width;
|
||||
img->act_h = height;
|
||||
img->vir_w = h_str;
|
||||
img->vir_h = v_str;
|
||||
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
static MPP_RET config_rga_yuv2rgb_mode(RgaCtx ctx)
|
||||
{
|
||||
RgaCtxImpl *impl = (RgaCtxImpl *)ctx;
|
||||
RgaReq *request = &impl->request;
|
||||
|
||||
/*
|
||||
* yuv2rgb_mode only set when translate yuv to rgb, or rga to yuv.
|
||||
* If format of input and output are both yuv or rga, set yuv2rgb_mode to 0.
|
||||
*/
|
||||
int src_format = request->src.format;
|
||||
int dst_format = request->dst.format;
|
||||
|
||||
request->yuv2rgb_mode = 0;
|
||||
if (is_yuv_format(src_format) && is_rgb_format(dst_format)) {
|
||||
/* Special config for yuv to rgb */
|
||||
request->yuv2rgb_mode |= 0x1 << 0;
|
||||
} else if (is_rgb_format(src_format) && is_yuv_format(dst_format)) {
|
||||
/* Special config for rgb to yuv */
|
||||
request->yuv2rgb_mode = (2 << 4);
|
||||
}
|
||||
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
MPP_RET rga_control(RgaCtx ctx, RgaCmd cmd, void *param)
|
||||
{
|
||||
if (NULL == ctx) {
|
||||
mpp_err_f("invalid NULL input\n");
|
||||
return MPP_ERR_NULL_PTR;
|
||||
}
|
||||
|
||||
rga_dbg_func("in\n");
|
||||
|
||||
MPP_RET ret = MPP_OK;
|
||||
RgaCtxImpl *impl = (RgaCtxImpl *)ctx;
|
||||
RgaReq *request = &impl->request;
|
||||
|
||||
switch (cmd) {
|
||||
case RGA_CMD_INIT : {
|
||||
memset(request, 0, sizeof(*request));
|
||||
request->mmu_info.mmu_en = 1;
|
||||
request->mmu_info.mmu_flag = 1;
|
||||
request->mmu_info.mmu_flag = ((2 & 0x3) << 4) | 1;
|
||||
request->mmu_info.mmu_flag |= (1 << 31) | (1 << 10) | (1 << 8);
|
||||
} break;
|
||||
case RGA_CMD_SET_SRC : {
|
||||
if (NULL == param) {
|
||||
mpp_err("invalid NULL param for setup source\n");
|
||||
ret = MPP_NOK;
|
||||
break;
|
||||
}
|
||||
|
||||
MppFrame *src = (MppFrame *)param;
|
||||
ret = config_rga_image(&request->src, src);
|
||||
} break;
|
||||
case RGA_CMD_SET_DST : {
|
||||
if (NULL == param) {
|
||||
mpp_err("invalid NULL param for setup destination\n");
|
||||
ret = MPP_NOK;
|
||||
break;
|
||||
}
|
||||
|
||||
MppFrame *dst = (MppFrame *)param;
|
||||
ret = config_rga_image(&request->dst, dst);
|
||||
// When config dst setup default clip
|
||||
RK_U32 width = mpp_frame_get_width(dst);
|
||||
RK_U32 height = mpp_frame_get_height(dst);
|
||||
request->clip.xmin = 0;
|
||||
request->clip.xmax = width - 1;
|
||||
request->clip.ymin = 0;
|
||||
request->clip.ymax = height - 1;
|
||||
} break;
|
||||
case RGA_CMD_RUN_SYNC : {
|
||||
config_rga_yuv2rgb_mode(ctx);
|
||||
ret = rga_ioctl(impl);
|
||||
} break;
|
||||
default : {
|
||||
mpp_err("invalid command %d\n", cmd);
|
||||
ret = MPP_NOK;
|
||||
} break;
|
||||
}
|
||||
|
||||
rga_dbg_func("out\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// sample for copy function
|
||||
MPP_RET rga_copy(RgaCtx ctx, MppFrame src, MppFrame dst)
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
RgaCtxImpl *impl = (RgaCtxImpl *)ctx;
|
||||
MppBuffer src_buf = mpp_frame_get_buffer(src);
|
||||
MppBuffer dst_buf = mpp_frame_get_buffer(dst);
|
||||
RK_U32 src_w = mpp_frame_get_width(src);
|
||||
RK_U32 src_h = mpp_frame_get_height(src);
|
||||
RK_U32 dst_w = mpp_frame_get_width(dst);
|
||||
RK_U32 dst_h = mpp_frame_get_height(dst);
|
||||
RK_S32 src_fd = mpp_buffer_get_fd(src_buf);
|
||||
RK_S32 dst_fd = mpp_buffer_get_fd(dst_buf);
|
||||
RgaReq *request = &impl->request;
|
||||
|
||||
RgaFormat src_fmt = rga_fmt_map(mpp_frame_get_fmt(src));
|
||||
RgaFormat dst_fmt = rga_fmt_map(mpp_frame_get_fmt(dst));
|
||||
|
||||
rga_dbg_func("in\n");
|
||||
|
||||
if (src_fmt >= RGA_FMT_BUTT || dst_fmt >= RGA_FMT_BUTT) {
|
||||
mpp_err("invalid input format for rga process src %d dst %d\n",
|
||||
src_fmt, dst_fmt);
|
||||
ret = MPP_NOK;
|
||||
goto END;
|
||||
}
|
||||
|
||||
mpp_assert(src_w > 0 && src_h > 0);
|
||||
|
||||
if (dst_w == 0 || dst_h == 0) {
|
||||
dst_w = src_w;
|
||||
dst_h = src_h;
|
||||
}
|
||||
|
||||
rga_dbg_copy("[fd:w:h:fmt] src - %d:%d:%d:%d dst - %d:%d:%d:%d\n",
|
||||
src_fd, src_w, src_h, src_fmt,
|
||||
dst_fd, dst_w, dst_h, dst_fmt);
|
||||
|
||||
memset(request, 0, sizeof(*request));
|
||||
request->src.yrgb_addr = src_fd;
|
||||
request->src.format = (RK_U32)src_fmt;
|
||||
request->src.vir_w = mpp_frame_get_hor_stride(src);
|
||||
request->src.vir_h = mpp_frame_get_ver_stride(src);
|
||||
request->src.act_w = src_w;
|
||||
request->src.act_h = src_h;
|
||||
|
||||
request->dst.yrgb_addr = dst_fd;
|
||||
request->dst.vir_w = dst_w;
|
||||
request->dst.vir_h = dst_h;
|
||||
request->dst.format = (RK_U32)dst_fmt;
|
||||
request->clip.xmin = 0;
|
||||
request->clip.xmax = dst_w - 1;
|
||||
request->clip.ymin = 0;
|
||||
request->clip.ymax = dst_h - 1;
|
||||
request->dst.act_w = dst_w;
|
||||
request->dst.act_h = dst_h;
|
||||
|
||||
config_rga_yuv2rgb_mode(ctx);
|
||||
|
||||
request->mmu_info.mmu_en = 1;
|
||||
request->mmu_info.mmu_flag = 1;
|
||||
request->mmu_info.mmu_flag = ((2 & 0x3) << 4) | 1;
|
||||
request->mmu_info.mmu_flag |= (1 << 31) | (1 << 10) | (1 << 8);
|
||||
|
||||
ret = rga_ioctl(impl);
|
||||
END:
|
||||
rga_dbg_func("out\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// sample for duplicate field to frame function
|
||||
MPP_RET rga_dup_field(RgaCtx ctx, MppFrame frame)
|
||||
{
|
||||
MPP_RET ret = MPP_OK;
|
||||
RgaCtxImpl *impl = (RgaCtxImpl *)ctx;
|
||||
MppBuffer buf = mpp_frame_get_buffer(frame);
|
||||
RK_U32 width = mpp_frame_get_width(frame);
|
||||
RK_U32 height = mpp_frame_get_height(frame);
|
||||
RK_U32 h_str = mpp_frame_get_hor_stride(frame);
|
||||
RK_U32 v_str = mpp_frame_get_ver_stride(frame);
|
||||
RK_S32 fd = mpp_buffer_get_fd(buf);
|
||||
void *ptr = mpp_buffer_get_ptr(buf);
|
||||
RgaFormat fmt = rga_fmt_map(mpp_frame_get_fmt(frame));
|
||||
RgaReq *request = &impl->request;
|
||||
|
||||
rga_dbg_func("in\n");
|
||||
|
||||
mpp_assert(fmt == RGA_FMT_YCbCr_420_SP);
|
||||
mpp_assert(width > 0 && height > 0);
|
||||
if (fmt != RGA_FMT_YCbCr_420_SP || width == 0 || height == 0) {
|
||||
ret = MPP_NOK;
|
||||
goto END;
|
||||
}
|
||||
|
||||
rga_dbg_dup("[fd:w:h:h_str:v_str:fmt] %d:%d:%d:%d:%d:%d\n",
|
||||
fd, width, height, h_str, v_str, fmt);
|
||||
|
||||
memset(request, 0, sizeof(*request));
|
||||
request->src.yrgb_addr = fd;
|
||||
request->src.format = (RK_U32)fmt;
|
||||
request->src.vir_w = h_str * 2;
|
||||
request->src.vir_h = v_str / 2;
|
||||
request->src.act_w = width;
|
||||
request->src.act_h = height / 2;
|
||||
|
||||
request->dst.yrgb_addr = 0;
|
||||
request->dst.uv_addr = (RK_U32)((uintptr_t)ptr) + h_str; // special process here
|
||||
request->dst.vir_w = h_str * 2;
|
||||
request->dst.vir_h = v_str / 2;
|
||||
request->dst.format = (RK_U32)fmt;
|
||||
request->dst.act_w = width;
|
||||
request->dst.act_h = height / 2;
|
||||
|
||||
request->clip.xmin = 0;
|
||||
request->clip.xmax = h_str * 2 - 1;
|
||||
request->clip.ymin = 0;
|
||||
request->clip.ymax = v_str / 2 - 1;
|
||||
|
||||
request->mmu_info.mmu_en = 1;
|
||||
request->mmu_info.mmu_flag = ((2 & 0x3) << 4) | 1;
|
||||
request->mmu_info.mmu_flag |= (1 << 31) | (1 << 10) | (1 << 8);
|
||||
|
||||
ret = rga_ioctl(impl);
|
||||
END:
|
||||
rga_dbg_func("out\n");
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Rockchip Electronics Co. LTD
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MPP_RGA_H
|
||||
#define MPP_RGA_H
|
||||
|
||||
/* NOTE: RGA support sync mode and async mode. We use sync mode only. */
|
||||
#define RGA_BLIT_SYNC 0x5017
|
||||
#define RGA_BLIT_ASYNC 0x5018
|
||||
#define RGA_FLUSH 0x5019
|
||||
#define RGA_GET_RESULT 0x501a
|
||||
|
||||
typedef enum RgaFormat_e {
|
||||
RGA_FMT_RGBA_8888 = 0x0,
|
||||
RGA_FMT_RGBX_8888 = 0x1,
|
||||
RGA_FMT_RGB_888 = 0x2,
|
||||
RGA_FMT_BGRA_8888 = 0x3,
|
||||
RGA_FMT_RGB_565 = 0x4,
|
||||
RGA_FMT_RGBA_5551 = 0x5,
|
||||
RGA_FMT_RGBA_4444 = 0x6,
|
||||
RGA_FMT_BGR_888 = 0x7,
|
||||
|
||||
RGA_FMT_YCbCr_422_SP = 0x8,
|
||||
RGA_FMT_YCbCr_422_P = 0x9,
|
||||
RGA_FMT_YCbCr_420_SP = 0xa,
|
||||
RGA_FMT_YCbCr_420_P = 0xb,
|
||||
|
||||
RGA_FMT_YCrCb_422_SP = 0xc,
|
||||
RGA_FMT_YCrCb_422_P = 0xd,
|
||||
RGA_FMT_YCrCb_420_SP = 0xe,
|
||||
RGA_FMT_YCrCb_420_P = 0xf,
|
||||
|
||||
RGA_FMT_BPP1 = 0x10,
|
||||
RGA_FMT_BPP2 = 0x11,
|
||||
RGA_FMT_BPP4 = 0x12,
|
||||
RGA_FMT_BPP8 = 0x13,
|
||||
RGA_FMT_BUTT,
|
||||
} RgaFormat;
|
||||
|
||||
typedef struct RgaImg_t {
|
||||
RK_ULONG yrgb_addr; /* yrgb addr */
|
||||
RK_ULONG uv_addr; /* cb/cr addr */
|
||||
RK_ULONG v_addr; /* cr addr */
|
||||
RK_U32 format; // definition by RgaFormat
|
||||
|
||||
RK_U16 act_w; // width
|
||||
RK_U16 act_h; // height
|
||||
RK_U16 x_offset; // offset from left
|
||||
RK_U16 y_offset; // offset from top
|
||||
|
||||
RK_U16 vir_w; // horizontal stride
|
||||
RK_U16 vir_h; // vertical stride
|
||||
|
||||
RK_U16 endian_mode; // for BPP
|
||||
RK_U16 alpha_swap;
|
||||
} RgaImg;
|
||||
|
||||
typedef struct RgaRect_t {
|
||||
RK_U16 xmin;
|
||||
RK_U16 xmax;
|
||||
RK_U16 ymin;
|
||||
RK_U16 ymax;
|
||||
} RgaRect;
|
||||
|
||||
typedef struct RgaPoint_t {
|
||||
RK_U16 x;
|
||||
RK_U16 y;
|
||||
} RgaPoint;
|
||||
|
||||
typedef struct RgaColorFill_t {
|
||||
RK_S16 gr_x_a;
|
||||
RK_S16 gr_y_a;
|
||||
RK_S16 gr_x_b;
|
||||
RK_S16 gr_y_b;
|
||||
RK_S16 gr_x_g;
|
||||
RK_S16 gr_y_g;
|
||||
RK_S16 gr_x_r;
|
||||
RK_S16 gr_y_r;
|
||||
} RgaColorFill;
|
||||
|
||||
typedef struct RgaLineDraw_t {
|
||||
RgaPoint start_point;
|
||||
RgaPoint end_point;
|
||||
RK_U32 color;
|
||||
RK_U32 flag;
|
||||
RK_U32 line_width;
|
||||
} RgaLineDraw;
|
||||
|
||||
typedef struct RgaFading_t {
|
||||
RK_U8 b;
|
||||
RK_U8 g;
|
||||
RK_U8 r;
|
||||
RK_U8 res;
|
||||
} RgaFading;
|
||||
|
||||
typedef struct RgaMmu_t {
|
||||
RK_U8 mmu_en;
|
||||
RK_ULONG base_addr;
|
||||
RK_U32 mmu_flag;
|
||||
} RgaMmu;
|
||||
|
||||
// structure for userspace / kernel communication
|
||||
typedef struct RgaRequest_t {
|
||||
RK_U8 render_mode;
|
||||
|
||||
RgaImg src;
|
||||
RgaImg dst;
|
||||
RgaImg pat;
|
||||
|
||||
RK_ULONG rop_mask_addr; /* rop4 mask addr */
|
||||
RK_ULONG LUT_addr; /* LUT addr */
|
||||
|
||||
RgaRect clip; /* dst clip window default value is dst_vir */
|
||||
/* value from [0, w-1] / [0, h-1]*/
|
||||
|
||||
RK_S32 sina; /* dst angle default value 0 16.16 scan from table */
|
||||
RK_S32 cosa; /* dst angle default value 0 16.16 scan from table */
|
||||
|
||||
/* alpha rop process flag */
|
||||
/* ([0] = 1 alpha_rop_enable) */
|
||||
/* ([1] = 1 rop enable) */
|
||||
/* ([2] = 1 fading_enable) */
|
||||
/* ([3] = 1 PD_enable) */
|
||||
/* ([4] = 1 alpha cal_mode_sel) */
|
||||
/* ([5] = 1 dither_enable) */
|
||||
/* ([6] = 1 gradient fill mode sel) */
|
||||
/* ([7] = 1 AA_enable) */
|
||||
RK_U16 alpha_rop_flag;
|
||||
RK_U8 scale_mode; /* 0 nearst / 1 bilnear / 2 bicubic */
|
||||
|
||||
RK_U32 color_key_max; /* color key max */
|
||||
RK_U32 color_key_min; /* color key min */
|
||||
|
||||
RK_U32 fg_color; /* foreground color */
|
||||
RK_U32 bg_color; /* background color */
|
||||
|
||||
RgaColorFill gr_color; /* color fill use gradient */
|
||||
|
||||
RgaLineDraw line_draw_info;
|
||||
|
||||
RgaFading fading;
|
||||
|
||||
RK_U8 PD_mode; /* porter duff alpha mode sel */
|
||||
RK_U8 alpha_global_value; /* global alpha value */
|
||||
RK_U16 rop_code; /* rop2/3/4 code scan from rop code table*/
|
||||
RK_U8 bsfilter_flag; /* [2] 0 blur 1 sharp / [1:0] filter_type*/
|
||||
RK_U8 palette_mode; /* (enum) color palatte 0/1bpp, 1/2bpp 2/4bpp 3/8bpp */
|
||||
RK_U8 yuv2rgb_mode; /* (enum) BT.601 MPEG / BT.601 JPEG / BT.709 */
|
||||
RK_U8 endian_mode;
|
||||
|
||||
/* (enum) rotate mode */
|
||||
/* 0x0, no rotate */
|
||||
/* 0x1, rotate */
|
||||
/* 0x2, x_mirror */
|
||||
/* 0x3, y_mirror */
|
||||
RK_U8 rotate_mode;
|
||||
|
||||
RK_U8 color_fill_mode; /* 0 solid color / 1 patten color */
|
||||
|
||||
RgaMmu mmu_info; /* mmu information */
|
||||
|
||||
/* ([0~1] alpha mode) */
|
||||
/* ([2~3] rop mode) */
|
||||
/* ([4] zero mode en) */
|
||||
/* ([5] dst alpha mode) */
|
||||
RK_U8 alpha_rop_mode;
|
||||
RK_U8 src_trans_mode;
|
||||
RK_U8 CMD_fin_int_enable;
|
||||
|
||||
/* completion is reported through a callback */
|
||||
void (*complete)(int retval);
|
||||
} RgaReq;
|
||||
|
||||
#endif // MPP_RGA_H
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# vim: syntax=cmake
|
||||
# ----------------------------------------------------------------------------
|
||||
# mpp/vproc/rga built-in unit test case
|
||||
# ----------------------------------------------------------------------------
|
||||
# rga unit test
|
||||
option(RGA_TEST "Build base rga unit test" ${BUILD_TEST})
|
||||
if (RGA_TEST)
|
||||
add_executable(rga_test rga_test.c)
|
||||
target_link_libraries(rga_test ${MPP_SHARED} utils)
|
||||
set_target_properties(rga_test PROPERTIES FOLDER "mpp/vproc/rga")
|
||||
add_test(NAME rga_test COMMAND rga_test)
|
||||
endif()
|
||||
|
|
@ -1,338 +0,0 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
|
||||
/*
|
||||
* Copyright (c) 2015 Rockchip Electronics Co., Ltd.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "mpp_log.h"
|
||||
#include "mpp_frame.h"
|
||||
#include "mpp_common.h"
|
||||
#include "mpp_err.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "rga_api.h"
|
||||
|
||||
#define MAX_NAME_LENGTH 256
|
||||
|
||||
typedef struct RgaTestCmd_t {
|
||||
RK_U32 src_w;
|
||||
RK_U32 src_h;
|
||||
RK_U32 dst_w;
|
||||
RK_U32 dst_h;
|
||||
MppFrameFormat src_fmt;
|
||||
MppFrameFormat dst_fmt;
|
||||
char input_file[MAX_NAME_LENGTH];
|
||||
char output_file[MAX_NAME_LENGTH];
|
||||
RK_U32 have_input;
|
||||
RK_U32 have_output;
|
||||
} RgaTestCmd;
|
||||
|
||||
void usage()
|
||||
{
|
||||
mpp_log("usage:./rga_test -i input -o output_file"
|
||||
" -w src_w -h src_h -f src_fmt -dst_w dst_w"
|
||||
" -dst_h dst_h -dst_fmt dst_fmt\n");
|
||||
}
|
||||
|
||||
static RK_S32 rga_test_parse_options(int argc, char **argv, RgaTestCmd *cmd)
|
||||
{
|
||||
const char *opt;
|
||||
const char *next;
|
||||
RK_S32 optindex = 1;
|
||||
RK_S32 handleoptions = 1;
|
||||
RK_S32 err = MPP_NOK;
|
||||
|
||||
if (argc < 2 || cmd == NULL) {
|
||||
err = 1;
|
||||
return err;
|
||||
}
|
||||
|
||||
while (optindex < argc) {
|
||||
opt = (const char *) argv[optindex++];
|
||||
next = (const char *) argv[optindex];
|
||||
|
||||
if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
|
||||
if (opt[1] == '-') {
|
||||
if (opt[2] != '\0') {
|
||||
opt++;
|
||||
} else {
|
||||
handleoptions = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
opt++;
|
||||
|
||||
switch (*opt) {
|
||||
case 'i' :
|
||||
if (next) {
|
||||
strncpy(cmd->input_file, next, MAX_NAME_LENGTH - 1);
|
||||
cmd->input_file[strlen(next)] = '\0';
|
||||
cmd->have_input = 1;
|
||||
} else {
|
||||
mpp_err("input file is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
case 'o' :
|
||||
if (next) {
|
||||
strncpy(cmd->output_file, next, MAX_NAME_LENGTH - 1);
|
||||
cmd->output_file[strlen(next)] = '\0';
|
||||
cmd->have_output = 1;
|
||||
} else {
|
||||
mpp_err("output file is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
case 'w' :
|
||||
if (next) {
|
||||
cmd->src_w = atoi(next);
|
||||
} else {
|
||||
mpp_err("src width is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
case 'h' :
|
||||
if (next) {
|
||||
cmd->src_h = atoi(next);
|
||||
} else {
|
||||
mpp_err("src height is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
case 'f' :
|
||||
if (next) {
|
||||
cmd->src_fmt = (MppFrameFormat) atoi(next);
|
||||
err = ((cmd->src_fmt >= MPP_FMT_YUV_BUTT && cmd->src_fmt < MPP_FRAME_FMT_RGB) ||
|
||||
cmd->src_fmt >= MPP_FMT_RGB_BUTT);
|
||||
} else {
|
||||
mpp_err("src fmt is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
case 'd' :
|
||||
if ((*(opt + 1) != '\0') && !strncmp(opt, "dst_w", 5)) {
|
||||
cmd->dst_w = atoi(next);
|
||||
} else if ((*(opt + 1) != '\0') && !strncmp(opt, "dst_h", 5)) {
|
||||
cmd->dst_h = atoi(next);
|
||||
} else if ((*(opt + 1) != '\0') && !strncmp(opt, "dst_fmt", 5)) {
|
||||
cmd->dst_fmt = (MppFrameFormat) atoi(next);
|
||||
} else {
|
||||
mpp_err("dst parameters is invalid\n");
|
||||
goto PARSE_ERR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PARSE_ERR:
|
||||
return err;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
mpp_log("rga test unit\n");
|
||||
|
||||
MPP_RET ret = MPP_NOK;
|
||||
RgaTestCmd cmd;
|
||||
MppBuffer src_buf = NULL;
|
||||
MppBuffer dst_buf = NULL;
|
||||
MppFrame src_frm = NULL;
|
||||
MppFrame dst_frm = NULL;
|
||||
FILE *fin = NULL;
|
||||
FILE *fout = NULL;
|
||||
RgaCtx ctx = NULL;
|
||||
RK_U32 frame_count = 0;
|
||||
|
||||
void *ptr;
|
||||
RK_U32 src_w;
|
||||
RK_U32 src_h;
|
||||
RK_U32 dst_w;
|
||||
RK_U32 dst_h;
|
||||
RK_U32 src_size;
|
||||
RK_U32 dst_size;
|
||||
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
if (rga_test_parse_options(argc, argv, &cmd)) {
|
||||
usage();
|
||||
goto END;
|
||||
}
|
||||
|
||||
mpp_log("src w:%d h:%d fmt:%d dst w:%d h:%d fmt:%d input:%s output:%s\n",
|
||||
cmd.src_w, cmd.src_h, cmd.src_fmt,
|
||||
cmd.dst_w, cmd.dst_h, cmd.dst_fmt,
|
||||
cmd.input_file, cmd.output_file);
|
||||
|
||||
src_w = cmd.src_w;
|
||||
src_h = cmd.src_h;
|
||||
dst_w = cmd.dst_w;
|
||||
dst_h = cmd.dst_h;
|
||||
src_size = src_w * src_h * 4;
|
||||
dst_size = dst_w * dst_h * 4;
|
||||
|
||||
if (cmd.have_input) {
|
||||
fin = fopen(cmd.input_file, "r");
|
||||
if (!fin) {
|
||||
mpp_log("open input file %s failed\n", cmd.input_file);
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.have_output) {
|
||||
fout = fopen(cmd.output_file, "w+");
|
||||
if (!fout) {
|
||||
mpp_log("open output file %s failed\n", cmd.output_file);
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
ret = mpp_buffer_get(NULL, &src_buf, src_size);
|
||||
if (ret) {
|
||||
mpp_err("failed to get src buffer %d with size %d\n", ret, src_size);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = mpp_buffer_get(NULL, &dst_buf, dst_size);
|
||||
if (ret) {
|
||||
mpp_err("failed to get dst buffer %d with size %d\n", ret, dst_size);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = mpp_frame_init(&src_frm);
|
||||
if (ret) {
|
||||
mpp_err("failed to init src frame\n");
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = mpp_frame_init(&dst_frm);
|
||||
if (ret) {
|
||||
mpp_err("failed to init dst frame\n");
|
||||
goto END;
|
||||
}
|
||||
|
||||
ptr = mpp_buffer_get_ptr(src_buf);
|
||||
if (cmd.have_input) {
|
||||
ret = read_image((RK_U8 *)ptr, fin, cmd.src_w, cmd.src_h,
|
||||
cmd.src_w, cmd.src_h, cmd.dst_fmt);
|
||||
if (ret) {
|
||||
mpp_err("failed to read input file ret:%d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
} else {
|
||||
ret = fill_image((RK_U8 *)ptr, cmd.src_w, cmd.src_h,
|
||||
cmd.src_w, cmd.src_h, cmd.src_fmt, frame_count);
|
||||
if (ret) {
|
||||
mpp_err("failed to fill input buffer ret:%d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
mpp_frame_set_buffer(src_frm, src_buf);
|
||||
mpp_frame_set_width(src_frm, src_w);
|
||||
mpp_frame_set_height(src_frm, src_h);
|
||||
mpp_frame_set_hor_stride(src_frm, MPP_ALIGN(src_w, 16));
|
||||
mpp_frame_set_ver_stride(src_frm, MPP_ALIGN(src_h, 16));
|
||||
mpp_frame_set_fmt(src_frm, cmd.src_fmt);
|
||||
|
||||
mpp_frame_set_buffer(dst_frm, dst_buf);
|
||||
mpp_frame_set_width(dst_frm, dst_w);
|
||||
mpp_frame_set_height(dst_frm, dst_h);
|
||||
mpp_frame_set_hor_stride(dst_frm, MPP_ALIGN(dst_w, 16));
|
||||
mpp_frame_set_ver_stride(dst_frm, MPP_ALIGN(dst_h, 16));
|
||||
mpp_frame_set_fmt(dst_frm, cmd.dst_fmt);
|
||||
|
||||
ret = rga_init(&ctx);
|
||||
if (ret) {
|
||||
mpp_err("init rga context failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
// start copy process
|
||||
ret = rga_control(ctx, RGA_CMD_INIT, NULL);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd init failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_SET_SRC, src_frm);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd setup source failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_SET_DST, dst_frm);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd setup destination failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_RUN_SYNC, NULL);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd process copy failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
// start field duplicate process
|
||||
mpp_frame_set_buffer(src_frm, dst_buf);
|
||||
mpp_frame_set_width(src_frm, dst_w);
|
||||
mpp_frame_set_height(src_frm, dst_h / 2);
|
||||
mpp_frame_set_hor_stride(src_frm, MPP_ALIGN(dst_w, 16) * 2);
|
||||
mpp_frame_set_ver_stride(src_frm, MPP_ALIGN(src_h, 16) / 2);
|
||||
mpp_frame_set_fmt(src_frm, cmd.dst_fmt);
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_INIT, NULL);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd init failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_SET_SRC, src_frm);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd setup source failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_SET_DST, dst_frm);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd setup destination failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_control(ctx, RGA_CMD_RUN_SYNC, NULL);
|
||||
if (ret) {
|
||||
mpp_err("rga cmd process copy failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = rga_deinit(ctx);
|
||||
if (ret) {
|
||||
mpp_err("deinit rga context failed %d\n", ret);
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (cmd.have_output)
|
||||
dump_mpp_frame_to_file(dst_frm, fout);
|
||||
|
||||
END:
|
||||
if (src_frm)
|
||||
mpp_frame_deinit(&src_frm);
|
||||
|
||||
if (dst_frm)
|
||||
mpp_frame_deinit(&dst_frm);
|
||||
|
||||
if (src_buf)
|
||||
mpp_buffer_put(src_buf);
|
||||
|
||||
if (dst_buf)
|
||||
mpp_buffer_put(dst_buf);
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
if (fout)
|
||||
fclose(fout);
|
||||
|
||||
mpp_log("rga test exit ret %d\n", ret);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -67,7 +67,5 @@ typedef enum MppClientType_e {
|
|||
|
||||
/* Platform image process hardware feature */
|
||||
#define HAVE_IPP (0x00000001)
|
||||
#define HAVE_RGA (0x00000002)
|
||||
#define HAVE_RGA2 (0x00000004)
|
||||
|
||||
#endif /* MPP_DEV_DEFS_H */
|
||||
|
|
|
|||
|
|
@ -197,9 +197,6 @@ rk_u32 mpp_get_2d_hw_flag(void)
|
|||
{
|
||||
rk_u32 flag = 0;
|
||||
|
||||
if (!access("/dev/rga", F_OK))
|
||||
flag |= HAVE_RGA;
|
||||
|
||||
if (!access("/dev/iep", F_OK))
|
||||
flag |= HAVE_IEP;
|
||||
|
||||
|
|
|
|||
|
|
@ -119,9 +119,7 @@ More document can be found at http://opensource.rock-chips.com/wiki_Mpp
|
|||
| | |
|
||||
| | |----- pp post-processor user library
|
||||
| | |
|
||||
| | |----- rga rga user library
|
||||
| | |
|
||||
| | |----- deinter deinterlace function module including pp/iep/rga
|
||||
| | |----- deinter deinterlace function module including pp/iep
|
||||
| | |
|
||||
| | |----- rkdec rockchip hardware decoder register generation
|
||||
| | | |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue