Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2010, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "IEffect" |
| 20 | #include <utils/Log.h> |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <binder/Parcel.h> |
| 24 | #include <media/IEffect.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | enum { |
| 29 | ENABLE = IBinder::FIRST_CALL_TRANSACTION, |
| 30 | DISABLE, |
| 31 | COMMAND, |
| 32 | DISCONNECT, |
| 33 | GET_CBLK |
| 34 | }; |
| 35 | |
| 36 | class BpEffect: public BpInterface<IEffect> |
| 37 | { |
| 38 | public: |
| 39 | BpEffect(const sp<IBinder>& impl) |
| 40 | : BpInterface<IEffect>(impl) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | status_t enable() |
| 45 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 46 | ALOGV("enable"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 47 | Parcel data, reply; |
| 48 | data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); |
| 49 | remote()->transact(ENABLE, data, &reply); |
| 50 | return reply.readInt32(); |
| 51 | } |
| 52 | |
| 53 | status_t disable() |
| 54 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 55 | ALOGV("disable"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 56 | Parcel data, reply; |
| 57 | data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); |
| 58 | remote()->transact(DISABLE, data, &reply); |
| 59 | return reply.readInt32(); |
| 60 | } |
| 61 | |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 62 | status_t command(uint32_t cmdCode, |
| 63 | uint32_t cmdSize, |
| 64 | void *pCmdData, |
| 65 | uint32_t *pReplySize, |
| 66 | void *pReplyData) |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 67 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 68 | ALOGV("command"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 69 | Parcel data, reply; |
| 70 | data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); |
| 71 | data.writeInt32(cmdCode); |
| 72 | int size = cmdSize; |
| 73 | if (pCmdData == NULL) { |
| 74 | size = 0; |
| 75 | } |
| 76 | data.writeInt32(size); |
| 77 | if (size) { |
| 78 | data.write(pCmdData, size); |
| 79 | } |
| 80 | if (pReplySize == NULL) { |
| 81 | size = 0; |
| 82 | } else { |
| 83 | size = *pReplySize; |
| 84 | } |
| 85 | data.writeInt32(size); |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 86 | |
| 87 | status_t status = remote()->transact(COMMAND, data, &reply); |
Andy Hung | 25a6344 | 2015-09-01 20:07:56 +0000 | [diff] [blame^] | 88 | if (status == NO_ERROR) { |
| 89 | status = reply.readInt32(); |
| 90 | } |
John Grossman | af7d818 | 2012-01-11 12:23:42 -0800 | [diff] [blame] | 91 | if (status != NO_ERROR) { |
| 92 | if (pReplySize != NULL) |
| 93 | *pReplySize = 0; |
| 94 | return status; |
| 95 | } |
| 96 | |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 97 | size = reply.readInt32(); |
| 98 | if (size != 0 && pReplyData != NULL && pReplySize != NULL) { |
| 99 | reply.read(pReplyData, size); |
| 100 | *pReplySize = size; |
| 101 | } |
| 102 | return status; |
| 103 | } |
| 104 | |
| 105 | void disconnect() |
| 106 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 107 | ALOGV("disconnect"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 108 | Parcel data, reply; |
| 109 | data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); |
| 110 | remote()->transact(DISCONNECT, data, &reply); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | virtual sp<IMemory> getCblk() const |
| 115 | { |
| 116 | Parcel data, reply; |
| 117 | sp<IMemory> cblk; |
| 118 | data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); |
| 119 | status_t status = remote()->transact(GET_CBLK, data, &reply); |
| 120 | if (status == NO_ERROR) { |
| 121 | cblk = interface_cast<IMemory>(reply.readStrongBinder()); |
| 122 | } |
| 123 | return cblk; |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect"); |
| 128 | |
| 129 | // ---------------------------------------------------------------------- |
| 130 | |
| 131 | status_t BnEffect::onTransact( |
| 132 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 133 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 134 | switch (code) { |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 135 | case ENABLE: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 136 | ALOGV("ENABLE"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 137 | CHECK_INTERFACE(IEffect, data, reply); |
| 138 | reply->writeInt32(enable()); |
| 139 | return NO_ERROR; |
| 140 | } break; |
| 141 | |
| 142 | case DISABLE: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 143 | ALOGV("DISABLE"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 144 | CHECK_INTERFACE(IEffect, data, reply); |
| 145 | reply->writeInt32(disable()); |
| 146 | return NO_ERROR; |
| 147 | } break; |
| 148 | |
| 149 | case COMMAND: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 150 | ALOGV("COMMAND"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 151 | CHECK_INTERFACE(IEffect, data, reply); |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 152 | uint32_t cmdCode = data.readInt32(); |
| 153 | uint32_t cmdSize = data.readInt32(); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 154 | char *cmd = NULL; |
| 155 | if (cmdSize) { |
Andy Hung | 57bed83 | 2015-08-26 16:34:33 -0700 | [diff] [blame] | 156 | cmd = (char *)calloc(cmdSize, 1); |
Andy Hung | 25a6344 | 2015-09-01 20:07:56 +0000 | [diff] [blame^] | 157 | if (cmd == NULL) { |
| 158 | reply->writeInt32(NO_MEMORY); |
| 159 | return NO_ERROR; |
| 160 | } |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 161 | data.read(cmd, cmdSize); |
| 162 | } |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 163 | uint32_t replySize = data.readInt32(); |
| 164 | uint32_t replySz = replySize; |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 165 | char *resp = NULL; |
| 166 | if (replySize) { |
Andy Hung | 57bed83 | 2015-08-26 16:34:33 -0700 | [diff] [blame] | 167 | resp = (char *)calloc(replySize, 1); |
Andy Hung | 25a6344 | 2015-09-01 20:07:56 +0000 | [diff] [blame^] | 168 | if (resp == NULL) { |
| 169 | free(cmd); |
| 170 | reply->writeInt32(NO_MEMORY); |
| 171 | return NO_ERROR; |
| 172 | } |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 173 | } |
| 174 | status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp); |
| 175 | reply->writeInt32(status); |
Andy Hung | 25a6344 | 2015-09-01 20:07:56 +0000 | [diff] [blame^] | 176 | if (status == NO_ERROR) { |
| 177 | if (replySz < replySize) { |
| 178 | replySize = replySz; |
| 179 | } |
| 180 | reply->writeInt32(replySize); |
| 181 | if (replySize) { |
| 182 | reply->write(resp, replySize); |
| 183 | } |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 184 | } |
| 185 | if (cmd) { |
| 186 | free(cmd); |
| 187 | } |
| 188 | if (resp) { |
| 189 | free(resp); |
| 190 | } |
| 191 | return NO_ERROR; |
| 192 | } break; |
| 193 | |
| 194 | case DISCONNECT: { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 195 | ALOGV("DISCONNECT"); |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 196 | CHECK_INTERFACE(IEffect, data, reply); |
| 197 | disconnect(); |
| 198 | return NO_ERROR; |
| 199 | } break; |
| 200 | |
| 201 | case GET_CBLK: { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 202 | CHECK_INTERFACE(IEffect, data, reply); |
| 203 | reply->writeStrongBinder(getCblk()->asBinder()); |
| 204 | return NO_ERROR; |
| 205 | } break; |
Eric Laurent | d71a1be | 2010-05-21 07:47:50 -0700 | [diff] [blame] | 206 | |
| 207 | default: |
| 208 | return BBinder::onTransact(code, data, reply, flags); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // ---------------------------------------------------------------------------- |
| 213 | |
| 214 | }; // namespace android |