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 //!
24 //! \file decode_hevc_downsampling_feature.cpp
25 //! \brief Defines the interface for Hevc decode downsampling feature
26 //! \details The Hevc decode downsampling feature interface is maintaining the down sampling context.
27 //!
28 #include "decode_hevc_downsampling_feature.h"
29 #include "decode_hevc_basic_feature.h"
30 #include "decode_utils.h"
31
32 #ifdef _DECODE_PROCESSING_SUPPORTED
33
34 namespace decode
35 {
HevcDownSamplingFeature(MediaFeatureManager * featureManager,DecodeAllocator * allocator,PMOS_INTERFACE osInterface)36 HevcDownSamplingFeature::HevcDownSamplingFeature(
37 MediaFeatureManager *featureManager, DecodeAllocator *allocator, PMOS_INTERFACE osInterface) :
38 DecodeDownSamplingFeature(featureManager, allocator, osInterface)
39 {
40 }
41
~HevcDownSamplingFeature()42 HevcDownSamplingFeature::~HevcDownSamplingFeature()
43 {
44 }
45
GetRefFrameList(std::vector<uint32_t> & refFrameList)46 MOS_STATUS HevcDownSamplingFeature::GetRefFrameList(std::vector<uint32_t> &refFrameList)
47 {
48 HevcBasicFeature *hevcBasicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
49 DECODE_CHK_NULL(hevcBasicFeature);
50
51 uint8_t curFrameIdx = hevcBasicFeature->m_hevcPicParams->CurrPic.FrameIdx;
52 DECODE_CHK_COND(curFrameIdx >= hevcBasicFeature->m_maxFrameIndex, "Frame Index of current frame out of range!");
53 PCODEC_REF_LIST destEntry = hevcBasicFeature->m_refFrames.m_refList[curFrameIdx];
54 DECODE_CHK_NULL(destEntry);
55
56 refFrameList.clear();
57 for(auto i = 0; i < CODEC_MAX_NUM_REF_FRAME_HEVC; i++)
58 {
59 uint8_t refFrameIdx = destEntry->RefList[i].FrameIdx;
60 if (refFrameIdx < hevcBasicFeature->m_maxFrameIndex)
61 {
62 refFrameList.push_back(refFrameIdx);
63 }
64 }
65
66 return MOS_STATUS_SUCCESS;
67 }
68
GetDecodeTargetSize(SurfaceWidthT & width,SurfaceHeightT & height)69 MOS_STATUS HevcDownSamplingFeature::GetDecodeTargetSize(SurfaceWidthT &width, SurfaceHeightT &height)
70 {
71 width = m_basicFeature->m_width;
72 height = m_basicFeature->m_height;
73 return MOS_STATUS_SUCCESS;
74 }
75
GetDecodeTargetFormat(MOS_FORMAT & format)76 MOS_STATUS HevcDownSamplingFeature::GetDecodeTargetFormat(MOS_FORMAT &format)
77 {
78 HevcBasicFeature *hevcBasicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
79 DECODE_CHK_NULL(hevcBasicFeature);
80 PCODEC_HEVC_PIC_PARAMS hevcPicParams = hevcBasicFeature->m_hevcPicParams;
81 DECODE_CHK_NULL(hevcPicParams);
82
83 if (hevcPicParams->chroma_format_idc == HCP_CHROMA_FORMAT_YUV444)
84 {
85 if (hevcPicParams->bit_depth_luma_minus8 > 2 ||
86 hevcPicParams->bit_depth_chroma_minus8 > 2)
87 {
88 format = Format_Y416;
89 }
90 else if (hevcPicParams->bit_depth_luma_minus8 > 0 ||
91 hevcPicParams->bit_depth_chroma_minus8 > 0)
92 {
93 format = Format_Y410;
94 }
95 else
96 {
97 format = Format_AYUV;
98 }
99 }
100 else if (hevcPicParams->chroma_format_idc == HCP_CHROMA_FORMAT_YUV422)
101 {
102 if (hevcPicParams->bit_depth_luma_minus8 > 2 ||
103 hevcPicParams->bit_depth_chroma_minus8 > 2)
104 {
105 format = Format_Y216;
106 }
107 else if (hevcPicParams->bit_depth_luma_minus8 > 0 ||
108 hevcPicParams->bit_depth_chroma_minus8 > 0)
109 {
110 format = Format_Y210;
111 }
112 else
113 {
114 format = Format_YUY2;
115 }
116 }
117 else
118 {
119 if (hevcPicParams->bit_depth_luma_minus8 > 2 ||
120 hevcPicParams->bit_depth_chroma_minus8 > 2)
121 {
122 format = Format_P016;
123 }
124 else if (hevcPicParams->bit_depth_luma_minus8 > 0 ||
125 hevcPicParams->bit_depth_chroma_minus8 > 0)
126 {
127 format = Format_P010;
128 }
129 else
130 {
131 format = Format_NV12;
132 }
133 }
134
135 return MOS_STATUS_SUCCESS;
136 }
137
UpdateDecodeTarget(MOS_SURFACE & surface)138 MOS_STATUS HevcDownSamplingFeature::UpdateDecodeTarget(MOS_SURFACE &surface)
139 {
140 HevcBasicFeature *hevcBasicFeature = dynamic_cast<HevcBasicFeature *>(m_basicFeature);
141 DECODE_CHK_NULL(hevcBasicFeature);
142
143 DECODE_CHK_STATUS(hevcBasicFeature->UpdateDestSurface(surface));
144 if (hevcBasicFeature->m_isSCCIBCMode)
145 {
146 DECODE_CHK_STATUS(hevcBasicFeature->CreateReferenceBeforeLoopFilter());
147 }
148
149 DECODE_CHK_NULL(hevcBasicFeature->m_hevcPicParams);
150 HevcReferenceFrames &refFrames = hevcBasicFeature->m_refFrames;
151 DECODE_CHK_STATUS(refFrames.UpdateCurResource(
152 *hevcBasicFeature->m_hevcPicParams, hevcBasicFeature->m_isSCCIBCMode));
153
154 return MOS_STATUS_SUCCESS;
155 }
156
157 }
158
159 #endif
160