1 /*! 2 * \copy 3 * Copyright (c) 2013, Cisco Systems 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33 //wels_slice.h 34 #ifndef WELS_SLICE_H__ 35 #define WELS_SLICE_H__ 36 37 #include "typedefs.h" 38 #include "wels_const.h" 39 #include "wels_common_basis.h" 40 #include "mb_cache.h" 41 #include "picture.h" 42 #include "parameter_sets.h" 43 #include "svc_enc_slice_segment.h" 44 #include "set_mb_syn_cabac.h" 45 #include "nal_encap.h" 46 47 namespace WelsEnc { 48 49 /*******************************sub struct of slice header****************************/ 50 51 52 /* 53 * Reference picture list reordering syntax, refer to page 64 in JVT X201wcm 54 */ 55 typedef struct TagRefPicListReorderSyntax { 56 struct { 57 uint32_t uiAbsDiffPicNumMinus1; //uiAbsDiffPicNumMinus1 SHOULD be in the range of [4, (1<<pSps->uiLog2MaxFrameNum)-1], {p104, JVT-X201wcm1} 58 //but int8_t can't cover the range, SHOULD modify it. 59 uint16_t iLongTermPicNum; 60 uint16_t uiReorderingOfPicNumsIdc; //in order to pack 2-uint16_t into 1-(u)int32_t, so modify the type into uint16_t. 61 } SReorderingSyntax[MAX_REFERENCE_REORDER_COUNT_NUM]; // MAX_REF_PIC_COUNT 62 } SRefPicListReorderSyntax; 63 64 65 /* Decoded reference picture marking syntax, refer to Page 66 in JVT X201wcm */ 66 typedef struct TagRefPicMarking { 67 struct { 68 int32_t iMmcoType; 69 int32_t iShortFrameNum; 70 int32_t iDiffOfPicNum; 71 int32_t iLongTermPicNum; 72 int32_t iLongTermFrameIdx; 73 int32_t iMaxLongTermFrameIdx; 74 } SMmcoRef[MAX_REFERENCE_MMCO_COUNT_NUM]; // MAX_MMCO_COUNT 75 76 // int32_t mmco_index; 77 uint8_t uiMmcoCount; 78 bool bNoOutputOfPriorPicsFlag; 79 bool bLongTermRefFlag; 80 bool bAdaptiveRefPicMarkingModeFlag; 81 } SRefPicMarking; 82 83 // slice level rc statistic info 84 typedef struct TagRCSlicing { 85 int32_t iComplexityIndexSlice; 86 int32_t iCalculatedQpSlice; 87 int32_t iStartMbSlice; 88 int32_t iEndMbSlice; 89 int32_t iTotalQpSlice; 90 int32_t iTotalMbSlice; 91 int32_t iTargetBitsSlice; 92 int32_t iBsPosSlice; 93 int32_t iFrameBitsSlice; 94 int32_t iGomBitsSlice; 95 int32_t iGomTargetBits; 96 //int32_t gom_coded_mb; 97 } SRCSlicing; 98 99 /* Header of slice syntax elements, refer to Page 63 in JVT X201wcm */ 100 typedef struct TagSliceHeader { 101 /*****************************slice header syntax and generated****************************/ 102 int32_t iFirstMbInSlice; 103 // uint32_t pic_parameter_set_id; 104 int32_t iFrameNum; 105 int32_t iPicOrderCntLsb; 106 107 // int32_t delta_pic_order_cnt_bottom; 108 // int32_t delta_pic_order_cnt[2]; 109 // int32_t redundant_pic_cnt; 110 111 EWelsSliceType eSliceType; 112 uint8_t uiNumRefIdxL0Active; // 113 //int32_t num_ref_idx_l1_active_minus1 //B frame is not supported 114 uint8_t uiRefCount; 115 //Ref_Pic *ref_pic; 116 uint8_t uiRefIndex; // exact reference picture index for slice 117 118 int8_t iSliceQpDelta; 119 // int32_t slice_qp; 120 // int32_t slice_qs_delta; // For SP/SI slices 121 uint8_t uiDisableDeblockingFilterIdc; 122 int8_t iSliceAlphaC0Offset; 123 int8_t iSliceBetaOffset; 124 #if !defined(DISABLE_FMO_FEATURE) 125 int32_t iSliceGroupChangeCycle; 126 #endif//!DISABLE_FMO_FEATURE 127 128 SWelsSPS* pSps; 129 SWelsPPS* pPps; 130 int32_t iSpsId; 131 int32_t iPpsId; 132 133 uint16_t uiIdrPicId; 134 // uint8_t color_plane_id;//from? 135 136 bool bNumRefIdxActiveOverrideFlag; 137 // bool field_pic_flag; //not supported in base profile 138 // bool bottom_field_flag; //not supported in base profile 139 uint8_t uiPadding1Bytes; 140 141 SRefPicMarking sRefMarking; // Decoded reference picture marking syntaxs 142 143 SRefPicListReorderSyntax sRefReordering; // Reference picture list reordering syntaxs 144 } SSliceHeader, *PSliceHeader; 145 146 147 /* SSlice header in scalable extension syntax, refer to Page 394 in JVT X201wcm */ 148 typedef struct TagSliceHeaderExt { 149 SSliceHeader sSliceHeader; 150 151 SSubsetSps* pSubsetSps; 152 153 uint32_t uiNumMbsInSlice; 154 155 bool bStoreRefBasePicFlag; 156 bool bConstrainedIntraResamplingFlag; 157 bool bSliceSkipFlag; 158 159 bool bAdaptiveBaseModeFlag; 160 bool bDefaultBaseModeFlag; 161 bool bAdaptiveMotionPredFlag; 162 bool bDefaultMotionPredFlag; 163 164 bool bAdaptiveResidualPredFlag; 165 bool bDefaultResidualPredFlag; 166 bool bTcoeffLevelPredFlag; 167 uint8_t uiDisableInterLayerDeblockingFilterIdc; 168 169 } SSliceHeaderExt, *PSliceHeaderExt; 170 171 172 typedef struct TagSlice { 173 // mainly for multiple threads imp. 174 SMbCache sMbCacheInfo; // MBCache is introduced within slice dependency 175 SBitStringAux* pSliceBsa; 176 SWelsSliceBs sSliceBs; 177 178 /*******************************sSliceHeader****************************/ 179 SSliceHeaderExt sSliceHeaderExt; 180 181 SMVUnitXY sMvStartMin; 182 SMVUnitXY sMvStartMax; 183 SMVUnitXY sMvc[5]; 184 uint8_t uiMvcNum; 185 uint8_t sScaleShift; 186 187 int32_t iSliceIdx; 188 uint32_t uiBufferIdx; 189 bool bSliceHeaderExtFlag; // Indicate which slice header is used, avc or ext? 190 uint8_t uiLastMbQp; // stored qp for last mb coded, maybe more efficient for mb skip detection etc. 191 192 bool bDynamicSlicingSliceSizeCtrlFlag; 193 uint8_t uiAssumeLog2BytePerMb; 194 195 uint32_t uiSliceFMECostDown;//TODO: for FME switch under MT, to opt after ME final? 196 197 uint8_t uiReservedFillByte; // reserved to meet 4 bytes alignment 198 199 SCabacCtx sCabacCtx; 200 int32_t iCabacInitIdc; 201 int32_t iMbSkipRun; 202 203 int32_t iCountMbNumInSlice; 204 uint32_t uiSliceConsumeTime; 205 int32_t iSliceComplexRatio; 206 207 SRCSlicing sSlicingOverRc; //slice level rc statistic info 208 } SSlice, *PSlice; 209 210 } 211 #endif//WELS_SLICE_H__ 212 213