From 1417f0d3302b6c4b4150f45b7617e7585a6b5f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thies=20M=C3=B6ller?= Date: Mon, 10 Jan 2022 09:02:45 +0100 Subject: [PATCH] gst-pylonsrc: add MaxTransferSize for USB3Vison devices increasing MaxTransferSize allows to lower the system overhead to receive video data in case of larger images --- sys/pylon/gstpylonsrc.c | 72 +++++++++++++++++++++++++++++++++++++---- sys/pylon/gstpylonsrc.h | 5 +-- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/sys/pylon/gstpylonsrc.c b/sys/pylon/gstpylonsrc.c index daff9e0..338c211 100644 --- a/sys/pylon/gstpylonsrc.c +++ b/sys/pylon/gstpylonsrc.c @@ -39,8 +39,10 @@ #include #include +#include "genapic/GenApiC.h" #include "common/genicampixelformat.h" + static int plugin_counter = 0; int @@ -177,6 +179,7 @@ typedef enum _GST_PYLONSRC_PROP PROP_FRAMETRANSDELAY, PROP_BANDWIDTHRESERVE, PROP_BANDWIDTHRESERVEACC, + PROP_MAXTRANSFERSIZE, PROP_CONFIGFILE, PROP_IGNOREDEFAULTS, @@ -363,6 +366,7 @@ ascii_strdown (gchar * *str, gssize len) #define DEFAULT_PROP_FRAMETRANSDELAY 0 #define DEFAULT_PROP_BANDWIDTHRESERVE 10 #define DEFAULT_PROP_BANDWIDTHRESERVEACC 10 +#define DEFAULT_PROP_MAXTRANSFERSIZE 262144 /* pad templates */ static GstStaticPadTemplate gst_pylonsrc_src_template = @@ -748,35 +752,46 @@ gst_pylonsrc_class_init (GstPylonSrcClass * klass) "Specifies the number of miiliseconds to wait for frame to be grabed from the camera.", 0, 60000, DEFAULT_PROP_GRABTIMEOUT, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + //TODO: Limits may be co-dependent on other transport layer parameters. g_object_class_install_property (gobject_class, PROP_PACKETSIZE, g_param_spec_int ("packet-size", "Maximum size of data packet", "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))); //TODO: Limits may be co-dependent on other transport layer parameters. + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + //TODO: Limits may be co-dependent on other transport layer parameters. 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))); //TODO: Limits may be co-dependent on other transport layer parameters. + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + //TODO: Limits may be co-dependent on other transport layer parameters. g_object_class_install_property (gobject_class, PROP_FRAMETRANSDELAY, g_param_spec_int ("frame-trans-delay", "Delay for begin transmitting frame.", "Sets a delay in ticks between when camera begisn transmitting frame afther acquiring it. By default, one tick equals 8 ns. With PTP enabled, one tick equals 1 ns.", 0, 50000000, DEFAULT_PROP_FRAMETRANSDELAY, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); //TODO: Limits may be co-dependent on other transport layer parameters. + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + //TODO: Limits may be co-dependent on other transport layer parameters. g_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVE, g_param_spec_int ("bandwidth-reserve", "Portion of bandwidth reserved for packet resends.", "The setting is expressed as a percentage of the assigned bandwidth.", 0, 26, DEFAULT_PROP_BANDWIDTHRESERVE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); //TODO: Limits may be co-dependent on other transport layer parameters. + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + //TODO: Limits may be co-dependent on other transport layer parameters. g_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVEACC, g_param_spec_int ("bandwidth-reserve-acc", "Pool of resends for unusual situations", "For situations when the network connection becomes unstable. A larger number of packet resends may be needed to transmit an image", 1, 32, DEFAULT_PROP_BANDWIDTHRESERVEACC, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); //TODO: Limits may be co-dependent on other transport layer parameters. + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + g_object_class_install_property (gobject_class, PROP_MAXTRANSFERSIZE, + g_param_spec_int ("max-transfer-size", + "Maximum USB data transfer size in bytes", + "Use the MaxTransferSize parameter to specify the maximum USB data transfer size in bytes. The default value is appropriate for most applications. Increase the value to lower the CPU load. USB host adapter drivers may require decreasing the value if the application fails to receive the image stream. The maximum value depends on the operating system.", + 0x400, 0x400000, DEFAULT_PROP_MAXTRANSFERSIZE, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); } static gboolean @@ -872,6 +887,7 @@ gst_pylonsrc_init (GstPylonSrc * src) src->frameTransDelay = DEFAULT_PROP_FRAMETRANSDELAY; src->bandwidthReserve = DEFAULT_PROP_BANDWIDTHRESERVE; src->bandwidthReserveAcc = DEFAULT_PROP_BANDWIDTHRESERVEACC; + src->maxTransferSize = DEFAULT_PROP_MAXTRANSFERSIZE; for (int i = 0; i < PROP_NUM_PROPERTIES; i++) { src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT; @@ -1080,7 +1096,7 @@ gst_pylonsrc_set_property (GObject * object, guint property_id, set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); break; case PROP_COLORADJUSTMENTENABLE: - src->colorAdjustment = g_value_get_boolean(value); + src->colorAdjustment = g_value_get_boolean (value); break; case PROP_MAXBANDWIDTH: src->maxBandwidth = g_value_get_int (value); @@ -1214,6 +1230,9 @@ gst_pylonsrc_set_property (GObject * object, guint property_id, case PROP_BANDWIDTHRESERVEACC: src->bandwidthReserveAcc = g_value_get_int (value); break; + case PROP_MAXTRANSFERSIZE: + src->maxTransferSize = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); return; @@ -1330,7 +1349,7 @@ gst_pylonsrc_get_property (GObject * object, guint property_id, g_value_set_double (value, src->saturation[COLOUR_MAGENTA]); break; case PROP_COLORADJUSTMENTENABLE: - g_value_set_boolean(value, src->colorAdjustment); + g_value_set_boolean (value, src->colorAdjustment); break; case PROP_MAXBANDWIDTH: g_value_set_int (value, src->maxBandwidth); @@ -1449,6 +1468,9 @@ gst_pylonsrc_get_property (GObject * object, guint property_id, case PROP_BANDWIDTHRESERVEACC: g_value_set_int (value, src->bandwidthReserveAcc); break; + case PROP_MAXTRANSFERSIZE: + g_value_set_int (value, src->maxTransferSize); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -3050,6 +3072,39 @@ error: return FALSE; } +static gboolean +gst_pylonsrc_set_maxTransferSize (GstPylonSrc * src) +{ + GENAPIC_RESULT res; + + if (is_prop_implicit (src, PROP_MAXTRANSFERSIZE)) { + if (is_prop_set (src, PROP_MAXTRANSFERSIZE)) { + NODE_HANDLE phNode = 0; + NODEMAP_HANDLE phStreamGrabberNodeMap = 0; + PylonStreamGrabberGetNodeMap (src->streamGrabber, + &phStreamGrabberNodeMap); + if (!phStreamGrabberNodeMap) + goto error; + GenApiNodeMapGetNode (phStreamGrabberNodeMap, "MaxTransferSize", &phNode); + if (phNode) { + _Bool isWritable = 0; + GenApiNodeIsWritable (phNode, &isWritable); + if (isWritable) { + GST_DEBUG_OBJECT (src, "Setting max transfer size to %d", + src->maxTransferSize); + res = GenApiIntegerSetValue (phNode, src->maxTransferSize); + PYLONC_CHECK_ERROR (src, res); + } + } + } + reset_prop (src, PROP_MAXTRANSFERSIZE); + } + return TRUE; + +error: + return FALSE; +} + static gboolean gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src) { @@ -3074,6 +3129,9 @@ gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src) res = PylonStreamGrabberOpen (src->streamGrabber); PYLONC_CHECK_ERROR (src, res); + // set the max transfer size in case of USB + gst_pylonsrc_set_maxTransferSize (src); + // Get the wait object res = PylonStreamGrabberGetWaitObject (src->streamGrabber, &src->waitObject); PYLONC_CHECK_ERROR (src, res); diff --git a/sys/pylon/gstpylonsrc.h b/sys/pylon/gstpylonsrc.h index 222f0dc..904e896 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 = 74 + GST_PYLONSRC_NUM_PROPS = 75 }; typedef enum _GST_PYLONSRC_PROPERTY_STATE @@ -101,7 +101,8 @@ struct _GstPylonSrc GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES]; gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize, - interPacketDelay, frameTransDelay, bandwidthReserve, bandwidthReserveAcc; + interPacketDelay, frameTransDelay, bandwidthReserve, bandwidthReserveAcc, + maxTransferSize; gint size[2]; gint binning[2]; gint maxSize[2];