blob: 5d47dff80808d45b66cce8d34e6fa53cdca949e3 [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:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070042 explicit BpEffect(const sp<IBinder>& impl)
Eric Laurentd71a1be2010-05-21 07:47:50 -070043 : 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());
Ytai Ben-Tsvi7dd39722019-09-05 15:14:30 -0700125 if (cblk != 0 && cblk->unsecurePointer() == NULL) {
Glenn Kastena1d401d2013-11-20 14:37:13 -0800126 cblk.clear();
127 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700128 }
129 return cblk;
130 }
131 };
132
133IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect");
134
135// ----------------------------------------------------------------------
136
137status_t BnEffect::onTransact(
138 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
139{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700140 switch (code) {
Eric Laurentd71a1be2010-05-21 07:47:50 -0700141 case ENABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100142 ALOGV("ENABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700143 CHECK_INTERFACE(IEffect, data, reply);
144 reply->writeInt32(enable());
145 return NO_ERROR;
146 } break;
147
148 case DISABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100149 ALOGV("DISABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700150 CHECK_INTERFACE(IEffect, data, reply);
151 reply->writeInt32(disable());
152 return NO_ERROR;
153 } break;
154
155 case COMMAND: {
Steve Block3856b092011-10-20 11:56:00 +0100156 ALOGV("COMMAND");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700157 CHECK_INTERFACE(IEffect, data, reply);
Eric Laurent25f43952010-07-28 05:40:18 -0700158 uint32_t cmdCode = data.readInt32();
159 uint32_t cmdSize = data.readInt32();
Eric Laurentd71a1be2010-05-21 07:47:50 -0700160 char *cmd = NULL;
161 if (cmdSize) {
ragoe2759072016-11-22 18:02:48 -0800162 if (cmdSize > EFFECT_PARAM_SIZE_MAX) {
163 reply->writeInt32(NO_MEMORY);
164 return NO_ERROR;
165 }
Andy Hungd0b59102015-08-26 16:34:33 -0700166 cmd = (char *)calloc(cmdSize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000167 if (cmd == NULL) {
168 reply->writeInt32(NO_MEMORY);
169 return NO_ERROR;
170 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700171 data.read(cmd, cmdSize);
172 }
Eric Laurent25f43952010-07-28 05:40:18 -0700173 uint32_t replySize = data.readInt32();
174 uint32_t replySz = replySize;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700175 char *resp = NULL;
176 if (replySize) {
ragoe2759072016-11-22 18:02:48 -0800177 if (replySize > EFFECT_PARAM_SIZE_MAX) {
178 free(cmd);
179 reply->writeInt32(NO_MEMORY);
180 return NO_ERROR;
181 }
Andy Hungd0b59102015-08-26 16:34:33 -0700182 resp = (char *)calloc(replySize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000183 if (resp == NULL) {
184 free(cmd);
185 reply->writeInt32(NO_MEMORY);
186 return NO_ERROR;
187 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700188 }
189 status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp);
190 reply->writeInt32(status);
Andy Hung25a63442015-09-01 20:07:56 +0000191 if (status == NO_ERROR) {
192 if (replySz < replySize) {
193 replySize = replySz;
194 }
195 reply->writeInt32(replySize);
196 if (replySize) {
197 reply->write(resp, replySize);
198 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700199 }
200 if (cmd) {
201 free(cmd);
202 }
203 if (resp) {
204 free(resp);
205 }
206 return NO_ERROR;
207 } break;
208
209 case DISCONNECT: {
Steve Block3856b092011-10-20 11:56:00 +0100210 ALOGV("DISCONNECT");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700211 CHECK_INTERFACE(IEffect, data, reply);
212 disconnect();
213 return NO_ERROR;
214 } break;
215
216 case GET_CBLK: {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700217 CHECK_INTERFACE(IEffect, data, reply);
Marco Nelissen06b46062014-11-14 07:58:25 -0800218 reply->writeStrongBinder(IInterface::asBinder(getCblk()));
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700219 return NO_ERROR;
220 } break;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700221
222 default:
223 return BBinder::onTransact(code, data, reply, flags);
224 }
225}
226
227// ----------------------------------------------------------------------------
228
Glenn Kasten40bc9062015-03-20 09:09:33 -0700229} // namespace android