1/*
2 * Copyright (C) 2009 The Android Open Source Project
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_BASE_H_
18
19#define OMX_COMPONENT_BASE_H_
20
21#include <OMX_Component.h>
22
23namespace android {
24
25struct OMXComponentBase {
26    OMXComponentBase(
27            const OMX_CALLBACKTYPE *callbacks,
28            OMX_PTR appData);
29
30    virtual ~OMXComponentBase();
31
32    virtual OMX_ERRORTYPE sendCommand(
33            OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR cmdData) = 0;
34
35    virtual OMX_ERRORTYPE getParameter(
36            OMX_INDEXTYPE index, OMX_PTR params) = 0;
37
38    virtual OMX_ERRORTYPE setParameter(
39            OMX_INDEXTYPE index, const OMX_PTR params) = 0;
40
41    virtual OMX_ERRORTYPE getConfig(
42            OMX_INDEXTYPE index, OMX_PTR config) = 0;
43
44    virtual OMX_ERRORTYPE setConfig(
45            OMX_INDEXTYPE index, const OMX_PTR config) = 0;
46
47    virtual OMX_ERRORTYPE getExtensionIndex(
48            const OMX_STRING name, OMX_INDEXTYPE *index) = 0;
49
50    virtual OMX_ERRORTYPE useBuffer(
51            OMX_BUFFERHEADERTYPE **bufHdr,
52            OMX_U32 portIndex,
53            OMX_PTR appPrivate,
54            OMX_U32 size,
55            OMX_U8 *buffer) = 0;
56
57    virtual OMX_ERRORTYPE allocateBuffer(
58            OMX_BUFFERHEADERTYPE **bufHdr,
59            OMX_U32 portIndex,
60            OMX_PTR appPrivate,
61            OMX_U32 size) = 0;
62
63    virtual OMX_ERRORTYPE freeBuffer(
64            OMX_U32 portIndex,
65            OMX_BUFFERHEADERTYPE *buffer) = 0;
66
67    virtual OMX_ERRORTYPE emptyThisBuffer(OMX_BUFFERHEADERTYPE *buffer) = 0;
68    virtual OMX_ERRORTYPE fillThisBuffer(OMX_BUFFERHEADERTYPE *buffer) = 0;
69
70    virtual OMX_ERRORTYPE enumerateRoles(OMX_U8 *role, OMX_U32 index) = 0;
71
72    virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state) = 0;
73
74    // Wraps a given OMXComponentBase instance into an OMX_COMPONENTTYPE
75    // as required by OpenMAX APIs.
76    static OMX_COMPONENTTYPE *MakeComponent(OMXComponentBase *base);
77
78protected:
79    void postEvent(OMX_EVENTTYPE event, OMX_U32 param1, OMX_U32 param2);
80    void postFillBufferDone(OMX_BUFFERHEADERTYPE *bufHdr);
81    void postEmptyBufferDone(OMX_BUFFERHEADERTYPE *bufHdr);
82
83private:
84    void setComponentHandle(OMX_COMPONENTTYPE *handle);
85
86    const OMX_CALLBACKTYPE *mCallbacks;
87    OMX_PTR mAppData;
88    OMX_COMPONENTTYPE *mComponentHandle;
89
90    OMXComponentBase(const OMXComponentBase &);
91    OMXComponentBase &operator=(const OMXComponentBase &);
92};
93
94}  // namespace android
95
96#endif  // OMX_COMPONENT_BASE_H_
97