The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 8 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 10 | ** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ICamera" |
| 20 | #include <utils/Log.h> |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 23 | #include <utils/Parcel.h> |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 24 | #include <ui/ICamera.h> |
| 25 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | enum { |
| 29 | DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, |
| 30 | SET_PREVIEW_DISPLAY, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 31 | SET_FRAME_CALLBACK_FLAG, |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | START_PREVIEW, |
| 33 | STOP_PREVIEW, |
| 34 | AUTO_FOCUS, |
| 35 | TAKE_PICTURE, |
| 36 | SET_PARAMETERS, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 37 | GET_PARAMETERS, |
| 38 | CONNECT |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpCamera: public BpInterface<ICamera> |
| 42 | { |
| 43 | public: |
| 44 | BpCamera(const sp<IBinder>& impl) |
| 45 | : BpInterface<ICamera>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | // disconnect from camera service |
| 50 | void disconnect() |
| 51 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 52 | LOGV("disconnect"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | Parcel data, reply; |
| 54 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 55 | remote()->transact(DISCONNECT, data, &reply); |
| 56 | } |
| 57 | |
| 58 | // pass the buffered ISurface to the camera service |
| 59 | status_t setPreviewDisplay(const sp<ISurface>& surface) |
| 60 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 61 | LOGV("setPreviewDisplay"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 62 | Parcel data, reply; |
| 63 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 64 | data.writeStrongBinder(surface->asBinder()); |
| 65 | remote()->transact(SET_PREVIEW_DISPLAY, data, &reply); |
| 66 | return reply.readInt32(); |
| 67 | } |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 68 | |
| 69 | // set the frame callback flag to affect how the received frames from |
| 70 | // preview are handled. |
| 71 | void setFrameCallbackFlag(int frame_callback_flag) |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 73 | LOGV("setFrameCallbackFlag(%d)", frame_callback_flag); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 74 | Parcel data, reply; |
| 75 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 76 | data.writeInt32(frame_callback_flag); |
| 77 | remote()->transact(SET_FRAME_CALLBACK_FLAG, data, &reply); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // start preview mode, must call setPreviewDisplay first |
| 81 | status_t startPreview() |
| 82 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 83 | LOGV("startPreview"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 86 | remote()->transact(START_PREVIEW, data, &reply); |
| 87 | return reply.readInt32(); |
| 88 | } |
| 89 | |
| 90 | // stop preview mode |
| 91 | void stopPreview() |
| 92 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 93 | LOGV("stopPreview"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 94 | Parcel data, reply; |
| 95 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 96 | remote()->transact(STOP_PREVIEW, data, &reply); |
| 97 | } |
| 98 | |
| 99 | // auto focus |
| 100 | status_t autoFocus() |
| 101 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 102 | LOGV("autoFocus"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 103 | Parcel data, reply; |
| 104 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 105 | remote()->transact(AUTO_FOCUS, data, &reply); |
| 106 | status_t ret = reply.readInt32(); |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | // take a picture - returns an IMemory (ref-counted mmap) |
| 111 | status_t takePicture() |
| 112 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 113 | LOGV("takePicture"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | Parcel data, reply; |
| 115 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 116 | remote()->transact(TAKE_PICTURE, data, &reply); |
| 117 | status_t ret = reply.readInt32(); |
| 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | // set preview/capture parameters - key/value pairs |
| 122 | status_t setParameters(const String8& params) |
| 123 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 124 | LOGV("setParameters"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 125 | Parcel data, reply; |
| 126 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 127 | data.writeString8(params); |
| 128 | remote()->transact(SET_PARAMETERS, data, &reply); |
| 129 | return reply.readInt32(); |
| 130 | } |
| 131 | |
| 132 | // get preview/capture parameters - key/value pairs |
| 133 | String8 getParameters() const |
| 134 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 135 | LOGV("getParameters"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | Parcel data, reply; |
| 137 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 138 | remote()->transact(GET_PARAMETERS, data, &reply); |
| 139 | return reply.readString8(); |
| 140 | } |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 141 | virtual status_t connect(const sp<ICameraClient>& cameraClient) |
| 142 | { |
| 143 | Parcel data, reply; |
| 144 | data.writeInterfaceToken(ICamera::getInterfaceDescriptor()); |
| 145 | data.writeStrongBinder(cameraClient->asBinder()); |
| 146 | remote()->transact(CONNECT, data, &reply); |
| 147 | return reply.readInt32(); |
| 148 | } |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | IMPLEMENT_META_INTERFACE(Camera, "android.hardware.ICamera"); |
| 152 | |
| 153 | // ---------------------------------------------------------------------- |
| 154 | |
| 155 | #define CHECK_INTERFACE(interface, data, reply) \ |
| 156 | do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ |
| 157 | LOGW("Call incorrectly routed to " #interface); \ |
| 158 | return PERMISSION_DENIED; \ |
| 159 | } } while (0) |
| 160 | |
| 161 | status_t BnCamera::onTransact( |
| 162 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 163 | { |
| 164 | switch(code) { |
| 165 | case DISCONNECT: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 166 | LOGV("DISCONNECT"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 167 | CHECK_INTERFACE(ICamera, data, reply); |
| 168 | disconnect(); |
| 169 | return NO_ERROR; |
| 170 | } break; |
| 171 | case SET_PREVIEW_DISPLAY: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 172 | LOGV("SET_PREVIEW_DISPLAY"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 173 | CHECK_INTERFACE(ICamera, data, reply); |
| 174 | sp<ISurface> surface = interface_cast<ISurface>(data.readStrongBinder()); |
| 175 | reply->writeInt32(setPreviewDisplay(surface)); |
| 176 | return NO_ERROR; |
| 177 | } break; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 178 | case SET_FRAME_CALLBACK_FLAG: { |
| 179 | LOGV("SET_FRAME_CALLBACK_TYPE"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 180 | CHECK_INTERFACE(ICamera, data, reply); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 181 | int frame_callback_flag = data.readInt32(); |
| 182 | setFrameCallbackFlag(frame_callback_flag); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 183 | return NO_ERROR; |
| 184 | } break; |
| 185 | case START_PREVIEW: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 186 | LOGV("START_PREVIEW"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 | CHECK_INTERFACE(ICamera, data, reply); |
| 188 | reply->writeInt32(startPreview()); |
| 189 | return NO_ERROR; |
| 190 | } break; |
| 191 | case STOP_PREVIEW: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 192 | LOGV("STOP_PREVIEW"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 193 | CHECK_INTERFACE(ICamera, data, reply); |
| 194 | stopPreview(); |
| 195 | return NO_ERROR; |
| 196 | } break; |
| 197 | case AUTO_FOCUS: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 198 | LOGV("AUTO_FOCUS"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 199 | CHECK_INTERFACE(ICamera, data, reply); |
| 200 | reply->writeInt32(autoFocus()); |
| 201 | return NO_ERROR; |
| 202 | } break; |
| 203 | case TAKE_PICTURE: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 204 | LOGV("TAKE_PICTURE"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 205 | CHECK_INTERFACE(ICamera, data, reply); |
| 206 | reply->writeInt32(takePicture()); |
| 207 | return NO_ERROR; |
| 208 | } break; |
| 209 | case SET_PARAMETERS: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 210 | LOGV("SET_PARAMETERS"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | CHECK_INTERFACE(ICamera, data, reply); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 212 | String8 params(data.readString8()); |
| 213 | reply->writeInt32(setParameters(params)); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 214 | return NO_ERROR; |
| 215 | } break; |
| 216 | case GET_PARAMETERS: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 217 | LOGV("GET_PARAMETERS"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | CHECK_INTERFACE(ICamera, data, reply); |
| 219 | reply->writeString8(getParameters()); |
| 220 | return NO_ERROR; |
| 221 | } break; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 222 | case CONNECT: { |
| 223 | CHECK_INTERFACE(ICamera, data, reply); |
| 224 | sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder()); |
| 225 | reply->writeInt32(connect(cameraClient)); |
| 226 | return NO_ERROR; |
| 227 | } break; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | default: |
| 229 | return BBinder::onTransact(code, data, reply, flags); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // ---------------------------------------------------------------------------- |
| 234 | |
| 235 | }; // namespace android |
| 236 | |