blob: e69c02dda198fef611e0f92a19e98bfbe10f59ec [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>
22#include <utils/List.h>
23#include <utils/String8.h>
Mathias Agopianbc1713d2017-02-13 18:37:50 -080024#include <cutils/native_handle.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070025
Lajos Molnar26a48f32015-06-04 10:30:02 -070026#include <list>
27
Pawin Vongmasa04563aa2017-03-09 07:02:01 -080028#include <hidl/HybridInterface.h>
Lajos Molnar05421982015-05-15 20:39:14 -070029#include <media/hardware/MetadataBufferType.h>
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080030#include <android/hardware/media/omx/1.0/IOmxNode.h>
Lajos Molnar05421982015-05-15 20:39:14 -070031
Pawin Vongmasa255735a2017-07-19 11:24:56 -070032#include <media/openmax/OMX_Core.h>
33#include <media/openmax/OMX_Video.h>
Lajos Molnar06e98362017-08-14 15:57:57 -070034#include <media/openmax/OMX_VideoExt.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070035
Andreas Huber20111aa2009-07-14 16:56:47 -070036namespace android {
37
Chong Zhangaddf2cb2016-09-28 17:53:01 -070038class IGraphicBufferProducer;
Chong Zhang6d332d22016-09-07 12:06:50 -070039class IGraphicBufferSource;
Andreas Huber20111aa2009-07-14 16:56:47 -070040class IMemory;
Chong Zhangaddf2cb2016-09-28 17:53:01 -070041class IOMXBufferSource;
Chong Zhangd59b9722016-09-20 16:31:18 -070042class IOMXNode;
Andreas Huber20111aa2009-07-14 16:56:47 -070043class IOMXObserver;
Lajos Molnar1b40f282016-05-09 22:24:52 -070044class NativeHandle;
Chong Zhang3fd200f2016-10-07 17:25:58 -070045class OMXBuffer;
Chong Zhang6cf9a122016-09-08 23:25:52 -070046struct omx_message;
Andreas Huber20111aa2009-07-14 16:56:47 -070047
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080048using hardware::media::omx::V1_0::IOmxNode;
49
Andreas Huber20111aa2009-07-14 16:56:47 -070050class IOMX : public IInterface {
51public:
52 DECLARE_META_INTERFACE(OMX);
53
Andy Hung609b8152014-05-02 11:05:04 -070054 typedef uint32_t buffer_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070055
Chong Zhangd59b9722016-09-20 16:31:18 -070056 enum {
57 kFenceTimeoutMs = 1000
58 };
59
Chong Zhangd02c0862016-10-13 14:32:32 -070060 enum PortMode {
61 kPortModePresetStart = 0,
62 kPortModePresetByteBuffer,
63 kPortModePresetANWBuffer,
64 kPortModePresetSecureBuffer,
65 kPortModePresetEnd,
66
67 kPortModeDynamicStart = 100,
68 kPortModeDynamicANWBuffer, // uses metadata mode kMetadataBufferTypeANWBuffer
69 // or kMetadataBufferTypeGrallocSource
70 kPortModeDynamicNativeHandle, // uses metadata mode kMetadataBufferTypeNativeHandleSource
71 kPortModeDynamicEnd,
72 };
73
Andreas Huber134ee6a2009-12-16 09:30:55 -080074 struct ComponentInfo {
75 String8 mName;
76 List<String8> mRoles;
77 };
78 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070079
Andreas Huber318ad9c2009-10-15 13:46:54 -070080 virtual status_t allocateNode(
81 const char *name, const sp<IOMXObserver> &observer,
Chong Zhang1d2e9cf2016-10-05 21:08:36 -070082 sp<IOMXNode> *omxNode) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070083
Chong Zhangaddf2cb2016-09-28 17:53:01 -070084 virtual status_t createInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -070085 sp<IGraphicBufferProducer> *bufferProducer,
Chong Zhangaddf2cb2016-09-28 17:53:01 -070086 sp<IGraphicBufferSource> *bufferSource) = 0;
Chong Zhangd59b9722016-09-20 16:31:18 -070087};
88
89class IOMXNode : public IInterface {
90public:
Pawin Vongmasaac7d4122017-03-01 05:48:42 -080091 DECLARE_HYBRID_META_INTERFACE(OMXNode, IOmxNode);
Chong Zhangd59b9722016-09-20 16:31:18 -070092
93 typedef IOMX::buffer_id buffer_id;
94
95 virtual status_t freeNode() = 0;
Andreas Huber318ad9c2009-10-15 13:46:54 -070096
97 virtual status_t sendCommand(
Chong Zhangd59b9722016-09-20 16:31:18 -070098 OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070099
Andreas Huber318ad9c2009-10-15 13:46:54 -0700100 virtual status_t getParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -0700101 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700102
Andreas Huber318ad9c2009-10-15 13:46:54 -0700103 virtual status_t setParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -0700104 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700105
Andreas Huber318ad9c2009-10-15 13:46:54 -0700106 virtual status_t getConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -0700107 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -0700108
Andreas Huber318ad9c2009-10-15 13:46:54 -0700109 virtual status_t setConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -0700110 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -0700111
Chong Zhangd02c0862016-10-13 14:32:32 -0700112 virtual status_t setPortMode(
113 OMX_U32 port_index, IOMX::PortMode mode) = 0;
James Donge8707722010-10-20 17:38:41 -0700114
Lajos Molnar56ce7262013-05-02 16:30:48 -0700115 virtual status_t prepareForAdaptivePlayback(
Chong Zhangd59b9722016-09-20 16:31:18 -0700116 OMX_U32 portIndex, OMX_BOOL enable,
Lajos Molnar56ce7262013-05-02 16:30:48 -0700117 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
118
Lajos Molnar15ab4992015-06-01 10:54:31 -0700119 virtual status_t configureVideoTunnelMode(
Chong Zhangd59b9722016-09-20 16:31:18 -0700120 OMX_U32 portIndex, OMX_BOOL tunneled,
Rachad5a446aa2014-07-29 16:47:56 -0700121 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
122
Jamie Gennise2ce6452011-02-23 19:01:28 -0800123 virtual status_t getGraphicBufferUsage(
Chong Zhangd59b9722016-09-20 16:31:18 -0700124 OMX_U32 port_index, OMX_U32* usage) = 0;
Jamie Gennise2ce6452011-02-23 19:01:28 -0800125
Chong Zhang8f469e12015-05-13 10:21:33 -0700126 virtual status_t setInputSurface(
Chong Zhangaddf2cb2016-09-28 17:53:01 -0700127 const sp<IOMXBufferSource> &bufferSource) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700128
Lajos Molnara63141a2016-02-11 16:40:36 -0800129 // Allocate an opaque buffer as a native handle. If component supports returning native
130 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
131 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
132 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
133 // pointer is just that, a pointer into local address space.
134 virtual status_t allocateSecureBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700135 OMX_U32 port_index, size_t size, buffer_id *buffer,
136 void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700137
Chong Zhang3fd200f2016-10-07 17:25:58 -0700138 // Instructs the component to use the buffer passed in via |omxBuf| on the
139 // specified port. Returns in |*buffer| the buffer id that the component
140 // assigns to this buffer. |omxBuf| must be one of:
141 // 1) OMXBuffer::sPreset for meta-mode,
142 // 2) type kBufferTypeANWBuffer for non-meta-graphic buffer mode,
143 // 3) type kBufferTypeSharedMem for bytebuffer mode.
144 virtual status_t useBuffer(
145 OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) = 0;
146
147 // Frees the buffer on the specified port with buffer id |buffer|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700148 virtual status_t freeBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700149 OMX_U32 port_index, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700150
Chong Zhang3fd200f2016-10-07 17:25:58 -0700151 // Calls OMX_FillBuffer on buffer. Passes |fenceFd| to component if it
152 // supports fences. Otherwise, it waits on |fenceFd| before calling
153 // OMX_FillBuffer. Takes ownership of |fenceFd| even if this call fails.
154 // If the port is in metadata mode, the buffer will be updated to point
155 // to the new buffer passed in via |omxBuf| before OMX_FillBuffer is called.
156 // Otherwise info in the |omxBuf| is not used.
157 virtual status_t fillBuffer(
158 buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700159
Chong Zhang3fd200f2016-10-07 17:25:58 -0700160 // Calls OMX_EmptyBuffer on buffer. Passes |fenceFd| to component if it
161 // supports fences. Otherwise, it waits on |fenceFd| before calling
162 // OMX_EmptyBuffer. Takes ownership of |fenceFd| even if this call fails.
163 // If the port is in metadata mode, the buffer will be updated to point
164 // to the new buffer passed in via |omxBuf| before OMX_EmptyBuffer is called.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700165 virtual status_t emptyBuffer(
Chong Zhang3fd200f2016-10-07 17:25:58 -0700166 buffer_id buffer, const OMXBuffer &omxBuf,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700167 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700168
Andreas Huber318ad9c2009-10-15 13:46:54 -0700169 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700170 const char *parameter_name,
171 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700172
Chong Zhang6cf9a122016-09-08 23:25:52 -0700173 virtual status_t dispatchMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700174};
175
176struct omx_message {
177 enum {
178 EVENT,
179 EMPTY_BUFFER_DONE,
180 FILL_BUFFER_DONE,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700181 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700182 } type;
183
Lajos Molnar15ab4992015-06-01 10:54:31 -0700184 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700185
Andreas Huber20111aa2009-07-14 16:56:47 -0700186 union {
187 // if type == EVENT
188 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700189 OMX_EVENTTYPE event;
190 OMX_U32 data1;
191 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700192 OMX_U32 data3;
193 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700194 } event_data;
195
Andreas Hubere0f0b082009-08-27 14:50:58 -0700196 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700197 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700198 IOMX::buffer_id buffer;
199 } buffer_data;
200
Andreas Hubere0f0b082009-08-27 14:50:58 -0700201 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700202 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700203 IOMX::buffer_id buffer;
204 OMX_U32 range_offset;
205 OMX_U32 range_length;
206 OMX_U32 flags;
207 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700208 } extended_buffer_data;
209
Lajos Molnar90fcf682015-06-04 10:29:19 -0700210 // if type == FRAME_RENDERED
211 struct {
212 OMX_TICKS timestamp;
213 OMX_S64 nanoTime;
214 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700215 } u;
216};
217
218class IOMXObserver : public IInterface {
219public:
220 DECLARE_META_INTERFACE(OMXObserver);
221
Lajos Molnar26a48f32015-06-04 10:30:02 -0700222 // Handle (list of) messages.
223 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700224};
225
226////////////////////////////////////////////////////////////////////////////////
227
228class BnOMX : public BnInterface<IOMX> {
229public:
Chong Zhangd59b9722016-09-20 16:31:18 -0700230 virtual status_t onTransact(
231 uint32_t code, const Parcel &data, Parcel *reply,
232 uint32_t flags = 0);
233};
234
235class BnOMXNode : public BnInterface<IOMXNode> {
236public:
Andreas Huber20111aa2009-07-14 16:56:47 -0700237 virtual status_t onTransact(
238 uint32_t code, const Parcel &data, Parcel *reply,
239 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700240
241protected:
242 // check if the codec is secure.
Chong Zhangd59b9722016-09-20 16:31:18 -0700243 virtual bool isSecure() const {
Wei Jia8dde7262015-09-28 11:32:23 -0700244 return false;
245 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700246};
247
248class BnOMXObserver : public BnInterface<IOMXObserver> {
249public:
250 virtual status_t onTransact(
251 uint32_t code, const Parcel &data, Parcel *reply,
252 uint32_t flags = 0);
253};
254
Lajos Molnar3e328782016-05-09 10:56:46 -0700255} // namespace android
256
Andreas Huber20111aa2009-07-14 16:56:47 -0700257#endif // ANDROID_IOMX_H_