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