IOMX.h revision d291c222357303b9611cab89d0c3b047584ef377
1/* 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 <gui/IGraphicBufferProducer.h> 23#include <gui/IGraphicBufferConsumer.h> 24#include <ui/GraphicBuffer.h> 25#include <utils/List.h> 26#include <utils/String8.h> 27 28#include <OMX_Core.h> 29#include <OMX_Video.h> 30 31namespace android { 32 33class IMemory; 34class IOMXObserver; 35class IOMXRenderer; 36class Surface; 37 38class IOMX : public IInterface { 39public: 40 DECLARE_META_INTERFACE(OMX); 41 42 typedef uint32_t buffer_id; 43 typedef uint32_t node_id; 44 45 // Given a node_id and the calling process' pid, returns true iff 46 // the implementation of the OMX interface lives in the same 47 // process. 48 virtual bool livesLocally(node_id node, pid_t pid) = 0; 49 50 struct ComponentInfo { 51 String8 mName; 52 List<String8> mRoles; 53 }; 54 virtual status_t listNodes(List<ComponentInfo> *list) = 0; 55 56 virtual status_t allocateNode( 57 const char *name, const sp<IOMXObserver> &observer, 58 node_id *node) = 0; 59 60 virtual status_t freeNode(node_id node) = 0; 61 62 virtual status_t sendCommand( 63 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0; 64 65 virtual status_t getParameter( 66 node_id node, OMX_INDEXTYPE index, 67 void *params, size_t size) = 0; 68 69 virtual status_t setParameter( 70 node_id node, OMX_INDEXTYPE index, 71 const void *params, size_t size) = 0; 72 73 virtual status_t getConfig( 74 node_id node, OMX_INDEXTYPE index, 75 void *params, size_t size) = 0; 76 77 virtual status_t setConfig( 78 node_id node, OMX_INDEXTYPE index, 79 const void *params, size_t size) = 0; 80 81 virtual status_t getState( 82 node_id node, OMX_STATETYPE* state) = 0; 83 84 virtual status_t storeMetaDataInBuffers( 85 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0; 86 87 virtual status_t prepareForAdaptivePlayback( 88 node_id node, OMX_U32 portIndex, OMX_BOOL enable, 89 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0; 90 91 virtual status_t configureVideoTunnelMode( 92 node_id node, OMX_U32 portIndex, OMX_BOOL tunneled, 93 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0; 94 95 virtual status_t enableGraphicBuffers( 96 node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0; 97 98 virtual status_t getGraphicBufferUsage( 99 node_id node, OMX_U32 port_index, OMX_U32* usage) = 0; 100 101 virtual status_t useBuffer( 102 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 103 buffer_id *buffer) = 0; 104 105 virtual status_t useGraphicBuffer( 106 node_id node, OMX_U32 port_index, 107 const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0; 108 109 virtual status_t updateGraphicBufferInMeta( 110 node_id node, OMX_U32 port_index, 111 const sp<GraphicBuffer> &graphicBuffer, buffer_id buffer) = 0; 112 113 virtual status_t createInputSurface( 114 node_id node, OMX_U32 port_index, 115 sp<IGraphicBufferProducer> *bufferProducer) = 0; 116 117 virtual status_t createPersistentInputSurface( 118 sp<IGraphicBufferProducer> *bufferProducer, 119 sp<IGraphicBufferConsumer> *bufferConsumer) = 0; 120 121 virtual status_t usePersistentInputSurface( 122 node_id node, OMX_U32 port_index, 123 const sp<IGraphicBufferConsumer> &bufferConsumer) = 0; 124 125 virtual status_t signalEndOfInputStream(node_id node) = 0; 126 127 // This API clearly only makes sense if the caller lives in the 128 // same process as the callee, i.e. is the media_server, as the 129 // returned "buffer_data" pointer is just that, a pointer into local 130 // address space. 131 virtual status_t allocateBuffer( 132 node_id node, OMX_U32 port_index, size_t size, 133 buffer_id *buffer, void **buffer_data) = 0; 134 135 virtual status_t allocateBufferWithBackup( 136 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 137 buffer_id *buffer) = 0; 138 139 virtual status_t freeBuffer( 140 node_id node, OMX_U32 port_index, buffer_id buffer) = 0; 141 142 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0; 143 144 virtual status_t emptyBuffer( 145 node_id node, 146 buffer_id buffer, 147 OMX_U32 range_offset, OMX_U32 range_length, 148 OMX_U32 flags, OMX_TICKS timestamp) = 0; 149 150 virtual status_t getExtensionIndex( 151 node_id node, 152 const char *parameter_name, 153 OMX_INDEXTYPE *index) = 0; 154 155 enum InternalOptionType { 156 INTERNAL_OPTION_SUSPEND, // data is a bool 157 INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t 158 INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t 159 INTERNAL_OPTION_MAX_FPS, // data is float 160 INTERNAL_OPTION_START_TIME, // data is an int64_t 161 INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2] 162 }; 163 virtual status_t setInternalOption( 164 node_id node, 165 OMX_U32 port_index, 166 InternalOptionType type, 167 const void *data, 168 size_t size) = 0; 169}; 170 171struct omx_message { 172 enum { 173 EVENT, 174 EMPTY_BUFFER_DONE, 175 FILL_BUFFER_DONE, 176 177 } type; 178 179 IOMX::node_id node; 180 181 union { 182 // if type == EVENT 183 struct { 184 OMX_EVENTTYPE event; 185 OMX_U32 data1; 186 OMX_U32 data2; 187 } event_data; 188 189 // if type == EMPTY_BUFFER_DONE 190 struct { 191 IOMX::buffer_id buffer; 192 } buffer_data; 193 194 // if type == FILL_BUFFER_DONE 195 struct { 196 IOMX::buffer_id buffer; 197 OMX_U32 range_offset; 198 OMX_U32 range_length; 199 OMX_U32 flags; 200 OMX_TICKS timestamp; 201 } extended_buffer_data; 202 203 } u; 204}; 205 206class IOMXObserver : public IInterface { 207public: 208 DECLARE_META_INTERFACE(OMXObserver); 209 210 virtual void onMessage(const omx_message &msg) = 0; 211}; 212 213//////////////////////////////////////////////////////////////////////////////// 214 215class BnOMX : public BnInterface<IOMX> { 216public: 217 virtual status_t onTransact( 218 uint32_t code, const Parcel &data, Parcel *reply, 219 uint32_t flags = 0); 220}; 221 222class BnOMXObserver : public BnInterface<IOMXObserver> { 223public: 224 virtual status_t onTransact( 225 uint32_t code, const Parcel &data, Parcel *reply, 226 uint32_t flags = 0); 227}; 228 229struct CodecProfileLevel { 230 OMX_U32 mProfile; 231 OMX_U32 mLevel; 232}; 233 234} // namespace android 235 236#endif // ANDROID_IOMX_H_ 237