From 314581b0023953ce34012dd3a371bea98b927a98 Mon Sep 17 00:00:00 2001 From: Eskild Helmersen Date: Thu, 14 May 2020 17:44:45 +0200 Subject: [PATCH] pylonsrc: added custom grab-timeout parameter instead of hardcoded 1s wait. Useful when trying to understand bandwith related issues on the Basler cameras. --- sys/pylon/gstpylonsrc.c | 21 ++++++++++++++++++--- sys/pylon/gstpylonsrc.h | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sys/pylon/gstpylonsrc.c b/sys/pylon/gstpylonsrc.c index 7a4b792..731d476 100644 --- a/sys/pylon/gstpylonsrc.c +++ b/sys/pylon/gstpylonsrc.c @@ -171,6 +171,7 @@ typedef enum _GST_PYLONSRC_PROP PROP_TRANSFORMATION21, PROP_TRANSFORMATION22, PROP_FRAMEDROPLIMIT, + PROP_GRABTIMEOUT, PROP_CONFIGFILE, PROP_IGNOREDEFAULTS, @@ -351,6 +352,7 @@ ascii_strdown (gchar * *str, gssize len) #define DEFAULT_PROP_IGNOREDEFAULTS FALSE #define DEFAULT_PROP_COLORADJUSTMENTENABLE TRUE #define DEFAULT_PROP_FRAMEDROPLIMIT 10 +#define DEFAULT_PROP_GRABTIMEOUT 1000 /* pad templates */ static GstStaticPadTemplate gst_pylonsrc_src_template = @@ -731,6 +733,11 @@ gst_pylonsrc_class_init (GstPylonSrcClass * klass) "Specifies the number of consecutive frames to fail before failing everything", 0, 100, DEFAULT_PROP_FRAMEDROPLIMIT, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + g_object_class_install_property (gobject_class, PROP_GRABTIMEOUT, + g_param_spec_int ("grab-timeout", "Initial load timeout", + "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))); } static gboolean @@ -820,6 +827,7 @@ gst_pylonsrc_init (GstPylonSrc * src) src->ignoreDefaults = DEFAULT_PROP_IGNOREDEFAULTS; src->frameDropLimit = DEFAULT_PROP_FRAMEDROPLIMIT; + src->grabtimeout = DEFAULT_PROP_GRABTIMEOUT; for (int i = 0; i < PROP_NUM_PROPERTIES; i++) { src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT; @@ -1141,6 +1149,9 @@ gst_pylonsrc_set_property (GObject * object, guint property_id, case PROP_FRAMEDROPLIMIT: src->frameDropLimit = g_value_get_int (value); break; + case PROP_GRABTIMEOUT: + src->grabtimeout = g_value_get_int (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); return; @@ -1355,6 +1366,9 @@ gst_pylonsrc_get_property (GObject * object, guint property_id, case PROP_FRAMEDROPLIMIT: g_value_set_int (value, src->frameDropLimit); break; + case PROP_GRABTIMEOUT: + g_value_set_int (value, src->grabtimeout); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -3800,8 +3814,8 @@ gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf) goto error; src->acquisition_configured = TRUE; } - // Wait for the buffer to be filled (up to 1 s) - res = PylonWaitObjectWait (src->waitObject, 1000, &bufferReady); + // Wait for the buffer to be filled (up to n ms). Can fail on large frames if timeout set too low. + res = PylonWaitObjectWait (src->waitObject, src->grabtimeout, &bufferReady); PYLONC_CHECK_ERROR (src, res); if (!bufferReady) { GST_ERROR_OBJECT (src, @@ -3850,8 +3864,9 @@ gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf) src->failedFrames += 1; GST_WARNING_OBJECT (src, "Failed capture count=%d. Status=%d", src->failedFrames, grabResult.Status); - } else + } else { src->failedFrames = 0; + } } else { GST_ERROR_OBJECT (src, "Error in the image processing loop. Status=%d", grabResult.Status); diff --git a/sys/pylon/gstpylonsrc.h b/sys/pylon/gstpylonsrc.h index 994831d..60ad210 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 = 68 + GST_PYLONSRC_NUM_PROPS = 69 }; typedef enum _GST_PYLONSRC_PROPERTY_STATE @@ -100,7 +100,7 @@ struct _GstPylonSrc GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES]; - gint maxBandwidth, testImage, frameDropLimit; + gint maxBandwidth, testImage, frameDropLimit, grabtimeout; gint size[2]; gint binning[2]; gint maxSize[2];