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 | ** |
| 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 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "ICameraClient" |
| 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 <ui/ICameraClient.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | enum { |
| 28 | SHUTTER_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, |
| 29 | RAW_CALLBACK, |
| 30 | JPEG_CALLBACK, |
| 31 | FRAME_CALLBACK, |
| 32 | ERROR_CALLBACK, |
| 33 | AUTOFOCUS_CALLBACK |
| 34 | }; |
| 35 | |
| 36 | class BpCameraClient: public BpInterface<ICameraClient> |
| 37 | { |
| 38 | public: |
| 39 | BpCameraClient(const sp<IBinder>& impl) |
| 40 | : BpInterface<ICameraClient>(impl) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | // callback to let the app know the shutter has closed, ideal for playing the shutter sound |
| 45 | void shutterCallback() |
| 46 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 47 | LOGV("shutterCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | Parcel data, reply; |
| 49 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 50 | remote()->transact(SHUTTER_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 51 | } |
| 52 | |
| 53 | // callback from camera service to app with picture data |
| 54 | void rawCallback(const sp<IMemory>& picture) |
| 55 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 56 | LOGV("rawCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 57 | Parcel data, reply; |
| 58 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 59 | data.writeStrongBinder(picture->asBinder()); |
| 60 | remote()->transact(RAW_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 61 | } |
| 62 | |
| 63 | // callback from camera service to app with picture data |
| 64 | void jpegCallback(const sp<IMemory>& picture) |
| 65 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 66 | LOGV("jpegCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 69 | data.writeStrongBinder(picture->asBinder()); |
| 70 | remote()->transact(JPEG_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 71 | } |
| 72 | |
| 73 | // callback from camera service to app with video frame data |
| 74 | void frameCallback(const sp<IMemory>& frame) |
| 75 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 76 | LOGV("frameCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 77 | Parcel data, reply; |
| 78 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 79 | data.writeStrongBinder(frame->asBinder()); |
| 80 | remote()->transact(FRAME_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 81 | } |
| 82 | |
| 83 | // callback from camera service to app to report error |
| 84 | void errorCallback(status_t error) |
| 85 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 86 | LOGV("errorCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | Parcel data, reply; |
| 88 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 89 | data.writeInt32(error); |
| 90 | remote()->transact(ERROR_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 91 | } |
| 92 | |
| 93 | // callback from camera service to app to report autofocus completion |
| 94 | void autoFocusCallback(bool focused) |
| 95 | { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 96 | LOGV("autoFocusCallback"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | Parcel data, reply; |
| 98 | data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor()); |
| 99 | data.writeInt32(focused); |
| 100 | remote()->transact(AUTOFOCUS_CALLBACK, data, &reply, IBinder::FLAG_ONEWAY); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient"); |
| 105 | |
| 106 | // ---------------------------------------------------------------------- |
| 107 | |
| 108 | #define CHECK_INTERFACE(interface, data, reply) \ |
| 109 | do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ |
| 110 | LOGW("Call incorrectly routed to " #interface); \ |
| 111 | return PERMISSION_DENIED; \ |
| 112 | } } while (0) |
| 113 | |
| 114 | status_t BnCameraClient::onTransact( |
| 115 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 116 | { |
| 117 | switch(code) { |
| 118 | case SHUTTER_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 119 | LOGV("SHUTTER_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 120 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 121 | shutterCallback(); |
| 122 | return NO_ERROR; |
| 123 | } break; |
| 124 | case RAW_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 125 | LOGV("RAW_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 127 | sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder()); |
| 128 | rawCallback(picture); |
| 129 | return NO_ERROR; |
| 130 | } break; |
| 131 | case JPEG_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 132 | LOGV("JPEG_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 133 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 134 | sp<IMemory> picture = interface_cast<IMemory>(data.readStrongBinder()); |
| 135 | jpegCallback(picture); |
| 136 | return NO_ERROR; |
| 137 | } break; |
| 138 | case FRAME_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 139 | LOGV("FRAME_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 140 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 141 | sp<IMemory> frame = interface_cast<IMemory>(data.readStrongBinder()); |
| 142 | frameCallback(frame); |
| 143 | return NO_ERROR; |
| 144 | } break; |
| 145 | case ERROR_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 146 | LOGV("ERROR_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 147 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 148 | status_t error = data.readInt32(); |
| 149 | errorCallback(error); |
| 150 | return NO_ERROR; |
| 151 | } break; |
| 152 | case AUTOFOCUS_CALLBACK: { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 153 | LOGV("AUTOFOCUS_CALLBACK"); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | CHECK_INTERFACE(ICameraClient, data, reply); |
| 155 | bool focused = (bool)data.readInt32(); |
| 156 | autoFocusCallback(focused); |
| 157 | return NO_ERROR; |
| 158 | } break; |
| 159 | default: |
| 160 | return BBinder::onTransact(code, data, reply, flags); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // ---------------------------------------------------------------------------- |
| 165 | |
| 166 | }; // namespace android |
| 167 | |