blob: 46c363af65be220b431ce72b878bc98f134cc3ee [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
28#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070029#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070030
Andreas Huber20111aa2009-07-14 16:56:47 -070031namespace android {
32
33class IMemory;
34class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070035class IOMXRenderer;
Andreas Huberf4148b52009-08-07 12:01:29 -070036class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070037
38class IOMX : public IInterface {
39public:
40 DECLARE_META_INTERFACE(OMX);
41
Andy Hung609b8152014-05-02 11:05:04 -070042 typedef uint32_t buffer_id;
43 typedef uint32_t node_id;
Andreas Huber20111aa2009-07-14 16:56:47 -070044
Andreas Huberd459b482012-01-31 11:16:24 -080045 // Given a node_id and the calling process' pid, returns true iff
Andreas Huber7eaa9c92010-01-15 15:28:19 -080046 // the implementation of the OMX interface lives in the same
47 // process.
Andreas Huberd459b482012-01-31 11:16:24 -080048 virtual bool livesLocally(node_id node, pid_t pid) = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080049
Andreas Huber134ee6a2009-12-16 09:30:55 -080050 struct ComponentInfo {
51 String8 mName;
52 List<String8> mRoles;
53 };
54 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070055
Andreas Huber318ad9c2009-10-15 13:46:54 -070056 virtual status_t allocateNode(
57 const char *name, const sp<IOMXObserver> &observer,
58 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070059
Andreas Huber318ad9c2009-10-15 13:46:54 -070060 virtual status_t freeNode(node_id node) = 0;
61
62 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070063 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
64
Andreas Huber318ad9c2009-10-15 13:46:54 -070065 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070066 node_id node, OMX_INDEXTYPE index,
67 void *params, size_t size) = 0;
68
Andreas Huber318ad9c2009-10-15 13:46:54 -070069 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070070 node_id node, OMX_INDEXTYPE index,
71 const void *params, size_t size) = 0;
72
Andreas Huber318ad9c2009-10-15 13:46:54 -070073 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070074 node_id node, OMX_INDEXTYPE index,
75 void *params, size_t size) = 0;
76
Andreas Huber318ad9c2009-10-15 13:46:54 -070077 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070078 node_id node, OMX_INDEXTYPE index,
79 const void *params, size_t size) = 0;
80
Jamie Gennisb1d666f2011-10-19 21:14:13 -070081 virtual status_t getState(
82 node_id node, OMX_STATETYPE* state) = 0;
83
James Donge8707722010-10-20 17:38:41 -070084 virtual status_t storeMetaDataInBuffers(
85 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
86
Lajos Molnar56ce7262013-05-02 16:30:48 -070087 virtual status_t prepareForAdaptivePlayback(
88 node_id node, OMX_U32 portIndex, OMX_BOOL enable,
89 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
90
Rachad5a446aa2014-07-29 16:47:56 -070091 virtual status_t configureVideoTunnelMode(
92 node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
93 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
94
Jamie Gennis83750ea2010-08-30 16:48:38 -070095 virtual status_t enableGraphicBuffers(
96 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
97
Jamie Gennise2ce6452011-02-23 19:01:28 -080098 virtual status_t getGraphicBufferUsage(
99 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
100
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700101 // Use |params| as an OMX buffer, but limit the size of the OMX buffer to |allottedSize|.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700102 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700103 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700104 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700105
Jamie Gennis83750ea2010-08-30 16:48:38 -0700106 virtual status_t useGraphicBuffer(
107 node_id node, OMX_U32 port_index,
108 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
109
Lajos Molnard0715862013-07-22 12:57:43 -0700110 virtual status_t updateGraphicBufferInMeta(
111 node_id node, OMX_U32 port_index,
112 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
113
Andy McFadden7cd58532013-02-19 07:28:30 -0800114 virtual status_t createInputSurface(
115 node_id node, OMX_U32 port_index,
116 sp<IGraphicBufferProducer> *bufferProducer) = 0;
117
Chong Zhangd291c222015-04-30 18:15:52 -0700118 virtual status_t createPersistentInputSurface(
119 sp<IGraphicBufferProducer> *bufferProducer,
120 sp<IGraphicBufferConsumer> *bufferConsumer) = 0;
121
Chong Zhang8f469e12015-05-13 10:21:33 -0700122 virtual status_t setInputSurface(
Chong Zhangd291c222015-04-30 18:15:52 -0700123 node_id node, OMX_U32 port_index,
124 const sp<IGraphicBufferConsumer> &bufferConsumer) = 0;
125
Andy McFadden7cd58532013-02-19 07:28:30 -0800126 virtual status_t signalEndOfInputStream(node_id node) = 0;
127
Andreas Huber570a3cb2010-01-20 15:05:46 -0800128 // This API clearly only makes sense if the caller lives in the
129 // same process as the callee, i.e. is the media_server, as the
130 // returned "buffer_data" pointer is just that, a pointer into local
131 // address space.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700132 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700133 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800134 buffer_id *buffer, void **buffer_data) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700135
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700136 // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
137 // may be larger.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700138 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700139 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
Lajos Molnarcc7cc672015-06-01 14:58:37 -0700140 buffer_id *buffer, OMX_U32 allottedSize) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700141
Andreas Huber318ad9c2009-10-15 13:46:54 -0700142 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700143 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
144
Andreas Huber318ad9c2009-10-15 13:46:54 -0700145 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700146
Andreas Huber318ad9c2009-10-15 13:46:54 -0700147 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700148 node_id node,
149 buffer_id buffer,
150 OMX_U32 range_offset, OMX_U32 range_length,
151 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700152
Andreas Huber318ad9c2009-10-15 13:46:54 -0700153 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700154 node_id node,
155 const char *parameter_name,
156 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700157
158 enum InternalOptionType {
159 INTERNAL_OPTION_SUSPEND, // data is a bool
Andreas Hubera61285d2013-07-31 13:50:42 -0700160 INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t
Chong Zhang94ee4b72014-01-10 17:36:57 -0800161 INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
Ronghua Wu37b2b382015-01-26 15:47:10 -0800162 INTERNAL_OPTION_MAX_FPS, // data is float
Chong Zhang72cecca2013-12-26 01:38:35 -0800163 INTERNAL_OPTION_START_TIME, // data is an int64_t
Chong Zhang2c9c8cb2014-02-11 13:54:59 -0800164 INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2]
Andreas Hubere40cda72013-07-17 13:55:26 -0700165 };
166 virtual status_t setInternalOption(
167 node_id node,
168 OMX_U32 port_index,
169 InternalOptionType type,
170 const void *data,
171 size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700172};
173
174struct omx_message {
175 enum {
176 EVENT,
177 EMPTY_BUFFER_DONE,
178 FILL_BUFFER_DONE,
179
Andreas Huber20111aa2009-07-14 16:56:47 -0700180 } type;
181
Andreas Huber693d2712009-08-14 14:37:10 -0700182 IOMX::node_id node;
183
Andreas Huber20111aa2009-07-14 16:56:47 -0700184 union {
185 // if type == EVENT
186 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700187 OMX_EVENTTYPE event;
188 OMX_U32 data1;
189 OMX_U32 data2;
190 } event_data;
191
Andreas Hubere0f0b082009-08-27 14:50:58 -0700192 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700193 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700194 IOMX::buffer_id buffer;
195 } buffer_data;
196
Andreas Hubere0f0b082009-08-27 14:50:58 -0700197 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700198 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700199 IOMX::buffer_id buffer;
200 OMX_U32 range_offset;
201 OMX_U32 range_length;
202 OMX_U32 flags;
203 OMX_TICKS timestamp;
Andreas Huber20111aa2009-07-14 16:56:47 -0700204 } extended_buffer_data;
205
Andreas Huber20111aa2009-07-14 16:56:47 -0700206 } u;
207};
208
209class IOMXObserver : public IInterface {
210public:
211 DECLARE_META_INTERFACE(OMXObserver);
212
Andreas Huber318ad9c2009-10-15 13:46:54 -0700213 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700214};
215
216////////////////////////////////////////////////////////////////////////////////
217
218class BnOMX : public BnInterface<IOMX> {
219public:
220 virtual status_t onTransact(
221 uint32_t code, const Parcel &data, Parcel *reply,
222 uint32_t flags = 0);
223};
224
225class BnOMXObserver : public BnInterface<IOMXObserver> {
226public:
227 virtual status_t onTransact(
228 uint32_t code, const Parcel &data, Parcel *reply,
229 uint32_t flags = 0);
230};
231
James Dong457116d2011-07-11 12:29:10 -0700232struct CodecProfileLevel {
233 OMX_U32 mProfile;
234 OMX_U32 mLevel;
235};
236
Andreas Huber20111aa2009-07-14 16:56:47 -0700237} // namespace android
238
239#endif // ANDROID_IOMX_H_