Skip to content

Commit

Permalink
[Build] Support VD product build system
Browse files Browse the repository at this point in the history
This patch supports the VD product build system.
`enable_tizen_privilege_check` and `enable_tizen_feature_check` are
newly added and below features are disabled.
* Privacy / Privilege Manager
* Resource Manager
* ProtoBuffer / FlatBuffer
* Test since python-numpy is not supported

Signed-off-by: Sangjung Woo <[email protected]>
  • Loading branch information
again4you authored and myungjoo committed Jul 24, 2020
1 parent 9ac15a5 commit 026f3db
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 123 deletions.
19 changes: 18 additions & 1 deletion api/capi/include/nnstreamer-capi-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#if defined (__TIZEN__)
#include "nnstreamer-tizen-internal.h"

#if defined (__FEATURE_CHECK_SUPPORT__)
#define check_feature_state() \
do { \
int feature_ret = ml_tizen_get_feature_enabled (); \
Expand All @@ -44,6 +45,13 @@
} while (0);

#define set_feature_state(...) ml_tizen_set_feature_state(__VA_ARGS__)
#else
#define check_feature_state()
#define set_feature_state(...)
#endif /* __FEATURE_CHECK_SUPPORT__ */

#if defined (__PRIVILEGE_CHECK_SUPPORT__)

#define convert_tizen_element(...) ml_tizen_convert_element(__VA_ARGS__)

#if (TIZENVERSION >= 5) && (TIZENVERSION < 9999)
Expand All @@ -62,14 +70,23 @@ typedef enum { MM_RESOURCE_MANAGER_RES_TYPE_MAX } mm_resource_manager_res_type_e
#error Tizen version is not defined.
#endif

#else

#define convert_tizen_element(...) ML_ERROR_NONE
#define get_tizen_resource(...) ML_ERROR_NONE
#define release_tizen_resource(...)
#define TIZEN5PLUS 0

#endif /* __PRIVILEGE_CHECK_SUPPORT__ */

#else
#define check_feature_state()
#define set_feature_state(...)
#define convert_tizen_element(...) ML_ERROR_NONE
#define get_tizen_resource(...) ML_ERROR_NONE
#define release_tizen_resource(...)
#define TIZEN5PLUS 0
#endif
#endif /* __TIZEN__ */

