IOMX.h revision e40cda70eec141fa05cbcca1de420fdb22b98be6
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
30namespace android {
31
32class IMemory;
33class IOMXObserver;
34class IOMXRenderer;
35class Surface;
36
37class IOMX : public IInterface {
38public:
39    DECLARE_META_INTERFACE(OMX);
40
41    typedef void *buffer_id;
42    typedef void *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 enableGraphicBuffers(
87            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
88
89    virtual status_t getGraphicBufferUsage(
90            node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
91
92    virtual status_t useBuffer(
93            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
94            buffer_id *buffer) = 0;
95
96    virtual status_t useGraphicBuffer(
97            node_id node, OMX_U32 port_index,
98            const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
99
100    virtual status_t createInputSurface(
101            node_id node, OMX_U32 port_index,
102            sp<IGraphicBufferProducer> *bufferProducer) = 0;
103
104    virtual status_t signalEndOfInputStream(node_id node) = 0;
105
106    // This API clearly only makes sense if the caller lives in the
107    // same process as the callee, i.e. is the media_server, as the
108    // returned "buffer_data" pointer is just that, a pointer into local
109    // address space.
110    virtual status_t allocateBuffer(
111            node_id node, OMX_U32 port_index, size_t size,
112            buffer_id *buffer, void **buffer_data) = 0;
113
114    virtual status_t allocateBufferWithBackup(
115            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
116            buffer_id *buffer) = 0;
117
118    virtual status_t freeBuffer(
119            node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
120
121    virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
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) = 0;
128
129    virtual status_t getExtensionIndex(
130            node_id node,
131            const char *parameter_name,
132            OMX_INDEXTYPE *index) = 0;
133
134    enum InternalOptionType {
135        INTERNAL_OPTION_SUSPEND,  // data is a bool
136    };
137    virtual status_t setInternalOption(
138            node_id node,
139            OMX_U32 port_index,
140            InternalOptionType type,
141            const void *data,
142            size_t size) = 0;
143};
144
145struct omx_message {
146    enum {
147        EVENT,
148        EMPTY_BUFFER_DONE,
149        FILL_BUFFER_DONE,
150
151    } type;
152
153    IOMX::node_id node;
154
155    union {
156        // if type == EVENT
157        struct {
158            OMX_EVENTTYPE event;
159            OMX_U32 data1;
160            OMX_U32 data2;
161        } event_data;
162
163        // if type == EMPTY_BUFFER_DONE
164        struct {
165            IOMX::buffer_id buffer;
166        } buffer_data;
167
168        // if type == FILL_BUFFER_DONE
169        struct {
170            IOMX::buffer_id buffer;
171            OMX_U32 range_offset;
172            OMX_U32 range_length;
173            OMX_U32 flags;
174            OMX_TICKS timestamp;
175            OMX_PTR platform_private;
176            OMX_PTR data_ptr;
177        } extended_buffer_data;
178
179    } u;
180};
181
182class IOMXObserver : public IInterface {
183public:
184    DECLARE_META_INTERFACE(OMXObserver);
185
186    virtual void onMessage(const omx_message &msg) = 0;
187};
188
189////////////////////////////////////////////////////////////////////////////////
190
191class BnOMX : public BnInterface<IOMX> {
192public:
193    virtual status_t onTransact(
194            uint32_t code, const Parcel &data, Parcel *reply,
195            uint32_t flags = 0);
196};
197
198class BnOMXObserver : public BnInterface<IOMXObserver> {
199public:
200    virtual status_t onTransact(
201            uint32_t code, const Parcel &data, Parcel *reply,
202            uint32_t flags = 0);
203};
204
205struct CodecProfileLevel {
206    OMX_U32 mProfile;
207    OMX_U32 mLevel;
208};
209
210}  // namespace android
211
212#endif  // ANDROID_IOMX_H_
213