• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2022-2023, 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      ddi_decode_jpeg_specific.h
24 //! \brief     Defines DdiDecodeJpeg class for JPEG decode
25 //!
26 
27 #ifndef __DDI_DECODE_JPEG_SPECIFIC_H__
28 #define __DDI_DECODE_JPEG_SPECIFIC_H__
29 
30 #include "ddi_decode_base_specific.h"
31 
32 namespace decode
33 {
34 
35 //!
36 //! \class DdiDecodeJpeg
37 //! \brief This class defines the member fields, functions etc used by JPEG decoder.
38 //!
39 class DdiDecodeJpeg : public DdiDecodeBase
40 {
41 public:
42     //!
43     //! \brief Constructor
44     //!
DdiDecodeJpeg()45     DdiDecodeJpeg() : DdiDecodeBase() {};
46 
47     //!
48     //! \brief Destructor
49     //!
~DdiDecodeJpeg()50     virtual ~DdiDecodeJpeg(){};
51 
52     // inherited virtual functions
53     virtual VAStatus BeginPicture(
54         VADriverContextP ctx,
55         VAContextID      context,
56         VASurfaceID      renderTarget) override;
57 
58     virtual void DestroyContext(
59         VADriverContextP ctx) override;
60 
61     virtual VAStatus RenderPicture(
62         VADriverContextP ctx,
63         VAContextID      context,
64         VABufferID       *buffers,
65         int32_t          numBuffers) override;
66 
67     virtual VAStatus InitDecodeParams(
68         VADriverContextP ctx,
69         VAContextID      context) override;
70 
71     virtual VAStatus SetDecodeParams() override;
72 
73     virtual void ContextInit(
74         int32_t picWidth,
75         int32_t picHeight) override;
76 
77     virtual VAStatus CodecHalInit(
78         DDI_MEDIA_CONTEXT *mediaCtx,
79         void              *ptr) override;
80 
81     virtual VAStatus AllocSliceControlBuffer(
82         DDI_MEDIA_BUFFER *buf) override;
83 
84     virtual VAStatus AllocBsBuffer(
85         DDI_CODEC_COM_BUFFER_MGR *bufMgr,
86         DDI_MEDIA_BUFFER         *buf) override;
87 
88     virtual uint8_t* GetPicParamBuf(
89         DDI_CODEC_COM_BUFFER_MGR *bufMgr) override;
90 
91 private:
92     //!
93     //! \brief   ParaSliceParam for Jpeg
94     //! \details parse the sliceParam info required by JPEG decoding for
95     //!          each slice
96     //!
97     //! \param   [in] *mediaCtx
98     //!          DDI_MEDIA_CONTEXT
99     //! \param   [in] *slcParam
100     //!          VASliceParameterBufferJPEGBaseline
101     //! \param   [in] numSlices
102     //!             uint32_t
103     //!
104     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
105     //!          else fail reason
106     VAStatus ParseSliceParams(
107         DDI_MEDIA_CONTEXT                  *mediaCtx,
108         VASliceParameterBufferJPEGBaseline *slcParam,
109         uint32_t                           numSlices);
110 
111     //!
112     //! \brief   ParaQMatrixParam for JPEG
113     //! \details parse the IQMatrix info required by JPEG decoding
114     //!
115     //! \param   [in] *mediaCtx
116     //!          DDI_MEDIA_CONTEXT
117     //! \param   [in] *matrix
118     //!          VAIQMatrixBufferJPEGBaseline
119     //!
120     //! \param   [in] numSlices
121     //!          int32_t
122     //!
123     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
124     //!          else fail reason
125     VAStatus ParseIQMatrix(
126         DDI_MEDIA_CONTEXT            *mediaCtx,
127         VAIQMatrixBufferJPEGBaseline *matrix);
128 
129     //! \brief   ParsePicParam for JPEG
130     //! \details parse the PicParam info required by JPEG decoding
131     //!
132     //! \param   [in] *mediaCtx
133     //!          DDI_MEDIA_CONTEXT
134     //! \param   [in] picParam
135     //!          VAPictureParameterBufferJPEGBaseline
136     //!
137     //! \param   [in] numSlices
138     //!          int32_t
139     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
140     //!          else fail reason
141     VAStatus ParsePicParams(
142         DDI_MEDIA_CONTEXT                    *mediaCtx,
143         VAPictureParameterBufferJPEGBaseline *picParam);
144 
145     //! \brief   Alloc SliceParam content for JPEG
146     //! \details Alloc/resize SlicePram content for JPEG decoding
147     //!
148     //! \param   [in] numSlices
149     //!          uint32_t the required number of slices
150     //!
151     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
152     //!          else fail reason
153     VAStatus AllocSliceParamContext(
154         uint32_t numSlices);
155 
156     //! \brief   Init resource buffer for JPEG
157     //! \details Initialize and allocate the resource buffer for JPEG
158     //!
159     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
160     //!          else fail reason
161     VAStatus InitResourceBuffer();
162 
163     //! \brief   Free Resource buffer for JPEG
164     //!
165     void FreeResourceBuffer();
166 
167     //! \brief   ParseHuffmanTbl for JPEG
168     //! \details parse the Huffman table info required by JPEG decoding
169     //!
170     //! \param   [in] *mediaCtx
171     //!          DDI_MEDIA_CONTEXT
172     //! \param   [in] huffmanTbl
173     //!          VAHuffmanTableBufferJPEGBaseline
174     //!
175     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
176     //!          else fail reason
177     VAStatus ParseHuffmanTbl(
178         DDI_MEDIA_CONTEXT                *mediaCtx,
179         VAHuffmanTableBufferJPEGBaseline *huffmanTbl);
180 
181     //! \brief   Set input buffer as rendered for JPEG decoding
182     //! \details Mark the input data buffer as rendered. This will be used in later decoding.
183     //!
184     //! \param   [in] bufferID
185     //!          VABufferID
186     //!
187     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
188     //!          else fail reason
189     VAStatus SetBufferRendered(VABufferID bufferID);
190 
191     //! \brief   Check the output format for JPEG decoding
192     //! \details Check whether the output format matches the chromat format.
193     //!
194     //! \param   [in] format
195     //!          MOS_FORMAT
196     //!
197     //! \return  return true if pass the format check.
198     //!          else false
199     bool CheckFormat(MOS_FORMAT format);
200 
201     void FreeResource();
202 
203     //! \brief  the internal JPEG bit-stream buffer
204     DDI_MEDIA_BUFFER *m_jpegBitstreamBuf = nullptr;
205 
206     //! \brief the total num of JPEG scans
207     int32_t m_numScans = 0;
208 
209     MEDIA_CLASS_DEFINE_END(decode__DdiDecodeJpeg)
210 };
211 } // namespace decode
212 #endif // __DDI_DECODE_JPEG_SPECIFIC_H__
213