#ifdef __cplusplus
extern "C" {
Expand Down
20 changes: 15 additions & 5 deletions api/capi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ capi_main += join_paths(meson.current_source_dir(), 'src', 'nnstreamer-capi-util
capi_main += join_paths(meson.current_source_dir(), 'src', 'nnstreamer-capi-single.c')
capi_main += join_paths(meson.current_source_dir(), 'src', 'tensor_filter_single.c')

if get_option('enable-tizen')
capi_main += join_paths('src', 'nnstreamer-capi-tizen.c')
if get_option('enable-tizen') and get_option('enable-tizen-feature-check')
capi_main += join_paths(meson.current_source_dir(), 'src', 'nnstreamer-capi-tizen-feature-check.c')
endif

if get_option('enable-tizen') and get_option('enable-tizen-privilege-check')
capi_main += join_paths(meson.current_source_dir(), 'src', 'nnstreamer-capi-tizen-privilege-check.c')
endif

capi_devel_main = []
Expand All @@ -59,21 +63,27 @@ if (get_option('enable-tizen'))
tizen_deps = [
dependency('dpm'),
dependency('mm-camcorder'),
dependency('capi-privacy-privilege-manager'),
dependency('capi-base-common'),
dependency('capi-system-info'),
dependency('dlog')
]

if get_option('enable-tizen-privilege-check')
tizen_deps += dependency('capi-privacy-privilege-manager')
endif
else
tizen_deps = [
dependency('dpm'),
dependency('mm-resource-manager'),
dependency('mm-camcorder'),
dependency('capi-privacy-privilege-manager'),
dependency('capi-base-common'),
dependency('capi-system-info'),
dependency('dlog')
]

if get_option('enable-tizen-privilege-check')
tizen_deps += dependency('mm-resource-manager')
tizen_deps += dependency('capi-privacy-privilege-manager')
endif
endif

capi_deps += tizen_deps
Expand Down
142 changes: 142 additions & 0 deletions api/capi/src/nnstreamer-capi-tizen-feature-check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*/

/**
* @file nnstreamer-capi-tizen-feature-check.c
* @date 21 July 2020
* @brief NNStreamer/C-API Tizen dependent functions.
* @see https://github.com/nnstreamer/nnstreamer
* @author MyungJoo Ham <[email protected]>
* @bug No known bugs except for NYI items
*/

#if !defined (__TIZEN__) || !defined (__FEATURE_CHECK_SUPPORT__)
#error "This file can be included only in Tizen."
#endif

#include <glib.h>
#include <system_info.h>

#include "nnstreamer-capi-private.h"

/**
* @brief Tizen ML feature.
*/
#define ML_INF_FEATURE_PATH "tizen.org/feature/machine_learning.inference"

/**
* @brief Internal struct to control tizen feature support (machine_learning.inference).
* -1: Not checked yet, 0: Not supported, 1: Supported
*/
typedef struct
{
GMutex mutex;
int feature_state;
} feature_info_s;

static feature_info_s *feature_info = NULL;

/**
* @brief Internal function to initialize feature state.
*/
static void
ml_tizen_initialize_feature_state (void)
{
if (feature_info == NULL) {
feature_info = g_new0 (feature_info_s, 1);
g_assert (feature_info);

g_mutex_init (&feature_info->mutex);
feature_info->feature_state = -1;
}
}

/**
* @brief Set the feature status of machine_learning.inference.
*/
int
ml_tizen_set_feature_state (int state)
{
ml_tizen_initialize_feature_state ();
g_mutex_lock (&feature_info->mutex);

/**
* Update feature status
* -1: Not checked yet, 0: Not supported, 1: Supported
*/
feature_info->feature_state = state;

g_mutex_unlock (&feature_info->mutex);
return ML_ERROR_NONE;
}

/**
* @brief Checks whether machine_learning.inference feature is enabled or not.
*/
int
ml_tizen_get_feature_enabled (void)
{
int ret;
int feature_enabled;

ml_tizen_initialize_feature_state ();

g_mutex_lock (&feature_info->mutex);
feature_enabled = feature_info->feature_state;
g_mutex_unlock (&feature_info->mutex);

if (0 == feature_enabled) {
ml_loge ("machine_learning.inference NOT supported");
return ML_ERROR_NOT_SUPPORTED;
} else if (-1 == feature_enabled) {
bool ml_inf_supported = false;
ret =
system_info_get_platform_bool (ML_INF_FEATURE_PATH, &ml_inf_supported);
if (0 == ret) {
if (false == ml_inf_supported) {
ml_loge ("machine_learning.inference NOT supported");
ml_tizen_set_feature_state (0);
return ML_ERROR_NOT_SUPPORTED;
}

ml_tizen_set_feature_state (1);
} else {
switch (ret) {
case SYSTEM_INFO_ERROR_INVALID_PARAMETER:
ml_loge
("failed to get feature value because feature key is not vaild");
ret = ML_ERROR_NOT_SUPPORTED;
break;

case SYSTEM_INFO_ERROR_IO_ERROR:
ml_loge ("failed to get feature value because of input/output error");
ret = ML_ERROR_NOT_SUPPORTED;
break;

case SYSTEM_INFO_ERROR_PERMISSION_DENIED:
ml_loge ("failed to get feature value because of permission denied");
ret = ML_ERROR_PERMISSION_DENIED;
break;

default:
ml_loge ("failed to get feature value because of unknown error");
ret = ML_ERROR_NOT_SUPPORTED;
break;
}
return ret;
}
}

return ML_ERROR_NONE;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved.
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand All @@ -13,15 +13,15 @@
*/

/**
* @file nnstreamer-capi-tizen.c
* @date 26 August 2019
* @file nnstreamer-capi-tizen-privilege-check.c
* @date 22 July 2020
* @brief NNStreamer/C-API Tizen dependent functions.
* @see https://github.com/nnstreamer/nnstreamer
* @author MyungJoo Ham <[email protected]>
* @bug No known bugs except for NYI items
*/

#if !defined (__TIZEN__)
#if !defined (__TIZEN__) || !defined (__PRIVILEGE_CHECK_SUPPORT__)
#error "This file can be included only in Tizen."
#endif

Expand Down Expand Up @@ -129,11 +129,6 @@ typedef struct
*/
#define TIZEN_RES_MM "tizen_res_mm"

/**
* @brief Tizen ML feature.
*/
#define ML_INF_FEATURE_PATH "tizen.org/feature/machine_learning.inference"

/**
* @brief Tizen Privilege Camera (See https://www.tizen.org/privilege)
*/
Expand All @@ -144,112 +139,6 @@ typedef struct
*/
#define TIZEN_PRIVILEGE_RECODER "http://tizen.org/privilege/recorder"

/**
* @brief Internal struct to control tizen feature support (machine_learning.inference).
* -1: Not checked yet, 0: Not supported, 1: Supported
*/
typedef struct
{
GMutex mutex;
int feature_state;
} feature_info_s;

static feature_info_s *feature_info = NULL;

/**
* @brief Internal function to initialize feature state.
*/
static void
ml_tizen_initialize_feature_state (void)
{
if (feature_info == NULL) {
feature_info = g_new0 (feature_info_s, 1);
g_assert (feature_info);

g_mutex_init (&feature_info->mutex);
feature_info->feature_state = -1;
}
}

/**
* @brief Set the feature status of machine_learning.inference.
*/
int
ml_tizen_set_feature_state (int state)
{
ml_tizen_initialize_feature_state ();
g_mutex_lock (&feature_info->mutex);

/**
* Update feature status
* -1: Not checked yet, 0: Not supported, 1: Supported
*/
feature_info->feature_state = state;

g_mutex_unlock (&feature_info->mutex);
return ML_ERROR_NONE;
}

/**
* @brief Checks whether machine_learning.inference feature is enabled or not.
*/
int
ml_tizen_get_feature_enabled (void)
{
int ret;
int feature_enabled;

ml_tizen_initialize_feature_state ();

g_mutex_lock (&feature_info->mutex);
feature_enabled = feature_info->feature_state;
g_mutex_unlock (&feature_info->mutex);

if (0 == feature_enabled) {
ml_loge ("machine_learning.inference NOT supported");
return ML_ERROR_NOT_SUPPORTED;
} else if (-1 == feature_enabled) {
bool ml_inf_supported = false;
ret =
system_info_get_platform_bool (ML_INF_FEATURE_PATH, &ml_inf_supported);
if (0 == ret) {
if (false == ml_inf_supported) {
ml_loge ("machine_learning.inference NOT supported");
ml_tizen_set_feature_state (0);
return ML_ERROR_NOT_SUPPORTED;
}

ml_tizen_set_feature_state (1);
} else {
switch (ret) {
case SYSTEM_INFO_ERROR_INVALID_PARAMETER:
ml_loge
("failed to get feature value because feature key is not vaild");
ret = ML_ERROR_NOT_SUPPORTED;
break;

case SYSTEM_INFO_ERROR_IO_ERROR:
ml_loge ("failed to get feature value because of input/output error");
ret = ML_ERROR_NOT_SUPPORTED;
break;

case SYSTEM_INFO_ERROR_PERMISSION_DENIED:
ml_loge ("failed to get feature value because of permission denied");
ret = ML_ERROR_PERMISSION_DENIED;
break;

default:
ml_loge ("failed to get feature value because of unknown error");
ret = ML_ERROR_NOT_SUPPORTED;
break;
}
return ret;
}
}

return ML_ERROR_NONE;
}

/** The following functions are either not used or supported in Tizen 4 */
#if TIZEN5PLUS
/**
Expand Down
Loading

0 comments on commit 026f3db

Please sign in to comment.