IEffect.cpp revision e53b9ead781c36e96d6b6f012ddffc93a3d80f0d
1d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent/* 2d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** 3d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Copyright 2010, The Android Open Source Project 4d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** 5d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Licensed under the Apache License, Version 2.0 (the "License"); 6d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** you may not use this file except in compliance with the License. 7d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** You may obtain a copy of the License at 8d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** 9d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** http://www.apache.org/licenses/LICENSE-2.0 10d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** 11d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Unless required by applicable law or agreed to in writing, software 12d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** distributed under the License is distributed on an "AS IS" BASIS, 13d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** See the License for the specific language governing permissions and 15d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** limitations under the License. 16d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent*/ 17d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 18d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent//#define LOG_NDEBUG 0 19d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#define LOG_TAG "IEffect" 20d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <utils/Log.h> 21d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <stdint.h> 22d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <sys/types.h> 23d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <binder/Parcel.h> 24d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <media/IEffect.h> 25d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 26d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentnamespace android { 27d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 28d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentenum { 29d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent ENABLE = IBinder::FIRST_CALL_TRANSACTION, 30d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent DISABLE, 31d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent COMMAND, 32d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent DISCONNECT, 33d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent GET_CBLK 34d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent}; 35d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 36d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentclass BpEffect: public BpInterface<IEffect> 37d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent{ 38d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentpublic: 39d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent BpEffect(const sp<IBinder>& impl) 40d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent : BpInterface<IEffect>(impl) 41d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 42d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 43d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 44d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t enable() 45d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("enable"); 47d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 48d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 49d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent remote()->transact(ENABLE, data, &reply); 50d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return reply.readInt32(); 51d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 52d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 53d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t disable() 54d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("disable"); 56d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 57d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 58d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent remote()->transact(DISABLE, data, &reply); 59d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return reply.readInt32(); 60d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 61d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 6225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent status_t command(uint32_t cmdCode, 6325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t cmdSize, 6425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent void *pCmdData, 6525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t *pReplySize, 6625f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent void *pReplyData) 67d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("command"); 69d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 70d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 71d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(cmdCode); 72d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int size = cmdSize; 73d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (pCmdData == NULL) { 74d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = 0; 75d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 76d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(size); 77d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (size) { 78d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.write(pCmdData, size); 79d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 80d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (pReplySize == NULL) { 81d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = 0; 82d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } else { 83d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = *pReplySize; 84d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 85d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(size); 86af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman 87af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman status_t status = remote()->transact(COMMAND, data, &reply); 88af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman if (status != NO_ERROR) { 89af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman if (pReplySize != NULL) 90af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman *pReplySize = 0; 91af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman return status; 92af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman } 93af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman 94af7d8189f91c45ab919a6c9ac386b268c8d91168John Grossman status = reply.readInt32(); 95d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = reply.readInt32(); 96d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (size != 0 && pReplyData != NULL && pReplySize != NULL) { 97d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply.read(pReplyData, size); 98d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent *pReplySize = size; 99d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 100d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return status; 101d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 102d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 103d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent void disconnect() 104d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 1053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("disconnect"); 106d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 107d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 108d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent remote()->transact(DISCONNECT, data, &reply); 109d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return; 110d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 111d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 112d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent virtual sp<IMemory> getCblk() const 113d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 114d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 115d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent sp<IMemory> cblk; 116d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 117d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t status = remote()->transact(GET_CBLK, data, &reply); 118d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (status == NO_ERROR) { 119d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent cblk = interface_cast<IMemory>(reply.readStrongBinder()); 120d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 121d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return cblk; 122d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 123d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent }; 124d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 125d71a1be83ff31cdb6599c351f9832cefc8d447baEric LaurentIMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect"); 126d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 127d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ---------------------------------------------------------------------- 128d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 129d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentstatus_t BnEffect::onTransact( 130d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 131d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent{ 132e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten switch (code) { 133d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case ENABLE: { 1343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("ENABLE"); 135d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 136d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(enable()); 137d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 138d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 139d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 140d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case DISABLE: { 1413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("DISABLE"); 142d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 143d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(disable()); 144d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 145d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 146d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 147d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case COMMAND: { 1483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("COMMAND"); 149d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 15025f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t cmdCode = data.readInt32(); 15125f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t cmdSize = data.readInt32(); 152d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent char *cmd = NULL; 153d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (cmdSize) { 154d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent cmd = (char *)malloc(cmdSize); 155d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.read(cmd, cmdSize); 156d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 15725f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t replySize = data.readInt32(); 15825f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent uint32_t replySz = replySize; 159d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent char *resp = NULL; 160d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySize) { 161d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent resp = (char *)malloc(replySize); 162d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 163d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp); 164d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(status); 165d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySz < replySize) { 166d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent replySize = replySz; 167d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 168d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(replySize); 169d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySize) { 170d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->write(resp, replySize); 171d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 172d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (cmd) { 173d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent free(cmd); 174d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 175d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (resp) { 176d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent free(resp); 177d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 178d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 179d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 180d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 181d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case DISCONNECT: { 1823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("DISCONNECT"); 183d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 184d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent disconnect(); 185d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 186d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 187d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 188d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case GET_CBLK: { 189e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten CHECK_INTERFACE(IEffect, data, reply); 190e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten reply->writeStrongBinder(getCblk()->asBinder()); 191e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten return NO_ERROR; 192e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten } break; 193d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 194d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent default: 195d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return BBinder::onTransact(code, data, reply, flags); 196d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 197d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent} 198d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 199d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ---------------------------------------------------------------------------- 200d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 201d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent}; // namespace android 202