📄 dectest.cpp
字号:
ret = vpu_DecGetBitstreamBuffer(handle, &paRdPtr, &paWrPtr, &size);
if(ret != RETCODE_SUCCESS) {
DEBUGMSG(1, (_T("VPU_DecGetBitstreamBuffer failed Error code is 0x%x \n"), ret));
goto ERR_DEC_OPEN;
}
FillBsBuffer(paWrPtr, paBsBufStart, paBsBufEnd, STREAM_FILL_SIZE, &streameof);
ret = vpu_DecUpdateBitstreamBuffer(handle, STREAM_FILL_SIZE);
if(ret != RETCODE_SUCCESS) {
DEBUGMSG(1, (_T("VPU_DecUpdateBitstreamBuffer failed Error code is 0x%x \n"), ret));
goto ERR_DEC_OPEN;
}
vpu_DecSetEscSeqInit( handle, 1 );
ret = vpu_DecGetInitialInfo(handle, &initialInfo);
if(ret != RETCODE_SUCCESS) {
DEBUGMSG(1, (_T("vpu_DecGetInitialInfo failed Error code is 0x%x \n"), ret));
goto ERR_DEC_OPEN;
}
vpu_DecSetEscSeqInit( handle, 0 );
fRateInfo = initialInfo.frameRateInfo;
RETAILMSG(1,(_T("picWidth: %u, picHeight: %u, frameRate: %.2f, frRes: %u, frDiv: %u\n"),
initialInfo.picWidth, initialInfo.picHeight, (double)(fRateInfo & 0xffff)/
((fRateInfo >> 16) + 1), fRateInfo & 0xffff, fRateInfo >> 16));
initialInfo.picWidth = ((initialInfo.picWidth + 15) & ~15);
initialInfo.picHeight = ((initialInfo.picHeight + 15) & ~15);
stride = initialInfo.picWidth;
YFrameSize = initialInfo.picWidth * initialInfo.picHeight;
tmp = (int) (YFrameSize * 1.5);
needbuffercounter = initialInfo.minFrameBufferCount + 2;
//allocate memory for framebuffer
if(RETCODE_SUCCESS != vpu_AllocPhysMem(tmp * needbuffercounter, &framebuffers)) {
printf("AllocPhysMem failed\n");
goto ERR_DEC_OPEN;
}
pFrameBuf = (UINT8*)framebuffers.VirtAdd;
FrameBufPhy = framebuffers.PhysAdd;
for (i = 0; i < needbuffercounter; i++) {
frameBuf[i].bufY = FrameBufPhy + tmp * i ;
frameBuf[i].bufCb = frameBuf[i].bufY + YFrameSize;
frameBuf[i].bufCr = frameBuf[i].bufCb + YFrameSize/4;
VframeBuf[i] = (PVOID) (pFrameBuf + tmp * i) ;
}
// Allocate memory for Slice save buffer for H264
// Size is initialInfo.worstSliceSize or initialInfo.normalSliceSize
// Now worst case is used
if (decOP.bitstreamFormat == STD_AVC) {
if(RETCODE_SUCCESS != vpu_AllocPhysMem(initialInfo.worstSliceSize*1024, &slicesavebuffer)) {
RETAILMSG(1, (_T("AllocPhysMem for Slice save buffer failed \n")));
goto ERR_DEC_OPEN;
}
decBufInfo.avcSliceBufInfo.sliceSaveBuffer = slicesavebuffer.PhysAdd;
decBufInfo.avcSliceBufInfo.sliceSaveBufferSize = initialInfo.worstSliceSize*1024;
}
// Register frame buffers requested by the decoder.
ret = vpu_DecRegisterFrameBuffer(handle, frameBuf, initialInfo.minFrameBufferCount, stride, &decBufInfo);
if( ret != RETCODE_SUCCESS ) {
DEBUGMSG(1, (_T("vpu_DecRegisterFrameBuffer failed Error code is 0x%x \n"), ret));
goto ERR_DEC_OPEN;
}
decParam.dispReorderBuf = 0;
decParam.prescanEnable = 1;
decParam.prescanMode = 0;
decParam.skipframeMode = 0;
decParam.skipframeNum = 0;
decParam.iframeSearchEnable = 0;
rotAngle = 0;
#ifdef EN_ROTATION
dispIdx = initialInfo.minFrameBufferCount+1;
vpu_DecGiveCommand(handle, SET_ROTATION_ANGLE, &rotAngle);
mirrorDirection = MIRDIR_VER;
vpu_DecGiveCommand(handle, SET_MIRROR_DIRECTION, &mirrorDirection);
rotStride = ( rotAngle == 90 || rotAngle == 270 ) ? initialInfo.picHeight : initialInfo.picWidth;
vpu_DecGiveCommand(handle, SET_ROTATOR_STRIDE, &rotStride);
#endif
exit = 0;
frameIdx = 0;
// Init pp module
ghPp = PPOpenHandle();
if (ghPp == NULL) {
DEBUGMSG(1, (_T("vPPOpenHandle is failed\r\n")));
goto ERR_DEC_OPEN;
}
ghPpDisplayEvent = CreateEvent(NULL, FALSE, FALSE, PP_EOF_EVENT_NAME);
if (ghPpDisplayEvent == NULL) {
DEBUGMSG(1, (_T("CreateEvent is failed\r\n")));
goto ERR_DEC_OPEN;
}
UINT16 inWidth, inHeigh;
inWidth = rotAngle == 90 || rotAngle == 270 ? initialInfo.picHeight : initialInfo.picWidth;
inHeigh = rotAngle == 90 || rotAngle == 270 ? initialInfo.picWidth : initialInfo.picHeight;
if(codestand == STD_MPEG4)
gPpConfig.bDeblock = TRUE;
else
gPpConfig.bDeblock = FALSE;
gPpConfig.bDering = FALSE;
gPpConfig.inputSize.width = inWidth;
gPpConfig.inputSize.height = inHeigh;
gPpConfig.inputStride = 0;
gPpConfig.outputSize.width = 240;//176;//240;//
gPpConfig.outputSize.height = 180;//120;//180;//
gPpConfig.outputStride = 240*2;//640*2;
gPpConfig.outputFormat = ppCSCOutputFormat_RGB16;
gPpConfig.outputPixelFormat.component0_width = 5;
gPpConfig.outputPixelFormat.component1_width = 6;
gPpConfig.outputPixelFormat.component2_width = 5;
gPpConfig.outputPixelFormat.component0_offset = 11;
gPpConfig.outputPixelFormat.component1_offset = 5;
gPpConfig.outputPixelFormat.component2_offset = 0;
gPpConfig.CSCEquation = ppCSCEquationA_1;
PPConfigure(ghPp, &gPpConfig);
PPStart(ghPp);
if((initialInfo.frameRateInfo<=0) || (initialInfo.frameRateInfo > 30))
initialInfo.frameRateInfo = 30;
/* Init the Timer for framerate control */
hRateTimerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// Starts a timer event for display
TimerId = timeSetEvent(1000/initialInfo.frameRateInfo, 0, (LPTIMECALLBACK)hRateTimerEvent, 0, TIME_CALLBACK_EVENT_SET|TIME_PERIODIC);
if(!TimerId) {
DEBUGMSG(1, (_T("timeSetEvent is failed\r\n")));
goto ERR_DEC_OPEN;
}
CeSetThreadPriority(GetCurrentThread(), 240);
#ifdef PROFILE_TIME
QueryPerformanceFrequency(&litmp);
fHighFre = (double)litmp.QuadPart;
QueryPerformanceCounter(&liTime);
#endif
while(control) {
SetEvent(hFillBufEvent); // Signal the FillBufThread to fill buffer
if(decOP.reorderEnable == 1 && decOP.bitstreamFormat == STD_AVC && bFirstFrame) {
decParam.prescanEnable = 0;
bFirstFrame = !bFirstFrame;
}
else
decParam.prescanEnable = PRESCAN_ENABLE_VALUE;
// Start decoding a frame.
#ifdef EN_ROTATION
vpu_DecGiveCommand( handle, SET_ROTATOR_OUTPUT, &frameBuf[dispIdx] );
if(frameIdx == 0) {
vpu_DecGiveCommand(handle, ENABLE_ROTATION, 0);
// vpu_DecGiveCommand(handle, ENABLE_MIRRORING, 0);
}
#endif
ret = vpu_DecStartOneFrame(handle, &decParam);
#ifdef PROFILE_TIME
QueryPerformanceCounter(&liStartTime);
#endif
if(ret != RETCODE_SUCCESS) {
DEBUGMSG(1, (_T("vpu_DecStartOneFrame failed Error code is 0x%x \n"), ret));
goto ERR_DEC_RUN;
}
WaitForSingleObject(RunEvent, INFINITE);
#ifdef PROFILE_TIME
QueryPerformanceCounter(&liStopTime);
liHWTime.QuadPart += (liStopTime.QuadPart - liStartTime.QuadPart);
#endif
// vpu_DecGetOutputInfo() should match vpu_DecStartOneFrame() with
// the same handle. No other API functions can intervene between these two
// functions, except for vpu_IsBusy(), vpu_DecGetBistreamBuffer(),
// and vpu_DecUpdateBitstreamBuffer().
ret = vpu_DecGetOutputInfo(handle, &outputInfo);
if(ret != RETCODE_SUCCESS) {
DEBUGMSG(1, (_T("vpu_DecGetOutputInfo failed Error code is 0x%x \n"), ret));
goto ERR_DEC_RUN;
}
if(outputInfo.notSufficientPsBuffer) {
DEBUGMSG(1, (_T("PS Buffer overflow framdIdx %d, Exit decoding... \n"), frameIdx));
decodefinish = 1;
}
if(outputInfo.notSufficientSliceBuffer) {
DEBUGMSG(1, (_T("Slice Buffer overflow framdIdx %d \n"), frameIdx));
}
if(outputInfo.indexFrameDisplay == -1)
decodefinish = 1;
else if((outputInfo.indexFrameDisplay > needbuffercounter) && (outputInfo.prescanresult != 0))
decodefinish = 1;
if(decodefinish)
break;
if(outputInfo.prescanresult == 0) {
printf("Prescan\n");
continue;
}
if(outputInfo.indexFrameDisplay == -3 || outputInfo.indexFrameDisplay == -2)
continue; // BIT don't have picture to be displayed
if (ret == RETCODE_SUCCESS) {
#ifdef EN_ROTATION
gPpInputPtr.InYBuf = (PVOID) frameBuf[dispIdx].bufY;
gPpInputPtr.InUBuf = (PVOID) frameBuf[dispIdx].bufCb;
gPpInputPtr.InVBuf = (PVOID) frameBuf[dispIdx].bufCr;
#else
gPpInputPtr.InYBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufY;
gPpInputPtr.InUBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufCb;
gPpInputPtr.InVBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufCr;
#endif
gPpInputPtr.OutBuf = (PVOID) frameBufferPhysAddr;
if(codestand == STD_MPEG4)
gPpInputPtr.InQPBuf = (PVOID) outputInfo.phys_qpInfo;
WaitForSingleObject(hRateTimerEvent, INFINITE);
PPAddBuffers(ghPp, &gPpInputPtr);
WaitForSingleObject(ghPpDisplayEvent, INFINITE);
}
else control = 0;
if( outputInfo.numOfErrMBs ) {
totalNumofErrMbs += outputInfo.numOfErrMBs;
DEBUGMSG(1, (_T("Num of Error Mbs : %d, in Frame : %d \n"), outputInfo.numOfErrMBs, frameIdx));
}
frameIdx++;
}
ERR_DEC_RUN:
#ifdef PROFILE_TIME
litmp = liTime;
QueryPerformanceCounter(&liTime);
liTime.QuadPart -= litmp.QuadPart;
printf("Dec: Average time of HW: %f(ms)\n",liHWTime.QuadPart/(fHighFre*frameIdx)*1000);
printf("Dec: Averate total time: %f(ms)\n",liTime.QuadPart/(fHighFre*frameIdx)*1000);
#endif
// Cancels the timer event
timeKillEvent(TimerId);
// Now that we are done with encoding, close the open instance.
ERR_DEC_OPEN:
vpu_DecClose(handle);
if(bitstreambuf.PhysAdd)
vpu_FreePhysMem(&bitstreambuf);
if(framebuffers.PhysAdd)
vpu_FreePhysMem(&framebuffers);
if(pssavebuffer.PhysAdd)
vpu_FreePhysMem(&pssavebuffer);
if(slicesavebuffer.PhysAdd)
vpu_FreePhysMem(&slicesavebuffer);
if (ghPp != NULL) {
PPStop(ghPp);
PPCloseHandle(ghPp);
ghPp = NULL;
}
if (ghPpDisplayEvent != NULL) {
CloseHandle(ghPpDisplayEvent);
ghPpDisplayEvent = NULL;
}
if(hFillBufIST) {
fLoopFillBufThread = FALSE; // Give the IST a chance to terminate itself
SetEvent(hFillBufEvent);
}
if(hFillBufEvent){
CloseHandle(hFillBufEvent);
hFillBufEvent = NULL;
}
if(hFillBufIST){
CloseHandle(hFillBufIST);
hFillBufEvent = NULL;
}
if(RunEvent) {
CloseHandle(RunEvent);
RunEvent = NULL;
}
CloseHandle(hRateTimerEvent);
ERR_DEC_INIT:
vpu_Deinit();
}
int main()
{
CodStd codestand;
hFile = CreateFileForMapping (TEXT("\\sd memory\\news_sif_cut.mpeg4"), GENERIC_READ,
FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_RANDOM_ACCESS,0);
if (hFile != INVALID_HANDLE_VALUE) {
// Get the size of the file
inputsize = GetFileSize(hFile, NULL);
hFileMap = CreateFileMapping (hFile, NULL, PAGE_READONLY, 0, 0, 0);
if (hFileMap)
{
codestand = STD_MPEG4;
DecodeTest(codestand);
CloseHandle (hFileMap);
}
CloseHandle (hFile);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -