Skip to content

Commit

Permalink
Merge branch 'feature/refactor_introspection' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
emmadrigal committed Mar 23, 2023
2 parents fb98493 + 20ee61e commit 58b0c5d
Show file tree
Hide file tree
Showing 22 changed files with 1,220 additions and 623 deletions.
18 changes: 18 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BasedOnStyle: Google
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
SortIncludes: true
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 3
SortPriority: 0
- Regex: '^<.*\.h>'
Priority: 2
SortPriority: 0
- Regex: '^<.*'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0

2 changes: 1 addition & 1 deletion bindings/src/pygstpylon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
# include "config.h"
#endif

#include "bindaccessfunctions.h"
Expand Down
72 changes: 51 additions & 21 deletions ext/pylon/gstpylon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "gst/pylon/gstpyloncache.h"
#include "gst/pylon/gstpylondebug.h"
#include "gst/pylon/gstpylonformatmapping.h"
#include "gst/pylon/gstpylonincludes.h"
#include "gst/pylon/gstpylonmetaprivate.h"
#include "gst/pylon/gstpylonobject.h"
Expand All @@ -46,11 +47,11 @@

#include <map>

/* Pixel format definitions */
typedef struct {
std::string pfnc_name;
std::string gst_name;
} PixelFormatMappingType;
/* retry open camera limits in case of collision with other
* process
*/
constexpr int FAILED_OPEN_RETRY_COUNT = 30;
constexpr int FAILED_OPEN_RETRY_WAIT_TIME_MS = 1000;

/* Mapping of GstStructure with its corresponding formats */
typedef struct {
Expand Down Expand Up @@ -122,19 +123,6 @@ struct _GstPylon {
gint requested_device_index;
};

static const std::vector<PixelFormatMappingType> pixel_format_mapping_raw = {
{"Mono8", "GRAY8"}, {"RGB8Packed", "RGB"},
{"BGR8Packed", "BGR"}, {"RGB8", "RGB"},
{"BGR8", "BGR"}, {"YCbCr422_8", "YUY2"},
{"YUV422_8_UYVY", "UYVY"}, {"YUV422_8", "YUY2"},
{"YUV422Packed", "UYVY"}, {"YUV422_YUYV_Packed", "YUY2"}};

static const std::vector<PixelFormatMappingType> pixel_format_mapping_bayer = {
{"BayerBG8", "bggr"},
{"BayerGR8", "grbg"},
{"BayerRG8", "rggb"},
{"BayerGB8", "gbrg"}};

static const std::vector<GstStPixelFormats> gst_structure_formats = {
{"video/x-raw", pixel_format_mapping_raw},
{"video/x-bayer", pixel_format_mapping_bayer}};
Expand Down Expand Up @@ -264,10 +252,34 @@ GstPylon *gst_pylon_new(GstElement *gstpylonsrc, const gchar *device_user_name,

device_info = device_list.at(device_index);

self->camera->Attach(factory.CreateDevice(device_info));
/* retry loop to start camera
* handles the cornercase of multiprocess pipelines started
* concurrently
*/
for (auto retry_idx = 0; retry_idx <= FAILED_OPEN_RETRY_COUNT;
retry_idx++) {
try {
self->camera->Attach(factory.CreateDevice(device_info));
break;
} catch (GenICam::GenericException &e) {
GST_INFO_OBJECT(gstpylonsrc, "Failed to Open %s (%s)\n",
device_info.GetSerialNumber().c_str(),
e.GetDescription());
/* wait for before new open attempt */
g_usleep(FAILED_OPEN_RETRY_WAIT_TIME_MS * 1000);
}
}
self->camera->Open();

/* Set the camera to a valid state */
/* Set the camera to a valid state
* close left open transactions on the device
*/
self->camera->DeviceFeaturePersistenceEnd.TryExecute();
self->camera->DeviceRegistersStreamingEnd.TryExecute();

/* Set the camera to a valid state
* load the poweron user set
*/
if (self->camera->UserSetSelector.IsWritable()) {
std::string default_set = "Auto";
gst_pylon_apply_set(self, default_set);
Expand Down Expand Up @@ -781,9 +793,11 @@ gboolean gst_pylon_set_configuration(GstPylon *self, const GstCaps *conf,

Pylon::CIntegerParameter width(nodemap, "Width");
width.SetValue(gst_width, Pylon::IntegerValueCorrection_None);
GST_INFO("Set Feature Width: %d", gst_width);

Pylon::CIntegerParameter height(nodemap, "Height");
height.SetValue(gst_height, Pylon::IntegerValueCorrection_None);
GST_INFO("Set Feature Height: %d", gst_height);

Pylon::CBooleanParameter framerate_enable(nodemap,
"AcquisitionFrameRateEnable");
Expand All @@ -792,13 +806,14 @@ gboolean gst_pylon_set_configuration(GstPylon *self, const GstCaps *conf,
framerate_enable.TrySetValue(true);

gdouble div = 1.0 * gst_numerator / gst_denominator;

if (self->camera->GetSfncVersion() >= Pylon::Sfnc_2_0_0) {
Pylon::CFloatParameter framerate(nodemap, "AcquisitionFrameRate");
framerate.TrySetValue(div, Pylon::FloatValueCorrection_None);
GST_INFO("Set Feature AcquisitionFrameRate: %f", div);
} else {
Pylon::CFloatParameter framerate(nodemap, "AcquisitionFrameRateAbs");
framerate.TrySetValue(div, Pylon::FloatValueCorrection_None);
GST_INFO("Set Feature AcquisitionFrameRateAbs: %f", div);
}

} catch (const Pylon::GenericException &e) {
Expand Down Expand Up @@ -894,6 +909,21 @@ static gchar *gst_pylon_get_string_properties(
Pylon::CBaslerUniversalInstantCamera camera(factory.CreateDevice(device),
Pylon::Cleanup_Delete);
camera.Open();

/* Set the camera to a valid state
* close left open transactions on the device
*/
camera.DeviceFeaturePersistenceEnd.TryExecute();
camera.DeviceRegistersStreamingEnd.TryExecute();

/* Set the camera to a valid state
* load the factory default set
*/
if (camera.UserSetSelector.IsWritable()) {
camera.UserSetSelector.SetValue("Default");
camera.UserSetLoad.Execute();
}

get_device_string_properties(&camera, &camera_properties,
DEFAULT_ALIGNMENT);
camera.Close();
Expand Down
2 changes: 1 addition & 1 deletion gst-libs/gst/pylon/gstpylon-prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

#ifndef EXT_PYLONSRC_API
# ifdef BUILDING_EXT_PYLONSRC
# define EXT_PYLONSRC_API GST_API_EXPORT /* from config.h */
# define EXT_PYLONSRC_API GST_PYLON_API_EXPORT /* from config.h */
# else
# define EXT_PYLONSRC_API GST_API_IMPORT
# endif
Expand Down
16 changes: 10 additions & 6 deletions gst-libs/gst/pylon/gstpyloncache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ static std::string gst_pylon_cache_create_filepath(
GstPylonCache::GstPylonCache(const std::string &name)
: filepath(gst_pylon_cache_create_filepath(name)),
feature_cache_dict(g_key_file_new()),
is_empty(TRUE) {}
is_modified(FALSE) {
/* load initial cache file */
if (!LoadCacheFile()) {
GST_LOG("No feature cache file found");
}
}

GstPylonCache::~GstPylonCache() { g_key_file_free(this->feature_cache_dict); }

gboolean GstPylonCache::IsCacheValid() {
gboolean GstPylonCache::LoadCacheFile() {
gboolean ret = TRUE;

/* Check if file exists */
Expand All @@ -88,13 +93,10 @@ gboolean GstPylonCache::IsCacheValid() {
if (!ret) {
return FALSE;
}

this->is_empty = FALSE;

return TRUE;
}

gboolean GstPylonCache::IsEmpty() { return this->is_empty; }
gboolean GstPylonCache::HasNewSettings() { return is_modified; }

void GstPylonCache::CreateCacheFile() {
GError *file_err = NULL;
Expand Down Expand Up @@ -128,12 +130,14 @@ void GstPylonCache::SetIntegerAttribute(const char *feature,
const char *attribute,
const gint64 val) {
g_key_file_set_int64(this->feature_cache_dict, feature, attribute, val);
is_modified = true;
}

void GstPylonCache::SetDoubleAttribute(const char *feature,
const char *attribute,
const gdouble val) {
g_key_file_set_double(this->feature_cache_dict, feature, attribute, val);
is_modified = true;
}

bool GstPylonCache::GetIntegerAttribute(const char *feature,
Expand Down
7 changes: 4 additions & 3 deletions gst-libs/gst/pylon/gstpyloncache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class GST_PLUGIN_EXPORT GstPylonCache {
public:
GstPylonCache(const std::string &name);
~GstPylonCache();
gboolean IsCacheValid();
gboolean IsEmpty();
gboolean HasNewSettings();

void SetIntProps(const gchar *feature_name, const gint64 min,
const gint64 max, const GParamFlags flags);
Expand All @@ -54,6 +53,8 @@ class GST_PLUGIN_EXPORT GstPylonCache {
bool GetDoubleProps(const gchar *feature_name, gdouble &min, gdouble &max,
GParamFlags &flags);

/* Load from file system */
gboolean LoadCacheFile();
/* Persist cache to filesystem */
void CreateCacheFile();

Expand All @@ -70,7 +71,7 @@ class GST_PLUGIN_EXPORT GstPylonCache {

std::string filepath;
GKeyFile *feature_cache_dict;
gboolean is_empty;
gboolean is_modified;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
# include "config.h"
#endif

#include "gstpylondebug.h"

GST_DEBUG_CATEGORY (gst_pylon_debug);
GST_DEBUG_CATEGORY(gst_pylon_debug);

void
gst_pylon_debug_init (void)
{
if (g_once_init_enter (&gst_pylon_debug)) {
GST_DEBUG_CATEGORY (cat_done);
GST_DEBUG_CATEGORY_INIT (cat_done, "pylonsrc", 0,
"debug category for pylonsrc element");
g_once_init_leave (&gst_pylon_debug, cat_done);
void gst_pylon_debug_init(void) {
if (g_once_init_enter(&gst_pylon_debug)) {
GST_DEBUG_CATEGORY(cat_done);
GST_DEBUG_CATEGORY_INIT(cat_done, "pylonsrc", 0,
"debug category for pylonsrc element");
g_once_init_leave(&gst_pylon_debug, cat_done);
}
}
Loading

0 comments on commit 58b0c5d

Please sign in to comment.