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_jpeg_picture_packet.h
24 //! \brief    Defines the implementation of jpeg decode picture packet
25 //!
26 
27 #ifndef __DECODE_JPEG_PICTURE_PACKET_H__
28 #define __DECODE_JPEG_PICTURE_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "decode_jpeg_pipeline.h"
32 #include "decode_utils.h"
33 #include "decode_jpeg_basic_feature.h"
34 #include "decode_downsampling_packet.h"
35 #include "mhw_vdbox_mfx_itf.h"
36 
37 using namespace mhw::vdbox::mfx;
38 
39 namespace decode{
40 class JpegDecodePicPkt : public DecodeSubPacket, public mhw::vdbox::mfx::Itf::ParSetting
41 {
42 public:
43     //!
44     //! \brief  JpegDecodePicPkt constructor
45     //!
JpegDecodePicPkt(JpegPipeline * pipeline,CodechalHwInterfaceNext * hwInterface)46     JpegDecodePicPkt(JpegPipeline *pipeline, CodechalHwInterfaceNext *hwInterface)
47         : DecodeSubPacket(pipeline, hwInterface), m_jpegPipeline(pipeline)
48     {
49         if (m_hwInterface != nullptr)
50         {
51             m_mfxItf = std::static_pointer_cast<mhw::vdbox::mfx::Itf>(m_hwInterface->GetMfxInterfaceNext());
52             m_miItf  = std::static_pointer_cast<mhw::mi::Itf>(hwInterface->GetMiInterfaceNext());
53         }
54     }
55 
56     //!
57     //! \brief  JpegDecodePicPkt deconstructor
58     //!
59     virtual ~JpegDecodePicPkt();
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     MOS_STATUS AddAllCmds_MFX_QM_STATE(PMOS_COMMAND_BUFFER cmdBuffer);
97     MOS_STATUS AddAllCmds_MFX_JPEG_HUFF_TABLE_STATE(PMOS_COMMAND_BUFFER cmdBuffer);
98     MOS_STATUS AddAllCmds_MFD_JPEG_BSD_OBJECT(PMOS_COMMAND_BUFFER cmdBuffer);
99 
100 protected:
101     MHW_SETPAR_DECL_HDR(MFX_PIPE_MODE_SELECT);
102     MHW_SETPAR_DECL_HDR(MFX_SURFACE_STATE);
103     MHW_SETPAR_DECL_HDR(MFX_PIPE_BUF_ADDR_STATE);
104     MHW_SETPAR_DECL_HDR(MFX_IND_OBJ_BASE_ADDR_STATE);
105     MHW_SETPAR_DECL_HDR(MFX_JPEG_PIC_STATE);
106 
107     virtual MOS_STATUS AllocateFixedResources();
108     //!
109     //! \brief  Free resources
110     //! \return MOS_STATUS
111     //!         MOS_STATUS_SUCCESS if success, else fail reason
112     //!
113     MOS_STATUS FreeResources();
114 
115     //!
116     //! \brief  Dump resources
117     //! \return MOS_STATUS
118     //!         MOS_STATUS_SUCCESS if success, else fail reason
119     //!
120     MOS_STATUS DumpResources(MHW_VDBOX_PIPE_BUF_ADDR_PARAMS& pipeBufAddrParams);
121 #ifdef _DECODE_PROCESSING_SUPPORTED
122     DecodeDownSamplingFeature *m_downSamplingFeature = nullptr;
123     DecodeDownSamplingPkt *    m_downSamplingPkt     = nullptr;
124 #endif
125     //Interfaces
126     JpegPipeline               *m_jpegPipeline     = nullptr;
127     JpegBasicFeature           *m_jpegBasicFeature = nullptr;
128     DecodeAllocator             *m_allocator         = nullptr;
129     DecodeMemComp               *m_mmcState          = nullptr;
130     std::shared_ptr<mhw::vdbox::mfx::Itf> m_mfxItf            = nullptr;
131 
132     CodecDecodeJpegPicParams   *m_jpegPicParams    = nullptr; //!< Pointer to picture parameter
133 
134     uint32_t m_pictureStatesSize           = 0;    //!< Picture states size
135     uint32_t m_picturePatchListSize        = 0;    //!< Picture patch list size
136 
137 MEDIA_CLASS_DEFINE_END(decode__JpegDecodePicPkt)
138 };
139 
140 }  // namespace decode
141 #endif
142