1 /*
2 * Copyright (c) 2020, 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_avc_reference_frames.h
24 //! \brief    Defines reference list related logic for avc decode
25 //!
26 #ifndef __DECODE_AVC_REFERENCE_FRAMES_H__
27 #define __DECODE_AVC_REFERENCE_FRAMES_H__
28 
29 #include "codec_def_decode_avc.h"
30 #include "mhw_vdbox.h"
31 #include "decode_allocator.h"
32 
33 namespace decode
34 {
35 class AvcBasicFeature;
36 
37 class AvcReferenceFrames
38 {
39 public:
40     //!
41     //! \brief  AvcReferenceFrames constructor
42     //!
43     AvcReferenceFrames();
44 
45     //!
46     //! \brief  AvcReferenceFrames deconstructor
47     //!
48     ~AvcReferenceFrames();
49 
50     //!
51     //! \brief  Init Avc reference frames
52     //! \param  [in] basicFeature
53     //!         Pointer to Avc basic feature
54     //! \return MOS_STATUS
55     //!         MOS_STATUS_SUCCESS if success, else fail reason
56     //!
57     MOS_STATUS Init(AvcBasicFeature *basicFeature, DecodeAllocator& allocator);
58 
59     //!
60     //! \brief  Update reference frames for picture
61     //! \param  [in] picParams
62     //!         Picture parameters
63     //! \return MOS_STATUS
64     //!         MOS_STATUS_SUCCESS if success, else fail reason
65     //!
66     MOS_STATUS UpdatePicture(CODEC_AVC_PIC_PARAMS & picParams);
67 
68     //!
69     //! \brief  Get active reference list for current frame
70     //! \param  [in] picParams
71     //!         Picture parameters
72     //! \return std::vector<uint8_t> &
73     //!         Active reference list indices for current frame
74     //!
75     const std::vector<uint8_t> & GetActiveReferenceList(const CODEC_AVC_PIC_PARAMS & picParams);
76 
77     //!
78     //! \brief  Get active reference list for current frame
79     //! \param  [in] frameIndex
80     //!         Frame index for reference
81     //! \return PMOS_RESOURCE
82     //!         Active reference list for current frame
83     //!
84     PMOS_RESOURCE GetReferenceByFrameIndex(uint8_t frameIndex);
85 
86     //!
87     //! \brief  Get valid reference for error concealment.
88     //! \return PMOS_RESOURCE
89     //!         Valid reference resource
90     //!
91     PMOS_RESOURCE GetValidReference();
92 
93     //!
94     //! \brief  Update current resource for reference list
95     //! \param  [in] picParams
96     //!         Picture parameters
97     //! \return  MOS_STATUS
98     //!         MOS_STATUS_SUCCESS if success, else fail reason
99     //!
100     MOS_STATUS UpdateCurResource(const CODEC_AVC_PIC_PARAMS &picParams);
101 
102     CODEC_PIC_ID        m_avcPicIdx[CODEC_AVC_MAX_NUM_REF_FRAME];          //!< Picture Index
103     PCODEC_REF_LIST     m_refList[CODEC_AVC_NUM_UNCOMPRESSED_SURFACE];     //!< Pointer to reference list
104 
105 protected:
106     //!
107     //! \brief  Update the current frame entry on m_refList
108     //! \param  [in] picParams
109     //!         Picture parameters
110     //! \return MOS_STATUS
111     //!         MOS_STATUS_SUCCESS if success, else fail reason
112     //!
113     MOS_STATUS UpdateCurFrame(const CODEC_AVC_PIC_PARAMS & picParams);
114 
115     //!
116     //! \brief  Update the reference list for current frame
117     //! \param  [in] picParams
118     //!         Picture parameters
119     //! \return MOS_STATUS
120     //!         MOS_STATUS_SUCCESS if success, else fail reason
121     //!
122     MOS_STATUS UpdateCurRefList(const CODEC_AVC_PIC_PARAMS & picParams);
123 
124     //!
125     //! \brief  Update the reference cache policy
126     //! \param  [in] picParams
127     //!         Picture parameters
128     //! \return MOS_STATUS
129     //!         MOS_STATUS_SUCCESS if success, else fail reason
130     //!
131     MOS_STATUS UpdateRefCachePolicy(const CODEC_AVC_PIC_PARAMS &picParams);
132 
133     //!
134     //! \brief    Set frame store Id for avc decode.
135     //! \details
136     //! \param    [in] frameIdx
137     //!           frame index
138     //! \return   MOS_STATUS
139     //!           MOS_STATUS_SUCCESS if success, else fail reason
140     //!
141     MOS_STATUS SetFrameStoreIds(uint8_t frameIdx);
142 
143     AvcBasicFeature*         m_basicFeature = nullptr;                       //!< AVC basic feature
144     DecodeAllocator*         m_allocator    = nullptr;                       //!< Decode allocator
145     std::vector<uint8_t>     m_activeReferenceList;                          //!< Active reference list of current picture
146     CODEC_PICTURE            m_prevPic;                                      //!< Current Picture Struct
147     CODEC_AVC_FRAME_STORE_ID m_avcFrameStoreId[CODEC_AVC_MAX_NUM_REF_FRAME]; //!< Avc Frame Store ID
148     PMOS_INTERFACE           m_osInterface = nullptr;                        //!< Os interface
149 
150 MEDIA_CLASS_DEFINE_END(decode__AvcReferenceFrames)
151 };
152 
153 }  // namespace decode
154 
155 #endif  // !__DECODE_AVC_REFERENCE_FRAMES_H__
156