| 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_mpeg2_pipeline.cpp |
| 24 |
//! \brief Defines the interface for mpeg2 decode pipeline |
| 25 |
//! |
| 26 |
#include "decode_mpeg2_pipeline.h" |
| 27 |
#include "decode_utils.h" |
| 28 |
#include "codechal_setting.h" |
| 29 |
#include "decode_mpeg2_feature_manager.h" |
| 30 |
#include "decode_huc_packet_creator_base.h" |
| 31 |
#include "media_debug_fast_dump.h" |
| 32 |
|
| 33 |
namespace decode{ |
| 34 |
|
| 35 |
Mpeg2Pipeline::Mpeg2Pipeline( |
| 36 |
CodechalHwInterfaceNext *hwInterface, |
| 37 |
CodechalDebugInterface *debugInterface) |
| 38 |
: DecodePipeline(hwInterface, debugInterface) |
| 39 |
{ |
| 40 |
MOS_STATUS m_status = InitUserSetting(m_userSettingPtr); |
| 41 |
} |
| 42 |
|
| 43 |
MOS_STATUS Mpeg2Pipeline::Initialize(void *settings) |
| 44 |
{ |
| 45 |
DECODE_FUNC_CALL(); |
| 46 |
|
| 47 |
DECODE_CHK_STATUS(DecodePipeline::Initialize(settings)); |
| 48 |
m_basicFeature = dynamic_cast<Mpeg2BasicFeature*>(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 |
HucPacketCreatorBase *hucPktCreator = dynamic_cast<HucPacketCreatorBase *>(this); |
| 59 |
DECODE_CHK_NULL(hucPktCreator); |
| 60 |
m_mpeg2BsCopyPkt = hucPktCreator->CreateHucCopyPkt(this, m_task, m_hwInterface); |
| 61 |
DECODE_CHK_NULL(m_mpeg2BsCopyPkt); |
| 62 |
MediaPacket *packet = dynamic_cast<MediaPacket *>(m_mpeg2BsCopyPkt); |
| 63 |
DECODE_CHK_NULL(packet); |
| 64 |
DECODE_CHK_STATUS(RegisterPacket(DecodePacketId(this, mpeg2BsCopyPktId), packet)); |
| 65 |
DECODE_CHK_STATUS(packet->Init()); |
| 66 |
|
| 67 |
return MOS_STATUS_SUCCESS; |
| 68 |
} |
| 69 |
|
| 70 |
MOS_STATUS Mpeg2Pipeline::Prepare(void *params) |
| 71 |
{ |
| 72 |
DECODE_FUNC_CALL(); |
| 73 |
|
| 74 |
DECODE_CHK_NULL(params); |
| 75 |
DECODE_CHK_STATUS(DecodePipeline::Prepare(params)); |
| 76 |
DECODE_CHK_STATUS(CopyBitstreamBuffer()); |
| 77 |
|
| 78 |
return MOS_STATUS_SUCCESS; |
| 79 |
} |
| 80 |
|
| 81 |
MOS_STATUS Mpeg2Pipeline::CopyDummyBitstream() |
| 82 |
{ |
| 83 |
DECODE_FUNC_CALL(); |
| 84 |
|
| 85 |
HucCopyPktItf::HucCopyParams copyParams = {}; |
| 86 |
|
| 87 |
for (uint16_t slcIdx = 0; slcIdx < m_basicFeature->m_totalNumSlicesRecv; slcIdx++) |
| 88 |
{ |
| 89 |
// Copy dummy slice to local buffer |
| 90 |
if (!m_basicFeature->m_copyDummySlicePresent && ((m_basicFeature->m_sliceRecord[slcIdx].prevSliceMbEnd != |
| 91 |
m_basicFeature->m_sliceRecord[slcIdx].sliceStartMbOffset && !m_basicFeature->m_sliceRecord[slcIdx].skip) || |
| 92 |
m_basicFeature->m_incompletePicture)) |
| 93 |
{ |
| 94 |
m_basicFeature->m_copyDummySlicePresent = true; |
| 95 |
copyParams.srcBuffer = &(m_basicFeature->m_resMpeg2DummyBistream->OsResource); |
| 96 |
copyParams.srcOffset = 0; |
| 97 |
copyParams.destBuffer = &(m_basicFeature->m_copiedDataBuf->OsResource); |
| 98 |
copyParams.destOffset = m_basicFeature->m_nextCopiedDataOffset; |
| 99 |
copyParams.copyLength = sizeof(m_basicFeature->Mpeg2DummyBsBuf); |
| 100 |
m_mpeg2BsCopyPkt->PushCopyParams(copyParams); |
| 101 |
|
| 102 |
m_basicFeature->m_dummySliceDataOffset = m_basicFeature->m_nextCopiedDataOffset; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
return MOS_STATUS_SUCCESS; |
| 107 |
} |
| 108 |
|
| 109 |
MOS_STATUS Mpeg2Pipeline::CopyBitstreamBuffer() |
| 110 |
{ |
| 111 |
DECODE_FUNC_CALL(); |
| 112 |
|
| 113 |
HucCopyPktItf::HucCopyParams copyParams = {}; |
| 114 |
|
| 115 |
if (m_basicFeature->m_copiedDataNeeded) |
| 116 |
{ |
| 117 |
m_basicFeature->m_copiedDataBufferInUse = true; |
| 118 |
if ((m_basicFeature->m_nextCopiedDataOffset + m_basicFeature->m_dataSize) > |
| 119 |
m_basicFeature->m_copiedDataBufferSize) |
| 120 |
{ |
| 121 |
DECODE_ASSERTMESSAGE("Copied data buffer is not large enough."); |
| 122 |
m_basicFeature->m_slicesInvalid = true; |
| 123 |
return MOS_STATUS_UNKNOWN; |
| 124 |
} |
| 125 |
|
| 126 |
uint32_t size = MOS_ALIGN_CEIL(m_basicFeature->m_dataSize, 16); |
| 127 |
copyParams.srcBuffer = &(m_basicFeature->m_resDataBuffer.OsResource); |
| 128 |
copyParams.srcOffset = 0; |
| 129 |
copyParams.destBuffer = &(m_basicFeature->m_copiedDataBuf->OsResource); |
| 130 |
copyParams.destOffset = m_basicFeature->m_nextCopiedDataOffset; |
| 131 |
copyParams.copyLength = m_basicFeature->m_dataSize; |
| 132 |
m_mpeg2BsCopyPkt->PushCopyParams(copyParams); |
| 133 |
|
| 134 |
m_basicFeature->m_copiedDataOffset = m_basicFeature->m_nextCopiedDataOffset; |
| 135 |
m_basicFeature->m_nextCopiedDataOffset += MOS_ALIGN_CEIL(size, MHW_CACHELINE_SIZE); |
| 136 |
|
| 137 |
bool immediateSubmit = true; |
| 138 |
DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, mpeg2BsCopyPktId), immediateSubmit, 0, 0)); |
| 139 |
m_activePacketList.back().frameTrackingRequested = false; |
| 140 |
DECODE_CHK_STATUS(ExecuteActivePackets()); |
| 141 |
} |
| 142 |
|
| 143 |
return MOS_STATUS_SUCCESS; |
| 144 |
} |
| 145 |
|
| 146 |
MOS_STATUS Mpeg2Pipeline::UserFeatureReport() |
| 147 |
{ |
| 148 |
DECODE_FUNC_CALL(); |
| 149 |
DECODE_CHK_STATUS(DecodePipeline::UserFeatureReport()); |
| 150 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 151 |
WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_APOGEIOS_MPEG2D_ENABLE_ID, 1, m_osInterface->pOsContext); |
| 152 |
#endif |
| 153 |
|
| 154 |
CODECHAL_DEBUG_TOOL( |
| 155 |
if (m_mmcState != nullptr) { |
| 156 |
m_mmcState->UpdateUserFeatureKey(&(m_basicFeature->m_destSurface)); |
| 157 |
}) |
| 158 |
|
| 159 |
return MOS_STATUS_SUCCESS; |
| 160 |
} |
| 161 |
|
| 162 |
MOS_STATUS Mpeg2Pipeline::Uninitialize() |
| 163 |
{ |
| 164 |
DECODE_FUNC_CALL(); |
| 165 |
return DecodePipeline::Uninitialize(); |
| 166 |
} |
| 167 |
|
| 168 |
MOS_STATUS Mpeg2Pipeline::ActivateDecodePackets() |
| 169 |
{ |
| 170 |
DECODE_FUNC_CALL(); |
| 171 |
|
| 172 |
bool immediateSubmit = false; |
| 173 |
|
| 174 |
if (m_basicFeature->m_copyDummySlicePresent) |
| 175 |
{ |
| 176 |
DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, mpeg2BsCopyPktId), immediateSubmit, 0, 0)); |
| 177 |
} |
| 178 |
|
| 179 |
DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, mpeg2DecodePacketId), immediateSubmit, 0, 0)); |
| 180 |
|
| 181 |
return MOS_STATUS_SUCCESS; |
| 182 |
} |
| 183 |
|
| 184 |
MOS_STATUS Mpeg2Pipeline::CreateFeatureManager() |
| 185 |
{ |
| 186 |
DECODE_FUNC_CALL(); |
| 187 |
m_featureManager = MOS_New(DecodeMpeg2FeatureManager, m_allocator, m_hwInterface, m_osInterface); |
| 188 |
DECODE_CHK_NULL(m_featureManager); |
| 189 |
return MOS_STATUS_SUCCESS; |
| 190 |
} |
| 191 |
|
| 192 |
MOS_STATUS Mpeg2Pipeline::CreateSubPackets(DecodeSubPacketManager& subPacketManager, CodechalSetting &codecSettings) |
| 193 |
{ |
| 194 |
DECODE_FUNC_CALL(); |
| 195 |
DECODE_CHK_STATUS(DecodePipeline::CreateSubPackets(subPacketManager, codecSettings)); |
| 196 |
return MOS_STATUS_SUCCESS; |
| 197 |
} |
| 198 |
|
| 199 |
#if USE_CODECHAL_DEBUG_TOOL |
| 200 |
MOS_STATUS Mpeg2Pipeline::DumpPicParams( |
| 201 |
CodecDecodeMpeg2PicParams *picParams) |
| 202 |
{ |
| 203 |
DECODE_FUNC_CALL(); |
| 204 |
|
| 205 |
if (picParams == nullptr) |
| 206 |
{ |
| 207 |
return MOS_STATUS_SUCCESS; |
| 208 |
} |
| 209 |
|
| 210 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrPicParams)) |
| 211 |
{ |
| 212 |
const char *fileName = m_debugInterface->CreateFileName( |
| 213 |
"_DEC", |
| 214 |
CodechalDbgBufferType::bufPicParams, |
| 215 |
CodechalDbgExtType::txt); |
| 216 |
|
| 217 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 218 |
{ |
| 219 |
MediaDebugFastDump::Dump( |
| 220 |
(uint8_t *)picParams, |
| 221 |
fileName, |
| 222 |
sizeof(CodecDecodeMpeg2PicParams), |
| 223 |
0, |
| 224 |
MediaDebugSerializer<CodecDecodeMpeg2PicParams>()); |
| 225 |
} |
| 226 |
else |
| 227 |
{ |
| 228 |
DumpDecodeMpeg2PicParams(picParams, fileName); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
return MOS_STATUS_SUCCESS; |
| 233 |
} |
| 234 |
|
| 235 |
MOS_STATUS Mpeg2Pipeline::DumpSliceParams( |
| 236 |
CodecDecodeMpeg2SliceParams *sliceParams, |
| 237 |
uint32_t numSlices) |
| 238 |
{ |
| 239 |
DECODE_FUNC_CALL(); |
| 240 |
|
| 241 |
if (sliceParams == nullptr) |
| 242 |
{ |
| 243 |
return MOS_STATUS_SUCCESS; |
| 244 |
} |
| 245 |
|
| 246 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSlcParams)) |
| 247 |
{ |
| 248 |
const char *fileName = m_debugInterface->CreateFileName( |
| 249 |
"_DEC", |
| 250 |
CodechalDbgBufferType::bufSlcParams, |
| 251 |
CodechalDbgExtType::txt); |
| 252 |
|
| 253 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 254 |
{ |
| 255 |
MediaDebugFastDump::Dump( |
| 256 |
(uint8_t *)sliceParams, |
| 257 |
fileName, |
| 258 |
sizeof(CodecDecodeMpeg2SliceParams) * numSlices, |
| 259 |
0, |
| 260 |
MediaDebugSerializer<CodecDecodeMpeg2SliceParams>()); |
| 261 |
} |
| 262 |
else |
| 263 |
{ |
| 264 |
DumpDecodeMpeg2SliceParams(sliceParams, numSlices, fileName); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
return MOS_STATUS_SUCCESS; |
| 269 |
} |
| 270 |
|
| 271 |
MOS_STATUS Mpeg2Pipeline::DumpMbParams( |
| 272 |
CodecDecodeMpeg2MbParams *mbParams, |
| 273 |
uint32_t numMbs) |
| 274 |
{ |
| 275 |
DECODE_FUNC_CALL(); |
| 276 |
|
| 277 |
if (mbParams == nullptr) |
| 278 |
{ |
| 279 |
return MOS_STATUS_SUCCESS; |
| 280 |
} |
| 281 |
|
| 282 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrMbParams)) |
| 283 |
{ |
| 284 |
const char *fileName = m_debugInterface->CreateFileName( |
| 285 |
"_DEC", |
| 286 |
CodechalDbgBufferType::bufMbParams, |
| 287 |
CodechalDbgExtType::txt); |
| 288 |
|
| 289 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 290 |
{ |
| 291 |
MediaDebugFastDump::Dump( |
| 292 |
(uint8_t *)mbParams, |
| 293 |
fileName, |
| 294 |
sizeof(CodecDecodeMpeg2MbParams) * numMbs, |
| 295 |
0, |
| 296 |
MediaDebugSerializer<CodecDecodeMpeg2MbParams>()); |
| 297 |
} |
| 298 |
else |
| 299 |
{ |
| 300 |
DumpDecodeMpeg2MbParams(mbParams, numMbs, fileName); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
return MOS_STATUS_SUCCESS; |
| 305 |
} |
| 306 |
|
| 307 |
MOS_STATUS Mpeg2Pipeline::DumpIQParams( |
| 308 |
CodecMpeg2IqMatrix *iqParams) |
| 309 |
{ |
| 310 |
DECODE_FUNC_CALL(); |
| 311 |
|
| 312 |
if (iqParams == nullptr) |
| 313 |
{ |
| 314 |
return MOS_STATUS_SUCCESS; |
| 315 |
} |
| 316 |
|
| 317 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrIqParams)) |
| 318 |
{ |
| 319 |
const char *fileName = m_debugInterface->CreateFileName( |
| 320 |
"_DEC", |
| 321 |
CodechalDbgBufferType::bufIqParams, |
| 322 |
CodechalDbgExtType::txt); |
| 323 |
|
| 324 |
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump)) |
| 325 |
{ |
| 326 |
MediaDebugFastDump::Dump( |
| 327 |
(uint8_t *)iqParams, |
| 328 |
fileName, |
| 329 |
sizeof(CodecMpeg2IqMatrix), |
| 330 |
0, |
| 331 |
MediaDebugSerializer<CodecMpeg2IqMatrix>()); |
| 332 |
} |
| 333 |
else |
| 334 |
{ |
| 335 |
DumpDecodeMpeg2IqParams(iqParams, fileName); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
return MOS_STATUS_SUCCESS; |
| 340 |
} |
| 341 |
#endif |
| 342 |
|
| 343 |
} |