Doxygen Book
gsttensor_srciio.c File Reference

GStreamer plugin to capture sensor data as tensor(s) More...

#include <gst/gstinfo.h>
#include <gst/gst.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <string.h>
#include <endian.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <nnstreamer_util.h>
#include "gsttensor_srciio.h"
Include dependency graph for gsttensor_srciio.c:

Go to the source code of this file.

Macros

#define DBG   (!self->silent)
 Macro for debug mode. More...
 
#define GST_CAT_DEFAULT   gst_tensor_src_iio_debug
 
#define PROCESS_SCANNED_DATA(DTYPE_UNSIGNED, DTYPE_SIGNED)
 Macro to generate data processing functions for various types. More...
 
#define DEFAULT_PROP_BASE_DIRECTORY   "/sys/bus/iio/devices"
 IIO system paths. More...
 
#define DEFAULT_PROP_DEV_DIRECTORY   "/dev"
 
#define CHANNELS_ENABLED_AUTO_CHAR   "auto"
 iio device channel enabled mode More...
 
#define CHANNELS_ENABLED_ALL_CHAR   "all"
 
#define DEFAULT_OPERATING_CHANNELS_ENABLED   CHANNELS_ENABLED_AUTO_CHAR
 
#define MODE_ONE_SHOT   "one-shot"
 tensor_src_iio device modes More...
 
#define MODE_CONTINUOUS   "continuous"
 
#define DEFAULT_OPERATING_MODE   MODE_CONTINUOUS
 
#define DEFAULT_PROP_SILENT   TRUE
 Flag to print minimized log. More...
 
#define DEFAULT_PROP_STRING   NULL
 Flag for general default value of string. More...
 
#define MIN_BUFFER_CAPACITY   1
 Minimum and maximum buffer length for iio. More...
 
#define MAX_BUFFER_CAPACITY   G_MAXUINT
 
#define DEFAULT_BUFFER_CAPACITY   1
 
#define MIN_FREQUENCY   0
 Minimum and maximum operating frequency for the device Frequency 0 chooses the first available frequency supported by device. More...
 
#define MAX_FREQUENCY   G_MAXULONG
 
#define DEFAULT_FREQUENCY   0
 
#define MIN_POLL_TIMEOUT   -1
 Minimum and maximum polling timeout for the buffered reading. More...
 
#define MAX_POLL_TIMEOUT   G_MAXINT
 
#define DEFAULT_POLL_TIMEOUT   10000
 
#define DEFAULT_MERGE_CHANNELS   TRUE
 Default behavior on merging channels. More...
 
#define DEFAULT_PROP_DEVICE_NUM   -1
 default trigger and device numbers More...
 
#define DEFAULT_PROP_TRIGGER_NUM   -1
 
#define BLOCKSIZE   1
 
#define DEVICE   "device"
 IIO devices/triggers. More...
 
#define BUFFER   "buffer"
 
#define TRIGGER   "trigger"
 
#define CHANNELS   "scan_elements"
 
#define IIO   "iio:"
 
#define TIMESTAMP   "timestamp"
 
#define DEVICE_PREFIX   IIO DEVICE
 
#define TRIGGER_PREFIX   IIO TRIGGER
 
#define CURRENT_TRIGGER   "current_trigger"
 
#define EN_SUFFIX   "_en"
 IIO device channels. More...
 
#define INDEX_SUFFIX   "_index"
 
#define TYPE_SUFFIX   "_type"
 
#define SCALE_SUFFIX   "_scale"
 
#define OFFSET_SUFFIX   "_offset"
 
#define NAME_FILE   "name"
 filenames for IIO devices/triggers characteristics More...
 
#define AVAIL_FREQUENCY_FILE   "sampling_frequency_available"
 
#define SAMPLING_FREQUENCY   "sampling_frequency"
 
#define gst_tensor_src_iio_parent_class   parent_class
 

Enumerations

enum  {
  PROP_0, PROP_MODE, PROP_SILENT, PROP_BASE_DIRECTORY,
  PROP_DEV_DIRECTORY, PROP_DEVICE, PROP_DEVICE_NUM, PROP_TRIGGER,
  PROP_TRIGGER_NUM, PROP_CHANNELS, PROP_BUFFER_CAPACITY, PROP_FREQUENCY,
  PROP_MERGE_CHANNELS, PROP_POLL_TIMEOUT
}
 tensor_src_iio properties. More...
 

Functions

 GST_DEBUG_CATEGORY_STATIC (gst_tensor_src_iio_debug)
 
 g_assert (sizeof(DTYPE_UNSIGNED)==sizeof(DTYPE_SIGNED))
 
value_unsignedif (prop->is_signed)
 
 PROCESS_SCANNED_DATA (guint8, gint8)
 
 PROCESS_SCANNED_DATA (guint16, gint16)
 
 PROCESS_SCANNED_DATA (guint32, gint32)
 
 PROCESS_SCANNED_DATA (guint64, gint64)
 
static void gst_tensor_src_iio_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 set tensor_src_iio properties More...
 
static void gst_tensor_src_iio_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 get tensor_src_iio properties More...
 
static void gst_tensor_src_iio_finalize (GObject *object)
 finalize the instance More...
 
static gboolean gst_tensor_src_iio_start (GstBaseSrc *src)
 start function, called when state changed null to ready. load the device and init the device resources More...
 
static gboolean gst_tensor_src_iio_stop (GstBaseSrc *src)
 stop function, called when state changed ready to null. More...
 
static GstStateChangeReturn gst_tensor_src_iio_change_state (GstElement *element, GstStateChange transition)
 Perform state change. More...
 
static gboolean gst_tensor_src_iio_event (GstBaseSrc *src, GstEvent *event)
 handle events More...
 
static gboolean gst_tensor_src_iio_set_caps (GstBaseSrc *src, GstCaps *caps)
 set new caps More...
 
static GstCaps * gst_tensor_src_iio_get_caps (GstBaseSrc *src, GstCaps *filter)
 get caps of subclass More...
 
static GstCaps * gst_tensor_src_iio_fixate (GstBaseSrc *src, GstCaps *caps)
 fixate the caps when needed during negotiation More...
 
static gboolean gst_tensor_src_iio_is_seekable (GstBaseSrc *src)
 check if source supports seeking More...
 
static GstFlowReturn gst_tensor_src_iio_create (GstBaseSrc *src, guint64 offset, guint size, GstBuffer **buffer)
 create a buffer with requested size and offset More...
 
static GstFlowReturn gst_tensor_src_iio_fill (GstBaseSrc *src, guint64 offset, guint size, GstBuffer *buffer)
 fill the buffer with data More...
 
static void gst_tensor_src_iio_get_times (GstBaseSrc *basesrc, GstBuffer *buffer, GstClockTime *start, GstClockTime *end)
 returns the time for the buffers More...
 
 G_DEFINE_TYPE (GstTensorSrcIIO, gst_tensor_src_iio, GST_TYPE_BASE_SRC)
 
static void gst_tensor_src_iio_class_init (GstTensorSrcIIOClass *klass)
 initialize the tensor_src_iio class. More...
 
static void gst_tensor_src_iio_channel_properties_free (gpointer data)
 delete GstTensorSrcIIODeviceProperties structure More...
 
static void gst_tensor_src_iio_device_properties_init (GstTensorSrcIIODeviceProperties *prop)
 initialize GstTensorSrcIIODeviceProperties structure More...
 
static void gst_tensor_src_iio_init (GstTensorSrcIIO *self)
 initialize tensor_src_iio element. More...
 
static gint gst_tensor_src_merge_tensor_by_type (GstTensorInfo *info, guint size, guint dir)
 merge multiple other/tensor More...
 
static gint gst_tensor_src_iio_get_id_by_name (const gchar *dir_name, const gchar *name, const gchar *prefix)
 check if device/trigger with the given name exists More...
 
static gchar * gst_tensor_src_iio_get_name_by_id (const gchar *dir_name, const gint id, const gchar *prefix)
 check if device/trigger with the given id exists More...
 
static gboolean gst_tensor_src_iio_get_float_from_file (const gchar *dirname, const gchar *name, const gchar *suffix, gfloat *value)
 parse float value from the file More...
 
static gboolean gst_tensor_src_iio_set_channel_type (GstTensorSrcIIOChannelProperties *prop, const gchar *contents)
 get type info about the channel from the string More...
 
static gchar * gst_tensor_src_iio_get_generic_name (const gchar *channel_name)
 get generic name for channel from the string More...
 
static gint gst_tensor_channel_list_sort_cmp (gconstpointer a, gconstpointer b)
 compare channels for sort based on their indices More...
 
static void gst_tensor_channel_list_filter_enabled (gpointer data, gpointer user_data)
 compare channels for filtering if enabled More...
 
static gint gst_tensor_src_iio_get_all_channel_info (GstTensorSrcIIO *self, const gchar *dir_name)
 get info about all the channels in the device More...
 
static gint64 gst_tensor_src_iio_get_available_frequency (const gchar *base_dir, const guint64 frequency)
 return sampling frequency given the frequency input from user More...
 
static gboolean gst_tensor_write_sysfs_string (GstTensorSrcIIO *self, const gchar *file, const gchar *base_dir, const gchar *contents)
 write the string in to the file More...
 
static gboolean gst_tensor_write_sysfs_int (GstTensorSrcIIO *self, const gchar *file, const gchar *base_dir, const gint contents)
 write the int in to the file More...
 
static gboolean gst_tensor_set_all_channels (GstTensorSrcIIO *self, const gint contents)
 set value to all the channels More...
 
static guint gst_tensor_get_size_from_channels (GList *channels)
 get the size of the combined data from channels More...
 
static gboolean gst_tensor_src_iio_create_config (GstTensorSrcIIO *tensor_src_iio)
 create the structure for the caps to update the src pad caps More...
 
