[camera] Add new parameter for camera_hal_interface_init() 07/245807/3 accepted/tizen/unified/20201102.124412 submit/tizen/20201029.072218
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 16 Oct 2020 05:04:00 +0000 (14:04 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 16 Oct 2020 06:29:36 +0000 (15:29 +0900)
- The "const char *hal_name" is added to select camera HAl implementation.

[Version] 0.0.31
[Issue Type] New parameter

Change-Id: I1d3acfd69ec9d2f80026d9bba3b49ce16bc74266
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/camera/camera_hal_interface.h
packaging/mm-hal-interface.spec
src/camera/camera_hal_interface.c
testcase/camera/camera_haltests.cpp

index c60dc9d..269cc89 100644 (file)
@@ -29,7 +29,7 @@ extern "C" {
 
 typedef struct _camera_hal_interface camera_hal_interface;
 
-int camera_hal_interface_init(camera_hal_interface **h);
+int camera_hal_interface_init(camera_hal_interface **h, const char *hal_name);
 int camera_hal_interface_deinit(camera_hal_interface *h);
 int camera_hal_interface_get_device_info_list(camera_hal_interface *h, camera_device_info_list_t *device_info_list);
 int camera_hal_interface_open_device(camera_hal_interface *h, int device_index);
index 568504a..9df4160 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       mm-hal-interface
 Summary:    Multimedia HAL Interface
-Version:    0.0.30
+Version:    0.0.31
 Release:    0
 Group:      Multimedia/Development
 License:    Apache-2.0
index 57f8af1..b6ef82c 100644 (file)
@@ -43,10 +43,11 @@ struct _camera_hal_interface {
 };
 
 
-int camera_hal_interface_init(camera_hal_interface **h)
+int camera_hal_interface_init(camera_hal_interface **h, const char *hal_name)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_hal_interface *tmp_h = NULL;
+       gchar *path = NULL;
 
        if (h == NULL) {
                LOGE("invalid parameter for camera_hal_interface");
@@ -54,12 +55,15 @@ int camera_hal_interface_init(camera_hal_interface **h)
        }
 
        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 (hal_name)
+               path = g_strdup_printf("%s/%s", PATH_LIBDIR, hal_name);
+       else
+               path = g_strdup_printf("%s", LIB_TIZEN_CAMERA);
+
+       LOGD("HAL path[%s]", path);
+
+       tmp_h->dl_handle = dlopen(path, 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");
@@ -91,38 +95,28 @@ int camera_hal_interface_init(camera_hal_interface **h)
                if (tmp_h->intf.init == NULL || tmp_h->intf.deinit == NULL) {
                        LOGE("could not get mandatory function. %p %p", tmp_h->intf.init, tmp_h->intf.deinit);
                        ret = CAMERA_ERROR_INTERNAL;
-                       goto _CAMERA_HAL_INTERFACE_GET_FAILED;
-               }
-
-               if (tmp_h->intf.init) {
+               } else {
                        ret = tmp_h->intf.init(&tmp_h->hal_handle);
-                       if (ret != CAMERA_ERROR_NONE) {
+                       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);
+               LOGE("dlopen[%s] failed[%s]", LIB_TIZEN_CAMERA, dlerror());
                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 (ret == CAMERA_ERROR_NONE) {
+               LOGI("interface[%p,%p]", tmp_h, tmp_h->dl_handle);
+               *h = tmp_h;
+       } else {
                if (tmp_h->dl_handle)
                        dlclose(tmp_h->dl_handle);
 
                g_free(tmp_h);
        }
 
+       g_free(path);
+
        return ret;
 }
 
index 3baeb5d..823552d 100644 (file)
@@ -166,7 +166,7 @@ class CameraHalTest : public testing::Test
 
                        system_info_get_platform_bool("http://tizen.org/feature/camera", &camera_supported);
 
-                       ret = camera_hal_interface_init(&h);
+                       ret = camera_hal_interface_init(&h, NULL);
                        if (ret != CAMERA_ERROR_NONE) {
                                cout << "camera hal init failed " << ret << endl;
                                return;
@@ -266,7 +266,7 @@ TEST_F(CameraHalTest, DeinitP)
 
        CAMERA_SUPPORT_CHECK;
 
-       ret = camera_hal_interface_init(&hal_handle);
+       ret = camera_hal_interface_init(&hal_handle, NULL);
 
        EXPECT_EQ(ret, CAMERA_ERROR_NONE);
        EXPECT_NE(hal_handle, nullptr);