blob: 6f3ba1cfcbba2cef82c2d183dffdb633ce7e8fef [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 Huber318ad9c2009-10-15 13:46:54 -070045 virtual status_t listNodes(List<String8> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070046
Andreas Huber318ad9c2009-10-15 13:46:54 -070047 virtual status_t allocateNode(
48 const char *name, const sp<IOMXObserver> &observer,
49 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070050
Andreas Huber318ad9c2009-10-15 13:46:54 -070051 virtual status_t freeNode(node_id node) = 0;
52
53 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070054 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
55
Andreas Huber318ad9c2009-10-15 13:46:54 -070056 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070057 node_id node, OMX_INDEXTYPE index,
58 void *params, size_t size) = 0;
59
Andreas Huber318ad9c2009-10-15 13:46:54 -070060 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070061 node_id node, OMX_INDEXTYPE index,
62 const void *params, size_t size) = 0;
63
Andreas Huber318ad9c2009-10-15 13:46:54 -070064 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070065 node_id node, OMX_INDEXTYPE index,
66 void *params, size_t size) = 0;
67
Andreas Huber318ad9c2009-10-15 13:46:54 -070068 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070069 node_id node, OMX_INDEXTYPE index,
70 const void *params, size_t size) = 0;
71
Andreas Huber318ad9c2009-10-15 13:46:54 -070072 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070073 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
74 buffer_id *buffer) = 0;
75
Andreas Huber318ad9c2009-10-15 13:46:54 -070076 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070077 node_id node, OMX_U32 port_index, size_t size,
78 buffer_id *buffer) = 0;
79
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -070081 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
82 buffer_id *buffer) = 0;
83
Andreas Huber318ad9c2009-10-15 13:46:54 -070084 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070085 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
86
Andreas Huber318ad9c2009-10-15 13:46:54 -070087 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070088
Andreas Huber318ad9c2009-10-15 13:46:54 -070089 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070090 node_id node,
91 buffer_id buffer,
92 OMX_U32 range_offset, OMX_U32 range_length,
93 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -070094
Andreas Huber318ad9c2009-10-15 13:46:54 -070095 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -070096 node_id node,
97 const char *parameter_name,
98 OMX_INDEXTYPE *index) = 0;
99
Andreas Huber8b938cd2009-07-31 11:52:50 -0700100 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;
Andreas Huberf4148b52009-08-07 12:01:29 -0700106
Andreas Huber1b84df12009-09-15 12:49:11 -0700107 // Note: These methods are _not_ virtual, it exists as a wrapper around
Andreas Huberf4148b52009-08-07 12:01:29 -0700108 // the virtual "createRenderer" method above facilitating extraction
Andreas Huber1b84df12009-09-15 12:49:11 -0700109 // of the ISurface from a regular Surface or a java Surface object.
Andreas Huberf4148b52009-08-07 12:01:29 -0700110 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);
Andreas Huber1b84df12009-09-15 12:49:11 -0700116
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);
Andreas Huber20111aa2009-07-14 16:56:47 -0700123};
124
125struct omx_message {
126 enum {
127 EVENT,
128 EMPTY_BUFFER_DONE,
129 FILL_BUFFER_DONE,
130
Andreas Huber20111aa2009-07-14 16:56:47 -0700131 } type;
132
Andreas Huber693d2712009-08-14 14:37:10 -0700133 IOMX::node_id node;
134
Andreas Huber20111aa2009-07-14 16:56:47 -0700135 union {
136 // if type == EVENT
137 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700138 OMX_EVENTTYPE event;
139 OMX_U32 data1;
140 OMX_U32 data2;
141 } event_data;
142
Andreas Hubere0f0b082009-08-27 14:50:58 -0700143 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700144 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700145 IOMX::buffer_id buffer;
146 } buffer_data;
147
Andreas Hubere0f0b082009-08-27 14:50:58 -0700148 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700149 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700150 IOMX::buffer_id buffer;
151 OMX_U32 range_offset;
152 OMX_U32 range_length;
153 OMX_U32 flags;
154 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700155 OMX_PTR platform_private;
Andreas Huber20111aa2009-07-14 16:56:47 -0700156 } extended_buffer_data;
157
Andreas Huber20111aa2009-07-14 16:56:47 -0700158 } u;
159};
160
161class IOMXObserver : public IInterface {
162public:
163 DECLARE_META_INTERFACE(OMXObserver);
164
Andreas Huber318ad9c2009-10-15 13:46:54 -0700165 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700166};
167
Andreas Huber8b938cd2009-07-31 11:52:50 -0700168class IOMXRenderer : public IInterface {
169public:
170 DECLARE_META_INTERFACE(OMXRenderer);
171
172 virtual void render(IOMX::buffer_id buffer) = 0;
173};
174
Andreas Huber20111aa2009-07-14 16:56:47 -0700175////////////////////////////////////////////////////////////////////////////////
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
Andreas Huber8b938cd2009-07-31 11:52:50 -0700191class 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
Andreas Huber20111aa2009-07-14 16:56:47 -0700198} // namespace android
199
200#endif // ANDROID_IOMX_H_