1 /*
2 * Copyright (c) 2020-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 //! \file decode_downsampling_packet.cpp
24 //! \details The decode down sampling feature interface is further sub-divided by codec standard,
25 //! this file is for the base interface which is shared by all codecs.
26 //!
27 #include "decode_downsampling_packet.h"
28 #include "decode_common_feature_defs.h"
29
30 #ifdef _DECODE_PROCESSING_SUPPORTED
31
32 namespace decode
33 {
34
DecodeDownSamplingPkt(DecodePipeline * pipeline,CodechalHwInterfaceNext * hwInterface)35 DecodeDownSamplingPkt::DecodeDownSamplingPkt(DecodePipeline *pipeline, CodechalHwInterfaceNext *hwInterface)
36 : DecodeSubPacket(pipeline, hwInterface)
37 {
38 MOS_ZeroMemory(&m_sfcParams, sizeof(m_sfcParams));
39 m_hwInterface = hwInterface;
40 }
41
~DecodeDownSamplingPkt()42 DecodeDownSamplingPkt::~DecodeDownSamplingPkt()
43 {
44 }
45
Init()46 MOS_STATUS DecodeDownSamplingPkt::Init()
47 {
48 DECODE_CHK_NULL(m_pipeline);
49
50 MediaFeatureManager *featureManager = m_pipeline->GetFeatureManager();
51 DECODE_CHK_NULL(featureManager);
52
53 m_basicFeature = dynamic_cast<DecodeBasicFeature *>(
54 featureManager->GetFeature(FeatureIDs::basicFeature));
55 DECODE_CHK_NULL(m_basicFeature);
56
57 m_downSampling = dynamic_cast<DecodeDownSamplingFeature *>(
58 featureManager->GetFeature(DecodeFeatureIDs::decodeDownSampling));
59
60 MOS_ZeroMemory(&m_sfcParams, sizeof(m_sfcParams));
61 return MOS_STATUS_SUCCESS;
62 }
63
Prepare()64 MOS_STATUS DecodeDownSamplingPkt::Prepare()
65 {
66 DECODE_FUNC_CALL();
67 return MOS_STATUS_SUCCESS;
68 }
69
Execute(MOS_COMMAND_BUFFER & cmdBuffer)70 MOS_STATUS DecodeDownSamplingPkt::Execute(MOS_COMMAND_BUFFER& cmdBuffer)
71 {
72 DECODE_FUNC_CALL();
73
74 if (!m_downSampling->IsEnabled())
75 {
76 m_isSupported = false;
77 return MOS_STATUS_SUCCESS;
78 }
79
80 if (m_sfcInterface == nullptr)
81 {
82 m_sfcInterface = m_hwInterface->GetMediaSfcInterface();
83 DECODE_CHK_NULL(m_sfcInterface);
84
85 MEDIA_SFC_INTERFACE_MODE mode;
86 SetSfcMode(mode);
87
88 DECODE_CHK_STATUS(m_sfcInterface->Initialize(mode));
89 }
90
91
92 DECODE_CHK_STATUS(InitSfcParams(m_sfcParams));
93 if (m_sfcInterface->IsParameterSupported(m_sfcParams) == MOS_STATUS_SUCCESS)
94 {
95 m_isSupported = true;
96 }
97 else
98 {
99 m_isSupported = false;
100 }
101
102 if (m_isSupported)
103 {
104 DECODE_CHK_STATUS(m_sfcInterface->Render(&cmdBuffer, m_sfcParams));
105 }
106
107 return MOS_STATUS_SUCCESS;
108 }
109
CalculateCommandSize(uint32_t & commandBufferSize,uint32_t & requestedPatchListSize)110 MOS_STATUS DecodeDownSamplingPkt::CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize)
111 {
112 // The command buffer size of SFC related commands should be calculated by picture packet,
113 // so just return zero here.
114 commandBufferSize = 0;
115 requestedPatchListSize = 0;
116 return MOS_STATUS_SUCCESS;
117 }
118
InitSfcParams(VDBOX_SFC_PARAMS & sfcParams)119 MOS_STATUS DecodeDownSamplingPkt::InitSfcParams(VDBOX_SFC_PARAMS &sfcParams)
120 {
121 DECODE_FUNC_CALL();
122
123 DECODE_CHK_NULL(m_downSampling->m_inputSurface);
124
125 // VD-SFC Input Frame width/height must equal to decoded frame width/height
126 sfcParams.input.width = m_downSampling->m_inputSurface->dwWidth;
127 sfcParams.input.height = m_downSampling->m_inputSurface->dwHeight;
128 // x + width/ y + height is the right/bottom padding boundary of SFC input, which may be smaller than frame width/height.
129 sfcParams.input.effectiveWidth = m_downSampling->m_inputSurfaceRegion.m_x +
130 m_downSampling->m_inputSurfaceRegion.m_width;
131 sfcParams.input.effectiveHeight = m_downSampling->m_inputSurfaceRegion.m_y +
132 m_downSampling->m_inputSurfaceRegion.m_height;
133 sfcParams.input.format = m_downSampling->m_inputSurface->Format;
134 sfcParams.input.colorSpace = CSpace_Any;
135 sfcParams.input.chromaSiting = m_downSampling->m_chromaSitingType;
136 sfcParams.input.mirrorEnabled = (m_downSampling->m_mirrorState != 0);
137
138 sfcParams.output.surface = &(m_downSampling->m_outputSurface);
139 sfcParams.output.colorSpace = CSpace_Any;
140 sfcParams.output.chromaSiting = m_downSampling->m_chromaSitingType;
141 sfcParams.output.rcDst.left = m_downSampling->m_outputSurfaceRegion.m_x;
142 sfcParams.output.rcDst.top = m_downSampling->m_outputSurfaceRegion.m_y;
143 sfcParams.output.rcDst.right = m_downSampling->m_outputSurfaceRegion.m_x +
144 m_downSampling->m_outputSurfaceRegion.m_width;
145 sfcParams.output.rcDst.bottom = m_downSampling->m_outputSurfaceRegion.m_y +
146 m_downSampling->m_outputSurfaceRegion.m_height;
147
148 sfcParams.videoParams.codecStandard = m_basicFeature->m_standard;
149 sfcParams.scalingMode = m_downSampling->m_scalingMode;
150
151 // If histogram is enabled
152 if (m_downSampling->m_histogramDestSurf || m_downSampling->m_histogramDebug)
153 {
154 sfcParams.output.histogramBuf = m_downSampling->m_histogramBuffer;
155 }
156
157 return MOS_STATUS_SUCCESS;
158 }
159
160 }
161
162 #endif // !_DECODE_PROCESSING_SUPPORTED
163