Doxygen Book
gsttensor_crop.c File Reference

GStreamer element to crop the regions of incoming tensor. More...

#include <string.h>
#include <nnstreamer_util.h>
#include "gsttensor_crop.h"
#include "tensor_data.h"
Include dependency graph for gsttensor_crop.c:

Go to the source code of this file.

Classes

struct  tensor_region_s
 Internal data structure to describe tensor region. More...
 
struct  tensor_crop_info_s
 Internal data structure to describe cropping tensor data. More...
 

Macros

#define GST_CAT_DEFAULT   gst_tensor_crop_debug
 
#define DEFAULT_SILENT   TRUE
 Flag to print minimized log. More...
 
#define DEFAULT_LATENESS   (-1)
 Default value to compare timestamp of raw and info buffer, in milliseconds (-1 means no synchronization). More...
 
#define gst_tensor_crop_parent_class   parent_class
 

Enumerations

enum  { PROP_0, PROP_LATENESS, PROP_SILENT }
 tensor_crop properties More...
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gst_tensor_crop_debug)
 
 G_DEFINE_TYPE (GstTensorCrop, gst_tensor_crop, GST_TYPE_ELEMENT)
 
static void gst_tensor_crop_finalize (GObject *object)
 Function to finalize instance. More...
 
static void gst_tensor_crop_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 Setter for tensor_crop properties. More...
 
static void gst_tensor_crop_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 Getter for tensor_crop properties. More...
 
static GstStateChangeReturn gst_tensor_crop_change_state (GstElement *element, GstStateChange transition)
 Handle state transition. More...
 
static gboolean gst_tensor_crop_src_event (GstPad *pad, GstObject *parent, GstEvent *event)
 Handle event on src pad. More...
 
static gboolean gst_tensor_crop_sink_event (GstCollectPads *pads, GstCollectData *data, GstEvent *event, gpointer user_data)
 Handle event on sink pad. More...
 
static GstFlowReturn gst_tensor_crop_collected (GstCollectPads *pads, gpointer user_data)
 Chain function called when the buffer is available on all of the collect pads. More...
 
static void gst_tensor_crop_class_init (GstTensorCropClass *klass)
 Initialize the tensor_crop's class. More...
 
static void gst_tensor_crop_pad_reset (GstTensorCropPadData *cpad)
 Clear and reset old pad data. More...
 
static void gst_tensor_crop_reset (GstTensorCrop *self)
 Clear and reset old data in tensor_crop. More...
 
static void gst_tensor_crop_init (GstTensorCrop *self)
 Initialize tensor_crop element. More...
 
static GstFlowReturn gst_tensor_crop_negotiate (GstTensorCrop *self)
 Set pad caps if not negotiated. More...
 
static gboolean gst_tensor_crop_prepare_out_meta (GstTensorCrop *self, gpointer buffer, GstTensorMetaInfo *meta, GstTensorInfo *info, gboolean *is_flexible)
 Internal function to prepare output meta info. More...
 
static gboolean gst_tensor_crop_get_crop_info (GstTensorCrop *self, GstBuffer *info, tensor_crop_info_s *cinfo)
 Internal function to parse buffer and fill crop info. More...
 
static GstBuffer * gst_tensor_crop_do_cropping (GstTensorCrop *self, GstBuffer *raw, tensor_crop_info_s *cinfo)
 Internal function to crop incoming buffer. More...
 
static GstFlowReturn gst_tensor_crop_chain (GstTensorCrop *self, GstCollectData *data_raw, GstCollectData *data_info)
 Internal function to transform the input buffer. More...
 

Variables

static GstStaticPadTemplate raw_template
 Template for sink pad (raw data). More...
 
static GstStaticPadTemplate info_template
 Template for sink pad (crop info). More...
 
static GstStaticPadTemplate src_template
 Template for src pad. More...
 

Detailed Description

GStreamer element to crop the regions of incoming tensor.

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

Date
10 May 2021
See also
https://github.com/nnstreamer/nnstreamer
Author
Jaeyun Jung jy121.nosp@m.0.ju.nosp@m.ng@sa.nosp@m.msun.nosp@m.g.com
Bug:
No known bugs except for NYI items

Definition in file gsttensor_crop.c.

Macro Definition Documentation

◆ DEFAULT_LATENESS

#define DEFAULT_LATENESS   (-1)

Default value to compare timestamp of raw and info buffer, in milliseconds (-1 means no synchronization).

Definition at line 89 of file gsttensor_crop.c.

◆ DEFAULT_SILENT

#define DEFAULT_SILENT   TRUE

Flag to print minimized log.

Definition at line 84 of file gsttensor_crop.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_tensor_crop_debug

Definition at line 69 of file gsttensor_crop.c.

◆ gst_tensor_crop_parent_class

#define gst_tensor_crop_parent_class   parent_class

Definition at line 116 of file gsttensor_crop.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

tensor_crop properties

Enumerator
PROP_0 
PROP_LATENESS 
PROP_SILENT 

Definition at line 74 of file gsttensor_crop.c.

Function Documentation

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( GstTensorCrop  ,
gst_tensor_crop  ,
GST_TYPE_ELEMENT   
)

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_tensor_crop_debug  )

◆ gst_tensor_crop_chain()

static GstFlowReturn gst_tensor_crop_chain ( GstTensorCrop self,
GstCollectData *  data_raw,
GstCollectData *  data_info 
)
static

