aboutsummaryrefslogtreecommitdiffstats
path: root/videocodec/OMXComponentDefines.h
blob: 02c45e4f668cb4d85a30fe5d0835dfcd9569bd3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OMX_COMPONENT_DEFINES_H_
#define OMX_COMPONENT_DEFINES_H_



#define DECLARE_HANDLER(CLASS, FUNC)\
    static OMX_ERRORTYPE Get##FUNC(void *inst, OMX_PTR pStructure) {\
        return ((CLASS*)inst)->Get##FUNC(pStructure);\
    }\
    static OMX_ERRORTYPE Set##FUNC(void *inst, OMX_PTR pStructure) {\
        return ((CLASS*)inst)->Set##FUNC(pStructure);\
    }\
    OMX_ERRORTYPE Get##FUNC(OMX_PTR pStructure);\
    OMX_ERRORTYPE Set##FUNC(OMX_PTR pStructure);

#define CHECK_TYPE_HEADER(P)\
    ret = CheckTypeHeader((P), sizeof(*(P)));\
    if (ret != OMX_ErrorNone) {\
        LOGE("Invalid type header.");\
        return ret;\
    }

#define CHECK_PORT_INDEX(P, INDEX)\
    if ((P)->nPortIndex != INDEX) {\
        LOGE("Bad port index %u, expected: %d", (P)->nPortIndex, INDEX);\
        return OMX_ErrorBadPortIndex;\
    }

#define CHECK_ENUMERATION_RANGE(INDEX, RANGE)\
    if (INDEX >= RANGE) {\
        LOGE("No more enumeration.");\
        return OMX_ErrorNoMore;\
    }

#define CHECK_PORT_INDEX_RANGE(P)\
    if ((P)->nPortIndex != 0 && (P)->nPortIndex != 1) {\
        LOGE("Port out of range %u", (P)->nPortIndex);\
        return OMX_ErrorBadPortIndex;\
    }

#define CHECK_RETURN_VALUE(FUNC)\
    if (ret != OMX_ErrorNone) {\
        LOGE(FUNC" failed: Error code = 0x%x", ret);\
        return ret;\
    }

#define CHECK_SET_PARAM_STATE()\
    OMX_STATETYPE state;\
    CBaseGetState((void *)GetComponentHandle(), &state);\
    if (state != OMX_StateLoaded && state != OMX_StateWaitForResources) {\
        LOGE("Invalid state to set param.");\
        return OMX_ErrorIncorrectStateOperation;\
    }

#define CHECK_SET_CONFIG_STATE()\
    OMX_STATETYPE state;\
    CBaseGetState((void *)GetComponentHandle(), &state);\
    if (state == OMX_StateLoaded || state == OMX_StateWaitForResources) {\
        LOGE("Invalid state to set config");\
        return OMX_ErrorNone;\
    }

#define CHECK_BS_STATE() \
    if (mBsState == BS_STATE_EXECUTING) { \
        LOGE("Wrong state"); \
        return OMX_ErrorUndefined; \
    }

#define CHECK_BS_STATUS(FUNC) \
    if (ret != BS_SUCCESS) { \
        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
        return OMX_ErrorUndefined; \
    }

#define CHECK_STATUS(FUNC) \
    if (ret != OMX_ErrorNone) { \
        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
        return ret; \
    }

#define CHECK_ENCODE_STATUS(FUNC)\
    if (ret < ENCODE_SUCCESS) { \
        LOGE(FUNC" Failed. ret = 0x%08x\n", ret); \
        return OMX_ErrorUndefined; \
    }

#define DECLARE_OMX_COMPONENT(NAME, ROLE, CLASS) \
    static const char *gName = (const char *)(NAME);\
    static const char *gRole = (const char *)(ROLE);\
    OMX_ERRORTYPE CreateInstance(OMX_PTR *instance) {\
        *instance = NULL;\
        ComponentBase *inst = new CLASS;\
        if (!inst) {\
            return OMX_ErrorInsufficientResources;\
        }\
        *instance = inst;\
        return OMX_ErrorNone;\
    }\
    struct wrs_omxil_cmodule_ops_s gOps = {CreateInstance};\
    struct wrs_omxil_cmodule_s WRS_OMXIL_CMODULE_SYMBOL = {gName, &gRole, 1, &gOps};

#endif /* OMX_COMPONENT_DEFINES_H_ */