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

📄 dectest.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
//
// File: dectest.cpp
//
// Provides the decoder implementation using VPU APIs.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include "vpu_api.h"
#include "bsp.h"
#include "pp.h"
#include "test.h"
#define ENC_DEC_SYNC
#define PS_SAVE_BUFFER_SIZE 60*1024 // 5KB for normal case, Large size allocated here
#define PRESCAN_ENABLE_VALUE 1
#define REORDER_ENABLE_VALUE 0
  
#define MAX_FRAME (16+1+4)    // AVC REF 16, REC 1 , FULL DUP 4	
#define STREAM_END_SIZE (0)  //  
#define NUM_FRAME_BUF MAX_FRAME


extern BOOL g_fLoopTest;
extern PhysicalAddress BitstreamPhy;
extern UINT8* pBitStream; 
extern double fHighFre;

#ifdef ENC_DEC_SYNC
extern HANDLE hDecoding;
#endif

static	PhysicalAddress FrameBufPhy;
static	PhysicalAddress paBsBufStart;	
static	PhysicalAddress paBsBufEnd;
static	UINT8* pFrameBuf;
static  UINT8* pinput;
static  int  inputsize;
static BOOL fLoopFillBufThread;
static DecHandle handle;
static int streameof;

/* For Post Processor */
static HANDLE ghPpDisplayEvent;
static HANDLE ghPp = NULL;
static ppConfigData gPpConfig;
static ppBuffers gPpInputPtr;


int SaveBSBuffer(UINT8* bsBuf0, size_t size0)
{
    RetCode ret;
    Uint32 size;
    int room;
    UINT8* pbuf;
    PhysicalAddress paWrPtr;	
    PhysicalAddress paRdPtr;

    ret = vpu_DecGetBitstreamBuffer(handle, &paRdPtr, &paWrPtr, &size);
    if(ret != RETCODE_SUCCESS) {
    	DEBUGMSG(1, (_T("vpu_DecGetBitstreamBuffer failed Error code is 0x%x \n"),  ret));
    	return 0;
    }
    if (size >= size0) {
        pbuf = pBitStream +(paWrPtr - BitstreamPhy);
        room = paBsBufEnd - paWrPtr;
    	if((paWrPtr + size0) > paBsBufEnd) {
            memcpy(pbuf, bsBuf0, room);
            memcpy(pBitStream, bsBuf0+room, size0-room);
        }
        else
            memcpy(pbuf, bsBuf0, size0);

        ret = vpu_DecUpdateBitstreamBuffer(handle, size0);
        if(ret != RETCODE_SUCCESS) {
            DEBUGMSG(1, (_T("VPU_DecUpdateBitstreamBuffer failed Error code is 0x%x \n"),  ret));
        }		
        return size0;
    }
    return 0;
}

// This function demonstrates how to decode using vpu API.
void DecodeTest(CodStd codestand)
{
    DecOpenParam decOP;
    DecInitialInfo initialInfo;
    DecOutputInfo outputInfo;
    DecParam decParam = { 0 };
    DecBufInfo decBufInfo = { 0 };
    RetCode ret;
    PhysicalAddress paWrPtr;	
    PhysicalAddress paRdPtr;
    Uint32 size;
    UINT YFrameSize;
    int tmp;
    HANDLE hRateTimerEvent;
    HANDLE RunEvent = NULL;
    HANDLE hEncodeThread = NULL;
    MMRESULT TimerId = NULL;
    BOOL bFirstFrame = TRUE;

    FrameBuffer frameBuf[NUM_FRAME_BUF];
    PVOID VframeBuf[NUM_FRAME_BUF];
    int i;
    int frameIdx;
    int exit;
    Uint32 fRateInfo;
    int stride;

    void *pPSSaveBuffer = NULL;
    void *pSliceSaveBuffer = NULL;
    PhysicalAddress AllocatedPhyPtr = 0;
    int totalNumofErrMbs = 0, decodefinish = 0;
    int needbuffercounter;

    int rotStride = 0, dispIdx = 0;
    int rotAngle = 0;
    int fillendBs = 0;
    // MirrorDirection  mirrorDirection;

#ifdef PROFILE_TIME
    LARGE_INTEGER liStartTime = {0}, liStopTime = {0};
    LARGE_INTEGER liTime = {0};
    LARGE_INTEGER liHWTime = {0};
    LARGE_INTEGER litmp = {0};
#endif
    
    VPUMemAlloc  bitstreambuf = {0};
	VPUMemAlloc  framebuffers = {0};
	VPUMemAlloc  pssavebuffer = {0};
	VPUMemAlloc  slicesavebuffer = {0};
    RunEvent = CreateEvent(NULL, FALSE, FALSE, VPU_INT_PIC_RUN_NAME);
    if(RunEvent == NULL) {
    	return ;
    }

    // Create encoding thread
    hEncodeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)EncodeProc, NULL, 0, NULL);
    if(hEncodeThread == NULL) {
    	CloseHandle(RunEvent);
    	return;
    }

/* use the physical address of framebuffer directly*/
    PhysicalAddress frameBufferPhysAddr;
    frameBufferPhysAddr = IMAGE_SHARE_FRAMEBUFFER_RAM_PA_START;
	
 
    // Open an instance and get initial information for decoding.	
    decOP.bitstreamFormat = codestand;
    decOP.bitstreamBuffer = BitstreamPhy;
    decOP.virt_bitstreamBuffer = pBitStream;
    decOP.bitstreamBufferSize = CODEC_BITSTREAM_SIZE;
    paBsBufStart = decOP.bitstreamBuffer;
    paBsBufEnd = decOP.bitstreamBuffer + decOP.bitstreamBufferSize;
	decOP.reorderEnable = REORDER_ENABLE_VALUE;
    decOP.filePlayEnable = 0;
    if(codestand == STD_MPEG4)
		decOP.qpReport = 1;
	else
		decOP.qpReport = 0;

    if(decOP.bitstreamFormat == STD_AVC) {
        if(RETCODE_SUCCESS != vpu_AllocPhysMem(PS_SAVE_BUFFER_SIZE, &pssavebuffer)) {
		    RETAILMSG(1, (_T("AllocPhysMem for Slice save buffer failed  \n")));
		    goto ERR_DEC_OPEN;
		}
        decOP.psSaveBuffer = pssavebuffer.PhysAdd;
        decOP.psSaveBufferSize = PS_SAVE_BUFFER_SIZE;
    }

    ret = vpu_DecOpen(&handle, &decOP);
    if(ret != RETCODE_SUCCESS) {
    	DEBUGMSG(1, (_T("VPU_DecOpen failed Error code is 0x%x \n"),  ret));
    	goto ERR_DEC_INIT;
    }

    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;
    }

    while(size > (CODEC_BITSTREAM_SIZE - 1024*2)) {
    	vpu_DecGetBitstreamBuffer(handle, &paRdPtr, &paWrPtr, &size);
    	Sleep(10);
    }
    
    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)) {

⌨️ 快捷键说明

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