blob: 39bd5b17d2687d4ed4e3153ba8624e3a1950b15b [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 Huber134ee6a2009-12-16 09:30:55 -080045 struct ComponentInfo {
46 String8 mName;
47 List<String8> mRoles;
48 };
49 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070050
Andreas Huber318ad9c2009-10-15 13:46:54 -070051 virtual status_t allocateNode(
52 const char *name, const sp<IOMXObserver> &observer,
53 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070054
Andreas Huber318ad9c2009-10-15 13:46:54 -070055 virtual status_t freeNode(node_id node) = 0;
56
57 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070058 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
59
Andreas Huber318ad9c2009-10-15 13:46:54 -070060 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070061 node_id node, OMX_INDEXTYPE index,
62 void *params, size_t size) = 0;
63
Andreas Huber318ad9c2009-10-15 13:46:54 -070064 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070065 node_id node, OMX_INDEXTYPE index,
66 const void *params, size_t size) = 0;
67
Andreas Huber318ad9c2009-10-15 13:46:54 -070068 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070069 node_id node, OMX_INDEXTYPE index,
70 void *params, size_t size) = 0;
71
Andreas Huber318ad9c2009-10-15 13:46:54 -070072 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070073 node_id node, OMX_INDEXTYPE index,
74 const void *params, size_t size) = 0;
75
Andreas Huber318ad9c2009-10-15 13:46:54 -070076 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070077 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
78 buffer_id *buffer) = 0;
79
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070081 node_id node, OMX_U32 port_index, size_t size,
82 buffer_id *buffer) = 0;
83
Andreas Huber318ad9c2009-10-15 13:46:54 -070084 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -070085 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
86 buffer_id *buffer) = 0;
87
Andreas Huber318ad9c2009-10-15 13:46:54 -070088 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070089 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
90
Andreas Huber318ad9c2009-10-15 13:46:54 -070091 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070092
Andreas Huber318ad9c2009-10-15 13:46:54 -070093 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070094 node_id node,
95 buffer_id buffer,
96 OMX_U32 range_offset, OMX_U32 range_length,
97 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -070098
Andreas Huber318ad9c2009-10-15 13:46:54 -070099 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700100 node_id node,
101 const char *parameter_name,
102 OMX_INDEXTYPE *index) = 0;
103
Andreas Huber8b938cd2009-07-31 11:52:50 -0700104 virtual sp<IOMXRenderer> createRenderer(
105 const sp<ISurface> &surface,
106 const char *componentName,
107 OMX_COLOR_FORMATTYPE colorFormat,
108 size_t encodedWidth, size_t encodedHeight,
109 size_t displayWidth, size_t displayHeight) = 0;
Andreas Huberf4148b52009-08-07 12:01:29 -0700110
Andreas Huber1b84df12009-09-15 12:49:11 -0700111 // Note: These methods are _not_ virtual, it exists as a wrapper around
Andreas Huberf4148b52009-08-07 12:01:29 -0700112 // the virtual "createRenderer" method above facilitating extraction
Andreas Huber1b84df12009-09-15 12:49:11 -0700113 // of the ISurface from a regular Surface or a java Surface object.
Andreas Huberf4148b52009-08-07 12:01:29 -0700114 sp<IOMXRenderer> createRenderer(
115 const sp<Surface> &surface,
116 const char *componentName,
117 OMX_COLOR_FORMATTYPE colorFormat,
118 size_t encodedWidth, size_t encodedHeight,
119 size_t displayWidth, size_t displayHeight);
Andreas Huber1b84df12009-09-15 12:49:11 -0700120
121 sp<IOMXRenderer> createRendererFromJavaSurface(
122 JNIEnv *env, jobject javaSurface,
123 const char *componentName,
124 OMX_COLOR_FORMATTYPE colorFormat,
125 size_t encodedWidth, size_t encodedHeight,
126 size_t displayWidth, size_t displayHeight);
Andreas Huber20111aa2009-07-14 16:56:47 -0700127};
128
129struct omx_message {
130 enum {
131 EVENT,
132 EMPTY_BUFFER_DONE,
133 FILL_BUFFER_DONE,
134
Andreas Huber20111aa2009-07-14 16:56:47 -0700135 } type;
136
Andreas Huber693d2712009-08-14 14:37:10 -0700137 IOMX::node_id node;
138
Andreas Huber20111aa2009-07-14 16:56:47 -0700139 union {
140 // if type == EVENT
141 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700142 OMX_EVENTTYPE event;
143 OMX_U32 data1;
144 OMX_U32 data2;
145 } event_data;
146
Andreas Hubere0f0b082009-08-27 14:50:58 -0700147 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700148 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700149 IOMX::buffer_id buffer;
150 } buffer_data;
151
Andreas Hubere0f0b082009-08-27 14:50:58 -0700152 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700153 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700154 IOMX::buffer_id buffer;
155 OMX_U32 range_offset;
156 OMX_U32 range_length;
157 OMX_U32 flags;
158 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700159 OMX_PTR platform_private;
Andreas Huber20111aa2009-07-14 16:56:47 -0700160 } extended_buffer_data;
161
Andreas Huber20111aa2009-07-14 16:56:47 -0700162 } u;
163};
164
165class IOMXObserver : public IInterface {
166public:
167 DECLARE_META_INTERFACE(OMXObserver);
168
Andreas Huber318ad9c2009-10-15 13:46:54 -0700169 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700170};
171
Andreas Huber8b938cd2009-07-31 11:52:50 -0700172class IOMXRenderer : public IInterface {
173public:
174 DECLARE_META_INTERFACE(OMXRenderer);
175
176 virtual void render(IOMX::buffer_id buffer) = 0;
177};
178
Andreas Huber20111aa2009-07-14 16:56:47 -0700179////////////////////////////////////////////////////////////////////////////////
180
181class BnOMX : public BnInterface<IOMX> {
182public:
183 virtual status_t onTransact(
184 uint32_t code, const Parcel &data, Parcel *reply,
185 uint32_t flags = 0);
186};
187
188class BnOMXObserver : public BnInterface<IOMXObserver> {
189public:
190 virtual status_t onTransact(
191 uint32_t code, const Parcel &data, Parcel *reply,
192 uint32_t flags = 0);
193};
194
Andreas Huber8b938cd2009-07-31 11:52:50 -0700195class BnOMXRenderer : public BnInterface<IOMXRenderer> {
196public:
197 virtual status_t onTransact(
198 uint32_t code, const Parcel &data, Parcel *reply,
199 uint32_t flags = 0);
200};
201
Andreas Huber20111aa2009-07-14 16:56:47 -0700202} // namespace android
203
204#endif // ANDROID_IOMX_H_