summaryrefslogtreecommitdiff
path: root/testcase/camera/camera_hal_interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'testcase/camera/camera_hal_interface.c')
-rw-r--r--testcase/camera/camera_hal_interface.c591
1 files changed, 591 insertions, 0 deletions
diff --git a/testcase/camera/camera_hal_interface.c b/testcase/camera/camera_hal_interface.c
new file mode 100644
index 0000000..a8522ab
--- /dev/null
+++ b/testcase/camera/camera_hal_interface.c
@@ -0,0 +1,591 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jeongmo Yang <jm80.yang@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <dlfcn.h>
+#include <glib.h>
+#include <dlog.h>
+#include "camera_hal_interface.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif /* LOG_TAG */
+#define LOG_TAG "CAMERA_HAL_INTF"
+
+#define LIB_TIZEN_CAMERA "libtizen-camera.so"
+
+struct _camera_hal_interface {
+ void *dl_handle;
+ void *hal_handle;
+ camera_interface_t intf;
+};
+
+
+int camera_hal_interface_init(camera_hal_interface **h)
+{
+ int ret = CAMERA_ERROR_NONE;
+ camera_hal_interface *tmp_h = NULL;
+
+ if (h == NULL) {
+ LOGE("invalid parameter for camera_hal_interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ tmp_h = g_new0(camera_hal_interface, 1);
+ if (tmp_h == NULL) {
+ LOGE("failed to allocate hal interface");
+ return CAMERA_ERROR_OUT_OF_MEMORY;
+ }
+
+ tmp_h->dl_handle = dlopen(LIB_TIZEN_CAMERA, RTLD_NOW);
+ if (tmp_h->dl_handle) {
+ tmp_h->intf.init = dlsym(tmp_h->dl_handle, "camera_init");
+ tmp_h->intf.deinit = dlsym(tmp_h->dl_handle, "camera_deinit");
+ tmp_h->intf.get_device_list = dlsym(tmp_h->dl_handle, "camera_get_device_list");
+ tmp_h->intf.open_device = dlsym(tmp_h->dl_handle, "camera_open_device");
+ tmp_h->intf.close_device = dlsym(tmp_h->dl_handle, "camera_close_device");
+ tmp_h->intf.add_message_callback = dlsym(tmp_h->dl_handle, "camera_add_message_callback");
+ tmp_h->intf.remove_message_callback = dlsym(tmp_h->dl_handle, "camera_remove_message_callback");
+ tmp_h->intf.set_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_set_preview_stream_format");
+ tmp_h->intf.get_preview_stream_format = dlsym(tmp_h->dl_handle, "camera_get_preview_stream_format");
+ tmp_h->intf.start_preview = dlsym(tmp_h->dl_handle, "camera_start_preview");
+ tmp_h->intf.release_preview_buffer = dlsym(tmp_h->dl_handle, "camera_release_preview_buffer");
+ tmp_h->intf.stop_preview = dlsym(tmp_h->dl_handle, "camera_stop_preview");
+ tmp_h->intf.start_auto_focus = dlsym(tmp_h->dl_handle, "camera_start_auto_focus");
+ tmp_h->intf.stop_auto_focus = dlsym(tmp_h->dl_handle, "camera_stop_auto_focus");
+ tmp_h->intf.start_capture = dlsym(tmp_h->dl_handle, "camera_start_capture");
+ tmp_h->intf.stop_capture = dlsym(tmp_h->dl_handle, "camera_stop_capture");
+ tmp_h->intf.set_video_stream_format = dlsym(tmp_h->dl_handle, "camera_set_video_stream_format");
+ tmp_h->intf.get_video_stream_format = dlsym(tmp_h->dl_handle, "camera_get_video_stream_format");
+ tmp_h->intf.start_record = dlsym(tmp_h->dl_handle, "camera_start_record");
+ tmp_h->intf.release_video_buffer = dlsym(tmp_h->dl_handle, "camera_release_video_buffer");
+ tmp_h->intf.stop_record = dlsym(tmp_h->dl_handle, "camera_stop_record");
+ tmp_h->intf.set_command = dlsym(tmp_h->dl_handle, "camera_set_command");
+ tmp_h->intf.get_command = dlsym(tmp_h->dl_handle, "camera_get_command");
+ tmp_h->intf.set_batch_command = dlsym(tmp_h->dl_handle, "camera_set_batch_command");
+
+ if (tmp_h->intf.init == NULL || tmp_h->intf.deinit == NULL) {
+ LOGE("could not get mandatory funtion. %p %1p", tmp_h->intf.init, tmp_h->intf.deinit);
+ ret = CAMERA_ERROR_INTERNAL;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+
+ if (tmp_h->intf.init) {
+ ret = tmp_h->intf.init(&tmp_h->hal_handle);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("camera_init failed 0x%x", ret);
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+ } else {
+ LOGE("no camera_init function");
+ ret = CAMERA_ERROR_INTERNAL;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+ } else {
+ LOGE("dlopen failed [%s][errno %d]", LIB_TIZEN_CAMERA, errno);
+ ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+ goto _CAMERA_HAL_INTERFACE_GET_FAILED;
+ }
+
+ *h = tmp_h;
+
+ return ret;
+
+_CAMERA_HAL_INTERFACE_GET_FAILED:
+ if (tmp_h) {
+ if (tmp_h->dl_handle)
+ dlclose(tmp_h->dl_handle);
+
+ g_free(tmp_h);
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_deinit(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->dl_handle) {
+ ret = h->intf.deinit(h->hal_handle);
+ if (ret != CAMERA_ERROR_NONE) {
+ LOGE("camera_deinit failed 0x%x", ret);
+ return ret;
+ }
+
+ h->hal_handle = NULL;
+
+ dlclose(h->dl_handle);
+ h->dl_handle = NULL;
+ }
+
+ g_free(h);
+
+ return CAMERA_ERROR_NONE;
+}
+
+
+int camera_hal_interface_get_device_list(camera_hal_interface *h, camera_device_list_t *device_list)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_device_list) {
+ ret = h->intf.get_device_list(h->hal_handle, device_list);
+ } else {
+ LOGE("camera_get_device_list not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_open_device(camera_hal_interface *h, int device_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.open_device) {
+ ret = h->intf.open_device(h->hal_handle, device_index);
+ } else {
+ LOGE("camera_open_device not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_close_device(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.close_device) {
+ ret = h->intf.close_device(h->hal_handle);
+ } else {
+ LOGE("camera_close_device not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_add_message_callback(camera_hal_interface *h, camera_message_cb callback, void *user_data, uint32_t *cb_id)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.add_message_callback) {
+ ret = h->intf.add_message_callback(h->hal_handle, callback, user_data, cb_id);
+ } else {
+ LOGE("camera_add_message_callback not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_remove_message_callback(camera_hal_interface *h, uint32_t cb_id)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.remove_message_callback) {
+ ret = h->intf.remove_message_callback(h->hal_handle, cb_id);
+ } else {
+ LOGE("camera_remove_message_callback not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_preview_stream_format) {
+ ret = h->intf.set_preview_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_set_preview_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_preview_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_preview_stream_format) {
+ ret = h->intf.get_preview_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_get_preview_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_preview(camera_hal_interface *h, camera_preview_frame_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_preview) {
+ ret = h->intf.start_preview(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_preview not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_release_preview_buffer(camera_hal_interface *h, int buffer_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.release_preview_buffer) {
+ ret = h->intf.release_preview_buffer(h->hal_handle, buffer_index);
+ } else {
+ LOGE("camera_release_preview_buffer not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_preview(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_preview) {
+ ret = h->intf.stop_preview(h->hal_handle);
+ } else {
+ LOGE("camera_stop_preview not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_auto_focus(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_auto_focus) {
+ ret = h->intf.start_auto_focus(h->hal_handle);
+ } else {
+ LOGE("camera_start_auto_focus not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_auto_focus(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_auto_focus) {
+ ret = h->intf.stop_auto_focus(h->hal_handle);
+ } else {
+ LOGE("camera_stop_auto_focus not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_capture(camera_hal_interface *h, camera_capture_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_capture) {
+ ret = h->intf.start_capture(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_capture not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_capture(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_capture) {
+ ret = h->intf.stop_capture(h->hal_handle);
+ } else {
+ LOGE("camera_stop_capture not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_video_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_video_stream_format) {
+ ret = h->intf.set_video_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_set_video_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_video_stream_format(camera_hal_interface *h, camera_format_t *format)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_video_stream_format) {
+ ret = h->intf.get_video_stream_format(h->hal_handle, format);
+ } else {
+ LOGE("camera_get_video_stream_format not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_start_record(camera_hal_interface *h, camera_video_frame_cb callback, void *user_data)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.start_record) {
+ ret = h->intf.start_record(h->hal_handle, callback, user_data);
+ } else {
+ LOGE("camera_start_record not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_release_video_buffer(camera_hal_interface *h, int buffer_index)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.release_video_buffer) {
+ ret = h->intf.release_video_buffer(h->hal_handle, buffer_index);
+ } else {
+ LOGE("camera_release_video_buffer not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_stop_record(camera_hal_interface *h)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.stop_record) {
+ ret = h->intf.stop_record(h->hal_handle);
+ } else {
+ LOGE("camera_stop_record not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_command(camera_hal_interface *h, int64_t command, void *value)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_command) {
+ ret = h->intf.set_command(h->hal_handle, command, value);
+ } else {
+ LOGE("camera_set_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_get_command(camera_hal_interface *h, int64_t command, void *value)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.get_command) {
+ ret = h->intf.get_command(h->hal_handle, command, value);
+ } else {
+ LOGE("camera_get_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+
+
+int camera_hal_interface_set_batch_command(camera_hal_interface *h, camera_batch_command_control_t *batch_command, int64_t *error_command)
+{
+ int ret = CAMERA_ERROR_NONE;
+
+ if (h == NULL) {
+ LOGE("NULL interface");
+ return CAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ if (h->intf.set_batch_command) {
+ ret = h->intf.set_batch_command(h->hal_handle, batch_command, error_command);
+ } else {
+ LOGE("camera_set_batch_command not implemented");
+ ret = CAMERA_ERROR_NOT_IMPLEMENTED;
+ }
+
+ return ret;
+}
+