1 /*
2 * Copyright (c) 2019-2022, 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_basic_feature.h
24 //! \brief    Defines the common interface for decode hevc basic feature
25 //!
26 #ifndef __DECODE_HEVC_BASIC_FEATURE_H__
27 #define __DECODE_HEVC_BASIC_FEATURE_H__
28 
29 #include "decode_basic_feature.h"
30 #include "codec_def_decode_hevc.h"
31 #include "codec_def_decode_hevc.h"
32 #include "decode_hevc_reference_frames.h"
33 #include "decode_hevc_mv_buffers.h"
34 #include "decode_hevc_tile_coding.h"
35 
36 namespace decode
37 {
38 class HevcBasicFeature :public DecodeBasicFeature
39 {
40 public:
HevcBasicFeature(DecodeAllocator * allocator,void * hwInterface,PMOS_INTERFACE osInterface)41     HevcBasicFeature(DecodeAllocator *allocator, void *hwInterface, PMOS_INTERFACE osInterface) :
42         DecodeBasicFeature(allocator, hwInterface, osInterface)
43     {
44         if (osInterface != nullptr)
45         {
46             m_osInterface = osInterface;
47         }
48     };
49 
50     virtual ~HevcBasicFeature();
51 
52     virtual MOS_STATUS Init(void *setting) override;
53 
54     virtual MOS_STATUS Update(void *params) override;
55 
GetOsInterface()56     PMOS_INTERFACE GetOsInterface()
57     {
58         return m_osInterface;
59     }
60 
61     MOS_STATUS CreateReferenceBeforeLoopFilter();
62 
63     bool IsLastSlice(uint32_t sliceIdx);
64     bool IsIndependentSlice(uint32_t sliceIdx);
65 
66     // Parameters passed from application
67     PCODEC_HEVC_PIC_PARAMS          m_hevcPicParams = nullptr;      //!< Pointer to picture parameter
68     PCODEC_HEVC_SLICE_PARAMS        m_hevcSliceParams = nullptr;    //!< Pointer to slice parameter
69     PCODECHAL_HEVC_IQ_MATRIX_PARAMS m_hevcIqMatrixParams = nullptr; //!< Pointer to IQ matrix parameter
70     PCODEC_HEVC_EXT_PIC_PARAMS      m_hevcRextPicParams = nullptr;  //!< Extended pic params for Rext
71     PCODEC_HEVC_EXT_SLICE_PARAMS    m_hevcRextSliceParams = nullptr;//!< Extended slice params for Rext
72     PCODEC_HEVC_SCC_PIC_PARAMS      m_hevcSccPicParams = nullptr;   //!< Pic params for SCC
73     PCODEC_HEVC_SUBSET_PARAMS       m_hevcSubsetParams = nullptr;   //!< Hevc subset params for tile entrypoint offset
74 
75     bool                            m_isWPPMode    = false;         //!< Indicate current picture is WPP mode
76     bool                            m_isSCCIBCMode = false;         //!< Indicate current picture is SCC IBC mode
77     bool                            m_isSCCPLTMode = false;         //!< Indicate current picture is SCC PLT mode
78     bool                            m_isSCCACTMode = false;         //!< Indicate current picture is SCC ACT mode
79 
80     PMOS_SURFACE                    m_referenceBeforeLoopFilter = nullptr; //!< For SCC IBC
81     HevcReferenceFrames             m_refFrames;                    //!< Reference frames
82     std::vector<uint32_t>           m_refFrameIndexList;            //!< Reference frame index list
83     RefrenceAssociatedBuffer<MOS_BUFFER, HevcMvBufferOpInf, HevcBasicFeature>
84                                     m_mvBuffers;                    //!< MV buffers
85     HevcTileCoding                  m_tileCoding;                   //!< Tile coding
86 
87     uint32_t                        m_minCtbSize = 0;               //!< Min Luma Coding Block Size
88     uint32_t                        m_ctbSize = 0;                  //!< Max coding tree block size
89     uint32_t                        m_widthInCtb  = 0;              //!< Frame width in LCU
90     uint32_t                        m_heightInCtb  = 0;             //!< Frame height in LCU
91 
92     bool                            m_dummyReferenceSlot[CODECHAL_MAX_CUR_NUM_REF_FRAME_HEVC];
93     bool                            m_shortFormatInUse = false;     //!< Indicate if short format
94 
95 protected:
96     virtual MOS_STATUS SetRequiredBitstreamSize(uint32_t requiredSize) override;
97 
98     MOS_STATUS SetPictureStructs();
99     MOS_STATUS SetSliceStructs();
100     MOS_STATUS ErrorDetectAndConceal();
101     MOS_STATUS ErrorDetectAndConcealForLongFormat();
102     MOS_STATUS SliceDataSizeCheck(uint32_t sliceIdx);
103     MOS_STATUS SliceSegmentAddressCheck(uint32_t sliceIdx, std::vector<int> &sliceSegmentAddressVector);
104     MOS_STATUS NumEntryPointOffsetsCheck(uint32_t sliceIdx);
105     MOS_STATUS ReferenceParamCheck(uint32_t sliceIdx);
106     MOS_STATUS CollocatedRefIdxCheck(uint32_t sliceIdx);
107 
108     PMOS_INTERFACE        m_osInterface  = nullptr;
109 
110 MEDIA_CLASS_DEFINE_END(decode__HevcBasicFeature)
111 };
112 
113 }  // namespace encode
114 
115 #endif  // !__DECODE_HEVC_BASIC_FEATURE_H__
116