blob: d38c17759b058c7e4815e3ac05b53e7ccae92c7e [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 Huber318ad9c2009-10-15 13:46:54 -070085 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070086 node_id node, OMX_U32 port_index, size_t size,
87 buffer_id *buffer) = 0;
88
Andreas Huber318ad9c2009-10-15 13:46:54 -070089 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -070090 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
91 buffer_id *buffer) = 0;
92
Andreas Huber318ad9c2009-10-15 13:46:54 -070093 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070094 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
95
Andreas Huber318ad9c2009-10-15 13:46:54 -070096 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070097
Andreas Huber318ad9c2009-10-15 13:46:54 -070098 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070099 node_id node,
100 buffer_id buffer,
101 OMX_U32 range_offset, OMX_U32 range_length,
102 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700103
Andreas Huber318ad9c2009-10-15 13:46:54 -0700104 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700105 node_id node,
106 const char *parameter_name,
107 OMX_INDEXTYPE *index) = 0;
108
Andreas Huber8b938cd2009-07-31 11:52:50 -0700109 virtual sp<IOMXRenderer> createRenderer(
110 const sp<ISurface> &surface,
111 const char *componentName,
112 OMX_COLOR_FORMATTYPE colorFormat,
113 size_t encodedWidth, size_t encodedHeight,
114 size_t displayWidth, size_t displayHeight) = 0;
Andreas Huberf4148b52009-08-07 12:01:29 -0700115
Andreas Huber1b84df12009-09-15 12:49:11 -0700116 // Note: These methods are _not_ virtual, it exists as a wrapper around
Andreas Huberf4148b52009-08-07 12:01:29 -0700117 // the virtual "createRenderer" method above facilitating extraction
Andreas Huber1b84df12009-09-15 12:49:11 -0700118 // of the ISurface from a regular Surface or a java Surface object.
Andreas Huberf4148b52009-08-07 12:01:29 -0700119 sp<IOMXRenderer> createRenderer(
120 const sp<Surface> &surface,
121 const char *componentName,
122 OMX_COLOR_FORMATTYPE colorFormat,
123 size_t encodedWidth, size_t encodedHeight,
124 size_t displayWidth, size_t displayHeight);
Andreas Huber1b84df12009-09-15 12:49:11 -0700125
126 sp<IOMXRenderer> createRendererFromJavaSurface(
127 JNIEnv *env, jobject javaSurface,
128 const char *componentName,
129 OMX_COLOR_FORMATTYPE colorFormat,
130 size_t encodedWidth, size_t encodedHeight,
131 size_t displayWidth, size_t displayHeight);
Andreas Huber20111aa2009-07-14 16:56:47 -0700132};
133
134struct omx_message {
135 enum {
136 EVENT,
137 EMPTY_BUFFER_DONE,
138 FILL_BUFFER_DONE,
139
Andreas Huber20111aa2009-07-14 16:56:47 -0700140 } type;
141
Andreas Huber693d2712009-08-14 14:37:10 -0700142 IOMX::node_id node;
143
Andreas Huber20111aa2009-07-14 16:56:47 -0700144 union {
145 // if type == EVENT
146 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700147 OMX_EVENTTYPE event;
148 OMX_U32 data1;
149 OMX_U32 data2;
150 } event_data;
151
Andreas Hubere0f0b082009-08-27 14:50:58 -0700152 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700153 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700154 IOMX::buffer_id buffer;
155 } buffer_data;
156
Andreas Hubere0f0b082009-08-27 14:50:58 -0700157 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700158 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700159 IOMX::buffer_id buffer;
160 OMX_U32 range_offset;
161 OMX_U32 range_length;
162 OMX_U32 flags;
163 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700164 OMX_PTR platform_private;
Andreas Huber20111aa2009-07-14 16:56:47 -0700165 } extended_buffer_data;
166
Andreas Huber20111aa2009-07-14 16:56:47 -0700167 } u;
168};
169
170class IOMXObserver : public IInterface {
171public:
172 DECLARE_META_INTERFACE(OMXObserver);
173
Andreas Huber318ad9c2009-10-15 13:46:54 -0700174 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700175};
176
Andreas Huber8b938cd2009-07-31 11:52:50 -0700177class IOMXRenderer : public IInterface {
178public:
179 DECLARE_META_INTERFACE(OMXRenderer);
180
181 virtual void render(IOMX::buffer_id buffer) = 0;
182};
183
Andreas Huber20111aa2009-07-14 16:56:47 -0700184////////////////////////////////////////////////////////////////////////////////
185
186class BnOMX : public BnInterface<IOMX> {
187public:
188 virtual status_t onTransact(
189 uint32_t code, const Parcel &data, Parcel *reply,
190 uint32_t flags = 0);
191};
192
193class BnOMXObserver : public BnInterface<IOMXObserver> {
194public:
195 virtual status_t onTransact(
196 uint32_t code, const Parcel &data, Parcel *reply,
197 uint32_t flags = 0);
198};
199
Andreas Huber8b938cd2009-07-31 11:52:50 -0700200class BnOMXRenderer : public BnInterface<IOMXRenderer> {
201public:
202 virtual status_t onTransact(
203 uint32_t code, const Parcel &data, Parcel *reply,
204 uint32_t flags = 0);
205};
206
Andreas Huber20111aa2009-07-14 16:56:47 -0700207} // namespace android
208
209#endif // ANDROID_IOMX_H_