From f1abc8b56d5270825c8fc11a7f11e3f60b3bbcb6 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 2 Apr 2018 20:08:26 +0900 Subject: [PATCH 01/16] Fix coverity issue - Improper use of negative value [Version] 0.3.16 [Profile] Common [Issue Type] Coverity [Dependency module] N/A Change-Id: I74fd52d369c73d1020c1496b96aec60d7d627dc6 Signed-off-by: Jeongmo Yang --- muse/src/muse_camera_dispatcher.c | 7 +++++++ packaging/mmsvc-camera.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 19ccbcd..a4ff8c3 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -1686,6 +1686,13 @@ int camera_dispatcher_start_preview(muse_module_h module) /* privilege check */ client_fd = muse_server_module_get_msg_fd(module); + if (client_fd < 0) { + ret = CAMERA_ERROR_INVALID_OPERATION; + LOGE("failed to get fd %d", client_fd); + muse_camera_msg_return(api, class, ret, module); + return MUSE_CAMERA_ERROR_INVALID; + } + if (!muse_server_security_check_cynara(client_fd, CAMERA_PRIVILEGE_NAME)) { ret = CAMERA_ERROR_PERMISSION_DENIED; LOGE("security check failed 0x%x", ret); diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index fe2f4a8..d9edad7 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.15 +Version: 0.3.16 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From ce199381c7cf2a9f38dff559896d5e8dda4cd747 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 1 Jun 2018 18:27:18 +0900 Subject: [PATCH 02/16] Remove unused code related with sound policy [Version] 0.3.17 [Profile] Common [Issue Type] Update [Dependency module] N/A Change-Id: I98339ab732d3aeb5bfea8b27078fc47bdf99dc34 Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 8 -------- legacy/src/legacy_camera.c | 12 ------------ packaging/mmsvc-camera.spec | 2 +- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index 6b0caf5..7972364 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -48,12 +48,9 @@ typedef enum { CAMERA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ CAMERA_ERROR_DEVICE = CAMERA_ERROR_CLASS | 0x04, /**< Device error */ CAMERA_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Internal error */ - CAMERA_ERROR_SOUND_POLICY = CAMERA_ERROR_CLASS | 0x06, /**< Blocked by Audio Session Manager (Deprecated since 3.0) */ CAMERA_ERROR_SECURITY_RESTRICTED = CAMERA_ERROR_CLASS | 0x07, /**< Restricted by security system policy */ CAMERA_ERROR_DEVICE_BUSY = CAMERA_ERROR_CLASS | 0x08, /**< The device is using another application or working on some operation */ CAMERA_ERROR_DEVICE_NOT_FOUND = CAMERA_ERROR_CLASS | 0x09, /**< No camera device */ - CAMERA_ERROR_SOUND_POLICY_BY_CALL = CAMERA_ERROR_CLASS | 0x0a, /**< Blocked by Audio Session Manager - CALL (Deprecated since 3.0) */ - CAMERA_ERROR_SOUND_POLICY_BY_ALARM = CAMERA_ERROR_CLASS | 0x0b, /**< Blocked by Audio Session Manager - ALARM (Deprecated since 3.0) */ CAMERA_ERROR_ESD = CAMERA_ERROR_CLASS | 0x0c, /**< ESD situation */ CAMERA_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< The access to the resources can not be granted*/ CAMERA_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< The feature is not supported */ @@ -139,9 +136,6 @@ typedef enum { */ typedef enum { CAMERA_POLICY_NONE = 0, /**< None */ - CAMERA_POLICY_SOUND, /**< Sound policy (Deprecated since 3.0) */ - CAMERA_POLICY_SOUND_BY_CALL, /**< Sound policy by CALL (Deprecated since 3.0) */ - CAMERA_POLICY_SOUND_BY_ALARM, /**< Sound policy by ALARM (Deprecated since 3.0) */ CAMERA_POLICY_SECURITY, /**< Security policy */ CAMERA_POLICY_RESOURCE_CONFLICT /**< Resource conflict (Since 3.0) */ } camera_policy_e; @@ -738,7 +732,6 @@ typedef bool (*camera_supported_preview_format_cb)(camera_pixel_format_e format, * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory - * @retval #CAMERA_ERROR_SOUND_POLICY Sound policy error * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_PERMISSION_DENIED The access to the resources can not be granted * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported @@ -800,7 +793,6 @@ int legacy_camera_destroy(camera_h camera); * @retval #CAMERA_ERROR_NONE Successful * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CAMERA_ERROR_INVALID_STATE Invalid state - * @retval #CAMERA_ERROR_SOUND_POLICY Sound policy error * @retval #CAMERA_ERROR_RESOURCE_CONFLICT Resource conflict error * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation * @retval #CAMERA_ERROR_DEVICE_BUSY The device is being used in another application or is performing other operations diff --git a/legacy/src/legacy_camera.c b/legacy/src/legacy_camera.c index 6fb8f5d..b86e3e3 100644 --- a/legacy/src/legacy_camera.c +++ b/legacy/src/legacy_camera.c @@ -105,18 +105,6 @@ int __convert_camera_error_code(const char *func, int code) ret = CAMERA_ERROR_OUT_OF_MEMORY; errorstr = "OUT_OF_MEMORY"; break; - case MM_ERROR_POLICY_BLOCKED: - ret = CAMERA_ERROR_SOUND_POLICY; - errorstr = "ERROR_SOUND_POLICY"; - break; - case MM_ERROR_POLICY_BLOCKED_BY_CALL: - ret = CAMERA_ERROR_SOUND_POLICY_BY_CALL; - errorstr = "ERROR_SOUND_POLICY_BY_CALL"; - break; - case MM_ERROR_POLICY_BLOCKED_BY_ALARM: - ret = CAMERA_ERROR_SOUND_POLICY_BY_ALARM; - errorstr = "ERROR_SOUND_POLICY_BY_ALARM"; - break; case MM_ERROR_POLICY_RESTRICTED: ret = CAMERA_ERROR_SECURITY_RESTRICTED; errorstr = "ERROR_RESTRICTED"; diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index d9edad7..67a091b 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.16 +Version: 0.3.17 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 81f981260c2bdcb9bd711c19cfc568432da24123 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 16 Jul 2018 20:11:22 +0900 Subject: [PATCH 03/16] Support new format - INVZ for depth data [Version] 0.3.18 [Profile] Common [Issue Type] Update [Dependency module] libmm-common, libmm-camcorder Change-Id: I80ba0ed7c363f7b16629ecb40b0e4db98f302089 Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 11 +++++++++++ legacy/src/legacy_camera.c | 4 ++-- muse/src/muse_camera_dispatcher.c | 6 ++++++ packaging/mmsvc-camera.spec | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index 7972364..decf02b 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -117,6 +117,7 @@ typedef enum { CAMERA_PIXEL_FORMAT_ARGB, /**< ARGB pixel format */ CAMERA_PIXEL_FORMAT_JPEG, /**< Encoded pixel format */ CAMERA_PIXEL_FORMAT_H264 = 15, /**< Encoded pixel format : H264 (Since 3.0) */ + CAMERA_PIXEL_FORMAT_INVZ /**< Depth pixel format : INVZ (Since 5.0) */ } camera_pixel_format_e; /** @@ -250,6 +251,16 @@ typedef struct { unsigned int u_size; /**< The size of u data */ unsigned int v_size; /**< The size of v data */ } triple_plane; /**< triple plane frame data */ + + struct { + unsigned char *data; /**< The encoded data pointer */ + unsigned int size; /**< The size of encoded data */ + } encoded_plane; /**< encoded plane frame data */ + + struct { + unsigned char *data; /**< The depth data pointer */ + unsigned int size; /**< The size of depth data */ + } depth_plane; /**< depth plane frame data (Since 5.0) */ } data; } camera_preview_data_s; diff --git a/legacy/src/legacy_camera.c b/legacy/src/legacy_camera.c index b86e3e3..e696790 100644 --- a/legacy/src/legacy_camera.c +++ b/legacy/src/legacy_camera.c @@ -1556,7 +1556,7 @@ int legacy_camera_set_capture_format(camera_h camera, camera_pixel_format_e form return CAMERA_ERROR_INVALID_PARAMETER; } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_H264 || + if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_INVZ || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); return CAMERA_ERROR_INVALID_PARAMETER; @@ -1580,7 +1580,7 @@ int legacy_camera_set_preview_format(camera_h camera, camera_pixel_format_e form return CAMERA_ERROR_INVALID_PARAMETER; } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_H264 || + if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_INVZ || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); return CAMERA_ERROR_INVALID_PARAMETER; diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index a4ff8c3..3bc790b 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -952,6 +952,9 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void case MM_CAM_STREAM_DATA_ENCODED: data_size = stream->data.encoded.length_data; break; + case MM_CAM_STREAM_DATA_DEPTH: + data_size = stream->data.depth.length_data; + break; default: LOGW("unknown data type %d", stream->data_type); break; @@ -995,6 +998,9 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void case MM_CAM_STREAM_DATA_ENCODED: memcpy(buf_pos, stream->data.encoded.data, stream->data.encoded.length_data); break; + case MM_CAM_STREAM_DATA_DEPTH: + memcpy(buf_pos, stream->data.depth.data, stream->data.depth.length_data); + break; default: break; } diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 67a091b..8136683 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.17 +Version: 0.3.18 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 9a288039759e59a02ea9117a7ee5447378a8ef46 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 10 Sep 2018 19:33:51 +0900 Subject: [PATCH 04/16] Update code for RGB data handling in preview callback [Version] 0.3.19 [Profile] Common [Issue Type] Update [Dependency module] N/A [Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-unified_20180910.1] Change-Id: I298c2c20ffa6e7c8224012f4adc03f978bbc5439 Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 5 +++++ muse/src/muse_camera_dispatcher.c | 6 ++++++ packaging/mmsvc-camera.spec | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index decf02b..42753db 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -261,6 +261,11 @@ typedef struct { unsigned char *data; /**< The depth data pointer */ unsigned int size; /**< The size of depth data */ } depth_plane; /**< depth plane frame data (Since 5.0) */ + + struct { + unsigned char *data; /**< The rgb data pointer */ + unsigned int size; /**< The size of rgb data */ + } rgb_plane; /**< rgb plane frame data (Since 5.0) */ } data; } camera_preview_data_s; diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 3bc790b..32c17cd 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -955,6 +955,9 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void case MM_CAM_STREAM_DATA_DEPTH: data_size = stream->data.depth.length_data; break; + case MM_CAM_STREAM_DATA_RGB: + data_size = stream->data.rgb.length_data; + break; default: LOGW("unknown data type %d", stream->data_type); break; @@ -1001,6 +1004,9 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void case MM_CAM_STREAM_DATA_DEPTH: memcpy(buf_pos, stream->data.depth.data, stream->data.depth.length_data); break; + case MM_CAM_STREAM_DATA_RGB: + memcpy(buf_pos, stream->data.rgb.data, stream->data.rgb.length_data); + break; default: break; } diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 8136683..a525e32 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.18 +Version: 0.3.19 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From acaba9a3e4b46bfa297cbf512283002f105c6518 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Tue, 27 Nov 2018 12:30:14 +0900 Subject: [PATCH 05/16] Add unit test - Precondition to run gtests-* : The executable label should be changed to "User" after install : The user should be "owner" [Version] 0.3.21 [Profile] Common [Issue Type] Update [Dependency module] N/A Change-Id: Iaca9b1511552406ccd4e3b1100ec9a400f88ebba Signed-off-by: Jeongmo Yang --- CMakeLists.txt | 3 ++ legacy/CMakeLists.txt | 20 +++---- muse/CMakeLists.txt | 16 +++--- muse/include/muse_camera.h | 2 +- muse/include/muse_camera_internal.h | 2 +- packaging/mmsvc-camera.spec | 20 ++++++- unittest/CMakeLists.txt | 3 ++ unittest/legacy/CMakeLists.txt | 22 ++++++++ unittest/legacy/gtests_legacy_camera.cpp | 89 ++++++++++++++++++++++++++++++++ unittest/legacy/gtests_legacy_camera.h | 27 ++++++++++ unittest/muse/CMakeLists.txt | 22 ++++++++ unittest/muse/gtests_muse_camera.cpp | 52 +++++++++++++++++++ unittest/muse/gtests_muse_camera.h | 27 ++++++++++ 13 files changed, 281 insertions(+), 24 deletions(-) create mode 100644 unittest/CMakeLists.txt create mode 100644 unittest/legacy/CMakeLists.txt create mode 100644 unittest/legacy/gtests_legacy_camera.cpp create mode 100644 unittest/legacy/gtests_legacy_camera.h create mode 100644 unittest/muse/CMakeLists.txt create mode 100644 unittest/muse/gtests_muse_camera.cpp create mode 100644 unittest/muse/gtests_muse_camera.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7441a9f..4d38e81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,9 @@ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/legacy-camera.pc DESTINATION ${LIB_INS ADD_SUBDIRECTORY(legacy) ADD_SUBDIRECTORY(muse) +IF(ENABLE_GTESTS) +ADD_SUBDIRECTORY(unittest) +ENDIF(ENABLE_GTESTS) IF(UNIX) diff --git a/legacy/CMakeLists.txt b/legacy/CMakeLists.txt index 1a02431..dac9bd5 100644 --- a/legacy/CMakeLists.txt +++ b/legacy/CMakeLists.txt @@ -1,14 +1,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - SET(service "legacy") SET(submodule "camera") -# for package file SET(dependents "dlog mm-camcorder capi-base-common") +SET(LEGACY "${service}-${submodule}") -SET(fw_name "${service}-${submodule}") - -PROJECT(${fw_name}) +PROJECT(${LEGACY}) SET(CMAKE_INSTALL_PREFIX /usr) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -17,8 +14,8 @@ SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_name} REQUIRED ${dependents}) -FOREACH(flag ${${fw_name}_CFLAGS}) +pkg_check_modules(${LEGACY} REQUIRED ${dependents}) +FOREACH(flag ${${LEGACY}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -35,17 +32,16 @@ ADD_DEFINITIONS("-DTIZEN_DEBUG") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") aux_source_directory(src LEGACY_SOURCES) -ADD_LIBRARY(${fw_name} SHARED ${LEGACY_SOURCES}) +ADD_LIBRARY(${LEGACY} SHARED ${LEGACY_SOURCES}) -SET_TARGET_PROPERTIES(${fw_name} +SET_TARGET_PROPERTIES(${LEGACY} PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) +TARGET_LINK_LIBRARIES(${LEGACY} ${${LEGACY}_LDFLAGS}) -TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) - -INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(TARGETS ${LEGACY} DESTINATION ${LIB_INSTALL_DIR}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/media FILES_MATCHING diff --git a/muse/CMakeLists.txt b/muse/CMakeLists.txt index 0cfb59c..e76da7c 100644 --- a/muse/CMakeLists.txt +++ b/muse/CMakeLists.txt @@ -3,9 +3,9 @@ SET(service "muse") SET(submodule "camera") SET(dependents "dlog glib-2.0 muse-server mm-common libtbm gstreamer-1.0") -SET(fw_name "${service}-${submodule}") +SET(MUSE_MODULE "${service}-${submodule}") -PROJECT(${fw_name}) +PROJECT(${MUSE_MODULE}) SET(CMAKE_INSTALL_PREFIX /usr) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) @@ -14,8 +14,8 @@ SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_name} REQUIRED ${dependents}) -FOREACH(flag ${${fw_name}_CFLAGS}) +pkg_check_modules(${MUSE_MODULE} REQUIRED ${dependents}) +FOREACH(flag ${${MUSE_MODULE}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -33,16 +33,16 @@ ADD_DEFINITIONS("-DLIBDIR=\"${LIBDIR}\"") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") aux_source_directory(src MUSED_SOURCES) -ADD_LIBRARY(${fw_name} SHARED ${MUSED_SOURCES}) +ADD_LIBRARY(${MUSE_MODULE} SHARED ${MUSED_SOURCES}) -TARGET_LINK_LIBRARIES(${fw_name} legacy-camera ${${fw_name}_LDFLAGS}) +TARGET_LINK_LIBRARIES(${MUSE_MODULE} legacy-camera ${${MUSE_MODULE}_LDFLAGS}) -SET_TARGET_PROPERTIES(${fw_name} +SET_TARGET_PROPERTIES(${MUSE_MODULE} PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) -INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(TARGETS ${MUSE_MODULE} DESTINATION ${LIB_INSTALL_DIR}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/media FILES_MATCHING diff --git a/muse/include/muse_camera.h b/muse/include/muse_camera.h index 990d716..1b2834f 100644 --- a/muse/include/muse_camera.h +++ b/muse/include/muse_camera.h @@ -17,7 +17,7 @@ #ifndef __MUSE_CAMERA_H__ #define __MUSE_CAMERA_H__ -#ifdef _cplusplus +#ifdef __cplusplus extern "C" { #endif diff --git a/muse/include/muse_camera_internal.h b/muse/include/muse_camera_internal.h index a6c6dad..98958f1 100644 --- a/muse/include/muse_camera_internal.h +++ b/muse/include/muse_camera_internal.h @@ -17,7 +17,7 @@ #ifndef __MUSE_CAMERA_INTERNAL_H__ #define __MUSE_CAMERA_INTERNAL_H__ -#ifdef _cplusplus +#ifdef __cplusplus extern "C" { #endif diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index a525e32..e6205a9 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.19 +Version: 0.3.21 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 @@ -12,6 +12,9 @@ BuildRequires: pkgconfig(muse-server) BuildRequires: pkgconfig(mm-camcorder) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libtbm) +%if "%{gtests}" == "1" +BuildRequires: pkgconfig(gmock) +%endif Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -39,7 +42,17 @@ Development related files of a Camera module for muse server. export CFLAGS+=" -DTIZEN_DEBUG_ENABLE" %endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` -%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DLIBDIR=%{_libdir} +%cmake . \ +%if "%{gtests}" == "1" + -DENABLE_GTESTS=On\ +%else + -DENABLE_GTESTS=Off\ +%endif + -DCMAKE_INSTALL_PREFIX=%{_prefix}\ + -DFULLVER=%{version}\ + -DMAJORVER=${MAJORVER}\ + -DLIBDIR=%{_libdir} + make %{?jobs:-j%jobs} @@ -59,6 +72,9 @@ rm -rf %{buildroot} %license LICENSE.APLv2 %{_libdir}/liblegacy-camera.so %{_libdir}/libmuse-camera.so +%if "%{gtests}" == "1" +%{_bindir}/gtests-* +%endif %files devel %{_includedir}/media/*.h diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt new file mode 100644 index 0000000..332ef66 --- /dev/null +++ b/unittest/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +ADD_SUBDIRECTORY(legacy) +ADD_SUBDIRECTORY(muse) diff --git a/unittest/legacy/CMakeLists.txt b/unittest/legacy/CMakeLists.txt new file mode 100644 index 0000000..df43688 --- /dev/null +++ b/unittest/legacy/CMakeLists.txt @@ -0,0 +1,22 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(LEGACY "legacy-camera") +SET(fw_test "gtests-${LEGACY}") + +PROJECT(${fw_test} C CXX) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED glib-2.0 gmock mm-camcorder capi-base-common) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") + MESSAGE(${flag}) +ENDFOREACH() + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Wall") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/legacy/include) +INCLUDE_DIRECTORIES(${REQUIRED_PKGS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${REQUIRED_PKGS_LIBRARY_DIRS}) + +ADD_EXECUTABLE(${fw_test} gtests_legacy_camera.cpp) +TARGET_LINK_LIBRARIES(${fw_test} ${LEGACY} ${LEGACY_LDFLAGS} ${REQUIRED_PKGS_LDFLAGS}) +INSTALL(TARGETS ${fw_test} DESTINATION bin) diff --git a/unittest/legacy/gtests_legacy_camera.cpp b/unittest/legacy/gtests_legacy_camera.cpp new file mode 100644 index 0000000..e6bed50 --- /dev/null +++ b/unittest/legacy/gtests_legacy_camera.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#include "gtests_legacy_camera.h" + +using namespace std; +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + + +class LegacyCameraTestF : public ::testing::Test { + protected: + camera_h handle; + + void SetUp() { + int ret = CAMERA_ERROR_NONE; + + cout << "[SetUp]" << endl; + + ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &handle); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + return; + } + + void TearDown() { + cout << "[TearDown]" << endl << endl; + + if (handle) { + legacy_camera_destroy(handle); + handle = NULL; + } + + return; + } +}; + +TEST(LegacyCameraTest, CreateP) +{ + int ret = CAMERA_ERROR_NONE; + camera_h new_handle = NULL; + + ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &new_handle); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + legacy_camera_destroy(new_handle); +} + +TEST(LegacyCameraTest, DestroyP) +{ + int ret = CAMERA_ERROR_NONE; + camera_h new_handle = NULL; + + ret = legacy_camera_create(CAMERA_DEVICE_CAMERA0, &new_handle); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); + + ret = legacy_camera_destroy(new_handle); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); +} + +TEST_F(LegacyCameraTestF, SetDisplayP) +{ + int ret = CAMERA_ERROR_NONE; + + ret = legacy_camera_set_display(handle, CAMERA_DISPLAY_TYPE_NONE, NULL); + ASSERT_EQ(ret, CAMERA_ERROR_NONE); +} + + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/unittest/legacy/gtests_legacy_camera.h b/unittest/legacy/gtests_legacy_camera.h new file mode 100644 index 0000000..3600926 --- /dev/null +++ b/unittest/legacy/gtests_legacy_camera.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef __LEGACY_CAMERA_UNITTEST_H__ +#define __LEGACY_CAMERA_UNITTEST_H__ + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_LEGACY_CAMERA" + +#endif /*__LEGACY_CAMERA_UNITTEST_H__*/ diff --git a/unittest/muse/CMakeLists.txt b/unittest/muse/CMakeLists.txt new file mode 100644 index 0000000..ee85d08 --- /dev/null +++ b/unittest/muse/CMakeLists.txt @@ -0,0 +1,22 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(MUSE_MODULE "muse-camera") +SET(fw_test "gtests-${MUSE_MODULE}") + +PROJECT(${fw_test} C CXX) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED glib-2.0 gmock) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") + MESSAGE(${flag}) +ENDFOREACH() + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -Wall") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/muse/include) +INCLUDE_DIRECTORIES(${REQUIRED_PKGS_INCLUDE_DIRS}) +LINK_DIRECTORIES(${REQUIRED_PKGS_LIBRARY_DIRS}) + +ADD_EXECUTABLE(${fw_test} gtests_muse_camera.cpp) +TARGET_LINK_LIBRARIES(${fw_test} ${MUSE_MODULE} ${MUSE_MODULE_LDFLAGS} ${REQUIRED_PKGS_LDFLAGS}) +INSTALL(TARGETS ${fw_test} DESTINATION bin) diff --git a/unittest/muse/gtests_muse_camera.cpp b/unittest/muse/gtests_muse_camera.cpp new file mode 100644 index 0000000..33e189e --- /dev/null +++ b/unittest/muse/gtests_muse_camera.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + + +#include "gtests_muse_camera.h" + +using namespace std; +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestCase; + + +class MuseCameraTestF : public ::testing::Test { + protected: + void SetUp() { + cout << "[SetUp]" << endl; + return; + } + + void TearDown() { + cout << "[TearDown]" << endl << endl; + return; + } +}; + +TEST_F(MuseCameraTestF, CreateP) +{ + int ret = 0; + + ASSERT_EQ(ret, 0); +} + + +int main(int argc, char **argv) +{ + InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/unittest/muse/gtests_muse_camera.h b/unittest/muse/gtests_muse_camera.h new file mode 100644 index 0000000..e2770ef --- /dev/null +++ b/unittest/muse/gtests_muse_camera.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +#ifndef __MUSE_CAMERA_UNITTEST_H__ +#define __MUSE_CAMERA_UNITTEST_H__ + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "GTEST_MUSE_CAMERA" + +#endif /*__MUSE_CAMERA_UNITTEST_H__*/ -- 2.7.4 From 6ac42cd3a649e1693c4485cb9e0380d857f22e38 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 7 Feb 2019 19:32:52 +0900 Subject: [PATCH 06/16] Replace tbm_key by tbm_fd for buffer protection - Any other process can access buffer if it knows its tbm_key, but, there is no way to access if it's replaced by tbm_fd. [Version] 0.3.22 [Profile] Common [Issue Type] Update [Dependency module] mmsvc-recorder, capi-media-camera Change-Id: I00cade818977f6a65836eb9a8b8c4064cfddc5c0 Signed-off-by: Jeongmo Yang --- muse/include/muse_camera.h | 8 -- muse/include/muse_camera_internal.h | 11 ++ muse/src/muse_camera_dispatcher.c | 263 ++++++++++++++++++++++++------------ packaging/mmsvc-camera.spec | 2 +- 4 files changed, 187 insertions(+), 97 deletions(-) diff --git a/muse/include/muse_camera.h b/muse/include/muse_camera.h index 1b2834f..4ebdc14 100644 --- a/muse/include/muse_camera.h +++ b/muse/include/muse_camera.h @@ -332,14 +332,6 @@ typedef enum { MUSE_CAMERA_GET_STRING_NUM } muse_camera_get_string_e; -typedef struct { - tbm_bo bo; - int key; - void *internal_buffer; - tbm_bo data_bo; - bool is_capture; -} muse_camera_export_data; - /** * @brief The structure type for muse camera errors. diff --git a/muse/include/muse_camera_internal.h b/muse/include/muse_camera_internal.h index 98958f1..656938f 100644 --- a/muse/include/muse_camera_internal.h +++ b/muse/include/muse_camera_internal.h @@ -39,6 +39,17 @@ extern "C" { typedef struct { + tbm_bo bo; + tbm_bo data_bo; + tbm_fd fd; + tbm_fd data_fd; + tbm_fd buffer_fd[MUSE_NUM_FD]; + int num_buffer_fd; + void *internal_buffer; + bool is_capture; +} muse_camera_export_data; + +typedef struct { int api; int class; int value; diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 32c17cd..d8e3ebf 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -38,9 +38,9 @@ #define MUSED_KEY_FLASH_STATE_RETURN "camera_get_flash_state_return" #define MUSED_KEY_FLASH_STATE_COUNT "camera_get_flash_state_count" -static int _camera_remove_export_data(muse_module_h module, int key, int remove_all); +static int _camera_remove_export_data(muse_module_h module, tbm_fd fd, int remove_all); -static void __camera_dispatcher_send_msg(muse_module_h module, char *msg) +static void __camera_dispatcher_send_msg(muse_module_h module, char *msg, int *tfd) { int len = 0; int sock_fd = 0; @@ -63,7 +63,7 @@ static void __camera_dispatcher_send_msg(muse_module_h module, char *msg) goto _DONE; } - len = muse_core_msg_send(sock_fd, msg); + len = muse_core_msg_send_fd(sock_fd, tfd, msg); if (len <= 0) LOGE("sending message[%s] failed. errno %d", msg, errno); @@ -81,7 +81,7 @@ static void muse_camera_msg_return(int api, int class, int ret, muse_module_h mo MUSE_TYPE_INT, PARAM_GET_TYPE, MUSE_CAMERA_GET_TYPE_NONE, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); return; } @@ -119,7 +119,7 @@ static void muse_camera_msg_return1(int api, int class, int ret, muse_module_h m LOGW("unknown type %d", get_type); } - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); return; } @@ -137,7 +137,7 @@ static void muse_camera_msg_return2(int api, int class, int ret, muse_module_h m MUSE_TYPE_INT, "get_value1", value1, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); return; } @@ -151,7 +151,7 @@ static void muse_camera_msg_event1(int api, int event, int class, muse_module_h MUSE_TYPE_INT, name, value, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); return; } @@ -167,7 +167,23 @@ static void muse_camera_msg_event2(int api, int event, int class, muse_module_h MUSE_TYPE_INT, name1, value1, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); + + return; +} + + +static void muse_camera_msg_event2_fd(int api, int event, int class, muse_module_h module, + const char *name0, int value0, const char *name1, int value1, int *tfd) +{ + char *send_msg = muse_core_msg_new(api, + MUSE_TYPE_INT, PARAM_EVENT, event, + MUSE_TYPE_INT, PARAM_EVENT_CLASS, class, + MUSE_TYPE_INT, name0, value0, + MUSE_TYPE_INT, name1, value1, + 0); + + __camera_dispatcher_send_msg(module, send_msg, tfd); return; } @@ -184,7 +200,24 @@ static void muse_camera_msg_event3(int api, int event, int class, muse_module_h MUSE_TYPE_INT, name2, value2, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); + + return; +} + + +static void muse_camera_msg_event3_fd(int api, int event, int class, muse_module_h module, + const char *name0, int value0, const char *name1, int value1, const char *name2, int value2, int *tfd) +{ + char *send_msg = muse_core_msg_new(api, + MUSE_TYPE_INT, PARAM_EVENT, event, + MUSE_TYPE_INT, PARAM_EVENT_CLASS, class, + MUSE_TYPE_INT, name0, value0, + MUSE_TYPE_INT, name1, value1, + MUSE_TYPE_INT, name2, value2, + 0); + + __camera_dispatcher_send_msg(module, send_msg, tfd); return; } @@ -484,14 +517,15 @@ bool _camera_dispatcher_callback_supported_ptz_type(int param1, void *user_data) return true; } -static int _camera_remove_export_data(muse_module_h module, int key, int remove_all) +static int _camera_remove_export_data(muse_module_h module, tbm_fd fd, int remove_all) { + int i = 0; muse_camera_handle_s *muse_camera = NULL; GList *tmp_list = NULL; muse_camera_export_data *export_data = NULL; - if (module == NULL || (key <= 0 && remove_all == FALSE)) { - LOGE("invalid parameter %p, %d", module, key); + if (module == NULL || (fd < 0 && remove_all == FALSE)) { + LOGE("invalid parameter %p, %d", module, fd); return FALSE; } @@ -509,12 +543,12 @@ static int _camera_remove_export_data(muse_module_h module, int key, int remove_ export_data = (muse_camera_export_data *)tmp_list->data; tmp_list = tmp_list->next; if (export_data) { - if (export_data->key == key || remove_all) { - /*LOGD("key %d matched, remove it (remove_all %d)", key, remove_all);*/ + if (export_data->fd == fd || remove_all) { + /*LOGD("fd %d matched, remove it (remove_all %d)", fd, remove_all);*/ if (remove_all) { - LOGW("remove remained export data key %d, internal buffer %p", - export_data->key, export_data->internal_buffer); + LOGW("remove remained export data fd %d, internal buffer %p", + export_data->fd, export_data->internal_buffer); } if (export_data->is_capture) { @@ -522,32 +556,50 @@ static int _camera_remove_export_data(muse_module_h module, int key, int remove_ g_cond_signal(&muse_camera->list_cond); } + /* unref bo and close exported fd */ if (export_data->bo) { + /*LOGD("close export_data->fd %d", export_data->fd);*/ + + close(export_data->fd); + export_data->fd = -1; + tbm_bo_unref(export_data->bo); export_data->bo = NULL; } else { - LOGW("bo for key %d is NULL", key); + LOGW("bo for fd %d is NULL", fd); } - export_data->key = 0; + /* unref data_bo and exported fd */ + if (export_data->data_bo) { + /*LOGD("close export_data->data_fd %d", export_data->data_fd);*/ - if (export_data->internal_buffer) { - gst_buffer_unref((GstBuffer *)export_data->internal_buffer); - export_data->internal_buffer = NULL; - } + close(export_data->data_fd); + export_data->data_fd = -1; - if (export_data->data_bo) { tbm_bo_unref(export_data->data_bo); export_data->data_bo = NULL; } + /* close exported fd for zero copy buffer */ + for (i = 0 ; i < export_data->num_buffer_fd ; i++) { + /*LOGD("close export_data->buffer_fd[%d] %d", i, export_data->buffer_fd[i]);*/ + close(export_data->buffer_fd[i]); + export_data->buffer_fd[i] = -1; + } + + /* unref GstBuffer */ + if (export_data->internal_buffer) { + gst_buffer_unref((GstBuffer *)export_data->internal_buffer); + export_data->internal_buffer = NULL; + } + muse_camera->data_list = g_list_remove(muse_camera->data_list, export_data); g_free(export_data); export_data = NULL; if (remove_all == FALSE) { - /*LOGD("key %d, remove done");*/ + /*LOGD("fd %d, remove done", fd);*/ g_mutex_unlock(&muse_camera->list_lock); return TRUE; } else { @@ -564,7 +616,7 @@ static int _camera_remove_export_data(muse_module_h module, int key, int remove_ if (remove_all) { LOGW("remove all done"); } else { - LOGE("should not be reached here - key %d", key); + LOGE("should not be reached here - fd %d", fd); } return FALSE; @@ -574,6 +626,7 @@ static int _camera_remove_export_data(muse_module_h module, int key, int remove_ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data) { muse_camera_handle_s *muse_camera = NULL; + int tfd_index = 0; int data_size_main = 0; int data_size_post = 0; int data_size_thumb = 0; @@ -586,9 +639,7 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da muse_camera_export_data *export_data_main = NULL; muse_camera_export_data *export_data_post = NULL; muse_camera_export_data *export_data_thumb = NULL; - int tbm_key_main = 0; - int tbm_key_post = 0; - int tbm_key_thumb = 0; + tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1}; muse_module_h module = (muse_module_h)user_data; unsigned char *buf_pos = NULL; gint64 end_time = 0; @@ -636,17 +687,17 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da tbm_bo_unmap(bo_main); - tbm_key_main = tbm_bo_export(bo_main); - if (tbm_key_main == 0) { - LOGE("Create key_info ERROR!!"); + tfd[tfd_index] = tbm_bo_export_fd(bo_main); + if (tfd[tfd_index] < 0) { + LOGE("export main bo ERROR"); goto main_image_error; } - LOGD("bo %p, vaddr %p, size %d, key %d", - bo_main, bo_main_handle.ptr, data_size_main, tbm_key_main); + LOGD("MAIN: bo %p, vaddr %p, size %d, fd %d", + bo_main, bo_main_handle.ptr, data_size_main, tfd[tfd_index]); /* set bo info */ - export_data_main->key = tbm_key_main; + export_data_main->fd = tfd[tfd_index]; export_data_main->bo = bo_main; export_data_main->is_capture = true; @@ -679,14 +730,15 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da memcpy(buf_pos, postview->data, postview->size); tbm_bo_unmap(bo_post); - tbm_key_post = tbm_bo_export(bo_post); - if (tbm_key_post == 0) { - LOGE("Create key_info ERROR!!"); + tfd_index++; + tfd[tfd_index] = tbm_bo_export_fd(bo_post); + if (tfd[tfd_index] < 0) { + LOGE("export postview ERROR"); goto postview_image_error; } /* set bo info */ - export_data_post->key = tbm_key_post; + export_data_post->fd = tfd[tfd_index]; export_data_post->bo = bo_post; } @@ -719,14 +771,15 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da memcpy(buf_pos, thumbnail->data, thumbnail->size); tbm_bo_unmap(bo_thumb); - tbm_key_thumb = tbm_bo_export(bo_thumb); - if (tbm_key_thumb == 0) { - LOGE("Create key_info ERROR!!"); + tfd_index++; + tfd[tfd_index] = tbm_bo_export_fd(bo_thumb); + if (tfd[tfd_index] < 0) { + LOGE("export thumb ERROR"); goto thumbnail_image_error; } /* set bo info */ - export_data_thumb->key = tbm_key_thumb; + export_data_thumb->fd = tfd[tfd_index]; export_data_thumb->bo = bo_thumb; } @@ -742,10 +795,14 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data_thumb); /* send message */ - muse_camera_msg_event3(MUSE_CAMERA_CB_EVENT, + muse_camera_msg_event3_fd(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_CAPTURE, MUSE_CAMERA_EVENT_CLASS_THREAD_SUB, - module, "tbm_key_main", tbm_key_main, "tbm_key_post", tbm_key_post, "tbm_key_thumb", tbm_key_thumb); + module, + "capture_fd_main", export_data_main->fd, + "capture_fd_post", export_data_post ? export_data_post->fd : -1, + "capture_fd_thumb", export_data_thumb ? export_data_thumb->fd : -1, + (int *)tfd); /* wait for capture callback return */ end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND * 3; @@ -869,20 +926,21 @@ void _camera_dispatcher_interrupt_started_cb(camera_policy_e policy, camera_stat void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void *user_data) { - muse_camera_handle_s *muse_camera = NULL; + int i = 0; int data_size = 0; + int send_ret = 0; + int sock_fd = 0; + muse_camera_handle_s *muse_camera = NULL; tbm_bo bo = NULL; tbm_bo data_bo = NULL; tbm_bo_handle bo_handle = {.ptr = NULL}; tbm_bo_handle data_bo_handle = {.ptr = NULL}; + /* 0: MMCamcorderVideoStreamDataType + 1: data_bo or zero copy bo[0] + 2: zero copy bo[1] + 3: zero copy bo[2] */ + tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1}; muse_camera_export_data *export_data = NULL; - int i = 0; - int tbm_key = 0; - int data_key = 0; - int buffer_key[BUFFER_MAX_PLANE_NUM] = {0, }; - int num_buffer_key = 0; - int send_ret = 0; - int sock_fd = 0; muse_module_h module = (muse_module_h)user_data; unsigned char *buf_pos = NULL; char *send_message = NULL; @@ -906,6 +964,9 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void return; } + export_data->fd = -1; + export_data->data_fd = -1; + data_size = sizeof(MMCamcorderVideoStreamDataType); bo = tbm_bo_alloc(muse_camera->bufmgr, data_size, TBM_BO_DEFAULT); @@ -1014,46 +1075,49 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void tbm_bo_unmap(data_bo); } else { /* zero copy */ - for (i = 0 ; i < BUFFER_MAX_PLANE_NUM ; i++) { + for (i = 0 ; i < MUSE_NUM_FD - 1 ; i++) { if (stream->bo[i]) { - buffer_key[i] = tbm_bo_export(stream->bo[i]); - if (buffer_key[i] == 0) { + tfd[i + 1] = tbm_bo_export_fd(stream->bo[i]); + if (tfd[i + 1] < 0) { LOGE("failed to export bo %p", stream->bo[i]); goto _PREVIEW_CB_ERROR; } - num_buffer_key++; + export_data->buffer_fd[i] = tfd[i + 1]; + export_data->num_buffer_fd++; } else { - /*LOGD("num_buffer_key %d", num_buffer_key);*/ + /*LOGD("num_buffer_fd %d", export_data->num_buffer_fd);*/ break; } } } - tbm_key = tbm_bo_export(bo); - if (tbm_key == 0) { - LOGE("Create key_info ERROR!!"); + tfd[0] = tbm_bo_export_fd(bo); + if (tfd[0] < 0) { + LOGE("export stream data ERROR"); goto _PREVIEW_CB_ERROR; } /* - LOGD("bo %p, vaddr %p, size %d, key %d", - bo, bo_handle.ptr, data_size, tbm_key); + LOGD("bo %p, vaddr %p, size %d, fd %d", + bo, bo_handle.ptr, data_size, tfd[0]); */ /* set bo info */ - export_data->key = tbm_key; + export_data->fd = tfd[0]; export_data->bo = bo; if (stream->internal_buffer) { export_data->internal_buffer = stream->internal_buffer; gst_buffer_ref((GstBuffer *)export_data->internal_buffer); } + if (data_bo) { export_data->data_bo = data_bo; - data_key = tbm_bo_export(data_bo); - if (data_key == 0) { - LOGE("Create key_info for data_bo ERROR!!"); + tfd[1] = tbm_bo_export_fd(data_bo); + if (tfd[1] < 0) { + LOGE("export data bo ERROR"); goto _PREVIEW_CB_ERROR; } + export_data->data_fd = tfd[1]; } /* add bo info to list */ @@ -1064,7 +1128,7 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void if (muse_camera->is_shutting_down) { LOGW("now shutting down.. skip this buffer"); g_mutex_unlock(&muse_camera->list_lock); - _camera_remove_export_data(module, tbm_key, FALSE); + _camera_remove_export_data(module, tfd[0], FALSE); return; } @@ -1076,10 +1140,8 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void send_message = muse_core_msg_new(MUSE_CAMERA_CB_EVENT, MUSE_TYPE_INT, PARAM_EVENT, MUSE_CAMERA_EVENT_TYPE_PREVIEW, MUSE_TYPE_INT, PARAM_EVENT_CLASS, MUSE_CAMERA_EVENT_CLASS_THREAD_SUB, - MUSE_TYPE_INT, "tbm_key", tbm_key, - MUSE_TYPE_INT, "num_buffer_key", num_buffer_key, - MUSE_TYPE_INT, "data_key", data_key, - MUSE_TYPE_ARRAY, "buffer_key", BUFFER_MAX_PLANE_NUM, buffer_key, + MUSE_TYPE_INT, "preview_fd", tfd[0], + MUSE_TYPE_INT, "num_buffer_fd", export_data->num_buffer_fd, 0); sock_fd = muse_server_module_get_msg_fd(module); @@ -1087,7 +1149,7 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void LOGE("failed to get socket fd from module %p", module); send_ret = 0; } else { - send_ret = muse_core_msg_send(sock_fd, send_message); + send_ret = muse_core_msg_send_fd(sock_fd, (int *)tfd, send_message); } muse_core_msg_free(send_message); @@ -1113,11 +1175,33 @@ _PREVIEW_CB_ERROR: tbm_bo_unref(bo); bo = NULL; } + if (data_bo) { tbm_bo_unref(data_bo); data_bo = NULL; } + if (export_data) { + if (export_data->fd >= 0) { + close(export_data->fd); + export_data->fd = -1; + } + + if (export_data->data_fd >= 0) { + close(export_data->data_fd); + export_data->data_fd = -1; + } + + for (i = 0 ; i < export_data->num_buffer_fd ; i++) { + close(export_data->buffer_fd[i]); + export_data->buffer_fd[i] = -1; + } + + if (export_data->internal_buffer) { + gst_buffer_unref(export_data->internal_buffer); + export_data->internal_buffer = NULL; + } + g_free(export_data); export_data = NULL; } @@ -1146,7 +1230,7 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun tbm_bo bo = NULL; tbm_bo_handle bo_handle = {NULL, }; int bo_size = sizeof(camera_detected_face_s) * count; - int tbm_key = 0; + tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1}; muse_camera_export_data *export_data = NULL; if (count >= 0) { @@ -1197,8 +1281,8 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun tbm_bo_unmap(bo); /* export bo */ - tbm_key = tbm_bo_export(bo); - if (tbm_key == 0) { + tfd[0] = tbm_bo_export_fd(bo); + if (tfd[0] < 0) { LOGE("failed to export bo for face detection info"); tbm_bo_unref(bo); @@ -1212,7 +1296,7 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun /* set export data */ export_data->bo = bo; - export_data->key = tbm_key; + export_data->fd = tfd[0]; /* add bo info to list */ g_mutex_lock(&muse_camera->list_lock); @@ -1220,13 +1304,16 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun g_mutex_unlock(&muse_camera->list_lock); } - LOGD("face - count %d, buffer size %d, key %d", count, bo_size, tbm_key); + LOGD("face - count %d, buffer size %d, fd %d", count, bo_size, tfd[0]); /* send message */ - muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT, + muse_camera_msg_event2_fd(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION, MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN, - module, "count", count, "tbm_key", tbm_key); + module, + "count", count, + "face_fd", tfd[0], + (int *)tfd); } else { LOGW("invalid count for face detection - %d", count); } @@ -1467,7 +1554,7 @@ static void _camera_dispatcher_release_resource(muse_module_h module) muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - _camera_remove_export_data(module, 0, TRUE); + _camera_remove_export_data(module, -1, TRUE); g_mutex_clear(&muse_camera->list_lock); g_cond_clear(&muse_camera->list_cond); @@ -4006,7 +4093,7 @@ int camera_dispatcher_attr_get_geotag(muse_module_h module) MUSE_TYPE_ARRAY, "get_value", msg_array_size, get_value, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); } else { muse_camera_msg_return(api, class, ret, module); } @@ -5036,7 +5123,7 @@ int camera_dispatcher_attr_get_display_roi_area(muse_module_h module) MUSE_TYPE_ARRAY, "get_value", 4, get_value, 0); - __camera_dispatcher_send_msg(module, send_msg); + __camera_dispatcher_send_msg(module, send_msg, NULL); } else { muse_camera_msg_return(api, class, ret, module); } @@ -5047,17 +5134,17 @@ int camera_dispatcher_attr_get_display_roi_area(muse_module_h module) int camera_dispatcher_return_buffer(muse_module_h module) { - int tbm_key = 0; + int ret_fd = 0; muse_camera_handle_s *muse_camera = NULL; muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - muse_camera_msg_get(tbm_key, muse_server_module_get_msg(module)); + muse_camera_msg_get(ret_fd, muse_server_module_get_msg(module)); - /*LOGD("handle : %p, key : %d", muse_camera, tbm_key);*/ + /*LOGD("ret_fd : %d", ret_fd);*/ - if (!_camera_remove_export_data(module, tbm_key, FALSE)) - LOGE("remove export data failed : key %d", tbm_key); + if (!_camera_remove_export_data(module, (tbm_fd)ret_fd, FALSE)) + LOGE("remove export data failed : fd %d", ret_fd); return MUSE_CAMERA_ERROR_NONE; } @@ -5443,7 +5530,7 @@ again: legacy_camera_start_preview(muse_camera->camera_handle); /* fall through */ case CAMERA_STATE_PREVIEW: - _camera_remove_export_data(module, 0, TRUE); /* force return buffer before stop preview */ + _camera_remove_export_data(module, -1, TRUE); /* force return buffer before stop preview */ legacy_camera_stop_preview(muse_camera->camera_handle); /* fall through */ case CAMERA_STATE_CREATED: diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index e6205a9..da45e8e 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.21 +Version: 0.3.22 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 2607fee1358ced2bafedec03d0b524d992b840e2 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 20 Feb 2019 17:37:12 +0900 Subject: [PATCH 07/16] Support user buffer fd [Version] 0.3.23 [Profile] Common [Issue Type] Update Change-Id: I0ce2cd72dd353d99f5bfea682be592c967cddf63 Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 25 ++++++++++++ legacy/include/legacy_camera_internal.h | 2 +- legacy/src/legacy_camera.c | 52 +++++++++++++++++++++++++ muse/include/muse_camera_internal.h | 2 + muse/src/muse_camera_dispatcher.c | 69 +++++++++++++++++++++++++++++++-- packaging/mmsvc-camera.spec | 2 +- 6 files changed, 146 insertions(+), 6 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index 42753db..db3a3b9 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -1159,6 +1159,20 @@ int legacy_camera_start_face_detection(camera_h camera, camera_face_detected_cb int legacy_camera_stop_face_detection(camera_h camera); /** + * @brief Sets the buffer fd allocated by user to use as preview buffer. + * @param[in] camera The handle to the camera + * @param[in] fds The buffer fd + * @param[in] number The number of buffer + * @return @c 0 on success, otherwise a negative error value + * @retval #CAMERA_ERROR_NONE Successful + * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CAMERA_ERROR_INVALID_STATE Invalid state + * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported + * @pre The camera state must be set to #CAMERA_STATE_CREATED. + */ +int legacy_camera_set_user_buffer(camera_h camera, int *fds, int number); + +/** * @} */ @@ -3542,6 +3556,17 @@ int legacy_camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled); bool legacy_camera_attr_is_supported_auto_contrast(camera_h camera); /** + * @brief Gets state of support of user buffer. + * @ingroup CAPI_MEDIA_CAMERA_CAPABILITY_MODULE + * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * @param[in] camera The handle to the camera + * @return true on supported, otherwise false + * @exception #CAMERA_ERROR_NONE Successful + * @exception #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter + */ +bool legacy_camera_attr_is_supported_user_buffer(camera_h camera); + +/** * @} */ diff --git a/legacy/include/legacy_camera_internal.h b/legacy/include/legacy_camera_internal.h index 8a41219..4cf9c2a 100644 --- a/legacy/include/legacy_camera_internal.h +++ b/legacy/include/legacy_camera_internal.h @@ -28,7 +28,7 @@ extern "C" { */ /** - * @brief Set pid of client for sound focus API. + * @brief Set pid of client. * @ingroup CAPI_MEDIA_CAMERA_MUSED_MODULE * @param[in] camera The handle to the camera * @param[in] pid The pid of client diff --git a/legacy/src/legacy_camera.c b/legacy/src/legacy_camera.c index e696790..7997764 100644 --- a/legacy/src/legacy_camera.c +++ b/legacy/src/legacy_camera.c @@ -4326,6 +4326,30 @@ bool legacy_camera_attr_is_supported_auto_contrast(camera_h camera) } +bool legacy_camera_attr_is_supported_user_buffer(camera_h camera) +{ + if (camera == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); + return false; + } + + int is_supported; + int ret = MM_ERROR_NONE; + camera_s *handle = (camera_s *)camera; + + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, + MMCAM_SUPPORT_USER_BUFFER, &is_supported, + NULL); + set_last_result(__convert_camera_error_code(__func__, ret)); + if (ret != MM_ERROR_NONE) { + LOGE("MMCAM_SUPPORT_USER_BUFFER get attr failed"); + return false; + } + + return (bool)is_supported; +} + + int legacy_camera_attr_disable_shutter_sound(camera_h camera, bool disable) { if (camera == NULL) { @@ -4808,3 +4832,31 @@ void legacy_camera_send_signal(camera_h camera) return; } + + +int legacy_camera_set_user_buffer(camera_h camera, int *fds, int number) +{ + int ret = MM_ERROR_NONE; + camera_s *handle = NULL; + + if (camera == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + if (!fds || number < 1) { + LOGE("invalid fds %p or number %d", fds, number); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + handle = (camera_s *)camera; + + LOGD("number - %d", number); + + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, + MMCAM_USER_BUFFER_FD, (void *)fds, number, + NULL); + + return __convert_camera_error_code(__func__, ret); +} + diff --git a/muse/include/muse_camera_internal.h b/muse/include/muse_camera_internal.h index 656938f..484d140 100644 --- a/muse/include/muse_camera_internal.h +++ b/muse/include/muse_camera_internal.h @@ -72,6 +72,8 @@ typedef struct { gboolean task_run; muse_module_h module; gboolean is_shutting_down; + int fds[MUSE_NUM_FD]; + int fd_number; } muse_camera_handle_s; diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index d8e3ebf..bcc4296 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -1397,6 +1397,7 @@ static void _camera_task_add_job(muse_camera_handle_s *muse_camera, int api, int static void __camera_task_process_job(muse_camera_handle_s *muse_camera, muse_camera_task_job_s *job) { + int i = 0; int ret = CAMERA_ERROR_NONE; if (!muse_camera) { @@ -1409,6 +1410,15 @@ static void __camera_task_process_job(muse_camera_handle_s *muse_camera, muse_ca switch (job->api) { case MUSE_CAMERA_API_STOP_PREVIEW: ret = legacy_camera_stop_preview(muse_camera->camera_handle); + + if (ret == CAMERA_ERROR_NONE && muse_camera->fd_number > 0) { + for (i = 0 ; i < muse_camera->fd_number ; i++) { + LOGD("close user buffer fd[%d] %d", i, muse_camera->fds[i]); + close(muse_camera->fds[i]); + muse_camera->fds[i] = -1; + } + muse_camera->fd_number = 0; + } break; case MUSE_CAMERA_API_START_CAPTURE: ret = legacy_camera_start_capture(muse_camera->camera_handle, @@ -1595,9 +1605,12 @@ static void _camera_dispatcher_release_resource(muse_module_h module) int camera_dispatcher_create(muse_module_h module) { int ret = CAMERA_ERROR_NONE; - int device_type; + int device_type = 0; + int preview_format = CAMERA_PIXEL_FORMAT_INVALID; + int user_buffer_supported = 0; int pid = 0; bool camera_feature_supported = false; + char *send_msg = NULL; void *gdbus_connection = NULL; muse_camera_handle_s *muse_camera = NULL; muse_camera_api_e api = MUSE_CAMERA_API_CREATE; @@ -1683,6 +1696,14 @@ int camera_dispatcher_create(muse_module_h module) goto _CREATE_ERROR; } + ret = legacy_camera_get_preview_format(muse_camera->camera_handle, &preview_format); + if (ret != CAMERA_ERROR_NONE) { + LOGE("legacy_camera_get_preview_format failed : 0x%x", ret); + goto _CREATE_ERROR; + } + + user_buffer_supported = legacy_camera_attr_is_supported_user_buffer(muse_camera->camera_handle); + g_mutex_init(&muse_camera->list_lock); g_cond_init(&muse_camera->list_cond); g_mutex_init(&muse_camera->preview_cb_lock); @@ -1690,10 +1711,19 @@ int camera_dispatcher_create(muse_module_h module) muse_camera->preview_cb_flag = 0; muse_camera->module = module; - LOGD("handle : %p", muse_camera); + LOGD("handle : %p, user buffer %d", muse_camera, user_buffer_supported); muse_server_ipc_set_handle(module, (intptr_t)muse_camera); - muse_camera_msg_return1(api, class, ret, module, MUSE_CAMERA_GET_TYPE_POINTER, -1, "handle", 0, muse_camera); + + send_msg = muse_core_msg_new(api, + MUSE_TYPE_INT, PARAM_API_CLASS, class, + MUSE_TYPE_INT, PARAM_RET, ret, + MUSE_TYPE_INT, "preview_format", preview_format, + MUSE_TYPE_INT, "user_buffer_supported", user_buffer_supported, + MUSE_TYPE_POINTER, "handle", muse_camera, + 0); + + __camera_dispatcher_send_msg(module, send_msg, NULL); return MUSE_CAMERA_ERROR_NONE; @@ -1773,8 +1803,11 @@ int camera_dispatcher_destroy(muse_module_h module) int camera_dispatcher_start_preview(muse_module_h module) { + int i = 0; int ret = CAMERA_ERROR_NONE; int client_fd = -1; + int fds[MUSE_NUM_FD] = {-1, -1, -1, -1}; + int fd_number = 0; muse_camera_handle_s *muse_camera = NULL; muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW; muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE; @@ -1799,10 +1832,38 @@ int camera_dispatcher_start_preview(muse_module_h module) return MUSE_CAMERA_ERROR_INVALID; } - ret = legacy_camera_start_preview(muse_camera->camera_handle); + /* get user buffer fd */ + if (muse_server_ipc_get_fds(module, fds, &fd_number) == MM_ERROR_NONE) { + /* set user buffer */ + if (fd_number > 0) { + ret = legacy_camera_set_user_buffer(muse_camera->camera_handle, fds, fd_number); + LOGD("fd number %d, ret 0x%x", fd_number, ret); + } + } + + ret |= legacy_camera_start_preview(muse_camera->camera_handle); muse_camera_msg_return(api, class, ret, module); + /* fd handling */ + if (fd_number > 0) { + if (ret == CAMERA_ERROR_NONE) { + /* set fd and number */ + for (i = 0 ; i < fd_number ; i++) + muse_camera->fds[i] = fds[i]; + + muse_camera->fd_number = fd_number; + } else { + /* close exported fd */ + for (i = 0 ; i < fd_number ; i++) { + LOGE("[PREVIEW FAILED] close exported fds[%d] %d", i, fds[i]); + close(fds[i]); + } + + muse_camera->fd_number = 0; + } + } + return MUSE_CAMERA_ERROR_NONE; } diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index da45e8e..7f845b2 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.22 +Version: 0.3.23 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 635270867fabcc616e84756cba9e720f680bdb56 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 13 Jun 2019 10:31:00 +0900 Subject: [PATCH 08/16] Fix bug - The minus value could not be sent for setting pan/tilt [Version] 0.3.24 [Profile] Common [Issue Type] Bug fix Change-Id: Ib71a608cbf56c760618ed7eb24f44ada66dcdb7f Signed-off-by: Jeongmo Yang --- muse/src/muse_camera_dispatcher.c | 30 ++++++++++++------------------ packaging/mmsvc-camera.spec | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index bcc4296..e488775 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -4947,22 +4947,19 @@ int camera_dispatcher_attr_set_pan(muse_module_h module) { int ret = CAMERA_ERROR_NONE; muse_camera_handle_s *muse_camera = NULL; - int value = 0; - int type = 0; - int step = 0; + int move_type = 0; + int pan_step = 0; muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_PAN; muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE; muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - muse_camera_msg_get(value, muse_server_module_get_msg(module)); - - type = value >> 16; - step = 0x0000ffff & value; + muse_camera_msg_get(move_type, muse_server_module_get_msg(module)); + muse_camera_msg_get(pan_step, muse_server_module_get_msg(module)); - LOGD("handle : %p - type %d, step %d", muse_camera, type, step); + LOGD("handle : %p - type %d, step %d", muse_camera, move_type, pan_step); - ret = legacy_camera_attr_set_pan(muse_camera->camera_handle, type, step); + ret = legacy_camera_attr_set_pan(muse_camera->camera_handle, move_type, pan_step); LOGD("ret : 0x%x", ret); @@ -5022,22 +5019,19 @@ int camera_dispatcher_attr_set_tilt(muse_module_h module) { int ret = CAMERA_ERROR_NONE; muse_camera_handle_s *muse_camera = NULL; - int value = 0; - int type = 0; - int step = 0; + int move_type = 0; + int tilt_step = 0; muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_TILT; muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE; muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - muse_camera_msg_get(value, muse_server_module_get_msg(module)); - - type = value >> 16; - step = 0x0000ffff & value; + muse_camera_msg_get(move_type, muse_server_module_get_msg(module)); + muse_camera_msg_get(tilt_step, muse_server_module_get_msg(module)); - LOGD("handle : %p - type %d, step %d", muse_camera, type, step); + LOGD("handle : %p - type %d, step %d", muse_camera, move_type, tilt_step); - ret = legacy_camera_attr_set_tilt(muse_camera->camera_handle, type, step); + ret = legacy_camera_attr_set_tilt(muse_camera->camera_handle, move_type, tilt_step); LOGD("ret : 0x%x", ret); diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 7f845b2..f8744c3 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.23 +Version: 0.3.24 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From cda24c61a15725e11df088d40769e0af0c2b1b89 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 8 Nov 2019 18:40:45 +0900 Subject: [PATCH 09/16] Change dispatcher interface for display setting [Version] 0.3.25 [Profile] Common [Issue Type] Update Change-Id: Id0110f89854c09ea03fb8916470abbbefa49d4d3 Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 8 ++++++ muse/include/muse_camera.h | 10 +++++++ muse/include/muse_camera_internal.h | 2 +- muse/src/muse_camera_dispatcher.c | 55 +++++++++++++++++++------------------ packaging/mmsvc-camera.spec | 2 +- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index db3a3b9..c7d5a07 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -270,6 +270,14 @@ typedef struct { } camera_preview_data_s; /** + * @brief The structure type to display information. + */ +typedef struct { + int surface_id; + MMRectType rect; +} camera_window_info_s; + +/** * @brief The Camera handle. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @see legacy_recorder_create_videorecorder() diff --git a/muse/include/muse_camera.h b/muse/include/muse_camera.h index 4ebdc14..a50c299 100644 --- a/muse/include/muse_camera.h +++ b/muse/include/muse_camera.h @@ -28,6 +28,7 @@ extern "C" { #include #include +#include /** @@ -342,6 +343,15 @@ typedef enum { } muse_camera_error_e; /** + * @brief The structure type for muse camera errors. + */ +typedef struct { + int type; + int parent_id; + MMRectType window_rect; +} muse_camera_display_info_s; + +/** * @brief Definition for the callback event id. */ #define MUSE_CAMERA_CB_EVENT MUSE_CAMERA_API_MAX + 1 /* 148 */ diff --git a/muse/include/muse_camera_internal.h b/muse/include/muse_camera_internal.h index 484d140..cb087dd 100644 --- a/muse/include/muse_camera_internal.h +++ b/muse/include/muse_camera_internal.h @@ -64,7 +64,7 @@ typedef struct { GMutex preview_cb_lock; GCond preview_cb_cond; guint preview_cb_flag; - gint parent_id; + camera_window_info_s window_info; GThread *task_thread; GMutex task_lock; GCond task_cond; diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index e488775..8bc18ad 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -2150,11 +2150,10 @@ int camera_dispatcher_stop_focusing(muse_module_h module) int camera_dispatcher_set_display(muse_module_h module) { int ret = CAMERA_ERROR_NONE; - int parent_id = 0; muse_camera_handle_s *muse_camera = NULL; muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY; muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE; - camera_display_type_e type = CAMERA_DISPLAY_TYPE_NONE; + muse_camera_display_info_s dp_info = {0, }; camera_h camera = NULL;; muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); @@ -2163,37 +2162,39 @@ int camera_dispatcher_set_display(muse_module_h module) camera = muse_camera->camera_handle; - muse_camera_msg_get(type, muse_server_module_get_msg(module)); + muse_core_msg_deserialize("dp_info", muse_server_module_get_msg(module), + NULL, NULL, MUSE_TYPE_ARRAY, (void *)&dp_info); - LOGD("type %d", type); + LOGD("type %d, parent id %d (%d,%d,%dx%d)", + dp_info.type, dp_info.parent_id, + dp_info.window_rect.x, dp_info.window_rect.y, + dp_info.window_rect.width, dp_info.window_rect.height); - if (type == CAMERA_DISPLAY_TYPE_OVERLAY) { - muse_camera_msg_get(parent_id, muse_server_module_get_msg(module)); + /* set window info */ + muse_camera->window_info.surface_id = dp_info.parent_id; + muse_camera->window_info.rect = dp_info.window_rect; - LOGD("wayland global surface id : %d", parent_id); - - muse_camera->parent_id = parent_id; - - ret = legacy_camera_set_display(muse_camera->camera_handle, type, (void *)&muse_camera->parent_id); - - muse_camera_msg_return(api, class, ret, module); - } else { + switch (dp_info.type) { + case CAMERA_DISPLAY_TYPE_OVERLAY: + LOGD("wayland global surface id : %d", muse_camera->window_info.surface_id); + ret = legacy_camera_set_display(muse_camera->camera_handle, + CAMERA_DISPLAY_TYPE_OVERLAY, (void *)&muse_camera->window_info); + break; + case CAMERA_DISPLAY_TYPE_EVAS: + ret = legacy_camera_set_preview_cb(muse_camera->camera_handle, + (camera_preview_cb)_camera_dispatcher_preview_cb, (void *)module); + if (ret == CAMERA_ERROR_NONE) + SET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_EVAS); + /* fall through */ + default: LOGD("NOT overlay type. set NONE type."); - - if (type == CAMERA_DISPLAY_TYPE_EVAS) { - ret = legacy_camera_set_preview_cb(muse_camera->camera_handle, - (camera_preview_cb)_camera_dispatcher_preview_cb, - (void *)module); - - if (ret == CAMERA_ERROR_NONE) - SET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_EVAS); - } - - ret = legacy_camera_set_display(muse_camera->camera_handle, CAMERA_DISPLAY_TYPE_NONE, NULL); - - muse_camera_msg_return(api, class, ret, module); + ret = legacy_camera_set_display(muse_camera->camera_handle, + CAMERA_DISPLAY_TYPE_NONE, NULL); + break; } + muse_camera_msg_return(api, class, ret, module); + return MUSE_CAMERA_ERROR_NONE; } diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index f8744c3..2f1e4c8 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.24 +Version: 0.3.25 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 66ac887faa293d3efb2de82701b63ec3385e7d47 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 4 Dec 2019 15:53:24 +0900 Subject: [PATCH 10/16] Modify condition to wait returned buffer in preview cb - No need to wait when non-zero copy buffer is used. - Need to wait when user callback is set. [Version] 0.3.26 [Profile] Common [Issue Type] Update Change-Id: If1b2c9aa5b903ddc31875bfb4cb9571fc1b70cf2 Signed-off-by: Jeongmo Yang --- muse/include/muse_camera_internal.h | 5 +++-- muse/src/muse_camera_dispatcher.c | 15 +++++++-------- packaging/mmsvc-camera.spec | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/muse/include/muse_camera_internal.h b/muse/include/muse_camera_internal.h index cb087dd..2c8645d 100644 --- a/muse/include/muse_camera_internal.h +++ b/muse/include/muse_camera_internal.h @@ -30,8 +30,9 @@ extern "C" { #include #include -#define PREVIEW_CB_TYPE_USER 0x0000000F -#define PREVIEW_CB_TYPE_EVAS 0x000000F0 +#define PREVIEW_CB_TYPE_USER 0x0000000F +#define PREVIEW_CB_TYPE_EVAS 0x000000F0 +#define PREVIEW_CB_TYPE_MEDIA_PACKET 0x00000F00 #define CHECK_PREVIEW_CB(muse_camera, cb_type) ((muse_camera)->preview_cb_flag & cb_type) #define SET_PREVIEW_CB_TYPE(muse_camera, cb_type) ((muse_camera)->preview_cb_flag |= cb_type) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 8bc18ad..8927514 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -1154,16 +1154,12 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void muse_core_msg_free(send_message); - /*LOGD("wait preview callback return message");*/ - - if (!CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_EVAS) && send_ret > 0) { + if (stream->bo[0] && send_ret > 0 && + CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_USER) && + CHECK_PREVIEW_CB(muse_camera, PREVIEW_CB_TYPE_MEDIA_PACKET)) { gint64 end_time = g_get_monotonic_time() + G_TIME_SPAN_SECOND; - - if (!g_cond_wait_until(&muse_camera->preview_cb_cond, &muse_camera->preview_cb_lock, end_time)) { + if (!g_cond_wait_until(&muse_camera->preview_cb_cond, &muse_camera->preview_cb_lock, end_time)) LOGW("preview callback return message timeout"); - } else { - /*LOGD("preview callback return message received");*/ - } } g_mutex_unlock(&muse_camera->preview_cb_lock); @@ -1457,8 +1453,11 @@ static void __camera_task_process_job(muse_camera_handle_s *muse_camera, muse_ca ret = legacy_camera_set_media_packet_preview_cb(muse_camera->camera_handle, (camera_preview_cb)_camera_dispatcher_preview_cb, (void *)muse_camera->module); + if (ret == CAMERA_ERROR_NONE) + SET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_MEDIA_PACKET); break; case MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB: + UNSET_PREVIEW_CB_TYPE(muse_camera, PREVIEW_CB_TYPE_MEDIA_PACKET); ret = legacy_camera_unset_media_packet_preview_cb(muse_camera->camera_handle); break; default: diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 2f1e4c8..0022046 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.25 +Version: 0.3.26 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 4edbbced453bd1a04e4c59462662d3838c0d1064 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 9 Dec 2019 14:04:52 +0900 Subject: [PATCH 11/16] Get client pid from socket credential for security [Version] 0.3.27 [Profile] Common [Issue Type] Security Change-Id: I7da5cc08d3fb135759ffbc5f43270cf2918ab7c9 Signed-off-by: Jeongmo Yang --- muse/src/muse_camera_dispatcher.c | 2 +- packaging/mmsvc-camera.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 8927514..a9ee803 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -1616,7 +1616,7 @@ int camera_dispatcher_create(muse_module_h module) muse_camera_api_class_e class = MUSE_CAMERA_API_CLASS_IMMEDIATE; muse_camera_msg_get(device_type, muse_server_module_get_msg(module)); - muse_camera_msg_get(pid, muse_server_module_get_msg(module)); + pid = muse_server_ipc_get_client_pid(module); LOGD("device type : %d, client pid : %d", device_type, pid); diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 0022046..4631b98 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.26 +Version: 0.3.27 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 35d9096699727220262345c5ca42302fdd4c539a Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 7 Feb 2020 14:21:50 +0900 Subject: [PATCH 12/16] Support MJPEG format and update camera_preview_data_s [Version] 0.3.28 [Profile] Common [Issue Type] Update Change-Id: Ia2da39ca9e5e775085067a195c374b5511b877ba Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 4 +++- legacy/src/legacy_camera.c | 4 ++-- packaging/mmsvc-camera.spec | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index c7d5a07..a89de94 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -117,7 +117,8 @@ typedef enum { CAMERA_PIXEL_FORMAT_ARGB, /**< ARGB pixel format */ CAMERA_PIXEL_FORMAT_JPEG, /**< Encoded pixel format */ CAMERA_PIXEL_FORMAT_H264 = 15, /**< Encoded pixel format : H264 (Since 3.0) */ - CAMERA_PIXEL_FORMAT_INVZ /**< Depth pixel format : INVZ (Since 5.0) */ + CAMERA_PIXEL_FORMAT_INVZ, /**< Depth pixel format : INVZ (Since 5.0) */ + CAMERA_PIXEL_FORMAT_MJPEG /**< Encoded pixel format : Motion JPEG for preview (Since 6.0) */ } camera_pixel_format_e; /** @@ -255,6 +256,7 @@ typedef struct { struct { unsigned char *data; /**< The encoded data pointer */ unsigned int size; /**< The size of encoded data */ + bool is_delta_frame; /**< The flag whether it's delta frame or not (Since 6.0) */ } encoded_plane; /**< encoded plane frame data */ struct { diff --git a/legacy/src/legacy_camera.c b/legacy/src/legacy_camera.c index 7997764..0583f92 100644 --- a/legacy/src/legacy_camera.c +++ b/legacy/src/legacy_camera.c @@ -1556,7 +1556,7 @@ int legacy_camera_set_capture_format(camera_h camera, camera_pixel_format_e form return CAMERA_ERROR_INVALID_PARAMETER; } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_INVZ || + if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_MJPEG || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); return CAMERA_ERROR_INVALID_PARAMETER; @@ -1580,7 +1580,7 @@ int legacy_camera_set_preview_format(camera_h camera, camera_pixel_format_e form return CAMERA_ERROR_INVALID_PARAMETER; } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_INVZ || + if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_MJPEG || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); return CAMERA_ERROR_INVALID_PARAMETER; diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 4631b98..eeb44b7 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.27 +Version: 0.3.28 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From a89bfbca206bb486ee711c89a3675533378641be Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 19 Mar 2020 18:24:34 +0900 Subject: [PATCH 13/16] Remove dispatcher initialization command function - The plugin preload function can be performed by muse-server itself with mused.conf file [Version] 0.3.29 [Profile] Common [Issue Type] Clean up Change-Id: I99a0015bcabbbc8b5b18d176608d80941ba2accb Signed-off-by: Jeongmo Yang --- muse/src/muse_camera_dispatcher.c | 35 +---------------------------------- packaging/mmsvc-camera.spec | 2 +- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index a9ee803..3107120 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -5502,39 +5502,6 @@ int (*dispatcher[MUSE_CAMERA_API_MAX]) (muse_module_h module) = { /******************/ /* cmd dispatcher */ /******************/ -static int camera_cmd_dispatcher_initialize(muse_module_h module) -{ - int item_count = 0; - int i = 0; - GstPlugin *plugin = NULL; - - const char *load_list[] = { - LIBDIR"/gstreamer-1.0/libgstcoreelements.so", - LIBDIR"/gstreamer-1.0/libgstcamerasrc.so", - LIBDIR"/gstreamer-1.0/libgstwaylandsink.so", - }; - - item_count = sizeof(load_list) / sizeof(load_list[0]); - - LOGD("item count %d", item_count); - - for (i = 0 ; i < item_count ; i++) { - plugin = gst_plugin_load_file(load_list[i], NULL); - if (plugin) { - LOGD("%s loaded", load_list[i]); - gst_object_unref(plugin); - plugin = NULL; - } else { - LOGW("failed to load %s", load_list[i]); - } - } - - LOGD("done"); - - return MUSE_CAMERA_ERROR_NONE; -} - - static int camera_cmd_dispatcher_shutdown(muse_module_h module) { muse_camera_handle_s *muse_camera = NULL; @@ -5607,7 +5574,7 @@ again: int (*cmd_dispatcher[MUSE_MODULE_COMMAND_MAX])(muse_module_h module) = { - camera_cmd_dispatcher_initialize, /* MUSE_MODULE_COMMAND_INITIALIZE */ + NULL, /* MUSE_MODULE_COMMAND_INITIALIZE */ camera_cmd_dispatcher_shutdown, /* MUSE_MODULE_COMMAND_SHUTDOWN */ NULL, /* MUSE_MODULE_COMMAND_DEBUG_INFO_DUMP */ NULL, /* MUSE_MODULE_COMMAND_CREATE_SERVER_ACK */ diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index eeb44b7..5ec509d 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.28 +Version: 0.3.29 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4 From 3962fb59c24fba919ddb192febd98a45e322a32a Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 27 Apr 2020 16:50:48 +0900 Subject: [PATCH 14/16] Add feature for line coverage measurement [Version] 0.3.29-1 [Profile] Common [Issue Type] Line coverage Change-Id: Idb468c54f44e204e770dfab1b146e0f6e6469e63 Signed-off-by: Jeongmo Yang --- packaging/mmsvc-camera.spec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 5ec509d..3d8339a 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,7 +1,7 @@ Name: mmsvc-camera Summary: A Camera module for muse server Version: 0.3.29 -Release: 0 +Release: 1 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -28,7 +28,6 @@ Summary: A Camera module for muse server (Development) Requires: %{name} = %{version}-%{release} Requires: pkgconfig(libtbm) - %description devel Development related files of a Camera module for muse server. @@ -38,6 +37,10 @@ Development related files of a Camera module for muse server. %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif %if 0%{?sec_build_binary_debug_enable} export CFLAGS+=" -DTIZEN_DEBUG_ENABLE" %endif -- 2.7.4 From d6b5c1868153d77424541b9160d87ff1443ffdce Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Wed, 13 May 2020 16:53:31 +0900 Subject: [PATCH 15/16] Set vconf key to check state of camera - libfeedback uses vconf key to check camera state, but it was not set. [Version] 0.3.30 [Profile] Common [Issue Type] Update Change-Id: I16983dcc5c34177978d103656364ce4560528736 Signed-off-by: Jeongmo Yang --- muse/CMakeLists.txt | 2 +- muse/src/muse_camera_dispatcher.c | 14 +++++++++++--- packaging/mmsvc-camera.spec | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/muse/CMakeLists.txt b/muse/CMakeLists.txt index e76da7c..eb7f381 100644 --- a/muse/CMakeLists.txt +++ b/muse/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(service "muse") SET(submodule "camera") -SET(dependents "dlog glib-2.0 muse-server mm-common libtbm gstreamer-1.0") +SET(dependents "dlog glib-2.0 vconf muse-server mm-common libtbm gstreamer-1.0") SET(MUSE_MODULE "${service}-${submodule}") PROJECT(${MUSE_MODULE}) diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 3107120..3715352 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "muse_camera_msg.h" #include "muse_camera_internal.h" #include @@ -860,6 +861,7 @@ void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e char value_key[KEY_LENGTH] = {'\0',}; int ret = CAMERA_ERROR_NONE; int set_value = -1; + int vconf_state = VCONFKEY_CAMERA_STATE_NULL; LOGD("Enter - previous %d, current %d, by_policy %d", previous, current, by_policy); @@ -882,14 +884,20 @@ void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e } snprintf(value_key, KEY_LENGTH, "device_state_camera%d", device_type); - if (previous == CAMERA_STATE_CREATED && current == CAMERA_STATE_PREVIEW) + if (previous == CAMERA_STATE_CREATED && current == CAMERA_STATE_PREVIEW) { set_value = CAMERA_DEVICE_STATE_WORKING; - else if (previous == CAMERA_STATE_PREVIEW && current == CAMERA_STATE_CREATED) + vconf_state = VCONFKEY_CAMERA_STATE_PREVIEW; + } else if (previous == CAMERA_STATE_PREVIEW && current == CAMERA_STATE_CREATED) { set_value = CAMERA_DEVICE_STATE_NULL; + vconf_state = VCONFKEY_CAMERA_STATE_NULL; + } if (set_value != -1) { - LOGD("device[%s] state set : %d", value_key, set_value); + LOGD("device[%s] state set : %d, vconf state : %d", + value_key, set_value, vconf_state); + muse_server_module_set_value(module, value_key, set_value); + vconf_set_int(VCONFKEY_CAMERA_STATE, vconf_state); } return; diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index 3d8339a..bfdd41b 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,13 +1,14 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.29 -Release: 1 +Version: 0.3.30 +Release: 0 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(gstreamer-1.0) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(muse-server) BuildRequires: pkgconfig(mm-camcorder) BuildRequires: pkgconfig(capi-base-common) -- 2.7.4 From 012818f39d435f177791f32708987a3b4e9c671c Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Mon, 18 May 2020 11:36:37 +0900 Subject: [PATCH 16/16] Update code for line coverage test - Replace error return code by macro - Remove unused code - Exclude device related error code [Version] 0.3.31 [Profile] Common [Issue Type] Update Change-Id: I3c62c168daf712ebde3bed00e252ecb059b9016c Signed-off-by: Jeongmo Yang --- legacy/include/legacy_camera.h | 7 +- legacy/include/legacy_camera_private.h | 16 + legacy/src/legacy_camera.c | 1566 +++++++++----------------------- legacy/src/legacy_camera_internal.c | 15 +- muse/src/muse_camera_dispatcher.c | 411 ++++----- packaging/mmsvc-camera.spec | 2 +- 6 files changed, 617 insertions(+), 1400 deletions(-) diff --git a/legacy/include/legacy_camera.h b/legacy/include/legacy_camera.h index a89de94..7dba78a 100644 --- a/legacy/include/legacy_camera.h +++ b/legacy/include/legacy_camera.h @@ -126,10 +126,9 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - CAMERA_DISPLAY_TYPE_OVERLAY = 0, /**< Overlay surface display */ - CAMERA_DISPLAY_TYPE_EVAS, /**< Evas object surface display */ - CAMERA_DISPLAY_TYPE_NONE, /**< This disposes off buffers */ - CAMERA_DISPLAY_TYPE_REMOTE /**< Remote surface for display */ + CAMERA_DISPLAY_TYPE_OVERLAY = 0, /**< Overlay surface display */ + CAMERA_DISPLAY_TYPE_EVAS, /**< Evas object surface display */ + CAMERA_DISPLAY_TYPE_NONE /**< This disposes off buffers */ } camera_display_type_e; /** diff --git a/legacy/include/legacy_camera_private.h b/legacy/include/legacy_camera_private.h index a84a387..984f7a2 100644 --- a/legacy/include/legacy_camera_private.h +++ b/legacy/include/legacy_camera_private.h @@ -29,6 +29,22 @@ extern "C" { #define MAX_DETECTED_FACE 20 +#define camera_return_if_fail(expr) \ + do { \ + if (!(expr)) { \ + LOGE("failed [%s]", #expr); \ + return; \ + } \ + } while (0) + +#define camera_return_val_if_fail(expr, val) \ + do { \ + if (!(expr)) { \ + LOGE("failed [%s]", #expr); \ + return (val); \ + } \ + } while (0) + typedef enum { _CAMERA_EVENT_TYPE_STATE_CHANGE, _CAMERA_EVENT_TYPE_FOCUS_CHANGE, diff --git a/legacy/src/legacy_camera.c b/legacy/src/legacy_camera.c index 0583f92..8058228 100644 --- a/legacy/src/legacy_camera.c +++ b/legacy/src/legacy_camera.c @@ -59,6 +59,7 @@ int __convert_camera_error_code(const char *func, int code) ret = CAMERA_ERROR_INVALID_STATE; errorstr = "INVALID_STATE"; break; +//LCOV_EXCL_START case MM_ERROR_CAMCORDER_DEVICE_NOT_FOUND: ret = CAMERA_ERROR_DEVICE_NOT_FOUND; errorstr = "DEVICE_NOT_FOUND"; @@ -117,6 +118,7 @@ int __convert_camera_error_code(const char *func, int code) ret = CAMERA_ERROR_PERMISSION_DENIED; errorstr = "ERROR_PERMISSION_DENIED"; break; +//LCOV_EXCL_STOP case MM_ERROR_COMMON_OUT_OF_ARRAY: case MM_ERROR_COMMON_OUT_OF_RANGE: case MM_ERROR_COMMON_ATTR_NOT_EXIST: @@ -124,6 +126,7 @@ int __convert_camera_error_code(const char *func, int code) ret = CAMERA_ERROR_NOT_SUPPORTED; errorstr = "ERROR_NOT_SUPPORTED"; break; +//LCOV_EXCL_START case MM_ERROR_RESOURCE_INTERNAL: ret = CAMERA_ERROR_RESOURCE_CONFLICT; errorstr = "ERROR_RESOURCE_CONFLICT"; @@ -132,6 +135,7 @@ int __convert_camera_error_code(const char *func, int code) ret = CAMERA_ERROR_INVALID_OPERATION; errorstr = "INVALID_OPERATION"; break; +//LCOV_EXCL_STOP } if (code != MM_ERROR_NONE) @@ -280,9 +284,6 @@ static camera_state_e __camera_state_convert(MMCamcorderStateType mm_state, MMCa static int __mm_camera_message_callback(int message, void *param, void *user_data) { - if (user_data == NULL || param == NULL) - return 0; - int i = 0; int camera_error = 0; camera_s *handle = (camera_s *)user_data; @@ -291,6 +292,8 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat camera_policy_e policy = CAMERA_POLICY_NONE; MMCamFaceDetectInfo *cam_fd_info = NULL; + camera_return_val_if_fail(user_data && param, 0); + if (handle->relay_message_callback) handle->relay_message_callback(message, param, handle->relay_user_data); @@ -311,6 +314,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat break; } +//LCOV_EXCL_START /* check policy */ if (message == MM_MESSAGE_CAMCORDER_STATE_CHANGED_BY_SECURITY) { policy = CAMERA_POLICY_SECURITY; @@ -330,6 +334,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat if (handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]) ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]); } +//LCOV_EXCL_STOP previous_state = handle->state; handle->state = __camera_state_convert(m->state.current, m->state.previous); @@ -381,6 +386,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat } break; } +//LCOV_EXCL_START case MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_SECURITY: case MM_MESSAGE_CAMCORDER_STATE_CHANGE_STARTED_BY_RM: if (handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]) { @@ -397,6 +403,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat } } break; +//LCOV_EXCL_STOP case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED: if (handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE]) { ((camera_focus_changed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE])(m->code, @@ -427,6 +434,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat ((camera_capture_completed_cb)handle->user_cb[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE])(handle->user_data[_CAMERA_EVENT_TYPE_CAPTURE_COMPLETE]); break; +//LCOV_EXCL_START case MM_MESSAGE_CAMCORDER_ERROR: switch (m->code) { case MM_ERROR_CAMCORDER_DEVICE: @@ -476,6 +484,7 @@ static int __mm_camera_message_callback(int message, void *param, void *user_dat } break; +//LCOV_EXCL_STOP case MM_MESSAGE_CAMCORDER_HDR_PROGRESS: if (handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS]) { ((camera_attr_hdr_progress_cb)handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS])(m->code, @@ -520,10 +529,7 @@ static int __capture_completed_event_cb(void *data) camera_s *handle = (camera_s *)data; camera_state_e previous_state = CAMERA_STATE_NONE; - if (handle == NULL) { - LOGE("handle is NULL"); - return false; - } + camera_return_val_if_fail(handle, false); if (handle->current_capture_count > 0 && handle->current_capture_count == handle->current_capture_complete_count && @@ -555,26 +561,17 @@ int legacy_camera_create(camera_device_e device, camera_h *camera) char *error = NULL; MMCamPreset info; - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(camera, CAMERA_ERROR_INVALID_PARAMETER); LOGD("device name = [%d]", device); info.videodev_type = device; - handle = (camera_s *)malloc(sizeof(camera_s)); - if (handle == NULL) { - LOGE("malloc fail"); - return CAMERA_ERROR_OUT_OF_MEMORY; - } - - memset(handle, 0x0, sizeof(camera_s)); + handle = (camera_s *)g_malloc0(sizeof(camera_s)); ret = mm_camcorder_create(&handle->mm_handle, &info); if (ret != MM_ERROR_NONE) { - free(handle); + g_free(handle); return __convert_camera_error_code(__func__, ret); } @@ -587,6 +584,7 @@ int legacy_camera_create(camera_device_e device, camera_h *camera) MMCAM_CAPTURE_HEIGHT, &handle->capture_height, NULL); if (ret != MM_ERROR_NONE) { +//LCOV_EXCL_START LOGE("mm_camcorder_get_attributes fail(%x)", ret); if (error) { LOGE("failed attribute name %s", error); @@ -594,9 +592,10 @@ int legacy_camera_create(camera_device_e device, camera_h *camera) } mm_camcorder_destroy(handle->mm_handle); - free(handle); + g_free(handle); return __convert_camera_error_code(__func__, ret); +//LCOV_EXCL_STOP } ret = mm_camcorder_set_attributes(handle->mm_handle, &error, @@ -612,6 +611,7 @@ int legacy_camera_create(camera_device_e device, camera_h *camera) handle->display_type = CAMERA_DISPLAY_TYPE_NONE; if (ret != MM_ERROR_NONE) { +//LCOV_EXCL_START LOGE("mm_camcorder_set_attributes fail(%x)", ret); if (error) { LOGE("failed attribute name %s", error); @@ -619,9 +619,10 @@ int legacy_camera_create(camera_device_e device, camera_h *camera) } mm_camcorder_destroy(handle->mm_handle); - free(handle); + g_free(handle); return __convert_camera_error_code(__func__, ret); +//LCOV_EXCL_STOP } handle->state = CAMERA_STATE_CREATED; @@ -662,34 +663,18 @@ int legacy_camera_change_device(camera_h *camera, camera_device_e device, bool i void *reuse_element = NULL; void *gdbus_connection = NULL; - if (camera == NULL) { - LOGE("NULL handle"); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (device > CAMERA_DEVICE_CAMERA9) { - LOGE("invalid device %d", device); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(camera, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(device <= CAMERA_DEVICE_CAMERA9, CAMERA_ERROR_INVALID_PARAMETER); old_handle = (camera_s *)*camera; - if (old_handle->is_used_in_recorder) { - LOGE("camera is using in another recorder."); - return CAMERA_ERROR_INVALID_OPERATION; - } - - if (old_handle->device_type == device) { - LOGE("same device. no need to change it."); - return CAMERA_ERROR_NONE; - } + camera_return_val_if_fail(old_handle->is_used_in_recorder == false, CAMERA_ERROR_INVALID_OPERATION); + camera_return_val_if_fail(old_handle->device_type != device, CAMERA_ERROR_NONE); /* check current state */ legacy_camera_get_state(*camera, &capi_state); - if (capi_state != CAMERA_STATE_CREATED) { - LOGE("invalid state %d", capi_state); - return CAMERA_ERROR_INVALID_STATE; - } + + camera_return_val_if_fail(capi_state == CAMERA_STATE_CREATED, CAMERA_ERROR_INVALID_STATE); /* get reuse element */ ret = mm_camcorder_get_attributes(old_handle->mm_handle, NULL, @@ -783,7 +768,7 @@ int legacy_camera_change_device(camera_h *camera, camera_device_e device, bool i LOGD("new handle %p", new_handle); return CAMERA_ERROR_NONE; - +//LCOV_EXCL_START _CHANGE_DEVICE_FAILED: legacy_camera_destroy((camera_h)new_handle); new_handle = NULL; @@ -795,23 +780,17 @@ _CHANGE_DEVICE_FAILED: } return __convert_camera_error_code(__func__, ret); +//LCOV_EXCL_STOP } int legacy_camera_destroy(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; - if (handle->is_used_in_recorder) { - LOGE("camera is using in another recorder."); - return CAMERA_ERROR_INVALID_OPERATION; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(handle->is_used_in_recorder == false, CAMERA_ERROR_INVALID_OPERATION); LOGW("camera handle %p", handle); @@ -819,7 +798,7 @@ int legacy_camera_destroy(camera_h camera) if (ret == MM_ERROR_NONE) { g_cond_clear(&handle->cond); g_mutex_clear(&handle->lock); - free(handle); + g_free(handle); } return __convert_camera_error_code(__func__, ret); @@ -828,16 +807,13 @@ int legacy_camera_destroy(camera_h camera) int legacy_camera_start_preview(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; camera_state_e capi_state = CAMERA_STATE_NONE; MMCamcorderStateType mm_state = MM_CAMCORDER_STATE_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + legacy_camera_get_state(camera, &capi_state); if (capi_state == CAMERA_STATE_CAPTURED) { ret = mm_camcorder_capture_stop(handle->mm_handle); @@ -870,15 +846,12 @@ int legacy_camera_start_preview(camera_h camera) int legacy_camera_stop_preview(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE;; camera_s *handle = (camera_s *)camera; MMCamcorderStateType state = MM_CAMCORDER_STATE_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_state(handle->mm_handle, &state); if (state == MM_CAMCORDER_STATE_PREPARE) { ret = mm_camcorder_stop(handle->mm_handle); @@ -898,15 +871,12 @@ int legacy_camera_stop_preview(camera_h camera) int legacy_camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; int ret = MM_ERROR_NONE; MMCamcorderStateType state = MM_CAMCORDER_STATE_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_state(handle->mm_handle, &state); if (state != MM_CAMCORDER_STATE_PREPARE && state != MM_CAMCORDER_STATE_RECORDING && @@ -953,15 +923,12 @@ int legacy_camera_start_capture(camera_h camera, camera_capturing_cb capturing_c bool legacy_camera_is_supported_continuous_capture(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_COUNT, &info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -978,27 +945,16 @@ bool legacy_camera_is_supported_continuous_capture(camera_h camera) int legacy_camera_start_continuous_capture(camera_h camera, int count, int interval, camera_capturing_cb capturing_cb, camera_capture_completed_cb completed_cb, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_is_supported_continuous_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (count < 2 || interval < 0) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; MMCamcorderStateType state = MM_CAMCORDER_STATE_NONE; int supported_zsl = FALSE; int ret = MM_ERROR_NONE; camera_attr_hdr_mode_e hdr_mode = CAMERA_ATTR_HDR_MODE_DISABLE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_continuous_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(count > 1 && interval >= 0, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_state(handle->mm_handle, &state); if (state != MM_CAMCORDER_STATE_PREPARE) { LOGE("INVALID_STATE(0x%08x)", CAMERA_ERROR_INVALID_STATE); @@ -1081,20 +1037,13 @@ int legacy_camera_start_continuous_capture(camera_h camera, int count, int inter int legacy_camera_stop_continuous_capture(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_is_supported_continuous_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - camera_s *handle = (camera_s *)camera; int ret = MM_ERROR_NONE; camera_state_e state = CAMERA_STATE_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_continuous_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + legacy_camera_get_state(camera, &state); if (state != CAMERA_STATE_CAPTURING && handle->capture_count > 1) { LOGE("INVALID_STATE(0x%08x)", CAMERA_ERROR_INVALID_STATE); @@ -1119,16 +1068,13 @@ int legacy_camera_stop_continuous_capture(camera_h camera) bool legacy_camera_is_supported_face_detection(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DETECT_MODE , &info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -1157,10 +1103,7 @@ bool legacy_camera_is_supported_zero_shutter_lag(camera_h camera) int supported_zsl = false; camera_s *handle = (camera_s *)camera; - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } + camera_return_val_if_fail(handle, false); ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_SUPPORT_ZSL_CAPTURE, &supported_zsl, @@ -1183,10 +1126,7 @@ bool legacy_camera_is_supported_media_packet_preview_cb(camera_h camera) int supported = false; camera_s *handle = (camera_s *)camera; - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } + camera_return_val_if_fail(handle, false); ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, &supported, @@ -1208,10 +1148,7 @@ int legacy_camera_get_device_count(camera_h camera, int *device_count) int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; - if (camera == NULL || device_count == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle && device_count, CAMERA_ERROR_INVALID_PARAMETER); ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_DEVICE_COUNT, device_count, @@ -1223,25 +1160,16 @@ int legacy_camera_get_device_count(camera_h camera, int *device_count) int legacy_camera_start_face_detection(camera_h camera, camera_face_detected_cb callback, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_is_supported_face_detection(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - camera_s *handle = (camera_s *)camera; camera_state_e state = CAMERA_STATE_NONE; int ret = MM_ERROR_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_face_detection(camera), CAMERA_ERROR_NOT_SUPPORTED); + legacy_camera_get_state(camera, &state); - if (state != CAMERA_STATE_PREVIEW) { - LOGE("INVALID_STATE(0x%08x)", CAMERA_ERROR_INVALID_STATE); - return CAMERA_ERROR_INVALID_STATE; - } + + camera_return_val_if_fail(state == CAMERA_STATE_PREVIEW, CAMERA_ERROR_INVALID_STATE); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_ON, @@ -1258,18 +1186,11 @@ int legacy_camera_start_face_detection(camera_h camera, camera_face_detected_cb int legacy_camera_stop_face_detection(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; int ret = MM_ERROR_NONE; - if (legacy_camera_is_supported_face_detection(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_face_detection(camera), CAMERA_ERROR_NOT_SUPPORTED); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DETECT_MODE, MM_CAMCORDER_DETECT_MODE_OFF, @@ -1286,16 +1207,13 @@ int legacy_camera_stop_face_detection(camera_h camera) int legacy_camera_get_state(camera_h camera, camera_state_e *state) { - if (camera == NULL || state == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; camera_state_e capi_state = CAMERA_STATE_NONE; MMCamcorderStateType mm_state = MM_CAMCORDER_STATE_NONE; MMCamcorderStateType mm_old_state = MM_CAMCORDER_STATE_NONE; + camera_return_val_if_fail(handle && state, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_state2(handle->mm_handle, &mm_state, &mm_old_state); capi_state = __camera_state_convert(mm_state, mm_old_state); @@ -1315,10 +1233,7 @@ int legacy_camera_get_device_type(camera_h camera, camera_device_e *device_type) int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; - if (camera == NULL || device_type == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle && device_type, CAMERA_ERROR_INVALID_PARAMETER); *device_type = handle->device_type; @@ -1327,13 +1242,10 @@ int legacy_camera_get_device_type(camera_h camera, camera_device_e *device_type) int legacy_camera_start_focusing(camera_h camera, bool continuous) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->cached_focus_mode != -1) { LOGD("apply cached focus mode %d", handle->cached_focus_mode); @@ -1359,15 +1271,12 @@ int legacy_camera_start_focusing(camera_h camera, bool continuous) int __camera_start_continuous_focusing(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; int ret = MM_ERROR_NONE; int mode = MM_CAMCORDER_FOCUS_MODE_NONE; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->on_continuous_focusing = true; mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, &mode, @@ -1387,13 +1296,10 @@ int __camera_start_continuous_focusing(camera_h camera) int legacy_camera_cancel_focusing(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->on_continuous_focusing = false; return __convert_camera_error_code(__func__, mm_camcorder_stop_focusing(handle->mm_handle)); @@ -1405,20 +1311,11 @@ int legacy_camera_set_display(camera_h camera, camera_display_type_e type, camer int ret = MM_ERROR_NONE; int set_surface = MM_DISPLAY_SURFACE_OVERLAY; void *set_handle = NULL; - char *socket_path = NULL; - camera_s *handle = NULL; - - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_s *handle = (camera_s *)camera; - if (type != CAMERA_DISPLAY_TYPE_NONE && display == NULL) { - LOGE("display type[%d] is not NONE, but display handle is NULL", type); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(type == CAMERA_DISPLAY_TYPE_NONE || display, CAMERA_ERROR_INVALID_PARAMETER); - handle = (camera_s *)camera; handle->display_type = type; LOGD("display type - %d, display handle - %p", type, display); @@ -1434,17 +1331,15 @@ int legacy_camera_set_display(camera_h camera, camera_display_type_e type, camer set_surface = MM_DISPLAY_SURFACE_EVAS; set_handle = display; break; - case CAMERA_DISPLAY_TYPE_REMOTE: - set_surface = MM_DISPLAY_SURFACE_REMOTE; - handle->display_handle = display; - break; case CAMERA_DISPLAY_TYPE_NONE: set_surface = MM_DISPLAY_SURFACE_NULL; handle->display_handle = 0; break; +//LCOV_EXCL_START default: LOGE("unknown display type %d", type); return CAMERA_ERROR_INVALID_PARAMETER; +//LCOV_EXCL_STOP } ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, @@ -1452,24 +1347,10 @@ int legacy_camera_set_display(camera_h camera, camera_display_type_e type, camer MMCAM_DISPLAY_SURFACE, set_surface, NULL); - if (ret == MM_ERROR_NONE) { - if (type == CAMERA_DISPLAY_TYPE_REMOTE) { - socket_path = (char *)handle->display_handle; - - if (!unlink(socket_path)) { - LOGW("[%s] remove done", socket_path); - } else { - LOGW("[%s] remove failed : errno %d", socket_path, errno); - } - - ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - MMCAM_DISPLAY_SOCKET_PATH, socket_path, strlen(socket_path), - NULL); - } else if (type != CAMERA_DISPLAY_TYPE_NONE) { - ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - MMCAM_DISPLAY_HANDLE, set_handle, sizeof(void *), - NULL); - } + if (ret == MM_ERROR_NONE && type != CAMERA_DISPLAY_TYPE_NONE) { + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, + MMCAM_DISPLAY_HANDLE, set_handle, sizeof(void *), + NULL); } return __convert_camera_error_code(__func__, ret); @@ -1478,22 +1359,15 @@ int legacy_camera_set_display(camera_h camera, camera_display_type_e type, camer int legacy_camera_set_preview_resolution(camera_h camera, int width, int height) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (width <= 0 || height <= 0) { - LOGE("invalid preview resolution %dx%d", width, height); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; int mm_fps = 0; int i = 0; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(width > 0 && height > 0, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FPS, &mm_fps, NULL); @@ -1523,19 +1397,12 @@ int legacy_camera_set_preview_resolution(camera_h camera, int width, int height) int legacy_camera_set_capture_resolution(camera_h camera, int width, int height) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (width <= 0 || height <= 0) { - LOGE("invalid capture resolution %dx%d", width, height); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(width > 0 && height > 0, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAPTURE_WIDTH, width, MMCAM_CAPTURE_HEIGHT, height, @@ -1551,11 +1418,6 @@ int legacy_camera_set_capture_resolution(camera_h camera, int width, int height) int legacy_camera_set_capture_format(camera_h camera, camera_pixel_format_e format) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_MJPEG || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); @@ -1565,6 +1427,8 @@ int legacy_camera_set_capture_format(camera_h camera, camera_pixel_format_e form int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAPTURE_FORMAT, format, NULL); @@ -1575,11 +1439,6 @@ int legacy_camera_set_capture_format(camera_h camera, camera_pixel_format_e form int legacy_camera_set_preview_format(camera_h camera, camera_pixel_format_e format) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - if (format < CAMERA_PIXEL_FORMAT_NV12 || format > CAMERA_PIXEL_FORMAT_MJPEG || (format > CAMERA_PIXEL_FORMAT_JPEG && format < CAMERA_PIXEL_FORMAT_H264)) { LOGE("invalid preview format %d", format); @@ -1590,6 +1449,8 @@ int legacy_camera_set_preview_format(camera_h camera, camera_pixel_format_e form int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + if (format == CAMERA_PIXEL_FORMAT_UYVY) { bool supported_ITLV_UYVY = false; MMCamAttrsInfo supported_format; @@ -1613,14 +1474,11 @@ int legacy_camera_set_preview_format(camera_h camera, camera_pixel_format_e form int legacy_camera_get_preview_resolution(camera_h camera, int *width, int *height) { - if (camera == NULL || width == NULL || height == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && width && height, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_WIDTH, width, MMCAM_CAMERA_HEIGHT, height, @@ -1632,19 +1490,12 @@ int legacy_camera_get_preview_resolution(camera_h camera, int *width, int *heigh int legacy_camera_set_display_rotation(camera_h camera, camera_rotation_e rotation) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (rotation > CAMERA_ROTATION_270) { - LOGE("invalid rotation %d", rotation); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(rotation <= CAMERA_ROTATION_270, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_ROTATION, rotation, NULL); @@ -1655,14 +1506,11 @@ int legacy_camera_set_display_rotation(camera_h camera, camera_rotation_e rotati int legacy_camera_get_display_rotation(camera_h camera, camera_rotation_e *rotation) { - if (camera == NULL || rotation == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && rotation, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_ROTATION, rotation, NULL); @@ -1673,19 +1521,12 @@ int legacy_camera_get_display_rotation(camera_h camera, camera_rotation_e *rotat int legacy_camera_set_display_flip(camera_h camera, camera_flip_e flip) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (flip > CAMERA_FLIP_BOTH) { - LOGE("invalid flip %d", flip); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(flip <= CAMERA_FLIP_BOTH, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_FLIP, flip, NULL); @@ -1696,14 +1537,11 @@ int legacy_camera_set_display_flip(camera_h camera, camera_flip_e flip) int legacy_camera_get_display_flip(camera_h camera, camera_flip_e *flip) { - if (camera == NULL || flip == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && flip, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_FLIP, flip, NULL); @@ -1714,14 +1552,11 @@ int legacy_camera_get_display_flip(camera_h camera, camera_flip_e *flip) int legacy_camera_set_display_visible(camera_h camera, bool visible) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_VISIBLE, visible, NULL); @@ -1730,17 +1565,14 @@ int legacy_camera_set_display_visible(camera_h camera, bool visible) } -int legacy_camera_is_display_visible(camera_h camera, bool* visible) +int legacy_camera_is_display_visible(camera_h camera, bool *visible) { - if (camera == NULL || visible == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int result = false; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && visible, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_VISIBLE, &result, NULL); @@ -1754,19 +1586,12 @@ int legacy_camera_is_display_visible(camera_h camera, bool* visible) int legacy_camera_set_display_mode(camera_h camera, camera_display_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_DISPLAY_MODE_CUSTOM_ROI) { - LOGE("invalid mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_DISPLAY_MODE_CUSTOM_ROI, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_GEOMETRY_METHOD, mode, NULL); @@ -1777,14 +1602,11 @@ int legacy_camera_set_display_mode(camera_h camera, camera_display_mode_e mode) int legacy_camera_get_display_mode(camera_h camera, camera_display_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_GEOMETRY_METHOD, mode, NULL); @@ -1795,13 +1617,10 @@ int legacy_camera_get_display_mode(camera_h camera, camera_display_mode_e *mode) int legacy_camera_get_capture_resolution(camera_h camera, int *width, int *height) { - if (camera == NULL || width == NULL || height == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && width && height, CAMERA_ERROR_INVALID_PARAMETER); + *width = handle->capture_width; *height = handle->capture_height; @@ -1811,14 +1630,11 @@ int legacy_camera_get_capture_resolution(camera_h camera, int *width, int *heigh int legacy_camera_get_capture_format(camera_h camera, camera_pixel_format_e *format) { - if (camera == NULL || format == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && format, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAPTURE_FORMAT, format, NULL); @@ -1829,14 +1645,11 @@ int legacy_camera_get_capture_format(camera_h camera, camera_pixel_format_e *for int legacy_camera_get_preview_format(camera_h camera, camera_pixel_format_e *format) { - if (camera == NULL || format == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && format, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FORMAT, format, NULL); @@ -1849,14 +1662,11 @@ int legacy_camera_get_preview_format(camera_h camera, camera_pixel_format_e *for int legacy_camera_get_facing_direction(camera_h camera, camera_facing_direction_e *facing_direction) { - if (camera == NULL || facing_direction == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && facing_direction, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FACING_DIRECTION, facing_direction, NULL); @@ -1866,12 +1676,10 @@ int legacy_camera_get_facing_direction(camera_h camera, camera_facing_direction_ int legacy_camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_PREVIEW] = (void *)user_data; @@ -1885,13 +1693,10 @@ int legacy_camera_set_preview_cb(camera_h camera, camera_preview_cb callback, vo int legacy_camera_unset_preview_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] == NULL) { mm_camcorder_set_video_stream_callback(handle->mm_handle, (mm_camcorder_video_stream_callback)NULL, @@ -1907,22 +1712,12 @@ int legacy_camera_unset_preview_cb(camera_h camera) int legacy_camera_set_media_packet_preview_cb(camera_h camera, camera_preview_cb callback, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_is_supported_media_packet_preview_cb(camera) == false) { - LOGE("NOT SUPPORTED"); - return CAMERA_ERROR_NOT_SUPPORTED; - } + camera_s *handle = (camera_s *)camera; - if (callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_media_packet_preview_cb(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(callback, CAMERA_ERROR_INVALID_PARAMETER); - camera_s *handle = (camera_s *)camera; handle->user_cb[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = (void *)user_data; @@ -1936,18 +1731,11 @@ int legacy_camera_set_media_packet_preview_cb(camera_h camera, camera_preview_cb int legacy_camera_unset_media_packet_preview_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_is_supported_media_packet_preview_cb(camera) == false) { - LOGE("NOT SUPPORTED"); - return CAMERA_ERROR_NOT_SUPPORTED; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_is_supported_media_packet_preview_cb(camera), CAMERA_ERROR_NOT_SUPPORTED); + if (handle->user_cb[_CAMERA_EVENT_TYPE_PREVIEW] == NULL) { mm_camcorder_set_video_stream_callback(handle->mm_handle, (mm_camcorder_video_stream_callback)NULL, @@ -1963,12 +1751,10 @@ int legacy_camera_unset_media_packet_preview_cb(camera_h camera) int legacy_camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)user_data; @@ -1978,12 +1764,10 @@ int legacy_camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb int legacy_camera_unset_state_changed_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_STATE_CHANGE] = (void *)NULL; @@ -1993,12 +1777,10 @@ int legacy_camera_unset_state_changed_cb(camera_h camera) int legacy_camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)user_data; @@ -2008,13 +1790,10 @@ int legacy_camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb call int legacy_camera_unset_interrupted_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPTED] = (void *)NULL; @@ -2024,12 +1803,10 @@ int legacy_camera_unset_interrupted_cb(camera_h camera) int legacy_camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = (void *)user_data; @@ -2039,13 +1816,10 @@ int legacy_camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_sta int legacy_camera_unset_interrupt_started_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = (void *)NULL; @@ -2055,13 +1829,10 @@ int legacy_camera_unset_interrupt_started_cb(camera_h camera) int legacy_camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)user_data; @@ -2071,13 +1842,10 @@ int legacy_camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb int legacy_camera_unset_focus_changed_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = (void *)NULL; @@ -2087,13 +1855,10 @@ int legacy_camera_unset_focus_changed_cb(camera_h camera) int legacy_camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_data) { - if (camera == NULL || callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void *)user_data; @@ -2103,13 +1868,10 @@ int legacy_camera_set_error_cb(camera_h camera, camera_error_cb callback, void * int legacy_camera_unset_error_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_ERROR] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_ERROR] = (void *)NULL; @@ -2123,16 +1885,11 @@ int legacy_camera_set_display_reuse_hint(camera_h camera, int hint) camera_s *handle = (camera_s *)camera; camera_state_e capi_state = CAMERA_STATE_NONE; - if (!handle) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); legacy_camera_get_state(camera, &capi_state); - if (capi_state != CAMERA_STATE_PREVIEW) { - LOGE("invalid state %d", capi_state); - return CAMERA_ERROR_INVALID_STATE; - } + + camera_return_val_if_fail(capi_state == CAMERA_STATE_PREVIEW, CAMERA_ERROR_INVALID_STATE); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_REUSE_HINT, hint, @@ -2147,10 +1904,7 @@ int legacy_camera_get_display_reuse_hint(camera_h camera, int *hint) int ret = CAMERA_ERROR_NONE; camera_s *handle = (camera_s *)camera; - if (!handle || !hint) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle && hint, CAMERA_ERROR_INVALID_PARAMETER); ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_REUSE_HINT, hint, @@ -2162,17 +1916,14 @@ int legacy_camera_get_display_reuse_hint(camera_h camera, int *hint) int legacy_camera_foreach_supported_preview_resolution(camera_h camera, camera_supported_preview_resolution_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo preview_width; MMCamAttrsInfo preview_height; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WIDTH, &preview_width); ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HEIGHT, &preview_height); if (ret != CAMERA_ERROR_NONE) @@ -2189,17 +1940,14 @@ int legacy_camera_foreach_supported_preview_resolution(camera_h camera, camera_s int legacy_camera_foreach_supported_capture_resolution(camera_h camera, camera_supported_capture_resolution_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo capture_width; MMCamAttrsInfo capture_height; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_WIDTH, &capture_width); ret |= mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_HEIGHT, &capture_height); if (ret != CAMERA_ERROR_NONE) @@ -2216,16 +1964,13 @@ int legacy_camera_foreach_supported_capture_resolution(camera_h camera, camera_s int legacy_camera_foreach_supported_capture_format(camera_h camera, camera_supported_capture_format_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo format; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAPTURE_FORMAT, &format); if (ret != CAMERA_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -2243,16 +1988,13 @@ int legacy_camera_foreach_supported_capture_format(camera_h camera, camera_suppo int legacy_camera_foreach_supported_preview_format(camera_h camera, camera_supported_preview_format_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo format; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FORMAT, &format); if (ret != CAMERA_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -2270,11 +2012,6 @@ int legacy_camera_foreach_supported_preview_format(camera_h camera, camera_suppo int legacy_camera_get_recommended_preview_resolution(camera_h camera, int *width, int *height) { - if (camera == NULL || width == NULL || height == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - enum MMCamcorderPreviewType wide = MM_CAMCORDER_PREVIEW_TYPE_NORMAL; int capture_w = 0; int capture_h = 0; @@ -2284,6 +2021,8 @@ int legacy_camera_get_recommended_preview_resolution(camera_h camera, int *width MMCamAttrsInfo width_info; MMCamAttrsInfo height_info; + camera_return_val_if_fail(handle && width && height, CAMERA_ERROR_INVALID_PARAMETER); + legacy_camera_get_capture_resolution(camera, &capture_w, &capture_h); if (capture_h == 0) { LOGE("Capture Height is 0"); @@ -2324,15 +2063,12 @@ int legacy_camera_get_recommended_preview_resolution(camera_h camera, int *width int legacy_camera_attr_get_lens_orientation(camera_h camera, int *angle) { - if (camera == NULL || angle == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; int rotation = MM_DISPLAY_ROTATION_NONE; + camera_return_val_if_fail(handle && angle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_RECOMMEND_DISPLAY_ROTATION, &rotation, NULL); @@ -2363,19 +2099,12 @@ int legacy_camera_attr_get_lens_orientation(camera_h camera, int *angle) int legacy_camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_THEATER_MODE_ENABLE) { - LOGE("invalid theater mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_THEATER_MODE_ENABLE, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_MODE, mode, NULL); @@ -2386,14 +2115,11 @@ int legacy_camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mod int legacy_camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_MODE, mode, NULL); @@ -2404,16 +2130,13 @@ int legacy_camera_attr_get_theater_mode(camera_h camera, camera_attr_theater_mod int legacy_camera_attr_foreach_supported_theater_mode(camera_h camera, camera_attr_supported_theater_mode_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_DISPLAY_MODE, &info); if (ret != CAMERA_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -2429,19 +2152,12 @@ int legacy_camera_attr_foreach_supported_theater_mode(camera_h camera, camera_at int legacy_camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (fps > CAMERA_ATTR_FPS_120) { - LOGE("invalid preview fps %d", fps); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(fps <= CAMERA_ATTR_FPS_120, CAMERA_ERROR_INVALID_PARAMETER); + if (fps == CAMERA_ATTR_FPS_AUTO) { ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FPS_AUTO, true, @@ -2459,19 +2175,12 @@ int legacy_camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps) int legacy_camera_attr_set_image_quality(camera_h camera, int quality) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (quality <= 0 || quality > 100) { - LOGE("invalid image quality %d", quality); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(quality > 0 && quality <= 100, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_IMAGE_ENCODER_QUALITY, quality, NULL); @@ -2482,16 +2191,13 @@ int legacy_camera_attr_set_image_quality(camera_h camera, int quality) int legacy_camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps) { - if (camera == NULL || fps == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int mm_fps = 0; int is_auto = false; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && fps, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FPS, &mm_fps, MMCAM_CAMERA_FPS_AUTO, &is_auto, @@ -2509,14 +2215,11 @@ int legacy_camera_attr_get_preview_fps(camera_h camera, camera_attr_fps_e *fps) int legacy_camera_attr_get_image_quality(camera_h camera, int *quality) { - if (camera == NULL || quality == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && quality, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_IMAGE_ENCODER_QUALITY, quality, NULL); @@ -2527,19 +2230,12 @@ int legacy_camera_attr_get_image_quality(camera_h camera, int *quality) int legacy_camera_attr_set_zoom(camera_h camera, int zoom) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (zoom < 0) { - LOGE("invalid zoom %d", zoom); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(zoom >= 0, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_DIGITAL_ZOOM, zoom, NULL); @@ -2550,21 +2246,14 @@ int legacy_camera_attr_set_zoom(camera_h camera, int zoom) int legacy_camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_AF_FULL) { - LOGE("invalid mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; int focus_mode; bool should_change_focus_mode = false; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_AF_FULL, CAMERA_ERROR_INVALID_PARAMETER); + mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, &focus_mode, NULL); @@ -2621,20 +2310,13 @@ int legacy_camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode) int legacy_camera_attr_set_af_area(camera_h camera, int x, int y) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (x < 0 || y < 0) { - LOGE("invalid AF area %d, %d", x, y); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; camera_attr_af_mode_e mode; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(x >= 0 && y >= 0, CAMERA_ERROR_INVALID_PARAMETER); + legacy_camera_attr_get_af_mode(camera, &mode); if (mode == CAMERA_ATTR_AF_NONE) { LOGE("INVALID_OPERATION(0x%08x) AF mode is CAMERA_ATTR_AF_NONE", CAMERA_ERROR_INVALID_OPERATION); @@ -2654,13 +2336,10 @@ int legacy_camera_attr_set_af_area(camera_h camera, int x, int y) int legacy_camera_attr_clear_af_area(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->focus_area_valid = false; return 0; @@ -2669,26 +2348,18 @@ int legacy_camera_attr_clear_af_area(camera_h camera) int legacy_camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_EXPOSURE_MODE_CUSTOM) { - LOGE("invalid exposure mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - + int ret = MM_ERROR_NONE; + camera_s *handle = (camera_s *)camera; int maptable[] = { MM_CAMCORDER_AUTO_EXPOSURE_OFF, /* CAMERA_ATTR_EXPOSURE_MODE_OFF */ MM_CAMCORDER_AUTO_EXPOSURE_ALL, /* CAMERA_ATTR_EXPOSURE_MODE_ALL */ MM_CAMCORDER_AUTO_EXPOSURE_CENTER_1, /* CAMERA_ATTR_EXPOSURE_MODE_CENTER */ MM_CAMCORDER_AUTO_EXPOSURE_SPOT_1, /* CAMERA_ATTR_EXPOSURE_MODE_SPOT */ MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1, /* CAMERA_ATTR_EXPOSURE_MODE_CUSTOM */ - }; + }; - int ret = MM_ERROR_NONE; - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_EXPOSURE_MODE_CUSTOM, CAMERA_ERROR_INVALID_PARAMETER); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_MODE, maptable[mode], @@ -2700,14 +2371,11 @@ int legacy_camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_m int legacy_camera_attr_set_exposure(camera_h camera, int value) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_VALUE, value, NULL); @@ -2718,19 +2386,12 @@ int legacy_camera_attr_set_exposure(camera_h camera, int value) int legacy_camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (iso > CAMERA_ATTR_ISO_3200) { - LOGE("invalid iso %d", iso); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(iso <= CAMERA_ATTR_ISO_3200, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ISO, iso, NULL); @@ -2741,14 +2402,11 @@ int legacy_camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso) int legacy_camera_attr_set_brightness(camera_h camera, int level) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_BRIGHTNESS, level, NULL); @@ -2759,14 +2417,11 @@ int legacy_camera_attr_set_brightness(camera_h camera, int level) int legacy_camera_attr_set_contrast(camera_h camera, int level) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_CONTRAST, level, NULL); @@ -2777,14 +2432,11 @@ int legacy_camera_attr_set_contrast(camera_h camera, int level) int legacy_camera_attr_set_hue(camera_h camera, int level) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_HUE, level, NULL); @@ -2795,19 +2447,12 @@ int legacy_camera_attr_set_hue(camera_h camera, int level) int legacy_camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (wb > CAMERA_ATTR_WHITE_BALANCE_CUSTOM) { - LOGE("invalid white balance %d", wb); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(wb <= CAMERA_ATTR_WHITE_BALANCE_CUSTOM, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_WB, wb, NULL); @@ -2818,19 +2463,12 @@ int legacy_camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalanc int legacy_camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (effect > CAMERA_ATTR_EFFECT_OTHER_GRAPHICS) { - LOGE("invalid effect %d", effect); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(effect <= CAMERA_ATTR_EFFECT_OTHER_GRAPHICS, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_COLOR_TONE, effect, NULL); @@ -2841,19 +2479,12 @@ int legacy_camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e eff int legacy_camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_SCENE_MODE_AQUA) { - LOGE("invalid scene mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_SCENE_MODE_AQUA, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_FILTER_SCENE_MODE, mode, NULL); @@ -2864,14 +2495,11 @@ int legacy_camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e int legacy_camera_attr_enable_tag(camera_h camera, bool enable) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_ENABLE, enable, NULL); @@ -2882,14 +2510,11 @@ int legacy_camera_attr_enable_tag(camera_h camera, bool enable) int legacy_camera_attr_set_tag_image_description(camera_h camera, const char *description) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_IMAGE_DESCRIPTION, description, description ? strlen(description) : 0, NULL); @@ -2900,19 +2525,13 @@ int legacy_camera_attr_set_tag_image_description(camera_h camera, const char *de int legacy_camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation_e orientation) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (orientation < CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT || orientation > CAMERA_ATTR_TAG_ORIENTATION_LEFT_BOTTOM) { - LOGE("invalid tag orientation %d", orientation); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(orientation >= CAMERA_ATTR_TAG_ORIENTATION_TOP_LEFT &&\ + orientation <= CAMERA_ATTR_TAG_ORIENTATION_LEFT_BOTTOM, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_ORIENTATION, orientation, NULL); @@ -2923,14 +2542,11 @@ int legacy_camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orie int legacy_camera_attr_set_tag_software(camera_h camera, const char *software) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_SOFTWARE, software, software ? strlen(software) : 0, NULL); @@ -2941,20 +2557,13 @@ int legacy_camera_attr_set_tag_software(camera_h camera, const char *software) int legacy_camera_attr_set_geotag(camera_h camera, double latitude , double longitude, double altitude) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (latitude > 90.0 || latitude < -90.0 || - longitude > 180.0 || longitude < -180.0) { - LOGE("invalid geotag: latitude %lf, logitude %lf", latitude, longitude); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(latitude >= -90.0 && latitude <= 90.0 && + longitude >= -180.0 && longitude <= 180.0, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_GPS_ENABLE, true, MMCAM_TAG_LATITUDE, latitude, @@ -2968,14 +2577,11 @@ int legacy_camera_attr_set_geotag(camera_h camera, double latitude , double long int legacy_camera_attr_remove_geotag(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_TAG_GPS_ENABLE, false, NULL); @@ -2986,19 +2592,12 @@ int legacy_camera_attr_remove_geotag(camera_h camera) int legacy_camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_FLASH_MODE_PERMANENT) { - LOGE("invalid flash mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_FLASH_MODE_PERMANENT, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_STROBE_MODE, mode, NULL); @@ -3009,14 +2608,11 @@ int legacy_camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e int legacy_camera_attr_get_zoom(camera_h camera, int *zoom) { - if (camera == NULL || zoom == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && zoom, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_DIGITAL_ZOOM, zoom, NULL); @@ -3027,15 +2623,12 @@ int legacy_camera_attr_get_zoom(camera_h camera, int *zoom) int legacy_camera_attr_get_zoom_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_DIGITAL_ZOOM, &ainfo); if (ret == MM_ERROR_NONE) { *min = ainfo.int_range.min; @@ -3048,17 +2641,14 @@ int legacy_camera_attr_get_zoom_range(camera_h camera, int *min, int *max) int legacy_camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int focus_mode; int af_range; int detect_mode; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FOCUS_MODE, &focus_mode, MMCAM_CAMERA_AF_SCAN_RANGE, &af_range, @@ -3104,11 +2694,9 @@ int legacy_camera_attr_get_af_mode(camera_h camera, camera_attr_af_mode_e *mode) int legacy_camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - + int ret = MM_ERROR_NONE; + int exposure_mode; + camera_s *handle = (camera_s *)camera; int maptable[] = { CAMERA_ATTR_EXPOSURE_MODE_OFF, /* MM_CAMCORDER_AUTO_EXPOSURE_OFF */ CAMERA_ATTR_EXPOSURE_MODE_ALL, /* MM_CAMCORDER_AUTO_EXPOSURE_ALL */ @@ -3119,10 +2707,9 @@ int legacy_camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_m CAMERA_ATTR_EXPOSURE_MODE_SPOT, /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2 */ CAMERA_ATTR_EXPOSURE_MODE_CUSTOM, /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1 */ CAMERA_ATTR_EXPOSURE_MODE_CUSTOM /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2 */ - }; - int ret = MM_ERROR_NONE; - int exposure_mode; - camera_s *handle = (camera_s *)camera; + }; + + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_MODE, &exposure_mode, @@ -3137,14 +2724,11 @@ int legacy_camera_attr_get_exposure_mode(camera_h camera, camera_attr_exposure_m int legacy_camera_attr_get_exposure(camera_h camera, int *value) { - if (camera == NULL || value == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && value, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_EXPOSURE_VALUE, value, NULL); @@ -3155,15 +2739,12 @@ int legacy_camera_attr_get_exposure(camera_h camera, int *value) int legacy_camera_attr_get_exposure_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_VALUE, &ainfo); if (ret == MM_ERROR_NONE) { *min = ainfo.int_range.min; @@ -3176,14 +2757,11 @@ int legacy_camera_attr_get_exposure_range(camera_h camera, int *min, int *max) int legacy_camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso) { - if (camera == NULL || iso == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && iso, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ISO, iso, NULL); @@ -3194,14 +2772,11 @@ int legacy_camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso) int legacy_camera_attr_get_brightness(camera_h camera, int *level) { - if (camera == NULL || level == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && level, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_BRIGHTNESS, level, NULL); @@ -3212,15 +2787,12 @@ int legacy_camera_attr_get_brightness(camera_h camera, int *level) int legacy_camera_attr_get_brightness_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_BRIGHTNESS, &ainfo); if (ret == MM_ERROR_NONE) { *min = ainfo.int_range.min; @@ -3233,14 +2805,11 @@ int legacy_camera_attr_get_brightness_range(camera_h camera, int *min, int *max) int legacy_camera_attr_get_contrast(camera_h camera, int *level) { - if (camera == NULL || level == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && level, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_CONTRAST, level, NULL); @@ -3251,15 +2820,12 @@ int legacy_camera_attr_get_contrast(camera_h camera, int *level) int legacy_camera_attr_get_contrast_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_CONTRAST, &ainfo); if (ret == MM_ERROR_NONE) { *min = ainfo.int_range.min; @@ -3272,14 +2838,11 @@ int legacy_camera_attr_get_contrast_range(camera_h camera, int *min, int *max) int legacy_camera_attr_get_hue(camera_h camera, int *level) { - if (camera == NULL || level == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && level, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_HUE, level, NULL); @@ -3290,15 +2853,12 @@ int legacy_camera_attr_get_hue(camera_h camera, int *level) int legacy_camera_attr_get_hue_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_HUE, &ainfo); if (ret == MM_ERROR_NONE) { *min = ainfo.int_range.min; @@ -3311,14 +2871,11 @@ int legacy_camera_attr_get_hue_range(camera_h camera, int *min, int *max) int legacy_camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb) { - if (camera == NULL || wb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && wb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_WB, wb, NULL); @@ -3329,14 +2886,11 @@ int legacy_camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalanc int legacy_camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *effect) { - if (camera == NULL || effect == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && effect, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_COLOR_TONE, effect, NULL); @@ -3347,14 +2901,11 @@ int legacy_camera_attr_get_effect(camera_h camera, camera_attr_effect_mode_e *ef int legacy_camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_FILTER_SCENE_MODE, mode, NULL); @@ -3365,15 +2916,12 @@ int legacy_camera_attr_get_scene_mode(camera_h camera, camera_attr_scene_mode_e int legacy_camera_attr_is_enabled_tag(camera_h camera, bool *enable) { - if (camera == NULL || enable == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int get_enabled = 0; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && enable, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_ENABLE, &get_enabled, NULL); @@ -3387,16 +2935,13 @@ int legacy_camera_attr_is_enabled_tag(camera_h camera, bool *enable) int legacy_camera_attr_get_tag_image_description(camera_h camera, char **description) { - if (camera == NULL || description == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; char *ndescription = NULL; int desc_size; + camera_return_val_if_fail(handle && description, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_IMAGE_DESCRIPTION, &ndescription, &desc_size, NULL); @@ -3413,14 +2958,11 @@ int legacy_camera_attr_get_tag_image_description(camera_h camera, char **descrip int legacy_camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orientation_e *orientation) { - if (camera == NULL || orientation == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && orientation, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_ORIENTATION, orientation, NULL); @@ -3431,16 +2973,13 @@ int legacy_camera_attr_get_tag_orientation(camera_h camera, camera_attr_tag_orie int legacy_camera_attr_get_tag_software(camera_h camera, char **software) { - if (camera == NULL || software == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; char *soft = NULL; int soft_size; + camera_return_val_if_fail(handle && software, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_SOFTWARE, &soft, &soft_size, NULL); @@ -3457,14 +2996,11 @@ int legacy_camera_attr_get_tag_software(camera_h camera, char **software) int legacy_camera_attr_get_geotag(camera_h camera, double *latitude , double *longitude, double *altitude) { - if (camera == NULL || latitude == NULL || longitude == NULL || altitude == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && latitude && longitude && altitude, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_TAG_LATITUDE, latitude, MMCAM_TAG_LONGITUDE, longitude, @@ -3477,14 +3013,11 @@ int legacy_camera_attr_get_geotag(camera_h camera, double *latitude , double *lo int legacy_camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e *mode) { - if (camera == NULL || mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_STROBE_MODE, mode, NULL); @@ -3495,16 +3028,13 @@ int legacy_camera_attr_get_flash_mode(camera_h camera, camera_attr_flash_mode_e int legacy_camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_supported_af_mode_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int i = 0; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo af_range; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_AF_SCAN_RANGE, &af_range); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3521,11 +3051,10 @@ int legacy_camera_attr_foreach_supported_af_mode(camera_h camera, camera_attr_su int legacy_camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_attr_supported_exposure_mode_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - + int i = 0; + int ret = MM_ERROR_NONE; + camera_s *handle = (camera_s *)camera; + MMCamAttrsInfo info; int maptable[] = { CAMERA_ATTR_EXPOSURE_MODE_OFF, /* MM_CAMCORDER_AUTO_EXPOSURE_OFF */ CAMERA_ATTR_EXPOSURE_MODE_ALL, /* MM_CAMCORDER_AUTO_EXPOSURE_ALL */ @@ -3536,11 +3065,9 @@ int legacy_camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_a -1, /* MM_CAMCORDER_AUTO_EXPOSURE_SPOT_2 */ CAMERA_ATTR_EXPOSURE_MODE_CUSTOM, /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_1 */ -1 /* MM_CAMCORDER_AUTO_EXPOSURE_CUSTOM_2 */ - }; - int i = 0; - int ret = MM_ERROR_NONE; - camera_s *handle = (camera_s *)camera; - MMCamAttrsInfo info; + }; + + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_EXPOSURE_MODE, &info); if (ret != MM_ERROR_NONE) @@ -3564,16 +3091,13 @@ int legacy_camera_attr_foreach_supported_exposure_mode(camera_h camera, camera_a int legacy_camera_attr_foreach_supported_iso(camera_h camera, camera_attr_supported_iso_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ISO, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3589,16 +3113,13 @@ int legacy_camera_attr_foreach_supported_iso(camera_h camera, camera_attr_suppor int legacy_camera_attr_foreach_supported_whitebalance(camera_h camera, camera_attr_supported_whitebalance_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_WB, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3614,16 +3135,13 @@ int legacy_camera_attr_foreach_supported_whitebalance(camera_h camera, camera_at int legacy_camera_attr_foreach_supported_effect(camera_h camera, camera_attr_supported_effect_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_COLOR_TONE, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3639,16 +3157,13 @@ int legacy_camera_attr_foreach_supported_effect(camera_h camera, camera_attr_sup int legacy_camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr_supported_scene_mode_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_FILTER_SCENE_MODE, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3664,16 +3179,13 @@ int legacy_camera_attr_foreach_supported_scene_mode(camera_h camera, camera_attr int legacy_camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr_supported_flash_mode_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_STROBE_MODE, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3689,11 +3201,6 @@ int legacy_camera_attr_foreach_supported_flash_mode(camera_h camera, camera_attr int legacy_camera_attr_foreach_supported_fps(camera_h camera, camera_attr_supported_fps_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; @@ -3701,6 +3208,8 @@ int legacy_camera_attr_foreach_supported_fps(camera_h camera, camera_attr_suppor int height = 0; int i = 0; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_WIDTH, &width, MMCAM_CAMERA_HEIGHT, &height, @@ -3723,16 +3232,13 @@ int legacy_camera_attr_foreach_supported_fps(camera_h camera, camera_attr_suppor int legacy_camera_attr_foreach_supported_fps_by_resolution(camera_h camera, int width, int height, camera_attr_supported_fps_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; int i = 0; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_fps_list_by_resolution(handle->mm_handle, width, height, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3748,16 +3254,13 @@ int legacy_camera_attr_foreach_supported_fps_by_resolution(camera_h camera, int int legacy_camera_attr_foreach_supported_stream_flip(camera_h camera, camera_attr_supported_stream_flip_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_FLIP, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3773,16 +3276,13 @@ int legacy_camera_attr_foreach_supported_stream_flip(camera_h camera, camera_att int legacy_camera_attr_foreach_supported_stream_rotation(camera_h camera, camera_attr_supported_stream_rotation_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ROTATION, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -3798,19 +3298,12 @@ int legacy_camera_attr_foreach_supported_stream_rotation(camera_h camera, camera int legacy_camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (rotation > CAMERA_ROTATION_270) { - LOGE("invalid stream rotation %d", rotation); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(rotation <= CAMERA_ROTATION_270, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ROTATION, rotation, NULL); @@ -3821,14 +3314,11 @@ int legacy_camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e ro int legacy_camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *rotation) { - if (camera == NULL || rotation == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && rotation, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ROTATION, rotation, NULL); @@ -3839,19 +3329,12 @@ int legacy_camera_attr_get_stream_rotation(camera_h camera, camera_rotation_e *r int legacy_camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (flip > CAMERA_FLIP_BOTH) { - LOGE("invalid stream flip %d", flip); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(flip <= CAMERA_FLIP_BOTH, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FLIP, flip, NULL); @@ -3862,14 +3345,11 @@ int legacy_camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip) int legacy_camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip) { - if (camera == NULL || flip == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && flip, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_FLIP, flip, NULL); @@ -3882,10 +3362,7 @@ int _camera_set_use(camera_h camera, bool used) { camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("handle is NULL"); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); handle->is_used_in_recorder = used; @@ -3895,13 +3372,10 @@ int _camera_set_use(camera_h camera, bool used) int _camera_get_mm_handle(camera_h camera, MMHandleType *handle) { - if (camera == NULL || handle == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *camera_handle = (camera_s *)camera; + camera_return_val_if_fail(camera_handle && handle, CAMERA_ERROR_INVALID_PARAMETER); + *handle = camera_handle->mm_handle; return CAMERA_ERROR_NONE; @@ -3910,12 +3384,10 @@ int _camera_get_mm_handle(camera_h camera, MMHandleType *handle) int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback callback, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + handle->relay_message_callback = callback; handle->relay_user_data = user_data; @@ -3925,24 +3397,13 @@ int _camera_set_relay_mm_message_callback(camera_h camera, MMMessageCallback cal int legacy_camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (mode > CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL) { - LOGE("invalid HDR mode %d", mode); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_hdr_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(mode <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_hdr_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_HDR_CAPTURE, mode, NULL); @@ -3960,24 +3421,13 @@ int legacy_camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode int legacy_camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_hdr_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (mode == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - mode", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_hdr_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(mode, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_HDR_CAPTURE, mode, NULL); @@ -3988,16 +3438,13 @@ int legacy_camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mod bool legacy_camera_attr_is_supported_hdr_capture(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int ret = MM_ERROR_NONE; int i = 0; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo hdr_info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_HDR_CAPTURE, &hdr_info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -4020,23 +3467,12 @@ bool legacy_camera_attr_is_supported_hdr_capture(camera_h camera) int legacy_camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_progress_cb callback, void *user_data) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_hdr_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (callback == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - callback", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_hdr_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(callback, CAMERA_ERROR_INVALID_PARAMETER); + handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)callback; handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)user_data; @@ -4046,18 +3482,11 @@ int legacy_camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_ int legacy_camera_attr_unset_hdr_capture_progress_cb(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_hdr_capture(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_hdr_capture(camera), CAMERA_ERROR_NOT_SUPPORTED); + handle->user_cb[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)NULL; handle->user_data[_CAMERA_EVENT_TYPE_HDR_PROGRESS] = (void *)NULL; @@ -4067,25 +3496,14 @@ int legacy_camera_attr_unset_hdr_capture_progress_cb(camera_h camera) int legacy_camera_attr_enable_anti_shake(camera_h camera, bool enable) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_anti_shake(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - int ret = MM_ERROR_NONE; - int mode = MM_CAMCORDER_AHS_OFF; camera_s *handle = (camera_s *)camera; - if (enable) - mode = MM_CAMCORDER_AHS_ON; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_anti_shake(camera), CAMERA_ERROR_NOT_SUPPORTED); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - MMCAM_CAMERA_ANTI_HANDSHAKE, mode, + MMCAM_CAMERA_ANTI_HANDSHAKE, enable ? MM_CAMCORDER_AHS_ON : MM_CAMCORDER_AHS_OFF, NULL); return __convert_camera_error_code(__func__, ret); @@ -4094,25 +3512,14 @@ int legacy_camera_attr_enable_anti_shake(camera_h camera, bool enable) int legacy_camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_anti_shake(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (enabled == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int get_enabled = 0; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_anti_shake(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(enabled, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_ANTI_HANDSHAKE, &get_enabled, NULL); @@ -4126,16 +3533,13 @@ int legacy_camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled) bool legacy_camera_attr_is_supported_anti_shake(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ash_info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_ANTI_HANDSHAKE, &ash_info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -4154,25 +3558,14 @@ bool legacy_camera_attr_is_supported_anti_shake(camera_h camera) int legacy_camera_attr_enable_video_stabilization(camera_h camera, bool enable) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_video_stabilization(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - int ret = MM_ERROR_NONE; - int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF; camera_s *handle = (camera_s *)camera; - if (enable) - mode = MM_CAMCORDER_VIDEO_STABILIZATION_ON; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_video_stabilization(camera), CAMERA_ERROR_NOT_SUPPORTED); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - MMCAM_CAMERA_VIDEO_STABILIZATION, mode, + MMCAM_CAMERA_VIDEO_STABILIZATION, enable ? MM_CAMCORDER_VIDEO_STABILIZATION_ON : MM_CAMCORDER_VIDEO_STABILIZATION_OFF, NULL); return __convert_camera_error_code(__func__, ret); @@ -4181,25 +3574,14 @@ int legacy_camera_attr_enable_video_stabilization(camera_h camera, bool enable) int legacy_camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_video_stabilization(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (enabled == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int mode = MM_CAMCORDER_VIDEO_STABILIZATION_OFF; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_video_stabilization(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(enabled, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_VIDEO_STABILIZATION, &mode, NULL); @@ -4213,16 +3595,13 @@ int legacy_camera_attr_is_enabled_video_stabilization(camera_h camera, bool *ena bool legacy_camera_attr_is_supported_video_stabilization(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo vs_info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_VIDEO_STABILIZATION, &vs_info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -4241,25 +3620,14 @@ bool legacy_camera_attr_is_supported_video_stabilization(camera_h camera) int legacy_camera_attr_enable_auto_contrast(camera_h camera, bool enable) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_auto_contrast(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - int ret = MM_ERROR_NONE; - int mode = MM_CAMCORDER_WDR_OFF; camera_s *handle = (camera_s *)camera; - if (enable) - mode = MM_CAMCORDER_WDR_ON; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_auto_contrast(camera), CAMERA_ERROR_NOT_SUPPORTED); ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - MMCAM_CAMERA_WDR, mode, + MMCAM_CAMERA_WDR, enable ? MM_CAMCORDER_WDR_ON : MM_CAMCORDER_WDR_OFF, NULL); return __convert_camera_error_code(__func__, ret); @@ -4268,25 +3636,14 @@ int legacy_camera_attr_enable_auto_contrast(camera_h camera, bool enable) int legacy_camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - handle", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (legacy_camera_attr_is_supported_auto_contrast(camera) == false) { - LOGE("NOT_SUPPORTED(0x%08x)", CAMERA_ERROR_NOT_SUPPORTED); - return CAMERA_ERROR_NOT_SUPPORTED; - } - - if (enabled == NULL) { - LOGE("INVALID_PARAMETER(0x%08x) - enabled", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int mode = MM_CAMCORDER_WDR_OFF; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(legacy_camera_attr_is_supported_auto_contrast(camera), CAMERA_ERROR_NOT_SUPPORTED); + camera_return_val_if_fail(enabled, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_WDR, &mode, NULL); @@ -4300,16 +3657,13 @@ int legacy_camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled) bool legacy_camera_attr_is_supported_auto_contrast(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_WDR, &info); set_last_result(__convert_camera_error_code(__func__, ret)); if (ret != MM_ERROR_NONE) { @@ -4328,15 +3682,12 @@ bool legacy_camera_attr_is_supported_auto_contrast(camera_h camera) bool legacy_camera_attr_is_supported_user_buffer(camera_h camera) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return false; - } - int is_supported; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, false); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_SUPPORT_USER_BUFFER, &is_supported, NULL); @@ -4352,17 +3703,14 @@ bool legacy_camera_attr_is_supported_user_buffer(camera_h camera) int legacy_camera_attr_disable_shutter_sound(camera_h camera, bool disable) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, - "capture-sound-enable", !disable, - NULL); + "capture-sound-enable", !disable, + NULL); if (ret != MM_ERROR_NONE) { LOGE("CAMERA_ERROR_INVALID_OPERATION : not permitted disable shutter sound"); return CAMERA_ERROR_INVALID_OPERATION; @@ -4374,14 +3722,11 @@ int legacy_camera_attr_disable_shutter_sound(camera_h camera, bool disable) int legacy_camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate) { - if (camera == NULL || bitrate == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && bitrate, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_ENCODED_PREVIEW_BITRATE, bitrate, NULL); @@ -4392,19 +3737,12 @@ int legacy_camera_attr_get_encoded_preview_bitrate(camera_h camera, int *bitrate int legacy_camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (bitrate <= 0) { - LOGE("invalid encoded preview bitrate %d", bitrate); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(bitrate > 0, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_ENCODED_PREVIEW_BITRATE, bitrate, NULL); @@ -4415,14 +3753,11 @@ int legacy_camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate) int legacy_camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *interval) { - if (camera == NULL || interval == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && interval, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, interval, NULL); @@ -4433,19 +3768,12 @@ int legacy_camera_attr_get_encoded_preview_gop_interval(camera_h camera, int *in int legacy_camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (interval < 0) { - LOGE("invalid encoded preview gop interval %d", interval); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(interval >= 0, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, interval, NULL); @@ -4456,16 +3784,13 @@ int legacy_camera_attr_set_encoded_preview_gop_interval(camera_h camera, int int int legacy_camera_attr_set_pan(camera_h camera, int move_type, int pan_step) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int step = 0; const char *pan_type = NULL; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) pan_type = MMCAM_CAMERA_PAN_MECHA; else @@ -4496,15 +3821,12 @@ int legacy_camera_attr_set_pan(camera_h camera, int move_type, int pan_step) int legacy_camera_attr_get_pan(camera_h camera, int *pan_step) { - if (camera == NULL || pan_step == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; const char *pan_type = NULL; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && pan_step, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) pan_type = MMCAM_CAMERA_PAN_MECHA; else @@ -4520,16 +3842,13 @@ int legacy_camera_attr_get_pan(camera_h camera, int *pan_step) int legacy_camera_attr_get_pan_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; const char *pan_type = NULL; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) pan_type = MMCAM_CAMERA_PAN_MECHA; else @@ -4545,18 +3864,16 @@ int legacy_camera_attr_get_pan_range(camera_h camera, int *min, int *max) } +//LCOV_EXCL_START int legacy_camera_attr_set_tilt(camera_h camera, int move_type, int tilt_step) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int step = 0; const char *tilt_type = NULL; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) tilt_type = MMCAM_CAMERA_TILT_MECHA; else @@ -4587,15 +3904,12 @@ int legacy_camera_attr_set_tilt(camera_h camera, int move_type, int tilt_step) int legacy_camera_attr_get_tilt(camera_h camera, int *tilt_step) { - if (camera == NULL || tilt_step == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; const char *tilt_type = NULL; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && tilt_step, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) tilt_type = MMCAM_CAMERA_TILT_MECHA; else @@ -4611,16 +3925,13 @@ int legacy_camera_attr_get_tilt(camera_h camera, int *tilt_step) int legacy_camera_attr_get_tilt_range(camera_h camera, int *min, int *max) { - if (camera == NULL || min == NULL || max == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; const char *tilt_type = NULL; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo ainfo; + camera_return_val_if_fail(handle && min && max, CAMERA_ERROR_INVALID_PARAMETER); + if (handle->ptz_type == CAMERA_ATTR_PTZ_TYPE_MECHANICAL) tilt_type = MMCAM_CAMERA_TILT_MECHA; else @@ -4638,14 +3949,11 @@ int legacy_camera_attr_get_tilt_range(camera_h camera, int *min, int *max) int legacy_camera_attr_set_ptz_type(camera_h camera, int ptz_type) { - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_set_attributes(handle->mm_handle, NULL, MMCAM_CAMERA_PTZ_TYPE, ptz_type, NULL); @@ -4659,16 +3967,13 @@ int legacy_camera_attr_set_ptz_type(camera_h camera, int ptz_type) int legacy_camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_supported_ptz_type_cb foreach_cb, void *user_data) { - if (camera == NULL || foreach_cb == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int i = 0; int ret = MM_ERROR_NONE; camera_s *handle = (camera_s *)camera; MMCamAttrsInfo info; + camera_return_val_if_fail(handle && foreach_cb, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attribute_info(handle->mm_handle, MMCAM_CAMERA_PTZ_TYPE, &info); if (ret != MM_ERROR_NONE) return __convert_camera_error_code(__func__, ret); @@ -4680,19 +3985,17 @@ int legacy_camera_attr_foreach_supported_ptz_type(camera_h camera, camera_attr_s return CAMERA_ERROR_NONE; } +//LCOV_EXCL_STOP int legacy_camera_attr_set_display_roi_area(camera_h camera, int *display_roi_area) { - if (camera == NULL || display_roi_area == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int current_method = MM_DISPLAY_METHOD_LETTER_BOX; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && display_roi_area, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_GEOMETRY_METHOD, ¤t_method, NULL); @@ -4718,11 +4021,6 @@ int legacy_camera_attr_set_display_roi_area(camera_h camera, int *display_roi_ar int legacy_camera_attr_get_display_roi_area(camera_h camera, int *display_roi_area) { - if (camera == NULL || display_roi_area == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - int ret = MM_ERROR_NONE; int current_method = MM_DISPLAY_METHOD_LETTER_BOX; int x = 0; @@ -4731,6 +4029,8 @@ int legacy_camera_attr_get_display_roi_area(camera_h camera, int *display_roi_ar int height = 0; camera_s *handle = (camera_s *)camera; + camera_return_val_if_fail(handle && display_roi_area, CAMERA_ERROR_INVALID_PARAMETER); + ret = mm_camcorder_get_attributes(handle->mm_handle, NULL, MMCAM_DISPLAY_GEOMETRY_METHOD, ¤t_method, NULL); @@ -4768,10 +4068,7 @@ bool legacy_camera_is_used(camera_h camera) { camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("handle is NULL"); - return false; - } + camera_return_val_if_fail(handle, false); return handle->is_used_in_recorder; } @@ -4782,10 +4079,7 @@ bool legacy_camera_wait(camera_h camera, unsigned int timeout) camera_s *handle = (camera_s *)camera; gint64 end_time; - if (handle == NULL) { - LOGE("handle is NULL"); - return false; - } + camera_return_val_if_fail(handle, false); end_time = g_get_monotonic_time() + timeout * G_TIME_SPAN_MILLISECOND; @@ -4797,10 +4091,7 @@ void legacy_camera_lock(camera_h camera, bool is_lock) { camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("handle is NULL"); - return; - } + camera_return_if_fail(handle); LOGD("%p lock %d", handle, is_lock); @@ -4819,10 +4110,7 @@ void legacy_camera_send_signal(camera_h camera) { camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("handle is NULL"); - return; - } + camera_return_if_fail(handle); LOGD("send signal"); @@ -4837,19 +4125,10 @@ void legacy_camera_send_signal(camera_h camera) int legacy_camera_set_user_buffer(camera_h camera, int *fds, int number) { int ret = MM_ERROR_NONE; - camera_s *handle = NULL; - - if (camera == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER); - return CAMERA_ERROR_INVALID_PARAMETER; - } - - if (!fds || number < 1) { - LOGE("invalid fds %p or number %d", fds, number); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_s *handle = (camera_s *)camera; - handle = (camera_s *)camera; + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); + camera_return_val_if_fail(fds && number > 0, CAMERA_ERROR_INVALID_PARAMETER); LOGD("number - %d", number); @@ -4859,4 +4138,3 @@ int legacy_camera_set_user_buffer(camera_h camera, int *fds, int number) return __convert_camera_error_code(__func__, ret); } - diff --git a/legacy/src/legacy_camera_internal.c b/legacy/src/legacy_camera_internal.c index 05a233e..abba856 100644 --- a/legacy/src/legacy_camera_internal.c +++ b/legacy/src/legacy_camera_internal.c @@ -38,10 +38,7 @@ int legacy_camera_set_client_pid(camera_h camera, int pid) int ret; camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("NULL handle"); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); LOGE("pid %d", pid); @@ -58,10 +55,7 @@ void legacy_camera_emit_signal(camera_h camera, const char *object_name, { camera_s *handle = (camera_s *)camera; - if (!handle) { - LOGE("NULL handle"); - return; - } + camera_return_if_fail(handle); mm_camcorder_emit_signal(handle->mm_handle, object_name, interface_name, signal_name, value); @@ -75,10 +69,7 @@ int legacy_camera_set_gdbus_connection(camera_h camera, void *gdbus_connection) int ret; camera_s *handle = (camera_s *)camera; - if (handle == NULL) { - LOGE("NULL handle"); - return CAMERA_ERROR_INVALID_PARAMETER; - } + camera_return_val_if_fail(handle, CAMERA_ERROR_INVALID_PARAMETER); LOGD("gdbus connection %p", gdbus_connection); diff --git a/muse/src/muse_camera_dispatcher.c b/muse/src/muse_camera_dispatcher.c index 3715352..203bc23 100644 --- a/muse/src/muse_camera_dispatcher.c +++ b/muse/src/muse_camera_dispatcher.c @@ -39,6 +39,22 @@ #define MUSED_KEY_FLASH_STATE_RETURN "camera_get_flash_state_return" #define MUSED_KEY_FLASH_STATE_COUNT "camera_get_flash_state_count" +#define camera_return_if_fail(expr) \ + do { \ + if (!(expr)) { \ + LOGE("failed [%s]", #expr); \ + return; \ + } \ + } while (0) + +#define camera_return_val_if_fail(expr, val) \ + do { \ + if (!(expr)) { \ + LOGE("failed [%s]", #expr); \ + return (val); \ + } \ + } while (0) + static int _camera_remove_export_data(muse_module_h module, tbm_fd fd, int remove_all); static void __camera_dispatcher_send_msg(muse_module_h module, char *msg, int *tfd) @@ -46,10 +62,7 @@ static void __camera_dispatcher_send_msg(muse_module_h module, char *msg, int *t int len = 0; int sock_fd = 0; - if (!msg) { - LOGE("NULL msg"); - return; - } + camera_return_if_fail(msg); if (!module) { LOGE("NULL module"); @@ -228,10 +241,7 @@ bool _camera_dispatcher_callback_supported_theater_mode(int param1, void *user_d { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_THEATER_MODE, @@ -245,10 +255,7 @@ bool _camera_dispatcher_callback_supported_af_mode(int param1, void *user_data) { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_AF_MODE, @@ -262,10 +269,7 @@ bool _camera_dispatcher_callback_supported_exposure_mode(int param1, void *user_ { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EXPOSURE_MODE, @@ -279,10 +283,7 @@ bool _camera_dispatcher_callback_supported_iso_mode(int param1, void *user_data) { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_ISO, @@ -296,10 +297,7 @@ bool _camera_dispatcher_callback_supported_whitebalance(int param1, void *user_d { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_WHITEBALANCE, @@ -313,10 +311,7 @@ bool _camera_dispatcher_callback_supported_effect(int param1, void *user_data) { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_EFFECT, @@ -330,10 +325,7 @@ bool _camera_dispatcher_callback_supported_scene_mode(int param1, void *user_dat { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_SCENE_MODE, @@ -347,10 +339,7 @@ bool _camera_dispatcher_callback_supported_flash_mode(int param1, void *user_dat { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FLASH_MODE, @@ -374,10 +363,7 @@ bool _camera_dispatcher_callback_supported_fps(int param1, void *user_data) { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS, @@ -391,10 +377,7 @@ bool _camera_dispatcher_callback_supported_fps_by_resolution(int param1, void *u { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_FPS_BY_RESOLUTION, @@ -408,10 +391,7 @@ bool _camera_dispatcher_callback_supported_stream_flip(int param1, void *user_da { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_FLIP, @@ -425,10 +405,7 @@ bool _camera_dispatcher_callback_supported_stream_rotation(int param1, void *use { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_STREAM_ROTATION, @@ -442,10 +419,7 @@ bool _camera_dispatcher_callback_supported_capture_format(int param1, void *user { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_FORMAT, @@ -459,10 +433,7 @@ bool _camera_dispatcher_callback_supported_preview_format(int param1, void *user { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_FORMAT, @@ -476,10 +447,7 @@ bool _camera_dispatcher_callback_supported_preview_resolution(int param1, int pa { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PREVIEW_RESOLUTION, @@ -493,6 +461,8 @@ bool _camera_dispatcher_callback_supported_capture_resolution(int param1, int pa { muse_module_h module = (muse_module_h)user_data; + camera_return_val_if_fail(module, false); + muse_camera_msg_event2(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_CAPTURE_RESOLUTION, MUSE_CAMERA_EVENT_CLASS_THREAD_SUB, @@ -505,10 +475,7 @@ bool _camera_dispatcher_callback_supported_ptz_type(int param1, void *user_data) { muse_module_h module = (muse_module_h)user_data; - if (!module) { - LOGE("NULL module"); - return false; - } + camera_return_val_if_fail(module, false); muse_camera_msg_event1(MUSE_CAMERA_CB_EVENT, MUSE_CAMERA_EVENT_TYPE_FOREACH_SUPPORTED_PTZ_TYPE, @@ -525,16 +492,12 @@ static int _camera_remove_export_data(muse_module_h module, tbm_fd fd, int remov GList *tmp_list = NULL; muse_camera_export_data *export_data = NULL; - if (module == NULL || (fd < 0 && remove_all == FALSE)) { - LOGE("invalid parameter %p, %d", module, fd); - return FALSE; - } + camera_return_val_if_fail(module, FALSE); + camera_return_val_if_fail(fd >= 0 || remove_all, FALSE); muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - if (muse_camera == NULL) { - LOGE("NULL handle"); - return FALSE; - } + + camera_return_val_if_fail(muse_camera, FALSE); g_mutex_lock(&muse_camera->list_lock); @@ -543,82 +506,81 @@ static int _camera_remove_export_data(muse_module_h module, tbm_fd fd, int remov while (tmp_list) { export_data = (muse_camera_export_data *)tmp_list->data; tmp_list = tmp_list->next; - if (export_data) { - if (export_data->fd == fd || remove_all) { - /*LOGD("fd %d matched, remove it (remove_all %d)", fd, remove_all);*/ + if (!export_data) { + LOGW("NULL data"); + continue; + } - if (remove_all) { - LOGW("remove remained export data fd %d, internal buffer %p", - export_data->fd, export_data->internal_buffer); - } + if (export_data->fd != fd && remove_all == FALSE) + continue; - if (export_data->is_capture) { - LOGD("capture callback is done"); - g_cond_signal(&muse_camera->list_cond); - } + /*LOGD("fd %d matched, remove it (remove_all %d)", fd, remove_all);*/ - /* unref bo and close exported fd */ - if (export_data->bo) { - /*LOGD("close export_data->fd %d", export_data->fd);*/ + if (remove_all) { + LOGW("remove remained export data fd %d, internal buffer %p", + export_data->fd, export_data->internal_buffer); + } - close(export_data->fd); - export_data->fd = -1; + if (export_data->is_capture) { + LOGD("capture callback is done"); + g_cond_signal(&muse_camera->list_cond); + } - tbm_bo_unref(export_data->bo); - export_data->bo = NULL; - } else { - LOGW("bo for fd %d is NULL", fd); - } + /* unref bo and close exported fd */ + if (export_data->bo) { + /*LOGD("close export_data->fd %d", export_data->fd);*/ - /* unref data_bo and exported fd */ - if (export_data->data_bo) { - /*LOGD("close export_data->data_fd %d", export_data->data_fd);*/ + close(export_data->fd); + export_data->fd = -1; - close(export_data->data_fd); - export_data->data_fd = -1; + tbm_bo_unref(export_data->bo); + export_data->bo = NULL; + } else { + LOGW("bo for fd %d is NULL", fd); + } - tbm_bo_unref(export_data->data_bo); - export_data->data_bo = NULL; - } + /* unref data_bo and exported fd */ + if (export_data->data_bo) { + /*LOGD("close export_data->data_fd %d", export_data->data_fd);*/ - /* close exported fd for zero copy buffer */ - for (i = 0 ; i < export_data->num_buffer_fd ; i++) { - /*LOGD("close export_data->buffer_fd[%d] %d", i, export_data->buffer_fd[i]);*/ - close(export_data->buffer_fd[i]); - export_data->buffer_fd[i] = -1; - } + close(export_data->data_fd); + export_data->data_fd = -1; - /* unref GstBuffer */ - if (export_data->internal_buffer) { - gst_buffer_unref((GstBuffer *)export_data->internal_buffer); - export_data->internal_buffer = NULL; - } + tbm_bo_unref(export_data->data_bo); + export_data->data_bo = NULL; + } - muse_camera->data_list = g_list_remove(muse_camera->data_list, export_data); + /* close exported fd for zero copy buffer */ + for (i = 0 ; i < export_data->num_buffer_fd ; i++) { + /*LOGD("close export_data->buffer_fd[%d] %d", i, export_data->buffer_fd[i]);*/ + close(export_data->buffer_fd[i]); + export_data->buffer_fd[i] = -1; + } + + /* unref GstBuffer */ + if (export_data->internal_buffer) { + gst_buffer_unref((GstBuffer *)export_data->internal_buffer); + export_data->internal_buffer = NULL; + } - g_free(export_data); - export_data = NULL; + muse_camera->data_list = g_list_remove(muse_camera->data_list, export_data); - if (remove_all == FALSE) { - /*LOGD("fd %d, remove done", fd);*/ - g_mutex_unlock(&muse_camera->list_lock); - return TRUE; - } else { - LOGD("check next data"); - } - } - } else { - LOGW("NULL data"); + g_free(export_data); + export_data = NULL; + + if (remove_all == FALSE) { + /*LOGD("fd %d, remove done", fd);*/ + g_mutex_unlock(&muse_camera->list_lock); + return TRUE; } } g_mutex_unlock(&muse_camera->list_lock); - if (remove_all) { + if (remove_all) LOGW("remove all done"); - } else { + else LOGE("should not be reached here - fd %d", fd); - } return FALSE; } @@ -648,17 +610,11 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da LOGD("Enter!!"); muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - if (!muse_camera || !image) { - LOGE("invalid ptr %p %p", muse_camera, image); - return; - } + + camera_return_if_fail(muse_camera && image); /* main image */ export_data_main = g_new0(muse_camera_export_data, 1); - if (export_data_main == NULL) { - LOGE("alloc export_data failed"); - return; - } data_size_main = sizeof(camera_image_data_s) + image->size; if (image->exif && image->exif_size > 0) @@ -817,6 +773,7 @@ void _camera_dispatcher_capturing_cb(camera_image_data_s* image, camera_image_da return; +//LCOV_EXCL_START thumbnail_image_error: if (bo_thumb) { tbm_bo_unref(bo_thumb); @@ -851,6 +808,7 @@ main_image_error: } return; +//LCOV_EXCL_STOP } void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data) @@ -872,10 +830,8 @@ void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e module, "previous", previous, "current", current, "by_policy", by_policy); muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - if (!muse_camera) { - LOGW("NULL muse camera handle"); - return; - } + + camera_return_if_fail(muse_camera); ret = legacy_camera_get_device_type(muse_camera->camera_handle, &device_type); if (ret != CAMERA_ERROR_NONE) { @@ -903,6 +859,8 @@ void _camera_dispatcher_state_changed_cb(camera_state_e previous, camera_state_e return; } + +//LCOV_EXCL_START void _camera_dispatcher_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data) { muse_module_h module = (muse_module_h)user_data; @@ -931,6 +889,8 @@ void _camera_dispatcher_interrupt_started_cb(camera_policy_e policy, camera_stat return; } +//LCOV_EXCL_STOP + void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void *user_data) { @@ -955,22 +915,11 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void /*LOGD("Enter");*/ - if (module == NULL || stream == NULL) { - LOGE("NULL data %p, %p", module, stream); - return; - } - muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - if (muse_camera == NULL) { - LOGE("NULL handle"); - return; - } + + camera_return_if_fail(muse_camera && stream); export_data = g_new0(muse_camera_export_data, 1); - if (export_data == NULL) { - LOGE("alloc export_data failed"); - return; - } export_data->fd = -1; export_data->data_fd = -1; @@ -1174,6 +1123,7 @@ void _camera_dispatcher_preview_cb(MMCamcorderVideoStreamDataType *stream, void return; +//LCOV_EXCL_START _PREVIEW_CB_ERROR: if (bo) { tbm_bo_unref(bo); @@ -1211,6 +1161,7 @@ _PREVIEW_CB_ERROR: } return; +//LCOV_EXCL_STOP } void _camera_dispatcher_capture_completed_cb(void *user_data) @@ -1237,91 +1188,79 @@ void _camera_dispatcher_face_detected_cb(camera_detected_face_s *faces, int coun tbm_fd tfd[MUSE_NUM_FD] = {-1, -1, -1, -1}; muse_camera_export_data *export_data = NULL; - if (count >= 0) { - if (module == NULL) { - LOGE("NULL module"); - return; - } + camera_return_if_fail(module); + camera_return_if_fail(count >= 0); - if (bo_size > 0) { - muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - if (muse_camera == NULL) { - LOGE("NULL handle"); - return; - } + if (bo_size > 0) { + muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); - export_data = g_new0(muse_camera_export_data, 1); - if (export_data == NULL) { - LOGE("alloc export_data failed"); - return; - } + camera_return_if_fail(muse_camera); - bo = tbm_bo_alloc(muse_camera->bufmgr, bo_size, TBM_BO_DEFAULT); - if (bo == NULL) { - LOGE("tbm_bo_alloc failed"); + export_data = g_new0(muse_camera_export_data, 1); - g_free(export_data); - export_data = NULL; - - return; - } + bo = tbm_bo_alloc(muse_camera->bufmgr, bo_size, TBM_BO_DEFAULT); + if (bo == NULL) { + LOGE("tbm_bo_alloc failed"); - bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE); - if (bo_handle.ptr == NULL) { - LOGE("bo map Error!"); + g_free(export_data); + export_data = NULL; - tbm_bo_unref(bo); - bo = NULL; + return; + } - g_free(export_data); - export_data = NULL; + bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ | TBM_OPTION_WRITE); + if (bo_handle.ptr == NULL) { + LOGE("bo map Error!"); - return; - } + tbm_bo_unref(bo); + bo = NULL; - /* copy face detection info */ - memcpy(bo_handle.ptr, faces, bo_size); + g_free(export_data); + export_data = NULL; - tbm_bo_unmap(bo); + return; + } - /* export bo */ - tfd[0] = tbm_bo_export_fd(bo); - if (tfd[0] < 0) { - LOGE("failed to export bo for face detection info"); + /* copy face detection info */ + memcpy(bo_handle.ptr, faces, bo_size); - tbm_bo_unref(bo); - bo = NULL; + tbm_bo_unmap(bo); - g_free(export_data); - export_data = NULL; + /* export bo */ + tfd[0] = tbm_bo_export_fd(bo); + if (tfd[0] < 0) { + LOGE("failed to export bo for face detection info"); - return; - } + tbm_bo_unref(bo); + bo = NULL; - /* set export data */ - export_data->bo = bo; - export_data->fd = tfd[0]; + g_free(export_data); + export_data = NULL; - /* add bo info to list */ - g_mutex_lock(&muse_camera->list_lock); - muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data); - g_mutex_unlock(&muse_camera->list_lock); + return; } - LOGD("face - count %d, buffer size %d, fd %d", count, bo_size, tfd[0]); + /* set export data */ + export_data->bo = bo; + export_data->fd = tfd[0]; - /* send message */ - muse_camera_msg_event2_fd(MUSE_CAMERA_CB_EVENT, - MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION, - MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN, - module, - "count", count, - "face_fd", tfd[0], - (int *)tfd); - } else { - LOGW("invalid count for face detection - %d", count); + /* add bo info to list */ + g_mutex_lock(&muse_camera->list_lock); + muse_camera->data_list = g_list_append(muse_camera->data_list, (gpointer)export_data); + g_mutex_unlock(&muse_camera->list_lock); } + LOGD("face - count %d, buffer size %d, fd %d", count, bo_size, tfd[0]); + + /* send message */ + muse_camera_msg_event2_fd(MUSE_CAMERA_CB_EVENT, + MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION, + MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN, + module, + "count", count, + "face_fd", tfd[0], + (int *)tfd); + return; } @@ -1372,17 +1311,9 @@ static void _camera_task_add_job(muse_camera_handle_s *muse_camera, int api, int { muse_camera_task_job_s *job = NULL; - if (!muse_camera) { - LOGE("NULL handle"); - return; - } + camera_return_if_fail(muse_camera); job = g_new0(muse_camera_task_job_s, 1); - if (!job) { - LOGE("job alloc failed"); - muse_camera_msg_return(api, class, CAMERA_ERROR_INVALID_OPERATION, muse_camera->module); - return; - } job->api = api; job->class = class; @@ -1493,10 +1424,7 @@ static void *_camera_dispatcher_task_func(gpointer data) bool is_signaled = false; bool use_wait_until = false; - if (!muse_camera) { - LOGE("NULL handle"); - return NULL; - } + camera_return_val_if_fail(muse_camera, NULL); LOGW("enter"); @@ -1562,15 +1490,12 @@ static void _camera_dispatcher_release_resource(muse_module_h module) { muse_camera_handle_s *muse_camera = NULL; - if (!module) { - LOGE("NULL handle"); - return; - } - LOGW("enter"); muse_camera = (muse_camera_handle_s *)muse_server_ipc_get_handle(module); + camera_return_if_fail(muse_camera); + _camera_remove_export_data(module, -1, TRUE); g_mutex_clear(&muse_camera->list_lock); @@ -1734,6 +1659,7 @@ int camera_dispatcher_create(muse_module_h module) return MUSE_CAMERA_ERROR_NONE; +//LCOV_EXCL_START _CREATE_ERROR: if (muse_camera->task_thread) { g_mutex_lock(&muse_camera->task_lock); @@ -1759,6 +1685,7 @@ _CREATE_ERROR: muse_camera_msg_return(api, class, ret, module); return MUSE_CAMERA_ERROR_INVALID; +//LCOV_EXCL_STOP } @@ -1796,6 +1723,10 @@ int camera_dispatcher_destroy(muse_module_h module) LOGD("Enter, handle : %p", muse_camera); + ret = legacy_camera_unset_state_changed_cb(muse_camera->camera_handle); + if (ret != CAMERA_ERROR_NONE) + LOGE("unset state changed cb failed 0x%x", ret); + ret = legacy_camera_destroy(muse_camera->camera_handle); if (ret == CAMERA_ERROR_NONE) _camera_dispatcher_release_resource(module); @@ -5510,6 +5441,7 @@ int (*dispatcher[MUSE_CAMERA_API_MAX]) (muse_module_h module) = { /******************/ /* cmd dispatcher */ /******************/ +//LCOV_EXCL_START static int camera_cmd_dispatcher_shutdown(muse_module_h module) { muse_camera_handle_s *muse_camera = NULL; @@ -5579,6 +5511,7 @@ again: return MUSE_CAMERA_ERROR_NONE; } +//LCOV_EXCL_STOP int (*cmd_dispatcher[MUSE_MODULE_COMMAND_MAX])(muse_module_h module) = { diff --git a/packaging/mmsvc-camera.spec b/packaging/mmsvc-camera.spec index bfdd41b..0bb888b 100644 --- a/packaging/mmsvc-camera.spec +++ b/packaging/mmsvc-camera.spec @@ -1,6 +1,6 @@ Name: mmsvc-camera Summary: A Camera module for muse server -Version: 0.3.30 +Version: 0.3.31 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 -- 2.7.4