| 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 |
//! |
| 24 |
//! \file decode_features.cpp |
| 25 |
//! \brief Defines the common interface for decode basic features |
| 26 |
//! \details The decode pipeline interface is further sub-divided by codec standard, |
| 27 |
//! this file is for the base interface which is shared by all codecs. |
| 28 |
//! |
| 29 |
#include "decode_basic_feature.h" |
| 30 |
#include "decode_utils.h" |
| 31 |
#include "codechal_debug.h" |
| 32 |
|
| 33 |
namespace decode { |
| 34 |
|
| 35 |
DecodeBasicFeature::DecodeBasicFeature( |
| 36 |
DecodeAllocator *allocator, |
| 37 |
void *hwInterface, |
| 38 |
PMOS_INTERFACE osInterface) : |
| 39 |
m_hwInterface(hwInterface), m_allocator(allocator), m_osInterface(osInterface) |
| 40 |
{ |
| 41 |
if (osInterface != nullptr) |
| 42 |
{ |
| 43 |
MEDIA_WA_TABLE* waTable = osInterface->pfnGetWaTable(osInterface); |
| 44 |
m_useDummyReference = (waTable != nullptr) ? MEDIA_IS_WA(waTable, WaDummyReference) : false; |
| 45 |
} |
| 46 |
|
| 47 |
MOS_ZeroMemory(&m_destSurface, sizeof(m_destSurface)); |
| 48 |
MOS_ZeroMemory(&m_resDataBuffer, sizeof(m_resDataBuffer)); |
| 49 |
MOS_ZeroMemory(&m_dummyReference, sizeof(m_dummyReference)); |
| 50 |
} |
| 51 |
|
| 52 |
DecodeBasicFeature::~DecodeBasicFeature() |
| 53 |
{ |
| 54 |
if (m_allocator != nullptr && m_dummyReferenceStatus == CODECHAL_DUMMY_REFERENCE_ALLOCATED) |
| 55 |
{ |
| 56 |
m_allocator->Destroy(m_dummyReference); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
MOS_STATUS DecodeBasicFeature::Init(void *setting) |
| 61 |
{ |
| 62 |
DECODE_FUNC_CALL(); |
| 63 |
DECODE_CHK_NULL(setting); |
| 64 |
DECODE_CHK_NULL(m_allocator); |
| 65 |
|
| 66 |
CodechalSetting *codecSettings = (CodechalSetting*)setting; |
| 67 |
m_standard = static_cast<CODECHAL_STANDARD>(codecSettings->standard); |
| 68 |
m_mode = static_cast<CODECHAL_MODE>(codecSettings->mode); |
| 69 |
m_codecFunction = codecSettings->codecFunction; |
| 70 |
|
| 71 |
m_is10Bit = (codecSettings->lumaChromaDepth & CODECHAL_LUMA_CHROMA_DEPTH_10_BITS) ? true : false; |
| 72 |
m_chromaFormat = static_cast<HCP_CHROMA_FORMAT_IDC>(codecSettings->chromaFormat); |
| 73 |
m_bitDepth = (codecSettings->lumaChromaDepth & CODECHAL_LUMA_CHROMA_DEPTH_12_BITS) ? |
| 74 |
12 : ((codecSettings->lumaChromaDepth & CODECHAL_LUMA_CHROMA_DEPTH_10_BITS) ? 10 : 8); |
| 75 |
|
| 76 |
m_width = codecSettings->width; |
| 77 |
m_height = codecSettings->height; |
| 78 |
m_picWidthInMb = (uint16_t)CODECHAL_GET_WIDTH_IN_MACROBLOCKS(m_width); |
| 79 |
m_picHeightInMb = (uint16_t)CODECHAL_GET_HEIGHT_IN_MACROBLOCKS(m_height); |
| 80 |
|
| 81 |
m_disableDecodeSyncLock = codecSettings->disableDecodeSyncLock ? true : false; |
| 82 |
|
| 83 |
m_frameNum = DecodeFrameIndex; |
| 84 |
|
| 85 |
return MOS_STATUS_SUCCESS; |
| 86 |
} |
| 87 |
|
| 88 |
MOS_STATUS DecodeBasicFeature::UpdateDestSurface(MOS_SURFACE &destSurface) |
| 89 |
{ |
| 90 |
m_destSurface = destSurface; |
| 91 |
|
| 92 |
if (m_useDummyReference) |
| 93 |
{ |
| 94 |
m_dummyReference.OsResource = m_destSurface.OsResource; |
| 95 |
m_dummyReferenceStatus = CODECHAL_DUMMY_REFERENCE_DEST_SURFACE; |
| 96 |
} |
| 97 |
|
| 98 |
return MOS_STATUS_SUCCESS; |
| 99 |
} |
| 100 |
|
| 101 |
MOS_STATUS DecodeBasicFeature::Update(void *params) |
| 102 |
{ |
| 103 |
DECODE_FUNC_CALL(); |
| 104 |
DECODE_CHK_NULL(params); |
| 105 |
|
| 106 |
CodechalDecodeParams* decodeParams = (CodechalDecodeParams*)params; |
| 107 |
|
| 108 |
m_dataSize = decodeParams->m_dataSize; // The bitstream size will be properly set by SetRequiredBitstreamSize later. |
| 109 |
m_dataOffset = decodeParams->m_dataOffset; |
| 110 |
m_numSlices = decodeParams->m_numSlices; |
| 111 |
m_refFrameSurface = decodeParams->m_refFrameSurface; |
| 112 |
m_refSurfaceNum = decodeParams->m_refSurfaceNum; |
| 113 |
|
| 114 |
DECODE_CHK_NULL(decodeParams->m_dataBuffer); |
| 115 |
m_resDataBuffer.OsResource = *(decodeParams->m_dataBuffer); |
| 116 |
DECODE_CHK_STATUS(m_allocator->UpdateResoreceUsageType(&m_resDataBuffer.OsResource, resourceInputBitstream)); |
| 117 |
|
| 118 |
if (decodeParams->m_destSurface != nullptr) |
| 119 |
{ |
| 120 |
DECODE_CHK_STATUS(UpdateDestSurface(*decodeParams->m_destSurface)); |
| 121 |
DECODE_CHK_STATUS(m_allocator->UpdateResoreceUsageType(&m_destSurface.OsResource, resourceOutputPicture)); |
| 122 |
DECODE_CHK_STATUS(m_allocator->GetSurfaceInfo(&m_destSurface)); |
| 123 |
} |
| 124 |
else |
| 125 |
{ |
| 126 |
m_destSurface.dwPitch = 0; |
| 127 |
m_destSurface.dwWidth = 0; |
| 128 |
m_destSurface.dwHeight = 0; |
| 129 |
m_destSurface.dwSize = 0; |
| 130 |
} |
| 131 |
|
| 132 |
return MOS_STATUS_SUCCESS; |
| 133 |
} |
| 134 |
|
| 135 |
} |