blob: 84fdf83d29f3bb3d6ed9bed1fcc0d2ebc85a4b92 [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>
Andy McFadden7cd58532013-02-19 07:28:30 -080022#include <gui/IGraphicBufferProducer.h>
Chong Zhangd291c222015-04-30 18:15:52 -070023#include <gui/IGraphicBufferConsumer.h>
Jamie Gennis83750ea2010-08-30 16:48:38 -070024#include <ui/GraphicBuffer.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070025#include <utils/List.h>
26#include <utils/String8.h>
27
Lajos Molnar05421982015-05-15 20:39:14 -070028#include <media/hardware/MetadataBufferType.h>
29
Andreas Huber20111aa2009-07-14 16:56:47 -070030#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070031#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070032
Andreas Huber20111aa2009-07-14 16:56:47 -070033namespace android {
34
35class IMemory;
36class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070037class IOMXRenderer;
Andreas Huberf4148b52009-08-07 12:01:29 -070038class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070039
40class IOMX : public IInterface {
41public:
42 DECLARE_META_INTERFACE(OMX);
43
Andy Hung609b8152014-05-02 11:05:04 -070044 typedef uint32_t buffer_id;
45 typedef uint32_t node_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070046
Andreas Huberd459b482012-01-31 11:16:24 -080047 // Given a node_id and the calling process' pid, returns true iff
Andreas Huber7eaa9c92010-01-15 15:28:19 -080048 // the implementation of the OMX interface lives in the same
49 // process.
Andreas Huberd459b482012-01-31 11:16:24 -080050 virtual bool livesLocally(node_id node, pid_t pid) = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080051
Andreas Huber134ee6a2009-12-16 09:30:55 -080052 struct ComponentInfo {
53 String8 mName;
54 List<String8> mRoles;
55 };
56 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070057
Andreas Huber318ad9c2009-10-15 13:46:54 -070058 virtual status_t allocateNode(
59 const char *name, const sp<IOMXObserver> &observer,
60 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070061
Andreas Huber318ad9c2009-10-15 13:46:54 -070062 virtual status_t freeNode(node_id node) = 0;
63
64 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070065 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
66
Andreas Huber318ad9c2009-10-15 13:46:54 -070067 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070068 node_id node, OMX_INDEXTYPE index,
69 void *params, size_t size) = 0;
70
Andreas Huber318ad9c2009-10-15 13:46:54 -070071 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070072 node_id node, OMX_INDEXTYPE index,
73 const void *params, size_t size) = 0;
74
Andreas Huber318ad9c2009-10-15 13:46:54 -070075 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070076 node_id node, OMX_INDEXTYPE index,
77 void *params, size_t size) = 0;
78
Andreas Huber318ad9c2009-10-15 13:46:54 -070079 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070080 node_id node, OMX_INDEXTYPE index,
81 const void *params, size_t size) = 0;
82
Jamie Gennisb1d666f2011-10-19 21:14:13 -070083 virtual status_t getState(
84 node_id node, OMX_STATETYPE* state) = 0;
85
Lajos Molnar05421982015-05-15 20:39:14 -070086 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
87 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -070088 virtual status_t storeMetaDataInBuffers(
Lajos Molnar05421982015-05-15 20:39:14 -070089 node_id node, OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -070090
Lajos Molnar56ce7262013-05-02 16:30:48 -070091 virtual status_t prepareForAdaptivePlayback(
92 node_id node, OMX_U32 portIndex, OMX_BOOL enable,
93 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
94
Lajos Molnar15ab4992015-06-01 10:54:31 -070095 virtual status_t configureVideoTunnelMode(
Rachad5a446aa2014-07-29 16:47:56 -070096 node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
97 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
98
Jamie Gennis83750ea2010-08-30 16:48:38 -070099 virtual status_t enableGraphicBuffers(
100 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
101
Jamie Gennise2ce6452011-02-23 19:01:28 -0800102 virtual status_t getGraphicBufferUsage(
103 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
104
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700105 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700106 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700107 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700108 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700109
Jamie Gennis83750ea2010-08-30 16:48:38 -0700110 virtual status_t useGraphicBuffer(
111 node_id node, OMX_U32 port_index,
112 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
113
Lajos Molnard0715862013-07-22 12:57:43 -0700114 virtual status_t updateGraphicBufferInMeta(
115 node_id node, OMX_U32 port_index,
116 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
117
Lajos Molnar05421982015-05-15 20:39:14 -0700118 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
119 // well as on success.
Andy McFadden7cd58532013-02-19 07:28:30 -0800120 virtual status_t createInputSurface(
121 node_id node, OMX_U32 port_index,
Lajos Molnar05421982015-05-15 20:39:14 -0700122 sp<IGraphicBufferProducer> *bufferProducer,
123 MetadataBufferType *type = NULL) = 0;
Andy McFadden7cd58532013-02-19 07:28:30 -0800124
Chong Zhangd291c222015-04-30 18:15:52 -0700125 virtual status_t createPersistentInputSurface(
126 sp<IGraphicBufferProducer> *bufferProducer,
127 sp<IGraphicBufferConsumer> *bufferConsumer) = 0;
128
Lajos Molnar05421982015-05-15 20:39:14 -0700129 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
130 // well as on success.
Chong Zhang8f469e12015-05-13 10:21:33 -0700131 virtual status_t setInputSurface(
Chong Zhangd291c222015-04-30 18:15:52 -0700132 node_id node, OMX_U32 port_index,
Lajos Molnar05421982015-05-15 20:39:14 -0700133 const sp<IGraphicBufferConsumer> &bufferConsumer,
134 MetadataBufferType *type) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700135
Andy McFadden7cd58532013-02-19 07:28:30 -0800136 virtual status_t signalEndOfInputStream(node_id node) = 0;
137
Andreas Huber570a3cb2010-01-20 15:05:46 -0800138 // This API clearly only makes sense if the caller lives in the
139 // same process as the callee, i.e. is the media_server, as the
140 // returned "buffer_data" pointer is just that, a pointer into local
141 // address space.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700142 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700143 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800144 buffer_id *buffer, void **buffer_data) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700145
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700146 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
147 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700148 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700149 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700150 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700151
Andreas Huber318ad9c2009-10-15 13:46:54 -0700152 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700153 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
154
Lajos Molnar15ab4992015-06-01 10:54:31 -0700155 enum {
156 kFenceTimeoutMs = 1000
157 };
158 // Calls OMX_FillBuffer on buffer, and passes |fenceFd| to component if it supports
159 // fences. Otherwise, it waits on |fenceFd| before calling OMX_FillBuffer.
160 // Takes ownership of |fenceFd| even if this call fails.
161 virtual status_t fillBuffer(node_id node, buffer_id buffer, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700162
Lajos Molnar15ab4992015-06-01 10:54:31 -0700163 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with |range_offset|,
164 // |range_length|, |flags| and |timestamp|). Passes |fenceFd| to component if it
165 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
166 // Takes ownership of |fenceFd| even if this call fails.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700167 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700168 node_id node,
169 buffer_id buffer,
170 OMX_U32 range_offset, OMX_U32 range_length,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700171 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700172
Andreas Huber318ad9c2009-10-15 13:46:54 -0700173 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700174 node_id node,
175 const char *parameter_name,
176 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700177
178 enum InternalOptionType {
179 INTERNAL_OPTION_SUSPEND, // data is a bool
Andreas Hubera61285d2013-07-31 13:50:42 -0700180 INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t
Chong Zhang94ee4b72014-01-10 17:36:57 -0800181 INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
Ronghua Wu37b2b382015-01-26 15:47:10 -0800182 INTERNAL_OPTION_MAX_FPS, // data is float
Chong Zhang72cecca2013-12-26 01:38:35 -0800183 INTERNAL_OPTION_START_TIME, // data is an int64_t
Chong Zhang2c9c8cb2014-02-11 13:54:59 -0800184 INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2]
Andreas Hubere40cda72013-07-17 13:55:26 -0700185 };
186 virtual status_t setInternalOption(
187 node_id node,
188 OMX_U32 port_index,
189 InternalOptionType type,
190 const void *data,
191 size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700192};
193
194struct omx_message {
195 enum {
196 EVENT,
197 EMPTY_BUFFER_DONE,
198 FILL_BUFFER_DONE,
199
Andreas Huber20111aa2009-07-14 16:56:47 -0700200 } type;
201
Andreas Huber693d2712009-08-14 14:37:10 -0700202 IOMX::node_id node;
Lajos Molnar15ab4992015-06-01 10:54:31 -0700203 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700204
Andreas Huber20111aa2009-07-14 16:56:47 -0700205 union {
206 // if type == EVENT
207 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700208 OMX_EVENTTYPE event;
209 OMX_U32 data1;
210 OMX_U32 data2;
211 } event_data;
212
Andreas Hubere0f0b082009-08-27 14:50:58 -0700213 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700214 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700215 IOMX::buffer_id buffer;
216 } buffer_data;
217
Andreas Hubere0f0b082009-08-27 14:50:58 -0700218 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700219 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700220 IOMX::buffer_id buffer;
221 OMX_U32 range_offset;
222 OMX_U32 range_length;
223 OMX_U32 flags;
224 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700225 } extended_buffer_data;
226
Andreas Huber20111aa2009-07-14 16:56:47 -0700227 } u;
228};
229
230class IOMXObserver : public IInterface {
231public:
232 DECLARE_META_INTERFACE(OMXObserver);
233
Andreas Huber318ad9c2009-10-15 13:46:54 -0700234 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700235};
236
237////////////////////////////////////////////////////////////////////////////////
238
239class BnOMX : public BnInterface<IOMX> {
240public:
241 virtual status_t onTransact(
242 uint32_t code, const Parcel &data, Parcel *reply,
243 uint32_t flags = 0);
244};
245
246class BnOMXObserver : public BnInterface<IOMXObserver> {
247public:
248 virtual status_t onTransact(
249 uint32_t code, const Parcel &data, Parcel *reply,
250 uint32_t flags = 0);
251};
252
James Dong457116d2011-07-11 12:29:10 -0700253struct CodecProfileLevel {
254 OMX_U32 mProfile;
255 OMX_U32 mLevel;
256};
257
Andreas Huber20111aa2009-07-14 16:56:47 -0700258} // namespace android
259
Lajos Molnar05421982015-05-15 20:39:14 -0700260inline static const char *asString(android::MetadataBufferType i, const char *def = "??") {
261 using namespace android;
262 switch (i) {
263 case kMetadataBufferTypeCameraSource: return "CameraSource";
264 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
265 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
266 case kMetadataBufferTypeInvalid: return "Invalid";
267 default: return def;
268 }
269}
270
Andreas Huber20111aa2009-07-14 16:56:47 -0700271#endif // ANDROID_IOMX_H_