IOMX.h revision f4148b55c5d6f68b22462e3880015fefa91ae7c6
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 use_buffer( 60 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 61 buffer_id *buffer) = 0; 62 63 virtual status_t allocate_buffer( 64 node_id node, OMX_U32 port_index, size_t size, 65 buffer_id *buffer) = 0; 66 67 virtual status_t allocate_buffer_with_backup( 68 node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms, 69 buffer_id *buffer) = 0; 70 71 virtual status_t free_buffer( 72 node_id node, OMX_U32 port_index, buffer_id buffer) = 0; 73 74 virtual status_t observe_node( 75 node_id node, const sp<IOMXObserver> &observer) = 0; 76 77 virtual void fill_buffer(node_id node, buffer_id buffer) = 0; 78 79 virtual void empty_buffer( 80 node_id node, 81 buffer_id buffer, 82 OMX_U32 range_offset, OMX_U32 range_length, 83 OMX_U32 flags, OMX_TICKS timestamp) = 0; 84 85 virtual sp<IOMXRenderer> createRenderer( 86 const sp<ISurface> &surface, 87 const char *componentName, 88 OMX_COLOR_FORMATTYPE colorFormat, 89 size_t encodedWidth, size_t encodedHeight, 90 size_t displayWidth, size_t displayHeight) = 0; 91 92 // Note: This method is _not_ virtual, it exists as a wrapper around 93 // the virtual "createRenderer" method above facilitating extraction 94 // of the ISurface from a regular Surface. 95 sp<IOMXRenderer> createRenderer( 96 const sp<Surface> &surface, 97 const char *componentName, 98 OMX_COLOR_FORMATTYPE colorFormat, 99 size_t encodedWidth, size_t encodedHeight, 100 size_t displayWidth, size_t displayHeight); 101}; 102 103struct omx_message { 104 enum { 105 EVENT, 106 EMPTY_BUFFER_DONE, 107 FILL_BUFFER_DONE, 108 109 // reserved for OMXDecoder use. 110 START, 111 INITIAL_FILL_BUFFER, 112 113 // reserved for OMXObserver use. 114 QUIT_OBSERVER, 115 } type; 116 117 union { 118 // if type == EVENT 119 struct { 120 IOMX::node_id node; 121 OMX_EVENTTYPE event; 122 OMX_U32 data1; 123 OMX_U32 data2; 124 } event_data; 125 126 // if type == EMPTY_BUFFER_DONE || type == FILL_BUFFER 127 // || type == INITIAL_FILL_BUFFER 128 struct { 129 IOMX::node_id node; 130 IOMX::buffer_id buffer; 131 } buffer_data; 132 133 // if type == EMPTY_BUFFER || type == FILL_BUFFER_DONE 134 struct { 135 IOMX::node_id node; 136 IOMX::buffer_id buffer; 137 OMX_U32 range_offset; 138 OMX_U32 range_length; 139 OMX_U32 flags; 140 OMX_TICKS timestamp; 141 OMX_PTR platform_private; // ignored if type == EMPTY_BUFFER 142 } extended_buffer_data; 143 144 // if type == SEND_COMMAND 145 struct { 146 IOMX::node_id node; 147 OMX_COMMANDTYPE cmd; 148 OMX_S32 param; 149 } send_command_data; 150 151 } u; 152}; 153 154class IOMXObserver : public IInterface { 155public: 156 DECLARE_META_INTERFACE(OMXObserver); 157 158 virtual void on_message(const omx_message &msg) = 0; 159}; 160 161class IOMXRenderer : public IInterface { 162public: 163 DECLARE_META_INTERFACE(OMXRenderer); 164 165 virtual void render(IOMX::buffer_id buffer) = 0; 166}; 167 168//////////////////////////////////////////////////////////////////////////////// 169 170class BnOMX : public BnInterface<IOMX> { 171public: 172 virtual status_t onTransact( 173 uint32_t code, const Parcel &data, Parcel *reply, 174 uint32_t flags = 0); 175}; 176 177class BnOMXObserver : public BnInterface<IOMXObserver> { 178public: 179 virtual status_t onTransact( 180 uint32_t code, const Parcel &data, Parcel *reply, 181 uint32_t flags = 0); 182}; 183 184class BnOMXRenderer : public BnInterface<IOMXRenderer> { 185public: 186 virtual status_t onTransact( 187 uint32_t code, const Parcel &data, Parcel *reply, 188 uint32_t flags = 0); 189}; 190 191} // namespace android 192 193#endif // ANDROID_IOMX_H_ 194