From: Wook Song Date: Mon, 17 Dec 2018 02:14:03 +0000 (+0900) Subject: [TensorMux] Support multi-tensors for input X-Git-Tag: v0.1.0~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09a0b83dfa93e3bfd8cbe0fbb3706a4ec916581a;p=platform%2Fupstream%2Fnnstreamer.git [TensorMux] Support multi-tensors for input This patch makes the TensorMux element have multi-tensors as its input stream. Signed-off-by: Wook Song --- diff --git a/gst/nnstreamer/tensor_common.c b/gst/nnstreamer/tensor_common.c index 6717924..37199e0 100644 --- a/gst/nnstreamer/tensor_common.c +++ b/gst/nnstreamer/tensor_common.c @@ -1147,8 +1147,9 @@ gst_gen_tensors_from_collectpad (GstCollectPads * collect, gint old_numerator = G_MAXINT; gint old_denominator = G_MAXINT; gint counting = 0; - GstTensorConfig config; + GstTensorsConfig in_configs; GstClockTime base = 0; + guint i = 0; walk = collect->data; @@ -1176,13 +1177,13 @@ gst_gen_tensors_from_collectpad (GstCollectPads * collect, GstCaps *caps = gst_pad_get_current_caps (pad->pad); GstStructure *s = gst_caps_get_structure (caps, 0); - gst_tensor_config_from_structure (&config, s); - g_assert (gst_tensor_config_validate (&config)); + gst_tensors_config_from_structure (&in_configs, s); + g_assert (gst_tensors_config_validate (&in_configs)); - if (config.rate_d < old_denominator) - old_denominator = config.rate_d; - if (config.rate_n < old_numerator) - old_numerator = config.rate_n; + if (in_configs.rate_d < old_denominator) + old_denominator = in_configs.rate_d; + if (in_configs.rate_n < old_numerator) + old_numerator = in_configs.rate_n; gst_caps_unref (caps); @@ -1259,8 +1260,17 @@ gst_gen_tensors_from_collectpad (GstCollectPads * collect, } if (GST_IS_BUFFER (buf)) { - mem = gst_buffer_get_memory (buf, 0); - gst_buffer_append_memory (tensors_buf, mem); + guint n_mem = gst_buffer_n_memory (buf); + + g_assert (n_mem == in_configs.info.num_tensors); + g_assert ((counting + n_mem) < NNS_TENSOR_SIZE_LIMIT); + + for (i = 0; i < n_mem; ++i) { + mem = gst_buffer_get_memory (buf, i); + gst_buffer_append_memory (tensors_buf, mem); + configs->info.info[counting] = in_configs.info.info[i]; + counting++; + } if (sync.mode == SYNC_NOSYNC) { gst_buffer_unref (buf); } @@ -1269,9 +1279,6 @@ gst_gen_tensors_from_collectpad (GstCollectPads * collect, isEOS = TRUE; return isEOS; } - - configs->info.info[counting] = config.info; - counting++; } configs->rate_d = old_denominator; diff --git a/gst/tensor_mux/gsttensormux.c b/gst/tensor_mux/gsttensormux.c index 222d678..f7ddcdd 100644 --- a/gst/tensor_mux/gsttensormux.c +++ b/gst/tensor_mux/gsttensormux.c @@ -97,6 +97,11 @@ enum }; /** + * @brief Default caps string for sink pad. + */ +#define CAPS_STRING_SINK GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT + +/** * @brief the capabilities of the inputs and outputs. * describe the real formats here. */ @@ -109,7 +114,7 @@ static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink_%u", GST_PAD_SINK, GST_PAD_REQUEST, - GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT) + GST_STATIC_CAPS (CAPS_STRING_SINK) ); static gboolean gst_tensor_mux_handle_src_event (GstPad * pad, @@ -241,6 +246,7 @@ gst_tensor_mux_request_new_pad (GstElement * element, GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps) { GstPad *newpad; + GSList *walk = NULL; GstTensorMux *tensor_mux; gchar *name; @@ -248,16 +254,9 @@ gst_tensor_mux_request_new_pad (GstElement * element, GstPadTemplate * templ, g_return_val_if_fail (GST_IS_TENSOR_MUX (element), NULL); tensor_mux = GST_TENSOR_MUX (element); + walk = tensor_mux->collect->data; - if (tensor_mux->tensors_config.info.num_tensors >= NNS_TENSOR_SIZE_LIMIT) { - GST_ERROR_OBJECT (tensor_mux, - "supposed max size is " NNS_TENSOR_SIZE_LIMIT_STR); - g_assert (0); - return NULL; - } - - name = - g_strdup_printf ("sink_%u", tensor_mux->tensors_config.info.num_tensors); + name = g_strdup_printf ("sink_%u", g_slist_length (walk)); newpad = gst_pad_new_from_template (templ, name); g_free (name); @@ -268,7 +267,6 @@ gst_tensor_mux_request_new_pad (GstElement * element, GstPadTemplate * templ, sizeof (GstTensorCollectPadData), NULL, TRUE); tensormuxpad->pad = newpad; gst_pad_set_element_private (newpad, tensormuxpad); - tensor_mux->tensors_config.info.num_tensors++; gst_element_add_pad (element, newpad); } else { GST_WARNING_OBJECT (tensor_mux, "failed to create request pad"); @@ -400,6 +398,11 @@ gst_tensor_mux_collected (GstCollectPads * pads, GstTensorMux * tensor_mux) if (!tensor_mux->negotiated) { GstCaps *newcaps; + if (GST_IS_BUFFER (tensors_buf)) { + tensor_mux->tensors_config.info.num_tensors = + gst_buffer_n_memory (tensors_buf); + } + g_assert (gst_tensors_config_validate (&tensor_mux->tensors_config)); newcaps = gst_tensors_caps_from_config (&tensor_mux->tensors_config);