Merge "Fix issue 2667797: [Audio Effect Framework] new base class and binder interfaces for effect control." into kraken

This commit is contained in:
Eric Laurent
2010-05-25 23:48:30 -07:00
committed by Android (Google) Code Review
5 changed files with 441 additions and 1 deletions

56
include/media/IEffect.h Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_IEFFECT_H
#define ANDROID_IEFFECT_H
#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <binder/IMemory.h>
namespace android {
class IEffect: public IInterface
{
public:
DECLARE_META_INTERFACE(Effect);
virtual status_t enable() = 0;
virtual status_t disable() = 0;
virtual status_t command(int cmdCode, int cmdSize, void *pCmdData, int *pReplySize, void *pReplyData) = 0;
virtual void disconnect() = 0;
virtual sp<IMemory> getCblk() const = 0;
};
// ----------------------------------------------------------------------------
class BnEffect: public BnInterface<IEffect>
{
public:
virtual status_t onTransact( uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags = 0);
};
}; // namespace android
#endif // ANDROID_IEFFECT_H

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_IEFFECTCLIENT_H
#define ANDROID_IEFFECTCLIENT_H
#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <binder/IMemory.h>
namespace android {
class IEffectClient: public IInterface
{
public:
DECLARE_META_INTERFACE(EffectClient);
virtual void controlStatusChanged(bool controlGranted) = 0;
virtual void enableStatusChanged(bool enabled) = 0;
virtual void commandExecuted(int cmdCode, int cmdSize, void *pCmdData, int replySize, void *pReplyData) = 0;
};
// ----------------------------------------------------------------------------
class BnEffectClient: public BnInterface<IEffectClient>
{
public:
virtual status_t onTransact( uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags = 0);
};
}; // namespace android
#endif // ANDROID_IEFFECTCLIENT_H

View File

@ -26,7 +26,9 @@ LOCAL_SRC_FILES:= \
MediaScannerClient.cpp \
autodetect.cpp \
IMediaDeathNotifier.cpp \
MediaProfiles.cpp
MediaProfiles.cpp \
IEffect.cpp \
IEffectClient.cpp
LOCAL_SHARED_LIBRARIES := \
libui libcutils libutils libbinder libsonivox libicuuc libexpat libsurfaceflinger_client libcamera_client

191
media/libmedia/IEffect.cpp Normal file
View File

