IOMX.h revision 693d271e62a3726689ff68f4505ba49228eb94b2
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 28namespace android { 29 30class IMemory; 31class IOMXObserver; 32class IOMXRenderer; 33class ISurface; 34class Surface; 35 36class IOMX : public IInterface { 37public: 38 DECLARE_META_INTERFACE(OMX); 39 40 typedef void *buffer_id; 41 typedef void *node_id; 42 43 virtual status_t list_nodes(List<String8> *list) = 0; 44 45 virtual status_t allocate_node(const char *name, node_id *node) = 0; 46 virtual status_t free_node(node_id node) = 0; 47 48 virtual status_t send_command( 49 node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0; 50 51 virtual status_t get_parameter( 52 node_id node, OMX_INDEXTYPE index, 53 void *params, size_t size) = 0; 54 55 virtual status_t set_parameter( 56 node_id node, OMX_INDEXTYPE index, 57 const void *params, size_t size) = 0; 58 59 virtual status_t get_config( 60 node_id node, OMX_INDEXTYPE index, 61 void *params, size_t size) = 0; 62 63 virtual status_t set_config( 64 node_id node, OMX_INDEXTYPE index, 65 const void *params, size_t size) = 0; 66 67 virtual status_t use_buffer( 68 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 69 buffer_id *buffer) = 0; 70 71 virtual status_t allocate_buffer( 72 node_id node, OMX_U32 port_index, size_t size, 73 buffer_id *buffer) = 0; 74 75 virtual status_t allocate_buffer_with_backup( 76 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 77 buffer_id *buffer) = 0; 78 79 virtual status_t free_buffer( 80 node_id node, OMX_U32 port_index, buffer_id buffer) = 0; 81 82 virtual status_t observe_node( 83 node_id node, const sp<IOMXObserver> &observer) = 0; 84 85 virtual void fill_buffer(node_id node, buffer_id buffer) = 0; 86 87 virtual void empty_buffer( 88 node_id node, 89 buffer_id buffer, 90 OMX_U32 range_offset, OMX_U32 range_length, 91 OMX_U32 flags, OMX_TICKS timestamp) = 0; 92 93 virtual status_t get_extension_index( 94 node_id node, 95 const char *parameter_name, 96 OMX_INDEXTYPE *index) = 0; 97 98 virtual sp<IOMXRenderer> createRenderer( 99 const sp<ISurface> &surface, 100 const char *componentName, 101 OMX_COLOR_FORMATTYPE colorFormat, 102 size_t encodedWidth, size_t encodedHeight, 103 size_t displayWidth, size_t displayHeight) = 0; 104 105 // Note: This method is _not_ virtual, it exists as a wrapper around 106 // the virtual "createRenderer" method above facilitating extraction 107 // of the ISurface from a regular Surface. 108 sp<IOMXRenderer> createRenderer( 109 const sp<Surface> &surface, 110 const char *componentName, 111 OMX_COLOR_FORMATTYPE colorFormat, 112 size_t encodedWidth, size_t encodedHeight, 113 size_t displayWidth, size_t displayHeight); 114}; 115 116struct omx_message { 117 enum { 118 EVENT, 119 EMPTY_BUFFER_DONE, 120 FILL_BUFFER_DONE, 121 122 // reserved for OMXDecoder use. 123 START, 124 INITIAL_FILL_BUFFER, 125 126 // reserved for OMXObserver use. 127 QUIT_OBSERVER, 128 } type; 129 130 IOMX::node_id node; 131 132 union { 133 // if type == EVENT 134 struct { 135 OMX_EVENTTYPE event; 136 OMX_U32 data1; 137 OMX_U32 data2; 138 } event_data; 139 140 // if type == EMPTY_BUFFER_DONE || type == FILL_BUFFER 141 // || type == INITIAL_FILL_BUFFER 142 struct { 143 IOMX::buffer_id buffer; 144 } buffer_data; 145 146 // if type == EMPTY_BUFFER || type == FILL_BUFFER_DONE 147 struct { 148 IOMX::buffer_id buffer; 149 OMX_U32 range_offset; 150 OMX_U32 range_length; 151 OMX_U32 flags; 152 OMX_TICKS timestamp; 153 OMX_PTR platform_private; // ignored if type == EMPTY_BUFFER 154 } extended_buffer_data; 155 156 // if type == SEND_COMMAND 157 struct { 158 OMX_COMMANDTYPE cmd; 159 OMX_S32 param; 160 } send_command_data; 161 162 } u; 163}; 164 165class IOMXObserver : public IInterface { 166public: 167 DECLARE_META_INTERFACE(OMXObserver); 168 169 virtual void on_message(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