static gboolean gst_tensor_src_iio_setup_device_properties (GstTensorSrcIIO *self)
 setup device using name/id More...
 
static gboolean gst_tensor_src_iio_setup_trigger_properties (GstTensorSrcIIO *self)
 setup trigger using name/id More...
 
static gboolean gst_tensor_src_iio_setup_sampling_frequency (GstTensorSrcIIO *self)
 setup device sampling frequency More...
 
static gboolean gst_tensor_src_iio_setup_scan_channels (GstTensorSrcIIO *self)
 setup scan channels for the device More...
 
static gboolean gst_tensor_src_iio_setup_device_buffer (GstTensorSrcIIO *self)
 setup device using name/id More...
 
static void gst_tensor_src_restore_iio_device (GstTensorSrcIIO *self)
 restore the iio device to its original device. More...
 
static gboolean gst_tensor_src_iio_process_scanned_data (GstTensorSrcIIOChannelProperties *prop, gchar *data, gfloat *buffer_map)
 process the scanned data from IIO device More...
 

Variables

GstTensorSrcIIOChannelPropertiesprop
 DTYPE_UNSIGNED ( . More...
 
GstTensorSrcIIOChannelProperties DTYPE_UNSIGNED value_unsigned
 
 else
 
return value_float
 

Detailed Description

GStreamer plugin to capture sensor data as tensor(s)

GStreamer Tensor_Source_IIO Copyright (C) 2005 Thomas Vander Stichele thoma.nosp@m.s@ap.nosp@m.estaa.nosp@m.rt.o.nosp@m.rg Copyright (C) 2005 Ronald S. Bultje rbult.nosp@m.je@r.nosp@m.onald.nosp@m..bit.nosp@m.freak.nosp@m..net Copyright (C) 2019 Parichay Kapoor pk.ka.nosp@m.poor.nosp@m.@sams.nosp@m.ung..nosp@m.com

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

Date
27 Feb 2019
See also
http://github.com/nnstreamer/nnstreamer
Author
Parichay Kapoor pk.ka.nosp@m.poor.nosp@m.@sams.nosp@m.ung..nosp@m.com
Bug:
No known bugs except for NYI items
Todo:

support specific channels as input

handle timestamp received from device

This is the plugin to capture data from sensors and convert them to tensor format. Current implementation will support accelerators, light and gyro sensors.

Definition in file gsttensor_srciio.c.

Macro Definition Documentation

◆ AVAIL_FREQUENCY_FILE

#define AVAIL_FREQUENCY_FILE   "sampling_frequency_available"

Definition at line 244 of file gsttensor_srciio.c.

◆ BLOCKSIZE

#define BLOCKSIZE   1

blocksize for buffer

Definition at line 216 of file gsttensor_srciio.c.

◆ BUFFER

#define BUFFER   "buffer"

Definition at line 222 of file gsttensor_srciio.c.

◆ CHANNELS

#define CHANNELS   "scan_elements"

Definition at line 224 of file gsttensor_srciio.c.

◆ CHANNELS_ENABLED_ALL_CHAR

#define CHANNELS_ENABLED_ALL_CHAR   "all"

Definition at line 160 of file gsttensor_srciio.c.

◆ CHANNELS_ENABLED_AUTO_CHAR

#define CHANNELS_ENABLED_AUTO_CHAR   "auto"

iio device channel enabled mode

Definition at line 159 of file gsttensor_srciio.c.

◆ CURRENT_TRIGGER

#define CURRENT_TRIGGER   "current_trigger"

Definition at line 229 of file gsttensor_srciio.c.

◆ DBG

#define DBG   (!self->silent)

Macro for debug mode.

SECTION:element-tensor_src_iio

#tensor_src_iio extends #gstbasesrc source element to handle Linux Industrial I/O sensors as input. IIO sources are only supported in buffered mode. Source elements only support push mode scheduling as a live source.

#tensor_src_iio supports configuring the device as well as the trigger via properties. Buffer capacity, frequency and scan channels to be read can be configured before PLAYING the stream. The configuration is supported only in states <= READY. Setting the state back to NULL restores the original configuration of the IIO device. The source can be configured to work with trigger for the source or read the data from the device at regular time intervals. Device name/number is the only necessary configuration needed to run the element (other configuration parameters is optional).

The output caps is either of other/tensor or other/tensors.

Data from various channels can be merged to form 1 other/tensor. Final caps of the src pad is of the following format: <itemizedlist> <listitem>

Dimension 0 : Channel number</listitem>

<listitem>

Dimension 1 : buffer capacity</listitem>

</itemizedlist> Other dimensions are not utilized. The data in the dimension 0 is sorted on the basis of the indexing of the channels provided by the IIO device.

The enabling of buffer for data capture is performed when transitioning from PAUSED to PLAYING state. This leads to automated synchronization handled by gstreamer. Buffer duration and timestamps set by #gstbasesrc remain in sync with linux IIO timestamps.

<refsect2> <title>Example launch line</title> |[ gst-launch -v -m tensor_src_iio device-number=0 ! fakesink ]| </refsect2>

Definition at line 97 of file gsttensor_srciio.c.

◆ DEFAULT_BUFFER_CAPACITY

#define DEFAULT_BUFFER_CAPACITY   1

Definition at line 185 of file gsttensor_srciio.c.

◆ DEFAULT_FREQUENCY

#define DEFAULT_FREQUENCY   0

Definition at line 193 of file gsttensor_srciio.c.

◆ DEFAULT_MERGE_CHANNELS

#define DEFAULT_MERGE_CHANNELS   TRUE

Default behavior on merging channels.

Definition at line 205 of file gsttensor_srciio.c.

◆ DEFAULT_OPERATING_CHANNELS_ENABLED

#define DEFAULT_OPERATING_CHANNELS_ENABLED   CHANNELS_ENABLED_AUTO_CHAR

Definition at line 161 of file gsttensor_srciio.c.

◆ DEFAULT_OPERATING_MODE

#define DEFAULT_OPERATING_MODE   MODE_CONTINUOUS

Definition at line 168 of file gsttensor_srciio.c.

◆ DEFAULT_POLL_TIMEOUT

#define DEFAULT_POLL_TIMEOUT   10000

Definition at line 200 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_BASE_DIRECTORY

#define DEFAULT_PROP_BASE_DIRECTORY   "/sys/bus/iio/devices"

IIO system paths.

Definition at line 153 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_DEV_DIRECTORY

#define DEFAULT_PROP_DEV_DIRECTORY   "/dev"

Definition at line 154 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_DEVICE_NUM

#define DEFAULT_PROP_DEVICE_NUM   -1

default trigger and device numbers

Definition at line 210 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_SILENT

#define DEFAULT_PROP_SILENT   TRUE

Flag to print minimized log.

Definition at line 173 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_STRING

#define DEFAULT_PROP_STRING   NULL

Flag for general default value of string.

Definition at line 178 of file gsttensor_srciio.c.

◆ DEFAULT_PROP_TRIGGER_NUM

#define DEFAULT_PROP_TRIGGER_NUM   -1

Definition at line 211 of file gsttensor_srciio.c.

◆ DEVICE

#define DEVICE   "device"

IIO devices/triggers.

Definition at line 221 of file gsttensor_srciio.c.

◆ DEVICE_PREFIX

#define DEVICE_PREFIX   IIO DEVICE

Definition at line 227 of file gsttensor_srciio.c.

◆ EN_SUFFIX

#define EN_SUFFIX   "_en"

IIO device channels.

Definition at line 234 of file gsttensor_srciio.c.

◆ GST_CAT_DEFAULT

#define GST_CAT_DEFAULT   gst_tensor_src_iio_debug

Definition at line 101 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_parent_class

#define gst_tensor_src_iio_parent_class   parent_class

internal functions

Definition at line 280 of file gsttensor_srciio.c.

◆ IIO

#define IIO   "iio:"

Definition at line 225 of file gsttensor_srciio.c.

◆ INDEX_SUFFIX

#define INDEX_SUFFIX   "_index"

Definition at line 235 of file gsttensor_srciio.c.

◆ MAX_BUFFER_CAPACITY

#define MAX_BUFFER_CAPACITY   G_MAXUINT

Definition at line 184 of file gsttensor_srciio.c.

◆ MAX_FREQUENCY

#define MAX_FREQUENCY   G_MAXULONG

Definition at line 192 of file gsttensor_srciio.c.

◆ MAX_POLL_TIMEOUT

#define MAX_POLL_TIMEOUT   G_MAXINT

Definition at line 199 of file gsttensor_srciio.c.

◆ MIN_BUFFER_CAPACITY

#define MIN_BUFFER_CAPACITY   1

Minimum and maximum buffer length for iio.

Definition at line 183 of file gsttensor_srciio.c.

◆ MIN_FREQUENCY

#define MIN_FREQUENCY   0

Minimum and maximum operating frequency for the device Frequency 0 chooses the first available frequency supported by device.

Definition at line 191 of file gsttensor_srciio.c.

◆ MIN_POLL_TIMEOUT

#define MIN_POLL_TIMEOUT   -1

Minimum and maximum polling timeout for the buffered reading.

Definition at line 198 of file gsttensor_srciio.c.

◆ MODE_CONTINUOUS

#define MODE_CONTINUOUS   "continuous"

Definition at line 167 of file gsttensor_srciio.c.

◆ MODE_ONE_SHOT

#define MODE_ONE_SHOT   "one-shot"

tensor_src_iio device modes

Definition at line 166 of file gsttensor_srciio.c.

◆ NAME_FILE

#define NAME_FILE   "name"

filenames for IIO devices/triggers characteristics

Definition at line 243 of file gsttensor_srciio.c.

◆ OFFSET_SUFFIX

#define OFFSET_SUFFIX   "_offset"

Definition at line 238 of file gsttensor_srciio.c.

◆ PROCESS_SCANNED_DATA

#define PROCESS_SCANNED_DATA (   DTYPE_UNSIGNED,
  DTYPE_SIGNED 
)
Value:
\
static gfloat \
gst_tensor_src_iio_process_scanned_data_from_

Macro to generate data processing functions for various types.

Definition at line 106 of file gsttensor_srciio.c.

◆ SAMPLING_FREQUENCY

#define SAMPLING_FREQUENCY   "sampling_frequency"

Definition at line 245 of file gsttensor_srciio.c.

◆ SCALE_SUFFIX

#define SCALE_SUFFIX   "_scale"

Definition at line 237 of file gsttensor_srciio.c.

◆ TIMESTAMP

#define TIMESTAMP   "timestamp"

Definition at line 226 of file gsttensor_srciio.c.

◆ TRIGGER

#define TRIGGER   "trigger"

Definition at line 223 of file gsttensor_srciio.c.

◆ TRIGGER_PREFIX

#define TRIGGER_PREFIX   IIO TRIGGER

Definition at line 228 of file gsttensor_srciio.c.

◆ TYPE_SUFFIX

#define TYPE_SUFFIX   "_type"

Definition at line 236 of file gsttensor_srciio.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

tensor_src_iio properties.

Enumerator
PROP_0 
PROP_MODE 
PROP_SILENT 
PROP_BASE_DIRECTORY 
PROP_DEV_DIRECTORY 
PROP_DEVICE 
PROP_DEVICE_NUM 
PROP_TRIGGER 
PROP_TRIGGER_NUM 
PROP_CHANNELS 
PROP_BUFFER_CAPACITY 
PROP_FREQUENCY 
PROP_MERGE_CHANNELS 
PROP_POLL_TIMEOUT 

Definition at line 132 of file gsttensor_srciio.c.

Function Documentation

◆ g_assert()

g_assert ( sizeof(DTYPE_UNSIGNED)  = =sizeof(DTYPE_SIGNED))
Here is the caller graph for this function:

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( GstTensorSrcIIO  ,
gst_tensor_src_iio  ,
GST_TYPE_BASE_SRC   
)

◆ GST_DEBUG_CATEGORY_STATIC()

GST_DEBUG_CATEGORY_STATIC ( gst_tensor_src_iio_debug  )

◆ gst_tensor_channel_list_filter_enabled()

static void gst_tensor_channel_list_filter_enabled ( gpointer  data,
gpointer  user_data 
)
static

compare channels for filtering if enabled

Parameters
[in]dataPointer of the data of the element
[in/out]user_data Pointer to the address of the list to be filtered

Definition at line 836 of file gsttensor_srciio.c.

◆ gst_tensor_channel_list_sort_cmp()

static gint gst_tensor_channel_list_sort_cmp ( gconstpointer  a,
gconstpointer  b 
)
static

compare channels for sort based on their indices

Parameters
[in]aFirst param to be compared
[in]bSecond param to be compared
Returns
negative if ab

Definition at line 822 of file gsttensor_srciio.c.

◆ gst_tensor_get_size_from_channels()

static guint gst_tensor_get_size_from_channels ( GList *  channels)
static

get the size of the combined data from channels

Parameters
[in]channelsList of all the channels
Returns
Size of one scan of data combined from all the channels

Also evaluates the location of each channel in the buffer

Definition at line 1499 of file gsttensor_srciio.c.

◆ gst_tensor_set_all_channels()

static gboolean gst_tensor_set_all_channels ( GstTensorSrcIIO self,
const gint  contents 
)
static

set value to all the channels

Parameters
[in]selfTensor src IIO object
[in]contentsData to be written to the file
Returns
True if write was successful, false if failure on any channel

Definition at line 1469 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_change_state()

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

Perform state change.

enable the buffer for the data to be captured

disable the buffer

Definition at line 2228 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_iio_channel_properties_free()

static void gst_tensor_src_iio_channel_properties_free ( gpointer  data)
static

delete GstTensorSrcIIODeviceProperties structure

Parameters
[in]dataData pointer to be freed

Definition at line 411 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_class_init()

static void gst_tensor_src_iio_class_init ( GstTensorSrcIIOClass klass)
static

initialize the tensor_src_iio class.

GObject methods

pad template

GstBaseSrcIIO methods

Definition at line 287 of file gsttensor_srciio.c.

Here is the call graph for this function:

◆ gst_tensor_src_iio_create()

static GstFlowReturn gst_tensor_src_iio_create ( GstBaseSrc *  src,
guint64  offset,
guint  size,
GstBuffer **  buffer 
)
static

create a buffer with requested size and offset

Note
offset, size ignored as the tensor src iio does not support pull mode

all the data, if unermged should be of the same size

Definition at line 2325 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_create_config()

static gboolean gst_tensor_src_iio_create_config ( GstTensorSrcIIO tensor_src_iio)
static

create the structure for the caps to update the src pad caps

Parameters
[in/out]structure Caps structure which will filled
Returns
True if structure is created and filled, False for any error

create a bigger array, insert info in it and then merge tensors with same type+size

