📄 umc_h264_video_encoder.h
字号:
//// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2004 - 2005 Intel Corporation. All Rights Reserved.//#ifndef __UMC_H264_VIDEO_ENCODER_H__#define __UMC_H264_VIDEO_ENCODER_H__#include "ippdefs.h"#include "vm_strings.h"#include "umc_video_data.h"#include "umc_h264_pub.h"#include "umc_h264_bs.h"#include "umc_h264_core_enc.h"#include "umc_h264_enc_cpb.h"#include "umc_h264_deblock.h"#include "umc_h264_npf.h"#include "umc_video_encoder.h"#include "umc_h264_crc.h"namespace UMC{class H264EncoderParams: public VideoEncoderParams{ Status CheckDPBSize();public: H264EncoderParams(); Status ReadParamFile(vm_char *ParFileName); vm_char SrcFName[256]; vm_char TemplateLogFile[256]; int numThreads; int LogMask; int frame_rate_code; int aspectRatio; int ProfileID; int LevelID; int chroma_format; int mpegNumb;#ifdef AdvMEAlgs int me_alg_num;#endif H264AdvRate_Options arco; int coding_type; // 0 - only FRM, 1 - only FLD , 2 - only AFRM, 3 - pure PicAFF(no MBAFF) 4 PicAFF + MBAFF Ipp32u B_Frame_Rate; Ipp32u treat_B_as_reference; Ipp32u num_ref_frames; Ipp32u num_ref_to_start_code_B_slice; Ipp8u level_idc; Ipp32s pixel_aspect_ratio; Ipp8u m_do_weak_forced_key_frames; // This flag is set when an application does wants the encoder // to retain pending P and B frames in the ready queue when // Make_Next_Frame_Key() is called. Ipp8u m_do_suppress_B_for_this_TR; // This flag is set when an application "overrides" a // B frame in the profile at the current TR for all layers. // The following reserved members are place holders that allow us // to add new options, without changing the size of this structure. // They are intended to be used after a release, so that adding // new options does not affect the size of our persistent data. Ipp8u Deblocking_Filter_Mode; // This indicates that even though annex J may be // on, the deblocking filter should not be called. // This means that motion vectors off the edge // are still on, as are 8x8 motion vectors. // This is a non-standard option and only // used in RealVideo. When this option is set // to true the DFP bit in the RealVideo slice // header is set to 1, otherwise, this bit will // be set to 0. If Annex J is turned off, this // option will be ignored. The decoder will also // ignore the bit, if Annex J is off. // These values control the deblocking filter strength // the valid range for both is +\- 6 Ipp32s Deblocking_Filter_Alpha; Ipp32s Deblocking_Filter_Beta; //Ipp32u entropy_coding_mode; //Ipp32u cabac_init_idc; // Determines whether 4x4, 4x8 & 8x4 subblocks are ever used Ipp32u me_split_8x8s; Ipp32u me_use_subpixel_search; Ipp32u use_weighted_pred; Ipp32u use_weighted_bipred; Ipp32u use_implicit_weighted_bipred; // Determines whether weighted interpolation is used to form bi-predictions Ipp8u use_spatial_direct_pred; Ipp32u use_direct_inference; Ipp32u me_search_x,me_search_y; SliceData slice_parms; EnumSliceType current_slice_type; Ipp8u entropy_coding_mode; Ipp32u cabac_init_idc; // more settings to be added here H264_Rate_Controls B_frame_rate_controls; Ipp16u Num_Slices; // Number of slices sDimensions dimensions; // Specifies the image dimensions for this layer. H264_Rate_Controls rate_controls; // Specifies bit rate control options for this layer. H264_Key_Frame_Controls key_frame_controls; // Specifies key frame rate control options for this layer. // The following reserved members are place holders that allow us // to add new options, without changing the size of this structure. // They are intended to be used after a release, so that adding // new options does not affect the size of our persistent data.};//VideoEncoder *createH264VideoEncoder();// Provide portable implementations of memory allocation and deallocation.//void *H264_Allocate(Ipp32u size, bool zero_init); // Allocate 'size' bytes of memory, optionally clear it, and // return a pointer to it. Returns NULL if allocation fails. // The caller is repsonsible for recovering from a failed allocation. // Allocating 0 bytes is supported, though it will result in // some non-zero number of bytes actually being allocated.void H264_Free(void*); // Free memory previously allocated by H264_Allocate.class H264VideoEncoder: public VideoEncoder{public: H264VideoEncoder(Status&); ~H264VideoEncoder();protected:public: H264_Image_Format m_input_format; H264_Image_Format m_output_format; // Initialize codec with specified parameter(s) virtual Status Init(BaseCodecParams *init); // Compress (decompress) next frame virtual Status GetFrame(MediaData *in, MediaData *out); // Get codec working (initialization) parameter(s) virtual Status GetInfo(BaseCodecParams *info); // Close all codec resources virtual Status Close(); virtual Status Reset () { return UMC_UNSUPPORTED; }; virtual Status SetParams (BaseCodecParams* params); Status InitImages(); Status DestroyImages();protected: Ipp32s profile_frequency; H264LocalMacroblockDescriptor m_mbinfo; H264CurrentMacroblockDescriptor m_cur_mb; EnumPicCodType eFrameType[H264_Max_B_Frames]; // End of user-visible settings CH264pBs * m_bs1; Ipp32u m_uIntraFrameInterval; // dimension dependent variables: Ipp32u m_HeightInMBs; Ipp32u m_WidthInMBs; Ipp32u m_NumMBs; // -- Total number of MBs.public: H264EncoderParams m_info; H264_Encoder_Compression_Flags cflags; H264_Encoder_Compression_Notes cnotes; H264_Image def_src,def_dst; H264EncoderFrameList m_cpb; H264EncoderFrameList m_dpb; Ipp32s m_dpbSize; H264EncoderFrame *m_pCurrentFrame; H264EncoderFrame *m_pReconstructFrame; Ipp8u m_field_index; Ipp32s m_NumRefsInL0List; Ipp32s m_NumRefsInL1List; Ipp32s m_NumRefsInLTList; Ipp8u m_NumShortEntriesInList; Ipp8u m_NumLongEntriesInList; AdaptiveMarkingInfo m_AdaptiveMarkingInfo; RefPicListReorderInfo m_ReorderInfoL0; RefPicListReorderInfo m_ReorderInfoL1; Ipp32s m_MaxLongTermFrameIdx;protected: Ipp8u * m_pAllocEncoderInst; // flags read by DetermineFrameType while sequencing the profile: bool m_bMakeNextFrameKey; bool m_bKeyFrameIntervalPending; DeblockingFilter m_deblockingFilter;#if defined (_DEBUG) Ipp32u m_counter_mv_bits; Ipp32u m_counter_coeff_bits; Ipp32u m_counter_mbhdr_bits; Ipp32u m_counter_total_mv_bits; Ipp32u m_counter_total_coeff_bits; Ipp32u m_counter_total_mbhdr_bits; Ipp32u m_counter_total_num_frames; void ZeroBits(); void ZeroTotalBits(); Ipp32u AddBits(); Ipp32u AddTotalBits(); void AddBitsToTotal(); void PrintBits(Ipp32u num); void PrintTotalBits(); void Write_Recon_Frame(EnumPicClass ePic_Class, H264EncoderFrame * frame); void Write_Order_Frame(EnumPicClass ePic_Class, H264EncoderFrame * curr_frame);#endif void Estimate_One_MV_Predictor( Ipp32u uMB, // which MB Ipp32u uBlock, // which 4x4 Block (UL Corner, Raster Order) Ipp32u uList, // 0, 1 for L0 or L1. T_ECORE_MV *pMVIn, // Optional MV to pass in. Will be used to fill block MV buffer if not NULL. Ipp32u uBlocksWide, // 1, 2, or 4 Ipp32u uBlocksHigh, // 1, 2, or 4 (4x16 and 16x4 not permitted) T_ECORE_MV *pMVPred, // resulting MV predictor T_ECORE_BIGMV *pMVDelta // resulting MV delta ); Status H264VideoEncoder::UpdateRefPicList( H264SliceHeader &SHdr, RefPicListReorderInfo *pReorderInfo_L0, RefPicListReorderInfo *pReorderInfo_L1, Ipp32u uSliceNum ); void H264VideoEncoder::InitPSliceRefPicList( bool bIsFieldSlice, Ipp32s /*NumL0RefActive*/, H264EncoderFrame **pRefPicList // pointer to start of list 0 ); void H264VideoEncoder::InitBSliceRefPicLists( bool bIsFieldSlice, Ipp32s /*NumL0RefActive*/, Ipp32s /*NumL1RefActive*/, H264EncoderFrame **pRefPicList0, // pointer to start of list 0 H264EncoderFrame **pRefPicList1 // pointer to start of list 1 ); void H264VideoEncoder::InitDistScaleFactor( Ipp32s NumL0RefActive, H264EncoderFrame **pRefPicList0, H264EncoderFrame **pRefPicList1, Ipp8s *pFields0, Ipp8s *pFields1 );#if defined SPLIT_INTO_FIELDS void H264VideoEncoder::AdjustRefPicListForFields( H264EncoderFrame **pRefPicList,Ipp8s *pFields);#endif // SPLIT_INTO_FIELDS void H264VideoEncoder::ReOrderRefPicList( bool bIsFieldSlice, H264EncoderFrame **pRefPicList, Ipp8s *pFields, RefPicListReorderInfo *pReorderInfo, Ipp32s MaxPicNum, Ipp32s NumRefActive ); Status H264VideoEncoder::UpdateRefPicMarking(); Status CompressFrame( EnumPicCodType &, H264_Image & ); Status EncodePicture(H264_Image& dst); // Encodes the current field or frame. Status EncodeDummyFrame(H264_Image &dst); // Encodes blank frame when overflow EnumPicCodType DetermineFrameType( Ipp32s ); Status encodeFrameHeader (CH264pBs*, H264_Image &dst, bool bIDR_Pic); void FrameType ( EnumPicCodType & ); void SetSequenceParameters (); void SetPictureParameters (PictureStructure picture_structure = FRAME_PICTURE); void SetDPBSize(); void SetSliceHeader ( H264EncoderFrame *, EnumPicClass ePictureClass ); Status MoveFromCPBToDPB(); Status CleanDPB(); void SetPictureQuant(); //void SwapReferencePtrs(); Ipp32s m_iProfileIndex; Ipp8u * m_pBitStream; // Pointer to bitstream buffer. bool m_bScratchBufferAllocated; // indicated whether bitstream- and scratch // buffers have been allocated. Should happen // only once per StartSequence bool m_bBuffersAllocated; // Indicates that all working buffers have been // allocated. Ipp32u m_uTRWrapAround; // Wrap around for TR Ipp32u m_uFrames_Num; // Decode order frame number. Ipp32u m_uPic_Count_Base; // Display order picture counter base. Sets to sequence number at IDR (Key Frame) // This allows an IDR frame relative Pic_Cnt to be calculated. Ipp32u m_uFrameCounter; // Counts frames in input order so that the sequence numbers of input frames can // be normalized to a strictly increasing counter. // Pointer to string of Ipp8u's containing the QP mask, one Ipp8u // for each macroblock Ipp8u *m_pQPMap; // Boolean indicating that a QP mask has been set and should // be used for the next encode of this frame. This flag is // always cleared bool m_bQPMapIsReady; // Store the size of the QP map. Ipp32u m_QPMapSize; // Input color convertor. // video noise reduction prefilter. CNoiseReductionFilter* m_noisepf; Ipp32u uWidthInMBs; Ipp32u uHeightInMBs; Ipp32u uWidthIn4x4Blocks; Ipp32u uHeightIn4x4Blocks; Ipp32u uPitch;public: // Provide implementations for the pure virtual methods inherited // from the H264_Encoder class. See the H264_Encoder class definition // for a description of these methods. // Ipp32u MaxCompressedSize(const H264_Image_Format&, const H264_Image_Format&); Ipp32u GetBsBufferMaxSize(const Ipp32u w, const Ipp32u h); Status Start_Sequence(const H264_Image_Format&, const H264_Image_Format&); Status End_Sequence(); Status Encode( const H264_Image &src, H264_Image &dst, const H264_Encoder_Compression_Flags, H264_Encoder_Compression_Notes& ); Status Set_Rate_Controls( const H264_Rate_Controls&); Status Set_Key_Frame_Controls( const H264_Key_Frame_Controls&); Status Make_Next_Frame_Key(); Status Set_B_Frames(Ipp32u number_of_B_frames); Status Set_Num_Slices(Ipp32u number_of_slices); Status Set_Deblocking_Loop_Filter(Ipp8u Use_Filter, Ipp32s Alpha, Ipp32s Beta); Status Get_Sequence_Controls(H264_Sequence_Controls&);private:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -