blob: c0c48c12e6b3d3c51bb1aa28104ffdfcec05185a [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
Chong Zhang6d332d22016-09-07 12:06:50 -070037class IGraphicBufferSource;
Andreas Huber20111aa2009-07-14 16:56:47 -070038class IMemory;
39class IOMXObserver;
Lajos Molnar1b40f282016-05-09 22:24:52 -070040class NativeHandle;
Chong Zhang6cf9a122016-09-08 23:25:52 -070041struct omx_message;
Andreas Huber20111aa2009-07-14 16:56:47 -070042
43class IOMX : public IInterface {
44public:
45 DECLARE_META_INTERFACE(OMX);
46
Andy Hung609b8152014-05-02 11:05:04 -070047 typedef uint32_t buffer_id;
48 typedef uint32_t node_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070049
Andreas Huberd459b482012-01-31 11:16:24 -080050 // Given a node_id and the calling process' pid, returns true iff
Andreas Huber7eaa9c92010-01-15 15:28:19 -080051 // the implementation of the OMX interface lives in the same
52 // process.
Andreas Huberd459b482012-01-31 11:16:24 -080053 virtual bool livesLocally(node_id node, pid_t pid) = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080054
Andreas Huber134ee6a2009-12-16 09:30:55 -080055 struct ComponentInfo {
56 String8 mName;
57 List<String8> mRoles;
58 };
59 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070060
Andreas Huber318ad9c2009-10-15 13:46:54 -070061 virtual status_t allocateNode(
62 const char *name, const sp<IOMXObserver> &observer,
Marco Nelissen23858872016-02-17 13:12:13 -080063 sp<IBinder> *nodeBinder,
Andreas Huber318ad9c2009-10-15 13:46:54 -070064 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070065
Andreas Huber318ad9c2009-10-15 13:46:54 -070066 virtual status_t freeNode(node_id node) = 0;
67
68 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070069 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
70
Andreas Huber318ad9c2009-10-15 13:46:54 -070071 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070072 node_id node, OMX_INDEXTYPE index,
73 void *params, size_t size) = 0;
74
Andreas Huber318ad9c2009-10-15 13:46:54 -070075 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070076 node_id node, OMX_INDEXTYPE index,
77 const void *params, size_t size) = 0;
78
Andreas Huber318ad9c2009-10-15 13:46:54 -070079 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070080 node_id node, OMX_INDEXTYPE index,
81 void *params, size_t size) = 0;
82
Andreas Huber318ad9c2009-10-15 13:46:54 -070083 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070084 node_id node, OMX_INDEXTYPE index,
85 const void *params, size_t size) = 0;
86
Jamie Gennisb1d666f2011-10-19 21:14:13 -070087 virtual status_t getState(
88 node_id node, OMX_STATETYPE* state) = 0;
89
Lajos Molnar05421982015-05-15 20:39:14 -070090 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
91 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -070092 virtual status_t storeMetaDataInBuffers(
Lajos Molnar05421982015-05-15 20:39:14 -070093 node_id node, OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -070094
Lajos Molnar56ce7262013-05-02 16:30:48 -070095 virtual status_t prepareForAdaptivePlayback(
96 node_id node, OMX_U32 portIndex, OMX_BOOL enable,
97 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
98
Lajos Molnar15ab4992015-06-01 10:54:31 -070099 virtual status_t configureVideoTunnelMode(
Rachad5a446aa2014-07-29 16:47:56 -0700100 node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
101 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
102
Lajos Molnara63141a2016-02-11 16:40:36 -0800103 virtual status_t enableNativeBuffers(
104 node_id node, OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;
Jamie Gennis83750ea2010-08-30 16:48:38 -0700105
Jamie Gennise2ce6452011-02-23 19:01:28 -0800106 virtual status_t getGraphicBufferUsage(
107 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
108
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700109 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700110 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700111 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700112 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700113
Jamie Gennis83750ea2010-08-30 16:48:38 -0700114 virtual status_t useGraphicBuffer(
115 node_id node, OMX_U32 port_index,
116 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
117
Lajos Molnard0715862013-07-22 12:57:43 -0700118 virtual status_t updateGraphicBufferInMeta(
119 node_id node, OMX_U32 port_index,
120 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
121
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700122 virtual status_t updateNativeHandleInMeta(
123 node_id node, OMX_U32 port_index,
124 const sp<NativeHandle> &nativeHandle, buffer_id buffer) = 0;
125
Lajos Molnar05421982015-05-15 20:39:14 -0700126 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
127 // well as on success.
Andy McFadden7cd58532013-02-19 07:28:30 -0800128 virtual status_t createInputSurface(
Lajos Molnar57fad3c2016-03-08 13:09:35 -0800129 node_id node, OMX_U32 port_index, android_dataspace dataSpace,
Lajos Molnar05421982015-05-15 20:39:14 -0700130 sp<IGraphicBufferProducer> *bufferProducer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700131 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700132 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,
Chong Zhang6d332d22016-09-07 12:06:50 -0700143 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700144 MetadataBufferType *type) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700145
Lajos Molnara63141a2016-02-11 16:40:36 -0800146 // Allocate an opaque buffer as a native handle. If component supports returning native
147 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
148 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
149 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
150 // pointer is just that, a pointer into local address space.
151 virtual status_t allocateSecureBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700152 node_id node, OMX_U32 port_index, size_t size,
Lajos Molnar1b40f282016-05-09 22:24:52 -0700153 buffer_id *buffer, void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700154
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700155 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
156 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700157 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700158 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700159 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700160
Andreas Huber318ad9c2009-10-15 13:46:54 -0700161 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700162 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
163
Lajos Molnar15ab4992015-06-01 10:54:31 -0700164 enum {
165 kFenceTimeoutMs = 1000
166 };
167 // Calls OMX_FillBuffer on buffer, and passes |fenceFd| to component if it supports
168 // fences. Otherwise, it waits on |fenceFd| before calling OMX_FillBuffer.
169 // Takes ownership of |fenceFd| even if this call fails.
170 virtual status_t fillBuffer(node_id node, buffer_id buffer, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700171
Lajos Molnar15ab4992015-06-01 10:54:31 -0700172 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with |range_offset|,
173 // |range_length|, |flags| and |timestamp|). Passes |fenceFd| to component if it
174 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
175 // Takes ownership of |fenceFd| even if this call fails.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700176 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700177 node_id node,
178 buffer_id buffer,
179 OMX_U32 range_offset, OMX_U32 range_length,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700180 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700181
Chong Zhang6d332d22016-09-07 12:06:50 -0700182 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with metadata of
183 // |graphicBuffer|, |flags| and |timestamp|). Passes |fenceFd| to component if it
184 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
185 // Takes ownership of |fenceFd| even if this call fails. If |origTimestamp| >= 0,
186 // timestamp on the filled buffer corresponding to this frame will be modified to
187 // |origTimestamp| after it's filled.
Chong Zhang6cf9a122016-09-08 23:25:52 -0700188 virtual status_t emptyGraphicBuffer(
189 node_id node,
190 buffer_id buffer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700191 const sp<GraphicBuffer> &graphicBuffer, OMX_U32 flags,
192 OMX_TICKS timestamp, OMX_TICKS origTimestamp, int fenceFd) = 0;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700193
Andreas Huber318ad9c2009-10-15 13:46:54 -0700194 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700195 node_id node,
196 const char *parameter_name,
197 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700198
Chong Zhang6cf9a122016-09-08 23:25:52 -0700199 virtual status_t dispatchMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700200};
201
202struct omx_message {
203 enum {
204 EVENT,
205 EMPTY_BUFFER_DONE,
206 FILL_BUFFER_DONE,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700207 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700208 } type;
209
Andreas Huber693d2712009-08-14 14:37:10 -0700210 IOMX::node_id node;
Lajos Molnar15ab4992015-06-01 10:54:31 -0700211 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700212
Andreas Huber20111aa2009-07-14 16:56:47 -0700213 union {
214 // if type == EVENT
215 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700216 OMX_EVENTTYPE event;
217 OMX_U32 data1;
218 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700219 OMX_U32 data3;
220 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700221 } event_data;
222
Andreas Hubere0f0b082009-08-27 14:50:58 -0700223 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700224 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700225 IOMX::buffer_id buffer;
226 } buffer_data;
227
Andreas Hubere0f0b082009-08-27 14:50:58 -0700228 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700229 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700230 IOMX::buffer_id buffer;
231 OMX_U32 range_offset;
232 OMX_U32 range_length;
233 OMX_U32 flags;
234 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700235 } extended_buffer_data;
236
Lajos Molnar90fcf682015-06-04 10:29:19 -0700237 // if type == FRAME_RENDERED
238 struct {
239 OMX_TICKS timestamp;
240 OMX_S64 nanoTime;
241 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700242 } u;
243};
244
245class IOMXObserver : public IInterface {
246public:
247 DECLARE_META_INTERFACE(OMXObserver);
248
Lajos Molnar26a48f32015-06-04 10:30:02 -0700249 // Handle (list of) messages.
250 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700251};
252
253////////////////////////////////////////////////////////////////////////////////
254
255class BnOMX : public BnInterface<IOMX> {
256public:
257 virtual status_t onTransact(
258 uint32_t code, const Parcel &data, Parcel *reply,
259 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700260
261protected:
262 // check if the codec is secure.
263 virtual bool isSecure(IOMX::node_id node) {
264 return false;
265 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700266};
267
268class BnOMXObserver : public BnInterface<IOMXObserver> {
269public:
270 virtual status_t onTransact(
271 uint32_t code, const Parcel &data, Parcel *reply,
272 uint32_t flags = 0);
273};
274
James Dong457116d2011-07-11 12:29:10 -0700275struct CodecProfileLevel {
276 OMX_U32 mProfile;
277 OMX_U32 mLevel;
278};
279
Lajos Molnar3e328782016-05-09 10:56:46 -0700280inline static const char *asString(MetadataBufferType i, const char *def = "??") {
Lajos Molnar05421982015-05-15 20:39:14 -0700281 using namespace android;
282 switch (i) {
283 case kMetadataBufferTypeCameraSource: return "CameraSource";
284 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
285 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
Lajos Molnar3e328782016-05-09 10:56:46 -0700286 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
Lajos Molnar05421982015-05-15 20:39:14 -0700287 case kMetadataBufferTypeInvalid: return "Invalid";
288 default: return def;
289 }
290}
291
Lajos Molnar3e328782016-05-09 10:56:46 -0700292} // namespace android
293
Andreas Huber20111aa2009-07-14 16:56:47 -0700294#endif // ANDROID_IOMX_H_