You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1722 lines
71 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2016-2019. All rights reserved.
* Description: iapi api for app
* Author: Hisilicon
* Create: 2016-01-1
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "uapi_vplugin.h"
#include "mpi_vplugin_define.h"
#include "mpi_vplugin_ext.h"
#include "mpi_memory_ext.h"
#include "mpi_media_ext.h"
#include "mpi_system_ext.h"
#include "securec.h"
#include "soc_errno.h"
#include "soc_log.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define transfer_a2b(a, b) (a) = (b)
#define transfer_a2b_r(a, b) (b) = (a)
static ext_drv_vplugin_frontout_stream_package g_catch_ext_frontout_stream_package;
static ext_drv_vplugin_backin_stream_package g_catch_ext_backin_stream_package;
static ext_drv_vplugin_frontout_stream_package g_sendback_ext_frontout_stream_package;
static ext_drv_vplugin_backin_stream_package g_sendback_ext_backin_stream_package;
typedef struct {
uapi_video_frame_packing_type iapi_packing_type;
ext_drv_3d_type mpi_packing_type;
} conversion_packing_type;
static conversion_packing_type g_conversion_packing_type[UAPI_FRAME_PACKING_TYPE_MAX + 1] = {
{ UAPI_FRAME_PACKING_TYPE_2D, EXT_DRV_3D_NONE },
{ UAPI_FRAME_PACKING_TYPE_SIDE_BY_SIDE, EXT_DRV_3D_SBS_HALF },
{ UAPI_FRAME_PACKING_TYPE_TOP_AND_BOTTOM, EXT_DRV_3D_TAB },
{ UAPI_FRAME_PACKING_TYPE_TIME_INTERLACED, EXT_DRV_3D_FS },
{ UAPI_FRAME_PACKING_TYPE_FRAME_PACKING, EXT_DRV_3D_FPK},
{ UAPI_FRAME_PACKING_TYPE_MAX, EXT_DRV_3D_MAX}
};
typedef struct {
uapi_video_field_mode iapi_field;
ext_drv_field_mode mpi_field;
} conversion_field;
static conversion_field g_conversion_field_mode[UAPI_VIDEO_FIELD_MAX + 1] = {
{ UAPI_VIDEO_FIELD_ALL, EXT_DRV_FIELD_ALL },
{ UAPI_VIDEO_FIELD_TOP, EXT_DRV_FIELD_TOP },
{ UAPI_VIDEO_FIELD_BOTTOM, EXT_DRV_FIELD_BOTTOM },
{ UAPI_VIDEO_FIELD_MAX, EXT_DRV_FIELD_MAX }
};
/***************************************************************************************/
typedef struct {
uapi_video_pixel_format iapi;
ext_drv_pixel_format drv;
} conversion_pix_format;
static conversion_pix_format g_conversion_pix_format[] = {
{ UAPI_FORMAT_YUV_SEMIPLANAR_422_VU, EXT_DRV_PIXEL_FMT_NV61_2X1 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_420_VU, EXT_DRV_PIXEL_FMT_NV21 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_400, EXT_DRV_PIXEL_FMT_NV80 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_411_VU, EXT_DRV_PIXEL_FMT_NV12_411 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_422_UV, EXT_DRV_PIXEL_FMT_NV61 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_444_VU, EXT_DRV_PIXEL_FMT_NV42 },
{ UAPI_FORMAT_YUV_PACKAGE_UYVY, EXT_DRV_PIXEL_FMT_UYVY },
{ UAPI_FORMAT_YUV_PACKAGE_YUYV, EXT_DRV_PIXEL_FMT_YUYV },
{ UAPI_FORMAT_YUV_SEMIPLANAR_420_UV, EXT_DRV_PIXEL_FMT_NV12 },
{ UAPI_FORMAT_YUV_PLANAR_400, EXT_DRV_PIXEL_FMT_YUV400 },
{ UAPI_FORMAT_YUV_SEMIPLANAR_400, EXT_DRV_PIXEL_FMT_NV80 },
{ UAPI_FORMAT_YUV_PLANAR_411_VU, EXT_DRV_PIXEL_FMT_YUV411 },
{ UAPI_FORMAT_YUV_PLANAR_420_VU, EXT_DRV_PIXEL_FMT_YUV420P },
{ UAPI_FORMAT_YUV_PLANAR_422_UV, EXT_DRV_PIXEL_FMT_YUV422_1X2 },
{ UAPI_FORMAT_YUV_PLANAR_422_VU, EXT_DRV_PIXEL_FMT_YUV422_2X1 },
{ UAPI_FORMAT_YUV_PLANAR_444_UV, EXT_DRV_PIXEL_FMT_YUV_444 },
{ UAPI_FORMAT_YUV_PLANAR_410_VU, EXT_DRV_PIXEL_FMT_YUV410P },
{ UAPI_FORMAT_RGB888, EXT_DRV_PIXEL_FMT_RGB24 },
{ UAPI_FORMAT_ARGB8888, EXT_DRV_PIXEL_FMT_ARGB8888 },
{ UAPI_FORMAT_YUV_TILE_420_VU, EXT_DRV_PIXEL_FMT_NV21 },
{ UAPI_FORMAT_YUV_TILE_420_UV, EXT_DRV_PIXEL_FMT_NV12 },
};
typedef struct {
uapi_pixel_bit_depth iapi;
ext_drv_pixel_bitwidth drv;
} conversion_bitwidth;
static conversion_bitwidth g_conversion_bitwidth[] = {
{ UAPI_PIXEL_BIT_DEPTH_DEFAULT, EXT_DRV_PIXEL_BITWIDTH_DEFAULT },
{ UAPI_PIXEL_BIT_DEPTH_8BIT, EXT_DRV_PIXEL_BITWIDTH_8BIT },
{ UAPI_PIXEL_BIT_DEPTH_10BIT, EXT_DRV_PIXEL_BITWIDTH_10BIT },
{ UAPI_PIXEL_BIT_DEPTH_12BIT, EXT_DRV_PIXEL_BITWIDTH_12BIT },
{ UAPI_PIXEL_BIT_DEPTH_16BIT, EXT_DRV_PIXEL_BITWIDTH_16BIT },
};
typedef struct {
uapi_video_afd_type iapi_afd;
ext_drv_video_afd_type mpi_afd;
} conversion_afd;
static conversion_afd g_conversion_afd[] = {
{ UAPI_AFD_TYPE_UNKNOWN, EXT_DRV_AFD_TYPE_UNKNOW },
{ UAPI_AFD_TYPE_BOX_16_9_TOP, EXT_DRV_AFD_TYPE_BOX_16_9_TOP },
{ UAPI_AFD_TYPE_BOX_14_9_TOP, EXT_DRV_AFD_TYPE_BOX_14_9_TOP },
{ UAPI_AFD_TYPE_BOX_16_9_CENTER, EXT_DRV_AFD_TYPE_BOX_16_9_CENTER },
{ UAPI_AFD_TYPE_SAME_AS_SRC, EXT_DRV_AFD_TYPE_SAME_AS_SRC },
{ UAPI_AFD_TYPE_4_3, EXT_DRV_AFD_TYPE_4_3 },
{ UAPI_AFD_TYPE_16_9, EXT_DRV_AFD_TYPE_16_9 },
{ UAPI_AFD_TYPE_14_9, EXT_DRV_AFD_TYPE_14_9 },
{ UAPI_AFD_TYPE_4_3_SHOOT_PRO_14_9, EXT_DRV_AFD_TYPE_4_3_SHOOT_PRO_14_9 },
{ UAPI_AFD_TYPE_16_9_SHOOT_PRO_14_9, EXT_DRV_AFD_TYPE_16_9_SHOOT_PRO_14_9 },
{ UAPI_AFD_TYPE_16_9_SHOOT_PRO_4_3, EXT_DRV_AFD_TYPE_16_9_SHOOT_PRO_4_3 },
{ UAPI_AFD_TYPE_MAX, EXT_DRV_AFD_TYPE_MAX },
};
typedef struct {
uapi_video_source iapi_src;
ext_drv_source mpi_src;
} conversion_source;
static conversion_source g_conversion_src_type[UAPI_VIDEO_SOURCE_MAX + 1] = {
{ UAPI_VIDEO_SOURCE_DTV, EXT_DRV_SOURCE_DTV },
{ UAPI_VIDEO_SOURCE_MEDIA, EXT_DRV_SOURCE_MEDIA },
{ UAPI_VIDEO_SOURCE_ATV, EXT_DRV_SOURCE_ATV },
{ UAPI_VIDEO_SOURCE_SCART, EXT_DRV_SOURCE_SCART },
{ UAPI_VIDEO_SOURCE_SVIDEO, EXT_DRV_SOURCE_SVIDEO },
{ UAPI_VIDEO_SOURCE_CVBS, EXT_DRV_SOURCE_CVBS },
{ UAPI_VIDEO_SOURCE_VGA, EXT_DRV_SOURCE_VGA },
{ UAPI_VIDEO_SOURCE_YPBPR, EXT_DRV_SOURCE_YPBPR },
{ UAPI_VIDEO_SOURCE_HDMI, EXT_DRV_SOURCE_HDMI },
{ UAPI_VIDEO_SOURCE_GRAPHIC, EXT_DRV_SOURCE_GRAPHIC },
{ UAPI_VIDEO_SOURCE_NETWORK, EXT_DRV_SOURCE_NETWORK },
{ UAPI_VIDEO_SOURCE_CAST, EXT_DRV_SOURCE_CAST },
{ UAPI_VIDEO_SOURCE_MAX, EXT_DRV_SOURCE_MAX }
};
typedef struct {
uapi_hdr_type iapi_hdr_type;
ext_drv_hdr_type mpi_hdr_type;
} conversion_hdr;
static conversion_hdr g_conversion_hdr_type[] = {
{ UAPI_HDR_TYPE_SDR, EXT_DRV_HDR_TYPE_SDR },
{ UAPI_HDR_TYPE_HDR10, EXT_DRV_HDR_TYPE_HDR10 },
{ UAPI_HDR_TYPE_HLG, EXT_DRV_HDR_TYPE_HLG },
{ UAPI_HDR_TYPE_CUVA, EXT_DRV_HDR_TYPE_CUVA },
{ UAPI_HDR_TYPE_JTP_SL_HDR, EXT_DRV_HDR_TYPE_JTP_SL_HDR },
{ UAPI_HDR_TYPE_DOLBYVISION, EXT_DRV_HDR_TYPE_DOLBYVISION },
{ UAPI_HDR_TYPE_MAX, EXT_DRV_HDR_TYPE_MAX },
};
static td_s32 check_stream_valid(const uapi_vplugin_frontout_stream_package *frontout_stream_package,
const uapi_vplugin_backin_stream_package *backin_stream_package, td_bool send_back)
{
if ((frontout_stream_package == TD_NULL) || (backin_stream_package == TD_NULL)) {
soc_log_err("frontout_stream_package or backin_stream_package is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if (send_back == TD_TRUE) {
if (memset_s(&g_sendback_ext_frontout_stream_package, sizeof(ext_drv_vplugin_frontout_stream_package), 0,
sizeof(ext_drv_vplugin_frontout_stream_package)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
if (memset_s(&g_sendback_ext_backin_stream_package, sizeof(ext_drv_vplugin_backin_stream_package), 0,
sizeof(ext_drv_vplugin_backin_stream_package)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
} else {
if (memset_s(&g_catch_ext_frontout_stream_package, sizeof(ext_drv_vplugin_frontout_stream_package), 0,
sizeof(ext_drv_vplugin_frontout_stream_package)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
if (memset_s(&g_catch_ext_backin_stream_package, sizeof(ext_drv_vplugin_backin_stream_package), 0,
sizeof(ext_drv_vplugin_backin_stream_package)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
}
return TD_SUCCESS;
}
static td_s32 transfer_video_pixel_format(uapi_video_pixel_format *iapi_type, ext_drv_pixel_format *mpi_type,
td_bool u_to_m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_pix_format) / sizeof(g_conversion_pix_format[0]); index++) {
if (u_to_m) {
if (*iapi_type == g_conversion_pix_format[index].iapi) {
*mpi_type = g_conversion_pix_format[index].drv;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_type == g_conversion_pix_format[index].drv) {
*iapi_type = g_conversion_pix_format[index].iapi;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("err para, iapi fmt:%d, mpi fmt:%d (is u_to_m:%d)\n", *iapi_type, *mpi_type, u_to_m);
}
return ret;
}
static td_s32 transfer_set_bitwidth(uapi_pixel_bit_depth *iapi_bitwidth, ext_drv_pixel_bitwidth *mpi_bitwidth,
td_bool u_to_m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_bitwidth) / sizeof(g_conversion_bitwidth[0]); index++) {
if (u_to_m) {
if (*iapi_bitwidth == g_conversion_bitwidth[index].iapi) {
*mpi_bitwidth = g_conversion_bitwidth[index].drv;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_bitwidth == g_conversion_bitwidth[index].drv) {
*iapi_bitwidth = g_conversion_bitwidth[index].iapi;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("err para, iapi bitwidth:%d, mpi bitwidth:%d (is u_to_m:%d)\n",
*iapi_bitwidth, *mpi_bitwidth, u_to_m);
}
return ret;
}
static td_s32 check_iapi_frame_info(const uapi_video_frame_info *iapi_info)
{
if ((iapi_info->codec_type >= UAPI_VCODEC_TYPE_MAX) || (iapi_info->bit_depth >= UAPI_PIXEL_BIT_DEPTH_MAX) ||
(iapi_info->hdr_type >= UAPI_HDR_TYPE_MAX) || (iapi_info->source_type >= UAPI_VIDEO_SOURCE_MAX)) {
soc_log_err("err para, codec_type:%d, bit_depth:%d, hdr_type type:%d, source_type:%d\n",
iapi_info->codec_type, iapi_info->bit_depth, iapi_info->hdr_type, iapi_info->source_type);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
/* color_description & hdr info check */
if ((iapi_info->video_format >= UAPI_FORMAT_MAX) || (iapi_info->scan_type >= UAPI_VIDEO_SCAN_TYPE_MAX) ||
(iapi_info->field_mode >= UAPI_VIDEO_FIELD_MAX)) {
soc_log_err("err para, fmt:%d, scan_type:%d, frm field_mode:%d\n",
iapi_info->video_format, iapi_info->scan_type, iapi_info->field_mode);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if ((iapi_info->frame_packing_type >= UAPI_FRAME_PACKING_TYPE_MAX) ||
(iapi_info->src_afd >= UAPI_AFD_TYPE_MAX) ||
(iapi_info->compress_info.compress_mode >= UAPI_VIDEO_COMPRESS_MAX)) {
soc_log_err("err para, frm packint type:%d, src_afrd:%d, compress_mode:%d\n",
iapi_info->frame_packing_type, iapi_info->src_afd, iapi_info->compress_info.compress_mode);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
return TD_SUCCESS;
}
static td_void transfer_sample_type_u_to_m(const uapi_video_scan_type *iapi, ext_drv_sample_type *mpi)
{
if (*iapi == UAPI_VIDEO_SCAN_TYPE_UNKNOWN) {
*mpi = EXT_DRV_SAMPLE_TYPE_UNKNOWN;
} else if (*iapi == UAPI_VIDEO_SCAN_TYPE_PROGRESSIVE) {
*mpi = EXT_DRV_SAMPLE_TYPE_PROGRESSIVE;
} else if (*iapi == UAPI_VIDEO_SCAN_TYPE_INTERLACE) {
*mpi = EXT_DRV_SAMPLE_TYPE_INTERLACE;
} else {
*mpi = EXT_DRV_SAMPLE_TYPE_MAX;
}
}
static td_void transfer_frame_basic_info_u_to_m(const uapi_video_frame_info *iapi_info, ext_drv_video_frame *mpi_info)
{
mpi_info->top_field_first = iapi_info->top_field_first;
mpi_info->repeat_first_field = (td_u8)iapi_info->repeat_first_field_cnt;
mpi_info->frame_rate = iapi_info->frame_rate;
transfer_a2b(mpi_info->frame_index, iapi_info->frame_index);
transfer_a2b(mpi_info->src_pts, iapi_info->src_pts);
transfer_a2b(mpi_info->pts, iapi_info->pts);
transfer_a2b(mpi_info->error_level, iapi_info->error_level);
transfer_a2b(mpi_info->flip_v, iapi_info->vertical_mirror);
transfer_a2b(mpi_info->flip_h, iapi_info->horizontal_mirror);
return;
}
static td_void transfer_coordinate(uapi_video_frame_info *iapi_info,
ext_drv_video_frame *mpi_info, td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi_info->width = iapi_info->decode_width;
mpi_info->height = iapi_info->decode_height;
mpi_info->disp_rect.rect_x = (td_s32)(iapi_info->display_center_x - (iapi_info->display_width / 0x2));
mpi_info->disp_rect.rect_y = (td_s32)(iapi_info->display_center_y - (iapi_info->display_height / 0x2));
mpi_info->disp_rect.rect_w = (td_s32)(iapi_info->display_width);
mpi_info->disp_rect.rect_h = (td_s32)(iapi_info->display_height);
mpi_info->aspect_width = iapi_info->aspect_width;
mpi_info->aspect_height = iapi_info->aspect_height;
} else {
iapi_info->decode_width = mpi_info->width;
iapi_info->decode_height = mpi_info->height;
iapi_info->display_center_x = (td_u32)(mpi_info->disp_rect.rect_x + (mpi_info->disp_rect.rect_w / 0x2));
iapi_info->display_center_y = (td_u32)(mpi_info->disp_rect.rect_y + (mpi_info->disp_rect.rect_h / 0x2));
iapi_info->display_width = (td_u32)(mpi_info->disp_rect.rect_w);
iapi_info->display_height = (td_u32)(mpi_info->disp_rect.rect_h);
iapi_info->aspect_width = mpi_info->aspect_width;
iapi_info->aspect_height = mpi_info->aspect_height;
}
return;
}
static td_void transfe_packing_type(uapi_video_frame_packing_type *iapi_packing_type,
ext_drv_3d_type *mpi_packing_type, td_bool u_to_m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_packing_type) / sizeof(g_conversion_packing_type[0]); index++) {
if (u_to_m == TD_TRUE) {
if (*iapi_packing_type == g_conversion_packing_type[index].iapi_packing_type) {
*mpi_packing_type = g_conversion_packing_type[index].mpi_packing_type;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_packing_type == g_conversion_packing_type[index].mpi_packing_type) {
*iapi_packing_type = g_conversion_packing_type[index].iapi_packing_type;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("packing_type conversion failed, iapi_packing_type:%d, max:%d, mpi_packing_type:%d, max:%d",
*iapi_packing_type, UAPI_FRAME_PACKING_TYPE_MAX, *mpi_packing_type, EXT_DRV_3D_MAX);
}
return;
}
static td_void transfe_filed_mode(uapi_video_field_mode *iapi_field, ext_drv_field_mode *mpi_field, td_bool u_to_m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_field_mode) / sizeof(g_conversion_field_mode[0]); index++) {
if (u_to_m) {
if (*iapi_field == g_conversion_field_mode[index].iapi_field) {
*mpi_field = g_conversion_field_mode[index].mpi_field;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_field == g_conversion_field_mode[index].mpi_field) {
*iapi_field = g_conversion_field_mode[index].iapi_field;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("field mode conversion failed, iapi_field:%d, max:%d, mpi_field:%d, max:%d",
*iapi_field, UAPI_VIDEO_FIELD_MAX, *mpi_field, EXT_DRV_FIELD_MAX);
}
return;
}
static td_void transfer_afd(uapi_video_afd_type *iapi_afd, ext_drv_video_afd_type *mpi_afd, td_bool u2m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_afd) / sizeof(g_conversion_afd[0]); index++) {
if (u2m == TD_TRUE) {
if (*iapi_afd == g_conversion_afd[index].iapi_afd) {
*mpi_afd = g_conversion_afd[index].mpi_afd;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_afd == g_conversion_afd[index].mpi_afd) {
*iapi_afd = g_conversion_afd[index].iapi_afd;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("afd conversion failed, iapi_afd:%d, max:%d, mpi_afd:%d, max:%d",
*iapi_afd, UAPI_AFD_TYPE_MAX, *mpi_afd, EXT_DRV_AFD_TYPE_MAX);
}
}
static td_void transfer_source_type(uapi_video_source *iapi_src, ext_drv_source *mpi_src, td_bool u2m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_src_type) / sizeof(g_conversion_src_type[0]); index++) {
if (u2m == TD_TRUE) {
if (*iapi_src == g_conversion_src_type[index].iapi_src) {
*mpi_src = g_conversion_src_type[index].mpi_src;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_src == g_conversion_src_type[index].mpi_src) {
*iapi_src = g_conversion_src_type[index].iapi_src;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("source type conversion failed, iapi_src:%d, max:%d, mpi_src:%d, max:%d",
*iapi_src, UAPI_VIDEO_SOURCE_MAX, *mpi_src, EXT_DRV_SOURCE_MAX);
}
return;
}
static td_void transfer_hdr_type(uapi_hdr_type *iapi_hdr_type, ext_drv_hdr_type *mpi_hdr_type, td_bool u2m)
{
td_u32 index;
td_s32 ret = SOC_ERR_VPLUGIN_PARAM_INVALID;
for (index = 0; index < sizeof(g_conversion_hdr_type) / sizeof(g_conversion_hdr_type[0]); index++) {
if (u2m == TD_TRUE) {
if (*iapi_hdr_type == g_conversion_hdr_type[index].iapi_hdr_type) {
*mpi_hdr_type = g_conversion_hdr_type[index].mpi_hdr_type;
ret = TD_SUCCESS;
break;
}
} else {
if (*mpi_hdr_type == g_conversion_hdr_type[index].mpi_hdr_type) {
*iapi_hdr_type = g_conversion_hdr_type[index].iapi_hdr_type;
ret = TD_SUCCESS;
break;
}
}
}
if (ret != TD_SUCCESS) {
soc_log_err("afd conversion failed, iapi_hdr_type:%d, max:%d, mpi_hdr_type:%d, max:%d",
*iapi_hdr_type, UAPI_HDR_TYPE_MAX, *mpi_hdr_type, EXT_DRV_HDR_TYPE_MAX);
}
}
static td_void transfer_hdr_mastering_display_info(uapi_hdr_mastering_display_info *iapi,
ext_drv_hdr_mastering_display_info *mpi, td_bool u2m)
{
td_u32 i;
td_u32 min_num;
min_num = (EXT_DRV_HDR_DISPLAY_PRIMARIES_NUM > UAPI_HDR_DISPLAY_PRIMARIES_NUM) ?
UAPI_HDR_DISPLAY_PRIMARIES_NUM : EXT_DRV_HDR_DISPLAY_PRIMARIES_NUM;
if (u2m == TD_TRUE) {
for (i = 0; i < min_num; i++) {
mpi->display_primaries_x[i] = iapi->display_primaries_x[i];
mpi->display_primaries_y[i] = iapi->display_primaries_y[i];
}
mpi->white_point_x = iapi->white_point_x;
mpi->white_point_y = iapi->white_point_y;
mpi->max_display_mastering_luminance = iapi->max_display_mastering_luminance;
mpi->min_display_mastering_luminance = iapi->min_display_mastering_luminance;
} else {
for (i = 0; i < min_num; i++) {
iapi->display_primaries_x[i] = mpi->display_primaries_x[i];
iapi->display_primaries_y[i] = mpi->display_primaries_y[i];
}
iapi->white_point_x = mpi->white_point_x;
iapi->white_point_y = mpi->white_point_y;
iapi->max_display_mastering_luminance = mpi->max_display_mastering_luminance;
iapi->min_display_mastering_luminance = mpi->min_display_mastering_luminance;
}
return;
}
static td_void transfer_hdr_light_level(uapi_hdr_content_light_level *iapi, ext_drv_hdr_content_light_level *mpi,
td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->max_content_light_level = iapi->max_content_light_level;
mpi->max_pic_average_light_level = iapi->max_frame_average_light_level;
} else {
iapi->max_content_light_level = mpi->max_content_light_level;
iapi->max_frame_average_light_level = mpi->max_pic_average_light_level;
}
return;
}
static td_void transfer_hdr_static_metadata(uapi_hdr_static_metadata *iapi, ext_drv_hdr_static_metadata *mpi,
td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->mastering_available = iapi->mastering_available;
mpi->content_available = iapi->content_available;
} else {
iapi->mastering_available = mpi->mastering_available;
iapi->content_available = mpi->content_available;
}
transfer_hdr_mastering_display_info(&iapi->mastering_info, &mpi->mastering_info, u2m);
transfer_hdr_light_level(&iapi->content_info, &mpi->content_info, u2m);
return;
}
static td_void transfer_hlg_metadata(uapi_hdr_hlg_metadata *iapi, ext_drv_hdr_hlg_metadata *mpi,
td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->mastering_available = iapi->mastering_available;
mpi->content_available = iapi->content_available;
mpi->backwards_compatible = iapi->backwards_compatible;
} else {
iapi->mastering_available = mpi->mastering_available;
iapi->content_available = mpi->content_available;
iapi->backwards_compatible = mpi->backwards_compatible;
}
transfer_hdr_mastering_display_info(&iapi->mastering_info, &mpi->mastering_info, u2m);
transfer_hdr_light_level(&iapi->content_info, &mpi->content_info, u2m);
return;
}
static td_void transfer_hdr_metadata_buf(uapi_hdr_metadata_buf *iapi, ext_drv_hdr_metadata_buf *mpi, td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->mem_addr = iapi->mem_addr;
mpi->data_length = iapi->data_length;
} else {
iapi->mem_addr = mpi->mem_addr;
iapi->data_length = mpi->data_length;
}
return;
}
static td_void transfer_sl_hdr_metadata(uapi_hdr_sl_metadata *iapi, ext_drv_hdr_sl_metadata *mpi,
td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->static_metadata_available = iapi->static_metadata_available;
mpi->dynamic_metadata_available = iapi->dynamic_metadata_available;
} else {
iapi->static_metadata_available = mpi->static_metadata_available;
iapi->dynamic_metadata_available = mpi->dynamic_metadata_available;
}
transfer_hdr_static_metadata(&iapi->static_metadata, &mpi->static_metadata, u2m);
transfer_hdr_metadata_buf(&iapi->dynamic_metadata, &mpi->dynamic_metadata, u2m);
return;
}
static td_void transfer_hdr_dolby_metadata(uapi_hdr_dolby_metadata *iapi, ext_drv_hdr_dolby_metadata *mpi,
td_bool u2m)
{
if (u2m == TD_TRUE) {
mpi->metadata_valid = iapi->metadata_valid;
mpi->compatible = iapi->compatible;
} else {
iapi->metadata_valid = mpi->metadata_valid;
iapi->compatible = mpi->compatible;
}
transfer_hdr_metadata_buf(&iapi->metadata, &mpi->metadata, u2m);
return;
}
static td_void transfer_hdr_metadata(uapi_hdr_metadata *iapi_hdr_metadata,
ext_drv_hdr_metadata *mpi_hdr_metadata, td_bool u2m)
{
transfer_hdr_static_metadata(&iapi_hdr_metadata->hdr10_metadata, &mpi_hdr_metadata->hdr10_info, u2m);
transfer_hlg_metadata(&iapi_hdr_metadata->hlg_metadata, &mpi_hdr_metadata->hlg_info, u2m);
transfer_sl_hdr_metadata(&iapi_hdr_metadata->sl_hdr_metadata, &mpi_hdr_metadata->sl_hdr_info, u2m);
transfer_sl_hdr_metadata((uapi_hdr_sl_metadata *)&iapi_hdr_metadata->cuva_metadata,
(ext_drv_hdr_sl_metadata *)&mpi_hdr_metadata->cuva_info, u2m);
transfer_hdr_dolby_metadata(&iapi_hdr_metadata->dolby_metadata, &mpi_hdr_metadata->dolby_info, u2m);
return;
}
static td_void transfer_color_space_u_to_m(const uapi_color_space *u_type, ext_drv_color_space *m_type)
{
switch (*u_type) {
case UAPI_COLOR_CS_YUV:
*m_type = EXT_DRV_COLOR_CS_YUV;
break;
case UAPI_COLOR_CS_RGB:
*m_type = EXT_DRV_COLOR_CS_RGB;
break;
default:
soc_log_err("err iapi para.[%u]\n", *u_type);
*m_type = EXT_DRV_COLOR_CS_YUV;
break;
}
}
static td_void transfer_quantify_range_u_to_m(const uapi_color_quantify_range *u_type,
ext_drv_color_quantify_range *m_type)
{
switch (*u_type) {
case UAPI_COLOR_LIMITED_RANGE:
*m_type = EXT_DRV_COLOR_LIMITED_RANGE;
break;
case UAPI_COLOR_FULL_RANGE:
*m_type = EXT_DRV_COLOR_FULL_RANGE;
break;
default:
soc_log_err("err iapi para.[%u]\n", *u_type);
*m_type = EXT_DRV_COLOR_LIMITED_RANGE;
break;
}
}
static td_void transfer_color_primary_u_to_m(const uapi_color_primary *u_type, ext_drv_color_primary *m_type)
{
switch (*u_type) {
case UAPI_COLOR_PRIMARY_UNSPECIFY:
*m_type = EXT_DRV_COLOR_PRIMARY_UNSPECIFY;
break;
case UAPI_COLOR_PRIMARY_BT601_525:
*m_type = EXT_DRV_COLOR_PRIMARY_BT601_525;
break;
case UAPI_COLOR_PRIMARY_BT601_625:
*m_type = EXT_DRV_COLOR_PRIMARY_BT601_625;
break;
case UAPI_COLOR_PRIMARY_BT709:
*m_type = EXT_DRV_COLOR_PRIMARY_BT709;
break;
case UAPI_COLOR_PRIMARY_BT2020:
*m_type = EXT_DRV_COLOR_PRIMARY_BT2020;
break;
case UAPI_COLOR_PRIMARY_CIE1931_XYZ:
*m_type = EXT_DRV_COLOR_PRIMARY_CIE1931_XYZ;
break;
case UAPI_COLOR_PRIMARY_BT470_SYSM:
*m_type = EXT_DRV_COLOR_PRIMARY_BT470_SYSM;
break;
case UAPI_COLOR_PRIMARY_SMPTE_240M:
*m_type = EXT_DRV_COLOR_PRIMARY_SMPTE_240M;
break;
case UAPI_COLOR_PRIMARY_GENERIC_FILM:
*m_type = EXT_DRV_COLOR_PRIMARY_GENERIC_FILM;
break;
case UAPI_COLOR_PRIMARY_SMPTE_RP431:
*m_type = EXT_DRV_COLOR_PRIMARY_SMPTE_RP431;
break;
case UAPI_COLOR_PRIMARY_SMPTE_EG432_1:
*m_type = EXT_DRV_COLOR_PRIMARY_SMPTE_EG432_1;
break;
case UAPI_COLOR_PRIMARY_EBU_TECH_3213E:
*m_type = EXT_DRV_COLOR_PRIMARY_EBU_TECH_3213E;
break;
case UAPI_COLOR_PRIMARY_DCI_P3:
*m_type = EXT_DRV_COLOR_PRIMARY_DCI_P3;
break;
case UAPI_COLOR_PRIMARY_ADOBE_RGB:
*m_type = EXT_DRV_COLOR_PRIMARY_ADOBE_RGB;
break;
case UAPI_COLOR_PRIMARY_DISPLAY_P3:
*m_type = EXT_DRV_COLOR_PRIMARY_DISPLAY_P3;
break;
default:
soc_log_err("err iapi para.[%u]\n", *u_type);
*m_type = EXT_DRV_COLOR_PRIMARY_UNSPECIFY;
break;
}
}
static td_void transfer_curve_type_u_to_m(const uapi_color_transfer_curve *u_type,
ext_drv_color_transfer_curve *m_type)
{
switch (*u_type) {
case UAPI_COLOR_TRANSFER_TYPE_GAMMA_SDR:
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_GAMMA_SDR;
break;
case UAPI_COLOR_TRANSFER_TYPE_GAMMA_HDR:
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_GAMMA_HDR;
break;
case UAPI_COLOR_TRANSFER_TYPE_PQ:
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_PQ;
break;
case UAPI_COLOR_TRANSFER_TYPE_HLG:
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_HLG;
break;
case UAPI_COLOR_TRANSFER_TYPE_XVYCC:
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_XVYCC;
break;
case UAPI_COLOR_TRANSFER_TYPE_GAMMA_22:
*m_type = EXT_DRV_COLOR_TRANSFER_GAMMA_22;
break;
case UAPI_COLOR_TRANSFER_TYPE_GAMMA_24:
*m_type = EXT_DRV_COLOR_TRANSFER_GAMMA_24;
break;
case UAPI_COLOR_TRANSFER_TYPE_GAMMA_26:
*m_type = EXT_DRV_COLOR_TRANSFER_GAMMA_26;
break;
default:
soc_log_err("err iapi para.[%u]\n", *u_type);
*m_type = EXT_DRV_COLOR_TRANSFER_TYPE_GAMMA_SDR;
break;
}
}
static td_void transfer_matrix_coef_u_to_m(const uapi_color_matrix_coeffs *u_cof, ext_drv_color_matrix_coeffs *m_cof)
{
switch (*u_cof) {
case UAPI_COLOR_MATRIX_COEFFS_IDENTITY:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_IDENTITY;
break;
case UAPI_COLOR_MATRIX_COEFFS_UNSPECIFY:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_UNSPECIFY;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT601_525:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT601_525;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT601_625:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT601_625;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT709:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT709;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT2020_NON_CONSTANT:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT2020_NON_CONSTANT;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT2020_CONSTANT:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT2020_CONSTANT;
break;
case UAPI_COLOR_MATRIX_COEFFS_BT2100_ICTCP:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_BT2100_ICTCP;
break;
case UAPI_COLOR_MATRIX_COEFFS_USFCC:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_USFCC;
break;
case UAPI_COLOR_MATRIX_COEFFS_SMPTE_240M:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_SMPTE_240M;
break;
case UAPI_COLOR_MATRIX_COEFFS_YCGCO:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_YCGCO;
break;
case UAPI_COLOR_MATRIX_COEFFS_ST2085:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_ST2085;
break;
case UAPI_COLOR_MATRIX_COEFFS_CHROMAT_NON_CONSTANT:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_CHROMAT_NON_CONSTANT;
break;
case UAPI_COLOR_MATRIX_COEFFS_CHROMAT_CONSTANT:
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_CHROMAT_CONSTANT;
break;
default:
soc_log_err("err iapi para.[%u]\n", *u_cof);
*m_cof = EXT_DRV_COLOR_MATRIX_COEFFS_IDENTITY;
break;
}
}
static td_void transfer_color_space_m_to_u(const ext_drv_color_space *m_type, uapi_color_space *u_type)
{
switch (*m_type) {
case EXT_DRV_COLOR_CS_YUV:
*u_type = UAPI_COLOR_CS_YUV;
break;
case EXT_DRV_COLOR_CS_RGB:
*u_type = UAPI_COLOR_CS_RGB;
break;
default:
soc_log_err("err mpi para.[%u]\n", *m_type);
*u_type = UAPI_COLOR_CS_YUV;
break;
}
}
static td_void transfer_quantify_range_m_to_u(const ext_drv_color_quantify_range *m_type,
uapi_color_quantify_range *u_type)
{
switch (*m_type) {
case EXT_DRV_COLOR_LIMITED_RANGE:
*u_type = UAPI_COLOR_LIMITED_RANGE;
break;
case EXT_DRV_COLOR_FULL_RANGE:
*u_type = UAPI_COLOR_FULL_RANGE;
break;
default:
soc_log_err("err mpi para.[%u]\n", *m_type);
*u_type = UAPI_COLOR_LIMITED_RANGE;
break;
}
}
static td_void transfer_color_primary_m_to_u(const ext_drv_color_primary *m_type, uapi_color_primary *u_type)
{
switch (*m_type) {
case EXT_DRV_COLOR_PRIMARY_UNSPECIFY:
*u_type = UAPI_COLOR_PRIMARY_UNSPECIFY;
break;
case EXT_DRV_COLOR_PRIMARY_BT601_525:
*u_type = UAPI_COLOR_PRIMARY_BT601_525;
break;
case EXT_DRV_COLOR_PRIMARY_BT601_625:
*u_type = UAPI_COLOR_PRIMARY_BT601_625;
break;
case EXT_DRV_COLOR_PRIMARY_BT709:
*u_type = UAPI_COLOR_PRIMARY_BT709;
break;
case EXT_DRV_COLOR_PRIMARY_BT2020:
*u_type = UAPI_COLOR_PRIMARY_BT2020;
break;
case EXT_DRV_COLOR_PRIMARY_CIE1931_XYZ:
*u_type = UAPI_COLOR_PRIMARY_CIE1931_XYZ;
break;
case EXT_DRV_COLOR_PRIMARY_BT470_SYSM:
*u_type = UAPI_COLOR_PRIMARY_BT470_SYSM;
break;
case EXT_DRV_COLOR_PRIMARY_SMPTE_240M:
*u_type = UAPI_COLOR_PRIMARY_SMPTE_240M;
break;
case EXT_DRV_COLOR_PRIMARY_GENERIC_FILM:
*u_type = UAPI_COLOR_PRIMARY_GENERIC_FILM;
break;
case EXT_DRV_COLOR_PRIMARY_SMPTE_RP431:
*u_type = UAPI_COLOR_PRIMARY_SMPTE_RP431;
break;
case EXT_DRV_COLOR_PRIMARY_SMPTE_EG432_1:
*u_type = UAPI_COLOR_PRIMARY_SMPTE_EG432_1;
break;
case EXT_DRV_COLOR_PRIMARY_EBU_TECH_3213E:
*u_type = UAPI_COLOR_PRIMARY_EBU_TECH_3213E;
break;
case EXT_DRV_COLOR_PRIMARY_DCI_P3:
*u_type = UAPI_COLOR_PRIMARY_DCI_P3;
break;
case EXT_DRV_COLOR_PRIMARY_ADOBE_RGB:
*u_type = UAPI_COLOR_PRIMARY_ADOBE_RGB;
break;
case EXT_DRV_COLOR_PRIMARY_DISPLAY_P3:
*u_type = UAPI_COLOR_PRIMARY_DISPLAY_P3;
break;
default:
soc_log_err("err mpi para.[%u]\n", *m_type);
*u_type = UAPI_COLOR_PRIMARY_UNSPECIFY;
break;
}
}
static td_void transfer_curve_type_m_to_u(const ext_drv_color_transfer_curve *m_type,
uapi_color_transfer_curve *u_type)
{
switch (*m_type) {
case EXT_DRV_COLOR_TRANSFER_TYPE_GAMMA_SDR:
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_SDR;
break;
case EXT_DRV_COLOR_TRANSFER_TYPE_GAMMA_HDR:
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_HDR;
break;
case EXT_DRV_COLOR_TRANSFER_TYPE_PQ:
*u_type = UAPI_COLOR_TRANSFER_TYPE_PQ;
break;
case EXT_DRV_COLOR_TRANSFER_TYPE_HLG:
*u_type = UAPI_COLOR_TRANSFER_TYPE_HLG;
break;
case EXT_DRV_COLOR_TRANSFER_TYPE_XVYCC:
*u_type = UAPI_COLOR_TRANSFER_TYPE_XVYCC;
break;
case EXT_DRV_COLOR_TRANSFER_GAMMA_22:
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_22;
break;
case EXT_DRV_COLOR_TRANSFER_GAMMA_24:
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_24;
break;
case EXT_DRV_COLOR_TRANSFER_GAMMA_26:
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_26;
break;
default:
soc_log_err("err mpi para.[%u]\n", *m_type);
*u_type = UAPI_COLOR_TRANSFER_TYPE_GAMMA_SDR;
break;
}
}
static td_void transfer_matrix_coef_m_to_u(const ext_drv_color_matrix_coeffs *m_cof, uapi_color_matrix_coeffs *u_cof)
{
switch (*m_cof) {
case EXT_DRV_COLOR_MATRIX_COEFFS_IDENTITY:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_IDENTITY;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_UNSPECIFY:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_UNSPECIFY;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT601_525:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT601_525;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT601_625:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT601_625;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT709:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT709;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT2020_NON_CONSTANT:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT2020_NON_CONSTANT;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT2020_CONSTANT:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT2020_CONSTANT;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_BT2100_ICTCP:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_BT2100_ICTCP;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_USFCC:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_USFCC;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_SMPTE_240M:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_SMPTE_240M;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_YCGCO:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_YCGCO;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_ST2085:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_ST2085;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_CHROMAT_NON_CONSTANT:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_CHROMAT_NON_CONSTANT;
break;
case EXT_DRV_COLOR_MATRIX_COEFFS_CHROMAT_CONSTANT:
*u_cof = UAPI_COLOR_MATRIX_COEFFS_CHROMAT_CONSTANT;
break;
default:
soc_log_err("err mpi para.[%u]\n", *m_cof);
*u_cof = UAPI_COLOR_MATRIX_COEFFS_IDENTITY;
break;
}
}
static td_void transfer_color_info(uapi_color_description *iapi_color_info, ext_drv_color_descript *mpi_color_info,
td_bool u2m)
{
if (u2m == TD_TRUE) {
transfer_color_space_u_to_m(&iapi_color_info->color_space, &mpi_color_info->color_space);
transfer_quantify_range_u_to_m(&iapi_color_info->quantify_range, &mpi_color_info->quantify_range);
transfer_color_primary_u_to_m(&iapi_color_info->color_primary, &mpi_color_info->color_primary);
transfer_curve_type_u_to_m(&iapi_color_info->transfer_type, &mpi_color_info->transfer_type);
transfer_matrix_coef_u_to_m(&iapi_color_info->matrix_coef, &mpi_color_info->matrix_coef);
} else {
transfer_color_space_m_to_u(&mpi_color_info->color_space, &iapi_color_info->color_space);
transfer_quantify_range_m_to_u(&mpi_color_info->quantify_range, &iapi_color_info->quantify_range);
transfer_color_primary_m_to_u(&mpi_color_info->color_primary, &iapi_color_info->color_primary);
transfer_curve_type_m_to_u(&mpi_color_info->transfer_type, &iapi_color_info->transfer_type);
transfer_matrix_coef_m_to_u(&mpi_color_info->matrix_coef, &iapi_color_info->matrix_coef);
}
return;
}
static td_void transfer_frame_addr_u_to_m(uapi_video_frame_addr *iapi_addr,
ext_drv_vid_frame_addr *mpi_addr, td_u32 array_num)
{
td_u32 i;
for (i = 0; i < array_num; i++) {
mpi_addr[i].start_addr = iapi_addr[i].start_addr;
mpi_addr[i].y_head_offset = iapi_addr[i].y_head_offset;
mpi_addr[i].y_offset = iapi_addr[i].y_offset;
mpi_addr[i].c_head_offset = iapi_addr[i].c_head_offset;
mpi_addr[i].c_offset = iapi_addr[i].c_offset;
mpi_addr[i].cr_head_offset = iapi_addr[i].cr_head_offset;
mpi_addr[i].cr_offset = iapi_addr[i].cr_offset;
mpi_addr[i].stride_y = iapi_addr[i].stride_y;
mpi_addr[i].stride_c = iapi_addr[i].stride_c;
mpi_addr[i].stride_cr = iapi_addr[i].stride_cr;
mpi_addr[i].head_stride = iapi_addr[i].head_stride;
mpi_addr[i].head_size = iapi_addr[i].head_size;
}
return;
}
static td_void transfer_private_info_u_to_m(const uapi_video_frame_info *iapi_info, ext_drv_video_frame *mpi_info)
{
ext_vid_frm_private_info *private_info = TD_NULL;
if (sizeof(iapi_info->priv_info.priv_data) < sizeof(ext_vid_frm_private_info)) {
soc_log_err("iapi private size=%d smaller than private struct size=%d\n",
sizeof(iapi_info->priv_info.priv_data), sizeof(ext_vid_frm_private_info));
return;
}
private_info = (ext_vid_frm_private_info *)iapi_info->priv_info.priv_data;
if (private_info->buf_valid_mode == EXT_FIELD_ALL) {
mpi_info->buf_valid_mode = EXT_DRV_FIELD_ALL;
} else if (private_info->buf_valid_mode == EXT_FIELD_TOP) {
mpi_info->buf_valid_mode = EXT_DRV_FIELD_TOP;
} else if (private_info->buf_valid_mode == EXT_FIELD_BOTTOM) {
mpi_info->buf_valid_mode = EXT_DRV_FIELD_BOTTOM;
} else {
mpi_info->buf_valid_mode = EXT_DRV_FIELD_MAX;
}
mpi_info->tunnel_buffer.fd_handle = private_info->tunnel_buffer.mem_handle;
mpi_info->tunnel_buffer.dma_handle = 0;
mpi_info->tunnel_buffer.offset = (td_u32)private_info->tunnel_buffer.addr_offset;
mpi_info->secure_info.session_id = private_info->secure_info.session_id;
mpi_info->secure_info.phy_addr = private_info->secure_info.phy_addr;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_NONE].allow_width =
private_info->secure_info.hdcp_info[EXT_HDCP_NONE].allow_width;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_NONE].allow_height =
private_info->secure_info.hdcp_info[EXT_HDCP_NONE].allow_height;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_14].allow_width =
private_info->secure_info.hdcp_info[EXT_HDCP_14].allow_width;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_14].allow_height =
private_info->secure_info.hdcp_info[EXT_HDCP_14].allow_height;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_22].allow_width =
private_info->secure_info.hdcp_info[EXT_HDCP_22].allow_width;
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_22].allow_height =
private_info->secure_info.hdcp_info[EXT_HDCP_22].allow_height;
return;
}
static td_s32 transfer_frame_u_to_m(uapi_video_frame_info *iapi_info, ext_drv_video_frame *mpi_info)
{
td_s32 ret;
ret = check_iapi_frame_info(iapi_info);
if (ret != TD_SUCCESS) {
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
memset_s(mpi_info, sizeof(ext_drv_video_frame), 0, sizeof(ext_drv_video_frame));
ret = transfer_video_pixel_format(&iapi_info->video_format, &mpi_info->pixel_format, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
if (iapi_info->video_format == UAPI_FORMAT_ARGB8888 ||
iapi_info->video_format == UAPI_FORMAT_RGB888) {
mpi_info->cmp_info.data_fmt = EXT_DRV_DATA_FMT_PKG;
}
transfer_sample_type_u_to_m(&iapi_info->scan_type, &mpi_info->sample_type);
transfer_frame_basic_info_u_to_m(iapi_info, mpi_info);
transfer_coordinate(iapi_info, mpi_info, TD_TRUE);
ret = transfer_set_bitwidth(&iapi_info->bit_depth, &mpi_info->bit_width, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
transfe_packing_type(&iapi_info->frame_packing_type, &mpi_info->video_3d_type, TD_TRUE);
transfe_filed_mode(&iapi_info->field_mode, &mpi_info->field_mode, TD_TRUE);
transfer_afd(&iapi_info->src_afd, &mpi_info->afd_format, TD_TRUE);
mpi_info->secure = iapi_info->secure_frame;
transfer_source_type(&iapi_info->source_type, &mpi_info->video_private.source, TD_TRUE);
transfer_hdr_type(&iapi_info->hdr_type, &mpi_info->hdr_type, TD_TRUE);
transfer_hdr_metadata(&iapi_info->hdr_metadata, &mpi_info->hdr_info, TD_TRUE);
transfer_color_info(&iapi_info->color_description, &mpi_info->color_space, TD_TRUE);
transfer_frame_addr_u_to_m(iapi_info->frame_addr, mpi_info->buf_addr, 0x2); /* 2 eyes, high 8bit */
transfer_frame_addr_u_to_m(iapi_info->frame_addr_ext, mpi_info->buf_addr_lb, 0x2); /* 2 eyes, low 2bit */
transfer_private_info_u_to_m(iapi_info, mpi_info);
return ret;
}
static td_void transfer_frame_basic_info_m_to_u(uapi_video_frame_info *iapi_info, const ext_drv_video_frame *mpi_info)
{
iapi_info->repeat_first_field_cnt = mpi_info->repeat_first_field;
iapi_info->frame_rate = mpi_info->frame_rate;
iapi_info->top_field_first = mpi_info->top_field_first;
transfer_a2b_r(mpi_info->frame_index, iapi_info->frame_index);
transfer_a2b_r(mpi_info->src_pts, iapi_info->src_pts);
transfer_a2b_r(mpi_info->pts, iapi_info->pts);
transfer_a2b_r(mpi_info->error_level, iapi_info->error_level);
transfer_a2b_r(mpi_info->flip_v, iapi_info->vertical_mirror);
transfer_a2b_r(mpi_info->flip_h, iapi_info->horizontal_mirror);
return;
}
static td_void transfer_sample_type_m_to_u(uapi_video_scan_type *iapi, const ext_drv_sample_type *mpi)
{
if (*mpi == EXT_DRV_SAMPLE_TYPE_UNKNOWN) {
*iapi = UAPI_VIDEO_SCAN_TYPE_UNKNOWN;
} else if (*mpi == EXT_DRV_SAMPLE_TYPE_PROGRESSIVE) {
*iapi = UAPI_VIDEO_SCAN_TYPE_PROGRESSIVE;
} else if (*mpi == EXT_DRV_SAMPLE_TYPE_INTERLACE) {
*iapi = UAPI_VIDEO_SCAN_TYPE_INTERLACE;
} else {
*iapi = UAPI_VIDEO_SCAN_TYPE_MAX;
}
}
static td_void transfer_frame_addr_m_to_u(uapi_video_frame_addr *iapi_addr,
ext_drv_vid_frame_addr *mpi_addr, td_u32 array_num)
{
td_u32 i;
for (i = 0; i < array_num; i++) {
iapi_addr[i].start_addr = mpi_addr[i].start_addr;
iapi_addr[i].y_head_offset = mpi_addr[i].y_head_offset;
iapi_addr[i].y_offset = mpi_addr[i].y_offset;
iapi_addr[i].c_head_offset = mpi_addr[i].c_head_offset;
iapi_addr[i].c_offset = mpi_addr[i].c_offset;
iapi_addr[i].cr_head_offset = mpi_addr[i].cr_head_offset;
iapi_addr[i].cr_offset = mpi_addr[i].cr_offset;
iapi_addr[i].stride_y = mpi_addr[i].stride_y;
iapi_addr[i].stride_c = mpi_addr[i].stride_c;
iapi_addr[i].stride_cr = mpi_addr[i].stride_cr;
iapi_addr[i].head_stride = mpi_addr[i].head_stride;
iapi_addr[i].head_size = mpi_addr[i].head_size;
}
return;
}
static td_void transfer_private_info_m_to_u(const ext_drv_video_frame *mpi_info, uapi_video_frame_info *iapi_info)
{
ext_vid_frm_private_info *private_info = TD_NULL;
if (sizeof(iapi_info->priv_info.priv_data) < sizeof(ext_vid_frm_private_info)) {
soc_log_err("iapi private size=%d smaller than private struct size=%d\n",
sizeof(iapi_info->priv_info.priv_data), sizeof(ext_vid_frm_private_info));
return;
}
private_info = (ext_vid_frm_private_info *)iapi_info->priv_info.priv_data;
private_info->content_available = TD_TRUE;
private_info->content_mode_id = SOC_ID_WIN;
if (mpi_info->buf_valid_mode == EXT_DRV_FIELD_ALL) {
private_info->buf_valid_mode = EXT_FIELD_ALL;
} else if (mpi_info->buf_valid_mode == EXT_DRV_FIELD_TOP) {
private_info->buf_valid_mode = EXT_FIELD_TOP;
} else if (mpi_info->buf_valid_mode == EXT_DRV_FIELD_BOTTOM) {
private_info->buf_valid_mode = EXT_FIELD_BOTTOM;
} else {
private_info->buf_valid_mode = EXT_FIELD_MAX;
}
private_info->tunnel_buffer.mem_handle = mpi_info->tunnel_buffer.fd_handle;
private_info->tunnel_buffer.addr_offset = mpi_info->tunnel_buffer.offset;
private_info->secure_info.session_id = mpi_info->secure_info.session_id;
private_info->secure_info.phy_addr = mpi_info->secure_info.phy_addr;
private_info->secure_info.hdcp_info[EXT_HDCP_NONE].allow_width =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_NONE].allow_width;
private_info->secure_info.hdcp_info[EXT_HDCP_NONE].allow_height =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_NONE].allow_height;
private_info->secure_info.hdcp_info[EXT_HDCP_14].allow_width =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_14].allow_width;
private_info->secure_info.hdcp_info[EXT_HDCP_14].allow_height =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_14].allow_height;
private_info->secure_info.hdcp_info[EXT_HDCP_22].allow_width =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_22].allow_width;
private_info->secure_info.hdcp_info[EXT_HDCP_22].allow_height =
mpi_info->secure_info.hdcp_info[EXT_DRV_HDCP_22].allow_height;
return;
}
static td_s32 transfer_frame_m_to_u(uapi_video_frame_info *iapi_info, ext_drv_video_frame *mpi_info)
{
td_s32 ret;
if ((mpi_info->pixel_format >= EXT_DRV_PIXEL_MAX) || (mpi_info->field_mode >= EXT_DRV_FIELD_MAX) ||
(mpi_info->video_3d_type >= EXT_DRV_3D_MAX) || (mpi_info->video_private.source >= EXT_DRV_SOURCE_MAX)) {
soc_log_err("err mpi para, fmt:%d, field_mode:%d, 3d type:%d source type:%d\n",
mpi_info->pixel_format, mpi_info->field_mode, mpi_info->video_3d_type, mpi_info->video_private.source);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
memset_s(iapi_info, sizeof(uapi_video_frame_info), 0, sizeof(uapi_video_frame_info));
ret = transfer_video_pixel_format(&iapi_info->video_format, &mpi_info->pixel_format, TD_FALSE);
if (ret != TD_SUCCESS) {
return ret;
}
transfer_frame_basic_info_m_to_u(iapi_info, mpi_info);
transfer_sample_type_m_to_u(&iapi_info->scan_type, &mpi_info->sample_type);
transfer_coordinate(iapi_info, mpi_info, TD_FALSE);
transfe_packing_type(&iapi_info->frame_packing_type, &mpi_info->video_3d_type, TD_FALSE);
transfe_filed_mode(&iapi_info->field_mode, &mpi_info->field_mode, TD_FALSE);
ret = transfer_set_bitwidth(&iapi_info->bit_depth, &mpi_info->bit_width, TD_FALSE);
if (ret != TD_SUCCESS) {
return ret;
}
iapi_info->secure_frame = mpi_info->secure;
transfer_source_type(&iapi_info->source_type, &mpi_info->video_private.source, TD_FALSE);
transfer_color_info(&iapi_info->color_description, &mpi_info->color_space, TD_FALSE);
transfer_frame_addr_m_to_u(iapi_info->frame_addr, mpi_info->buf_addr, 0x2); /* 2 eyes, high 8bit */
transfer_frame_addr_m_to_u(iapi_info->frame_addr_ext, mpi_info->buf_addr_lb, 0x2); /* 2 eyes, low 2bit */
transfer_hdr_type(&iapi_info->hdr_type, &mpi_info->hdr_type, TD_FALSE);
transfer_hdr_metadata(&iapi_info->hdr_metadata, &mpi_info->hdr_info, TD_FALSE);
transfer_afd(&iapi_info->src_afd, &mpi_info->afd_format, TD_FALSE);
transfer_private_info_m_to_u(mpi_info, iapi_info);
return ret;
}
static td_s32 transfer_frame(uapi_video_frame_info *iapi_info, ext_drv_video_frame *mpi_info, td_bool u_to_m)
{
td_s32 ret;
if (u_to_m) {
ret = transfer_frame_u_to_m(iapi_info, mpi_info);
} else {
ret = transfer_frame_m_to_u(iapi_info, mpi_info);
}
return ret;
}
td_s32 uapi_vplugin_init(td_void)
{
td_s32 ret;
ext_mpi_sys_init();
ret = ext_mpi_vplugin_init();
return ret;
}
td_s32 uapi_vplugin_deinit(td_void)
{
td_s32 ret;
ext_mpi_sys_deinit();
ret = ext_mpi_vplugin_deinit();
return ret;
}
td_s32 uapi_vplugin_create(td_handle win_handle, td_handle *vplugin_handle)
{
if (vplugin_handle == TD_NULL) {
soc_log_err("vplugin_handle is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
return ext_mpi_vplugin_create(win_handle, vplugin_handle);
}
td_s32 uapi_vplugin_destroy(td_handle vplugin_handle)
{
return ext_mpi_vplugin_destroy(vplugin_handle);
}
td_s32 uapi_vplugin_set_param(td_handle vplugin_handle, uapi_vplugin_stream_index stream_index,
uapi_vplugin_frontout_param *frontout_param, uapi_vplugin_backin_param *backin_param)
{
td_s32 ret;
ext_drv_vplugin_stream_index ext_stream_index;
ext_drv_vplugin_frontout_param ext_frontout_param;
ext_drv_vplugin_backin_param ext_backin_param;
if (stream_index >= UAPI_VPLUGIN_STREAM_MAX) {
soc_log_err("stream_index %d is over range!\n", stream_index);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if ((frontout_param == TD_NULL) || (backin_param == TD_NULL)) {
soc_log_err("frontout_param or backin_param is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if (memset_s(&ext_frontout_param, sizeof(ext_drv_vplugin_frontout_param),
0, sizeof(ext_drv_vplugin_frontout_param)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
if (memset_s(&ext_backin_param, sizeof(ext_drv_vplugin_backin_param),
0, sizeof(ext_drv_vplugin_backin_param)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
ext_stream_index = (ext_drv_vplugin_stream_index)stream_index;
ret = transfer_video_pixel_format(&frontout_param->frame_format, &ext_frontout_param.frame_format, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
ret = transfer_set_bitwidth(&frontout_param->frame_bit_depth, &ext_frontout_param.frame_bit_depth, TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err("transfer bitwidth failure!!!!!\n");
return ret;
}
if (memcpy_s(&(ext_frontout_param.crop_rect), sizeof(ext_frontout_param.crop_rect), &(frontout_param->crop_rect),
sizeof(frontout_param->crop_rect)) != EOK) {
soc_log_err("memcpy_s failed\n");
return TD_FAILURE;
}
ext_frontout_param.frame_width = frontout_param->frame_width;
ext_frontout_param.frame_height = frontout_param->frame_height;
ret = transfer_video_pixel_format(&backin_param->frame_format, &ext_backin_param.frame_format, TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err("transfer vedio pixel format failure!!!!\n");
return ret;
}
ret = transfer_set_bitwidth(&backin_param->frame_bit_depth, &ext_backin_param.frame_bit_depth, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
ext_backin_param.frame_stride_y = backin_param->frame_stride_y;
ext_backin_param.frame_stride_c = backin_param->frame_stride_c;
ext_backin_param.frame_width = backin_param->frame_width;
ext_backin_param.frame_height = backin_param->frame_height;
ext_backin_param.result_cnt = backin_param->result_cnt;
ext_backin_param.secure_frame = backin_param->secure_frame;
if (memcpy_s(&(ext_backin_param.result_size), sizeof(ext_backin_param.result_size), &(backin_param->result_size),
sizeof(backin_param->result_size)) != EOK) {
soc_log_err("memcpy_s failed\n");
return TD_FAILURE;
}
return ext_mpi_vplugin_set_param(vplugin_handle, ext_stream_index, &ext_frontout_param, &ext_backin_param);
}
td_s32 uapi_vplugin_get_param(td_handle vplugin_handle, uapi_vplugin_stream_index stream_index,
uapi_vplugin_frontout_param *frontout_param, uapi_vplugin_backin_param *backin_param)
{
td_s32 ret;
ext_drv_vplugin_stream_index ext_stream_index;
ext_drv_vplugin_frontout_param ext_frontout_param;
ext_drv_vplugin_backin_param ext_backin_param;
if (stream_index >= UAPI_VPLUGIN_STREAM_MAX) {
soc_log_err("stream_index %d is over range!\n", stream_index);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if ((frontout_param == TD_NULL) || (backin_param == TD_NULL)) {
soc_log_err("frontout_param or backin_param is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if (memset_s(&ext_frontout_param, sizeof(ext_drv_vplugin_frontout_param),
0, sizeof(ext_drv_vplugin_frontout_param)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
if (memset_s(&ext_backin_param, sizeof(ext_drv_vplugin_backin_param), 0,
sizeof(ext_drv_vplugin_backin_param)) != EOK) {
soc_log_err("memset_s failed\n");
return TD_FAILURE;
}
ext_stream_index = (ext_drv_vplugin_stream_index)stream_index;
ret = ext_mpi_vplugin_get_param(vplugin_handle, ext_stream_index, &ext_frontout_param, &ext_backin_param);
if (ret != TD_SUCCESS) {
soc_log_err("set vplugin server config param failed, ret=0x%x", ret);
return ret;
}
ret = transfer_video_pixel_format(&frontout_param->frame_format, &ext_frontout_param.frame_format, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
ret = transfer_set_bitwidth(&frontout_param->frame_bit_depth, &ext_frontout_param.frame_bit_depth, TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err("transfer bitwidth failure!!!!!\n");
return ret;
}
if (memcpy_s(&(frontout_param->crop_rect), sizeof(ext_frontout_param.crop_rect), &(ext_frontout_param.crop_rect),
sizeof(frontout_param->crop_rect)) != EOK) {
soc_log_err("memcpy_s failed\n");
return TD_FAILURE;
}
frontout_param->frame_width = ext_frontout_param.frame_width;
frontout_param->frame_height = ext_frontout_param.frame_height;
ret = transfer_video_pixel_format(&backin_param->frame_format, &ext_backin_param.frame_format, TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err("transfer vedio pixel format failure!!!!\n");
return ret;
}
ret = transfer_set_bitwidth(&backin_param->frame_bit_depth, &ext_backin_param.frame_bit_depth, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
backin_param->frame_stride_y = ext_backin_param.frame_stride_y;
backin_param->frame_stride_c = ext_backin_param.frame_stride_c;
backin_param->frame_width = ext_backin_param.frame_width;
backin_param->frame_height = ext_backin_param.frame_height;
backin_param->result_cnt = ext_backin_param.result_cnt;
backin_param->secure_frame = ext_backin_param.secure_frame;
if (memcpy_s(&(backin_param->result_size), sizeof(ext_backin_param.result_size), &(ext_backin_param.result_size),
sizeof(backin_param->result_size)) != EOK) {
soc_log_err("memcpy_s failed\n");
return TD_FAILURE;
}
return TD_SUCCESS;
}
td_s32 uapi_vplugin_set_enable(td_handle vplugin_handle, uapi_vplugin_stream_index stream_index,
td_bool enable)
{
ext_drv_vplugin_stream_index ext_stream_index;
if (stream_index >= UAPI_VPLUGIN_STREAM_MAX) {
soc_log_err("stream_index %d is over range!\n", stream_index);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
ext_stream_index = (ext_drv_vplugin_stream_index)stream_index;
return ext_mpi_vplugin_set_enable(vplugin_handle, ext_stream_index, enable);
}
td_s32 uapi_vplugin_get_enable(td_handle vplugin_handle, uapi_vplugin_stream_index stream_index,
td_bool *enable)
{
ext_drv_vplugin_stream_index ext_stream_index;
if (stream_index >= UAPI_VPLUGIN_STREAM_MAX) {
soc_log_err("stream_index %d is over range!\n", stream_index);
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
if (enable == TD_NULL) {
soc_log_err("enable is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
ext_stream_index = (ext_drv_vplugin_stream_index)stream_index;
return ext_mpi_vplugin_get_enable(vplugin_handle, ext_stream_index, enable);
}
td_s32 uapi_vplugin_get_inst_status(td_handle vplugin_handle, uapi_vplugin_inst_status *status)
{
td_s32 ret;
ext_drv_vplugin_state ext_inst_status = EXT_DRV_VPLUGIN_STATUS_MAX;
if (status == TD_NULL) {
soc_log_err("status is NULL!\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
ret = ext_mpi_vplugin_get_inst_status(vplugin_handle, &ext_inst_status);
if (ret != TD_SUCCESS) {
soc_log_err("set vplugin server config param failed, ret=0x%x", ret);
return ret;
}
*status = (uapi_vplugin_inst_status)ext_inst_status;
return TD_SUCCESS;
}
#define TIMEOUT_MAX_VALUE_MS 3000
#define WINDOW_ACQUIRE_FRAME_DELAY 1000
td_s32 uapi_vplugin_catch_stream(td_handle vplugin_handle,
uapi_vplugin_frontout_stream_package *frontout_stream_package,
uapi_vplugin_backin_stream_package *backin_stream_package, td_u32 timeout_ms)
{
td_s32 ret;
td_u32 delay_time = 0;
ext_drv_vplugin_rect_info drv_rect_info;
ret = check_stream_valid(frontout_stream_package, backin_stream_package, TD_FALSE);
if (ret != TD_SUCCESS) {
return ret;
}
g_catch_ext_frontout_stream_package.frontout_stream_cnt = frontout_stream_package->frontout_stream_cnt;
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
g_catch_ext_backin_stream_package.backin_stream_cnt =
backin_stream_package->backin_stream_cnt;
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
if (timeout_ms > TIMEOUT_MAX_VALUE_MS) {
soc_log_err("timeout is too big.\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
do {
ret = ext_mpi_vplugin_catch_stream(vplugin_handle, &g_catch_ext_frontout_stream_package,
&g_catch_ext_backin_stream_package, &drv_rect_info, timeout_ms);
if (ret == TD_SUCCESS) {
ret = transfer_frame(&(frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame),
&g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame,
TD_FALSE);
if (ret != TD_SUCCESS) {
soc_log_err(" transfer_frame failed! ret:%x \n", ret);
}
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].
backin_frame.frame_addr[UAPI_MULTI_VIEW_0].start_addr =
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].
backin_frame.buf_addr[EXT_DRV_3D_EYE_LEFT].start_addr;
break;
}
delay_time += 1;
usleep(WINDOW_ACQUIRE_FRAME_DELAY);
if (delay_time == timeout_ms) {
soc_log_warn(" catch time out \n");
return SOC_ERR_VPLUGIN_NOT_SUPPORT_CHANGE_PARAM;
}
} while (delay_time <= timeout_ms);
if (ret != TD_SUCCESS) {
soc_log_err("set vplugin server config param failed, ret=0x%x", ret);
}
return ret;
}
static void transfer_rect_info(uapi_video_rect *video_rect, ext_drv_rect drv_rect)
{
soc_log_info("drv_rect.x:%d, drv_rect.rect_y:%d, drv_rect.rect_w:%d, drv_rect.rect_h:%d\n", drv_rect.rect_x,
drv_rect.rect_y, drv_rect.rect_w, drv_rect.rect_h);
video_rect->x = drv_rect.rect_x;
video_rect->y = drv_rect.rect_y;
video_rect->width = drv_rect.rect_w;
video_rect->height = drv_rect.rect_h;
soc_log_info("video_rect->x:%d, video_rect->y:%d, video_rect->width:%d, video_rect->height:%d\n", video_rect->x,
video_rect->y, video_rect->width, video_rect->height);
}
td_s32 uapi_vplugin_catch_stream_ext(td_handle vplugin_handle,
uapi_vplugin_frontout_stream_package *frontout_stream_package,
uapi_vplugin_backin_stream_package *backin_stream_package,
uapi_vplugin_rect_info *rect_info, td_u32 timeout_ms)
{
td_s32 ret;
td_u32 delay_time = 0;
ext_drv_vplugin_rect_info drv_rect_info;
ret = check_stream_valid(frontout_stream_package, backin_stream_package, TD_FALSE);
if (ret != TD_SUCCESS) {
return ret;
}
g_catch_ext_frontout_stream_package.frontout_stream_cnt = frontout_stream_package->frontout_stream_cnt;
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
g_catch_ext_backin_stream_package.backin_stream_cnt =
backin_stream_package->backin_stream_cnt;
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
if (timeout_ms > TIMEOUT_MAX_VALUE_MS) {
soc_log_err("timeout is too big.\n");
return SOC_ERR_VPLUGIN_PARAM_INVALID;
}
do {
ret = ext_mpi_vplugin_catch_stream(vplugin_handle, &g_catch_ext_frontout_stream_package,
&g_catch_ext_backin_stream_package, &drv_rect_info, timeout_ms);
if (ret == TD_SUCCESS) {
ret = transfer_frame(&(frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame),
&g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame,
TD_FALSE);
if (ret != TD_SUCCESS) {
soc_log_err(" transfer_frame failed! ret:%x \n", ret);
}
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
g_catch_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
ret = transfer_frame(&(backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame),
&g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame, TD_FALSE);
if (ret != TD_SUCCESS) {
soc_log_err(" transfer_frame failed! ret:%x \n", ret);
}
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.frame_addr[UAPI_MULTI_VIEW_0].
start_addr = g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.
buf_addr[EXT_DRV_3D_EYE_LEFT].start_addr;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.frame_addr[UAPI_MULTI_VIEW_0].
y_offset = g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.
buf_addr[EXT_DRV_3D_EYE_LEFT].y_offset;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.frame_addr[UAPI_MULTI_VIEW_0].
c_offset = g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.
buf_addr[EXT_DRV_3D_EYE_LEFT].c_offset;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.frame_addr[UAPI_MULTI_VIEW_0].
stride_y = g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].
backin_frame.buf_addr[EXT_DRV_3D_EYE_LEFT].stride_y;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.frame_addr[UAPI_MULTI_VIEW_0].
stride_c = g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].
backin_frame.buf_addr[EXT_DRV_3D_EYE_LEFT].stride_c;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.display_height =
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.height;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.display_width =
g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.width;
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.bit_depth = (int)
(g_catch_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame.bit_width);
transfer_rect_info(&rect_info->video_rect, drv_rect_info.video_rect);
transfer_rect_info(&rect_info->crop_rect, drv_rect_info.crop_rect);
break;
}
delay_time += 1;
usleep(WINDOW_ACQUIRE_FRAME_DELAY);
if (delay_time == timeout_ms) {
soc_log_warn(" catch time out \n");
return SOC_ERR_VPLUGIN_NOT_SUPPORT_CHANGE_PARAM;
}
} while (delay_time <= timeout_ms);
if (ret != TD_SUCCESS) {
soc_log_err("set vplugin server config param failed, ret=0x%x", ret);
}
return ret;
}
td_s32 uapi_vplugin_sendback_stream(td_handle vplugin_handle,
uapi_vplugin_backin_stream_package *backin_stream_package,
uapi_vplugin_frontout_stream_package *frontout_stream_package)
{
td_s32 ret;
ret = check_stream_valid(frontout_stream_package, backin_stream_package, TD_TRUE);
if (ret != TD_SUCCESS) {
return ret;
}
ret = transfer_frame(&(frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame),
&g_sendback_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].frontout_frame,
TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err(" transfer_frame failed! ret:%x \n", ret);
}
g_sendback_ext_frontout_stream_package.frontout_stream_cnt = frontout_stream_package->frontout_stream_cnt;
g_sendback_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_sendback_ext_frontout_stream_package.frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
frontout_stream_package->frontout_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
g_sendback_ext_backin_stream_package.backin_stream_cnt =
backin_stream_package->backin_stream_cnt;
g_sendback_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].stream_valid;
g_sendback_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].frame_vaild =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].frame_vaild;
g_sendback_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid =
backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_EXT_0].stream_valid;
ret = transfer_frame(&(backin_stream_package->backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame),
&(g_sendback_ext_backin_stream_package.backin_stream[UAPI_VPLUGIN_STREAM_MAIN].backin_frame),
TD_TRUE);
if (ret != TD_SUCCESS) {
soc_log_err(" transfer_frame failed! ret:%x \n", ret);
}
ret = ext_mpi_vplugin_sendback_stream(vplugin_handle,
&g_sendback_ext_backin_stream_package,
&g_sendback_ext_frontout_stream_package);
if (ret != TD_SUCCESS) {
soc_log_err("set vplugin server config param failed, ret=0x%x", ret);
return ret;
}
return TD_SUCCESS;
}
#ifdef __cplusplus
#if __cplusplus /* __cplusplus */
}
#endif
#endif