blob: 0014d5c5e3b064f12f68ec75b7e346ab32ca5a98 [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 Huber20111aa2009-07-14 16:56:47 -070028namespace android {
29
30class IMemory;
31class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070032class IOMXRenderer;
33class ISurface;
Andreas Huberf4148b52009-08-07 12:01:29 -070034class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070035
36class IOMX : public IInterface {
37public:
38 DECLARE_META_INTERFACE(OMX);
39
40 typedef void *buffer_id;
41 typedef void *node_id;
42
Andreas Huber20111aa2009-07-14 16:56:47 -070043 virtual status_t list_nodes(List<String8> *list) = 0;
44
45 virtual status_t allocate_node(const char *name, node_id *node) = 0;
46 virtual status_t free_node(node_id node) = 0;
47
48 virtual status_t send_command(
49 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
50
51 virtual status_t get_parameter(
52 node_id node, OMX_INDEXTYPE index,
53 void *params, size_t size) = 0;
54
55 virtual status_t set_parameter(
56 node_id node, OMX_INDEXTYPE index,
57 const void *params, size_t size) = 0;
58
Andreas Huber693d2712009-08-14 14:37:10 -070059 virtual status_t get_config(
60 node_id node, OMX_INDEXTYPE index,
61 void *params, size_t size) = 0;
62
63 virtual status_t set_config(
64 node_id node, OMX_INDEXTYPE index,
65 const void *params, size_t size) = 0;
66
Andreas Huber20111aa2009-07-14 16:56:47 -070067 virtual status_t use_buffer(
68 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
69 buffer_id *buffer) = 0;
70
71 virtual status_t allocate_buffer(
72 node_id node, OMX_U32 port_index, size_t size,
73 buffer_id *buffer) = 0;
74
75 virtual status_t allocate_buffer_with_backup(
76 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
77 buffer_id *buffer) = 0;
78
79 virtual status_t free_buffer(
80 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
81
Andreas Huber20111aa2009-07-14 16:56:47 -070082 virtual status_t observe_node(
83 node_id node, const sp<IOMXObserver> &observer) = 0;
84
85 virtual void fill_buffer(node_id node, buffer_id buffer) = 0;
86
87 virtual void empty_buffer(
88 node_id node,
89 buffer_id buffer,
90 OMX_U32 range_offset, OMX_U32 range_length,
91 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -070092
Andreas Huber693d2712009-08-14 14:37:10 -070093 virtual status_t get_extension_index(
94 node_id node,
95 const char *parameter_name,
96 OMX_INDEXTYPE *index) = 0;
97
Andreas Huber8b938cd2009-07-31 11:52:50 -070098 virtual sp<IOMXRenderer> createRenderer(
99 const sp<ISurface> &surface,
100 const char *componentName,
101 OMX_COLOR_FORMATTYPE colorFormat,
102 size_t encodedWidth, size_t encodedHeight,
103 size_t displayWidth, size_t displayHeight) = 0;
Andreas Huberf4148b52009-08-07 12:01:29 -0700104
105 // Note: This method is _not_ virtual, it exists as a wrapper around
106 // the virtual "createRenderer" method above facilitating extraction
107 // of the ISurface from a regular Surface.
108 sp<IOMXRenderer> createRenderer(
109 const sp<Surface> &surface,
110 const char *componentName,
111 OMX_COLOR_FORMATTYPE colorFormat,
112 size_t encodedWidth, size_t encodedHeight,
113 size_t displayWidth, size_t displayHeight);
Andreas Huber20111aa2009-07-14 16:56:47 -0700114};
115
116struct omx_message {
117 enum {
118 EVENT,
119 EMPTY_BUFFER_DONE,
120 FILL_BUFFER_DONE,
121
Andreas Huber20111aa2009-07-14 16:56:47 -0700122 } type;
123
Andreas Huber693d2712009-08-14 14:37:10 -0700124 IOMX::node_id node;
125
Andreas Huber20111aa2009-07-14 16:56:47 -0700126 union {
127 // if type == EVENT
128 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700129 OMX_EVENTTYPE event;
130 OMX_U32 data1;
131 OMX_U32 data2;
132 } event_data;
133
Andreas Hubere0f0b082009-08-27 14:50:58 -0700134 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700135 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700136 IOMX::buffer_id buffer;
137 } buffer_data;
138
Andreas Hubere0f0b082009-08-27 14:50:58 -0700139 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700140 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700141 IOMX::buffer_id buffer;
142 OMX_U32 range_offset;
143 OMX_U32 range_length;
144 OMX_U32 flags;
145 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700146 OMX_PTR platform_private;
Andreas Huber20111aa2009-07-14 16:56:47 -0700147 } extended_buffer_data;
148
Andreas Huber20111aa2009-07-14 16:56:47 -0700149 } u;
150};
151
152class IOMXObserver : public IInterface {
153public:
154 DECLARE_META_INTERFACE(OMXObserver);
155
156 virtual void on_message(const omx_message &msg) = 0;
157};
158
Andreas Huber8b938cd2009-07-31 11:52:50 -0700159class IOMXRenderer : public IInterface {
160public:
161 DECLARE_META_INTERFACE(OMXRenderer);
162
163 virtual void render(IOMX::buffer_id buffer) = 0;
164};
165
Andreas Huber20111aa2009-07-14 16:56:47 -0700166////////////////////////////////////////////////////////////////////////////////
167
168class BnOMX : public BnInterface<IOMX> {
169public:
170 virtual status_t onTransact(
171 uint32_t code, const Parcel &data, Parcel *reply,
172 uint32_t flags = 0);
173};
174
175class BnOMXObserver : public BnInterface<IOMXObserver> {
176public:
177 virtual status_t onTransact(
178 uint32_t code, const Parcel &data, Parcel *reply,
179 uint32_t flags = 0);
180};
181
Andreas Huber8b938cd2009-07-31 11:52:50 -0700182class BnOMXRenderer : public BnInterface<IOMXRenderer> {
183public:
184 virtual status_t onTransact(
185 uint32_t code, const Parcel &data, Parcel *reply,
186 uint32_t flags = 0);
187};
188
Andreas Huber20111aa2009-07-14 16:56:47 -0700189} // namespace android
190
191#endif // ANDROID_IOMX_H_