1 /*
2 * Copyright (c) 2020, 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     encode_packet_utilities.h
24 //! \brief    Defines encode packrt utilities.
25 //!
26 
27 #ifndef __ENCODE_PACKET_UTILITIES_H__
28 #define __ENCODE_PACKET_UTILITIES_H__
29 
30 #include "mhw_mi.h"
31 #include "mos_util_debug.h"
32 #include "encode_utils.h"
33 #include "codec_hw_next.h"
34 #include "codechal_debug.h"
35 #include "encode_basic_feature.h"
36 #include "mhw_vdbox.h"
37 
38 namespace encode
39 {
40 class PacketUtilities
41 {
42 public:
43     PacketUtilities(CodechalHwInterfaceNext *hwInterface, MediaFeatureManager *featureManager);
44 
45     ~PacketUtilities();
46 
47     MOS_STATUS AddMemCopyCmd(PMOS_COMMAND_BUFFER cmdBuf, PMOS_RESOURCE pDst, PMOS_RESOURCE pSrc, uint32_t size);
48     MOS_STATUS AddStoreDataImmCmd(PMOS_COMMAND_BUFFER cmdBuf, PMOS_RESOURCE pSrc, uint32_t offset, uint32_t flag);
49 
50     MOS_STATUS Init();
51 
52     MOS_STATUS SendMarkerCommand(PMOS_COMMAND_BUFFER cmdBuffer, PMOS_RESOURCE presSetMarker);
53 
54     MOS_STATUS SendPredicationCommand(PMOS_COMMAND_BUFFER cmdBuffer);
55 
56 #if USE_CODECHAL_DEBUG_TOOL
57     //!
58     //! \brief  Modify the frame size with fake header size
59     //!
60     //! \param  [in] cmdBuffer
61     //!         command buffer
62     //! \param  [in] fakeHeaderSizeInByte
63     //!         fake header size in bytes
64     //! \param  [in] resBrcUpdateCurbe
65     //!         Curebe/Dmem for brcupdate kernel
66     //! \param  [in] targetSizePos
67     //!         offset of targetSize in resBrcUpdateCurbe
68     //! \param  [in] resPakStat
69     //!         Pak stastics
70     //! \param  [in] slcHrdSizePos
71     //!         offset of slcHrdSizePos in resPakStat
72     //!
73     //! \return MOS_STATUS
74     //!           MOS_STATUS_SUCCESS if success, else fail reason
75     //!
76     MOS_STATUS ModifyEncodedFrameSizeWithFakeHeaderSize(
77         PMOS_COMMAND_BUFFER     cmdBuffer,
78         uint32_t                fakeHeaderSizeInByte,
79         PMOS_RESOURCE           resBrcUpdateCurbe,
80         uint32_t                targetSizePos,
81         PMOS_RESOURCE           resPakStat,
82         uint32_t                slcHrdSizePos);
83 
84     //!
85     //! \brief  Modify the frame size with fake header size for AVC
86     //!
87     //! \param  [in] cmdBuffer
88     //!         command buffer
89     //! \param  [in] fakeHeaderSizeInByte
90     //!         fake header size in bytes
91     //! \param  [in] resBrcUpdateCurbe
92     //!         Curebe/Dmem for brcupdate kernel
93     //! \param  [in] targetSizePos
94     //!         offset of targetSize in resBrcUpdateCurbe
95     //! \param  [in] resPakStat
96     //!         Pak stastics
97     //! \param  [in] slcHrdSizePos
98     //!         offset of slcHrdSizePos in resPakStat
99     //!
100     //! \return MOS_STATUS
101     //!           MOS_STATUS_SUCCESS if success, else fail reason
102     //!
103     MOS_STATUS ModifyEncodedFrameSizeWithFakeHeaderSizeAVC(
104         PMOS_COMMAND_BUFFER cmdBuffer,
105         uint32_t            fakeHeaderSizeInByte,
106         PMOS_RESOURCE       *resBrcUpdateCurbe,
107         uint32_t            targetSizePos,
108         PMOS_RESOURCE       resPakStat,
109         uint32_t            slcHrdSizePos);
110 
111     //!
112     //! \brief  Add/Subtract a value to specified gfx memory
113     //!
114     //! \param  [in] cmdBuffer
115     //!         command buffer
116     //! \param  [in] presStoreBuffer
117     //!         buffer to modify
118     //! \param  [in] offset
119     //!         member offset in the buffer
120     //! \param  [in] value
121     //!         value to add/subtract
122     //! \param  [in] bAdd
123     //!         add or subtract
124     //!
125     //! \return MOS_STATUS
126     //!           MOS_STATUS_SUCCESS if success, else fail reason
127     //!
128     MOS_STATUS AddBufferWithIMMValue(
129         PMOS_COMMAND_BUFFER     cmdBuffer,
130         PMOS_RESOURCE           presStoreBuffer,
131         uint32_t                offset,
132         uint32_t                value,
133         bool                    bAdd);
134 
135     //!
136     //! \brief  Set a 16 bit value to specified gfx memory dword
137     //!
138     //! \param  [in] cmdBuffer
139     //!         command buffer
140     //! \param  [in] presStoreBuffer
141     //!         buffer to modify
142     //! \param  [in] offset
143     //!         member offset in the buffer
144     //! \param  [in] value
145     //!         value to set
146     //! \param  [in] bSecond
147     //!         second or first word in dword
148     //!
149     //! \return MOS_STATUS
150     //!         MOS_STATUS_SUCCESS if success, else fail reason
151     //!
152     MOS_STATUS SetBufferWithIMMValueU16(
153         PMOS_COMMAND_BUFFER cmdBuffer,
154         PMOS_RESOURCE       presStoreBuffer,
155         uint32_t            offset,
156         uint32_t            value,
157         bool                bSecond);
158 
159     bool GetFakeHeaderSettings(uint32_t &fakeHeaderSizeInByte, bool isIframe);
160 #endif
161 
162 protected:
163     MediaFeatureManager          *m_featureManager = nullptr;
164     CodechalHwInterfaceNext      *m_hwInterface    = nullptr;
165     std::shared_ptr<mhw::mi::Itf> m_miItf          = nullptr;
166     MHW_VDBOX_NODE_IND            m_vdboxIndex     = MHW_VDBOX_NODE_1;
167     MediaUserSettingSharedPtr     m_userSettingPtr = nullptr;
168 
169 #if USE_CODECHAL_DEBUG_TOOL
170     bool    m_enableFakeHrdSize     = false;
171     int32_t m_fakeIFrameHrdSize     = 0;
172     int32_t m_fakePBFrameHrdSize    = 0;
173 #endif
174 
175 MEDIA_CLASS_DEFINE_END(encode__PacketUtilities)
176 };
177 
178 }  // namespace encode
179 #endif
180