Ai
1 Star 0 Fork 0

steve-dev/ispdsp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
snap_mgr_imp.cpp 16.03 KB
一键复制 编辑 原始数据 按行查看 历史
steve-dev 提交于 2019-04-08 22:27 +08:00 . first commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
#include "snap_mgr_imp.h"
#include "vi_mgr.h"
#include "venc_mgr.h"
#include "guard.h"
#include "sys_ctrl_mgr.h"
using namespace detu_infra;
using namespace Json;
namespace detu_media
{
PATTERN_SINGLETON_IMPLEMENT(SnapMgrImp)
SnapMgrImp::SnapMgrImp(): SnapMgr(), fMutex(MUTEX_RECURSIVE)
{
}
SnapMgrImp::~SnapMgrImp()
{
}
S_Result SnapMgrImp::LoadDspCoreBinary(SVP_DSP_ID_E enCoreId)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_CHAR * aszBin[4][4] = {
{"/usr/data/dsp/dsp0/hi_sram.bin","/usr/data/dsp/dsp0/hi_iram0.bin","/usr/data/dsp/dsp0/hi_dram0.bin","/usr/data/dsp/dsp0/hi_dram1.bin"},
{"/usr/data/dsp/dsp1/hi_sram.bin","/usr/data/dsp/dsp1/hi_iram0.bin","/usr/data/dsp/dsp1/hi_dram0.bin","/usr/data/dsp/dsp1/hi_dram1.bin"},
{"/usr/data/dsp/dsp2/hi_sram.bin","/usr/data/dsp/dsp2/hi_iram0.bin","/usr/data/dsp/dsp2/hi_dram0.bin","/usr/data/dsp/dsp2/hi_dram1.bin"},
{"/usr/data/dsp/dsp3/hi_sram.bin","/usr/data/dsp/dsp3/hi_iram0.bin","/usr/data/dsp/dsp3/hi_dram0.bin","/usr/data/dsp/dsp3/hi_dram1.bin"}};
s32Ret = HI_MPI_SVP_DSP_PowerOn(enCoreId);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_PowerOn failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_LoadBin(aszBin[enCoreId][1], SVP_DSP_MEM_TYPE_E(enCoreId * 4 + 1));
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_LoadBin failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_LoadBin(aszBin[enCoreId][0], SVP_DSP_MEM_TYPE_E(enCoreId * 4 + 0));
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_LoadBin failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_LoadBin(aszBin[enCoreId][2], SVP_DSP_MEM_TYPE_E(enCoreId * 4 + 2));
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_LoadBin failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_LoadBin(aszBin[enCoreId][3], SVP_DSP_MEM_TYPE_E(enCoreId * 4 + 3));
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_LoadBin failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_EnableCore(enCoreId);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_LoadBin failed with %#x!\n", s32Ret);
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
S_Result SnapMgrImp:: UnloadDspCoreBinary(SVP_DSP_ID_E enCoreId)
{
HI_S32 s32Ret = HI_FAILURE;
s32Ret = HI_MPI_SVP_DSP_DisableCore(enCoreId);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_DisableCore failed with %#x!\n", s32Ret);
return S_ERROR;
}
s32Ret = HI_MPI_SVP_DSP_PowerOff(enCoreId);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_SVP_DSP_PowerOff failed with %#x!\n", s32Ret);
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
//初始化
S_Result SnapMgrImp::PhotoSnapInit(PHOTO_ALG_TYPE_E enAlgType,SVP_DSP_ID_E enCoreId,HI_U32 u32Width, HI_U32 u32Height)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_CHAR cBufName[32];
HI_U32 u32PubMemSize = 0;
HI_U64 u64PubPhyAddr;
HI_VOID* pPubVirAddr;
if (S_OK != LoadDspCoreBinary(enCoreId))
{
UnloadDspCoreBinary(enCoreId);
printf("LoadDspCoreBinary failed! \n");
return S_ERROR;
}
if(PHOTO_ALG_TYPE_HDR == enAlgType)
{
snprintf(cBufName, 32, "HdrPubMem");
u32PubMemSize = HDR_GetPublicMemSize(u32Width, u32Height);
}
else if(PHOTO_ALG_TYPE_SFNR == enAlgType)
{
snprintf(cBufName, 32, "SfnrPubMem");
u32PubMemSize = SFNR_GetPublicMemSize(u32Width, u32Height);
}
else if(PHOTO_ALG_TYPE_MFNR == enAlgType)
{
snprintf(cBufName, 32, "MfnrPubMem");
u32PubMemSize = MFNR_GetPublicMemSize(u32Width, u32Height);
}
else if(PHOTO_ALG_TYPE_DE == enAlgType)
{
snprintf(cBufName, 32, "DePubMem");
u32PubMemSize = DE_GetPublicMemSize(u32Width, u32Height);
}
else
{
printf("the enAlgType Error!\n");
return S_ERROR;
}
SysCtrlMgr& sysCtrl = *SysCtrlMgr::instance();
//此接口需要封装
//if (S_OK != sysCtrl.mmzAlloc_Cached(&u64PubPhyAddr, &pPubVirAddr, cBufName, NULL, u32PubMemSize))
{
printf("HI_MPI_SYS_MmzAlloc_Cached failed!\n");
return S_ERROR;
}
PHOTO_ALG_INIT_S stPhotoInit;
stPhotoInit.u64PublicMemPhyAddr = u64PubPhyAddr;
stPhotoInit.u64PublicMemVirAddr = (HI_U64)pPubVirAddr;
stPhotoInit.u32PublicMemSize = u32PubMemSize;
stPhotoInit.bPrintDebugInfo = HI_FALSE;
s32Ret = HI_MPI_PHOTO_AlgInit(enAlgType, &stPhotoInit);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_PHOTO_AlgInit failed!\n");
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
S_Result SnapMgrImp::PhotoSnapProcess(PHOTO_ALG_TYPE_E enAlgType, HI_VOID *pSrcVideoFrame, HI_U32 size)
{
HI_S32 s32Ret = HI_SUCCESS;
VIDEO_FRAME_INFO_S stSrcVideoFrame;
PHOTO_ALG_ATTR_S stPhotoAttr = {0};
HI_U64 u64JpegDCFPhyAddr = 0;
JPEG_DCF_S* pstJpegDcf = HI_NULL;
HI_U32 pu32Iso;
memcpy(&stSrcVideoFrame,pSrcVideoFrame,size);
u64JpegDCFPhyAddr = stSrcVideoFrame->stVFrame.stSupplement.u64JpegDCFPhyAddr;
//pstJpegDcf =(JPEG_DCF_S*)sysCtrl.mmap(u64JpegDCFPhyAddr, sizeof(JPEG_DCF_S));
pstJpegDcf = HI_MPI_SYS_Mmap(u64JpegDCFPhyAddr, sizeof(JPEG_DCF_S));
pu32Iso = pstJpegDcf->stIspDCFInfo.stIspDCFUpdateInfo.u32ISOSpeedRatings;
HI_MPI_SYS_Munmap(pstJpegDcf, sizeof(JPEG_DCF_S));
//SysCtrlMgr& sysCtrl = *SysCtrlMgr::instance();
//if(S_OK != sysCtrl.munmap((JPEG_DCF_S*)pstJpegDcf, sizeof(JPEG_DCF_S)));
{
printf("munmap failed!\n");
return S_ERROR;
}
if(PHOTO_ALG_TYPE_SFNR == enAlgType)
{
memcpy(&stPhotoAttr.stSFNRAttr.stFrm,pSrcVideoFrame,size);
stPhotoAttr.stSFNRAttr.u32ISO = pu32Iso;
}
s32Ret = HI_MPI_PHOTO_AlgProcess(enAlgType, &stPhotoAttr);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_PHOTO_AlgProcess failed!\n");
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
S_Result SnapMgrImp::PhotoSnapProcess(PHOTO_ALG_TYPE_E enAlgType, PHOTO_ALG_ATTR_S *stPhotoAttr)
{
HI_S32 s32Ret = HI_SUCCESS;
s32Ret = HI_MPI_PHOTO_AlgProcess(enAlgType, stPhotoAttr);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_PHOTO_AlgProcess failed!\n");
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
S_Result SnapMgrImp::PhotoSnapDeinit(PHOTO_ALG_TYPE_E enAlgType,SVP_DSP_ID_E enCoreId)
{
HI_S32 s32Ret = HI_SUCCESS;
s32Ret = HI_MPI_PHOTO_AlgDeinit(enAlgType);
if(HI_SUCCESS != s32Ret)
{
printf("HI_MPI_PHOTO_AlgDeinit failed!\n");
return S_ERROR;
}
if(S_OK != UnloadDspCoreBinary(enCoreId))
{
printf("UnloadDspCoreBinary failed!\n");
return S_ERROR;
}
return (HI_SUCCESS == s32Ret) ? S_OK : S_ERROR;
}
//用于触发
S_Result SnapMgrImp::trigger(const Json::Value& viPipeList, const Uint32_t count)
{
S_Result ret = S_ERROR;
do
{
std::vector<ViPipe*> pipes;
if (viPipeList.isArray())
{
ViMgr& viMgr = *ViMgr::instance();
for(int i = 0; i < viPipeList.size(); i++)
{
if (viPipeList[i].isString())
{
ViPipe* pipe;
if (S_OK != viMgr.getPipe(viPipeList[i].asString(), &pipe))
{
printf("get pipe: %s failed!\n", viPipeList[i].asCString());
}
else
{
pipes.push_back(pipe);
}
}
}
}
if (pipes.empty())
{
printf("no snap pipes!\n");
break;
}
do
{
int i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
printf("%s, %d, pipe[%d].startSnap\n", __FUNCTION__, __LINE__, i);
if (S_OK != pipe.startSnap(count))
{
printf("startSnap pipe: %s failed!\n", viPipeList[i].asCString());
break;
}
printf("%s, %d, pipe[%d].startSnap done\n", __FUNCTION__, __LINE__, i);
}
}
printf("%s, %d, pipes.startSnap done\n", __FUNCTION__, __LINE__);
if (i < pipes.size())
{
printf("startSnap pipes failed!\n");
i--;
for (; i >= 0; i--)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
if (S_OK != pipe.stopSnap())
{
printf("stopSnap pipe: %s failed!\n", viPipeList[i].asCString());
}
}
}
break;
}
do
{
i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
printf("%s, %d, pipe[%d].triggerSnap\n", __FUNCTION__, __LINE__, i);
int j = 0;
for(; j < count; j++)
{
if (S_OK != pipe.triggerSnap())
{
printf("triggerSnap pipe: %s failed!\n", viPipeList[i].asCString());
break;
}
}
if (j < count)
break;
else
printf("%s, %d, pipe[%d].triggerSnap done\n", __FUNCTION__, __LINE__, i);
}
}
printf("%s, %d, pipes.triggerSnap done\n", __FUNCTION__, __LINE__);
if (i < pipes.size())
{
printf("triggerSnap pipes failed!\n");
break;
}
}
while(0);
sleep(1);
i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
if (S_OK != pipe.stopSnap())
{
printf("stopSnap pipe: %s failed!\n", viPipeList[i].asCString());
}
}
}
}
while(0);
}
while(0);
return ret;
}
//dsp 拍照处理
S_Result SnapMgrImp::process(const Json::Value& vpssList, StreamMap& streams, const Uint32_t count)
{
S_Result ret = S_ERROR;
do
{
std::vector<VpssGrp*> vpssgrps;
// std::vector<VpssChn*> vpsschns;
if (vpssList.isArray())
{
VpssMgr& vpssMgr = *VpssMgr::instance();
for(int i = 0; i < vpssList.size(); i++)
{
if (vpssList[i].isString())
{
VpssGrp* vpssgrp;
if (S_OK != vpssMgr.getGrp(vpssList[i].asString(), &vpssgrp))
{
printf("get pipe: %s failed!\n", vpssList[i].asCString());
}
else
{
vpssgrps.push_back(vpssgrp);
}
#if 0
VpssChn* vpsschn;
if(S_OK != vpssgrp->getChn(vpssList[i]["chns"].asString(),&vpsschn));
{
printf("get chn failed!\n");
}
else
{
vpsschns.push_back(vpsschn);
}
#endif
}
}
}
#if 0
if (vpsschns.empty())
{
printf("no snap vpsschns!\n");
break;
}
#endif
if (vpssgrps.empty())
{
printf("no snap vpssgrps!\n");
break;
}
}
while(0);
return ret;
}
S_Result SnapMgrImp::encode(const Json::Value& vencChnList, StreamMap& unencoded, StreamMap& encoded, const Uint32_t count)
{
S_Result ret = S_ERROR;
do
{
}
while(0);
return ret;
}
S_Result SnapMgrImp::snap(const Json::Value& snapTarget, StreamMap& photos, const Uint32_t count)
{
Guard guard(fMutex);
S_Result ret = S_ERROR;
do
{
}
while(0);
return ret;
}
#if 0
S_Result SnapMgrImp::snap(const Json::Value& snapList, StreamMap& streams, const Uint32_t count)
{
Guard guard(fMutex);
S_Result ret = S_ERROR;
do
{
std::vector<ViPipe*> pipes;
if (snapList.isMember("pipes") && snapList["pipes"].isArray())
{
const Value& pipeNames = snapList["pipes"];
ViMgr& viMgr = *ViMgr::instance();
for(int i = 0; i < pipeNames.size(); i++)
{
if (pipeNames[i].isString())
{
ViPipe* pipe;
if (S_OK != viMgr.getPipe(pipeNames[i].asString(), &pipe))
{
printf("get pipe: %s failed!\n", pipeNames[i].asCString());
}
else
{
pipes.push_back(pipe);
}
}
}
}
if (pipes.empty())
{
printf("no snap pipes!\n");
break;
}
std::vector<VencChn*> chns;
if (snapList.isMember("chns") && snapList["chns"].isArray())
{
const Value& chnNames = snapList["chns"];
VencMgr& vencMgr = *VencMgr::instance();
for(int i = 0; i < chnNames.size(); i++)
{
if (chnNames[i].isString())
{
VencChn* chn;
if (S_OK != vencMgr.getChn(chnNames[i].asString(), &chn))
{
printf("get chn: %s failed!\n", chnNames[i].asCString());
}
else
{
chns.push_back(chn);
}
}
}
}
if (chns.empty())
{
printf("no snap chns!\n");
break;
}
int i = 0;
for (; i < chns.size(); i++)
{
if(chns[i])
{
VencChn& chn = *chns[i];
printf("%s, %d, chn[%d].start\n", __FUNCTION__, __LINE__, i);
if (S_OK != chn.start(count))
{
printf("start chn: %s failed!\n", snapList["chns"][i].asCString());
break;
}
printf("%s, %d, chn[%d].start done\n", __FUNCTION__, __LINE__, i);
}
}
printf("%s, %d, chns.start done\n", __FUNCTION__, __LINE__);
if (i < chns.size())
{
printf("start chns failed!\n");
i--;
for(; i >= 0; i--)
{
if(chns[i])
{
VencChn& chn = *chns[i];
if (S_OK != chn.stop())
{
printf("stop chn: %s failed!\n", snapList["chns"][i].asCString());
}
}
}
break;
}
do
{
i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
printf("%s, %d, pipe[%d].startSnap\n", __FUNCTION__, __LINE__, i);
if (S_OK != pipe.startSnap(count))
{
printf("startSnap pipe: %s failed!\n", snapList["pipes"][i].asCString());
break;
}
printf("%s, %d, pipe[%d].startSnap done\n", __FUNCTION__, __LINE__, i);
}
}
printf("%s, %d, pipes.startSnap done\n", __FUNCTION__, __LINE__);
if (i < pipes.size())
{
printf("startSnap pipes failed!\n");
i--;
for (; i >= 0; i--)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
if (S_OK != pipe.stopSnap())
{
printf("stopSnap pipe: %s failed!\n", snapList["pipes"][i].asCString());
}
}
}
break;
}
do
{
i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
printf("%s, %d, pipe[%d].triggerSnap\n", __FUNCTION__, __LINE__, i);
if (S_OK != pipe.triggerSnap())
{
printf("triggerSnap pipe: %s failed!\n", snapList["pipes"][i].asCString());
break;
}
printf("%s, %d, pipe[%d].triggerSnap done\n", __FUNCTION__, __LINE__, i);
}
}
printf("%s, %d, pipes.triggerSnap done\n", __FUNCTION__, __LINE__);
if (i < pipes.size())
{
printf("triggerSnap pipes failed!\n");
break;
}
int j = 0;
std::vector<Uint32_t> seqVec(chns.size(), 0u);
for (; j < count; j++)
{
for (i = 0; i < chns.size(); i++)
{
if(chns[i])
{
VencChn& chn = *chns[i];
Stream stream;
StreamInfo info;
printf("%s, %d, chn[%d].getStream\n", __FUNCTION__, __LINE__, i);
if (S_OK != chn.getStream(seqVec[i], stream, info))
{
printf("getStream of chn: %s failed!\n", snapList["chns"][i].asCString());
break;
}
printf("%s, %d, chn[%d].getStream done\n", __FUNCTION__, __LINE__, i);
streams[snapList["chns"][i].asString()].push_back(stream);
stream.fAddr = NULL;
}
}
printf("%s, %d, chns.getStream done\n", __FUNCTION__, __LINE__, i);
if (i < chns.size())
{
printf("getStream of chns failed! curCount: %d\n", j);
break;
}
}
if (j < count)
{
printf("getStreams of chns failed!\n");
break;
}
ret = S_OK;
}
while(0);
i = 0;
for (; i < pipes.size(); i++)
{
if(pipes[i])
{
ViPipe& pipe = *pipes[i];
if (S_OK != pipe.stopSnap())
{
printf("stopSnap pipe: %s failed!\n", snapList["pipes"][i].asCString());
}
}
}
}
while(0);
i = 0;
for (; i < chns.size(); i++)
{
if(chns[i])
{
VencChn& chn = *chns[i];
if (S_OK != chn.stop())
{
printf("stop chn: %s failed!\n", snapList["chns"][i].asCString());
}
}
}
}
while(0);
return ret;
}
#endif
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/steve-dev/ispdsp.git
git@gitee.com:steve-dev/ispdsp.git
steve-dev
ispdsp
ispdsp
master

搜索帮助