IOMX.h revision 134ee6a324c35f39e3576172e4eae4c6de6eb9dc
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 struct ComponentInfo { 46 String8 mName; 47 List<String8> mRoles; 48 }; 49 virtual status_t listNodes(List<ComponentInfo> *list) = 0; 50 51 virtual status_t allocateNode( 52 const char *name, const sp<IOMXObserver> &observer, 53 node_id *node) = 0; 54 55 virtual status_t freeNode(node_id node) = 0; 56 57 virtual status_t sendCommand( 58 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0; 59 60 virtual status_t getParameter( 61 node_id node, OMX_INDEXTYPE index, 62 void *params, size_t size) = 0; 63 64 virtual status_t setParameter( 65 node_id node, OMX_INDEXTYPE index, 66 const void *params, size_t size) = 0; 67 68 virtual status_t getConfig( 69 node_id node, OMX_INDEXTYPE index, 70 void *params, size_t size) = 0; 71 72 virtual status_t setConfig( 73 node_id node, OMX_INDEXTYPE index, 74 const void *params, size_t size) = 0; 75 76 virtual status_t useBuffer( 77 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 78 buffer_id *buffer) = 0; 79 80 virtual status_t allocateBuffer( 81 node_id node, OMX_U32 port_index, size_t size, 82 buffer_id *buffer) = 0; 83 84 virtual status_t allocateBufferWithBackup( 85 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 86 buffer_id *buffer) = 0; 87 88 virtual status_t freeBuffer( 89 node_id node, OMX_U32 port_index, buffer_id buffer) = 0; 90 91 virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0; 92 93 virtual status_t emptyBuffer( 94 node_id node, 95 buffer_id buffer, 96 OMX_U32 range_offset, OMX_U32 range_length, 97 OMX_U32 flags, OMX_TICKS timestamp) = 0; 98 99 virtual status_t getExtensionIndex( 100 node_id node, 101 const char *parameter_name, 102 OMX_INDEXTYPE *index) = 0; 103 104 virtual sp<IOMXRenderer> createRenderer( 105 const sp<ISurface> &surface, 106 const char *componentName, 107 OMX_COLOR_FORMATTYPE colorFormat, 108 size_t encodedWidth, size_t encodedHeight, 109 size_t displayWidth, size_t displayHeight) = 0; 110 111 // Note: These methods are _not_ virtual, it exists as a wrapper around 112 // the virtual "createRenderer" method above facilitating extraction 113 // of the ISurface from a regular Surface or a java Surface object. 114 sp<IOMXRenderer> createRenderer( 115 const sp<Surface> &surface, 116 const char *componentName, 117 OMX_COLOR_FORMATTYPE colorFormat, 118 size_t encodedWidth, size_t encodedHeight, 119 size_t displayWidth, size_t displayHeight); 120 121 sp<IOMXRenderer> createRendererFromJavaSurface( 122 JNIEnv *env, jobject javaSurface, 123 const char *componentName, 124 OMX_COLOR_FORMATTYPE colorFormat, 125 size_t encodedWidth, size_t encodedHeight, 126 size_t displayWidth, size_t displayHeight); 127}; 128 129struct omx_message { 130 enum { 131 EVENT, 132 EMPTY_BUFFER_DONE, 133 FILL_BUFFER_DONE, 134 135 } type; 136 137 IOMX::node_id node; 138 139 union { 140 // if type == EVENT 141 struct { 142 OMX_EVENTTYPE event; 143 OMX_U32 data1; 144 OMX_U32 data2; 145 } event_data; 146 147 // if type == EMPTY_BUFFER_DONE 148 struct { 149 IOMX::buffer_id buffer; 150 } buffer_data; 151 152 // if type == FILL_BUFFER_DONE 153 struct { 154 IOMX::buffer_id buffer; 155 OMX_U32 range_offset; 156 OMX_U32 range_length; 157 OMX_U32 flags; 158 OMX_TICKS timestamp; 159 OMX_PTR platform_private; 160 } extended_buffer_data; 161 162 } u; 163}; 164 165class IOMXObserver : public IInterface { 166public: 167 DECLARE_META_INTERFACE(OMXObserver); 168 169 virtual void onMessage(const omx_message &msg) = 0; 170}; 171 172class IOMXRenderer : public IInterface { 173public: 174 DECLARE_META_INTERFACE(OMXRenderer); 175 176 virtual void render(IOMX::buffer_id buffer) = 0; 177}; 178 179//////////////////////////////////////////////////////////////////////////////// 180 181class BnOMX : public BnInterface<IOMX> { 182public: 183 virtual status_t onTransact( 184 uint32_t code, const Parcel &data, Parcel *reply, 185 uint32_t flags = 0); 186}; 187 188class BnOMXObserver : public BnInterface<IOMXObserver> { 189public: 190 virtual status_t onTransact( 191 uint32_t code, const Parcel &data, Parcel *reply, 192 uint32_t flags = 0); 193}; 194 195class BnOMXRenderer : public BnInterface<IOMXRenderer> { 196public: 197 virtual status_t onTransact( 198 uint32_t code, const Parcel &data, Parcel *reply, 199 uint32_t flags = 0); 200}; 201 202} // namespace android 203 204#endif // ANDROID_IOMX_H_ 205