1 /*--------------------------------------------------------------------------
2 Copyright (c) 2017, 2019, The Linux Foundation. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13 * Neither the name of The Linux Foundation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 --------------------------------------------------------------------------*/
29
init_vendor_extensions(VendorExtensionStore & store)30 void omx_vdec::init_vendor_extensions (VendorExtensionStore &store) {
31
32 //TODO: add extensions based on Codec, m_platform and/or other capability queries
33
34 ADD_EXTENSION("qti-ext-dec-picture-order", OMX_QcomIndexParamVideoDecoderPictureOrder, OMX_DirOutput)
35 ADD_PARAM_END("enable", OMX_AndroidVendorValueInt32)
36
37 ADD_EXTENSION("qti-ext-dec-low-latency", OMX_QTIIndexParamLowLatencyMode, OMX_DirOutput)
38 ADD_PARAM_END("enable", OMX_AndroidVendorValueInt32)
39
40 ADD_EXTENSION("qti-ext-extradata-enable", OMX_QcomIndexParamIndexExtraDataType, OMX_DirOutput)
41 ADD_PARAM_END("types", OMX_AndroidVendorValueString)
42
43 ADD_EXTENSION("qti-ext-dec-caps-vt-driver-version", OMX_QTIIndexParamCapabilitiesVTDriverVersion, OMX_DirOutput)
44 ADD_PARAM_END("number", OMX_AndroidVendorValueInt32)
45
46 ADD_EXTENSION("qti-ext-dec-output-frame-rate", OMX_QTIIndexParamVideoDecoderOutputFrameRate, OMX_DirOutput)
47 ADD_PARAM_END("value", OMX_AndroidVendorValueInt32)
48
49 ADD_EXTENSION("qti-ext-dec-thumbnail-mode", OMX_QcomIndexParamVideoSyncFrameDecodingMode, OMX_DirOutput)
50 ADD_PARAM_END("value", OMX_AndroidVendorValueInt32)
51 }
52
53
get_vendor_extension_config(OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE * ext)54 OMX_ERRORTYPE omx_vdec::get_vendor_extension_config(
55 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
56 if (ext->nIndex >= mVendorExtensionStore.size()) {
57 return OMX_ErrorNoMore;
58 }
59
60 const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
61 DEBUG_PRINT_LOW("VendorExt: getConfig: index=%u (%s)", ext->nIndex, vExt.name());
62
63 vExt.copyInfoTo(ext);
64 if (ext->nParamSizeUsed < vExt.paramCount()) {
65 // this happens during initial getConfig to query only extension-name and param-count
66 return OMX_ErrorNone;
67 }
68
69 // We now have sufficient params allocated in extension data passed.
70 // Following code is to set the extension-specific data
71
72 bool setStatus = true;
73
74 switch ((OMX_U32)vExt.extensionIndex()) {
75 case OMX_QcomIndexParamVideoDecoderPictureOrder:
76 {
77 setStatus &= vExt.setParamInt32(ext, "enable", m_decode_order_mode);
78 break;
79 }
80 case OMX_QTIIndexParamLowLatencyMode:
81 {
82 setStatus &= vExt.setParamInt32(ext, "enable", m_sParamLowLatency.bEnableLowLatencyMode);
83 break;
84 }
85 case OMX_QcomIndexParamIndexExtraDataType:
86 {
87 char exType[OMX_MAX_STRINGVALUE_SIZE + 1];
88 memset (exType, 0, (sizeof(char)*OMX_MAX_STRINGVALUE_SIZE));
89 strlcat(exType, "basic", OMX_MAX_STRINGVALUE_SIZE);
90
91 if (m_client_extradata & EXTRADATA_ADVANCED) {
92 strlcat(exType, "|advanced", OMX_MAX_STRINGVALUE_SIZE);
93 }
94
95 setStatus &= vExt.setParamString(ext, "types", exType);
96 DEBUG_PRINT_LOW("VendorExt: getparam: Extradata %s", exType);
97 break;
98 }
99 case OMX_QTIIndexParamCapabilitiesVTDriverVersion:
100 {
101 setStatus &= vExt.setParamInt32(ext, "number", VT_DRIVER_VERSION);
102 break;
103 }
104 case OMX_QTIIndexParamVideoDecoderOutputFrameRate:
105 {
106 setStatus &= vExt.setParamInt32(ext, "value", m_dec_hfr_fps);
107 break;
108 }
109 case OMX_QcomIndexParamVideoSyncFrameDecodingMode:
110 {
111 setStatus &= vExt.setParamInt32(ext, "value", drv_ctx.idr_only_decoding);
112 break;
113 }
114 default:
115 {
116 return OMX_ErrorNotImplemented;
117 }
118 }
119 return setStatus ? OMX_ErrorNone : OMX_ErrorUndefined;
120 }
121
set_vendor_extension_config(OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE * ext)122 OMX_ERRORTYPE omx_vdec::set_vendor_extension_config(
123 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
124
125 DEBUG_PRINT_LOW("set_vendor_extension_config");
126 if (ext->nIndex >= mVendorExtensionStore.size()) {
127 DEBUG_PRINT_ERROR("unrecognized vendor extension index (%u) max(%u)",
128 ext->nIndex, mVendorExtensionStore.size());
129 return OMX_ErrorBadParameter;
130 }
131
132 const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
133 DEBUG_PRINT_LOW("VendorExt: setConfig: index=%u (%s)", ext->nIndex, vExt.name());
134
135 OMX_ERRORTYPE err = OMX_ErrorNone;
136 err = vExt.isConfigValid(ext);
137 if (err != OMX_ErrorNone) {
138 return err;
139 }
140
141 // mark this as set, regardless of set_config succeeding/failing.
142 // App will know by inconsistent values in output-format
143 vExt.set();
144
145 bool valueSet = false;
146 switch ((OMX_U32)vExt.extensionIndex()) {
147 case OMX_QcomIndexParamVideoDecoderPictureOrder:
148 {
149 OMX_S32 pic_order_enable = 0;
150 valueSet |= vExt.readParamInt32(ext, "enable", &pic_order_enable);
151 if (!valueSet) {
152 break;
153 }
154
155 DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: OMX_QcomIndexParamVideoDecoderPictureOrder : %d",
156 pic_order_enable);
157
158 QOMX_VIDEO_DECODER_PICTURE_ORDER decParam;
159 OMX_INIT_STRUCT(&decParam, QOMX_VIDEO_DECODER_PICTURE_ORDER);
160 decParam.eOutputPictureOrder =
161 pic_order_enable ? QOMX_VIDEO_DECODE_ORDER : QOMX_VIDEO_DISPLAY_ORDER;
162 decParam.nPortIndex = OMX_DirOutput;
163
164 err = set_parameter(
165 NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoDecoderPictureOrder, &decParam);
166 if (err != OMX_ErrorNone) {
167 DEBUG_PRINT_ERROR("set_config: OMX_QcomIndexParamVideoDecoderPictureOrder failed !");
168 }
169 break;
170 }
171 case OMX_QTIIndexParamLowLatencyMode:
172 {
173 QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE lowLatency;
174 memcpy(&lowLatency, &m_sParamLowLatency, sizeof(QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE));
175 valueSet |= vExt.readParamInt32(ext, "enable", (OMX_S32 *)&(lowLatency.bEnableLowLatencyMode));
176 if (!valueSet) {
177 break;
178 }
179
180 DEBUG_PRINT_HIGH("VENDOR-EXT: set_param: low latency mode =%u", lowLatency.bEnableLowLatencyMode);
181 err = set_parameter(
182 NULL, (OMX_INDEXTYPE)OMX_QTIIndexParamLowLatencyMode, &lowLatency);
183 if (err != OMX_ErrorNone) {
184 DEBUG_PRINT_ERROR("set_param: OMX_QTIIndexParamLowLatencyMode failed !");
185 }
186
187 break;
188 }
189 case OMX_QcomIndexParamIndexExtraDataType:
190 {
191 QOMX_INDEXEXTRADATATYPE extraDataParam;
192 char exType[OMX_MAX_STRINGVALUE_SIZE];
193 OMX_INIT_STRUCT(&extraDataParam, QOMX_INDEXEXTRADATATYPE);
194 valueSet |= vExt.readParamString(ext, "types", exType);
195 if (!valueSet) {
196 break;
197 }
198 char *rest = exType;
199 char *token = NULL;
200 while ((token = strtok_r(rest, "|", &rest))) {
201 extraDataParam.nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
202 extraDataParam.bEnabled = OMX_TRUE;
203 if (!strcmp(token, "basic")) {
204 extraDataParam.nIndex = (OMX_INDEXTYPE)OMX_QTI_ExtraDataCategory_Basic;
205 } else if (!strcmp(token, "advanced")) {
206 extraDataParam.nIndex = (OMX_INDEXTYPE)OMX_QTI_ExtraDataCategory_Advanced;
207 } else {
208 DEBUG_PRINT_HIGH("extradata %s not supported", token);
209 continue;
210 }
211 DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: extradata: enable for index = %x",
212 extraDataParam.nIndex);
213 err = set_parameter(
214 NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType, &extraDataParam);
215 if (err != OMX_ErrorNone) {
216 DEBUG_PRINT_ERROR("set_config: OMX_QcomIndexParamIndexExtraDataType failed !");
217 }
218 }
219 break;
220 }
221 case OMX_QTIIndexParamVideoDecoderOutputFrameRate:
222 {
223 QOMX_VIDEO_OUTPUT_FRAME_RATE decOutputFrameRateParam;
224 OMX_INIT_STRUCT(&decOutputFrameRateParam, QOMX_VIDEO_OUTPUT_FRAME_RATE);
225 valueSet |= vExt.readParamInt32(ext, "value", (OMX_S32 *)&decOutputFrameRateParam.fps);
226 if (!valueSet) {
227 break;
228 }
229
230 DEBUG_PRINT_HIGH("VENDOR-EXT: set_param: decoder output-frame-rate value =%d", decOutputFrameRateParam.fps);
231 err = set_parameter(
232 NULL, (OMX_INDEXTYPE)OMX_QTIIndexParamVideoDecoderOutputFrameRate, &decOutputFrameRateParam);
233 if (err != OMX_ErrorNone) {
234 DEBUG_PRINT_ERROR("set_param: OMX_QTIIndexParamVideoDecoderOutputFrameRate failed !");
235 }
236 break;
237 }
238 case OMX_QcomIndexParamVideoSyncFrameDecodingMode:
239 {
240 OMX_U32 thumbnail_mode = 0;
241 valueSet |= vExt.readParamInt32(ext, "value", (OMX_S32 *)&thumbnail_mode);
242 DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: OMX_QcomIndexParamVideoSyncFrameDecodingMode : %d",
243 thumbnail_mode);
244 if (!valueSet || !thumbnail_mode)
245 break;
246 err = set_parameter(
247 NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSyncFrameDecodingMode, &thumbnail_mode);
248 if (err != OMX_ErrorNone) {
249 DEBUG_PRINT_ERROR("set_param: OMX_QcomIndexParamVideoSyncFrameDecodingMode failed !");
250 }
251 break;
252 }
253 case OMX_QTIIndexParamCapabilitiesVTDriverVersion:
254 {
255 break;
256 }
257 default:
258 {
259 return OMX_ErrorNotImplemented;
260 }
261 }
262
263 return err;
264 }
265