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_IOMX_H_
18 
19 #define ANDROID_IOMX_H_
20 
21 #include <binder/IInterface.h>
22 #include <gui/IGraphicBufferProducer.h>
23 #include <ui/GraphicBuffer.h>
24 #include <utils/List.h>
25 #include <utils/String8.h>
26 
27 #include <OMX_Core.h>
28 #include <OMX_Video.h>
29 
30 namespace android {
31 
32 class IMemory;
33 class IOMXObserver;
34 class IOMXRenderer;
35 class Surface;
36 
37 class IOMX : public IInterface {
38 public:
39     DECLARE_META_INTERFACE(OMX);
40 
41     typedef uint32_t buffer_id;
42     typedef uint32_t node_id;
43 
44     // Given a node_id and the calling process' pid, returns true iff
45     // the implementation of the OMX interface lives in the same
46     // process.
47     virtual bool livesLocally(node_id node, pid_t pid) = 0;
48 
49     struct ComponentInfo {
50         String8 mName;
51         List<String8> mRoles;
52     };
53     virtual status_t listNodes(List<ComponentInfo> *list) = 0;
54 
55     virtual status_t allocateNode(
56             const char *name, const sp<IOMXObserver> &observer,
57             node_id *node) = 0;
58 
59     virtual status_t freeNode(node_id node) = 0;
60 
61     virtual status_t sendCommand(
62             node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
63 
64     virtual status_t getParameter(
65             node_id node, OMX_INDEXTYPE index,
66             void *params, size_t size) = 0;
67 
68     virtual status_t setParameter(
69             node_id node, OMX_INDEXTYPE index,
70             const void *params, size_t size) = 0;
71 
72     virtual status_t getConfig(
73             node_id node, OMX_INDEXTYPE index,
74             void *params, size_t size) = 0;
75 
76     virtual status_t setConfig(
77             node_id node, OMX_INDEXTYPE index,
78             const void *params, size_t size) = 0;
79 
80     virtual status_t getState(
81             node_id node, OMX_STATETYPE* state) = 0;
82 
83     virtual status_t storeMetaDataInBuffers(
84             node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
85 
86     virtual status_t prepareForAdaptivePlayback(
87             node_id node, OMX_U32 portIndex, OMX_BOOL enable,
88             OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
89 
90    virtual status_t configureVideoTunnelMode(
91             node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
92             OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
93 
94     virtual status_t enableGraphicBuffers(
95             node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
96 
97     virtual status_t getGraphicBufferUsage(
98             node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
99 
100     virtual status_t useBuffer(
101             node_id node, OMX_U32 port_index, const sp<IMemory> &params,
102             buffer_id *buffer) = 0;
103 
104     virtual status_t useGraphicBuffer(
105             node_id node, OMX_U32 port_index,
106             const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
107 
108     virtual status_t updateGraphicBufferInMeta(
109             node_id node, OMX_U32 port_index,
110             const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
111 
112     virtual status_t createInputSurface(
113             node_id node, OMX_U32 port_index,
114             sp<IGraphicBufferProducer> *bufferProducer) = 0;
115 
116     virtual status_t signalEndOfInputStream(node_id node) = 0;
117 
118     // This API clearly only makes sense if the caller lives in the
119     // same process as the callee, i.e. is the media_server, as the
120     // returned "buffer_data" pointer is just that, a pointer into local
121     // address space.
122     virtual status_t allocateBuffer(
123             node_id node, OMX_U32 port_index, size_t size,
124             buffer_id *buffer, void **buffer_data) = 0;
125 
126     virtual status_t allocateBufferWithBackup(
127             node_id node, OMX_U32 port_index, const sp<IMemory> &params,
128             buffer_id *buffer) = 0;
129 
130     virtual status_t freeBuffer(
131             node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
132 
133     virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
134 
135     virtual status_t emptyBuffer(
136             node_id node,
137             buffer_id buffer,
138             OMX_U32 range_offset, OMX_U32 range_length,
139             OMX_U32 flags, OMX_TICKS timestamp) = 0;
140 
141     virtual status_t getExtensionIndex(
142             node_id node,
143             const char *parameter_name,
144             OMX_INDEXTYPE *index) = 0;
145 
146     enum InternalOptionType {
147         INTERNAL_OPTION_SUSPEND,  // data is a bool
148         INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY,  // data is an int64_t
149         INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
150         INTERNAL_OPTION_START_TIME, // data is an int64_t
151         INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2]
152     };
153     virtual status_t setInternalOption(
154             node_id node,
155             OMX_U32 port_index,
156             InternalOptionType type,
157             const void *data,
158             size_t size) = 0;
159 };
160 
161 struct omx_message {
162     enum {
163         EVENT,
164         EMPTY_BUFFER_DONE,
165         FILL_BUFFER_DONE,
166 
167     } type;
168 
169     IOMX::node_id node;
170 
171     union {
172         // if type == EVENT
173         struct {
174             OMX_EVENTTYPE event;
175             OMX_U32 data1;
176             OMX_U32 data2;
177         } event_data;
178 
179         // if type == EMPTY_BUFFER_DONE
180         struct {
181             IOMX::buffer_id buffer;
182         } buffer_data;
183 
184         // if type == FILL_BUFFER_DONE
185         struct {
186             IOMX::buffer_id buffer;
187             OMX_U32 range_offset;
188             OMX_U32 range_length;
189             OMX_U32 flags;
190             OMX_TICKS timestamp;
191         } extended_buffer_data;
192 
193     } u;
194 };
195 
196 class IOMXObserver : public IInterface {
197 public:
198     DECLARE_META_INTERFACE(OMXObserver);
199 
200     virtual void onMessage(const omx_message &msg) = 0;
201 };
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 
205 class BnOMX : public BnInterface<IOMX> {
206 public:
207     virtual status_t onTransact(
208             uint32_t code, const Parcel &data, Parcel *reply,
209             uint32_t flags = 0);
210 };
211 
212 class BnOMXObserver : public BnInterface<IOMXObserver> {
213 public:
214     virtual status_t onTransact(
215             uint32_t code, const Parcel &data, Parcel *reply,
216             uint32_t flags = 0);
217 };
218 
219 struct CodecProfileLevel {
220     OMX_U32 mProfile;
221     OMX_U32 mLevel;
222 };
223 
224 }  // namespace android
225 
226 #endif  // ANDROID_IOMX_H_
227