OMX.h revision 038ccfd6ff5a32d6f559e5b479d6f8e55d0b5133
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 updateNativeHandleInMeta(
97            node_id node, OMX_U32 port_index,
98            const sp<NativeHandle> &nativeHandle, buffer_id buffer);
99
100    virtual status_t createInputSurface(
101            node_id node, OMX_U32 port_index, android_dataspace dataSpace,
102            sp<IGraphicBufferProducer> *bufferProducer,
103            MetadataBufferType *type);
104
105    virtual status_t createPersistentInputSurface(
106            sp<IGraphicBufferProducer> *bufferProducer,
107            sp<IGraphicBufferConsumer> *bufferConsumer);
108
109    virtual status_t setInputSurface(
110            node_id node, OMX_U32 port_index,
111            const sp<IGraphicBufferConsumer> &bufferConsumer,
112            MetadataBufferType *type);
113
114    virtual status_t signalEndOfInputStream(node_id node);
115
116    virtual status_t allocateSecureBuffer(
117            node_id node, OMX_U32 port_index, size_t size,
118            buffer_id *buffer, void **buffer_data, sp<NativeHandle> *native_handle);
119
120    virtual status_t allocateBufferWithBackup(
121            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
122            buffer_id *buffer, OMX_U32 allottedSize);
123
124    virtual status_t freeBuffer(
125            node_id node, OMX_U32 port_index, buffer_id buffer);
126
127    virtual status_t fillBuffer(node_id node, buffer_id buffer, int fenceFd);
128
129    virtual status_t emptyBuffer(
130            node_id node,
131            buffer_id buffer,
132            OMX_U32 range_offset, OMX_U32 range_length,
133            OMX_U32 flags, OMX_TICKS timestamp, int fenceFd);
134
135    virtual status_t getExtensionIndex(
136            node_id node,
137            const char *parameter_name,
138            OMX_INDEXTYPE *index);
139
140    virtual status_t setInternalOption(
141            node_id node,
142            OMX_U32 port_index,
143            InternalOptionType type,
144            const void *data,
145            size_t size);
146
147    virtual void binderDied(const wp<IBinder> &the_late_who);
148
149    virtual bool isSecure(IOMX::node_id node);
150
151    OMX_ERRORTYPE OnEvent(
152            node_id node,
153            OMX_IN OMX_EVENTTYPE eEvent,
154            OMX_IN OMX_U32 nData1,
155            OMX_IN OMX_U32 nData2,
156            OMX_IN OMX_PTR pEventData);
157
158    OMX_ERRORTYPE OnEmptyBufferDone(
159            node_id node, buffer_id buffer, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer, int fenceFd);
160
161    OMX_ERRORTYPE OnFillBufferDone(
162            node_id node, buffer_id buffer, OMX_IN OMX_BUFFERHEADERTYPE *pBuffer, int fenceFd);
163
164    void invalidateNodeID(node_id node);
165
166protected:
167    virtual ~OMX();
168
169private:
170    struct CallbackDispatcherThread;
171    struct CallbackDispatcher;
172
173    Mutex mLock;
174    OMXMaster *mMaster;
175    size_t mNodeCounter;
176
177    KeyedVector<wp<IBinder>, OMXNodeInstance *> mLiveNodes;
178    KeyedVector<node_id, OMXNodeInstance *> mNodeIDToInstance;
179    KeyedVector<node_id, sp<CallbackDispatcher> > mDispatchers;
180
181    node_id makeNodeID_l(OMXNodeInstance *instance);
182    OMXNodeInstance *findInstance(node_id node);
183    sp<CallbackDispatcher> findDispatcher(node_id node);
184
185    void invalidateNodeID_l(node_id node);
186
187    OMX(const OMX &);
188    OMX &operator=(const OMX &);
189};
190
191}  // namespace android
192
193#endif  // ANDROID_OMX_H_
194