1 /*
2 * Copyright (c) 2020-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_vp8_pipeline.cpp
24 //! \brief    Defines the interface for vp8 decode pipeline
25 //!
26 #include "decode_vp8_pipeline.h"
27 #include "decode_utils.h"
28 #include "codechal_setting.h"
29 #include "decode_vp8_feature_manager.h"
30 #include "media_debug_fast_dump.h"
31 
32 namespace decode
33 {
Vp8Pipeline(CodechalHwInterfaceNext * hwInterface,CodechalDebugInterface * debugInterface)34 Vp8Pipeline::Vp8Pipeline(
35     CodechalHwInterfaceNext *   hwInterface,
36     CodechalDebugInterface  *debugInterface)
37     : DecodePipeline(hwInterface, debugInterface)
38 {
39     MOS_STATUS m_status = InitUserSetting(m_userSettingPtr);
40 }
41 
Initialize(void * settings)42 MOS_STATUS Vp8Pipeline::Initialize(void *settings)
43 {
44     DECODE_FUNC_CALL();
45     DECODE_CHK_STATUS(DecodePipeline::Initialize(settings));
46 
47     // Create basic GPU context
48     DecodeScalabilityPars scalPars;
49     MOS_ZeroMemory(&scalPars, sizeof(scalPars));
50     DECODE_CHK_STATUS(m_mediaContext->SwitchContext(VdboxDecodeFunc, &scalPars, &m_scalability));
51     m_decodeContext = m_osInterface->pfnGetGpuContext(m_osInterface);
52     m_decodeContextHandle = m_osInterface->CurrentGpuContextHandle;
53 
54     m_basicFeature = dynamic_cast<Vp8BasicFeature *>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
55     DECODE_CHK_NULL(m_basicFeature);
56 
57     auto *codecSettings = (CodechalSetting *)settings;
58     DECODE_CHK_NULL(codecSettings);
59 
60     return MOS_STATUS_SUCCESS;
61 }
62 
Prepare(void * params)63 MOS_STATUS Vp8Pipeline::Prepare(void *params)
64 {
65     DECODE_FUNC_CALL();
66     DECODE_CHK_NULL(params);
67 
68     DECODE_CHK_STATUS(DecodePipeline::Prepare(params));
69 
70     return MOS_STATUS_SUCCESS;
71 }
72 
Uninitialize()73 MOS_STATUS Vp8Pipeline::Uninitialize()
74 {
75     DECODE_FUNC_CALL();
76 
77     return DecodePipeline::Uninitialize();
78 }
79 
UserFeatureReport()80 MOS_STATUS Vp8Pipeline::UserFeatureReport()
81 {
82     DECODE_FUNC_CALL();
83     DECODE_CHK_STATUS(DecodePipeline::UserFeatureReport());
84 #if (_DEBUG || _RELEASE_INTERNAL)
85     WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_APOGEIOS_VP8D_ENABLE_ID, 1, m_osInterface->pOsContext);
86 #endif
87 
88 #ifdef _MMC_SUPPORTED
89     CODECHAL_DEBUG_TOOL(
90         if (m_mmcState != nullptr) {
91             m_mmcState->UpdateUserFeatureKey(&(m_basicFeature->m_destSurface));
92         })
93 #endif
94     return MOS_STATUS_SUCCESS;
95 }
96 
Execute()97 MOS_STATUS Vp8Pipeline::Execute()
98 {
99     DECODE_FUNC_CALL();
100 
101     bool immediateSubmit = false;
102     DECODE_CHK_STATUS(ActivatePacket(DecodePacketId(this, vp8DecodePacketId), immediateSubmit, 0, 0));
103     DECODE_CHK_STATUS(ExecuteActivePackets());
104     return MOS_STATUS_SUCCESS;
105 }
106 
CreateFeatureManager()107 MOS_STATUS Vp8Pipeline::CreateFeatureManager()
108 {
109     DECODE_FUNC_CALL();
110     m_featureManager = MOS_New(DecodeVp8FeatureManager, m_allocator, m_hwInterface, m_osInterface);
111     DECODE_CHK_NULL(m_featureManager);
112     return MOS_STATUS_SUCCESS;
113 }
114 
CreateSubPackets(DecodeSubPacketManager & subPacketManager,CodechalSetting & codecSettings)115 MOS_STATUS Vp8Pipeline::CreateSubPackets(DecodeSubPacketManager &subPacketManager, CodechalSetting &codecSettings)
116 {
117     DECODE_FUNC_CALL();
118 
119     DECODE_CHK_STATUS(DecodePipeline::CreateSubPackets(subPacketManager, codecSettings));
120 
121     return MOS_STATUS_SUCCESS;
122 }
123 
GetDecodeMode()124 Vp8Pipeline::Vp8DecodeMode Vp8Pipeline::GetDecodeMode()
125 {
126     return m_decodeMode;
127 }
128 
129 #if USE_CODECHAL_DEBUG_TOOL
DumpPicParams(PCODEC_VP8_PIC_PARAMS picParams)130 MOS_STATUS Vp8Pipeline::DumpPicParams(PCODEC_VP8_PIC_PARAMS 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(CODEC_VP8_PIC_PARAMS),
152                 0,
153                 MediaDebugSerializer<CODEC_VP8_PIC_PARAMS>());
154         }
155         else
156         {
157             DumpDecodeVp8PicParams(picParams, fileName);
158         }
159     }
160 
161     return MOS_STATUS_SUCCESS;
162 }
163 
DumpSliceParams(PCODEC_VP8_SLICE_PARAMS sliceParams)164 MOS_STATUS Vp8Pipeline::DumpSliceParams(PCODEC_VP8_SLICE_PARAMS sliceParams)
165 {
166     DECODE_FUNC_CALL();
167 
168     if (sliceParams == nullptr)
169     {
170         return MOS_STATUS_SUCCESS;
171     }
172 
173     if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSlcParams))
174     {
175         const char *fileName = m_debugInterface->CreateFileName(
176             "_DEC",
177             CodechalDbgBufferType::bufSlcParams,
178             CodechalDbgExtType::txt);
179 
180         if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump))
181         {
182             MediaDebugFastDump::Dump(
183                 (uint8_t *)sliceParams,
184                 fileName,
185                 sizeof(CODEC_VP8_SLICE_PARAMS),
186                 0,
187                 MediaDebugSerializer<CODEC_VP8_SLICE_PARAMS>());
188         }
189         else
190         {
191             DumpDecodeVp8SliceParams(sliceParams, fileName);
192         }
193     }
194 
195     return MOS_STATUS_SUCCESS;
196 }
197 
DumpIQParams(PCODEC_VP8_IQ_MATRIX_PARAMS iqParams)198 MOS_STATUS Vp8Pipeline::DumpIQParams(PCODEC_VP8_IQ_MATRIX_PARAMS iqParams)
199 {
200     DECODE_FUNC_CALL();
201 
202     if (iqParams == nullptr)
203     {
204         return MOS_STATUS_SUCCESS;
205     }
206 
207     if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrIqParams))
208     {
209         const char *fileName = m_debugInterface->CreateFileName(
210             "_DEC",
211             CodechalDbgBufferType::bufIqParams,
212             CodechalDbgExtType::txt);
213 
214         if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrEnableFastDump))
215         {
216             MediaDebugFastDump::Dump(
217                 (uint8_t *)iqParams,
218                 fileName,
219                 sizeof(CODEC_VP8_IQ_MATRIX_PARAMS),
220                 0,
221                 MediaDebugSerializer<CODEC_VP8_IQ_MATRIX_PARAMS>());
222         }
223         else
224         {
225             DumpDecodeVp8IqParams(iqParams, fileName);
226         }
227     }
228 
229     return MOS_STATUS_SUCCESS;
230 }
231 
DumpCoefProbBuffer(PMOS_RESOURCE m_resCoefProbBuffer)232 MOS_STATUS Vp8Pipeline::DumpCoefProbBuffer(PMOS_RESOURCE m_resCoefProbBuffer)
233 {
234     DECODE_FUNC_CALL();
235 
236     if (m_resCoefProbBuffer == nullptr)
237     {
238         return MOS_STATUS_SUCCESS;
239     }
240 
241     if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrCoefProb))
242     {
243         DECODE_CHK_STATUS(m_debugInterface->DumpBuffer(
244             m_resCoefProbBuffer,
245             CodechalDbgAttr::attrCoefProb,
246             "_DEC_CoefProb",
247             m_basicFeature->m_coefProbSize));
248     }
249 
250     return MOS_STATUS_SUCCESS;
251 }
252 #endif
253 
254 }  // namespace decode
255