1.修改文件损坏时的代码优化

This commit is contained in:
payton 2023-09-11 15:30:53 +08:00
parent 72d31658a6
commit b480dfb0e8
2 changed files with 304 additions and 138 deletions

View File

@ -16,7 +16,8 @@
#include "PhotoFast.h"
#include <kwrap/cmdsys.h>
#include "DxHunting.h"
#include "UIAppPhoto_Param.h"
#include "DCF.h"
#if HUNTING_CAMERA_MCU == ENABLE
#include <sf_mcu.h>
#endif
@ -104,28 +105,36 @@ static void PhotoFast_SliceEncode_Get_Src_Slice_Info(
PhotoFast_SliceSize_Info *src_info,
const HD_VIDEO_FRAME video_frame)
{
src_info->slice_num = dst_info->slice_num;
src_info->width = video_frame.dim.w;
src_info->height = video_frame.dim.h;
src_info->slice_num = dst_info->slice_num;
src_info->width = video_frame.dim.w;
src_info->height = video_frame.dim.h;
if(src_info->slice_num > 1){
src_info->slice_height = ALIGN_CEIL((src_info->width * dst_info->slice_height) / dst_info->width, 2);
src_info->last_slice_height = ALIGN_CEIL(src_info->height - src_info->slice_height * (src_info->slice_num - 1), 2);
}
else{
src_info->slice_height = video_frame.dim.h;
src_info->last_slice_height = src_info->slice_height;
}
if(src_info->slice_num > 1){
src_info->slice_height = ALIGN_CEIL((src_info->height) / src_info->slice_num, 2);
src_info->last_slice_height = ALIGN_CEIL(src_info->height - src_info->slice_height * (src_info->slice_num - 1), 2);
}
else{
src_info->slice_height = video_frame.dim.h;
src_info->last_slice_height = src_info->slice_height;
}
PHOTOFAST_SLICE_ENC_DUMP("Src Slice Info: size = {%lu,%lu} slice num = {%lu} slice height = {%lu} last slice height = {%lu}\r\n",
src_info->width, src_info->height, src_info->slice_num, src_info->slice_height, src_info->last_slice_height);
if(src_info->slice_height * (src_info->slice_num - 1) >= src_info->height){
DBG_ERR("aligned total slice height(%lu * %lu + %lu = %lu) exceed photo height(%lu)!\n",
src_info->slice_height,
src_info->slice_num - 1,
src_info->last_slice_height,
src_info->height);
}
PHOTOFAST_SLICE_ENC_DUMP("Src Slice Info: size = {%lu,%lu} slice num = {%lu} slice height = {%lu} last slice height = {%lu}\r\n",
src_info->width, src_info->height, src_info->slice_num, src_info->slice_height, src_info->last_slice_height);
}
INT32 PhotoFast_SliceEncode_Get_Max_Dst_Slice_Buffer_Size(HD_VIDEO_PXLFMT pxl_fmt)
{
HD_DIM dim = PhotoFast_SliceEncode_Get_Encode_Max_Size();
UINT32 reserved_buffer = 0;
UINT32 max_buffer_size = VDO_YUV_BUFSIZE(dim.w, dim.h, pxl_fmt) + reserved_buffer;
UINT32 max_buffer_size = VDO_YUV_BUFSIZE(ALIGN_CEIL(dim.w, 16), ALIGN_CEIL(dim.h, 16), pxl_fmt) + reserved_buffer;
return max_buffer_size;
}
@ -135,11 +144,17 @@ static INT32 PhotoFast_SliceEncode_Get_Dst_Slice_Info(PhotoFast_SliceSize_Info *
info->width = cap_size_w;
info->height = cap_size_h;
info->slice_num = slice_num;
info->slice_height = ALIGN_CEIL_16(info->height / info->slice_num);
if(info->height == 1080 && slice_num == 1){
info->slice_height = info->height;
}
else{
info->slice_height = ALIGN_CEIL_16(info->height / info->slice_num);
}
if(info->slice_height * (info->slice_num - 1) > info->height){
DBG_ERR("calculate last slice height error!\n");
DBG_ERR("calculate last slice height error!(slice_height = %lu, slice_num = %lu, photo height = %lu)\n", info->slice_height, info->slice_num, info->height);
return E_SYS;
}
@ -151,33 +166,136 @@ static INT32 PhotoFast_SliceEncode_Get_Dst_Slice_Info(PhotoFast_SliceSize_Info *
return E_OK;
}
INT32 PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(PhotoFast_SliceSize_Info *info)
INT32 PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(PhotoFast_SliceSize_Info *info, const HD_VIDEO_FRAME src_frame)
{
UINT32 cap_size_w = GetPhotoSizeWidth(SysGetFlag(FL_PHOTO_SIZE));
UINT32 cap_size_h = GetPhotoSizeHeight(SysGetFlag(FL_PHOTO_SIZE));
UINT32 max_slice_num;
UINT32 slice_num;
unsigned int cap_size = cap_size_w * cap_size_h;
unsigned int buf_size = CFG_PHOTOFAST_SLICE_ENC_PRIMARY_BUF_WIDTH * CFG_PHOTOFAST_SLICE_ENC_PRIMARY_BUF_HEIGHT;
if(buf_size > cap_size){
max_slice_num = 1;
slice_num = 1;
}
else{
PHOTOFAST_SLICE_ENC_DUMP("cap_size = %lu buf_size = %lu\n", cap_size, buf_size);
UINT32 lines = (buf_size / cap_size_w);
slice_num = cap_size_h / lines + (cap_size_h % lines ? 1 : 0);
max_slice_num = cap_size_h / lines + (cap_size_h % lines ? 1 : 0);
UINT32 tmp_src_h = src_frame.dim.h / 2;
UINT32 tmp_dst_h = cap_size_h / 16;
UINT32 found_common_factor = 0;
UINT32 i;
for (i = 1; i <= (tmp_src_h > tmp_dst_h ? tmp_dst_h : tmp_src_h) ; ++i)
{
if (tmp_src_h % i == 0 && tmp_dst_h % i == 0)
{
PHOTOFAST_SLICE_ENC_DUMP("common factor = %d\n", i);
if(max_slice_num < i){
found_common_factor = i;
break;
}
}
}
if(found_common_factor){
slice_num = found_common_factor;
PHOTOFAST_SLICE_ENC_DUMP("use common factor %d\n ", slice_num);
}
else{
slice_num = max_slice_num;
PHOTOFAST_SLICE_ENC_DUMP("use max slice num %d\n ", slice_num);
}
}
return PhotoFast_SliceEncode_Get_Dst_Slice_Info(info, cap_size_w, cap_size_h, slice_num);
}
static HD_DIM PhotoFast_SliceEncode_Get_Encode_Max_Size()
static UINT32 PhotoFast_SliceEncode_Get_Max_Dst_Slice_Info(PhotoFast_SliceSize_Info *info)
{
static PhotoFast_SliceSize_Info max_slice_info = {0};
UINT32 max_slice_num;
UINT32 slice_num;
INT32 ret = E_OK;
UIAPP_PHOTO_SENSOR_INFO *sensor_info = UIAppPhoto_get_SensorInfo(0);
unsigned int buf_size = CFG_PHOTOFAST_SLICE_ENC_PRIMARY_BUF_WIDTH * CFG_PHOTOFAST_SLICE_ENC_PRIMARY_BUF_HEIGHT;
/* search max slice (slice height * slice width) */
if(!max_slice_info.slice_height || !max_slice_info.width){
UINT8 cap_idx = 0;
for(cap_idx = PHOTO_MAX_CAP_SIZE ; cap_idx <= PHOTO_SLICE_ENC_MIN_CAP_SIZE ; cap_idx++)
{
HD_DIM tmp_cap_size = {0};
PhotoFast_SliceSize_Info tmp_slice_info = {0};
tmp_cap_size = (HD_DIM){GetPhotoSizeWidth(cap_idx), GetPhotoSizeHeight(cap_idx)};
if(buf_size > (tmp_cap_size.w * tmp_cap_size.h)){
max_slice_num = 1;
slice_num = 1;
}
else{
PHOTOFAST_SLICE_ENC_DUMP("cap_size = %lu buf_size = %lu\n", tmp_cap_size.w * tmp_cap_size.h, buf_size);
UINT32 lines = (buf_size / tmp_cap_size.w);
max_slice_num = tmp_cap_size.h / lines + (tmp_cap_size.h % lines ? 1 : 0);
UINT32 tmp_src_h = sensor_info->sSize.h / 2;
UINT32 tmp_dst_h = tmp_cap_size.h / 16;
UINT32 found_common_factor = 0;
UINT32 i;
for (i = 1; i <= (tmp_src_h > tmp_dst_h ? tmp_dst_h : tmp_src_h) ; ++i)
{
if (tmp_src_h % i == 0 && tmp_dst_h % i == 0)
{
PHOTOFAST_SLICE_ENC_DUMP("common factor = %d\n", i);
if(max_slice_num < i){
found_common_factor = i;
break;
}
}
}
if(found_common_factor){
slice_num = found_common_factor;
PHOTOFAST_SLICE_ENC_DUMP("use common factor %d\n ", slice_num);
}
else{
slice_num = max_slice_num;
PHOTOFAST_SLICE_ENC_DUMP("use max slice num %d\n ", slice_num);
}
}
ret = PhotoFast_SliceEncode_Get_Dst_Slice_Info(&tmp_slice_info, tmp_cap_size.w, tmp_cap_size.h, slice_num);
if((tmp_slice_info.slice_height * tmp_slice_info.width) > (max_slice_info.slice_height * max_slice_info.width)){
max_slice_info = tmp_slice_info;
}
}
PHOTOFAST_SLICE_ENC_DUMP("max dst slice = {%lu, %lu}, cap idx = %lu\n", max_slice_info.width, max_slice_info.slice_height, cap_idx);
}
*info = max_slice_info;
return ret;
}
static HD_DIM PhotoFast_SliceEncode_Get_Encode_Max_Size(void)
{
PhotoFast_SliceSize_Info info;
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&info) != E_OK)
if(PhotoFast_SliceEncode_Get_Max_Dst_Slice_Info(&info) != E_OK)
return (HD_DIM){0, 0};
HD_DIM dim_max_slice = {info.width, info.slice_height};
@ -187,7 +305,7 @@ static HD_DIM PhotoFast_SliceEncode_Get_Encode_Max_Size()
static UINT32 PhotoFast_SliceEncode_Get_Encode_Max_Bitrate(HD_VIDEO_PXLFMT vproc_out_pxlfmt)
{
const UINT32 ratio = 4;
const UINT32 ratio = CFG_PHOTOFAST_SLICE_ENC_BS_BUF_RATIO;
UINT32 bitrate;
HD_DIM dim = PhotoFast_SliceEncode_Get_Encode_Max_Size();
@ -307,7 +425,7 @@ INT32 PhotoFast_SliceEncode_Open(const HD_PATH_ID vproc_path_id)
HD_OUT_ID out = HD_VIDEOENC_OUT(0, first_out_port);
/* calculate dst slice info */
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info) != E_OK){
if(PhotoFast_SliceEncode_Get_Max_Dst_Slice_Info(&dst_slice_info) != E_OK){
goto EXIT;
}
@ -317,13 +435,15 @@ INT32 PhotoFast_SliceEncode_Open(const HD_PATH_ID vproc_path_id)
ret = hd_videoproc_get(vproc_path_id, HD_VIDEOPROC_PARAM_OUT, (VOID*)&vproc_out);
if(ret != HD_OK){
DBG_ERR("hd_videoproc_get HD_VIDEOPROC_PARAM_OUT failed(path_id=%lx, ret=%d)!", vproc_path_id, ret);
goto EXIT;
vproc_out_pxlfmt = HD_VIDEO_PXLFMT_YUV420;
}
vproc_out_pxlfmt = vproc_out.pxlfmt;
else{
vproc_out_pxlfmt = vproc_out.pxlfmt;
}
}
if ((ret = hd_videoenc_init()) != HD_OK){
ret = hd_videoenc_init();
if (ret != HD_OK && ret != HD_ERR_UNINIT){
DBG_ERR("hd_videoenc_init failed (%d)\r\n", ret);
goto EXIT;
}
@ -350,7 +470,7 @@ INT32 PhotoFast_SliceEncode_Open(const HD_PATH_ID vproc_path_id)
/* calculate max buffer for slice */
info->yuv_buf_mem_info.blk_size = PhotoFast_SliceEncode_Get_Max_Dst_Slice_Buffer_Size(vproc_out_pxlfmt);
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&max_info) != E_OK)
if(PhotoFast_SliceEncode_Get_Max_Dst_Slice_Info(&max_info) != E_OK)
goto EXIT;
bitrate = PhotoFast_SliceEncode_Get_Encode_Max_Bitrate(vproc_out_pxlfmt);
@ -570,99 +690,101 @@ static INT32 PhotoFast_SliceEncode_Get_Enc_Buffer_Info(const HD_PATH_ID enc_path
}
static INT32 PhotoFast_SliceEncode_Init_VF_GFX_Slice(
VF_GFX_SCALE* vf_gfx_scale_param,
const HD_VIDEO_FRAME* video_frame,
const PhotoFast_MEM_Info dst_buffer_info,
const PhotoFast_SliceSize_Info src_slice_info,
const PhotoFast_SliceSize_Info dst_slice_info,
const UINT8 slice_idx)
VF_GFX_SCALE* vf_gfx_scale_param,
const HD_VIDEO_FRAME* video_frame,
const PhotoFast_MEM_Info dst_buffer_info,
const PhotoFast_SliceSize_Info src_slice_info,
const PhotoFast_SliceSize_Info dst_slice_info,
const UINT8 slice_idx)
{
HD_RESULT ret;
UINT32 addr_src[HD_VIDEO_MAX_PLANE] = {0};
UINT32 addr_dst[HD_VIDEO_MAX_PLANE] = {0};
UINT32 loff_src[HD_VIDEO_MAX_PLANE] = {0};
UINT32 loff_dst[HD_VIDEO_MAX_PLANE] = {0};
UINT32 offset;
UINT32 scr_slice_height = (slice_idx == (src_slice_info.slice_num - 1)) ? src_slice_info.last_slice_height : src_slice_info.slice_height;
UINT32 dst_slice_height = (slice_idx == (dst_slice_info.slice_num - 1)) ? dst_slice_info.last_slice_height : dst_slice_info.slice_height;
UINT32 dst_scale_slice_height = (slice_idx == (dst_slice_info.slice_num - 1)) ? (src_slice_info.last_slice_height * dst_slice_info.slice_height / src_slice_info.slice_height) : dst_slice_info.slice_height;
HD_RESULT ret;
UINT32 addr_src[HD_VIDEO_MAX_PLANE] = {0};
UINT32 addr_dst[HD_VIDEO_MAX_PLANE] = {0};
UINT32 loff_src[HD_VIDEO_MAX_PLANE] = {0};
UINT32 loff_dst[HD_VIDEO_MAX_PLANE] = {0};
UINT32 offset;
UINT32 scr_slice_height = (slice_idx == (src_slice_info.slice_num - 1)) ? src_slice_info.last_slice_height : src_slice_info.slice_height;
UINT32 dst_slice_height = (slice_idx == (dst_slice_info.slice_num - 1)) ? dst_slice_info.last_slice_height : dst_slice_info.slice_height;
UINT32 dst_scale_slice_height = (slice_idx == (dst_slice_info.slice_num - 1)) ? (src_slice_info.last_slice_height * dst_slice_info.slice_height / src_slice_info.slice_height) : dst_slice_info.slice_height;
/* dst img */
addr_dst[0] = dst_buffer_info.pa;
loff_dst[0] = dst_slice_info.width;
addr_dst[1] = addr_dst[0] + loff_dst[0] * dst_slice_height;
loff_dst[1] = dst_slice_info.width;
ret = vf_init_ex(&vf_gfx_scale_param->dst_img, dst_slice_info.width, dst_slice_height, video_frame->pxlfmt, loff_dst, addr_dst);
if (ret != HD_OK) {
DBG_ERR("vf_init_ex dst failed(%d)\r\n", ret);
return E_SYS;
}
/* dst img */
addr_dst[0] = dst_buffer_info.pa;
loff_dst[0] = dst_slice_info.width;
addr_dst[1] = addr_dst[0] + loff_dst[0] * dst_slice_height;
loff_dst[1] = dst_slice_info.width;
ret = vf_init_ex(&vf_gfx_scale_param->dst_img, dst_slice_info.width, dst_slice_height, video_frame->pxlfmt, loff_dst, addr_dst);
if (ret != HD_OK) {
DBG_ERR("vf_init_ex dst failed(%d)\r\n", ret);
return E_SYS;
}
vf_gfx_scale_param->engine = 0;
vf_gfx_scale_param->src_region.x = 0;
vf_gfx_scale_param->src_region.y = 0;
vf_gfx_scale_param->src_region.w = src_slice_info.width;
vf_gfx_scale_param->src_region.h = scr_slice_height;
vf_gfx_scale_param->dst_region.x = 0;
vf_gfx_scale_param->dst_region.y = 0;
vf_gfx_scale_param->dst_region.w = dst_slice_info.width;
vf_gfx_scale_param->dst_region.h = dst_scale_slice_height;
vf_gfx_scale_param->dst_img.blk = dst_buffer_info.blk;
vf_gfx_scale_param->quality = HD_GFX_SCALE_QUALITY_NULL;
vf_gfx_scale_param->engine = 0;
vf_gfx_scale_param->src_region.x = 0;
vf_gfx_scale_param->src_region.y = 0;
vf_gfx_scale_param->src_region.w = src_slice_info.width;
vf_gfx_scale_param->src_region.h = scr_slice_height;
vf_gfx_scale_param->dst_region.x = 0;
vf_gfx_scale_param->dst_region.y = 0;
vf_gfx_scale_param->dst_region.w = dst_slice_info.width;
vf_gfx_scale_param->dst_region.h = dst_scale_slice_height;
vf_gfx_scale_param->dst_img.blk = dst_buffer_info.blk;
vf_gfx_scale_param->quality = HD_GFX_SCALE_QUALITY_NULL;
offset = video_frame->loff[HD_VIDEO_PINDEX_Y] * slice_idx * src_slice_info.slice_height;
offset = video_frame->loff[HD_VIDEO_PINDEX_Y] * slice_idx * src_slice_info.slice_height;
addr_src[0] = video_frame->phy_addr[HD_VIDEO_PINDEX_Y] + offset;
addr_src[1] = video_frame->phy_addr[HD_VIDEO_PINDEX_UV] + offset/2;
addr_src[0] = video_frame->phy_addr[HD_VIDEO_PINDEX_Y] + offset;
addr_src[1] = video_frame->phy_addr[HD_VIDEO_PINDEX_UV] + offset/2;
loff_src[0] = video_frame->loff[HD_VIDEO_PINDEX_Y];
loff_src[1] = video_frame->loff[HD_VIDEO_PINDEX_UV];
if ((ret = vf_init_ex(&vf_gfx_scale_param->src_img, src_slice_info.width, scr_slice_height, video_frame->pxlfmt, loff_src, addr_src)) != HD_OK) {
DBG_ERR("vf_init_ex dst failed(%d)\r\n", ret);
return E_SYS;
}
if ((ret = vf_init_ex(&vf_gfx_scale_param->src_img, src_slice_info.width, scr_slice_height, video_frame->pxlfmt, loff_src, addr_src)) != HD_OK) {
DBG_ERR("vf_init_ex dst failed(%d)\r\n", ret);
return E_SYS;
}
PHOTOFAST_SLICE_ENC_DUMP("[Slice %lu] src dim{%lu, %lu} src region{%lu, %lu, %lu, %lu} addr{y:%lx uv:%lx}\r\n",
slice_idx,
vf_gfx_scale_param->src_img.dim.w,
vf_gfx_scale_param->src_img.dim.h,
vf_gfx_scale_param->src_region.x,
vf_gfx_scale_param->src_region.y,
vf_gfx_scale_param->src_region.w,
vf_gfx_scale_param->src_region.h,
addr_src[0], addr_src[1]
);
PHOTOFAST_SLICE_ENC_DUMP("[Slice %lu] src dim{%lu, %lu} src region{%lu, %lu, %lu, %lu} addr{y:%lx uv:%lx}\r\n",
slice_idx,
vf_gfx_scale_param->src_img.dim.w,
vf_gfx_scale_param->src_img.dim.h,
vf_gfx_scale_param->src_region.x,
vf_gfx_scale_param->src_region.y,
vf_gfx_scale_param->src_region.w,
vf_gfx_scale_param->src_region.h,
addr_src[0], addr_src[1]
);
PHOTOFAST_SLICE_ENC_DUMP("[Slice %lu] dst dim{%lu, %lu} dst region{%lu, %lu, %lu, %lu} addr{y:%lx uv:%lx}\r\n",
slice_idx,
vf_gfx_scale_param->dst_img.dim.w,
vf_gfx_scale_param->dst_img.dim.h,
vf_gfx_scale_param->dst_region.x,
vf_gfx_scale_param->dst_region.y,
vf_gfx_scale_param->dst_region.w,
vf_gfx_scale_param->dst_region.h,
addr_dst[0], addr_dst[1]
);
PHOTOFAST_SLICE_ENC_DUMP("[Slice %lu] dst dim{%lu, %lu} dst region{%lu, %lu, %lu, %lu} addr{y:%lx uv:%lx}\r\n",
slice_idx,
vf_gfx_scale_param->dst_img.dim.w,
vf_gfx_scale_param->dst_img.dim.h,
vf_gfx_scale_param->dst_region.x,
vf_gfx_scale_param->dst_region.y,
vf_gfx_scale_param->dst_region.w,
vf_gfx_scale_param->dst_region.h,
addr_dst[0], addr_dst[1]
);
if(slice_idx == (dst_slice_info.slice_num - 1)){
if(slice_idx == (dst_slice_info.slice_num - 1) &&
dst_scale_slice_height < dst_slice_info.last_slice_height
){
HD_GFX_DRAW_RECT draw_rect = {0};
HD_GFX_DRAW_RECT draw_rect = {0};
draw_rect.dst_img.dim = vf_gfx_scale_param->dst_img.dim;
draw_rect.dst_img.ddr_id = vf_gfx_scale_param->dst_img.ddr_id;
draw_rect.dst_img.format = vf_gfx_scale_param->dst_img.pxlfmt;
draw_rect.dst_img.p_phy_addr[0] = vf_gfx_scale_param->dst_img.phy_addr[0];
draw_rect.dst_img.p_phy_addr[1] = vf_gfx_scale_param->dst_img.phy_addr[1];
draw_rect.dst_img.lineoffset[0] = vf_gfx_scale_param->dst_img.loff[0];
draw_rect.dst_img.lineoffset[1] = vf_gfx_scale_param->dst_img.loff[1];
draw_rect.dst_img.dim = vf_gfx_scale_param->dst_img.dim;
draw_rect.dst_img.ddr_id = vf_gfx_scale_param->dst_img.ddr_id;
draw_rect.dst_img.format = vf_gfx_scale_param->dst_img.pxlfmt;
draw_rect.dst_img.p_phy_addr[0] = vf_gfx_scale_param->dst_img.phy_addr[0];
draw_rect.dst_img.p_phy_addr[1] = vf_gfx_scale_param->dst_img.phy_addr[1];
draw_rect.dst_img.lineoffset[0] = vf_gfx_scale_param->dst_img.loff[0];
draw_rect.dst_img.lineoffset[1] = vf_gfx_scale_param->dst_img.loff[1];
draw_rect.color = LV_USER_CFG_STAMP_COLOR_BACKGROUND;
draw_rect.thickness = 1;
draw_rect.type = HD_GFX_RECT_SOLID;
draw_rect.rect = (HD_IRECT){0, 0, vf_gfx_scale_param->dst_img.dim.w, vf_gfx_scale_param->dst_img.dim.h};
hd_gfx_draw_rect(&draw_rect);
}
draw_rect.thickness = 1;
draw_rect.type = HD_GFX_RECT_SOLID;
draw_rect.rect = (HD_IRECT){0, 0, vf_gfx_scale_param->dst_img.dim.w, vf_gfx_scale_param->dst_img.dim.h};
hd_gfx_draw_rect(&draw_rect);
}
return E_OK;
return E_OK;
}
#if 1//PHOTOFAST_SLICE_ENC_DBG_PRIMARY_YUV
@ -1116,7 +1238,7 @@ EXIT:
DBG_ERR("hd_videoenc_stop failed(%d)\r\n", ret);
}
return (ret == HD_OK) ? E_OK : E_SYS;
return (ret == HD_OK) ? E_OK : ret;
}
@ -1196,7 +1318,6 @@ static INT32 PhotoFast_SliceEncode_Encode_Primary(
dst_slice_info,
slice_idx);
if(vf_gfx_scale(&vf_gfx_scale_param, 1) != HD_OK){
goto EXIT;
}
@ -1427,15 +1548,18 @@ INT32 PhotoFast_SliceEncode(const HD_PATH_ID vproc_path_id, const HD_VIDEO_FRAME
ret = hd_videoproc_get(vproc_path_id, HD_VIDEOPROC_PARAM_OUT, (VOID*)&vproc_out);
if(ret != HD_OK){
DBG_ERR("hd_videoproc_get HD_VIDEOPROC_PARAM_OUT failed(path_id=%lx, ret=%d)!", vproc_path_id, ret);
goto EXIT;
vproc_out_pxlfmt = HD_VIDEO_PXLFMT_YUV420;
}
else{
vproc_out_pxlfmt = vproc_out.pxlfmt;
}
vproc_out_pxlfmt = vproc_out.pxlfmt;
/*******************************************************************
* Calculate dst slice info
******************************************************************/
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info) != E_OK){
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info, video_frame) != E_OK){
return NVTEVT_CONSUME;
}
@ -1482,11 +1606,12 @@ INT32 PhotoFast_SliceEncode(const HD_PATH_ID vproc_path_id, const HD_VIDEO_FRAME
}
// slice_encode_primary_info->bs_buf_mem_info.blk_size = (VDO_YUV_BUFSIZE(dst_slice_info.width, dst_slice_info.height, video_frame.pxlfmt) / (CFG_PHOTOFAST_SLICE_ENC_BS_BUF_RATIO)) + CFG_JPG_HEADER_SIZE + PhotoFast_GetScreenNailSize() ;
slice_encode_primary_info->bs_buf_mem_info.blk_size = ((PhotoFast_SliceEncode_Get_Encode_Max_Bitrate(HD_VIDEO_PXLFMT_YUV420)/ 8) * (dst_slice_info.slice_num + 2)) + CFG_JPG_HEADER_SIZE + PhotoFast_GetScreenNailSize() ;
slice_encode_primary_info->bs_buf_mem_info.blk_size = ((PhotoFast_SliceEncode_Get_Encode_Max_Bitrate(HD_VIDEO_PXLFMT_YUV420)/ 8) * (dst_slice_info.slice_num + 1)) + CFG_JPG_HEADER_SIZE + PhotoFast_GetScreenNailSize() ;
if(PhotoFast_SliceEncode_Alloc_Buffer(&slice_encode_primary_info->bs_buf_mem_info, "slice_enc_primary") != E_OK){
goto EXIT;
}
PhotoFastCapDateImprint_GenYuvData(&video_frame);
/* check free mem */
#if POWERON_FAST_BOOT_MSG == ENABLE
nvt_cmdsys_runcmd("nvtmpp info");
@ -1617,7 +1742,7 @@ INT32 PhotoFast_SliceEncode(const HD_PATH_ID vproc_path_id, const HD_VIDEO_FRAME
DBG_DUMP("elapsed time of slice encode without write file = %lu us\n", tick_end - tick_start);
extern INT32 PhotoFast_WriteFile(UINT32 Addr, UINT32 Size, UINT32 Fmt, UINT32 uiPathId);
extern INT32 PhotoFast_WriteFile(UINT32 Addr, UINT32 Size, UINT32 Fmt, UINT32 uiPathId, char* path);
if(fastboot_wait_done_timeout(BOOT_INIT_FILESYSOK, FASTBOOT_WAIT_FILESYS_TIMEOUT_MS) != E_OK){
@ -1632,6 +1757,7 @@ INT32 PhotoFast_SliceEncode(const HD_PATH_ID vproc_path_id, const HD_VIDEO_FRAME
dst_jpg_file.addr,
dst_jpg_file.size,
NAMERULE_FMT_JPG,
0,
0);
EXIT:
@ -1740,6 +1866,12 @@ typedef struct {
PhotoFast_MEM_Info mem_info_combined;
PhotoFast_MEM_Info mem_info_thumb;
PhotoFast_SliceEncode_Queue_Comm_Param comm;
#if PHOTOFAST_FAST_CLOSE
char file_path[NMC_TOTALFILEPATH_MAX_LEN];
UINT32 nextFolderID;
UINT32 nextFileID;
#endif
} PhotoFast_SliceEncode_Queue23_Param;
typedef struct {
@ -1841,17 +1973,11 @@ INT32 PhotoFast_SliceEncode_CB2(void* user_data)
hd_ret = hd_videoproc_get(vproc_path_id, HD_VIDEOPROC_PARAM_OUT, (VOID*)&vproc_out);
if(hd_ret != HD_OK){
DBG_ERR("hd_videoproc_get HD_VIDEOPROC_PARAM_OUT failed(path_id=%lx, ret=%d)!", vproc_path_id, ret);
goto EXIT;
}
vproc_out_pxlfmt = vproc_out.pxlfmt;
/*******************************************************************
* Calculate dst slice info
******************************************************************/
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info) != E_OK){
return NVTEVT_CONSUME;
vproc_out_pxlfmt = HD_VIDEO_PXLFMT_YUV420;
}
else{
vproc_out_pxlfmt = vproc_out.pxlfmt;
}
/* pull out vprc frame is in the CB1 */
@ -1894,7 +2020,21 @@ INT32 PhotoFast_SliceEncode_CB2(void* user_data)
goto EXIT;
}
DBG_IND("process frame %lu\n", param->cnt);
DBG_DUMP("process frame %lu\n", param->cnt);
/*******************************************************************
* Fast Stamp (higher speed, lower quality)
******************************************************************/
#if PHOTOFAST_FAST_STAMP
PhotoFastCapDateImprint_GenYuvData(&queue_ele_in->frame);
#endif
/*******************************************************************
* Calculate dst slice info
******************************************************************/
if(PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(&dst_slice_info, queue_ele_in->frame) != E_OK){
goto EXIT;
}
/*******************************************************************
* Calculate src slice info
@ -1921,13 +2061,6 @@ INT32 PhotoFast_SliceEncode_CB2(void* user_data)
goto EXIT;
}
/*******************************************************************
* Fast Stamp (higher speed, lower quality)
******************************************************************/
#if PHOTOFAST_FAST_STAMP
PhotoFastCapDateImprint_GenYuvData(&queue_ele_in->frame);
#endif
/*******************************************************************
* Screennail & Thumbnail Scale
******************************************************************/
@ -2041,6 +2174,16 @@ INT32 PhotoFast_SliceEncode_CB2(void* user_data)
queue_ele_out->mem_info_combined = slice_encode_primary_info->bs_buf_mem_info;
queue_ele_out->mem_info_thumb = slice_encode_screennail_info->bs_buf_mem_info;
#if PHOTOFAST_FAST_CLOSE
UINT32 nextFolderID = 0, nextFileID = 0;
DCF_GetNextID(&nextFolderID,&nextFileID);
queue_ele_out->nextFolderID = nextFolderID;
queue_ele_out->nextFileID = nextFileID;
DCF_MakeObjPath(nextFolderID, nextFileID, DCF_FILE_TYPE_JPG, queue_ele_out->file_path);
DCF_AddDBfile(queue_ele_out->file_path);
DBG_DUMP("%s added to DCF\r\n", queue_ele_out->file_path);
#endif
while (lfqueue_enq(param->queue23, (void*) queue_ele_out) == -1)
{
DBG_ERR("ENQ Full ?\r\n");
@ -2125,7 +2268,7 @@ INT32 PhotoFast_SliceEncode_CB3(void* user_data)
/*******************************************************************
* Output jpg file
******************************************************************/
extern INT32 PhotoFast_WriteFile(UINT32 Addr, UINT32 Size, UINT32 Fmt, UINT32 uiPathId);
extern INT32 PhotoFast_WriteFile(UINT32 Addr, UINT32 Size, UINT32 Fmt, UINT32 uiPathId, char* Path);
if(fastboot_wait_done_timeout(BOOT_INIT_FILESYSOK, FASTBOOT_WAIT_FILESYS_TIMEOUT_MS) != E_OK){
goto EXIT;
@ -2135,17 +2278,40 @@ INT32 PhotoFast_SliceEncode_CB3(void* user_data)
goto EXIT;
}
#if !PHOTOFAST_FAST_CLOSE
PhotoFast_WriteFile(
(UINT32)queue_ele_in->jpg_combined_addr,
queue_ele_in->jpg_combined_size,
NAMERULE_FMT_JPG,
0,
0);
#else
PhotoFast_WriteFile(
(UINT32)queue_ele_in->jpg_combined_addr,
queue_ele_in->jpg_combined_size,
NAMERULE_FMT_JPG,
0,
queue_ele_in->file_path);
#endif
{
extern CHAR* PhotoFast_GetLastWriteFilePath(void);
char* file_path = PhotoFast_GetLastWriteFilePath();
char tmp[256] = {'\0'};
char tmp[NMC_TOTALFILEPATH_MAX_LEN] = {'\0'};
#if !PHOTOFAST_FAST_CLOSE
extern CHAR* PhotoFast_GetLastWriteFilePath(void);
char* file_path = PhotoFast_GetLastWriteFilePath();
#else
char file_path[NMC_TOTALFILEPATH_MAX_LEN];
#if HUNTING_CAMERA_MCU == ENABLE
sprintf(tmp, "W%03ld%04ld.JPG", queue_ele_in->nextFolderID, queue_ele_in->nextFileID);
strncpy(file_path, tmp, strlen(queue_ele_in->file_path) - 1);
DBG_IND("last send file:%s\r\n", file_path);
#else
strncpy(file_path, FilePath, strlen(queue_ele_in->file_path) - 1);
#endif
#endif
#if HUNTING_CAMERA_MCU == ENABLE
char tmp2[64] = {'\0'};
#endif

View File

@ -31,7 +31,7 @@ typedef struct
INT32 PhotoFast_SliceEncode_Open(const HD_PATH_ID vproc_path_id);
INT32 PhotoFast_SliceEncode_Close(void);
INT32 PhotoFast_SliceEncode(const HD_PATH_ID vproc_path_id, const HD_VIDEO_FRAME *p_video_frame);
INT32 PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(PhotoFast_SliceSize_Info *info);
INT32 PhotoFast_SliceEncode_Get_Curr_Dst_Slice_Info(PhotoFast_SliceSize_Info *info, const HD_VIDEO_FRAME src_frame);
INT32 PhotoFast_SliceEncode_Get_Max_Dst_Slice_Buffer_Size(HD_VIDEO_PXLFMT pxl_fmt);
#if POWERON_FAST_SLICE_ENC_VER2 == ENABLE