Doxygen Book
gstdatareposink.c File Reference

GStreamer plugin that writes data from buffers to files in in MLOps Data repository. More...

#include <gst/gst.h>
#include <gst/video/video-info.h>
#include <gst/audio/audio-info.h>
#include <glib/gstdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <nnstreamer_plugin_api.h>
#include <tensor_common.h>
#include <nnstreamer_util.h>
#include "gstdatareposink.h"
Include dependency graph for gstdatareposink.c:

Go to the source code of this file.

Macros

#define TENSOR_CAPS   GST_TENSORS_CAP_MAKE ("{ static, flexible, sparse }")
 Tensors caps. More...
 
#define SUPPORTED_VIDEO_FORMAT   "{RGB, BGR, RGBx, BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, GRAY8}"
 Video caps. More...
 
#define VIDEO_CAPS
 
#define SUPPORTED_AUDIO_FORMAT   "{S8, U8, S16LE, S16BE, U16LE, U16BE, S32LE, S32BE, U32LE, U32BE, F32LE, F32BE, F64LE, F64BE}"
 Audio caps. More...
 
#define AUDIO_CAPS
 
#define TEXT_CAPS   "text/x-raw, format = (string) utf8"
 Text caps. More...
 
#define OCTET_CAPS   "application/octet-stream"
 Octet caps. More...
 
#define IMAGE_CAPS
 Image caps. More...
 
#define GST_CAT_DEFAULT   gst_data_repo_sink_debug
 
#define _do_init   GST_DEBUG_CATEGORY_INIT (gst_data_repo_sink_debug, "datareposink", 0, "datareposink element");
 
#define gst_data_repo_sink_parent_class   parent_class
 

Enumerations

enum  { PROP_0, PROP_LOCATION, PROP_JSON }
 datareposink properties. More...
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gst_data_repo_sink_debug)
 
 G_DEFINE_TYPE_WITH_CODE (GstDataRepoSink, gst_data_repo_sink, GST_TYPE_BASE_SINK, _do_init)
 
static void gst_data_repo_sink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 Setter for datareposink properties. More...
 
static void gst_data_repo_sink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 Getter datareposink properties. More...
 
static void gst_data_repo_sink_finalize (GObject *object)
 finalize datareposink. More...
 
static gboolean gst_data_repo_sink_stop (GstBaseSink *basesink)
 Stop datareposink. More...
 
static GstStateChangeReturn gst_data_repo_sink_change_state (GstElement *element, GstStateChange transition)
 Change state of datareposink. More...
 
static GstFlowReturn gst_data_repo_sink_render (GstBaseSink *bsink, GstBuffer *buffer)
 Called when a buffer should be presented or output. More...
 
static GstCaps * gst_data_repo_sink_get_caps (GstBaseSink *bsink, GstCaps *filter)
 Get caps of datareposink. More...
 
static gboolean gst_data_repo_sink_set_caps (GstBaseSink *bsink, GstCaps *caps)
 Set caps of datareposink. More...
 
static gboolean gst_data_repo_sink_query (GstBaseSink *bsink, GstQuery *query)
 Perform a GstQuery on datareposink. More...
 
static void gst_data_repo_sink_class_init (GstDataRepoSinkClass *klass)
 Initialize datareposink class. More...
 
static void gst_data_repo_sink_init (GstDataRepoSink *sink)
 Initialize datareposink. More...
 
static GstFlowReturn gst_data_repo_sink_write_others (GstDataRepoSink *sink, GstBuffer *buffer)
 Function to write others media type (tensors(fixed), video, audio, octet and text) More...
 
static GstFlowReturn gst_data_repo_sink_write_flexible_or_sparse_tensors (GstDataRepoSink *sink, GstBuffer *buffer)
 Function to write flexible tensors or sparse tensors. More...
 
static gchar * gst_data_repo_sink_get_image_filename (GstDataRepoSink *sink)
 Get image filename. More...
 
static GstFlowReturn gst_data_repo_sink_write_multi_images (GstDataRepoSink *sink, GstBuffer *buffer)
 Function to read multi image files. More...
 
static void gst_data_repo_sink_set_is_static_tensors (GstDataRepoSink *sink)
 Set whether the given pad caps are static or not. More...
 
static gboolean gst_data_repo_sink_open_file (GstDataRepoSink *sink)
 Function to open file. More...
 
static gboolean __write_json (JsonObject *object, const gchar *filename)
 Write json to file. More...
 
static gboolean gst_data_repo_sink_write_json_meta_file (GstDataRepoSink *sink)
 write the meta information to a JSON file More...
 

Variables

static GstStaticPadTemplate sinktemplate
 

