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 <utils/List.h> 23 #include <utils/String8.h> 24 #include <cutils/native_handle.h> 25 26 #include <list> 27 28 #include <hidl/HybridInterface.h> 29 #include <media/hardware/MetadataBufferType.h> 30 #include <android/hardware/media/omx/1.0/IOmxNode.h> 31 32 #include <media/openmax/OMX_Core.h> 33 #include <media/openmax/OMX_Video.h> 34 #include <media/openmax/OMX_VideoExt.h> 35 36 namespace android { 37 namespace hardware { 38 namespace media { 39 namespace omx { 40 namespace V1_0 { 41 struct IGraphicBufferSource; 42 } // namespace V1_0 43 } // namespace omx 44 } // namespace media 45 } // namespace hardware 46 47 class IGraphicBufferProducer; 48 class IMemory; 49 class IOMXBufferSource; 50 class IOMXNode; 51 class IOMXObserver; 52 class NativeHandle; 53 class OMXBuffer; 54 struct omx_message; 55 56 using hardware::media::omx::V1_0::IOmxNode; 57 58 class IOMX : public RefBase { 59 public: 60 61 typedef uint32_t buffer_id; 62 63 enum { 64 kFenceTimeoutMs = 1000 65 }; 66 67 enum PortMode { 68 kPortModePresetStart = 0, 69 kPortModePresetByteBuffer, 70 kPortModePresetANWBuffer, 71 kPortModePresetSecureBuffer, 72 kPortModePresetEnd, 73 74 kPortModeDynamicStart = 100, 75 kPortModeDynamicANWBuffer, // uses metadata mode kMetadataBufferTypeANWBuffer 76 // or kMetadataBufferTypeGrallocSource 77 kPortModeDynamicNativeHandle, // uses metadata mode kMetadataBufferTypeNativeHandleSource 78 kPortModeDynamicEnd, 79 }; 80 81 struct ComponentInfo { 82 String8 mName; 83 List<String8> mRoles; 84 }; 85 virtual status_t listNodes(List<ComponentInfo> *list) = 0; 86 87 virtual status_t allocateNode( 88 const char *name, const sp<IOMXObserver> &observer, 89 sp<IOMXNode> *omxNode) = 0; 90 91 virtual status_t createInputSurface( 92 sp<IGraphicBufferProducer> *bufferProducer, 93 sp<hardware::media::omx::V1_0::IGraphicBufferSource> *bufferSource) = 0; 94 }; 95 96 class IOMXNode : public IInterface { 97 public: 98 DECLARE_HYBRID_META_INTERFACE(OMXNode, IOmxNode); 99 100 typedef IOMX::buffer_id buffer_id; 101 102 virtual status_t freeNode() = 0; 103 104 virtual status_t sendCommand( 105 OMX_COMMANDTYPE cmd, OMX_S32 param) = 0; 106 107 virtual status_t getParameter( 108 OMX_INDEXTYPE index, void *params, size_t size) = 0; 109 110 virtual status_t setParameter( 111 OMX_INDEXTYPE index, const void *params, size_t size) = 0; 112 113 virtual status_t getConfig( 114 OMX_INDEXTYPE index, void *params, size_t size) = 0; 115 116 virtual status_t setConfig( 117 OMX_INDEXTYPE index, const void *params, size_t size) = 0; 118 119 virtual status_t setPortMode( 120 OMX_U32 port_index, IOMX::PortMode mode) = 0; 121 122 virtual status_t prepareForAdaptivePlayback( 123 OMX_U32 portIndex, OMX_BOOL enable, 124 OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0; 125 126 virtual status_t configureVideoTunnelMode( 127 OMX_U32 portIndex, OMX_BOOL tunneled, 128 OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0; 129 130 virtual status_t getGraphicBufferUsage( 131 OMX_U32 port_index, OMX_U32* usage) = 0; 132 133 virtual status_t setInputSurface( 134 const sp<IOMXBufferSource> &bufferSource) = 0; 135 136 // Allocate an opaque buffer as a native handle. If component supports returning native 137 // handles, those are returned in *native_handle. Otherwise, the allocated buffer is 138 // returned in *buffer_data. This clearly only makes sense if the caller lives in the 139 // same process as the callee, i.e. is the media_server, as the returned "buffer_data" 140 // pointer is just that, a pointer into local address space. 141 virtual status_t allocateSecureBuffer( 142 OMX_U32 port_index, size_t size, buffer_id *buffer, 143 void **buffer_data, sp<NativeHandle> *native_handle) = 0; 144 145 // Instructs the component to use the buffer passed in via |omxBuf| on the 146 // specified port. Returns in |*buffer| the buffer id that the component 147 // assigns to this buffer. |omxBuf| must be one of: 148 // 1) OMXBuffer::sPreset for meta-mode, 149 // 2) type kBufferTypeANWBuffer for non-meta-graphic buffer mode, 150 // 3) type kBufferTypeSharedMem for bytebuffer mode. 151 virtual status_t useBuffer( 152 OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) = 0; 153 154 // Frees the buffer on the specified port with buffer id |buffer|. 155 virtual status_t freeBuffer( 156 OMX_U32 port_index, buffer_id buffer) = 0; 157 158 // Calls OMX_FillBuffer on buffer. Passes |fenceFd| to component if it 159 // supports fences. Otherwise, it waits on |fenceFd| before calling 160 // OMX_FillBuffer. Takes ownership of |fenceFd| even if this call fails. 161 // If the port is in metadata mode, the buffer will be updated to point 162 // to the new buffer passed in via |omxBuf| before OMX_FillBuffer is called. 163 // Otherwise info in the |omxBuf| is not used. 164 virtual status_t fillBuffer( 165 buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd = -1) = 0; 166 167 // Calls OMX_EmptyBuffer on buffer. Passes |fenceFd| to component if it 168 // supports fences. Otherwise, it waits on |fenceFd| before calling 169 // OMX_EmptyBuffer. Takes ownership of |fenceFd| even if this call fails. 170 // If the port is in metadata mode, the buffer will be updated to point 171 // to the new buffer passed in via |omxBuf| before OMX_EmptyBuffer is called. 172 virtual status_t emptyBuffer( 173 buffer_id buffer, const OMXBuffer &omxBuf, 174 OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0; 175 176 virtual status_t getExtensionIndex( 177 const char *parameter_name, 178 OMX_INDEXTYPE *index) = 0; 179 180 virtual status_t dispatchMessage(const omx_message &msg) = 0; 181 }; 182 183 struct omx_message { 184 enum { 185 EVENT, 186 EMPTY_BUFFER_DONE, 187 FILL_BUFFER_DONE, 188 FRAME_RENDERED, 189 } type; 190 191 int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this 192 193 union { 194 // if type == EVENT 195 struct { 196 OMX_EVENTTYPE event; 197 OMX_U32 data1; 198 OMX_U32 data2; 199 OMX_U32 data3; 200 OMX_U32 data4; 201 } event_data; 202 203 // if type == EMPTY_BUFFER_DONE 204 struct { 205 IOMX::buffer_id buffer; 206 } buffer_data; 207 208 // if type == FILL_BUFFER_DONE 209 struct { 210 IOMX::buffer_id buffer; 211 OMX_U32 range_offset; 212 OMX_U32 range_length; 213 OMX_U32 flags; 214 OMX_TICKS timestamp; 215 } extended_buffer_data; 216 217 // if type == FRAME_RENDERED 218 struct { 219 OMX_TICKS timestamp; 220 OMX_S64 nanoTime; 221 } render_data; 222 } u; 223 }; 224 225 class IOMXObserver : public IInterface { 226 public: 227 DECLARE_META_INTERFACE(OMXObserver); 228 229 // Handle (list of) messages. 230 virtual void onMessages(const std::list<omx_message> &messages) = 0; 231 }; 232 233 //////////////////////////////////////////////////////////////////////////////// 234 class BnOMXNode : public BnInterface<IOMXNode> { 235 public: 236 virtual status_t onTransact( 237 uint32_t code, const Parcel &data, Parcel *reply, 238 uint32_t flags = 0); 239 240 protected: 241 // check if the codec is secure. isSecure()242 virtual bool isSecure() const { 243 return false; 244 } 245 }; 246 247 class BnOMXObserver : public BnInterface<IOMXObserver> { 248 public: 249 virtual status_t onTransact( 250 uint32_t code, const Parcel &data, Parcel *reply, 251 uint32_t flags = 0); 252 }; 253 254 } // namespace android 255 256 #endif // ANDROID_IOMX_H_ 257