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

📄 h263_enc.hpp

📁 audio-video-codecs.rar语音编解码器
💻 HPP
📖 第 1 页 / 共 2 页
字号:
protected :
  bool        mIsInit;
  Ipp32s      mbsAlloc;
  Ipp32s      mExpandSize;
  Ipp32s      mNumMacroBlockPerRow;
  Ipp32s      mNumMacroBlockPerCol;
  Ipp32s      mNumMacroBlockPerPic;
  h263e_Frame  *mFrameC, *mFrameF, *mFrameB;
  Ipp32s      mQuantIPic, mQuantPPic, mQuantBPic;
  Ipp32s      mIPicdist, mPPicdist, mBPicdist, mLastIPic;
  Ipp32s      mPPicsearchHor, mPPicsearchVer;
//    Ipp32s      mBPicsearchHorForw, mBPicsearchVerForw;
//    Ipp32s      mBPicsearchHorBack, mBPicsearchVerBack;
//    Ipp32s      mPPicfcodeForw;
//    Ipp32s      mBPicfcodeForw;
//    Ipp32s      mBPicfcodeBack;
  Ipp32s      mMEaccuracy;
  Ipp32s      mMEalgorithm;
  Ipp32s      mMEfastHP;
  Ipp32s      *mMEfastSAD;
  Ipp32s      mMEfastSADsize;
  Ipp32s      mMEthrSAD16x16, mMEthrSAD8x8, mMEthrSAD16x8;
  Ipp32s      mME4mv;
  Ipp32s      mCalcPSNR;
//    Ipp32s      mVideoPacketLength;
  Ipp64s      mPictime, mSyncTime;
  Ipp32s      mNumBPic, mIndxBPic, mTRB, mTRD, mSyncTimeB;
  Ipp32s      mRateControl;
  Ipp32s      mBitRate;
  Ipp32s      mBPPmax;

  Ipp32s      mBitsEncodedFrame, mBitsDesiredFrame;
  Ipp64s      mBitsEncodedTotal, mBitsDesiredTotal;
  Ipp32s      mRCfap, mRCqap, mRCbap, mRCq;
  Ipp64f      mRCqa, mRCfa;

  Ipp32s      mFrameSkipEnabled;
  Ipp32s      mSkipFrame;
  Ipp32s      mFrameSkipped;

  Ipp32s      mSceneChangeThreshold, mNumIntraMB;
  Ipp32s      mGOBheaders;
  Ipp32s      mGSTUF;
  h263e_VideoSequence          mVideoSequence;
  h263e_VideoPicture           mVideoPicture;
  static const h263e_VLC       mVLC_CBPY_TB8[16];
  static const h263e_VLC       mVLC_MCBPC_TB7[20];
  static const h263e_VLC       mVLC_MVD_TB12[65];
  // info for each macroblock
  h263e_MacroBlock            *mMBinfo;
  // additional buffers for data_partitioned
  Ipp8u                       *mBuffer_1;
  Ipp8u                       *mBuffer_2;
  // data for RTP support
  h263e_RTPdata                mRTPdata;
public :
          ippVideoEncoderH263() { mIsInit = false; };
          ippVideoEncoderH263(h263e_Param *par);
          ~ippVideoEncoderH263();
  Ipp32s  Init(h263e_Param *par);
  void    Close();
