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