| 1 | /* |
| 2 | * Copyright (c) 2021-2024, 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,Av1EncodeTile |
| 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 encode_avc_aqm.cpp |
| 24 | //! \brief Defines the common interface for avc aqm |
| 25 | //! |
| 26 | |
| 27 | #include "encode_avc_aqm.h" |
| 28 | #include "encode_avc_vdenc_feature_manager.h" |
| 29 | #include "encode_avc_basic_feature.h" |
| 30 | #include "encode_avc_vdenc_fastpass.h" |
| 31 | #include "media_avc_feature_defs.h" |
| 32 | |
| 33 | namespace encode |
| 34 | { |
| 35 | AvcEncodeAqm::AvcEncodeAqm(MediaFeatureManager *featureManager, |
| 36 | EncodeAllocator * allocator, |
| 37 | CodechalHwInterfaceNext * hwInterface, |
| 38 | void * constSettings) : EncodeAqmFeature(featureManager, allocator, hwInterface, constSettings) |
| 39 | { |
| 40 | auto encFeatureManager = dynamic_cast<EncodeAvcVdencFeatureManager *>(featureManager); |
| 41 | ENCODE_CHK_NULL_NO_STATUS_RETURN(encFeatureManager); |
| 42 | |
| 43 | m_basicFeature = dynamic_cast<EncodeBasicFeature *>(encFeatureManager->GetFeature(FeatureIDs::basicFeature)); |
| 44 | ENCODE_CHK_NULL_NO_STATUS_RETURN(m_basicFeature); |
| 45 | |
| 46 | m_numTiles = 1; |
| 47 | }; |
| 48 | |
| 49 | MOS_STATUS AvcEncodeAqm::Update(void* params) |
| 50 | { |
| 51 | ENCODE_FUNC_CALL(); |
| 52 | auto basicFeature = dynamic_cast<AvcBasicFeature*>(m_basicFeature); |
| 53 | ENCODE_CHK_NULL_RETURN(basicFeature); |
| 54 | |
| 55 | auto fastPassFeature = dynamic_cast<AvcVdencFastPass *>(m_featureManager->GetFeature(AvcFeatureIDs::avcFastPass)); |
| 56 | if (fastPassFeature && fastPassFeature->IsEnabled()) |
| 57 | { |
| 58 | m_useFastPass = true; |
| 59 | m_dsWidth = fastPassFeature->GetFastPassDsWidth(); |
| 60 | m_dsHeight = fastPassFeature->GetFastPassDsHeight(); |
| 61 | } |
| 62 | |
| 63 | if (basicFeature->m_picParam->QualityInfoSupportFlags.fields.enable_frame) |
| 64 | { |
| 65 | m_enabled = true; |
| 66 | basicFeature->m_suppressReconPicSupported = false; |
| 67 | } |
| 68 | m_numTiles = 1; |
| 69 | m_tile_width[0] = m_useFastPass ? (uint16_t)m_dsWidth : (uint16_t)m_basicFeature->m_oriFrameWidth; |
| 70 | m_tile_height[0] = m_useFastPass ? (uint16_t)m_dsHeight : (uint16_t)m_basicFeature->m_oriFrameHeight; |
| 71 | |
| 72 | #if USE_CODECHAL_DEBUG_TOOL |
| 73 | UpdateFrameDisplayOrder(basicFeature->m_pictureCodingType, basicFeature->m_picParam->CurrFieldOrderCnt[0] / 2, basicFeature->m_seqParam->GopPicSize); |
| 74 | #endif |
| 75 | ENCODE_CHK_STATUS_RETURN(EncodeAqmFeature::Update(params)); |
| 76 | return MOS_STATUS_SUCCESS; |
| 77 | } |
| 78 | |
| 79 | MOS_STATUS AvcEncodeAqm::Init(void *setting) |
| 80 | { |
| 81 | ENCODE_FUNC_CALL(); |
| 82 | ENCODE_CHK_NULL_RETURN(setting); |
| 83 | |
| 84 | ENCODE_CHK_STATUS_RETURN(EncodeAqmFeature::Init(setting)); |
| 85 | |
| 86 | auto basicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature); |
| 87 | ENCODE_CHK_NULL_RETURN(basicFeature); |
| 88 | |
| 89 | if (m_enabled) |
| 90 | { |
| 91 | // Assuming AvcBasicFeature is already initialized, if VDAQM is in use, enable deblocking/recon generation for all frames |
| 92 | basicFeature->m_suppressReconPicSupported = false; |
| 93 | } |
| 94 | |
| 95 | return MOS_STATUS_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | MHW_SETPAR_DECL_SRC(AQM_PIC_STATE, AvcEncodeAqm) |
| 99 | { |
| 100 | ENCODE_CHK_STATUS_RETURN(EncodeAqmFeature::MHW_SETPAR_F(AQM_PIC_STATE)(params)); |
| 101 | if (m_enabled) |
| 102 | { |
| 103 | params.frameWidthInPixelMinus1 = m_useFastPass ? (MOS_ALIGN_CEIL(m_dsWidth, 16) - 1) : (MOS_ALIGN_CEIL(m_basicFeature->m_oriFrameWidth, 16) - 1); |
| 104 | params.FrameHeightInPixelMinus1 = m_useFastPass ? (MOS_ALIGN_CEIL(m_dsHeight, 16) - 1) : (MOS_ALIGN_CEIL(m_basicFeature->m_oriFrameHeight, 16) - 1); |
| 105 | params.lcuSize = LCU_SIZE_16X16; |
| 106 | params.codectype = CODECTYPE_AVC; |
| 107 | } |
| 108 | |
| 109 | return MOS_STATUS_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | MHW_SETPAR_DECL_SRC(AQM_SLICE_STATE, AvcEncodeAqm) |
| 113 | { |
| 114 | auto basicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature); |
| 115 | ENCODE_CHK_NULL_RETURN(basicFeature); |
| 116 | |
| 117 | auto sliceParams = &basicFeature->m_sliceParams[basicFeature->m_curNumSlices]; |
| 118 | uint16_t width = m_useFastPass ? m_dsWidth : basicFeature->m_seqParam->FrameWidth; |
| 119 | uint16_t height = m_useFastPass ? m_dsHeight : basicFeature->m_seqParam->FrameHeight; |
| 120 | auto frameWidth = static_cast<uint32_t>(CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(width)); |
| 121 | auto frameHeight = static_cast<uint32_t>(CODECHAL_GET_WIDTH_IN_MACROBLOCKS(height)); |
| 122 | |
| 123 | uint32_t numMbsForSlice = m_useFastPass ? (frameWidth * frameHeight) : sliceParams->NumMbsForSlice; |
| 124 | auto nextsliceMbStartYPosition = (sliceParams->first_mb_in_slice + numMbsForSlice) / frameWidth; |
| 125 | params.tileSliceStartLcuMbX = 0; |
| 126 | params.tileSliceStartLcuMbY = sliceParams->first_mb_in_slice / frameWidth; |
| 127 | params.nextTileSliceStartLcuMbX = 0; |
| 128 | params.nextTileSliceStartLcuMbY = nextsliceMbStartYPosition > frameHeight ? frameHeight : nextsliceMbStartYPosition; |
| 129 | |
| 130 | return MOS_STATUS_SUCCESS; |
| 131 | } |
| 132 | |
| 133 | MHW_SETPAR_DECL_SRC(MFX_AVC_IMG_STATE, AvcEncodeAqm) |
| 134 | { |
| 135 | params.vdaqmEnable = m_enabled; |
| 136 | |
| 137 | return MOS_STATUS_SUCCESS; |
| 138 | } |
| 139 | |
| 140 | #if USE_CODECHAL_DEBUG_TOOL |
| 141 | MOS_STATUS AvcEncodeAqm::UpdateFrameDisplayOrder(const uint16_t pictureCodingType, const uint32_t framePOC, const uint32_t gopPicSize) |
| 142 | { |
| 143 | auto basicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature); |
| 144 | ENCODE_CHK_NULL_RETURN(basicFeature); |
| 145 | if (basicFeature->m_picParam->bIdrPic == 1) |
| 146 | { |
| 147 | m_frameNumPrevious += m_gopSizePrevious; |
| 148 | } |
| 149 | uint32_t displayOrderInGOP = framePOC; |
| 150 | uint32_t displayOrderInSeq = displayOrderInGOP + m_frameNumPrevious; |
| 151 | m_gopSizePrevious = gopPicSize; |
| 152 | m_frameIdxQueue.push(displayOrderInSeq); |
| 153 | return MOS_STATUS_SUCCESS; |
| 154 | } |
| 155 | #endif |
| 156 | |
| 157 | } // namespace encode |