1 /*
2 * Copyright (c) 2019-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_av1_tile_coding_g12.h
24 //! \brief    Defines tile coding related logic for av1 decode
25 //!
26 #ifndef __DECODE_AV1_TILE_CODING_G12_H__
27 #define __DECODE_AV1_TILE_CODING_G12_H__
28 
29 #include "codec_def_decode_av1.h"
30 #include "mhw_vdbox.h"
31 #include "codechal_setting.h"
32 
33 namespace decode
34 {
35     class Av1BasicFeatureG12;
36     class Av1PipelineG12;
37 
38     class Av1DecodeTileG12
39     {
40     public:
41         //!
42         //! \struct TileDesc
43         //! Tile Descriptor to store each tile info
44         //!
45         struct TileDesc
46         {
47             uint32_t    m_offset;           //!< byte-aligned starting address of a tile in the bitstream
48             uint32_t    m_size;             //!< tile size for the current tile
49             uint16_t    m_tileGroupId;      //!< tile Group ID that this tile belongs to
50             uint16_t    m_tileNum;          //!< tile num in the current tile group
51             bool        m_lastInGroup;      //!< last tile in this tile group
52             uint16_t    m_tileRow;          //!< tile row index in source position if large scale tile is enabled
53             uint16_t    m_tileColumn;       //!< tile column index in source position if large scale tile is enabled
54             uint16_t    m_tileIndex;        //!< tile index in tile list, valid when large scale tile is enabled
55             uint8_t     m_anchorFrameIdx;   //!< anchor frame index for this tile, valid when large scale tile is enabled
56             uint16_t    m_tileIndexCount;   //!< tile index in tile list, valid when large scale tile is enabled
57         };
58 
59         //multiple tiles enabling
60         int16_t         m_curTile                = -1;           //!< tile ID currently decoding
61         int16_t         m_lastTileId             = -1;           //!< tile ID of the last tile parsed in the current execute() call
62         uint16_t        m_prevFrmTileNum         = 0;            //!< record the tile numbers in previous frame.
63         uint16_t        m_firstTileInTg          = 0;            //!< tile ID of the first tile in the current tile group
64         uint16_t        m_tileGroupId            = 0;            //!< record the last tile group ID
65         bool            m_isTruncatedTile        = false;        //!< flag to indicate if the last tile is truncated tile
66         TileDesc        *m_tileDesc              = nullptr;      //!< tile descriptors for each tile of the frame
67         bool            m_hasTileMissing         = false;        //! flag to indicate if having tile missing
68         bool            m_hasDuplicateTile       = false;        //! flag to indicate if having duplicate tile
69         uint32_t        m_tileStartOffset        = 0;            //!< record the tile or tile group header start address offset against the first byte of the bitstream buffer
70         bool            m_newFrameStart          = true;         //!< flag to indicate a new frame is coming, which means m_lastTileId should be reset to -1.
71         uint32_t        m_numTiles               = 0;            //!< Num of tiles
72         uint32_t        m_totalTileNum           = 0;            //!< Total tile number in the frame.
73         uint16_t         m_decPassNum            = 1;            //!< Total decode number pass in the frame.
74         //Used to calc tile width/height
75         uint16_t        m_miCols                 = 0;            //!< frame width in MI units (4x4)
76         uint16_t        m_miRows                 = 0;            //!< frame height in MI units (4x4)
77         uint16_t        m_tileWidthInMi          = 0;            //!< tile width in MI_units (4x4)
78         uint16_t        m_tileHeightInMi         = 0;            //!< tile height in MI units (4x4)
79         uint16_t        m_tileColStartSb[64];                    //!< tile column start SB
80         uint16_t        m_tileRowStartSb[64];                    //!< tile row start SB
81 
82         // Super-res x_step_qn and x0_qn
83         int32_t         m_lumaXStepQn            = 0;            //!< x_step_qn for luma
84         int32_t         m_lumaX0Qn[64];                          //!< x0_qn for each tile column for luma
85         int32_t         m_chromaXStepQn          = 0;            //!< x_step_qn for chroma
86         int32_t         m_chromaX0Qn[64];                        //!< x0_qn for each tile column for chroma
87 
88         //!
89         //! \brief  Av1TileCoding constructor
90         //!
Av1DecodeTileG12()91         Av1DecodeTileG12() {};
92 
93         //!
94         //! \brief  Av1TileCoding deconstructor
95         //!
96         ~Av1DecodeTileG12();
97 
98         //!
99         //! \brief  Initialize Av1 tile coding
100         //! \param  [in] params
101         //!         Pointer to Av1BasicFeatureG12
102         //! \param  [in] codecSettings
103         //!         Pointer to CodechalSetting
104         //! \return  MOS_STATUS
105         //!         MOS_STATUS_SUCCESS if success, else fail reason
106         //!
107         MOS_STATUS Init(Av1BasicFeatureG12 *basicFeature, CodechalSetting *codecSettings);
108 
109         //!
110         //! \brief  Update reference frames for tile
111         //! \param  [in] picParams
112         //!         Reference to picture parameters
113         //! \param  [in] picParams
114         //!         Pointer to tile parameters
115         //! \return  MOS_STATUS
116         //!         MOS_STATUS_SUCCESS if success, else fail reason
117         //!
118         MOS_STATUS Update(CodecAv1PicParams & picParams,
119                                CodecAv1TileParams *tileParams);
120 
121         //!
122         //! \brief  Detect conformance conflict and do error concealment
123         //! \return MOS_STATUS
124         //!         MOS_STATUS_SUCCESS if success, else fail reason
125         //!
126         MOS_STATUS ErrorDetectAndConceal();
127 
128         //!
129         //! \brief    Calculate decode pass number
130         //! \return   MOS_STATUS
131         //!           MOS_STATUS_SUCCESS if success, else fail reason
132         //!
133         MOS_STATUS CalcNumPass(const CodecAv1PicParams &picParams, CodecAv1TileParams *tileParams);
134         //!
135         //! \brief    Calculate upscaled Convolve Step and offset
136         //! \return   MOS_STATUS
137         //!           MOS_STATUS_SUCCESS if success, else fail reason
138         //!
139         void GetUpscaleConvolveStepX0(const CodecAv1PicParams &picParams, bool isChroma);
140 
141         //!
142         //! \brief  Get Decode pass number
143         //! \return uint16_t
GetNumPass()144         uint16_t GetNumPass() { return m_decPassNum; }
145 
146     protected:
147         //!
148         //! \brief    Calaculate Tile info Max tile
149         //! \return   MOS_STATUS
150         //!           MOS_STATUS_SUCCESS if success, else fail reason
151         //!
152         MOS_STATUS CalcTileInfoMaxTile(CodecAv1PicParams & picParams);
153 
154         //!
155         //! \brief    Calculate tile column width and tile column number
156         //! \return   MOS_STATUS
157         //!           MOS_STATUS_SUCCESS if success, else fail reason
158         //!
159         MOS_STATUS CalculateTileCols(CodecAv1PicParams & picParams);
160 
161         //!
162         //! \brief    Calculate tile row height and tile row number
163         //! \return   MOS_STATUS
164         //!           MOS_STATUS_SUCCESS if success, else fail reason
165         //!
166         MOS_STATUS CalculateTileRows(CodecAv1PicParams & picParams);
167 
168         //!
169         //! \brief    Parse tile params to get each tile info
170         //! \return   MOS_STATUS
171         //!           MOS_STATUS_SUCCESS if success, else fail reason
172         //!
173         MOS_STATUS ParseTileInfo(const CodecAv1PicParams & picParams, CodecAv1TileParams *tileParams);
174 
175         Av1BasicFeatureG12 *m_basicFeature = nullptr;
176     MEDIA_CLASS_DEFINE_END(decode__Av1DecodeTileG12)
177     };
178 
179 }  // namespace decode
180 
181 #endif  // !__DECODE_AV1_TILE_CODING_G12_H__
182