The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 3 | * Copyright (C) 2008 HTC Inc. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_HARDWARE_CAMERA_H |
| 19 | #define ANDROID_HARDWARE_CAMERA_H |
| 20 | |
| 21 | #include <ui/ICameraClient.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 25 | /* |
| 26 | * A set of bit masks for specifying how the received frames from preview are |
| 27 | * handled before the frame callback call. |
| 28 | * |
| 29 | * The least significant 3 bits of an "int" value are used for this purpose: |
| 30 | * |
| 31 | * ..... 0 0 0 |
| 32 | * ^ ^ ^ |
| 33 | * | | |---------> determine whether the callback is enabled or not |
| 34 | * | |-----------> determine whether the callback is one-shot or not |
| 35 | * |-------------> determine whether the frame is copied out or not |
| 36 | * |
| 37 | * For instance, |
| 38 | * 1. 0x00 disables the callback. In this case, copy out and one shot bits |
| 39 | * are ignored. |
| 40 | * 2. 0x01 enables a callback without copying out the recievied frames. A |
| 41 | * typical use case is the Camcorder application to avoid making costly |
| 42 | * frame copies. |
| 43 | * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical |
| 44 | * use case is the Camera application. |
| 45 | * 4. 0x07 is enabling a callback with frame copied out only once. A typical use |
| 46 | * case is the Barcode scanner application. |
| 47 | */ |
| 48 | #define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01 |
| 49 | #define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02 |
| 50 | #define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04 |
| 51 | |
| 52 | // Typical use cases |
| 53 | #define FRAME_CALLBACK_FLAG_NOOP 0x00 |
| 54 | #define FRAME_CALLBACK_FLAG_CAMCORDER 0x01 |
| 55 | #define FRAME_CALLBACK_FLAG_CAMERA 0x05 |
| 56 | #define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 |
| 57 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 58 | class ICameraService; |
| 59 | class ICamera; |
| 60 | class Surface; |
| 61 | class Mutex; |
| 62 | class String8; |
| 63 | |
| 64 | typedef void (*shutter_callback)(void *cookie); |
| 65 | typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie); |
| 66 | typedef void (*autofocus_callback)(bool focused, void *cookie); |
| 67 | typedef void (*error_callback)(status_t err, void *cookie); |
| 68 | |
| 69 | class Camera : public BnCameraClient, public IBinder::DeathRecipient |
| 70 | { |
| 71 | public: |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 72 | // construct a camera client from an existing remote |
| 73 | Camera(const sp<ICamera>& camera); |
| 74 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 75 | static sp<Camera> connect(); |
| 76 | ~Camera(); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 77 | void init(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 79 | status_t reconnect(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | void disconnect(); |
| 81 | |
| 82 | status_t getStatus() { return mStatus; } |
| 83 | |
| 84 | // pass the buffered ISurface to the camera service |
| 85 | status_t setPreviewDisplay(const sp<Surface>& surface); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 86 | status_t setPreviewDisplay(const sp<ISurface>& surface); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | |
| 88 | // start preview mode, must call setPreviewDisplay first |
| 89 | status_t startPreview(); |
| 90 | |
| 91 | // stop preview mode |
| 92 | void stopPreview(); |
| 93 | |
| 94 | // autoFocus - status returned from callback |
| 95 | status_t autoFocus(); |
| 96 | |
| 97 | // take a picture - picture returned from callback |
| 98 | status_t takePicture(); |
| 99 | |
| 100 | // set preview/capture parameters - key/value pairs |
| 101 | status_t setParameters(const String8& params); |
| 102 | |
| 103 | // get preview/capture parameters - key/value pairs |
| 104 | String8 getParameters() const; |
| 105 | |
| 106 | void setShutterCallback(shutter_callback cb, void *cookie); |
| 107 | void setRawCallback(frame_callback cb, void *cookie); |
| 108 | void setJpegCallback(frame_callback cb, void *cookie); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 109 | |
| 110 | void setFrameCallback(frame_callback cb, |
| 111 | void *cookie, |
| 112 | int frame_callback_flag = FRAME_CALLBACK_FLAG_NOOP); |
| 113 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | void setErrorCallback(error_callback cb, void *cookie); |
| 115 | void setAutoFocusCallback(autofocus_callback cb, void *cookie); |
| 116 | // ICameraClient interface |
| 117 | virtual void shutterCallback(); |
| 118 | virtual void rawCallback(const sp<IMemory>& picture); |
| 119 | virtual void jpegCallback(const sp<IMemory>& picture); |
| 120 | virtual void frameCallback(const sp<IMemory>& frame); |
| 121 | virtual void errorCallback(status_t error); |
| 122 | virtual void autoFocusCallback(bool focused); |
| 123 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 124 | sp<ICamera> remote(); |
| 125 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | private: |
| 127 | Camera(); |
| 128 | virtual void binderDied(const wp<IBinder>& who); |
| 129 | |
| 130 | class DeathNotifier: public IBinder::DeathRecipient |
| 131 | { |
| 132 | public: |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 133 | DeathNotifier() { |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | } |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 135 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | virtual void binderDied(const wp<IBinder>& who); |
| 137 | }; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 138 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 139 | static sp<DeathNotifier> mDeathNotifier; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 140 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 141 | // helper function to obtain camera service handle |
| 142 | static const sp<ICameraService>& getCameraService(); |
| 143 | |
| 144 | sp<ICamera> mCamera; |
| 145 | status_t mStatus; |
| 146 | |
| 147 | shutter_callback mShutterCallback; |
| 148 | void *mShutterCallbackCookie; |
| 149 | frame_callback mRawCallback; |
| 150 | void *mRawCallbackCookie; |
| 151 | frame_callback mJpegCallback; |
| 152 | void *mJpegCallbackCookie; |
| 153 | frame_callback mFrameCallback; |
| 154 | void *mFrameCallbackCookie; |
| 155 | error_callback mErrorCallback; |
| 156 | void *mErrorCallbackCookie; |
| 157 | autofocus_callback mAutoFocusCallback; |
| 158 | void *mAutoFocusCallbackCookie; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 159 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 160 | friend class DeathNotifier; |
| 161 | |
| 162 | static Mutex mLock; |
| 163 | static sp<ICameraService> mCameraService; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 164 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | }; // namespace android |
| 168 | |
| 169 | #endif |
| 170 | |