From 5b809cc950fa8cb56eca9e1b90f0de71602c15ce Mon Sep 17 00:00:00 2001 From: Eskild Helmersen Date: Fri, 15 May 2020 18:35:53 +0200 Subject: [PATCH] pylonsrc: added gst parameter inter-packet-delay for tuning when using multiple cameras and limited bandwidth situations --- sys/pylon/gstpylonsrc.c | 44 +++++++++++++++++++++++++++++++++++++++-- sys/pylon/gstpylonsrc.h | 5 +++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/sys/pylon/gstpylonsrc.c b/sys/pylon/gstpylonsrc.c index 97ea295..b39e046 100644 --- a/sys/pylon/gstpylonsrc.c +++ b/sys/pylon/gstpylonsrc.c @@ -173,6 +173,7 @@ typedef enum _GST_PYLONSRC_PROP PROP_FRAMEDROPLIMIT, PROP_GRABTIMEOUT, PROP_PACKETSIZE, + PROP_INTERPACKETDELAY, PROP_CONFIGFILE, PROP_IGNOREDEFAULTS, @@ -355,7 +356,7 @@ ascii_strdown (gchar * *str, gssize len) #define DEFAULT_PROP_FRAMEDROPLIMIT 10 #define DEFAULT_PROP_GRABTIMEOUT 1000 #define DEFAULT_PROP_PACKETSIZE 1500 - +#define DEFAULT_PROP_INTERPACKETDELAY 0 /* pad templates */ static GstStaticPadTemplate gst_pylonsrc_src_template = GST_STATIC_PAD_TEMPLATE ("src", @@ -745,6 +746,12 @@ gst_pylonsrc_class_init (GstPylonSrcClass * klass) "The packetsize parameter specifies the maximum size of a data packet transmitted via Ethernet. The value is in bytes.", 0, 16000, DEFAULT_PROP_PACKETSIZE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + g_object_class_install_property (gobject_class, PROP_INTERPACKETDELAY, + g_param_spec_int ("inter-packet-delay", + "Inter-Packet Delay between packet transmissions", + "If your network hardware can't handle the incoming packet rate, it is useful to increase the delay between packet transmissions.", + 0, 3435, DEFAULT_PROP_INTERPACKETDELAY, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); } static gboolean @@ -836,6 +843,7 @@ gst_pylonsrc_init (GstPylonSrc * src) src->frameDropLimit = DEFAULT_PROP_FRAMEDROPLIMIT; src->grabtimeout = DEFAULT_PROP_GRABTIMEOUT; src->packetSize = DEFAULT_PROP_PACKETSIZE; + src->interPacketDelay = DEFAULT_PROP_INTERPACKETDELAY; for (int i = 0; i < PROP_NUM_PROPERTIES; i++) { src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT; @@ -1163,6 +1171,9 @@ gst_pylonsrc_set_property (GObject * object, guint property_id, case PROP_PACKETSIZE: src->packetSize = g_value_get_int (value); break; + case PROP_INTERPACKETDELAY: + src->interPacketDelay = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); return; @@ -1383,6 +1394,9 @@ gst_pylonsrc_get_property (GObject * object, guint property_id, case PROP_PACKETSIZE: g_value_set_int (value, src->packetSize); break; + case PROP_INTERPACKETDELAY: + g_value_set_int (value, src->interPacketDelay); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -2888,6 +2902,30 @@ error: return FALSE; } +static gboolean +gst_pylonsrc_set_interPacketDelay (GstPylonSrc * src) +{ + GENAPIC_RESULT res; + + if (is_prop_implicit (src, PROP_INTERPACKETDELAY)) { + if (is_prop_set (src, PROP_INTERPACKETDELAY)) { + if (feature_supported (src, "GevSCPD")) { + GST_DEBUG_OBJECT (src, "Setting inter packet delay to %d", + src->interPacketDelay); + res = + PylonDeviceSetIntegerFeature (src->deviceHandle, "GevSCPD", + src->interPacketDelay); + PYLONC_CHECK_ERROR (src, res); + } + } + reset_prop (src, PROP_INTERPACKETDELAY); + } + return TRUE; + +error: + return FALSE; +} + static gboolean gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src) { @@ -3716,6 +3754,7 @@ read_all_features (GstPylonSrc * src) gst_pylonsrc_read_pixel_format (src); gst_pylonsrc_read_test_image (src); //gst_pylonsrc_read_packetsize(src); + //gst_pylonsrc_read_interPacketDelay(src) gst_pylonsrc_read_readout (src); gst_pylonsrc_read_bandwidth (src); gst_pylonsrc_read_framerate (src); @@ -3773,6 +3812,7 @@ gst_pylonsrc_set_properties (GstPylonSrc * src) gst_pylonsrc_set_pixel_format (src) && gst_pylonsrc_set_test_image (src) && gst_pylonsrc_set_packetsize (src) && + gst_pylonsrc_set_interPacketDelay (src) && gst_pylonsrc_set_readout (src) && gst_pylonsrc_set_bandwidth (src) && gst_pylonsrc_set_framerate (src) && @@ -4056,8 +4096,8 @@ pylonc_print_camera_info (GstPylonSrc * src, PYLON_DEVICE_HANDLE deviceHandle, serial[1] = '\0'; } } - if (PylonDeviceFeatureIsReadable (deviceHandle, "DeviceUserID")) { + siz = sizeof (id); res = PylonDeviceFeatureToString (deviceHandle, "DeviceUserID", id, &siz); PYLONC_CHECK_ERROR (src, res); diff --git a/sys/pylon/gstpylonsrc.h b/sys/pylon/gstpylonsrc.h index fe8a973..112a668 100644 --- a/sys/pylon/gstpylonsrc.h +++ b/sys/pylon/gstpylonsrc.h @@ -39,7 +39,7 @@ enum GST_PYLONSRC_NUM_CAPTURE_BUFFERS = 10, GST_PYLONSRC_NUM_AUTO_FEATURES = 3, GST_PYLONSRC_NUM_LIMITED_FEATURES = 2, - GST_PYLONSRC_NUM_PROPS = 70 + GST_PYLONSRC_NUM_PROPS = 71 }; typedef enum _GST_PYLONSRC_PROPERTY_STATE @@ -100,7 +100,8 @@ struct _GstPylonSrc GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES]; - gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize; + gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize, + interPacketDelay; gint size[2]; gint binning[2]; gint maxSize[2];