10d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray/*--------------------------------------------------------------------------
20d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayCopyright (c) 2017, The Linux Foundation. All rights reserved.
30d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
40d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayRedistribution and use in source and binary forms, with or without
50d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffraymodification, are permitted provided that the following conditions are
60d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffraymet:
70d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    * Redistributions of source code must retain the above copyright
80d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      notice, this list of conditions and the following disclaimer.
90d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    * Redistributions in binary form must reproduce the above
100d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      copyright notice, this list of conditions and the following
110d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      disclaimer in the documentation and/or other materials provided
120d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      with the distribution.
130d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    * Neither the name of The Linux Foundation nor the names of its
140d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      contributors may be used to endorse or promote products derived
150d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray      from this software without specific prior written permission.
160d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
170d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayTHIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
180d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
190d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
200d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
210d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffraySUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
240d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
250d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
260d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
270d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayIF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
280d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray--------------------------------------------------------------------------*/
290d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
300d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffrayvoid omx_vdec::init_vendor_extensions (VendorExtensionStore &store) {
310d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
320d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    //TODO: add extensions based on Codec, m_platform and/or other capability queries
330d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
340d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    ADD_EXTENSION("qti-ext-dec-picture-order", OMX_QcomIndexParamVideoDecoderPictureOrder, OMX_DirOutput)
350d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray    ADD_PARAM_END("enable", OMX_AndroidVendorValueInt32)
360d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray}
370d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
380d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray
390d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas GeoffrayOMX_ERRORTYPE omx_vdec::get_vendor_extension_config(
400d8db99ac5d838f81e0d3be83a5b00d5475edf86Nicolas Geoffray                OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
41    if (ext->nIndex >= mVendorExtensionStore.size()) {
42        return OMX_ErrorNoMore;
43    }
44
45    const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
46    DEBUG_PRINT_LOW("VendorExt: getConfig: index=%u (%s)", ext->nIndex, vExt.name());
47
48    vExt.copyInfoTo(ext);
49    if (ext->nParamSizeUsed < vExt.paramCount()) {
50        // this happens during initial getConfig to query only extension-name and param-count
51        return OMX_ErrorNone;
52    }
53
54    // We now have sufficient params allocated in extension data passed.
55    // Following code is to set the extension-specific data
56
57    bool setStatus = true;
58
59    switch ((OMX_U32)vExt.extensionIndex()) {
60        case OMX_QcomIndexParamVideoDecoderPictureOrder:
61        {
62            setStatus &= vExt.setParamInt32(ext, "enable", m_decode_order_mode);
63            break;
64        }
65        default:
66        {
67            return OMX_ErrorNotImplemented;
68        }
69    }
70    return setStatus ? OMX_ErrorNone : OMX_ErrorUndefined;
71}
72
73OMX_ERRORTYPE omx_vdec::set_vendor_extension_config(
74                OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext) {
75
76    ALOGI("set_vendor_extension_config");
77    if (ext->nIndex >= mVendorExtensionStore.size()) {
78        DEBUG_PRINT_ERROR("unrecognized vendor extension index (%u) max(%u)",
79                ext->nIndex, mVendorExtensionStore.size());
80        return OMX_ErrorBadParameter;
81    }
82
83    const VendorExtension& vExt = mVendorExtensionStore[ext->nIndex];
84    DEBUG_PRINT_LOW("VendorExt: setConfig: index=%u (%s)", ext->nIndex, vExt.name());
85
86    OMX_ERRORTYPE err = OMX_ErrorNone;
87    err = vExt.isConfigValid(ext);
88    if (err != OMX_ErrorNone) {
89        return err;
90    }
91
92    // mark this as set, regardless of set_config succeeding/failing.
93    // App will know by inconsistent values in output-format
94    vExt.set();
95
96    bool valueSet = false;
97    switch ((OMX_U32)vExt.extensionIndex()) {
98        case OMX_QcomIndexParamVideoDecoderPictureOrder:
99        {
100            OMX_S32 pic_order_enable = 0;
101            valueSet |= vExt.readParamInt32(ext, "enable", &pic_order_enable);
102            if (!valueSet) {
103                break;
104            }
105
106            DEBUG_PRINT_HIGH("VENDOR-EXT: set_config: OMX_QcomIndexParamVideoDecoderPictureOrder : %d",
107                    pic_order_enable);
108
109            QOMX_VIDEO_DECODER_PICTURE_ORDER decParam;
110            OMX_INIT_STRUCT(&decParam, QOMX_VIDEO_DECODER_PICTURE_ORDER);
111            decParam.eOutputPictureOrder =
112                    pic_order_enable ? QOMX_VIDEO_DECODE_ORDER : QOMX_VIDEO_DISPLAY_ORDER;
113
114            err = set_parameter(
115                    NULL, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoDecoderPictureOrder, &decParam);
116            if (err != OMX_ErrorNone) {
117                DEBUG_PRINT_ERROR("set_config: OMX_QcomIndexParamVideoDecoderPictureOrder failed !");
118            }
119            break;
120        }
121        default:
122        {
123            return OMX_ErrorNotImplemented;
124        }
125    }
126
127    return err;
128}
129