pylonsrc: refactor _start
It was getting hard to navigate through this function
This commit is contained in:
parent
3d074be9a0
commit
0606ad67b3
@ -53,7 +53,6 @@ _Bool pylonc_connect_camera (GstPylonSrc * src);
|
|||||||
void pylonc_disconnect_camera (GstPylonSrc * src);
|
void pylonc_disconnect_camera (GstPylonSrc * src);
|
||||||
void pylonc_print_camera_info (GstPylonSrc * src,
|
void pylonc_print_camera_info (GstPylonSrc * src,
|
||||||
PYLON_DEVICE_HANDLE deviceHandle, int deviceId);
|
PYLON_DEVICE_HANDLE deviceHandle, int deviceId);
|
||||||
void pylonc_initialize ();
|
|
||||||
void pylonc_terminate ();
|
void pylonc_terminate ();
|
||||||
|
|
||||||
|
|
||||||
@ -1165,19 +1164,12 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_pylonsrc_start (GstBaseSrc * bsrc)
|
gst_pylonsrc_select_device (GstPylonSrc * src)
|
||||||
{
|
{
|
||||||
GstPylonSrc *src = GST_PYLONSRC (bsrc);
|
int i;
|
||||||
GENAPIC_RESULT res;
|
|
||||||
gint i;
|
|
||||||
size_t numDevices;
|
size_t numDevices;
|
||||||
int64_t width = 0, height = 0;
|
GENAPIC_RESULT res;
|
||||||
GString *pixelFormat = g_string_new (NULL);
|
|
||||||
size_t num_streams;
|
|
||||||
|
|
||||||
pylonc_initialize ();
|
|
||||||
|
|
||||||
// Select a device
|
|
||||||
res = PylonEnumerateDevices (&numDevices);
|
res = PylonEnumerateDevices (&numDevices);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
GST_DEBUG_OBJECT (src, "src: found %i Basler device(s).", (int) numDevices);
|
GST_DEBUG_OBJECT (src, "src: found %i Basler device(s).", (int) numDevices);
|
||||||
@ -1229,7 +1221,18 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
("Failed to initialise the camera"), ("No camera connected"));
|
("Failed to initialise the camera"), ("No camera connected"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
// Connect to the camera
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_connect_device (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
if (!pylonc_connect_camera (src)) {
|
if (!pylonc_connect_camera (src)) {
|
||||||
GST_ERROR_OBJECT (src, "Couldn't initialise the camera");
|
GST_ERROR_OBJECT (src, "Couldn't initialise the camera");
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||||
@ -1252,6 +1255,7 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
src->reset = g_ascii_strdown (src->reset, -1);
|
src->reset = g_ascii_strdown (src->reset, -1);
|
||||||
if (strcmp (src->reset, "before") == 0) {
|
if (strcmp (src->reset, "before") == 0) {
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "DeviceReset")) {
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "DeviceReset")) {
|
||||||
|
size_t numDevices;
|
||||||
pylonc_reset_camera (src);
|
pylonc_reset_camera (src);
|
||||||
pylonc_disconnect_camera (src);
|
pylonc_disconnect_camera (src);
|
||||||
pylonc_terminate ();
|
pylonc_terminate ();
|
||||||
@ -1260,7 +1264,7 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"Camera reset. Waiting 6 seconds for it to fully reboot.");
|
"Camera reset. Waiting 6 seconds for it to fully reboot.");
|
||||||
g_usleep (6 * G_USEC_PER_SEC);
|
g_usleep (6 * G_USEC_PER_SEC);
|
||||||
|
|
||||||
pylonc_initialize ();
|
PylonInitialize ();
|
||||||
res = PylonEnumerateDevices (&numDevices);
|
res = PylonEnumerateDevices (&numDevices);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
|
||||||
@ -1280,6 +1284,19 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_resolution (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
int64_t width = 0, height = 0;
|
||||||
|
|
||||||
// set binning of camera
|
// set binning of camera
|
||||||
if (FEATURE_SUPPORTED ("BinningHorizontal") &&
|
if (FEATURE_SUPPORTED ("BinningHorizontal") &&
|
||||||
FEATURE_SUPPORTED ("BinningVertical")) {
|
FEATURE_SUPPORTED ("BinningVertical")) {
|
||||||
@ -1357,6 +1374,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
GST_DEBUG_OBJECT (src, "Setting resolution to %dx%d.", src->width,
|
GST_DEBUG_OBJECT (src, "Setting resolution to %dx%d.", src->width,
|
||||||
src->height);
|
src->height);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_offset (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Set the offset
|
// Set the offset
|
||||||
if (!FEATURE_SUPPORTED ("OffsetX") || !FEATURE_SUPPORTED ("OffsetY")) {
|
if (!FEATURE_SUPPORTED ("OffsetX") || !FEATURE_SUPPORTED ("OffsetY")) {
|
||||||
GST_WARNING_OBJECT (src,
|
GST_WARNING_OBJECT (src,
|
||||||
@ -1421,6 +1449,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_reverse (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Flip the image
|
// Flip the image
|
||||||
if (!FEATURE_SUPPORTED ("ReverseX")) {
|
if (!FEATURE_SUPPORTED ("ReverseX")) {
|
||||||
src->flipx = FALSE;
|
src->flipx = FALSE;
|
||||||
@ -1445,6 +1484,18 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_pixel_format (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
GString *pixelFormat = g_string_new (NULL);
|
||||||
|
|
||||||
// Set pixel format.
|
// Set pixel format.
|
||||||
src->imageFormat = g_ascii_strdown (src->imageFormat, -1);
|
src->imageFormat = g_ascii_strdown (src->imageFormat, -1);
|
||||||
if (strncmp ("bayer", src->imageFormat, 5) == 0) {
|
if (strncmp ("bayer", src->imageFormat, 5) == 0) {
|
||||||
@ -1562,6 +1613,16 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
}
|
}
|
||||||
g_string_free (pixelFormat, TRUE);
|
g_string_free (pixelFormat, TRUE);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_test_image (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Set whether test image will be shown
|
// Set whether test image will be shown
|
||||||
if (FEATURE_SUPPORTED ("TestImageSelector")) {
|
if (FEATURE_SUPPORTED ("TestImageSelector")) {
|
||||||
@ -1583,6 +1644,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
GST_WARNING_OBJECT (src, "The camera doesn't support test image mode.");
|
GST_WARNING_OBJECT (src, "The camera doesn't support test image mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_readout (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Set sensor readout mode (default: Normal)
|
// Set sensor readout mode (default: Normal)
|
||||||
if (FEATURE_SUPPORTED ("SensorReadoutMode")) {
|
if (FEATURE_SUPPORTED ("SensorReadoutMode")) {
|
||||||
src->sensorMode = g_ascii_strdown (src->sensorMode, -1);
|
src->sensorMode = g_ascii_strdown (src->sensorMode, -1);
|
||||||
@ -1612,6 +1684,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"Camera does not support changing the readout mode.");
|
"Camera does not support changing the readout mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_bandwidth (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Set bandwidth limit mode (default: on)
|
// Set bandwidth limit mode (default: on)
|
||||||
if (FEATURE_SUPPORTED ("DeviceLinkThroughputLimitMode")) {
|
if (FEATURE_SUPPORTED ("DeviceLinkThroughputLimitMode")) {
|
||||||
if (src->limitBandwidth) {
|
if (src->limitBandwidth) {
|
||||||
@ -1652,6 +1735,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"Camera does not support changing the throughput limit.");
|
"Camera does not support changing the throughput limit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_framerate (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Set framerate
|
// Set framerate
|
||||||
if (src->setFPS || (src->fps != 0)) {
|
if (src->setFPS || (src->fps != 0)) {
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle,
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle,
|
||||||
@ -1685,6 +1779,16 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_lightsource (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
// Set lightsource preset
|
// Set lightsource preset
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "LightSourcePreset")) {
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "LightSourcePreset")) {
|
||||||
src->lightsource = g_ascii_strdown (src->lightsource, -1);
|
src->lightsource = g_ascii_strdown (src->lightsource, -1);
|
||||||
@ -1729,6 +1833,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"This camera doesn't have any lightsource presets");
|
"This camera doesn't have any lightsource presets");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_auto_exp_gain_wb (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Enable/disable automatic exposure
|
// Enable/disable automatic exposure
|
||||||
src->autoexposure = g_ascii_strdown (src->autoexposure, -1);
|
src->autoexposure = g_ascii_strdown (src->autoexposure, -1);
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "ExposureAuto")) {
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "ExposureAuto")) {
|
||||||
@ -1935,6 +2050,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"Using the auto profile currently saved on the device.");
|
"Using the auto profile currently saved on the device.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_color (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Configure colour balance
|
// Configure colour balance
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "BalanceRatio")) {
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "BalanceRatio")) {
|
||||||
if (strcmp (src->autowhitebalance, "off") == 0) {
|
if (strcmp (src->autowhitebalance, "off") == 0) {
|
||||||
@ -2344,6 +2470,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"This camera doesn't support transforming colours. Skipping...");
|
"This camera doesn't support transforming colours. Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_exposure_gain_level (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Configure exposure
|
// Configure exposure
|
||||||
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "ExposureTime")) {
|
if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "ExposureTime")) {
|
||||||
if (strcmp (src->autoexposure, "off") == 0) {
|
if (strcmp (src->autoexposure, "off") == 0) {
|
||||||
@ -2403,6 +2540,17 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
"This camera doesn't support setting gamma values.");
|
"This camera doesn't support setting gamma values.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_set_pgi (GstPylonSrc * src)
|
||||||
|
{
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
// Basler PGI
|
// Basler PGI
|
||||||
if (FEATURE_SUPPORTED ("DemosaicingMode")) {
|
if (FEATURE_SUPPORTED ("DemosaicingMode")) {
|
||||||
if (src->demosaicing || src->sharpnessenhancement != 999.0
|
if (src->demosaicing || src->sharpnessenhancement != 999.0
|
||||||
@ -2460,7 +2608,42 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
GST_DEBUG_OBJECT (src, "Basler's PGI is not supported. Skipping.");
|
GST_DEBUG_OBJECT (src, "Basler's PGI is not supported. Skipping.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_pylonsrc_set_trigger (src))
|
return TRUE;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_pylonsrc_start (GstBaseSrc * bsrc)
|
||||||
|
{
|
||||||
|
GstPylonSrc *src = GST_PYLONSRC (bsrc);
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
gint i;
|
||||||
|
size_t num_streams;
|
||||||
|
|
||||||
|
if (PylonInitialize () != 0) {
|
||||||
|
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||||
|
("Failed to initialise the camera"),
|
||||||
|
("Pylon library initialization failed"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_pylonsrc_select_device (src) ||
|
||||||
|
!gst_pylonsrc_connect_device (src) ||
|
||||||
|
!gst_pylonsrc_set_resolution (src) ||
|
||||||
|
!gst_pylonsrc_set_offset (src) ||
|
||||||
|
!gst_pylonsrc_set_reverse (src) ||
|
||||||
|
!gst_pylonsrc_set_pixel_format (src) ||
|
||||||
|
!gst_pylonsrc_set_test_image (src) ||
|
||||||
|
!gst_pylonsrc_set_readout (src) ||
|
||||||
|
!gst_pylonsrc_set_bandwidth (src) ||
|
||||||
|
!gst_pylonsrc_set_framerate (src) ||
|
||||||
|
!gst_pylonsrc_set_lightsource (src) ||
|
||||||
|
!gst_pylonsrc_set_auto_exp_gain_wb (src) ||
|
||||||
|
!gst_pylonsrc_set_color (src) ||
|
||||||
|
!gst_pylonsrc_set_exposure_gain_level (src) ||
|
||||||
|
!gst_pylonsrc_set_pgi (src) || !gst_pylonsrc_set_trigger (src))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
// Create a stream grabber
|
// Create a stream grabber
|
||||||
@ -2672,7 +2855,8 @@ gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
|||||||
(void *) bufferIndex);
|
(void *) bufferIndex);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
} else {
|
} else {
|
||||||
GST_ERROR_OBJECT (src, "Error in the image processing loop.");
|
GST_ERROR_OBJECT (src, "Error in the image processing loop. Status=%d",
|
||||||
|
grabResult.Status);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2717,12 +2901,6 @@ gst_pylonsrc_finalize (GObject * object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* PylonC functions */
|
/* PylonC functions */
|
||||||
void
|
|
||||||
pylonc_initialize ()
|
|
||||||
{
|
|
||||||
PylonInitialize ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
pylonc_terminate ()
|
pylonc_terminate ()
|
||||||
{
|
{
|
||||||
@ -2764,7 +2942,8 @@ _Bool
|
|||||||
pylonc_connect_camera (GstPylonSrc * src)
|
pylonc_connect_camera (GstPylonSrc * src)
|
||||||
{
|
{
|
||||||
GENAPIC_RESULT res;
|
GENAPIC_RESULT res;
|
||||||
GST_DEBUG_OBJECT (src, "Connecting to the camera...");
|
GST_DEBUG_OBJECT (src, "Connecting to the camera (index=%d)...",
|
||||||
|
src->cameraId);
|
||||||
|
|
||||||
res = PylonCreateDeviceByIndex (src->cameraId, &src->deviceHandle);
|
res = PylonCreateDeviceByIndex (src->cameraId, &src->deviceHandle);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user