| 1 | /* |
| 2 | * Copyright (c) 2022, 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 decode_jpeg_pipeline.cpp |
| 24 | //! \brief Defines the interface for jpeg decode pipeline |
| 25 | //! |
| 26 | #include "decode_jpeg_pipeline.h" |
| 27 | #include "decode_utils.h" |
| 28 | #include "codechal_setting.h" |
| 29 | #include "decode_jpeg_feature_manager.h" |
| 30 | #include "decode_jpeg_input_bitstream.h" |
| 31 | #include "media_debug_fast_dump.h" |
| 32 | |
| 33 | namespace decode{ |
| 34 | |
| 35 | JpegPipeline::JpegPipeline( |
| 36 | CodechalHwInterfaceNext *hwInterface, |
| 37 | CodechalDebugInterface *debugInterface) |
| 38 | : DecodePipeline(hwInterface, debugInterface) |
| 39 | { |
| 40 | MOS_STATUS m_status = InitUserSetting(m_userSettingPtr); |
| 41 | } |
| 42 | |
| 43 | MOS_STATUS JpegPipeline::Initialize(void *settings) |
| 44 | { |
| 45 | DECODE_FUNC_CALL(); |
| 46 | |
| 47 | DECODE_CHK_STATUS(DecodePipeline::Initialize(settings)); |
| 48 | m_basicFeature = dynamic_cast<JpegBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature)); |
| 49 | DECODE_CHK_NULL(m_basicFeature); |
| 50 | |
| 51 | // Create basic GPU context |
| 52 | DecodeScalabilityPars scalPars; |
| 53 | MOS_ZeroMemory(&scalPars, sizeof(scalPars)); |
| 54 | DECODE_CHK_STATUS(m_mediaContext->SwitchContext(VdboxDecodeFunc, &scalPars, &m_scalability)); |
| 55 | m_decodeContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 56 | m_decodeContextHandle = m_osInterface->CurrentGpuContextHandle; |
| 57 | |
| 58 | return MOS_STATUS_SUCCESS; |
| 59 | } |
| 60 | |
| 61 | MOS_STATUS JpegPipeline::Prepare(void *params) |
| 62 | { |
| 63 | DECODE_FUNC_CALL(); |
| 64 | |
| 65 | DECODE_CHK_NULL(params); |
| 66 | DECODE_CHK_STATUS(DecodePipeline::Prepare(params)); |
| 67 | |
| 68 | return MOS_STATUS_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | MOS_STATUS JpegPipeline::UserFeatureReport() |
| 72 | { |
| 73 | DECODE_FUNC_CALL(); |
| 74 | DECODE_CHK_STATUS(DecodePipeline::UserFeatureReport()); |
| 75 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 76 | WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_APOGEIOS_JPEGD_ENABLE_ID, 1, m_osInterface->pOsContext); |
| 77 | #endif |
| 78 | |
| 79 | CODECHAL_DEBUG_TOOL( |
| 80 | if (m_mmcState != nullptr) { |
| 81 | m_mmcState->UpdateUserFeatureKey(&(m_basicFeature->m_destSurface)); |
| 82 | }) |
| 83 | |
| 84 | return MOS_STATUS_SUCCESS; |
| 85 | } |
| 86 | |
| 87 | MOS_STATUS JpegPipeline::Uninitialize() |
| 88 | { |
| 89 | DECODE_FUNC_CALL(); |
| 90 | return DecodePipeline::Uninitialize(); |
| 91 | } |
| 92 | |
| 93 | MOS_STATUS JpegPipeline::ActivateDecodePackets() |
| 94 | { |
| 95 | DECODE_FUNC_CALL(); |
| 96 | |
| 97 | bool immediateSubmit = false; |
| 98 | |
| 99 | |
| 100 | DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, jpegDecodePacketId), immediateSubmit, 0, 0)); |
| 101 | |
| 102 | return MOS_STATUS_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | MOS_STATUS JpegPipeline::CreateFeatureManager() |
| 106 | { |
| 107 | DECODE_FUNC_CALL(); |
| 108 | m_featureManager = MOS_New(DecodeJpegFeatureManager, m_allocator, m_hwInterface, m_osInterface); |
| 109 | DECODE_CHK_NULL(m_featureManager); |
| 110 | return MOS_STATUS_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | MOS_STATUS JpegPipeline::CreateSubPackets(DecodeSubPacketManager& subPacketManager, CodechalSetting &codecSettings) |
| 114 | { |
| 115 | DECODE_FUNC_CALL(); |
| 116 | DECODE_CHK_STATUS(DecodePipeline::CreateSubPackets(subPacketManager, codecSettings)); |
| 117 | return MOS_STATUS_SUCCESS; |
| 118 | } |
| 119 | |
| 120 | MOS_STATUS JpegPipeline::CreatePreSubPipeLines(DecodeSubPipelineManager &subPipelineManager) |
| 121 | { |
| 122 | m_bitstream = MOS_New(DecodeJpegInputBitstream, this, m_task, m_numVdbox); |
| 123 | DECODE_CHK_NULL(m_bitstream); |
| 124 | DECODE_CHK_STATUS(subPipelineManager.Register(*m_bitstream)); |
| 125 | return MOS_STATUS_SUCCESS; |
| 126 | } |
| 127 | |
| 128 | #if USE_CODECHAL_DEBUG_TOOL |
| 129 | MOS_STATUS JpegPipeline::DumpPicParams( |
| 130 | CodecDecodeJpegPicParams *picParams) |
| 131 | { |
| 132 | DECODE_FUNC_CALL(); |
| 133 | |
| 134 | if (picParams == nullptr) |
| 135 | { |
| 136 | return MOS_STATUS_SUCCESS; |
| 137 | } |
| 138 | |
| 139 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrPicParams)) |
| 140 | { |
| 141 | const char *fileName = m_debugInterface->CreateFileName( |
| 142 | "_DEC", |
| 143 | CodechalDbgBufferType::bufPicParams, |
| 144 | CodechalDbgExtType::txt); |
| 145 | |
| 146 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 147 | { |
| 148 | MediaDebugFastDump::Dump( |
| 149 | (uint8_t *)picParams, |
| 150 | fileName, |
| 151 | sizeof(CodecDecodeJpegPicParams), |
| 152 | 0, |
| 153 | MediaDebugSerializer<CodecDecodeJpegPicParams>()); |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | DumpDecodeJpegPicParams(picParams, fileName); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return MOS_STATUS_SUCCESS; |
| 162 | } |
| 163 | |
| 164 | MOS_STATUS JpegPipeline::DumpScanParams( |
| 165 | CodecDecodeJpegScanParameter *scanParams) |
| 166 | { |
| 167 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 168 | |
| 169 | if (scanParams == nullptr) |
| 170 | { |
| 171 | return MOS_STATUS_SUCCESS; |
| 172 | } |
| 173 | |
| 174 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrScanParams)) |
| 175 | { |
| 176 | const char *fileName = m_debugInterface->CreateFileName( |
| 177 | "_DEC", |
| 178 | CodechalDbgBufferType::bufScanParams, |
| 179 | CodechalDbgExtType::txt); |
| 180 | |
| 181 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 182 | { |
| 183 | MediaDebugFastDump::Dump( |
| 184 | (uint8_t *)scanParams, |
| 185 | fileName, |
| 186 | sizeof(CodecDecodeJpegScanParameter), |
| 187 | 0, |
| 188 | MediaDebugSerializer<CodecDecodeJpegScanParameter>()); |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | DumpDecodeJpegScanParams(scanParams, fileName); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return MOS_STATUS_SUCCESS; |
| 197 | } |
| 198 | |
| 199 | MOS_STATUS JpegPipeline::DumpHuffmanTable( |
| 200 | PCODECHAL_DECODE_JPEG_HUFFMAN_TABLE huffmanTable) |
| 201 | { |
| 202 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 203 | |
| 204 | if (huffmanTable == nullptr) |
| 205 | { |
| 206 | return MOS_STATUS_SUCCESS; |
| 207 | } |
| 208 | |
| 209 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrHuffmanTbl)) |
| 210 | { |
| 211 | const char *fileName = m_debugInterface->CreateFileName( |
| 212 | "_DEC", |
| 213 | CodechalDbgBufferType::bufHuffmanTbl, |
| 214 | CodechalDbgExtType::txt); |
| 215 | |
| 216 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 217 | { |
| 218 | MediaDebugFastDump::Dump( |
| 219 | (uint8_t *)huffmanTable, |
| 220 | fileName, |
| 221 | sizeof(CODECHAL_DECODE_JPEG_HUFFMAN_TABLE), |
| 222 | 0, |
| 223 | MediaDebugSerializer<CODECHAL_DECODE_JPEG_HUFFMAN_TABLE>()); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | DumpDecodeJpegHuffmanParams(huffmanTable, fileName); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return MOS_STATUS_SUCCESS; |
| 232 | } |
| 233 | |
| 234 | MOS_STATUS JpegPipeline::DumpIQParams(CodecJpegQuantMatrix *iqParams) |
| 235 | { |
| 236 | CODECHAL_DEBUG_FUNCTION_ENTER; |
| 237 | |
| 238 | if (iqParams == nullptr) |
| 239 | { |
| 240 | return MOS_STATUS_SUCCESS; |
| 241 | } |
| 242 | |
| 243 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrIqParams)) |
| 244 | { |
| 245 | const char *fileName = m_debugInterface->CreateFileName( |
| 246 | "_DEC", |
| 247 | CodechalDbgBufferType::bufIqParams, |
| 248 | CodechalDbgExtType::txt); |
| 249 | |
| 250 | if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 251 | { |
| 252 | MediaDebugFastDump::Dump( |
| 253 | (uint8_t *)iqParams, |
| 254 | fileName, |
| 255 | sizeof(CodecJpegQuantMatrix), |
| 256 | 0, |
| 257 | MediaDebugSerializer<CodecJpegQuantMatrix>()); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | DumpDecodeJpegIqParams(iqParams, fileName); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | return MOS_STATUS_SUCCESS; |
| 266 | } |
| 267 | #endif |
| 268 | |
| 269 | } |