@ -0,0 +1,191 @@
/*
**
** Copyright 2010, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "IEffect"
#include <utils/Log.h>
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IEffect.h>
namespace android {
enum {
ENABLE = IBinder::FIRST_CALL_TRANSACTION,
DISABLE,
COMMAND,
DISCONNECT,
GET_CBLK
};
class BpEffect: public BpInterface<IEffect>
{
public:
BpEffect(const sp<IBinder>& impl)
: BpInterface<IEffect>(impl)
{
}
status_t enable()
{
LOGV("enable");
Parcel data, reply;
data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
remote()->transact(ENABLE, data, &reply);
return reply.readInt32();
}
status_t disable()
{
LOGV("disable");
Parcel data, reply;
data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
remote()->transact(DISABLE, data, &reply);
return reply.readInt32();
}
status_t command(int cmdCode, int cmdSize, void *pCmdData, int *pReplySize, void *pReplyData)
{
LOGV("command");
Parcel data, reply;
data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
data.writeInt32(cmdCode);
int size = cmdSize;
if (pCmdData == NULL) {
size = 0;
}
data.writeInt32(size);
if (size) {
data.write(pCmdData, size);
}
if (pReplySize == NULL) {
size = 0;
} else {
size = *pReplySize;
}
data.writeInt32(size);
remote()->transact(COMMAND, data, &reply);
status_t status = reply.readInt32();
size = reply.readInt32();
if (size != 0 && pReplyData != NULL && pReplySize != NULL) {
reply.read(pReplyData, size);
*pReplySize = size;
}
return status;
}
void disconnect()
{
LOGV("disconnect");
Parcel data, reply;
data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
remote()->transact(DISCONNECT, data, &reply);
return;
}
virtual sp<IMemory> getCblk() const
{
Parcel data, reply;
sp<IMemory> cblk;
data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
status_t status = remote()->transact(GET_CBLK, data, &reply);
if (status == NO_ERROR) {
cblk = interface_cast<IMemory>(reply.readStrongBinder());
}
return cblk;
}
};
IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect");
// ----------------------------------------------------------------------
status_t BnEffect::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch(code) {
case ENABLE: {
LOGV("ENABLE");
CHECK_INTERFACE(IEffect, data, reply);
reply->writeInt32(enable());
return NO_ERROR;
} break;
case DISABLE: {
LOGV("DISABLE");
CHECK_INTERFACE(IEffect, data, reply);
reply->writeInt32(disable());
return NO_ERROR;
} break;
case COMMAND: {
LOGV("COMMAND");
CHECK_INTERFACE(IEffect, data, reply);
int cmdCode = data.readInt32();
int cmdSize = data.readInt32();
char *cmd = NULL;
if (cmdSize) {
cmd = (char *)malloc(cmdSize);
data.read(cmd, cmdSize);
}
int replySize = data.readInt32();
int replySz = replySize;
char *resp = NULL;
if (replySize) {
resp = (char *)malloc(replySize);
}
status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp);
reply->writeInt32(status);
if (replySz < replySize) {
replySize = replySz;
}
reply->writeInt32(replySize);
if (replySize) {
reply->write(resp, replySize);
}
if (cmd) {
free(cmd);
}
if (resp) {
free(resp);
}
return NO_ERROR;
} break;
case DISCONNECT: {
LOGV("DISCONNECT");
CHECK_INTERFACE(IEffect, data, reply);
disconnect();
return NO_ERROR;
} break;
case GET_CBLK: {
CHECK_INTERFACE(IEffect, data, reply);
reply->writeStrongBinder(getCblk()->asBinder());
return NO_ERROR;
} break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
// ----------------------------------------------------------------------------
}; // namespace android

View File

@ -0,0 +1,141 @@
/*
**
** Copyright 2010, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "IEffectClient"
#include <utils/Log.h>
#include <stdint.h>
#include <sys/types.h>
#include <media/IEffectClient.h>
namespace android {
enum {
CONTROL_STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
ENABLE_STATUS_CHANGED,
COMMAND_EXECUTED
};
class BpEffectClient: public BpInterface<IEffectClient>
{
public:
BpEffectClient(const sp<IBinder>& impl)
: BpInterface<IEffectClient>(impl)
{
}
void controlStatusChanged(bool controlGranted)
{
LOGV("controlStatusChanged");
Parcel data, reply;
data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
data.writeInt32((uint32_t)controlGranted);
remote()->transact(CONTROL_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
}
void enableStatusChanged(bool enabled)
{
LOGV("enableStatusChanged");
Parcel data, reply;
data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
data.writeInt32((uint32_t)enabled);
remote()->transact(ENABLE_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
}
void commandExecuted(int cmdCode, int cmdSize, void *pCmdData, int replySize, void *pReplyData)
{
LOGV("commandExecuted");
Parcel data, reply;
data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
data.writeInt32(cmdCode);
int size = cmdSize;
if (pCmdData == NULL) {
size = 0;
}
data.writeInt32(size);
if (size) {
data.write(pCmdData, size);
}
size = replySize;
if (pReplyData == NULL) {
size = 0;
}
data.writeInt32(size);
if (size) {
data.write(pReplyData, size);
}
remote()->transact(COMMAND_EXECUTED, data, &reply, IBinder::FLAG_ONEWAY);
}
};
IMPLEMENT_META_INTERFACE(EffectClient, "android.media.IEffectClient");
// ----------------------------------------------------------------------
status_t BnEffectClient::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch(code) {
case CONTROL_STATUS_CHANGED: {
LOGV("CONTROL_STATUS_CHANGED");
CHECK_INTERFACE(IEffectClient, data, reply);
bool hasControl = (bool)data.readInt32();
controlStatusChanged(hasControl);
return NO_ERROR;
} break;
case ENABLE_STATUS_CHANGED: {
LOGV("ENABLE_STATUS_CHANGED");
CHECK_INTERFACE(IEffectClient, data, reply);
bool enabled = (bool)data.readInt32();
enableStatusChanged(enabled);
return NO_ERROR;
} break;
case COMMAND_EXECUTED: {
LOGV("COMMAND_EXECUTED");
CHECK_INTERFACE(IEffectClient, data, reply);
int cmdCode = data.readInt32();
int cmdSize = data.readInt32();
char *cmd = NULL;
if (cmdSize) {
cmd = (char *)malloc(cmdSize);
data.read(cmd, cmdSize);
}
int replySize = data.readInt32();
char *resp = NULL;
if (replySize) {
resp = (char *)malloc(replySize);
data.read(resp, replySize);
}
commandExecuted(cmdCode, cmdSize, cmd, replySize, resp);
if (cmd) {
free(cmd);
}
if (resp) {
free(resp);
}
return NO_ERROR;
} break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
// ----------------------------------------------------------------------------
}; // namespace android