From 634a51509ee50475f3e9f8ccf897e90fc72ded31 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Wed, 20 Feb 2013 17:15:11 -0800 Subject: Camera: Add ProCamera private binder interface for an API2-light functionality Change-Id: I2af7a807c99df75ea659e6e6acc9c4fca6a56274 --- include/camera/ICameraService.h | 8 +- include/camera/IProCameraCallbacks.h | 57 ++++++++++++ include/camera/IProCameraUser.h | 82 +++++++++++++++++ include/camera/ProCamera.h | 167 +++++++++++++++++++++++++++++++++++ 4 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 include/camera/IProCameraCallbacks.h create mode 100644 include/camera/IProCameraUser.h create mode 100644 include/camera/ProCamera.h (limited to 'include/camera') diff --git a/include/camera/ICameraService.h b/include/camera/ICameraService.h index 7d70c1e..11d7b65 100644 --- a/include/camera/ICameraService.h +++ b/include/camera/ICameraService.h @@ -23,6 +23,7 @@ #include #include +#include namespace android { @@ -32,7 +33,8 @@ public: enum { GET_NUMBER_OF_CAMERAS = IBinder::FIRST_CALL_TRANSACTION, GET_CAMERA_INFO, - CONNECT + CONNECT, + CONNECT_PRO }; public: @@ -43,6 +45,10 @@ public: struct CameraInfo* cameraInfo) = 0; virtual sp connect(const sp& cameraClient, int cameraId) = 0; + + virtual sp + connect(const sp& cameraCb, + int cameraId) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/camera/IProCameraCallbacks.h b/include/camera/IProCameraCallbacks.h new file mode 100644 index 0000000..ac1d5eb --- /dev/null +++ b/include/camera/IProCameraCallbacks.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 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. + */ + +#ifndef ANDROID_HARDWARE_IPROCAMERA_CALLBACKS_H +#define ANDROID_HARDWARE_IPROCAMERA_CALLBACKS_H + +#include +#include +#include +#include +#include +#include + +namespace android { + +class IProCameraCallbacks: public IInterface +{ +public: + DECLARE_META_INTERFACE(ProCameraCallbacks); + + virtual void notifyCallback(int32_t msgType, int32_t ext1, + int32_t ext2) = 0; + virtual void dataCallback(int32_t msgType, + const sp& data, + camera_frame_metadata_t *metadata) = 0; + virtual void dataCallbackTimestamp(nsecs_t timestamp, + int32_t msgType, + const sp& data) = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnProCameraCallbacks: public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif diff --git a/include/camera/IProCameraUser.h b/include/camera/IProCameraUser.h new file mode 100644 index 0000000..6170410 --- /dev/null +++ b/include/camera/IProCameraUser.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 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. + */ + +#ifndef ANDROID_HARDWARE_IPROCAMERAUSER_H +#define ANDROID_HARDWARE_IPROCAMERAUSER_H + +#include +#include +#include +#include +#include +#include + +struct camera_metadata; + +namespace android { + +class IProCameraUserClient; +class IGraphicBufferProducer; +class Surface; + +class IProCameraUser: public IInterface +{ +public: + DECLARE_META_INTERFACE(ProCameraUser); + + virtual void disconnect() = 0; + + // connect to the service, given a callbacks listener + virtual status_t connect(const sp& callbacks) + = 0; + + /** + * Locking + **/ + virtual status_t exclusiveTryLock() = 0; + virtual status_t exclusiveLock() = 0; + virtual status_t exclusiveUnlock() = 0; + + virtual bool hasExclusiveLock() = 0; + + /** + * Request Handling + **/ + + // Note that the callee gets a copy of the metadata. + virtual int submitRequest(struct camera_metadata* metadata, + bool streaming = false) = 0; + virtual status_t cancelRequest(int requestId) = 0; + + virtual status_t requestStream(int streamId) = 0; + virtual status_t cancelStream(int streamId) = 0; + +}; + +// ---------------------------------------------------------------------------- + +class BnProCameraUser: public BnInterface +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +}; // namespace android + +#endif diff --git a/include/camera/ProCamera.h b/include/camera/ProCamera.h new file mode 100644 index 0000000..ba5fdc0 --- /dev/null +++ b/include/camera/ProCamera.h @@ -0,0 +1,167 @@ +/* + * Copyright (C) 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. + */ + +#ifndef ANDROID_HARDWARE_PRO_CAMERA_H +#define ANDROID_HARDWARE_PRO_CAMERA_H + +#include +#include +#include +#include +#include +#include + +struct camera_metadata; + +namespace android { + +// ref-counted object for callbacks +class ProCameraListener : public CameraListener +{ +public: + // Lock has been acquired. Write operations now available. + virtual void onLockAcquired() = 0; + // Lock has been released with exclusiveUnlock, or has been stolen by + // another client. + virtual void onLockReleased() = 0; + + // Lock free. + virtual void onTriggerNotify(int32_t msgType, int32_t ext1, int32_t ext2) + = 0; +}; + +class ProCamera : public BnProCameraCallbacks, public IBinder::DeathRecipient +{ +public: + /** + * Connect a shared camera. By default access is restricted to read only + * (Lock free) operations. To be able to submit custom requests a lock needs + * to be acquired with exclusive[Try]Lock. + */ + static sp connect(int cameraId); + virtual void disconnect(); + virtual ~ProCamera(); + + void setListener(const sp& listener); + + /** + * Exclusive Locks: + * - We may request exclusive access to a camera if no other + * clients are using the camera. This works as a traditional + * client, writing/reading any camera state. + * - An application opening the camera (a regular 'Camera') will + * always steal away the exclusive lock from a ProCamera, + * this will call onLockReleased. + * - onLockAcquired will be called again once it is possible + * to again exclusively lock the camera. + * + */ + + /** + * All exclusiveLock/unlock functions are asynchronous. The remote endpoint + * shall not block while waiting to acquire the lock. Instead the lock + * notifications will come in asynchronously on the listener. + */ + + /** + * Attempt to acquire the lock instantly (non-blocking) + * - If this succeeds, you do not need to wait for onLockAcquired + * but the event will still be fired + * + * Returns -EBUSY if already locked. 0 on success. + */ + status_t exclusiveTryLock(); + // always returns 0. wait for onLockAcquired before lock is acquired. + status_t exclusiveLock(); + // release a lock if we have one, or cancel the lock request. + status_t exclusiveUnlock(); + + // exclusive lock = do whatever we want. no lock = read only. + bool hasExclusiveLock(); + + /** + * < 0 error, >= 0 the request ID. streaming to have the request repeat + * until cancelled. + * The request queue is flushed when a lock is released or stolen + * if not locked will return PERMISSION_DENIED + */ + int submitRequest(const struct camera_metadata* metadata, + bool streaming = false); + // if not locked will return PERMISSION_DENIED, BAD_VALUE if requestId bad + status_t cancelRequest(int requestId); + + /** + * Ask for a stream to be enabled. + * Lock free. Service maintains counter of streams. + */ + status_t requestStream(int streamId); + /** + * Ask for a stream to be disabled. + * Lock free. Service maintains counter of streams. + * Errors: BAD_VALUE if unknown stream ID. + */ + status_t cancelStream(int streamId); + + sp remote(); + +protected: + //////////////////////////////////////////////////////// + // IProCameraCallbacks implementation + //////////////////////////////////////////////////////// + virtual void notifyCallback(int32_t msgType, int32_t ext, + int32_t ext2); + virtual void dataCallback(int32_t msgType, + const sp& dataPtr, + camera_frame_metadata_t *metadata); + virtual void dataCallbackTimestamp(nsecs_t timestamp, + int32_t msgType, + const sp& dataPtr); + + class DeathNotifier: public IBinder::DeathRecipient + { + public: + DeathNotifier() { + } + + virtual void binderDied(const wp& who); + }; + +private: + ProCamera(); + + virtual void binderDied(const wp& who); + + // helper function to obtain camera service handle + static const sp& getCameraService(); + + static sp mDeathNotifier; + + sp mCamera; + status_t mStatus; + + sp mListener; + + friend class DeathNotifier; + + static Mutex mLock; + static sp mCameraService; + + +}; + +}; // namespace android + +#endif -- cgit v1.1