blob: 1f8ce71a595b88a4df8af52df13c8f560d53a83a [file] [log] [blame]
Andreas Huber20111aa2009-07-14 16:56:47 -07001/*
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>
Jamie Gennis83750ea2010-08-30 16:48:38 -070022#include <ui/GraphicBuffer.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070023#include <utils/List.h>
24#include <utils/String8.h>
25
26#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070027#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070028
Andreas Huber1b84df12009-09-15 12:49:11 -070029#include "jni.h"
30
Andreas Huber20111aa2009-07-14 16:56:47 -070031namespace android {
32
33class IMemory;
34class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070035class IOMXRenderer;
36class ISurface;
Andreas Huberf4148b52009-08-07 12:01:29 -070037class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070038
39class IOMX : public IInterface {
40public:
41 DECLARE_META_INTERFACE(OMX);
42
43 typedef void *buffer_id;
44 typedef void *node_id;
45
Andreas Huber7eaa9c92010-01-15 15:28:19 -080046 // 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
Andreas Huber134ee6a2009-12-16 09:30:55 -080051 struct ComponentInfo {
52 String8 mName;
53 List<String8> mRoles;
54 };
55 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070056
Andreas Huber318ad9c2009-10-15 13:46:54 -070057 virtual status_t allocateNode(
58 const char *name, const sp<IOMXObserver> &observer,
59 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070060
Andreas Huber318ad9c2009-10-15 13:46:54 -070061 virtual status_t freeNode(node_id node) = 0;
62
63 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070064 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
65
Andreas Huber318ad9c2009-10-15 13:46:54 -070066 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070067 node_id node, OMX_INDEXTYPE index,
68 void *params, size_t size) = 0;
69
Andreas Huber318ad9c2009-10-15 13:46:54 -070070 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070071 node_id node, OMX_INDEXTYPE index,
72 const void *params, size_t size) = 0;
73
Andreas Huber318ad9c2009-10-15 13:46:54 -070074 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070075 node_id node, OMX_INDEXTYPE index,
76 void *params, size_t size) = 0;
77
Andreas Huber318ad9c2009-10-15 13:46:54 -070078 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070079 node_id node, OMX_INDEXTYPE index,
80 const void *params, size_t size) = 0;
81
Jamie Gennis83750ea2010-08-30 16:48:38 -070082 virtual status_t enableGraphicBuffers(
83 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
84
Andreas Huber318ad9c2009-10-15 13:46:54 -070085 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070086 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
87 buffer_id *buffer) = 0;
88
Jamie Gennis83750ea2010-08-30 16:48:38 -070089 virtual status_t useGraphicBuffer(
90 node_id node, OMX_U32 port_index,
91 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
92
Andreas Huber570a3cb2010-01-20 15:05:46 -080093 // This API clearly only makes sense if the caller lives in the
94 // same process as the callee, i.e. is the media_server, as the
95 // returned "buffer_data" pointer is just that, a pointer into local
96 // address space.
Andreas Huber318ad9c2009-10-15 13:46:54 -070097 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070098 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -080099 buffer_id *buffer, void **buffer_data) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700100
Andreas Huber318ad9c2009-10-15 13:46:54 -0700101 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700102 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
103 buffer_id *buffer) = 0;
104
Andreas Huber318ad9c2009-10-15 13:46:54 -0700105 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700106 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
107
Andreas Huber318ad9c2009-10-15 13:46:54 -0700108 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700109
Andreas Huber318ad9c2009-10-15 13:46:54 -0700110 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700111 node_id node,
112 buffer_id buffer,
113 OMX_U32 range_offset, OMX_U32 range_length,
114 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700115
Andreas Huber318ad9c2009-10-15 13:46:54 -0700116 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700117 node_id node,
118 const char *parameter_name,
119 OMX_INDEXTYPE *index) = 0;
120
Andreas Huber8b938cd2009-07-31 11:52:50 -0700121 virtual sp<IOMXRenderer> createRenderer(
122 const sp<ISurface> &surface,
123 const char *componentName,
124 OMX_COLOR_FORMATTYPE colorFormat,
125 size_t encodedWidth, size_t encodedHeight,
126 size_t displayWidth, size_t displayHeight) = 0;
Andreas Huberf4148b52009-08-07 12:01:29 -0700127
Andreas Huber1b84df12009-09-15 12:49:11 -0700128 // Note: These methods are _not_ virtual, it exists as a wrapper around
Andreas Huberf4148b52009-08-07 12:01:29 -0700129 // the virtual "createRenderer" method above facilitating extraction
Andreas Huber1b84df12009-09-15 12:49:11 -0700130 // of the ISurface from a regular Surface or a java Surface object.
Andreas Huberf4148b52009-08-07 12:01:29 -0700131 sp<IOMXRenderer> createRenderer(
132 const sp<Surface> &surface,
133 const char *componentName,
134 OMX_COLOR_FORMATTYPE colorFormat,
135 size_t encodedWidth, size_t encodedHeight,
136 size_t displayWidth, size_t displayHeight);
Andreas Huber1b84df12009-09-15 12:49:11 -0700137
138 sp<IOMXRenderer> createRendererFromJavaSurface(
139 JNIEnv *env, jobject javaSurface,
140 const char *componentName,
141 OMX_COLOR_FORMATTYPE colorFormat,
142 size_t encodedWidth, size_t encodedHeight,
143 size_t displayWidth, size_t displayHeight);
Andreas Huber20111aa2009-07-14 16:56:47 -0700144};
145
146struct omx_message {
147 enum {
148 EVENT,
149 EMPTY_BUFFER_DONE,
150 FILL_BUFFER_DONE,
151
Andreas Huber20111aa2009-07-14 16:56:47 -0700152 } type;
153
Andreas Huber693d2712009-08-14 14:37:10 -0700154 IOMX::node_id node;
155
Andreas Huber20111aa2009-07-14 16:56:47 -0700156 union {
157 // if type == EVENT
158 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700159 OMX_EVENTTYPE event;
160 OMX_U32 data1;
161 OMX_U32 data2;
162 } event_data;
163
Andreas Hubere0f0b082009-08-27 14:50:58 -0700164 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700165 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700166 IOMX::buffer_id buffer;
167 } buffer_data;
168
Andreas Hubere0f0b082009-08-27 14:50:58 -0700169 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700170 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700171 IOMX::buffer_id buffer;
172 OMX_U32 range_offset;
173 OMX_U32 range_length;
174 OMX_U32 flags;
175 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700176 OMX_PTR platform_private;
Andreas Huber213addf2010-01-25 10:41:35 -0800177 OMX_PTR data_ptr;
Andreas Huber20111aa2009-07-14 16:56:47 -0700178 } extended_buffer_data;
179
Andreas Huber20111aa2009-07-14 16:56:47 -0700180 } u;
181};
182
183class IOMXObserver : public IInterface {
184public:
185 DECLARE_META_INTERFACE(OMXObserver);
186
Andreas Huber318ad9c2009-10-15 13:46:54 -0700187 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700188};
189
Andreas Huber8b938cd2009-07-31 11:52:50 -0700190class IOMXRenderer : public IInterface {
191public:
192 DECLARE_META_INTERFACE(OMXRenderer);
193
194 virtual void render(IOMX::buffer_id buffer) = 0;
195};
196
Andreas Huber20111aa2009-07-14 16:56:47 -0700197////////////////////////////////////////////////////////////////////////////////
198
199class BnOMX : public BnInterface<IOMX> {
200public:
201 virtual status_t onTransact(
202 uint32_t code, const Parcel &data, Parcel *reply,
203 uint32_t flags = 0);
204};
205
206class BnOMXObserver : public BnInterface<IOMXObserver> {
207public:
208 virtual status_t onTransact(
209 uint32_t code, const Parcel &data, Parcel *reply,
210 uint32_t flags = 0);
211};
212
Andreas Huber8b938cd2009-07-31 11:52:50 -0700213class BnOMXRenderer : public BnInterface<IOMXRenderer> {
214public:
215 virtual status_t onTransact(
216 uint32_t code, const Parcel &data, Parcel *reply,
217 uint32_t flags = 0);
218};
219
Andreas Huber20111aa2009-07-14 16:56:47 -0700220} // namespace android
221
222#endif // ANDROID_IOMX_H_