blob: 54fa85f91efc376906e95d1cc91914fe0f41abda [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
54 // Returns true iff the implementation of the OMX interface
55 // lives in the same process.
56 virtual bool livesLocally() = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080057
Andreas Huber134ee6a2009-12-16 09:30:55 -080058 struct ComponentInfo {
59 String8 mName;
60 List<String8> mRoles;
61 };
62 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070063
Andreas Huber318ad9c2009-10-15 13:46:54 -070064 virtual status_t allocateNode(
65 const char *name, const sp<IOMXObserver> &observer,
Chong Zhang1d2e9cf2016-10-05 21:08:36 -070066 sp<IOMXNode> *omxNode) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070067
Chong Zhangd59b9722016-09-20 16:31:18 -070068 virtual status_t createPersistentInputSurface(
69 sp<IGraphicBufferProducer> *bufferProducer,
70 sp<IGraphicBufferConsumer> *bufferConsumer) = 0;
71};
72
73class IOMXNode : public IInterface {
74public:
75 DECLARE_META_INTERFACE(OMXNode);
76
77 typedef IOMX::buffer_id buffer_id;
78
79 virtual status_t freeNode() = 0;
Andreas Huber318ad9c2009-10-15 13:46:54 -070080
81 virtual status_t sendCommand(
Chong Zhangd59b9722016-09-20 16:31:18 -070082 OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070083
Andreas Huber318ad9c2009-10-15 13:46:54 -070084 virtual status_t getParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070085 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070086
Andreas Huber318ad9c2009-10-15 13:46:54 -070087 virtual status_t setParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070088 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070089
Andreas Huber318ad9c2009-10-15 13:46:54 -070090 virtual status_t getConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070091 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070092
Andreas Huber318ad9c2009-10-15 13:46:54 -070093 virtual status_t setConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070094 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070095
Chong Zhangd59b9722016-09-20 16:31:18 -070096 virtual status_t getState(OMX_STATETYPE* state) = 0;
Jamie Gennisb1d666f2011-10-19 21:14:13 -070097
Lajos Molnar05421982015-05-15 20:39:14 -070098 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
99 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -0700100 virtual status_t storeMetaDataInBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -0700101 OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -0700102
Lajos Molnar56ce7262013-05-02 16:30:48 -0700103 virtual status_t prepareForAdaptivePlayback(
Chong Zhangd59b9722016-09-20 16:31:18 -0700104 OMX_U32 portIndex, OMX_BOOL enable,
Lajos Molnar56ce7262013-05-02 16:30:48 -0700105 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
106
Lajos Molnar15ab4992015-06-01 10:54:31 -0700107 virtual status_t configureVideoTunnelMode(
Chong Zhangd59b9722016-09-20 16:31:18 -0700108 OMX_U32 portIndex, OMX_BOOL tunneled,
Rachad5a446aa2014-07-29 16:47:56 -0700109 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
110
Lajos Molnara63141a2016-02-11 16:40:36 -0800111 virtual status_t enableNativeBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -0700112 OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;
Jamie Gennis83750ea2010-08-30 16:48:38 -0700113
Jamie Gennise2ce6452011-02-23 19:01:28 -0800114 virtual status_t getGraphicBufferUsage(
Chong Zhangd59b9722016-09-20 16:31:18 -0700115 OMX_U32 port_index, OMX_U32* usage) = 0;
Jamie Gennise2ce6452011-02-23 19:01:28 -0800116
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700117 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700118 virtual status_t useBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700119 OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700120 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700121
Jamie Gennis83750ea2010-08-30 16:48:38 -0700122 virtual status_t useGraphicBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700123 OMX_U32 port_index,
Jamie Gennis83750ea2010-08-30 16:48:38 -0700124 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
125
Lajos Molnard0715862013-07-22 12:57:43 -0700126 virtual status_t updateGraphicBufferInMeta(
Chong Zhangd59b9722016-09-20 16:31:18 -0700127 OMX_U32 port_index,
Lajos Molnard0715862013-07-22 12:57:43 -0700128 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
129
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700130 virtual status_t updateNativeHandleInMeta(
Chong Zhangd59b9722016-09-20 16:31:18 -0700131 OMX_U32 port_index,
Lajos Molnar7e0bef82016-05-09 10:48:30 -0700132 const sp<NativeHandle> &nativeHandle, buffer_id buffer) = 0;
133
Lajos Molnar05421982015-05-15 20:39:14 -0700134 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
135 // well as on success.
Andy McFadden7cd58532013-02-19 07:28:30 -0800136 virtual status_t createInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -0700137 OMX_U32 port_index, android_dataspace dataSpace,
Lajos Molnar05421982015-05-15 20:39:14 -0700138 sp<IGraphicBufferProducer> *bufferProducer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700139 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700140 MetadataBufferType *type = NULL) = 0;
Andy McFadden7cd58532013-02-19 07:28:30 -0800141
Lajos Molnar05421982015-05-15 20:39:14 -0700142 // This will set *type to resulting metadata buffer type on OMX error (not on binder error) as
143 // well as on success.
Chong Zhang8f469e12015-05-13 10:21:33 -0700144 virtual status_t setInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -0700145 OMX_U32 port_index,
Lajos Molnar05421982015-05-15 20:39:14 -0700146 const sp<IGraphicBufferConsumer> &bufferConsumer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700147 sp<IGraphicBufferSource> *bufferSource,
Lajos Molnar05421982015-05-15 20:39:14 -0700148 MetadataBufferType *type) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700149
Lajos Molnara63141a2016-02-11 16:40:36 -0800150 // Allocate an opaque buffer as a native handle. If component supports returning native
151 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
152 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
153 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
154 // pointer is just that, a pointer into local address space.
155 virtual status_t allocateSecureBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700156 OMX_U32 port_index, size_t size, buffer_id *buffer,
157 void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700158
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700159 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
160 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700161 virtual status_t allocateBufferWithBackup(
Chong Zhangd59b9722016-09-20 16:31:18 -0700162 OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700163 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700164
Andreas Huber318ad9c2009-10-15 13:46:54 -0700165 virtual status_t freeBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700166 OMX_U32 port_index, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700167
Lajos Molnar15ab4992015-06-01 10:54:31 -0700168 // 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.
Chong Zhangd59b9722016-09-20 16:31:18 -0700171 virtual status_t fillBuffer(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 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(
Chong Zhang6cf9a122016-09-08 23:25:52 -0700189 buffer_id buffer,
Chong Zhang6d332d22016-09-07 12:06:50 -0700190 const sp<GraphicBuffer> &graphicBuffer, OMX_U32 flags,
191 OMX_TICKS timestamp, OMX_TICKS origTimestamp, int fenceFd) = 0;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700192
Andreas Huber318ad9c2009-10-15 13:46:54 -0700193 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700194 const char *parameter_name,
195 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700196
Chong Zhang6cf9a122016-09-08 23:25:52 -0700197 virtual status_t dispatchMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700198};
199
200struct omx_message {
201 enum {
202 EVENT,
203 EMPTY_BUFFER_DONE,
204 FILL_BUFFER_DONE,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700205 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700206 } type;
207
Lajos Molnar15ab4992015-06-01 10:54:31 -0700208 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700209
Andreas Huber20111aa2009-07-14 16:56:47 -0700210 union {
211 // if type == EVENT
212 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700213 OMX_EVENTTYPE event;
214 OMX_U32 data1;
215 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700216 OMX_U32 data3;
217 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700218 } event_data;
219
Andreas Hubere0f0b082009-08-27 14:50:58 -0700220 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700221 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700222 IOMX::buffer_id buffer;
223 } buffer_data;
224
Andreas Hubere0f0b082009-08-27 14:50:58 -0700225 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700226 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700227 IOMX::buffer_id buffer;
228 OMX_U32 range_offset;
229 OMX_U32 range_length;
230 OMX_U32 flags;
231 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700232 } extended_buffer_data;
233
Lajos Molnar90fcf682015-06-04 10:29:19 -0700234 // if type == FRAME_RENDERED
235 struct {
236 OMX_TICKS timestamp;
237 OMX_S64 nanoTime;
238 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700239 } u;
240};
241
242class IOMXObserver : public IInterface {
243public:
244 DECLARE_META_INTERFACE(OMXObserver);
245
Lajos Molnar26a48f32015-06-04 10:30:02 -0700246 // Handle (list of) messages.
247 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700248};
249
250////////////////////////////////////////////////////////////////////////////////
251
252class BnOMX : public BnInterface<IOMX> {
253public:
Chong Zhangd59b9722016-09-20 16:31:18 -0700254 virtual bool livesLocally() {
255 return true;
256 }
257
258 virtual status_t onTransact(
259 uint32_t code, const Parcel &data, Parcel *reply,
260 uint32_t flags = 0);
261};
262
263class BnOMXNode : public BnInterface<IOMXNode> {
264public:
Andreas Huber20111aa2009-07-14 16:56:47 -0700265 virtual status_t onTransact(
266 uint32_t code, const Parcel &data, Parcel *reply,
267 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700268
269protected:
270 // check if the codec is secure.
Chong Zhangd59b9722016-09-20 16:31:18 -0700271 virtual bool isSecure() const {
Wei Jia8dde7262015-09-28 11:32:23 -0700272 return false;
273 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700274};
275
276class BnOMXObserver : public BnInterface<IOMXObserver> {
277public:
278 virtual status_t onTransact(
279 uint32_t code, const Parcel &data, Parcel *reply,
280 uint32_t flags = 0);
281};
282
James Dong457116d2011-07-11 12:29:10 -0700283struct CodecProfileLevel {
284 OMX_U32 mProfile;
285 OMX_U32 mLevel;
286};
287
Lajos Molnar3e328782016-05-09 10:56:46 -0700288inline static const char *asString(MetadataBufferType i, const char *def = "??") {
Lajos Molnar05421982015-05-15 20:39:14 -0700289 using namespace android;
290 switch (i) {
291 case kMetadataBufferTypeCameraSource: return "CameraSource";
292 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
293 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
Lajos Molnar3e328782016-05-09 10:56:46 -0700294 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
Lajos Molnar05421982015-05-15 20:39:14 -0700295 case kMetadataBufferTypeInvalid: return "Invalid";
296 default: return def;
297 }
298}
299
Lajos Molnar3e328782016-05-09 10:56:46 -0700300} // namespace android
301
Andreas Huber20111aa2009-07-14 16:56:47 -0700302#endif // ANDROID_IOMX_H_