1 /*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /**
18 * @file CameraHal.cpp
19 *
20 * This file maps the Camera Hardware Interface to V4L2.
21 *
22 */
23
24 #include <utils/threads.h>
25
26 #include "CameraHal.h"
27 #include "CameraProperties.h"
28 #include "TICameraParameters.h"
29
30
31 #ifdef CAMERAHAL_DEBUG_VERBOSE
32 # define CAMHAL_LOG_MODULE_FUNCTION_NAME LOG_FUNCTION_NAME
33 #else
34 # define CAMHAL_LOG_MODULE_FUNCTION_NAME
35 #endif
36
37
38 namespace Ti {
39 namespace Camera {
40
41 static CameraProperties gCameraProperties;
42 static CameraHal* gCameraHals[MAX_CAMERAS_SUPPORTED];
43 static unsigned int gCamerasOpen = 0;
44 static android::Mutex gCameraHalDeviceLock;
45
46 static int camera_device_open(const hw_module_t* module, const char* name,
47 hw_device_t** device);
48 static int camera_device_close(hw_device_t* device);
49 static int camera_get_number_of_cameras(void);
50 static int camera_get_camera_info(int camera_id, struct camera_info *info);
51
52 static struct hw_module_methods_t camera_module_methods = {
53 open: camera_device_open
54 };
55
56 } // namespace Camera
57 } // namespace Ti
58
59
60 camera_module_t HAL_MODULE_INFO_SYM = {
61 common: {
62 tag: HARDWARE_MODULE_TAG,
63 version_major: 1,
64 version_minor: 0,
65 id: CAMERA_HARDWARE_MODULE_ID,
66 name: "TI OMAP CameraHal Module",
67 author: "TI",
68 methods: &Ti::Camera::camera_module_methods,
69 dso: NULL, /* remove compilation warnings */
70 reserved: {0}, /* remove compilation warnings */
71 },
72 get_number_of_cameras: Ti::Camera::camera_get_number_of_cameras,
73 get_camera_info: Ti::Camera::camera_get_camera_info,
74 };
75
76
77 namespace Ti {
78 namespace Camera {
79
80 typedef struct ti_camera_device {
81 camera_device_t base;
82 /* TI specific "private" data can go here (base.priv) */
83 int cameraid;
84 } ti_camera_device_t;
85
86
87 /*******************************************************************
88 * implementation of camera_device_ops functions
89 *******************************************************************/
90
camera_set_preview_window(struct camera_device * device,struct preview_stream_ops * window)91 int camera_set_preview_window(struct camera_device * device,
92 struct preview_stream_ops *window)
93 {
94 CAMHAL_LOG_MODULE_FUNCTION_NAME;
95
96 int rv = -EINVAL;
97 ti_camera_device_t* ti_dev = NULL;
98
99 if(!device)
100 return rv;
101
102 ti_dev = (ti_camera_device_t*) device;
103
104 rv = gCameraHals[ti_dev->cameraid]->setPreviewWindow(window);
105
106 return rv;
107 }
108
109 #ifdef OMAP_ENHANCEMENT_CPCAM
camera_set_extended_preview_ops(struct camera_device * device,preview_stream_extended_ops_t * extendedOps)110 int camera_set_extended_preview_ops(struct camera_device * device,
111 preview_stream_extended_ops_t * extendedOps)
112 {
113 CAMHAL_LOG_MODULE_FUNCTION_NAME;
114
115 if (!device) {
116 return BAD_VALUE;
117 }
118
119 ti_camera_device_t * const tiDevice = reinterpret_cast<ti_camera_device_t*>(device);
120 gCameraHals[tiDevice->cameraid]->setExtendedPreviewStreamOps(extendedOps);
121
122 return OK;
123 }
124
camera_set_buffer_source(struct camera_device * device,struct preview_stream_ops * tapin,struct preview_stream_ops * tapout)125 int camera_set_buffer_source(struct camera_device * device,
126 struct preview_stream_ops *tapin,
127 struct preview_stream_ops *tapout)
128 {
129 CAMHAL_LOG_MODULE_FUNCTION_NAME;
130
131 int rv = -EINVAL;
132 ti_camera_device_t* ti_dev = NULL;
133
134 if(!device)
135 return rv;
136
137 ti_dev = (ti_camera_device_t*) device;
138
139 rv = gCameraHals[ti_dev->cameraid]->setBufferSource(tapin, tapout);
140
141 return rv;
142 }
143
camera_release_buffer_source(struct camera_device * device,struct preview_stream_ops * tapin,struct preview_stream_ops * tapout)144 int camera_release_buffer_source(struct camera_device * device,
145 struct preview_stream_ops *tapin,
146 struct preview_stream_ops *tapout)
147 {
148 CAMHAL_LOG_MODULE_FUNCTION_NAME;
149
150 int rv = -EINVAL;
151 ti_camera_device_t* ti_dev = NULL;
152
153 if(!device)
154 return rv;
155
156 ti_dev = (ti_camera_device_t*) device;
157
158 rv = gCameraHals[ti_dev->cameraid]->releaseBufferSource(tapin, tapout);
159
160 return rv;
161 }
162 #endif
163
camera_set_callbacks(struct camera_device * device,camera_notify_callback notify_cb,camera_data_callback data_cb,camera_data_timestamp_callback data_cb_timestamp,camera_request_memory get_memory,void * user)164 void camera_set_callbacks(struct camera_device * device,
165 camera_notify_callback notify_cb,
166 camera_data_callback data_cb,
167 camera_data_timestamp_callback data_cb_timestamp,
168 camera_request_memory get_memory,
169 void *user)
170 {
171 CAMHAL_LOG_MODULE_FUNCTION_NAME;
172
173 ti_camera_device_t* ti_dev = NULL;
174
175 if(!device)
176 return;
177
178 ti_dev = (ti_camera_device_t*) device;
179
180 gCameraHals[ti_dev->cameraid]->setCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user);
181 }
182
camera_enable_msg_type(struct camera_device * device,int32_t msg_type)183 void camera_enable_msg_type(struct camera_device * device, int32_t msg_type)
184 {
185 CAMHAL_LOG_MODULE_FUNCTION_NAME;
186
187 ti_camera_device_t* ti_dev = NULL;
188
189 if(!device)
190 return;
191
192 ti_dev = (ti_camera_device_t*) device;
193
194 gCameraHals[ti_dev->cameraid]->enableMsgType(msg_type);
195 }
196
camera_disable_msg_type(struct camera_device * device,int32_t msg_type)197 void camera_disable_msg_type(struct camera_device * device, int32_t msg_type)
198 {
199 CAMHAL_LOG_MODULE_FUNCTION_NAME;
200
201 ti_camera_device_t* ti_dev = NULL;
202
203 if(!device)
204 return;
205
206 ti_dev = (ti_camera_device_t*) device;
207
208 gCameraHals[ti_dev->cameraid]->disableMsgType(msg_type);
209 }
210
camera_msg_type_enabled(struct camera_device * device,int32_t msg_type)211 int camera_msg_type_enabled(struct camera_device * device, int32_t msg_type)
212 {
213 CAMHAL_LOG_MODULE_FUNCTION_NAME;
214
215 ti_camera_device_t* ti_dev = NULL;
216
217 if(!device)
218 return 0;
219
220 ti_dev = (ti_camera_device_t*) device;
221
222 return gCameraHals[ti_dev->cameraid]->msgTypeEnabled(msg_type);
223 }
224
camera_start_preview(struct camera_device * device)225 int camera_start_preview(struct camera_device * device)
226 {
227 CAMHAL_LOG_MODULE_FUNCTION_NAME;
228
229 int rv = -EINVAL;
230 ti_camera_device_t* ti_dev = NULL;
231
232 if(!device)
233 return rv;
234
235 ti_dev = (ti_camera_device_t*) device;
236
237 rv = gCameraHals[ti_dev->cameraid]->startPreview();
238
239 return rv;
240 }
241
camera_stop_preview(struct camera_device * device)242 void camera_stop_preview(struct camera_device * device)
243 {
244 CAMHAL_LOG_MODULE_FUNCTION_NAME;
245
246 ti_camera_device_t* ti_dev = NULL;
247
248 if(!device)
249 return;
250
251 ti_dev = (ti_camera_device_t*) device;
252
253 gCameraHals[ti_dev->cameraid]->stopPreview();
254 }
255
camera_preview_enabled(struct camera_device * device)256 int camera_preview_enabled(struct camera_device * device)
257 {
258 CAMHAL_LOG_MODULE_FUNCTION_NAME;
259
260 int rv = -EINVAL;
261 ti_camera_device_t* ti_dev = NULL;
262
263 if(!device)
264 return rv;
265
266 ti_dev = (ti_camera_device_t*) device;
267
268 rv = gCameraHals[ti_dev->cameraid]->previewEnabled();
269 return rv;
270 }
271
camera_store_meta_data_in_buffers(struct camera_device * device,int enable)272 int camera_store_meta_data_in_buffers(struct camera_device * device, int enable)
273 {
274 CAMHAL_LOG_MODULE_FUNCTION_NAME;
275
276 int rv = -EINVAL;
277 ti_camera_device_t* ti_dev = NULL;
278
279 if(!device)
280 return rv;
281
282 ti_dev = (ti_camera_device_t*) device;
283
284 // TODO: meta data buffer not current supported
285 rv = gCameraHals[ti_dev->cameraid]->storeMetaDataInBuffers(enable);
286 return rv;
287 //return enable ? android::INVALID_OPERATION: android::OK;
288 }
289
camera_start_recording(struct camera_device * device)290 int camera_start_recording(struct camera_device * device)
291 {
292 CAMHAL_LOG_MODULE_FUNCTION_NAME;
293
294 int rv = -EINVAL;
295 ti_camera_device_t* ti_dev = NULL;
296
297 if(!device)
298 return rv;
299
300 ti_dev = (ti_camera_device_t*) device;
301
302 rv = gCameraHals[ti_dev->cameraid]->startRecording();
303 return rv;
304 }
305
camera_stop_recording(struct camera_device * device)306 void camera_stop_recording(struct camera_device * device)
307 {
308 CAMHAL_LOG_MODULE_FUNCTION_NAME;
309
310 ti_camera_device_t* ti_dev = NULL;
311
312 if(!device)
313 return;
314
315 ti_dev = (ti_camera_device_t*) device;
316
317 gCameraHals[ti_dev->cameraid]->stopRecording();
318 }
319
camera_recording_enabled(struct camera_device * device)320 int camera_recording_enabled(struct camera_device * device)
321 {
322 CAMHAL_LOG_MODULE_FUNCTION_NAME;
323
324 int rv = -EINVAL;
325 ti_camera_device_t* ti_dev = NULL;
326
327 if(!device)
328 return rv;
329
330 ti_dev = (ti_camera_device_t*) device;
331
332 rv = gCameraHals[ti_dev->cameraid]->recordingEnabled();
333 return rv;
334 }
335
camera_release_recording_frame(struct camera_device * device,const void * opaque)336 void camera_release_recording_frame(struct camera_device * device,
337 const void *opaque)
338 {
339 CAMHAL_LOG_MODULE_FUNCTION_NAME;
340
341 ti_camera_device_t* ti_dev = NULL;
342
343 if(!device)
344 return;
345
346 ti_dev = (ti_camera_device_t*) device;
347
348 gCameraHals[ti_dev->cameraid]->releaseRecordingFrame(opaque);
349 }
350
camera_auto_focus(struct camera_device * device)351 int camera_auto_focus(struct camera_device * device)
352 {
353 CAMHAL_LOG_MODULE_FUNCTION_NAME;
354
355 int rv = -EINVAL;
356 ti_camera_device_t* ti_dev = NULL;
357
358 if(!device)
359 return rv;
360
361 ti_dev = (ti_camera_device_t*) device;
362
363 rv = gCameraHals[ti_dev->cameraid]->autoFocus();
364 return rv;
365 }
366
camera_cancel_auto_focus(struct camera_device * device)367 int camera_cancel_auto_focus(struct camera_device * device)
368 {
369 CAMHAL_LOG_MODULE_FUNCTION_NAME;
370
371 int rv = -EINVAL;
372 ti_camera_device_t* ti_dev = NULL;
373
374 if(!device)
375 return rv;
376
377 ti_dev = (ti_camera_device_t*) device;
378
379 rv = gCameraHals[ti_dev->cameraid]->cancelAutoFocus();
380 return rv;
381 }
382
camera_take_picture(struct camera_device * device)383 int camera_take_picture(struct camera_device * device)
384 {
385 CAMHAL_LOG_MODULE_FUNCTION_NAME;
386
387 int rv = -EINVAL;
388 ti_camera_device_t* ti_dev = NULL;
389
390 if(!device)
391 return rv;
392
393 ti_dev = (ti_camera_device_t*) device;
394
395 rv = gCameraHals[ti_dev->cameraid]->takePicture(0);
396 return rv;
397 }
398
399 #ifdef OMAP_ENHANCEMENT_CPCAM
camera_take_picture_with_parameters(struct camera_device * device,const char * params)400 int camera_take_picture_with_parameters(struct camera_device * device, const char *params)
401 {
402 CAMHAL_LOG_MODULE_FUNCTION_NAME;
403
404 int rv = -EINVAL;
405 ti_camera_device_t* ti_dev = NULL;
406
407 if(!device)
408 return rv;
409
410 ti_dev = (ti_camera_device_t*) device;
411
412 rv = gCameraHals[ti_dev->cameraid]->takePicture(params);
413 return rv;
414 }
415 #endif
416
camera_cancel_picture(struct camera_device * device)417 int camera_cancel_picture(struct camera_device * device)
418 {
419 CAMHAL_LOG_MODULE_FUNCTION_NAME;
420
421 int rv = -EINVAL;
422 ti_camera_device_t* ti_dev = NULL;
423
424 if(!device)
425 return rv;
426
427 ti_dev = (ti_camera_device_t*) device;
428
429 rv = gCameraHals[ti_dev->cameraid]->cancelPicture();
430 return rv;
431 }
432
433 #ifdef OMAP_ENHANCEMENT_CPCAM
camera_reprocess(struct camera_device * device,const char * params)434 int camera_reprocess(struct camera_device * device, const char *params)
435 {
436 CAMHAL_LOG_MODULE_FUNCTION_NAME;
437
438 int rv = -EINVAL;
439 ti_camera_device_t* ti_dev = NULL;
440
441 if(!device)
442 return rv;
443
444 ti_dev = (ti_camera_device_t*) device;
445
446 rv = gCameraHals[ti_dev->cameraid]->reprocess(params);
447 return rv;
448 }
449
camera_cancel_reprocess(struct camera_device * device)450 int camera_cancel_reprocess(struct camera_device * device)
451 {
452 CAMHAL_LOG_MODULE_FUNCTION_NAME;
453
454 int rv = -EINVAL;
455 ti_camera_device_t* ti_dev = NULL;
456
457 if(!device)
458 return rv;
459
460 ti_dev = (ti_camera_device_t*) device;
461
462 rv = gCameraHals[ti_dev->cameraid]->cancel_reprocess();
463 return rv;
464 }
465 #endif
466
camera_set_parameters(struct camera_device * device,const char * params)467 int camera_set_parameters(struct camera_device * device, const char *params)
468 {
469 CAMHAL_LOG_MODULE_FUNCTION_NAME;
470
471 int rv = -EINVAL;
472 ti_camera_device_t* ti_dev = NULL;
473
474 if(!device)
475 return rv;
476
477 ti_dev = (ti_camera_device_t*) device;
478
479 rv = gCameraHals[ti_dev->cameraid]->setParameters(params);
480 return rv;
481 }
482
camera_get_parameters(struct camera_device * device)483 char* camera_get_parameters(struct camera_device * device)
484 {
485 CAMHAL_LOG_MODULE_FUNCTION_NAME;
486
487 char* param = NULL;
488 ti_camera_device_t* ti_dev = NULL;
489
490 if(!device)
491 return NULL;
492
493 ti_dev = (ti_camera_device_t*) device;
494
495 param = gCameraHals[ti_dev->cameraid]->getParameters();
496
497 return param;
498 }
499
camera_put_parameters(struct camera_device * device,char * parms)500 static void camera_put_parameters(struct camera_device *device, char *parms)
501 {
502 CAMHAL_LOG_MODULE_FUNCTION_NAME;
503
504 ti_camera_device_t* ti_dev = NULL;
505
506 if(!device)
507 return;
508
509 ti_dev = (ti_camera_device_t*) device;
510
511 gCameraHals[ti_dev->cameraid]->putParameters(parms);
512 }
513
camera_send_command(struct camera_device * device,int32_t cmd,int32_t arg1,int32_t arg2)514 int camera_send_command(struct camera_device * device,
515 int32_t cmd, int32_t arg1, int32_t arg2)
516 {
517 CAMHAL_LOG_MODULE_FUNCTION_NAME;
518
519 int rv = -EINVAL;
520 ti_camera_device_t* ti_dev = NULL;
521
522 if(!device)
523 return rv;
524
525 ti_dev = (ti_camera_device_t*) device;
526
527 #ifdef OMAP_ENHANCEMENT
528 if ( cmd == CAMERA_CMD_SETUP_EXTENDED_OPERATIONS ) {
529 camera_device_extended_ops_t * const ops = static_cast<camera_device_extended_ops_t*>(
530 camera_cmd_send_command_args_to_pointer(arg1, arg2));
531
532 #ifdef OMAP_ENHANCEMENT_CPCAM
533 ops->set_extended_preview_ops = camera_set_extended_preview_ops;
534 ops->set_buffer_source = camera_set_buffer_source;
535 ops->release_buffer_source = camera_release_buffer_source;
536 ops->take_picture_with_parameters = camera_take_picture_with_parameters;
537 ops->reprocess = camera_reprocess;
538 ops->cancel_reprocess = camera_cancel_reprocess;
539 #endif
540
541 return OK;
542 }
543 #endif
544
545 rv = gCameraHals[ti_dev->cameraid]->sendCommand(cmd, arg1, arg2);
546 return rv;
547 }
548
camera_release(struct camera_device * device)549 void camera_release(struct camera_device * device)
550 {
551 CAMHAL_LOG_MODULE_FUNCTION_NAME;
552
553 ti_camera_device_t* ti_dev = NULL;
554
555 if(!device)
556 return;
557
558 ti_dev = (ti_camera_device_t*) device;
559
560 gCameraHals[ti_dev->cameraid]->release();
561 }
562
camera_dump(struct camera_device * device,int fd)563 int camera_dump(struct camera_device * device, int fd)
564 {
565 CAMHAL_LOG_MODULE_FUNCTION_NAME;
566
567 int rv = -EINVAL;
568 ti_camera_device_t* ti_dev = NULL;
569
570 if(!device)
571 return rv;
572
573 ti_dev = (ti_camera_device_t*) device;
574
575 rv = gCameraHals[ti_dev->cameraid]->dump(fd);
576 return rv;
577 }
578
579 extern "C" void heaptracker_free_leaked_memory(void);
580
camera_device_close(hw_device_t * device)581 int camera_device_close(hw_device_t* device)
582 {
583 CAMHAL_LOG_MODULE_FUNCTION_NAME;
584
585 int ret = 0;
586 ti_camera_device_t* ti_dev = NULL;
587
588 android::AutoMutex lock(gCameraHalDeviceLock);
589
590 if (!device) {
591 ret = -EINVAL;
592 goto done;
593 }
594
595 ti_dev = (ti_camera_device_t*) device;
596
597 if (ti_dev) {
598 if (gCameraHals[ti_dev->cameraid]) {
599 delete gCameraHals[ti_dev->cameraid];
600 gCameraHals[ti_dev->cameraid] = NULL;
601 gCamerasOpen--;
602 }
603
604 if (ti_dev->base.ops) {
605 free(ti_dev->base.ops);
606 }
607 free(ti_dev);
608 }
609 done:
610 #ifdef HEAPTRACKER
611 heaptracker_free_leaked_memory();
612 #endif
613 return ret;
614 }
615
616 /*******************************************************************
617 * implementation of camera_module functions
618 *******************************************************************/
619
620 /* open device handle to one of the cameras
621 *
622 * assume camera service will keep singleton of each camera
623 * so this function will always only be called once per camera instance
624 */
625
camera_device_open(const hw_module_t * module,const char * name,hw_device_t ** device)626 int camera_device_open(const hw_module_t* module, const char* name,
627 hw_device_t** device)
628 {
629 int rv = 0;
630 int num_cameras = 0;
631 int cameraid;
632 ti_camera_device_t* camera_device = NULL;
633 camera_device_ops_t* camera_ops = NULL;
634 CameraHal* camera = NULL;
635 CameraProperties::Properties* properties = NULL;
636
637 android::AutoMutex lock(gCameraHalDeviceLock);
638
639 CAMHAL_LOGI("camera_device open");
640
641 if (name != NULL) {
642 cameraid = atoi(name);
643 num_cameras = gCameraProperties.camerasSupported();
644
645 if(cameraid > num_cameras)
646 {
647 CAMHAL_LOGE("camera service provided cameraid out of bounds, "
648 "cameraid = %d, num supported = %d",
649 cameraid, num_cameras);
650 rv = -EINVAL;
651 goto fail;
652 }
653
654 if(gCamerasOpen >= MAX_SIMUL_CAMERAS_SUPPORTED)
655 {
656 CAMHAL_LOGE("maximum number of cameras already open");
657 rv = -ENOMEM;
658 goto fail;
659 }
660
661 camera_device = (ti_camera_device_t*)malloc(sizeof(*camera_device));
662 if(!camera_device)
663 {
664 CAMHAL_LOGE("camera_device allocation fail");
665 rv = -ENOMEM;
666 goto fail;
667 }
668
669 camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops));
670 if(!camera_ops)
671 {
672 CAMHAL_LOGE("camera_ops allocation fail");
673 rv = -ENOMEM;
674 goto fail;
675 }
676
677 memset(camera_device, 0, sizeof(*camera_device));
678 memset(camera_ops, 0, sizeof(*camera_ops));
679
680 camera_device->base.common.tag = HARDWARE_DEVICE_TAG;
681 camera_device->base.common.version = 0;
682 camera_device->base.common.module = (hw_module_t *)(module);
683 camera_device->base.common.close = camera_device_close;
684 camera_device->base.ops = camera_ops;
685
686 camera_ops->set_preview_window = camera_set_preview_window;
687 camera_ops->set_callbacks = camera_set_callbacks;
688 camera_ops->enable_msg_type = camera_enable_msg_type;
689 camera_ops->disable_msg_type = camera_disable_msg_type;
690 camera_ops->msg_type_enabled = camera_msg_type_enabled;
691 camera_ops->start_preview = camera_start_preview;
692 camera_ops->stop_preview = camera_stop_preview;
693 camera_ops->preview_enabled = camera_preview_enabled;
694 camera_ops->store_meta_data_in_buffers = camera_store_meta_data_in_buffers;
695 camera_ops->start_recording = camera_start_recording;
696 camera_ops->stop_recording = camera_stop_recording;
697 camera_ops->recording_enabled = camera_recording_enabled;
698 camera_ops->release_recording_frame = camera_release_recording_frame;
699 camera_ops->auto_focus = camera_auto_focus;
700 camera_ops->cancel_auto_focus = camera_cancel_auto_focus;
701 camera_ops->take_picture = camera_take_picture;
702 camera_ops->cancel_picture = camera_cancel_picture;
703 camera_ops->set_parameters = camera_set_parameters;
704 camera_ops->get_parameters = camera_get_parameters;
705 camera_ops->put_parameters = camera_put_parameters;
706 camera_ops->send_command = camera_send_command;
707 camera_ops->release = camera_release;
708 camera_ops->dump = camera_dump;
709
710 *device = &camera_device->base.common;
711
712 // -------- TI specific stuff --------
713
714 camera_device->cameraid = cameraid;
715
716 if(gCameraProperties.getProperties(cameraid, &properties) < 0)
717 {
718 CAMHAL_LOGE("Couldn't get camera properties");
719 rv = -ENOMEM;
720 goto fail;
721 }
722
723 camera = new CameraHal(cameraid);
724
725 if(!camera)
726 {
727 CAMHAL_LOGE("Couldn't create instance of CameraHal class");
728 rv = -ENOMEM;
729 goto fail;
730 }
731
732 if(properties && (camera->initialize(properties) != NO_ERROR))
733 {
734 CAMHAL_LOGE("Couldn't initialize camera instance");
735 rv = -ENODEV;
736 goto fail;
737 }
738
739 gCameraHals[cameraid] = camera;
740 gCamerasOpen++;
741 }
742
743 return rv;
744
745 fail:
746 if(camera_device) {
747 free(camera_device);
748 camera_device = NULL;
749 }
750 if(camera_ops) {
751 free(camera_ops);
752 camera_ops = NULL;
753 }
754 if(camera) {
755 delete camera;
756 camera = NULL;
757 }
758 *device = NULL;
759 return rv;
760 }
761
camera_get_number_of_cameras(void)762 int camera_get_number_of_cameras(void)
763 {
764 int num_cameras = MAX_CAMERAS_SUPPORTED;
765
766 // this going to be the first call from camera service
767 // initialize camera properties here...
768 if(gCameraProperties.initialize() != NO_ERROR)
769 {
770 CAMHAL_LOGEA("Unable to create or initialize CameraProperties");
771 return NULL;
772 }
773
774 num_cameras = gCameraProperties.camerasSupported();
775
776 return num_cameras;
777 }
778
camera_get_camera_info(int camera_id,struct camera_info * info)779 int camera_get_camera_info(int camera_id, struct camera_info *info)
780 {
781 int rv = 0;
782 int face_value = CAMERA_FACING_BACK;
783 int orientation = 0;
784 const char *valstr = NULL;
785 CameraProperties::Properties* properties = NULL;
786
787 // this going to be the first call from camera service
788 // initialize camera properties here...
789 if(gCameraProperties.initialize() != NO_ERROR)
790 {
791 CAMHAL_LOGEA("Unable to create or initialize CameraProperties");
792 rv = -EINVAL;
793 goto end;
794 }
795
796 //Get camera properties for camera index
797 if(gCameraProperties.getProperties(camera_id, &properties) < 0)
798 {
799 CAMHAL_LOGE("Couldn't get camera properties");
800 rv = -EINVAL;
801 goto end;
802 }
803
804 if(properties)
805 {
806 valstr = properties->get(CameraProperties::FACING_INDEX);
807 if(valstr != NULL)
808 {
809 if (strcmp(valstr, TICameraParameters::FACING_FRONT) == 0)
810 {
811 face_value = CAMERA_FACING_FRONT;
812 }
813 else if (strcmp(valstr, TICameraParameters::FACING_BACK) == 0)
814 {
815 face_value = CAMERA_FACING_BACK;
816 }
817 }
818
819 valstr = properties->get(CameraProperties::ORIENTATION_INDEX);
820 if(valstr != NULL)
821 {
822 orientation = atoi(valstr);
823 }
824 }
825 else
826 {
827 CAMHAL_LOGEB("getProperties() returned a NULL property set for Camera id %d", camera_id);
828 }
829
830 info->facing = face_value;
831 info->orientation = orientation;
832
833 end:
834 return rv;
835 }
836
837
838 } // namespace Camera
839 } // namespace Ti
840