blob: 9790f844fc12acbc3356e4053d1c83b25ebd101a [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;
Chong Zhangd59b9722016-09-20 16:31:18 -070039class IOMXNode;
Andreas Huber20111aa2009-07-14 16:56:47 -070040class IOMXObserver;
Lajos Molnar1b40f282016-05-09 22:24:52 -070041class NativeHandle;
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;
Andreas Huber20111aa2009-07-14 16:56:47 -070049
Chong Zhangd59b9722016-09-20 16:31:18 -070050 enum {
51 kFenceTimeoutMs = 1000
52 };
53
Andreas Huber134ee6a2009-12-16 09:30:55 -080054 struct ComponentInfo {
55 String8 mName;
56 List<String8> mRoles;
57 };
58 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070059
Andreas Huber318ad9c2009-10-15 13:46:54 -070060 virtual status_t allocateNode(
61 const char *name, const sp<IOMXObserver> &observer,
Chong Zhang1d2e9cf2016-10-05 21:08:36 -070062 sp<IOMXNode> *omxNode) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070063
Chong Zhangd59b9722016-09-20 16:31:18 -070064 virtual status_t createPersistentInputSurface(
65 sp<IGraphicBufferProducer> *bufferProducer,
66 sp<IGraphicBufferConsumer> *bufferConsumer) = 0;
67};
68
69class IOMXNode : public IInterface {
70public:
71 DECLARE_META_INTERFACE(OMXNode);
72
73 typedef IOMX::buffer_id buffer_id;
74
75 virtual status_t freeNode() = 0;
Andreas Huber318ad9c2009-10-15 13:46:54 -070076
77 virtual status_t sendCommand(
Chong Zhangd59b9722016-09-20 16:31:18 -070078 OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070079
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 virtual status_t getParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070081 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070082
Andreas Huber318ad9c2009-10-15 13:46:54 -070083 virtual status_t setParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070084 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070085
Andreas Huber318ad9c2009-10-15 13:46:54 -070086 virtual status_t getConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070087 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070088
Andreas Huber318ad9c2009-10-15 13:46:54 -070089 virtual status_t setConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070090 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070091
Lajos Molnar05421982015-05-15 20:39:14 -070092 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
93 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -070094 virtual status_t storeMetaDataInBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -070095 OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -070096
Lajos Molnar56ce7262013-05-02 16:30:48 -070097 virtual status_t prepareForAdaptivePlayback(
Chong Zhangd59b9722016-09-20 16:31:18 -070098 OMX_U32 portIndex, OMX_BOOL enable,
Lajos Molnar56ce7262013-05-02 16:30:48 -070099 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
100
Lajos Molnar15ab4992015-06-01 10:54:31 -0700101 virtual status_t configureVideoTunnelMode(
Chong Zhangd59b9722016-09-20 16:31:18 -0700102 OMX_U32 portIndex, OMX_BOOL tunneled,
Rachad5a446aa2014-07-29 16:47:56 -0700103 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
104
Lajos Molnara63141a2016-02-11 16:40:36 -0800105 virtual status_t enableNativeBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -0700106 OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;
Jamie Gennis83750ea2010-08-30 16:48:38 -0700107
Jamie Gennise2ce6452011-02-23 19:01:28 -0800108 virtual status_t getGraphicBufferUsage(
Chong Zhangd59b9722016-09-20 16:31:18 -0700109 OMX_U32 port_index, OMX_U32* usage) = 0;
Jamie Gennise2ce6452011-02-23 19:01:28 -0800110
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700111 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700112 virtual status_t useBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700113 OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700114 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700115
Jamie Gennis83750ea2010-08-30 16:48:38 -0700116 virtual status_t useGraphicBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700117 OMX_U32 port_index,
Jamie Gennis83750ea2010-08-30 16:48:38 -0700118 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
119
Lajos Molnard0715862013-07-22 12:57:43 -0700120 virtual status_t updateGraphicBufferInMeta(
Chong Zhangd59b9722016-09-20 16:31:18 -0700121 OMX_U32 port_index,
Lajos Molnard0715862013-07-22 12:57:43 -0700122 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
123
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700124 virtual status_t updateNativeHandleInMeta(
Chong Zhangd59b9722016-09-20 16:31:18 -0700125 OMX_U32 port_index,
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700126 const sp<NativeHandle> &nativeHandle, buffer_id buffer) = 0;
127
Lajos Molnar05421982015-05-15 20:39:14 -0700128 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
129 // well as on success.
Andy McFadden7cd58532013-02-19 07:28:30 -0800130 virtual status_t createInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -0700131 OMX_U32 port_index, android_dataspace dataSpace,
Lajos Molnar05421982015-05-15 20:39:14 -0700132 sp<IGraphicBufferProducer> *bufferProducer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700133 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700134 MetadataBufferType *type = NULL) = 0;
Andy McFadden7cd58532013-02-19 07:28:30 -0800135
Lajos Molnar05421982015-05-15 20:39:14 -0700136 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
137 // well as on success.
Chong Zhang8f469e12015-05-13 10:21:33 -0700138 virtual status_t setInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -0700139 OMX_U32 port_index,
Lajos Molnar05421982015-05-15 20:39:14 -0700140 const sp<IGraphicBufferConsumer> &bufferConsumer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700141 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700142 MetadataBufferType *type) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700143
Lajos Molnara63141a2016-02-11 16:40:36 -0800144 // Allocate an opaque buffer as a native handle. If component supports returning native
145 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
146 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
147 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
148 // pointer is just that, a pointer into local address space.
149 virtual status_t allocateSecureBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700150 OMX_U32 port_index, size_t size, buffer_id *buffer,
151 void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700152
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700153 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
154 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700155 virtual status_t allocateBufferWithBackup(
Chong Zhangd59b9722016-09-20 16:31:18 -0700156 OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700157 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700158
Andreas Huber318ad9c2009-10-15 13:46:54 -0700159 virtual status_t freeBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700160 OMX_U32 port_index, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700161
Lajos Molnar15ab4992015-06-01 10:54:31 -0700162 // Calls OMX_FillBuffer on buffer, and passes |fenceFd| to component if it supports
163 // fences. Otherwise, it waits on |fenceFd| before calling OMX_FillBuffer.
164 // Takes ownership of |fenceFd| even if this call fails.
Chong Zhangd59b9722016-09-20 16:31:18 -0700165 virtual status_t fillBuffer(buffer_id buffer, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700166
Lajos Molnar15ab4992015-06-01 10:54:31 -0700167 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with |range_offset|,
168 // |range_length|, |flags| and |timestamp|). Passes |fenceFd| to component if it
169 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
170 // Takes ownership of |fenceFd| even if this call fails.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700171 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700172 buffer_id buffer,
173 OMX_U32 range_offset, OMX_U32 range_length,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700174 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700175
Chong Zhang6d332d22016-09-07 12:06:50 -0700176 // Calls OMX_EmptyBuffer on buffer (after updating buffer header with metadata of
177 // |graphicBuffer|, |flags| and |timestamp|). Passes |fenceFd| to component if it
178 // supports fences. Otherwise, it waits on |fenceFd| before calling OMX_EmptyBuffer.
179 // Takes ownership of |fenceFd| even if this call fails. If |origTimestamp| >= 0,
180 // timestamp on the filled buffer corresponding to this frame will be modified to
181 // |origTimestamp| after it's filled.
Chong Zhang6cf9a122016-09-08 23:25:52 -0700182 virtual status_t emptyGraphicBuffer(
Chong Zhang6cf9a122016-09-08 23:25:52 -0700183 buffer_id buffer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700184 const sp<GraphicBuffer> &graphicBuffer, OMX_U32 flags,
185 OMX_TICKS timestamp, OMX_TICKS origTimestamp, int fenceFd) = 0;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700186
Andreas Huber318ad9c2009-10-15 13:46:54 -0700187 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700188 const char *parameter_name,
189 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700190
Chong Zhang6cf9a122016-09-08 23:25:52 -0700191 virtual status_t dispatchMessage(const omx_message &msg) = 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,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700199 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700200 } type;
201
Lajos Molnar15ab4992015-06-01 10:54:31 -0700202 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700203
Andreas Huber20111aa2009-07-14 16:56:47 -0700204 union {
205 // if type == EVENT
206 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700207 OMX_EVENTTYPE event;
208 OMX_U32 data1;
209 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700210 OMX_U32 data3;
211 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700212 } event_data;
213
Andreas Hubere0f0b082009-08-27 14:50:58 -0700214 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700215 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700216 IOMX::buffer_id buffer;
217 } buffer_data;
218
Andreas Hubere0f0b082009-08-27 14:50:58 -0700219 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700220 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700221 IOMX::buffer_id buffer;
222 OMX_U32 range_offset;
223 OMX_U32 range_length;
224 OMX_U32 flags;
225 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700226 } extended_buffer_data;
227
Lajos Molnar90fcf682015-06-04 10:29:19 -0700228 // if type == FRAME_RENDERED
229 struct {
230 OMX_TICKS timestamp;
231 OMX_S64 nanoTime;
232 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700233 } u;
234};
235
236class IOMXObserver : public IInterface {
237public:
238 DECLARE_META_INTERFACE(OMXObserver);
239
Lajos Molnar26a48f32015-06-04 10:30:02 -0700240 // Handle (list of) messages.
241 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700242};
243
244////////////////////////////////////////////////////////////////////////////////
245
246class BnOMX : public BnInterface<IOMX> {
247public:
Chong Zhangd59b9722016-09-20 16:31:18 -0700248 virtual status_t onTransact(
249 uint32_t code, const Parcel &data, Parcel *reply,
250 uint32_t flags = 0);
251};
252
253class BnOMXNode : public BnInterface<IOMXNode> {
254public:
Andreas Huber20111aa2009-07-14 16:56:47 -0700255 virtual status_t onTransact(
256 uint32_t code, const Parcel &data, Parcel *reply,
257 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700258
259protected:
260 // check if the codec is secure.
Chong Zhangd59b9722016-09-20 16:31:18 -0700261 virtual bool isSecure() const {
Wei Jia8dde7262015-09-28 11:32:23 -0700262 return false;
263 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700264};
265
266class BnOMXObserver : public BnInterface<IOMXObserver> {
267public:
268 virtual status_t onTransact(
269 uint32_t code, const Parcel &data, Parcel *reply,
270 uint32_t flags = 0);
271};
272
James Dong457116d2011-07-11 12:29:10 -0700273struct CodecProfileLevel {
274 OMX_U32 mProfile;
275 OMX_U32 mLevel;
276};
277
Lajos Molnar3e328782016-05-09 10:56:46 -0700278inline static const char *asString(MetadataBufferType i, const char *def = "??") {
Lajos Molnar05421982015-05-15 20:39:14 -0700279 using namespace android;
280 switch (i) {
281 case kMetadataBufferTypeCameraSource: return "CameraSource";
282 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
283 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
Lajos Molnar3e328782016-05-09 10:56:46 -0700284 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
Lajos Molnar05421982015-05-15 20:39:14 -0700285 case kMetadataBufferTypeInvalid: return "Invalid";
286 default: return def;
287 }
288}
289
Lajos Molnar3e328782016-05-09 10:56:46 -0700290} // namespace android
291
Andreas Huber20111aa2009-07-14 16:56:47 -0700292#endif // ANDROID_IOMX_H_