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_mpeg2_picture_packet.h
24 //! \brief    Defines the implementation of mpeg2 decode picture packet
25 //!
26 
27 #ifndef __DECODE_MPEG2_PICTURE_PACKET_H__
28 #define __DECODE_MPEG2_PICTURE_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "decode_mpeg2_pipeline.h"
32 #include "decode_utils.h"
33 #include "decode_mpeg2_basic_feature.h"
34 #include "mhw_vdbox_mfx_itf.h"
35 
36 using namespace mhw::vdbox::mfx;
37 
38 namespace decode{
39 
40 class Mpeg2DecodePicPkt : public DecodeSubPacket, public Itf::ParSetting
41 {
42 public:
43     //!
44     //! \brief  Mpeg2DecodePicPkt constructor
45     //!
Mpeg2DecodePicPkt(Mpeg2Pipeline * pipeline,CodechalHwInterfaceNext * hwInterface)46     Mpeg2DecodePicPkt(Mpeg2Pipeline *pipeline, CodechalHwInterfaceNext *hwInterface)
47         : DecodeSubPacket(pipeline, hwInterface), m_mpeg2Pipeline(pipeline)
48     {
49         if (m_hwInterface != nullptr)
50         {
51             m_mfxItf = std::static_pointer_cast<Itf>(m_hwInterface->GetMfxInterfaceNext());
52             m_miItf        = std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext());
53         }
54     }
55 
56     //!
57     //! \brief  Mpeg2DecodePicPkt deconstructor
58     //!
59     virtual ~Mpeg2DecodePicPkt();
60 
61     //!
62     //! \brief  Initialize the media packet, allocate required resources
63     //! \return MOS_STATUS
64     //!         MOS_STATUS_SUCCESS if success, else fail reason
65     //!
66     virtual MOS_STATUS Init() override;
67 
68     //!
69     //! \brief  Prepare interal parameters, should be invoked for each frame
70     //! \return MOS_STATUS
71     //!         MOS_STATUS_SUCCESS if success, else fail reason
72     //!
73     virtual MOS_STATUS Prepare() override;
74 
75     //!
76     //! \brief  Execute av1 picture packet
77     //! \return MOS_STATUS
78     //!         MOS_STATUS_SUCCESS if success, else fail reason
79     //!
80     virtual MOS_STATUS Execute(MOS_COMMAND_BUFFER& cmdBuffer) = 0;
81 
82     //!
83     //! \brief  Calculate Command Size
84     //!
85     //! \param  [in, out] commandBufferSize
86     //!         requested size
87     //! \param  [in, out] requestedPatchListSize
88     //!         requested size
89     //! \return MOS_STATUS
90     //!         status
91     //!
92     MOS_STATUS CalculateCommandSize(
93         uint32_t &commandBufferSize,
94         uint32_t &requestedPatchListSize) override;
95 
96 protected:
97     virtual MOS_STATUS AllocateFixedResources();
98 
99     MOS_STATUS FixMfxPipeBufAddrParams() const;
100     MOS_STATUS AddAllCmds_MFX_PIPE_MODE_SELECT(MOS_COMMAND_BUFFER &cmdBuffer);
101     MOS_STATUS AddAllCmds_MFX_QM_STATE(MOS_COMMAND_BUFFER &cmdBuffer);
102 
103     MHW_SETPAR_DECL_HDR(MFX_PIPE_MODE_SELECT);
104     MHW_SETPAR_DECL_HDR(MFX_SURFACE_STATE);
105     MHW_SETPAR_DECL_HDR(MFX_PIPE_BUF_ADDR_STATE);
106     MHW_SETPAR_DECL_HDR(MFX_IND_OBJ_BASE_ADDR_STATE);
107     MHW_SETPAR_DECL_HDR(MFX_BSP_BUF_BASE_ADDR_STATE);
108     MHW_SETPAR_DECL_HDR(MFX_MPEG2_PIC_STATE);
109 
110     //!
111     //! \brief  Free resources
112     //! \return MOS_STATUS
113     //!         MOS_STATUS_SUCCESS if success, else fail reason
114     //!
115     MOS_STATUS FreeResources();
116 
117     //!
118     //! \brief  Dump resources
119     //! \return MOS_STATUS
120     //!         MOS_STATUS_SUCCESS if success, else fail reason
121     //!
122     MOS_STATUS DumpResources(MFX_PIPE_BUF_ADDR_STATE_PAR &pipeBufAddrParams) const;
123 
124     //Interfaces
125     Mpeg2Pipeline               *m_mpeg2Pipeline     = nullptr;
126     Mpeg2BasicFeature           *m_mpeg2BasicFeature = nullptr;
127     DecodeAllocator             *m_allocator         = nullptr;
128     DecodeMemComp               *m_mmcState          = nullptr;
129     std::shared_ptr<Itf>         m_mfxItf            = nullptr;
130 
131     CodecDecodeMpeg2PicParams   *m_mpeg2PicParams    = nullptr; //!< Pointer to picture parameter
132 
133     PMOS_BUFFER                 m_resMfdDeblockingFilterRowStoreScratchBuffer = nullptr; //!< Handle of MFD Deblocking Filter Row Store Scratch data surface
134     PMOS_BUFFER                 m_resBsdMpcRowStoreScratchBuffer = nullptr;              //!< Handle of MPR Row Store Scratch data surface
135 
136     uint32_t m_pictureStatesSize           = 0;    //!< Picture states size
137     uint32_t m_picturePatchListSize        = 0;    //!< Picture patch list size
138 
139 private:
140     //!
141     //! \enum  DecodeRefAddrIndex
142     //! \brief Reference address indexes
143     //!
144     enum DecodeRefAddrIndex
145     {
146         // MPEG2 reference address indexes
147         CodechalDecodeFwdRefTop     = 0,    //!< forward reference top field
148         CodechalDecodeBwdRefTop     = 1,    //!< backward reference top field
149         CodechalDecodeFwdRefBottom  = 2,    //!< forward reference bottom field
150         CodechalDecodeBwdRefBottom  = 3,    //!< backward reference bottom field
151     };
152 
153     //!
154     //! \enum     Mpeg2Vc1PictureStructure
155     //! \brief    MPEG2 VC1 picture structure
156     //!
157     enum Mpeg2Vc1PictureStructure
158     {
159         mpeg2Vc1TopField = 1,
160         mpeg2Vc1BottomField,
161         mpeg2Vc1Frame
162     };
163 
164 MEDIA_CLASS_DEFINE_END(decode__Mpeg2DecodePicPkt)
165 };
166 
167 }  // namespace decode
168 #endif
169