Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions c/src/ml-api-common-tizen-feature-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ static feature_info_s *feature_info = NULL;
/**
* @brief Internal function to initialize feature state.
*/
static void
static int
ml_tizen_initialize_feature_state (void)
{
int i;

if (feature_info == NULL) {
feature_info = g_new0 (feature_info_s, 1);
g_assert (feature_info);
feature_info = g_try_new0 (feature_info_s, 1);
if (feature_info == NULL) {
_ml_loge ("Failed to allocate memory for feature_info");
return ML_ERROR_OUT_OF_MEMORY;
}

g_mutex_init (&feature_info->mutex);
for (i = 0; i < ML_FEATURE_MAX; i++)
feature_info->feature_state[i] = NOT_CHECKED_YET;
}
return ML_ERROR_NONE;
}

/**
Expand All @@ -66,7 +70,12 @@ ml_tizen_initialize_feature_state (void)
int
_ml_tizen_set_feature_state (ml_feature_e ml_feature, int state)
{
ml_tizen_initialize_feature_state ();
int status;

status = ml_tizen_initialize_feature_state ();
if (status != ML_ERROR_NONE)
return status;

g_mutex_lock (&feature_info->mutex);

/**
Expand Down Expand Up @@ -97,7 +106,9 @@ _ml_tizen_get_feature_enabled (ml_feature_e ml_feature)
int ret;
int feature_enabled;

ml_tizen_initialize_feature_state ();
ret = ml_tizen_initialize_feature_state ();
if (ret != ML_ERROR_NONE)
return ret;

g_mutex_lock (&feature_info->mutex);
feature_enabled = feature_info->feature_state[ml_feature];
Expand Down
10 changes: 7 additions & 3 deletions c/src/ml-api-inference-pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ construct_pipeline_internal (const char *pipeline_description,
pipeline = gst_parse_launch (description, &err);
g_free (description);

if (pipeline == NULL || err) {
if (!GST_IS_PIPELINE (pipeline) || err) {
_ml_error_report
("ml_pipeline_construct error: gst_parse_launch cannot parse and launch the given pipeline = [%s]. The error message from gst_parse_launch is '%s'.",
pipeline_description, (err) ? err->message : "unknown reason");
Expand All @@ -1044,12 +1044,16 @@ construct_pipeline_internal (const char *pipeline_description,
goto failed;
}

g_assert (GST_IS_PIPELINE (pipeline));
pipe_h->element = pipeline;

/* bus and message callback */
pipe_h->bus = gst_element_get_bus (pipeline);
g_assert (pipe_h->bus);
if (pipe_h->bus == NULL) {
_ml_error_report
("ml_pipeline_construct error: Failed to retrieve bus from the pipeline.");
status = ML_ERROR_STREAMS_PIPE;
goto failed;
}

gst_bus_enable_sync_message_emission (pipe_h->bus);
pipe_h->signal_msg = g_signal_connect (pipe_h->bus, "sync-message",
Expand Down
21 changes: 16 additions & 5 deletions java/android/nnstreamer/src/main/jni/nnstreamer-native-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ nns_attach_current_thread (pipeline_info_s * pipe_info)
JavaVM *jvm;
JavaVMAttachArgs args;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}

jvm = pipe_info->jvm;

args.version = pipe_info->version;
Expand All @@ -48,7 +52,10 @@ nns_get_jni_env (pipeline_info_s * pipe_info)
{
JNIEnv *env;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}

if ((env = pthread_getspecific (pipe_info->jni_env)) == NULL) {
env = nns_attach_current_thread (pipe_info);
Expand Down Expand Up @@ -197,15 +204,19 @@ nns_construct_pipe_info (JNIEnv * env, jobject thiz, gpointer handle,
pipe_info = g_new0 (pipeline_info_s, 1);
g_return_val_if_fail (pipe_info != NULL, NULL);

(*env)->GetJavaVM (env, &pipe_info->jvm);
if (!pipe_info->jvm) {
_ml_loge ("Failed to get Java VM.");
g_free (pipe_info);
return NULL;
}

pipe_info->pipeline_type = type;
pipe_info->pipeline_handle = handle;
pipe_info->element_handles =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
nns_free_element_data);
g_mutex_init (&pipe_info->lock);

(*env)->GetJavaVM (env, &pipe_info->jvm);
g_assert (pipe_info->jvm);
pthread_key_create (&pipe_info->jni_env, NULL);

pipe_info->version = (*env)->GetVersion (env);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,16 @@ nnstreamer_native_finalize (void)
const char *
nnstreamer_native_get_data_path (void)
{
char *data_path = NULL;
const char *data_path = NULL;

G_LOCK (nns_native_lock);
g_assert (g_nns_is_initialized);
data_path = g_files_dir;

if (g_nns_is_initialized) {
data_path = g_files_dir;
} else {
_ml_loge ("NNStreamer native library is not initialized.");
}

G_UNLOCK (nns_native_lock);

return data_path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ nns_get_sink_handle (pipeline_info_s * pipe_info, const gchar * element_name)
element_data_s *item;
int status;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}
pipe = pipe_info->pipeline_handle;

handle = (ml_pipeline_sink_h) nns_get_element_handle (pipe_info,
Expand Down Expand Up @@ -275,7 +278,10 @@ nns_get_src_handle (pipeline_info_s * pipe_info, const gchar * element_name)
element_data_s *item;
int status;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}
pipe = pipe_info->pipeline_handle;

handle = (ml_pipeline_src_h) nns_get_element_handle (pipe_info,
Expand Down Expand Up @@ -323,7 +329,10 @@ nns_get_switch_handle (pipeline_info_s * pipe_info, const gchar * element_name)
element_data_s *item;
int status;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}
pipe = pipe_info->pipeline_handle;

handle = (ml_pipeline_switch_h) nns_get_element_handle (pipe_info,
Expand Down Expand Up @@ -371,7 +380,10 @@ nns_get_valve_handle (pipeline_info_s * pipe_info, const gchar * element_name)
element_data_s *item;
int status;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}
pipe = pipe_info->pipeline_handle;

handle = (ml_pipeline_valve_h) nns_get_element_handle (pipe_info,
Expand Down Expand Up @@ -419,7 +431,10 @@ nns_get_video_sink_data (pipeline_info_s * pipe_info,
element_data_s *item;
int status;

g_assert (pipe_info);
if (!pipe_info) {
_ml_loge ("pipe_info is NULL.");
return NULL;
}
pipe = pipe_info->pipeline_handle;

item = nns_get_element_data (pipe_info, element_name);
Expand Down
Loading