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