blob: c6c35efcff067e7dd7908740a69e386bf0cf4886 [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
Mathias Agopian3cf61352010-02-09 17:46:37 -0800350// callback from camera service
351void Camera::notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2)
352{
Igor Murashkinc073ba52013-02-26 14:32:34 -0800353 return CameraBaseT::notifyCallback(msgType, ext1, ext2);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800354}
355
356// callback from camera service when frame or image is ready
Wu-cheng Li57c86182011-07-30 05:00:37 +0800357void Camera::dataCallback(int32_t msgType, const sp<IMemory>& dataPtr,
358 camera_frame_metadata_t *metadata)
Mathias Agopian3cf61352010-02-09 17:46:37 -0800359{
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800360 sp<CameraListener> listener;
361 {
362 Mutex::Autolock _l(mLock);
363 listener = mListener;
364 }
365 if (listener != NULL) {
366 listener->postData(msgType, dataPtr, metadata);
367 }
Mathias Agopian3cf61352010-02-09 17:46:37 -0800368}
369
370// callback from camera service when timestamped frame is ready
371void Camera::dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr)
372{
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800373 // If recording proxy listener is registered, forward the frame and return.
374 // The other listener (mListener) is ignored because the receiver needs to
375 // call releaseRecordingFrame.
376 sp<ICameraRecordingProxyListener> proxylistener;
377 {
378 Mutex::Autolock _l(mLock);
379 proxylistener = mRecordingProxyListener;
380 }
381 if (proxylistener != NULL) {
382 proxylistener->dataCallbackTimestamp(timestamp, msgType, dataPtr);
383 return;
384 }
385
Igor Murashkinfa4cf9d2013-03-04 16:14:23 -0800386 sp<CameraListener> listener;
387 {
388 Mutex::Autolock _l(mLock);
389 listener = mListener;
390 }
391
392 if (listener != NULL) {
393 listener->postDataTimestamp(timestamp, msgType, dataPtr);
394 } else {
Steve Block5ff1dd52012-01-05 23:22:43 +0000395 ALOGW("No listener was set. Drop a recording frame.");
James Dongc42478e2010-11-15 10:38:37 -0800396 releaseRecordingFrame(dataPtr);
Mathias Agopian3cf61352010-02-09 17:46:37 -0800397 }
398}
399
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700400void Camera::recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle)
401{
402 // If recording proxy listener is registered, forward the frame and return.
403 // The other listener (mListener) is ignored because the receiver needs to
404 // call releaseRecordingFrameHandle.
405 sp<ICameraRecordingProxyListener> proxylistener;
406 {
407 Mutex::Autolock _l(mLock);
408 proxylistener = mRecordingProxyListener;
409 }
410 if (proxylistener != NULL) {
411 proxylistener->recordingFrameHandleCallbackTimestamp(timestamp, handle);
412 return;
413 }
414
415 sp<CameraListener> listener;
416 {
417 Mutex::Autolock _l(mLock);
418 listener = mListener;
419 }
420
421 if (listener != NULL) {
422 listener->postRecordingFrameHandleTimestamp(timestamp, handle);
423 } else {
424 ALOGW("No listener was set. Drop a recording frame.");
425 releaseRecordingFrameHandle(handle);
426 }
427}
428
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700429void Camera::recordingFrameHandleCallbackTimestampBatch(
430 const std::vector<nsecs_t>& timestamps,
431 const std::vector<native_handle_t*>& handles)
432{
433 // If recording proxy listener is registered, forward the frame and return.
434 // The other listener (mListener) is ignored because the receiver needs to
435 // call releaseRecordingFrameHandle.
436 sp<ICameraRecordingProxyListener> proxylistener;
437 {
438 Mutex::Autolock _l(mLock);
439 proxylistener = mRecordingProxyListener;
440 }
441 if (proxylistener != NULL) {
442 proxylistener->recordingFrameHandleCallbackTimestampBatch(timestamps, handles);
443 return;
444 }
445
446 sp<CameraListener> listener;
447 {
448 Mutex::Autolock _l(mLock);
449 listener = mListener;
450 }
451
452 if (listener != NULL) {
453 listener->postRecordingFrameHandleTimestampBatch(timestamps, handles);
454 } else {
455 ALOGW("No listener was set. Drop a batch of recording frames.");
456 releaseRecordingFrameHandleBatch(handles);
457 }
458}
459
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800460sp<ICameraRecordingProxy> Camera::getRecordingProxy() {
Steve Block3856b092011-10-20 11:56:00 +0100461 ALOGV("getProxy");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800462 return new RecordingProxy(this);
463}
464
465status_t Camera::RecordingProxy::startRecording(const sp<ICameraRecordingProxyListener>& listener)
466{
Steve Block3856b092011-10-20 11:56:00 +0100467 ALOGV("RecordingProxy::startRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800468 mCamera->setRecordingProxyListener(listener);
469 mCamera->reconnect();
470 return mCamera->startRecording();
471}
472
473void Camera::RecordingProxy::stopRecording()
474{
Steve Block3856b092011-10-20 11:56:00 +0100475 ALOGV("RecordingProxy::stopRecording");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800476 mCamera->stopRecording();
477}
478
479void Camera::RecordingProxy::releaseRecordingFrame(const sp<IMemory>& mem)
480{
Steve Block3856b092011-10-20 11:56:00 +0100481 ALOGV("RecordingProxy::releaseRecordingFrame");
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800482 mCamera->releaseRecordingFrame(mem);
483}
484
Chien-Yu Chen2d13b1d2016-04-28 12:11:20 -0700485void Camera::RecordingProxy::releaseRecordingFrameHandle(native_handle_t* handle) {
486 ALOGV("RecordingProxy::releaseRecordingFrameHandle");
487 mCamera->releaseRecordingFrameHandle(handle);
488}
489
Yin-Chia Yehb5df5472017-03-20 19:32:19 -0700490void Camera::RecordingProxy::releaseRecordingFrameHandleBatch(
491 const std::vector<native_handle_t*>& handles) {
492 ALOGV("RecordingProxy::releaseRecordingFrameHandleBatch");
493 mCamera->releaseRecordingFrameHandleBatch(handles);
494}
495
Wu-cheng Li4ca2c7c2011-06-01 17:22:24 +0800496Camera::RecordingProxy::RecordingProxy(const sp<Camera>& camera)
497{
498 mCamera = camera;
499}
500
Mathias Agopian3cf61352010-02-09 17:46:37 -0800501}; // namespace android