pylonsrc: move global variables to be instance variables
This commit is contained in:
parent
c0f68e83d3
commit
2099e46e72
@ -56,10 +56,7 @@ void pylonc_print_camera_info (GstPylonSrc * src,
|
|||||||
void pylonc_initialize ();
|
void pylonc_initialize ();
|
||||||
void pylonc_terminate ();
|
void pylonc_terminate ();
|
||||||
|
|
||||||
_Bool deviceConnected = FALSE;
|
|
||||||
#define NUM_BUFFERS 10
|
|
||||||
unsigned char *buffers[NUM_BUFFERS];
|
|
||||||
PYLON_STREAMBUFFER_HANDLE bufferHandle[NUM_BUFFERS];
|
|
||||||
|
|
||||||
/* debug category */
|
/* debug category */
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_pylonsrc_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_pylonsrc_debug_category);
|
||||||
@ -505,6 +502,8 @@ gst_pylonsrc_init (GstPylonSrc * src)
|
|||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (src, "Initialising defaults");
|
GST_DEBUG_OBJECT (src, "Initialising defaults");
|
||||||
|
|
||||||
|
src->deviceConnected = FALSE;
|
||||||
|
|
||||||
// Default parameter values
|
// Default parameter values
|
||||||
src->continuousMode = TRUE;
|
src->continuousMode = TRUE;
|
||||||
src->limitBandwidth = TRUE;
|
src->limitBandwidth = TRUE;
|
||||||
@ -992,7 +991,7 @@ gst_pylonsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
|
|||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "Received a request for caps.");
|
GST_DEBUG_OBJECT (src, "Received a request for caps.");
|
||||||
if (!deviceConnected) {
|
if (!src->deviceConnected) {
|
||||||
GST_DEBUG_OBJECT (src, "Could not send caps - no camera connected.");
|
GST_DEBUG_OBJECT (src, "Could not send caps - no camera connected.");
|
||||||
return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc));
|
return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc));
|
||||||
} else {
|
} else {
|
||||||
@ -2467,9 +2466,9 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
|
||||||
// Allocate the memory for the frame payloads
|
// Allocate the memory for the frame payloads
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
for (i = 0; i < NUM_CAPTURE_BUFFERS; ++i) {
|
||||||
buffers[i] = (unsigned char *) malloc (src->payloadSize);
|
src->buffers[i] = (unsigned char *) malloc (src->payloadSize);
|
||||||
if (NULL == buffers[i]) {
|
if (NULL == src->buffers[i]) {
|
||||||
GST_ERROR_OBJECT (src, "Memory allocation error.");
|
GST_ERROR_OBJECT (src, "Memory allocation error.");
|
||||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Memory allocation error"),
|
GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Memory allocation error"),
|
||||||
("Couldn't allocate memory."));
|
("Couldn't allocate memory."));
|
||||||
@ -2478,7 +2477,9 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define buffers
|
// Define buffers
|
||||||
res = PylonStreamGrabberSetMaxNumBuffer (src->streamGrabber, NUM_BUFFERS);
|
res =
|
||||||
|
PylonStreamGrabberSetMaxNumBuffer (src->streamGrabber,
|
||||||
|
NUM_CAPTURE_BUFFERS);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
res =
|
res =
|
||||||
PylonStreamGrabberSetMaxBufferSize (src->streamGrabber, src->payloadSize);
|
PylonStreamGrabberSetMaxBufferSize (src->streamGrabber, src->payloadSize);
|
||||||
@ -2488,16 +2489,16 @@ gst_pylonsrc_start (GstBaseSrc * bsrc)
|
|||||||
res = PylonStreamGrabberPrepareGrab (src->streamGrabber);
|
res = PylonStreamGrabberPrepareGrab (src->streamGrabber);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
for (i = 0; i < NUM_CAPTURE_BUFFERS; ++i) {
|
||||||
res =
|
res =
|
||||||
PylonStreamGrabberRegisterBuffer (src->streamGrabber, buffers[i],
|
PylonStreamGrabberRegisterBuffer (src->streamGrabber, src->buffers[i],
|
||||||
src->payloadSize, &bufferHandle[i]);
|
src->payloadSize, &src->bufferHandle[i]);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
for (i = 0; i < NUM_CAPTURE_BUFFERS; ++i) {
|
||||||
res =
|
res =
|
||||||
PylonStreamGrabberQueueBuffer (src->streamGrabber, bufferHandle[i],
|
PylonStreamGrabberQueueBuffer (src->streamGrabber, src->bufferHandle[i],
|
||||||
(void *) i);
|
(void *) i);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
}
|
}
|
||||||
@ -2706,14 +2707,14 @@ pylonc_terminate ()
|
|||||||
void
|
void
|
||||||
pylonc_disconnect_camera (GstPylonSrc * src)
|
pylonc_disconnect_camera (GstPylonSrc * src)
|
||||||
{
|
{
|
||||||
if (deviceConnected) {
|
if (src->deviceConnected) {
|
||||||
if (strcmp (src->reset, "after") == 0) {
|
if (strcmp (src->reset, "after") == 0) {
|
||||||
pylonc_reset_camera (src);
|
pylonc_reset_camera (src);
|
||||||
}
|
}
|
||||||
|
|
||||||
PylonDeviceClose (src->deviceHandle);
|
PylonDeviceClose (src->deviceHandle);
|
||||||
PylonDestroyDevice (src->deviceHandle);
|
PylonDestroyDevice (src->deviceHandle);
|
||||||
deviceConnected = FALSE;
|
src->deviceConnected = FALSE;
|
||||||
GST_DEBUG_OBJECT (src, "Camera disconnected.");
|
GST_DEBUG_OBJECT (src, "Camera disconnected.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2748,7 +2749,7 @@ pylonc_connect_camera (GstPylonSrc * src)
|
|||||||
PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM);
|
PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM);
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
|
||||||
deviceConnected = TRUE;
|
src->deviceConnected = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|||||||
@ -24,6 +24,8 @@
|
|||||||
#include <gst/base/gstpushsrc.h>
|
#include <gst/base/gstpushsrc.h>
|
||||||
#include "pylonc/PylonC.h"
|
#include "pylonc/PylonC.h"
|
||||||
|
|
||||||
|
#define NUM_CAPTURE_BUFFERS 10
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_TYPE_PYLONSRC (gst_pylonsrc_get_type())
|
#define GST_TYPE_PYLONSRC (gst_pylonsrc_get_type())
|
||||||
@ -43,6 +45,10 @@ struct _GstPylonSrc
|
|||||||
PYLON_DEVICE_HANDLE deviceHandle; // Handle for the camera.
|
PYLON_DEVICE_HANDLE deviceHandle; // Handle for the camera.
|
||||||
PYLON_STREAMGRABBER_HANDLE streamGrabber; // Handler for camera's streams.
|
PYLON_STREAMGRABBER_HANDLE streamGrabber; // Handler for camera's streams.
|
||||||
PYLON_WAITOBJECT_HANDLE waitObject; // Handles timing out in the main loop.
|
PYLON_WAITOBJECT_HANDLE waitObject; // Handles timing out in the main loop.
|
||||||
|
gboolean deviceConnected;
|
||||||
|
|
||||||
|
unsigned char *buffers[NUM_CAPTURE_BUFFERS];
|
||||||
|
PYLON_STREAMBUFFER_HANDLE bufferHandle[NUM_CAPTURE_BUFFERS];
|
||||||
|
|
||||||
int32_t frameSize; // Size of a frame in bytes.
|
int32_t frameSize; // Size of a frame in bytes.
|
||||||
int32_t payloadSize; // Size of a frame in bytes.
|
int32_t payloadSize; // Size of a frame in bytes.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user