Doxygen Book
gsttensor_rate.c File Reference

GStreamer plugin to adjust tensor rate. More...

#include <nnstreamer_log.h>
#include <nnstreamer_util.h>
#include "gsttensor_rate.h"
Include dependency graph for gsttensor_rate.c:

Go to the source code of this file.

Macros

#define DBG   (!self->silent)
 Macro for debug mode. More...
 
#define ABSDIFF(a, b)   (((a) > (b)) ? (a) - (b) : (b) - (a))
 
#define GST_CAT_DEFAULT   gst_tensor_rate_debug
 
#define CAPS_STRING   GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT
 
#define GST_TENSOR_RATE_SCALED_TIME(self, count)
 
#define DEFAULT_SILENT   TRUE
 default parameters More...
 
#define DEFAULT_THROTTLE   TRUE
 
#define gst_tensor_rate_parent_class   parent_class
 
#define THROTTLE_DELAY_RATIO   (0.999)
 
#define MAGIC_LIMIT   25
 

Enumerations

enum  {
  PROP_0, PROP_IN, PROP_OUT, PROP_DUP,
  PROP_DROP, PROP_SILENT, PROP_THROTTLE, PROP_FRAMERATE
}
 tensor_rate properties More...
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gst_tensor_rate_debug)
 
 G_DEFINE_TYPE (GstTensorRate, gst_tensor_rate, GST_TYPE_BASE_TRANSFORM)
 
static void gst_tensor_rate_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 Setter for tensor_rate properties. More...
 
static void gst_tensor_rate_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 Getter for tensor_rate properties. More...
 
static void gst_tensor_rate_finalize (GObject *object)
 Function to finalize instance. (GST Standard) More...
 
static GstFlowReturn gst_tensor_rate_transform_ip (GstBaseTransform *trans, GstBuffer *buffer)
 in-place transform More...
 
static GstCaps * gst_tensor_rate_transform_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *filter)
 configure tensor-srcpad cap from "proposed" cap. (GST Standard) More...
 
static GstCaps * gst_tensor_rate_fixate_caps (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, GstCaps *othercaps)
 fixate caps. required vmethod of GstBaseTransform. More...
 
static gboolean gst_tensor_rate_set_caps (GstBaseTransform *trans, GstCaps *in_caps, GstCaps *out_caps)
 set caps. required vmethod of GstBaseTransform. More...
 
static void gst_tensor_rate_swap_prev (GstTensorRate *self, GstBuffer *buffer, gint64 time)
 swap a previous buffer More...
 
static GstFlowReturn gst_tensor_rate_flush_prev (GstTensorRate *self, gboolean duplicate, GstClockTime next_intime)
 flush the oldest buffer More...
 
static void gst_tensor_rate_notify_drop (GstTensorRate *self)
 notify a frame drop event More...
 
static void gst_tensor_rate_notify_duplicate (GstTensorRate *self)
 notify a frame duplicate event More...
 
static gboolean gst_tensor_rate_start (GstBaseTransform *trans)
 Called when the element starts processing. optional vmethod of BaseTransform. More...
 
static gboolean gst_tensor_rate_stop (GstBaseTransform *trans)
 Called when the element stops processing. optional vmethod of BaseTransform. More...
 
static gboolean gst_tensor_rate_sink_event (GstBaseTransform *trans, GstEvent *event)
 Event handler for sink pad of tensor rate. More...
 
static void gst_tensor_rate_install_properties (GObjectClass *object_class)
 Installs all the properties for tensor_rate. More...
 
static void gst_tensor_rate_class_init (GstTensorRateClass *klass)
 initialize the tensor_rate's class (GST Standard) More...
 
static GstFlowReturn gst_tensor_rate_push_buffer (GstTensorRate *self, GstBuffer *outbuf, gboolean duplicate, GstClockTime next_intime)
 push the buffer to src pad More...
 
static void gst_tensor_rate_reset (GstTensorRate *self)
 reset variables of the element (GST Standard) More...
 
static void gst_tensor_rate_init (GstTensorRate *self)
 initialize the new element (GST Standard) More...
 
static void gst_tensor_rate_send_qos_throttle (GstTensorRate *self, GstClockTime timestamp)
 send throttling qos event to upstream elements More...
 

Variables

static GstStaticPadTemplate sink_factory
 The capabilities of the inputs. More...
 
static GstStaticPadTemplate src_factory
 The capabilities of the outputs. More...
 
static GParamSpec * pspec_drop = NULL
 
static GParamSpec * pspec_duplicate = NULL
 

Detailed Description

GStreamer plugin to adjust tensor rate.

GStreamer/NNStreamer Tensor-Rate Copyright (C) 2020 Dongju Chae dongj.nosp@m.u.ch.nosp@m.ae@sa.nosp@m.msun.nosp@m.g.com

