📄 vldtest.c
字号:
if (data == 0x8) {
vldGetBits(instance, 4, &data);
pictinfo->hForwRSize = data - 1;
vldGetBits(instance, 4, &data);
pictinfo->vForwRSize = data - 1;
vldGetBits(instance, 4, &data);
pictinfo->hBackRSize = data - 1;
vldGetBits(instance, 4, &data);
pictinfo->vBackRSize = data - 1;
vldGetBits(instance, 4, &data);
pictinfo->pictureStruct = data & 0x3;
vldGetBits(instance, 10, &data);
pictinfo->framePFrameD = (data & 0x100) >> 8;
DP(("FramePFrameD: %d 0x%x\n", pictinfo->framePFrameD, data));
pictinfo->intraVLC = (data & 0x20) >> 5;
pictinfo->concealMV = (data & 0x80) >> 7;
pictinfo->mpeg2Mode = 1;
}
vldNextStartCode(instance, &data);
}
/*
* If next start code is extension or user start code, parse off
* extension data.
*/
while (data == EXT_START_CODE || data == USER_START_CODE) {
vldFlushBits(instance, 8);
vldNextStartCode(instance, &data);
}
DP(("finished parse picture \n"));
return 0;
}
/************************************************************************
static Int parseSlice(void)
Parses off slice header. quantizer scale is recorded into VLD
****************************************************************************/
static Int
parseSlice(void)
{
UInt32 data;
DP(("parse slice begin \n"));
/*
* Flush slice start code. vldNextStartCode already flushed 24 bits.
*/
/* Parse off slice vertical position. */
vldGetBits(instance, 8, &data);
DP(("slice_vert_pos(last 8 bit value of slice startcode): 0x%x\n", data));
/*
* skip scalable and vertical position extension since we are doing
* only main profile, main level
*/
/*
* Parse off quantization scale and pass it to VLD
*/
vldGetBits(instance, 5, &data);
vldSetQS(data);
DP(("quant_scale_code: 0x%x \n", data));
/*
* parse off extra bit slice
*/
vldGetBits(instance, 1, &data);
while (data == 1) {
vldFlushBits(instance, 8);
vldGetBits(instance, 1, &data);
}
DP(("finished slice parse \n"));
return 0;
}
/************************************************************************
static Int decodeframe(vldPictureInfo_t *pictinfo)
Decode one frame using pictinfo
****************************************************************************/
static Int
decodeframe(vldPictureInfo_t * pictinfo)
{
static vldMBHMpeg2_t *mbhRef = (vldMBHMpeg2_t *) MbhRef;
static UInt32 *tokenRef = (UInt32 *) TokenRef;
UInt32 data, status;
Int frameDone, mbDone;
vldMBHMpeg2_t *mbh = Mbh;
UInt32 *token = Token;
UInt mpeg2Mode = pictinfo->mpeg2Mode;
Int cbp;
Int mStatus, tStatus;
reportPictureInfo(pictinfo);
vldSetPictureInfo(instance, pictinfo);
ERROR_IF_NOT_OK(parseSlice());
frameDone = False;
ParsedMbs = 0;
ErrorMbs = 0;
while (frameDone == False) {
/*
* No need to invalidate the buffer here since they are read
* only and we invalidate right before reading. Give enough
* counts so that the corresponding STATUS bits are not set.
*/
ERROR_IF_NOT_OK(vldParseMacroblocks(instance, 1, (Pointer) mbh, (Pointer) token,
VLD_MAX_MHB, VLD_MAX_RL));
mbDone = False;
while (mbDone == False) {
/*
* Wait until any of the VLD status bits are set
* except for the VLD_STATUS_DMA_IN_DONE bit. When
* that bit is set, VLD generates an interrupt and it
* is handled in ISR.
*/
status = GET_RETURN_VALUE_FROM_HVLD;
while (status == 0) {
if (vldGetEmptyFlag(instance) == True) {
inputEmptyCallback(pvidStream, True);
}
status = GET_RETURN_VALUE_FROM_HVLD;
}
vldClearSTATUS();
switch (status) {
case VLD_STATUS_SUCCESS:
{
/*
* One macro block done successfully.
*/
_cache_invalidate(mbh, 16);
_cache_invalidate(token, (MAX_TOKENS_PER_MB << 2));
cbp = reportMbh(mbh);
#ifdef DEBUG_VLD_PARSE
printMBInfo(mbh, token);
printMBInfo(mbhRef, tokenRef);
#endif
ParsedMbs++;
DP(("MB %d : ", ParsedMbs));
if(stream == 1) {
mStatus = compareMbh(mbh, (Pointer *) & mbhRef, mpeg2Mode);
if (mStatus) {
DP(("mbh mismatch\n"));
printf("mbh mismatch\n");
}
tStatus = compareToken(token, (Pointer *) & tokenRef, cbp);
if (tStatus) {
DP(("token mismatch\n"));
}
if (mStatus || tStatus) {
ErrorMbs++;
}
else {
DP(("match\n"));
}
}
mbDone = True;
break;
}
case VLD_STATUS_ERROR:
{
error("VLD_STAT_ERROR: status = 0x%x\n", status);
break;
}
case VLD_STATUS_STARTCODE:
{
vldShowBits(instance, 8, &data);
data |= 0x100;
DP(("STARTCODE: 0x%x\n", data));
if ((data <= SLICE_MAX_START_CODE) &&
(data >= SLICE_MIN_START_CODE)) {
ERROR_IF_NOT_OK(parseSlice());
/*
* No need to redo anything.
* Just start VLD again.
*/
vldParseMacroblocks(instance, 1, (Pointer) mbh, (Pointer) token,
VLD_MAX_MHB, VLD_MAX_RL);
}
else {
mbDone = True;
frameDone = True;
}
break;
}
default:
{
error("Bad VLD status, 0x%x", status);
break;
}
}
}
} DP(("Frame done \n"));
return 0;
}
/************************************************************************
static void *cache_calloc_share(unsigned num, unsigned size, int i)
cache_c(m)alloc_share are intended for shared buffers
between CPU and host/pheripherals.
For these, we need to copyback/invalidate
right after alloc.
***********************************************************************/
static void *
cache_calloc_share(unsigned num, unsigned size, int i)
{
unsigned long allocBlocks = (num * size + 63) >> 6;
unsigned char *addr;
unsigned char *ad;
addr = (unsigned char *) cache_calloc(num, size, i);
ad = addr;
if (ad == 0)
return (void *) 0;
_cache_copyback(addr, size);
_cache_invalidate(addr, size);
return (void *) addr;
}
/************************************************************************
static void *cache_calloc(unsigned num, unsigned size, int i)
***********************************************************************/
static void *
cache_calloc(unsigned num, unsigned size, int i)
{
unsigned int totSize = num * size;
char *res = (char *) _cache_malloc(totSize, i);
if (res == 0) {
return res;
}
memset(res, 0, totSize);
return res;
}
/************************************************************************
static void reportPictureInfo(vldPictureInfo_t *pictinfo)
obvious
***********************************************************************/
static void
reportPictureInfo(vldPictureInfo_t * pictinfo)
{
DP(("PictureType: %d \n", pictinfo->pictureType));
DP(("PictureStruct: %d \n", pictinfo->pictureStruct));
DP(("FramePFrameD: %d \n", pictinfo->framePFrameD));
DP(("IntraVLC: %d \n", pictinfo->intraVLC));
DP(("ConcealMV: %d \n", pictinfo->concealMV));
DP(("Mpeg2Mode: %d \n", pictinfo->mpeg2Mode));
DP(("H_Forw_Rsize: %d \n", pictinfo->hForwRSize));
DP(("V_Forw_Rsize: %d \n", pictinfo->vForwRSize));
DP(("H_Back_Rsize: %d \n", pictinfo->hBackRSize));
DP(("V_Back_Rsize: %d \n", pictinfo->vBackRSize));
}
/************************************************************************
static UInt reportMbh(vldMBHMpeg2_t *mbh)
obvious. return cbp, not raw cbp, but the right cbp.
***********************************************************************/
static UInt
reportMbh(vldMBHMpeg2_t * mbh)
{
vldMBHField_t mbhField;
Int mbPattern;
ERROR_IF_NOT_OK(vldGetMBHeader(instance, &mbhField, mbh));
/* DP(("mb_escape_cnt: %d \n", mbhField.mbEscapeCnt));
DP(("mb_addr_incr: %d \n", mbhField.mbAddrIncr));
DP(("mb_type: %d \n", mbhField.mbType));
DP(("motion_type: %d \n", mbhField.motionType));
DP(("dct_type: %d \n", mbhField.dctType));
DP(("mv_count: %d \n", mbhField.mvCount));
DP(("mv_format: %d \n", mbhField.mvFormat));
DP(("dmv_flag: %d \n", mbhField.dmvFlag));
DP(("quant_scale_code: %d \n", mbhField.quantScaleCode));
DP(("cbp: %d \n", mbhField.cbp));
*/
mbPattern = mbhField.mbType & MB_PATTERN;
return IZERO(mbPattern, mbhField.cbp);
}
/****************************************************************************
static Int compareMbh(Pointer mbh, Pointer *pMbhRef, Int mpeg2Mode)
Compare one vldMBHMpeg2_t or vldMBHMpeg1_t depending on mpeg2Mode
return the advanced reference pointer in *pMbhRef.
****************************************************************************/
static Int
compareMbh(Pointer mbh, Pointer * pMbhRef, Int mpeg2Mode)
{
int sizeInBytes = MUX(mpeg2Mode,
sizeof (vldMBHMpeg2_t), sizeof (vldMBHMpeg1_t));
int res = memcmp(mbh, *pMbhRef, sizeInBytes);
*pMbhRef = (Pointer) ((UInt32) *pMbhRef + sizeInBytes);
return res;
}
/****************************************************************************
static Int compareToken(Pointer token, Pointer *pTokenRef, Int cbp)
Compare token and reference token for an MB.
cbp contains the coded block pattern which tells when t stop.
return the advanced reference pointer in *pTokenRef.
****************************************************************************/
static Int
compareToken(Pointer token, Pointer * pTokenRef, Int cbp)
{
int i;
UInt32 *t = (UInt32 *) token;
UInt32 *tr = (UInt32 *) (*pTokenRef);
Int res = 0;
/*
* For each block in a macro block
*/
for (i = 0; i < 6; i++) {
/*
* If coded
*/
if (cbp & 0x1) {
/*
* 2nd byte contains 0xff for EOB
*/
while (IBYTESEL(*tr, 2) >= 0) {
if (*t != *tr) {
res = -1;
}
t++;
tr++;
}
/*
* Compare the token containing EOB
*/
if (*t != *tr) {
res = -1;
}
t++;
tr++;
}
cbp >>= 1;
}
*pTokenRef = tr;
return res;
}
#ifdef DEBUG_VLD_PARSE
/****************************************************************************
static void printMBInfo(vldMBHMpeg2_t *mbh, UInt32 *token)
for debugging
****************************************************************************/
static void
printMBInfo(vldMBHMpeg2_t * mbh, UInt32 * token)
{
DP((" &mbh = 0x%x, &token = 0x%x\n",
&(mbh->word[0]), token));
DP((" mbh (%x, %x, %x, %x, %x, %x, %x, %x)\n",
mbh->word[0], mbh->word[1],
mbh->word[2], mbh->word[3],
mbh->word[4], mbh->word[5],
mbh->word[6], mbh->word[7]));
DP((" mbh (%x, %x, %x, %x, %x, %x, %x, %x)\n",
mbh->word[8], mbh->word[9],
mbh->word[10], mbh->word[11],
mbh->word[12], mbh->word[13],
mbh->word[14], mbh->word[15]));
DP((" mbh (%x, %x, %x, %x, %x, %x, %x, %x)\n",
mbh->word[16], mbh->word[17],
mbh->word[18], mbh->word[19],
mbh->word[20], mbh->word[21],
mbh->word[22], mbh->word[23]));
DP((" mbh (%x, %x, %x, %x, %x, %x, %x, %x)\n",
mbh->word[24], mbh->word[25],
mbh->word[26], mbh->word[27],
mbh->word[28], mbh->word[29],
mbh->word[30], mbh->word[31]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[0], token[1], token[2], token[3],
token[4], token[5], token[6], token[7]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[8], token[9], token[10], token[11],
token[12], token[13], token[14], token[15]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[16], token[17], token[18], token[19],
token[20], token[21], token[22], token[23]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[24], token[25], token[26], token[27],
token[28], token[29], token[30], token[31]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[32], token[33], token[34], token[35],
token[36], token[37], token[38], token[39]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[40], token[41], token[42], token[43],
token[44], token[45], token[46], token[47]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[48], token[49], token[50], token[51],
token[52], token[53], token[54], token[55]));
DP((" token (%x, %x, %x, %x, %x, %x, %x, %x)\n",
token[56], token[57], token[58], token[59],
token[60], token[61], token[62], token[63]));
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -