Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright (C) 2008, The Android Open Source Project |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [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 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "Camera" |
| 20 | #include <utils/Log.h> |
| 21 | #include <utils/threads.h> |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 22 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
| 24 | #include <binder/IMemory.h> |
| 25 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 26 | #include <Camera.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 27 | #include <android/hardware/ICameraService.h> |
| 28 | #include <android/hardware/ICamera.h> |
Mathias Agopian | df712ea | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 29 | #include <gui/Surface.h> |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 33 | Camera::Camera(int cameraId) |
| 34 | : CameraBase(cameraId) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | { |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 38 | CameraTraits<Camera>::TCamConnectService CameraTraits<Camera>::fnConnectService = |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 39 | &::android::hardware::ICameraService::connect; |
Ruben Brunk | 0f61d8f | 2013-08-08 13:07:18 -0700 | [diff] [blame] | 40 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 41 | // construct a camera client from an existing camera remote |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 42 | sp<Camera> Camera::create(const sp<::android::hardware::ICamera>& camera) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 43 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 44 | ALOGV("create"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 45 | if (camera == 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 46 | ALOGE("camera remote is a NULL pointer"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 50 | sp<Camera> c = new Camera(-1); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 51 | if (camera->connect(c) == NO_ERROR) { |
| 52 | c->mStatus = NO_ERROR; |
| 53 | c->mCamera = camera; |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 54 | IInterface::asBinder(camera)->linkToDeath(c); |
Wu-cheng Li | 627baac | 2011-01-04 20:00:55 +0800 | [diff] [blame] | 55 | return c; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 56 | } |
Wu-cheng Li | 627baac | 2011-01-04 20:00:55 +0800 | [diff] [blame] | 57 | return 0; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 60 | Camera::~Camera() |
| 61 | { |
Chih-Chung Chang | d06618e | 2010-05-13 15:14:24 +0800 | [diff] [blame] | 62 | // We don't need to call disconnect() here because if the CameraService |
| 63 | // thinks we are the owner of the hardware, it will hold a (strong) |
| 64 | // reference to us, and we can't possibly be here. We also don't want to |
| 65 | // call disconnect() here if we are in the same process as mediaserver, |
| 66 | // because we may be invoked by CameraService::Client::connect() and will |
| 67 | // deadlock if we call any method of ICamera here. |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Austin Borger | d1ad6c6 | 2024-07-01 11:28:31 -0700 | [diff] [blame] | 70 | sp<Camera> Camera::connect(int cameraId, int targetSdkVersion, int rotationOverride, |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 71 | bool forceSlowJpegMode, const AttributionSourceState& clientAttribution, |
| 72 | int32_t devicePolicy) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 73 | { |
Austin Borger | d1ad6c6 | 2024-07-01 11:28:31 -0700 | [diff] [blame] | 74 | return CameraBaseT::connect(cameraId, targetSdkVersion, rotationOverride, |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 75 | forceSlowJpegMode, clientAttribution, devicePolicy); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | status_t Camera::reconnect() |
| 79 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 80 | ALOGV("reconnect"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 81 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 82 | if (c == 0) return NO_INIT; |
| 83 | return c->connect(this); |
| 84 | } |
| 85 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 86 | status_t Camera::lock() |
| 87 | { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 88 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 89 | if (c == 0) return NO_INIT; |
| 90 | return c->lock(); |
| 91 | } |
| 92 | |
| 93 | status_t Camera::unlock() |
| 94 | { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 95 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 96 | if (c == 0) return NO_INIT; |
| 97 | return c->unlock(); |
| 98 | } |
| 99 | |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 100 | // pass the Surface to the camera service |
| 101 | status_t Camera::setPreviewTarget(const sp<SurfaceType>& target) { |
| 102 | ALOGV("setPreviewTarget(%p)", target.get()); |
| 103 | sp<::android::hardware::ICamera> c = mCamera; |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 104 | if (c == 0) return NO_INIT; |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 105 | ALOGD_IF(target == 0, "app passed NULL surface"); |
| 106 | return c->setPreviewTarget(target); |
Jamie Gennis | bfa33aa | 2010-12-20 11:51:31 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 109 | status_t Camera::setVideoTarget(const sp<SurfaceType>& target) { |
| 110 | ALOGV("setVideoTarget(%p)", target.get()); |
| 111 | sp<::android::hardware::ICamera> c = mCamera; |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 112 | if (c == 0) return NO_INIT; |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 113 | ALOGD_IF(target == 0, "app passed NULL video surface"); |
| 114 | return c->setVideoTarget(target); |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 117 | // start preview mode |
| 118 | status_t Camera::startPreview() |
| 119 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 120 | ALOGV("startPreview"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 121 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 122 | if (c == 0) return NO_INIT; |
| 123 | return c->startPreview(); |
| 124 | } |
| 125 | |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 126 | status_t Camera::setVideoBufferMode(int32_t videoBufferMode) |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 127 | { |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 128 | ALOGV("setVideoBufferMode: %d", videoBufferMode); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 129 | sp <::android::hardware::ICamera> c = mCamera; |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 130 | if (c == 0) return NO_INIT; |
Chien-Yu Chen | 8cca075 | 2015-11-13 15:28:48 -0800 | [diff] [blame] | 131 | return c->setVideoBufferMode(videoBufferMode); |
James Dong | e2ad673 | 2010-10-18 20:42:51 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Eino-Ville Talvala | 4b820b0 | 2013-08-21 14:39:05 -0700 | [diff] [blame] | 134 | // start recording mode, must call setPreviewTarget first |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 135 | status_t Camera::startRecording() |
| 136 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 137 | ALOGV("startRecording"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 138 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 139 | if (c == 0) return NO_INIT; |
| 140 | return c->startRecording(); |
| 141 | } |
| 142 | |
| 143 | // stop preview mode |
| 144 | void Camera::stopPreview() |
| 145 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 146 | ALOGV("stopPreview"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 147 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 148 | if (c == 0) return; |
| 149 | c->stopPreview(); |
| 150 | } |
| 151 | |
| 152 | // stop recording mode |
| 153 | void Camera::stopRecording() |
| 154 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 155 | ALOGV("stopRecording"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 156 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 157 | if (c == 0) return; |
| 158 | c->stopRecording(); |
| 159 | } |
| 160 | |
| 161 | // release a recording frame |
| 162 | void Camera::releaseRecordingFrame(const sp<IMemory>& mem) |
| 163 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 164 | ALOGV("releaseRecordingFrame"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 165 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 166 | if (c == 0) return; |
| 167 | c->releaseRecordingFrame(mem); |
| 168 | } |
| 169 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 170 | void Camera::releaseRecordingFrameHandle(native_handle_t* handle) |
| 171 | { |
| 172 | ALOGV("releaseRecordingFrameHandle"); |
| 173 | sp <::android::hardware::ICamera> c = mCamera; |
| 174 | if (c == 0) return; |
| 175 | c->releaseRecordingFrameHandle(handle); |
| 176 | } |
| 177 | |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 178 | void Camera::releaseRecordingFrameHandleBatch( |
| 179 | const std::vector<native_handle_t*> handles) { |
| 180 | ALOGV("releaseRecordingFrameHandleBatch"); |
| 181 | sp <::android::hardware::ICamera> c = mCamera; |
| 182 | if (c == 0) return; |
| 183 | c->releaseRecordingFrameHandleBatch(handles); |
| 184 | } |
| 185 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 186 | // get preview state |
| 187 | bool Camera::previewEnabled() |
| 188 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 189 | ALOGV("previewEnabled"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 190 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 191 | if (c == 0) return false; |
| 192 | return c->previewEnabled(); |
| 193 | } |
| 194 | |
| 195 | // get recording state |
| 196 | bool Camera::recordingEnabled() |
| 197 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 198 | ALOGV("recordingEnabled"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 199 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 200 | if (c == 0) return false; |
| 201 | return c->recordingEnabled(); |
| 202 | } |
| 203 | |
| 204 | status_t Camera::autoFocus() |
| 205 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 206 | ALOGV("autoFocus"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 207 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 208 | if (c == 0) return NO_INIT; |
| 209 | return c->autoFocus(); |
| 210 | } |
| 211 | |
| 212 | status_t Camera::cancelAutoFocus() |
| 213 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 214 | ALOGV("cancelAutoFocus"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 215 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 216 | if (c == 0) return NO_INIT; |
| 217 | return c->cancelAutoFocus(); |
| 218 | } |
| 219 | |
| 220 | // take a picture |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 221 | status_t Camera::takePicture(int msgType) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 222 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 223 | ALOGV("takePicture: 0x%x", msgType); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 224 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 225 | if (c == 0) return NO_INIT; |
James Dong | e468ac5 | 2011-02-17 16:38:06 -0800 | [diff] [blame] | 226 | return c->takePicture(msgType); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // set preview/capture parameters - key/value pairs |
| 230 | status_t Camera::setParameters(const String8& params) |
| 231 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 232 | ALOGV("setParameters"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 233 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 234 | if (c == 0) return NO_INIT; |
| 235 | return c->setParameters(params); |
| 236 | } |
| 237 | |
| 238 | // get preview/capture parameters - key/value pairs |
| 239 | String8 Camera::getParameters() const |
| 240 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 241 | ALOGV("getParameters"); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 242 | String8 params; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 243 | sp <::android::hardware::ICamera> c = mCamera; |
Tony Guo | 3966c1f | 2023-09-07 03:46:05 +0000 | [diff] [blame] | 244 | if (c != 0) params = c->getParameters(); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 245 | return params; |
| 246 | } |
| 247 | |
| 248 | // send command to camera driver |
| 249 | status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) |
| 250 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 251 | ALOGV("sendCommand"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 252 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 253 | if (c == 0) return NO_INIT; |
| 254 | return c->sendCommand(cmd, arg1, arg2); |
| 255 | } |
| 256 | |
| 257 | void Camera::setListener(const sp<CameraListener>& listener) |
| 258 | { |
| 259 | Mutex::Autolock _l(mLock); |
| 260 | mListener = listener; |
| 261 | } |
| 262 | |
| 263 | void Camera::setPreviewCallbackFlags(int flag) |
| 264 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 265 | ALOGV("setPreviewCallbackFlags"); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 266 | sp <::android::hardware::ICamera> c = mCamera; |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 267 | if (c == 0) return; |
Tony Guo | 3966c1f | 2023-09-07 03:46:05 +0000 | [diff] [blame] | 268 | c->setPreviewCallbackFlag(flag); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 271 | status_t Camera::setPreviewCallbackTarget(const sp<SurfaceType>& target) { |
| 272 | sp<::android::hardware::ICamera> c = mCamera; |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 273 | if (c == 0) return NO_INIT; |
Carlos Martinez Romero | ca0ff17 | 2024-09-12 08:45:52 -0700 | [diff] [blame] | 274 | return c->setPreviewCallbackTarget(target); |
Eino-Ville Talvala | 3ee3550 | 2013-04-02 15:45:11 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 277 | status_t Camera::setAudioRestriction(int32_t mode) |
Yin-Chia Yeh | dba0323 | 2019-08-19 15:54:28 -0700 | [diff] [blame] | 278 | { |
| 279 | sp <::android::hardware::ICamera> c = mCamera; |
| 280 | if (c == 0) return NO_INIT; |
| 281 | return c->setAudioRestriction(mode); |
| 282 | } |
| 283 | |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 284 | int32_t Camera::getGlobalAudioRestriction() |
| 285 | { |
| 286 | sp <::android::hardware::ICamera> c = mCamera; |
| 287 | if (c == 0) return NO_INIT; |
| 288 | return c->getGlobalAudioRestriction(); |
| 289 | } |
| 290 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 291 | // callback from camera service |
| 292 | void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) |
| 293 | { |
Igor Murashkin | c073ba5 | 2013-02-26 14:32:34 -0800 | [diff] [blame] | 294 | return CameraBaseT::notifyCallback(msgType, ext1, ext2); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | // callback from camera service when frame or image is ready |
Wu-cheng Li | 57c8618 | 2011-07-30 05:00:37 +0800 | [diff] [blame] | 298 | void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, |
| 299 | camera_frame_metadata_t *metadata) |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 300 | { |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 301 | sp<CameraListener> listener; |
| 302 | { |
| 303 | Mutex::Autolock _l(mLock); |
| 304 | listener = mListener; |
| 305 | } |
| 306 | if (listener != NULL) { |
| 307 | listener->postData(msgType, dataPtr, metadata); |
| 308 | } |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | // callback from camera service when timestamped frame is ready |
| 312 | void Camera::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) |
| 313 | { |
Igor Murashkin | fa4cf9d | 2013-03-04 16:14:23 -0800 | [diff] [blame] | 314 | sp<CameraListener> listener; |
| 315 | { |
| 316 | Mutex::Autolock _l(mLock); |
| 317 | listener = mListener; |
| 318 | } |
| 319 | |
| 320 | if (listener != NULL) { |
| 321 | listener->postDataTimestamp(timestamp, msgType, dataPtr); |
| 322 | } else { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 323 | ALOGW("No listener was set. Drop a recording frame."); |
James Dong | c42478e | 2010-11-15 10:38:37 -0800 | [diff] [blame] | 324 | releaseRecordingFrame(dataPtr); |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 328 | void Camera::recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle) |
| 329 | { |
Chien-Yu Chen | 2d13b1d | 2016-04-28 12:11:20 -0700 | [diff] [blame] | 330 | sp<CameraListener> listener; |
| 331 | { |
| 332 | Mutex::Autolock _l(mLock); |
| 333 | listener = mListener; |
| 334 | } |
| 335 | |
| 336 | if (listener != NULL) { |
| 337 | listener->postRecordingFrameHandleTimestamp(timestamp, handle); |
| 338 | } else { |
| 339 | ALOGW("No listener was set. Drop a recording frame."); |
| 340 | releaseRecordingFrameHandle(handle); |
| 341 | } |
| 342 | } |
| 343 | |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 344 | void Camera::recordingFrameHandleCallbackTimestampBatch( |
| 345 | const std::vector<nsecs_t>& timestamps, |
| 346 | const std::vector<native_handle_t*>& handles) |
| 347 | { |
Yin-Chia Yeh | b5df547 | 2017-03-20 19:32:19 -0700 | [diff] [blame] | 348 | sp<CameraListener> listener; |
| 349 | { |
| 350 | Mutex::Autolock _l(mLock); |
| 351 | listener = mListener; |
| 352 | } |
| 353 | |
| 354 | if (listener != NULL) { |
| 355 | listener->postRecordingFrameHandleTimestampBatch(timestamps, handles); |
| 356 | } else { |
| 357 | ALOGW("No listener was set. Drop a batch of recording frames."); |
| 358 | releaseRecordingFrameHandleBatch(handles); |
| 359 | } |
| 360 | } |
| 361 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 362 | sp<ICameraRecordingProxy> Camera::getRecordingProxy() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 363 | ALOGV("getProxy"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 364 | return new RecordingProxy(this); |
| 365 | } |
| 366 | |
Eino-Ville Talvala | b8ed8ef | 2020-06-22 16:59:48 -0700 | [diff] [blame] | 367 | status_t Camera::RecordingProxy::startRecording() |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 368 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 369 | ALOGV("RecordingProxy::startRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 370 | mCamera->reconnect(); |
| 371 | return mCamera->startRecording(); |
| 372 | } |
| 373 | |
| 374 | void Camera::RecordingProxy::stopRecording() |
| 375 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 376 | ALOGV("RecordingProxy::stopRecording"); |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 377 | mCamera->stopRecording(); |
| 378 | } |
| 379 | |
Wu-cheng Li | 4ca2c7c | 2011-06-01 17:22:24 +0800 | [diff] [blame] | 380 | Camera::RecordingProxy::RecordingProxy(const sp<Camera>& camera) |
| 381 | { |
| 382 | mCamera = camera; |
| 383 | } |
| 384 | |
Mathias Agopian | 3cf6135 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 385 | }; // namespace android |