📄 ippvideoencodermpeg4.hpp
字号:
int Width; int Height; int NumOfFrames; int TimeResolution; int TimeIncrement; int short_video_header; int load_intra_quant_mat; int load_intra_quant_mat_len; Ipp8u intra_quant_mat[64]; int load_nonintra_quant_mat; int load_nonintra_quant_mat_len; Ipp8u nonintra_quant_mat[64]; int quant_type; int quantIVOP, quantPVOP, quantBVOP; int IVOPdist, BVOPdist; int PVOPsearchWidth, PVOPsearchHeight; int BVOPsearchWidthForw, BVOPsearchHeightForw; int BVOPsearchWidthBack, BVOPsearchHeightBack; int MEalgorithm; int MEaccuracy; int ME4mv; int obmc_disable; int RoundingControl; int calcPSNR; int insertGOV; int repeatHeaders; int resync; int VideoPacketLenght; int data_partitioned; int reversible_vlc; int interlaced; int top_field_first; int alternate_vertical_scan_flag; int interlacedME; int sprite_enable; int sprite_width; int sprite_height; int sprite_left_coordinate; int sprite_top_coordinate; int no_of_sprite_warping_points; int sprite_warping_accuracy; int sprite_brightness_change; int *warping_mv_code_du; int *warping_mv_code_dv; int *brightness_change_factor; Ipp8u *bsBuffer; int bsBuffSize; int padType; int RateControl; int BitRate; int SceneChangeThreshold;};struct mp4_VLC { int code; int len;};struct mp4_Frame { Ipp8u* ap; Ipp8u* pY; Ipp8u* pU; Ipp8u* pV; int type; Ipp64s time;};#if defined (_WIN32_WCE) && defined (_M_IX86) && defined (__stdcall) #define _IPP_STDCALL_CDECL #undef __stdcall#endiftypedef IppStatus (__STDCALL *ippSAD_func) (const Ipp8u* pSrcCur, Ipp32s srcCurStep, const Ipp8u* pSrcRef, Ipp32s srcRefStep, Ipp32s* pDst, Ipp32s mcType);typedef IppStatus (__STDCALL *ippCopyQP_func) (const Ipp8u* pSrc, int srcStep, Ipp8u *pDst, int dstStep, int acc, int rc);#if defined (_IPP_STDCALL_CDECL) #undef _IPP_STDCALL_CDECL #define __stdcall __cdecl#endifstruct mp4_Data_ME { mp4_MacroBlock *MBcurr; int xMB, yMB; Ipp32s *meBuff; IppMotionVector mvPred; int quant, fcode, qpel; Ipp8u *pYc, *pYf, *pUc, *pUf, *pVc, *pVf; int stepL, stepC; int xL, xR, yT, yB; int thrDiff16x16, thrDiff8x8, thrDiff16x8; // Ipp8u *pCur, *pRef; int step; int bestDiff; int thrDiff; int xPos, yPos; ippSAD_func sadFunc; ippCopyQP_func copyQPFunc;};struct mp4_MB_RC { int bpuAvg, bpsAvg, bpsEnc, sQuant; Ipp8u *sBitPtr; int sBitOff;};#define YUV_CHROMA_420 0#define YUV_CHROMA_422 1#define YUV_CHROMA_444 2#define MP4_STS_NODATA -2#define MP4_STS_BUFFERED -1#define MP4_STS_NOERR 0#define MP4_STS_ERR_NOTINIT 1#define MP4_STS_ERR_PARAM 2#define MP4_STS_ERR_NOMEM 3#define MP4_STS_ERR_BUFOVER 4#define RCBS 30class ippVideoEncoderMPEG4{protected : bool mIsInit; ippBitStream cBS; int mbsAlloc; int mSourceFormat; // 4:2:0 supported only int mSourceWidth; // width int mSourceHeight; // height int mNumOfFrames; int mFrameCount; int mExpandSize; int mNumMacroBlockPerRow; int mNumMacroBlockPerCol; int mNumMacroBlockPerVOP; int mLumaPlaneSize; int mChromaPlaneSize; int mPlanes; int mExpandSizeA; int mStepLuma; int mStepChroma; int mQuantIVOP, mQuantPVOP, mQuantBVOP; int mIVOPdist, mBVOPdist, mLastIVOP; int mPVOPsearchHor, mPVOPsearchVer; int mBVOPsearchHorForw, mBVOPsearchVerForw; int mBVOPsearchHorBack, mBVOPsearchVerBack; int mPVOPfcodeForw; int mBVOPfcodeForw; int mBVOPfcodeBack; Ipp16s mDefDC; int mMEaccuracy; int mMEalgorithm; int mMEfastHP; Ipp32s *mMEfastSAD; int mMEfastSADsize; int mME4mv; int mRoundingControl; int mCalcPSNR; int mMBNlength; int mVideoPacketLength; int mInterlacedME; Ipp64s mVOPtime, mSyncTime; int mNumBVOP, mIndxBVOP, mTRB, mTRD, mSyncTimeB; int mPadType; int mInsertGOV; int mRepeatHeaders; int mRateControl, mBitRate, mBitsEncodedFrame, mBitsDesiredFrame; Ipp64s mBitsEncodedTotal, mBitsDesiredTotal; Ipp8u mRCqb[RCBS]; int mRCqh, mRCqs, mRCbf; mp4_MB_RC mMBRC; int mSceneChangeThreshold, mNumIntraMB, mNumNotCodedMB; int mQuantSum; Ipp64s mPSNR_Y, mPSNR_U, mPSNR_V; mp4_Frame *mFrame, *mFrameC, *mFrameF, *mFrameB; mp4_VisualObjectSequence VOS; mp4_VisualObject VO; mp4_VideoObjectLayer VOL; mp4_GroupOfVideoObjectPlane GOV; mp4_VideoObjectPlane VOP; // tables static const Ipp8u mDefaultIntraQuantMatrix[64]; static const Ipp8u mDefaultNonIntraQuantMatrix[64]; static const Ipp8u mZigZagScan[64]; static const mp4_VLC mVLC_CBPY_TB8[16]; static const mp4_VLC mVLC_MCBPC_TB7[20]; static const mp4_VLC mVLC_MVD_TB12[65]; static const int mDC_VLC_Threshold[8]; static const int mp4_DivIntraDivisor[47]; // info for each macroblock mp4_MacroBlock *MBinfo; // additional buffers for data_partitioned Ipp8u *mBuffer_1; Ipp8u *mBuffer_2; // ippVC specs IppiWarpSpec_MPEG4 *mWarpSpec; IppiQuantInterSpec_MPEG4 *mQuantInterSpec; IppiQuantIntraSpec_MPEG4 *mQuantIntraSpec; IppiQuantInvInterSpec_MPEG4 *mQuantInvInterSpec; IppiQuantInvIntraSpec_MPEG4 *mQuantInvIntraSpec; // buffer for GMC predict of the row of macroblocks Ipp8u *mGMCPredY, *mGMCPredU, *mGMCPredV; // buffers for RPT support Ipp8u *mMBquant; IppMotionVector *mMBpredMV; Ipp32u *mMBpos;public : ippVideoEncoderMPEG4() { mIsInit = false; }; ippVideoEncoderMPEG4(mp4_Param *par); ~ippVideoEncoderMPEG4(); int Init(mp4_Param *par); void Close(); int EncodeHeader(); int EncodeFrame(int noMoreData); void InitBuffer(Ipp8u *ptr, int size) { cBS.Init(ptr, size); }; Ipp8u* GetBufferPtr() { return cBS.GetPtr(); }; int GetBufferFullness() { return cBS.GetFullness(); }; void GetBufferPos(Ipp8u **ptr, int *bitOff) { cBS.GetPos(ptr, bitOff); }; void ResetBuffer() { cBS.Reset(); }; int GetFrameQuantSum() { return mQuantSum; }; int GetFrameMacroBlockPerRow() { return mNumMacroBlockPerRow; }; int GetFrameMacroBlockPerCol() { return mNumMacroBlockPerCol; }; int GetFrameType() { return VOL.short_video_header ? VOP.picture_coding_type : VOP.vop_coding_type; }; void GetFrameMSE(Ipp64s *y, Ipp64s *u, Ipp64s *v) { *y = mPSNR_Y; *u = mPSNR_U; *v = mPSNR_V; }; int GetFrameWriteInfo(Ipp8u **pY, Ipp8u **pU, Ipp8u **pV, int *stepLuma, int *stepChroma); Ipp64s GetFrameBytesEncoded() { return GetBufferFullness(); }; int SetFrameBasicSpriteWarpCoeffs(int *du, int *dv, int bcf); // for RTP support Ipp8u* GetFrameQuant() { return mMBquant; }; IppMotionVector* GetFrameMVpred() { return mMBpredMV; }; Ipp32u* GetFrameMBpos() { return mMBpos; };protected : void ErrorMessage(const vm_char *msg); void EncodeStartCode(Ipp8u sc); void EncodeZeroBitsAlign(); void EncodeStuffingBitsAlign(); void EncodeVideoPacketHeader(int mbn); void EncodeMarkerDC(); void EncodeMarkerMV(); void EncodeVOS_Header(); void EncodeVO_Header(); void EncodeVOL_Header(); void EncodeGOV_Header(); void EncodeVOP_Header(); void EncodeVOPSH_Header(); void EncodeIVOP(); void EncodePVOP(); void EncodeBVOP(); void EncodeSVOP(); void EncodeIVOPSH(); void EncodePVOPSH(); void EncodeDquant(int dquant); void EncodeMCBPC_I(int mbtype, int mcbpc); void EncodeCBPY_I(int pat); void EncodeMCBPC_P(int mbtype, int mcbpc); void EncodeCBPY_P(int mbtype, int pat); void EncodeMacroBlockIntra_H263(Ipp16s *coeffs, int pattern, int *nzCount); void EncodeMacroBlockInter_H263(Ipp16s *coeffs, int pattern, int *nzCount); void EncodeMacroBlockIntra_MPEG4(Ipp16s *coeffs, int pattern, int use_dc_vlc, int *predDir, int *nzCount); void EncodeMacroBlockIntra_DC_MPEG4(Ipp16s *coeffs); void EncodeMacroBlockIntra_AC_MPEG4(Ipp16s *coeffs, int *predDir, int use_intra_dc_vlc, int pattern, int *nzCount); void EncodeMacroBlockInter_MPEG4(Ipp16s *coeffs, int pattern, int *nzCount); void EncodeMV(IppMotionVector *mv, int fcode, int mbType); void ExpandFrame(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV); void PredictMV(mp4_MacroBlock *MBcurr, int i, int j, IppMotionVector *mvPred); void Predict1MV(mp4_MacroBlock *MBcurr, int i, int j, IppMotionVector *mvPred); void Predict3MV(mp4_MacroBlock *MBcurr, int i, int j, IppMotionVector *mvPred, IppMotionVector *mvCurr); void PredictIntraDCAC(mp4_MacroBlock *MBcurr, Ipp16s *dcCurr, int quant, int *predictDir, int predAC, int *pSum0, int *pSum1, int *nzCount); int TransMacroBlockIntra_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s *nzCount, int quant); int TransMacroBlockInter_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s *nzCount, int quant, Ipp8u *mcPred, int lumaErr); int TransMacroBlockIntra_MPEG4(Ipp8u *py, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s *nzCount, int quant, int row, int col, int *dct_type); int TransMacroBlockInter_MPEG4(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp16s *coeffMB, Ipp32s *nzCount, int quant, Ipp8u *mcPred, int row, int col, int *dct_type); void ReconMacroBlockNotCoded(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp8u *mcPred); void ReconMacroBlockIntra_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, int quant, int pattern); void ReconMacroBlockInter_H263(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp8u *mcPred, Ipp16s *coeffMB, int quant, int pattern); void ReconMacroBlockIntra_MPEG4(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, int quant, mp4_MacroBlock *MBcurr, int pattern, int dct_type); void ReconMacroBlockInter_MPEG4(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp8u *mcPred, Ipp16s *coeffMB, int quant, int pattern, int dct_type); void ME_SAD_16x16(mp4_Data_ME *meData); void ME_SAD_16x8(mp4_Data_ME *meData); void ME_SAD_8x8(mp4_Data_ME *meData); void ME_MacroBlock_PSH(mp4_Data_ME *meData); void ME_MacroBlock_P(mp4_Data_ME *meData); void ME_MacroBlock_S(mp4_Data_ME *meData); void MergeBuffersDP(int nBits_1, int nBits_2); void FindTransformGMC(); void PostFrameRC(); void InitMBRC(); void UpdateMBRC(int *dquant); void CloseMBRC();};#if defined(__INTEL_COMPILER) && !defined(_WIN32_WCE) #define __ALIGN16(type, name, size) \ __declspec (align(16)) type name[size]#else #if defined(_WIN64) || defined(WIN64) || defined(LINUX64) #define __ALIGN16(type, name, size) \ Ipp8u _a16_##name[(size)*sizeof(type)+15]; type *name = (type*)(((Ipp64s)(_a16_##name) + 15) & ~15) #else #define __ALIGN16(type, name, size) \ Ipp8u _a16_##name[(size)*sizeof(type)+15]; type *name = (type*)(((Ipp32s)(_a16_##name) + 15) & ~15) #endif#endif#define mp4_Zero4MV(mv) (mv)[0].dx = (mv)[0].dy = (mv)[1].dx = (mv)[1].dy =(mv)[2].dx = (mv)[2].dy =(mv)[3].dx = (mv)[3].dy = 0#define mp4_Div2(a) ((a) >= 0 ? ((a) >> 1) : (((a)+1) >> 1))#define mp4_Div2Round(a) (((a) >> 1) | ((a) & 1))#define mp4_DivRoundInf(a, b) ((((a) + (((a) >= 0) ? ((b) >> 1) : -((b) >> 1))) / (b)))#define mp4_Clip(a, l, r) if (a < (l)) a = l; else if (a > (r)) a = r;#define mp4_ClipL(a, l) if (a < (l)) a = l;#define mp4_ClipR(a, r) if (a > (r)) a = r;#define mp4_Abs(a) ((a) >= 0 ? (a) : -(a))#define mp4_GetNumBits(oPtr, oOff, nPtr, nOff) (int)(((nPtr) - (oPtr)) << 3) + (nOff) - (oOff)#define USE_TABLE_INTRA_DIV#ifndef USE_TABLE_INTRA_DIV#define mp4_DivIntraDC(a, b) (((a) + ((b) >> 1)) / (b))#define mp4_DivIntraAC(a, b) mp4_DivRoundInf(a, b)#else// tested on (-2047..2047) // (1..46)#define mp4_DivIntraDC(a, b) (((a) * mp4_DivIntraDivisor[b] + (1 << 17)) >> 18)#define mp4_DivIntraAC(a, b) mp4_DivIntraDC(a, b)#endif#define MP4_MV_OFF_HP(dx, dy, step) \ (((dx) >> 1) + (step) * ((dy) >> 1))#define MP4_MV_ACC_HP(dx, dy) \ ((((dy) & 1) << 1) + ((dx) & 1))#define MP4_MV_OFF_QP(dx, dy, step) \ (((dx) >> 2) + (step) * ((dy) >> 2))#define MP4_MV_ACC_QP(dx, dy) \ ((((dy) & 3) << 2) + ((dx) & 3))#define mp4_Copy8x4HP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy8x4HP_8u_C1R(pSrc + MP4_MV_OFF_HP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_HP((mv)->dx, (mv)->dy), rc)#define mp4_Copy8x8HP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy8x8HP_8u_C1R(pSrc + MP4_MV_OFF_HP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_HP((mv)->dx, (mv)->dy), rc)#define mp4_Copy16x8HP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy16x8HP_8u_C1R(pSrc + MP4_MV_OFF_HP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_HP((mv)->dx, (mv)->dy), rc)#define mp4_Copy16x16HP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy16x16HP_8u_C1R(pSrc + MP4_MV_OFF_HP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_HP((mv)->dx, (mv)->dy), rc)#define mp4_Copy8x8QP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy8x8QP_MPEG4_8u_C1R(pSrc + MP4_MV_OFF_QP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_QP((mv)->dx, (mv)->dy), rc)#define mp4_Copy16x8QP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy16x8QP_MPEG4_8u_C1R(pSrc + MP4_MV_OFF_QP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_QP((mv)->dx, (mv)->dy), rc)#define mp4_Copy16x16QP_8u(pSrc, srcStep, pDst, dstStep, mv, rc) \ ippiCopy16x16QP_MPEG4_8u_C1R(pSrc + MP4_MV_OFF_QP((mv)->dx, (mv)->dy, srcStep), srcStep, pDst, dstStep, MP4_MV_ACC_QP((mv)->dx, (mv)->dy), rc)#define mp4_Add8x8_16s8u(pSrcDst, pResid, srcDstStep) \ ippiAdd8x8_16s8u_C1IRS(pResid, 16, pSrcDst, srcDstStep)//--------------------- defines to control ME process -------------------------//#define ME_FULLSEARCH_RECT // using rectangle instead of involute search//#define ME_USE_THRESHOLD // using threshold in ME (faster)#define SAD_FAVOR_ZERO 0#define SAD_FAVOR_PRED - SAD_FAVOR_ZERO / 2#define SAD_FAVOR_DIRECT 129 /2#define SAD_FAVOR_INTER 400 // 500 H.263 App III#define SAD_FAVOR_16x16 200 // 200 H.263 App III#define SAD_FAVOR_FIELD 65#define SAD_FAVOR_GMC (SAD_FAVOR_ZERO + SAD_FAVOR_16x16 + 1)#define RANGE_ME_8x8 3 // radius for search 8x8 MVs from 16x16 approximation#define SAD_NOTCODED_THR_LUMA 10#define SAD_NOTCODED_THR_CHROMA 20#define DEV_FAVOR_INTRA 100#define MAX_SAD (16 * 16 * 256)extern int mp4_WeightMV(int dx, int dy, int fcode, int quant, int qpel);template <class T> inline void mp4_Swap(T &a, T &b){ T t; t = a; a = b; b = t;}extern const Ipp8u mp4_cCbCrMvRound16_[];extern const Ipp8u mp4_DCScalerLuma_[];extern const Ipp8u mp4_DCScalerChroma_[];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -