OMX.h revision 8dde7269a5356503d2b283234b6cb46d0c3f214e
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 ANDROID_OMX_H_
18#define ANDROID_OMX_H_
19
20#include <media/IOMX.h>
21#include <utils/threads.h>
22#include <utils/KeyedVector.h>
23
24namespace android {
25
26struct OMXMaster;
27struct OMXNodeInstance;
28
29class OMX : public BnOMX,
30            public IBinder::DeathRecipient {
31public:
32    OMX();
33
34    virtual bool livesLocally(node_id node, pid_t pid);
35
36    virtual status_t listNodes(List<ComponentInfo> *list);
37
38    virtual status_t allocateNode(
39            const char *name, const sp<IOMXObserver> &observer, node_id *node);
40
41    virtual status_t freeNode(node_id node);
42
43    virtual status_t sendCommand(
44            node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param);
45
46    virtual status_t getParameter(
47            node_id node, OMX_INDEXTYPE index,
48            void *params, size_t size);
49
50    virtual status_t setParameter(
51            node_id node, OMX_INDEXTYPE index,
52            const void *params, size_t size);
53
54    virtual status_t getConfig(
55            node_id node, OMX_INDEXTYPE index,
56            void *params, size_t size);
57
58    virtual status_t setConfig(
59            node_id node, OMX_INDEXTYPE index,
60            const void *params, size_t size);
61
62    virtual status_t getState(
63            node_id node, OMX_STATETYPE* state);
64
65    virtual status_t enableGraphicBuffers(
66            node_id node, OMX_U32 port_index, OMX_BOOL enable);
67
68    virtual status_t getGraphicBufferUsage(
69            node_id node, OMX_U32 port_index, OMX_U32* usage);
70
71    virtual status_t storeMetaDataInBuffers(
72            node_id node, OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type);
73
74    virtual status_t prepareForAdaptivePlayback(
75            node_id node, OMX_U32 portIndex, OMX_BOOL enable,
76            OMX_U32 max_frame_width, OMX_U32 max_frame_height);
77
78    virtual status_t configureVideoTunnelMode(
79            node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
80            OMX_U32 audioHwSync, native_handle_t **sidebandHandle);
81
82    virtual status_t useBuffer(
83            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
84            buffer_id *buffer, OMX_U32 allottedSize);
85
86    virtual status_t useGraphicBuffer(
87            node_id node, OMX_U32 port_index,
88            const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer);
89
90    virtual status_t updateGraphicBufferInMeta(
91            node_id node, OMX_U32 port_index,
92            const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer);
93
94    virtual status_t createInputSurface(
95            node_id node, OMX_U32 port_index,
96            sp<IGraphicBufferProducer> *bufferProducer,
97            MetadataBufferType *type);
98
99    virtual status_t createPersistentInputSurface(
100            sp<IGraphicBufferProducer> *bufferProducer,
101            sp<IGraphicBufferConsumer> *bufferConsumer);
102
103    virtual status_t setInputSurface(
104            node_id node, OMX_U32 port_index,
105            const sp<IGraphicBufferConsumer> &bufferConsumer,
106            MetadataBufferType *type);
107
108    virtual status_t signalEndOfInputStream(node_id node);
109
110    virtual status_t allocateBuffer(
111            node_id node, OMX_U32 port_index, size_t size,
112            buffer_id *buffer, void **buffer_data);
113
114    virtual status_t allocateBufferWithBackup(
115            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
116            buffer_id *buffer, OMX_U32 allottedSize);
117
118    virtual status_t freeBuffer(
119            node_id node, OMX_U32 port_index, buffer_id buffer);
120
121    virtual status_t fillBuffer(node_id node, buffer_id buffer, int fenceFd);
122
123    virtual status_t emptyBuffer(
124            node_id node,
125            buffer_id buffer,
126            OMX_U32 range_offset, OMX_U32 range_length,
127            OMX_U32 flags, OMX_TICKS timestamp, int fenceFd);
128
129    virtual status_t getExtensionIndex(
130            node_id node,
131            const char *parameter_name,
132            OMX_INDEXTYPE *index);
133
134    virtual status_t setInternalOption(
135            node_id node,
136            OMX_U32 port_index,
137            InternalOptionType type,
138            const void *data,
139            size_t size);
140
141    virtual void binderDied(const wp<IBinder> &the_late_who);
142
143    virtual bool isSecure(IOMX::node_id node);
144
145    OMX_ERRORTYPE OnEvent(
146            node_id node,
147            OMX_IN OMX_EVENTTYPE eEvent,
148            OMX_IN OMX_U32 nData1,
149            OMX_IN OMX_U32 nData2,
150            OMX_IN OMX_PTR pEventData);
151
152    OMX_ERRORTYPE OnEmptyBufferDone(
153            node_id node, buffer_id buffer, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer, int fenceFd);
154
155    OMX_ERRORTYPE OnFillBufferDone(
156            node_id node, buffer_id buffer, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer, int fenceFd);
157
158    void invalidateNodeID(node_id node);
159
160protected:
161    virtual ~OMX();
162
163private:
164    struct CallbackDispatcherThread;
165    struct CallbackDispatcher;
166
167    Mutex mLock;
168    OMXMaster *mMaster;
169    int32_t mNodeCounter;
170
171    KeyedVector<wp<IBinder>, OMXNodeInstance *> mLiveNodes;
172    KeyedVector<node_id, OMXNodeInstance *> mNodeIDToInstance;
173    KeyedVector<node_id, sp<CallbackDispatcher> > mDispatchers;
174
175    node_id makeNodeID(OMXNodeInstance *instance);
176    OMXNodeInstance *findInstance(node_id node);
177    sp<CallbackDispatcher> findDispatcher(node_id node);
178
179    void invalidateNodeID_l(node_id node);
180
181    OMX(const OMX &);
182    OMX &operator=(const OMX &);
183};
184
185}  // namespace android
186
187#endif  // ANDROID_OMX_H_
188