1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef _MP4ENC_LIB_H_ 19 #define _MP4ENC_LIB_H_ 20 21 #include "mp4def.h" // typedef 22 #include "mp4lib_int.h" // main video structure 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif 28 29 /* defined in vop.c */ 30 PV_STATUS EncodeVop(VideoEncData *video); 31 PV_STATUS EncodeSlice(VideoEncData *video); 32 PV_STATUS EncodeVideoPacketHeader(VideoEncData *video, int MB_number, 33 int quant_scale, Int insert); 34 #ifdef ALLOW_VOP_NOT_CODED 35 PV_STATUS EncodeVopNotCoded(VideoEncData *video, UChar *bstream, Int *size, ULong modTime); 36 #endif 37 38 /* defined in combined_decode.c */ 39 PV_STATUS EncodeFrameCombinedMode(VideoEncData *video); 40 PV_STATUS EncodeSliceCombinedMode(VideoEncData *video); 41 42 /* defined in datapart_decode.c */ 43 PV_STATUS EncodeFrameDataPartMode(VideoEncData *video); 44 PV_STATUS EncodeSliceDataPartMode(VideoEncData *video); 45 46 /* defined in fastcodeMB.c */ 47 48 //void m4v_memset(void *adr_dst, uint8 value, uint32 size); 49 50 PV_STATUS CodeMB_H263(VideoEncData *video, approxDCT *function, Int offsetQP, Int ncoefblck[]); 51 #ifndef NO_MPEG_QUANT 52 PV_STATUS CodeMB_MPEG(VideoEncData *video, approxDCT *function, Int offsetQP, Int ncoefblck[]); 53 #endif 54 Int getBlockSAV(Short block[]); 55 Int Sad8x8(UChar *rec, UChar *prev, Int lx); 56 Int getBlockSum(UChar *rec, Int lx); 57 58 /* defined in dct.c */ 59 void blockIdct(Short *block); 60 void blockIdct_SSE(Short *input); 61 void BlockDCTEnc(Short *blockData, Short *blockCoeff); 62 63 /*---- FastQuant.c -----*/ 64 Int cal_dc_scalerENC(Int QP, Int type) ; 65 Int BlockQuantDequantH263Inter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam, 66 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, 67 Int dctMode, Int comp, Int dummy, UChar shortHeader); 68 69 Int BlockQuantDequantH263Intra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam, 70 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, 71 Int dctMode, Int comp, Int dc_scaler, UChar shortHeader); 72 73 Int BlockQuantDequantH263DCInter(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam, 74 UChar *bitmaprow, UInt *bitmapzz, Int dummy, UChar shortHeader); 75 76 Int BlockQuantDequantH263DCIntra(Short *rcoeff, Short *qcoeff, struct QPstruct *QuantParam, 77 UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler, UChar shortHeader); 78 79 #ifndef NO_MPEG_QUANT 80 Int BlockQuantDequantMPEGInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat, 81 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, 82 Int DctMode, Int comp, Int dc_scaler); 83 84 Int BlockQuantDequantMPEGIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat, 85 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, 86 Int DctMode, Int comp, Int dc_scaler); 87 88 Int BlockQuantDequantMPEGDCInter(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat, 89 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dummy); 90 91 Int BlockQuantDequantMPEGDCIntra(Short *rcoeff, Short *qcoeff, Int QP, Int *qmat, 92 UChar bitmapcol[ ], UChar *bitmaprow, UInt *bitmapzz, Int dc_scaler); 93 #endif 94 95 /*---- FastIDCT.c -----*/ 96 void BlockIDCTMotionComp(Short *block, UChar *bitmapcol, UChar bitmaprow, 97 Int dctMode, UChar *rec, UChar *prev, Int lx_intra_zeroMV); 98 99 100 /* defined in motion_comp.c */ 101 void getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset); 102 void EncPrediction_INTER(Int xpred, Int ypred, UChar *c_prev, UChar *c_rec, 103 Int width, Int round1); 104 105 void EncPrediction_INTER4V(Int xpred, Int ypred, MOT *mot, UChar *c_prev, UChar *c_rec, 106 Int width, Int round1); 107 108 void EncPrediction_Chrom(Int xpred, Int ypred, UChar *cu_prev, UChar *cv_prev, UChar *cu_rec, 109 UChar *cv_rec, Int pitch_uv, Int width_uv, Int height_uv, Int round1); 110 111 void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v, 112 Short mb[6][64], Int width, Int width_uv); 113 114 void PutSkippedBlock(UChar *rec, UChar *prev, Int lx); 115 116 /* defined in motion_est.c */ 117 void MotionEstimation(VideoEncData *video); 118 #ifdef HTFM 119 void InitHTFM(VideoEncData *video, HTFM_Stat *htfm_stat, double *newvar, Int *collect); 120 void UpdateHTFM(VideoEncData *video, double *newvar, double *exp_lamda, HTFM_Stat *htfm_stat); 121 #endif 122 123 /* defined in ME_utils.c */ 124 void ChooseMode_C(UChar *Mode, UChar *cur, Int lx, Int min_SAD); 125 void ChooseMode_MMX(UChar *Mode, UChar *cur, Int lx, Int min_SAD); 126 void GetHalfPelMBRegion_C(UChar *cand, UChar *hmem, Int lx); 127 void GetHalfPelMBRegion_SSE(UChar *cand, UChar *hmem, Int lx); 128 void GetHalfPelBlkRegion(UChar *cand, UChar *hmem, Int lx); 129 void PaddingEdge(Vop *padVop); 130 void ComputeMBSum_C(UChar *cur, Int lx, MOT *mot_mb); 131 void ComputeMBSum_MMX(UChar *cur, Int lx, MOT *mot_mb); 132 void ComputeMBSum_SSE(UChar *cur, Int lx, MOT *mot_mb); 133 void GetHalfPelMBRegionPadding(UChar *ncand, UChar *hmem, Int lx, Int *reptl); 134 void GetHalfPelBlkRegionPadding(UChar *ncand, UChar *hmem, Int lx, Int *reptl); 135 136 /* defined in findhalfpel.c */ 137 void FindHalfPelMB(VideoEncData *video, UChar *cur, MOT *mot, UChar *ncand, 138 Int xpos, Int ypos, Int *xhmin, Int *yhmin, Int hp_guess); 139 Int FindHalfPelBlk(VideoEncData *video, UChar *cur, MOT *mot, Int sad16, UChar *ncand8[], 140 UChar *mode, Int xpos, Int ypos, Int *xhmin, Int *yhmin, UChar *hp_mem); 141 142 143 /* defined in sad.c */ 144 Int SAD_MB_HalfPel_Cxhyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 145 Int SAD_MB_HalfPel_Cyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 146 Int SAD_MB_HalfPel_Cxh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 147 Int SAD_MB_HalfPel_MMX(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 148 Int SAD_MB_HalfPel_SSE(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 149 Int SAD_Blk_HalfPel_C(UChar *ref, UChar *blk, Int dmin, Int lx, Int rx, Int xh, Int yh, void *extra_info); 150 Int SAD_Blk_HalfPel_MMX(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 151 Int SAD_Blk_HalfPel_SSE(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 152 Int SAD_Macroblock_C(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 153 Int SAD_Macroblock_MMX(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 154 Int SAD_Macroblock_SSE(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 155 Int SAD_Block_C(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 156 Int SAD_Block_MMX(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 157 Int SAD_Block_SSE(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 158 159 #ifdef HTFM /* Hypothesis Testing Fast Matching */ 160 Int SAD_MB_HP_HTFM_Collectxhyh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info); 161 Int SAD_MB_HP_HTFM_Collectyh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info); 162 Int SAD_MB_HP_HTFM_Collectxh(UChar *ref, UChar *blk, Int dmin_x, void *extra_info); 163 Int SAD_MB_HP_HTFMxhyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 164 Int SAD_MB_HP_HTFMyh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 165 Int SAD_MB_HP_HTFMxh(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 166 Int SAD_MB_HTFM_Collect(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 167 Int SAD_MB_HTFM(UChar *ref, UChar *blk, Int dmin_lx, void *extra_info); 168 #endif 169 /* on-the-fly padding */ 170 Int SAD_Blk_PADDING(UChar *ref, UChar *cur, Int dmin, Int lx, void *extra_info); 171 Int SAD_MB_PADDING(UChar *ref, UChar *cur, Int dmin, Int lx, void *extra_info); 172 #ifdef HTFM 173 Int SAD_MB_PADDING_HTFM_Collect(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 174 Int SAD_MB_PADDING_HTFM(UChar *ref, UChar *blk, Int dmin, Int lx, void *extra_info); 175 #endif 176 177 /* defined in rate_control.c */ 178 /* These are APIs to rate control exposed to core encoder module. */ 179 PV_STATUS RC_Initialize(void *video); 180 PV_STATUS RC_VopQPSetting(VideoEncData *video, rateControl *rc[]); 181 PV_STATUS RC_VopUpdateStat(VideoEncData *video, rateControl *rc); 182 PV_STATUS RC_MBQPSetting(VideoEncData *video, rateControl *rc, Int start_packet_header); 183 PV_STATUS RC_MBUpdateStat(VideoEncData *video, rateControl *rc, Int Bi, Int Hi); 184 PV_STATUS RC_Cleanup(rateControl *rc[], Int numLayers); 185 186 Int RC_GetSkipNextFrame(VideoEncData *video, Int currLayer); 187 Int RC_GetRemainingVops(VideoEncData *video, Int currLayer); 188 void RC_ResetSkipNextFrame(VideoEncData *video, Int currLayer); 189 PV_STATUS RC_UpdateBuffer(VideoEncData *video, Int currLayer, Int num_skip); 190 PV_STATUS RC_UpdateBXRCParams(void *input); 191 192 193 /* defined in vlc_encode.c */ 194 void MBVlcEncodeDataPar_I_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr); 195 void MBVlcEncodeDataPar_P_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr); 196 void MBVlcEncodeCombined_I_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr); 197 void MBVlcEncodeCombined_P_VOP(VideoEncData *video, Int ncoefblck[], void *blkCodePtr); 198 void BlockCodeCoeff_ShortHeader(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode); 199 void BlockCodeCoeff_RVLC(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode); 200 void BlockCodeCoeff_Normal(RunLevelBlock *RLB, BitstreamEncVideo *bs, Int j_start, Int j_stop, UChar Mode); 201 202 #ifdef __cplusplus 203 } 204 #endif 205 206 #endif /* _MP4ENC_LIB_H_ */ 207 208