compile tensor info data

merge info about the tensors with same type

verify the merging of the array

tensors config data

buffer_capacity number of data samples are captured at once, packed together and sent downstream

Definition at line 1527 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_device_properties_init()

static void gst_tensor_src_iio_device_properties_init ( GstTensorSrcIIODeviceProperties prop)
static

initialize GstTensorSrcIIODeviceProperties structure

Parameters
[in]dataDevice properties pointer to be initialized

Definition at line 427 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_event()

static gboolean gst_tensor_src_iio_event ( GstBaseSrc *  src,
GstEvent *  event 
)
static

handle events

No events to be handled yet

Definition at line 2132 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_fill()

static GstFlowReturn gst_tensor_src_iio_fill ( GstBaseSrc *  src,
guint64  offset,
guint  size,
GstBuffer *  buffer 
)
static

fill the buffer with data

Note
ignore offset,size as there is pull mode
buffer timestamp is already handled by gstreamer with gst clock

Only supporting tensors made of 1 tensor for now

get writable buffer

memory to data from file

wait for the data to arrive

sleep for a device tick

using read for non-blocking access

parse the read data

current assumption is that the all data is float and merged to form a 1 dimension data. 2nd dimension comes from buffer capacity.

for other/tensor, only 1 map exist as there is only 1 mem

for other/tensors, multiple maps exist as there are multiple mem

Definition at line 2462 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_finalize()

static void gst_tensor_src_iio_finalize ( GObject *  object)
static

finalize the instance

Definition at line 1358 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_iio_fixate()

static GstCaps * gst_tensor_src_iio_fixate ( GstBaseSrc *  src,
GstCaps *  caps 
)
static

fixate the caps when needed during negotiation

Caps are fixated based on the device source in _start().

Definition at line 2186 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_iio_get_all_channel_info()

static gint gst_tensor_src_iio_get_all_channel_info ( GstTensorSrcIIO self,
const gchar *  dir_name 
)
static

get info about all the channels in the device

Parameters
[in/out]self Tensor src IIO object
[in]dir_nameDirectory name with all the scan elements for device
Returns
>=0 number of enabled channels -1 if any error when scanning channels

check for enable

not enabling and handling buffer timestamps for now

set the name and base_dir

find and set the current state

find and set the index

find and set the type information

if specific type info unavailable, use generic type info

find and setup offset info

find and setup scale info

sort the list with the order of the indices

Definition at line 860 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_available_frequency()

static gint64 gst_tensor_src_iio_get_available_frequency ( const gchar *  base_dir,
const guint64  frequency 
)
static

return sampling frequency given the frequency input from user

Parameters
[in]base_dirDevice base directory (containing sampling freq file)
[in]frequencyFrequency specified by user (else 0)
Returns
>0 if OK, represents sampling frequency to be set 0 if sampling frequency file does not exist, dont change anything -1 if any error occurs

get frequency list supported by the device

if the frequency is set 0, set the first available frequency else verify the frequency received from user is supported by the device

Definition at line 1036 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_caps()

static GstCaps * gst_tensor_src_iio_get_caps ( GstBaseSrc *  src,
GstCaps *  filter 
)
static

get caps of subclass

Note
basesrc _get_caps returns the caps from the pad_template however, we set the caps manually and needs to returned here

Definition at line 2160 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_get_float_from_file()

static gboolean gst_tensor_src_iio_get_float_from_file ( const gchar *  dirname,
const gchar *  name,
const gchar *  suffix,
gfloat *  value 
)
static

parse float value from the file

Parameters
[in]dirnameDirectory containing the file
[in]nameFilename of the file
[in]suffixSuffix to be attached to the filename
[in/out]value Output value returned via value
Returns
FALSE on errors, else TRUE

Definition at line 677 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_generic_name()

static gchar* gst_tensor_src_iio_get_generic_name ( const gchar *  channel_name)
static

get generic name for channel from the string

Parameters
[in]channel_nameName of the channel with its id embedded in it
Returns
Ptr to the generic name of the channel, caller should free the returned string

Definition at line 799 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_id_by_name()

static gint gst_tensor_src_iio_get_id_by_name ( const gchar *  dir_name,
const gchar *  name,
const gchar *  prefix 
)
static

check if device/trigger with the given name exists

Parameters
[in]dir_nameDirectory containing all the devices
[in]nameName of the device to be found
[in]prefixPrefix to match with the filename of the device
Returns
>=0 if OK, represents device/trigger number -1 if returned with error

check for prefix and the next digit should be a number

Definition at line 576 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_name_by_id()

static gchar* gst_tensor_src_iio_get_name_by_id ( const gchar *  dir_name,
const gint  id,
const gchar *  prefix 
)
static

check if device/trigger with the given id exists

Parameters
[in]dir_nameDirectory containing all the devices
[in]idID of the device to be found
[in]prefixPrefix to match with the filename of the device
Returns
name on success (owned by caller), else NULL

Definition at line 640 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_get_property()

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

