1 /*
2 * Copyright (c) 2019, 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_hevc_tile_coding.h
24 //! \brief    Defines tile coding related logic for hevc decode
25 //!
26 #ifndef __DECODE_HEVC_TILE_CODING_H__
27 #define __DECODE_HEVC_TILE_CODING_H__
28 
29 #include "codec_def_decode_hevc.h"
30 #include "mhw_vdbox.h"
31 #include "codechal_setting.h"
32 
33 namespace decode
34 {
35 class HevcBasicFeature;
36 class HevcPipeline;
37 
38 class HevcTileCoding
39 {
40 public:
41     struct SubTileInfo
42     {
43         uint16_t tileX;     //!< The tile index in horizontal
44         uint16_t tileY;     //!< The tile index in vertical
45         uint16_t ctbX;      //!< Tile horizontal offset in ctb
46         uint16_t ctbY;      //!< Tile vertical offset in ctb
47         uint32_t bsdOffset; //!< Tile bitstream offset in the slice segment
48         uint32_t bsdLength; //!< Tile bitstream length
49     };
50 
51     struct SliceTileInfo
52     {
53         uint16_t sliceTileX;        //!< The tile index in horizontal which contains this slice
54         uint16_t sliceTileY;        //!< The tile index in vertical which contains this slice
55         bool     firstSliceOfTile;  //!< First slice of the tile
56         bool     lastSliceOfTile;   //!< Last slice of the tile
57 
58         uint16_t     origCtbX;      //!< Original slice start Ctb X index
59         uint16_t     origCtbY;      //!< Original slice start Ctb Y index
60         uint16_t     numTiles;      //!< Number of tiles in this slice
61         SubTileInfo* tileArrayBuf;  //!< Sub tile buffer in this slice
62         uint16_t     tileArraySize; //!< Allocation number for tileArrayBuf
63     };
64 
65     //!
66     //! \brief  HevcTileCoding constructor
67     //!
HevcTileCoding()68     HevcTileCoding() {};
69 
70     //!
71     //! \brief  HevcTileCoding deconstructor
72     //!
73     ~HevcTileCoding();
74 
75     //!
76     //! \brief  Initialize Hevc tile coding
77     //! \param  [in] params
78     //!         Pointer to HevcBasicFeature
79     //! \param  [in] codecSettings
80     //!         Pointer to CodechalSetting
81     //! \return  MOS_STATUS
82     //!         MOS_STATUS_SUCCESS if success, else fail reason
83     //!
84     MOS_STATUS Init(HevcBasicFeature *basicFeature, CodechalSetting *codecSettings);
85 
86     //!
87     //! \brief  Update reference frames for picture
88     //! \param  [in] picParams
89     //!         Pointer to picture parameters
90     //! \return  MOS_STATUS
91     //!         MOS_STATUS_SUCCESS if success, else fail reason
92     //!
93     MOS_STATUS UpdatePicture(const CODEC_HEVC_PIC_PARAMS & picParams);
94 
95     //!
96     //! \brief  Update reference frames for slice
97     //! \param  [in] picParams
98     //!         Reference to picture parameters
99     //! \param  [in] picParams
100     //!         Pointer to slice parameters
101     //! \return  MOS_STATUS
102     //!         MOS_STATUS_SUCCESS if success, else fail reason
103     //!
104     MOS_STATUS UpdateSlice(const CODEC_HEVC_PIC_PARAMS & picParams,
105                            const PCODEC_HEVC_SLICE_PARAMS sliceParams);
106 
107     //!
108     //! \brief  Update the tile information for slices
109     //! \return  MOS_STATUS
110     //!         MOS_STATUS_SUCCESS if success, else fail reason
111     //!
112     MOS_STATUS UpdateSliceTileInfo();
113 
114     //!
115     //! \brief    Utility to get tile column width
116     //! \return   uint16_t*
117     //!           Tile column width
118     //!
119     const uint16_t *GetTileColWidth();
120 
121     //!
122     //! \brief    Utility to get tile row height
123     //! \return   uint16_t*
124     //!           Tile row height
125     //!
126     const uint16_t *GetTileRowHeight();
127 
128     //!
129     //! \brief    Utility to get slice tile info by index
130     //! \return   uint16_t*
131     //!           Tile row height
132     //!
133     const SliceTileInfo *GetSliceTileInfo(uint32_t sliceIndex);
134 
135     //!
136     //! \brief    Utility to get tile index for the 1st tile in the slice
137     //! \param  [in] sliceIndex
138     //!         Slice index
139     //! \return   uint16_t
140     //!           tile index in horizontal
141     //!
142     uint16_t GetSliceTileX(uint32_t sliceIndex);
143 
144     //!
145     //! \brief    Utility to get tile index for the 1st tile in the slice
146     //! \param  [in] sliceIndex
147     //!         Slice index
148     //! \return   uint16_t
149     //!           tile index in vertical
150     //!
151     uint16_t GetSliceTileY(uint32_t sliceIndex);
152 
153     //!
154     //! \brief    Utility to get LCU index for specified tile column
155     //!
156     //! \return   uint16_t
157     //!           LCU index in horizontal
158     //!
159     uint16_t  GetTileCtbX(uint16_t col);
160 
161     //!
162     //! \brief    Utility to get LCU index for specified tile row
163     //!
164     //! \return   uint16_t
165     //!           LCU index in vertical
166     //!
167     uint16_t GetTileCtbY(uint16_t row);
168 
169 protected:
170     //!
171     //! \brief    Get all tile information
172     //! \details  Get all tile information in HEVC decode driver
173     //!
174     //! \return   MOS_STATUS
175     //!           MOS_STATUS_SUCCESS if success, else fail reason
176     //!
177     MOS_STATUS GetAllTileInfo(const CODEC_HEVC_PIC_PARAMS & picParams, uint32_t widthInCtb, uint32_t heightInCtb);
178 
179     //!
180     //! \brief    Compute tile index for the 1st tile in the slice
181     //! \param  [in] picParams
182     //!         Pointer to picture parameters
183     //! \param  [in] slc
184     //!         Pointer to slice parameters
185     //! \return   uint16_t
186     //!           tile index in horizontal
187     //!
188     uint16_t ComputeSliceTileX(const CODEC_HEVC_PIC_PARAMS & picParams, const CODEC_HEVC_SLICE_PARAMS & slc);
189 
190     //!
191     //! \brief    Compute tile index for the 1st tile in the slice
192     //!
193     //! \return   uint16_t
194     //!           tile index in vertical
195     //!
196     uint16_t ComputeSliceTileY(const CODEC_HEVC_PIC_PARAMS & picParams, const CODEC_HEVC_SLICE_PARAMS & slc);
197 
198     //!
199     //! \brief    Allocate tile information context for slice, reuse context if exist
200     //! \param  [in] sliceIndex
201     //!         Index of slice
202     //! \return   SliceTileInfo
203     //!           Point to slice tile information context
204     //!
205     SliceTileInfo* AllocateSliceTileInfo(uint32_t sliceIndex);
206 
207     //!
208     //! \brief  Compute tile number in this slice
209     //! \param  [in] picParams
210     //!         Picture parameters
211     //! \param  [in] sliceIdx
212     //!         slice index
213     //! \param  [in] sliceTileX
214     //!         The tile index in horizontal which contains this slice
215     //! \param  [in] sliceTileY
216     //!         The tile index in vertical which contains this slice
217     //! \param  [in] lastSlice
218     //!         Flag to indicate if this slice is last slice of frame
219     //! \return   uint16_t
220     //!           Number of tile in this slice
221     //!
222     uint16_t ComputeTileNumForSlice(const CODEC_HEVC_PIC_PARAMS & picParams,
223                                     uint32_t sliceIdx,
224                                     uint16_t sliceTileX,
225                                     uint16_t sliceTileY,
226                                     bool lastSlice);
227 
228     //!
229     //! \brief  Update tiles infomation in slice
230     //! \param  [in] picParams
231     //!         Picture parameters
232     //! \param  [in] sliceParams
233     //!         slice parameters
234     //! \param  [in] sliceTileInfo
235     //!         Context of slice tile information
236     //! \return  MOS_STATUS
237     //!         MOS_STATUS_SUCCESS if success, else fail reason
238     //!
239     MOS_STATUS UpdateSubTileInfo(const CODEC_HEVC_PIC_PARAMS & picParams,
240                                  const CODEC_HEVC_SLICE_PARAMS & sliceParams,
241                                  SliceTileInfo &sliceTileInfo);
242 
243     MOS_STATUS RsToTsAddrConvert(const CODEC_HEVC_PIC_PARAMS &picParams, uint32_t picSizeInCtbsY);
244 
245     HevcBasicFeature *  m_basicFeature = nullptr;                   //!<  HEVC paramter
246     uint16_t            m_tileColWidth[HEVC_NUM_MAX_TILE_COLUMN];   //!< Table of tile column width
247     uint16_t            m_tileRowHeight[HEVC_NUM_MAX_TILE_ROW];     //!< Table of tile row height
248     uint32_t            *m_pCtbAddrRsToTs = nullptr;                //!< Entry of raster scan to tile scan map
249     uint32_t            m_CurRsToTsTableSize = 0;                   //!< Record of current rs to ts map table size
250 
251     std::vector<SliceTileInfo*> m_sliceTileInfoList;                //!< List of slice tile info
252 
253 MEDIA_CLASS_DEFINE_END(decode__HevcTileCoding)
254 };
255 
256 }  // namespace decode
257 
258 #endif  // !__DECODE_HEVC_TILE_CODING_H__
259