Doxygen Book
gstdatareposrc.c File Reference

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"
Include dependency graph for gstdatareposrc.c:

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
 

Detailed Description

GStreamer plugin to read file in MLOps Data repository into buffers.

Copyright (C) 2022 Samsung Electronics Co., Ltd.

Date
31 January 2023
See also
https://github.com/nnstreamer/nnstreamer
Author
Hyunil Park hyuni.nosp@m.l46..nosp@m.park@.nosp@m.sams.nosp@m.ung.c.nosp@m.om
Bug:
No known bugs except for NYI items

//! 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.

Macro Definition Documentation

◆ _do_init

#define _do_init   GST_DEBUG_CATEGORY_INIT (gst_data_repo_src_debug, "datareposrc", 0, "datareposrc element");

Definition at line 108 of file gstdatareposrc.c.

◆ DEFAULT_EPOCHS

#define DEFAULT_EPOCHS   1

Definition at line 91 of file gstdatareposrc.c.

◆ DEFAULT_INDEX

#define DEFAULT_INDEX   0

Definition at line 90 of file gstdatareposrc.c.

◆ DEFAULT_IS_SHUFFLE

#define DEFAULT_IS_SHUFFLE   TRUE

Definition at line 92 of file gstdatareposrc.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_data_repo_src_debug

Definition at line 74 of file gstdatareposrc.c.

◆ gst_data_repo_src_parent_class

#define gst_data_repo_src_parent_class   parent_class

Definition at line 111 of file gstdatareposrc.c.

◆ O_BINARY

#define O_BINARY   (0)

Definition at line 65 of file gstdatareposrc.c.

◆ S_ISDIR

#define S_ISDIR (   mode)    ((mode)&_S_IFDIR)

Definition at line 58 of file gstdatareposrc.c.

◆ S_ISREG

#define S_ISREG (   mode)    ((mode)&_S_IFREG)

Definition at line 55 of file gstdatareposrc.c.

◆ S_ISSOCK

#define S_ISSOCK (   x)    (0)

Definition at line 62 of file gstdatareposrc.c.

◆ struct_stat

#define struct_stat   struct stat

Definition at line 52 of file gstdatareposrc.c.

Enumeration Type Documentation

◆ anonymous enum

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.

Function Documentation

◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE ( GstDataRepoSrc  ,
gst_data_repo_src  ,
GST_TYPE_PUSH_SRC  ,
_do_init   
)

◆ gst_data_repo_get_caps_by_tensors_sequence()

static gboolean gst_data_repo_get_caps_by_tensors_sequence ( GstDataRepoSrc src)
static

Get caps with tensors_sequence applied.

Definition at line 1326 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_change_state()

static GstStateChangeReturn gst_data_repo_src_change_state ( GstElement *  element,
GstStateChange  transition 
)
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.

Here is the caller graph for this function:

◆ gst_data_repo_src_class_init()

static void gst_data_repo_src_class_init ( GstDataRepoSrcClass klass)
static

initialize the datareposrc's class

Definition at line 119 of file gstdatareposrc.c.

Here is the call graph for this function:

◆ gst_data_repo_src_create()

static GstFlowReturn gst_data_repo_src_create ( GstPushSrc *  pushsrc,
GstBuffer **  buffer 
)
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_epoch_is_done()

static gboolean gst_data_repo_src_epoch_is_done ( GstDataRepoSrc src)
static

Function to check epoch and EOS.

Definition at line 553 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_finalize()

static void gst_data_repo_src_finalize ( GObject *  object)
static

Function to finalize instance.

Definition at line 270 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_get_caps()

static GstCaps * gst_data_repo_src_get_caps ( GstBaseSrc *  basesrc,
GstCaps *  filter 
)
static

Get caps for caps negotiation.

Definition at line 1371 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_get_file_offset()

static guint64 gst_data_repo_src_get_file_offset ( GstDataRepoSrc src,
guint  sample_index 
)
static

Function to get file offset with sample index.

Definition at line 504 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_get_image_filename()

static gchar* gst_data_repo_src_get_image_filename ( GstDataRepoSrc src)
static

Get image filename.

Definition at line 894 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_get_num_tensors()

