*/
/**
- * SECTION:element-tensorsplit
+ * SECTION:element-tensor_split
*
* A Deuxer that split tensors stream to tensor stream for NN frameworks.
- * The outputs are always in the format of other/tensor
+ * The outputs are always in the format of other/tensor.
*
* <refsect2>
* <title>Example launch line</title>
static void gst_tensor_split_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_tensor_split_dispose (GObject * object);
+
#define gst_tensor_split_parent_class parent_class
G_DEFINE_TYPE (GstTensorSplit, gst_tensor_split, GST_TYPE_ELEMENT);
* initialize instance structure
*/
static void
-gst_tensor_split_init (GstTensorSplit * tensor_split)
+gst_tensor_split_init (GstTensorSplit * split)
{
- tensor_split->sinkpad =
- gst_pad_new_from_static_template (&sink_templ, "sink");
- gst_element_add_pad (GST_ELEMENT_CAST (tensor_split), tensor_split->sinkpad);
- gst_pad_set_chain_function (tensor_split->sinkpad,
+ split->sinkpad = gst_pad_new_from_static_template (&sink_templ, "sink");
+ gst_element_add_pad (GST_ELEMENT_CAST (split), split->sinkpad);
+ gst_pad_set_chain_function (split->sinkpad,
GST_DEBUG_FUNCPTR (gst_tensor_split_chain));
- gst_pad_set_event_function (tensor_split->sinkpad,
+ gst_pad_set_event_function (split->sinkpad,
GST_DEBUG_FUNCPTR (gst_tensor_split_event));
- tensor_split->num_tensors = 0;
- tensor_split->num_srcpads = 0;
- tensor_split->silent = TRUE;
- tensor_split->tensorpick = NULL;
- tensor_split->tensorseg = NULL;
- tensor_split->have_group_id = FALSE;
- tensor_split->group_id = G_MAXUINT;
- tensor_split->srcpads = NULL;
- gst_tensor_config_init (&tensor_split->sink_tensor_conf);
+ split->num_tensors = 0;
+ split->num_srcpads = 0;
+ split->silent = TRUE;
+ split->tensorpick = NULL;
+ split->tensorseg = NULL;
+ split->have_group_id = FALSE;
+ split->group_id = G_MAXUINT;
+ split->srcpads = NULL;
+ gst_tensor_config_init (&split->sink_tensor_conf);
}
/**
* @brief function to remove srcpad list
*/
static void
-gst_tensor_split_remove_src_pads (GstTensorSplit * tensor_split)
+gst_tensor_split_remove_src_pads (GstTensorSplit * split)
{
- while (tensor_split->srcpads != NULL) {
- GstTensorPad *tensor_pad = tensor_split->srcpads->data;
- gst_element_remove_pad (GST_ELEMENT (tensor_split), tensor_pad->pad);
+ while (split->srcpads != NULL) {
+ GstTensorPad *tensor_pad = split->srcpads->data;
+ gst_element_remove_pad (GST_ELEMENT (split), tensor_pad->pad);
g_free (tensor_pad);
- tensor_split->srcpads =
- g_slist_delete_link (tensor_split->srcpads, tensor_split->srcpads);
+ split->srcpads = g_slist_delete_link (split->srcpads, split->srcpads);
}
- tensor_split->srcpads = NULL;
- tensor_split->num_tensors = 0;
- tensor_split->num_srcpads = 0;
+ split->srcpads = NULL;
+ split->num_tensors = 0;
+ split->num_srcpads = 0;
}
/**
static void
gst_tensor_split_dispose (GObject * object)
{
- GstTensorSplit *tensor_split = GST_TENSOR_SPLIT (object);
+ GstTensorSplit *split;
- gst_tensor_split_remove_src_pads (tensor_split);
+ split = GST_TENSOR_SPLIT (object);
+ gst_tensor_split_remove_src_pads (split);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
/**
* @brief Set Caps in pad.
- * @param tensor_split GstTensorSplit Ojbect
+ * @param split GstTensorSplit Ojbect
* @param caps incomming capablity
* @return TRUE/FALSE (if successfully generate & set cap, return TRUE)
*/
static gboolean
-gst_tensor_split_get_capsparam (GstTensorSplit * tensor_split, GstCaps * caps)
+gst_tensor_split_get_capsparam (GstTensorSplit * split, GstCaps * caps)
{
- gboolean ret = FALSE;
-
- GstStructure *s = gst_caps_get_structure (caps, 0);
- if (gst_structure_has_name (s, "other/tensor")) {
- gst_tensor_config_from_structure (&tensor_split->sink_tensor_conf, s);
+ GstStructure *st;
- ret = TRUE;
- }
+ st = gst_caps_get_structure (caps, 0);
- return ret;
+ return gst_tensor_config_from_structure (&split->sink_tensor_conf, st);
}
/**
static gboolean
gst_tensor_split_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
- GstTensorSplit *tensor_split;
- tensor_split = GST_TENSOR_SPLIT (parent);
+ GstTensorSplit *split;
+
+ split = GST_TENSOR_SPLIT (parent);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CAPS:
{
GstCaps *caps;
gst_event_parse_caps (event, &caps);
- if (!gst_tensor_split_get_capsparam (tensor_split, caps)) {
- GST_ELEMENT_ERROR (tensor_split, STREAM, WRONG_TYPE,
+ if (!gst_tensor_split_get_capsparam (split, caps)) {
+ GST_ELEMENT_ERROR (split, STREAM, WRONG_TYPE,
("This stream contains no valid type."), NULL);
}
- return gst_pad_event_default (pad, parent, event);
+ break;
}
case GST_EVENT_EOS:
- if (!tensor_split->srcpads) {
- GST_ELEMENT_ERROR (tensor_split, STREAM, WRONG_TYPE,
+ if (!split->srcpads) {
+ GST_ELEMENT_ERROR (split, STREAM, WRONG_TYPE,
("This stream contains no valid stremas."),
("Got EOS before adding any pads"));
gst_event_unref (event);
return FALSE;
- } else {
- return gst_pad_event_default (pad, parent, event);
}
break;
default:
- return gst_pad_event_default (pad, parent, event);
+ break;
}
+
+ return gst_pad_event_default (pad, parent, event);
}
/**
* @brief Checking if the source pad is created and if not, create TensorPad
- * @param tesnor_split TensorSplit Object
+ * @param split TensorSplit Object
* @param inbuf inputbuf GstBuffer Object including GstMeta
* @param[out] created will be updated in this function
* @param nth source ordering
* If not return new pad after creation.
*/
static GstTensorPad *
-gst_get_tensor_pad (GstTensorSplit * tensor_split, GstBuffer * inbuf,
+gst_tensor_split_get_tensor_pad (GstTensorSplit * split, GstBuffer * inbuf,
gboolean * created, gint nth)
{
GSList *walk;
- walk = tensor_split->srcpads;
- while (walk) {
- GstTensorPad *pad = (GstTensorPad *) walk->data;
- if (nth == pad->nth) {
- if (created) {
- *created = FALSE;
- }
- return pad;
- }
- walk = walk->next;
- }
-
GstPad *pad;
GstTensorPad *tensorpad;
gchar *name;
tensor_dim *dim;
guint i;
+ walk = split->srcpads;
+ while (walk) {
+ GstTensorPad *pad = (GstTensorPad *) walk->data;
+ if (nth == pad->nth) {
+ if (created) {
+ *created = FALSE;
+ }
+ return pad;
+ }
+ walk = g_slist_next (walk);
+ }
+
tensorpad = g_new0 (GstTensorPad, 1);
- GST_DEBUG_OBJECT (tensor_split, "createing pad: %d(%dth)",
- tensor_split->num_srcpads, nth);
+ GST_DEBUG_OBJECT (split, "createing pad: %d(%dth)", split->num_srcpads, nth);
- name = g_strdup_printf ("src_%u", tensor_split->num_srcpads);
+ name = g_strdup_printf ("src_%u", split->num_srcpads);
pad = gst_pad_new_from_static_template (&src_templ, name);
g_free (name);
tensorpad->last_ret = GST_FLOW_OK;
tensorpad->last_ts = GST_CLOCK_TIME_NONE;
- tensor_split->srcpads = g_slist_append (tensor_split->srcpads, tensorpad);
- dim =
- g_array_index (tensor_split->tensorseg, tensor_dim *,
- tensor_split->num_srcpads);
+ split->srcpads = g_slist_append (split->srcpads, tensorpad);
+ dim = g_array_index (split->tensorseg, tensor_dim *, split->num_srcpads);
- tensor_split->num_srcpads++;
+ split->num_srcpads++;
gst_pad_use_fixed_caps (pad);
gst_pad_set_active (pad, TRUE);
- if (!tensor_split->have_group_id) {
+ if (!split->have_group_id) {
event =
- gst_pad_get_sticky_event (tensor_split->sinkpad, GST_EVENT_STREAM_START,
- 0);
+ gst_pad_get_sticky_event (split->sinkpad, GST_EVENT_STREAM_START, 0);
if (event) {
- tensor_split->have_group_id =
- gst_event_parse_group_id (event, &tensor_split->group_id);
+ split->have_group_id = gst_event_parse_group_id (event, &split->group_id);
gst_event_unref (event);
- } else if (!tensor_split->have_group_id) {
- tensor_split->have_group_id = TRUE;
- tensor_split->group_id = gst_util_group_id_next ();
+ } else if (!split->have_group_id) {
+ split->have_group_id = TRUE;
+ split->group_id = gst_util_group_id_next ();
}
}
stream_id =
- gst_pad_create_stream_id (pad, GST_ELEMENT_CAST (tensor_split),
- "other/tensor");
+ gst_pad_create_stream_id (pad, GST_ELEMENT_CAST (split), "other/tensor");
event = gst_event_new_stream_start (stream_id);
- if (tensor_split->have_group_id)
- gst_event_set_group_id (event, tensor_split->group_id);
+ if (split->have_group_id)
+ gst_event_set_group_id (event, split->group_id);
gst_pad_store_sticky_event (pad, event);
g_free (stream_id);
for (i = 0; i < NNS_TENSOR_RANK_LIMIT; i++) {
pad_config.info.dimension[i] = (*dim)[i];
}
- pad_config.info.type = tensor_split->sink_tensor_conf.info.type;
- pad_config.rate_n = tensor_split->sink_tensor_conf.rate_n;
- pad_config.rate_d = tensor_split->sink_tensor_conf.rate_d;
+ pad_config.info.type = split->sink_tensor_conf.info.type;
+ pad_config.rate_n = split->sink_tensor_conf.rate_n;
+ pad_config.rate_d = split->sink_tensor_conf.rate_d;
caps = gst_tensor_caps_from_config (&pad_config);
gst_pad_set_caps (pad, caps);
- gst_element_add_pad (GST_ELEMENT_CAST (tensor_split), pad);
+ gst_element_add_pad (GST_ELEMENT_CAST (split), pad);
gst_caps_unref (caps);
*created = TRUE;
}
- if (tensor_split->tensorpick != NULL) {
- GST_DEBUG_OBJECT (tensor_split, "TensorPick is set! : %dth tensor\n", nth);
- if (g_list_length (tensor_split->tensorpick) == tensor_split->num_srcpads) {
- gst_element_no_more_pads (GST_ELEMENT_CAST (tensor_split));
+ if (split->tensorpick != NULL) {
+ GST_DEBUG_OBJECT (split, "TensorPick is set! : %dth tensor\n", nth);
+ if (g_list_length (split->tensorpick) == split->num_srcpads) {
+ gst_element_no_more_pads (GST_ELEMENT_CAST (split));
}
}
/**
* @brief Check the status among sources in split
- * @param tensor_split TensorSplit Object
+ * @param split TensorSplit Object
* @param TensorPad Tensorpad
* @param ret return status of current pad
* @return return status after check sources
*/
static GstFlowReturn
-gst_tensorsplit_combine_flows (GstTensorSplit * tensor_split,
+gst_tensor_split_combine_flows (GstTensorSplit * split,
GstTensorPad * pad, GstFlowReturn ret)
{
GSList *walk;
- pad->last_ret = ret;
+ GstTensorPad *opad;
+ pad->last_ret = ret;
if (ret != GST_FLOW_NOT_LINKED)
goto done;
- for (walk = tensor_split->srcpads; walk; walk = g_slist_next (walk)) {
- GstTensorPad *opad = (GstTensorPad *) walk->data;
+ for (walk = split->srcpads; walk; walk = g_slist_next (walk)) {
+ opad = (GstTensorPad *) walk->data;
ret = opad->last_ret;
if (ret != GST_FLOW_NOT_LINKED)
goto done;
/**
* @brief Make Splited Tensor
- * @param tensor_split TensorSplit Object
+ * @param split TensorSplit Object
* @param buffer gstbuffer form src
* @param nth orther of tensor
* @return return GstMemory for splited tensor
*/
static GstMemory *
-gst_get_splited_tensor (GstTensorSplit * split, GstBuffer * buffer, gint nth)
+gst_tensor_split_get_splited (GstTensorSplit * split, GstBuffer * buffer,
+ gint nth)
{
GstMemory *mem;
tensor_dim *dim;
static GstFlowReturn
gst_tensor_split_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
+ GstTensorSplit *split;
gint num_tensors, i;
GstFlowReturn res = GST_FLOW_OK;
- GstTensorSplit *tensor_split;
- tensor_split = GST_TENSOR_SPLIT (parent);
- num_tensors = tensor_split->num_tensors;
- GST_DEBUG_OBJECT (tensor_split, " Number of Tensors: %d", num_tensors);
+ split = GST_TENSOR_SPLIT (parent);
+
+ num_tensors = split->num_tensors;
+ GST_DEBUG_OBJECT (split, " Number of Tensors: %d", num_tensors);
- if (tensor_split->tensorseg == NULL) {
- GST_ERROR_OBJECT (tensor_split, "No rule to split incoming buffers.");
+ if (split->tensorseg == NULL) {
+ GST_ERROR_OBJECT (split, "No rule to split incoming buffers.");
return GST_FLOW_ERROR;
}
for (i = 0; i < num_tensors; i++) {
- if (tensor_split->tensorpick != NULL) {
+ GstTensorPad *srcpad;
+ GstBuffer *outbuf;
+ GstMemory *mem;
+ gboolean created;
+ GstClockTime ts;
+
+ if (split->tensorpick != NULL) {
gboolean found = FALSE;
GList *list;
- for (list = tensor_split->tensorpick; list != NULL; list = list->next) {
+ for (list = split->tensorpick; list != NULL; list = list->next) {
if (i == GPOINTER_TO_INT (list->data)) {
found = TRUE;
break;
continue;
}
- GstTensorPad *srcpad;
- GstBuffer *outbuf;
- GstMemory *mem;
- gboolean created;
- GstClockTime ts;
- srcpad = gst_get_tensor_pad (tensor_split, buf, &created, i);
+ srcpad = gst_tensor_split_get_tensor_pad (split, buf, &created, i);
outbuf = gst_buffer_new ();
- mem = gst_get_splited_tensor (tensor_split, buf, i);
+ mem = gst_tensor_split_get_splited (split, buf, i);
gst_buffer_append_memory (outbuf, mem);
ts = GST_BUFFER_TIMESTAMP (buf);
if (srcpad->last_ts == GST_CLOCK_TIME_NONE || srcpad->last_ts != ts) {
srcpad->last_ts = ts;
} else {
- GST_DEBUG_OBJECT (tensor_split, "invalid timestamp %" GST_TIME_FORMAT,
+ GST_DEBUG_OBJECT (split, "invalid timestamp %" GST_TIME_FORMAT,
GST_TIME_ARGS (ts));
}
- GST_DEBUG_OBJECT (tensor_split,
- "pushing buffer with timestamp %" GST_TIME_FORMAT,
+ GST_DEBUG_OBJECT (split, "pushing buffer with timestamp %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
res = gst_pad_push (srcpad->pad, outbuf);
- res = gst_tensorsplit_combine_flows (tensor_split, srcpad, res);
+ res = gst_tensor_split_combine_flows (split, srcpad, res);
if (res != GST_FLOW_OK)
break;
}
static GstStateChangeReturn
gst_tensor_split_change_state (GstElement * element, GstStateChange transition)
{
- GstTensorSplit *tensor_split;
+ GstTensorSplit *split;
GstStateChangeReturn ret;
- tensor_split = GST_TENSOR_SPLIT (element);
+
+ split = GST_TENSOR_SPLIT (element);
+
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
if (ret == GST_STATE_CHANGE_FAILURE)
return ret;
+
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
- tensor_split->group_id = G_MAXUINT;
- tensor_split->have_group_id = FALSE;
- gst_tensor_split_remove_src_pads (tensor_split);
+ split->group_id = G_MAXUINT;
+ split->have_group_id = FALSE;
+ gst_tensor_split_remove_src_pads (split);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
gst_tensor_split_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
- GstTensorSplit *self = GST_TENSOR_SPLIT (object);
+ GstTensorSplit *split;
+
+ split = GST_TENSOR_SPLIT (object);
+
switch (prop_id) {
case PROP_SILENT:
- self->silent = g_value_get_boolean (value);
+ split->silent = g_value_get_boolean (value);
break;
case PROP_TENSORPICK:
{
gint num = g_strv_length (strv);
for (i = 0; i < num; i++) {
val = g_ascii_strtoll (strv[i], NULL, 10);
- self->tensorpick =
- g_list_append (self->tensorpick, GINT_TO_POINTER (val));
+ split->tensorpick =
+ g_list_append (split->tensorpick, GINT_TO_POINTER (val));
}
g_strfreev (strv);
break;
gint i;
const gchar *param = g_value_get_string (value);
gchar **strv = g_strsplit_set (param, ",.;/", -1);
- self->num_tensors = g_strv_length (strv);
- self->tensorseg =
+ split->num_tensors = g_strv_length (strv);
+ split->tensorseg =
g_array_sized_new (FALSE, FALSE, sizeof (tensor_dim *),
- self->num_tensors);
- for (i = 0; i < self->num_tensors; i++) {
+ split->num_tensors);
+ for (i = 0; i < split->num_tensors; i++) {
gchar **p;
gint num, k;
tensor_dim *d;
for (k = num; k < NNS_TENSOR_RANK_LIMIT; k++)
(*d)[k] = 1;
- g_array_append_val (self->tensorseg, d);
+ g_array_append_val (split->tensorseg, d);
g_strfreev (p);
}
g_strfreev (strv);
gst_tensor_split_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- GstTensorSplit *self = GST_TENSOR_SPLIT (object);
+ GstTensorSplit *split;
+
+ split = GST_TENSOR_SPLIT (object);
+
switch (prop_id) {
case PROP_SILENT:
- g_value_set_boolean (value, self->silent);
+ g_value_set_boolean (value, split->silent);
break;
case PROP_TENSORPICK:
{
GList *list;
- char *p = "";
+ char *p;
GPtrArray *arr = g_ptr_array_new ();
gchar **strings;
- for (list = self->tensorpick; list != NULL; list = list->next) {
+
+ for (list = split->tensorpick; list != NULL; list = list->next) {
g_ptr_array_add (arr, g_strdup_printf ("%i",
GPOINTER_TO_INT (list->data)));
}
}
case PROP_TENSORSEG:
{
- if (self->tensorseg && self->tensorseg->len > 0) {
+ if (split->tensorseg && split->tensorseg->len > 0) {
tensor_dim *dim = NULL;
int i, j;
gchar **strings;
- gchar *p = "";
- gchar *strv = "";
- for (i = 0; i < self->tensorseg->len; i++) {
+ gchar *p, *strv;
+
+ for (i = 0; i < split->tensorseg->len; i++) {
GPtrArray *arr = g_ptr_array_new ();
- dim = g_array_index (self->tensorseg, tensor_dim *, i);
+ dim = g_array_index (split->tensorseg, tensor_dim *, i);
for (j = 0; j < NNS_TENSOR_RANK_LIMIT; j++) {
g_ptr_array_add (arr, g_strdup_printf ("%i", (*dim)[j]));
}
p = g_strjoinv (":", strings);
g_strfreev (strings);
if (i > 0) {
- /** if i = 1, this is previous p.
- * otherwise, it's previous g_strjoin result */
+ /**
+ * If i = 1, this is previous p.
+ * Otherwise, it's previous g_strjoin result.
+ */
gchar *oldstrv = strv;
strv = g_strjoin (",", strv, p, NULL);