2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Jeongmo Yang <jm80.yang@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include "camera_hal_interface.h"
32 #define LOG_TAG "CAMERA_HAL_INTF"
34 #define LIB_TIZEN_CAMERA "libtizen-camera.so"
36 struct _camera_hal_interface {
39 camera_interface_t intf;
43 int camera_hal_interface_init(camera_hal_interface **h)
45 int ret = CAMERA_ERROR_NONE;
46 camera_hal_interface *tmp_h = NULL;
49 LOGE("invalid parameter for camera_hal_interface");
50 return CAMERA_ERROR_INVALID_PARAMETER;
53 tmp_h = g_new0(camera_hal_interface, 1);
55 LOGE("failed to allocate hal interface");
56 return CAMERA_ERROR_OUT_OF_MEMORY;
59 tmp_h->dl_handle = dlopen(LIB_TIZEN_CAMERA, RTLD_NOW);
60 if (tmp_h->dl_handle) {
61 tmp_h->intf.init = dlsym(tmp_h->dl_handle, "camera_init");
62 tmp_h->intf.deinit = dlsym(tmp_h->dl_handle, "camera_deinit");
63 tmp_h->intf.get_device_list = dlsym(tmp_h->dl_handle, "camera_get_device_list");
64 tmp_h->intf.open_device = dlsym(tmp_h->dl_handle, "camera_open_device");
65 tmp_h->intf.close_device = dlsym(tmp_h->dl_handle, "camera_close_device");
66 tmp_h->intf.add_message_callback = dlsym(tmp_h->dl_handle, "camera_add_message_callback");
67 tmp_h->intf.remove_message_callback = dlsym(tmp_h->dl_handle, "camera_remove_message_callback");
68 tmp_h->intf.set_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_set_preview_stream_format");
69 tmp_h->intf.get_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_get_preview_stream_format");
70 tmp_h->intf.start_preview = dlsym(tmp_h->dl_handle, "camera_start_preview");
71 tmp_h->intf.release_preview_buffer = dlsym(tmp_h->dl_handle, "camera_release_preview_buffer");
72 tmp_h->intf.stop_preview = dlsym(tmp_h->dl_handle, "camera_stop_preview");
73 tmp_h->intf.start_auto_focus = dlsym(tmp_h->dl_handle, "camera_start_auto_focus");
74 tmp_h->intf.stop_auto_focus = dlsym(tmp_h->dl_handle, "camera_stop_auto_focus");
75 tmp_h->intf.start_capture = dlsym(tmp_h->dl_handle, "camera_start_capture");
76 tmp_h->intf.stop_capture = dlsym(tmp_h->dl_handle, "camera_stop_capture");
77 tmp_h->intf.set_video_stream_format = dlsym(tmp_h->dl_handle, "camera_set_video_stream_format");
78 tmp_h->intf.get_video_stream_format = dlsym(tmp_h->dl_handle, "camera_get_video_stream_format");
79 tmp_h->intf.start_record = dlsym(tmp_h->dl_handle, "camera_start_record");
80 tmp_h->intf.release_video_buffer = dlsym(tmp_h->dl_handle, "camera_release_video_buffer");
81 tmp_h->intf.stop_record = dlsym(tmp_h->dl_handle, "camera_stop_record");
82 tmp_h->intf.set_command = dlsym(tmp_h->dl_handle, "camera_set_command");
83 tmp_h->intf.get_command = dlsym(tmp_h->dl_handle, "camera_get_command");
84 tmp_h->intf.set_batch_command = dlsym(tmp_h->dl_handle, "camera_set_batch_command");
86 if (tmp_h->intf.init == NULL || tmp_h->intf.deinit == NULL) {
87 LOGE("could not get mandatory funtion. %p %1p", tmp_h->intf.init, tmp_h->intf.deinit);
88 ret = CAMERA_ERROR_INTERNAL;
89 goto _CAMERA_HAL_INTERFACE_GET_FAILED;
92 if (tmp_h->intf.init) {
93 ret = tmp_h->intf.init(&tmp_h->hal_handle);
94 if (ret != CAMERA_ERROR_NONE) {
95 LOGE("camera_init failed 0x%x", ret);
96 goto _CAMERA_HAL_INTERFACE_GET_FAILED;
99 LOGE("no camera_init function");
100 ret = CAMERA_ERROR_INTERNAL;
101 goto _CAMERA_HAL_INTERFACE_GET_FAILED;
104 LOGE("dlopen failed [%s][errno %d]", LIB_TIZEN_CAMERA, errno);
105 ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
106 goto _CAMERA_HAL_INTERFACE_GET_FAILED;
113 _CAMERA_HAL_INTERFACE_GET_FAILED:
115 if (tmp_h->dl_handle)
116 dlclose(tmp_h->dl_handle);
125 int camera_hal_interface_deinit(camera_hal_interface *h)
127 int ret = CAMERA_ERROR_NONE;
130 LOGE("NULL interface");
131 return CAMERA_ERROR_INVALID_PARAMETER;
135 ret = h->intf.deinit(h->hal_handle);
136 if (ret != CAMERA_ERROR_NONE) {
137 LOGE("camera_deinit failed 0x%x", ret);
141 h->hal_handle = NULL;
143 dlclose(h->dl_handle);
149 return CAMERA_ERROR_NONE;
153 int camera_hal_interface_get_device_list(camera_hal_interface *h, camera_device_list_t *device_list)
155 int ret = CAMERA_ERROR_NONE;
158 LOGE("NULL interface");
159 return CAMERA_ERROR_INVALID_PARAMETER;
162 if (h->intf.get_device_list) {
163 ret = h->intf.get_device_list(h->hal_handle, device_list);
165 LOGE("camera_get_device_list not implemented");
166 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
173 int camera_hal_interface_open_device(camera_hal_interface *h, int device_index)
175 int ret = CAMERA_ERROR_NONE;
178 LOGE("NULL interface");
179 return CAMERA_ERROR_INVALID_PARAMETER;
182 if (h->intf.open_device) {
183 ret = h->intf.open_device(h->hal_handle, device_index);
185 LOGE("camera_open_device not implemented");
186 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
193 int camera_hal_interface_close_device(camera_hal_interface *h)
195 int ret = CAMERA_ERROR_NONE;
198 LOGE("NULL interface");
199 return CAMERA_ERROR_INVALID_PARAMETER;
202 if (h->intf.close_device) {
203 ret = h->intf.close_device(h->hal_handle);
205 LOGE("camera_close_device not implemented");
206 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
213 int camera_hal_interface_add_message_callback(camera_hal_interface *h, camera_message_cb callback, void *user_data, uint32_t *cb_id)
215 int ret = CAMERA_ERROR_NONE;
218 LOGE("NULL interface");
219 return CAMERA_ERROR_INVALID_PARAMETER;
222 if (h->intf.add_message_callback) {
223 ret = h->intf.add_message_callback(h->hal_handle, callback, user_data, cb_id);
225 LOGE("camera_add_message_callback not implemented");
226 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
233 int camera_hal_interface_remove_message_callback(camera_hal_interface *h, uint32_t cb_id)
235 int ret = CAMERA_ERROR_NONE;
238 LOGE("NULL interface");
239 return CAMERA_ERROR_INVALID_PARAMETER;
242 if (h->intf.remove_message_callback) {
243 ret = h->intf.remove_message_callback(h->hal_handle, cb_id);
245 LOGE("camera_remove_message_callback not implemented");
246 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
253 int camera_hal_interface_set_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
255 int ret = CAMERA_ERROR_NONE;
258 LOGE("NULL interface");
259 return CAMERA_ERROR_INVALID_PARAMETER;
262 if (h->intf.set_preview_stream_format) {
263 ret = h->intf.set_preview_stream_format(h->hal_handle, format);
265 LOGE("camera_set_preview_stream_format not implemented");
266 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
273 int camera_hal_interface_get_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
275 int ret = CAMERA_ERROR_NONE;
278 LOGE("NULL interface");
279 return CAMERA_ERROR_INVALID_PARAMETER;
282 if (h->intf.get_preview_stream_format) {
283 ret = h->intf.get_preview_stream_format(h->hal_handle, format);
285 LOGE("camera_get_preview_stream_format not implemented");
286 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
293 int camera_hal_interface_start_preview(camera_hal_interface *h, camera_preview_frame_cb callback, void *user_data)
295 int ret = CAMERA_ERROR_NONE;
298 LOGE("NULL interface");
299 return CAMERA_ERROR_INVALID_PARAMETER;
302 if (h->intf.start_preview) {
303 ret = h->intf.start_preview(h->hal_handle, callback, user_data);
305 LOGE("camera_start_preview not implemented");
306 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
313 int camera_hal_interface_release_preview_buffer(camera_hal_interface *h, int buffer_index)
315 int ret = CAMERA_ERROR_NONE;
318 LOGE("NULL interface");
319 return CAMERA_ERROR_INVALID_PARAMETER;
322 if (h->intf.release_preview_buffer) {
323 ret = h->intf.release_preview_buffer(h->hal_handle, buffer_index);
325 LOGE("camera_release_preview_buffer not implemented");
326 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
333 int camera_hal_interface_stop_preview(camera_hal_interface *h)
335 int ret = CAMERA_ERROR_NONE;
338 LOGE("NULL interface");
339 return CAMERA_ERROR_INVALID_PARAMETER;
342 if (h->intf.stop_preview) {
343 ret = h->intf.stop_preview(h->hal_handle);
345 LOGE("camera_stop_preview not implemented");
346 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
353 int camera_hal_interface_start_auto_focus(camera_hal_interface *h)
355 int ret = CAMERA_ERROR_NONE;
358 LOGE("NULL interface");
359 return CAMERA_ERROR_INVALID_PARAMETER;
362 if (h->intf.start_auto_focus) {
363 ret = h->intf.start_auto_focus(h->hal_handle);
365 LOGE("camera_start_auto_focus not implemented");
366 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
373 int camera_hal_interface_stop_auto_focus(camera_hal_interface *h)
375 int ret = CAMERA_ERROR_NONE;
378 LOGE("NULL interface");
379 return CAMERA_ERROR_INVALID_PARAMETER;
382 if (h->intf.stop_auto_focus) {
383 ret = h->intf.stop_auto_focus(h->hal_handle);
385 LOGE("camera_stop_auto_focus not implemented");
386 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
393 int camera_hal_interface_start_capture(camera_hal_interface *h, camera_capture_cb callback, void *user_data)
395 int ret = CAMERA_ERROR_NONE;
398 LOGE("NULL interface");
399 return CAMERA_ERROR_INVALID_PARAMETER;
402 if (h->intf.start_capture) {
403 ret = h->intf.start_capture(h->hal_handle, callback, user_data);
405 LOGE("camera_start_capture not implemented");
406 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
413 int camera_hal_interface_stop_capture(camera_hal_interface *h)
415 int ret = CAMERA_ERROR_NONE;
418 LOGE("NULL interface");
419 return CAMERA_ERROR_INVALID_PARAMETER;
422 if (h->intf.stop_capture) {
423 ret = h->intf.stop_capture(h->hal_handle);
425 LOGE("camera_stop_capture not implemented");
426 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
433 int camera_hal_interface_set_video_stream_format(camera_hal_interface *h, camera_format_t *format)
435 int ret = CAMERA_ERROR_NONE;
438 LOGE("NULL interface");
439 return CAMERA_ERROR_INVALID_PARAMETER;
442 if (h->intf.set_video_stream_format) {
443 ret = h->intf.set_video_stream_format(h->hal_handle, format);
445 LOGE("camera_set_video_stream_format not implemented");
446 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
453 int camera_hal_interface_get_video_stream_format(camera_hal_interface *h, camera_format_t *format)
455 int ret = CAMERA_ERROR_NONE;
458 LOGE("NULL interface");
459 return CAMERA_ERROR_INVALID_PARAMETER;
462 if (h->intf.get_video_stream_format) {
463 ret = h->intf.get_video_stream_format(h->hal_handle, format);
465 LOGE("camera_get_video_stream_format not implemented");
466 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
473 int camera_hal_interface_start_record(camera_hal_interface *h, camera_video_frame_cb callback, void *user_data)
475 int ret = CAMERA_ERROR_NONE;
478 LOGE("NULL interface");
479 return CAMERA_ERROR_INVALID_PARAMETER;
482 if (h->intf.start_record) {
483 ret = h->intf.start_record(h->hal_handle, callback, user_data);
485 LOGE("camera_start_record not implemented");
486 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
493 int camera_hal_interface_release_video_buffer(camera_hal_interface *h, int buffer_index)
495 int ret = CAMERA_ERROR_NONE;
498 LOGE("NULL interface");
499 return CAMERA_ERROR_INVALID_PARAMETER;
502 if (h->intf.release_video_buffer) {
503 ret = h->intf.release_video_buffer(h->hal_handle, buffer_index);
505 LOGE("camera_release_video_buffer not implemented");
506 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
513 int camera_hal_interface_stop_record(camera_hal_interface *h)
515 int ret = CAMERA_ERROR_NONE;
518 LOGE("NULL interface");
519 return CAMERA_ERROR_INVALID_PARAMETER;
522 if (h->intf.stop_record) {
523 ret = h->intf.stop_record(h->hal_handle);
525 LOGE("camera_stop_record not implemented");
526 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
533 int camera_hal_interface_set_command(camera_hal_interface *h, int64_t command, void *value)
535 int ret = CAMERA_ERROR_NONE;
538 LOGE("NULL interface");
539 return CAMERA_ERROR_INVALID_PARAMETER;
542 if (h->intf.set_command) {
543 ret = h->intf.set_command(h->hal_handle, command, value);
545 LOGE("camera_set_command not implemented");
546 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
553 int camera_hal_interface_get_command(camera_hal_interface *h, int64_t command, void *value)
555 int ret = CAMERA_ERROR_NONE;
558 LOGE("NULL interface");
559 return CAMERA_ERROR_INVALID_PARAMETER;
562 if (h->intf.get_command) {
563 ret = h->intf.get_command(h->hal_handle, command, value);
565 LOGE("camera_get_command not implemented");
566 ret = CAMERA_ERROR_NOT_IMPLEMENTED;
573 int camera_hal_interface_set_batch_command(camera_hal_interface *h, camera_batch_command_control_t *batch_command, int64_t *error_command)
575 int ret = CAMERA_ERROR_NONE;
578 LOGE("NULL interface");
579 return CAMERA_ERROR_INVALID_PARAMETER;
582 if (h->intf.set_batch_command) {
583 ret = h->intf.set_batch_command(h->hal_handle, batch_command, error_command);
585 LOGE("camera_set_batch_command not implemented");
586 ret = CAMERA_ERROR_NOT_IMPLEMENTED;