1 Star 0 Fork 3

jeremy/hi3516dv300-rtsp-h264

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sample_comm_venc.c 93.04 KB
一键复制 编辑 原始数据 按行查看 历史
rinetd 提交于 2019-12-03 18:18 . imx335
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582
/******************************************************************************
Copyright (C), 2017, Hisilicon Tech. Co., Ltd.
******************************************************************************
File Name : sample_comm_venc.c
Version : Initial Draft
Author : Hisilicon multimedia software group
Created : 2017
Description :
******************************************************************************/
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <sys/select.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include <signal.h>
#include <sys/prctl.h>
#include "sample_comm.h"
const HI_U8 g_SOI[2] = {0xFF, 0xD8};
const HI_U8 g_EOI[2] = {0xFF, 0xD9};
static pthread_t gs_VencPid;
static pthread_t gs_VencQpmapPid;
static SAMPLE_VENC_GETSTREAM_PARA_S gs_stPara;
static SAMPLE_VENC_QPMAP_SENDFRAME_PARA_S stQpMapSendFramePara;
static HI_S32 gs_s32SnapCnt = 0;
HI_CHAR* DstBuf = NULL;
#define TEMP_BUF_LEN 8
#define MAX_THM_SIZE (64*1024)
#ifdef __READ_ALL_FILE__
static HI_S32 FileTrans_GetThmFromJpg(HI_CHAR* JPGPath, HI_U32* DstSize)
{
HI_S32 s32RtnVal = 0;
FILE* fpJpg = NULL;
HI_CHAR tempbuf[TEMP_BUF_LEN] = {0};
HI_S32 bufpos = 0;
HI_CHAR startflag[2] = {0xff, 0xd8};
HI_S32 startpos = 0;
HI_CHAR endflag[2] = {0xff, 0xd9};
HI_S32 endpos = 0;
fpJpg = fopen(JPGPath, "rb");
HI_CHAR* pszFile = NULL;
HI_S32 fd = 0;
HI_S32 s32I = 0;
struct stat stStat;
memset(&stStat, 0, sizeof(struct stat));
if (NULL == fpJpg)
{
printf("file %s not exist!\n", JPGPath);
return HI_FAILURE;
}
else
{
fd = fileno(fpJpg);
fstat(fd, &stStat);
pszFile = (HI_CHAR*)malloc(stStat.st_size);
if ((NULL == pszFile) || (stStat.st_size < 6))
{
fclose(fpJpg);
printf("memory malloc fail!\n");
return HI_FAILURE;
}
if (fread(pszFile, stStat.st_size , 1, fpJpg) <= 0)
{
fclose(fpJpg);
free(pszFile);
printf("fread jpeg src fail!\n");
return HI_FAILURE;
}
fclose(fpJpg);
HI_U16 u16THMLen = 0;
u16THMLen = (pszFile[4] << 8) + pszFile[5];
while (s32I < stStat.st_size)
{
tempbuf[bufpos] = pszFile[s32I++];
if (bufpos > 0)
{
if (0 == memcmp(tempbuf + bufpos - 1, startflag, sizeof(startflag)))
{
startpos = s32I - 2;
if (startpos < 0)
{
startpos = 0;
}
}
if (0 == memcmp(tempbuf + bufpos - 1, endflag, sizeof(endflag)))
{
if (u16THMLen == s32I)
{
endpos = s32I;
break;
}
else
{
endpos = s32I;
break;
}
}
}
bufpos++;
if (bufpos == (TEMP_BUF_LEN - 1))
{
if (tempbuf[bufpos - 1] != 0xFF)
{
bufpos = 0;
}
}
else if (bufpos > (TEMP_BUF_LEN - 1))
{
bufpos = 0;
}
}
}
if (endpos - startpos <= 0)
{
free(pszFile);
printf("get .thm 11 fail!\n");
return HI_FAILURE;
}
if (endpos - startpos >= stStat.st_size)
{
free(pszFile);
printf("NO DCF info, get .thm 22 fail!\n");
return HI_FAILURE;
}
HI_CHAR* temp = pszFile + startpos;
if(MAX_THM_SIZE < (endpos - startpos))
{
printf("Thm is too large than MAX_THM_SIZE, get .thm 33 fail!\n");
return HI_FAILURE;
}
HI_CHAR* cDstBuf = (HI_CHAR*)malloc(endpos - startpos);
if (NULL == cDstBuf)
{
printf("memory malloc fail!\n");
return HI_FAILURE;
}
memcpy(cDstBuf, temp, endpos - startpos);
DstBuf = cDstBuf;
*DstSize = endpos - startpos;
free(pszFile);
return HI_SUCCESS;
}
#else
static HI_S32 FileTrans_GetThmFromJpg(HI_CHAR* JPGPath, HI_U32* DstSize)
{
HI_CHAR tempbuf[TEMP_BUF_LEN] = {0};
HI_S32 bufpos = 0;
HI_CHAR startflag[2] = {0xff, 0xd8};
HI_S32 startpos = 0;
HI_CHAR endflag[2] = {0xff, 0xd9};
HI_S32 endpos = 0;
HI_BOOL bStartMatch = HI_FALSE;
HI_S32 fd = 0;
struct stat stStat;
memset(&stStat, 0, sizeof(struct stat));
FILE* fpJpg = NULL;
fpJpg = fopen(JPGPath, "rb");
if (NULL == fpJpg)
{
printf("file %s not exist!\n", JPGPath);
return HI_FAILURE;
}
else
{
fd = fileno(fpJpg);
fstat(fd, &stStat);
while (!feof(fpJpg))
{
tempbuf[bufpos]=getc(fpJpg);
if (bufpos > 0)
{
if (0 == memcmp(tempbuf + bufpos - 1, startflag, sizeof(startflag)))
{
startpos = ftell(fpJpg)-2;
if (startpos < 0)
{
startpos = 0;
}
bStartMatch = HI_TRUE;
}
if (0 == memcmp(tempbuf + bufpos - 1, endflag, sizeof(endflag)))
{
endpos = ftell(fpJpg);
if(HI_TRUE == bStartMatch)
{
break;
}
}
}
bufpos++;
if (bufpos == (TEMP_BUF_LEN - 1))
{
if (tempbuf[bufpos - 1] != 0xFF)
{
bufpos = 0;
}
}
else if (bufpos > (TEMP_BUF_LEN - 1))
{
if (tempbuf[bufpos -1] == 0xFF)
{
tempbuf[0] = 0xFF;
bufpos = 1;
}
else
{
bufpos = 0;
}
}
}
}
if (endpos - startpos <= 0)
{
printf("get .thm 11 fail!\n");
fclose(fpJpg);
return HI_FAILURE;
}
if (endpos - startpos > MAX_THM_SIZE)
{
printf("Thm is too large than MAX_THM_SIZE, get .thm 22 fail!\n");
fclose(fpJpg);
return HI_FAILURE;
}
if (endpos - startpos >= stStat.st_size)
{
printf("NO DCF info, get .thm 33 fail!\n");
fclose(fpJpg);
return HI_FAILURE;
}
HI_CHAR* cDstBuf = (HI_CHAR*)malloc(endpos - startpos);
if (NULL == cDstBuf)
{
printf("memory malloc fail!\n");
fclose(fpJpg);
return HI_FAILURE;
}
fseek(fpJpg, (long)startpos, SEEK_SET);
*DstSize = fread(cDstBuf,1,endpos-startpos,fpJpg);
if(*DstSize != (endpos - startpos))
{
free(cDstBuf);
printf("fread fail!\n");
fclose(fpJpg);
return HI_FAILURE;
}
DstBuf = cDstBuf;
fclose(fpJpg);
return HI_SUCCESS;
}
#endif
/******************************************************************************
* function : Set venc memory location
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_MemConfig(HI_VOID)
{
HI_S32 i = 0;
HI_S32 s32Ret;
HI_CHAR* pcMmzName;
MPP_CHN_S stMppChnVENC;
/* group, venc max chn is 64*/
for (i = 0; i < 64; i++)
{
stMppChnVENC.enModId = HI_ID_VENC;
stMppChnVENC.s32DevId = 0;
stMppChnVENC.s32ChnId = i;
pcMmzName = NULL;
/*venc*/
s32Ret = HI_MPI_SYS_SetMemConfig(&stMppChnVENC, pcMmzName);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_SetMemConfig with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : get file postfix according palyload_type.
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_GetFilePostfix(PAYLOAD_TYPE_E enPayload, char* szFilePostfix)
{
if (PT_H264 == enPayload)
{
strcpy(szFilePostfix, ".h264");
}
else if (PT_H265 == enPayload)
{
strcpy(szFilePostfix, ".h265");
}
else if (PT_JPEG == enPayload)
{
strcpy(szFilePostfix, ".jpg");
}
else if (PT_MJPEG == enPayload)
{
strcpy(szFilePostfix, ".mjp");
}
else
{
SAMPLE_PRT("payload type err!\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_GetGopAttr(VENC_GOP_MODE_E enGopMode,VENC_GOP_ATTR_S *pstGopAttr)
{
switch(enGopMode)
{
case VENC_GOPMODE_NORMALP:
pstGopAttr->enGopMode = VENC_GOPMODE_NORMALP;
pstGopAttr->stNormalP.s32IPQpDelta = 2;
break;
case VENC_GOPMODE_SMARTP:
pstGopAttr->enGopMode = VENC_GOPMODE_SMARTP;
pstGopAttr->stSmartP.s32BgQpDelta = 4;
pstGopAttr->stSmartP.s32ViQpDelta = 2;
pstGopAttr->stSmartP.u32BgInterval = 90;
break;
case VENC_GOPMODE_DUALP:
pstGopAttr->enGopMode = VENC_GOPMODE_DUALP;
pstGopAttr->stDualP.s32IPQpDelta = 4;
pstGopAttr->stDualP.s32SPQpDelta = 2;
pstGopAttr->stDualP.u32SPInterval = 3;
break;
case VENC_GOPMODE_BIPREDB:
pstGopAttr->enGopMode = VENC_GOPMODE_BIPREDB;
pstGopAttr->stBipredB.s32BQpDelta = -2;
pstGopAttr->stBipredB.s32IPQpDelta = 3;
pstGopAttr->stBipredB.u32BFrmNum = 2;
break;
default:
SAMPLE_PRT("not support the gop mode !\n");
return HI_FAILURE;
break;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_Getdcfinfo(char* SrcJpgPath, char* DstThmPath)
{
HI_S32 s32RtnVal = HI_SUCCESS;
HI_CHAR JPGSrcPath[FILE_NAME_LEN] = {0};
HI_CHAR JPGDesPath[FILE_NAME_LEN] = {0};
HI_U32 DstSize = 0;
snprintf(JPGSrcPath, sizeof(JPGSrcPath), "%s", SrcJpgPath);
snprintf(JPGDesPath, sizeof(JPGDesPath), "%s", DstThmPath);
s32RtnVal = FileTrans_GetThmFromJpg(JPGSrcPath, &DstSize);
if ((HI_SUCCESS != s32RtnVal) || (0 == DstSize))
{
printf("fail to get thm\n");
return HI_FAILURE;
}
FILE* fpTHM = fopen(JPGDesPath, "w");
if (HI_NULL == fpTHM)
{
printf("file to create file %s\n", JPGDesPath);
return HI_FAILURE;
}
HI_U32 u32WritenSize = 0;
while (u32WritenSize < DstSize)
{
s32RtnVal = fwrite(DstBuf + u32WritenSize, 1, DstSize, fpTHM);
if (s32RtnVal <= 0)
{
printf("fail to wirte file, rtn=%d\n", s32RtnVal);
break;
}
u32WritenSize += s32RtnVal;
}
if (fpTHM)
{
fclose(fpTHM);
fpTHM = 0;
}
if(NULL != DstBuf)
{
free(DstBuf);
DstBuf = NULL;
}
return 0;
}
/******************************************************************************
* funciton : save stream
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SaveStream(FILE* pFd, VENC_STREAM_S* pstStream)
{
HI_S32 i;
for (i = 0; i < pstStream->u32PackCount; i++)
{
fwrite(pstStream->pstPack[i].pu8Addr + pstStream->pstPack[i].u32Offset,
pstStream->pstPack[i].u32Len - pstStream->pstPack[i].u32Offset, 1, pFd);
fflush(pFd);
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : the process of physical address retrace
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SaveStream_PhyAddr(FILE* pFd, VENC_STREAM_BUF_INFO_S *pstStreamBuf, VENC_STREAM_S* pstStream)
{
HI_U32 i,j;
HI_U64 u64SrcPhyAddr;
HI_U32 u32Left;
HI_S32 s32Ret = 0;
for(i=0; i<pstStream->u32PackCount; i++)
{
for(j=0; j<MAX_TILE_NUM; j++)
{
if((pstStream->pstPack[i].u64PhyAddr > pstStreamBuf->u64PhyAddr[j])&&\
(pstStream->pstPack[i].u64PhyAddr <= pstStreamBuf->u64PhyAddr[j]+pstStreamBuf->u64BufSize[j]))
break;
}
if(pstStream->pstPack[i].u64PhyAddr + pstStream->pstPack[i].u32Len >=
pstStreamBuf->u64PhyAddr[j] + pstStreamBuf->u64BufSize[j])
{
if (pstStream->pstPack[i].u64PhyAddr + pstStream->pstPack[i].u32Offset >=
pstStreamBuf->u64PhyAddr[j] + pstStreamBuf->u64BufSize[j])
{
/* physical address retrace in offset segment */
u64SrcPhyAddr = pstStreamBuf->u64PhyAddr[j] +
((pstStream->pstPack[i].u64PhyAddr + pstStream->pstPack[i].u32Offset) -
(pstStreamBuf->u64PhyAddr[j] + pstStreamBuf->u64BufSize[j]));
s32Ret = fwrite ((void *)(HI_UL)u64SrcPhyAddr, pstStream->pstPack[i].u32Len - pstStream->pstPack[i].u32Offset, 1, pFd);
if(s32Ret<0)
{
SAMPLE_PRT("fwrite err %d\n", s32Ret);
return s32Ret;
}
}
else
{
/* physical address retrace in data segment */
u32Left = (pstStreamBuf->u64PhyAddr[j] + pstStreamBuf->u64BufSize[j]) - pstStream->pstPack[i].u64PhyAddr;
s32Ret = fwrite((void *)(HI_UL)(pstStream->pstPack[i].u64PhyAddr + pstStream->pstPack[i].u32Offset),
u32Left - pstStream->pstPack[i].u32Offset, 1, pFd);
if(s32Ret<0)
{
SAMPLE_PRT("fwrite err %d\n", s32Ret);
return s32Ret;
}
s32Ret = fwrite((void *)(HI_UL)pstStreamBuf->u64PhyAddr[j], pstStream->pstPack[i].u32Len - u32Left, 1, pFd);
if(s32Ret<0)
{
SAMPLE_PRT("fwrite err %d\n", s32Ret);
return s32Ret;
}
}
}
else
{
/* physical address retrace does not happen */
s32Ret = fwrite ((void *)(HI_UL)(pstStream->pstPack[i].u64PhyAddr + pstStream->pstPack[i].u32Offset),
pstStream->pstPack[i].u32Len - pstStream->pstPack[i].u32Offset, 1, pFd);
if(s32Ret<0)
{
SAMPLE_PRT("fwrite err %d\n", s32Ret);
return s32Ret;
}
}
fflush(pFd);
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_CloseReEncode(VENC_CHN VencChn)
{
HI_S32 s32Ret;
VENC_RC_PARAM_S stRcParam;
VENC_CHN_ATTR_S stChnAttr;
s32Ret = HI_MPI_VENC_GetChnAttr(VencChn,&stChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("GetChnAttr failed!\n");
return HI_FAILURE;
}
s32Ret = HI_MPI_VENC_GetRcParam(VencChn,&stRcParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("GetRcParam failed!\n");
return HI_FAILURE;
}
if(VENC_RC_MODE_H264CBR == stChnAttr.stRcAttr.enRcMode)
{
stRcParam.stParamH264Cbr.s32MaxReEncodeTimes = 0;
}
else if(VENC_RC_MODE_H264VBR == stChnAttr.stRcAttr.enRcMode)
{
stRcParam.stParamH264Vbr.s32MaxReEncodeTimes = 0;
}
else if(VENC_RC_MODE_H265CBR == stChnAttr.stRcAttr.enRcMode)
{
stRcParam.stParamH264Cbr.s32MaxReEncodeTimes = 0;
}
else if(VENC_RC_MODE_H265VBR == stChnAttr.stRcAttr.enRcMode)
{
stRcParam.stParamH264Vbr.s32MaxReEncodeTimes = 0;
}
else
{
return HI_SUCCESS;
}
s32Ret = HI_MPI_VENC_SetRcParam(VencChn,&stRcParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SetRcParam failed!\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_Creat(VENC_CHN VencChn, PAYLOAD_TYPE_E enType, PIC_SIZE_E enSize, SAMPLE_RC_E enRcMode, HI_U32 u32Profile, HI_BOOL bRcnRefShareBuf,VENC_GOP_ATTR_S *pstGopAttr)
{
HI_S32 s32Ret;
SIZE_S stPicSize;
VENC_CHN_ATTR_S stVencChnAttr;
VENC_ATTR_JPEG_S stJpegAttr;
SAMPLE_VI_CONFIG_S stViConfig;
HI_U32 u32FrameRate;
HI_U32 u32StatTime;
HI_U32 u32Gop = 30;
s32Ret = SAMPLE_COMM_SYS_GetPicSize( enSize, &stPicSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Get picture size failed!\n");
return HI_FAILURE;
}
SAMPLE_COMM_VI_GetSensorInfo(&stViConfig);
if(SAMPLE_SNS_TYPE_BUTT == stViConfig.astViInfo[0].stSnsInfo.enSnsType)
{
SAMPLE_PRT("Not set SENSOR%d_TYPE !\n",0);
return HI_FALSE;
}
s32Ret = SAMPLE_COMM_VI_GetFrameRateBySensor(stViConfig.astViInfo[0].stSnsInfo.enSnsType, &u32FrameRate);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VI_GetFrameRateBySensor failed!\n");
return s32Ret;
}
/******************************************
step 1: Create Venc Channel
******************************************/
stVencChnAttr.stVencAttr.enType = enType;
stVencChnAttr.stVencAttr.u32MaxPicWidth = stPicSize.u32Width;
stVencChnAttr.stVencAttr.u32MaxPicHeight = stPicSize.u32Height;
stVencChnAttr.stVencAttr.u32PicWidth = stPicSize.u32Width;/*the picture width*/
stVencChnAttr.stVencAttr.u32PicHeight = stPicSize.u32Height;/*the picture height*/
stVencChnAttr.stVencAttr.u32BufSize = stPicSize.u32Width * stPicSize.u32Height * 2;/*stream buffer size*/
stVencChnAttr.stVencAttr.u32Profile = u32Profile;
stVencChnAttr.stVencAttr.bByFrame = HI_TRUE;/*get stream mode is slice mode or frame mode?*/
if(VENC_GOPMODE_SMARTP == pstGopAttr->enGopMode)
{
u32StatTime = pstGopAttr->stSmartP.u32BgInterval/u32Gop;
}
else
{
u32StatTime = 1;
}
switch (enType)
{
case PT_H265:
{
if (SAMPLE_RC_CBR == enRcMode)
{
VENC_H265_CBR_S stH265Cbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CBR;
stH265Cbr.u32Gop = u32Gop;
stH265Cbr.u32StatTime = u32StatTime; /* stream rate statics time(s) */
stH265Cbr.u32SrcFrameRate = u32FrameRate; /* input (vi) frame rate */
stH265Cbr.fr32DstFrameRate = u32FrameRate; /* target frame rate */
switch (enSize)
{
case PIC_720P:
stH265Cbr.u32BitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH265Cbr.u32BitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH265Cbr.u32BitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH265Cbr.u32BitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH265Cbr.u32BitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH265Cbr.u32BitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH265Cbr.u32BitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH265Cbr, &stH265Cbr, sizeof(VENC_H265_CBR_S));
}
else if (SAMPLE_RC_FIXQP == enRcMode)
{
VENC_H265_FIXQP_S stH265FixQp;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265FIXQP;
stH265FixQp.u32Gop = 30;
stH265FixQp.u32SrcFrameRate = u32FrameRate;
stH265FixQp.fr32DstFrameRate = u32FrameRate;
stH265FixQp.u32IQp = 25;
stH265FixQp.u32PQp = 30;
stH265FixQp.u32BQp = 32;
memcpy(&stVencChnAttr.stRcAttr.stH265FixQp, &stH265FixQp, sizeof(VENC_H265_FIXQP_S));
}
else if (SAMPLE_RC_VBR == enRcMode)
{
VENC_H265_VBR_S stH265Vbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265VBR;
stH265Vbr.u32Gop = u32Gop;
stH265Vbr.u32StatTime = u32StatTime;
stH265Vbr.u32SrcFrameRate = u32FrameRate;
stH265Vbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_720P:
stH265Vbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH265Vbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH265Vbr.u32MaxBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH265Vbr.u32MaxBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH265Vbr.u32MaxBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH265Vbr.u32MaxBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH265Vbr.u32MaxBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH265Vbr, &stH265Vbr, sizeof(VENC_H265_VBR_S));
}
else if(SAMPLE_RC_AVBR == enRcMode)
{
VENC_H265_AVBR_S stH265AVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265AVBR;
stH265AVbr.u32Gop = u32Gop;
stH265AVbr.u32StatTime = u32StatTime;
stH265AVbr.u32SrcFrameRate = u32FrameRate;
stH265AVbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_720P:
stH265AVbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH265AVbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH265AVbr.u32MaxBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH265AVbr.u32MaxBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH265AVbr.u32MaxBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH265AVbr.u32MaxBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH265AVbr.u32MaxBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH265AVbr, &stH265AVbr, sizeof(VENC_H265_AVBR_S));
}
else if(SAMPLE_RC_QVBR == enRcMode)
{
VENC_H265_QVBR_S stH265QVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265QVBR;
stH265QVbr.u32Gop = u32Gop;
stH265QVbr.u32StatTime = u32StatTime;
stH265QVbr.u32SrcFrameRate = u32FrameRate;
stH265QVbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_720P:
stH265QVbr.u32TargetBitRate= 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH265QVbr.u32TargetBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH265QVbr.u32TargetBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH265QVbr.u32TargetBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH265QVbr.u32TargetBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH265QVbr.u32TargetBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH265QVbr.u32TargetBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH265QVbr, &stH265QVbr, sizeof(VENC_H265_QVBR_S));
}
else if(SAMPLE_RC_CVBR == enRcMode)
{
VENC_H265_CVBR_S stH265CVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265CVBR;
stH265CVbr.u32Gop = u32Gop;
stH265CVbr.u32StatTime = u32StatTime;
stH265CVbr.u32SrcFrameRate = u32FrameRate;
stH265CVbr.fr32DstFrameRate = u32FrameRate;
stH265CVbr.u32LongTermStatTime = 1;
stH265CVbr.u32ShortTermStatTime = u32StatTime;
switch (enSize)
{
case PIC_720P:
stH265CVbr.u32MaxBitRate = 1024 * 3 + 1024*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 2 + 1024*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 512;
break;
case PIC_1080P:
stH265CVbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 2 + 2048*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024;
break;
case PIC_2592x1944:
stH265CVbr.u32MaxBitRate = 1024 * 4 + 3072*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 3 + 3072*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024*2;
break;
case PIC_3840x2160:
stH265CVbr.u32MaxBitRate = 1024 * 8 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 5 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024*3;
break;
case PIC_4000x3000:
stH265CVbr.u32MaxBitRate = 1024 * 12 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 10 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024*4;
break;
case PIC_7680x4320:
stH265CVbr.u32MaxBitRate = 1024 * 24 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 20 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024*6;
break;
default :
stH265CVbr.u32MaxBitRate = 1024 * 24 + 5120*u32FrameRate/30;
stH265CVbr.u32LongTermMaxBitrate = 1024 * 15 + 2048*u32FrameRate/30;
stH265CVbr.u32LongTermMinBitrate = 1024*5;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH265CVbr, &stH265CVbr, sizeof(VENC_H265_CVBR_S));
}
else if(SAMPLE_RC_QPMAP == enRcMode)
{
VENC_H265_QPMAP_S stH265QpMap;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H265QPMAP;
stH265QpMap.u32Gop = u32Gop;
stH265QpMap.u32StatTime = u32StatTime;
stH265QpMap.u32SrcFrameRate = u32FrameRate;
stH265QpMap.fr32DstFrameRate = u32FrameRate;
stH265QpMap.enQpMapMode = VENC_RC_QPMAP_MODE_MEANQP;
memcpy(&stVencChnAttr.stRcAttr.stH265QpMap, &stH265QpMap, sizeof(VENC_H265_QPMAP_S));
}
else
{
SAMPLE_PRT("%s,%d,enRcMode(%d) not support\n",__FUNCTION__,__LINE__,enRcMode);
return HI_FAILURE;
}
stVencChnAttr.stVencAttr.stAttrH265e.bRcnRefShareBuf = bRcnRefShareBuf;
}
break;
case PT_H264:
{
if (SAMPLE_RC_CBR == enRcMode)
{
VENC_H264_CBR_S stH264Cbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
stH264Cbr.u32Gop = u32Gop; /*the interval of IFrame*/
stH264Cbr.u32StatTime = u32StatTime; /* stream rate statics time(s) */
stH264Cbr.u32SrcFrameRate = u32FrameRate; /* input (vi) frame rate */
stH264Cbr.fr32DstFrameRate = u32FrameRate; /* target frame rate */
switch (enSize)
{
case PIC_720P:
stH264Cbr.u32BitRate = 1024 * 3 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH264Cbr.u32BitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH264Cbr.u32BitRate = 1024 * 4 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH264Cbr.u32BitRate = 1024 * 8 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH264Cbr.u32BitRate = 1024 * 12 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH264Cbr.u32BitRate = 1024 * 24 + 5120*u32FrameRate/30;
break;
default :
stH264Cbr.u32BitRate = 1024 * 24 + 5120*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH264Cbr, &stH264Cbr, sizeof(VENC_H264_CBR_S));
}
else if (SAMPLE_RC_FIXQP == enRcMode)
{
VENC_H264_FIXQP_S stH264FixQp;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264FIXQP;
stH264FixQp.u32Gop = 30;
stH264FixQp.u32SrcFrameRate = u32FrameRate;
stH264FixQp.fr32DstFrameRate = u32FrameRate;
stH264FixQp.u32IQp = 25;
stH264FixQp.u32PQp = 30;
stH264FixQp.u32BQp = 32;
memcpy(&stVencChnAttr.stRcAttr.stH264FixQp, &stH264FixQp, sizeof(VENC_H264_FIXQP_S));
}
else if (SAMPLE_RC_VBR == enRcMode)
{
VENC_H264_VBR_S stH264Vbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264VBR;
stH264Vbr.u32Gop = u32Gop;
stH264Vbr.u32StatTime = u32StatTime;
stH264Vbr.u32SrcFrameRate = u32FrameRate;
stH264Vbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_360P:
stH264Vbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_720P:
stH264Vbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH264Vbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH264Vbr.u32MaxBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH264Vbr.u32MaxBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH264Vbr.u32MaxBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH264Vbr.u32MaxBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH264Vbr.u32MaxBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH264Vbr, &stH264Vbr, sizeof(VENC_H264_VBR_S));
}
else if (SAMPLE_RC_AVBR == enRcMode)
{
VENC_H264_VBR_S stH264AVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264AVBR;
stH264AVbr.u32Gop = u32Gop;
stH264AVbr.u32StatTime = u32StatTime;
stH264AVbr.u32SrcFrameRate = u32FrameRate;
stH264AVbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_360P:
stH264AVbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_720P:
stH264AVbr.u32MaxBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH264AVbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH264AVbr.u32MaxBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH264AVbr.u32MaxBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH264AVbr.u32MaxBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH264AVbr.u32MaxBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH264AVbr.u32MaxBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH264AVbr, &stH264AVbr, sizeof(VENC_H264_AVBR_S));
}
else if (SAMPLE_RC_QVBR == enRcMode)
{
VENC_H264_QVBR_S stH264QVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264QVBR;
stH264QVbr.u32Gop = u32Gop;
stH264QVbr.u32StatTime = u32StatTime;
stH264QVbr.u32SrcFrameRate = u32FrameRate;
stH264QVbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_360P:
stH264QVbr.u32TargetBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_720P:
stH264QVbr.u32TargetBitRate = 1024 * 2 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stH264QVbr.u32TargetBitRate = 1024 * 2 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stH264QVbr.u32TargetBitRate = 1024 * 3 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stH264QVbr.u32TargetBitRate = 1024 * 5 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stH264QVbr.u32TargetBitRate = 1024 * 10 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stH264QVbr.u32TargetBitRate = 1024 * 20 + 5120*u32FrameRate/30;
break;
default :
stH264QVbr.u32TargetBitRate = 1024 * 15 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH264QVbr, &stH264QVbr, sizeof(VENC_H264_QVBR_S));
}
else if(SAMPLE_RC_CVBR == enRcMode)
{
VENC_H264_CVBR_S stH264CVbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CVBR;
stH264CVbr.u32Gop = u32Gop;
stH264CVbr.u32StatTime = u32StatTime;
stH264CVbr.u32SrcFrameRate = u32FrameRate;
stH264CVbr.fr32DstFrameRate = u32FrameRate;
stH264CVbr.u32LongTermStatTime = 1;
stH264CVbr.u32ShortTermStatTime = u32StatTime;
switch (enSize)
{
case PIC_720P:
stH264CVbr.u32MaxBitRate = 1024 * 3 + 1024*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 2 + 1024*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 512;
break;
case PIC_1080P:
stH264CVbr.u32MaxBitRate = 1024 * 2 + 2048*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 2 + 2048*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024;
break;
case PIC_2592x1944:
stH264CVbr.u32MaxBitRate = 1024 * 4 + 3072*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 3 + 3072*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024*2;
break;
case PIC_3840x2160:
stH264CVbr.u32MaxBitRate = 1024 * 8 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 5 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024*3;
break;
case PIC_4000x3000:
stH264CVbr.u32MaxBitRate = 1024 * 12 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 10 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024*4;
break;
case PIC_7680x4320:
stH264CVbr.u32MaxBitRate = 1024 * 24 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 20 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024*6;
break;
default :
stH264CVbr.u32MaxBitRate = 1024 * 24 + 5120*u32FrameRate/30;
stH264CVbr.u32LongTermMaxBitrate = 1024 * 15 + 2048*u32FrameRate/30;
stH264CVbr.u32LongTermMinBitrate = 1024*5;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stH264CVbr, &stH264CVbr, sizeof(VENC_H264_CVBR_S));
}
else if(SAMPLE_RC_QPMAP == enRcMode)
{
VENC_H264_QPMAP_S stH264QpMap;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264QPMAP;
stH264QpMap.u32Gop = u32Gop;
stH264QpMap.u32StatTime = u32StatTime;
stH264QpMap.u32SrcFrameRate = u32FrameRate;
stH264QpMap.fr32DstFrameRate = u32FrameRate;
memcpy(&stVencChnAttr.stRcAttr.stH264QpMap, &stH264QpMap, sizeof(VENC_H264_QPMAP_S));
}
else
{
SAMPLE_PRT("%s,%d,enRcMode(%d) not support\n",__FUNCTION__,__LINE__,enRcMode);
return HI_FAILURE;
}
stVencChnAttr.stVencAttr.stAttrH264e.bRcnRefShareBuf = bRcnRefShareBuf;
}
break;
case PT_MJPEG:
{
if (SAMPLE_RC_FIXQP == enRcMode)
{
VENC_MJPEG_FIXQP_S stMjpegeFixQp;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_MJPEGFIXQP;
stMjpegeFixQp.u32Qfactor = 95;
stMjpegeFixQp.u32SrcFrameRate = u32FrameRate;
stMjpegeFixQp.fr32DstFrameRate = u32FrameRate;
memcpy(&stVencChnAttr.stRcAttr.stMjpegFixQp, &stMjpegeFixQp,sizeof(VENC_MJPEG_FIXQP_S));
}
else if (SAMPLE_RC_CBR == enRcMode)
{
VENC_MJPEG_CBR_S stMjpegeCbr;
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_MJPEGCBR;
stMjpegeCbr.u32StatTime = u32StatTime;
stMjpegeCbr.u32SrcFrameRate = u32FrameRate;
stMjpegeCbr.fr32DstFrameRate = u32FrameRate;
switch (enSize)
{
case PIC_360P:
stMjpegeCbr.u32BitRate = 1024 * 3 + 1024*u32FrameRate/30;
break;
case PIC_720P:
stMjpegeCbr.u32BitRate = 1024 * 5 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stMjpegeCbr.u32BitRate = 1024 * 8 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stMjpegeCbr.u32BitRate = 1024 * 20 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stMjpegeCbr.u32BitRate = 1024 * 25 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stMjpegeCbr.u32BitRate = 1024 * 30 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stMjpegeCbr.u32BitRate = 1024 * 40 + 5120*u32FrameRate/30;
break;
default :
stMjpegeCbr.u32BitRate = 1024 * 20 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stMjpegCbr, &stMjpegeCbr,sizeof(VENC_MJPEG_CBR_S));
}
else if ((SAMPLE_RC_VBR == enRcMode) ||(SAMPLE_RC_AVBR == enRcMode)||
(SAMPLE_RC_QVBR == enRcMode)||(SAMPLE_RC_CVBR == enRcMode))
{
VENC_MJPEG_VBR_S stMjpegVbr;
if(SAMPLE_RC_AVBR == enRcMode)
{
SAMPLE_PRT("Mjpege not support AVBR, so change rcmode to VBR!\n");
}
stVencChnAttr.stRcAttr.enRcMode = VENC_RC_MODE_MJPEGVBR;
stMjpegVbr.u32StatTime = u32StatTime;
stMjpegVbr.u32SrcFrameRate = u32FrameRate;
stMjpegVbr.fr32DstFrameRate = 5;
switch (enSize)
{
case PIC_360P:
stMjpegVbr.u32MaxBitRate = 1024 * 3 + 1024*u32FrameRate/30;
break;
case PIC_720P:
stMjpegVbr.u32MaxBitRate = 1024 * 5 + 1024*u32FrameRate/30;
break;
case PIC_1080P:
stMjpegVbr.u32MaxBitRate = 1024 * 8 + 2048*u32FrameRate/30;
break;
case PIC_2592x1944:
stMjpegVbr.u32MaxBitRate = 1024 * 20 + 3072*u32FrameRate/30;
break;
case PIC_3840x2160:
stMjpegVbr.u32MaxBitRate = 1024 * 25 + 5120*u32FrameRate/30;
break;
case PIC_4000x3000:
stMjpegVbr.u32MaxBitRate = 1024 * 30 + 5120*u32FrameRate/30;
break;
case PIC_7680x4320:
stMjpegVbr.u32MaxBitRate = 1024 * 40 + 5120*u32FrameRate/30;
break;
default :
stMjpegVbr.u32MaxBitRate = 1024 * 20 + 2048*u32FrameRate/30;
break;
}
memcpy(&stVencChnAttr.stRcAttr.stMjpegVbr, &stMjpegVbr,sizeof(VENC_MJPEG_VBR_S));
}
else
{
SAMPLE_PRT("cann't support other mode(%d) in this version!\n",enRcMode);
return HI_FAILURE;
}
}
break;
case PT_JPEG:
stJpegAttr.bSupportDCF = HI_FALSE;
stJpegAttr.stMPFCfg.u8LargeThumbNailNum = 0;
stJpegAttr.enReceiveMode = VENC_PIC_RECEIVE_SINGLE;
memcpy(&stVencChnAttr.stVencAttr.stAttrJpege, &stJpegAttr, sizeof(VENC_ATTR_JPEG_S));
break;
default:
SAMPLE_PRT("cann't support this enType (%d) in this version!\n",enType);
return HI_ERR_VENC_NOT_SUPPORT;
}
if(PT_MJPEG == enType || PT_JPEG == enType )
{
stVencChnAttr.stGopAttr.enGopMode = VENC_GOPMODE_NORMALP;
stVencChnAttr.stGopAttr.stNormalP.s32IPQpDelta = 0;
}
else
{
memcpy(&stVencChnAttr.stGopAttr,pstGopAttr,sizeof(VENC_GOP_ATTR_S));
if((VENC_GOPMODE_BIPREDB == pstGopAttr->enGopMode)&&(PT_H264 == enType))
{
if(0 == stVencChnAttr.stVencAttr.u32Profile)
{
stVencChnAttr.stVencAttr.u32Profile = 1;
SAMPLE_PRT("H.264 base profile not support BIPREDB, so change profile to main profile!\n");
}
}
if((VENC_RC_MODE_H264QPMAP == stVencChnAttr.stRcAttr.enRcMode)||(VENC_RC_MODE_H265QPMAP == stVencChnAttr.stRcAttr.enRcMode))
{
if(VENC_GOPMODE_ADVSMARTP == pstGopAttr->enGopMode)
{
stVencChnAttr.stGopAttr.enGopMode = VENC_GOPMODE_SMARTP;
SAMPLE_PRT("advsmartp not support QPMAP, so change gopmode to smartp!\n");
}
}
}
s32Ret = HI_MPI_VENC_CreateChn(VencChn, &stVencChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_CreateChn [%d] faild with %#x! ===\n", \
VencChn, s32Ret);
return s32Ret;
}
s32Ret = SAMPLE_COMM_VENC_CloseReEncode(VencChn);
if (HI_SUCCESS != s32Ret)
{
HI_MPI_VENC_DestroyChn(VencChn);
return s32Ret;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : Start venc stream mode
* note : rate control parameter need adjust, according your case.
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_Start(VENC_CHN VencChn, PAYLOAD_TYPE_E enType, PIC_SIZE_E enSize, SAMPLE_RC_E enRcMode, HI_U32 u32Profile, HI_BOOL bRcnRefShareBuf,VENC_GOP_ATTR_S *pstGopAttr)
{
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
/******************************************
step 1: Creat Encode Chnl
******************************************/
s32Ret = SAMPLE_COMM_VENC_Creat(VencChn,enType,enSize,enRcMode,u32Profile,bRcnRefShareBuf,pstGopAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VENC_Creat faild with%#x! \n", s32Ret);
return HI_FAILURE;
}
/******************************************
step 2: Start Recv Venc Pictures
******************************************/
stRecvParam.s32RecvPicNum = -1;
s32Ret = HI_MPI_VENC_StartRecvFrame(VencChn,&stRecvParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StartRecvPic faild with%#x! \n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : Stop venc ( stream mode -- H264, MJPEG )
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_Stop(VENC_CHN VencChn)
{
HI_S32 s32Ret;
/******************************************
step 1: Stop Recv Pictures
******************************************/
s32Ret = HI_MPI_VENC_StopRecvFrame(VencChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StopRecvPic vechn[%d] failed with %#x!\n", \
VencChn, s32Ret);
return HI_FAILURE;
} /******************************************
step 2: Distroy Venc Channel
******************************************/
s32Ret = HI_MPI_VENC_DestroyChn(VencChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_DestroyChn vechn[%d] failed with %#x!\n", \
VencChn, s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : Start snap
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SnapStart(VENC_CHN VencChn, SIZE_S* pstSize, HI_BOOL bSupportDCF)
{
HI_S32 s32Ret;
VENC_CHN_ATTR_S stVencChnAttr;
/******************************************
step 1: Create Venc Channel
******************************************/
stVencChnAttr.stVencAttr.enType = PT_JPEG;
stVencChnAttr.stVencAttr.u32MaxPicWidth = pstSize->u32Width;
stVencChnAttr.stVencAttr.u32MaxPicHeight = pstSize->u32Height;
stVencChnAttr.stVencAttr.u32PicWidth = pstSize->u32Width;
stVencChnAttr.stVencAttr.u32PicHeight = pstSize->u32Height;
stVencChnAttr.stVencAttr.u32BufSize = pstSize->u32Width * pstSize->u32Height * 2;
stVencChnAttr.stVencAttr.bByFrame = HI_TRUE;/*get stream mode is field mode or frame mode*/
stVencChnAttr.stVencAttr.stAttrJpege.bSupportDCF = bSupportDCF;
//stVencChnAttr.stVencAttr.stAttrJpege.bSupportXMP = HI_FALSE;
stVencChnAttr.stVencAttr.stAttrJpege.stMPFCfg.u8LargeThumbNailNum = 0;
stVencChnAttr.stVencAttr.stAttrJpege.enReceiveMode = VENC_PIC_RECEIVE_SINGLE;
s32Ret = HI_MPI_VENC_CreateChn(VencChn, &stVencChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_CreateChn [%d] faild with %#x!\n", \
VencChn, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : Stop snap
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SnapStop(VENC_CHN VencChn)
{
HI_S32 s32Ret;
s32Ret = HI_MPI_VENC_StopRecvFrame(VencChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StopRecvPic vechn[%d] failed with %#x!\n", VencChn, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VENC_DestroyChn(VencChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_DestroyChn vechn[%d] failed with %#x!\n", VencChn, s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : snap process
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_SnapProcess(VENC_CHN VencChn, HI_U32 SnapCnt, HI_BOOL bSaveJpg, HI_BOOL bSaveThm)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_CHN_STATUS_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
VENC_RECV_PIC_PARAM_S stRecvParam;
HI_U32 i;
#ifdef __HuaweiLite__
VENC_STREAM_BUF_INFO_S stStreamBufInfo;
#endif
/******************************************
step 2: Start Recv Venc Pictures
******************************************/
stRecvParam.s32RecvPicNum = SnapCnt;
s32Ret = HI_MPI_VENC_StartRecvFrame(VencChn, &stRecvParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_StartRecvPic faild with%#x!\n", s32Ret);
return HI_FAILURE;
}
/******************************************
step 3: recv picture
******************************************/
s32VencFd = HI_MPI_VENC_GetFd(VencChn);
if (s32VencFd < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd faild with%#x!\n", s32VencFd);
return HI_FAILURE;
}
for(i=0; i<SnapCnt; i++)
{
FD_ZERO(&read_fds);
FD_SET(s32VencFd, &read_fds);
TimeoutVal.tv_sec = 10;
TimeoutVal.tv_usec = 0;
s32Ret = select(s32VencFd + 1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("snap select failed!\n");
return HI_FAILURE;
}
else if (0 == s32Ret)
{
SAMPLE_PRT("snap time out!\n");
return HI_FAILURE;
}
else
{
if (FD_ISSET(s32VencFd, &read_fds))
{
s32Ret = HI_MPI_VENC_QueryStatus(VencChn, &stStat);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_QueryStatus failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*******************************************************
suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{ SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
*******************************************************/
if (0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc memory failed!\n");
return HI_FAILURE;
}
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(VencChn, &stStream, -1);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
if(bSaveJpg || bSaveThm)
{
char acFile[FILE_NAME_LEN] = {0};
FILE* pFile;
snprintf(acFile, FILE_NAME_LEN, "snap_%d.jpg", gs_s32SnapCnt);
pFile = fopen(acFile, "wb");
if (pFile == NULL)
{
SAMPLE_PRT("open file err\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
#ifndef __HuaweiLite__
s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("save snap picture failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
#else
s32Ret = HI_MPI_VENC_GetStreamBufInfo (VencChn, &stStreamBufInfo);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStreamBufInfo failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile, &stStreamBufInfo, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("save snap picture failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
#endif
if(bSaveThm)
{
char acFile_dcf[FILE_NAME_LEN] = {0};
snprintf(acFile_dcf, FILE_NAME_LEN, "snap_thm_%d.jpg", gs_s32SnapCnt);
s32Ret = SAMPLE_COMM_VENC_Getdcfinfo(acFile, acFile_dcf);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("save thm picture failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
}
fclose(pFile);
gs_s32SnapCnt++;
}
s32Ret = HI_MPI_VENC_ReleaseStream(VencChn, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_ReleaseStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
free(stStream.pstPack);
stStream.pstPack = NULL;
}
}
}
/******************************************
step 4: stop recv picture
******************************************/
s32Ret = HI_MPI_VENC_StopRecvFrame(VencChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_StopRecvPic failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_SaveJpeg(VENC_CHN VencChn, HI_U32 SnapCnt)
{
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 s32VencFd;
VENC_CHN_STATUS_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
HI_U32 i;
#ifdef __HuaweiLite__
VENC_STREAM_BUF_INFO_S stStreamBufInfo;
#endif
s32VencFd = HI_MPI_VENC_GetFd(VencChn);
if (s32VencFd < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd faild with%#x!\n", s32VencFd);
return HI_FAILURE;
}
for(i=0; i<SnapCnt; i++)
{
FD_ZERO(&read_fds);
FD_SET(s32VencFd, &read_fds);
TimeoutVal.tv_sec = 10;
TimeoutVal.tv_usec = 0;
s32Ret = select(s32VencFd + 1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("snap select failed!\n");
return HI_FAILURE;
}
else if (0 == s32Ret)
{
SAMPLE_PRT("snap time out!\n");
return HI_FAILURE;
}
else
{
if (FD_ISSET(s32VencFd, &read_fds))
{
s32Ret = HI_MPI_VENC_QueryStatus(VencChn, &stStat);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_QueryStatus failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*******************************************************
suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{ SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
*******************************************************/
if (0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
return HI_SUCCESS;
}
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc memory failed!\n");
return HI_FAILURE;
}
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(VencChn, &stStream, -1);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
if(1)
{
char acFile[FILE_NAME_LEN] = {0};
FILE* pFile;
snprintf(acFile, FILE_NAME_LEN, "snap_%d.jpg", gs_s32SnapCnt);
pFile = fopen(acFile, "wb");
if (pFile == NULL)
{
SAMPLE_PRT("open file err\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
#ifndef __HuaweiLite__
s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("save snap picture failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
#else
s32Ret = HI_MPI_VENC_GetStreamBufInfo (VencChn, &stStreamBufInfo);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStreamBufInfo failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile, &stStreamBufInfo, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("save snap picture failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
fclose(pFile);
return HI_FAILURE;
}
#endif
fclose(pFile);
gs_s32SnapCnt++;
}
s32Ret = HI_MPI_VENC_ReleaseStream(VencChn, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_ReleaseStream failed with %#x!\n", s32Ret);
free(stStream.pstPack);
stStream.pstPack = NULL;
return HI_FAILURE;
}
free(stStream.pstPack);
stStream.pstPack = NULL;
}
}
}
return HI_SUCCESS;
}
#define QpMapBufNum 8
HI_VOID* SAMPLE_COMM_QpmapSendFrameProc(HI_VOID* p)
{
HI_U32 i,j,VeChnCnt;
HI_S32 s32Ret;
VIDEO_FRAME_INFO_S *pstVideoFrame;
USER_FRAME_INFO_S stFrame[QpMapBufNum];
SAMPLE_VENC_QPMAP_SENDFRAME_PARA_S *pstPara;
//HI_U32 u32AlignPicHeight ;
//HI_U32 u32AlignPicWidth ;
HI_U32 u32QpMapSize;
HI_U64 u64QpMapPhyAddr[QpMapBufNum];
HI_VOID* pQpMapVirAddr[QpMapBufNum];
HI_U32 u32QpMapSizeHeight ;
HI_U32 u32QpMapSizeWidth ;
HI_U8 *pVirAddr;
HI_U64 u64PhyAddr;
HI_U8 *pVirAddrTemp;
HI_U32 u32SkipWeightHeight_H264 ;
HI_U32 u32SkipWeightWidth_H264 ;
HI_U32 u32SkipWeightSize_H264;
HI_U64 u64SkipWeightPhyAddr_H264[QpMapBufNum];
HI_VOID* pSkipWeightVirAddr_H264[QpMapBufNum];
HI_U32 u32SkipWeightHeight_H265 ;
HI_U32 u32SkipWeightWidth_H265 ;
HI_U32 u32SkipWeightSize_H265;
HI_U64 u64SkipWeightPhyAddr_H265[QpMapBufNum];
HI_VOID* pSkipWeightVirAddr_H265[QpMapBufNum];
VPSS_CHN_ATTR_S stChnAttr;
pstPara = (SAMPLE_VENC_QPMAP_SENDFRAME_PARA_S*)p;
//u32AlignPicWidth = (pstPara->stSize.u32Height + 15)/16;
//u32AlignPicHeight = (pstPara->stSize.u32Height + 15)/16;
/* qpmap */
u32QpMapSizeWidth = (pstPara->stSize.u32Width + 511)/512 *32;
u32QpMapSizeHeight = (pstPara->stSize.u32Height + 15)/16;
u32QpMapSize = u32QpMapSizeWidth * u32QpMapSizeHeight;
s32Ret = HI_MPI_SYS_MmzAlloc(&u64PhyAddr, (void**)&pVirAddr, NULL, HI_NULL, u32QpMapSize*QpMapBufNum);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzAlloc err:0x%x",s32Ret);
return NULL;
}
for(i=0; i<QpMapBufNum; i++)
{
u64QpMapPhyAddr[i] = u64PhyAddr + i*u32QpMapSize;
pQpMapVirAddr[i] = pVirAddr + i*u32QpMapSize;
}
/* skipweight h.264 */
u32SkipWeightWidth_H264 = (pstPara->stSize.u32Width + 511)/512 *16;
u32SkipWeightHeight_H264 = (pstPara->stSize.u32Height + 15)/16;
u32SkipWeightSize_H264 = u32SkipWeightWidth_H264*u32SkipWeightHeight_H264;
s32Ret = HI_MPI_SYS_MmzAlloc(&u64PhyAddr, (void**)&pVirAddr, NULL, HI_NULL, u32SkipWeightSize_H264*QpMapBufNum);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzAlloc err:0x%x",s32Ret);
HI_MPI_SYS_MmzFree(u64QpMapPhyAddr[0],pQpMapVirAddr[0]);
return NULL;
}
for(i=0; i<QpMapBufNum; i++)
{
u64SkipWeightPhyAddr_H264[i] = u64PhyAddr + i*u32SkipWeightSize_H264;
pSkipWeightVirAddr_H264[i] = pVirAddr + i*u32SkipWeightSize_H264;
}
/* skipweight h.265 */
u32SkipWeightWidth_H265 = (pstPara->stSize.u32Width + 2047)/2048 *16;
u32SkipWeightHeight_H265 = (pstPara->stSize.u32Height + 63)/64;
u32SkipWeightSize_H265 = u32SkipWeightWidth_H265*u32SkipWeightHeight_H265;
s32Ret = HI_MPI_SYS_MmzAlloc(&u64PhyAddr, (void**)&pVirAddr, NULL, HI_NULL, u32SkipWeightSize_H265*QpMapBufNum);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzAlloc err:0x%x",s32Ret);
HI_MPI_SYS_MmzFree(u64QpMapPhyAddr[0],pQpMapVirAddr[0]);
HI_MPI_SYS_MmzFree(u64SkipWeightPhyAddr_H264[0],pSkipWeightVirAddr_H264[0]);
return NULL;
}
for(i=0; i<QpMapBufNum; i++)
{
u64SkipWeightPhyAddr_H265[i] = u64PhyAddr + i*u32SkipWeightSize_H265;
pSkipWeightVirAddr_H265[i] = pVirAddr + i*u32SkipWeightSize_H265;
}
s32Ret = HI_MPI_VPSS_GetChnAttr(pstPara->VpssGrp,pstPara->VpssChn,&stChnAttr);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_GetChnAttr err:0x%x",s32Ret);
return NULL;
}
stChnAttr.u32Depth = 3;
s32Ret = HI_MPI_VPSS_SetChnAttr(pstPara->VpssGrp,pstPara->VpssChn,&stChnAttr);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr err:0x%x",s32Ret);
return NULL;
}
i=0;
while(HI_TRUE == pstPara->bThreadStart)
{
pstVideoFrame = &stFrame[i].stUserFrame;
s32Ret = HI_MPI_VPSS_GetChnFrame(pstPara->VpssGrp,pstPara->VpssChn,pstVideoFrame,1000);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_GetChnFrame err:0x%x\n",s32Ret);
continue;
}
pVirAddrTemp = (HI_U8 *)pQpMapVirAddr[i];
for(j=0; j<u32QpMapSize; j++)
{
*pVirAddrTemp = 0x5E;
pVirAddrTemp++;
}
pVirAddrTemp = (HI_U8 *)pSkipWeightVirAddr_H264[i];
for(j=0; j<u32SkipWeightSize_H264; j++)
{
*pVirAddrTemp = 0x88;
pVirAddrTemp++;
}
pVirAddrTemp = (HI_U8 *)pSkipWeightVirAddr_H265[i];
for(j=0; j<u32SkipWeightSize_H265; j++)
{
*pVirAddrTemp = 0x88;
pVirAddrTemp++;
}
for(VeChnCnt=0; VeChnCnt<pstPara->s32Cnt; VeChnCnt++)
{
VENC_CHN_ATTR_S stChnAttr;
HI_MPI_VENC_GetChnAttr(pstPara->VeChn[VeChnCnt],&stChnAttr);
if(PT_H264 ==stChnAttr.stVencAttr.enType)
{
stFrame[i].stUserRcInfo.bSkipWeightValid = 1;
stFrame[i].stUserRcInfo.u64SkipWeightPhyAddr = u64SkipWeightPhyAddr_H264[i];
}
else if(PT_H265 ==stChnAttr.stVencAttr.enType)
{
stFrame[i].stUserRcInfo.bSkipWeightValid = 1;
stFrame[i].stUserRcInfo.u64SkipWeightPhyAddr = u64SkipWeightPhyAddr_H265[i];
}
else
{
continue;
}
stFrame[i].stUserRcInfo.bQpMapValid = 1;
stFrame[i].stUserRcInfo.u64QpMapPhyAddr = u64QpMapPhyAddr[i];
stFrame[i].stUserRcInfo.u32BlkStartQp = 30;
stFrame[i].stUserRcInfo.enFrameType = VENC_FRAME_TYPE_NONE;
s32Ret = HI_MPI_VENC_SendFrameEx(pstPara->VeChn[VeChnCnt], &stFrame[i],-1);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_SendFrame err:0x%x\n",s32Ret);
break;
}
}
if(HI_SUCCESS != s32Ret)
{
s32Ret = HI_MPI_VPSS_ReleaseChnFrame(pstPara->VpssGrp,pstPara->VpssChn,pstVideoFrame);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_ReleaseChnFrame err:0x%x",s32Ret);
goto err_out;
}
continue;
}
s32Ret = HI_MPI_VPSS_ReleaseChnFrame(pstPara->VpssGrp,pstPara->VpssChn,pstVideoFrame);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_ReleaseChnFrame err:0x%x",s32Ret);
goto err_out;
}
i++;
if(i >= QpMapBufNum)
{
i = 0;
}
}
err_out:
s32Ret = HI_MPI_SYS_MmzFree(u64QpMapPhyAddr[0],pQpMapVirAddr[0]);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzFree err:0x%x",s32Ret);
return NULL;
}
s32Ret = HI_MPI_SYS_MmzFree(u64SkipWeightPhyAddr_H264[0],pSkipWeightVirAddr_H264[0]);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzFree err:0x%x",s32Ret);
return NULL;
}
s32Ret = HI_MPI_SYS_MmzFree(u64SkipWeightPhyAddr_H265[0],pSkipWeightVirAddr_H265[0]);
if(HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_MmzFree err:0x%x",s32Ret);
return NULL;
}
return NULL;
}
HI_S32 SAMPLE_COMM_VENC_QpmapSendFrame(VPSS_GRP VpssGrp,VPSS_CHN VpssChn,VENC_CHN VeChn[],HI_S32 s32Cnt,SIZE_S stSize)
{
HI_S32 i;
stQpMapSendFramePara.bThreadStart = HI_TRUE;
stQpMapSendFramePara.VpssGrp = VpssGrp;
stQpMapSendFramePara.VpssChn = VpssChn;
stQpMapSendFramePara.s32Cnt = s32Cnt;
stQpMapSendFramePara.stSize = stSize;
for(i=0; i<s32Cnt;i++)
{
stQpMapSendFramePara.VeChn[i] = VeChn[i];
}
return pthread_create(&gs_VencQpmapPid, 0, SAMPLE_COMM_QpmapSendFrameProc, (HI_VOID*)&stQpMapSendFramePara);
}
/******************************************************************************
* funciton : get stream from each channels and save them
******************************************************************************/
HI_VOID* SAMPLE_COMM_VENC_GetVencStreamProc(HI_VOID* p)
{
HI_S32 i;
HI_S32 s32ChnTotal;
VENC_CHN_ATTR_S stVencChnAttr;
SAMPLE_VENC_GETSTREAM_PARA_S* pstPara;
HI_S32 maxfd = 0;
struct timeval TimeoutVal;
fd_set read_fds;
HI_U32 u32PictureCnt[VENC_MAX_CHN_NUM]={0};
HI_S32 VencFd[VENC_MAX_CHN_NUM];
HI_CHAR aszFileName[VENC_MAX_CHN_NUM][64];
FILE* pFile[VENC_MAX_CHN_NUM];
char szFilePostfix[10];
VENC_CHN_STATUS_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
VENC_CHN VencChn;
PAYLOAD_TYPE_E enPayLoadType[VENC_MAX_CHN_NUM];
VENC_STREAM_BUF_INFO_S stStreamBufInfo[VENC_MAX_CHN_NUM];
prctl(PR_SET_NAME, "GetVencStream", 0,0,0);
pstPara = (SAMPLE_VENC_GETSTREAM_PARA_S*)p;
s32ChnTotal = pstPara->s32Cnt;
/******************************************
step 1: check & prepare save-file & venc-fd
******************************************/
if (s32ChnTotal >= VENC_MAX_CHN_NUM)
{
SAMPLE_PRT("input count invaild\n");
return NULL;
}
for (i = 0; i < s32ChnTotal; i++)
{
/* decide the stream file name, and open file to save stream */
VencChn = pstPara->VeChn[i];
s32Ret = HI_MPI_VENC_GetChnAttr(VencChn, &stVencChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_GetChnAttr chn[%d] failed with %#x!\n", \
VencChn, s32Ret);
return NULL;
}
enPayLoadType[i] = stVencChnAttr.stVencAttr.enType;
s32Ret = SAMPLE_COMM_VENC_GetFilePostfix(enPayLoadType[i], szFilePostfix);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("SAMPLE_COMM_VENC_GetFilePostfix [%d] failed with %#x!\n", \
stVencChnAttr.stVencAttr.enType, s32Ret);
return NULL;
}
if(PT_JPEG != enPayLoadType[i])
{
snprintf(aszFileName[i],32, "stream_chn%d%s", i, szFilePostfix);
pFile[i] = fopen(aszFileName[i], "wb");
if (!pFile[i])
{
SAMPLE_PRT("open file[%s] failed!\n",
aszFileName[i]);
return NULL;
}
}
/* Set Venc Fd. */
VencFd[i] = HI_MPI_VENC_GetFd(i);
if (VencFd[i] < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd failed with %#x!\n",
VencFd[i]);
return NULL;
}
if (maxfd <= VencFd[i])
{
maxfd = VencFd[i];
}
s32Ret = HI_MPI_VENC_GetStreamBufInfo (i, &stStreamBufInfo[i]);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStreamBufInfo failed with %#x!\n", s32Ret);
return (void *)HI_FAILURE;
}
}
/******************************************
step 2: Start to get streams of each channel.
******************************************/
while (HI_TRUE == pstPara->bThreadStart)
{
FD_ZERO(&read_fds);
for (i = 0; i < s32ChnTotal; i++)
{
FD_SET(VencFd[i], &read_fds);
}
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("select failed!\n");
break;
}
else if (s32Ret == 0)
{
SAMPLE_PRT("get venc stream time out, exit thread\n");
continue;
}
else
{
for (i = 0; i < s32ChnTotal; i++)
{
if (FD_ISSET(VencFd[i], &read_fds))
{
/*******************************************************
step 2.1 : query how many packs in one-frame stream.
*******************************************************/
memset(&stStream, 0, sizeof(stStream));
s32Ret = HI_MPI_VENC_QueryStatus(i, &stStat);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_QueryStatus chn[%d] failed with %#x!\n", i, s32Ret);
break;
}
/*******************************************************
step 2.2 :suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
continue;
}
*******************************************************/
if(0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
continue;
}
/*******************************************************
step 2.3 : malloc corresponding number of pack nodes.
*******************************************************/
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc stream pack failed!\n");
break;
}
/*******************************************************
step 2.4 : call mpi to get one-frame stream
*******************************************************/
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
if (HI_SUCCESS != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \
s32Ret);
break;
}
HisiPutH264DataToBuffer(&stStream);
/*******************************************************
step 2.5 : save frame to file
*******************************************************/
/* if(PT_JPEG == enPayLoadType[i])
{
snprintf(aszFileName[i],32, "stream_chn%d_%d%s", i, u32PictureCnt[i],szFilePostfix);
pFile[i] = fopen(aszFileName[i], "wb");
if (!pFile[i])
{
SAMPLE_PRT("open file err!\n");
return NULL;
}
}*/
#ifndef __HuaweiLite__
//s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile[i], &stStream);
#else
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile[i], &stStreamBufInfo[i], &stStream);
#endif
if (HI_SUCCESS != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
SAMPLE_PRT("save stream failed!\n");
break;
}
/*******************************************************
step 2.6 : release stream
*******************************************************/
s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_ReleaseStream failed!\n");
free(stStream.pstPack);
stStream.pstPack = NULL;
break;
}
/*******************************************************
step 2.7 : free pack nodes
*******************************************************/
free(stStream.pstPack);
stStream.pstPack = NULL;
u32PictureCnt[i]++;
if(PT_JPEG == enPayLoadType[i])
{
fclose(pFile[i]);
}
}
}
}
}
/*******************************************************
* step 3 : close save-file
*******************************************************/
for (i = 0; i < s32ChnTotal; i++)
{
if(PT_JPEG != enPayLoadType[i])
{
fclose(pFile[i]);
}
}
return NULL;
}
/******************************************************************************
* funciton : get svc_t stream from h264 channels and save them
******************************************************************************/
HI_VOID* SAMPLE_COMM_VENC_GetVencStreamProc_Svc_t(void* p)
{
HI_S32 i = 0;
HI_S32 s32Cnt = 0;
HI_S32 s32ChnTotal;
VENC_CHN_ATTR_S stVencChnAttr;
SAMPLE_VENC_GETSTREAM_PARA_S* pstPara;
HI_S32 maxfd = 0;
struct timeval TimeoutVal;
fd_set read_fds;
HI_S32 VencFd[VENC_MAX_CHN_NUM];
HI_CHAR aszFileName[VENC_MAX_CHN_NUM][64];
FILE* pFile[VENC_MAX_CHN_NUM];
char szFilePostfix[10];
VENC_CHN_STATUS_S stStat;
VENC_STREAM_S stStream;
HI_S32 s32Ret;
VENC_CHN VencChn;
PAYLOAD_TYPE_E enPayLoadType[VENC_MAX_CHN_NUM];
VENC_STREAM_BUF_INFO_S stStreamBufInfo[VENC_MAX_CHN_NUM];
pstPara = (SAMPLE_VENC_GETSTREAM_PARA_S*)p;
s32ChnTotal = pstPara->s32Cnt;
/******************************************
step 1: check & prepare save-file & venc-fd
******************************************/
if (s32ChnTotal >= VENC_MAX_CHN_NUM)
{
SAMPLE_PRT("input count invaild\n");
return NULL;
}
for (i = 0; i < s32ChnTotal; i++)
{
/* decide the stream file name, and open file to save stream */
VencChn = i;
s32Ret = HI_MPI_VENC_GetChnAttr(VencChn, &stVencChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VENC_GetChnAttr chn[%d] failed with %#x!\n", \
VencChn, s32Ret);
return NULL;
}
enPayLoadType[i] = stVencChnAttr.stVencAttr.enType;
s32Ret = SAMPLE_COMM_VENC_GetFilePostfix(enPayLoadType[i], szFilePostfix);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("SAMPLE_COMM_VENC_GetFilePostfix [%d] failed with %#x!\n", \
stVencChnAttr.stVencAttr.enType, s32Ret);
return NULL;
}
for (s32Cnt = 0; s32Cnt < 3; s32Cnt++)
{
snprintf(aszFileName[i + s32Cnt],32, "Tid%d%s", i + s32Cnt, szFilePostfix);
pFile[i + s32Cnt] = fopen(aszFileName[i + s32Cnt], "wb");
if (!pFile[i + s32Cnt])
{
SAMPLE_PRT("open file[%s] failed!\n",
aszFileName[i + s32Cnt]);
return NULL;
}
}
/* Set Venc Fd. */
VencFd[i] = HI_MPI_VENC_GetFd(i);
if (VencFd[i] < 0)
{
SAMPLE_PRT("HI_MPI_VENC_GetFd failed with %#x!\n",
VencFd[i]);
return NULL;
}
if (maxfd <= VencFd[i])
{
maxfd = VencFd[i];
}
s32Ret = HI_MPI_VENC_GetStreamBufInfo (i, &stStreamBufInfo[i]);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_GetStreamBufInfo failed with %#x!\n", s32Ret);
return NULL;
}
}
/******************************************
step 2: Start to get streams of each channel.
******************************************/
while (HI_TRUE == pstPara->bThreadStart)
{
FD_ZERO(&read_fds);
for (i = 0; i < s32ChnTotal; i++)
{
FD_SET(VencFd[i], &read_fds);
}
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal);
if (s32Ret < 0)
{
SAMPLE_PRT("select failed!\n");
break;
}
else if (s32Ret == 0)
{
SAMPLE_PRT("get venc stream time out, exit thread\n");
continue;
}
else
{
for (i = 0; i < s32ChnTotal; i++)
{
if (FD_ISSET(VencFd[i], &read_fds))
{
/*******************************************************
step 2.1 : query how many packs in one-frame stream.
*******************************************************/
memset(&stStream, 0, sizeof(stStream));
s32Ret = HI_MPI_VENC_QueryStatus(i, &stStat);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VENC_Query chn[%d] failed with %#x!\n", i, s32Ret);
break;
}
/*******************************************************
step 2.2 :suggest to check both u32CurPacks and u32LeftStreamFrames at the same time,for example:
if(0 == stStat.u32CurPacks || 0 == stStat.u32LeftStreamFrames)
{ SAMPLE_PRT("NOTE: Current frame is NULL!\n");
continue;
}
*******************************************************/
if (0 == stStat.u32CurPacks)
{
SAMPLE_PRT("NOTE: Current frame is NULL!\n");
continue;
}
/*******************************************************
step 2.3 : malloc corresponding number of pack nodes.
*******************************************************/
stStream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stStat.u32CurPacks);
if (NULL == stStream.pstPack)
{
SAMPLE_PRT("malloc stream pack failed!\n");
break;
}
/*******************************************************
step 2.4 : call mpi to get one-frame stream
*******************************************************/
stStream.u32PackCount = stStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(i, &stStream, HI_TRUE);
if (HI_SUCCESS != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
SAMPLE_PRT("HI_MPI_VENC_GetStream failed with %#x!\n", \
s32Ret);
break;
}
/*******************************************************
step 2.5 : save frame to file
*******************************************************/
for (s32Cnt = 0; s32Cnt < 3; s32Cnt++)
{
switch (s32Cnt)
{
case 0:
if (BASE_IDRSLICE == stStream.stH264Info.enRefType ||
BASE_PSLICE_REFBYBASE == stStream.stH264Info.enRefType)
{
#ifndef __HuaweiLite__
s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile[i+s32Cnt], &stStream);
#else
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile[i + s32Cnt], &stStreamBufInfo[i], &stStream);
#endif
}
break;
case 1:
if (BASE_IDRSLICE == stStream.stH264Info.enRefType ||
BASE_PSLICE_REFBYBASE == stStream.stH264Info.enRefType ||
BASE_PSLICE_REFBYENHANCE == stStream.stH264Info.enRefType)
{
#ifndef __HuaweiLite__
s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile[i+s32Cnt], &stStream);
#else
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile[i + s32Cnt], &stStreamBufInfo[i], &stStream);
#endif
}
break;
case 2:
#ifndef __HuaweiLite__
s32Ret = SAMPLE_COMM_VENC_SaveStream(pFile[i+s32Cnt], &stStream);
#else
s32Ret = SAMPLE_COMM_VENC_SaveStream_PhyAddr(pFile[i + s32Cnt], &stStreamBufInfo[i], &stStream);
#endif
break;
}
if (HI_SUCCESS != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
SAMPLE_PRT("save stream failed!\n");
break;
}
}
/*******************************************************
step 2.6 : release stream
*******************************************************/
s32Ret = HI_MPI_VENC_ReleaseStream(i, &stStream);
if (HI_SUCCESS != s32Ret)
{
free(stStream.pstPack);
stStream.pstPack = NULL;
break;
}
/*******************************************************
step 2.7 : free pack nodes
*******************************************************/
free(stStream.pstPack);
stStream.pstPack = NULL;
}
}
}
}
/*******************************************************
step 3 : close save-file
*******************************************************/
for (i = 0; i < s32ChnTotal; i++)
{
for (s32Cnt = 0; s32Cnt < 3; s32Cnt++)
{
if (pFile[i + s32Cnt])
{
fclose(pFile[i + s32Cnt]);
}
}
}
return NULL;
}
/******************************************************************************
* funciton : start get venc stream process thread
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_StartGetStream(VENC_CHN VeChn[],HI_S32 s32Cnt)
{
HI_U32 i;
gs_stPara.bThreadStart = HI_TRUE;
gs_stPara.s32Cnt = 1; //s32Cnt;
for(i=0; i<s32Cnt; i++)
{
gs_stPara.VeChn[i] = VeChn[i];
}
return pthread_create(&gs_VencPid, 0, SAMPLE_COMM_VENC_GetVencStreamProc, (HI_VOID*)&gs_stPara);
}
/******************************************************************************
* funciton : start get venc svc-t stream process thread
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_StartGetStream_Svc_t(HI_S32 s32Cnt)
{
gs_stPara.bThreadStart = HI_TRUE;
gs_stPara.s32Cnt = s32Cnt;
return pthread_create(&gs_VencPid, 0, SAMPLE_COMM_VENC_GetVencStreamProc_Svc_t, (HI_VOID*)&gs_stPara);
}
/******************************************************************************
* funciton : stop get venc stream process.
******************************************************************************/
HI_S32 SAMPLE_COMM_VENC_StopGetStream(void)
{
if (HI_TRUE == gs_stPara.bThreadStart)
{
gs_stPara.bThreadStart = HI_FALSE;
pthread_join(gs_VencPid, 0);
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VENC_StopSendQpmapFrame(void)
{
if (HI_TRUE == stQpMapSendFramePara.bThreadStart)
{
stQpMapSendFramePara.bThreadStart = HI_FALSE;
pthread_join(gs_VencQpmapPid, 0);
}
return HI_SUCCESS;
}
HI_VOID SAMPLE_COMM_VENC_ReadOneFrame( FILE* fp, HI_U8* pY, HI_U8* pU, HI_U8* pV,
HI_U32 width, HI_U32 height, HI_U32 stride, HI_U32 stride2)
{
HI_U8* pDst;
HI_U32 u32Row;
pDst = pY;
for ( u32Row = 0; u32Row < height; u32Row++ )
{
fread( pDst, width, 1, fp );
pDst += stride;
}
pDst = pU;
for ( u32Row = 0; u32Row < height / 2; u32Row++ )
{
fread( pDst, width / 2, 1, fp );
pDst += stride2;
}
pDst = pV;
for ( u32Row = 0; u32Row < height / 2; u32Row++ )
{
fread( pDst, width / 2, 1, fp );
pDst += stride2;
}
}
HI_S32 SAMPLE_COMM_VENC_PlanToSemi(HI_U8* pY, HI_S32 yStride,
HI_U8* pU, HI_S32 uStride,
HI_U8* pV, HI_S32 vStride,
HI_S32 picWidth, HI_S32 picHeight)
{
HI_S32 i;
HI_U8* pTmpU, *ptu;
HI_U8* pTmpV, *ptv;
HI_S32 s32HafW = uStride >> 1 ;
HI_S32 s32HafH = picHeight >> 1 ;
HI_S32 s32Size = s32HafW * s32HafH;
pTmpU = malloc( s32Size );
if(pTmpU == HI_NULL)
{
printf("malloc buf failed\n");
return HI_FAILURE;
}
ptu = pTmpU;
pTmpV = malloc( s32Size );
if (pTmpV == HI_NULL)
{
printf("malloc buf failed\n");
free( pTmpU );
return HI_FAILURE;
}
ptv = pTmpV;
memcpy(pTmpU, pU, s32Size);
memcpy(pTmpV, pV, s32Size);
for (i = 0; i<s32Size >> 1; i++)
{
*pU++ = *pTmpV++;
*pU++ = *pTmpU++;
}
for (i = 0; i<s32Size >> 1; i++)
{
*pV++ = *pTmpV++;
*pV++ = *pTmpU++;
}
free( ptu );
free( ptv );
return HI_SUCCESS;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jeremy111hz/hi3516dv300-rtsp-h264.git
[email protected]:jeremy111hz/hi3516dv300-rtsp-h264.git
jeremy111hz
hi3516dv300-rtsp-h264
hi3516dv300-rtsp-h264
master

搜索帮助