2008-10-21 14:00:00 +00:00
|
|
|
/*
|
|
|
|
**
|
|
|
|
** Copyright 2008, The Android Open Source Project
|
|
|
|
**
|
2008-12-18 02:05:43 +00:00
|
|
|
** 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
|
2008-10-21 14:00:00 +00:00
|
|
|
**
|
2008-12-18 02:05:43 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2008-10-21 14:00:00 +00:00
|
|
|
**
|
2008-12-18 02:05:43 +00:00
|
|
|
** 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
|
2008-10-21 14:00:00 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2008-12-18 02:05:43 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
|
|
|
#define LOG_TAG "ICamera"
|
|
|
|
#include <utils/Log.h>
|
2008-10-21 14:00:00 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <utils/Parcel.h>
|
|
|
|
#include <ui/ICamera.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
|
|
|
|
SET_PREVIEW_DISPLAY,
|
2008-12-18 02:05:43 +00:00
|
|
|
SET_FRAME_CALLBACK_FLAG,
|
2008-10-21 14:00:00 +00:00
|
|
|
START_PREVIEW,
|
|
|
|
STOP_PREVIEW,
|
|
|
|
AUTO_FOCUS,
|
|
|
|
TAKE_PICTURE,
|
|
|
|
SET_PARAMETERS,
|
2008-12-18 02:05:43 +00:00
|
|
|
GET_PARAMETERS,
|
2009-01-10 01:51:23 +00:00
|
|
|
CONNECT,
|
|
|
|
LOCK,
|
|
|
|
UNLOCK,
|
|
|
|
PREVIEW_ENABLED
|
2008-10-21 14:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BpCamera: public BpInterface<ICamera>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BpCamera(const sp<IBinder>& impl)
|
|
|
|
: BpInterface<ICamera>(impl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// disconnect from camera service
|
|
|
|
void disconnect()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("disconnect");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(DISCONNECT, data, &reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass the buffered ISurface to the camera service
|
|
|
|
status_t setPreviewDisplay(const sp<ISurface>& surface)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("setPreviewDisplay");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(surface->asBinder());
|
|
|
|
remote()->transact(SET_PREVIEW_DISPLAY, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
|
|
|
|
// set the frame callback flag to affect how the received frames from
|
|
|
|
// preview are handled.
|
|
|
|
void setFrameCallbackFlag(int frame_callback_flag)
|
2008-10-21 14:00:00 +00:00
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("setFrameCallbackFlag(%d)", frame_callback_flag);
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
2008-12-18 02:05:43 +00:00
|
|
|
data.writeInt32(frame_callback_flag);
|
|
|
|
remote()->transact(SET_FRAME_CALLBACK_FLAG, data, &reply);
|
2008-10-21 14:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// start preview mode, must call setPreviewDisplay first
|
|
|
|
status_t startPreview()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("startPreview");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(START_PREVIEW, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop preview mode
|
|
|
|
void stopPreview()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("stopPreview");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(STOP_PREVIEW, data, &reply);
|
|
|
|
}
|
|
|
|
|
2009-01-10 01:51:23 +00:00
|
|
|
// check preview state
|
|
|
|
bool previewEnabled()
|
|
|
|
{
|
|
|
|
LOGV("previewEnabled");
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(PREVIEW_ENABLED, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
// auto focus
|
|
|
|
status_t autoFocus()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("autoFocus");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(AUTO_FOCUS, data, &reply);
|
|
|
|
status_t ret = reply.readInt32();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// take a picture - returns an IMemory (ref-counted mmap)
|
|
|
|
status_t takePicture()
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("takePicture");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(TAKE_PICTURE, data, &reply);
|
|
|
|
status_t ret = reply.readInt32();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set preview/capture parameters - key/value pairs
|
|
|
|
status_t setParameters(const String8& params)
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("setParameters");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
data.writeString8(params);
|
|
|
|
remote()->transact(SET_PARAMETERS, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get preview/capture parameters - key/value pairs
|
|
|
|
String8 getParameters() const
|
|
|
|
{
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("getParameters");
|
2008-10-21 14:00:00 +00:00
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(GET_PARAMETERS, data, &reply);
|
|
|
|
return reply.readString8();
|
|
|
|
}
|
2008-12-18 02:05:43 +00:00
|
|
|
virtual status_t connect(const sp<ICameraClient>& cameraClient)
|
|
|
|
{
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
data.writeStrongBinder(cameraClient->asBinder());
|
|
|
|
remote()->transact(CONNECT, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
2009-01-10 01:51:23 +00:00
|
|
|
virtual status_t lock()
|
|
|
|
{
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(LOCK, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
|
|
|
virtual status_t unlock()
|
|
|
|
{
|
|
|
|
Parcel data, reply;
|
|
|
|
data.writeInterfaceToken(ICamera::getInterfaceDescriptor());
|
|
|
|
remote()->transact(UNLOCK, data, &reply);
|
|
|
|
return reply.readInt32();
|
|
|
|
}
|
2008-10-21 14:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera");
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#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 BnCamera::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
switch(code) {
|
|
|
|
case DISCONNECT: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("DISCONNECT");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
disconnect();
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_PREVIEW_DISPLAY: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("SET_PREVIEW_DISPLAY");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder());
|
|
|
|
reply->writeInt32(setPreviewDisplay(surface));
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2008-12-18 02:05:43 +00:00
|
|
|
case SET_FRAME_CALLBACK_FLAG: {
|
|
|
|
LOGV("SET_FRAME_CALLBACK_TYPE");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
2008-12-18 02:05:43 +00:00
|
|
|
int frame_callback_flag = data.readInt32();
|
|
|
|
setFrameCallbackFlag(frame_callback_flag);
|
2008-10-21 14:00:00 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case START_PREVIEW: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("START_PREVIEW");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(startPreview());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case STOP_PREVIEW: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("STOP_PREVIEW");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
stopPreview();
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2009-01-10 01:51:23 +00:00
|
|
|
case PREVIEW_ENABLED: {
|
|
|
|
LOGV("PREVIEW_ENABLED");
|
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(previewEnabled());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2008-10-21 14:00:00 +00:00
|
|
|
case AUTO_FOCUS: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("AUTO_FOCUS");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(autoFocus());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case TAKE_PICTURE: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("TAKE_PICTURE");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(takePicture());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case SET_PARAMETERS: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("SET_PARAMETERS");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
2008-12-18 02:05:43 +00:00
|
|
|
String8 params(data.readString8());
|
|
|
|
reply->writeInt32(setParameters(params));
|
2008-10-21 14:00:00 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case GET_PARAMETERS: {
|
2008-12-18 02:05:43 +00:00
|
|
|
LOGV("GET_PARAMETERS");
|
2008-10-21 14:00:00 +00:00
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeString8(getParameters());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2008-12-18 02:05:43 +00:00
|
|
|
case CONNECT: {
|
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
|
|
|
|
reply->writeInt32(connect(cameraClient));
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2009-01-10 01:51:23 +00:00
|
|
|
case LOCK: {
|
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(lock());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
|
|
|
case UNLOCK: {
|
|
|
|
CHECK_INTERFACE(ICamera, data, reply);
|
|
|
|
reply->writeInt32(unlock());
|
|
|
|
return NO_ERROR;
|
|
|
|
} break;
|
2008-10-21 14:00:00 +00:00
|
|
|
default:
|
|
|
|
return BBinder::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|