Detailed Description

GStreamer plugin that writes data from buffers to files in in MLOps Data repository.

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

Date
30 March 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 videotestsrc ! datareposink location=filename json=video.json gst-launch-1.0 videotestsrc ! pngenc ! datareposink location=image_%02d.png json=video.json gst-launch-1.0 audiotestsrc samplesperbuffer=44100 ! audio/x-raw, format=S16LE, layout=interleaved, rate=44100, channels=1 ! \ datareposink location=filename json=audio.json gst-launch-1.0 datareposrc location=file.dat json=file.json tensors-sequence=2,3 start-sample-index=0 stop-sample-index=199 epochs=1 ! \ other/tensors, format=static, num_tensors=2, framerate=0/1, dimensions=1:1:784:1.1:1:10:1, types=float32.float32 ! \ datareposink location=hyunil.dat json=file.json ]|

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

Date
30 March 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

Definition in file gstdatareposink.c.

Macro Definition Documentation

◆ _do_init

#define _do_init   GST_DEBUG_CATEGORY_INIT (gst_data_repo_sink_debug, "datareposink", 0, "datareposink element");

Definition at line 92 of file gstdatareposink.c.

◆ AUDIO_CAPS

#define AUDIO_CAPS
Value:
GST_AUDIO_CAPS_MAKE (SUPPORTED_AUDIO_FORMAT) "," \
"layout = (string) interleaved"

Definition at line 55 of file gstdatareposink.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_data_repo_sink_debug

Definition at line 91 of file gstdatareposink.c.

◆ gst_data_repo_sink_parent_class

#define gst_data_repo_sink_parent_class   parent_class

Definition at line 94 of file gstdatareposink.c.

◆ IMAGE_CAPS

#define IMAGE_CAPS
Value:
"image/png, width = (int) [ 16, 1000000 ], height = (int) [ 16, 1000000 ], framerate = (fraction) [ 0/1, MAX];" \
"image/jpeg, width = (int) [ 16, 65535 ], height = (int) [ 16, 65535 ], framerate = (fraction) [ 0/1, MAX], sof-marker = (int) { 0, 1, 2, 4, 9 };" \
"image/tiff, endianness = (int) { BIG_ENDIAN, LITTLE_ENDIAN };" \
"image/gif;" \
"image/bmp"

Image caps.

Definition at line 68 of file gstdatareposink.c.

◆ OCTET_CAPS

#define OCTET_CAPS   "application/octet-stream"

Octet caps.

Definition at line 64 of file gstdatareposink.c.

◆ SUPPORTED_AUDIO_FORMAT

#define SUPPORTED_AUDIO_FORMAT   "{S8, U8, S16LE, S16BE, U16LE, U16BE, S32LE, S32BE, U32LE, U32BE, F32LE, F32BE, F64LE, F64BE}"

Audio caps.

Definition at line 53 of file gstdatareposink.c.

◆ SUPPORTED_VIDEO_FORMAT

#define SUPPORTED_VIDEO_FORMAT   "{RGB, BGR, RGBx, BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, GRAY8}"

Video caps.

Definition at line 46 of file gstdatareposink.c.

◆ TENSOR_CAPS

#define TENSOR_CAPS   GST_TENSORS_CAP_MAKE ("{ static, flexible, sparse }")

Tensors caps.

Definition at line 42 of file gstdatareposink.c.

◆ TEXT_CAPS

#define TEXT_CAPS   "text/x-raw, format = (string) utf8"

Text caps.

Definition at line 60 of file gstdatareposink.c.

◆ VIDEO_CAPS

#define VIDEO_CAPS
Value:
GST_VIDEO_CAPS_MAKE (SUPPORTED_VIDEO_FORMAT) "," \
"interlace-mode = (string) progressive"

Definition at line 48 of file gstdatareposink.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

datareposink properties.

Enumerator
PROP_0 
PROP_LOCATION 
PROP_JSON 

Definition at line 83 of file gstdatareposink.c.

Function Documentation

◆ __write_json()

static gboolean __write_json ( JsonObject *  object,
const gchar *  filename 
)
static

Write json to file.

Definition at line 668 of file gstdatareposink.c.

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

◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE ( GstDataRepoSink  ,
gst_data_repo_sink  ,
GST_TYPE_BASE_SINK  ,
_do_init   
)

◆ gst_data_repo_sink_change_state()

static GstStateChangeReturn gst_data_repo_sink_change_state ( GstElement *  element,
GstStateChange  transition 
)
static

Change state of datareposink.

Definition at line 750 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_class_init()

static void gst_data_repo_sink_class_init ( GstDataRepoSinkClass klass)
static

