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