blob: e551d179f6990238fbc3cbc5e95175adec5bad71 [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 Huber20111aa2009-07-14 16:56:47 -070045 virtual status_t list_nodes(List<String8> *list) = 0;
46
47 virtual status_t allocate_node(const char *name, node_id *node) = 0;
48 virtual status_t free_node(node_id node) = 0;
49
50 virtual status_t send_command(
51 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
52
53 virtual status_t get_parameter(
54 node_id node, OMX_INDEXTYPE index,
55 void *params, size_t size) = 0;
56
57 virtual status_t set_parameter(
58 node_id node, OMX_INDEXTYPE index,
59 const void *params, size_t size) = 0;
60
Andreas Huber693d2712009-08-14 14:37:10 -070061 virtual status_t get_config(
62 node_id node, OMX_INDEXTYPE index,
63 void *params, size_t size) = 0;
64
65 virtual status_t set_config(
66 node_id node, OMX_INDEXTYPE index,
67 const void *params, size_t size) = 0;
68
Andreas Huber20111aa2009-07-14 16:56:47 -070069 virtual status_t use_buffer(
70 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
71 buffer_id *buffer) = 0;
72
73 virtual status_t allocate_buffer(
74 node_id node, OMX_U32 port_index, size_t size,
75 buffer_id *buffer) = 0;
76
77 virtual status_t allocate_buffer_with_backup(
78 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
79 buffer_id *buffer) = 0;
80
81 virtual status_t free_buffer(
82 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
83
Andreas Huber20111aa2009-07-14 16:56:47 -070084 virtual status_t observe_node(
85 node_id node, const sp<IOMXObserver> &observer) = 0;
86
Andreas Huber36efa032009-10-08 11:02:27 -070087 virtual status_t fill_buffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070088
Andreas Huber36efa032009-10-08 11:02:27 -070089 virtual status_t empty_buffer(
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 Huber693d2712009-08-14 14:37:10 -070095 virtual status_t get_extension_index(
96 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
165 virtual void on_message(const omx_message &msg) = 0;
166};
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_