1/*--------------------------------------------------------------------------
2Copyright (c) 2017, The Linux Foundation. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are
6met:
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
17THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28--------------------------------------------------------------------------*/
29
30void 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
38
39OMX_ERRORTYPE omx_vdec::get_vendor_extension_config(
40                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