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