get tensor_src_iio properties

interface of frequency is kept long for outside but uint64 inside

Definition at line 1264 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_iio_get_times()

static void gst_tensor_src_iio_get_times ( GstBaseSrc *  basesrc,
GstBuffer *  buffer,
GstClockTime *  start,
GstClockTime *  end 
)
static

returns the time for the buffers

can't sync using DTS, use PTS

Definition at line 2298 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_init()

static void gst_tensor_src_iio_init ( GstTensorSrcIIO self)
static

initialize tensor_src_iio element.

init properties

format of the source since IIO device as a source is live and operates at a fixed frequency, GST_FORMAT_TIME is used

set the source to be live

set the timestamps on each buffer

set async is necessary to make state change async sync state changes does not need calling _start_complete() from _start()

Definition at line 439 of file gsttensor_srciio.c.

Here is the call graph for this function:

◆ gst_tensor_src_iio_is_seekable()

static gboolean gst_tensor_src_iio_is_seekable ( GstBaseSrc *  src)
static

check if source supports seeking

iio sensors are live source without any support for seeking

Definition at line 2287 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_process_scanned_data()

static gboolean gst_tensor_src_iio_process_scanned_data ( GstTensorSrcIIOChannelProperties prop,
gchar *  data,
gfloat *  buffer_map 
)
static

process the scanned data from IIO device

Parameters
[in]propProperties of one of the enabled channels
[in]dataData read from the IIO device
[in/out]buffer_map Gst buffer map to write data to
Returns
FALSE if fail, else TRUE

assumes each data starting point is byte aligned

right shift the extra storage bits

right shift the extra storage bits for big endian

mask out the extra storage bits for little endian

follow through

right shift the extra storage bits for big endian

mask out the extra storage bits for little endian

follow through

follow through

follow through

right shift the extra storage bits for big endian

mask out the extra storage bits for little endian

Definition at line 2376 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_set_caps()

static gboolean gst_tensor_src_iio_set_caps ( GstBaseSrc *  src,
GstCaps *  caps 
)
static

set new caps

Definition at line 2142 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_set_channel_type()

static gboolean gst_tensor_src_iio_set_channel_type ( GstTensorSrcIIOChannelProperties prop,
const gchar *  contents 
)
static

get type info about the channel from the string

Parameters
[in/out]prop Channel properties where type info will be set
[in]contentsContains type unparsed information to be set
Returns
True if info was successfully set, false is info is not be parsed correctly @detail The format for the contents is expected to be of format

check endian

verify static parts of the contents

check sign

used bits

verify static parts of the contents

storage bits

verify static parts of the contents

Definition at line 718 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_set_property()

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

set tensor_src_iio properties

GObject method implementation

No support for setting properties in PAUSED/PLAYING state as it needs to reset the device. To change the properties, user should stop the pipeline and set element state to READY/NULL and then change the properties

using direct as we only need to store keys and keys form a unique set

this means val is duplicated. just skip it, then.

Definition at line 1098 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_iio_setup_device_buffer()

static gboolean gst_tensor_src_iio_setup_device_buffer ( GstTensorSrcIIO self)
static

setup device using name/id

Parameters
[in/out]self Tensor src iio object
Returns
TRUE on success, FALSE on failure

once all these are set, set the buffer related thingies

open the buffer to read and ready the file descriptor

Definition at line 1913 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_setup_device_properties()

static gboolean gst_tensor_src_iio_setup_device_properties ( GstTensorSrcIIO self)
static

setup device using name/id

Parameters
[in/out]self Tensor src iio object
Returns
TRUE on success, FALSE on failure

Find the device

Definition at line 1623 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_setup_sampling_frequency()

static gboolean gst_tensor_src_iio_setup_sampling_frequency ( GstTensorSrcIIO self)
static

setup device sampling frequency

Parameters
[in/out]self Tensor src iio object
Returns
TRUE on success, FALSE on failure

check if sampling frequency file exists

reset the sampling frequency set by the user if any, as it cant be set

store the default frequency

verify the frequency given by the user if any from the list of available sampling frequencies

if sampling frequency file does not exist, no error

if sampling frequency file does not exist, sampling frequency is first value from the list of available sampling frequencies. So, we can ignore setting it

interface of frequency is kept long for outside but uint64 inside

Definition at line 1735 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_setup_scan_channels()

static gboolean gst_tensor_src_iio_setup_scan_channels ( GstTensorSrcIIO self)
static

setup scan channels for the device

Parameters
[in/out]self Tensor src iio object
Returns
TRUE on success, FALSE on failure

get all the channels that exist and then set enable on them

if enabling all channels failed, disable all channels

enable the custom channels and disable the rest

filter out disabled channels

set fixed caps for the src pad

create tensor_config

Definition at line 1822 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_setup_trigger_properties()

static gboolean gst_tensor_src_iio_setup_trigger_properties ( GstTensorSrcIIO self)
static

setup trigger using name/id

Parameters
[in/out]self Tensor src iio object
Returns
TRUE on success, FALSE on failure

