blob: 9c70500ffe750f0b646b290d40f7dc21aa54215f [file] [log] [blame]
Eric Laurentd71a1be2010-05-21 07:47:50 -07001/*
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
26namespace android {
27
ragoe2759072016-11-22 18:02:48 -080028// Maximum command/reply size expected
29#define EFFECT_PARAM_SIZE_MAX 65536
30
Eric Laurentd71a1be2010-05-21 07:47:50 -070031enum {
32 ENABLE = IBinder::FIRST_CALL_TRANSACTION,
33 DISABLE,
34 COMMAND,
35 DISCONNECT,
36 GET_CBLK
37};
38
39class BpEffect: public BpInterface<IEffect>
40{
41public:
42 BpEffect(const sp<IBinder>& impl)
43 : BpInterface<IEffect>(impl)
44 {
45 }
46
47 status_t enable()
48 {
Steve Block3856b092011-10-20 11:56:00 +010049 ALOGV("enable");
Eric Laurentd71a1be2010-05-21 07:47:50 -070050 Parcel data, reply;
51 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
52 remote()->transact(ENABLE, data, &reply);
53 return reply.readInt32();
54 }
55
56 status_t disable()
57 {
Steve Block3856b092011-10-20 11:56:00 +010058 ALOGV("disable");
Eric Laurentd71a1be2010-05-21 07:47:50 -070059 Parcel data, reply;
60 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
61 remote()->transact(DISABLE, data, &reply);
62 return reply.readInt32();
63 }
64
Eric Laurent25f43952010-07-28 05:40:18 -070065 status_t command(uint32_t cmdCode,
66 uint32_t cmdSize,
67 void *pCmdData,
68 uint32_t *pReplySize,
69 void *pReplyData)
Eric Laurentd71a1be2010-05-21 07:47:50 -070070 {
Steve Block3856b092011-10-20 11:56:00 +010071 ALOGV("command");
Eric Laurentd71a1be2010-05-21 07:47:50 -070072 Parcel data, reply;
73 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
74 data.writeInt32(cmdCode);
75 int size = cmdSize;
76 if (pCmdData == NULL) {
77 size = 0;
78 }
79 data.writeInt32(size);
80 if (size) {
81 data.write(pCmdData, size);
82 }
83 if (pReplySize == NULL) {
84 size = 0;
85 } else {
86 size = *pReplySize;
87 }
88 data.writeInt32(size);
John Grossmanaf7d8182012-01-11 12:23:42 -080089
90 status_t status = remote()->transact(COMMAND, data, &reply);
Andy Hung25a63442015-09-01 20:07:56 +000091 if (status == NO_ERROR) {
92 status = reply.readInt32();
93 }
John Grossmanaf7d8182012-01-11 12:23:42 -080094 if (status != NO_ERROR) {
95 if (pReplySize != NULL)
96 *pReplySize = 0;
97 return status;
98 }
99
Eric Laurentd71a1be2010-05-21 07:47:50 -0700100 size = reply.readInt32();
101 if (size != 0 && pReplyData != NULL && pReplySize != NULL) {
102 reply.read(pReplyData, size);
103 *pReplySize = size;
104 }
105 return status;
106 }
107
108 void disconnect()
109 {
Steve Block3856b092011-10-20 11:56:00 +0100110 ALOGV("disconnect");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700111 Parcel data, reply;
112 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
113 remote()->transact(DISCONNECT, data, &reply);
114 return;
115 }
116
117 virtual sp<IMemory> getCblk() const
118 {
119 Parcel data, reply;
120 sp<IMemory> cblk;
121 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
122 status_t status = remote()->transact(GET_CBLK, data, &reply);
123 if (status == NO_ERROR) {
124 cblk = interface_cast<IMemory>(reply.readStrongBinder());
125 }
126 return cblk;
127 }
128 };
129
130IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect");
131
132// ----------------------------------------------------------------------
133
134status_t BnEffect::onTransact(
135 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
136{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700137 switch (code) {
Eric Laurentd71a1be2010-05-21 07:47:50 -0700138 case ENABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100139 ALOGV("ENABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700140 CHECK_INTERFACE(IEffect, data, reply);
141 reply->writeInt32(enable());
142 return NO_ERROR;
143 } break;
144
145 case DISABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100146 ALOGV("DISABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700147 CHECK_INTERFACE(IEffect, data, reply);
148 reply->writeInt32(disable());
149 return NO_ERROR;
150 } break;
151
152 case COMMAND: {
Steve Block3856b092011-10-20 11:56:00 +0100153 ALOGV("COMMAND");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700154 CHECK_INTERFACE(IEffect, data, reply);
Eric Laurent25f43952010-07-28 05:40:18 -0700155 uint32_t cmdCode = data.readInt32();
156 uint32_t cmdSize = data.readInt32();
Eric Laurentd71a1be2010-05-21 07:47:50 -0700157 char *cmd = NULL;
158 if (cmdSize) {
ragoe2759072016-11-22 18:02:48 -0800159 if (cmdSize > EFFECT_PARAM_SIZE_MAX) {
160 reply->writeInt32(NO_MEMORY);
161 return NO_ERROR;
162 }
Andy Hung57bed832015-08-26 16:34:33 -0700163 cmd = (char *)calloc(cmdSize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000164 if (cmd == NULL) {
165 reply->writeInt32(NO_MEMORY);
166 return NO_ERROR;
167 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700168 data.read(cmd, cmdSize);
169 }
Eric Laurent25f43952010-07-28 05:40:18 -0700170 uint32_t replySize = data.readInt32();
171 uint32_t replySz = replySize;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700172 char *resp = NULL;
173 if (replySize) {
ragoe2759072016-11-22 18:02:48 -0800174 if (replySize > EFFECT_PARAM_SIZE_MAX) {
175 free(cmd);
176 reply->writeInt32(NO_MEMORY);
177 return NO_ERROR;
178 }
Andy Hung57bed832015-08-26 16:34:33 -0700179 resp = (char *)calloc(replySize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000180 if (resp == NULL) {
181 free(cmd);
182 reply->writeInt32(NO_MEMORY);
183 return NO_ERROR;
184 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700185 }
186 status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp);
187 reply->writeInt32(status);
Andy Hung25a63442015-09-01 20:07:56 +0000188 if (status == NO_ERROR) {
189 if (replySz < replySize) {
190 replySize = replySz;
191 }
192 reply->writeInt32(replySize);
193 if (replySize) {
194 reply->write(resp, replySize);
195 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700196 }
197 if (cmd) {
198 free(cmd);
199 }
200 if (resp) {
201 free(resp);
202 }
203 return NO_ERROR;
204 } break;
205
206 case DISCONNECT: {
Steve Block3856b092011-10-20 11:56:00 +0100207 ALOGV("DISCONNECT");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700208 CHECK_INTERFACE(IEffect, data, reply);
209 disconnect();
210 return NO_ERROR;
211 } break;
212
213 case GET_CBLK: {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700214 CHECK_INTERFACE(IEffect, data, reply);
215 reply->writeStrongBinder(getCblk()->asBinder());
216 return NO_ERROR;
217 } break;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700218
219 default:
220 return BBinder::onTransact(code, data, reply, flags);
221 }
222}
223
224// ----------------------------------------------------------------------------
225
226}; // namespace android