1 /*
2 * Copyright (c) 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_hevc_slice_packet.h
24 //! \brief    Defines the implementation of hevc decode slice packet
25 //!
26 
27 #ifndef __DECODE_HEVC_SLICE_PACKET_H__
28 #define __DECODE_HEVC_SLICE_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "decode_hevc_pipeline.h"
32 #include "decode_utils.h"
33 #include "decode_hevc_basic_feature.h"
34 #include "mhw_vdbox_hcp_itf.h"
35 
36 namespace decode
37 {
38 
39 class HevcDecodeSlcPkt : public DecodeSubPacket, public mhw::vdbox::hcp::Itf::ParSetting
40 {
41 public:
HevcDecodeSlcPkt(HevcPipeline * pipeline,CodechalHwInterfaceNext * hwInterface)42     HevcDecodeSlcPkt(HevcPipeline *pipeline, CodechalHwInterfaceNext*hwInterface)
43         : DecodeSubPacket(pipeline, hwInterface), m_hevcPipeline(pipeline)
44     {
45         if (m_hwInterface != nullptr)
46         {
47             m_hcpItf = std::static_pointer_cast<mhw::vdbox::hcp::Itf>(m_hwInterface->GetHcpInterfaceNext());
48             m_miItf  = std::static_pointer_cast<mhw::mi::Itf>(m_hwInterface->GetMiInterfaceNext());
49         }
50     }
51     virtual ~HevcDecodeSlcPkt();
52 
53     //!
54     //! \brief  Initialize the media packet, allocate required resources
55     //! \return MOS_STATUS
56     //!         MOS_STATUS_SUCCESS if success, else fail reason
57     //!
58     virtual MOS_STATUS Init() override;
59 
60     //!
61     //! \brief  Prepare interal parameters, should be invoked for each frame
62     //! \return MOS_STATUS
63     //!         MOS_STATUS_SUCCESS if success, else fail reason
64     //!
65     virtual MOS_STATUS Prepare() override;
66 
67     //!
68     //! \brief  Execute hevc slice packet
69     //! \return MOS_STATUS
70     //!         MOS_STATUS_SUCCESS if success, else fail reason
71     //!
72     virtual MOS_STATUS Execute(MOS_COMMAND_BUFFER& cmdBuffer, uint32_t sliceIdx, uint32_t subTileIdx) = 0;
73 
74     //!
75     //! \brief  Calculate Command Size
76     //!
77     //! \param  [in, out] commandBufferSize
78     //!         requested size
79     //! \param  [in, out] requestedPatchListSize
80     //!         requested size
81     //! \return MOS_STATUS
82     //!         status
83     //!
84     MOS_STATUS CalculateCommandSize(
85         uint32_t &commandBufferSize,
86         uint32_t &requestedPatchListSize) override;
87 
88 protected:
89     virtual MOS_STATUS ValidateSubTileIdx(const HevcTileCoding::SliceTileInfo &sliceTileInfo, uint32_t subTileIdx);
90     MOS_STATUS AddHcpCpState(MOS_COMMAND_BUFFER &cmdBuffer, uint32_t sliceIdx, uint32_t subTileIdx);
91 
92     //!
93     //! \brief  Calculate slcie level command Buffer Size
94     //!
95     //! \return uint32_t
96     //!         Command buffer size calculated
97     //!
98     virtual MOS_STATUS CalculateSliceStateCommandSize();
99 
100     virtual MOS_STATUS AddCmd_HCP_PALETTE_INITIALIZER_STATE(MOS_COMMAND_BUFFER &cmdBuffer, uint32_t sliceIdx);
101     virtual MOS_STATUS SET_HCP_SLICE_STATE(uint32_t sliceIdx, uint32_t subTileIdx);
102     virtual MOS_STATUS SET_HCP_REF_IDX_STATE(uint32_t sliceIdx);
103     virtual MOS_STATUS SET_HCP_WEIGHTOFFSET_STATE(uint32_t sliceIdx);
104     virtual MOS_STATUS AddCmd_HCP_WEIGHTOFFSET_STATE(MOS_COMMAND_BUFFER &cmdBuffer, uint32_t sliceIdx);
105     virtual MOS_STATUS SET_HCP_BSD_OBJECT(uint32_t sliceIdx, uint32_t subTileIdx);
106     virtual MOS_STATUS AddCmd_HCP_BSD_OBJECT(MOS_COMMAND_BUFFER &cmdBuffer, uint32_t sliceIdx, uint32_t subTileIdx);
107 
108     HevcPipeline                         *m_hevcPipeline     = nullptr;
109     std::shared_ptr<mhw::vdbox::hcp::Itf> m_hcpItf           = nullptr;
110     HevcBasicFeature                     *m_hevcBasicFeature = nullptr;
111     DecodeAllocator                      *m_allocator        = nullptr;
112 
113     // Parameters passed from application
114     PCODEC_HEVC_PIC_PARAMS       m_hevcPicParams       = nullptr;  //!< Pointer to picture parameter
115     PCODEC_HEVC_SLICE_PARAMS     m_hevcSliceParams     = nullptr;  //!< Pointer to slice parameter
116     PCODEC_HEVC_EXT_PIC_PARAMS   m_hevcRextPicParams   = nullptr;  //!< Extended pic params for Rext
117     PCODEC_HEVC_EXT_SLICE_PARAMS m_hevcRextSliceParams = nullptr;  //!< Extended slice params for Rext
118     PCODEC_HEVC_SCC_PIC_PARAMS   m_hevcSccPicParams    = nullptr;  //!< Pic params for SCC
119 
120     uint32_t              m_sliceStatesSize    = 0;  //!< Slice state command size
121     uint32_t              m_slicePatchListSize = 0;  //!< Slice patch list size
122     static const uint32_t m_HevcSccPaletteSize = 96; //!< For HEVC SCC palette size on Gen12+
123 
124     //! \brief SLICE_TYPE
125     //! \details
126     //!  In VDENC mode, for HEVC standard this field can be 0 or 2 only.
127     enum SLICE_TYPE
128     {
129         SLICE_TYPE_B_SLICE         = 0,  //!< No additional details
130         SLICE_TYPE_P_SLICE         = 1,  //!< No additional details
131         SLICE_TYPE_I_SLICE         = 2,  //!< No additional details
132         SLICE_TYPE_ILLEGALRESERVED = 3,  //!< No additional details
133     };
134 
135 MEDIA_CLASS_DEFINE_END(decode__HevcDecodeSlcPkt)
136 };
137 
138 } // namespace decode
139 #endif
140