Date
24 Sep 2020
See also
https://github.com/nnstreamer/nnstreamer
Author
Dongju Chae dongj.nosp@m.u.ch.nosp@m.ae@sa.nosp@m.msun.nosp@m.g.com
Bug:
No known bugs except for NYI items

Definition in file gsttensor_rate.c.

Macro Definition Documentation

◆ ABSDIFF

#define ABSDIFF (   a,
 
)    (((a) > (b)) ? (a) - (b) : (b) - (a))

Definition at line 60 of file gsttensor_rate.c.

◆ CAPS_STRING

#define CAPS_STRING   GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT

Definition at line 66 of file gsttensor_rate.c.

◆ DBG

#define DBG   (!self->silent)

Macro for debug mode.

SECTION:element-tensor_rate

This element controls a frame rate of tensor streams in the pipeline.

Basically, this element takes an incoming stream of tensor frames, and produces an adjusted stream that matches the source pad's framerate. The adjustment is performed by dropping and duplicating tensor frames. By default the element will simply negotiate the same framerate on its source and sink pad.

Also, when 'throttle' property is set, it propagates a specified frame-rate to upstream elements by sending qos events, which prevents unnecessary data from upstream elements.

<refsect2> <title>Example launch line with tensor rate</title> gst-launch-1.0 videotestsrc ! video/x-raw,width=640,height=480,framerate=15/1 ! tensor_converter ! tensor_rate framerate=10/1 throttle=true ! tensor_decoder mode=direct_video ! videoconvert ! autovideosink </refsect2>

Definition at line 56 of file gsttensor_rate.c.

◆ DEFAULT_SILENT

#define DEFAULT_SILENT   TRUE

default parameters

Definition at line 73 of file gsttensor_rate.c.

◆ DEFAULT_THROTTLE

#define DEFAULT_THROTTLE   TRUE

Definition at line 74 of file gsttensor_rate.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_tensor_rate_debug

Definition at line 64 of file gsttensor_rate.c.

◆ gst_tensor_rate_parent_class

#define gst_tensor_rate_parent_class   parent_class

Definition at line 110 of file gsttensor_rate.c.

◆ GST_TENSOR_RATE_SCALED_TIME

#define GST_TENSOR_RATE_SCALED_TIME (   self,
  count 
)
Value:
gst_util_uint64_scale (count,\
self->to_rate_denominator * GST_SECOND, self->to_rate_numerator)

Definition at line 68 of file gsttensor_rate.c.

◆ MAGIC_LIMIT

#define MAGIC_LIMIT   25

Definition at line 773 of file gsttensor_rate.c.

◆ THROTTLE_DELAY_RATIO

#define THROTTLE_DELAY_RATIO   (0.999)

Definition at line 449 of file gsttensor_rate.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

tensor_rate properties

Enumerator
PROP_0 
PROP_IN 
PROP_OUT 
PROP_DUP 
PROP_DROP 
PROP_SILENT 
PROP_THROTTLE 
PROP_FRAMERATE 

Definition at line 79 of file gsttensor_rate.c.

Function Documentation

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( GstTensorRate  ,
gst_tensor_rate  ,
GST_TYPE_BASE_TRANSFORM   
)

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_tensor_rate_debug  )

◆ gst_tensor_rate_class_init()

static void gst_tensor_rate_class_init ( GstTensorRateClass klass)
static

initialize the tensor_rate's class (GST Standard)

Definition at line 148 of file gsttensor_rate.c.

Here is the call graph for this function:

◆ gst_tensor_rate_finalize()

static void gst_tensor_rate_finalize ( GObject *  object)
static

Function to finalize instance. (GST Standard)

Definition at line 341 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_fixate_caps()

static GstCaps * gst_tensor_rate_fixate_caps ( GstBaseTransform *  trans,
GstPadDirection  direction,
GstCaps *  caps,
GstCaps *  othercaps 
)
static

fixate caps. required vmethod of GstBaseTransform.

Definition at line 680 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_flush_prev()

static GstFlowReturn gst_tensor_rate_flush_prev ( GstTensorRate self,
gboolean  duplicate,
GstClockTime  next_intime 
)
static

flush the oldest buffer

Definition at line 259 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_get_property()

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

Getter for tensor_rate properties.

Definition at line 407 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_init()

static void gst_tensor_rate_init ( GstTensorRate self)
static

initialize the new element (GST Standard)

Definition at line 317 of file gsttensor_rate.c.

Here is the call graph for this function:

◆ gst_tensor_rate_install_properties()

static void gst_tensor_rate_install_properties ( GObjectClass *  object_class)
static

Installs all the properties for tensor_rate.

