1 /*
2 * Copyright (c) 2018-2021, 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_avc_packet.h
24 //! \brief    Defines the interface for avc decode packet.
25 //!
26 
27 #ifndef __DECODE_AVC_PACKET_H__
28 #define __DECODE_AVC_PACKET_H__
29 
30 #include "media_cmd_packet.h"
31 #include "codec_hw_next.h"
32 #include "decode_vdbox_mfx_common.h"
33 #include "decode_avc_basic_feature.h"
34 #include "decode_avc_pipeline.h"
35 #include "decode_utils.h"
36 #include "decode_avc_picture_packet.h"
37 #include "decode_avc_slice_packet.h"
38 
39 namespace decode
40 {
41 class AvcDecodePkt : public CmdPacket, public MediaStatusReportObserver
42 {
43 public:
AvcDecodePkt(MediaPipeline * pipeline,MediaTask * task,CodechalHwInterfaceNext * hwInterface)44     AvcDecodePkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterfaceNext*hwInterface)
45         : CmdPacket(task)
46     {
47         if (pipeline != nullptr)
48         {
49             m_statusReport   = pipeline->GetStatusReportInstance();
50             m_featureManager = pipeline->GetFeatureManager();
51             m_avcPipeline    = dynamic_cast<AvcPipeline *>(pipeline);
52         }
53         if (hwInterface != nullptr)
54         {
55             m_hwInterface    = hwInterface;
56             m_miItf          = hwInterface->GetMiInterfaceNext();
57             m_osInterface    = hwInterface->GetOsInterface();
58         }
59     }
~AvcDecodePkt()60     virtual ~AvcDecodePkt(){};
61 
62     //!
63     //! \brief  Initialize the media packet, allocate required resources
64     //! \return MOS_STATUS
65     //!         MOS_STATUS_SUCCESS if success, else fail reason
66     //!
67     virtual MOS_STATUS Init() override;
68 
69     //!
70     //! \brief  Prepare interal parameters, should be invoked for each frame
71     //! \return MOS_STATUS
72     //!         MOS_STATUS_SUCCESS if success, else fail reason
73     //!
74     virtual MOS_STATUS Prepare() override;
75 
76     //!
77     //! \brief  Destroy the media packet and release the resources
78     //! \return MOS_STATUS
79     //!         MOS_STATUS_SUCCESS if success, else fail reason
80     //!
81     virtual MOS_STATUS Destroy() override;
82 
83     //!
84     //! \brief  One frame is completed
85     //! \param  [in] mfxStatus
86     //!         pointer to status buffer which for mfx
87     //! \param  [in] rcsStatus
88     //!         pointer to status buffer which for RCS
89     //! \param  [in, out] statusReport
90     //!         pointer of DecoderStatusReport
91     //! \return MOS_STATUS
92     //!         MOS_STATUS_SUCCESS if success, else fail reason
93     //!
94     virtual MOS_STATUS Completed(void *mfxStatus, void *rcsStatus, void *statusReport) override;
95 
96     //!
97     //! \brief  Calculate Command Size
98     //!
99     //! \param  [in, out] commandBufferSize
100     //!         requested size
101     //! \param  [in, out] requestedPatchListSize
102     //!         requested size
103     //! \return MOS_STATUS
104     //!         status
105     //!
106     MOS_STATUS CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize) override;
107 
108     //!
109     //! \brief  Get Packet Name
110     //! \return std::string
111     //!
GetPacketName()112     virtual std::string GetPacketName() override
113     {
114         return "AVC_DECODE";
115     }
116 
117 protected:
118     //!
119     //! \brief  Calculate Command Buffer Size
120     //!
121     //! \return uint32_t
122     //!         Command buffer size calculated
123     //!
124     virtual uint32_t CalculateCommandBufferSize();
125 
126     //!
127     //! \brief  Calculate Patch List Size
128     //!
129     //! \return uint32_t
130     //!         Patchlist size calculated
131     //!
132     virtual uint32_t CalculatePatchListSize();
133 
134     void SetPerfTag(CODECHAL_MODE mode, uint16_t picCodingType);
135 
136     bool IsPrologRequired();
137 
138     MOS_STATUS SendPrologWithFrameTracking(MOS_COMMAND_BUFFER &cmdBuffer, bool frameTrackingRequested);
139 
140     MOS_STATUS MiFlush(MOS_COMMAND_BUFFER &cmdBuffer);
141 
142     MOS_STATUS AddForceWakeup(MOS_COMMAND_BUFFER &cmdBuffer);
143 
144     MOS_STATUS ReadMfxStatus(MediaStatusReport *statusReport, MOS_COMMAND_BUFFER &cmdBuffer);
145 
146     MOS_STATUS SetCencBatchBuffer(PMOS_COMMAND_BUFFER cmdBuffer);
147 
148     virtual MOS_STATUS StartStatusReport(uint32_t srType, MOS_COMMAND_BUFFER *cmdBuffer) override;
149     virtual MOS_STATUS EndStatusReport(uint32_t srType, MOS_COMMAND_BUFFER *cmdBuffer) override;
150 
151     MediaFeatureManager *   m_featureManager  = nullptr;
152     AvcPipeline *           m_avcPipeline     = nullptr;
153     DecodeAllocator *       m_allocator       = nullptr;
154     AvcBasicFeature *       m_avcBasicFeature = nullptr;
155     CodechalHwInterfaceNext*   m_hwInterface     = nullptr;
156     DecodeMemComp *         m_mmcState        = nullptr;
157 
158     AvcDecodePicPkt *m_picturePkt = nullptr;
159     AvcDecodeSlcPkt *m_slicePkt   = nullptr;
160 
161     // Parameters passed from application
162     const CODEC_AVC_PIC_PARAMS *m_avcPicParams = nullptr;  //!< Pointer to picture parameter
163 
164     uint32_t m_pictureStatesSize    = 0;
165     uint32_t m_picturePatchListSize = 0;
166     uint32_t m_sliceStatesSize      = 0;
167     uint32_t m_slicePatchListSize   = 0;
168 
169 MEDIA_CLASS_DEFINE_END(decode__AvcDecodePkt)
170 };
171 }  // namespace decode
172 #endif  // !__DECODE_AVC_PACKET_H__