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