Parameters
[in]gobject_classGlib object class whose properties will be set

Definition at line 953 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_notify_drop()

static void gst_tensor_rate_notify_drop ( GstTensorRate self)
static

notify a frame drop event

Parameters
[in]self"this" pointer

Definition at line 758 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_notify_duplicate()

static void gst_tensor_rate_notify_duplicate ( GstTensorRate self)
static

notify a frame duplicate event

Parameters
[in]self"this" pointer

Definition at line 768 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_push_buffer()

static GstFlowReturn gst_tensor_rate_push_buffer ( GstTensorRate self,
GstBuffer *  outbuf,
gboolean  duplicate,
GstClockTime  next_intime 
)
static

push the buffer to src pad

There must always be a valid duration on prevbuf if rate > 0, it is ensured in the transform_ip function

Definition at line 202 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_reset()

static void gst_tensor_rate_reset ( GstTensorRate self)
static

reset variables of the element (GST Standard)

Definition at line 295 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_send_qos_throttle()

static void gst_tensor_rate_send_qos_throttle ( GstTensorRate self,
GstClockTime  timestamp 
)
static

send throttling qos event to upstream elements

unused

Definition at line 455 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_set_caps()

static gboolean gst_tensor_rate_set_caps ( GstBaseTransform *  trans,
GstCaps *  incaps,
GstCaps *  outcaps 
)
static

set caps. required vmethod of GstBaseTransform.

After a setcaps, our caps may have changed. In that case, we can't use the old buffer, if there was one (it might have different dimensions)

Definition at line 705 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_set_property()

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

Setter for tensor_rate properties.

Definition at line 350 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_sink_event()

static gboolean gst_tensor_rate_sink_event ( GstBaseTransform *  trans,
GstEvent *  event 
)
static

Event handler for sink pad of tensor rate.

Parameters
[in]trans"this" pointer
[in]eventa passed event object
Returns
TRUE if there is no error.

fill up to the end of current segment, or only send out the stored buffer if there is no specific stop. regardless, prevent going loopy in strange cases

fill up to the end of current segment, or only send out the stored buffer if there is no specific stop. regardless, prevent going loopy in strange cases

Output at least one frame but if the buffer duration is valid, output enough frames to use the complete buffer duration

Definition at line 781 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_start()

static gboolean gst_tensor_rate_start ( GstBaseTransform *  trans)
static

Called when the element starts processing. optional vmethod of BaseTransform.

Parameters
[in]trans"this" pointer
Returns
TRUE if there is no error.

Definition at line 928 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_stop()

static gboolean gst_tensor_rate_stop ( GstBaseTransform *  trans)
static

Called when the element stops processing. optional vmethod of BaseTransform.

Parameters
[in]trans"this" pointer
Returns
TRUE if there is no error.

Definition at line 941 of file gsttensor_rate.c.

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

◆ gst_tensor_rate_swap_prev()

static void gst_tensor_rate_swap_prev ( GstTensorRate self,
GstBuffer *  buffer,
gint64  time 
)
static

swap a previous buffer

Definition at line 280 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_transform_caps()

static GstCaps * gst_tensor_rate_transform_caps ( GstBaseTransform *  trans,
GstPadDirection  direction,
GstCaps *  caps,
GstCaps *  filter 
)
static

configure tensor-srcpad cap from "proposed" cap. (GST Standard)

@trans ("this" pointer) @direction (why do we need this?) @caps sinkpad cap (if direction GST_PAD_SINK) @filter this element's cap (don't know specifically.)

Be careful not to fix/set caps at this stage. Negotiation not completed yet.

Definition at line 634 of file gsttensor_rate.c.

Here is the caller graph for this function:

◆ gst_tensor_rate_transform_ip()

static GstFlowReturn gst_tensor_rate_transform_ip ( GstBaseTransform *  trans,
GstBuffer *  buffer 
)
static

in-place transform

continue while the first one was the best, if they were equal avoid going into an infinite loop

Definition at line 477 of file gsttensor_rate.c.

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

Variable Documentation

◆ pspec_drop

GParamSpec* pspec_drop = NULL
static

Definition at line 107 of file gsttensor_rate.c.

◆ pspec_duplicate

GParamSpec* pspec_duplicate = NULL
static

Definition at line 108 of file gsttensor_rate.c.

◆ sink_factory

GstStaticPadTemplate sink_factory
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (CAPS_STRING))

The capabilities of the inputs.

Definition at line 94 of file gsttensor_rate.c.

◆ src_factory

GstStaticPadTemplate src_factory
static
Initial value:
= GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (CAPS_STRING))

The capabilities of the outputs.

Definition at line 102 of file gsttensor_rate.c.

CAPS_STRING
#define CAPS_STRING
Definition: gsttensor_rate.c:66