• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2018, 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     encode_hevc_reference_frames.h
24 //! \brief    Defines reference list related logic for encode hevc
25 //!
26 #ifndef __ENCODE_HEVC_REFERENCE_FRAMES_H__
27 #define __ENCODE_HEVC_REFERENCE_FRAMES_H__
28 
29 #include "codec_def_encode_hevc.h"
30 #include "mhw_vdbox.h"
31 #include "mhw_vdbox_vdenc_itf.h"
32 #include "mhw_vdbox_hcp_itf.h"
33 #include "encode_mem_compression.h"
34 
35 namespace encode
36 {
37 class HevcBasicFeature;
38 
39 class HevcReferenceFrames : public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::hcp::Itf::ParSetting
40 {
41 public:
42 
43     //!
44     //! \brief  HevcReferenceFrames constructor
45     //!
HevcReferenceFrames()46     HevcReferenceFrames() {};
47 
48     //!
49     //! \brief  HevcReferenceFrames deconstructor
50     //!
51     ~HevcReferenceFrames();
52 
53     //!
54     //! \brief  Initialize reference frame
55     //! \param  [in] params
56     //!         Pointer to HevcBasicFeature
57     //! \return  MOS_STATUS
58     //!         MOS_STATUS_SUCCESS if success, else fail reason
59     //!
60     MOS_STATUS Init(HevcBasicFeature *basicFeature, EncodeAllocator *allocator);
61 
62     //!
63     //! \brief  Update reference frame for picture
64     //! \return  MOS_STATUS
65     //!         MOS_STATUS_SUCCESS if success, else fail reason
66     //!
67     MOS_STATUS UpdatePicture();
68 
69     //!
70     //! \brief  Update reference frame for slice
71     //! \return  MOS_STATUS
72     //!         MOS_STATUS_SUCCESS if success, else fail reason
73     //!
74     MOS_STATUS UpdateSlice();
75 
76     //!
77     //! \brief  Update pic params rollingI reference location.
78     //! \return  MOS_STATUS
79     //!         MOS_STATUS_SUCCESS if success, else fail reason
80     //!
81     MOS_STATUS UpdateRollingIReferenceLocation();
82 
83     //!
84     //! \brief  Set SlotForRecNotFiltered.
85     //! \param  [in, out] slotForRecNotFiltered
86     //!         slot for recnotfiltered surface
87     //! \return  MOS_STATUS
88     //!         MOS_STATUS_SUCCESS if success, else fail reason
89     //!
90     MOS_STATUS SetSlotForRecNotFiltered(unsigned char &slotForRecNotFiltered);
91 
92     //!
93     //! \brief  Get picture index
94     //! \param  [in] idx
95     //!         Index of pic index
96     //! \return  CODEC_PIC_ID
97     //!         CODEC_PIC_ID refer to the picure index
98     //!
GetPicIndex(uint8_t idx)99     CODEC_PIC_ID GetPicIndex(uint8_t idx) { return m_picIdx[idx]; };
100 
101     //!
102     //! \brief  Get reference list index
103     //! \param  [in] idx
104     //!         Index of pic index
105     //! \return  uint8_t
106     //!         reference list index
107     //!
GetRefListIndex(uint8_t idx)108     uint8_t GetRefListIndex(uint8_t idx) { return m_picIdx[idx].ucPicIdx; };
109 
110     //!
111     //! \brief  Get frame store index
112     //! \param  [in] idx
113     //!         Index of reference index mapping
114     //!
GetFrameRestoreIndex(uint8_t idx)115     uint8_t GetFrameRestoreIndex(uint8_t idx) { return m_refIdxMapping[idx]; };
116 
117     //!
118     //! \brief  Get current reference list
119     //! \return  PCODEC_REF_LIST
120     //!         Pointer of current reference list
121     //!
GetCurrRefList()122     PCODEC_REF_LIST GetCurrRefList() { return m_currRefList; };
123 
124     //!
125     //! \brief  Get reference list
126     //! \return  PCODEC_REF_LIST *
127     //!         Pointer of current reference list
128     //!
GetRefList()129     PCODEC_REF_LIST *GetRefList() { return m_refList; };
130 
131     //!
132     //! \brief  Get reference index mapping
133     //! \return  uint8_t
134     //!         reference index mapping
135     //!
GetRefIdxMapping()136     int8_t *GetRefIdxMapping() { return m_refIdxMapping; };
GetRefIdxMapping()137     const int8_t *GetRefIdxMapping() const { return m_refIdxMapping; };
138 
139     //!
140     //! \brief  Get picture coding type
141     //! \return  uint16_t
142     //!         Picture coding type
143     //!
GetPictureCodingType()144     uint16_t GetPictureCodingType() { return m_pictureCodingType; };
145 
146     //!
147     //! \brief  Is current used as reference
148     //! \param  [in] idx
149     //!         Index of reference list
150     //! \return  bool
151     //!         true if used as reference, else false
152     //!
153     bool IsCurrentUsedAsRef(uint8_t idx);
154     //!
155     //! \brief  Is low delay
156     //! \return  bool
157     //!         true if low delay,, else false
158     //!
IsLowDelay()159     bool IsLowDelay() const { return m_lowDelay; };
160 
161     //!
162     //! \brief  Is same ref list
163     //! \return bool
164     //!         true if same ref list, else false
165     //!
IsSameRefList()166     bool IsSameRefList() const { return m_sameRefList; };
167 
168     MHW_SETPAR_DECL_HDR(VDENC_PIPE_BUF_ADDR_STATE);
169 
170     MHW_SETPAR_DECL_HDR(HCP_PIPE_BUF_ADDR_STATE);
171 
172     MHW_SETPAR_DECL_HDR(HCP_SURFACE_STATE);
173 
174     EncodeMemComp *m_mmcState = nullptr;
175 
176     static constexpr uint8_t m_numMaxVdencL0Ref = 3;                                //!< Max number of reference frame list0
177     static constexpr uint8_t m_numMaxVdencL1Ref = 3;                                //!< Max number of reference frame list1
178 
179 protected:
180 
181     //!
182     //! \brief  Validate low delay B frame
183     //! \param  [in] slcParams
184     //!         Pointer to CODEC_HEVC_ENCODE_SLICE_PARAMS
185     //! \return  MOS_STATUS
186     //!         MOS_STATUS_SUCCESS if success, else fail reason
187     //!
188     MOS_STATUS ValidateLowDelayBFrame(PCODEC_HEVC_ENCODE_SLICE_PARAMS slcParams);
189 
190     //!
191     //! \brief  Validate same reference in L0 and L1
192     //! \param  [in] slcParams
193     //!         Pointer to CODEC_HEVC_ENCODE_SLICE_PARAMS
194     //! \return  MOS_STATUS
195     //!         MOS_STATUS_SUCCESS if success, else fail reason
196     //!
197     MOS_STATUS ValidateSameRefInL0L1(PCODEC_HEVC_ENCODE_SLICE_PARAMS slcParams);
198 
199     //!
200     //! \brief  Validate temporal mvp enabling flag
201     //! \param  [in] slcParams
202     //!         Pointer to CODEC_HEVC_ENCODE_SLICE_PARAMS
203     //! \return  MOS_STATUS
204     //!         MOS_STATUS_SUCCESS if success, else fail reason
205     //!
206     MOS_STATUS ValidateTmvp(PCODEC_HEVC_ENCODE_SLICE_PARAMS slcParams);
207 
208     ////!
209     ////! \brief  Validate radndom access
210     ////! \param  [in] slcParams
211     ////!         Pointer to CODEC_HEVC_ENCODE_SLICE_PARAMS
212     ////! \return  MOS_STATUS
213     ////!         MOS_STATUS_SUCCESS if success, else fail reason
214     ////!
215     //MOS_STATUS ValidateRandomAccess(PCODEC_HEVC_ENCODE_SLICE_PARAMS slcParams);
216 
217     uint16_t                m_pictureCodingType = 0;                                //!< I, P, or B frame
218     uint8_t                 m_idxForTempMVP = 0;                                    //!< Temp MVP index;
219     CODEC_PIC_ID            m_picIdx[CODEC_MAX_NUM_REF_FRAME_HEVC] = {};            //!< Reference picture index array
220     PCODEC_REF_LIST         m_refList[CODECHAL_NUM_UNCOMPRESSED_SURFACE_HEVC] = {}; //!< Pointer to reference pictures
221     PCODEC_REF_LIST         m_currRefList = nullptr;                                //!< Current reference list
222     uint8_t                 m_currRefIdx = 0;                                       //!< Current reference list Index
223     int8_t                  m_refIdxMapping[CODEC_MAX_NUM_REF_FRAME_HEVC] = {};     //!< Reference Index mapping
224     bool                    m_currUsedRefPic[CODEC_MAX_NUM_REF_FRAME_HEVC] = {};    //!< Reference picture usage array
225     bool                    m_lowDelay = false;                                     //!< Low delay flag
226     bool                    m_sameRefList = false;                                  //!< Flag to specify if ref list L0 and L1 are same
227     int32_t                 m_currGopIFramePOC = -1;                                //!< record POC for I frame in current GoP for temporal MVP verification
228 
229     HevcBasicFeature        *m_basicFeature = nullptr;                              //!<  HEVC paramter
230     EncodeAllocator         *m_allocator = nullptr;                                 //!< Encode allocator
231 
232 MEDIA_CLASS_DEFINE_END(encode__HevcReferenceFrames)
233 };
234 
235 }  // namespace encode
236 
237 #endif  // !__ENCODE_HEVC_REFERENCE_FRAMES_H__
238