GStreamer plugin to read file in MLOps Data repository into buffers. More...
#include <gst/gst.h>
#include <gst/video/video-info.h>
#include <gst/audio/audio-info.h>
#include <glib/gstdio.h>
#include <nnstreamer_plugin_api.h>
#include <nnstreamer_util.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <inttypes.h>
#include "gstdatareposrc.h"
Go to the source code of this file.
Macros | |
#define | struct_stat struct stat |
#define | S_ISREG(mode) ((mode)&_S_IFREG) |
#define | S_ISDIR(mode) ((mode)&_S_IFDIR) |
#define | S_ISSOCK(x) (0) |
#define | O_BINARY (0) |
#define | GST_CAT_DEFAULT gst_data_repo_src_debug |
#define | DEFAULT_INDEX 0 |
#define | DEFAULT_EPOCHS 1 |
#define | DEFAULT_IS_SHUFFLE TRUE |
#define | _do_init GST_DEBUG_CATEGORY_INIT (gst_data_repo_src_debug, "datareposrc", 0, "datareposrc element"); |
#define | gst_data_repo_src_parent_class parent_class |
Enumerations | |
enum | { PROP_0, PROP_LOCATION, PROP_JSON, PROP_START_SAMPLE_INDEX, PROP_STOP_SAMPLE_INDEX, PROP_EPOCHS, PROP_IS_SHUFFLE, PROP_TENSORS_SEQUENCE, PROP_CAPS } |
Functions | |
GST_DEBUG_CATEGORY_STATIC (gst_data_repo_src_debug) | |
static void | gst_data_repo_src_finalize (GObject *object) |
Function to finalize instance. More... | |
static GstStateChangeReturn | gst_data_repo_src_change_state (GstElement *element, GstStateChange transition) |
Change state of datareposrc. More... | |
static void | gst_data_repo_src_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
Setter for datareposrc properties. More... | |
static void | gst_data_repo_src_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
Getter datareposrc properties. More... | |
static gboolean | gst_data_repo_src_stop (GstBaseSrc *basesrc) |
Stop datareposrc, unmap and close the file. More... | |
static GstCaps * | gst_data_repo_src_get_caps (GstBaseSrc *basesrc, GstCaps *filter) |
Get caps for caps negotiation. More... | |
static gboolean | gst_data_repo_src_set_caps (GstBaseSrc *basesrc, GstCaps *caps) |
caps after caps negotiation More... | |
static GstFlowReturn | gst_data_repo_src_create (GstPushSrc *pushsrc, GstBuffer **buffer) |
Function to create a buffer. More... | |
G_DEFINE_TYPE_WITH_CODE (GstDataRepoSrc, gst_data_repo_src, GST_TYPE_PUSH_SRC, _do_init) | |
static void | gst_data_repo_src_class_init (GstDataRepoSrcClass *klass) |
initialize the datareposrc's class More... | |
static void | gst_data_repo_src_init (GstDataRepoSrc *src) |
Initialize datareposrc. More... | |
static gboolean | gst_data_repo_src_parse_caps (GstDataRepoSrc *src, GstCaps *caps) |
Parse gst-caps to get media type and data size. More... | |
static gboolean | gst_data_repo_src_set_file_path (GstDataRepoSrc *src, const int prop, const gchar *file_path, GError **err) |
Function to set file path. More... | |
static gboolean | gst_data_repo_src_set_tensors_sequence (GstDataRepoSrc *src) |
Function to set tensors sequence. More... | |
static guint64 | gst_data_repo_src_get_file_offset (GstDataRepoSrc *src, guint sample_index) |
Function to get file offset with sample index. More... | |
static void | gst_data_repo_src_shuffle_samples_index (GstDataRepoSrc *src) |
Function to shuffle samples index. More... | |
static gboolean | gst_data_repo_src_epoch_is_done (GstDataRepoSrc *src) |
Function to check epoch and EOS. More... | |
static GstFlowReturn | gst_data_repo_src_read_tensors (GstDataRepoSrc *src, GstBuffer **buffer) |
Function to read tensors. More... | |
static guint | gst_data_repo_src_get_num_tensors (GstDataRepoSrc *src, guint shuffled_index) |
Function to get num_tensors from tensor_count_array. More... | |
static GstFlowReturn | gst_data_repo_src_read_flexible_or_sparse_tensors (GstDataRepoSrc *src, GstBuffer **buffer) |
Function to read flexible or sparse tensors. More... | |
static gchar * | gst_data_repo_src_get_image_filename (GstDataRepoSrc *src) |
Get image filename. More... | |
static GstFlowReturn | gst_data_repo_src_read_multi_images (GstDataRepoSrc *src, GstBuffer **buffer) |
Function to read multi image files. More... | |
static GstFlowReturn | gst_data_repo_src_read_others (GstDataRepoSrc *src, GstBuffer **buffer) |
Function to read others media type (video, audio, octet and text) More... | |
static gboolean | gst_data_repo_src_start (GstDataRepoSrc *src) |
Start datareposrc, open the file. More... | |
static void | gst_data_repo_src_set_timestamp (GstDataRepoSrc *src, GstBuffer *buffer) |
Set timestamp. More... | |
static gboolean | gst_data_repo_get_caps_by_tensors_sequence (GstDataRepoSrc *src) |
Get caps with tensors_sequence applied. More... | |
static gboolean | gst_data_repo_src_read_json_file (GstDataRepoSrc *src) |
Read JSON file. More... | |
Variables | |
static GstStaticPadTemplate | srctemplate |
GStreamer plugin to read file in MLOps Data repository into buffers.
Copyright (C) 2022 Samsung Electronics Co., Ltd.
//! Example launch line |[ gst-launch-1.0 datareposrc location=mnist.data json=mnist.json start-sample-index=3 stop-sample-index=202 epochs=5 ! \ ! tensor_sink gst-launch-1.0 datareposrc location=image_%02ld.png json=image.json start-sample-index=3 stop-sample-index=9 epochs=2 ! fakesink gst-launch-1.0 datareposrc location=audiofile json=audio.json ! fakesink gst-launch-1.0 datareposrc location=videofile json=video.json ! fakesink |] |[ Unknown sample file(has not JSON) need to set caps and blocksize or set caps to tensors type without blocksize gst-launch-1.0 datareposrc blocksize=3176 location=unknown.data start-sample-index=3 stop-sample-index=202 epochs=5 \ caps ="application/octet-stream" ! tensor_converter input-dim=1:1:784:1,1:1:10:1 input-type=float32,float32 ! fakesink |] or |[ gst-launch-1.0 datareposrc location=unknown.data start-sample-index=3 stop-sample-index=202 epochs=5 \ caps ="other/tensors, format=(string)static, framerate=(fraction)0/1, num_tensors=(int)2, dimensions=(string)1:1:784:1.1:1:10:1, types=(string)float32.float32" \ ! fakesink ]|
Definition in file gstdatareposrc.c.
#define _do_init GST_DEBUG_CATEGORY_INIT (gst_data_repo_src_debug, "datareposrc", 0, "datareposrc element"); |
Definition at line 108 of file gstdatareposrc.c.
#define DEFAULT_EPOCHS 1 |
Definition at line 91 of file gstdatareposrc.c.
#define DEFAULT_INDEX 0 |
Definition at line 90 of file gstdatareposrc.c.
#define DEFAULT_IS_SHUFFLE TRUE |
Definition at line 92 of file gstdatareposrc.c.
#define GST_CAT_DEFAULT gst_data_repo_src_debug |
Definition at line 74 of file gstdatareposrc.c.
#define gst_data_repo_src_parent_class parent_class |
Definition at line 111 of file gstdatareposrc.c.
#define O_BINARY (0) |
Definition at line 65 of file gstdatareposrc.c.
#define S_ISDIR | ( | mode | ) | ((mode)&_S_IFDIR) |
Definition at line 58 of file gstdatareposrc.c.
#define S_ISREG | ( | mode | ) | ((mode)&_S_IFREG) |
Definition at line 55 of file gstdatareposrc.c.
#define S_ISSOCK | ( | x | ) | (0) |
Definition at line 62 of file gstdatareposrc.c.
#define struct_stat struct stat |
Definition at line 52 of file gstdatareposrc.c.
anonymous enum |
Enumerator | |
---|---|
PROP_0 | |
PROP_LOCATION | |
PROP_JSON | |
PROP_START_SAMPLE_INDEX | |
PROP_STOP_SAMPLE_INDEX | |
PROP_EPOCHS | |
PROP_IS_SHUFFLE | |
PROP_TENSORS_SEQUENCE | |
PROP_CAPS |
Definition at line 77 of file gstdatareposrc.c.
G_DEFINE_TYPE_WITH_CODE | ( | GstDataRepoSrc | , |
gst_data_repo_src | , | ||
GST_TYPE_PUSH_SRC | , | ||
_do_init | |||
) |
|
static |
Get caps with tensors_sequence applied.
Definition at line 1326 of file gstdatareposrc.c.
|
static |
Change state of datareposrc.
if data_type is not GST_DATA_REPO_DATA_UNKNOWN and sample_size is 0 then 'caps' is set by property and sample size needs to be set by blocksize (in the case of otect and text)
A case of importing a sample format using 'caps' property without JSON.
Definition at line 1674 of file gstdatareposrc.c.
|
static |
initialize the datareposrc's class
Definition at line 119 of file gstdatareposrc.c.
|
static |
Function to create a buffer.
set_caps is completed after PAUSED_TO_PLAYING, so we cannot use change_state. datareposrc can get type and size after set_caps()
Definition at line 1263 of file gstdatareposrc.c.
|
static |
Function to check epoch and EOS.
Definition at line 553 of file gstdatareposrc.c.
|
static |
Function to finalize instance.
Definition at line 270 of file gstdatareposrc.c.
|
static |
Get caps for caps negotiation.
Definition at line 1371 of file gstdatareposrc.c.
|
static |
Function to get file offset with sample index.
Definition at line 504 of file gstdatareposrc.c.
|
static |
Get image filename.
Definition at line 894 of file gstdatareposrc.c.
|
static |
Function to get num_tensors from tensor_count_array.
Definition at line 708 of file gstdatareposrc.c.
|
static |
Getter datareposrc properties.
Definition at line 1630 of file gstdatareposrc.c.
|
static |
Initialize datareposrc.
Definition at line 223 of file gstdatareposrc.c.
|
static |
Parse gst-caps to get media type and data size.
Definition at line 303 of file gstdatareposrc.c.
|
static |
Function to read flexible or sparse tensors.
Definition at line 744 of file gstdatareposrc.c.
|
static |
Read JSON file.
Definition at line 1414 of file gstdatareposrc.c.
|
static |
Function to read multi image files.
Definition at line 927 of file gstdatareposrc.c.
|
static |
Function to read others media type (video, audio, octet and text)
Definition at line 1002 of file gstdatareposrc.c.
|
static |
Function to read tensors.
offset and sample_offset(byte size) are from 0. if the size of one sample is 6352 and num_tensors is 4, dimensions are '1:1:784:1' , '1:1:10:1', '1:1:784:1' and '1:1:10:1' with float32.
sample_offset: 6352 tensors index: [ 0 | 1 | 2 | 3 ] tensors_size: [ 3136 | 40 | 3136 | 40 ] tensors_offset: [ 0 | 3136 | 3176 | 6312 ]
if user sets "tensor-sequence=2,1", datareposrc read offset 9528 then 9488.
Definition at line 570 of file gstdatareposrc.c.
|
static |
caps after caps negotiation
Definition at line 1401 of file gstdatareposrc.c.
|
static |
Function to set file path.
Definition at line 396 of file gstdatareposrc.c.
|
static |
Setter for datareposrc properties.
To get caps, read JSON before Caps negotiation, to get information on sample data
let's retry set tensors-sequence. if caps property is set later than tensors-sequence property, setting tensors-sequence fails because caps information is unknown.
Definition at line 1562 of file gstdatareposrc.c.
|
static |
Function to set tensors sequence.
Definition at line 450 of file gstdatareposrc.c.
|
static |
Set timestamp.
Definition at line 1225 of file gstdatareposrc.c.
|
static |
Function to shuffle samples index.
Definition at line 521 of file gstdatareposrc.c.
|
static |
Start datareposrc, open the file.
Definition at line 1102 of file gstdatareposrc.c.
|
static |
Stop datareposrc, unmap and close the file.
Definition at line 1311 of file gstdatareposrc.c.
GST_DEBUG_CATEGORY_STATIC | ( | gst_data_repo_src_debug | ) |
|
static |
Definition at line 68 of file gstdatareposrc.c.