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