gst-pylonsrc: add MaxTransferSize for USB3Vison devices

increasing MaxTransferSize allows to lower the system overhead
to receive video data in case of larger images
This commit is contained in:
Thies Möller 2022-01-10 09:02:45 +01:00 committed by joshdoe
parent 9e91e8afc9
commit 1417f0d330
2 changed files with 68 additions and 9 deletions

View File

@ -39,8 +39,10 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <glib.h> #include <glib.h>
#include "genapic/GenApiC.h"
#include "common/genicampixelformat.h" #include "common/genicampixelformat.h"
static int plugin_counter = 0; static int plugin_counter = 0;
int int
@ -177,6 +179,7 @@ typedef enum _GST_PYLONSRC_PROP
PROP_FRAMETRANSDELAY, PROP_FRAMETRANSDELAY,
PROP_BANDWIDTHRESERVE, PROP_BANDWIDTHRESERVE,
PROP_BANDWIDTHRESERVEACC, PROP_BANDWIDTHRESERVEACC,
PROP_MAXTRANSFERSIZE,
PROP_CONFIGFILE, PROP_CONFIGFILE,
PROP_IGNOREDEFAULTS, PROP_IGNOREDEFAULTS,
@ -363,6 +366,7 @@ ascii_strdown (gchar * *str, gssize len)
#define DEFAULT_PROP_FRAMETRANSDELAY 0 #define DEFAULT_PROP_FRAMETRANSDELAY 0
#define DEFAULT_PROP_BANDWIDTHRESERVE 10 #define DEFAULT_PROP_BANDWIDTHRESERVE 10
#define DEFAULT_PROP_BANDWIDTHRESERVEACC 10 #define DEFAULT_PROP_BANDWIDTHRESERVEACC 10
#define DEFAULT_PROP_MAXTRANSFERSIZE 262144
/* pad templates */ /* pad templates */
static GstStaticPadTemplate gst_pylonsrc_src_template = 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.", "Specifies the number of miiliseconds to wait for frame to be grabed from the camera.",
0, 60000, DEFAULT_PROP_GRABTIMEOUT, 0, 60000, DEFAULT_PROP_GRABTIMEOUT,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); (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_object_class_install_property (gobject_class, PROP_PACKETSIZE,
g_param_spec_int ("packet-size", "Maximum size of data packet", 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.", "The packetsize parameter specifies the maximum size of a data packet transmitted via Ethernet. The value is in bytes.",
0, 16000, DEFAULT_PROP_PACKETSIZE, 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_object_class_install_property (gobject_class, PROP_INTERPACKETDELAY,
g_param_spec_int ("inter-packet-delay", g_param_spec_int ("inter-packet-delay",
"Inter-Packet Delay between packet transmissions", "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.", "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, 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_object_class_install_property (gobject_class, PROP_FRAMETRANSDELAY,
g_param_spec_int ("frame-trans-delay", g_param_spec_int ("frame-trans-delay",
"Delay for begin transmitting frame.", "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.", "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, 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_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVE,
g_param_spec_int ("bandwidth-reserve", g_param_spec_int ("bandwidth-reserve",
"Portion of bandwidth reserved for packet resends.", "Portion of bandwidth reserved for packet resends.",
"The setting is expressed as a percentage of the assigned bandwidth.", "The setting is expressed as a percentage of the assigned bandwidth.",
0, 26, DEFAULT_PROP_BANDWIDTHRESERVE, 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_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVEACC,
g_param_spec_int ("bandwidth-reserve-acc", g_param_spec_int ("bandwidth-reserve-acc",
"Pool of resends for unusual situations", "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", "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, 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 static gboolean
@ -872,6 +887,7 @@ gst_pylonsrc_init (GstPylonSrc * src)
src->frameTransDelay = DEFAULT_PROP_FRAMETRANSDELAY; src->frameTransDelay = DEFAULT_PROP_FRAMETRANSDELAY;
src->bandwidthReserve = DEFAULT_PROP_BANDWIDTHRESERVE; src->bandwidthReserve = DEFAULT_PROP_BANDWIDTHRESERVE;
src->bandwidthReserveAcc = DEFAULT_PROP_BANDWIDTHRESERVEACC; src->bandwidthReserveAcc = DEFAULT_PROP_BANDWIDTHRESERVEACC;
src->maxTransferSize = DEFAULT_PROP_MAXTRANSFERSIZE;
for (int i = 0; i < PROP_NUM_PROPERTIES; i++) { for (int i = 0; i < PROP_NUM_PROPERTIES; i++) {
src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT; src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT;
@ -1214,6 +1230,9 @@ gst_pylonsrc_set_property (GObject * object, guint property_id,
case PROP_BANDWIDTHRESERVEACC: case PROP_BANDWIDTHRESERVEACC:
src->bandwidthReserveAcc = g_value_get_int (value); src->bandwidthReserveAcc = g_value_get_int (value);
break; break;
case PROP_MAXTRANSFERSIZE:
src->maxTransferSize = g_value_get_int (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
return; return;
@ -1449,6 +1468,9 @@ gst_pylonsrc_get_property (GObject * object, guint property_id,
case PROP_BANDWIDTHRESERVEACC: case PROP_BANDWIDTHRESERVEACC:
g_value_set_int (value, src->bandwidthReserveAcc); g_value_set_int (value, src->bandwidthReserveAcc);
break; break;
case PROP_MAXTRANSFERSIZE:
g_value_set_int (value, src->maxTransferSize);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -3050,6 +3072,39 @@ error:
return FALSE; 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 static gboolean
gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src) gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src)
{ {
@ -3074,6 +3129,9 @@ gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src)
res = PylonStreamGrabberOpen (src->streamGrabber); res = PylonStreamGrabberOpen (src->streamGrabber);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
// set the max transfer size in case of USB
gst_pylonsrc_set_maxTransferSize (src);
// Get the wait object // Get the wait object
res = PylonStreamGrabberGetWaitObject (src->streamGrabber, &src->waitObject); res = PylonStreamGrabberGetWaitObject (src->streamGrabber, &src->waitObject);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);

View File

@ -39,7 +39,7 @@ enum
GST_PYLONSRC_NUM_CAPTURE_BUFFERS = 10, GST_PYLONSRC_NUM_CAPTURE_BUFFERS = 10,
GST_PYLONSRC_NUM_AUTO_FEATURES = 3, GST_PYLONSRC_NUM_AUTO_FEATURES = 3,
GST_PYLONSRC_NUM_LIMITED_FEATURES = 2, GST_PYLONSRC_NUM_LIMITED_FEATURES = 2,
GST_PYLONSRC_NUM_PROPS = 74 GST_PYLONSRC_NUM_PROPS = 75
}; };
typedef enum _GST_PYLONSRC_PROPERTY_STATE typedef enum _GST_PYLONSRC_PROPERTY_STATE
@ -101,7 +101,8 @@ struct _GstPylonSrc
GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES]; GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES];
gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize, gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize,
interPacketDelay, frameTransDelay, bandwidthReserve, bandwidthReserveAcc; interPacketDelay, frameTransDelay, bandwidthReserve, bandwidthReserveAcc,
maxTransferSize;
gint size[2]; gint size[2];
gint binning[2]; gint binning[2];
gint maxSize[2]; gint maxSize[2];