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