1/*
2* Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17#ifndef OMX_COMPONENT_DEFINES_H_
18#define OMX_COMPONENT_DEFINES_H_
19
20
21
22#define DECLARE_HANDLER(CLASS, FUNC)\
23    static OMX_ERRORTYPE Get##FUNC(void *inst, OMX_PTR pStructure) {\
24        return ((CLASS*)inst)->Get##FUNC(pStructure);\
25    }\
26    static OMX_ERRORTYPE Set##FUNC(void *inst, OMX_PTR pStructure) {\
27        return ((CLASS*)inst)->Set##FUNC(pStructure);\
28    }\
29    OMX_ERRORTYPE Get##FUNC(OMX_PTR pStructure);\
30    OMX_ERRORTYPE Set##FUNC(OMX_PTR pStructure);
31
32#define CHECK_TYPE_HEADER(P)\
33    ret = CheckTypeHeader((P), sizeof(*(P)));\
34    if (ret != OMX_ErrorNone) {\
35        LOGE("Invalid type header.");\
36        return ret;\
37    }
38
39#define CHECK_PORT_INDEX(P, INDEX)\
40    if ((P)->nPortIndex != INDEX) {\
41        LOGE("Bad port index %u, expected: %d", (P)->nPortIndex, INDEX);\
42        return OMX_ErrorBadPortIndex;\
43    }
44
45#define CHECK_ENUMERATION_RANGE(INDEX, RANGE)\
46    if (INDEX >= RANGE) {\
47        LOGE("No more enumeration.");\
48        return OMX_ErrorNoMore;\
49    }
50
51#define CHECK_PORT_INDEX_RANGE(P)\
52    if ((P)->nPortIndex != 0 && (P)->nPortIndex != 1) {\
53        LOGE("Port out of range %u", (P)->nPortIndex);\
54        return OMX_ErrorBadPortIndex;\
55    }
56
57#define CHECK_RETURN_VALUE(FUNC)\
58    if (ret != OMX_ErrorNone) {\
59        LOGE(FUNC" failed: Error code = 0x%x", ret);\
60        return ret;\
61    }
62
63#define CHECK_SET_PARAM_STATE()\
64    OMX_STATETYPE state;\
65    CBaseGetState((void *)GetComponentHandle(), &state);\
66    if (state != OMX_StateLoaded && state != OMX_StateWaitForResources) {\
67        LOGE("Invalid state to set param.");\
68        return OMX_ErrorIncorrectStateOperation;\
69    }
70
71#define CHECK_SET_CONFIG_STATE()\
72    OMX_STATETYPE state;\
73    CBaseGetState((void *)GetComponentHandle(), &state);\
74    if (state == OMX_StateLoaded || state == OMX_StateWaitForResources) {\
75        LOGE("Invalid state to set config");\
76        return OMX_ErrorNone;\
77    }
78
79#define CHECK_BS_STATE() \
80    if (mBsState == BS_STATE_EXECUTING) { \
81        LOGE("Wrong state"); \
82        return OMX_ErrorUndefined; \
83    }
84
85#define CHECK_BS_STATUS(FUNC) \
86    if (ret != BS_SUCCESS) { \
87        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
88        return OMX_ErrorUndefined; \
89    }
90
91#define CHECK_STATUS(FUNC) \
92    if (ret != OMX_ErrorNone) { \
93        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
94        return ret; \
95    }
96
97#define CHECK_ENCODE_STATUS(FUNC)\
98    if (ret < ENCODE_SUCCESS) { \
99        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
100        return OMX_ErrorUndefined; \
101    }
102
103#define DECLARE_OMX_COMPONENT(NAME, ROLE, CLASS) \
104    static const char *gName = (const char *)(NAME);\
105    static const char *gRole = (const char *)(ROLE);\
106    OMX_ERRORTYPE CreateInstance(OMX_PTR *instance) {\
107        *instance = NULL;\
108        ComponentBase *inst = new CLASS;\
109        if (!inst) {\
110            return OMX_ErrorInsufficientResources;\
111        }\
112        *instance = inst;\
113        return OMX_ErrorNone;\
114    }\
115    struct wrs_omxil_cmodule_ops_s gOps = {CreateInstance};\
116    struct wrs_omxil_cmodule_s WRS_OMXIL_CMODULE_SYMBOL = {gName, &gRole, 1, &gOps};
117
118#endif /* OMX_COMPONENT_DEFINES_H_ */
119