40 #define GST_CAT_DEFAULT gst_tensor_reposrc_debug
41 #define CAPS_STRING GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT
54 #define DEFAULT_SILENT TRUE
55 #define DEFAULT_INDEX 0
56 #define INVALID_INDEX G_MAXUINT
59 const GValue * value, GParamSpec * pspec);
61 GValue * value, GParamSpec * pspec);
67 #define gst_tensor_reposrc_parent_class parent_class
76 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
77 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
78 GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass);
79 GstBaseSrcClass *basesrc_class = GST_BASE_SRC_CLASS (klass);
80 GstPadTemplate *pad_template;
83 GST_DEBUG_CATEGORY_INIT (gst_tensor_reposrc_debug,
"tensor_reposrc", 0,
84 "Source element to handle tensor repository");
90 g_object_class_install_property (gobject_class,
PROP_CAPS,
91 g_param_spec_boxed (
"caps",
"Caps",
92 "Caps describing the format of the data.",
93 GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
95 g_object_class_install_property (gobject_class,
PROP_SILENT,
96 g_param_spec_boolean (
"silent",
"Silent",
"Produce verbose output",
99 g_object_class_install_property (gobject_class,
PROP_SLOT_ID,
100 g_param_spec_uint (
"slot-index",
"Slot Index",
"repository slot index",
102 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
107 gst_element_class_set_static_metadata (element_class,
109 "Source/Tensor/Repository",
110 "Pop element to handle tensor repository",
111 "Samsung Electronics Co., Ltd.");
116 pad_template = gst_pad_template_new (
"src", GST_PAD_SRC, GST_PAD_ALWAYS,
118 gst_element_class_add_pad_template (element_class, pad_template);
119 gst_caps_unref (pad_caps);
130 self->negotiation =
FALSE;
133 self->set_startid =
FALSE;
147 GST_ELEMENT_ERROR (
self, RESOURCE, WRITE,
148 (
"Cannot remove [key: %d] in repo", self->myid), NULL);
151 gst_caps_unref (self->caps);
153 G_OBJECT_CLASS (parent_class)->dispose (
object);
163 GstCaps *cap, *check, *
result;
164 GstStructure *st = NULL;
166 GST_DEBUG_OBJECT (
self,
"returning %" GST_PTR_FORMAT, self->caps);
170 cap = gst_caps_intersect_full (filter, self->caps,
171 GST_CAPS_INTERSECT_FIRST);
173 cap = gst_caps_ref (self->caps);
176 cap = gst_caps_ref (filter);
178 cap = gst_caps_new_any ();
182 result = gst_caps_intersect_full (cap, check, GST_CAPS_INTERSECT_FIRST);
185 GST_ELEMENT_ERROR (GST_ELEMENT (
self), STREAM, WRONG_TYPE,
186 (
"Only Tensor/Tensors MIME are supported for now"), (NULL));
188 gst_caps_unref (check);
189 gst_caps_unref (cap);
191 st = gst_caps_get_structure (
result, 0);
202 const GValue * value, GParamSpec * pspec)
208 self->silent = g_value_get_boolean (value);
211 self->o_myid =
self->myid;
212 self->myid = g_value_get_uint (value);
213 self->negotiation =
FALSE;
217 if (!self->set_startid) {
218 self->o_myid =
self->myid;
219 self->set_startid =
TRUE;
222 if (self->o_myid != self->myid)
227 GstStructure *st = NULL;
228 const GstCaps *caps = gst_value_get_caps (value);
232 new_caps = gst_caps_new_any ();
234 new_caps = gst_caps_copy (caps);
236 gst_caps_replace (&self->caps, new_caps);
237 gst_pad_set_caps (GST_BASE_SRC_PAD (
self), new_caps);
238 st = gst_caps_get_structure (new_caps, 0);
240 if (new_caps && gst_caps_get_size (new_caps) == 1 && st
241 && gst_structure_get_fraction (st,
"framerate", &self->fps_n,
243 GST_INFO_OBJECT (
self,
"Setting framerate to %d/%d", self->fps_n,
251 gst_caps_unref (new_caps);
252 self->negotiation =
FALSE;
256 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
266 GValue * value, GParamSpec * pspec)
272 g_value_set_boolean (value, self->silent);
275 g_value_set_uint (value, self->myid);
278 gst_value_set_caps (value, self->caps);
281 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
292 GstBuffer *buf = NULL;
296 guint i, num_tensors;
299 buf = gst_buffer_new ();
300 num_tensors =
self->config.info.num_tensors;
302 for (i = 0; i < num_tensors; i++) {
305 mem = gst_allocator_alloc (NULL, size, NULL);
308 if (!gst_memory_map (mem, &map, GST_MAP_WRITE)) {
309 gst_buffer_unref (buf);
310 ml_logf (
"Cannot map gst memory (tensor-repo-src).");
314 memset (map.data, 0, map.size);
315 gst_memory_unmap (mem, &map);
328 GstBuffer *buf = NULL;
329 GstCaps *caps = NULL;
330 gboolean eos =
FALSE;
340 while (!buf && !eos) {
347 if (!self->negotiation && buf != NULL) {
349 GST_ELEMENT_ERROR (GST_ELEMENT (
self), CORE, NEGOTIATION,
350 (
"Negotiation Failed! : repo_sink & repos_src"), (NULL));
356 self->negotiation =
TRUE;
360 gst_caps_unref (caps);
368 gst_buffer_unref (buf);
370 gst_caps_unref (caps);