blob: 58a74c7e0b6cfabb4180a99a3d1e112a7137fff0 [file] [log] [blame]
Andreas Hubere46b7be2009-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 Huber1de13162009-07-31 11:52:50 -070026#include <OMX_Video.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070027
Andreas Hubere46b7be2009-07-14 16:56:47 -070028namespace android {
29
30class IMemory;
31class IOMXObserver;
Andreas Huber1de13162009-07-31 11:52:50 -070032class IOMXRenderer;
33class ISurface;
Andreas Huberccf8b942009-08-07 12:01:29 -070034class Surface;
Andreas Hubere46b7be2009-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 Hubere46b7be2009-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 Huberbe06d262009-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 Hubere46b7be2009-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 Hubere46b7be2009-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 Huber1de13162009-07-31 11:52:50 -070092
Andreas Huberbe06d262009-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 Huber1de13162009-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 Huberccf8b942009-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 Hubere46b7be2009-07-14 16:56:47 -0700114};
115
116struct omx_message {
117 enum {
118 EVENT,
119 EMPTY_BUFFER_DONE,
120 FILL_BUFFER_DONE,
121
Andreas Hubere46b7be2009-07-14 16:56:47 -0700122 // reserved for OMXDecoder use.
123 START,
124 INITIAL_FILL_BUFFER,
125
126 // reserved for OMXObserver use.
127 QUIT_OBSERVER,
128 } type;
129
Andreas Huberbe06d262009-08-14 14:37:10 -0700130 IOMX::node_id node;
131
Andreas Hubere46b7be2009-07-14 16:56:47 -0700132 union {
133 // if type == EVENT
134 struct {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700135 OMX_EVENTTYPE event;
136 OMX_U32 data1;
137 OMX_U32 data2;
138 } event_data;
139
140 // if type == EMPTY_BUFFER_DONE || type == FILL_BUFFER
141 // || type == INITIAL_FILL_BUFFER
142 struct {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700143 IOMX::buffer_id buffer;
144 } buffer_data;
145
146 // if type == EMPTY_BUFFER || type == FILL_BUFFER_DONE
147 struct {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700148 IOMX::buffer_id buffer;
149 OMX_U32 range_offset;
150 OMX_U32 range_length;
151 OMX_U32 flags;
152 OMX_TICKS timestamp;
153 OMX_PTR platform_private; // ignored if type == EMPTY_BUFFER
154 } extended_buffer_data;
155
156 // if type == SEND_COMMAND
157 struct {
Andreas Hubere46b7be2009-07-14 16:56:47 -0700158 OMX_COMMANDTYPE cmd;
159 OMX_S32 param;
160 } send_command_data;
161
162 } u;
163};
164
165class IOMXObserver : public IInterface {
166public:
167 DECLARE_META_INTERFACE(OMXObserver);
168
169 virtual void on_message(const omx_message &msg) = 0;
170};
171
Andreas Huber1de13162009-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 Hubere46b7be2009-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 Huber1de13162009-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 Hubere46b7be2009-07-14 16:56:47 -0700202} // namespace android
203
204#endif // ANDROID_IOMX_H_