Internal function to transform the input buffer.

The case when raw and info have different timestamp. Compare timestamp and if time diff is less than lateness, crop raw buffer.

Definition at line 725 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_change_state()

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

Handle state transition.

Definition at line 333 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_class_init()

static void gst_tensor_crop_class_init ( GstTensorCropClass klass)
static

Initialize the tensor_crop's class.

GstTensorCrop::lateness:

The time difference between raw and info buffer, in milliseconds (-1 means no synchronization). If raw and info buffers on the pads have different timestamp and time-diff is larger than 'lateness', tensor-crop will drop old buffer and wait for next buffers.

GstTensorCrop::silent:

The flag to enable/disable debugging messages.

Definition at line 137 of file gsttensor_crop.c.

Here is the call graph for this function:

◆ gst_tensor_crop_collected()

static GstFlowReturn gst_tensor_crop_collected ( GstCollectPads *  pads,
gpointer  user_data 
)
static

Chain function called when the buffer is available on all of the collect pads.

Definition at line 812 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_do_cropping()

static GstBuffer* gst_tensor_crop_do_cropping ( GstTensorCrop self,
GstBuffer *  raw,
tensor_crop_info_s cinfo 
)
static

Internal function to crop incoming buffer.

Todo:
Add various mode to crop tensor.

Definition at line 624 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_finalize()

static void gst_tensor_crop_finalize ( GObject *  object)
static

Function to finalize instance.

Definition at line 265 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_get_crop_info()

static gboolean gst_tensor_crop_get_crop_info ( GstTensorCrop self,
GstBuffer *  info,
tensor_crop_info_s cinfo 
)
static

Internal function to parse buffer and fill crop info.

Todo:
Add various mode to crop tensor. Now tensor-crop handles NHWC data format only.

Definition at line 547 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_get_property()

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

Getter for tensor_crop properties.

Definition at line 309 of file gsttensor_crop.c.

Here is the caller graph for this function:

◆ gst_tensor_crop_init()

static void gst_tensor_crop_init ( GstTensorCrop self)
static

Initialize tensor_crop element.

Definition at line 228 of file gsttensor_crop.c.

Here is the call graph for this function:

◆ gst_tensor_crop_negotiate()

static GstFlowReturn gst_tensor_crop_negotiate ( GstTensorCrop self)
static

Set pad caps if not negotiated.

Cannot use gst-pad util to get stream ID (multiple sink pads). Create stream ID using first sink pad.

Get config from collect-pads and set framerate. Output is always flexible tensor.

Definition at line 423 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_pad_reset()

static void gst_tensor_crop_pad_reset ( GstTensorCropPadData cpad)
static

Clear and reset old pad data.

Definition at line 195 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_prepare_out_meta()

static gboolean gst_tensor_crop_prepare_out_meta ( GstTensorCrop self,
gpointer  buffer,
GstTensorMetaInfo meta,
GstTensorInfo info,
gboolean *  is_flexible 
)
static

Internal function to prepare output meta info.

Note
tensor-crop handles single tensor. Parse first one.

Definition at line 497 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_reset()

static void gst_tensor_crop_reset ( GstTensorCrop self)
static

Clear and reset old data in tensor_crop.

Definition at line 205 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_set_property()

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

Setter for tensor_crop properties.

Definition at line 285 of file gsttensor_crop.c.

Here is the caller graph for this function:

◆ gst_tensor_crop_sink_event()

static gboolean gst_tensor_crop_sink_event ( GstCollectPads *  pads,
GstCollectData *  data,
GstEvent *  event,
gpointer  user_data 
)
static

Handle event on sink pad.

Definition at line 388 of file gsttensor_crop.c.

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

◆ gst_tensor_crop_src_event()

static gboolean gst_tensor_crop_src_event ( GstPad *  pad,
GstObject *  parent,
GstEvent *  event 
)
static

Handle event on src pad.

Definition at line 368 of file gsttensor_crop.c.

Here is the caller graph for this function:

Variable Documentation

◆ info_template

GstStaticPadTemplate info_template
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("info",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_TENSORS_FLEX_CAP_DEFAULT))

Template for sink pad (crop info).

Definition at line 103 of file gsttensor_crop.c.

◆ raw_template

GstStaticPadTemplate raw_template
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("raw",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_TENSOR_CAP_DEFAULT ";"
GST_TENSORS_CAP_MAKE ("{ static, flexible }")))

Template for sink pad (raw data).

Definition at line 94 of file gsttensor_crop.c.

◆ src_template

GstStaticPadTemplate src_template
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_TENSORS_FLEX_CAP_DEFAULT))

Template for src pad.

Definition at line 111 of file gsttensor_crop.c.

GST_TENSOR_CAP_DEFAULT
#define GST_TENSOR_CAP_DEFAULT
Default static capability for other/tensor.
Definition: tensor_typedef.h:78
GST_TENSORS_FLEX_CAP_DEFAULT
#define GST_TENSORS_FLEX_CAP_DEFAULT
Caps string for the caps template of flexible tensors. This mimetype handles non-static,...
Definition: tensor_typedef.h:123
GST_TENSORS_CAP_MAKE
#define GST_TENSORS_CAP_MAKE(fmt)
Caps string for the caps template of tensor stream. format should be a string that describes the data...
Definition: tensor_typedef.h:97