1 /*--------------------------------------------------------------------------
2 Copyright (c) 2017, 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
47
get_vendor_extension_config(OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE * ext)48 OMX_ERRORTYPE omx_vdec::get_vendor_extension_config(
49 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
50 if (ext->nIndex >= mVendorExtensionStore.size()) {
51 return OMX_ErrorNoMore;
52 }
53
54 const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
55 DEBUG_PRINT_LOW("VendorExt: getConfig: index=%u (%s)", ext->nIndex, vExt.name());
56
57 vExt.copyInfoTo(ext);
58 if (ext->nParamSizeUsed < vExt.paramCount()) {
59 // this happens during initial getConfig to query only extension-name and param-count
60 return OMX_ErrorNone;
61 }
62
63 // We now have sufficient params allocated in extension data passed.
64 // Following code is to set the extension-specific data
65
66 bool setStatus = true;
67
68 switch ((OMX_U32)vExt.extensionIndex()) {
69 case OMX_QcomIndexParamVideoDecoderPictureOrder:
70 {
71 setStatus &= vExt.setParamInt32(ext, "enable", m_decode_order_mode);
72 break;
73 }
74 case OMX_QTIIndexParamLowLatencyMode:
75 {
76 setStatus &= vExt.setParamInt32(ext, "enable", m_sParamLowLatency.bEnableLowLatencyMode);
77 break;
78 }
79 case OMX_QcomIndexParamIndexExtraDataType:
80 {
81 char exType[OMX_MAX_STRINGVALUE_SIZE + 1];
82 memset (exType, 0, (sizeof(char)*OMX_MAX_STRINGVALUE_SIZE));
83 if ((OMX_BOOL)(client_extradata & OMX_OUTPUTCROP_EXTRADATA)){
84 const char * outputCropInfo = getStringForExtradataType(OMX_ExtraDataOutputCropInfo);
85 if (outputCropInfo != NULL &&
86 (strlcat(exType, outputCropInfo,
87 OMX_MAX_STRINGVALUE_SIZE)) >= OMX_MAX_STRINGVALUE_SIZE) {
88 DEBUG_PRINT_LOW("extradata string size exceeds size %d",OMX_MAX_STRINGVALUE_SIZE);
89 }
90 }
91
92 setStatus &= vExt.setParamString(ext, "types", exType);
93 DEBUG_PRINT_LOW("VendorExt: getparam: Extradata %s", exType);
94 break;
95 }
96 case OMX_QTIIndexParamCapabilitiesVTDriverVersion:
97 {
98 setStatus &= vExt.setParamInt32(ext, "number", 65536);
99 break;
100 }
101 default:
102 {
103 return OMX_ErrorNotImplemented;
104 }
105 }
106 return setStatus ? OMX_ErrorNone : OMX_ErrorUndefined;
107 }
108
set_vendor_extension_config(OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE * ext)109 OMX_ERRORTYPE omx_vdec::set_vendor_extension_config(
110 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
111
112 DEBUG_PRINT_LOW("set_vendor_extension_config");
113 if (ext->nIndex >= mVendorExtensionStore.size()) {
114 DEBUG_PRINT_ERROR("unrecognized vendor extension index (%u) max(%u)",
115 ext->nIndex, mVendorExtensionStore.size());
116 return OMX_ErrorBadParameter;
117 }
118
119 const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
120 DEBUG_PRINT_LOW("VendorExt: setConfig: index=%u (%s)", ext->nIndex, vExt.name());
121
122 OMX_ERRORTYPE err = OMX_ErrorNone;
123 err = vExt.isConfigValid(ext);
124 if (err != OMX_ErrorNone) {
125 return err;
126 }
127
128 // mark this as set, regardless of set_config succeeding/failing.
129 // App will know by inconsistent values in output-format
130 vExt.set();
131
132 bool valueSet = false;
133 switch ((OMX_U32)vExt.extensionIndex()) {
134 case OMX_QcomIndexParamVideoDecoderPictureOrder:
135 {
136 OMX_S32 pic_order_enable = 0;
137 valueSet |= vExt.readParamInt32(ext, "enable", &pic_order_enable);
138 if (!valueSet) {
139 break;
140 }
141
142 DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: OMX_QcomIndexParamVideoDecoderPictureOrder : %d",
143 pic_order_enable);
144
145 QOMX_VIDEO_DECODER_PICTURE_ORDER decParam;
146 OMX_INIT_STRUCT(&decParam, QOMX_VIDEO_DECODER_PICTURE_ORDER);
147 decParam.eOutputPictureOrder =
148 pic_order_enable ? QOMX_VIDEO_DECODE_ORDER : QOMX_VIDEO_DISPLAY_ORDER;
149 decParam.nPortIndex = OMX_DirOutput;
150
151 err = set_parameter(
152 NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoDecoderPictureOrder, &decParam);
153 if (err != OMX_ErrorNone) {
154 DEBUG_PRINT_ERROR("set_config: OMX_QcomIndexParamVideoDecoderPictureOrder failed !");
155 }
156 break;
157 }
158 case OMX_QTIIndexParamLowLatencyMode:
159 {
160 QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE lowLatency;
161 memcpy(&lowLatency, &m_sParamLowLatency, sizeof(QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE));
162 valueSet |= vExt.readParamInt32(ext, "enable", (OMX_S32 *)&(lowLatency.bEnableLowLatencyMode));
163 if (!valueSet) {
164 break;
165 }
166
167 DEBUG_PRINT_HIGH("VENDOR-EXT: set_param: low latency mode =%u", lowLatency.bEnableLowLatencyMode);
168 err = set_parameter(
169 NULL, (OMX_INDEXTYPE)OMX_QTIIndexParamLowLatencyMode, &lowLatency);
170 if (err != OMX_ErrorNone) {
171 DEBUG_PRINT_ERROR("set_param: OMX_QTIIndexParamLowLatencyMode failed !");
172 }
173
174 break;
175 }
176 case OMX_QcomIndexParamIndexExtraDataType:
177 {
178 QOMX_INDEXEXTRADATATYPE extraDataParam;
179 char exType[OMX_MAX_STRINGVALUE_SIZE];
180 OMX_INIT_STRUCT(&extraDataParam, QOMX_INDEXEXTRADATATYPE);
181 valueSet |= vExt.readParamString(ext, "types", exType);
182 if (!valueSet) {
183 break;
184 }
185 char *rest = exType;
186 char *token = strtok_r(exType, "|", &rest);
187 do {
188 extraDataParam.bEnabled = OMX_TRUE;
189 extraDataParam.nIndex = (OMX_INDEXTYPE)getIndexForExtradataType(token);
190 if (extraDataParam.nIndex < 0) {
191 DEBUG_PRINT_HIGH(" extradata %s not supported ", token);
192 continue;
193 }
194 if (extraDataParam.nIndex == (OMX_INDEXTYPE)OMX_ExtraDataOutputCropInfo) {
195 extraDataParam.nPortIndex = OMX_CORE_OUTPUT_PORT_INDEX;
196 }
197 DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: extradata: enable for index = %x",
198 extraDataParam.nIndex);
199 err = set_parameter(
200 NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamIndexExtraDataType, &extraDataParam);
201 if (err != OMX_ErrorNone) {
202 DEBUG_PRINT_ERROR("set_config: OMX_QcomIndexParamIndexExtraDataType failed !");
203 }
204 } while ((token = strtok_r(NULL, "|", &rest)));
205 break;
206 }
207 case OMX_QTIIndexParamCapabilitiesVTDriverVersion:
208 {
209 break;
210 }
211 default:
212 {
213 return OMX_ErrorNotImplemented;
214 }
215 }
216
217 return err;
218 }
219