blob: 2f61cbe1cabda611118921c939617176e38b3447 [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>
22#include <utils/List.h>
23#include <utils/String8.h>
24
25#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070026#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070027
Andreas Huber1b84df12009-09-15 12:49:11 -070028#include "jni.h"
29
Andreas Huber20111aa2009-07-14 16:56:47 -070030namespace android {
31
32class IMemory;
33class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070034class IOMXRenderer;
35class ISurface;
Andreas Huberf4148b52009-08-07 12:01:29 -070036class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070037
38class IOMX : public IInterface {
39public:
40 DECLARE_META_INTERFACE(OMX);
41
42 typedef void *buffer_id;
43 typedef void *node_id;
44
Andreas Huber7eaa9c92010-01-15 15:28:19 -080045 // Given the calling process' pid, returns true iff
46 // the implementation of the OMX interface lives in the same
47 // process.
48 virtual bool livesLocally(pid_t pid) = 0;
49
Andreas Huber134ee6a2009-12-16 09:30:55 -080050 struct ComponentInfo {
51 String8 mName;
52 List<String8> mRoles;
53 };
54 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070055
Andreas Huber318ad9c2009-10-15 13:46:54 -070056 virtual status_t allocateNode(
57 const char *name, const sp<IOMXObserver> &observer,
58 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070059
Andreas Huber318ad9c2009-10-15 13:46:54 -070060 virtual status_t freeNode(node_id node) = 0;
61
62 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070063 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
64
Andreas Huber318ad9c2009-10-15 13:46:54 -070065 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070066 node_id node, OMX_INDEXTYPE index,
67 void *params, size_t size) = 0;
68
Andreas Huber318ad9c2009-10-15 13:46:54 -070069 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070070 node_id node, OMX_INDEXTYPE index,
71 const void *params, size_t size) = 0;
72
Andreas Huber318ad9c2009-10-15 13:46:54 -070073 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070074 node_id node, OMX_INDEXTYPE index,
75 void *params, size_t size) = 0;
76
Andreas Huber318ad9c2009-10-15 13:46:54 -070077 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070078 node_id node, OMX_INDEXTYPE index,
79 const void *params, size_t size) = 0;
80
Andreas Huber318ad9c2009-10-15 13:46:54 -070081 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070082 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
83 buffer_id *buffer) = 0;
84
Andreas Huber570a3cb2010-01-20 15:05:46 -080085 // This API clearly only makes sense if the caller lives in the
86 // same process as the callee, i.e. is the media_server, as the
87 // returned "buffer_data" pointer is just that, a pointer into local
88 // address space.
Andreas Huber318ad9c2009-10-15 13:46:54 -070089 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070090 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -080091 buffer_id *buffer, void **buffer_data) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070092
Andreas Huber318ad9c2009-10-15 13:46:54 -070093 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -070094 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
95 buffer_id *buffer) = 0;
96
Andreas Huber318ad9c2009-10-15 13:46:54 -070097 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070098 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
99
Andreas Huber318ad9c2009-10-15 13:46:54 -0700100 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700101
Andreas Huber318ad9c2009-10-15 13:46:54 -0700102 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700103 node_id node,
104 buffer_id buffer,
105 OMX_U32 range_offset, OMX_U32 range_length,
106 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700107
Andreas Huber318ad9c2009-10-15 13:46:54 -0700108 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700109 node_id node,
110 const char *parameter_name,
111 OMX_INDEXTYPE *index) = 0;
112
Andreas Huber8b938cd2009-07-31 11:52:50 -0700113 virtual sp<IOMXRenderer> createRenderer(
114 const sp<ISurface> &surface,
115 const char *componentName,
116 OMX_COLOR_FORMATTYPE colorFormat,
117 size_t encodedWidth, size_t encodedHeight,
118 size_t displayWidth, size_t displayHeight) = 0;
Andreas Huberf4148b52009-08-07 12:01:29 -0700119
Andreas Huber1b84df12009-09-15 12:49:11 -0700120 // Note: These methods are _not_ virtual, it exists as a wrapper around
Andreas Huberf4148b52009-08-07 12:01:29 -0700121 // the virtual "createRenderer" method above facilitating extraction
Andreas Huber1b84df12009-09-15 12:49:11 -0700122 // of the ISurface from a regular Surface or a java Surface object.
Andreas Huberf4148b52009-08-07 12:01:29 -0700123 sp<IOMXRenderer> createRenderer(
124 const sp<Surface> &surface,
125 const char *componentName,
126 OMX_COLOR_FORMATTYPE colorFormat,
127 size_t encodedWidth, size_t encodedHeight,
128 size_t displayWidth, size_t displayHeight);
Andreas Huber1b84df12009-09-15 12:49:11 -0700129
130 sp<IOMXRenderer> createRendererFromJavaSurface(
131 JNIEnv *env, jobject javaSurface,
132 const char *componentName,
133 OMX_COLOR_FORMATTYPE colorFormat,
134 size_t encodedWidth, size_t encodedHeight,
135 size_t displayWidth, size_t displayHeight);
Andreas Huber20111aa2009-07-14 16:56:47 -0700136};
137
138struct omx_message {
139 enum {
140 EVENT,
141 EMPTY_BUFFER_DONE,
142 FILL_BUFFER_DONE,
143
Andreas Huber20111aa2009-07-14 16:56:47 -0700144 } type;
145
Andreas Huber693d2712009-08-14 14:37:10 -0700146 IOMX::node_id node;
147
Andreas Huber20111aa2009-07-14 16:56:47 -0700148 union {
149 // if type == EVENT
150 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700151 OMX_EVENTTYPE event;
152 OMX_U32 data1;
153 OMX_U32 data2;
154 } event_data;
155
Andreas Hubere0f0b082009-08-27 14:50:58 -0700156 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700157 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700158 IOMX::buffer_id buffer;
159 } buffer_data;
160
Andreas Hubere0f0b082009-08-27 14:50:58 -0700161 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700162 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700163 IOMX::buffer_id buffer;
164 OMX_U32 range_offset;
165 OMX_U32 range_length;
166 OMX_U32 flags;
167 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700168 OMX_PTR platform_private;
Andreas Huber213addf2010-01-25 10:41:35 -0800169 OMX_PTR data_ptr;
Andreas Huber20111aa2009-07-14 16:56:47 -0700170 } extended_buffer_data;
171
Andreas Huber20111aa2009-07-14 16:56:47 -0700172 } u;
173};
174
175class IOMXObserver : public IInterface {
176public:
177 DECLARE_META_INTERFACE(OMXObserver);
178
Andreas Huber318ad9c2009-10-15 13:46:54 -0700179 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700180};
181
Andreas Huber8b938cd2009-07-31 11:52:50 -0700182class IOMXRenderer : public IInterface {
183public:
184 DECLARE_META_INTERFACE(OMXRenderer);
185
186 virtual void render(IOMX::buffer_id buffer) = 0;
187};
188
Andreas Huber20111aa2009-07-14 16:56:47 -0700189////////////////////////////////////////////////////////////////////////////////
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
Andreas Huber8b938cd2009-07-31 11:52:50 -0700205class BnOMXRenderer : public BnInterface<IOMXRenderer> {
206public:
207 virtual status_t onTransact(
208 uint32_t code, const Parcel &data, Parcel *reply,
209 uint32_t flags = 0);
210};
211
Andreas Huber20111aa2009-07-14 16:56:47 -0700212} // namespace android
213
214#endif // ANDROID_IOMX_H_