IOMX.h revision 7eaa9c9385535b651064e02d05a8ffa4b2359281
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 25#include <OMX_Core.h> 26#include <OMX_Video.h> 27 28#include "jni.h" 29 30namespace android { 31 32class IMemory; 33class IOMXObserver; 34class IOMXRenderer; 35class ISurface; 36class Surface; 37 38class IOMX : public IInterface { 39public: 40 DECLARE_META_INTERFACE(OMX); 41 42 typedef void *buffer_id; 43 typedef void *node_id; 44 45 // Given the calling process' pid, returns true iff 46 // the implementation of the OMX interface lives in the same 47 // process. 48 virtual bool livesLocally(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 useBuffer( 82 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 83 buffer_id *buffer) = 0; 84 85 virtual status_t allocateBuffer( 86 node_id node, OMX_U32 port_index, size_t size, 87 buffer_id *buffer) = 0; 88 89 virtual status_t allocateBufferWithBackup( 90 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 91 buffer_id *buffer) = 0; 92 93 virtual status_t freeBuffer( 94 node_id node, OMX_U32 port_index, buffer_id buffer) = 0; 95 96 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0; 97 98 virtual status_t emptyBuffer( 99 node_id node, 100 buffer_id buffer, 101 OMX_U32 range_offset, OMX_U32 range_length, 102 OMX_U32 flags, OMX_TICKS timestamp) = 0; 103 104 virtual status_t getExtensionIndex( 105 node_id node, 106 const char *parameter_name, 107 OMX_INDEXTYPE *index) = 0; 108 109 virtual sp<IOMXRenderer> createRenderer( 110 const sp<ISurface> &surface, 111 const char *componentName, 112 OMX_COLOR_FORMATTYPE colorFormat, 113 size_t encodedWidth, size_t encodedHeight, 114 size_t displayWidth, size_t displayHeight) = 0; 115 116 // Note: These methods are _not_ virtual, it exists as a wrapper around 117 // the virtual "createRenderer" method above facilitating extraction 118 // of the ISurface from a regular Surface or a java Surface object. 119 sp<IOMXRenderer> createRenderer( 120 const sp<Surface> &surface, 121 const char *componentName, 122 OMX_COLOR_FORMATTYPE colorFormat, 123 size_t encodedWidth, size_t encodedHeight, 124 size_t displayWidth, size_t displayHeight); 125 126 sp<IOMXRenderer> createRendererFromJavaSurface( 127 JNIEnv *env, jobject javaSurface, 128 const char *componentName, 129 OMX_COLOR_FORMATTYPE colorFormat, 130 size_t encodedWidth, size_t encodedHeight, 131 size_t displayWidth, size_t displayHeight); 132}; 133 134struct omx_message { 135 enum { 136 EVENT, 137 EMPTY_BUFFER_DONE, 138 FILL_BUFFER_DONE, 139 140 } type; 141 142 IOMX::node_id node; 143 144 union { 145 // if type == EVENT 146 struct { 147 OMX_EVENTTYPE event; 148 OMX_U32 data1; 149 OMX_U32 data2; 150 } event_data; 151 152 // if type == EMPTY_BUFFER_DONE 153 struct { 154 IOMX::buffer_id buffer; 155 } buffer_data; 156 157 // if type == FILL_BUFFER_DONE 158 struct { 159 IOMX::buffer_id buffer; 160 OMX_U32 range_offset; 161 OMX_U32 range_length; 162 OMX_U32 flags; 163 OMX_TICKS timestamp; 164 OMX_PTR platform_private; 165 } extended_buffer_data; 166 167 } u; 168}; 169 170class IOMXObserver : public IInterface { 171public: 172 DECLARE_META_INTERFACE(OMXObserver); 173 174 virtual void onMessage(const omx_message &msg) = 0; 175}; 176 177class IOMXRenderer : public IInterface { 178public: 179 DECLARE_META_INTERFACE(OMXRenderer); 180 181 virtual void render(IOMX::buffer_id buffer) = 0; 182}; 183 184//////////////////////////////////////////////////////////////////////////////// 185 186class BnOMX : public BnInterface<IOMX> { 187public: 188 virtual status_t onTransact( 189 uint32_t code, const Parcel &data, Parcel *reply, 190 uint32_t flags = 0); 191}; 192 193class BnOMXObserver : public BnInterface<IOMXObserver> { 194public: 195 virtual status_t onTransact( 196 uint32_t code, const Parcel &data, Parcel *reply, 197 uint32_t flags = 0); 198}; 199 200class BnOMXRenderer : public BnInterface<IOMXRenderer> { 201public: 202 virtual status_t onTransact( 203 uint32_t code, const Parcel &data, Parcel *reply, 204 uint32_t flags = 0); 205}; 206 207} // namespace android 208 209#endif // ANDROID_IOMX_H_ 210