IEffect.cpp revision d71a1be83ff31cdb6599c351f9832cefc8d447ba
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 { 46d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("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 { 55d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("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 62d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t command(int cmdCode, int cmdSize, void *pCmdData, int *pReplySize, void *pReplyData) 63d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 64d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("command"); 65d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 66d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 67d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(cmdCode); 68d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int size = cmdSize; 69d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (pCmdData == NULL) { 70d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = 0; 71d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 72d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(size); 73d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (size) { 74d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.write(pCmdData, size); 75d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 76d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (pReplySize == NULL) { 77d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = 0; 78d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } else { 79d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = *pReplySize; 80d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 81d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInt32(size); 82d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent remote()->transact(COMMAND, data, &reply); 83d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t status = reply.readInt32(); 84d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent size = reply.readInt32(); 85d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (size != 0 && pReplyData != NULL && pReplySize != NULL) { 86d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply.read(pReplyData, size); 87d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent *pReplySize = size; 88d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 89d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return status; 90d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 91d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 92d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent void disconnect() 93d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 94d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("disconnect"); 95d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 96d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 97d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent remote()->transact(DISCONNECT, data, &reply); 98d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return; 99d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 100d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 101d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent virtual sp<IMemory> getCblk() const 102d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent { 103d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent Parcel data, reply; 104d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent sp<IMemory> cblk; 105d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.writeInterfaceToken(IEffect::getInterfaceDescriptor()); 106d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t status = remote()->transact(GET_CBLK, data, &reply); 107d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (status == NO_ERROR) { 108d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent cblk = interface_cast<IMemory>(reply.readStrongBinder()); 109d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 110d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return cblk; 111d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 112d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent }; 113d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 114d71a1be83ff31cdb6599c351f9832cefc8d447baEric LaurentIMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect"); 115d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 116d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ---------------------------------------------------------------------- 117d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 118d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentstatus_t BnEffect::onTransact( 119d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 120d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent{ 121d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent switch(code) { 122d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case ENABLE: { 123d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("ENABLE"); 124d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 125d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(enable()); 126d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 127d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 128d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 129d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case DISABLE: { 130d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("DISABLE"); 131d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 132d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(disable()); 133d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 134d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 135d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 136d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case COMMAND: { 137d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("COMMAND"); 138d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 139d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int cmdCode = data.readInt32(); 140d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int cmdSize = data.readInt32(); 141d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent char *cmd = NULL; 142d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (cmdSize) { 143d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent cmd = (char *)malloc(cmdSize); 144d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent data.read(cmd, cmdSize); 145d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 146d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int replySize = data.readInt32(); 147d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent int replySz = replySize; 148d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent char *resp = NULL; 149d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySize) { 150d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent resp = (char *)malloc(replySize); 151d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 152d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp); 153d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(status); 154d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySz < replySize) { 155d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent replySize = replySz; 156d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 157d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeInt32(replySize); 158d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (replySize) { 159d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->write(resp, replySize); 160d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 161d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (cmd) { 162d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent free(cmd); 163d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 164d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent if (resp) { 165d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent free(resp); 166d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 167d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 168d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 169d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 170d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case DISCONNECT: { 171d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent LOGV("DISCONNECT"); 172d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 173d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent disconnect(); 174d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 175d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 176d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 177d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent case GET_CBLK: { 178d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent CHECK_INTERFACE(IEffect, data, reply); 179d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent reply->writeStrongBinder(getCblk()->asBinder()); 180d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return NO_ERROR; 181d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } break; 182d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 183d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent default: 184d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent return BBinder::onTransact(code, data, reply, flags); 185d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent } 186d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent} 187d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 188d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ---------------------------------------------------------------------------- 189d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 190d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent}; // namespace android 191d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent 192