2008-10-21 14:00:00 +00:00
|
|
|
/*
|
|
|
|
**
|
|
|
|
** Copyright 2008, 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.
|
|
|
|
*/
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
#define LOG_TAG "ICameraClient"
|
|
|
|
#include <utils/Log.h>
|
2008-10-21 14:00:00 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <ui/ICameraClient.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SHUTTER_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
RAW_CALLBACK,
|
|
|
|
JPEG_CALLBACK,
|
2009-02-10 23:44:00 +00:00
|
|
|
PREVIEW_CALLBACK,
|
2008-10-21 14:00:00 +00:00
|
|
|
ERROR_CALLBACK,
|
2009-02-10 23:44:00 +00:00
|
|
|
AUTOFOCUS_CALLBACK,
|
|
|
|
RECORDING_CALLBACK,
|
2008-10-21 14:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BpCameraClient: public BpInterface<ICameraClient>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BpCameraClient(const sp<IBinder>& impl)
|
|
|
|
: BpInterface<ICameraClient>(impl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback to let the app know the shutter has closed, ideal for playing the shutter sound
|
|
|
|
void shutterCallback()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("shutterCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
remote()->transact(SHUTTER_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback from camera service to app with picture data
|
|
|
|
void rawCallback(const sp<IMemory>& picture)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("rawCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(picture->asBinder());
|
|
|
|
remote()->transact(RAW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback from camera service to app with picture data
|
|
|
|
void jpegCallback(const sp<IMemory>& picture)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("jpegCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(picture->asBinder());
|
|
|
|
remote()->transact(JPEG_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
|
2009-02-10 23:44:00 +00:00
|
|
|
// callback from camera service to app with preview frame data
|
|
|
|
void previewCallback(const sp<IMemory>& frame)
|
2008-10-21 14:00:00 +00:00
|
|
|
{
|
2009-02-10 23:44:00 +00:00
|
|
|
LOGV("previewCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(frame->asBinder());
|
2009-02-10 23:44:00 +00:00
|
|
|
remote()->transact(PREVIEW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback from camera service to app with recording frame data
|
|
|
|
void recordingCallback(const sp<IMemory>& frame)
|
|
|
|
{
|
|
|
|
LOGV("recordingCallback");
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(frame->asBinder());
|
|
|
|
remote()->transact(RECORDING_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// callback from camera service to app to report error
|
|
|
|
void errorCallback(status_t error)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("errorCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(error);
|
|
|
|
remote()->transact(ERROR_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback from camera service to app to report autofocus completion
|
|
|
|
void autoFocusCallback(bool focused)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("autoFocusCallback");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
|
|
|
|
data.writeInt32(focused);
|
|
|
|
remote()->transact(AUTOFOCUS_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define CHECK_INTERFACE(interface, data, reply) \
|
|
|
|
do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
|
|
|
|
LOGW("Call incorrectly routed to " #interface); \
|
|
|
|
return PERMISSION_DENIED; \
|
|
|
|
} } while (0)
|
|
|
|
|
|
|
|
status_t BnCameraClient::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
switch(code) {
|
|
|
|
case SHUTTER_CALLBACK: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("SHUTTER_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
shutterCallback();
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case RAW_CALLBACK: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("RAW_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
|
|
|
|
rawCallback(picture);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case JPEG_CALLBACK: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("JPEG_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder());
|
|
|
|
jpegCallback(picture);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2009-02-10 23:44:00 +00:00
|
|
|
case PREVIEW_CALLBACK: {
|
|
|
|
LOGV("PREVIEW_CALLBACK");
|
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder());
|
|
|
|
previewCallback(frame);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case RECORDING_CALLBACK: {
|
|
|
|
LOGV("RECORDING_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder());
|
2009-02-10 23:44:00 +00:00
|
|
|
recordingCallback(frame);
|
2008-10-21 14:00:00 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case ERROR_CALLBACK: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("ERROR_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
status_t error = data.readInt32();
|
|
|
|
errorCallback(error);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case AUTOFOCUS_CALLBACK: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("AUTOFOCUS_CALLBACK");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICameraClient, data, reply);
|
|
|
|
bool focused = (bool)data.readInt32();
|
|
|
|
autoFocusCallback(focused);
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
return BBinder::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|