blob: 205ef608c617aba0250853448a366512d9666518 [file] [log] [blame]
Sam Protsenkoce268502023-09-08 19:45:36 -05001/*
2**
3** Copyright 2013, Samsung Electronics Co. LTD
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 "ExynosCameraInterface"
20#include <cutils/log.h>
21
22#include "ExynosCameraInterface.h"
23#include "ExynosCameraAutoTimer.h"
24
25#ifdef SAMSUNG_TN_FEATURE
26#include "SecCameraVendorTags.h"
27#endif
28
29namespace android {
30
31static int HAL_camera_device_open(
32 const struct hw_module_t* module,
33 const char *id,
34 struct hw_device_t** device)
35{
36 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
37
38 int cameraId = atoi(id);
39 CameraMetadata metadata;
40 camera_metadata_entry flashAvailable;
41 bool hasFlash = false;
42 FILE *fp = NULL;
43 char flashFilePath[100] = {'\0',};
44
45#ifdef BOARD_FRONT_CAMERA_ONLY_USE
46 cameraId += 1;
47#endif
48
49#ifdef BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA
50 if (cameraId == 0) {
51 return HAL_ext_camera_device_open_wrapper(module, id, device);
52 }
53#endif
54
55#ifdef BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA
56 if (cameraId == 1) {
57 return HAL_ext_camera_device_open_wrapper(module, id, device);
58 }
59#endif
60
61#if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA)
62#else
63 enum CAMERA_STATE state;
64
65 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
66
67#ifdef BOARD_FRONT_CAMERA_ONLY_USE
68 if (cameraId < 1 || cameraId > HAL_getNumberOfCameras())
69#else
70 if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras())
71#endif
72 {
73 ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id);
74 return -EINVAL;
75 }
76
77#ifdef FRONT_1_CAMERA_SENSOR_NAME
78 /*
79 * if it use dual camera.
80 * just calibrate it as proper cameraId_1.
81 */
82 int cameraId_0 = -1;
83 int cameraId_1 = -1;
84
85 getDualCameraId(&cameraId_0, &cameraId_1);
86
87 if (0 < cameraId_1) {
88 if (CAMERA_ID_BACK_1 <= cameraId) {
89 ALOGD("DEBUG(%s[%d]):calibrate camera ID(%d) -> camera ID(%d) for dual camera",
90 __FUNCTION__, __LINE__, cameraId, cameraId_1);
91 cameraId = cameraId_1;
92 }
93 }
94#endif
95
96 state = CAMERA_OPENED;
97 if (check_camera_state(state, cameraId) == false) {
98 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state);
99 return -EUSERS;
100 }
101
102#ifdef BOARD_FRONT_CAMERA_ONLY_USE
103 if ((unsigned int)cameraId <= (sizeof(sCameraInfo) / sizeof(sCameraInfo[0])))
104#else
105 if ((unsigned int)cameraId < (sizeof(sCameraInfo) / sizeof(sCameraInfo[0])))
106#endif
107 {
108 if (g_cam_device[cameraId]) {
109 ALOGE("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id);
110 *device = (hw_device_t *)g_cam_device[cameraId];
111 goto done;
112 }
113
114 g_cam_device[cameraId] = (camera_device_t *)malloc(sizeof(camera_device_t));
115 if (!g_cam_device[cameraId])
116 return -ENOMEM;
117
118 g_cam_openLock[cameraId].lock();
119 g_cam_device[cameraId]->common.tag = HARDWARE_DEVICE_TAG;
120 g_cam_device[cameraId]->common.version = 1;
121 g_cam_device[cameraId]->common.module = const_cast<hw_module_t *>(module);
122 g_cam_device[cameraId]->common.close = HAL_camera_device_close;
123
124 g_cam_device[cameraId]->ops = &camera_device_ops;
125
126 ALOGD("DEBUG(%s):open camera %s", __FUNCTION__, id);
127 g_cam_device[cameraId]->priv = new ExynosCamera(cameraId, g_cam_device[cameraId]);
128 *device = (hw_device_t *)g_cam_device[cameraId];
129 ALOGI("INFO(%s[%d]):camera(%d) out from new g_cam_device[%d]->priv()",
130 __FUNCTION__, __LINE__, cameraId, cameraId);
131
132 g_cam_openLock[cameraId].unlock();
133 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
134 } else {
135 ALOGE("DEBUG(%s):camera(%s) open fail - must front camera open first",
136 __FUNCTION__, id);
137 return -EINVAL;
138 }
139
140done:
141 cam_stateLock[cameraId].lock();
142 cam_state[cameraId] = state;
143 cam_stateLock[cameraId].unlock();
144
145 if (g_cam_info[cameraId]) {
146 metadata = g_cam_info[cameraId];
147 flashAvailable = metadata.find(ANDROID_FLASH_INFO_AVAILABLE);
148
149 if (flashAvailable.count == 1 && flashAvailable.data.u8[0] == 1) {
150 hasFlash = true;
151 } else {
152 hasFlash = false;
153 }
154 }
155
156 if(hasFlash && g_cam_torchEnabled[cameraId]) {
157 if (cameraId == CAMERA_ID_BACK) {
158 snprintf(flashFilePath, sizeof(flashFilePath), TORCH_REAR_FILE_PATH);
159 } else {
160 snprintf(flashFilePath, sizeof(flashFilePath), TORCH_FRONT_FILE_PATH);
161 }
162
163 fp = fopen(flashFilePath, "w+");
164
165 if (fp == NULL) {
166 ALOGE("ERR(%s[%d]):torch file open(%s) fail",
167 __FUNCTION__, __LINE__, flashFilePath);
168 } else {
169 fwrite("0", sizeof(char), 1, fp);
170 fflush(fp);
171 fclose(fp);
172
173 g_cam_torchEnabled[cameraId] = false;
174 }
175 }
176
177 if (g_callbacks) {
178 g_callbacks->torch_mode_status_change(g_callbacks, id, TORCH_MODE_STATUS_NOT_AVAILABLE);
179 ALOGI("INFO(%s[%d]):camera(%d) TORCH_MODE_STATUS_NOT_AVAILABLE", __FUNCTION__, __LINE__, cameraId);
180 }
181
182 ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId);
183#endif /* (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) */
184
185 return 0;
186}
187
188static int HAL_camera_device_close(struct hw_device_t* device)
189{
190 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
191
192 uint32_t cameraId = -1;
193 enum CAMERA_STATE state;
194 char camid[10];
195
196#if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA)
197#else
198 ALOGI("INFO(%s[%d]): in", __FUNCTION__, __LINE__);
199
200 if (device) {
201 camera_device_t *cam_device = (camera_device_t *)device;
202 cameraId = obj(cam_device)->getCameraId();
203
204 ALOGI("INFO(%s[%d]):camera(%d)", __FUNCTION__, __LINE__, cameraId);
205
206 state = CAMERA_CLOSED;
207 if (check_camera_state(state, cameraId) == false) {
208 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID",
209 __FUNCTION__, cameraId, state);
210 return -1;
211 }
212
213 g_cam_openLock[cameraId].lock();
214 ALOGI("INFO(%s[%d]):camera(%d) locked..", __FUNCTION__, __LINE__, cameraId);
215 g_cam_device[cameraId] = NULL;
216 g_cam_openLock[cameraId].unlock();
217 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
218
219 delete static_cast<ExynosCamera *>(cam_device->priv);
220 free(cam_device);
221
222 cam_stateLock[cameraId].lock();
223 cam_state[cameraId] = state;
224 cam_stateLock[cameraId].unlock();
225 ALOGI("INFO(%s[%d]):camera(%d)", __FUNCTION__, __LINE__, cameraId);
226 } else {
227 ALOGE("ERR(%s) invalid device", __FUNCTION__);
228 return -1;
229 }
230
231 /* Update torch status */
232 g_cam_torchEnabled[cameraId] = false;
233 snprintf(camid, sizeof(camid), "%d\n", cameraId);
234 if (g_callbacks) {
235 g_callbacks->torch_mode_status_change(g_callbacks, camid, TORCH_MODE_STATUS_AVAILABLE_OFF);
236 ALOGI("INFO(%s[%d]):camera(%d) TORCH_MODE_STATUS_AVAILABLE_OFF", __FUNCTION__, __LINE__, cameraId);
237 }
238 ALOGI("INFO(%s[%d]): out", __FUNCTION__, __LINE__);
239#endif /* (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA) */
240
241 return 0;
242}
243
244static int HAL_camera_device_set_preview_window(
245 struct camera_device *dev,
246 struct preview_stream_ops *buf)
247{
248 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
249
250 static int ret;
251 uint32_t cameraId = obj(dev)->getCameraId();
252
253 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
254 ret = obj(dev)->setPreviewWindow(buf);
255 ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId);
256 return ret;
257}
258
259static void HAL_camera_device_set_callbacks(struct camera_device *dev,
260 camera_notify_callback notify_cb,
261 camera_data_callback data_cb,
262 camera_data_timestamp_callback data_cb_timestamp,
263 camera_request_memory get_memory,
264 void* user)
265{
266 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
267
268 ALOGV("DEBUG(%s):", __FUNCTION__);
269 obj(dev)->setCallbacks(notify_cb, data_cb, data_cb_timestamp,
270 get_memory,
271 user);
272}
273
274static void HAL_camera_device_enable_msg_type(
275 struct camera_device *dev,
276 int32_t msg_type)
277{
278 ALOGV("DEBUG(%s):", __FUNCTION__);
279 obj(dev)->enableMsgType(msg_type);
280}
281
282static void HAL_camera_device_disable_msg_type(
283 struct camera_device *dev,
284 int32_t msg_type)
285{
286 ALOGV("DEBUG(%s):", __FUNCTION__);
287 obj(dev)->disableMsgType(msg_type);
288}
289
290static int HAL_camera_device_msg_type_enabled(
291 struct camera_device *dev,
292 int32_t msg_type)
293{
294 ALOGV("DEBUG(%s):", __FUNCTION__);
295 return obj(dev)->msgTypeEnabled(msg_type);
296}
297
298static int HAL_camera_device_start_preview(struct camera_device *dev)
299{
300 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
301
302 static int ret;
303 uint32_t cameraId = obj(dev)->getCameraId();
304 enum CAMERA_STATE state;
305
306 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
307
308 state = CAMERA_PREVIEW;
309 if (check_camera_state(state, cameraId) == false) {
310 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID",
311 __FUNCTION__, cameraId, state);
312 return -1;
313 }
314
315 g_cam_previewLock[cameraId].lock();
316
317#ifdef DUAL_CAMERA_SUPPORTED
318 if (cameraId != 0 && g_cam_device[0] != NULL
319 && cam_state[0] != CAMERA_NONE && cam_state[0] != CAMERA_CLOSED) {
320 ret = obj(dev)->setDualMode(true);
321 if (ret != NO_ERROR)
322 ALOGE("ERR(%s[%d]):camera(%d) set dual mode fail, ret(%d)",
323 __FUNCTION__, __LINE__, cameraId, ret);
324 else
325 ALOGI("INFO(%s[%d]):camera(%d) set dual mode)",
326 __FUNCTION__, __LINE__, cameraId);
327 }
328#endif
329
330 ret = obj(dev)->startPreview();
331 ALOGI("INFO(%s[%d]):camera(%d) out from startPreview()",
332 __FUNCTION__, __LINE__, cameraId);
333
334 g_cam_previewLock[cameraId].unlock();
335
336 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
337
338 if (ret == OK) {
339 cam_stateLock[cameraId].lock();
340 cam_state[cameraId] = state;
341 cam_stateLock[cameraId].unlock();
342 ALOGI("INFO(%s[%d]):camera(%d) out (startPreview succeeded)",
343 __FUNCTION__, __LINE__, cameraId);
344 } else {
345 ALOGI("INFO(%s[%d]):camera(%d) out (startPreview FAILED)",
346 __FUNCTION__, __LINE__, cameraId);
347 }
348 return ret;
349}
350
351static void HAL_camera_device_stop_preview(struct camera_device *dev)
352{
353 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
354
355 uint32_t cameraId = obj(dev)->getCameraId();
356 enum CAMERA_STATE state;
357
358 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
359/* HACK : If camera in recording state, */
360/* CameraService have to call the stop_recording before the stop_preview */
361#if 1
362 if (cam_state[cameraId] == CAMERA_RECORDING) {
363 ALOGE("ERR(%s[%d]):camera(%d) in RECORDING RUNNING state ---- INVALID ----",
364 __FUNCTION__, __LINE__, cameraId);
365 ALOGE("ERR(%s[%d]):camera(%d) The stop_recording must be called "
366 "before the stop_preview ---- INVALID ----",
367 __FUNCTION__, __LINE__, cameraId);
368 HAL_camera_device_stop_recording(dev);
369 ALOGE("ERR(%s[%d]):cameraId=%d out from stop_recording ---- INVALID ----",
370 __FUNCTION__, __LINE__, cameraId);
371
372 for (int i=0; i<30; i++) {
373 ALOGE("ERR(%s[%d]):camera(%d) The stop_recording must be called "
374 "before the stop_preview ---- INVALID ----",
375 __FUNCTION__, __LINE__, cameraId);
376 }
377 ALOGE("ERR(%s[%d]):camera(%d) sleep 500ms for ---- INVALID ---- state",
378 __FUNCTION__, __LINE__, cameraId);
379 usleep(500000); /* to notify, sleep 500ms */
380 }
381#endif
382 state = CAMERA_PREVIEWSTOPPED;
383 if (check_camera_state(state, cameraId) == false) {
384 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state);
385 return;
386 }
387
388 g_cam_previewLock[cameraId].lock();
389
390 obj(dev)->stopPreview();
391 ALOGI("INFO(%s[%d]):camera(%d) out from stopPreview()",
392 __FUNCTION__, __LINE__, cameraId);
393
394 g_cam_previewLock[cameraId].unlock();
395
396 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
397
398 cam_stateLock[cameraId].lock();
399 cam_state[cameraId] = state;
400 cam_stateLock[cameraId].unlock();
401 ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId);
402}
403
404static int HAL_camera_device_preview_enabled(struct camera_device *dev)
405{
406 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
407
408 ALOGV("DEBUG(%s):", __FUNCTION__);
409 return obj(dev)->previewEnabled();
410}
411
412static int HAL_camera_device_store_meta_data_in_buffers(
413 struct camera_device *dev,
414 int enable)
415{
416 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
417
418 ALOGV("DEBUG(%s):", __FUNCTION__);
419 return obj(dev)->storeMetaDataInBuffers(enable);
420}
421
422static int HAL_camera_device_start_recording(struct camera_device *dev)
423{
424 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
425
426 static int ret;
427 uint32_t cameraId = obj(dev)->getCameraId();
428 enum CAMERA_STATE state;
429
430 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
431
432 state = CAMERA_RECORDING;
433 if (check_camera_state(state, cameraId) == false) {
434 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID",
435 __FUNCTION__, cameraId, state);
436 return -1;
437 }
438
439 g_cam_recordingLock[cameraId].lock();
440
441 ret = obj(dev)->startRecording();
442 ALOGI("INFO(%s[%d]):camera(%d) out from startRecording()",
443 __FUNCTION__, __LINE__, cameraId);
444
445 g_cam_recordingLock[cameraId].unlock();
446
447 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
448
449 if (ret == OK) {
450 cam_stateLock[cameraId].lock();
451 cam_state[cameraId] = state;
452 cam_stateLock[cameraId].unlock();
453 ALOGI("INFO(%s[%d]):camera(%d) out (startRecording succeeded)",
454 __FUNCTION__, __LINE__, cameraId);
455 } else {
456 ALOGI("INFO(%s[%d]):camera(%d) out (startRecording FAILED)",
457 __FUNCTION__, __LINE__, cameraId);
458 }
459 return ret;
460}
461
462static void HAL_camera_device_stop_recording(struct camera_device *dev)
463{
464 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
465
466 uint32_t cameraId = obj(dev)->getCameraId();
467 enum CAMERA_STATE state;
468
469 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
470
471 state = CAMERA_RECORDINGSTOPPED;
472 if (check_camera_state(state, cameraId) == false) {
473 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID", __FUNCTION__, cameraId, state);
474 return;
475 }
476
477 g_cam_recordingLock[cameraId].lock();
478
479 obj(dev)->stopRecording();
480 ALOGI("INFO(%s[%d]):camera(%d) out from stopRecording()",
481 __FUNCTION__, __LINE__, cameraId);
482
483 g_cam_recordingLock[cameraId].unlock();
484
485 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
486
487 cam_stateLock[cameraId].lock();
488 cam_state[cameraId] = state;
489 cam_stateLock[cameraId].unlock();
490 ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId);
491}
492
493static int HAL_camera_device_recording_enabled(struct camera_device *dev)
494{
495 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
496
497 ALOGV("DEBUG(%s):", __FUNCTION__);
498 return obj(dev)->recordingEnabled();
499}
500
501static void HAL_camera_device_release_recording_frame(struct camera_device *dev,
502 const void *opaque)
503{
504 /* ExynosCameraAutoTimer autoTimer(__FUNCTION__); */
505
506 ALOGV("DEBUG(%s):", __FUNCTION__);
507 obj(dev)->releaseRecordingFrame(opaque);
508}
509
510static int HAL_camera_device_auto_focus(struct camera_device *dev)
511{
512 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
513
514 ALOGV("DEBUG(%s):", __FUNCTION__);
515 return obj(dev)->autoFocus();
516}
517
518static int HAL_camera_device_cancel_auto_focus(struct camera_device *dev)
519{
520 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
521
522 ALOGV("DEBUG(%s):", __FUNCTION__);
523 return obj(dev)->cancelAutoFocus();
524}
525
526static int HAL_camera_device_take_picture(struct camera_device *dev)
527{
528 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
529
530 ALOGV("DEBUG(%s):", __FUNCTION__);
531 return obj(dev)->takePicture();
532}
533
534static int HAL_camera_device_cancel_picture(struct camera_device *dev)
535{
536 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
537
538 ALOGV("DEBUG(%s):", __FUNCTION__);
539 return obj(dev)->cancelPicture();
540}
541
542static int HAL_camera_device_set_parameters(
543 struct camera_device *dev,
544 const char *parms)
545{
546 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
547
548 ALOGV("DEBUG(%s):", __FUNCTION__);
549 String8 str(parms);
550 CameraParameters p(str);
551 return obj(dev)->setParameters(p);
552}
553
554char *HAL_camera_device_get_parameters(struct camera_device *dev)
555{
556 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
557
558 ALOGV("DEBUG(%s):", __FUNCTION__);
559 String8 str;
560
561/* HACK : to avoid compile error */
562#if (defined BOARD_BACK_CAMERA_USES_EXTERNAL_CAMERA) && (defined BOARD_FRONT_CAMERA_USES_EXTERNAL_CAMERA)
563 ALOGE("ERR(%s[%d]):invalid opertion on external camera", __FUNCTION__, __LINE__);
564#else
565 CameraParameters parms = obj(dev)->getParameters();
566 str = parms.flatten();
567#endif
David Marble381440d2024-03-23 13:13:31 -0500568 return strdup(str.c_str());
Sam Protsenkoce268502023-09-08 19:45:36 -0500569}
570
571static void HAL_camera_device_put_parameters(
572 __unused struct camera_device *dev,
573 char *parms)
574{
575 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
576
577 ALOGV("DEBUG(%s):", __FUNCTION__);
578 free(parms);
579}
580
581static int HAL_camera_device_send_command(
582 struct camera_device *dev,
583 int32_t cmd,
584 int32_t arg1,
585 int32_t arg2)
586{
587 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
588
589 ALOGV("DEBUG(%s):", __FUNCTION__);
590 return obj(dev)->sendCommand(cmd, arg1, arg2);
591}
592
593static void HAL_camera_device_release(struct camera_device *dev)
594{
595 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
596
597 uint32_t cameraId = obj(dev)->getCameraId();
598 enum CAMERA_STATE state;
599
600 ALOGI("INFO(%s[%d]):camera(%d) in", __FUNCTION__, __LINE__, cameraId);
601
602 state = CAMERA_RELEASED;
603 if (check_camera_state(state, cameraId) == false) {
604 ALOGE("ERR(%s):camera(%d) state(%d) is INVALID",
605 __FUNCTION__, cameraId, state);
606 return;
607 }
608
609 g_cam_openLock[cameraId].lock();
610
611 obj(dev)->release();
612 ALOGI("INFO(%s[%d]):camera(%d) out from release()",
613 __FUNCTION__, __LINE__, cameraId);
614
615 g_cam_openLock[cameraId].unlock();
616
617 ALOGI("INFO(%s[%d]):camera(%d) unlocked..", __FUNCTION__, __LINE__, cameraId);
618
619 cam_stateLock[cameraId].lock();
620 cam_state[cameraId] = state;
621 cam_stateLock[cameraId].unlock();
622 ALOGI("INFO(%s[%d]):camera(%d) out", __FUNCTION__, __LINE__, cameraId);
623}
624
625static int HAL_camera_device_dump(struct camera_device *dev, int fd)
626{
627 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
628
629 ALOGV("DEBUG(%s):", __FUNCTION__);
630 return obj(dev)->dump(fd);
631}
632
633static int HAL_getNumberOfCameras()
634{
635 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
636
637 ALOGV("DEBUG(%s):", __FUNCTION__);
638 return sizeof(sCameraInfo) / sizeof(sCameraInfo[0]);
639}
640
641static int HAL_set_callbacks(const camera_module_callbacks_t *callbacks)
642{
643 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
644
645 if (callbacks == NULL)
646 ALOGE("ERR(%s[%d]):dev is NULL", __FUNCTION__, __LINE__);
647
648 g_callbacks = callbacks;
649
650 return 0;
651}
652
653static int HAL_getCameraInfo(int cameraId, struct camera_info *info)
654{
655 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
656 status_t ret = NO_ERROR;
657
658 ALOGV("DEBUG(%s):", __FUNCTION__);
659 if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras()) {
660 ALOGE("ERR(%s):Invalid camera ID %d", __FUNCTION__, cameraId);
661 return -EINVAL;
662 }
663
664 info->facing = sCameraInfo[cameraId][0];
665 info->orientation = sCameraInfo[cameraId][1];
666 info->device_version = HARDWARE_DEVICE_API_VERSION(1, 0);
667
668 if (g_cam_info[cameraId] == NULL) {
669 ALOGD("DEBUG(%s[%d]):Return static information (%d)", __FUNCTION__, __LINE__, cameraId);
670 ret = ExynosCamera1MetadataConverter::constructStaticInfo(cameraId, &g_cam_info[cameraId]);
671 if (ret != 0) {
672 ALOGE("ERR(%s[%d]): static information is NULL", __FUNCTION__, __LINE__);
673 return -EINVAL;
674 }
675 info->static_camera_characteristics = g_cam_info[cameraId];
676 } else {
677 ALOGD("DEBUG(%s[%d]):Reuse!! Return static information (%d)", __FUNCTION__, __LINE__, cameraId);
678 info->static_camera_characteristics = g_cam_info[cameraId];
679 }
680
681 /* set service arbitration (resource_cost, conflicting_devices, conflicting_devices_length */
682 info->resource_cost = sCameraConfigInfo[cameraId].resource_cost;
683 info->conflicting_devices = sCameraConfigInfo[cameraId].conflicting_devices;
684 info->conflicting_devices_length = sCameraConfigInfo[cameraId].conflicting_devices_length;
685 ALOGD("INFO(%s info->resource_cost = %d ", __FUNCTION__, info->resource_cost);
686 if (info->conflicting_devices_length) {
687 for (size_t i = 0; i < info->conflicting_devices_length; i++) {
688 ALOGD("INFO(%s info->conflicting_devices = %s ", __FUNCTION__, info->conflicting_devices[i]);
689 }
690 } else {
691 ALOGD("INFO(%s info->conflicting_devices_length is zero ", __FUNCTION__);
692 }
693
694 return NO_ERROR;
695}
696
697static int HAL_set_torch_mode(const char* camera_id, bool enabled)
698{
699 ExynosCameraAutoTimer autoTimer(__FUNCTION__);
700
701 int cameraId = atoi(camera_id);
702 FILE *fp = NULL;
703 char flashFilePath[100] = {'\0',};
704 CameraMetadata metadata;
705 camera_metadata_entry flashAvailable;
706 int ret = 0;
707
708 ALOGI("INFO(%s[%d]):in =====", __FUNCTION__, __LINE__);
709 if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras()) {
710 ALOGE("ERR(%s[%d]):Invalid camera ID %d", __FUNCTION__, __LINE__, cameraId);
711 return -EINVAL;
712 }
713
714 /* Check the android.flash.info.available */
715 /* If this camera device does not support flash, It have to return -ENOSYS */
716 metadata = g_cam_info[cameraId];
717 flashAvailable = metadata.find(ANDROID_FLASH_INFO_AVAILABLE);
718
719 if (flashAvailable.count == 1 && flashAvailable.data.u8[0] == 1) {
720 ALOGV("DEBUG(%s[%d]): Flash metadata exist", __FUNCTION__, __LINE__);
721 } else {
722 ALOGE("ERR(%s[%d]): Can not find flash metadata", __FUNCTION__, __LINE__);
723 return -ENOSYS;
724 }
725
726 ALOGI("INFO(%s[%d]): Current Camera State (state = %d)", __FUNCTION__, __LINE__, cam_state[cameraId]);
727
728 /* Add the check the camera state that camera in use or not */
729 if (cam_state[cameraId] > CAMERA_CLOSED) {
730 ALOGE("ERR(%s[%d]): Camera Device is busy (state = %d)", __FUNCTION__, __LINE__, cam_state[cameraId]);
731 if (g_callbacks) {
732 g_callbacks->torch_mode_status_change(g_callbacks, camera_id, TORCH_MODE_STATUS_AVAILABLE_OFF);
733 ALOGI("INFO(%s[%d]):camera(%d) TORCH_MODE_STATUS_AVAILABLE_OFF", __FUNCTION__, __LINE__, cameraId);
734 }
735 return -EBUSY;
736 }
737
738 /* Add the sysfs file read (sys/class/camera/flash/torch_flash) then set 0 or 1 */
739 if (cameraId == CAMERA_ID_BACK) {
740 snprintf(flashFilePath, sizeof(flashFilePath), TORCH_REAR_FILE_PATH);
741 } else {
742 snprintf(flashFilePath, sizeof(flashFilePath), TORCH_FRONT_FILE_PATH);
743 }
744
745 fp = fopen(flashFilePath, "w+");
746
747 if (fp == NULL) {
748 ALOGE("ERR(%s[%d]):torch file open(%s) fail",
749 __FUNCTION__, __LINE__, flashFilePath);
750 return -ENOSYS;
751 }
752
753 if (enabled) {
754 fwrite("1", sizeof(char), 1, fp);
755 } else {
756 fwrite("0", sizeof(char), 1, fp);
757 }
758
759 fflush(fp);
760
761 ret = fclose(fp);
762 if (ret != 0) {
763 ALOGE("ERR(%s[%d]): file close failed(%d)", __FUNCTION__, __LINE__, ret);
764 }
765
766 if (enabled) {
767 g_cam_torchEnabled[cameraId] = true;
768 if (g_callbacks) {
769 g_callbacks->torch_mode_status_change(g_callbacks, camera_id, TORCH_MODE_STATUS_AVAILABLE_ON);
770 ALOGI("INFO(%s[%d]):camera(%d) TORCH_MODE_STATUS_AVAILABLE_ON", __FUNCTION__, __LINE__, cameraId);
771 }
772 } else {
773 g_cam_torchEnabled[cameraId] = false;
774 if (g_callbacks) {
775 g_callbacks->torch_mode_status_change(g_callbacks, camera_id, TORCH_MODE_STATUS_AVAILABLE_OFF);
776 ALOGI("INFO(%s[%d]):camera(%d) TORCH_MODE_STATUS_AVAILABLE_OFF", __FUNCTION__, __LINE__, cameraId);
777 }
778 }
779
780 ALOGI("INFO(%s[%d]):out =====", __FUNCTION__, __LINE__);
781
782 return NO_ERROR;
783}
784
785static int HAL_init()
786{
787 ALOGI("INFO(%s[%d]):in =====", __FUNCTION__, __LINE__);
788
789 return OK;
790}
791
792static int HAL_open_legacy(__unused const struct hw_module_t* module, __unused const char* id,
793 __unused uint32_t halVersion, __unused struct hw_device_t** device)
794{
795 ALOGV("DEBUG(%s):", __FUNCTION__);
796 return NO_ERROR;
797}
798
799static void HAL_get_vendor_tag_ops(__unused vendor_tag_ops_t* ops)
800{
801 ALOGV("INFO(%s):", __FUNCTION__);
802/*
803 SecCameraVendorTags::Ops = ops;
804
805 ops->get_all_tags = SecCameraVendorTags::get_ext_all_tags;
806 ops->get_tag_count = SecCameraVendorTags::get_ext_tag_count;
807 ops->get_tag_type = SecCameraVendorTags::get_ext_tag_type;
808 ops->get_tag_name = SecCameraVendorTags::get_ext_tag_name;
809 ops->get_section_name = SecCameraVendorTags::get_ext_section_name;
810 ops->reserved[0] = NULL;
811*/
812}
813
814}; /* namespace android */