📄 encodevop.c
字号:
#include "ippVideoEncoderMPEG4.h"
#include "ippiVideoEncodeMPEG4_table.h"
#include "string.h"
#include "ippvc.h"
#include "math.h"
#include "enum.h"
#include <cdefBF533.h>
#include <stdio.h>
//#include "table.h"
//changed by gary
#include "global_declare.h"
/*****************************************************************/
extern void PutBits(Ipp32u val, int n);
extern void xhDCT8x8Fwd_16s_C1I(Ipp16s *pSrcDst,Ipp16s *coeff,Ipp16s *temp );
//extern void xhDCT8x8Inv_16s_C1I(Ipp16s *pSrcDst,Ipp16s *i_coeff,Ipp16s *temp );
extern void convert_8u16s(const Ipp8u *src, Ipp16s *dst, int src_step);
extern void convert_16s8u(const Ipp16s *src, Ipp8u *dst, int dst_step);
extern void fdct_int32(short *const block);extern void idct_int32(short *const block);
//extern void xhDCT8x8Fwd_8u16s_C1R(unsigned char *pSrc, int srcStep, short *pDst,Ipp16s *coeff,Ipp16s *temp);
//extern void xhDCT8x8Inv_16s8u_C1R(const short* block, short int *i_coeff,short int *temp, unsigned char* pDst, int dstStep );
//extern void Predict3MV( struct mp4_MacroBlock *MBcurr, int i, int j,struct IppMotionVector *mvPred, struct IppMotionVector *mvCurr);
//extern void Predict1MV(struct mp4_MacroBlock *MBcurr, int i, int j, struct IppMotionVector *mvPred);
//extern void PredictMV(struct mp4_MacroBlock *MBcurr, int i, int j, struct IppMotionVector *mvPred);
//extern void Predict1MV(struct IppMotionVector *refmv, int i, int j, struct IppMotionVector *mvPred);
extern void Predict1MV(struct IppMotionVector *refmv, int i, struct IppMotionVector *mvPred);
extern Ipp32u xhQuantIntra_H263_C1I(Ipp16s* pSrcDst,Ipp32s QP,Ipp32s* pCount);
extern Ipp32u xhQuantInvIntra_H263_C1I( Ipp16s* pSrcDst, int QP);
extern Ipp32u xhQuantIntra_MPEG4_16s_C1I(Ipp16s* pSrcDst,Ipp32s QP,const Ipp8u* pQPMatrix,Ipp32s* pCount);
//extern Ipp32u xhQuantInvIntra_MPEG4_16s_C1I( Ipp16s* pSrcDst,int QP,Ipp16s* pQPMatrix);
extern Ipp32u xhQuantInvIntra_MPEG4_16s_C1I( Ipp16s* pSrcDst,int QP,const Ipp8u* pQPMatrix);
extern Ipp32u xhQuant_H263_C1I( Ipp16s* pSrcDst,Ipp32s QP,Ipp32s* pCount);
extern Ipp32u xhQuantInv_H263_C1I( Ipp16s* pSrcDst, int QP );
extern Ipp32u xhQuant_MPEG4_16s_C1I( Ipp16s* pSrcDst,Ipp32s QP,const Ipp8u* pQPMatrix,Ipp32s* pCount);
//extern Ipp32u xhQuantInv_MPEG4_16s_C1I( Ipp16s* pSrcDst,int QP,Ipp16s* pQPMatrix);
extern Ipp32u xhQuantInv_MPEG4_16s_C1I( Ipp16s* pSrcDst,int QP,const Ipp8u* pQPMatrix);
//extern void xhEncode_IntraDCVLC_MPEG4_16s1u( Ipp16s qDCCoef,Ipp8u** ppBitStream, int* pBitOffset,IppVideoComponent videoComp );
//extern void xhEncode_IntraACVLC_MPEG4_16s1u( Ipp16s* pQDctBlkCoef,Ipp8u** ppBitStream,int* pBitOffset, int predDir,int noDCcode);
//extern void xhEncode_InterVLC_MPEG4_16s1u( Ipp16s* pQDctBlkCoef,Ipp8u** ppBitStream,int* pBitOffset);
extern void xhEncode_IntraDCVLC_MPEG4_16s1u( Ipp16s qDCCoef,IppVideoComponent videoComp );
extern void xhEncode_IntraACVLC_MPEG4_16s1u( Ipp16s* pQDctBlkCoef, int predDir,int noDCcode);
extern void xhEncode_InterVLC_MPEG4_16s1u( Ipp16s* pQDctBlkCoef);
//extern void xhSAD8x8_8u32s_C1R( const Ipp8u* pSrcCur,int srcCurStep,const Ipp8u* pSrcRef, int srcRefStep,Ipp32s* pDst, Ipp32s mcType);
//extern void xhSAD16x16_8u32s( const Ipp8u* pSrc,Ipp32s srcStep,const Ipp8u* pRef,Ipp32s refStep,Ipp32s* pSAD,Ipp32s mcType);
//extern void mp4_ME_8x8(Ipp8u *pCur, Ipp8u *pRef, int step, int xL, int xR, int yT, int yB, int *bestSAD,struct IppMotionVector *mv, int alg, int acc,struct IppMotionVector *mv4, int thrSAD_8x8);
//extern void mp4_ME_16x16(Ipp8u *pCur, Ipp8u *pRef, int step, int xL, int xR, int yT, int yB, int *bestSAD,struct IppMotionVector *mv, int alg, int acc, Ipp32s *sadBuf, int thrSAD_16x16);
//extern void xhAverageBlock_MPEG4_8u( const Ipp8u* pSrc1,int src1Step,const Ipp8u* pSrc2,int src2Step,Ipp8u* pDst,int dstStep);
//extern void xhAverageMB_MPEG4_8u( const Ipp8u* pSrc1, int src1Step, const Ipp8u* pSrc2, int src2Step, Ipp8u* pDst, int dstStep);
extern void xhCopyBlock_16x16_8u( const Ipp8u* pSrc,int srcStep,Ipp8u* pDst,int dstStep);
extern void xhCopyBlock_8x8_8u( const Ipp8u* pSrc,int srcStep,Ipp8u* pDst,int dstStep);
//extern void xhMeanAbsDev16x16_8u32s_C1R( const Ipp8u* pSrc,int srcStep,Ipp32s* pDst);
extern void xhMeanAbsDev16x16_8u32s_C1R_MOD(const Ipp8u *pSrc,Ipp32s *pDst);
extern unsigned int xhGetDiff8x8_8u16s_C1( const Ipp8u* pSrcCur,Ipp32s srcCurStep,const Ipp8u* pSrcRef,
Ipp32s srcRefStep, Ipp16s* pDstDiff,
Ipp32s dstDiffStep,//以byte为单位,用在汇编里,基地址直接加上这个值就可以找到pDstDiff的下一行的首地址
Ipp16s* pDstPredictor,//这个参数暂时不用
Ipp32s dstPredictorStep,//这个参数暂时不用
Ipp32s mcType,
Ipp32s roundControl );
extern void get_interpolate_uv(Ipp8u *pSrc,int srcStep,Ipp8u *pDst,Ipp32s mcType);
//extern void xhReconBlockHalfpel_MPEG4_8u( const Ipp8u* pSrc, int srcStep, Ipp16s pResidue[64], Ipp8u* pDst,
// int dstStep, const struct IppMotionVector* pMV, int roundControl);
extern void xhReconBlockHalfpel_MPEG4_8u_MOD (const Ipp8u* pSrc, int srcStep,
Ipp16s pResidue[64], Ipp8u* pDst, int dstStep, int roundControl);
extern void xhCopyBlockHalfpel_MPEG4_8u( const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep,
const struct IppMotionVector* pMV, int roundControl);
//extern void xhCopyMBHalfpel_MPEG4_8u( const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep,
// const struct IppMotionVector* pMV, int roundControl);
//extern void xhCopyBlockHalfpel_MPEG4_8u_MOD(const Ipp8u* pSrc,int srcStep,Ipp8u* pDst, int dstStep, int roundControl);
//extern void xhCopyMBHalfpel_MPEG4_8u_MOD( const Ipp8u* pSrc, int srcStep,Ipp8u* pDst, int dstStep, int roundControl);
//extern void xhSqrDiff16x16_8u32s( const Ipp8u* pSrc,Ipp32s srcStep, const Ipp8u* pRef,Ipp32s refStep,Ipp32s mcType, Ipp32s* pSqrDiff);
//extern void mp4_ME_8x8_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv,struct IppMotionVector *mv4);
//extern void mp4_ME_16x16_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv);
extern void mp4_ME_16x16_C(Ipp8u *pCur, Ipp8u *ref_window, int *bestSAD,struct IppMotionVector *mv, int refwin_step);
extern void GetDiff8x8_8u16s_C1(Ipp8u *pCur,int step,Ipp8u *_match_16x16,Ipp16s* pDstDiff);
extern void mp4_Set8x8_asm(Ipp8u *p, int step, int level);
extern void MatchBlock_to_Cur_frame_dma_en(Ipp8u *pCur_mb,Ipp8u *pYc,Ipp8u *pUc,Ipp8u *pVc);
extern void MatchBlock_to_Cur_frame_dma_ini();
extern void MatchBlock_copy_asm(Ipp8u *pCur_mb_y,Ipp8u *pCur_mb_u, Ipp8u *pCur_mb_v,
Ipp8u *pYc,Ipp8u *pUc,Ipp8u *pVc,
int y_step, int uv_step);
//extern Ipp8u refwin[48*48];
extern Ipp8u MBy_match_16x16[256];
extern Ipp8u MBy_match_4x8x8[256];
extern Ipp8u MBy_match_uv[128];
//extern Ipp8u Current_MB[384*2];
int dma_done;
struct mp4_VLC {
int code;
int len;
};
// table B-12 //8*65=520B
segment ("L1_data_b")const struct mp4_VLC mVLC_MVD_TB12[65] = {
{0x05, 13}, {0x07, 13}, {0x05, 12}, {0x07, 12}, {0x09, 12}, {0x0b, 12}, {0x0d, 12}, {0x0f, 12},
{0x09, 11}, {0x0b, 11}, {0x0d, 11}, {0x0f, 11}, {0x11, 11}, {0x13, 11}, {0x15, 11}, {0x17, 11},
{0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11}, {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10},
{0x17, 10}, {0x07, 8}, {0x09, 8}, {0x0b, 8}, {0x07, 7}, {0x03, 5}, {0x03, 4}, {0x03, 3},
{0x01, 1}, {0x02, 3}, {0x02, 4}, {0x02, 5}, {0x06, 7}, {0x0a, 8}, {0x08, 8}, {0x06, 8},
{0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11}, {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11},
{0x18, 11}, {0x16, 11}, {0x14, 11}, {0x12, 11}, {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},
{0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12}, {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},
{0x04, 13}
};
//8*20=160
segment ("L1_data_b")const struct mp4_VLC mVLC_MCBPC_TB7[20] = {
{1, 1}, {3, 4}, {2, 4}, {5, 6}, {3, 3}, {7, 7}, {6, 7}, {5, 9},
{2, 3}, {5, 7}, {4, 7}, {5, 8}, {3, 5}, {4, 8}, {3, 8}, {3, 7},
{4, 6}, {4, 9}, {3, 9}, {2, 9}
};
// table B-8 //8*16=128
segment ("L1_data_b")const struct mp4_VLC mVLC_CBPY_TB8[16] = {
{3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
{2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void EncodeMV(struct IppMotionVector *mv, int fcode, int mbType)
{
int i, nMV = (mbType == IPP_VIDEO_INTER4V || mbType == IPP_VIDEO_INTER4V_Q) ? 4 : 1;
for (i = 0; i < nMV; i ++) {
if (fcode == 1) {
PutBits(mVLC_MVD_TB12[mv[i].dx+32].code, mVLC_MVD_TB12[mv[i].dx+32].len);
PutBits(mVLC_MVD_TB12[mv[i].dy+32].code, mVLC_MVD_TB12[mv[i].dy+32].len);
} else {
int f, a, b;
f = fcode - 1;
if (mv[i].dx == 0) {
PutBits(mVLC_MVD_TB12[32].code, mVLC_MVD_TB12[32].len);
} else {
if (mv[i].dx > 0) {
a = ((mv[i].dx - 1) >> f) + 1;
b = mv[i].dx - 1 - ((a - 1) << f);
} else {
a = ((-mv[i].dx - 1) >> f) + 1;
b = -mv[i].dx - 1 - ((a - 1) << f);
a = -a;
}
PutBits(mVLC_MVD_TB12[a+32].code, mVLC_MVD_TB12[a+32].len);
PutBits(b, f);
}
if (mv[i].dy == 0) {
PutBits(mVLC_MVD_TB12[32].code, mVLC_MVD_TB12[32].len);
} else {
if (mv[i].dy > 0) {
a = ((mv[i].dy - 1) >> f) + 1;
b = mv[i].dy - 1 - ((a - 1) << f);
} else {
a = ((-mv[i].dy - 1) >> f) + 1;
b = -mv[i].dy - 1 - ((a - 1) << f);
a = -a;
}
PutBits(mVLC_MVD_TB12[a+32].code, mVLC_MVD_TB12[a+32].len);
PutBits(b, f);
}
}
}
}
void EncodeMCBPC_I(int mbtype, int mcbpc)
{
if (mbtype == IPP_VIDEO_INTRA) {
if (mcbpc == 0)
PutBits(1, 1);
else
PutBits(mcbpc, 3);
} else {
if (mcbpc == 0)
PutBits(1, 4);
else
PutBits(mcbpc, 7);
}
}
void EncodeCBPY_I(int pat)
{
PutBits(mVLC_CBPY_TB8[pat].code, mVLC_CBPY_TB8[pat].len);
}
void EncodeMCBPC_P(int mbtype, int pat)
{
PutBits(mVLC_MCBPC_TB7[mbtype*4+pat].code, mVLC_MCBPC_TB7[mbtype*4+pat].len);
}
void EncodeCBPY_P(int mbtype, int pat)
{
if (mbtype == IPP_VIDEO_INTER || mbtype == IPP_VIDEO_INTER_Q || mbtype == IPP_VIDEO_INTER4V || mbtype == IPP_VIDEO_INTER4V_Q)
pat = 15 - pat;
PutBits(mVLC_CBPY_TB8[pat].code, mVLC_CBPY_TB8[pat].len);
}
static inline int mp4_GetDCscaler(int quant, int num)
{
if (quant <= 4)
return 8;
if (quant <= 8)
return (num < 4) ? (2 * quant) : (quant + 13) >> 1;
if (quant <= 24)
return (num < 4) ? (quant + 8) : (quant + 13) >> 1;
return (num < 4) ? (2 * quant - 16) : (quant - 6);
}
/*******************************
static void mp4_PredictIntraDCAC(struct mp4_MacroBlock *mbCurr, Ipp16s *dcCurr, int dcScaler, int blockNum, int *predictDir, int predAC, int *pSum0, int *pSum1)
{
int predDir, dc, k, zC, zA, predQuantA, predQuantC;
Ipp16s dcA, dcB, dcC;
Ipp16s *predAcA, *predAcC;
int sum0 = 0, sum1 = 0;
dcA = *mbCurr->predDcA[blockNum];
dcB = *mbCurr->predDcB[blockNum];
dcC = *mbCurr->predDcC[blockNum];
dc = *dcCurr;
if (abs(dcA - dcB) < abs(dcB - dcC)) {
predDir = IPP_VIDEO_VERTICAL;
*dcCurr = (Ipp16s)(dc / dcScaler - (dcC + (dcScaler >> 1)) / dcScaler);
mbCurr->dct_dc[blockNum] = (Ipp16s)((dc / dcScaler) * dcScaler);
} else {
predDir = IPP_VIDEO_HORIZONTAL;
*dcCurr = (Ipp16s)(dc / dcScaler - (dcA + (dcScaler >> 1)) / dcScaler);
mbCurr->dct_dc[blockNum] = (Ipp16s)((dc / dcScaler) * dcScaler);
}
zC = zA = 0;
for (k = 1; k < 8; k ++) {
mbCurr->dct_acC[blockNum][k] = dcCurr[k];
if (dcCurr[k])
zC = 1;
mbCurr->dct_acA[blockNum][k] = dcCurr[k*8];
if (dcCurr[k*8])
zA = 1;
}
mbCurr->dct_acC[blockNum][0] = (Ipp16s)zC;
mbCurr->dct_acA[blockNum][0] = (Ipp16s)zA;
if (predAC) {
predAcA = mbCurr->predAcA[blockNum];
predAcC = mbCurr->predAcC[blockNum];
predQuantA = *mbCurr->predQuantA[blockNum];
predQuantC = *mbCurr->predQuantC[blockNum];
if (predDir == IPP_VIDEO_VERTICAL && predAcC) {
if (predAcC[0])
if (predQuantC == mbCurr->quant)
for (k = 1; k < 8; k ++) {
sum0 += abs(dcCurr[k]);
dcCurr[k] = (Ipp16s)(dcCurr[k] - predAcC[k]);
sum1 += abs(dcCurr[k]);
}
else
for (k = 1; k < 8; k ++) {
sum0 += abs(dcCurr[k]);
dcCurr[k] = (Ipp16s)(dcCurr[k] - (predAcC[k] * predQuantC + ((mbCurr->quant) >> 1)) / mbCurr->quant);
sum1 += abs(dcCurr[k]);
}
}
if (predDir == IPP_VIDEO_HORIZONTAL && predAcA) {
if (predAcA[0])
if (predQuantA == mbCurr->quant)
for (k = 1; k < 8; k ++) {
sum0 += abs(dcCurr[k*8]);
dcCurr[k*8] = (Ipp16s)(dcCurr[k*8] - predAcA[k]);
sum1 += abs(dcCurr[k*8]);
}
else
for (k = 1; k < 8; k ++) {
sum0 += abs(dcCurr[k*8]);
dcCurr[k*8] = (Ipp16s)(dcCurr[k*8] - (predAcA[k] * predQuantA + ((mbCurr->quant) >> 1)) / mbCurr->quant);
sum1 += abs(dcCurr[k*8]);
}
}
*pSum0 += sum0;
*pSum1 += sum1;
} else
predDir = IPP_VIDEO_NONE;
*predictDir = predDir;
}
************************************/
/***********************************
static void mp4_PredictIntraDCAC(struct mp4_MacroBlock *mbCurr, Ipp16s *dcCurr, int dcScaler, int blockNum, int *predictDir, int predAC, int *pSum0, int *pSum1)
{
int predDir, dc, k, zC, zA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -