From 7b82efe7a376c882f8f938e1c41b8311a8cdda4a Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Thu, 25 Jul 2013 17:12:35 -0700 Subject: Camera: Rename new API to camera2, rearrange camera service - Support API rename from photography to camera2 - Reorganize camera service files - API support files to api1/, api2/, api_pro/ - HAL device support files into device{1,2,3}/ - Common files into common/ - Camera service remains at top-level Change-Id: Ie474c12536f543832fba0a2dc936ac4fd39fe6a9 --- camera/Android.mk | 6 +- camera/ICameraService.cpp | 6 +- camera/camera2/CaptureRequest.cpp | 124 ++++++++++ camera/camera2/ICameraDeviceCallbacks.cpp | 109 +++++++++ camera/camera2/ICameraDeviceUser.cpp | 322 ++++++++++++++++++++++++++ camera/photography/CaptureRequest.cpp | 124 ---------- camera/photography/ICameraDeviceCallbacks.cpp | 110 --------- camera/photography/ICameraDeviceUser.cpp | 322 -------------------------- 8 files changed, 561 insertions(+), 562 deletions(-) create mode 100644 camera/camera2/CaptureRequest.cpp create mode 100644 camera/camera2/ICameraDeviceCallbacks.cpp create mode 100644 camera/camera2/ICameraDeviceUser.cpp delete mode 100644 camera/photography/CaptureRequest.cpp delete mode 100644 camera/photography/ICameraDeviceCallbacks.cpp delete mode 100644 camera/photography/ICameraDeviceUser.cpp (limited to 'camera') diff --git a/camera/Android.mk b/camera/Android.mk index 8f58f87..e633450 100644 --- a/camera/Android.mk +++ b/camera/Android.mk @@ -16,9 +16,9 @@ LOCAL_SRC_FILES:= \ ICameraRecordingProxyListener.cpp \ IProCameraUser.cpp \ IProCameraCallbacks.cpp \ - photography/ICameraDeviceUser.cpp \ - photography/ICameraDeviceCallbacks.cpp \ - photography/CaptureRequest.cpp \ + camera2/ICameraDeviceUser.cpp \ + camera2/ICameraDeviceCallbacks.cpp \ + camera2/CaptureRequest.cpp \ ProCamera.cpp \ CameraBase.cpp \ diff --git a/camera/ICameraService.cpp b/camera/ICameraService.cpp index 068fb0f..876a2df 100644 --- a/camera/ICameraService.cpp +++ b/camera/ICameraService.cpp @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include namespace android { @@ -151,7 +151,7 @@ public: return interface_cast(reply.readStrongBinder()); } - // connect to camera service (android.hardware.photography.CameraDevice) + // connect to camera service (android.hardware.camera2.CameraDevice) virtual sp connect( const sp& cameraCb, int cameraId, diff --git a/camera/camera2/CaptureRequest.cpp b/camera/camera2/CaptureRequest.cpp new file mode 100644 index 0000000..57e5319 --- /dev/null +++ b/camera/camera2/CaptureRequest.cpp @@ -0,0 +1,124 @@ +/* +** +** Copyright 2013, 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 "CameraRequest" +#include + +#include + +#include +#include + +namespace android { + +status_t CaptureRequest::readFromParcel(Parcel* parcel) { + if (parcel == NULL) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + mMetadata.clear(); + mSurfaceList.clear(); + + status_t err; + + if ((err = mMetadata.readFromParcel(parcel)) != OK) { + ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__); + return err; + } + ALOGV("%s: Read metadata from parcel", __FUNCTION__); + + int32_t size; + if ((err = parcel->readInt32(&size)) != OK) { + ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__); + return err; + } + ALOGV("%s: Read surface list size = %d", __FUNCTION__, size); + + // Do not distinguish null arrays from 0-sized arrays. + for (int i = 0; i < size; ++i) { + // Parcel.writeParcelableArray + size_t len; + const char16_t* className = parcel->readString16Inplace(&len); + ALOGV("%s: Read surface class = %s", __FUNCTION__, + className != NULL ? String8(className).string() : ""); + + if (className == NULL) { + continue; + } + + // Surface.writeToParcel + String16 name = parcel->readString16(); + ALOGV("%s: Read surface name = %s", + __FUNCTION__, String8(name).string()); + sp binder(parcel->readStrongBinder()); + ALOGV("%s: Read surface binder = %p", + __FUNCTION__, binder.get()); + + sp surface; + + if (binder != NULL) { + sp gbp = + interface_cast(binder); + surface = new Surface(gbp); + } + + mSurfaceList.push_back(surface); + } + + return OK; +} + +status_t CaptureRequest::writeToParcel(Parcel* parcel) const { + if (parcel == NULL) { + ALOGE("%s: Null parcel", __FUNCTION__); + return BAD_VALUE; + } + + status_t err; + + if ((err = mMetadata.writeToParcel(parcel)) != OK) { + return err; + } + + int32_t size = static_cast(mSurfaceList.size()); + + // Send 0-sized arrays when it's empty. Do not send null arrays. + parcel->writeInt32(size); + + for (int32_t i = 0; i < size; ++i) { + sp surface = mSurfaceList[i]; + + sp binder; + if (surface != 0) { + binder = surface->getIGraphicBufferProducer()->asBinder(); + } + + // not sure if readParcelableArray does this, hard to tell from source + parcel->writeString16(String16("android.view.Surface")); + + // Surface.writeToParcel + parcel->writeString16(String16("unknown_name")); + // Surface.nativeWriteToParcel + parcel->writeStrongBinder(binder); + } + + return OK; +} + +}; // namespace android diff --git a/camera/camera2/ICameraDeviceCallbacks.cpp b/camera/camera2/ICameraDeviceCallbacks.cpp new file mode 100644 index 0000000..188bd8e --- /dev/null +++ b/camera/camera2/ICameraDeviceCallbacks.cpp @@ -0,0 +1,109 @@ +/* +** +** Copyright 2013, 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 "ICameraDeviceCallbacks" +#include +#include +#include + +#include +#include +#include +#include + +#include +#include "camera/CameraMetadata.h" + +namespace android { + +enum { + NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, + RESULT_RECEIVED, +}; + +class BpCameraDeviceCallbacks: public BpInterface +{ +public: + BpCameraDeviceCallbacks(const sp& impl) + : BpInterface(impl) + { + } + + // generic callback from camera service to app + void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) + { + ALOGV("notifyCallback"); + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); + data.writeInt32(msgType); + data.writeInt32(ext1); + data.writeInt32(ext2); + remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); + data.writeNoException(); + } + + void onResultReceived(int32_t frameId, const CameraMetadata& result) { + ALOGV("onResultReceived"); + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); + data.writeInt32(frameId); + result.writeToParcel(&data); + remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY); + data.writeNoException(); + } +}; + +IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks, + "android.hardware.camera2.ICameraDeviceCallbacks"); + +// ---------------------------------------------------------------------- + +status_t BnCameraDeviceCallbacks::onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) +{ + ALOGV("onTransact - code = %d", code); + switch(code) { + case NOTIFY_CALLBACK: { + ALOGV("NOTIFY_CALLBACK"); + CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); + int32_t msgType = data.readInt32(); + int32_t ext1 = data.readInt32(); + int32_t ext2 = data.readInt32(); + notifyCallback(msgType, ext1, ext2); + data.readExceptionCode(); + return NO_ERROR; + } break; + case RESULT_RECEIVED: { + ALOGV("RESULT_RECEIVED"); + CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); + int32_t frameId = data.readInt32(); + CameraMetadata result; + result.readFromParcel(const_cast(&data)); + onResultReceived(frameId, result); + data.readExceptionCode(); + return NO_ERROR; + break; + } + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + +// ---------------------------------------------------------------------------- + +}; // namespace android diff --git a/camera/camera2/ICameraDeviceUser.cpp b/camera/camera2/ICameraDeviceUser.cpp new file mode 100644 index 0000000..923f487 --- /dev/null +++ b/camera/camera2/ICameraDeviceUser.cpp @@ -0,0 +1,322 @@ +/* +** +** Copyright 2013, 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 "ICameraDeviceUser" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace android { + +typedef Parcel::WritableBlob WritableBlob; +typedef Parcel::ReadableBlob ReadableBlob; + +enum { + DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, + SUBMIT_REQUEST, + CANCEL_REQUEST, + DELETE_STREAM, + CREATE_STREAM, + CREATE_DEFAULT_REQUEST, + GET_CAMERA_INFO, + WAIT_UNTIL_IDLE, +}; + +class BpCameraDeviceUser : public BpInterface +{ +public: + BpCameraDeviceUser(const sp& impl) + : BpInterface(impl) + { + } + + // disconnect from camera service + void disconnect() + { + ALOGV("disconnect"); + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + remote()->transact(DISCONNECT, data, &reply); + reply.readExceptionCode(); + } + + virtual int submitRequest(sp request, bool streaming) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + + // arg0 = CaptureRequest + if (request != 0) { + data.writeInt32(1); + request->writeToParcel(&data); + } else { + data.writeInt32(0); + } + + // arg1 = streaming (bool) + data.writeInt32(streaming); + + remote()->transact(SUBMIT_REQUEST, data, &reply); + + reply.readExceptionCode(); + return reply.readInt32(); + } + + virtual status_t cancelRequest(int requestId) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + data.writeInt32(requestId); + + remote()->transact(CANCEL_REQUEST, data, &reply); + + reply.readExceptionCode(); + return reply.readInt32(); + } + + virtual status_t deleteStream(int streamId) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + data.writeInt32(streamId); + + remote()->transact(DELETE_STREAM, data, &reply); + + reply.readExceptionCode(); + return reply.readInt32(); + } + + virtual status_t createStream(int width, int height, int format, + const sp& bufferProducer) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + data.writeInt32(width); + data.writeInt32(height); + data.writeInt32(format); + + data.writeInt32(1); // marker that bufferProducer is not null + data.writeString16(String16("unknown_name")); // name of surface + sp b(bufferProducer->asBinder()); + data.writeStrongBinder(b); + + remote()->transact(CREATE_STREAM, data, &reply); + + reply.readExceptionCode(); + return reply.readInt32(); + } + + // Create a request object from a template. + virtual status_t createDefaultRequest(int templateId, + /*out*/ + CameraMetadata* request) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + data.writeInt32(templateId); + remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply); + + reply.readExceptionCode(); + status_t result = reply.readInt32(); + + CameraMetadata out; + if (reply.readInt32() != 0) { + out.readFromParcel(&reply); + } + + if (request != NULL) { + request->swap(out); + } + return result; + } + + + virtual status_t getCameraInfo(CameraMetadata* info) + { + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + remote()->transact(GET_CAMERA_INFO, data, &reply); + + reply.readExceptionCode(); + status_t result = reply.readInt32(); + + CameraMetadata out; + if (reply.readInt32() != 0) { + out.readFromParcel(&reply); + } + + if (info != NULL) { + info->swap(out); + } + + return result; + } + + virtual status_t waitUntilIdle() + { + ALOGV("waitUntilIdle"); + Parcel data, reply; + data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); + remote()->transact(WAIT_UNTIL_IDLE, data, &reply); + reply.readExceptionCode(); + return reply.readInt32(); + } + +private: + + +}; + +IMPLEMENT_META_INTERFACE(CameraDeviceUser, + "android.hardware.camera2.ICameraDeviceUser"); + +// ---------------------------------------------------------------------- + +status_t BnCameraDeviceUser::onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) +{ + switch(code) { + case DISCONNECT: { + ALOGV("DISCONNECT"); + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + disconnect(); + reply->writeNoException(); + return NO_ERROR; + } break; + case SUBMIT_REQUEST: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + + // arg0 = request + sp request; + if (data.readInt32() != 0) { + request = new CaptureRequest(); + request->readFromParcel(const_cast(&data)); + } + + // arg1 = streaming (bool) + bool streaming = data.readInt32(); + + // return code: requestId (int32) + reply->writeNoException(); + reply->writeInt32(submitRequest(request, streaming)); + + return NO_ERROR; + } break; + case CANCEL_REQUEST: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + int requestId = data.readInt32(); + reply->writeNoException(); + reply->writeInt32(cancelRequest(requestId)); + return NO_ERROR; + } break; + case DELETE_STREAM: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + int streamId = data.readInt32(); + reply->writeNoException(); + reply->writeInt32(deleteStream(streamId)); + return NO_ERROR; + } break; + case CREATE_STREAM: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + int width, height, format; + + width = data.readInt32(); + ALOGV("%s: CREATE_STREAM: width = %d", __FUNCTION__, width); + height = data.readInt32(); + ALOGV("%s: CREATE_STREAM: height = %d", __FUNCTION__, height); + format = data.readInt32(); + ALOGV("%s: CREATE_STREAM: format = %d", __FUNCTION__, format); + + sp bp; + if (data.readInt32() != 0) { + String16 name = data.readString16(); + bp = interface_cast( + data.readStrongBinder()); + + ALOGV("%s: CREATE_STREAM: bp = %p, name = %s", __FUNCTION__, + bp.get(), String8(name).string()); + } else { + ALOGV("%s: CREATE_STREAM: bp = unset, name = unset", + __FUNCTION__); + } + + status_t ret; + ret = createStream(width, height, format, bp); + + reply->writeNoException(); + ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__); + reply->writeInt32(ret); + ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret); + + return NO_ERROR; + } break; + + case CREATE_DEFAULT_REQUEST: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + + int templateId = data.readInt32(); + + CameraMetadata request; + status_t ret; + ret = createDefaultRequest(templateId, &request); + + reply->writeNoException(); + reply->writeInt32(ret); + + // out-variables are after exception and return value + reply->writeInt32(1); // to mark presence of metadata object + request.writeToParcel(const_cast(reply)); + + return NO_ERROR; + } break; + case GET_CAMERA_INFO: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + + CameraMetadata info; + status_t ret; + ret = getCameraInfo(&info); + + reply->writeNoException(); + reply->writeInt32(ret); + + // out-variables are after exception and return value + reply->writeInt32(1); // to mark presence of metadata object + info.writeToParcel(reply); + + return NO_ERROR; + } break; + case WAIT_UNTIL_IDLE: { + CHECK_INTERFACE(ICameraDeviceUser, data, reply); + reply->writeNoException(); + reply->writeInt32(waitUntilIdle()); + return NO_ERROR; + } break; + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + +// ---------------------------------------------------------------------------- + +}; // namespace android diff --git a/camera/photography/CaptureRequest.cpp b/camera/photography/CaptureRequest.cpp deleted file mode 100644 index b822fc9..0000000 --- a/camera/photography/CaptureRequest.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -** -** Copyright 2013, 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 "CameraRequest" -#include - -#include - -#include -#include - -namespace android { - -status_t CaptureRequest::readFromParcel(Parcel* parcel) { - if (parcel == NULL) { - ALOGE("%s: Null parcel", __FUNCTION__); - return BAD_VALUE; - } - - mMetadata.clear(); - mSurfaceList.clear(); - - status_t err; - - if ((err = mMetadata.readFromParcel(parcel)) != OK) { - ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__); - return err; - } - ALOGV("%s: Read metadata from parcel", __FUNCTION__); - - int32_t size; - if ((err = parcel->readInt32(&size)) != OK) { - ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__); - return err; - } - ALOGV("%s: Read surface list size = %d", __FUNCTION__, size); - - // Do not distinguish null arrays from 0-sized arrays. - for (int i = 0; i < size; ++i) { - // Parcel.writeParcelableArray - size_t len; - const char16_t* className = parcel->readString16Inplace(&len); - ALOGV("%s: Read surface class = %s", __FUNCTION__, - className != NULL ? String8(className).string() : ""); - - if (className == NULL) { - continue; - } - - // Surface.writeToParcel - String16 name = parcel->readString16(); - ALOGV("%s: Read surface name = %s", - __FUNCTION__, String8(name).string()); - sp binder(parcel->readStrongBinder()); - ALOGV("%s: Read surface binder = %p", - __FUNCTION__, binder.get()); - - sp surface; - - if (binder != NULL) { - sp gbp = - interface_cast(binder); - surface = new Surface(gbp); - } - - mSurfaceList.push_back(surface); - } - - return OK; -} - -status_t CaptureRequest::writeToParcel(Parcel* parcel) const { - if (parcel == NULL) { - ALOGE("%s: Null parcel", __FUNCTION__); - return BAD_VALUE; - } - - status_t err; - - if ((err = mMetadata.writeToParcel(parcel)) != OK) { - return err; - } - - int32_t size = static_cast(mSurfaceList.size()); - - // Send 0-sized arrays when it's empty. Do not send null arrays. - parcel->writeInt32(size); - - for (int32_t i = 0; i < size; ++i) { - sp surface = mSurfaceList[i]; - - sp binder; - if (surface != 0) { - binder = surface->getIGraphicBufferProducer()->asBinder(); - } - - // not sure if readParcelableArray does this, hard to tell from source - parcel->writeString16(String16("android.view.Surface")); - - // Surface.writeToParcel - parcel->writeString16(String16("unknown_name")); - // Surface.nativeWriteToParcel - parcel->writeStrongBinder(binder); - } - - return OK; -} - -}; // namespace android diff --git a/camera/photography/ICameraDeviceCallbacks.cpp b/camera/photography/ICameraDeviceCallbacks.cpp deleted file mode 100644 index 19763d7..0000000 --- a/camera/photography/ICameraDeviceCallbacks.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* -** -** Copyright 2013, 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 "ICameraDeviceCallbacks" -#include -#include -#include - -#include -#include -#include -#include - -#include -#include "camera/CameraMetadata.h" - -namespace android { - -enum { - NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, - RESULT_RECEIVED, -}; - -class BpCameraDeviceCallbacks: public BpInterface -{ -public: - BpCameraDeviceCallbacks(const sp& impl) - : BpInterface(impl) - { - } - - // generic callback from camera service to app - void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) - { - ALOGV("notifyCallback"); - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); - data.writeInt32(msgType); - data.writeInt32(ext1); - data.writeInt32(ext2); - remote()->transact(NOTIFY_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); - data.writeNoException(); - } - - void onResultReceived(int32_t frameId, const CameraMetadata& result) { - ALOGV("onResultReceived"); - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceCallbacks::getInterfaceDescriptor()); - data.writeInt32(frameId); - result.writeToParcel(&data); - remote()->transact(RESULT_RECEIVED, data, &reply, IBinder::FLAG_ONEWAY); - data.writeNoException(); - } -}; - -IMPLEMENT_META_INTERFACE(CameraDeviceCallbacks, - "android.hardware.photography.ICameraDeviceCallbacks"); - -// ---------------------------------------------------------------------- - -status_t BnCameraDeviceCallbacks::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - ALOGV("onTransact - code = %d", code); - switch(code) { - case NOTIFY_CALLBACK: { - ALOGV("NOTIFY_CALLBACK"); - CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); - int32_t msgType = data.readInt32(); - int32_t ext1 = data.readInt32(); - int32_t ext2 = data.readInt32(); - notifyCallback(msgType, ext1, ext2); - data.readExceptionCode(); - return NO_ERROR; - } break; - case RESULT_RECEIVED: { - ALOGV("RESULT_RECEIVED"); - CHECK_INTERFACE(ICameraDeviceCallbacks, data, reply); - int32_t frameId = data.readInt32(); - CameraMetadata result; - result.readFromParcel(const_cast(&data)); - onResultReceived(frameId, result); - data.readExceptionCode(); - return NO_ERROR; - break; - } - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - -// ---------------------------------------------------------------------------- - -}; // namespace android - diff --git a/camera/photography/ICameraDeviceUser.cpp b/camera/photography/ICameraDeviceUser.cpp deleted file mode 100644 index 95609da..0000000 --- a/camera/photography/ICameraDeviceUser.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* -** -** Copyright 2013, 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 "ICameraDeviceUser" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace android { - -typedef Parcel::WritableBlob WritableBlob; -typedef Parcel::ReadableBlob ReadableBlob; - -enum { - DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, - SUBMIT_REQUEST, - CANCEL_REQUEST, - DELETE_STREAM, - CREATE_STREAM, - CREATE_DEFAULT_REQUEST, - GET_CAMERA_INFO, - WAIT_UNTIL_IDLE, -}; - -class BpCameraDeviceUser : public BpInterface -{ -public: - BpCameraDeviceUser(const sp& impl) - : BpInterface(impl) - { - } - - // disconnect from camera service - void disconnect() - { - ALOGV("disconnect"); - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - remote()->transact(DISCONNECT, data, &reply); - reply.readExceptionCode(); - } - - virtual int submitRequest(sp request, bool streaming) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - - // arg0 = CaptureRequest - if (request != 0) { - data.writeInt32(1); - request->writeToParcel(&data); - } else { - data.writeInt32(0); - } - - // arg1 = streaming (bool) - data.writeInt32(streaming); - - remote()->transact(SUBMIT_REQUEST, data, &reply); - - reply.readExceptionCode(); - return reply.readInt32(); - } - - virtual status_t cancelRequest(int requestId) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - data.writeInt32(requestId); - - remote()->transact(CANCEL_REQUEST, data, &reply); - - reply.readExceptionCode(); - return reply.readInt32(); - } - - virtual status_t deleteStream(int streamId) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - data.writeInt32(streamId); - - remote()->transact(DELETE_STREAM, data, &reply); - - reply.readExceptionCode(); - return reply.readInt32(); - } - - virtual status_t createStream(int width, int height, int format, - const sp& bufferProducer) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - data.writeInt32(width); - data.writeInt32(height); - data.writeInt32(format); - - data.writeInt32(1); // marker that bufferProducer is not null - data.writeString16(String16("unknown_name")); // name of surface - sp b(bufferProducer->asBinder()); - data.writeStrongBinder(b); - - remote()->transact(CREATE_STREAM, data, &reply); - - reply.readExceptionCode(); - return reply.readInt32(); - } - - // Create a request object from a template. - virtual status_t createDefaultRequest(int templateId, - /*out*/ - CameraMetadata* request) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - data.writeInt32(templateId); - remote()->transact(CREATE_DEFAULT_REQUEST, data, &reply); - - reply.readExceptionCode(); - status_t result = reply.readInt32(); - - CameraMetadata out; - if (reply.readInt32() != 0) { - out.readFromParcel(&reply); - } - - if (request != NULL) { - request->swap(out); - } - return result; - } - - - virtual status_t getCameraInfo(CameraMetadata* info) - { - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - remote()->transact(GET_CAMERA_INFO, data, &reply); - - reply.readExceptionCode(); - status_t result = reply.readInt32(); - - CameraMetadata out; - if (reply.readInt32() != 0) { - out.readFromParcel(&reply); - } - - if (info != NULL) { - info->swap(out); - } - - return result; - } - - virtual status_t waitUntilIdle() - { - ALOGV("waitUntilIdle"); - Parcel data, reply; - data.writeInterfaceToken(ICameraDeviceUser::getInterfaceDescriptor()); - remote()->transact(WAIT_UNTIL_IDLE, data, &reply); - reply.readExceptionCode(); - return reply.readInt32(); - } - -private: - - -}; - -IMPLEMENT_META_INTERFACE(CameraDeviceUser, - "android.hardware.photography.ICameraDeviceUser"); - -// ---------------------------------------------------------------------- - -status_t BnCameraDeviceUser::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - switch(code) { - case DISCONNECT: { - ALOGV("DISCONNECT"); - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - disconnect(); - reply->writeNoException(); - return NO_ERROR; - } break; - case SUBMIT_REQUEST: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - - // arg0 = request - sp request; - if (data.readInt32() != 0) { - request = new CaptureRequest(); - request->readFromParcel(const_cast(&data)); - } - - // arg1 = streaming (bool) - bool streaming = data.readInt32(); - - // return code: requestId (int32) - reply->writeNoException(); - reply->writeInt32(submitRequest(request, streaming)); - - return NO_ERROR; - } break; - case CANCEL_REQUEST: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - int requestId = data.readInt32(); - reply->writeNoException(); - reply->writeInt32(cancelRequest(requestId)); - return NO_ERROR; - } break; - case DELETE_STREAM: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - int streamId = data.readInt32(); - reply->writeNoException(); - reply->writeInt32(deleteStream(streamId)); - return NO_ERROR; - } break; - case CREATE_STREAM: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - int width, height, format; - - width = data.readInt32(); - ALOGV("%s: CREATE_STREAM: width = %d", __FUNCTION__, width); - height = data.readInt32(); - ALOGV("%s: CREATE_STREAM: height = %d", __FUNCTION__, height); - format = data.readInt32(); - ALOGV("%s: CREATE_STREAM: format = %d", __FUNCTION__, format); - - sp bp; - if (data.readInt32() != 0) { - String16 name = data.readString16(); - bp = interface_cast( - data.readStrongBinder()); - - ALOGV("%s: CREATE_STREAM: bp = %p, name = %s", __FUNCTION__, - bp.get(), String8(name).string()); - } else { - ALOGV("%s: CREATE_STREAM: bp = unset, name = unset", - __FUNCTION__); - } - - status_t ret; - ret = createStream(width, height, format, bp); - - reply->writeNoException(); - ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__); - reply->writeInt32(ret); - ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret); - - return NO_ERROR; - } break; - - case CREATE_DEFAULT_REQUEST: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - - int templateId = data.readInt32(); - - CameraMetadata request; - status_t ret; - ret = createDefaultRequest(templateId, &request); - - reply->writeNoException(); - reply->writeInt32(ret); - - // out-variables are after exception and return value - reply->writeInt32(1); // to mark presence of metadata object - request.writeToParcel(const_cast(reply)); - - return NO_ERROR; - } break; - case GET_CAMERA_INFO: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - - CameraMetadata info; - status_t ret; - ret = getCameraInfo(&info); - - reply->writeNoException(); - reply->writeInt32(ret); - - // out-variables are after exception and return value - reply->writeInt32(1); // to mark presence of metadata object - info.writeToParcel(reply); - - return NO_ERROR; - } break; - case WAIT_UNTIL_IDLE: { - CHECK_INTERFACE(ICameraDeviceUser, data, reply); - reply->writeNoException(); - reply->writeInt32(waitUntilIdle()); - return NO_ERROR; - } break; - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - -// ---------------------------------------------------------------------------- - -}; // namespace android -- cgit v1.1