代码拉取完成,页面将自动刷新
#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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。