//  Ipp32s  GetAverageQuant() { return (Ipp32s)mQuantAvg; };
  Ipp32s  GetNumMacroBlockPerRow() { return mNumMacroBlockPerRow; };
  Ipp32s  GetNumMacroBlockPerCol() { return mNumMacroBlockPerCol; };
  Ipp32s  GetFrameType() { return mVideoPicture.picture_coding_type; };
  Ipp64s  GetBitsEncoded() { return mBitsEncodedTotal; };
  void    GetMSE(Ipp64s *y, Ipp64s *u, Ipp64s *v) { *y = mPSNR_Y; *u = mPSNR_U; *v = mPSNR_V; };
  Ipp32s  GetCurrentFrameInfo(Ipp8u **pY, Ipp8u **pU, Ipp8u **pV, Ipp32s *stepLuma, Ipp32s *stepChroma);
  void    InitBuffer(Ipp8u *ptr, Ipp32s size) { cBS.Init(ptr, size); };
  Ipp8u*  GetBufferPtr() { return cBS.GetPtr(); };
  Ipp32s  GetBufferFullness() { return cBS.GetFullness(); };
  void    GetBufferPos(Ipp8u **ptr, Ipp32s *bitOff) { cBS.GetPos(ptr, bitOff); };
  void    ResetBuffer() { cBS.Reset(); };
  Ipp32s  EncodeFrame(Ipp32s noMoreData);
  // for RTP support
  Ipp32u* GetFrameGOBstartPos() { return mRTPdata.GOBstartPos; };
  Ipp8u*  GetFrameQuant() { return mRTPdata.MBquant; };
  IppMotionVector*  GetFrameMVpred() { return mRTPdata.MBpredMV; };
  IppMotionVector*  GetFrameMVpred1() { return mRTPdata.MBpredMV1; };
  Ipp32u* GetFrameMBpos() { return mRTPdata.MBpos; };
  Ipp8u   GetFrameCodingModes() { return mRTPdata.codingModes; };
  Ipp16u  GetFrameDBQ_TRB_TR() {
    return (Ipp16u)(mVideoPicture.PBframes ? ((mVideoPicture.dbquant << 11) | (mVideoPicture.temporal_reference_B << 8) | mVideoPicture.temporal_reference) : 0);
  };
protected :
  Ipp32s  EncodePic(Ipp32s picType, Ipp32s nt);
  void    ErrorMessage(const vm_char *msg);
  void    EncodeZeroBitsAlign();
  void    EncodeStuffingBitsAlign();
  void    EncodePicture_Header();
  void    EncodeGOB_Header(Ipp32s gob_num);
  void    EncodeIPic();
  void    EncodePPic();
//    void    EncodeBPic();
  void    EncodeMCBPC_I(Ipp32s mbtype, Ipp32s mcbpc);
  void    EncodeAdvIntraPredMode(Ipp32s scan);
  void    EncodeCBPY_I(Ipp32s pat);
  void    EncodeMCBPC_P(Ipp32s mbtype, Ipp32s mcbpc);
  void    EncodeCBPY_P(Ipp32s mbtype, Ipp32s pat);
  void    EncodeMacroBlockIntra_H263(Ipp16s *coeffs, Ipp32s pattern, Ipp32s *nzCount, Ipp32s scan);
  void    EncodeMacroBlockInter_H263(Ipp16s *coeffs, Ipp32s pattern, Ipp32s *nzCount);
  void    EncodeMV(IppMotionVector *mv, Ipp32s mbType);
  void    ExpandFrame(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV);
  void    PredictMV(h263e_MacroBlock *MBcurr, Ipp32s frGOB, Ipp32s i, Ipp32s j, Ipp32s adv, IppMotionVector *mvPred);
  void    Predict3MV(h263e_MacroBlock *MBcurr, Ipp32s frGOB, Ipp32s i, Ipp32s j, IppMotionVector *mvPred, IppMotionVector *mvCurr);
  void    me4MV_Neighbours(h263e_MacroBlock *MBcurr, Ipp32s frGOB, Ipp32s i, Ipp32s j, IppMotionVector *mvPred);

  void    ChooseAdvIntraPred(h263e_MacroBlock *MBcurr, Ipp16s *coeffs, Ipp32s *predDir);

  void    PredictAdvIntra(h263e_MacroBlock *MBcurr, Ipp16s *coeffs, Ipp32s scan);
  Ipp32s  PredictReconstructAdvIntra(Ipp8u *pF[6], h263e_MacroBlock *MBcurr, Ipp16s *coeffs, Ipp32s *nzCount, Ipp32s quant, Ipp32s scan);

  void    DCT8x8MacroBlock_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB);
  Ipp32s  QuantMacroBlockIntra_H263(Ipp16s *coeffMB, Ipp32s *nzCount, Ipp32s quant);
  Ipp32s  TransMacroBlockInter_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s *nzCount, Ipp32s quant, Ipp8u *mcPred, Ipp32s lumaErr);
  void    ReconMacroBlockNotCoded(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp8u *mcPred);

  void    OBMC_Macroblock(h263e_MacroBlock *pMBinfo, IppMotionVector *mvCur, Ipp32s colNum, Ipp32s rowNum, IppiRect limitRectL, Ipp8u *pYr, Ipp32s stepYr, Ipp8u *pYc, Ipp32s stepYc);

  void    ReconMacroBlockIntra_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s quant, Ipp32s pattern);
  void    ReconBlockIntra_AdvI_H263(Ipp8u *p, Ipp32s step, Ipp16s *coef, h263e_Block *bCurr, Ipp32s quant, Ipp32s pattern, Ipp32s scan);

  void    ReconMacroBlockInter_H263(Ipp8u *pYc, Ipp8u *pUc, Ipp8u *pVc, Ipp8u *mcPred, Ipp16s *coeffMB, Ipp32s quant, Ipp32s pattern);
  void    ReconMacroBlockIntra_H263(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV, Ipp16s *coeffMB, Ipp32s quant, h263e_MacroBlock *MBcurr, Ipp32s pattern, Ipp32s dct_type);
  void    ME_SAD_16x16(Ipp8u *pCur, Ipp8u *pRef, Ipp32s step, Ipp32s xL, Ipp32s xR, Ipp32s yT, Ipp32s yB, Ipp32s *bestSAD, IppMotionVector *mv);
  void    ME_SAD_8x8(Ipp8u *pCur, Ipp8u *pRef, Ipp32s step, Ipp32s xL, Ipp32s xR, Ipp32s yT, Ipp32s yB, Ipp32s *bestSAD, IppMotionVector *mv, IppMotionVector *mv4, Ipp32s x, Ipp32s y, IppMotionVector *mvNeighb);
  void    PostFrameRC();
};

#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 h263e_Div2(a) ((a) >= 0 ? ((a) >> 1) : (((a)+1) >> 1))
#define h263e_Div2Round(a) (((a) >> 1) | ((a) & 1))
#define h263e_DivRoundInf(a, b) ((a) < 0 ? (((a) - ((b) >> 1)) / (b)) : (((a) + ((b) >> 1)) / (b)))
#define h263e_Clip(a, l, r) if (a < (l)) a = l; else if (a > (r)) a = r;
#define h263e_ClipL(a, l) if (a < (l)) a = l;
#define h263e_ClipR(a, r) if (a > (r)) a = r;
#define h263e_Abs(a) ((a) >= 0 ? (a) : -(a))

#define h263e_Zero8_16s(pDst) \
  ((Ipp32u*)pDst)[0] = ((Ipp32u*)pDst)[1] = ((Ipp32u*)pDst)[2] = ((Ipp32u*)pDst)[3] = 0;

#ifdef USE_INTRINSIC

#define h263e_Zero4MV(mv) \
  memset(mv, 0, 4 * sizeof(IppMotionVector));

#define h263e_Zero64_16s(pDst) \
{ \
  __m128i _p_val = _mm_setzero_si128(); \
  ((__m128i*)(pDst))[0] = _p_val; \
  ((__m128i*)(pDst))[1] = _p_val; \
  ((__m128i*)(pDst))[2] = _p_val; \
  ((__m128i*)(pDst))[3] = _p_val; \
  ((__m128i*)(pDst))[4] = _p_val; \
  ((__m128i*)(pDst))[5] = _p_val; \
  ((__m128i*)(pDst))[6] = _p_val; \
  ((__m128i*)(pDst))[7] = _p_val; \
}

#define h263e_Set64_16s(val, pDst) \
{ \
  __m128i _p_val = _mm_set1_epi16((Ipp16s)(val)); \
  ((__m128i*)(pDst))[0] = _p_val; \
  ((__m128i*)(pDst))[1] = _p_val; \
  ((__m128i*)(pDst))[2] = _p_val; \
  ((__m128i*)(pDst))[3] = _p_val; \
  ((__m128i*)(pDst))[4] = _p_val; \
  ((__m128i*)(pDst))[5] = _p_val; \
  ((__m128i*)(pDst))[6] = _p_val; \
  ((__m128i*)(pDst))[7] = _p_val; \
}

#else

#define h263e_Zero4MV(mv) \
    *((Ipp32u*)&mv[0]) = *((Ipp32u*)&mv[1]) = *((Ipp32u*)&mv[2]) = *((Ipp32u*)&mv[3]) = 0

#define h263e_Zero64_16s(pDst) \
{ \
  Ipp32s  i; \
  for (i = 0; i < 16; i += 4) {\
    ((Ipp64u*)(pDst))[i] = 0; \
    ((Ipp64u*)(pDst))[i+1] = 0; \
    ((Ipp64u*)(pDst))[i+2] = 0; \
    ((Ipp64u*)(pDst))[i+3] = 0; \
  } \
}

#define h263e_Set64_16s(val, pDst) \
{ \
  Ipp32s  i; \
  Ipp32u  v; \
  v = ((val) << 16) + (Ipp16u)(val); \
  for (i = 0; i < 32; i += 8) { \
    ((Ipp32u*)(pDst))[i] = v; \
    ((Ipp32u*)(pDst))[i+1] = v; \
    ((Ipp32u*)(pDst))[i+2] = v; \
    ((Ipp32u*)(pDst))[i+3] = v; \
    ((Ipp32u*)(pDst))[i+4] = v; \
    ((Ipp32u*)(pDst))[i+5] = v; \
    ((Ipp32u*)(pDst))[i+6] = v; \
    ((Ipp32u*)(pDst))[i+7] = v; \
  } \
}

#endif

template <class T> inline void h263e_Swap(T &a, T &b)
{
  T  t;
  t = a; a = b; b = t;
}

#define limitMV(dx, xmin, xmax, mvd) \
{                                    \
  if ((dx) < (xmin))                 \
    mvd = (Ipp16s)(xmin);          \
  else if ((dx) >= (xmax))           \
    mvd = (Ipp16s)(xmax);          \
  else                               \
    mvd = (Ipp16s)(dx);            \
}

inline void h263e_LimitMV(const IppMotionVector *pSrcMV, IppMotionVector *pDstMV, const IppiRect *limitRect, Ipp32s x, Ipp32s y, Ipp32s size)
{
  limitMV(pSrcMV->dx, (limitRect->x - x) << 1, (limitRect->x - x + limitRect->width  - size) << 1, pDstMV->dx);
  limitMV(pSrcMV->dy, (limitRect->y - y) << 1, (limitRect->y - y + limitRect->height - size) << 1, pDstMV->dy);
}

inline void h263e_Limit4MV(const IppMotionVector *pSrcMV, IppMotionVector *pDstMV, const IppiRect *limitRect, Ipp32s x, Ipp32s y, Ipp32s size)
{
  h263e_LimitMV(&pSrcMV[0], &pDstMV[0], limitRect, x       , y,        size);
  h263e_LimitMV(&pSrcMV[1], &pDstMV[1], limitRect, x + size, y,        size);
  h263e_LimitMV(&pSrcMV[2], &pDstMV[2], limitRect, x       , y + size, size);
  h263e_LimitMV(&pSrcMV[3], &pDstMV[3], limitRect, x + size, y + size, size);
}

extern const Ipp8u h263e_cCbCrMvRound16_[];
extern const Ipp8u h263e_DCScalerLuma_[];
extern const Ipp8u h263e_DCScalerChroma_[];

⌨️ 快捷键说明

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