1 /*
2 * Copyright (c) 2021, 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_jpeg_downsampling_feature.cpp
25 //! \brief Defines the interface for Jpeg decode downsampling feature
26 //! \details The Jpeg decode downsampling feature interface is maintaining the down sampling context.
27 //!
28 #include "decode_jpeg_downsampling_feature.h"
29 #include "decode_jpeg_basic_feature.h"
30 #include "decode_utils.h"
31
32 #ifdef _DECODE_PROCESSING_SUPPORTED
33
34 namespace decode
35 {
JpegDownSamplingFeature(MediaFeatureManager * featureManager,DecodeAllocator * allocator,PMOS_INTERFACE osInterface)36 JpegDownSamplingFeature::JpegDownSamplingFeature(MediaFeatureManager *featureManager, DecodeAllocator *allocator,
37 PMOS_INTERFACE osInterface) : DecodeDownSamplingFeature(featureManager, allocator, osInterface)
38 {
39 MOS_ZeroMemory(&m_sfcInSurface, sizeof(m_sfcInSurface));
40 }
41
~JpegDownSamplingFeature()42 JpegDownSamplingFeature::~JpegDownSamplingFeature()
43 {
44 }
45
GetDecodeTargetSize(SurfaceWidthT & width,SurfaceHeightT & height)46 MOS_STATUS JpegDownSamplingFeature::GetDecodeTargetSize(SurfaceWidthT &width, SurfaceHeightT &height)
47 {
48 JpegBasicFeature *jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
49 DECODE_CHK_NULL(jpegBasicFeature);
50
51 width = jpegBasicFeature->m_destSurface.dwWidth;
52 height = jpegBasicFeature->m_destSurface.dwHeight;
53 return MOS_STATUS_SUCCESS;
54 }
55
UpdateDecodeTarget(MOS_SURFACE & surface)56 MOS_STATUS JpegDownSamplingFeature::UpdateDecodeTarget(MOS_SURFACE& surface)
57 {
58 JpegBasicFeature *jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
59 DECODE_CHK_NULL(jpegBasicFeature);
60 DECODE_CHK_STATUS(GetDecodeTargetSize(surface.dwWidth, surface.dwHeight));
61 DECODE_CHK_STATUS(GetInputSurfFormat(m_inputSurface));
62 DECODE_CHK_STATUS(GetDecodeTargetFormat(m_outputSurface.Format));
63
64 return MOS_STATUS_SUCCESS;
65 }
66
Update(void * params)67 MOS_STATUS JpegDownSamplingFeature::Update(void* params)
68 {
69 DECODE_FUNC_CALL();
70 DECODE_CHK_NULL(params);
71
72 JpegBasicFeature *jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
73 DECODE_CHK_NULL(jpegBasicFeature);
74
75 if (MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrSFCPipe) &&
76 !MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrDisableVDBox2SFC) &&
77 m_basicFeature->m_destSurface.Format == Format_A8R8G8B8 && // Currently only support this SFC usage in JPEG
78 (jpegBasicFeature->m_jpegPicParams->m_interleavedData || // SFC only support interleaved single scan (YUV400 is excluded for "interleaved" limitation)
79 jpegBasicFeature->m_jpegPicParams->m_chromaType == jpegYUV400) &&
80 jpegBasicFeature->m_jpegPicParams->m_totalScans == 1)
81 {
82 CodechalDecodeParams *decodeParams = (CodechalDecodeParams *)params;
83 if (decodeParams->m_procParams == nullptr) //procParams not givin by app
84 {
85 DecodeProcessingParams procParams;
86 MOS_ZeroMemory(&procParams, sizeof(DecodeProcessingParams));
87 m_sfcInSurface.dwPitch = MOS_ALIGN_CEIL(jpegBasicFeature->m_destSurface.dwWidth, CODECHAL_SURFACE_PITCH_ALIGNMENT);
88 procParams.m_inputSurface = &m_sfcInSurface;
89 procParams.m_inputSurfaceRegion.m_width = jpegBasicFeature->m_destSurface.dwWidth;
90 procParams.m_inputSurfaceRegion.m_height = jpegBasicFeature->m_destSurface.dwHeight;
91 procParams.m_inputSurface->OsResource = jpegBasicFeature->m_destSurface.OsResource;
92 procParams.m_outputSurface = &jpegBasicFeature->m_destSurface;
93 procParams.m_outputSurfaceRegion.m_width = jpegBasicFeature->m_destSurface.dwWidth;
94 procParams.m_outputSurfaceRegion.m_height = jpegBasicFeature->m_destSurface.dwHeight;
95
96 decodeParams->m_procParams = &procParams;
97
98 DecodeDownSamplingFeature::Update(decodeParams);
99 decodeParams->m_procParams = nullptr; //to in case duplicate free.
100 }
101 else
102 {
103 DecodeDownSamplingFeature::Update(decodeParams);
104 }
105 }
106 else
107 {
108 if ((!MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrSFCPipe) ||
109 MEDIA_IS_SKU(m_osInterface->pfnGetSkuTable(m_osInterface), FtrDisableVDBox2SFC)) &&
110 m_basicFeature->m_destSurface.Format == Format_A8R8G8B8)
111 {
112 DECODE_ASSERTMESSAGE("Don't support using SFC to convert.");
113 return MOS_STATUS_INVALID_PARAMETER;
114 }
115 }
116
117 return MOS_STATUS_SUCCESS;
118 }
119
GetRefFrameList(std::vector<uint32_t> & refFrameList)120 MOS_STATUS JpegDownSamplingFeature::GetRefFrameList(std::vector<uint32_t> &refFrameList)
121 {
122 return MOS_STATUS_SUCCESS;
123 }
124
GetDecodeTargetFormat(MOS_FORMAT & format)125 MOS_STATUS JpegDownSamplingFeature::GetDecodeTargetFormat(MOS_FORMAT &format)
126 {
127 JpegBasicFeature *jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
128 DECODE_CHK_NULL(jpegBasicFeature);
129
130 jpegBasicFeature->GetRenderTargetFormat(&format);
131
132 return MOS_STATUS_SUCCESS;
133 }
134
GetInputSurfFormat(PMOS_SURFACE surface)135 MOS_STATUS JpegDownSamplingFeature::GetInputSurfFormat(PMOS_SURFACE surface)
136 {
137 JpegBasicFeature *jpegBasicFeature = dynamic_cast<JpegBasicFeature *>(m_basicFeature);
138 DECODE_CHK_NULL(jpegBasicFeature);
139 switch (jpegBasicFeature->m_jpegPicParams->m_chromaType)
140 {
141 case jpegYUV400:
142 surface->Format = Format_400P;
143 break;
144 case jpegYUV411:
145 m_sfcInSurface.Format = Format_411P;
146 break;
147 case jpegYUV420:
148 surface->Format = Format_NV12;
149 surface->VPlaneOffset.iYOffset =
150 MOS_ALIGN_CEIL(jpegBasicFeature->m_destSurface.dwHeight, MHW_VDBOX_MFX_UV_PLANE_ALIGNMENT_LEGACY) + (jpegBasicFeature->m_destSurface.dwHeight >> 1);
151 break;
152 case jpegYUV422H2Y:
153 case jpegYUV422H4Y:
154 surface->Format = Format_422H;
155 surface->VPlaneOffset.iYOffset =
156 MOS_ALIGN_CEIL(jpegBasicFeature->m_destSurface.dwHeight, MHW_VDBOX_MFX_UV_PLANE_ALIGNMENT_LEGACY) + (jpegBasicFeature->m_destSurface.dwHeight >> 1);
157 break;
158 case jpegYUV444:
159 case jpegRGB:
160 case jpegBGR:
161 surface->Format = Format_444P;
162 surface->VPlaneOffset.iYOffset =
163 MOS_ALIGN_CEIL(jpegBasicFeature->m_destSurface.dwHeight, MHW_VDBOX_MFX_UV_PLANE_ALIGNMENT_LEGACY) + jpegBasicFeature->m_destSurface.dwHeight;
164 break;
165 default:
166 surface->Format = Format_Invalid;
167 return MOS_STATUS_INVALID_PARAMETER; //Format not support, exit downsampling feature.
168 }
169 return MOS_STATUS_SUCCESS;
170 }
171
172 }
173
174 #endif
175