⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dectest.cpp

📁 mx27 f14v2 源代码。包括ADS板上诸多驱动的源码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		    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 = PRESCAN_ENABLE_VALUE;
    decParam.prescanMode = 0;
    decParam.skipframeMode = 0;
    decParam.skipframeNum = 0;	
    decParam.iframeSearchEnable = 0;

    rotAngle = 0;
    // 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);

    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 = 240*IMAGE_HEIGHT/IMAGE_WIDTH;//120;//180;//
    gPpConfig.outputStride = 240*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);
    while(g_fLoopTest) {
#ifdef PROFILE_TIME
        if(frameIdx == 100)
            QueryPerformanceCounter(&liTime);
        else if(frameIdx == PROFILE_FRMAE_END_NUM) {
            litmp = liTime;
            QueryPerformanceCounter(&liTime);
            liTime.QuadPart -= litmp.QuadPart;
        }
#endif
        if(decOP.reorderEnable == 1 && decOP.bitstreamFormat == STD_AVC && bFirstFrame) {	
            decParam.prescanEnable = 0;
            bFirstFrame = !bFirstFrame;
        }
	    else
            decParam.prescanEnable = PRESCAN_ENABLE_VALUE;
        // Start decoding a frame.
//		vpu_DecGiveCommand( handle, SET_ROTATOR_OUTPUT, &frameBuf[dispIdx] );
//		if( frameIdx == 0 ) 
//		{
//			vpu_DecGiveCommand(handle, ENABLE_ROTATION, 0);
//			vpu_DecGiveCommand(handle, ENABLE_MIRRORING, 0);
//		}
#ifdef ENC_DEC_SYNC
        WaitForSingleObject(hDecoding, INFINITE);
#endif

    	ret = vpu_DecStartOneFrame(handle, &decParam);
#ifdef PROFILE_TIME
    	if((frameIdx >= 100) && (frameIdx < 4100))
            QueryPerformanceCounter(&liStartTime);
#endif
    	if(ret != RETCODE_SUCCESS) {
            DEBUGMSG(1, (_T("vpu_DecStartOneFrame failed Error code is 0x%x \n"),  ret));
            goto ERR_DEC_OPEN;
    	}

    	WaitForSingleObject(RunEvent, INFINITE);
#ifdef PROFILE_TIME
    	if((frameIdx >= 100) && (frameIdx < PROFILE_FRMAE_END_NUM)) {
            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_OPEN;
    	}		

        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) {
            continue;
    	}
		
    	if(outputInfo.indexFrameDisplay == -3 || outputInfo.indexFrameDisplay == -2) 
            continue; // BIT don't have picture to be displayed
		if (ret == RETCODE_SUCCESS) {
            gPpInputPtr.InYBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufY;
            gPpInputPtr.InUBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufCb;
            gPpInputPtr.InVBuf = (PVOID) frameBuf[outputInfo.indexFrameDisplay].bufCr;
            gPpInputPtr.OutBuf = (PVOID) frameBufferPhysAddr;
			if(codestand == STD_MPEG4)
				gPpInputPtr.InQPBuf = (PVOID) outputInfo.phys_qpInfo;
            WaitForSingleObject(hRateTimerEvent, INFINITE);
            PPAddBuffers(ghPp, &gPpInputPtr); 		  
            WaitForSingleObject(ghPpDisplayEvent, INFINITE);
        }


    	if(outputInfo.numOfErrMBs) {
            totalNumofErrMbs += outputInfo.numOfErrMBs;			
            DEBUGMSG(1, (_T("Num of Error Mbs : %d, in Frame : %d \n"), outputInfo.numOfErrMBs, frameIdx));
    	}		
    	frameIdx++;

    	if(frameIdx == TEST_FRAME_NUM)
            g_fLoopTest = FALSE; // inform the whole system to finish demo
    }
#ifdef PROFILE_TIME
    printf("Dec: total frames:%d", frameIdx);
    printf("Dec: Average time of HW: %f(ms)\n",liHWTime.QuadPart/(fHighFre*PROFILE_FRMAE_NUM)*1000);
    printf("Dec: Averate total time : %f(ms)\n",liTime.QuadPart/(fHighFre*PROFILE_FRMAE_NUM)*1000);
#endif
    // Now wait the encoding thread ending
    if(hEncodeThread) {
    	g_fLoopTest = FALSE;
    	Sleep(200); // Wait the encoding thread to terminate
    	TerminateThread(hEncodeThread, 0);
    	CloseHandle(hEncodeThread);
    	hEncodeThread = NULL;
    }	
    // 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(RunEvent) { 
        CloseHandle(RunEvent);
        RunEvent = NULL;
    }
    CloseHandle(hRateTimerEvent);

ERR_DEC_INIT:
    return ;
}


	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -