1 /*
2 * Copyright (c) 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 //! \file     decode_avc_slice_xe_m_base_packet.cpp
24 //! \brief    Defines the interface for avc decode slice packet
25 //!
26 #include "codechal_utilities.h"
27 #include "decode_avc_slice_xe_m_base_packet.h"
28 
29 namespace decode
30 {
Init()31     MOS_STATUS AvcDecodeSlcPktXe_M_Base::Init()
32     {
33         DECODE_FUNC_CALL();
34 
35         DECODE_CHK_NULL(m_featureManager);
36         DECODE_CHK_NULL(m_hwInterface);
37         DECODE_CHK_NULL(m_osInterface);
38         DECODE_CHK_NULL(m_miInterface);
39         DECODE_CHK_NULL(m_avcPipeline);
40         DECODE_CHK_NULL(m_mfxInterface);
41 
42         m_avcBasicFeature = dynamic_cast<AvcBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
43         DECODE_CHK_NULL(m_avcBasicFeature);
44 
45         m_allocator = m_pipeline ->GetDecodeAllocator();
46         DECODE_CHK_NULL(m_allocator);
47 
48         DECODE_CHK_STATUS(CalculateSliceStateCommandSize());
49 
50         return MOS_STATUS_SUCCESS;
51     }
52 
Prepare()53     MOS_STATUS AvcDecodeSlcPktXe_M_Base::Prepare()
54     {
55         DECODE_FUNC_CALL();
56 
57         DECODE_CHK_NULL(m_avcBasicFeature->m_avcPicParams);
58         DECODE_CHK_NULL(m_avcBasicFeature->m_avcSliceParams);
59 
60         m_avcPicParams = m_avcBasicFeature->m_avcPicParams;
61         m_avcSliceParams = m_avcBasicFeature->m_avcSliceParams;
62 
63         return MOS_STATUS_SUCCESS;
64     }
65 
SetAvcSliceStateParams(MHW_VDBOX_AVC_SLICE_STATE & avcSliceState,uint32_t slcIdx)66     MOS_STATUS AvcDecodeSlcPktXe_M_Base::SetAvcSliceStateParams(
67         MHW_VDBOX_AVC_SLICE_STATE &avcSliceState, uint32_t slcIdx)
68     {
69         DECODE_FUNC_CALL();
70 
71         MOS_ZeroMemory(&avcSliceState, sizeof(avcSliceState));
72 
73         PCODEC_AVC_SLICE_PARAMS slc = m_avcSliceParams + slcIdx;
74         uint32_t nextLength = 0;
75         uint32_t nextOffset = 0;
76 
77         if (slcIdx < m_avcBasicFeature->m_lastValidSlice)
78         {
79             nextLength = (slc + 1)->slice_data_size;
80             nextOffset = (slc + 1)->slice_data_offset;
81         }
82 
83         avcSliceState.bIntelEntrypointInUse = m_avcPipeline->m_intelEntrypointInUse;
84         avcSliceState.bPicIdRemappingInUse  = m_avcBasicFeature->m_picIdRemappingInUse;
85         avcSliceState.bShortFormatInUse     = m_avcPipeline->IsShortFormat();
86         avcSliceState.presDataBuffer        = &m_avcBasicFeature->m_resDataBuffer.OsResource;
87         avcSliceState.pAvcPicParams         = m_avcPicParams;
88         avcSliceState.pMvcExtPicParams      = m_avcBasicFeature->m_mvcExtPicParams;
89         avcSliceState.pAvcPicIdx            = &m_avcBasicFeature->m_refFrames.m_avcPicIdx[0];
90         avcSliceState.bPhantomSlice         = false;
91         avcSliceState.ucDisableDeblockingFilterIdc = slc->disable_deblocking_filter_idc;
92         avcSliceState.ucSliceBetaOffsetDiv2    = slc->slice_beta_offset_div2;
93         avcSliceState.ucSliceAlphaC0OffsetDiv2 = slc->slice_alpha_c0_offset_div2;
94         avcSliceState.pAvcSliceParams = slc;
95         avcSliceState.dwOffset        = m_avcBasicFeature->m_sliceRecord[slcIdx].offset;
96         avcSliceState.dwLength        = m_avcBasicFeature->m_sliceRecord[slcIdx].length;
97         avcSliceState.dwNextOffset    = nextOffset;
98         avcSliceState.dwNextLength    = nextLength;
99         avcSliceState.dwSliceIndex    = slcIdx;
100         avcSliceState.bLastSlice      = (slcIdx == m_avcBasicFeature->m_lastValidSlice);
101         avcSliceState.bFullFrameData  = m_avcBasicFeature->m_fullFrameData;
102 
103         if (slcIdx > 0)
104         {
105             avcSliceState.dwTotalBytesConsumed = m_avcBasicFeature->m_sliceRecord[slcIdx - 1].totalBytesConsumed;
106         }
107         else
108         {
109             avcSliceState.dwTotalBytesConsumed = 0;
110         }
111 
112         return MOS_STATUS_SUCCESS;
113     }
114 
SetAvcPhantomSliceParams(MHW_VDBOX_AVC_SLICE_STATE & avcSliceState,uint32_t slcIdx)115     MOS_STATUS AvcDecodeSlcPktXe_M_Base::SetAvcPhantomSliceParams(
116         MHW_VDBOX_AVC_SLICE_STATE &avcSliceState, uint32_t slcIdx)
117     {
118         DECODE_FUNC_CALL();
119 
120         PCODEC_AVC_SLICE_PARAMS slc = m_avcSliceParams + slcIdx;
121         MOS_ZeroMemory(&avcSliceState, sizeof(avcSliceState));
122 
123         avcSliceState.ucDisableDeblockingFilterIdc = slc->disable_deblocking_filter_idc;
124         avcSliceState.ucSliceBetaOffsetDiv2    = slc->slice_beta_offset_div2;
125         avcSliceState.ucSliceAlphaC0OffsetDiv2 = slc->slice_alpha_c0_offset_div2;
126         avcSliceState.bIntelEntrypointInUse = m_avcPipeline->m_intelEntrypointInUse;
127         avcSliceState.bPicIdRemappingInUse  = m_avcBasicFeature->m_picIdRemappingInUse;
128         avcSliceState.bShortFormatInUse     = false;
129         avcSliceState.presDataBuffer        = &m_avcBasicFeature->m_resDataBuffer.OsResource;
130         avcSliceState.pAvcPicParams         = m_avcPicParams;
131         avcSliceState.pMvcExtPicParams      = m_avcBasicFeature->m_mvcExtPicParams;
132         avcSliceState.pAvcPicIdx            = &m_avcBasicFeature->m_refFrames.m_avcPicIdx[0];
133         avcSliceState.bPhantomSlice         = true;
134         avcSliceState.dwTotalBytesConsumed  = 0;
135         avcSliceState.pAvcSliceParams       = slc;
136 
137         avcSliceState.dwOffset        = 0;
138         avcSliceState.dwLength        = slc->slice_data_offset;
139         avcSliceState.dwNextOffset    = slc->slice_data_offset;
140         avcSliceState.dwNextLength    = slc->slice_data_size;
141 
142         return MOS_STATUS_SUCCESS;
143     }
144 
SetSliceWeightOffsetParams(MHW_VDBOX_AVC_WEIGHTOFFSET_PARAMS & weightOffsetParams,uint32_t slcIdx)145     void AvcDecodeSlcPktXe_M_Base::SetSliceWeightOffsetParams(
146         MHW_VDBOX_AVC_WEIGHTOFFSET_PARAMS &weightOffsetParams,
147         uint32_t slcIdx)
148     {
149         DECODE_FUNC_CALL();
150 
151         PCODEC_AVC_SLICE_PARAMS slc = m_avcSliceParams + slcIdx;
152         MOS_ZeroMemory(&weightOffsetParams, sizeof(weightOffsetParams));
153 
154         weightOffsetParams.uiList = 0;
155         MOS_SecureMemcpy(
156             &weightOffsetParams.Weights,
157             sizeof(weightOffsetParams.Weights),
158             &slc->Weights,
159             sizeof(slc->Weights));
160     }
161 
SetSliceRefIdxParams(MHW_VDBOX_AVC_REF_IDX_PARAMS & refIdxParams,uint32_t slcIdx)162     void AvcDecodeSlcPktXe_M_Base::SetSliceRefIdxParams(
163         MHW_VDBOX_AVC_REF_IDX_PARAMS &refIdxParams,
164         uint32_t slcIdx)
165     {
166         DECODE_FUNC_CALL();
167 
168         PCODEC_AVC_SLICE_PARAMS slc = m_avcSliceParams + slcIdx;
169         MOS_ZeroMemory(&refIdxParams, sizeof(refIdxParams));
170 
171         refIdxParams.CurrPic = m_avcPicParams->CurrPic;
172         refIdxParams.uiList = LIST_0;
173         refIdxParams.uiNumRefForList[LIST_0] = slc->num_ref_idx_l0_active_minus1 + 1;
174 
175         MOS_SecureMemcpy(
176             &refIdxParams.RefPicList,
177             sizeof(refIdxParams.RefPicList),
178             &slc->RefPicList,
179             sizeof(slc->RefPicList));
180 
181         refIdxParams.pAvcPicIdx = &m_avcBasicFeature->m_refFrames.m_avcPicIdx[0];
182         refIdxParams.avcRefList = (void**)m_avcBasicFeature->m_refFrames.m_refList;
183         refIdxParams.bIntelEntrypointInUse = m_avcPipeline->m_intelEntrypointInUse;
184         refIdxParams.bPicIdRemappingInUse = m_avcBasicFeature->m_picIdRemappingInUse;
185     }
186 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)187     MOS_STATUS AvcDecodeSlcPktXe_M_Base::CalculateCommandSize(uint32_t &commandBufferSize,
188                                                       uint32_t &requestedPatchListSize)
189     {
190         DECODE_FUNC_CALL();
191 
192         commandBufferSize      = m_sliceStatesSize;
193         requestedPatchListSize = m_slicePatchListSize;
194 
195         return MOS_STATUS_SUCCESS;
196     }
197 
CalculateSliceStateCommandSize()198     MOS_STATUS AvcDecodeSlcPktXe_M_Base::CalculateSliceStateCommandSize()
199     {
200         DECODE_FUNC_CALL();
201 
202         // Slice Level Commands
203         DECODE_CHK_STATUS(static_cast<CodechalHwInterfaceG12*>(m_hwInterface)->GetMfxPrimitiveCommandsDataSize(
204                                                                     CODECHAL_DECODE_MODE_AVCVLD,
205                                                                     &m_sliceStatesSize,
206                                                                     &m_slicePatchListSize,
207                                                                     m_avcPipeline->IsShortFormat()));
208 
209         return MOS_STATUS_SUCCESS;
210     }
211 
212 }
213