register the trigger

verify if trigger is supported by our device

find if the provided trigger exists

get the default trigger, if any

set the trigger

Definition at line 1659 of file gsttensor_srciio.c.

◆ gst_tensor_src_iio_start()

static gboolean gst_tensor_src_iio_start ( GstBaseSrc *  src)
static

start function, called when state changed null to ready. load the device and init the device resources

GstBaseSrc method implementation

load and init resources

no support one shot mode for now

bytes every buffer will be fixed

complete the start of the base src

complete the start of the base src

Definition at line 1977 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_src_iio_stop()

static gboolean gst_tensor_src_iio_stop ( GstBaseSrc *  src)
static

stop function, called when state changed ready to null.

free resources related to the device

restore the iio device

Definition at line 2097 of file gsttensor_srciio.c.

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

◆ gst_tensor_src_merge_tensor_by_type()

static gint gst_tensor_src_merge_tensor_by_type ( GstTensorInfo info,
guint  size,
guint  dir 
)
static

merge multiple other/tensor

Note
they should have matching type and shape to form 1 other/tensors
extra dimension should be available for other/tensors
order of merge is stable
merging into 1 tensor only supported using innermost dimension.
Parameters
[in/out]info Tensor info to be merged
[in]sizeInfo array size
[in]dirInnermost/outermost/innermost-outer (0/1/2) available dimension
Returns
>=0 number of valid entries in the info after merge -1 failed due to missing extra dimension/mismatch shape/type

base error control check

verify extra dimension (innermost to outermost)

verify that all the types and shapes match

return original if cant be merged and size within limits

If there are multiple available dimensions to merge along, we use dir to choose which the dimension to merge. If there is just 1 dimension, dir variable has no effect

No outer dimension available to merge

Now merge into 1 tensor using the selected dimension

Definition at line 491 of file gsttensor_srciio.c.

◆ gst_tensor_src_restore_iio_device()

static void gst_tensor_src_restore_iio_device ( GstTensorSrcIIO self)
static

restore the iio device to its original device.

reset enabled channels

reset sampling_frequency

converting to long as setting interface to device

reset buffer_capacity

reset current trigger

Definition at line 2049 of file gsttensor_srciio.c.

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

◆ gst_tensor_write_sysfs_int()

static gboolean gst_tensor_write_sysfs_int ( GstTensorSrcIIO self,
const gchar *  file,
const gchar *  base_dir,
const gint  contents 
)
static

write the int in to the file

Parameters
[in]selfTensor src IIO object
[in]fileDestination file for the data
[in]base_dirDirectory containing the file
[in]contentsData to be written to the file
Returns
True if write was successful, false on failure

Definition at line 1449 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ gst_tensor_write_sysfs_string()

static gboolean gst_tensor_write_sysfs_string ( GstTensorSrcIIO self,
const gchar *  file,
const gchar *  base_dir,
const gchar *  contents 
)
static

write the string in to the file

Parameters
[in]selfTensor src IIO object
[in]fileDestination file for the data
[in]base_dirDirectory containing the file
[in]contentsData to be written to the file
Returns
True if write was successful, false on failure

Definition at line 1384 of file gsttensor_srciio.c.

Here is the caller graph for this function:

◆ if()

value_unsigned& if ( prop->  is_signed)

Definition at line 117 of file gsttensor_srciio.c.

◆ PROCESS_SCANNED_DATA() [1/4]

PROCESS_SCANNED_DATA ( guint16  ,
gint16   
)

◆ PROCESS_SCANNED_DATA() [2/4]

PROCESS_SCANNED_DATA ( guint32  ,
gint32   
)

◆ PROCESS_SCANNED_DATA() [3/4]

PROCESS_SCANNED_DATA ( guint64  ,
gint64   
)

◆ PROCESS_SCANNED_DATA() [4/4]

PROCESS_SCANNED_DATA ( guint8  ,
gint8   
)

Define data processing functions for various types

Variable Documentation

◆ else

else
Initial value:

Definition at line 123 of file gsttensor_srciio.c.

◆ prop

DTYPE_UNSIGNED ( .

Definition at line 110 of file gsttensor_srciio.c.

◆ value_float

return value_float

Definition at line 126 of file gsttensor_srciio.c.

◆ value_unsigned

value_unsigned
Initial value:
{
gfloat value_float

Definition at line 110 of file gsttensor_srciio.c.

_GstTensorSrcIIOChannelProperties::scale
gfloat scale
Definition: gsttensor_srciio.h:96
prop
GstTensorSrcIIOChannelProperties * prop
DTYPE_UNSIGNED ( .
Definition: gsttensor_srciio.c:110
value_unsigned
GstTensorSrcIIOChannelProperties DTYPE_UNSIGNED value_unsigned
Definition: gsttensor_srciio.c:110
value_float
return value_float
Definition: gsttensor_srciio.c:126
_GstTensorSrcIIOChannelProperties::offset
gfloat offset
Definition: gsttensor_srciio.h:95