static guint gst_data_repo_src_get_num_tensors ( GstDataRepoSrc src,
guint  shuffled_index 
)
static

Function to get num_tensors from tensor_count_array.

Definition at line 708 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_get_property()

static void gst_data_repo_src_get_property ( GObject *  object,
guint  prop_id,
GValue *  value,
GParamSpec *  pspec 
)
static

Getter datareposrc properties.

Definition at line 1630 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_init()

static void gst_data_repo_src_init ( GstDataRepoSrc src)
static

Initialize datareposrc.

Definition at line 223 of file gstdatareposrc.c.

Here is the call graph for this function:

◆ gst_data_repo_src_parse_caps()

static gboolean gst_data_repo_src_parse_caps ( GstDataRepoSrc src,
GstCaps *  caps 
)
static

Parse gst-caps to get media type and data size.

Note
This function always takes the ownership of gst-caps.

Definition at line 303 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_read_flexible_or_sparse_tensors()

static GstFlowReturn gst_data_repo_src_read_flexible_or_sparse_tensors ( GstDataRepoSrc src,
GstBuffer **  buffer 
)
static

Function to read flexible or sparse tensors.

Definition at line 744 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_read_json_file()

static gboolean gst_data_repo_src_read_json_file ( GstDataRepoSrc src)
static

Read JSON file.

Definition at line 1414 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_read_multi_images()

static GstFlowReturn gst_data_repo_src_read_multi_images ( GstDataRepoSrc src,
GstBuffer **  buffer 
)
static

Function to read multi image files.

Definition at line 927 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_read_others()

static GstFlowReturn gst_data_repo_src_read_others ( GstDataRepoSrc src,
GstBuffer **  buffer 
)
static

Function to read others media type (video, audio, octet and text)

Definition at line 1002 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_read_tensors()

static GstFlowReturn gst_data_repo_src_read_tensors ( GstDataRepoSrc src,
GstBuffer **  buffer 
)
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.

the offset of the second sample is as follows.

sample_offset: 6352 tensors index: [ 0 | 1 | 2 | 3 ] tensors_size: [ 3136 | 40 | 3136 | 40 ] tensors_offset: [ 0 | 3136 | 3176 | 6312 ]

fd offset: [ 6352 | 9488 | 9528 | 12664 ]

if user sets "tensor-sequence=2,1", datareposrc read offset 9528 then 9488.

Definition at line 570 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_set_caps()

static gboolean gst_data_repo_src_set_caps ( GstBaseSrc *  basesrc,
GstCaps *  caps 
)
static

caps after caps negotiation

Definition at line 1401 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_set_file_path()

static gboolean gst_data_repo_src_set_file_path ( GstDataRepoSrc src,
const int  prop,
const gchar *  file_path,
GError **  err 
)
static

Function to set file path.

Definition at line 396 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_set_property()

static void gst_data_repo_src_set_property ( GObject *  object,
guint  prop_id,
const GValue *  value,
GParamSpec *  pspec 
)
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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_set_tensors_sequence()

static gboolean gst_data_repo_src_set_tensors_sequence ( GstDataRepoSrc src)
static

Function to set tensors sequence.

Definition at line 450 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_set_timestamp()

static void gst_data_repo_src_set_timestamp ( GstDataRepoSrc src,
GstBuffer *  buffer 
)
static

Set timestamp.

Definition at line 1225 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_shuffle_samples_index()

static void gst_data_repo_src_shuffle_samples_index ( GstDataRepoSrc src)
static

Function to shuffle samples index.

Definition at line 521 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ gst_data_repo_src_start()

static gboolean gst_data_repo_src_start ( GstDataRepoSrc src)
static

Start datareposrc, open the file.

Definition at line 1102 of file gstdatareposrc.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gst_data_repo_src_stop()

static gboolean gst_data_repo_src_stop ( GstBaseSrc *  basesrc)
static

Stop datareposrc, unmap and close the file.

Definition at line 1311 of file gstdatareposrc.c.

Here is the caller graph for this function:

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_data_repo_src_debug  )

Variable Documentation

◆ srctemplate

GstStaticPadTemplate srctemplate
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY)

Definition at line 68 of file gstdatareposrc.c.