pylonsrc: handle float features with int aliases

This commit is contained in:
mrstecklo 2021-02-15 15:21:38 +03:00 committed by joshdoe
parent a28d0fd840
commit f9d9af433c

View File

@ -1460,6 +1460,38 @@ feature_alias_readable (const GstPylonSrc * src, const char *feature,
} }
} }
static GENAPIC_RESULT
gst_pylonsrc_set_float_feature_alias (GstPylonSrc * src, const char *feature,
const char *alias, double value)
{
GENAPIC_RESULT res = GENAPI_E_NODE_NOT_FOUND;
const char *name = feature_alias_available (src, feature, alias);
if (name != NULL) {
res = PylonDeviceSetFloatFeature (src->deviceHandle, name, value);
GST_DEBUG_OBJECT (src, "Setting %s to %f", name, value);
}
return res;
}
static GENAPIC_RESULT
gst_pylonsrc_set_float_feature_with_int_alias (GstPylonSrc * src,
const char *feature, const char *alias, double value)
{
GENAPIC_RESULT res = GENAPI_E_NODE_NOT_FOUND;
const char *name = feature_alias_available (src, feature, alias);
if (name != NULL) {
if (name == alias) {
const int64_t temp = (int64_t) value;
res = PylonDeviceSetIntegerFeature (src->deviceHandle, name, temp);
GST_DEBUG_OBJECT (src, "Setting %s to %ld", name, temp);
} else {
res = PylonDeviceSetFloatFeature (src->deviceHandle, name, value);
GST_DEBUG_OBJECT (src, "Setting %s to %f", name, value);
}
}
return res;
}
static gboolean static gboolean
gst_pylonsrc_set_trigger (GstPylonSrc * src) gst_pylonsrc_set_trigger (GstPylonSrc * src)
{ {
@ -2085,16 +2117,15 @@ gst_pylonsrc_set_framerate (GstPylonSrc * src)
if (is_prop_implicit (src, PROP_FPS)) { if (is_prop_implicit (src, PROP_FPS)) {
if (is_prop_set (src, PROP_FPS)) { if (is_prop_set (src, PROP_FPS)) {
// apply only if it is set explicitly (default is zero) // apply only if it is set explicitly (default is zero)
const char *fps = feature_alias_available (src, "AcquisitionFrameRate", res = gst_pylonsrc_set_float_feature_alias (src, "AcquisitionFrameRate",
"AcquisitionFrameRateAbs"); "AcquisitionFrameRateAbs", src->fps);
if (fps != NULL) { if (res != GENAPI_E_NODE_NOT_FOUND) {
res = PylonDeviceSetFloatFeature (src->deviceHandle, fps, src->fps);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
}
if (src->setFPS) { if (src->setFPS) {
GST_DEBUG_OBJECT (src, "Capping framerate to %0.2lf.", src->fps); GST_DEBUG_OBJECT (src, "Capping framerate to %0.2lf.", src->fps);
} }
} }
}
reset_prop (src, PROP_FPS); reset_prop (src, PROP_FPS);
} }
@ -2242,13 +2273,16 @@ gst_pylonsrc_set_limited_feature (GstPylonSrc * src,
featManualFeature[feature]); featManualFeature[feature]);
} }
const char *upper = if (feature == AUTOF_GAIN) {
feature_alias_available (src, featLimitedUpper[feature], res = gst_pylonsrc_set_float_feature_with_int_alias (src,
featLimitedUpperAlias[feature]); featLimitedUpper[feature], featLimitedUpperAlias[feature],
if (upper != NULL) { src->limitedFeature[feature].upper);
res = } else {
PylonDeviceSetFloatFeature (src->deviceHandle, res = gst_pylonsrc_set_float_feature_alias (src,
upper, src->limitedFeature[feature].upper); featLimitedUpper[feature], featLimitedUpperAlias[feature],
src->limitedFeature[feature].upper);
}
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
reset_prop (src, propLimitedUpper[feature]); reset_prop (src, propLimitedUpper[feature]);
@ -2272,13 +2306,16 @@ gst_pylonsrc_set_limited_feature (GstPylonSrc * src,
} }
} }
const char *lower = if (feature == AUTOF_GAIN) {
feature_alias_available (src, featLimitedLower[feature], res = gst_pylonsrc_set_float_feature_with_int_alias (src,
featLimitedLowerAlias[feature]); featLimitedLower[feature], featLimitedLowerAlias[feature],
if (lower != NULL) { src->limitedFeature[feature].lower);
res = } else {
PylonDeviceSetFloatFeature (src->deviceHandle, res = gst_pylonsrc_set_float_feature_alias (src,
lower, src->limitedFeature[feature].lower); featLimitedLower[feature], featLimitedLowerAlias[feature],
src->limitedFeature[feature].lower);
}
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
reset_prop (src, propLimitedLower[feature]); reset_prop (src, propLimitedLower[feature]);
@ -2309,17 +2346,10 @@ gst_pylonsrc_set_auto_exp_gain_wb (GstPylonSrc * src)
if (is_prop_implicit (src, PROP_AUTOBRIGHTNESSTARGET)) { if (is_prop_implicit (src, PROP_AUTOBRIGHTNESSTARGET)) {
if (is_prop_set (src, PROP_AUTOBRIGHTNESSTARGET)) { if (is_prop_set (src, PROP_AUTOBRIGHTNESSTARGET)) {
if (feature_available (src, "AutoTargetBrightness")) {
res = res =
PylonDeviceSetFloatFeature (src->deviceHandle, gst_pylonsrc_set_float_feature_with_int_alias (src,
"AutoTargetBrightness", src->brightnesstarget); "AutoTargetBrightness", "AutoTargetValue", src->brightnesstarget);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} else if (feature_available (src, "AutoTargetValue")) {
res =
PylonDeviceSetIntegerFeature (src->deviceHandle, "AutoTargetValue",
(int64_t) src->brightnesstarget);
PYLONC_CHECK_ERROR (src, res);
}
} }
reset_prop (src, PROP_AUTOBRIGHTNESSTARGET); reset_prop (src, PROP_AUTOBRIGHTNESSTARGET);
} }
@ -2377,21 +2407,21 @@ gst_pylonsrc_set_colour_balance (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour)
if (is_prop_implicit (src, propColourBalance[colour])) { if (is_prop_implicit (src, propColourBalance[colour])) {
if (is_prop_set (src, propColourBalance[colour])) { if (is_prop_set (src, propColourBalance[colour])) {
if (strcmp (src->autoFeature[AUTOF_WHITEBALANCE], "off") == 0) { if (strcmp (src->autoFeature[AUTOF_WHITEBALANCE], "off") == 0) {
const char *name = if (feature_available (src, "BalanceRatioSelector")) {
feature_alias_available (src, "BalanceRatio", "BalanceRatioAbs");
if (name != NULL) {
GENAPIC_RESULT res; GENAPIC_RESULT res;
res = res =
PylonDeviceFeatureFromString (src->deviceHandle, PylonDeviceFeatureFromString (src->deviceHandle,
"BalanceRatioSelector", featColour[colour]); "BalanceRatioSelector", featColour[colour]);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
res = GST_DEBUG_OBJECT (src, "BalanceRatioSelector: %s",
PylonDeviceSetFloatFeature (src->deviceHandle, name, featColour[colour]);
src->balance[colour]);
PYLONC_CHECK_ERROR (src, res);
GST_DEBUG_OBJECT (src, "%s balance set to %.2lf", featColour[colour], res =
src->balance[colour]); gst_pylonsrc_set_float_feature_alias (src, "BalanceRatio",
"BalanceRatioAbs", src->balance[colour]);
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res);
}
} }
} else { } else {
GST_DEBUG_OBJECT (src, GST_DEBUG_OBJECT (src,
@ -2624,23 +2654,26 @@ gst_pylonsrc_set_manual_feature (GstPylonSrc * src,
// Configure exposure/gain // Configure exposure/gain
if (is_prop_implicit (src, propManualFeature[feature])) { if (is_prop_implicit (src, propManualFeature[feature])) {
if (is_prop_set (src, propManualFeature[feature])) { if (is_prop_set (src, propManualFeature[feature])) {
const char *name =
feature_alias_available (src, featManualFeature[feature],
featManualFeatureAlias[feature]);
if (name != NULL) {
if (strcmp (src->autoFeature[feature], "off") == 0) { if (strcmp (src->autoFeature[feature], "off") == 0) {
GENAPIC_RESULT res; GENAPIC_RESULT res;
GST_DEBUG_OBJECT (src, "Setting %s to %0.2lf", if (feature == AUTOF_GAIN) {
name, src->limitedFeature[feature].manual);
res = res =
PylonDeviceSetFloatFeature (src->deviceHandle, gst_pylonsrc_set_float_feature_with_int_alias (src,
name, src->limitedFeature[feature].manual); featManualFeature[feature], featManualFeatureAlias[feature],
src->limitedFeature[feature].manual);
} else {
res =
gst_pylonsrc_set_float_feature_alias (src,
featManualFeature[feature], featManualFeatureAlias[feature],
src->limitedFeature[feature].manual);
}
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
}
} else { } else {
GST_WARNING_OBJECT (src, GST_WARNING_OBJECT (src,
"%s has been enabled, skipping setting manual %s.", "%s has been enabled, skipping setting manual %s.",
featAutoFeature[feature], name); featAutoFeature[feature], featManualFeature[feature]);
}
} }
} else { } else {
GST_DEBUG_OBJECT (src, GST_DEBUG_OBJECT (src,
@ -2670,12 +2703,10 @@ gst_pylonsrc_set_exposure_gain_level (GstPylonSrc * src)
// Configure black level // Configure black level
if (is_prop_implicit (src, PROP_BLACKLEVEL)) { if (is_prop_implicit (src, PROP_BLACKLEVEL)) {
const char *name =
feature_alias_available (src, "BlackLevel", "BlackLevelRaw");
if (name != NULL) {
GST_DEBUG_OBJECT (src, "Setting black level to %0.2lf", src->blacklevel);
res = res =
PylonDeviceSetFloatFeature (src->deviceHandle, name, src->blacklevel); gst_pylonsrc_set_float_feature_with_int_alias (src, "BlackLevel",
"BlackLevelRaw", src->blacklevel);
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
reset_prop (src, PROP_BLACKLEVEL); reset_prop (src, PROP_BLACKLEVEL);
@ -2733,15 +2764,9 @@ gst_pylonsrc_set_pgi (GstPylonSrc * src)
// PGI Modules (Noise reduction and Sharpness enhancement). // PGI Modules (Noise reduction and Sharpness enhancement).
if (is_prop_implicit (src, PROP_DEMOSAICINGNOISEREDUCTION)) { if (is_prop_implicit (src, PROP_DEMOSAICINGNOISEREDUCTION)) {
if (is_prop_set (src, PROP_DEMOSAICINGNOISEREDUCTION)) { if (is_prop_set (src, PROP_DEMOSAICINGNOISEREDUCTION)) {
const char *noise = res = gst_pylonsrc_set_float_feature_alias (src, "NoiseReduction",
feature_alias_available (src, "NoiseReduction", "NoiseReductionAbs", src->noisereduction);
"NoiseReductionAbs"); if (res != GENAPI_E_NODE_NOT_FOUND) {
if (noise != NULL) {
GST_DEBUG_OBJECT (src, "Setting PGI noise reduction to %0.2lf",
src->noisereduction);
res =
PylonDeviceSetFloatFeature (src->deviceHandle,
noise, src->noisereduction);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
} else { } else {
@ -2753,16 +2778,11 @@ gst_pylonsrc_set_pgi (GstPylonSrc * src)
if (is_prop_implicit (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) { if (is_prop_implicit (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) {
if (is_prop_set (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) { if (is_prop_set (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) {
const char *sharpness =
feature_alias_available (src, "SharpnessEnhancement",
"SharpnessEnhancementAbs");
if (sharpness != NULL) {
GST_DEBUG_OBJECT (src,
"Setting PGI sharpness enhancement to %0.2lf",
src->sharpnessenhancement);
res = res =
PylonDeviceSetFloatFeature (src->deviceHandle, gst_pylonsrc_set_float_feature_alias (src,
sharpness, src->sharpnessenhancement); "SharpnessEnhancement", "SharpnessEnhancementAbs",
src->sharpnessenhancement);
if (res != GENAPI_E_NODE_NOT_FOUND) {
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
} else { } else {
@ -2858,8 +2878,8 @@ gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src)
for (i = 0; i < GST_PYLONSRC_NUM_CAPTURE_BUFFERS; ++i) { for (i = 0; i < GST_PYLONSRC_NUM_CAPTURE_BUFFERS; ++i) {
res = res =
PylonStreamGrabberQueueBuffer (src->streamGrabber, src->bufferHandle[i], PylonStreamGrabberQueueBuffer (src->streamGrabber,
(void *) i); src->bufferHandle[i], (void *) i);
PYLONC_CHECK_ERROR (src, res); PYLONC_CHECK_ERROR (src, res);
} }
@ -2963,13 +2983,17 @@ read_string_feature (GstPylonSrc * src, const char *feature)
} }
static GENAPIC_RESULT static GENAPIC_RESULT
read_bool_feature (GstPylonSrc * src, const char *feature, _Bool * result) read_bool_feature (GstPylonSrc * src, const char *feature, _Bool *result)
{ {
GENAPIC_RESULT res = GENAPI_E_FAIL; GENAPIC_RESULT res = GENAPI_E_FAIL;
if (feature_readable (src, feature)) { if (feature_readable (src, feature)) {
res = PylonDeviceGetBooleanFeature (src->deviceHandle, feature, result); res = PylonDeviceGetBooleanFeature (src->deviceHandle, feature, result);
if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading bool feature: %s = %s", feature, GST_DEBUG_OBJECT (src, "Reading bool feature: %s = %s", feature,
boolalpha (*result)); boolalpha (*result));
} else {
GST_ERROR_OBJECT (src, "Failed to read %s", feature);
}
} }
return res; return res;
@ -2981,8 +3005,12 @@ read_integer_feature (GstPylonSrc * src, const char *feature, int64_t * result)
GENAPIC_RESULT res = GENAPI_E_FAIL; GENAPIC_RESULT res = GENAPI_E_FAIL;
if (feature_readable (src, feature)) { if (feature_readable (src, feature)) {
res = PylonDeviceGetIntegerFeature (src->deviceHandle, feature, result); res = PylonDeviceGetIntegerFeature (src->deviceHandle, feature, result);
if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading integer feature: %s = %ld", feature, GST_DEBUG_OBJECT (src, "Reading integer feature: %s = %ld", feature,
*result); *result);
} else {
GST_ERROR_OBJECT (src, "Failed to read %s", feature);
}
} }
return res; return res;
@ -2994,7 +3022,12 @@ read_float_feature (GstPylonSrc * src, const char *feature, double *result)
GENAPIC_RESULT res = GENAPI_E_FAIL; GENAPIC_RESULT res = GENAPI_E_FAIL;
if (feature_readable (src, feature)) { if (feature_readable (src, feature)) {
res = PylonDeviceGetFloatFeature (src->deviceHandle, feature, result); res = PylonDeviceGetFloatFeature (src->deviceHandle, feature, result);
GST_DEBUG_OBJECT (src, "Reading float feature: %s = %f", feature, *result); if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading float feature: %s = %f", feature,
*result);
} else {
GST_ERROR_OBJECT (src, "Failed to read %s", feature);
}
} }
return res; return res;
@ -3008,7 +3041,40 @@ read_float_feature_alias (GstPylonSrc * src, const char *feature,
const char *name = feature_alias_readable (src, feature, alias); const char *name = feature_alias_readable (src, feature, alias);
if (name != NULL) { if (name != NULL) {
res = PylonDeviceGetFloatFeature (src->deviceHandle, name, result); res = PylonDeviceGetFloatFeature (src->deviceHandle, name, result);
if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading float feature: %s = %f", name, *result); GST_DEBUG_OBJECT (src, "Reading float feature: %s = %f", name, *result);
} else {
GST_ERROR_OBJECT (src, "Failed to read %s", name);
}
}
return res;
}
static GENAPIC_RESULT
read_float_feature_with_int_alias (GstPylonSrc * src, const char *feature,
const char *alias, double *result)
{
GENAPIC_RESULT res = GENAPI_E_FAIL;
const char *name = feature_alias_readable (src, feature, alias);
if (name != NULL) {
if (name == feature) {
res = PylonDeviceGetFloatFeature (src->deviceHandle, name, result);
if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading float feature: %s = %f", name, *result);
}
} else {
int64_t temp = 0;
res = PylonDeviceGetIntegerFeature (src->deviceHandle, name, &temp);
if (res == GENAPI_E_OK) {
GST_DEBUG_OBJECT (src, "Reading integer feature: %s = %ld", name, temp);
*result = (double) temp;
}
}
if (res != GENAPI_E_OK) {
GST_ERROR_OBJECT (src, "Failed to read %s", name);
}
} }
return res; return res;
@ -3029,9 +3095,11 @@ gst_pylonsrc_read_max_size_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis)
GST_INFO_OBJECT (src, "Read %s value from upper bound of %s", GST_INFO_OBJECT (src, "Read %s value from upper bound of %s",
featMaxSize[axis], featSize[axis]); featMaxSize[axis], featSize[axis]);
return maxSize; return maxSize;
} } else {
} GST_ERROR_OBJECT (src, "Failed to get upper bound of %s", featSize[axis]);
return G_MAXINT; return G_MAXINT;
}
}
} }
static void static void
@ -3216,13 +3284,27 @@ gst_pylonsrc_read_limited_feature (GstPylonSrc * src,
"Trying to read limits for unsupported autofeature: %d", (int) feature); "Trying to read limits for unsupported autofeature: %d", (int) feature);
} else { } else {
if (is_prop_not_set (src, propLimitedUpper[feature])) { if (is_prop_not_set (src, propLimitedUpper[feature])) {
if (feature == AUTOF_GAIN) {
read_float_feature_with_int_alias (src, featLimitedUpper[feature],
featLimitedUpperAlias[feature],
&src->limitedFeature[feature].upper);
} else {
read_float_feature_alias (src, featLimitedUpper[feature], read_float_feature_alias (src, featLimitedUpper[feature],
featLimitedUpperAlias[feature], &src->limitedFeature[feature].upper); featLimitedUpperAlias[feature],
&src->limitedFeature[feature].upper);
}
} }
if (is_prop_not_set (src, propLimitedLower[feature])) { if (is_prop_not_set (src, propLimitedLower[feature])) {
if (feature == AUTOF_GAIN) {
read_float_feature_with_int_alias (src, featLimitedLower[feature],
featLimitedLowerAlias[feature],
&src->limitedFeature[feature].lower);
} else {
read_float_feature_alias (src, featLimitedLower[feature], read_float_feature_alias (src, featLimitedLower[feature],
featLimitedLowerAlias[feature], &src->limitedFeature[feature].lower); featLimitedLowerAlias[feature],
&src->limitedFeature[feature].lower);
}
} }
} }
} }
@ -3240,8 +3322,8 @@ gst_pylonsrc_read_auto_exp_gain_wb (GstPylonSrc * src)
} }
if (is_prop_not_set (src, PROP_AUTOBRIGHTNESSTARGET)) { if (is_prop_not_set (src, PROP_AUTOBRIGHTNESSTARGET)) {
read_float_feature_alias (src, "AutoTargetBrightness", "AutoTargetValue", read_float_feature_with_int_alias (src, "AutoTargetBrightness",
&src->brightnesstarget); "AutoTargetValue", &src->brightnesstarget);
} }
if (is_prop_not_set (src, PROP_AUTOPROFILE)) { if (is_prop_not_set (src, PROP_AUTOPROFILE)) {
@ -3292,7 +3374,7 @@ gst_pylonsrc_read_colour_hue (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour)
{ {
if (is_prop_not_set (src, propColourHue[colour])) { if (is_prop_not_set (src, propColourHue[colour])) {
const char *selector = const char *selector =
feature_alias_available (src, "ColorAdjustmentSelector", feature_alias_readable (src, "ColorAdjustmentSelector",
"BslColorAdjustmentSelector"); "BslColorAdjustmentSelector");
GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle,
selector, featColour[colour]); selector, featColour[colour]);
@ -3317,7 +3399,7 @@ gst_pylonsrc_read_colour_saturation (GstPylonSrc * src,
{ {
if (is_prop_not_set (src, propColourSaturation[colour])) { if (is_prop_not_set (src, propColourSaturation[colour])) {
const char *selector = const char *selector =
feature_alias_available (src, "ColorAdjustmentSelector", feature_alias_readable (src, "ColorAdjustmentSelector",
"BslColorAdjustmentSelector"); "BslColorAdjustmentSelector");
GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle,
selector, featColour[colour]); selector, featColour[colour]);
@ -3408,11 +3490,17 @@ gst_pylonsrc_read_manual_feature (GstPylonSrc * src,
(int) feature); (int) feature);
} else { } else {
if (is_prop_not_set (src, propManualFeature[feature])) { if (is_prop_not_set (src, propManualFeature[feature])) {
if (feature == AUTOF_GAIN) {
read_float_feature_with_int_alias (src, featManualFeature[feature],
featManualFeatureAlias[feature],
&src->limitedFeature[feature].manual);
} else {
read_float_feature_alias (src, featManualFeature[feature], read_float_feature_alias (src, featManualFeature[feature],
featManualFeatureAlias[feature], featManualFeatureAlias[feature],
&src->limitedFeature[feature].manual); &src->limitedFeature[feature].manual);
} }
} }
}
} }
static void static void
@ -3423,7 +3511,7 @@ gst_pylonsrc_read_exposure_gain_level (GstPylonSrc * src)
} }
if (is_prop_not_set (src, PROP_BLACKLEVEL)) { if (is_prop_not_set (src, PROP_BLACKLEVEL)) {
read_float_feature_alias (src, "BlackLevel", "BlackLevelRaw", read_float_feature_with_int_alias (src, "BlackLevel", "BlackLevelRaw",
&src->blacklevel); &src->blacklevel);
} }
// Configure gamma correction // Configure gamma correction