multimedia/device/mpp/tools/rc_attr.c

224 lines
6.2 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hi_common.h"
#include "hi_comm_video.h"
#include "hi_comm_sys.h"
#include "hi_comm_vo.h"
#include "hi_comm_rc.h"
#include "hi_comm_venc.h"
#include "mpi_vb.h"
#include "mpi_sys.h"
#include "mpi_vi.h"
#include "mpi_vo.h"
#include "mpi_venc.h"
#define USAGE_HELP(void)\
{\
printf("\n\tusage : %s group para value\n", argv[0]); \
printf("\n\t para: \n"); \
printf("\tstattime [ͳ<><CDB3>ʱ<EFBFBD><CAB1>,<2C><>λ:<3A><>\n"); \
printf("\t bitrate <20><><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>λ:kbps\n"); \
printf("\tgop <20><><EFBFBD><EFBFBD><49>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ:֡\n"); \
printf("\tqpdelta I֡<49><D6A1><50><D6A1><EFBFBD><EFBFBD>QP<51><50><EFBFBD><EFBFBD><ECA3AC><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ЧӦ<D0A7><D3A6><EFBFBD><EFBFBD>\n"); \
printf("\tmqpdelta <20>ں<EFBFBD><DABA><EFBFBD><E9BCB6><EFBFBD>ʿ<EFBFBD><CABF><EFBFBD>ʱ<EFBFBD><CAB1>ÿһ<C3BF>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼQp<51><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʼQp<51>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ\n"); \
printf("\tmaxqp <20><><EFBFBD><EFBFBD>QPԼ<50><D4BC>\n"); \
}
#define CHECK_RET(express,name)\
do{\
if (HI_SUCCESS != express)\
{\
printf("%s failed at %s: LINE: %d ! errno:%d \n",\
name, __FUNCTION__, __LINE__, express);\
return HI_FAILURE;\
}\
}while(0)
HI_S32 main(int argc, char* argv[])
{
HI_S32 s32Ret;
HI_S32 s32EncChn;
HI_CHAR para[16];
HI_U32 value = 0;
HI_U32 i;
VENC_RC_MODE_E eMode;
VENC_RC_PARAM_S stVencRcParam;
VENC_CHN_ATTR_S stVencChnAttr;
if (argc < 3)
{
USAGE_HELP();
return -1;
}
s32EncChn = 0;
s32EncChn = atoi(argv[1]);
strcpy(para, argv[2]);
s32Ret = HI_MPI_VENC_GetRcParam(s32EncChn, &stVencRcParam);
CHECK_RET(s32Ret, "get Rc param");
s32Ret = HI_MPI_VENC_GetChnAttr(s32EncChn, &stVencChnAttr);
CHECK_RET(s32Ret, "get Rc Attr");
eMode = stVencChnAttr.stRcAttr.enRcMode;
if (0 == strcmp(para, "?"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
printf("\tstattime %d\n", stVencChnAttr.stRcAttr.stAttrH264Cbr.u32StatTime);
printf("\tbitrate %d\n", stVencChnAttr.stRcAttr.stAttrH264Cbr.u32BitRate);
printf("\tgop %d\n", stVencChnAttr.stRcAttr.stAttrH264Cbr.u32Gop);
printf("\tqpdelta %d\n", stVencRcParam.stParamH264Cbr.s32IPQPDelta);
printf("\tmaxqp %d\n", stVencRcParam.stParamH264Cbr.u32MaxQp);
}
else
{
printf("\tstattime %d\n", stVencChnAttr.stRcAttr.stAttrH265Cbr.u32StatTime);
printf("\tbitrate %d\n", stVencChnAttr.stRcAttr.stAttrH265Cbr.u32BitRate);
printf("\tgop %d\n", stVencChnAttr.stRcAttr.stAttrH265Cbr.u32Gop);
printf("\tqpdelta %d\n", stVencRcParam.stParamH265Cbr.s32IPQPDelta);
printf("\tmaxqp %d\n", stVencRcParam.stParamH265Cbr.u32MaxQp);
}
printf("\tmqpdelta %d\n", stVencRcParam.u32RowQpDelta);
return 0;
}
value = atoi(argv[3]);
printf("chn %d, para %s, value %d\n", s32EncChn, para, value);
if (0 == strcmp(para, "stattime"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencChnAttr.stRcAttr.stAttrH264Cbr.u32StatTime = value;
}
else
{
stVencChnAttr.stRcAttr.stAttrH265Cbr.u32StatTime = value;
}
}
if (0 == strcmp(para, "thresh") && argc == 15)
{
for (i = 0; i < 12; i++)
{
stVencRcParam.u32ThrdI[i] = atoi(argv[i + 3]);
stVencRcParam.u32ThrdP[i] = atoi(argv[i + 3]);
}
}
if (0 == strcmp(para, "pthresh") && argc == 15)
{
for (i = 0; i < 12; i++)
{
stVencRcParam.u32ThrdP[i] = atoi(argv[i + 3]);
}
}
else if (0 == strcmp(para, "bitrate"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencChnAttr.stRcAttr.stAttrH264Cbr.u32BitRate = value;
}
else
{
stVencChnAttr.stRcAttr.stAttrH265Cbr.u32BitRate = value;
}
}
else if ( 0 == strcmp(para, "framerate"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencChnAttr.stRcAttr.stAttrH264Cbr.fr32DstFrmRate = value;
}
else
{
stVencChnAttr.stRcAttr.stAttrH265Cbr.fr32DstFrmRate = value;
}
}
else if (0 == strcmp(para, "gop"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencChnAttr.stRcAttr.stAttrH264Cbr.u32Gop = value;
}
else
{
stVencChnAttr.stRcAttr.stAttrH265Cbr.u32Gop = value;
}
}
else if (0 == strcmp(para, "flut"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencChnAttr.stRcAttr.stAttrH264Cbr.u32FluctuateLevel = value;
}
else
{
stVencChnAttr.stRcAttr.stAttrH265Cbr.u32FluctuateLevel = value;
}
}
else if (0 == strcmp(para, "qpdelta"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencRcParam.stParamH264Cbr.s32IPQPDelta = value;
}
else
{
stVencRcParam.stParamH265Cbr.s32IPQPDelta = value;
}
}
else if (0 == strcmp(para, "maxqp"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencRcParam.stParamH264Cbr.u32MaxQp = value;
}
else
{
stVencRcParam.stParamH265Cbr.u32MaxQp = value;
}
}
else if (0 == strcmp(para, "level"))
{
if (eMode == VENC_RC_MODE_H264CBR)
{
stVencRcParam.stParamH264Cbr.s32QualityLevel = value;
}
else
{
stVencRcParam.stParamH265Cbr.s32QualityLevel = value;
}
}
else if (0 == strcmp(para, "mqpdelta"))
{
stVencRcParam.u32RowQpDelta = value;
}
else if ( 0 == strcmp(para, "deblock"))
{
VENC_PARAM_H264_DBLK_S stH264Dblk;
s32Ret = HI_MPI_VENC_GetH264Dblk(0, &stH264Dblk);
CHECK_RET(s32Ret, "get deblock");
stH264Dblk.disable_deblocking_filter_idc = 2;
stH264Dblk.slice_alpha_c0_offset_div2 = value;
stH264Dblk.slice_beta_offset_div2 = value;
s32Ret = HI_MPI_VENC_SetH264Dblk(0, &stH264Dblk);
CHECK_RET(s32Ret, "get deblock");
}
s32Ret = HI_MPI_VENC_SetChnAttr(s32EncChn, &stVencChnAttr);
CHECK_RET(s32Ret, "set Chn Attr");
s32Ret = HI_MPI_VENC_SetRcParam(s32EncChn, &stVencRcParam);
CHECK_RET(s32Ret, "set Rc param");
return 0;
}