Initialize datareposink class.

Definition at line 118 of file gstdatareposink.c.

Here is the call graph for this function:

◆ gst_data_repo_sink_finalize()

static void gst_data_repo_sink_finalize ( GObject *  object)
static

finalize datareposink.

Definition at line 195 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_get_caps()

static GstCaps * gst_data_repo_sink_get_caps ( GstBaseSink *  bsink,
GstCaps *  filter 
)
static

Get caps of datareposink.

Definition at line 494 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ gst_data_repo_sink_get_image_filename()

static gchar* gst_data_repo_sink_get_image_filename ( GstDataRepoSink sink)
static

Get image filename.

Definition at line 400 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ gst_data_repo_sink_get_property()

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

Getter datareposink properties.

Definition at line 251 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_init()

static void gst_data_repo_sink_init ( GstDataRepoSink sink)
static

Initialize datareposink.

Definition at line 174 of file gstdatareposink.c.

◆ gst_data_repo_sink_open_file()

static gboolean gst_data_repo_sink_open_file ( GstDataRepoSink sink)
static

Function to open file.

Definition at line 590 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_query()

static gboolean gst_data_repo_sink_query ( GstBaseSink *  sink,
GstQuery *  query 
)
static

Perform a GstQuery on datareposink.

Definition at line 564 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ gst_data_repo_sink_render()

static GstFlowReturn gst_data_repo_sink_render ( GstBaseSink *  bsink,
GstBuffer *  buffer 
)
static

Called when a buffer should be presented or output.

Definition at line 467 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_set_caps()

static gboolean gst_data_repo_sink_set_caps ( GstBaseSink *  bsink,
GstCaps *  caps 
)
static

Set caps of datareposink.

Definition at line 539 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_set_is_static_tensors()

static void gst_data_repo_sink_set_is_static_tensors ( GstDataRepoSink sink)
static

Set whether the given pad caps are static or not.

Definition at line 520 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_set_property()

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

Setter for datareposink properties.

Definition at line 227 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ gst_data_repo_sink_stop()

static gboolean gst_data_repo_sink_stop ( GstBaseSink *  basesink)
static

Stop datareposink.

Definition at line 652 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ gst_data_repo_sink_write_flexible_or_sparse_tensors()

static GstFlowReturn gst_data_repo_sink_write_flexible_or_sparse_tensors ( GstDataRepoSink sink,
GstBuffer *  buffer 
)
static

Function to write flexible tensors or sparse tensors.

Definition at line 317 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_write_json_meta_file()

static gboolean gst_data_repo_sink_write_json_meta_file ( GstDataRepoSink sink)
static

write the meta information to a JSON file

Definition at line 696 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_write_multi_images()

static GstFlowReturn gst_data_repo_sink_write_multi_images ( GstDataRepoSink sink,
GstBuffer *  buffer 
)
static

Function to read multi image files.

Definition at line 424 of file gstdatareposink.c.

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

◆ gst_data_repo_sink_write_others()

static GstFlowReturn gst_data_repo_sink_write_others ( GstDataRepoSink sink,
GstBuffer *  buffer 
)
static

Function to write others media type (tensors(fixed), video, audio, octet and text)

Definition at line 275 of file gstdatareposink.c.

Here is the caller graph for this function:

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_data_repo_sink_debug  )

Variable Documentation

◆ sinktemplate

GstStaticPadTemplate sinktemplate
static
Initial value:
=
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
GST_STATIC_CAPS (TENSOR_CAPS ";" VIDEO_CAPS ";" AUDIO_CAPS ";" IMAGE_CAPS

Definition at line 75 of file gstdatareposink.c.

TEXT_CAPS
#define TEXT_CAPS
Text caps.
Definition: gstdatareposink.c:60
SUPPORTED_AUDIO_FORMAT
#define SUPPORTED_AUDIO_FORMAT
Audio caps.
Definition: gstdatareposink.c:53
TENSOR_CAPS
#define TENSOR_CAPS
Tensors caps.
Definition: gstdatareposink.c:42
OCTET_CAPS
#define OCTET_CAPS
Octet caps.
Definition: gstdatareposink.c:64
AUDIO_CAPS
#define AUDIO_CAPS
Definition: gstdatareposink.c:55
SUPPORTED_VIDEO_FORMAT
#define SUPPORTED_VIDEO_FORMAT
Video caps.
Definition: gstdatareposink.c:46
IMAGE_CAPS
#define IMAGE_CAPS
Image caps.
Definition: gstdatareposink.c:68
VIDEO_CAPS
#define VIDEO_CAPS
Definition: gstdatareposink.c:48