xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/codec/hal/codechal_decode_jpeg.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2011-2017, 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     codechal_decode_jpeg.h
24 //! \brief    Defines the decode interface extension for JPEG.
25 //! \details  Defines all types, macros, and functions required by CodecHal for JPEG decoding.
26 //!           Definitions are not externally facing.
27 //!
28 
29 #ifndef __CODECHAL_DECODER_JPEG_H__
30 #define __CODECHAL_DECODER_JPEG_H__
31 
32 #include "codechal_decoder.h"
33 #include "codechal_decode_sfc_jpeg.h"
34 
35 //!
36 //! \def CODECHAL_DECODE_JPEG_BLOCK_SIZE
37 //! Jpeg block size
38 //!
39 #define CODECHAL_DECODE_JPEG_BLOCK_SIZE            8
40 
41 typedef class CodechalDecodeJpeg *PCODECHAL_DECODE_JPEG_STATE;
42 
43 //!
44 //! \class CodechalDecodeJpeg
45 //! \brief This class defines the member fields, functions etc used by JPEG decoder.
46 //!
47 class CodechalDecodeJpeg: public CodechalDecode
48 {
49 public:
50     //!
51     //! \brief  Constructor
52     //! \param    [in] hwInterface
53     //!           Hardware interface
54     //! \param    [in] debugInterface
55     //!           Debug interface
56     //! \param    [in] standardInfo
57     //!           The information of decode standard for this instance
58     //!
59     CodechalDecodeJpeg(
60         CodechalHwInterface   *hwInterface,
61         CodechalDebugInterface* debugInterface,
62         PCODECHAL_STANDARD_INFO standardInfo);
63 
64     //!
65     //! \brief    Copy constructor
66     //!
67     CodechalDecodeJpeg(const CodechalDecodeJpeg&) = delete;
68 
69     //!
70     //! \brief    Copy assignment operator
71     //!
72     CodechalDecodeJpeg& operator=(const CodechalDecodeJpeg&) = delete;
73 
74     //!
75     //! \brief    Destructor
76     //!
77     ~CodechalDecodeJpeg();
78 
79     //!
80     //! \brief    Allocate and Initialize JPEG decoder standard
81     //! \param    [in] settings
82     //!           Pointer to CodechalSetting
83     //! \return   MOS_STATUS
84     //!           MOS_STATUS_SUCCESS if success, else fail reason
85     //!
86     MOS_STATUS AllocateStandard (
87         CodechalSetting *settings) override;
88 
89     //!
90     //! \brief  Set states for each frame to prepare for JPEG decode
91     //! \return MOS_STATUS
92     //!         MOS_STATUS_SUCCESS if success, else fail reason
93     //!
94     MOS_STATUS SetFrameStates () override;
95 
96     //!
97     //! \brief    JPEG decoder state level function
98     //! \details  State level function for JPEG decoder
99     //!
100     //! \return   MOS_STATUS
101     //!           MOS_STATUS_SUCCESS if success, else fail reason
102     //!
103     MOS_STATUS DecodeStateLevel () override;
104 
105     //!
106     //! \brief    JPEG decoder primitive level function
107     //! \details  Primitive level function for GEN specific JPEG decoder
108     //!
109     //! \return   MOS_STATUS
110     //!           MOS_STATUS_SUCCESS if success, else fail reason
111     //!
112     MOS_STATUS DecodePrimitiveLevel () override;
113 
114     //!
115     //! \brief  Indicates whether or not the jpeg scan is incomplete
116     //! \return If jpeg scan is incomplete \see m_incompleteJpegScan
117     //!
IsIncompleteJpegScan()118     bool IsIncompleteJpegScan() override { return m_incompleteJpegScan; }
119 
120     MOS_STATUS InitMmcState() override;
121 
122 #ifdef _DECODE_PROCESSING_SUPPORTED
123     virtual MOS_STATUS InitSfcState();
124 #endif
125 
126     MOS_SURFACE               m_destSurface;    //!< Pointer to MOS_SURFACE of render surface
127     CodecDecodeJpegPicParams *m_jpegPicParams = nullptr;  //!< Picture parameter for JPEG
128 
129 #if USE_CODECHAL_DEBUG_TOOL
130     MOS_STATUS DumpIQParams(
131         CodecJpegQuantMatrix *matrixData);
132 
133     MOS_STATUS DumpPicParams(
134         CodecDecodeJpegPicParams *picParams);
135 
136     MOS_STATUS DumpScanParams(
137         CodecDecodeJpegScanParameter *scanParams);
138 
139     MOS_STATUS DumpHuffmanTable(
140         PCODECHAL_DECODE_JPEG_HUFFMAN_TABLE huffmanTable);
141 #endif
142 
143 protected:
144 
145     //!
146     //! \brief    Initialize during begin frame
147     //! \details  Initialize during begin frame in JPEG decode driver
148     //! \return   MOS_STATUS
149     //!           MOS_STATUS_SUCCESS if success, else fail reason
150     //!
151     MOS_STATUS InitializeBeginFrame();
152 
153     //!
154     //! \brief    Copy data surface
155     //! \details  Copy data surface in JPEG decode driver
156     //! \return   MOS_STATUS
157     //!           MOS_STATUS_SUCCESS if success, else fail reason
158     //!
159     MOS_STATUS CopyDataSurface();
160     //!
161     //! \brief    Check supported format
162     //! \details  Check supported format in JPEG decode driver
163     //! \param    [in,out] format
164     //!           MOS_Format to check
165     //!
166     //! \return   MOS_STATUS
167     //!           MOS_STATUS_SUCCESS if success, else fail reason
168     //!
169     MOS_STATUS CheckSupportedFormat(PMOS_FORMAT format);
170     //!
171     //! \brief    Check and copy incomplete bit stream
172     //! \details  Check and copy incomplete bit stream in JPEG decode driver
173     //! \return   MOS_STATUS
174     //!           MOS_STATUS_SUCCESS if success, else fail reason
175     //!
176     MOS_STATUS CheckAndCopyIncompleteBitStream();
177     //!
178     //! \brief    Allocate resources
179     //! \details  Allocate resources for JPEG decode driver
180     //! \return   MOS_STATUS
181     //!           MOS_STATUS_SUCCESS if success, else fail reason
182     //!
183     MOS_STATUS AllocateResources ();
184     //!
185     //! \brief    Set output surface layout
186     //! \details  Set output surface layout for JPEG decode driver
187     //! \param    [out] outputSurfLayout
188     //!           Pointer to CodecDecodeJpegImageLayout
189     //!
190     //! \return   MOS_STATUS
191     //!           MOS_STATUS_SUCCESS if success, else fail reason
192     //!
193     void SetOutputSurfaceLayout(
194         CodecDecodeJpegImageLayout *outputSurfLayout);
195 
196 protected:
197     //!
198     //! \brief  Indicates whether or not the SFC is inuse
199     //!         JPEG may not use SFC even when FtrSFCPipe == True, but it can't be known when creating device.
200     //! \return If SFC is inuse
201     //!
IsSfcInUse(CodechalSetting * codecHalSettings)202     bool IsSfcInUse(CodechalSetting * codecHalSettings) override
203     {
204         return (codecHalSettings->sfcEnablingHinted && MEDIA_IS_SKU(m_skuTable, FtrSFCPipe));
205 
206     }
207 
208 protected:
209     uint32_t                            m_dataSize;          //!< Data size of the bitstream
210     uint32_t                            m_dataOffset;        //!< Data offset of the bitstream
211     CodecDecodeJpegScanParameter *      m_jpegScanParams = nullptr;    //!< Scan parameter for JPEG
212     CodecJpegQuantMatrix *              m_jpegQMatrix = nullptr;       //!< QMatrix for JPEG
213     PCODECHAL_DECODE_JPEG_HUFFMAN_TABLE m_jpegHuffmanTable;  //!< Huffman table for JPEG
214 
215     MOS_RESOURCE m_resDataBuffer;          //!< Handle of bitstream buffer
216     MOS_RESOURCE m_resCopiedDataBuffer;    //!< The internal buffer to store copied data
217     uint32_t     m_copiedDataBufferSize;   //!< The max size of the internal copied buffer
218     uint32_t     m_nextCopiedDataOffset;   //!< The offset of the next bitstream data used for copying
219     uint32_t     m_totalDataLength;        //!< The total data length
220     uint32_t     m_preNumScans;            //!< Record the previous scan number before the new scan comes
221     bool         m_copiedDataBufferInUse;  //!< Flag to indicate whether the copy data buffer is used
222 
223     //! \brief Indicates if current input scan for Jpeg is incomplete
224     bool                    m_incompleteJpegScan = false;
225 
226     MOS_RESOURCE m_resSyncObjectWaContextInUse;     //!< Signals on the video WA context
227     MOS_RESOURCE m_resSyncObjectVideoContextInUse;  //!< Signals on the video context
228 
229 #ifdef _DECODE_PROCESSING_SUPPORTED
230     CodechalJpegSfcState *m_sfcState = nullptr;  //!< SFC state
231 #endif
232 };
233 #endif
234