blob: 3db2c3855c5f405a9f84e0635139c46a960d200d [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>
Jamie Gennis83750ea2010-08-30 16:48:38 -070023#include <ui/GraphicBuffer.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070024#include <utils/List.h>
25#include <utils/String8.h>
26
27#include <OMX_Core.h>
Andreas Huber8b938cd2009-07-31 11:52:50 -070028#include <OMX_Video.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070029
Andreas Huber20111aa2009-07-14 16:56:47 -070030namespace android {
31
32class IMemory;
33class IOMXObserver;
Andreas Huber8b938cd2009-07-31 11:52:50 -070034class IOMXRenderer;
Andreas Huberf4148b52009-08-07 12:01:29 -070035class Surface;
Andreas Huber20111aa2009-07-14 16:56:47 -070036
37class IOMX : public IInterface {
38public:
39 DECLARE_META_INTERFACE(OMX);
40
41 typedef void *buffer_id;
42 typedef void *node_id;
43
Andreas Huberd459b482012-01-31 11:16:24 -080044 // Given a node_id and the calling process' pid, returns true iff
Andreas Huber7eaa9c92010-01-15 15:28:19 -080045 // the implementation of the OMX interface lives in the same
46 // process.
Andreas Huberd459b482012-01-31 11:16:24 -080047 virtual bool livesLocally(node_id node, pid_t pid) = 0;
Andreas Huber7eaa9c92010-01-15 15:28:19 -080048
Andreas Huber134ee6a2009-12-16 09:30:55 -080049 struct ComponentInfo {
50 String8 mName;
51 List<String8> mRoles;
52 };
53 virtual status_t listNodes(List<ComponentInfo> *list) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070054
Andreas Huber318ad9c2009-10-15 13:46:54 -070055 virtual status_t allocateNode(
56 const char *name, const sp<IOMXObserver> &observer,
57 node_id *node) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -070058
Andreas Huber318ad9c2009-10-15 13:46:54 -070059 virtual status_t freeNode(node_id node) = 0;
60
61 virtual status_t sendCommand(
Andreas Huber20111aa2009-07-14 16:56:47 -070062 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
63
Andreas Huber318ad9c2009-10-15 13:46:54 -070064 virtual status_t getParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070065 node_id node, OMX_INDEXTYPE index,
66 void *params, size_t size) = 0;
67
Andreas Huber318ad9c2009-10-15 13:46:54 -070068 virtual status_t setParameter(
Andreas Huber20111aa2009-07-14 16:56:47 -070069 node_id node, OMX_INDEXTYPE index,
70 const void *params, size_t size) = 0;
71
Andreas Huber318ad9c2009-10-15 13:46:54 -070072 virtual status_t getConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070073 node_id node, OMX_INDEXTYPE index,
74 void *params, size_t size) = 0;
75
Andreas Huber318ad9c2009-10-15 13:46:54 -070076 virtual status_t setConfig(
Andreas Huber693d2712009-08-14 14:37:10 -070077 node_id node, OMX_INDEXTYPE index,
78 const void *params, size_t size) = 0;
79
Jamie Gennisb1d666f2011-10-19 21:14:13 -070080 virtual status_t getState(
81 node_id node, OMX_STATETYPE* state) = 0;
82
James Donge8707722010-10-20 17:38:41 -070083 virtual status_t storeMetaDataInBuffers(
84 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
85
Lajos Molnar56ce7262013-05-02 16:30:48 -070086 virtual status_t prepareForAdaptivePlayback(
87 node_id node, OMX_U32 portIndex, OMX_BOOL enable,
88 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
89
Jamie Gennis83750ea2010-08-30 16:48:38 -070090 virtual status_t enableGraphicBuffers(
91 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
92
Jamie Gennise2ce6452011-02-23 19:01:28 -080093 virtual status_t getGraphicBufferUsage(
94 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
95
Andreas Huber318ad9c2009-10-15 13:46:54 -070096 virtual status_t useBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -070097 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
98 buffer_id *buffer) = 0;
99
Jamie Gennis83750ea2010-08-30 16:48:38 -0700100 virtual status_t useGraphicBuffer(
101 node_id node, OMX_U32 port_index,
102 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
103
Lajos Molnard0715862013-07-22 12:57:43 -0700104 virtual status_t updateGraphicBufferInMeta(
105 node_id node, OMX_U32 port_index,
106 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0;
107
Andy McFadden7cd58532013-02-19 07:28:30 -0800108 virtual status_t createInputSurface(
109 node_id node, OMX_U32 port_index,
110 sp<IGraphicBufferProducer> *bufferProducer) = 0;
111
112 virtual status_t signalEndOfInputStream(node_id node) = 0;
113
Andreas Huber570a3cb2010-01-20 15:05:46 -0800114 // This API clearly only makes sense if the caller lives in the
115 // same process as the callee, i.e. is the media_server, as the
116 // returned "buffer_data" pointer is just that, a pointer into local
117 // address space.
Andreas Huber318ad9c2009-10-15 13:46:54 -0700118 virtual status_t allocateBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700119 node_id node, OMX_U32 port_index, size_t size,
Andreas Huber570a3cb2010-01-20 15:05:46 -0800120 buffer_id *buffer, void **buffer_data) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700121
Andreas Huber318ad9c2009-10-15 13:46:54 -0700122 virtual status_t allocateBufferWithBackup(
Andreas Huber20111aa2009-07-14 16:56:47 -0700123 node_id node, OMX_U32 port_index, const sp<IMemory> &params,
124 buffer_id *buffer) = 0;
125
Andreas Huber318ad9c2009-10-15 13:46:54 -0700126 virtual status_t freeBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700127 node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
128
Andreas Huber318ad9c2009-10-15 13:46:54 -0700129 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700130
Andreas Huber318ad9c2009-10-15 13:46:54 -0700131 virtual status_t emptyBuffer(
Andreas Huber20111aa2009-07-14 16:56:47 -0700132 node_id node,
133 buffer_id buffer,
134 OMX_U32 range_offset, OMX_U32 range_length,
135 OMX_U32 flags, OMX_TICKS timestamp) = 0;
Andreas Huber8b938cd2009-07-31 11:52:50 -0700136
Andreas Huber318ad9c2009-10-15 13:46:54 -0700137 virtual status_t getExtensionIndex(
Andreas Huber693d2712009-08-14 14:37:10 -0700138 node_id node,
139 const char *parameter_name,
140 OMX_INDEXTYPE *index) = 0;
Andreas Hubere40cda72013-07-17 13:55:26 -0700141
142 enum InternalOptionType {
143 INTERNAL_OPTION_SUSPEND, // data is a bool
Andreas Hubera61285d2013-07-31 13:50:42 -0700144 INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t
Chong Zhang94ee4b72014-01-10 17:36:57 -0800145 INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t
Chong Zhang72cecca2013-12-26 01:38:35 -0800146 INTERNAL_OPTION_START_TIME, // data is an int64_t
Andreas Hubere40cda72013-07-17 13:55:26 -0700147 };
148 virtual status_t setInternalOption(
149 node_id node,
150 OMX_U32 port_index,
151 InternalOptionType type,
152 const void *data,
153 size_t size) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700154};
155
156struct omx_message {
157 enum {
158 EVENT,
159 EMPTY_BUFFER_DONE,
160 FILL_BUFFER_DONE,
161
Andreas Huber20111aa2009-07-14 16:56:47 -0700162 } type;
163
Andreas Huber693d2712009-08-14 14:37:10 -0700164 IOMX::node_id node;
165
Andreas Huber20111aa2009-07-14 16:56:47 -0700166 union {
167 // if type == EVENT
168 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700169 OMX_EVENTTYPE event;
170 OMX_U32 data1;
171 OMX_U32 data2;
172 } event_data;
173
Andreas Hubere0f0b082009-08-27 14:50:58 -0700174 // if type == EMPTY_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700175 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700176 IOMX::buffer_id buffer;
177 } buffer_data;
178
Andreas Hubere0f0b082009-08-27 14:50:58 -0700179 // if type == FILL_BUFFER_DONE
Andreas Huber20111aa2009-07-14 16:56:47 -0700180 struct {
Andreas Huber20111aa2009-07-14 16:56:47 -0700181 IOMX::buffer_id buffer;
182 OMX_U32 range_offset;
183 OMX_U32 range_length;
184 OMX_U32 flags;
185 OMX_TICKS timestamp;
Andreas Hubere0f0b082009-08-27 14:50:58 -0700186 OMX_PTR platform_private;
Andreas Huber213addf2010-01-25 10:41:35 -0800187 OMX_PTR data_ptr;
Andreas Huber20111aa2009-07-14 16:56:47 -0700188 } extended_buffer_data;
189
Andreas Huber20111aa2009-07-14 16:56:47 -0700190 } u;
191};
192
193class IOMXObserver : public IInterface {
194public:
195 DECLARE_META_INTERFACE(OMXObserver);
196
Andreas Huber318ad9c2009-10-15 13:46:54 -0700197 virtual void onMessage(const omx_message &msg) = 0;
Andreas Huber20111aa2009-07-14 16:56:47 -0700198};
199
200////////////////////////////////////////////////////////////////////////////////
201
202class BnOMX : public BnInterface<IOMX> {
203public:
204 virtual status_t onTransact(
205 uint32_t code, const Parcel &data, Parcel *reply,
206 uint32_t flags = 0);
207};
208
209class BnOMXObserver : public BnInterface<IOMXObserver> {
210public:
211 virtual status_t onTransact(
212 uint32_t code, const Parcel &data, Parcel *reply,
213 uint32_t flags = 0);
214};
215
James Dong457116d2011-07-11 12:29:10 -0700216struct CodecProfileLevel {
217 OMX_U32 mProfile;
218 OMX_U32 mLevel;
219};
220
Andreas Huber20111aa2009-07-14 16:56:47 -0700221} // namespace android
222
223#endif // ANDROID_IOMX_H_