blob: 84d1d934e19fe2e8a4c1dd6b28768c84f18ed76e [file] [log] [blame]
Mathias Agopian3cf61352010-02-09 17:46:37 -08001/*
2**
3** Copyright (C) 2008, The Android Open Source Project
Mathias Agopian3cf61352010-02-09 17:46:37 -08004**
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 Talvalaceb388d2013-02-19 10:40:14 -080022#include <utils/String16.h>
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +080023#include <binder/IPCThreadState.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080024#include <binder/IServiceManager.h>
25#include <binder/IMemory.h>
26
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080027#include <Camera.h>
28#include <ICameraRecordingProxyListener.h>
29#include <android/hardware/ICameraService.h>
30#include <android/hardware/ICamera.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080031
Andy McFadden8ba01022012-12-18 09:46:54 -080032#include <gui/IGraphicBufferProducer.h>
Mathias Agopiandf712ea2012-02-25 18:48:35 -080033#include <gui/Surface.h>
Mathias Agopian3cf61352010-02-09 17:46:37 -080034
35namespace android {
36
Igor Murashkinc073ba52013-02-26 14:32:34 -080037Camera::Camera(int cameraId)
38 : CameraBase(cameraId)
Mathias Agopian3cf61352010-02-09 17:46:37 -080039{
Mathias Agopian3cf61352010-02-09 17:46:37 -080040}
41
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070042CameraTraits<Camera>::TCamConnectService CameraTraits<Camera>::fnConnectService =
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080043 &::android::hardware::ICameraService::connect;
Ruben Brunk0f61d8f2013-08-08 13:07:18 -070044
Mathias Agopian3cf61352010-02-09 17:46:37 -080045// construct a camera client from an existing camera remote
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080046sp<Camera> Camera::create(const sp<::android::hardware::ICamera>& camera)
Mathias Agopian3cf61352010-02-09 17:46:37 -080047{
Steve Block3856b092011-10-20 11:56:00 +010048 ALOGV("create");
Mathias Agopian3cf61352010-02-09 17:46:37 -080049 if (camera == 0) {
Steve Block29357bc2012-01-06 19:20:56 +000050 ALOGE("camera remote is a NULL pointer");
Mathias Agopian3cf61352010-02-09 17:46:37 -080051 return 0;
52 }
53
Igor Murashkinc073ba52013-02-26 14:32:34 -080054 sp<Camera> c = new Camera(-1);
Mathias Agopian3cf61352010-02-09 17:46:37 -080055 if (camera->connect(c) == NO_ERROR) {
56 c->mStatus = NO_ERROR;
57 c->mCamera = camera;
Marco Nelissen06b46062014-11-14 07:58:25 -080058 IInterface::asBinder(camera)->linkToDeath(c);
Wu-cheng Li627baac2011-01-04 20:00:55 +080059 return c;
Mathias Agopian3cf61352010-02-09 17:46:37 -080060 }
Wu-cheng Li627baac2011-01-04 20:00:55 +080061 return 0;
Mathias Agopian3cf61352010-02-09 17:46:37 -080062}
63
Mathias Agopian3cf61352010-02-09 17:46:37 -080064Camera::~Camera()
65{
Chih-Chung Changd06618e2010-05-13 15:14:24 +080066 // We don't need to call disconnect() here because if the CameraService
67 // thinks we are the owner of the hardware, it will hold a (strong)
68 // reference to us, and we can't possibly be here. We also don't want to
69 // call disconnect() here if we are in the same process as mediaserver,
70 // because we may be invoked by CameraService::Client::connect() and will
71 // deadlock if we call any method of ICamera here.
Mathias Agopian3cf61352010-02-09 17:46:37 -080072}
73
Svetoslav Ganov280405a2015-05-12 02:19:27 +000074sp<Camera> Camera::connect(int cameraId, const String16& clientPackageName,
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080075 int clientUid, int clientPid)
Mathias Agopian3cf61352010-02-09 17:46:37 -080076{
Chien-Yu Chen98a668f2015-12-18 14:10:33 -080077 return CameraBaseT::connect(cameraId, clientPackageName, clientUid, clientPid);
Mathias Agopian3cf61352010-02-09 17:46:37 -080078}
79
Zhijun Heb10cdad2014-06-16 16:38:35 -070080status_t Camera::connectLegacy(int cameraId, int halVersion,
Svetoslav Ganov280405a2015-05-12 02:19:27 +000081 const String16& clientPackageName,
Zhijun Heb10cdad2014-06-16 16:38:35 -070082 int clientUid,
83 sp<Camera>& camera)
84{
85 ALOGV("%s: connect legacy camera device", __FUNCTION__);
86 sp<Camera> c = new Camera(cameraId);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080087 sp<::android::hardware::ICameraClient> cl = c;
Zhijun Heb10cdad2014-06-16 16:38:35 -070088 status_t status = NO_ERROR;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080089 const sp<::android::hardware::ICameraService>& cs = CameraBaseT::getCameraService();
Zhijun Heb10cdad2014-06-16 16:38:35 -070090
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080091 binder::Status ret;
92 if (cs != nullptr) {
93 ret = cs.get()->connectLegacy(cl, cameraId, halVersion, clientPackageName,
94 clientUid, /*out*/&(c->mCamera));
Zhijun Heb10cdad2014-06-16 16:38:35 -070095 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080096 if (ret.isOk() && c->mCamera != nullptr) {
Marco Nelissen06b46062014-11-14 07:58:25 -080097 IInterface::asBinder(c->mCamera)->linkToDeath(c);
Zhijun Heb10cdad2014-06-16 16:38:35 -070098 c->mStatus = NO_ERROR;
99 camera = c;
100 } else {
Eino-Ville Talvala3525dd92016-03-20 18:04:09 -0700101 switch(ret.serviceSpecificErrorCode()) {
102 case hardware::ICameraService::ERROR_DISCONNECTED:
103 status = -ENODEV;
104 break;
105 case hardware::ICameraService::ERROR_CAMERA_IN_USE:
106 status = -EBUSY;
107 break;
108 case hardware::ICameraService::ERROR_INVALID_OPERATION:
109 status = -EINVAL;
110 break;
111 case hardware::ICameraService::ERROR_MAX_CAMERAS_IN_USE:
112 status = -EUSERS;
113 break;
114 case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT:
115 status = BAD_VALUE;
116 break;
117 case hardware::ICameraService::ERROR_DEPRECATED_HAL:
118 status = -EOPNOTSUPP;
119 break;
120 case hardware::ICameraService::ERROR_DISABLED:
121 status = -EACCES;
122 break;
123 case hardware::ICameraService::ERROR_PERMISSION_DENIED:
124 status = PERMISSION_DENIED;
125 break;
126 default:
127 status = -EINVAL;
128 ALOGW("An error occurred while connecting to camera %d: %s", cameraId,
129 (cs != nullptr) ? "Service not available" : ret.toString8().string());
130 break;
131 }
Zhijun Heb10cdad2014-06-16 16:38:35 -0700132 c.clear();
133 }
134 return status;
135}
136
Mathias Agopian3cf61352010-02-09 17:46:37 -0800137status_t Camera::reconnect()
138{
Steve Block3856b092011-10-20 11:56:00 +0100139 ALOGV("reconnect");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800140 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800141 if (c == 0) return NO_INIT;
142 return c->connect(this);
143}
144
Mathias Agopian3cf61352010-02-09 17:46:37 -0800145status_t Camera::lock()
146{
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800147 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800148 if (c == 0) return NO_INIT;
149 return c->lock();
150}
151
152status_t Camera::unlock()
153{
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800154 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800155 if (c == 0) return NO_INIT;
156 return c->unlock();
157}
158
Andy McFadden8ba01022012-12-18 09:46:54 -0800159// pass the buffered IGraphicBufferProducer to the camera service
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700160status_t Camera::setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)
Jamie Gennisbfa33aa2010-12-20 11:51:31 -0800161{
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700162 ALOGV("setPreviewTarget(%p)", bufferProducer.get());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800163 sp <::android::hardware::ICamera> c = mCamera;
Jamie Gennisbfa33aa2010-12-20 11:51:31 -0800164 if (c == 0) return NO_INIT;
Mathias Agopian99617ad2013-03-12 18:42:23 -0700165 ALOGD_IF(bufferProducer == 0, "app passed NULL surface");
Eino-Ville Talvala1ce7c342013-08-21 13:57:21 -0700166 return c->setPreviewTarget(bufferProducer);
Jamie Gennisbfa33aa2010-12-20 11:51:31 -0800167}
168
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800169status_t Camera::setVideoTarget(const sp<IGraphicBufferProducer>& bufferProducer)
170{
171 ALOGV("setVideoTarget(%p)", bufferProducer.get());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800172 sp <::android::hardware::ICamera> c = mCamera;
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800173 if (c == 0) return NO_INIT;
174 ALOGD_IF(bufferProducer == 0, "app passed NULL video surface");
175 return c->setVideoTarget(bufferProducer);
176}
177
Mathias Agopian3cf61352010-02-09 17:46:37 -0800178// start preview mode
179status_t Camera::startPreview()
180{
Steve Block3856b092011-10-20 11:56:00 +0100181 ALOGV("startPreview");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800182 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800183 if (c == 0) return NO_INIT;
184 return c->startPreview();
185}
186
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800187status_t Camera::setVideoBufferMode(int32_t videoBufferMode)
James Donge2ad6732010-10-18 20:42:51 -0700188{
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800189 ALOGV("setVideoBufferMode: %d", videoBufferMode);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800190 sp <::android::hardware::ICamera> c = mCamera;
James Donge2ad6732010-10-18 20:42:51 -0700191 if (c == 0) return NO_INIT;
Chien-Yu Chen8cca0752015-11-13 15:28:48 -0800192 return c->setVideoBufferMode(videoBufferMode);
James Donge2ad6732010-10-18 20:42:51 -0700193}
194
Eino-Ville Talvala4b820b02013-08-21 14:39:05 -0700195// start recording mode, must call setPreviewTarget first
Mathias Agopian3cf61352010-02-09 17:46:37 -0800196status_t Camera::startRecording()
197{
Steve Block3856b092011-10-20 11:56:00 +0100198 ALOGV("startRecording");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800199 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800200 if (c == 0) return NO_INIT;
201 return c->startRecording();
202}
203
204// stop preview mode
205void Camera::stopPreview()
206{
Steve Block3856b092011-10-20 11:56:00 +0100207 ALOGV("stopPreview");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800208 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800209 if (c == 0) return;
210 c->stopPreview();
211}
212
213// stop recording mode
214void Camera::stopRecording()
215{
Steve Block3856b092011-10-20 11:56:00 +0100216 ALOGV("stopRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800217 {
218 Mutex::Autolock _l(mLock);
219 mRecordingProxyListener.clear();
220 }
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800221 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800222 if (c == 0) return;
223 c->stopRecording();
224}
225
226// release a recording frame
227void Camera::releaseRecordingFrame(const sp<IMemory>& mem)
228{
Steve Block3856b092011-10-20 11:56:00 +0100229 ALOGV("releaseRecordingFrame");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800230 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800231 if (c == 0) return;
232 c->releaseRecordingFrame(mem);
233}
234
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700235void Camera::releaseRecordingFrameHandle(native_handle_t* handle)
236{
237 ALOGV("releaseRecordingFrameHandle");
238 sp <::android::hardware::ICamera> c = mCamera;
239 if (c == 0) return;
240 c->releaseRecordingFrameHandle(handle);
241}
242
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700243void Camera::releaseRecordingFrameHandleBatch(
244 const std::vector<native_handle_t*> handles) {
245 ALOGV("releaseRecordingFrameHandleBatch");
246 sp <::android::hardware::ICamera> c = mCamera;
247 if (c == 0) return;
248 c->releaseRecordingFrameHandleBatch(handles);
249}
250
Mathias Agopian3cf61352010-02-09 17:46:37 -0800251// get preview state
252bool Camera::previewEnabled()
253{
Steve Block3856b092011-10-20 11:56:00 +0100254 ALOGV("previewEnabled");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800255 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800256 if (c == 0) return false;
257 return c->previewEnabled();
258}
259
260// get recording state
261bool Camera::recordingEnabled()
262{
Steve Block3856b092011-10-20 11:56:00 +0100263 ALOGV("recordingEnabled");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800264 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800265 if (c == 0) return false;
266 return c->recordingEnabled();
267}
268
269status_t Camera::autoFocus()
270{
Steve Block3856b092011-10-20 11:56:00 +0100271 ALOGV("autoFocus");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800272 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800273 if (c == 0) return NO_INIT;
274 return c->autoFocus();
275}
276
277status_t Camera::cancelAutoFocus()
278{
Steve Block3856b092011-10-20 11:56:00 +0100279 ALOGV("cancelAutoFocus");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800280 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800281 if (c == 0) return NO_INIT;
282 return c->cancelAutoFocus();
283}
284
285// take a picture
James Donge468ac52011-02-17 16:38:06 -0800286status_t Camera::takePicture(int msgType)
Mathias Agopian3cf61352010-02-09 17:46:37 -0800287{
Steve Block3856b092011-10-20 11:56:00 +0100288 ALOGV("takePicture: 0x%x", msgType);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800289 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800290 if (c == 0) return NO_INIT;
James Donge468ac52011-02-17 16:38:06 -0800291 return c->takePicture(msgType);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800292}
293
294// set preview/capture parameters - key/value pairs
295status_t Camera::setParameters(const String8& params)
296{
Steve Block3856b092011-10-20 11:56:00 +0100297 ALOGV("setParameters");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800298 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800299 if (c == 0) return NO_INIT;
300 return c->setParameters(params);
301}
302
303// get preview/capture parameters - key/value pairs
304String8 Camera::getParameters() const
305{
Steve Block3856b092011-10-20 11:56:00 +0100306 ALOGV("getParameters");
Mathias Agopian3cf61352010-02-09 17:46:37 -0800307 String8 params;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800308 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800309 if (c != 0) params = mCamera->getParameters();
310 return params;
311}
312
313// send command to camera driver
314status_t Camera::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2)
315{
Steve Block3856b092011-10-20 11:56:00 +0100316 ALOGV("sendCommand");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800317 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800318 if (c == 0) return NO_INIT;
319 return c->sendCommand(cmd, arg1, arg2);
320}
321
322void Camera::setListener(const sp<CameraListener>& listener)
323{
324 Mutex::Autolock _l(mLock);
325 mListener = listener;
326}
327
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800328void Camera::setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener)
329{
330 Mutex::Autolock _l(mLock);
331 mRecordingProxyListener = listener;
332}
333
Mathias Agopian3cf61352010-02-09 17:46:37 -0800334void Camera::setPreviewCallbackFlags(int flag)
335{
Steve Block3856b092011-10-20 11:56:00 +0100336 ALOGV("setPreviewCallbackFlags");
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800337 sp <::android::hardware::ICamera> c = mCamera;
Mathias Agopian3cf61352010-02-09 17:46:37 -0800338 if (c == 0) return;
339 mCamera->setPreviewCallbackFlag(flag);
340}
341
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700342status_t Camera::setPreviewCallbackTarget(
343 const sp<IGraphicBufferProducer>& callbackProducer)
344{
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800345 sp <::android::hardware::ICamera> c = mCamera;
Eino-Ville Talvala3ee35502013-04-02 15:45:11 -0700346 if (c == 0) return NO_INIT;
347 return c->setPreviewCallbackTarget(callbackProducer);
348}
349
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -0700350status_t Camera::setAudioRestriction(int32_t mode)
Yin-Chia Yehdba03232019-08-19 15:54:28 -0700351{
352 sp <::android::hardware::ICamera> c = mCamera;
353 if (c == 0) return NO_INIT;
354 return c->setAudioRestriction(mode);
355}
356
Yin-Chia Yehcfab4e12019-09-09 13:08:28 -0700357int32_t Camera::getGlobalAudioRestriction()
358{
359 sp <::android::hardware::ICamera> c = mCamera;
360 if (c == 0) return NO_INIT;
361 return c->getGlobalAudioRestriction();
362}
363
Mathias Agopian3cf61352010-02-09 17:46:37 -0800364// callback from camera service
365void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
366{
Igor Murashkinc073ba52013-02-26 14:32:34 -0800367 return CameraBaseT::notifyCallback(msgType, ext1, ext2);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800368}
369
370// callback from camera service when frame or image is ready
Wu-cheng Li57c86182011-07-30 05:00:37 +0800371void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
372 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -0800373{
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800374 sp<CameraListener> listener;
375 {
376 Mutex::Autolock _l(mLock);
377 listener = mListener;
378 }
379 if (listener != NULL) {
380 listener->postData(msgType, dataPtr, metadata);
381 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800382}
383
384// callback from camera service when timestamped frame is ready
385void Camera::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
386{
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800387 // If recording proxy listener is registered, forward the frame and return.
388 // The other listener (mListener) is ignored because the receiver needs to
389 // call releaseRecordingFrame.
390 sp<ICameraRecordingProxyListener> proxylistener;
391 {
392 Mutex::Autolock _l(mLock);
393 proxylistener = mRecordingProxyListener;
394 }
395 if (proxylistener != NULL) {
396 proxylistener->dataCallbackTimestamp(timestamp, msgType, dataPtr);
397 return;
398 }
399
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800400 sp<CameraListener> listener;
401 {
402 Mutex::Autolock _l(mLock);
403 listener = mListener;
404 }
405
406 if (listener != NULL) {
407 listener->postDataTimestamp(timestamp, msgType, dataPtr);
408 } else {
Steve Block5ff1dd52012-01-05 23:22:43 +0000409 ALOGW("No listener was set. Drop a recording frame.");
James Dongc42478e2010-11-15 10:38:37 -0800410 releaseRecordingFrame(dataPtr);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800411 }
412}
413
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700414void Camera::recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle)
415{
416 // If recording proxy listener is registered, forward the frame and return.
417 // The other listener (mListener) is ignored because the receiver needs to
418 // call releaseRecordingFrameHandle.
419 sp<ICameraRecordingProxyListener> proxylistener;
420 {
421 Mutex::Autolock _l(mLock);
422 proxylistener = mRecordingProxyListener;
423 }
424 if (proxylistener != NULL) {
425 proxylistener->recordingFrameHandleCallbackTimestamp(timestamp, handle);
426 return;
427 }
428
429 sp<CameraListener> listener;
430 {
431 Mutex::Autolock _l(mLock);
432 listener = mListener;
433 }
434
435 if (listener != NULL) {
436 listener->postRecordingFrameHandleTimestamp(timestamp, handle);
437 } else {
438 ALOGW("No listener was set. Drop a recording frame.");
439 releaseRecordingFrameHandle(handle);
440 }
441}
442
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700443void Camera::recordingFrameHandleCallbackTimestampBatch(
444 const std::vector<nsecs_t>& timestamps,
445 const std::vector<native_handle_t*>& handles)
446{
447 // If recording proxy listener is registered, forward the frame and return.
448 // The other listener (mListener) is ignored because the receiver needs to
449 // call releaseRecordingFrameHandle.
450 sp<ICameraRecordingProxyListener> proxylistener;
451 {
452 Mutex::Autolock _l(mLock);
453 proxylistener = mRecordingProxyListener;
454 }
455 if (proxylistener != NULL) {
456 proxylistener->recordingFrameHandleCallbackTimestampBatch(timestamps, handles);
457 return;
458 }
459
460 sp<CameraListener> listener;
461 {
462 Mutex::Autolock _l(mLock);
463 listener = mListener;
464 }
465
466 if (listener != NULL) {
467 listener->postRecordingFrameHandleTimestampBatch(timestamps, handles);
468 } else {
469 ALOGW("No listener was set. Drop a batch of recording frames.");
470 releaseRecordingFrameHandleBatch(handles);
471 }
472}
473
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800474sp<ICameraRecordingProxy> Camera::getRecordingProxy() {
Steve Block3856b092011-10-20 11:56:00 +0100475 ALOGV("getProxy");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800476 return new RecordingProxy(this);
477}
478
479status_t Camera::RecordingProxy::startRecording(const sp<ICameraRecordingProxyListener>& listener)
480{
Steve Block3856b092011-10-20 11:56:00 +0100481 ALOGV("RecordingProxy::startRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800482 mCamera->setRecordingProxyListener(listener);
483 mCamera->reconnect();
484 return mCamera->startRecording();
485}
486
487void Camera::RecordingProxy::stopRecording()
488{
Steve Block3856b092011-10-20 11:56:00 +0100489 ALOGV("RecordingProxy::stopRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800490 mCamera->stopRecording();
491}
492
493void Camera::RecordingProxy::releaseRecordingFrame(const sp<IMemory>& mem)
494{
Steve Block3856b092011-10-20 11:56:00 +0100495 ALOGV("RecordingProxy::releaseRecordingFrame");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800496 mCamera->releaseRecordingFrame(mem);
497}
498
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700499void Camera::RecordingProxy::releaseRecordingFrameHandle(native_handle_t* handle) {
500 ALOGV("RecordingProxy::releaseRecordingFrameHandle");
501 mCamera->releaseRecordingFrameHandle(handle);
502}
503
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700504void Camera::RecordingProxy::releaseRecordingFrameHandleBatch(
505 const std::vector<native_handle_t*>& handles) {
506 ALOGV("RecordingProxy::releaseRecordingFrameHandleBatch");
507 mCamera->releaseRecordingFrameHandleBatch(handles);
508}
509
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800510Camera::RecordingProxy::RecordingProxy(const sp<Camera>& camera)
511{
512 mCamera = camera;
513}
514
Mathias Agopian3cf61352010-02-09 17:46:37 -0800515}; // namespace android