📄 dectest.cpp
字号:
//-----------------------------------------------------------------------------
//
// 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"
//#define EN_ROTATION
#define PROFILE_TIME
#define PS_SAVE_BUFFER_SIZE 60*1024 // 5KB for normal case, Large size allocated here
#define PRESCAN_ENABLE_VALUE 0
#define REORDER_ENABLE_VALUE 0
#define MAX_FRAME (16+1+4) // AVC REF 16, REC 1 , FULL DUP 4
#define STREAM_FILL_SIZE ( 512*8*8 ) // 4 * 1024 | 512 | 512+256( wrap around test )
#define STREAM_END_SIZE (0) //
#define NUM_FRAME_BUF MAX_FRAME
#define PRJ_TRISTAN 0xF000
#define PRJ_TRISTAN_REV 0xF001
#define PRJ_PRISM_CX 0xF002
#define PRJ_SHIVA 0xF003
#define PRJ_PRISM_EX 0xF004
PhysicalAddress BitstreamPhy;
UINT8* pBitStream;
static PhysicalAddress FrameBufPhy;
static PhysicalAddress paBsBufStart;
static PhysicalAddress paBsBufEnd;
static UINT8* pFrameBuf;
static UINT8* pinput;
static int inputsize;
static HANDLE hFile, hFileMap;
static HANDLE hFillBufEvent;
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;
static HANDLE pfoutput;
static int FillBsBuffer(PhysicalAddress targetAddr, PhysicalAddress bsBufStartAddr, PhysicalAddress bsBufEndAddr,
int size, int *streameof)
{
static int inputoffset = 0;
int maplen;
int room;
if(inputsize == 0){
*streameof = 1;
return 0;
}
if(size >= inputsize)
maplen = inputsize;
else
maplen = size;
pinput = (UINT8*)MapViewOfFile (hFileMap, FILE_MAP_READ, 0, inputoffset, maplen);
if (pinput) {
UINT8* pbuf = pBitStream +(targetAddr - BitstreamPhy);
room = bsBufEndAddr - targetAddr; // The size from target address to the buffer end in bytes
if(inputsize >= size) {
if((targetAddr + size) > bsBufEndAddr){ // Bitstream wrapped-around case
memcpy(pbuf, pinput, room);
memcpy(pBitStream, pinput+room, size-room); // Wrapped-around bitstream buffer
}
else { // Not wrapped-around
memcpy(pbuf, pinput, size);
}
pinput += size;
inputsize -= size;
}
else{
if((targetAddr + size) > bsBufEndAddr){ // Bitstream wrapped-around case
if(room > inputsize) { // The available data is less than the size required
memcpy(pbuf, pinput, inputsize);
memset(pbuf+inputsize, 0, room-inputsize); // Fill the 0 to the remainder buffer
memset(pBitStream, 0, size-room); // Wrapped-around bitstream buffer
} else {
memcpy(pbuf, pinput, room);
memcpy(pBitStream, pinput+room, inputsize-room);
memset(pBitStream+inputsize-room, 0, size - inputsize);
}
}
else {
memcpy(pbuf, pinput, inputsize);
memset(pbuf+inputsize, 0, size-inputsize);
}
inputsize = 0;
}
inputoffset += maplen;
// Start cleanup by unmapping view.
UnmapViewOfFile (pinput);
return 1;
}
return 0;
}
static DWORD WINAPI FillBufThread(LPVOID lpParameter)
{
RetCode ret;
PhysicalAddress paWrPtr;
PhysicalAddress paRdPtr;
Uint32 size;
int readnum;
int fillendBs = 0, decodefinish = 0;
//CeSetThreadPriority(GetCurrentThread(), 252);
while(fLoopFillBufThread) {
WaitForSingleObject(hFillBufEvent, INFINITE);
if(!fLoopFillBufThread)
break;
ret = vpu_DecGetBitstreamBuffer(handle, &paRdPtr, &paWrPtr, &size);
if(ret != RETCODE_SUCCESS)
DEBUGMSG(1, (_T("vpu_DecGetBitstreamBuffer failed Error code is 0x%x \n"), ret));
if (size >= STREAM_FILL_SIZE) {
readnum = FillBsBuffer(paWrPtr, paBsBufStart, paBsBufEnd, STREAM_FILL_SIZE, &streameof);
if(streameof == 0){
ret = vpu_DecUpdateBitstreamBuffer(handle, STREAM_FILL_SIZE);
if( ret != RETCODE_SUCCESS ) {
DEBUGMSG(1, (_T("VPU_DecUpdateBitstreamBuffer failed Error code is 0x%x \n"), ret));
}
}
else {
if( !fillendBs ) {
ret = vpu_DecUpdateBitstreamBuffer(handle, STREAM_END_SIZE);
if( ret != RETCODE_SUCCESS ) {
DEBUGMSG(1, (_T("VPU_DecUpdateBitstreamBuffer failed Error code is 0x%x \n"), ret));
}
fillendBs = 1;
}
}
}
}
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;
BOOL bFirstFrame = TRUE;
void *pPSSaveBuffer = NULL;
void *pSliceSaveBuffer = NULL;
PhysicalAddress AllocatedPhyPtr = 0;
int needbuffercounter;
HANDLE hRateTimerEvent;
HANDLE RunEvent = NULL;
HANDLE hFillBufIST = NULL;
MMRESULT TimerId = NULL;
FrameBuffer frameBuf[NUM_FRAME_BUF];
PVOID VframeBuf[NUM_FRAME_BUF];
int i;
int frameIdx;
int exit;
Uint32 fRateInfo;
int stride;
int totalNumofErrMbs = 0, decodefinish = 0;
int rotStride = 0, dispIdx = 0;
int control = 1;
int rotAngle = 0;
int readnum = 0;
int fillendBs = 0;
#ifdef EN_ROTATION
MirrorDirection mirrorDirection;
#endif
#ifdef PROFILE_TIME
LARGE_INTEGER liStartTime = {0}, liStopTime = {0};
LARGE_INTEGER liTime = {0};
LARGE_INTEGER liHWTime = {0};
LARGE_INTEGER litmp = {0};
#endif
double fHighFre = 0;
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 ;
}
hFillBufEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if(RunEvent == NULL) {
CloseHandle(RunEvent);
return ;
}
// Create IST thread to fill stream buffer
fLoopFillBufThread = TRUE;
hFillBufIST = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)FillBufThread, NULL, 0, NULL);
if(hFillBufIST == NULL) {
CloseHandle(RunEvent);
CloseHandle(hFillBufEvent);
return;
}
// use the physical address of framebuffer directly
PhysicalAddress frameBufferPhysAddr;
frameBufferPhysAddr = IMAGE_SHARE_FRAMEBUFFER_RAM_PA_START;
// Initiate vpu*/
ret = vpu_Init(); // Disable interrupt
if( ret != RETCODE_SUCCESS &&
ret != RETCODE_CALLED_BEFORE ) {
DEBUGMSG(1, (_T("vpu_Init failed Error code is 0x%x \n"), ret));
goto ERR_DEC_INIT;
}
{ // check version
char productstr[18]={0};
char versionstr[18]={0};
Uint32 versioninfo;
Uint16 pn;
Uint16 version;
Uint8 ipprjnum;
vpu_GetVersionInfo( &versioninfo );
pn = (Uint16)(versioninfo>>16);
version = (Uint16)versioninfo;
ipprjnum = (Uint8)(pn);
switch(ipprjnum) {
case (PRJ_TRISTAN & 0x0f):
strcpy(productstr, "TRISTANeX");
break;
case (PRJ_TRISTAN_REV & 0x0f):
strcpy(productstr, "TRISTANeX-Rev");
break;
case (PRJ_PRISM_CX & 0x0f):
strcpy(productstr, "PRiSM-CX");
break;
case (PRJ_SHIVA & 0x0f):
strcpy(productstr, "Shiva");
break;
case (PRJ_PRISM_EX & 0x0f):
strcpy(productstr, "PRiSM-EX");
break;
default: break;
}
sprintf( versionstr, "%04d.%04d.%08d", (version>>(12))&0x0f, (version>>(8))&0x0f, (version)&0xff );
RETAILMSG(1, (_T("VPU Firmware Version => \n product : %S | version : %S\n\n"), productstr, versionstr));
}
//bitstream buffer init ...
if (RETCODE_SUCCESS != vpu_AllocPhysMem(0x040000, &bitstreambuf)) {
goto ERR_DEC_OPEN;
}
pBitStream = (UINT8 *)bitstreambuf.VirtAdd;
BitstreamPhy = bitstreambuf.PhysAdd;
// Open an instance and get initial information for decoding.
decOP.bitstreamFormat = codestand;
decOP.bitstreamBuffer = BitstreamPhy;
decOP.virt_bitstreamBuffer = pBitStream;
decOP.bitstreamBufferSize = 0x040000;
paBsBufStart = decOP.bitstreamBuffer;
paBsBufEnd = decOP.bitstreamBuffer + decOP.bitstreamBufferSize;
decOP.reorderEnable = 0;
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -