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

📄 umc_mpeg2_enc.h

📁 audio-video-codecs.rar语音编解码器
💻 H
📖 第 1 页 / 共 2 页
字号:

  // Encode reordered frames (B frames following the corresponding I/P frames).
  // frame_type must be supplied (I_PICTURE, P_PICTURE, B_PICTURE).
  // No buffering because the frames are already reordered.
  Status EncodeFrameReordered(VideoData* frame, MediaData *out);

  void setUserData(vm_char* data, Ipp32s len);

  Ipp32s InitRateControl(Ipp32s BitRate); // inits bit rate control

  // used in thread routine
  FrameType  picture_coding_type;     // picture coding type (I, P or B)
  void encodeB(Ipp32s numTh);
  void encodeP(Ipp32s numTh);
  void encodeI(Ipp32s numTh);

protected:
  MediaData m_UserData; // user data, must have no start codes

  void PrepareBuffers();
  void PutSequenceHeader();
  void PutSequenceExt();
  void PutSequenceDisplayExt();
  void PutUserData(Ipp32s part); // part: 0-after seq.h., 1-after gop.h., 2-after pic.h.
  void PutGOPHeader(Ipp32s Count);
  void PutPictureHeader();
  void PutPictureCodingExt();
  void PutSequenceEnd();
  void PutSliceHeader(Ipp32s RowNumber, Ipp32s numTh);
  void PutMV(Ipp32s delta, Ipp32s f_code, Ipp32s numTh);
  void PutAddrIncrement(Ipp32s increment, Ipp32s numTh);
  Ipp32s  FrameToTimecode(Ipp32s frame);
  void PutNonIntraBlock(Ipp16s* block, Ipp32s count, Ipp32s numTh);
  void PutIntraBlock(Ipp16s* block, Ipp32s* dc_dct_pred,
                     const IppVCHuffmanSpec_32u* DC_Tbl,
                     Ipp32s count, Ipp32s numTh);
  void PutIntraMacroBlock(Ipp32s numTh, Ipp32s k, const Ipp8u *BlockSrc[3], Ipp8u *BlockRec[3], Ipp32s *dc_dct_pred);
  Ipp32s IntraMBSize(Ipp32s k, const Ipp8u *BlockSrc[3], Ipp32s *dc_dct_pred, Ipp32s increment, Ipp32s scantype, Ipp32s vlcFormat);
  void PutMV_FRAME(Ipp32s numTh, Ipp32s k, IppMotionVector2 *vector, Ipp32s motion_type);
  void PutMV_FIELD(Ipp32s numTh, Ipp32s k, IppMotionVector2 *vector, IppMotionVector2 *vector2, Ipp32s motion_type);

  Status PutPicture();
  void NonIntraMBCoeffs(Ipp32s numTh, MB_prediction_info *prediction_info, Ipp32s *Count, Ipp32s *pCodedBlockPattern);

  /////Motion estimation
  Ipp32s MotionEstimation_Frame(ME_PARAMS);
  Ipp32s MotionEstimation_Field(ME_PARAMS);
  Ipp32s MotionEstimation_FieldPict(ME_PARAMS);
  void AdjustSearchRange(Ipp32s B_count, Ipp32s direction);

  /////////////////////////////////////////////////////////////////////
  MPEG2EncoderParams encodeInfo;
  VideoProcessing* frame_loader;

  // to set up internal VideoData buffers
  void InitInternalFrame(VideoData* frame);
  void SetInternalFramePointers(VideoData* frame, Ipp8u* buffer);
  // lock unlock buffers from external memory allocator
  Status      LockBuffers();    // Lock buffers
  Status      UnlockBuffers();  // Unlock buffers

  VideoData   *tmpFrame;       // temporal input frame to copy here when needed
  Ipp8u       *tmpFrame_buf;   // memory for temporal input frame
  MemID       mid_tmpFrame_buf;// its MemID

  Ipp8u       *m_lpbReference; // (Ipp8u *) pointer to allocated space for references
  MemID       mid_Reference;   // its MemID
  VideoData   *RotatingFrames[4]; // refs to frames in m_lpbReference[fwd/bwd*2 + orig/recon]
  VideoData   **pRotFrames[2];    // refs to RotatingFrames, subject of rotation

  // for [topfield/bottomfield][forward/backward] ME; points to refs in frames_buff
  Ipp8u       *YRefFrame[2][2];   // [top/bottom][fwd/bwd]
  Ipp8u       *URefFrame[2][2];
  Ipp8u       *VRefFrame[2][2];
  Ipp8u       *YRecFrame[2][2];   // [top/bottom][fwd/bwd]
  Ipp8u       *URecFrame[2][2];
  Ipp8u       *VRecFrame[2][2];

  // YUV frames buffer
  VideoData   *VideoData_buff;
  Ipp8u       *frames_buff;
  Ipp32s      is_frames_buff_locked;
  MemID       mid_frames_buff; // its MemID
  Ipp32s      buff_size;       // in number of frames
  Ipp32s      buff_ind;
  Ipp32s      num_btype;
  Ipp32s      num_new;
  Ipp32s      curr_gop;


  // Input frame; point to tmpFrame_buf or frames_buff
  Ipp8u       *Y_src;
  Ipp8u       *U_src;
  Ipp8u       *V_src;

  Ipp32s      MBcountH;
  Ipp32s      MBcountV;
  Ipp32s      MBcount;

  // Aligned sizes of all frames
  Ipp32s      YFrameHSize;
  Ipp32s      UVFrameHSize;
  Ipp32s      YFrameVSize;
  Ipp32s      UVFrameVSize;
  Ipp32s      YFrameSize;
  Ipp32s      UVFrameSize;
  Ipp32s      YUVFrameSize;

  Ipp32s      aspectRatio_code;      // 1-square,4:3,16:9,2.21:1
  Ipp32s      frame_rate_code;       // code for values, specified in standard
  Ipp32s      frame_rate_extension_n;// 2 bits
  Ipp32s      frame_rate_extension_d;// 5 bits
  Ipp32s      picture_structure;     // picture structure (frame, top / bottom field)
  Ipp32s      top_field_first;       // display top field first
  Ipp32s      repeat_first_field;    // increased display time
  Ipp32s      ipflag;                // P-field instead of second I-field (ref only opposite fld)
  Ipp32s      temporal_reference;    // display order in the GOP
  Ipp32s      closed_gop;            // doesn't refer to previous, i.e. first

  // params for each type of frame
  MotionData  *pMotionData;          // motion estimation ranges for P, B0, B1, ...
  Ipp32s      MotionDataCount;       // count of pMotionData array elements
  const Ipp32s (*mp_f_code)[2];      // points to forward[x,y], backward[x,y]

  Ipp32s      curr_frame_dct;        // when 0 dct_type have to be found
  Ipp32s      curr_frame_pred;       // is frame_pred_frame_dct, when 0 allows 16x8 modes
  Ipp32s      curr_intra_vlc_format;
  Ipp32s      curr_scan;
  Ipp32s      intra_dc_precision;
  Ipp32s      vbv_delay;             // vbv_delay code for picture header
  Ipp32s      rc_vbv_max;            // max allowed size of the frame to be encoded in bits
  Ipp32s      rc_vbv_min;            // min allowed size of the frame to avoid overflow with next frame
  Ipp64f      rc_vbv_fullness;       // buffer fullness before frame removing in bits
  Ipp64f      rc_delay;              // vbv examination delay for current picture
  Ipp64f      rc_ip_delay;           // extra delay for I or P pictures in bits
  Ipp64f      rc_ave_frame_bits;     // bits per frame
  Ipp32s      qscale[3];             // qscale codes for 3 frame types (Ipp32s!)
  Ipp32s      prsize[3];             // bitsize of previous frame of the type
  Ipp32s      prqscale[3];           // quant scale value, used with previous frame of the type
  Ipp32s      quantiser_scale_value; // for the current frame
  Ipp32s      q_scale_type;          // 0 for linear 1 for nonlinear
  Ipp32s      quantiser_scale_code;  // bitcode for current scale value
  bool        bQuantiserChanged;     // recalculate picture with new quantizer
  bool        bSceneChanged;         // recalculate P picture to I
  bool        bExtendGOP;            // recalculate I picture to P
  Ipp64f      rc_weight[3];          // frame weight (length proportion)
  Ipp64f      rc_tagsize[3];         // bitsize target of the type
  Ipp64f      rc_dev;                // bitrate deviation (sum of GOP's frame diffs)

  Ipp32s      varThreshold;          // threshold for block variance

  Ipp32s      PictureRateControl(Ipp64s bits_in_headers);  // selects curr scale
  Ipp32s      PostPictureRateControl(Ipp64s bits_encoded); // adaptation here
  Ipp32s      changeQuant(Ipp32s quant_value);             // changes all related
  Ipp32s      mapQuant(Ipp32s quant_value);                // returns mapped value

  Status      SetFrameRate(Ipp64f new_fr, Ipp32s is_mpeg1 = 0); // sets framerate code and extensions
  Status      SetAspectRatio(Ipp32s hor, Ipp32s ver); // sets aspect code from h/v value
  Ipp32s      onlyIFrames;   // true if no B-frames
  Ipp32s      B_count;       // index of B frame
  Ipp32s      m_GOP_Start;   // first frame of current GOP
  Ipp32s      m_GOP_Start_tmp; // first frame of current GOP (for restore)
  Ipp32s      m_FirstFrame;  // true if numEncodedFrames==0

  Ipp32s      block_count;   // 6 or 8 or 12 depending on chroma format

  Ipp16s*     IntraQMatrix;
  Ipp16s*     NonIntraQMatrix;
  VM_ALIGN16_DECL(Ipp32f) _InvIntraQMatrix[64];
  VM_ALIGN16_DECL(Ipp32f) _InvNonIntraQMatrix[64];
  Ipp32f*     InvIntraQMatrix;
  Ipp32f*     InvNonIntraQMatrix;

  Ipp32s      m_Inited;
  MBInfo      *pMBInfo;    // macroblock side information array

  // threads
  Ipp32s      threadsAllocated; // but used threads is encodeInfo.numThreads
  threadSpecificData *threadSpec;
  threadInfo  **threads;

  // Variable Length Coding tables
  IppVCHuffmanSpec_32s *vlcTableB5c_e;
  IppVCHuffmanSpec_32s *vlcTableB15;

  // Output bitstream
  Ipp8u  *out_pointer;
  Ipp32s output_buffer_size;
  Ipp32s mEncodedSize;
  Ipp32s thread_buffer_size;

  // Offsets
  Ipp32s block_offset_frm[12];
  Ipp32s block_offset_fld[12];
  Ipp32s frm_dct_step[12];
  Ipp32s fld_dct_step[12];
  Ipp32s frm_diff_off[12];
  Ipp32s fld_diff_off[12];

  // GetDiff & MotionCompensation functions
  functype_getdiff
    func_getdiff_frame_c, func_getdiff_field_c;
  functype_getdiffB
    func_getdiffB_frame_c, func_getdiffB_field_c;
  functype_mc
    func_mc_frame_c, func_mc_field_c;
  functype_mcB
    func_mcB_frame_c, func_mcB_field_c;

  // Internal var's
  Ipp32s BlkWidth_c;
  Ipp32s BlkStride_c;
  Ipp32s BlkHeight_c;
  Ipp32s chroma_fld_flag;
  Ipp32s curr_field;      // 0 - top or frame coded, 1 - bottom
  Ipp32s second_field;    // set, but not used yet

  const IppVCHuffmanSpec_32u *DC_Tbl[3];

  // const tables
  static const Ipp32s color_index[12];
  static const VLCode_8u CBP_VLC_Tbl[64];
  static const VLCode_8u AddrIncrementTbl[35];
  static const VLCode_8u mbtypetab[3][32];
  static const VLCode_8u MV_VLC_Tbl[33];
  static const IppVCHuffmanSpec_32u Y_DC_Tbl[12];
  static const IppVCHuffmanSpec_32u Cr_DC_Tbl[12];
  static const Ipp32s ResetTbl[4];
  static const Ipp32s dct_coeff_next_RL[];
  static const Ipp32s Table15[];
  static const IppiPoint MV_ZERO;
};

} // namespace UMC

#endif // __UMC_MPEG2_ENC_H

#endif // UMC_ENABLE_MPEG2_VIDEO_ENCODER

⌨️ 快捷键说明

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