From 8bd6934d780513c9588c63e7d118a47ccf92a583 Mon Sep 17 00:00:00 2001 From: mrstecklo Date: Thu, 29 Oct 2020 18:02:53 +0300 Subject: [PATCH] pylonsrc: return a copy of src->caps in get_caps; restored variable fps --- .gitignore | 1 + common/genicampixelformat.h | 40 +++++++++++++++++++++++++++++++++++++ sys/pylon/gstpylonsrc.c | 8 +++++--- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c60ad7c..e0bec67 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ Thumbs.db *.cache *.ilk *.log +.vscode [Bb]in [Dd]ebug*/ *.lib diff --git a/common/genicampixelformat.h b/common/genicampixelformat.h index f21c9e7..c68f5bb 100644 --- a/common/genicampixelformat.h +++ b/common/genicampixelformat.h @@ -288,5 +288,45 @@ gst_genicam_pixel_format_caps_from_pixel_format (const char *pixel_format, caps = gst_caps_fixate (caps); + return caps; +} + +static GstCaps * +gst_genicam_pixel_format_caps_from_pixel_format_var (const char *pixel_format, + int endianness, int width, int height) +{ + const char *caps_string; + GstCaps *caps; + GstStructure *structure; + + GST_DEBUG + ("Trying to create caps from: %s, endianness=%d, %dx%d", + pixel_format, endianness, width, height); + + caps_string = + gst_genicam_pixel_format_to_caps_string (pixel_format, endianness); + if (caps_string == NULL) + return NULL; + + GST_DEBUG ("Got caps string: %s", caps_string); + + structure = gst_structure_from_string (caps_string, NULL); + if (structure == NULL) + return NULL; + + gst_structure_set (structure, + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); + + if (g_str_has_prefix (pixel_format, "Bayer")) { + const GstGenicamPixelFormatInfo *info = gst_genicam_pixel_format_get_info(pixel_format, endianness); + g_assert (info); + gst_structure_set(structure, "bpp", G_TYPE_INT, (gint)info->bpp, NULL); + } + + caps = gst_caps_new_empty (); + gst_caps_append_structure (caps, structure); + return caps; } \ No newline at end of file diff --git a/sys/pylon/gstpylonsrc.c b/sys/pylon/gstpylonsrc.c index fe9d9a2..fcece48 100644 --- a/sys/pylon/gstpylonsrc.c +++ b/sys/pylon/gstpylonsrc.c @@ -991,7 +991,9 @@ gst_pylonsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) GST_DEBUG_OBJECT (src, "Could not send caps - no camera connected."); return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)); } else { - return src->caps; + GstCaps* result = gst_caps_copy(src->caps); + + return result; } } @@ -1486,8 +1488,8 @@ gst_pylonsrc_get_supported_caps (GstPylonSrc * src) // TODO: query FPS format_caps = - gst_genicam_pixel_format_caps_from_pixel_format (info->pixel_format, - G_BYTE_ORDER, src->width, src->height, 30, 1, 1, 1); + gst_genicam_pixel_format_caps_from_pixel_format_var (info->pixel_format, + G_BYTE_ORDER, src->width, src->height); if (format_caps) gst_caps_append (caps, format_caps);