blob: e32c9c9fe2724ed00652dfb18ae6feb8ec138887
1 | /* |
2 | * Copyright (C) 2011 The Android Open Source Project |
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 | //#define LOG_NDEBUG 0 |
18 | #define LOG_TAG "CameraHAL_Module " |
19 | |
20 | #include <utils/threads.h> |
21 | |
22 | #include "DebugUtils.h" |
23 | #include "CameraHal.h" |
24 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
25 | #include "VirtualCamHal.h" |
26 | #endif |
27 | |
28 | #include "CameraProperties.h" |
29 | #include "ExCameraParameters.h" |
30 | |
31 | static android::CameraProperties gCameraProperties; |
32 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
33 | static android::CameraHal* gCameraHals[MAX_CAM_NUM_ADD_VCAM-1]; |
34 | static android::VirtualCamHal* gVCameraHals; |
35 | #else |
36 | static android::CameraHal* gCameraHals[MAX_CAMERAS_SUPPORTED]; |
37 | #endif |
38 | static unsigned int gCamerasOpen = 0; |
39 | static unsigned int gCamerasSupported = 0; |
40 | static android::Mutex gCameraHalDeviceLock; |
41 | |
42 | static int camera_device_open(const hw_module_t* module, const char* name, |
43 | hw_device_t** device); |
44 | static int camera_device_close(hw_device_t* device); |
45 | static int camera_get_number_of_cameras(void); |
46 | static int camera_get_camera_info(int camera_id, struct camera_info *info); |
47 | |
48 | #ifdef CAMHAL_USER_MODE |
49 | volatile int32_t gCamHal_LogLevel = 4; |
50 | #else |
51 | volatile int32_t gCamHal_LogLevel = 6; |
52 | #endif |
53 | static void setLogLevel(void *p){ |
54 | int level = (int) p; |
55 | android_atomic_write(level, &gCamHal_LogLevel); |
56 | } |
57 | |
58 | static const char *macro_info[]={ |
59 | #ifdef CAMHAL_USER_MODE |
60 | "user mode", |
61 | #endif |
62 | #ifdef AMLOGIC_FRONT_CAMERA_SUPPORT |
63 | "front board camera", |
64 | #endif |
65 | #ifdef AMLOGIC_BACK_CAMERA_SUPPORT |
66 | "back board camera", |
67 | #endif |
68 | #ifdef AMLOGIC_USB_CAMERA_SUPPORT |
69 | "usb camera", |
70 | #endif |
71 | #ifdef AMLOGIC_TWO_CH_UVC |
72 | "usb is two channel", |
73 | #endif |
74 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
75 | "virtual camera enable", |
76 | #endif |
77 | #ifdef AMLOGIC_CAMERA_NONBLOCK_SUPPORT |
78 | "nonblock mode", |
79 | #endif |
80 | }; |
81 | |
82 | |
83 | static struct hw_module_methods_t camera_module_methods = { |
84 | open: camera_device_open |
85 | }; |
86 | |
87 | camera_module_t HAL_MODULE_INFO_SYM = { |
88 | common: { |
89 | tag: HARDWARE_MODULE_TAG, |
90 | version_major: 1, |
91 | version_minor: 0, |
92 | id: CAMERA_HARDWARE_MODULE_ID, |
93 | name: "CameraHal Module", |
94 | author: "Amlogic", |
95 | methods: &camera_module_methods, |
96 | dso: NULL, /* remove compilation warnings */ |
97 | reserved: {0}, /* remove compilation warnings */ |
98 | }, |
99 | get_number_of_cameras: camera_get_number_of_cameras, |
100 | get_camera_info: camera_get_camera_info, |
101 | set_callbacks: NULL, |
102 | get_vendor_tag_ops: NULL, |
103 | open_legacy: NULL, |
104 | set_torch_mode: NULL, |
105 | init: NULL, |
106 | reserved: {0}, |
107 | }; |
108 | |
109 | typedef struct aml_camera_device { |
110 | camera_device_t base; |
111 | int cameraid; |
112 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
113 | int type; |
114 | #endif |
115 | } aml_camera_device_t; |
116 | |
117 | /******************************************************************* |
118 | * implementation of camera_device_ops functions |
119 | *******************************************************************/ |
120 | |
121 | int camera_set_preview_window(struct camera_device * device, |
122 | struct preview_stream_ops *window) |
123 | { |
124 | int rv = -EINVAL; |
125 | aml_camera_device_t* aml_dev = NULL; |
126 | |
127 | LOG_FUNCTION_NAME; |
128 | |
129 | if(!device) |
130 | return rv; |
131 | |
132 | aml_dev = (aml_camera_device_t*) device; |
133 | |
134 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
135 | if( 1 == aml_dev->type ){ |
136 | return gVCameraHals->setPreviewWindow(window); |
137 | } |
138 | #endif |
139 | |
140 | rv = gCameraHals[aml_dev->cameraid]->setPreviewWindow(window); |
141 | |
142 | return rv; |
143 | } |
144 | |
145 | void camera_set_callbacks(struct camera_device * device, |
146 | camera_notify_callback notify_cb, |
147 | camera_data_callback data_cb, |
148 | camera_data_timestamp_callback data_cb_timestamp, |
149 | camera_request_memory get_memory, |
150 | void *user) |
151 | { |
152 | aml_camera_device_t* aml_dev = NULL; |
153 | |
154 | LOG_FUNCTION_NAME; |
155 | |
156 | if(!device) |
157 | return; |
158 | |
159 | aml_dev = (aml_camera_device_t*) device; |
160 | |
161 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
162 | if( 1 == aml_dev->type ){ |
163 | gVCameraHals->setCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user); |
164 | return; |
165 | } |
166 | #endif |
167 | gCameraHals[aml_dev->cameraid]->setCallbacks(notify_cb, data_cb, data_cb_timestamp, get_memory, user); |
168 | } |
169 | |
170 | void camera_enable_msg_type(struct camera_device * device, int32_t msg_type) |
171 | { |
172 | aml_camera_device_t* aml_dev = NULL; |
173 | |
174 | LOG_FUNCTION_NAME; |
175 | |
176 | if(!device) |
177 | return; |
178 | |
179 | aml_dev = (aml_camera_device_t*) device; |
180 | |
181 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
182 | if( 1 == aml_dev->type ){ |
183 | gVCameraHals->enableMsgType(msg_type); |
184 | return ; |
185 | } |
186 | #endif |
187 | gCameraHals[aml_dev->cameraid]->enableMsgType(msg_type); |
188 | } |
189 | |
190 | void camera_disable_msg_type(struct camera_device * device, int32_t msg_type) |
191 | { |
192 | aml_camera_device_t* aml_dev = NULL; |
193 | |
194 | LOG_FUNCTION_NAME; |
195 | |
196 | if(!device) |
197 | return; |
198 | |
199 | aml_dev = (aml_camera_device_t*) device; |
200 | |
201 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
202 | if( 1 == aml_dev->type ){ |
203 | gVCameraHals->disableMsgType(msg_type); |
204 | return; |
205 | } |
206 | #endif |
207 | gCameraHals[aml_dev->cameraid]->disableMsgType(msg_type); |
208 | } |
209 | |
210 | int camera_msg_type_enabled(struct camera_device * device, int32_t msg_type) |
211 | { |
212 | aml_camera_device_t* aml_dev = NULL; |
213 | |
214 | LOG_FUNCTION_NAME; |
215 | |
216 | if(!device) |
217 | return 0; |
218 | |
219 | aml_dev = (aml_camera_device_t*) device; |
220 | |
221 | return gCameraHals[aml_dev->cameraid]->msgTypeEnabled(msg_type); |
222 | } |
223 | |
224 | int camera_start_preview(struct camera_device * device) |
225 | { |
226 | int rv = -EINVAL; |
227 | aml_camera_device_t* aml_dev = NULL; |
228 | |
229 | LOG_FUNCTION_NAME; |
230 | |
231 | if(!device) |
232 | return rv; |
233 | |
234 | aml_dev = (aml_camera_device_t*) device; |
235 | |
236 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
237 | if( 1 == aml_dev->type ){ |
238 | return gVCameraHals->startPreview(); |
239 | } |
240 | #endif |
241 | rv = gCameraHals[aml_dev->cameraid]->startPreview(); |
242 | |
243 | return rv; |
244 | } |
245 | |
246 | void camera_stop_preview(struct camera_device * device) |
247 | { |
248 | aml_camera_device_t* aml_dev = NULL; |
249 | |
250 | LOG_FUNCTION_NAME; |
251 | |
252 | if(!device) |
253 | return; |
254 | |
255 | aml_dev = (aml_camera_device_t*) device; |
256 | |
257 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
258 | if( 1 == aml_dev->type ){ |
259 | gVCameraHals->stopPreview(); |
260 | return ; |
261 | } |
262 | #endif |
263 | gCameraHals[aml_dev->cameraid]->stopPreview(); |
264 | } |
265 | |
266 | int camera_preview_enabled(struct camera_device * device) |
267 | { |
268 | int rv = -EINVAL; |
269 | aml_camera_device_t* aml_dev = NULL; |
270 | |
271 | LOG_FUNCTION_NAME; |
272 | |
273 | if(!device) |
274 | return rv; |
275 | |
276 | aml_dev = (aml_camera_device_t*) device; |
277 | |
278 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
279 | if( 1 == aml_dev->type ){ |
280 | return gVCameraHals->previewEnabled(); |
281 | } |
282 | #endif |
283 | rv = gCameraHals[aml_dev->cameraid]->previewEnabled(); |
284 | return rv; |
285 | } |
286 | |
287 | int camera_store_meta_data_in_buffers(struct camera_device * device, int enable) |
288 | { |
289 | int rv = -EINVAL; |
290 | aml_camera_device_t* aml_dev = NULL; |
291 | |
292 | LOG_FUNCTION_NAME; |
293 | |
294 | if(!device) |
295 | return rv; |
296 | |
297 | aml_dev = (aml_camera_device_t*) device; |
298 | |
299 | // TODO: meta data buffer not current supported |
300 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
301 | if( 1 == aml_dev->type ){ |
302 | return gVCameraHals->storeMetaDataInBuffers(enable); |
303 | } |
304 | #endif |
305 | rv = gCameraHals[aml_dev->cameraid]->storeMetaDataInBuffers(enable); |
306 | return rv; |
307 | //return enable ? android::INVALID_OPERATION: android::OK; |
308 | } |
309 | |
310 | int camera_start_recording(struct camera_device * device) |
311 | { |
312 | int rv = -EINVAL; |
313 | aml_camera_device_t* aml_dev = NULL; |
314 | |
315 | LOG_FUNCTION_NAME; |
316 | |
317 | if(!device) |
318 | return rv; |
319 | |
320 | aml_dev = (aml_camera_device_t*) device; |
321 | |
322 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
323 | if( 1 == aml_dev->type ){ |
324 | return gVCameraHals->startRecording(); |
325 | } |
326 | #endif |
327 | rv = gCameraHals[aml_dev->cameraid]->startRecording(); |
328 | return rv; |
329 | } |
330 | |
331 | void camera_stop_recording(struct camera_device * device) |
332 | { |
333 | aml_camera_device_t* aml_dev = NULL; |
334 | |
335 | LOG_FUNCTION_NAME; |
336 | |
337 | if(!device) |
338 | return; |
339 | |
340 | aml_dev = (aml_camera_device_t*) device; |
341 | |
342 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
343 | if( 1 == aml_dev->type ){ |
344 | gVCameraHals->stopRecording(); |
345 | return; |
346 | } |
347 | #endif |
348 | gCameraHals[aml_dev->cameraid]->stopRecording(); |
349 | } |
350 | |
351 | int camera_recording_enabled(struct camera_device * device) |
352 | { |
353 | int rv = -EINVAL; |
354 | aml_camera_device_t* aml_dev = NULL; |
355 | |
356 | LOG_FUNCTION_NAME; |
357 | |
358 | if(!device) |
359 | return rv; |
360 | |
361 | aml_dev = (aml_camera_device_t*) device; |
362 | |
363 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
364 | if( 1 == aml_dev->type ){ |
365 | return gVCameraHals->recordingEnabled(); |
366 | } |
367 | #endif |
368 | rv = gCameraHals[aml_dev->cameraid]->recordingEnabled(); |
369 | return rv; |
370 | } |
371 | |
372 | void camera_release_recording_frame(struct camera_device * device, |
373 | const void *opaque) |
374 | { |
375 | aml_camera_device_t* aml_dev = NULL; |
376 | |
377 | LOG_FUNCTION_NAME; |
378 | |
379 | if(!device) |
380 | return; |
381 | |
382 | aml_dev = (aml_camera_device_t*) device; |
383 | |
384 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
385 | if( 1 == aml_dev->type ){ |
386 | gVCameraHals->releaseRecordingFrame(opaque); |
387 | return; |
388 | } |
389 | #endif |
390 | gCameraHals[aml_dev->cameraid]->releaseRecordingFrame(opaque); |
391 | } |
392 | |
393 | int camera_auto_focus(struct camera_device * device) |
394 | { |
395 | int rv = -EINVAL; |
396 | aml_camera_device_t* aml_dev = NULL; |
397 | |
398 | LOG_FUNCTION_NAME; |
399 | |
400 | if(!device) |
401 | return rv; |
402 | |
403 | aml_dev = (aml_camera_device_t*) device; |
404 | |
405 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
406 | if( 1 == aml_dev->type ){ |
407 | return gVCameraHals->autoFocus(); |
408 | } |
409 | #endif |
410 | rv = gCameraHals[aml_dev->cameraid]->autoFocus(); |
411 | return rv; |
412 | } |
413 | |
414 | int camera_cancel_auto_focus(struct camera_device * device) |
415 | { |
416 | int rv = -EINVAL; |
417 | aml_camera_device_t* aml_dev = NULL; |
418 | |
419 | LOG_FUNCTION_NAME; |
420 | |
421 | if(!device) |
422 | return rv; |
423 | |
424 | aml_dev = (aml_camera_device_t*) device; |
425 | |
426 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
427 | if( 1 == aml_dev->type ){ |
428 | return gVCameraHals->cancelAutoFocus(); |
429 | } |
430 | #endif |
431 | rv = gCameraHals[aml_dev->cameraid]->cancelAutoFocus(); |
432 | return rv; |
433 | } |
434 | |
435 | int camera_take_picture(struct camera_device * device) |
436 | { |
437 | int rv = -EINVAL; |
438 | aml_camera_device_t* aml_dev = NULL; |
439 | |
440 | LOG_FUNCTION_NAME; |
441 | |
442 | if(!device) |
443 | return rv; |
444 | |
445 | aml_dev = (aml_camera_device_t*) device; |
446 | |
447 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
448 | if( 1 == aml_dev->type ){ |
449 | return gVCameraHals->takePicture(); |
450 | } |
451 | #endif |
452 | rv = gCameraHals[aml_dev->cameraid]->takePicture(); |
453 | return rv; |
454 | } |
455 | |
456 | int camera_cancel_picture(struct camera_device * device) |
457 | { |
458 | int rv = -EINVAL; |
459 | aml_camera_device_t* aml_dev = NULL; |
460 | |
461 | LOG_FUNCTION_NAME; |
462 | |
463 | if(!device) |
464 | return rv; |
465 | |
466 | aml_dev = (aml_camera_device_t*) device; |
467 | |
468 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
469 | if( 1 == aml_dev->type ){ |
470 | return gVCameraHals->cancelPicture(); |
471 | } |
472 | #endif |
473 | rv = gCameraHals[aml_dev->cameraid]->cancelPicture(); |
474 | return rv; |
475 | } |
476 | |
477 | int camera_set_parameters(struct camera_device * device, const char *params) |
478 | { |
479 | int rv = -EINVAL; |
480 | aml_camera_device_t* aml_dev = NULL; |
481 | |
482 | LOG_FUNCTION_NAME; |
483 | |
484 | if(!device) |
485 | return rv; |
486 | |
487 | aml_dev = (aml_camera_device_t*) device; |
488 | |
489 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
490 | if( 1 == aml_dev->type ){ |
491 | return gVCameraHals->setParameters(params); |
492 | } |
493 | #endif |
494 | rv = gCameraHals[aml_dev->cameraid]->setParameters(params); |
495 | return rv; |
496 | } |
497 | |
498 | char* camera_get_parameters(struct camera_device * device) |
499 | { |
500 | char* param = NULL; |
501 | aml_camera_device_t* aml_dev = NULL; |
502 | |
503 | LOG_FUNCTION_NAME; |
504 | |
505 | if(!device) |
506 | return NULL; |
507 | |
508 | aml_dev = (aml_camera_device_t*) device; |
509 | |
510 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
511 | if( 1 == aml_dev->type ){ |
512 | return gVCameraHals->getParameters(); |
513 | } |
514 | #endif |
515 | param = gCameraHals[aml_dev->cameraid]->getParameters(); |
516 | |
517 | return param; |
518 | } |
519 | |
520 | static void camera_put_parameters(struct camera_device *device, char *parms) |
521 | { |
522 | aml_camera_device_t* aml_dev = NULL; |
523 | |
524 | LOG_FUNCTION_NAME; |
525 | |
526 | if(!device) |
527 | return; |
528 | |
529 | aml_dev = (aml_camera_device_t*) device; |
530 | |
531 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
532 | if( 1 == aml_dev->type ){ |
533 | gVCameraHals->putParameters(parms); |
534 | return ; |
535 | } |
536 | #endif |
537 | gCameraHals[aml_dev->cameraid]->putParameters(parms); |
538 | } |
539 | |
540 | int camera_send_command(struct camera_device * device, |
541 | int32_t cmd, int32_t arg1, int32_t arg2) |
542 | { |
543 | int rv = -EINVAL; |
544 | aml_camera_device_t* aml_dev = NULL; |
545 | |
546 | LOG_FUNCTION_NAME; |
547 | |
548 | if(!device) |
549 | return rv; |
550 | |
551 | aml_dev = (aml_camera_device_t*) device; |
552 | |
553 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
554 | if( 1 == aml_dev->type ){ |
555 | return gVCameraHals->sendCommand(cmd, arg1, arg2); |
556 | } |
557 | #endif |
558 | rv = gCameraHals[aml_dev->cameraid]->sendCommand(cmd, arg1, arg2); |
559 | return rv; |
560 | } |
561 | |
562 | void camera_release(struct camera_device * device) |
563 | { |
564 | aml_camera_device_t* aml_dev = NULL; |
565 | |
566 | LOG_FUNCTION_NAME; |
567 | |
568 | if(!device) |
569 | return; |
570 | |
571 | aml_dev = (aml_camera_device_t*) device; |
572 | |
573 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
574 | if( 1 == aml_dev->type ){ |
575 | gVCameraHals->release(); |
576 | return ; |
577 | } |
578 | #endif |
579 | gCameraHals[aml_dev->cameraid]->release(); |
580 | } |
581 | |
582 | int camera_dump(struct camera_device * device, int fd) |
583 | { |
584 | int rv = -EINVAL; |
585 | aml_camera_device_t* aml_dev = NULL; |
586 | LOG_FUNCTION_NAME; |
587 | |
588 | if(!device) |
589 | return rv; |
590 | |
591 | aml_dev = (aml_camera_device_t*) device; |
592 | |
593 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
594 | if( 1 == aml_dev->type ){ |
595 | return gVCameraHals->dump(fd); |
596 | } |
597 | #endif |
598 | |
599 | setLogLevel(aml_dev->base.priv); |
600 | |
601 | rv = gCameraHals[aml_dev->cameraid]->dump(fd); |
602 | return rv; |
603 | } |
604 | |
605 | extern "C" void heaptracker_free_leaked_memory(void); |
606 | |
607 | int camera_device_close(hw_device_t* device) |
608 | { |
609 | int ret = 0; |
610 | aml_camera_device_t* aml_dev = NULL; |
611 | |
612 | LOG_FUNCTION_NAME; |
613 | |
614 | android::Mutex::Autolock lock(gCameraHalDeviceLock); |
615 | |
616 | if (!device) { |
617 | ret = -EINVAL; |
618 | goto done; |
619 | } |
620 | |
621 | aml_dev = (aml_camera_device_t*) device; |
622 | |
623 | if (aml_dev) { |
624 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
625 | if( 1 == aml_dev->type ){ |
626 | if (gVCameraHals) { |
627 | delete gVCameraHals; |
628 | gVCameraHals = NULL; |
629 | gCamerasOpen--; |
630 | } |
631 | }else{ |
632 | if (gCameraHals[aml_dev->cameraid]) { |
633 | delete gCameraHals[aml_dev->cameraid]; |
634 | gCameraHals[aml_dev->cameraid] = NULL; |
635 | gCamerasOpen--; |
636 | } |
637 | } |
638 | #else |
639 | if (gCameraHals[aml_dev->cameraid]) { |
640 | delete gCameraHals[aml_dev->cameraid]; |
641 | gCameraHals[aml_dev->cameraid] = NULL; |
642 | gCamerasOpen--; |
643 | } |
644 | #endif |
645 | |
646 | if (aml_dev->base.ops) { |
647 | free(aml_dev->base.ops); |
648 | } |
649 | free(aml_dev); |
650 | } |
651 | done: |
652 | #ifdef HEAPTRACKER |
653 | heaptracker_free_leaked_memory(); |
654 | #endif |
655 | return ret; |
656 | } |
657 | |
658 | /******************************************************************* |
659 | * implementation of camera_module functions |
660 | *******************************************************************/ |
661 | |
662 | /* open device handle to one of the cameras |
663 | * |
664 | * assume camera service will keep singleton of each camera |
665 | * so this function will always only be called once per camera instance |
666 | */ |
667 | |
668 | int camera_device_open(const hw_module_t* module, const char* name, |
669 | hw_device_t** device) |
670 | { |
671 | int rv = 0; |
672 | int num_cameras = 0; |
673 | int cameraid; |
674 | aml_camera_device_t* camera_device = NULL; |
675 | camera_device_ops_t* camera_ops = NULL; |
676 | android::CameraHal* camera = NULL; |
677 | android::CameraProperties::Properties* properties = NULL; |
678 | |
679 | android::Mutex::Autolock lock(gCameraHalDeviceLock); |
680 | |
681 | CAMHAL_LOGIA("camera_device open"); |
682 | |
683 | if (name != NULL) { |
684 | cameraid = atoi(name); |
685 | num_cameras = gCameraProperties.camerasSupported(); |
686 | |
687 | if(cameraid > num_cameras) |
688 | { |
689 | CAMHAL_LOGEB("camera service provided cameraid out of bounds," |
690 | "cameraid = %d, num supported = %d", |
691 | cameraid, num_cameras); |
692 | rv = -EINVAL; |
693 | goto fail; |
694 | } |
695 | |
696 | #ifndef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
697 | if(gCamerasOpen >= MAX_SIMUL_CAMERAS_SUPPORTED) |
698 | { |
699 | CAMHAL_LOGEA("maximum number of cameras already open"); |
700 | rv = -ENOMEM; |
701 | goto fail; |
702 | } |
703 | #else |
704 | if((gCamerasOpen >= MAX_SIMUL_CAMERAS_SUPPORTED) && |
705 | (!gVCameraHals) ) |
706 | { |
707 | CAMHAL_LOGEA("maximum number of cameras already open"); |
708 | rv = -ENOMEM; |
709 | goto fail; |
710 | } |
711 | |
712 | CAMHAL_LOGDB("cameraid=%d, num_cameras-1=%d\n", cameraid, num_cameras-1); |
713 | CAMHAL_LOGDB("max_add-1=%d\n", gCamerasSupported-1); |
714 | |
715 | if( cameraid == (gCamerasSupported-1) ) |
716 | { |
717 | camera_device = (aml_camera_device_t*)malloc(sizeof(*camera_device)); |
718 | if(!camera_device) |
719 | { |
720 | CAMHAL_LOGEA("camera_device allocation fail"); |
721 | rv = -ENOMEM; |
722 | goto fail; |
723 | } |
724 | |
725 | camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops)); |
726 | if(!camera_ops) |
727 | { |
728 | CAMHAL_LOGEA("camera_ops allocation fail"); |
729 | rv = -ENOMEM; |
730 | goto fail; |
731 | } |
732 | |
733 | memset(camera_device, 0, sizeof(*camera_device)); |
734 | memset(camera_ops, 0, sizeof(*camera_ops)); |
735 | |
736 | camera_device->base.common.tag = HARDWARE_DEVICE_TAG; |
737 | camera_device->base.common.version = 0; |
738 | camera_device->base.common.module = (hw_module_t *)(module); |
739 | camera_device->base.common.close = camera_device_close; |
740 | camera_device->base.ops = camera_ops; |
741 | |
742 | camera_ops->set_preview_window = camera_set_preview_window; |
743 | camera_ops->set_callbacks = camera_set_callbacks; |
744 | camera_ops->enable_msg_type = camera_enable_msg_type; |
745 | camera_ops->disable_msg_type = camera_disable_msg_type; |
746 | camera_ops->msg_type_enabled = camera_msg_type_enabled; |
747 | camera_ops->start_preview = camera_start_preview; |
748 | camera_ops->stop_preview = camera_stop_preview; |
749 | camera_ops->preview_enabled = camera_preview_enabled; |
750 | camera_ops->store_meta_data_in_buffers = camera_store_meta_data_in_buffers; |
751 | camera_ops->start_recording = camera_start_recording; |
752 | camera_ops->stop_recording = camera_stop_recording; |
753 | camera_ops->recording_enabled = camera_recording_enabled; |
754 | camera_ops->release_recording_frame = camera_release_recording_frame; |
755 | camera_ops->auto_focus = camera_auto_focus; |
756 | camera_ops->cancel_auto_focus = camera_cancel_auto_focus; |
757 | camera_ops->take_picture = camera_take_picture; |
758 | camera_ops->cancel_picture = camera_cancel_picture; |
759 | camera_ops->set_parameters = camera_set_parameters; |
760 | camera_ops->get_parameters = camera_get_parameters; |
761 | camera_ops->put_parameters = camera_put_parameters; |
762 | camera_ops->send_command = camera_send_command; |
763 | camera_ops->release = camera_release; |
764 | camera_ops->dump = camera_dump; |
765 | |
766 | *device = &camera_device->base.common; |
767 | |
768 | // -------- vendor specific stuff -------- |
769 | |
770 | CAMHAL_LOGDB("virtual num_cameras=%d cameraid=%d", num_cameras, cameraid); |
771 | camera_device->cameraid = cameraid; |
772 | camera_device->type = 1; |
773 | |
774 | if(gCameraProperties.getProperties(cameraid, &properties) < 0) |
775 | { |
776 | CAMHAL_LOGEA("Couldn't get virtual camera properties"); |
777 | rv = -ENOMEM; |
778 | goto fail; |
779 | } |
780 | |
781 | gVCameraHals = new android::VirtualCamHal(cameraid); |
782 | CAMHAL_LOGDA("Virtual CameraHal\n"); |
783 | |
784 | if(!gVCameraHals) |
785 | { |
786 | CAMHAL_LOGEA("Couldn't create instance of VirtualCameraHal class"); |
787 | rv = -ENOMEM; |
788 | goto fail; |
789 | } |
790 | |
791 | if(properties && (gVCameraHals->initialize(properties) != android::NO_ERROR)) |
792 | { |
793 | CAMHAL_LOGEA("Couldn't initialize virtual camera instance"); |
794 | rv = -ENODEV; |
795 | goto fail; |
796 | } |
797 | |
798 | gCamerasOpen++; |
799 | |
800 | return rv; |
801 | } |
802 | #endif |
803 | |
804 | camera_device = (aml_camera_device_t*)malloc(sizeof(*camera_device)); |
805 | if(!camera_device) |
806 | { |
807 | CAMHAL_LOGEA("camera_device allocation fail"); |
808 | rv = -ENOMEM; |
809 | goto fail; |
810 | } |
811 | |
812 | camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops)); |
813 | if(!camera_ops) |
814 | { |
815 | CAMHAL_LOGEA("camera_ops allocation fail"); |
816 | rv = -ENOMEM; |
817 | goto fail; |
818 | } |
819 | |
820 | memset(camera_device, 0, sizeof(*camera_device)); |
821 | memset(camera_ops, 0, sizeof(*camera_ops)); |
822 | |
823 | camera_device->base.common.tag = HARDWARE_DEVICE_TAG; |
824 | camera_device->base.common.version = 0; |
825 | camera_device->base.common.module = (hw_module_t *)(module); |
826 | camera_device->base.common.close = camera_device_close; |
827 | camera_device->base.ops = camera_ops; |
828 | |
829 | camera_ops->set_preview_window = camera_set_preview_window; |
830 | camera_ops->set_callbacks = camera_set_callbacks; |
831 | camera_ops->enable_msg_type = camera_enable_msg_type; |
832 | camera_ops->disable_msg_type = camera_disable_msg_type; |
833 | camera_ops->msg_type_enabled = camera_msg_type_enabled; |
834 | camera_ops->start_preview = camera_start_preview; |
835 | camera_ops->stop_preview = camera_stop_preview; |
836 | camera_ops->preview_enabled = camera_preview_enabled; |
837 | camera_ops->store_meta_data_in_buffers = camera_store_meta_data_in_buffers; |
838 | camera_ops->start_recording = camera_start_recording; |
839 | camera_ops->stop_recording = camera_stop_recording; |
840 | camera_ops->recording_enabled = camera_recording_enabled; |
841 | camera_ops->release_recording_frame = camera_release_recording_frame; |
842 | camera_ops->auto_focus = camera_auto_focus; |
843 | camera_ops->cancel_auto_focus = camera_cancel_auto_focus; |
844 | camera_ops->take_picture = camera_take_picture; |
845 | camera_ops->cancel_picture = camera_cancel_picture; |
846 | camera_ops->set_parameters = camera_set_parameters; |
847 | camera_ops->get_parameters = camera_get_parameters; |
848 | camera_ops->put_parameters = camera_put_parameters; |
849 | camera_ops->send_command = camera_send_command; |
850 | camera_ops->release = camera_release; |
851 | camera_ops->dump = camera_dump; |
852 | |
853 | *device = &camera_device->base.common; |
854 | |
855 | // -------- vendor specific stuff -------- |
856 | |
857 | CAMHAL_LOGDB("num_cameras=%d cameraid=%d", num_cameras, cameraid); |
858 | camera_device->cameraid = cameraid; |
859 | #ifdef AMLOGIC_VIRTUAL_CAMERA_SUPPORT |
860 | camera_device->type = 0; |
861 | #endif |
862 | |
863 | if(gCameraProperties.getProperties(cameraid, &properties) < 0) |
864 | { |
865 | CAMHAL_LOGEA("Couldn't get camera properties"); |
866 | rv = -ENOMEM; |
867 | goto fail; |
868 | } |
869 | |
870 | camera = new android::CameraHal(cameraid); |
871 | |
872 | if(!camera) |
873 | { |
874 | CAMHAL_LOGEA("Couldn't create instance of CameraHal class"); |
875 | rv = -ENOMEM; |
876 | goto fail; |
877 | } |
878 | |
879 | if(properties && (camera->initialize(properties) != android::NO_ERROR)) |
880 | { |
881 | CAMHAL_LOGEA("Couldn't initialize camera instance"); |
882 | rv = -ENODEV; |
883 | goto fail; |
884 | } |
885 | |
886 | gCameraHals[cameraid] = camera; |
887 | gCamerasOpen++; |
888 | } |
889 | |
890 | return rv; |
891 | |
892 | fail: |
893 | if(camera_device) { |
894 | free(camera_device); |
895 | camera_device = NULL; |
896 | } |
897 | if(camera_ops) { |
898 | free(camera_ops); |
899 | camera_ops = NULL; |
900 | } |
901 | if(camera) { |
902 | delete camera; |
903 | camera = NULL; |
904 | } |
905 | *device = NULL; |
906 | return rv; |
907 | } |
908 | |
909 | extern "C" int CameraAdapter_CameraNum(); |
910 | int camera_get_number_of_cameras(void) |
911 | { |
912 | int num_cameras = CameraAdapter_CameraNum(); |
913 | gCamerasSupported = num_cameras; |
914 | CAMHAL_LOGDB("gCamerasSupported=%d,num_cameras=%d\n", |
915 | gCamerasSupported, num_cameras); |
916 | |
917 | #ifdef HAVE_VERSION_INFO |
918 | CAMHAL_LOGIB("\n--------------------------------\n" |
919 | "author:aml.sh multi-media team\n" |
920 | "branch name: %s\n" |
921 | "git version: %s \n" |
922 | "last changed: %s\n" |
923 | "build-time: %s\n" |
924 | "build-name: %s\n" |
925 | "uncommitted-file-num:%d\n" |
926 | "ssh user@%s, cd %s\n" |
927 | "hostname %s\n" |
928 | "--------------------------------\n", |
929 | CAMHAL_BRANCH_NAME, |
930 | CAMHAL_GIT_VERSION, |
931 | CAMHAL_LAST_CHANGED, |
932 | CAMHAL_BUILD_TIME, |
933 | CAMHAL_BUILD_NAME, |
934 | CAMHAL_GIT_UNCOMMIT_FILE_NUM, |
935 | CAMHAL_IP, CAMHAL_PATH, CAMHAL_HOSTNAME |
936 | ); |
937 | #endif |
938 | for(unsigned i = 0;i<sizeof(macro_info)/sizeof(macro_info[0]) ;i++){ |
939 | CAMHAL_LOGIB("%s\n", macro_info[i]); |
940 | } |
941 | return num_cameras; |
942 | } |
943 | |
944 | int camera_get_camera_info(int camera_id, struct camera_info *info) |
945 | { |
946 | int rv = 0; |
947 | int face_value = CAMERA_FACING_BACK; |
948 | int orientation = 0; |
949 | const char *valstr = NULL; |
950 | android::CameraProperties::Properties* properties = NULL; |
951 | |
952 | CAMHAL_LOGDB("camera_get_camera_info camera_id=%d", camera_id); |
953 | // this going to be the first call from camera service |
954 | // initialize camera properties here... |
955 | if( ( gCamerasOpen == 0 ) |
956 | && (gCameraProperties.initialize(camera_id) != android::NO_ERROR)) |
957 | { |
958 | CAMHAL_LOGEA("Unable to create or initialize CameraProperties"); |
959 | return -EINVAL; |
960 | } |
961 | |
962 | //Get camera properties for camera index |
963 | if(gCameraProperties.getProperties(camera_id, &properties) < 0) |
964 | { |
965 | CAMHAL_LOGEA("Couldn't get camera properties"); |
966 | rv = -EINVAL; |
967 | goto end; |
968 | } |
969 | |
970 | if(properties) |
971 | { |
972 | valstr = properties->get(android::CameraProperties::FACING_INDEX); |
973 | if(valstr != NULL) |
974 | { |
975 | if (strcmp(valstr, (const char *) android::ExCameraParameters::FACING_FRONT) == 0) |
976 | { |
977 | face_value = CAMERA_FACING_FRONT; |
978 | } |
979 | else if (strcmp(valstr, (const char *) android::ExCameraParameters::FACING_BACK) == 0) |
980 | { |
981 | face_value = CAMERA_FACING_BACK; |
982 | } |
983 | } |
984 | |
985 | valstr = properties->get(android::CameraProperties::ORIENTATION_INDEX); |
986 | if(valstr != NULL) |
987 | { |
988 | orientation = atoi(valstr); |
989 | } |
990 | } |
991 | else |
992 | { |
993 | CAMHAL_LOGEB("getProperties() returned a NULL property set for Camera id %d", camera_id); |
994 | } |
995 | |
996 | info->facing = face_value; |
997 | info->orientation = orientation; |
998 | |
999 | end: |
1000 | return rv; |
1001 | } |
1002 | |
1003 | |
1004 | |
1005 | |
1006 | |
1007 |