blob: f971ee221104687e441b53c1fde842dd6f809fd0 [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 Molnar26a48f32015-06-04 10:30:02 -070028#include <list>
29
Lajos Molnar05421982015-05-15 20:39:14 -070030#include <media/hardware/MetadataBufferType.h>
31
Andreas Huber20111aa2009-07-14 16:56:47 -070032#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070033#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070034
Andreas Huber20111aa2009-07-14 16:56:47 -070035namespace android {
36
37class IMemory;
38class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070039class IOMXRenderer;
Lajos Molnar1b40f282016-05-09 22:24:52 -070040class NativeHandle;
Andreas Huberf4148b52009-08-07 12:01:29 -070041class Surface;
Chong Zhang6cf9a122016-09-08 23:25:52 -070042struct omx_message;
Andreas Huber20111aa2009-07-14 16:56:47 -070043
44class IOMX : public IInterface {
45public:
46 DECLARE_META_INTERFACE(OMX);
47
Andy Hung609b8152014-05-02 11:05:04 -070048 typedef uint32_t buffer_id;
49 typedef uint32_t node_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070050
Andreas Huberd459b482012-01-31 11:16:24 -080051 // Given a node_id and the calling process' pid, returns true iff
Andreas Huber7eaa9c92010-01-15 15:28:19 -080052 // the implementation of the OMX interface lives in the same
53 // process.
Andreas Huberd459b482012-01-31 11:16:24 -080054 virtual bool livesLocally(node_id node, pid_t pid) = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080055
Andreas Huber134ee6a2009-12-16 09:30:55 -080056 struct ComponentInfo {
57 String8 mName;
58 List<String8> mRoles;
59 };
60 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070061
Andreas Huber318ad9c2009-10-15 13:46:54 -070062 virtual status_t allocateNode(
63 const char *name, const sp<IOMXObserver> &observer,
Marco Nelissen23858872016-02-17 13:12:13 -080064 sp<IBinder> *nodeBinder,
Andreas Huber318ad9c2009-10-15 13:46:54 -070065 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070066
Andreas Huber318ad9c2009-10-15 13:46:54 -070067 virtual status_t freeNode(node_id node) = 0;
68
69 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070070 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
71
Andreas Huber318ad9c2009-10-15 13:46:54 -070072 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070073 node_id node, OMX_INDEXTYPE index,
74 void *params, size_t size) = 0;
75
Andreas Huber318ad9c2009-10-15 13:46:54 -070076 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070077 node_id node, OMX_INDEXTYPE index,
78 const void *params, size_t size) = 0;
79
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070081 node_id node, OMX_INDEXTYPE index,
82 void *params, size_t size) = 0;
83
Andreas Huber318ad9c2009-10-15 13:46:54 -070084 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070085 node_id node, OMX_INDEXTYPE index,
86 const void *params, size_t size) = 0;
87
Jamie Gennisb1d666f2011-10-19 21:14:13 -070088 virtual status_t getState(
89 node_id node, OMX_STATETYPE* state) = 0;
90
Lajos Molnar05421982015-05-15 20:39:14 -070091 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
92 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -070093 virtual status_t storeMetaDataInBuffers(
Lajos Molnar05421982015-05-15 20:39:14 -070094 node_id node, OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -070095
Lajos Molnar56ce7262013-05-02 16:30:48 -070096 virtual status_t prepareForAdaptivePlayback(
97 node_id node, OMX_U32 portIndex, OMX_BOOL enable,
98 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
99
Lajos Molnar15ab4992015-06-01 10:54:31 -0700100 virtual status_t configureVideoTunnelMode(
Rachad5a446aa2014-07-29 16:47:56 -0700101 node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
102 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
103
Lajos Molnara63141a2016-02-11 16:40:36 -0800104 virtual status_t enableNativeBuffers(
105 node_id node, OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;
Jamie Gennis83750ea2010-08-30 16:48:38 -0700106
Jamie Gennise2ce6452011-02-23 19:01:28 -0800107 virtual status_t getGraphicBufferUsage(
108 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
109
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700110 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700111 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700112 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700113 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700114
Jamie Gennis83750ea2010-08-30 16:48:38 -0700115 virtual status_t useGraphicBuffer(
116 node_id node, OMX_U32 port_index,
117 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
118
Lajos Molnard0715862013-07-22 12:57:43 -0700119 virtual status_t updateGraphicBufferInMeta(
120 node_id node, OMX_U32 port_index,
121 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
122
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700123 virtual status_t updateNativeHandleInMeta(
124 node_id node, OMX_U32 port_index,
125 const sp<NativeHandle> &nativeHandle, buffer_id buffer) = 0;
126
Lajos Molnar05421982015-05-15 20:39:14 -0700127 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
128 // well as on success.
Andy McFadden7cd58532013-02-19 07:28:30 -0800129 virtual status_t createInputSurface(
Lajos Molnar57fad3c2016-03-08 13:09:35 -0800130 node_id node, OMX_U32 port_index, android_dataspace dataSpace,
Lajos Molnar05421982015-05-15 20:39:14 -0700131 sp<IGraphicBufferProducer> *bufferProducer,
132 MetadataBufferType *type = NULL) = 0;
Andy McFadden7cd58532013-02-19 07:28:30 -0800133
Chong Zhangd291c222015-04-30 18:15:52 -0700134 virtual status_t createPersistentInputSurface(
135 sp<IGraphicBufferProducer> *bufferProducer,
136 sp<IGraphicBufferConsumer> *bufferConsumer) = 0;
137
Lajos Molnar05421982015-05-15 20:39:14 -0700138 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
139 // well as on success.
Chong Zhang8f469e12015-05-13 10:21:33 -0700140 virtual status_t setInputSurface(
Chong Zhangd291c222015-04-30 18:15:52 -0700141 node_id node, OMX_U32 port_index,
Lajos Molnar05421982015-05-15 20:39:14 -0700142 const sp<IGraphicBufferConsumer> &bufferConsumer,
143 MetadataBufferType *type) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700144
Andy McFadden7cd58532013-02-19 07:28:30 -0800145 virtual status_t signalEndOfInputStream(node_id node) = 0;
146
Lajos Molnara63141a2016-02-11 16:40:36 -0800147 // Allocate an opaque buffer as a native handle. If component supports returning native
148 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
149 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
150 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
151 // pointer is just that, a pointer into local address space.
152 virtual status_t allocateSecureBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700153 node_id node, OMX_U32 port_index, size_t size,
Lajos Molnar1b40f282016-05-09 22:24:52 -0700154 buffer_id *buffer, void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700155
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700156 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
157 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700158 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700159 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700160 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700161
Andreas Huber318ad9c2009-10-15 13:46:54 -0700162 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700163 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
164
Lajos Molnar15ab4992015-06-01 10:54:31 -0700165 enum {
166 kFenceTimeoutMs = 1000
167 };
168 // Calls OMX_FillBuffer on buffer, and passes |fenceFd| to component if it supports
169 // fences. Otherwise, it waits on |fenceFd| before calling OMX_FillBuffer.
170 // Takes ownership of |fenceFd| even if this call fails.
171 virtual status_t fillBuffer(node_id node, buffer_id buffer, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700172
Lajos Molnar15ab4992015-06-01 10:54:31 -0700173 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with |range_offset|,
174 // |range_length|, |flags| and |timestamp|). Passes |fenceFd| to component if it
175 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
176 // Takes ownership of |fenceFd| even if this call fails.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700177 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700178 node_id node,
179 buffer_id buffer,
180 OMX_U32 range_offset, OMX_U32 range_length,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700181 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700182
Chong Zhang6cf9a122016-09-08 23:25:52 -0700183 virtual status_t emptyGraphicBuffer(
184 node_id node,
185 buffer_id buffer,
186 const sp<GraphicBuffer> &graphicBuffer,
187 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd) = 0;
188
Andreas Huber318ad9c2009-10-15 13:46:54 -0700189 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700190 node_id node,
191 const char *parameter_name,
192 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700193
194 enum InternalOptionType {
195 INTERNAL_OPTION_SUSPEND, // data is a bool
Andreas Hubera61285d2013-07-31 13:50:42 -0700196 INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t
Chong Zhang94ee4b72014-01-10 17:36:57 -0800197 INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
Ronghua Wu37b2b382015-01-26 15:47:10 -0800198 INTERNAL_OPTION_MAX_FPS, // data is float
Chong Zhang72cecca2013-12-26 01:38:35 -0800199 INTERNAL_OPTION_START_TIME, // data is an int64_t
Chong Zhang2c9c8cb2014-02-11 13:54:59 -0800200 INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2]
Lajos Molnardd81af72016-03-10 18:19:18 -0800201 INTERNAL_OPTION_COLOR_ASPECTS, // data is ColorAspects
Hangyu Kuang61fcfd12016-08-30 13:50:58 -0700202 INTERNAL_OPTION_TIME_OFFSET, // data is an int64_t
Andreas Hubere40cda72013-07-17 13:55:26 -0700203 };
204 virtual status_t setInternalOption(
205 node_id node,
206 OMX_U32 port_index,
207 InternalOptionType type,
208 const void *data,
209 size_t size) = 0;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700210
211 virtual status_t dispatchMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700212};
213
214struct omx_message {
215 enum {
216 EVENT,
217 EMPTY_BUFFER_DONE,
218 FILL_BUFFER_DONE,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700219 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700220 } type;
221
Andreas Huber693d2712009-08-14 14:37:10 -0700222 IOMX::node_id node;
Lajos Molnar15ab4992015-06-01 10:54:31 -0700223 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700224
Andreas Huber20111aa2009-07-14 16:56:47 -0700225 union {
226 // if type == EVENT
227 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700228 OMX_EVENTTYPE event;
229 OMX_U32 data1;
230 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700231 OMX_U32 data3;
232 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700233 } event_data;
234
Andreas Hubere0f0b082009-08-27 14:50:58 -0700235 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700236 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700237 IOMX::buffer_id buffer;
238 } buffer_data;
239
Andreas Hubere0f0b082009-08-27 14:50:58 -0700240 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700241 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700242 IOMX::buffer_id buffer;
243 OMX_U32 range_offset;
244 OMX_U32 range_length;
245 OMX_U32 flags;
246 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700247 } extended_buffer_data;
248
Lajos Molnar90fcf682015-06-04 10:29:19 -0700249 // if type == FRAME_RENDERED
250 struct {
251 OMX_TICKS timestamp;
252 OMX_S64 nanoTime;
253 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700254 } u;
255};
256
257class IOMXObserver : public IInterface {
258public:
259 DECLARE_META_INTERFACE(OMXObserver);
260
Lajos Molnar26a48f32015-06-04 10:30:02 -0700261 // Handle (list of) messages.
262 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700263};
264
265////////////////////////////////////////////////////////////////////////////////
266
267class BnOMX : public BnInterface<IOMX> {
268public:
269 virtual status_t onTransact(
270 uint32_t code, const Parcel &data, Parcel *reply,
271 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700272
273protected:
274 // check if the codec is secure.
275 virtual bool isSecure(IOMX::node_id node) {
276 return false;
277 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700278};
279
280class BnOMXObserver : public BnInterface<IOMXObserver> {
281public:
282 virtual status_t onTransact(
283 uint32_t code, const Parcel &data, Parcel *reply,
284 uint32_t flags = 0);
285};
286
James Dong457116d2011-07-11 12:29:10 -0700287struct CodecProfileLevel {
288 OMX_U32 mProfile;
289 OMX_U32 mLevel;
290};
291
Lajos Molnar3e328782016-05-09 10:56:46 -0700292inline static const char *asString(MetadataBufferType i, const char *def = "??") {
Lajos Molnar05421982015-05-15 20:39:14 -0700293 using namespace android;
294 switch (i) {
295 case kMetadataBufferTypeCameraSource: return "CameraSource";
296 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
297 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
Lajos Molnar3e328782016-05-09 10:56:46 -0700298 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
Lajos Molnar05421982015-05-15 20:39:14 -0700299 case kMetadataBufferTypeInvalid: return "Invalid";
300 default: return def;
301 }
302}
303
Lajos Molnar3e328782016-05-09 10:56:46 -0700304} // namespace android
305
Andreas Huber20111aa2009-07-14 16:56:47 -0700306#endif // ANDROID_IOMX_H_