1 /*
2 * Copyright (c) 2021-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_slice_packet.cpp
24 //! \brief    Defines the interface for vp8 decode slice packet
25 //!
26 #include "decode_vp8_slice_packet.h"
27 
28 namespace decode
29 {
Init()30     MOS_STATUS Vp8DecodeSlcPkt::Init()
31     {
32         DECODE_FUNC_CALL();
33 
34         m_vp8BasicFeature = dynamic_cast<Vp8BasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
35         m_allocator = m_pipeline ->GetDecodeAllocator();
36         m_decodecp = m_pipeline->GetDecodeCp();
37 
38         DECODE_CHK_NULL(m_featureManager);
39         DECODE_CHK_NULL(m_hwInterface);
40         DECODE_CHK_NULL(m_osInterface);
41         DECODE_CHK_NULL(m_miItf);
42         DECODE_CHK_NULL(m_vp8Pipeline);
43         DECODE_CHK_NULL(m_mfxItf);
44         DECODE_CHK_NULL(m_vp8BasicFeature);
45         DECODE_CHK_NULL(m_allocator);
46         DECODE_CHK_STATUS(CalculateSliceStateCommandSize());
47 
48         return MOS_STATUS_SUCCESS;
49     }
50 
Prepare()51     MOS_STATUS Vp8DecodeSlcPkt::Prepare()
52     {
53         DECODE_FUNC_CALL();
54 
55         DECODE_CHK_NULL(m_vp8BasicFeature->m_vp8PicParams);
56 
57         m_vp8PicParams = m_vp8BasicFeature->m_vp8PicParams;
58         m_vp8SliceParams = m_vp8BasicFeature->m_vp8SliceParams;
59 
60         return MOS_STATUS_SUCCESS;
61     }
62 
MHW_SETPAR_DECL_SRC(MFD_VP8_BSD_OBJECT,Vp8DecodeSlcPkt)63     MHW_SETPAR_DECL_SRC(MFD_VP8_BSD_OBJECT, Vp8DecodeSlcPkt){
64 
65         uint8_t numPartitions = (1 << m_vp8PicParams->CodedCoeffTokenPartition);
66 
67         params.CodedNumOfCoeffTokenPartitions = m_vp8PicParams->CodedCoeffTokenPartition;
68         params.Partition0CpbacEntropyRange = m_vp8PicParams->uiP0EntropyRange;
69         params.Partition0CpbacEntropyCount = m_vp8PicParams->ucP0EntropyCount;
70         params.Partition0CpbacEntropyValue = m_vp8PicParams->ucP0EntropyValue;
71 
72         params.IndirectPartition0DataLength = m_vp8PicParams->uiPartitionSize[0] + 1;
73         params.IndirectPartition0DataStartOffset = m_vp8PicParams->uiFirstMbByteOffset;
74 
75         params.IndirectPartition1DataLength = m_vp8PicParams->uiPartitionSize[1] + 1;
76         params.IndirectPartition1DataStartOffset = params.IndirectPartition0DataStartOffset +
77             m_vp8PicParams->uiPartitionSize[0] +
78             (numPartitions - 1) * 3;      // Account for P Sizes: 3 bytes per partition
79                                             // excluding partition 0 and last partition.
80 
81         int32_t i = 2;
82         if (i < ((1 + numPartitions)))
83         {
84             params.IndirectPartition2DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
85             params.IndirectPartition2DataStartOffset = params.IndirectPartition1DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
86         }
87 
88         i = 3;
89         if (i < ((1 + numPartitions)))
90         {
91             params.IndirectPartition3DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
92             params.IndirectPartition3DataStartOffset = params.IndirectPartition2DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
93         }
94 
95         i = 4;
96         if (i < ((1 + numPartitions)))
97         {
98             params.IndirectPartition4DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
99             params.IndirectPartition4DataStartOffset = params.IndirectPartition3DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
100         }
101 
102         i = 5;
103         if (i < ((1 + numPartitions)))
104         {
105             params.IndirectPartition5DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
106             params.IndirectPartition5DataStartOffset = params.IndirectPartition4DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
107         }
108 
109         i = 6;
110         if (i < ((1 + numPartitions)))
111         {
112             params.IndirectPartition6DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
113             params.IndirectPartition6DataStartOffset = params.IndirectPartition5DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
114         }
115 
116         i = 7;
117         if (i < ((1 + numPartitions)))
118         {
119             params.IndirectPartition7DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
120             params.IndirectPartition7DataStartOffset = params.IndirectPartition6DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
121         }
122 
123         i = 8;
124         if (i < ((1 + numPartitions)))
125         {
126             params.IndirectPartition8DataLength = m_vp8PicParams->uiPartitionSize[i] + 1;
127             params.IndirectPartition8DataStartOffset = params.IndirectPartition7DataStartOffset + m_vp8PicParams->uiPartitionSize[i - 1];
128         }
129 
130         return MOS_STATUS_SUCCESS;
131     }
132 
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)133     MOS_STATUS Vp8DecodeSlcPkt::CalculateCommandSize(uint32_t &commandBufferSize,
134                                                       uint32_t &requestedPatchListSize)
135     {
136         DECODE_FUNC_CALL();
137 
138         commandBufferSize      = m_sliceStatesSize;
139         requestedPatchListSize = m_slicePatchListSize;
140 
141         return MOS_STATUS_SUCCESS;
142     }
143 
144 
AddMiFlushDwCmd(MOS_COMMAND_BUFFER & cmdBuffer)145     MOS_STATUS Vp8DecodeSlcPkt::AddMiFlushDwCmd(MOS_COMMAND_BUFFER &cmdBuffer)
146     {
147         DECODE_FUNC_CALL();
148 
149         auto &par = m_miItf->GETPAR_MI_FLUSH_DW();
150         MOS_ZeroMemory(&par, sizeof(par));
151         DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_FLUSH_DW(&cmdBuffer));
152 
153         return MOS_STATUS_SUCCESS;
154     }
155 
AddMiBatchBufferEnd(MOS_COMMAND_BUFFER & cmdBuffer)156     MOS_STATUS Vp8DecodeSlcPkt::AddMiBatchBufferEnd(MOS_COMMAND_BUFFER &cmdBuffer)
157     {
158         DECODE_FUNC_CALL();
159 
160         DECODE_CHK_STATUS(m_miItf->ADDCMD_MI_BATCH_BUFFER_END(&cmdBuffer, nullptr));
161 
162         return MOS_STATUS_SUCCESS;
163     }
164 
165 
166 
CalculateSliceStateCommandSize()167     MOS_STATUS Vp8DecodeSlcPkt::CalculateSliceStateCommandSize()
168     {
169         DECODE_FUNC_CALL();
170 
171         // Slice Level Commands
172         DECODE_CHK_STATUS(m_hwInterface->GetMfxPrimitiveCommandsDataSize(
173             m_vp8BasicFeature->m_mode,
174             &m_sliceStatesSize,
175             &m_slicePatchListSize,
176             m_vp8BasicFeature->m_shortFormatInUse));
177 
178         return MOS_STATUS_SUCCESS;
179     }
180 
181 }
182