blob: 839945cb97a70d753e457447bcda06f60ef6bdae [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>
Chong Zhang3fd200f2016-10-07 17:25:58 -070022#include <gui/IGraphicBufferProducer.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070023#include <utils/List.h>
24#include <utils/String8.h>
25
Lajos Molnar26a48f32015-06-04 10:30:02 -070026#include <list>
27
Lajos Molnar05421982015-05-15 20:39:14 -070028#include <media/hardware/MetadataBufferType.h>
29
Andreas Huber20111aa2009-07-14 16:56:47 -070030#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070031#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070032
Andreas Huber20111aa2009-07-14 16:56:47 -070033namespace android {
34
Chong Zhangaddf2cb2016-09-28 17:53:01 -070035class IGraphicBufferProducer;
Chong Zhang6d332d22016-09-07 12:06:50 -070036class IGraphicBufferSource;
Andreas Huber20111aa2009-07-14 16:56:47 -070037class IMemory;
Chong Zhangaddf2cb2016-09-28 17:53:01 -070038class IOMXBufferSource;
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 Zhang3fd200f2016-10-07 17:25:58 -070042class OMXBuffer;
Chong Zhang6cf9a122016-09-08 23:25:52 -070043struct omx_message;
Andreas Huber20111aa2009-07-14 16:56:47 -070044
45class IOMX : public IInterface {
46public:
47 DECLARE_META_INTERFACE(OMX);
48
Andy Hung609b8152014-05-02 11:05:04 -070049 typedef uint32_t buffer_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070050
Chong Zhangd59b9722016-09-20 16:31:18 -070051 enum {
52 kFenceTimeoutMs = 1000
53 };
54
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,
Chong Zhang1d2e9cf2016-10-05 21:08:36 -070063 sp<IOMXNode> *omxNode) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070064
Chong Zhangaddf2cb2016-09-28 17:53:01 -070065 virtual status_t createInputSurface(
Chong Zhangd59b9722016-09-20 16:31:18 -070066 sp<IGraphicBufferProducer> *bufferProducer,
Chong Zhangaddf2cb2016-09-28 17:53:01 -070067 sp<IGraphicBufferSource> *bufferSource) = 0;
Chong Zhangd59b9722016-09-20 16:31:18 -070068};
69
70class IOMXNode : public IInterface {
71public:
72 DECLARE_META_INTERFACE(OMXNode);
73
74 typedef IOMX::buffer_id buffer_id;
75
76 virtual status_t freeNode() = 0;
Andreas Huber318ad9c2009-10-15 13:46:54 -070077
78 virtual status_t sendCommand(
Chong Zhangd59b9722016-09-20 16:31:18 -070079 OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070080
Andreas Huber318ad9c2009-10-15 13:46:54 -070081 virtual status_t getParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070082 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070083
Andreas Huber318ad9c2009-10-15 13:46:54 -070084 virtual status_t setParameter(
Chong Zhangd59b9722016-09-20 16:31:18 -070085 OMX_INDEXTYPE index, const 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 getConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070088 OMX_INDEXTYPE index, void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070089
Andreas Huber318ad9c2009-10-15 13:46:54 -070090 virtual status_t setConfig(
Chong Zhangd59b9722016-09-20 16:31:18 -070091 OMX_INDEXTYPE index, const void *params, size_t size) = 0;
Andreas Huber693d2712009-08-14 14:37:10 -070092
Lajos Molnar05421982015-05-15 20:39:14 -070093 // This will set *type to previous metadata buffer type on OMX error (not on binder error), and
94 // new metadata buffer type on success.
James Donge8707722010-10-20 17:38:41 -070095 virtual status_t storeMetaDataInBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -070096 OMX_U32 port_index, OMX_BOOL enable, MetadataBufferType *type = NULL) = 0;
James Donge8707722010-10-20 17:38:41 -070097
Lajos Molnar56ce7262013-05-02 16:30:48 -070098 virtual status_t prepareForAdaptivePlayback(
Chong Zhangd59b9722016-09-20 16:31:18 -070099 OMX_U32 portIndex, OMX_BOOL enable,
Lajos Molnar56ce7262013-05-02 16:30:48 -0700100 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
101
Lajos Molnar15ab4992015-06-01 10:54:31 -0700102 virtual status_t configureVideoTunnelMode(
Chong Zhangd59b9722016-09-20 16:31:18 -0700103 OMX_U32 portIndex, OMX_BOOL tunneled,
Rachad5a446aa2014-07-29 16:47:56 -0700104 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
105
Lajos Molnara63141a2016-02-11 16:40:36 -0800106 virtual status_t enableNativeBuffers(
Chong Zhangd59b9722016-09-20 16:31:18 -0700107 OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;
Jamie Gennis83750ea2010-08-30 16:48:38 -0700108
Jamie Gennise2ce6452011-02-23 19:01:28 -0800109 virtual status_t getGraphicBufferUsage(
Chong Zhangd59b9722016-09-20 16:31:18 -0700110 OMX_U32 port_index, OMX_U32* usage) = 0;
Jamie Gennise2ce6452011-02-23 19:01:28 -0800111
Chong Zhang8f469e12015-05-13 10:21:33 -0700112 virtual status_t setInputSurface(
Chong Zhangaddf2cb2016-09-28 17:53:01 -0700113 const sp<IOMXBufferSource> &bufferSource) = 0;
Chong Zhangd291c222015-04-30 18:15:52 -0700114
Lajos Molnara63141a2016-02-11 16:40:36 -0800115 // Allocate an opaque buffer as a native handle. If component supports returning native
116 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
117 // returned in *buffer_data. This clearly only makes sense if the caller lives in the
118 // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
119 // pointer is just that, a pointer into local address space.
120 virtual status_t allocateSecureBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700121 OMX_U32 port_index, size_t size, buffer_id *buffer,
122 void **buffer_data, sp<NativeHandle> *native_handle) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700123
Chong Zhang3fd200f2016-10-07 17:25:58 -0700124 // Instructs the component to use the buffer passed in via |omxBuf| on the
125 // specified port. Returns in |*buffer| the buffer id that the component
126 // assigns to this buffer. |omxBuf| must be one of:
127 // 1) OMXBuffer::sPreset for meta-mode,
128 // 2) type kBufferTypeANWBuffer for non-meta-graphic buffer mode,
129 // 3) type kBufferTypeSharedMem for bytebuffer mode.
130 virtual status_t useBuffer(
131 OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) = 0;
132
133 // Frees the buffer on the specified port with buffer id |buffer|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700134 virtual status_t freeBuffer(
Chong Zhangd59b9722016-09-20 16:31:18 -0700135 OMX_U32 port_index, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700136
Chong Zhang3fd200f2016-10-07 17:25:58 -0700137 // Calls OMX_FillBuffer on buffer. Passes |fenceFd| to component if it
138 // supports fences. Otherwise, it waits on |fenceFd| before calling
139 // OMX_FillBuffer. Takes ownership of |fenceFd| even if this call fails.
140 // If the port is in metadata mode, the buffer will be updated to point
141 // to the new buffer passed in via |omxBuf| before OMX_FillBuffer is called.
142 // Otherwise info in the |omxBuf| is not used.
143 virtual status_t fillBuffer(
144 buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd = -1) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700145
Chong Zhang3fd200f2016-10-07 17:25:58 -0700146 // Calls OMX_EmptyBuffer on buffer. Passes |fenceFd| to component if it
147 // supports fences. Otherwise, it waits on |fenceFd| before calling
148 // OMX_EmptyBuffer. Takes ownership of |fenceFd| even if this call fails.
149 // If the port is in metadata mode, the buffer will be updated to point
150 // to the new buffer passed in via |omxBuf| before OMX_EmptyBuffer is called.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700151 virtual status_t emptyBuffer(
Chong Zhang3fd200f2016-10-07 17:25:58 -0700152 buffer_id buffer, const OMXBuffer &omxBuf,
Lajos Molnar15ab4992015-06-01 10:54:31 -0700153 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700154
Andreas Huber318ad9c2009-10-15 13:46:54 -0700155 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700156 const char *parameter_name,
157 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700158
Chong Zhang6cf9a122016-09-08 23:25:52 -0700159 virtual status_t dispatchMessage(const omx_message &msg) = 0;
Chong Zhang21b46582016-10-04 12:44:53 -0700160
161 // TODO: this is temporary, will be removed when quirks move to OMX side
162 virtual status_t setQuirks(OMX_U32 quirks) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700163};
164
165struct omx_message {
166 enum {
167 EVENT,
168 EMPTY_BUFFER_DONE,
169 FILL_BUFFER_DONE,
Lajos Molnar90fcf682015-06-04 10:29:19 -0700170 FRAME_RENDERED,
Andreas Huber20111aa2009-07-14 16:56:47 -0700171 } type;
172
Lajos Molnar15ab4992015-06-01 10:54:31 -0700173 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
Andreas Huber693d2712009-08-14 14:37:10 -0700174
Andreas Huber20111aa2009-07-14 16:56:47 -0700175 union {
176 // if type == EVENT
177 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700178 OMX_EVENTTYPE event;
179 OMX_U32 data1;
180 OMX_U32 data2;
Chong Zhang6cf9a122016-09-08 23:25:52 -0700181 OMX_U32 data3;
182 OMX_U32 data4;
Andreas Huber20111aa2009-07-14 16:56:47 -0700183 } event_data;
184
Andreas Hubere0f0b082009-08-27 14:50:58 -0700185 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700186 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700187 IOMX::buffer_id buffer;
188 } buffer_data;
189
Andreas Hubere0f0b082009-08-27 14:50:58 -0700190 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700191 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700192 IOMX::buffer_id buffer;
193 OMX_U32 range_offset;
194 OMX_U32 range_length;
195 OMX_U32 flags;
196 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700197 } extended_buffer_data;
198
Lajos Molnar90fcf682015-06-04 10:29:19 -0700199 // if type == FRAME_RENDERED
200 struct {
201 OMX_TICKS timestamp;
202 OMX_S64 nanoTime;
203 } render_data;
Andreas Huber20111aa2009-07-14 16:56:47 -0700204 } u;
205};
206
207class IOMXObserver : public IInterface {
208public:
209 DECLARE_META_INTERFACE(OMXObserver);
210
Lajos Molnar26a48f32015-06-04 10:30:02 -0700211 // Handle (list of) messages.
212 virtual void onMessages(const std::list<omx_message> &messages) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700213};
214
215////////////////////////////////////////////////////////////////////////////////
216
217class BnOMX : public BnInterface<IOMX> {
218public:
Chong Zhangd59b9722016-09-20 16:31:18 -0700219 virtual status_t onTransact(
220 uint32_t code, const Parcel &data, Parcel *reply,
221 uint32_t flags = 0);
222};
223
224class BnOMXNode : public BnInterface<IOMXNode> {
225public:
Andreas Huber20111aa2009-07-14 16:56:47 -0700226 virtual status_t onTransact(
227 uint32_t code, const Parcel &data, Parcel *reply,
228 uint32_t flags = 0);
Wei Jia8dde7262015-09-28 11:32:23 -0700229
230protected:
231 // check if the codec is secure.
Chong Zhangd59b9722016-09-20 16:31:18 -0700232 virtual bool isSecure() const {
Wei Jia8dde7262015-09-28 11:32:23 -0700233 return false;
234 }
Andreas Huber20111aa2009-07-14 16:56:47 -0700235};
236
237class BnOMXObserver : public BnInterface<IOMXObserver> {
238public:
239 virtual status_t onTransact(
240 uint32_t code, const Parcel &data, Parcel *reply,
241 uint32_t flags = 0);
242};
243
James Dong457116d2011-07-11 12:29:10 -0700244struct CodecProfileLevel {
245 OMX_U32 mProfile;
246 OMX_U32 mLevel;
247};
248
Lajos Molnar3e328782016-05-09 10:56:46 -0700249inline static const char *asString(MetadataBufferType i, const char *def = "??") {
Lajos Molnar05421982015-05-15 20:39:14 -0700250 using namespace android;
251 switch (i) {
252 case kMetadataBufferTypeCameraSource: return "CameraSource";
253 case kMetadataBufferTypeGrallocSource: return "GrallocSource";
254 case kMetadataBufferTypeANWBuffer: return "ANWBuffer";
Lajos Molnar3e328782016-05-09 10:56:46 -0700255 case kMetadataBufferTypeNativeHandleSource: return "NativeHandleSource";
Lajos Molnar05421982015-05-15 20:39:14 -0700256 case kMetadataBufferTypeInvalid: return "Invalid";
257 default: return def;
258 }
259}
260
Lajos Molnar3e328782016-05-09 10:56:46 -0700261} // namespace android
262
Andreas Huber20111aa2009-07-14 16:56:47 -0700263#endif // ANDROID_IOMX_H_