37 #include <gst/video/video-info.h>
38 #include <gst/audio/audio-info.h>
39 #include <glib/gstdio.h>
47 #include <sys/types.h>
52 #define struct_stat struct stat
55 #define S_ISREG(mode) ((mode)&_S_IFREG)
58 #define S_ISDIR(mode) ((mode)&_S_IFDIR)
62 #define S_ISSOCK(x) (0)
68 static GstStaticPadTemplate
srctemplate = GST_STATIC_PAD_TEMPLATE (
"src",
74 #define GST_CAT_DEFAULT gst_data_repo_src_debug
90 #define DEFAULT_INDEX 0
91 #define DEFAULT_EPOCHS 1
92 #define DEFAULT_IS_SHUFFLE TRUE
96 element, GstStateChange transition);
98 const GValue * value, GParamSpec * pspec);
100 GValue * value, GParamSpec * pspec);
107 GstBuffer ** buffer);
109 GST_DEBUG_CATEGORY_INIT (gst_data_repo_src_debug, "datareposrc", 0, "datareposrc element");
111 #define gst_data_repo_src_parent_class parent_class
121 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
122 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
123 GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
124 GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
126 gobject_class->set_property =
128 gobject_class->get_property =
131 g_object_class_install_property (gobject_class,
PROP_LOCATION,
132 g_param_spec_string (
"location",
"File Location",
133 "Location of the file to read that is stored in MLOps Data Repository, "
134 "if the files are images, write the index of filename name "
135 "like %04ld or %04lld (e.g., filenmae%04ld.png)",
137 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
138 GST_PARAM_MUTABLE_READY));
140 g_object_class_install_property (gobject_class,
PROP_JSON,
141 g_param_spec_string (
"json",
"Json file path",
142 "Json file path containing the meta information of the file "
143 "specified as location", NULL,
144 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
145 GST_PARAM_MUTABLE_READY));
148 g_param_spec_uint (
"start-sample-index",
"Start index of samples",
149 "Start index of sample to read, in case of image, "
150 "the starting index of the numbered files. start at 0."
151 "Set start index of range of samples or files to read",
153 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
154 GST_PARAM_MUTABLE_READY));
157 g_param_spec_uint (
"stop-sample-index",
"Stop index of samples",
158 "Stop index of sample to read, in case of image, "
159 "the stopping index of the numbered files. start at 0."
160 "Set stop index of range of samples or files to read",
162 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
163 GST_PARAM_MUTABLE_READY));
165 g_object_class_install_property (gobject_class,
PROP_EPOCHS,
166 g_param_spec_uint (
"epochs",
"Epochs",
167 "Repetition of range of files or samples to read, set number of repetitions",
169 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
170 GST_PARAM_MUTABLE_READY));
173 g_param_spec_string (
"tensors-sequence",
"Tensors sequence",
174 "Tensors in a sample are read into gstBuffer according to tensors-sequence."
175 "Only read the set tensors among all tensors in a sample"
176 "e.g, if a sample has '1:1:1:1','1:1:10:1','1:1:784:1' and each index is '0,1,2', "
177 "'tensors-sequence=2,1' means that only '1:1:784:1' then '1:1:10:1' are read. "
178 "Use for other/tensors and the default value is NULL"
179 "(all tensors are read in the order stored in a sample).",
181 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
182 GST_PARAM_MUTABLE_READY));
185 g_param_spec_boolean (
"is-shuffle",
"Is shuffle",
186 "If the value is true, samples are shuffled",
188 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
189 GST_PARAM_MUTABLE_READY));
191 g_object_class_install_property (gobject_class,
PROP_CAPS,
192 g_param_spec_boxed (
"caps",
"Caps",
193 "Optional property, Caps describing the format of the sample data.",
195 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
196 GST_PARAM_MUTABLE_READY));
201 gst_element_class_set_static_metadata (gstelement_class,
202 "NNStreamer MLOps Data Repository Source",
204 "Read files in MLOps Data Repository into buffers",
205 "Samsung Electronics Co., Ltd.");
206 gst_element_class_add_static_pad_template (gstelement_class, &
srctemplate);
213 if (
sizeof (off_t) < 8) {
214 GST_LOG (
"No large file support, sizeof (off_t) = %" G_GSIZE_FORMAT
"!",
262 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
263 gst_base_src_set_live (GST_BASE_SRC (src),
TRUE);
280 g_close (src->
fd, NULL);
285 g_object_unref (src->
parser);
291 gst_caps_replace (&src->
caps, NULL);
295 G_OBJECT_CLASS (parent_class)->finalize (
object);
307 g_return_val_if_fail (src != NULL,
FALSE);
308 g_return_val_if_fail (caps != NULL,
FALSE);
311 s = gst_caps_get_structure (caps, 0);
324 GST_DEBUG_OBJECT (src,
"format(%s), width(%d), height(%d): %zd byte/frame",
325 gst_structure_get_string (s,
"format"),
333 gint rate, channel, depth;
340 depth = GST_AUDIO_INFO_DEPTH (&audio_info);
342 src->
sample_size = (gsize) channel * (depth / 8) * rate;
344 GST_DEBUG_OBJECT (src,
345 "format(%s), depth(%d), rate(%d), channel(%d): %zd bps",
346 gst_structure_get_string (s,
"format"), depth, rate, channel,
364 GST_DEBUG_OBJECT (src,
"offset[%u]: %zd", i, src->
tensors_offset[i]);
365 GST_DEBUG_OBJECT (src,
"size[%u]: %zd", i, src->
tensors_size[i]);
376 if (gst_structure_has_field (s,
"framerate")) {
377 gst_structure_get_fraction (s,
"framerate", &src->
rate_n, &src->
rate_d);
380 GST_LOG_OBJECT (src,
"framerate %d/%d", src->
rate_n, src->
rate_d);
381 GST_LOG_OBJECT (src,
"data type: %d", src->
data_type);
385 gst_caps_take (&src->
caps, caps);
387 gst_caps_unref (caps);
397 const gchar * file_path, GError ** err)
399 gchar *filename = NULL;
405 GST_OBJECT_LOCK (src);
406 state = GST_STATE (src);
407 if (state != GST_STATE_READY && state != GST_STATE_NULL)
409 GST_OBJECT_UNLOCK (src);
412 if (file_path == NULL) {
416 filename = g_strdup (file_path);
417 GST_INFO_OBJECT (src,
"%sname : %s",
435 (
"Changing the `location or json' property on datareposrc when a file is "
436 "open is not supported.");
438 g_set_error (err, GST_URI_ERROR, GST_URI_ERROR_BAD_STATE,
439 "Changing the `location or json' property on datareposrc when a file is "
440 "open is not supported.");
441 GST_OBJECT_UNLOCK (src);
452 g_auto (GStrv) strv = NULL;
456 g_return_val_if_fail (src != NULL,
FALSE);
464 length = g_strv_length (strv);
466 GST_ERROR_OBJECT (src,
"The total number of indices exceeded %d.",
471 while (strv[i] != NULL && strlen (strv[i]) > 0) {
472 src->
tensors_seq[i] = (guint) g_ascii_strtoull (strv[i], NULL, 10);
474 GST_ERROR_OBJECT (src,
"Invalid index %d, max is %d", src->
tensors_seq[i],
482 GST_INFO_OBJECT (src,
"The number of selected tensors is %d",
487 GST_ERROR_OBJECT (src,
488 "The number of tensors selected(%d) "
489 "is greater than the total number of tensors(%d) in a sample.",
508 g_return_val_if_fail (src != NULL, 0);
510 g_return_val_if_fail (src->
fd != 0, 0);
524 guint value_i, value_j;
525 g_return_if_fail (src != NULL);
528 GST_LOG_OBJECT (src,
"samples index are shuffled");
544 GST_DEBUG_OBJECT (src,
"%u -> %u", i,
555 g_return_val_if_fail (src != NULL,
FALSE);
572 GstFlowReturn ret = GST_FLOW_OK;
573 guint i = 0, seq_idx = 0;
574 GstBuffer *buf = NULL;
575 gsize to_read, byte_read;
578 GstMemory *mem = NULL;
580 guint shuffled_index = 0;
581 guint64 sample_offset = 0;
584 g_return_val_if_fail (src->
fd != 0, GST_FLOW_ERROR);
589 GST_LOG_OBJECT (src,
"send EOS");
604 GST_LOG_OBJECT (src,
"shuffled_index [%d] -> %d", src->
array_index - 1,
609 GST_LOG_OBJECT (src,
"sample offset 0x%" G_GINT64_MODIFIER
"x (%d size)",
610 sample_offset, (guint) sample_offset);
612 buf = gst_buffer_new ();
616 mem = gst_allocator_alloc (NULL, src->
tensors_size[seq_idx], NULL);
618 if (!gst_memory_map (mem, &info, GST_MAP_WRITE)) {
619 GST_ERROR_OBJECT (src,
"Could not map GstMemory[%d]", i);
620 ret = GST_FLOW_ERROR;
624 GST_INFO_OBJECT (src,
"sequence index: %d", seq_idx);
625 GST_INFO_OBJECT (src,
"tensor_size[%d]: %zd", seq_idx,
627 GST_INFO_OBJECT (src,
"tensors_offset[%d]: %zd", seq_idx,
649 src->
fd_offset = lseek (src->
fd, offset, SEEK_SET);
651 while (to_read > 0) {
653 "Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER
"x (%zd size)",
657 read_size = read (src->
fd,
data + byte_read, to_read);
658 GST_LOG_OBJECT (src,
"Read: %zd", read_size);
660 if (errno == EAGAIN || errno == EINTR)
662 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
663 ret = GST_FLOW_ERROR;
667 if (read_size == 0) {
671 GST_DEBUG_OBJECT (src,
"EOS");
675 to_read -= read_size;
676 byte_read += read_size;
682 gst_memory_unmap (mem, &info);
695 gst_memory_unmap (mem, &info);
696 gst_memory_unref (mem);
699 gst_buffer_unref (buf);
710 guint num_tensors = 0;
711 guint cur_idx_tensor_cnt = 0;
712 guint next_idx_tensor_cnt = 0;
715 g_return_val_if_fail (src != NULL, 0);
718 g_return_val_if_fail (val >= 0, 0);
720 cur_idx_tensor_cnt = (guint) val;
721 GST_DEBUG_OBJECT (src,
"cur_idx_tensor_cnt:%u", cur_idx_tensor_cnt);
728 g_return_val_if_fail (val >= 0, 0);
730 next_idx_tensor_cnt = (guint) val;
732 GST_DEBUG_OBJECT (src,
"next_idx_tensor_cnt:%u", next_idx_tensor_cnt);
734 num_tensors = next_idx_tensor_cnt - cur_idx_tensor_cnt;
735 GST_DEBUG_OBJECT (src,
"num_tensors:%u", num_tensors);
747 GstFlowReturn ret = GST_FLOW_OK;
749 guint shuffled_index = 0;
751 guint num_tensors = 0;
752 GstBuffer *buf = NULL;
753 GstMemory *mem = NULL;
757 gsize to_read, byte_read;
763 g_return_val_if_fail (src->
fd != 0, GST_FLOW_ERROR);
768 GST_LOG_OBJECT (src,
"send EOS");
784 GST_LOG_OBJECT (src,
"shuffled_index [%d] -> %d", src->
array_index - 1,
790 GST_ERROR_OBJECT (src,
"Could not get the sample offset from json.");
791 return GST_FLOW_ERROR;
794 GST_LOG_OBJECT (src,
"sample offset 0x%" G_GINT64_MODIFIER
"x (%d size)",
801 GST_ERROR_OBJECT (src,
"Could not get the tensor count from json.");
802 return GST_FLOW_ERROR;
804 tensor_count = (guint) val;
808 buf = gst_buffer_new ();
810 for (i = 0; i < num_tensors; i++) {
813 GST_ERROR_OBJECT (src,
"Could not get the size of tensor from json.");
814 ret = GST_FLOW_ERROR;
818 tensor_size = (gsize) val;
819 mem = gst_allocator_alloc (NULL, tensor_size, NULL);
821 if (!gst_memory_map (mem, &info, GST_MAP_WRITE)) {
822 GST_ERROR_OBJECT (src,
"Could not map GstMemory[%d]", i);
823 ret = GST_FLOW_ERROR;
829 to_read = tensor_size;
830 while (to_read > 0) {
832 "Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER
"x (%lld size)",
835 read_size = read (src->
fd,
data + byte_read, to_read);
836 GST_LOG_OBJECT (src,
"Read: %zd", read_size);
838 if (errno == EAGAIN || errno == EINTR)
840 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
841 ret = GST_FLOW_ERROR;
845 if (read_size == 0) {
849 GST_DEBUG_OBJECT (src,
"EOS");
853 to_read -= read_size;
854 byte_read += read_size;
862 GST_ERROR_OBJECT (src,
"Invalid flexible tensors");
863 ret = GST_FLOW_ERROR;
867 gst_memory_unmap (mem, &info);
881 gst_memory_unmap (mem, &info);
882 gst_memory_unref (mem);
885 gst_buffer_unref (buf);
896 gchar *filename = NULL;
897 guint shuffled_index = 0;
898 g_return_val_if_fail (src != NULL, NULL);
900 g_return_val_if_fail (src->
filename != NULL, NULL);
911 #pragma GCC diagnostic push
912 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
915 filename = g_strdup_printf (src->
filename, shuffled_index);
917 #pragma GCC diagnostic pop
929 g_autofree gchar *filename = NULL;
934 GError *error = NULL;
940 GST_LOG_OBJECT (src,
"send EOS");
955 GST_DEBUG_OBJECT (src,
"Reading from file \"%s\".", filename);
959 read_size = g_file_get_contents (filename, &
data, &size, &error);
964 g_error_free (error);
972 GST_DEBUG_OBJECT (src,
"file size is %zd", size);
974 buf = gst_buffer_new ();
975 gst_buffer_append_memory (buf,
985 GST_ELEMENT_ERROR (src, RESOURCE, READ,
986 (
"Error while reading from file \"%s\".", filename),
987 (
"%s", error->message));
988 g_error_free (error);
990 GST_ELEMENT_ERROR (src, RESOURCE, READ,
991 (
"Error while reading from file \"%s\".", filename),
992 (
"%s", g_strerror (errno)));
994 return GST_FLOW_ERROR;
1001 static GstFlowReturn
1004 GstFlowReturn ret = GST_FLOW_OK;
1006 gsize to_read, byte_read;
1011 guint shuffled_index = 0;
1014 g_return_val_if_fail (src->
fd != 0, GST_FLOW_ERROR);
1019 GST_LOG_OBJECT (src,
"send EOS");
1020 return GST_FLOW_EOS;
1035 GST_LOG_OBJECT (src,
"shuffled_index [%d] -> %d", src->
array_index - 1,
1038 src->
fd_offset = lseek (src->
fd, offset, SEEK_SET);
1040 mem = gst_allocator_alloc (NULL, src->
sample_size, NULL);
1042 if (!gst_memory_map (mem, &info, GST_MAP_WRITE)) {
1043 GST_ERROR_OBJECT (src,
"Could not map GstMemory");
1044 gst_memory_unref (mem);
1045 return GST_FLOW_ERROR;
1052 while (to_read > 0) {
1053 GST_LOG_OBJECT (src,
"Reading %zd bytes at offset 0x%" G_GINT64_MODIFIER
"x",
1056 read_size = read (src->
fd,
data + byte_read, to_read);
1057 GST_LOG_OBJECT (src,
"Read: %zd", read_size);
1058 if (read_size < 0) {
1059 if (errno == EAGAIN || errno == EINTR)
1061 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
1062 ret = GST_FLOW_ERROR;
1066 if (read_size == 0) {
1070 GST_DEBUG_OBJECT (src,
"EOS");
1074 to_read -= read_size;
1075 byte_read += read_size;
1081 gst_memory_unmap (mem, &info);
1083 buf = gst_buffer_new ();
1084 gst_buffer_append_memory (buf, mem);
1091 gst_memory_unmap (mem, &info);
1092 gst_memory_unref (mem);
1104 g_autofree gchar *filename = NULL;
1108 g_return_val_if_fail (src != NULL,
FALSE);
1115 GST_INFO_OBJECT (src,
1116 "The number of samples to be used out of the total samples in the file is %d, [%d] ~ [%d]",
1118 GST_INFO_OBJECT (src,
"data type: %d", src->
data_type);
1122 filename = g_strdup (src->
filename);
1125 GST_INFO_OBJECT (src,
"opening file %s", filename);
1128 src->
fd = g_open (filename, flags, 0);
1134 if (fstat (src->
fd, &stat_results) < 0)
1141 if (
S_ISDIR (stat_results.st_mode))
1144 if (
S_ISSOCK (stat_results.st_mode))
1148 if (!
S_ISREG (stat_results.st_mode))
1155 g_close (src->
fd, NULL);
1167 GST_LOG_OBJECT (src,
"Start file offset 0x%" G_GINT64_MODIFIER
"x",
1176 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
1177 (
"No file name specified for reading."), (NULL));
1184 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
1185 (
"No such file \"%s\"", src->
filename));
1188 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1189 ((
"Could not open file \"%s\" for reading."), src->
filename),
1197 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1198 ((
"Could not get info on \"%s\"."), src->
filename), (NULL));
1203 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1204 ((
"\"%s\" is a directory."), src->
filename), (NULL));
1209 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1210 ((
"File \"%s\" is a socket."), src->
filename), (NULL));
1215 g_close (src->
fd, NULL);
1228 GstClockTime next_time;
1229 GstClockTime duration = GST_CLOCK_TIME_NONE;
1231 g_return_if_fail (src != NULL);
1232 g_return_if_fail (buffer != NULL);
1236 GST_WARNING_OBJECT (src,
1237 "Use audiorate element for the framerate of audio");
1241 duration = gst_util_uint64_scale_int (GST_SECOND, src->
rate_d, src->
rate_n);
1242 GST_BUFFER_DURATION (buffer) = duration;
1244 gst_object_sync_values (GST_OBJECT (src), GST_BUFFER_TIMESTAMP (buffer));
1247 gst_util_uint64_scale (src->
n_frame++, src->
rate_d * GST_SECOND,
1251 GST_LOG_OBJECT (src,
"next_time %" GST_TIME_FORMAT
"",
1252 GST_TIME_ARGS (next_time));
1253 GST_LOG_OBJECT (src,
1254 "timestamp [%" GST_TIME_FORMAT
" dur %" GST_TIME_FORMAT
"]",
1255 GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
1256 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
1262 static GstFlowReturn
1265 GstFlowReturn ret = GST_FLOW_OK;
1273 return GST_FLOW_ERROR;
1295 return GST_FLOW_ERROR;
1298 if (ret != GST_FLOW_OK)
1316 g_close (src->
fd, NULL);
1335 g_return_val_if_fail (src != NULL,
FALSE);
1336 g_return_val_if_fail (src->
caps != NULL,
FALSE);
1338 s = gst_caps_get_structure (src->
caps, 0);
1358 GST_DEBUG_OBJECT (src,
1359 "datareposrc caps by tensors_sequence %" GST_PTR_FORMAT, new_caps);
1380 GST_DEBUG_OBJECT (src,
"Current datareposrc caps %" GST_PTR_FORMAT,
1385 return gst_caps_intersect_full (filter, src->
caps,
1386 GST_CAPS_INTERSECT_FIRST);
1388 return gst_caps_ref (src->
caps);
1391 return gst_caps_ref (filter);
1393 return gst_caps_new_any ();
1405 GST_INFO_OBJECT (src,
"set caps: %" GST_PTR_FORMAT, caps);
1416 g_autofree gchar *contents = NULL;
1417 GError *error = NULL;
1421 const gchar *caps_str = NULL;
1425 g_return_val_if_fail (src != NULL,
FALSE);
1428 if ((file = g_file_new_for_path (src->
json_filename)) == NULL) {
1429 GST_ERROR_OBJECT (src,
"Failed to get file object of %s.",
1434 if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error)) {
1435 GST_ERROR_OBJECT (src,
"Failed to open %s: %s", src->
json_filename,
1436 error ? error->message :
"Unknown error");
1437 g_clear_error (&error);
1438 g_object_unref (file);
1443 g_object_unref (src->
parser);
1444 src->
parser = json_parser_new ();
1446 if (!json_parser_load_from_data (src->
parser, contents, -1, NULL)) {
1447 GST_ERROR_OBJECT (src,
"Failed to load data from %s", src->
json_filename);
1451 root = json_parser_get_root (src->
parser);
1452 if (!JSON_NODE_HOLDS_OBJECT (root)) {
1453 GST_ERROR_OBJECT (src,
"it does not contain a JsonObject: %s", contents);
1457 object = json_node_get_object (root);
1459 GST_INFO_OBJECT (src,
">>>>>>> Start parsing JSON file(%s)",
1462 if (!json_object_has_member (
object,
"gst_caps")) {
1463 GST_ERROR_OBJECT (src,
"There is no gst_caps field: %s", contents);
1467 caps_str = json_object_get_string_member (
object,
"gst_caps");
1468 GST_INFO_OBJECT (src,
"caps_str : %s", caps_str);
1470 new_caps = gst_caps_from_string (caps_str);
1476 GST_INFO_OBJECT (src,
"gst_caps : %" GST_PTR_FORMAT, src->
caps);
1482 if (!json_object_has_member (
object,
"sample_size")) {
1483 GST_ERROR_OBJECT (src,
"There is not sample_size field: %s", contents);
1487 val = json_object_get_int_member (
object,
"sample_size");
1489 GST_ERROR_OBJECT (src,
"Invalid sample_size: %" G_GINT64_FORMAT, val);
1494 GST_INFO_OBJECT (src,
"sample_size: %zd", src->
sample_size);
1499 if (!json_object_has_member (
object,
"sample_offset")) {
1500 GST_ERROR_OBJECT (src,
"There is no sample_offset field: %s", contents);
1504 json_object_get_array_member (
object,
"sample_offset");
1508 if (!json_object_has_member (
object,
"tensor_size")) {
1509 GST_ERROR_OBJECT (src,
"There is no tensor_size field: %s", contents);
1513 json_object_get_array_member (
object,
"tensor_size");
1515 GST_INFO_OBJECT (src,
"tensor_size_array_len:%u",
1518 if (!json_object_has_member (
object,
"tensor_count")) {
1519 GST_ERROR_OBJECT (src,
"There is no tensor_count field: %s", contents);
1523 json_object_get_array_member (
object,
"tensor_count");
1526 GST_INFO_OBJECT (src,
"tensor_count_array_len:%u",
1533 if (!json_object_has_member (
object,
"total_samples")) {
1534 GST_ERROR_OBJECT (src,
"There is no total_samples field: %s", contents);
1538 val = json_object_get_int_member (
object,
"total_samples");
1540 GST_ERROR_OBJECT (src,
"Invalid total_samples: %" G_GINT64_FORMAT, val);
1545 GST_INFO_OBJECT (src,
"total_samples: %u", src->
total_samples);
1547 g_object_unref (file);
1552 GST_ERROR_OBJECT (src,
"Failed to parse %s", src->
json_filename);
1553 g_object_unref (file);
1563 const GValue * value, GParamSpec * pspec)
1566 const GstCaps *caps;
1575 g_value_get_string (value), NULL);
1579 g_value_get_string (value), NULL);
1583 GST_ERROR_OBJECT (src,
"Failed to get data format");
1593 src->
epochs = g_value_get_uint (value);
1596 src->
is_shuffle = g_value_get_boolean (value);
1602 GST_ERROR_OBJECT (src,
"Failed to set tensors sequence");
1608 caps = gst_value_get_caps (value);
1621 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
1653 g_value_set_uint (value, src->
epochs);
1656 g_value_set_boolean (value, src->
is_shuffle);
1662 gst_value_set_caps (value, src->
caps);
1665 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
1673 static GstStateChangeReturn
1678 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1679 GstBaseSrc *basesrc = NULL;
1682 switch (transition) {
1683 case GST_STATE_CHANGE_NULL_TO_READY:
1684 GST_INFO_OBJECT (src,
"NULL_TO_READY");
1687 goto state_change_failed;
1694 basesrc = GST_BASE_SRC (src);
1695 g_object_get (G_OBJECT (basesrc),
"blocksize", &blocksize, NULL);
1696 GST_DEBUG_OBJECT (src,
"blocksize = %u", blocksize);
1697 if (blocksize == 0) {
1698 GST_ERROR_OBJECT (src,
"Please set the 'blocksize' property "
1699 "when using the 'caps' property to set the sample format without JSON.");
1700 goto state_change_failed;
1707 GST_ERROR_OBJECT (src,
"Please set the 'stop-sample-index' property "
1708 "when using the 'caps' property to set the sample format without JSON.");
1709 goto state_change_failed;
1720 GST_ERROR_OBJECT (src,
"Check for invalid range values");
1722 goto state_change_failed;
1728 GST_ERROR_OBJECT (src,
1729 "tensors-sequence properties is only for tensor/others type(%d), current type(%d)",
1731 goto state_change_failed;
1735 goto state_change_failed;
1744 case GST_STATE_CHANGE_READY_TO_PAUSED:
1745 GST_INFO_OBJECT (src,
"READY_TO_PAUSED");
1748 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1749 GST_INFO_OBJECT (src,
"PAUSED_TO_PLAYING");
1756 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1758 switch (transition) {
1759 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1760 GST_INFO_OBJECT (src,
"PLAYING_TO_PAUSED");
1763 case GST_STATE_CHANGE_PAUSED_TO_READY:
1764 GST_INFO_OBJECT (src,
"PAUSED_TO_READY");
1767 case GST_STATE_CHANGE_READY_TO_NULL:
1768 GST_INFO_OBJECT (src,
"READY_TO_NULL");
1777 state_change_failed:
1778 GST_ERROR_OBJECT (src,
"state change failed");
1780 return GST_STATE_CHANGE_FAILURE;