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