ml_tensors_data_s *_data;
ml_tensors_info_s *_info;
guint i;
+ int status = ML_ERROR_NONE;
check_feature_state (ML_FEATURE);
_data = g_new0 (ml_tensors_data_s, 1);
if (!_data)
_ml_error_report_return (ML_ERROR_OUT_OF_MEMORY,
- "Failed to allocate memory for tensors data with g_new0(). Probably the system is out of memory.");
+ "Failed to allocate memory for tensors data. Probably the system is out of memory.");
g_mutex_init (&_data->lock);
_info = (ml_tensors_info_s *) info;
if (_info != NULL) {
- /* Ignore error case when creating internal info handle (single-shot). */
- _ml_tensors_info_create_from (info, &_data->info);
+ status = _ml_tensors_info_create_from (info, &_data->info);
+ if (status != ML_ERROR_NONE) {
+ _ml_error_report_continue
+ ("Failed to create internal information handle for tensors data.");
+ goto error;
+ }
G_LOCK_UNLESS_NOLOCK (*_info);
_data->num_tensors = _info->info.num_tensors;
G_UNLOCK_UNLESS_NOLOCK (*_info);
}
- *data = _data;
- return ML_ERROR_NONE;
+error:
+ if (status == ML_ERROR_NONE) {
+ *data = _data;
+ } else {
+ _ml_tensors_data_destroy_internal (_data, FALSE);
+ }
+
+ return status;
}
/**
guint i, num_tensors;
GList *l;
ml_tensors_data_s *_data = NULL;
- ml_tensors_info_h out_info = NULL;
GstTensorsInfo gst_info;
int status;
}
/* Create new output info, data handle should be updated here. */
- _ml_tensors_info_create_from_gst (&out_info, &gst_info);
_ml_tensors_info_create_from_gst (&_data->info, &gst_info);
/* Iterate e->handles, pass the data to them */
callback = sink->callback_info->sink_cb;
if (callback)
- callback (_data, out_info, sink->callback_info->sink_pdata);
+ callback (_data, _data->info, sink->callback_info->sink_pdata);
/** @todo Measure time. Warn if it takes long. Kill if it takes too long. */
}
gst_memory_unref (mem[i]);
}
- if (out_info)
- ml_tensors_info_destroy (out_info);
-
_ml_tensors_data_destroy_internal (_data, FALSE);
_data = NULL;
static void
__setup_in_out_tensors (ml_single * single_h)
{
- int i;
+ guint i;
ml_tensors_data_s *in_tensors = (ml_tensors_data_s *) single_h->in_tensors;
ml_tensors_data_s *out_tensors = (ml_tensors_data_s *) single_h->out_tensors;
/* Setup input buffer */
- _ml_tensors_info_free (in_tensors->info);
- _ml_tensors_info_copy_from_gst (in_tensors->info, &single_h->in_info);
+ if (in_tensors) {
+ _ml_tensors_info_free (in_tensors->info);
+ _ml_tensors_info_copy_from_gst (in_tensors->info, &single_h->in_info);
+ } else {
+ ml_tensors_info_h info;
+
+ _ml_tensors_info_create_from_gst (&info, &single_h->in_info);
+ _ml_tensors_data_create_no_alloc (info, &single_h->in_tensors);
+
+ ml_tensors_info_destroy (info);
+ in_tensors = (ml_tensors_data_s *) single_h->in_tensors;
+ }
in_tensors->num_tensors = single_h->in_info.num_tensors;
for (i = 0; i < in_tensors->num_tensors; i++) {
}
/* Setup output buffer */
- _ml_tensors_info_free (out_tensors->info);
- _ml_tensors_info_copy_from_gst (out_tensors->info, &single_h->out_info);
+ if (out_tensors) {
+ _ml_tensors_info_free (out_tensors->info);
+ _ml_tensors_info_copy_from_gst (out_tensors->info, &single_h->out_info);
+ } else {
+ ml_tensors_info_h info;
+
+ _ml_tensors_info_create_from_gst (&info, &single_h->out_info);
+ _ml_tensors_data_create_no_alloc (info, &single_h->out_tensors);
+
+ ml_tensors_info_destroy (info);
+ out_tensors = (ml_tensors_data_s *) single_h->out_tensors;
+ }
out_tensors->num_tensors = single_h->out_info.num_tensors;
for (i = 0; i < out_tensors->num_tensors; i++) {
{
ml_single *single_h;
GError *error;
- ml_tensors_info_h info_h;
- int status;
gboolean created = FALSE;
single_h = g_new0 (ml_single, 1);
g_mutex_init (&single_h->mutex);
g_cond_init (&single_h->cond);
- /* Dummy info to allocate tensors-info handle in data. */
- status = ml_tensors_info_create_extended (&info_h);
- if (status != ML_ERROR_NONE) {
- _ml_error_report
- ("Failed to create tensor information in single handle. Internal error or out of memory?");
- goto done;
- }
-
- status = _ml_tensors_data_create_no_alloc (info_h, &single_h->in_tensors);
- if (status != ML_ERROR_NONE) {
- _ml_error_report
- ("Failed to create input data in single handle. Internal error or out of memory?");
- goto done;
- }
-
- status = _ml_tensors_data_create_no_alloc (info_h, &single_h->out_tensors);
- if (status != ML_ERROR_NONE) {
- _ml_error_report
- ("Failed to create output data in single handle. Internal error or out of memory?");
- goto done;
- }
-
single_h->klass = g_type_class_ref (G_TYPE_TENSOR_FILTER_SINGLE);
if (single_h->klass == NULL) {
_ml_error_report
created = TRUE;
done:
- ml_tensors_info_destroy (info_h);
-
if (!created) {
ml_single_close (single_h);
single_h = NULL;