1 /* 2 * Copyright (c) 2018-2021, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file codec_def_encode.h 24 //! \brief Defines encode types and macros shared by CodecHal and DDI layer 25 //! \details Applies to encode only. Should not contain any DDI specific code. 26 //! 27 28 #ifndef __CODEC_DEF_ENCODE_H__ 29 #define __CODEC_DEF_ENCODE_H__ 30 #include "mos_os.h" 31 32 //! 33 //! \struct CodechalEncodeSeiData 34 //! \brief Indicate the SeiData parameters 35 //! 36 struct CodechalEncodeSeiData 37 { 38 bool newSEIData; 39 uint32_t dwSEIDataSize; 40 uint32_t dwSEIBufSize; 41 uint8_t* pSEIBuffer; 42 }; 43 44 struct MetaDataOffset 45 { 46 uint32_t dwEncodeErrorFlags = 0; 47 uint32_t dwEncodedBitstreamWrittenBytesCount = 0; 48 uint32_t dwWrittenSubregionsCount = 0; 49 50 uint32_t dwEncodeStats = 0; 51 uint32_t dwAverageQP = 0; 52 uint32_t dwIntraCodingUnitsCount = 0; 53 uint32_t dwInterCodingUnitsCount = 0; 54 uint32_t dwSkipCodingUnitsCount = 0; 55 uint32_t dwAverageMotionEstimationXDirection = 0; 56 uint32_t dwAverageMotionEstimationYDirection = 0; 57 58 uint32_t dwbSize = 0; 59 uint32_t dwbStartOffset = 0; 60 uint32_t dwbHeaderSize = 0; 61 62 uint32_t dwMetaDataSize = 0; 63 uint32_t dwMetaDataSubRegionSize = 0; 64 }; 65 66 //! 67 //! \struct EncoderParams 68 //! \brief Encoder parameters 69 //! 70 struct EncoderParams 71 { 72 CODECHAL_FUNCTION ExecCodecFunction = CODECHAL_FUNCTION_INVALID; //!< High level codec functionality requested. 73 74 PMOS_SURFACE psRawSurface = nullptr; //!< Raw surface 75 PMOS_SURFACE psReconSurface = nullptr; //!< reconstructed surface 76 PMOS_RESOURCE presBitstreamBuffer = nullptr; //!< Output buffer for bitstream data. 77 PMOS_RESOURCE presMetadataBuffer = nullptr; //!< Output buffer for meta data. 78 PMOS_RESOURCE presMbCodeSurface = nullptr; //!< PAK objects provided by framework. 79 PMOS_SURFACE psMbSegmentMapSurface = nullptr; //!< [VP9] 80 /* \brief [AVC & MPEG2] MB QP data provided by framework. 81 * 82 * When in CQP mode, the framework can provide this surface that contains a single QpY value for each macroblock to be used for encoding. If it is not provided, the frame level QpY(QpY + slice_qp_delta) will be used for all macroblocks. 83 */ 84 PMOS_SURFACE psMbQpDataSurface = nullptr; //!< pointer to surface of Mb QP Data 85 PCODEC_ENCODE_MB_CONTROL pMbCtrlBuffer = nullptr; //!< [AVC] MB contrl map provided by framework 86 PMOS_SURFACE psMbDisableSkipMapSurface = nullptr; //!< [AVC] MB disable skip map provided by framework 87 PMOS_SURFACE psCoeffSurface = nullptr; //!< [VP9] 88 PMOS_RESOURCE presCoeffProbabilityBuffer = nullptr; //!< [VP9] Coefficient probabilities provided by framework. 89 bool bNewSeq = false; //!< Indicates the start of a new sequence. 90 bool bPicQuant = false; //!< Indicates whether the scaling list is for SPS (0) or PPS (1). 91 bool bNewQmatrixData = false; //!< Indicates that new QM data was provided by framework. 92 CodechalEncodeSeiData *pSeiData = nullptr; //!< [AVC & HEVC] Information pertaining to pSeiParamBuffer. 93 uint32_t dwSEIDataOffset = 0; //!< [AVC & HEVC] Offset to the first SEI message within pSeiParamBuffer. 94 uint8_t *pSeiParamBuffer = nullptr; //!< [AVC & HEVC] Packed SEI messages provided by the framework 95 uint32_t dwNumSlices = 0; //!< Number of slice data structures in pSliceParams. 96 uint32_t dwAppDataSize = 0; //!< [JPEG] 97 uint32_t dwNumHuffBuffers = 0; //!< [JPEG] 98 uint32_t dwMbDataBufferSize = 0; //!< Size of the data contained in presMbCodeSurface 99 uint32_t dwBitstreamSize = 0; //!< Maximum amount of data to be output to presBitstreamBuffer. 100 bool bNewVuiData = false; //!< [AVC & MPEG2] Indicates that pVuiParams is present and expected to be valid. 101 bool bJpegQuantMatrixSent = false; //!< [JPEG] Indicates whether a quant matrix was sent by the framework. 102 PBSBuffer pBSBuffer = nullptr; //!< Packed header data provided by the framework to be inserted in the bitstream. 103 PCODECHAL_NAL_UNIT_PARAMS *ppNALUnitParams = nullptr; //!< Information about the packed header data in pBSBuffer. 104 uint32_t uiNumNalUnits = 0; //!< Number of NAL units in ppNALUnitParams. 105 void *pSlcHeaderData = nullptr; //!< [AVC, HEVC, & MPEG2] Packed slice header data provided by the framework. 106 bool bAcceleratorHeaderPackingCaps = false; //!< [AVC] Indicates whether or not the driver is packing the slice headers. 107 uint32_t uiSlcStructCaps = 0; //!< [AVC] Slice capability information, formatted as CODEC_SLICE_STRUCTS 108 bool bMADEnabled = false; //!< MAD is enabled 109 bool bMbQpDataEnabled = false; //!< [AVC & MPEG2] Indicates that psMbQpDataSurface is present. 110 bool bMbDisableSkipMapEnabled = false; //!< [AVC] Indicates that psMbDisableSkipMapSurface is present. 111 bool bReportStatisticsEnabled = false; //!< [HEVC] Indicates whether statistic reporting is enabled, disabled by default. 112 bool bQualityImprovementEnable = false; //!< [HEVC] Indicates whether quality improvement is enabled, disabled by default. 113 bool newSeqHeader = false; //!< [AVC] Flag for new Sequence Header. 114 bool newPpsHeader = false; //!< [AVC] Flag for new PPS Header. 115 bool arbitraryNumMbsInSlice = false; //!< [AVC] Flag to indicate if the sliceMapSurface needs to be programmed or not. 116 117 void *pSeqParams = nullptr; //!< Sequence parameter set structure defined per standard. 118 void *pPicParams = nullptr; //!< Picture parameter set structure defined per standard. 119 void *pVuiParams = nullptr; //!< [AVC & MPEG2] Picture parameter set structure defined per standard. 120 void *pSliceParams = nullptr; //!< Slice data array defined per standard, expect dwNumSlices entries. 121 void *pSegmentParams = nullptr; //!< [VP9] 122 void *pIQMatrixBuffer = nullptr; //!< [AVC, HEVC, & MPEG2] IQ parameter structure defined per standard. 123 124 // AVC Specific Parameters 125 void *pIQWeightScaleLists = nullptr; //!< list of IQ Weight scale 126 void *pAVCQCParams = nullptr; //!< AVC QC parameters 127 void *pAVCRoundingParams = nullptr; //!< AVC rounding parameters 128 129 void *pQuantData = nullptr; 130 PMOS_RESOURCE presDistortionDataSurface = nullptr; 131 uint32_t uiFrameRate = 0; 132 133 bool bSegmentMapProvided = false; //!< [VP9] 134 135 void *pMpeg2UserDataListHead = nullptr; //!< [MPEG2] 136 137 void *pHuffmanTable = nullptr; //!< [JPEG] 138 void *pQuantizationTable = nullptr; //!< [JPEG] 139 void *pApplicationData = nullptr; //!< [JPEG] 140 141 void *pFeiPicParams = nullptr; //!< [FEI] 142 void *pPreEncParams = nullptr; //!< [FEI] 143 144 // HEVC Specific Parameters 145 bool bVdencActive = false; //!< Indicate if vdenc is active 146 bool advanced = false; //!< Indicate if vdenc is active 147 148 MOS_SURFACE rawSurface = {}; //!< Raw surface 149 MOS_SURFACE reconSurface = {}; //!< reconstructed surface 150 MOS_RESOURCE resBitstreamBuffer = {}; //!< Output buffer for bitstream data. 151 MOS_SURFACE mbQpSurface = {}; 152 MOS_SURFACE disableSkipMapSurface = {}; //!< [AVC] MB disable skip map provided by framework 153 HANDLE gpuAppTaskEvent = nullptr; // MSDK event handling 154 //Call back to application. This informs the application all ENC kernel workload is submitted(in case of HEVC VME) 155 //such that Application can make use of render engine when encoder is working on PAK. this helps in efficient utilisation of 156 //Render engine for improving the performance as the render engine will be idle when encoder is working on PAK. 157 void * plastEncKernelSubmissionCompleteCallback = nullptr; 158 159 160 bool bStreamOutEnable = false; 161 PMOS_RESOURCE pStreamOutBuffer = nullptr; // StreamOut buffer 162 bool bCoeffRoundTag = false; 163 uint32_t uiRoundIntra = 0; 164 uint32_t uiRoundInter = 0; 165 166 PMOS_RESOURCE presMbInlineData = nullptr; 167 PMOS_RESOURCE presMbConstSurface = nullptr; 168 PMOS_RESOURCE presVMEOutSurface = nullptr; 169 uint32_t uiMVoffset = 0; // App provides PAK objects and MV data in the same surface. This is offset to MV Data. 170 bool fullHeaderInAppData = false; //!< [JPEG] 171 uint32_t uiOverallNALPayload = 0; 172 MetaDataOffset metaDataOffset = {}; 173 void * pSliceHeaderParams = nullptr; //!< [HEVC] 174 175 PMOS_RESOURCE m_presPredication = nullptr; //! \brief [Predication] Resource for predication 176 uint64_t m_predicationResOffset = 0; //! \brief [Predication] Offset for Predication resource 177 bool m_predicationNotEqualZero = false; //! \brief [Predication] Predication mode 178 bool m_predicationEnabled = false; //! \brief [Predication] Indicates whether or not Predication is enabled 179 PMOS_RESOURCE *m_tempPredicationBuffer = nullptr; //! \brief [Predication] Temp buffer for Predication 180 181 bool m_setMarkerEnabled = false; //! \brief [SetMarker] Indicates whether or not SetMarker is enabled 182 PMOS_RESOURCE m_presSetMarker = nullptr; //! \brief [SetMarker] Resource for SetMarker 183 }; 184 185 #endif // !__CODEC_DEF_ENCODE_H__ 186