diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fd7a3a..2714f11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,69 +54,9 @@ macro_log_feature(GOBJECT_FOUND "GObject" "Required to build gst-plugins-vision" find_package(Orc REQUIRED) macro_log_feature(ORC_FOUND "Orc" "Required library to improve performance" "http://code.entropywave.com/orc/" TRUE) -find_package(Bitflow) -macro_log_feature(BITFLOW_FOUND "BitFlow" "Required to build BitFlow source element" "http://www.bitflow.com/" FALSE) - -find_package(NIIMAQ) -macro_log_feature(NIIMAQ_FOUND "NI-IMAQ" "Required to build National Instruments IMAQ source element" "http://www.ni.com/" FALSE) - -find_package(NIIMAQdx) -macro_log_feature(NIIMAQDX_FOUND "NI-IMAQdx" "Required to build National Instruments IMAQdx source element" "http://www.ni.com/" FALSE) - -find_package(FreeImage) -macro_log_feature(FREEIMAGE_FOUND "FreeImage" "Required to build FreeImage plugin" "http://freeimage.sourceforge.net/" FALSE) - -find_package(OpenCV) -macro_log_feature(OPENCV_FOUND "OpenCV" "Required to build sensorfx plugin" "http://opencv.willowgarage.com/" FALSE) - -find_package(Aptina) -macro_log_feature(APTINA_FOUND "Aptina" "Required to build aptinasrc source element" "http://www.onsemi.com/" FALSE) - -find_package(EDT) -macro_log_feature(EDT_FOUND "EDT" "Required to build EDT PDV source element" "http://www.edt.com/" FALSE) - -find_package(Euresys) -macro_log_feature(EURESYS_FOUND "Euresys" "Required to build Euresys source element" "http://www.euresys.com/" FALSE) - -find_package(GigESim) -macro_log_feature(GIGESIM_FOUND "GigESim" "Required to build A&B Soft GigESim sink element" "http://www.ab-soft.com/" FALSE) - find_package(IDSuEye) macro_log_feature(IDSUEYE_FOUND "IDS uEye" "Required to build IDS uEye source element" "http://en.ids-imaging.com/" FALSE) -find_package(Imperx) -macro_log_feature(IMPERX_FLEX_FOUND "Imperx FrameLink Express" "Required to build Imperx FrameLink Express source element" "http://www.imperx.com/" FALSE) - -find_package(ImperxSDI) -macro_log_feature(IMPERX_SDI_FOUND "Imperx HD-SDI Express" "Required to build Imperx HD-SDI Express source element" "http://www.imperx.com/" FALSE) - -find_package(IOtechDaqX) -macro_log_feature(IOTECHDAQX_FOUND "IOtech DaqX" "Required to build IOtech DaqX source element" "http://www.mccdaq.com/" FALSE) - -find_package(KAYA) -macro_log_feature(KAYA_FOUND "KAYA Vision Point" "Required to build KAYA source element" "http://www.kayainstruments.com/" FALSE) - -find_package(Matrox) -macro_log_feature(MATROX_FOUND "Matrox MIL" "Required to build Matrox MIL source element" "http://www.matrox.com/imaging/" FALSE) - -find_package(Phoenix) -macro_log_feature(PHOENIX_FOUND "Active Silicon Phoenix" "Required to build Active Silicon Phoenix source element" "http://www.activesilicon.com/" FALSE) - -find_package(Pleora) -macro_log_feature(Pleora_FOUND "Pleora eBUS" "Required to build Pleora eBUS source element" "http://www.pleora.com/" FALSE) - -find_package(Pylon) -macro_log_feature(PYLON_FOUND "Basler Pylon" "Required to build Basler Pylon source element" "http://www.baslerweb.com/" FALSE) - -find_package(QCam) -macro_log_feature(QCAM_FOUND "QImaging QCam" "Required to build QImaging QCam source element" "https://www.photometrics.com/qimaging" FALSE) - -find_package(Sapera) -macro_log_feature(SAPERA_FOUND "Teledyne DALSA Sapera" "Required to build Teledyne DALSA Sapera source element" "http://www.teledynedalsa.com/" FALSE) - -find_package(XCLIB) -macro_log_feature(XCLIB_FOUND "EPIX PIXCI" "Required to build EPIX PIXCI source element" "http://www.epixinc.com/" FALSE) - if (WIN32) # Windows distributions of GStreamer include ZLIB set(ZLIB_ROOT ${GSTREAMER_ROOT}) diff --git a/sys/CMakeLists.txt b/sys/CMakeLists.txt index 7a4f0c4..955082f 100644 --- a/sys/CMakeLists.txt +++ b/sys/CMakeLists.txt @@ -1,73 +1,3 @@ -if (APTINA_FOUND) - add_subdirectory(aptina) -endif (APTINA_FOUND) - -if (BITFLOW_FOUND) - add_subdirectory(bitflow) -endif (BITFLOW_FOUND) - -if (EDT_FOUND) - add_subdirectory(edt) -endif (EDT_FOUND) - -if (EURESYS_FOUND) - add_subdirectory (euresys) -endif (EURESYS_FOUND) - -add_subdirectory (gentl) - if (IDSUEYE_FOUND) add_subdirectory (idsueye) endif (IDSUEYE_FOUND) - -if (KAYA_FOUND) - add_subdirectory (kaya) -endif (KAYA_FOUND) - -if (MATROX_FOUND) - add_subdirectory (matrox) -endif (MATROX_FOUND) - -if (NIIMAQ_FOUND) - add_subdirectory (niimaq) -endif (NIIMAQ_FOUND) - -if (NIIMAQDX_FOUND) - add_subdirectory (niimaqdx) -endif (NIIMAQDX_FOUND) - -if (IMPERX_FLEX_FOUND) - add_subdirectory (imperxflex) -endif () - -if (IMPERX_SDI_FOUND) - add_subdirectory (imperxsdi) -endif () - -if (IOTECHDAQX_FOUND) - add_subdirectory (iotechdaqx) -endif (IOTECHDAQX_FOUND) - -if (PHOENIX_FOUND) - add_subdirectory(phoenix) -endif (PHOENIX_FOUND) - -if (Pleora_FOUND) - add_subdirectory(pleora) -endif (Pleora_FOUND) - -if (PYLON_FOUND) - add_subdirectory(pylon) -endif (PYLON_FOUND) - -if (QCAM_FOUND) - add_subdirectory(qcam) -endif (QCAM_FOUND) - -if (SAPERA_FOUND) - add_subdirectory(sapera) -endif (SAPERA_FOUND) - -if (XCLIB_FOUND) - add_subdirectory(pixci) -endif (XCLIB_FOUND) diff --git a/sys/aptina/CMakeLists.txt b/sys/aptina/CMakeLists.txt deleted file mode 100644 index 5a888b5..0000000 --- a/sys/aptina/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -add_definitions(-DHAVE_ORC=TRUE) - -set (SOURCES - gstaptinasrc.c) - -set (HEADERS - gstaptinasrc.h) - -include_directories (AFTER - ${ORC_INCLUDE_DIR} - ${APTINA_INCLUDE_DIR}) - -set (libname gstaptina) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${ORC_LIBRARIES} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${APTINA_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/aptina/gstaptinasrc.c b/sys/aptina/gstaptinasrc.c deleted file mode 100644 index d4a75d5..0000000 --- a/sys/aptina/gstaptinasrc.c +++ /dev/null @@ -1,659 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstaptinasrc - * - * The aptinasrc element is a source for Aptina dev kits. - * - * - * Example launch line - * |[ - * gst-launch -v aptinasrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default Aptina dev kit - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifdef HAVE_ORC -#include -#else -#define orc_memcpy memcpy -#endif - -#include "gstaptinasrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_aptinasrc_debug); -#define GST_CAT_DEFAULT gst_aptinasrc_debug - -/* prototypes */ -static void gst_aptinasrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_aptinasrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_aptinasrc_dispose (GObject * object); -static void gst_aptinasrc_finalize (GObject * object); - -static gboolean gst_aptinasrc_start (GstBaseSrc * src); -static gboolean gst_aptinasrc_stop (GstBaseSrc * src); -static GstCaps *gst_aptinasrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_aptinasrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_aptinasrc_unlock (GstBaseSrc * src); -static gboolean gst_aptinasrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_aptinasrc_fill (GstPushSrc * src, GstBuffer * buf); - -enum -{ - PROP_0, - PROP_DEVICE_INDEX, - PROP_CONFIG_FILE, - PROP_CONFIG_PRESET, - PROP_XSDAT_FILE -}; - -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_CONFIG_FILE "" -#define DEFAULT_PROP_CONFIG_PRESET "" -#define DEFAULT_PROP_XSDAT_FILE "" - -/* pad templates */ - -static GstStaticPadTemplate gst_aptinasrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ BGR, BGRx }") ";" - "video/x-bayer,format=(string){bggr,grbg,gbrg,rggb}," - "width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX];" - "video/x-bayer,format=(string){bggr16,grbg16,gbrg16,rggb16}," - "bpp=(int){10,12,14,16},endianness={1234,4321}," - "width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX]") - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstAptinaSrc, gst_aptinasrc, GST_TYPE_PUSH_SRC); - -static void -gst_aptinasrc_class_init (GstAptinaSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_aptinasrc_set_property; - gobject_class->get_property = gst_aptinasrc_get_property; - gobject_class->dispose = gst_aptinasrc_dispose; - gobject_class->finalize = gst_aptinasrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_aptinasrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Aptina Video Source", "Source/Video", - "Aptina Imaging video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_aptinasrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_aptinasrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_aptinasrc_get_caps); - //gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_aptinasrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_aptinasrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_aptinasrc_unlock_stop); - - gstpushsrc_class->fill = GST_DEBUG_FUNCPTR (gst_aptinasrc_fill); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_int ("device", "Device index", - "Device index", 0, 254, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CONFIG_FILE, - g_param_spec_string ("config-file", "Config file", - "Filepath of the INI file", - DEFAULT_PROP_CONFIG_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_XSDAT_FILE, - g_param_spec_string ("xsdat-file", "xsdat file", - "Filepath of the .xsdat file or directory", - DEFAULT_PROP_CONFIG_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_CONFIG_PRESET, - g_param_spec_string ("config-preset", "Config preset", - "Name of the preset in the INI file to run", - DEFAULT_PROP_CONFIG_PRESET, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -} - -static void -gst_aptinasrc_reset (GstAptinaSrc * src) -{ - src->raw_framesize = 0; - src->out_framesize = 0; - src->convert_to_rgb = FALSE; - - src->is_started = FALSE; - - src->last_frame_count = 0; - src->total_dropped_frames = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->buffer) { - g_free (src->buffer); - src->buffer = NULL; - } -} - -static void -gst_aptinasrc_init (GstAptinaSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->camera_index = DEFAULT_PROP_DEVICE_INDEX; - src->config_file = g_strdup (DEFAULT_PROP_CONFIG_FILE); - src->config_preset = g_strdup (DEFAULT_PROP_CONFIG_PRESET); - src->xsdat_file = g_strdup (DEFAULT_PROP_XSDAT_FILE); - - src->apbase = NULL; - src->stop_requested = FALSE; - src->caps = NULL; - src->buffer = NULL; - - gst_aptinasrc_reset (src); -} - -void -gst_aptinasrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstAptinaSrc *src; - - src = GST_APTINA_SRC (object); - - switch (property_id) { - case PROP_DEVICE_INDEX: - src->camera_index = g_value_get_int (value); - break; - case PROP_CONFIG_FILE: - g_free (src->config_file); - src->config_file = g_strdup (g_value_get_string (value)); - break; - case PROP_CONFIG_PRESET: - g_free (src->config_preset); - src->config_preset = g_strdup (g_value_get_string (value)); - break; - case PROP_XSDAT_FILE: - g_free (src->xsdat_file); - src->xsdat_file = g_strdup (g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_aptinasrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstAptinaSrc *src; - - g_return_if_fail (GST_IS_APTINA_SRC (object)); - src = GST_APTINA_SRC (object); - - switch (property_id) { - case PROP_DEVICE_INDEX: - g_value_set_int (value, src->camera_index); - break; - case PROP_CONFIG_FILE: - g_value_set_string (value, src->config_file); - break; - case PROP_CONFIG_PRESET: - g_value_set_string (value, src->config_preset); - break; - case PROP_XSDAT_FILE: - g_value_set_string (value, src->xsdat_file); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_aptinasrc_dispose (GObject * object) -{ - GstAptinaSrc *src; - - g_return_if_fail (GST_IS_APTINA_SRC (object)); - src = GST_APTINA_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_aptinasrc_parent_class)->dispose (object); -} - -void -gst_aptinasrc_finalize (GObject * object) -{ - GstAptinaSrc *src; - - g_return_if_fail (GST_IS_APTINA_SRC (object)); - src = GST_APTINA_SRC (object); - - /* clean up object here */ - - g_free (src->config_file); - g_free (src->config_preset); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - G_OBJECT_CLASS (gst_aptinasrc_parent_class)->finalize (object); -} - -ap_s32 -handle_error_message (void *pContext, const char *szMessage, - unsigned int mbType) -{ - GstAptinaSrc *src = GST_APTINA_SRC (pContext); - GST_DEBUG_OBJECT (src, "ApBase error: %s", szMessage); - return 1; -} - -static gboolean -gst_aptinasrc_calculate_caps (GstAptinaSrc * src) -{ - ap_u32 ret; - guint32 width, height; - GstVideoInfo vinfo; - char image_type[64]; - gint framesize; - GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN; - gint bayer_bpp = 0; - - framesize = ap_GrabFrame (src->apbase, NULL, 0); - if (framesize != src->raw_framesize) { - src->raw_framesize = framesize; - if (src->buffer) { - g_free (src->buffer); - } - src->buffer = (guint8 *) g_malloc (src->raw_framesize); - } - - ret = ap_GrabFrame (src->apbase, src->buffer, src->raw_framesize); - if (ret == 0) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Grabbing failed with error %d", ap_GetLastError ()), (NULL)); - return FALSE; - } - - ap_GetImageFormat (src->apbase, &width, &height, image_type, - sizeof (image_type)); - GST_DEBUG_OBJECT (src, "Image format is %dx%d '%s'", width, height, - image_type); - - if (g_strcmp0 (image_type, "BAYER-6") == 0) { - bayer_bpp = 6; - } else if (g_strcmp0 (image_type, "BAYER-8") == 0) { - bayer_bpp = 8; - } else if (g_strcmp0 (image_type, "BAYER-10") == 0) { - bayer_bpp = 10; - } else if (g_strcmp0 (image_type, "BAYER-12") == 0) { - bayer_bpp = 12; - } else if (g_strcmp0 (image_type, "BAYER-14") == 0) { - bayer_bpp = 14; - } else if (g_strcmp0 (image_type, "BAYER-16") == 0) { - bayer_bpp = 16; - } else if (g_strcmp0 (image_type, "RGB-24") == 0) { - format = GST_VIDEO_FORMAT_BGR; - } else if (g_strcmp0 (image_type, "RGB-32") == 0) { - format = GST_VIDEO_FORMAT_BGRx; - } else { - GST_WARNING_OBJECT (src, - "Image format not supported yet, will convert to BGRx"); - } - - if (format == GST_VIDEO_FORMAT_UNKNOWN && bayer_bpp == 0) { - ap_u32 rgb_width = 0, rgb_height = 0, rgb_depth = 0; - src->convert_to_rgb = TRUE; - ap_ColorPipe (src->apbase, src->buffer, src->raw_framesize, &rgb_width, - &rgb_height, &rgb_depth); - width = rgb_width; - height = rgb_height; - if (rgb_depth == 24) { - format = GST_VIDEO_FORMAT_BGR; - } else if (rgb_depth == 32) { - format = GST_VIDEO_FORMAT_BGRx; - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Depth is %d, but only 24- and 32-bit supported currently.", - rgb_depth), (NULL)); - return FALSE; - } - } - - if (format != GST_VIDEO_FORMAT_UNKNOWN) { - gst_video_info_init (&vinfo); - gst_video_info_set_format (&vinfo, format, width, height); - if (src->caps) { - gst_caps_unref (src->caps); - } - src->out_framesize = (guint) GST_VIDEO_INFO_SIZE (&vinfo); - src->caps = gst_video_info_to_caps (&vinfo); - } else if (bayer_bpp != 0) { - gint depth; - const char *bay_fmt = NULL; - int xoffset, yoffset; - - if (bayer_bpp <= 8) - depth = 8; - else if (bayer_bpp <= 16) - depth = 16; - else - g_assert_not_reached (); - - xoffset = ap_GetState (src->apbase, "X Offset"); - yoffset = ap_GetState (src->apbase, "Y Offset"); - if (xoffset == 0 && yoffset == 0) { - bay_fmt = (depth == 16) ? "grbg16" : "grbg"; - } else if (xoffset == 0 && yoffset == 1) { - bay_fmt = (depth == 16) ? "bggr16" : "bggr"; - } else if (xoffset == 1 && yoffset == 0) { - bay_fmt = (depth == 16) ? "rggb16" : "rggb"; - } else if (xoffset == 1 && yoffset == 1) { - bay_fmt = (depth == 16) ? "gbrg16" : "gbrg"; - } - - if (depth == 8) { - src->caps = gst_caps_new_simple ("video/x-bayer", - "format", G_TYPE_STRING, bay_fmt, - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION, 30, 1, NULL); - } else if (depth == 16) { - src->caps = gst_caps_new_simple ("video/x-bayer", - "format", G_TYPE_STRING, bay_fmt, - "bpp", G_TYPE_INT, bayer_bpp, - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION, 30, 1, NULL); - } else { - g_assert_not_reached (); - } - src->out_framesize = width * height * depth / 8; - } else { - g_assert_not_reached (); - } - - gst_base_src_set_blocksize (GST_BASE_SRC (src), src->out_framesize); - - gst_base_src_set_caps (GST_BASE_SRC (src), src->caps); - GST_DEBUG_OBJECT (src, "Created caps %" GST_PTR_FORMAT, src->caps); - - return TRUE; -} - -static gboolean -gst_aptinasrc_start (GstBaseSrc * bsrc) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - ap_s32 ret; - gchar *ini_file, *preset; - - GST_DEBUG_OBJECT (src, "start"); - - ap_DeviceProbe (src->xsdat_file); - - //src->apbase = ap_CreateFromImageFile("C:\\temp\\1.jpg"); - src->apbase = ap_Create (src->camera_index); - if (!src->apbase) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Failed to open camera, error=%d", ap_GetLastError ()), (NULL)); - return FALSE; - } - - ap_SetCallback_ErrorMessage (src->apbase, handle_error_message, src); - - //ap_SetState(src->apbase, "Sensor Reset", 1); - //g_usleep(1000000); - //ap_SetState(src->apbase, "Sensor Reset", 0); - //g_usleep(1000000); - - if (!src->config_file || strlen (src->config_file) == 0) { - ini_file = NULL; - } else { - if (!g_file_test (src->config_file, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Camera file does not exist: %s", src->config_file), (NULL)); - return FALSE; - } - ini_file = g_strdup (src->config_file); - } - - if (!src->config_preset || strlen (src->config_preset) == 0) { - preset = NULL; - } else { - preset = g_strdup (src->config_preset); - } - - ret = ap_LoadIniPreset (src->apbase, ini_file, preset); - g_free (ini_file); - g_free (preset); - - if (ret != AP_INI_SUCCESS) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to load INI preset"), (NULL)); - return FALSE; - } - //ap_CheckSensorState(src->apbase, 0); - - if (!gst_aptinasrc_calculate_caps (src)) { - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_aptinasrc_stop (GstBaseSrc * bsrc) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - ap_Destroy (src->apbase); - ap_Finalize (); - - gst_aptinasrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_aptinasrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - GstCaps *caps; - - if (src->caps) { - caps = gst_caps_copy (src->caps); - } else { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_aptinasrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) == GST_VIDEO_FORMAT_UNKNOWN) { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_aptinasrc_unlock (GstBaseSrc * bsrc) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_aptinasrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstAptinaSrc *src = GST_APTINA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstFlowReturn -gst_aptinasrc_fill (GstPushSrc * psrc, GstBuffer * buf) -{ - GstAptinaSrc *src = GST_APTINA_SRC (psrc); - ap_s32 ret; - GstMapInfo minfo; - GstClock *clock; - GstClockTime clock_time; - char *pBuffer = NULL; - static int temp_ugly_buf_index = 0; - - GST_LOG_OBJECT (src, "create"); - - if (!src->is_started) { - /* TODO: check timestamps on buffers vs start time */ - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - - src->is_started = TRUE; - } - - ret = ap_GrabFrame (src->apbase, src->buffer, src->raw_framesize); - if (ret == 0) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Grabbing failed with error %d", ap_GetLastError ()), (NULL)); - return GST_FLOW_ERROR; - } - - clock = gst_element_get_clock (GST_ELEMENT (src)); - clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - if (src->convert_to_rgb) { - guint8 *unpacked; - ap_u32 rgb_width = 0, rgb_height = 0, rgb_depth = 0; - unpacked = - ap_ColorPipe (src->apbase, src->buffer, src->raw_framesize, &rgb_width, - &rgb_height, &rgb_depth); - orc_memcpy (minfo.data, unpacked, (int) minfo.size); - } else { - orc_memcpy (minfo.data, src->buffer, (int) minfo.size); - } - gst_buffer_unmap (buf, &minfo); - - GST_BUFFER_TIMESTAMP (buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - clock_time); - GST_BUFFER_OFFSET (buf) = temp_ugly_buf_index++; - - if (src->stop_requested) { - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_aptinasrc_debug, "aptinasrc", 0, - "debug category for aptinasrc element"); - gst_element_register (plugin, "aptinasrc", GST_RANK_NONE, - gst_aptinasrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - aptina, - "Aptina camera source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/aptina/gstaptinasrc.h b/sys/aptina/gstaptinasrc.h deleted file mode 100644 index 4f2700a..0000000 --- a/sys/aptina/gstaptinasrc.h +++ /dev/null @@ -1,73 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_APTINA_SRC_H_ -#define _GST_APTINA_SRC_H_ - -#include - -#include "apbase.h" - -G_BEGIN_DECLS - -#define GST_TYPE_APTINA_SRC (gst_aptinasrc_get_type()) -#define GST_APTINA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_APTINA_SRC,GstAptinaSrc)) -#define GST_APTINA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_APTINA_SRC,GstAptinaSrcClass)) -#define GST_IS_APTINA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_APTINA_SRC)) -#define GST_IS_APTINA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_APTINA_SRC)) - -typedef struct _GstAptinaSrc GstAptinaSrc; -typedef struct _GstAptinaSrcClass GstAptinaSrcClass; - -struct _GstAptinaSrc -{ - GstPushSrc base_aptinasrc; - - AP_HANDLE apbase; - gboolean is_started; - - /* properties */ - gint camera_index; - gchar *config_file; - gchar *config_preset; - gchar *xsdat_file; - - GstClockTime acq_start_time; - guint32 last_frame_count; - guint32 total_dropped_frames; - - GstCaps *caps; - gint raw_framesize; - guint out_framesize; - gboolean convert_to_rgb; - guint8 *buffer; - - gboolean stop_requested; -}; - -struct _GstAptinaSrcClass -{ - GstPushSrcClass base_aptinasrc_class; -}; - -GType gst_aptinasrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/bitflow/CMakeLists.txt b/sys/bitflow/CMakeLists.txt deleted file mode 100644 index e67b90b..0000000 --- a/sys/bitflow/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstbitflowsrc.c) - -set (HEADERS - gstbitflowsrc.h) - -include_directories (AFTER - ${BITFLOW_INCLUDE_DIR}) - -set (libname gstbitflow) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${BITFLOW_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/bitflow/gstbitflowsrc.c b/sys/bitflow/gstbitflowsrc.c deleted file mode 100644 index b0efb8e..0000000 --- a/sys/bitflow/gstbitflowsrc.c +++ /dev/null @@ -1,648 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstbitflowsrc - * - * The bitflowsrc element is a source for BitFlow framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v bitflowsrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default BitFlow framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstbitflowsrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_bitflowsrc_debug); -#define GST_CAT_DEFAULT gst_bitflowsrc_debug - -/* prototypes */ -static void gst_bitflowsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_bitflowsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_bitflowsrc_dispose (GObject * object); -static void gst_bitflowsrc_finalize (GObject * object); - -static gboolean gst_bitflowsrc_start (GstBaseSrc * src); -static gboolean gst_bitflowsrc_stop (GstBaseSrc * src); -static GstCaps *gst_bitflowsrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_bitflowsrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_bitflowsrc_unlock (GstBaseSrc * src); -static gboolean gst_bitflowsrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_bitflowsrc_create (GstPushSrc * src, GstBuffer ** buf); - -static gchar *gst_bitflowsrc_get_error_string (GstBitflowSrc * src, - BIRC error_num); - -enum -{ - PROP_0, - PROP_CAMERA_FILE, - PROP_NUM_CAPTURE_BUFFERS, - PROP_BOARD, - PROP_TIMEOUT -}; - -#define DEFAULT_PROP_CAMERA_FILE "" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_BOARD 0 -#define DEFAULT_PROP_TIMEOUT 1000 - -/* pad templates */ - -static GstStaticPadTemplate gst_bitflowsrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGRA }")) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstBitflowSrc, gst_bitflowsrc, GST_TYPE_PUSH_SRC); - -static void -gst_bitflowsrc_class_init (GstBitflowSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_bitflowsrc_set_property; - gobject_class->get_property = gst_bitflowsrc_get_property; - gobject_class->dispose = gst_bitflowsrc_dispose; - gobject_class->finalize = gst_bitflowsrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_bitflowsrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "BitFlow Video Source", "Source/Video", - "BitFlow framegrabber video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_bitflowsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_bitflowsrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_bitflowsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_bitflowsrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_bitflowsrc_unlock); - gstbasesrc_class->unlock_stop = - GST_DEBUG_FUNCPTR (gst_bitflowsrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_bitflowsrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_CAMERA_FILE, - g_param_spec_string ("config-file", "Config file", - "Filepath of the video file for the selected camera", - DEFAULT_PROP_CAMERA_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_uint ("board", "Board", "Board number", 0, 7, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - -} - -static void -gst_bitflowsrc_reset (GstBitflowSrc * src) -{ - src->board = NULL; - memset (&src->buffer_array, 0, sizeof (src->buffer_array)); - src->error_string[0] = 0; - src->last_frame_count = 0; - src->total_dropped_frames = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } -} - -static void -gst_bitflowsrc_init (GstBitflowSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->camera_file = g_strdup (DEFAULT_PROP_CAMERA_FILE); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->board_index = DEFAULT_PROP_BOARD; - src->timeout = DEFAULT_PROP_TIMEOUT; - - src->stop_requested = FALSE; - src->caps = NULL; - - gst_bitflowsrc_reset (src); -} - -void -gst_bitflowsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstBitflowSrc *src; - - src = GST_BITFLOW_SRC (object); - - switch (property_id) { - case PROP_CAMERA_FILE: - g_free (src->camera_file); - src->camera_file = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - src->num_capture_buffers = g_value_get_uint (value); - break; - case PROP_BOARD: - src->board_index = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_bitflowsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstBitflowSrc *src; - - g_return_if_fail (GST_IS_BITFLOW_SRC (object)); - src = GST_BITFLOW_SRC (object); - - switch (property_id) { - case PROP_CAMERA_FILE: - g_value_set_string (value, src->camera_file); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_uint (value, src->board_index); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_bitflowsrc_dispose (GObject * object) -{ - GstBitflowSrc *src; - - g_return_if_fail (GST_IS_BITFLOW_SRC (object)); - src = GST_BITFLOW_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_bitflowsrc_parent_class)->dispose (object); -} - -void -gst_bitflowsrc_finalize (GObject * object) -{ - GstBitflowSrc *src; - - g_return_if_fail (GST_IS_BITFLOW_SRC (object)); - src = GST_BITFLOW_SRC (object); - - /* clean up object here */ - g_free (src->camera_file); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - G_OBJECT_CLASS (gst_bitflowsrc_parent_class)->finalize (object); -} - -static gboolean -gst_bitflowsrc_start (GstBaseSrc * bsrc) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - BFRC ret; - guint32 width, height, bpp, stride; - GstVideoInfo vinfo; - - GST_DEBUG_OBJECT (src, "start"); - - if (strlen (src->camera_file)) { - if (!g_file_test (src->camera_file, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Camera file does not exist: %s", src->camera_file), (NULL)); - return FALSE; - } - - ret = - BiBrdOpenCam (BiTypeAny, src->board_index, &src->board, - src->camera_file); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Board could not be opened with camera file: %s", src->camera_file), - (NULL)); - return FALSE; - } - } else { - /* use default camera file set in SysReg */ - ret = BiBrdOpen (BiTypeAny, src->board_index, &src->board); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Board could not be opened with default camera file"), (NULL)); - return FALSE; - } - } - - { - BFCHAR ModelSt[MAX_STRING]; - BFCHAR FamilySt[MAX_STRING]; - BFU32 FamilyIndex; - BFU32 CiFamily; - BFGetBoardStrings (src->board, ModelSt, MAX_STRING, FamilySt, MAX_STRING, - &FamilyIndex, &CiFamily); - - GST_DEBUG_OBJECT (src, "Board \"%s(%d) - %s\" has been opened.\n", FamilySt, - src->board_index, ModelSt); - } - - ret = - BiBufferAllocCam (src->board, &src->buffer_array, - src->num_capture_buffers); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate buffers: %s", gst_bitflowsrc_get_error_string (src, - ret)), (NULL)); - BiBrdClose (src->board); - return FALSE; - } - - /* CirErIgnore will cause "tearing" if buffers aren't handled fast enough */ - /* TODO: CirErLast and CirErNew might be available in some hardware, - which would prevent tearing but would drop frames */ - ret = - BiCircAqSetup (src->board, &src->buffer_array, CirErIgnore, - BiAqEngJ | NoResetOnError | UseHighResTimer); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to setup circular acquisition: %s", - gst_bitflowsrc_get_error_string (src, ret)), (NULL)); - BiBufferFree (src->board, &src->buffer_array); - BiBrdClose (src->board); - return FALSE; - } - - /* BiCamInqFormat gets tap config, see BFFormatStandard */ - /* BiCamInqCamType gets line/area, see BFCamTypeAreaScan */ - /* BiCamInqBytesPerPix gets bytes per pixel */ - /* BiCamInqFrameSize0 gets total frame size */ - BiBrdInquire (src->board, BiCamInqXSize, &width); - BiBrdInquire (src->board, BiCamInqYSize0, &height); - BiBrdInquire (src->board, BiCamInqBitsPerPix, &bpp); - BiBrdInquire (src->board, BiCamInqFrameWidth, &stride); - - /* create caps */ - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - gst_video_info_init (&vinfo); - - if (bpp <= 8) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height); - src->caps = gst_video_info_to_caps (&vinfo); - } else if (bpp > 8 && bpp <= 16) { - GValue val = G_VALUE_INIT; - GstStructure *s; - - if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width, - height); - } else if (G_BYTE_ORDER == G_BIG_ENDIAN) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_BE, width, - height); - } - src->caps = gst_video_info_to_caps (&vinfo); - - /* set bpp, extra info for GRAY16 so elements can scale properly */ - s = gst_caps_get_structure (src->caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, bpp); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Unknown or unsupported bit depth (%d).", bpp), (NULL)); - return FALSE; - } - - src->height = vinfo.height; - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - src->bf_stride = stride; - - GST_DEBUG_OBJECT (src, "starting acquisition"); - ret = BiCirControl (src->board, &src->buffer_array, BISTART, BiWait); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to start grabbing: %s", gst_bitflowsrc_get_error_string (src, - ret)), (NULL)); - BiCircCleanUp (src->board, &src->buffer_array); - BiBufferFree (src->board, &src->buffer_array); - BiBrdClose (src->board); - return GST_FLOW_ERROR; - } - - /* TODO: check timestamps on buffers vs start time */ - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - - return TRUE; -} - -static gboolean -gst_bitflowsrc_stop (GstBaseSrc * bsrc) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - BFRC ret; - GST_DEBUG_OBJECT (src, "stop"); - - ret = BiCircCleanUp (src->board, &src->buffer_array); - if (ret != BI_OK) { - GST_WARNING_OBJECT (src, "Failed to cleanup circular acquisition: %s", - gst_bitflowsrc_get_error_string (src, ret)); - } - - ret = BiBufferFree (src->board, &src->buffer_array); - if (ret != BI_OK) { - GST_WARNING_OBJECT (src, "Failed to free buffer array: %s", - gst_bitflowsrc_get_error_string (src, ret)); - } - - ret = BiBrdClose (src->board); - if (ret != BI_OK) { - GST_WARNING_OBJECT (src, "Failed to free buffer array: %s", - gst_bitflowsrc_get_error_string (src, ret)); - } - - gst_bitflowsrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_bitflowsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - GstCaps *caps; - - if (src->board == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_bitflowsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_bitflowsrc_unlock (GstBaseSrc * bsrc) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_bitflowsrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstBuffer * -gst_bitflowsrc_create_buffer_from_circ_handle (GstBitflowSrc * src, - BiCirHandle * circ_handle) -{ - GstMapInfo minfo; - GstBuffer *buf; - - /* TODO: use allocator or use from pool */ - buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - /* Copy image to buffer from surface */ - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (src, - "GstBuffer size=%d, gst_stride=%d, buffer_num=%d, frame_count=%d, num_frames_on_queue=%d", - minfo.size, src->gst_stride, circ_handle->BufferNumber, - circ_handle->FrameCount, circ_handle->NumItemsOnQueue); - GST_LOG_OBJECT (src, "Buffer timestamp %02d:%02d:%02d.%06d", - circ_handle->HiResTimeStamp.hour, circ_handle->HiResTimeStamp.min, - circ_handle->HiResTimeStamp.sec, circ_handle->HiResTimeStamp.usec); - - /* TODO: use orc_memcpy */ - if (src->gst_stride == src->bf_stride) { - memcpy (minfo.data, ((guint8 *) circ_handle->pBufData), minfo.size); - } else { - int i; - GST_LOG_OBJECT (src, "Image strides not identical, copy will be slower."); - for (i = 0; i < src->height; i++) { - memcpy (minfo.data + i * src->gst_stride, - ((guint8 *) circ_handle->pBufData) + - i * src->bf_stride, src->bf_stride); - } - } - gst_buffer_unmap (buf, &minfo); - - return buf; -} - -static GstFlowReturn -gst_bitflowsrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstBitflowSrc *src = GST_BITFLOW_SRC (psrc); - BFRC ret; - BiCirHandle circ_handle; - guint32 dropped_frames; - GstClock *clock; - GstClockTime clock_time; - - GST_LOG_OBJECT (src, "create"); - - /* wait for next frame to be available */ - ret = BiCirWaitDoneFrame (src->board, &src->buffer_array, - src->timeout, &circ_handle); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to acquire frame: %s", gst_bitflowsrc_get_error_string (src, - ret)), (NULL)); - return GST_FLOW_ERROR; - } - - clock = gst_element_get_clock (GST_ELEMENT (src)); - clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - - /* check for dropped frames and disrupted signal */ - dropped_frames = (circ_handle.FrameCount - src->last_frame_count) - 1; - if (dropped_frames > 0) { - src->total_dropped_frames += dropped_frames; - GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - src->total_dropped_frames); - } else if (dropped_frames < 0) { - GST_WARNING_OBJECT (src, "Frame count non-monotonic, signal disrupted?"); - } - src->last_frame_count = circ_handle.FrameCount; - - /* create GstBuffer then release circ buffer back to acquisition */ - *buf = gst_bitflowsrc_create_buffer_from_circ_handle (src, &circ_handle); - ret = - BiCirStatusSet (src->board, &src->buffer_array, circ_handle, BIAVAILABLE); - if (ret != BI_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to release buffer: %s", gst_bitflowsrc_get_error_string (src, - ret)), (NULL)); - return GST_FLOW_ERROR; - } - - /* TODO: understand why timestamps for circ_handle are sometimes 0 */ - //GST_BUFFER_TIMESTAMP (*buf) = - // GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - // src->acq_start_time + circ_handle.HiResTimeStamp.totalSec * GST_SECOND); - GST_BUFFER_TIMESTAMP (*buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - clock_time); - GST_BUFFER_OFFSET (*buf) = circ_handle.FrameCount - 1; - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - -gchar * -gst_bitflowsrc_get_error_string (GstBitflowSrc * src, BIRC error_num) -{ - BFU32 error_string_size = MAX_STRING; - BiErrorTextGet (src->board, error_num, src->error_string, &error_string_size); - return src->error_string; -} - - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_bitflowsrc_debug, "bitflowsrc", 0, - "debug category for bitflowsrc element"); - gst_element_register (plugin, "bitflowsrc", GST_RANK_NONE, - gst_bitflowsrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - bitflow, - "BitFlow frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/bitflow/gstbitflowsrc.h b/sys/bitflow/gstbitflowsrc.h deleted file mode 100644 index 05a2430..0000000 --- a/sys/bitflow/gstbitflowsrc.h +++ /dev/null @@ -1,74 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_BITFLOW_SRC_H_ -#define _GST_BITFLOW_SRC_H_ - -#include - -#include "BiApi.h" - -G_BEGIN_DECLS - -#define GST_TYPE_BITFLOW_SRC (gst_bitflowsrc_get_type()) -#define GST_BITFLOW_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BITFLOW_SRC,GstBitflowSrc)) -#define GST_BITFLOW_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BITFLOW_SRC,GstBitflowSrcClass)) -#define GST_IS_BITFLOW_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BITFLOW_SRC)) -#define GST_IS_BITFLOW_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BITFLOW_SRC)) - -typedef struct _GstBitflowSrc GstBitflowSrc; -typedef struct _GstBitflowSrcClass GstBitflowSrcClass; - -struct _GstBitflowSrc -{ - GstPushSrc base_bitflowsrc; - - /* camera handle */ - Bd board; - BIBA buffer_array; - BFCHAR error_string[MAX_STRING]; - - /* properties */ - gchar *camera_file; - guint num_capture_buffers; - guint board_index; - gint timeout; - - GstClockTime acq_start_time; - guint32 last_frame_count; - guint32 total_dropped_frames; - - GstCaps *caps; - gint height; - gint gst_stride; - gint bf_stride; - - gboolean stop_requested; -}; - -struct _GstBitflowSrcClass -{ - GstPushSrcClass base_bitflowsrc_class; -}; - -GType gst_bitflowsrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/edt/CMakeLists.txt b/sys/edt/CMakeLists.txt deleted file mode 100644 index 116f7b5..0000000 --- a/sys/edt/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set (SOURCES - gstedt.c - gstedtpdvsink.c - gstedtpdvsrc.c) - -set (HEADERS - gstedtpdvsink.h - gstedtpdvsrc.h) - -include_directories (AFTER - ${EDT_INCLUDE_DIR}) - -set (libname gstedt) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${EDT_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/edt/gstedt.c b/sys/edt/gstedt.c deleted file mode 100644 index b0736eb..0000000 --- a/sys/edt/gstedt.c +++ /dev/null @@ -1,35 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstedtpdvsink.h" -#include "gstedtpdvsrc.h" - -#define GST_CAT_DEFAULT gst_gstedt_debug -GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "edt", 0, - "debug category for EDT elements"); - - if (!gst_element_register (plugin, "edtpdvsink", GST_RANK_NONE, - GST_TYPE_EDT_PDV_SINK)) { - return FALSE; - } - - if (!gst_element_register (plugin, "edtpdvsrc", GST_RANK_NONE, - GST_TYPE_EDT_PDV_SRC)) { - return FALSE; - } - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - edt, - "EDT PDV elements", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/edt/gstedtpdvsink.c b/sys/edt/gstedtpdvsink.c deleted file mode 100644 index 0c46edf..0000000 --- a/sys/edt/gstedtpdvsink.c +++ /dev/null @@ -1,320 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstedtpdvsink - * - * The edtpdvsink element is a sink for Camera Link simulators supported by the EDT PDV driver. - * - * - * Example launch line - * |[ - * gst-launch -v videotestsrc ! ffmpegcolorspace ! edtpdvsink - * ]| - * Outputs test video on the default EDT Camera Link channel. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include -#include - -#include "gstedtpdvsink.h" - -/* GObject prototypes */ -static void gst_edt_pdv_sink_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_edt_pdv_sink_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_edt_pdv_sink_dispose (GObject * object); - -/* GstBaseSink prototypes */ -static gboolean gst_edt_pdv_sink_start (GstBaseSink * basesink); -static gboolean gst_edt_pdv_sink_stop (GstBaseSink * basesink); -static GstCaps *gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, - GstCaps * filter_caps); -static gboolean gst_edt_pdv_sink_set_caps (GstBaseSink * basesink, - GstCaps * caps); -static GstFlowReturn gst_edt_pdv_sink_render (GstBaseSink * basesink, - GstBuffer * buffer); - -enum -{ - PROP_0 -}; - - -/* pad templates */ - -static GstStaticPadTemplate gst_edt_pdv_sink_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ GRAY8 }")) - ); - -/* class initialization */ - -/* setup debug */ -GST_DEBUG_CATEGORY_STATIC (edtpdvsink_debug); -#define GST_CAT_DEFAULT edtpdvsink_debug - -G_DEFINE_TYPE (GstEdtPdvSink, gst_edt_pdv_sink, GST_TYPE_BASE_SINK); - -static void -gst_edt_pdv_sink_class_init (GstEdtPdvSinkClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "edtpdvsink", 0, - "EDT PDV Camera Link simulator sink"); - - gobject_class->set_property = gst_edt_pdv_sink_set_property; - gobject_class->get_property = gst_edt_pdv_sink_get_property; - gobject_class->dispose = gst_edt_pdv_sink_dispose; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_edt_pdv_sink_sink_template)); - - gst_element_class_set_details_simple (gstelement_class, - "EDT PDV Sink", "Sink/Video", - "EDT PDV Sink for Camera Link simulator boards", - "Joshua M. Doe "); - - gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_edt_pdv_sink_start); - gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_edt_pdv_sink_stop); - gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_sink_set_caps); - gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_sink_get_caps); - gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_edt_pdv_sink_render); -} - -static void -gst_edt_pdv_sink_init (GstEdtPdvSink * pdvsink) -{ - pdvsink->dev = NULL; - pdvsink->buffers = NULL; - pdvsink->n_buffers = 2; - pdvsink->cur_buffer = 0; - - /* TODO: put these in properties */ - pdvsink->unit = 0; - pdvsink->channel = 0; -} - -void -gst_edt_pdv_sink_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstEdtPdvSink *pdvsink; - - g_return_if_fail (GST_IS_EDT_PDV_SINK (object)); - pdvsink = GST_EDT_PDV_SINK (object); - - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_edt_pdv_sink_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstEdtPdvSink *pdvsink; - - g_return_if_fail (GST_IS_EDT_PDV_SINK (object)); - pdvsink = GST_EDT_PDV_SINK (object); - - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_edt_pdv_sink_dispose (GObject * object) -{ - GstEdtPdvSink *pdvsink; - - g_return_if_fail (GST_IS_EDT_PDV_SINK (object)); - pdvsink = GST_EDT_PDV_SINK (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_edt_pdv_sink_parent_class)->dispose (object); -} - -gboolean -gst_edt_pdv_sink_start (GstBaseSink * basesink) -{ - GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); - - GST_DEBUG_OBJECT (pdvsink, "Starting"); - - pdvsink->dev = pdv_open_channel ("pdv", pdvsink->unit, pdvsink->channel); - if (pdvsink->dev == NULL) { - GST_ELEMENT_ERROR (pdvsink, RESOURCE, OPEN_WRITE, - ("Unable to open unit %d, channel %d", pdvsink->unit, pdvsink->channel), - (NULL)); - return FALSE; - } - - if (!pdv_is_simulator (pdvsink->dev)) { - GST_ELEMENT_ERROR (pdvsink, RESOURCE, OPEN_WRITE, - ("EDT unit is not a simulator."), (NULL)); - pdv_close (pdvsink->dev); - } - - /* FIXME: set timeout to wait forever, shouldn't do this of course */ - edt_set_wtimeout (pdvsink->dev, 0); - edt_set_rtimeout (pdvsink->dev, 0); - - pdv_flush_fifo (pdvsink->dev); - - /* turn off counter data so we can DMA our own image data */ - pdv_cls_set_datacnt (pdvsink->dev, 0); - - pdvsink->cur_buffer = 0; - - return TRUE; -} - -gboolean -gst_edt_pdv_sink_stop (GstBaseSink * basesink) -{ - GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); - - if (pdvsink->dev) - pdv_close (pdvsink->dev); - - return TRUE; -} - -GstCaps * -gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps) -{ - GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); - gint width, height, depth; - GstVideoFormat format; - GstVideoInfo vinfo; - - if (!pdvsink->dev) { - return gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD - (pdvsink))); - } - - gst_video_info_init (&vinfo); - width = pdv_get_width (pdvsink->dev); - height = pdv_get_height (pdvsink->dev); - depth = pdv_get_depth (pdvsink->dev); - - switch (depth) { - case 8: - format = GST_VIDEO_FORMAT_GRAY8; - break; - case 16: - /* TODO: will this be host order or always one of BE/LE? */ - format = GST_VIDEO_FORMAT_GRAY16_BE; - break; - default: - format = GST_VIDEO_FORMAT_UNKNOWN; - } - gst_video_info_set_format (&vinfo, format, width, height); - - /* TODO: handle filter_caps */ - return gst_video_info_to_caps (&vinfo); -} - -gboolean -gst_edt_pdv_sink_set_caps (GstBaseSink * basesink, GstCaps * caps) -{ - GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); - int buffer_size; - gint depth; - int taps; - GstVideoInfo vinfo; - - GST_DEBUG_OBJECT (pdvsink, "Caps being set"); - - gst_video_info_from_caps (&vinfo, caps); - - depth = GST_VIDEO_INFO_COMP_DEPTH (&vinfo, 0); - buffer_size = vinfo.height * pdv_bytes_per_line (vinfo.width, depth); - - GST_DEBUG_OBJECT (pdvsink, - "Configuring EDT ring buffer with %d buffers each of size %d", - pdvsink->n_buffers, buffer_size); - - /* we'll use just two buffers and ping pong between them */ - edt_configure_ring_buffers (pdvsink->dev, buffer_size, pdvsink->n_buffers, - EDT_WRITE, NULL); - - pdvsink->buffers = edt_buffer_addresses (pdvsink->dev); - - taps = pdvsink->dev->dd_p->cls.taps; - - /* TODO: handle RGB correctly */ - if (depth == 24) { - taps = 1; - depth = 32; - } - - if (taps == 0) { - GST_WARNING_OBJECT (pdvsink, "Taps set to 0, changing to 1"); - taps = 1; - } - - GST_DEBUG_OBJECT (pdvsink, "Configuring simulator with %d taps", taps); - - /* configure simulator */ - pdv_cls_set_size (pdvsink->dev, taps, depth, vinfo.width, vinfo.height, PDV_CLS_DEFAULT_HGAP, (vinfo.width / taps) + PDV_CLS_DEFAULT_HGAP, // taps=1 - PDV_CLS_DEFAULT_VGAP, vinfo.height + PDV_CLS_DEFAULT_VGAP); - - GST_DEBUG ("Configured simulator"); - - return TRUE; -} - -GstFlowReturn -gst_edt_pdv_sink_render (GstBaseSink * basesink, GstBuffer * buffer) -{ - GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); - GstMapInfo minfo; - - GST_LOG_OBJECT (pdvsink, "Rendering buffer"); - - gst_buffer_map (buffer, &minfo, GST_MAP_WRITE); - /* TODO: fix stride? */ - memcpy (pdvsink->buffers[pdvsink->cur_buffer], minfo.data, minfo.size); - gst_buffer_unmap (buffer, &minfo); - - edt_start_buffers (pdvsink->dev, 1); - pdvsink->cur_buffer = (pdvsink->cur_buffer + 1) % pdvsink->n_buffers; - - return GST_FLOW_OK; -} diff --git a/sys/edt/gstedtpdvsink.h b/sys/edt/gstedtpdvsink.h deleted file mode 100644 index da36ff7..0000000 --- a/sys/edt/gstedtpdvsink.h +++ /dev/null @@ -1,59 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_EDT_PDV_SINK_H_ -#define _GST_EDT_PDV_SINK_H_ - -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_EDT_PDV_SINK (gst_edt_pdv_sink_get_type()) -#define GST_EDT_PDV_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EDT_PDV_SINK,GstEdtPdvSink)) -#define GST_EDT_PDV_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EDT_PDV_SINK,GstEdtPdvSinkClass)) -#define GST_IS_EDT_PDV_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDT_PDV_SINK)) -#define GST_IS_EDT_PDV_SINK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDT_PDV_SINK)) - -typedef struct _GstEdtPdvSink GstEdtPdvSink; -typedef struct _GstEdtPdvSinkClass GstEdtPdvSinkClass; - -struct _GstEdtPdvSink -{ - GstBaseSink base; - - PdvDev *dev; - int unit; - int channel; - - unsigned char **buffers; - int n_buffers; - int cur_buffer; -}; - -struct _GstEdtPdvSinkClass -{ - GstBaseSinkClass base_class; -}; - -GType gst_edt_pdv_sink_get_type (void); - -G_END_DECLS - -#endif /* _GST_EDT_PDV_SINK_H_ */ \ No newline at end of file diff --git a/sys/edt/gstedtpdvsrc.c b/sys/edt/gstedtpdvsrc.c deleted file mode 100644 index 7d7f5b6..0000000 --- a/sys/edt/gstedtpdvsrc.c +++ /dev/null @@ -1,480 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstedt_pdv_src - * - * The edtpdvsrc element is a source for EDT framegrabbers supported by the EDT PDV library. - * - * - * Example launch line - * |[ - * gst-launch -v edtpdvsrc ! ffmpegcolorspace ! autovideosink - * ]| - * Shows video from the default camera source (unit 0, channel 0). - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstedtpdvsrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_edt_pdv_src_debug); -#define GST_CAT_DEFAULT gst_edt_pdv_src_debug - -/* prototypes */ -static void gst_edt_pdv_src_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_edt_pdv_src_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_edt_pdv_src_dispose (GObject * object); -static void gst_edt_pdv_src_finalize (GObject * object); - -static gboolean gst_edt_pdv_src_start (GstBaseSrc * src); -static gboolean gst_edt_pdv_src_stop (GstBaseSrc * src); -static GstCaps *gst_edt_pdv_src_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_edt_pdv_src_set_caps (GstBaseSrc * src, GstCaps * caps); - -static GstFlowReturn gst_edt_pdv_src_create (GstPushSrc * src, - GstBuffer ** buf); - -static GstCaps *gst_edt_pdv_src_create_caps (GstEdtPdvSrc * src); -static void gst_edt_pdv_src_reset (GstEdtPdvSrc * src); -enum -{ - PROP_0, - PROP_UNIT, - PROP_CHANNEL, - PROP_CONFIG_FILE, - PROP_NUM_RING_BUFFERS -}; - -#define DEFAULT_PROP_UNIT 0 -#define DEFAULT_PROP_CHANNEL 0 -#define DEFAULT_PROP_NUM_RING_BUFFERS 4 - -/* pad templates */ - -static GstStaticPadTemplate gst_edt_pdv_src_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, RGB }")) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstEdtPdvSrc, gst_edt_pdv_src, GST_TYPE_PUSH_SRC); - -static void -gst_edt_pdv_src_class_init (GstEdtPdvSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "edtpdvsrc", 0, - "EDT PDV Camera Link source"); - - gobject_class->set_property = gst_edt_pdv_src_set_property; - gobject_class->get_property = gst_edt_pdv_src_get_property; - gobject_class->dispose = gst_edt_pdv_src_dispose; - gobject_class->finalize = gst_edt_pdv_src_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_edt_pdv_src_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "EDT PDV Video Source", "Source/Video", - "EDT PDV framegrabber video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_set_caps); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_UNIT, - g_param_spec_uint ("unit", "Unit", "Unit number", 0, G_MAXUINT, - DEFAULT_PROP_UNIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_CHANNEL, - g_param_spec_uint ("channel", "Channel", "Channel number (0 for auto)", 0, - G_MAXUINT, DEFAULT_PROP_CHANNEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_CONFIG_FILE, - g_param_spec_string ("config-file", "Config file", - "Camera configuration path (empty or NULL to use previous config)", - NULL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_RING_BUFFERS, - g_param_spec_uint ("num-ring-buffers", "Number of ring buffers", - "Number of ring buffers to use for DMAing frames from card", 1, - G_MAXUINT, DEFAULT_PROP_NUM_RING_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -} - -static void -gst_edt_pdv_src_init (GstEdtPdvSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize properties */ - src->unit = DEFAULT_PROP_UNIT; - src->channel = DEFAULT_PROP_CHANNEL; - src->config_file_path = NULL; - src->num_ring_buffers = DEFAULT_PROP_NUM_RING_BUFFERS; - - gst_edt_pdv_src_reset (src); -} - -static void -gst_edt_pdv_src_reset (GstEdtPdvSrc * src) -{ - src->dev = NULL; - src->total_timeouts = 0; - src->acq_started = FALSE; -} - -void -gst_edt_pdv_src_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstEdtPdvSrc *src; - - src = GST_EDT_PDV_SRC (object); - - switch (property_id) { - case PROP_UNIT: - src->unit = g_value_get_uint (value); - break; - case PROP_CHANNEL: - src->channel = g_value_get_uint (value); - break; - case PROP_CONFIG_FILE: - if (src->config_file_path) { - g_free (src->config_file_path); - } - src->config_file_path = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_RING_BUFFERS: - src->num_ring_buffers = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_edt_pdv_src_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstEdtPdvSrc *src; - - g_return_if_fail (GST_IS_EDT_PDV_SRC (object)); - src = GST_EDT_PDV_SRC (object); - - switch (property_id) { - case PROP_UNIT: - g_value_set_uint (value, src->unit); - break; - case PROP_CHANNEL: - g_value_set_uint (value, src->channel); - break; - case PROP_CONFIG_FILE: - g_value_set_string (value, src->config_file_path); - break; - case PROP_NUM_RING_BUFFERS: - g_value_set_uint (value, src->num_ring_buffers); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_edt_pdv_src_dispose (GObject * object) -{ - GstEdtPdvSrc *src; - - g_return_if_fail (GST_IS_EDT_PDV_SRC (object)); - src = GST_EDT_PDV_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_edt_pdv_src_parent_class)->dispose (object); -} - -void -gst_edt_pdv_src_finalize (GObject * object) -{ - GstEdtPdvSrc *src; - - g_return_if_fail (GST_IS_EDT_PDV_SRC (object)); - src = GST_EDT_PDV_SRC (object); - - /* clean up object here */ - - G_OBJECT_CLASS (gst_edt_pdv_src_parent_class)->finalize (object); -} - -static gboolean -gst_edt_pdv_src_start (GstBaseSrc * bsrc) -{ - GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "start"); - - if (src->config_file_path && strlen (src->config_file_path)) { - Dependent *dd_p; - Edtinfo edtinfo; - EdtDev *edt_p; - char bitdir[256]; - *bitdir = '\0'; - - dd_p = pdv_alloc_dependent (); - g_assert (dd_p != NULL); - - if (pdv_readcfg (src->config_file_path, dd_p, &edtinfo)) { - GST_ERROR_OBJECT (src, "Failed to read config file: '%s'", - src->config_file_path); - goto fail; - } - - edt_p = edt_open_channel (EDT_INTERFACE, src->unit, src->channel); - if (edt_p == NULL) { - GST_ERROR_OBJECT (src, "Failed to open channel to perform configuration"); - edt_perror ("error message"); - free (dd_p); - goto fail; - } - - if (pdv_initcam (edt_p, dd_p, src->unit, &edtinfo, src->config_file_path, - bitdir, 0)) { - GST_ERROR_OBJECT (src, "Failed to initialize camera"); - free (dd_p); - edt_close (edt_p); - goto fail; - } - - edt_close (edt_p); - } - - src->dev = pdv_open_channel (EDT_INTERFACE, src->unit, src->channel); - if (src->dev == NULL) { - GST_ERROR_OBJECT (src, "Failed to open EDT PDV unit %d channel %d)", - src->unit, src->channel); - pdv_perror ("error message"); - goto fail; - } - - if (pdv_multibuf (src->dev, src->num_ring_buffers)) { - GST_ERROR_OBJECT (src, "Failed to setup ring buffer"); - goto fail; - } - - return TRUE; - -fail: - if (src->dev) { - pdv_close (src->dev); - src->dev = NULL; - } - return FALSE; -} - -static gboolean -gst_edt_pdv_src_stop (GstBaseSrc * bsrc) -{ - GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - g_assert (src->dev != NULL); - if (pdv_close (src->dev)) { - GST_ERROR_OBJECT (src, "Failed to close device"); - return FALSE; - } - - gst_edt_pdv_src_reset (src); - - return TRUE; -} - -static GstCaps * -gst_edt_pdv_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc); - GstCaps *caps; - - if (src->dev == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - gint width, height, depth; - GstVideoInfo vinfo; - - /* Create video info */ - gst_video_info_init (&vinfo); - - width = pdv_get_width (src->dev); - height = pdv_get_height (src->dev); - depth = pdv_get_depth (src->dev); - - if (depth <= 8) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height); - caps = gst_video_info_to_caps (&vinfo); - } else if (depth <= 16) { - GValue val = G_VALUE_INIT; - GstStructure *s; - - /* TODO: check endianness */ - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width, - height); - caps = gst_video_info_to_caps (&vinfo); - - /* set bpp, extra info for GRAY16 so elements can scale properly */ - s = gst_caps_get_structure (caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, depth); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } else if (depth == 24) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGB, width, height); - caps = gst_video_info_to_caps (&vinfo); - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - (("Unknown or unsupported color format.")), (NULL)); - goto Error; - } - - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; - -Error: - return NULL; -} - -static gboolean -gst_edt_pdv_src_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - g_assert (src->dev != NULL); - src->edt_stride = pdv_get_pitch (src->dev); - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - src->height = vinfo.height; - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static GstFlowReturn -gst_edt_pdv_src_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstEdtPdvSrc *src = GST_EDT_PDV_SRC (psrc); - GstMapInfo minfo; - guint8 *image; - gint timeouts; - - if (!src->acq_started) { - /* start freerun/continuous capture */ - pdv_start_images (src->dev, 0); - src->acq_started = TRUE; - } - - /* TODO: any way to know if this particular image is good? */ - /* TODO: use pdv_ wait_image_timed to get rough timestamp */ - image = pdv_wait_image (src->dev); - - /* TODO: if there are timeouts, do we drop frame, return GST_FLOW_FATAL? */ - timeouts = pdv_timeouts (src->dev); - if (timeouts > src->total_timeouts) { - GST_WARNING_OBJECT (src, - "Received timeout, data might be incomplete. Check cables and system bandwidth."); - src->total_timeouts = timeouts; - - /* TODO: perhaps call twice as in take.c to be more robust */ - pdv_timeout_restart (src->dev, TRUE); - } - - /* TODO: use allocator */ - *buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - /* Copy image to buffer from surface TODO: use orc_memcpy */ - gst_buffer_map (*buf, &minfo, GST_MAP_WRITE); - - if (src->gst_stride == src->edt_stride) { - memcpy (minfo.data, image, minfo.size); - } else { - int i; - GST_LOG_OBJECT (src, "Stride not a multiple of 4, extra copy needed"); - for (i = 0; i < src->height; i++) { - memcpy (minfo.data + i * src->gst_stride, - image + i * src->edt_stride, src->edt_stride); - } - } - gst_buffer_unmap (*buf, &minfo); - - - return GST_FLOW_OK; -} diff --git a/sys/edt/gstedtpdvsrc.h b/sys/edt/gstedtpdvsrc.h deleted file mode 100644 index 5849e95..0000000 --- a/sys/edt/gstedtpdvsrc.h +++ /dev/null @@ -1,79 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_EDT_PDV_SRC_H_ -#define _GST_EDT_PDV_SRC_H_ - -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_EDT_PDV_SRC (gst_edt_pdv_src_get_type()) -#define GST_EDT_PDV_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EDT_PDV_SRC,GstEdtPdvSrc)) -#define GST_EDT_PDV_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EDT_PDV_SRC,GstEdtPdvSrcClass)) -#define GST_IS_EDT_PDV_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDT_PDV_SRC)) -#define GST_IS_EDT_PDV_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDT_PDV_SRC)) - -typedef struct _GstEdtPdvSrc GstEdtPdvSrc; -typedef struct _GstEdtPdvSrcClass GstEdtPdvSrcClass; - -/** -* GstEdtPdvSrcConnector: -* @MC_Connector_VID<1..16>: channel is linked to camera at the VID<1..16> input -* @MC_Connector_YC: channel is linked to a camera at the YC input -* -* -* Identifies the connector that the camera is connected to. -*/ -typedef enum { - -} GstEdtPdvSrcConnector; - -struct _GstEdtPdvSrc -{ - GstPushSrc base_edt_pdv_src; - - /* properties */ - guint unit; - guint channel; - gchar *config_file_path; - guint num_ring_buffers; - - PdvDev *dev; - gboolean acq_started; - - gint total_timeouts; - - gint height; - gint gst_stride; - gint edt_stride; -}; - -struct _GstEdtPdvSrcClass -{ - GstPushSrcClass base_edt_pdv_src_class; -}; - -GType gst_edt_pdv_src_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/euresys/CMakeLists.txt b/sys/euresys/CMakeLists.txt deleted file mode 100644 index 17d9f56..0000000 --- a/sys/euresys/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gsteuresyssrc.c) - -set (HEADERS - gsteuresyssrc.h) - -include_directories (AFTER - ${EURESYS_INCLUDE_DIR}) - -set (libname gsteuresys) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${EURESYS_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/euresys/gsteuresyssrc.c b/sys/euresys/gsteuresyssrc.c deleted file mode 100644 index 5297659..0000000 --- a/sys/euresys/gsteuresyssrc.c +++ /dev/null @@ -1,802 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gsteuresys - * - * The euresys element is a source for framegrabbers supported by the Euresys Multicam driver. - * - * - * Example launch line - * |[ - * gst-launch -v euresys ! ffmpegcolorspace ! autovideosink - * ]| - * Shows video from the default Euresys framegrabber - * - */ - -/* TODO: - * - add all caps supported by any Euresys framegrabber to src pad static caps - * - once specific framegrabber is known, set caps to available set - * - once caps are negotiated set to framegrabber - * - possibly use SurfaceColorFormat to determine the format of each surface - * - apply surface timestamp to buffer - * - issue warning and message if a frame has dropped - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include "gsteuresyssrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_euresys_debug); -#define GST_CAT_DEFAULT gst_euresys_debug - -/* prototypes */ -static void gst_euresys_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_euresys_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_euresys_dispose (GObject * object); - -static gboolean gst_euresys_start (GstBaseSrc * src); -static gboolean gst_euresys_stop (GstBaseSrc * src); -static GstCaps *gst_euresys_get_caps (GstBaseSrc * bsrc, GstCaps * filter); -static gboolean gst_euresys_set_caps (GstBaseSrc * bsrc, GstCaps * caps); - -static GstFlowReturn gst_euresys_fill (GstPushSrc * src, GstBuffer * buf); - -enum -{ - PROP_0, - PROP_BOARD_INDEX, - PROP_CAMERA_TYPE, - PROP_CONNECTOR, - PROP_COLOR_FORMAT, - PROP_PIXEL_TIMING, - PROP_NUM_CAPTURE_BUFFERS -}; - -#define DEFAULT_PROP_BOARD_INDEX 0 -#define DEFAULT_PROP_CAMERA_TYPE GST_EURESYS_CAMERA_EIA -#define DEFAULT_PROP_CONNECTOR GST_EURESYS_CONNECTOR_VID1 -#define DEFAULT_PROP_COLOR_FORMAT GST_EURESYS_COLOR_FORMAT_Y8 -#define DEFAULT_PROP_PIXEL_TIMING GST_EURESYS_PIXEL_TIMING_SQUARE -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 - -/* pad templates */ - -static GstStaticPadTemplate gst_euresys_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, BGR, BGRx, RGB_16, RGB_16 }")) - ); - -int gst_euresys_connector_map[] = { - MC_Connector_VID1, - MC_Connector_VID2, - MC_Connector_VID3, - MC_Connector_VID4 -}; - -#define GST_TYPE_EURESYS_CONNECTOR (gst_euresys_connector_get_type()) -static GType -gst_euresys_connector_get_type (void) -{ - static GType euresys_connector_type = 0; - static const GEnumValue euresys_connector[] = { - {GST_EURESYS_CONNECTOR_VID1, "VID1", "VID1 input"}, - {GST_EURESYS_CONNECTOR_VID2, "VID2", "VID2 input"}, - {GST_EURESYS_CONNECTOR_VID3, "VID3", "VID3 input"}, - {GST_EURESYS_CONNECTOR_VID4, "VID4", "VID4 input"}, - //{MC_Connector_VID5, "VID5", "VID5 input"}, - //{MC_Connector_VID6, "VID6", "VID6 input"}, - //{MC_Connector_VID7, "VID7", "VID7 input"}, - //{MC_Connector_VID8, "VID8", "VID8 input"}, - //{MC_Connector_VID9, "VID9", "VID9 input"}, - //{MC_Connector_VID10, "VID10", "VID10 input"}, - //{MC_Connector_VID11, "VID11", "VID11 input"}, - //{MC_Connector_VID12, "VID12", "VID12 input"}, - //{MC_Connector_VID13, "VID13", "VID13 input"}, - //{MC_Connector_VID14, "VID14", "VID14 input"}, - //{MC_Connector_VID15, "VID15", "VID15 input"}, - //{MC_Connector_VID16, "VID16", "VID16 input"}, - //{MC_Connector_YC, "YC", "YC input using the MiniDIN4 or DB9 connector"}, - //{MC_Connector_YC1, "YC1", "YC1 input using the HD44 connector"}, - //{MC_Connector_YC2, "YC2", "YC2 input using the HD44 connector"}, - //{MC_Connector_YC3, "YC3", "YC3 input using the HD44 connector"}, - //{MC_Connector_YC4, "YC4", "YC4 input using the HD44 connector"}, - //{MC_Connector_X, "X", "X input"}, - //{MC_Connector_Y, "Y", "Y input"}, - //{MC_Connector_XBIS, "XBIS", "XBIS input using the secondary lane"}, - //{MC_Connector_YBIS, "YBIS", "YBIS input using the secondary lane"}, - //{MC_Connector_X1, "X1", "X1 input"}, - //{MC_Connector_X2, "X2", "X2 input"}, - //{MC_Connector_Y1, "Y1", "Y1 input"}, - //{MC_Connector_Y2, "Y2", "Y2 input"}, - //{MC_Connector_A, "A", - // "A input (Grablink Expert 2 DuoCam mode, connector A)"}, - //{MC_Connector_B, "B", - // "B input (Grablink Expert 2 DuoCam mode, connector B)"}, - //{MC_Connector_M, "M", "M input (Grablink in MonoCam mode)"}, - {0, NULL, NULL}, - }; - - if (!euresys_connector_type) { - euresys_connector_type = - g_enum_register_static ("GstEuresysConnector", euresys_connector); - } - return euresys_connector_type; -} - -int gst_euresys_color_format_map[] = { - MC_ColorFormat_Y8, - MC_ColorFormat_RGB24, - MC_ColorFormat_RGB32, - MC_ColorFormat_ARGB32 -}; - -#define GST_TYPE_EURESYS_COLOR_FORMAT (gst_euresys_color_format_get_type()) -static GType -gst_euresys_color_format_get_type (void) -{ - static GType euresys_color_format_type = 0; - static const GEnumValue euresys_color_format[] = { - {GST_EURESYS_COLOR_FORMAT_Y8, "Y8", "Monochrome 8-bit"}, - {GST_EURESYS_COLOR_FORMAT_RGB24, "RGB24", "RGB24"}, - {GST_EURESYS_COLOR_FORMAT_RGB32, "RGB32", "RGB32"}, - {GST_EURESYS_COLOR_FORMAT_ARGB32, "ARGB32", "ARGB32"}, - {0, NULL, NULL}, - }; - - if (!euresys_color_format_type) { - euresys_color_format_type = - g_enum_register_static ("GstEuresysColorFormat", euresys_color_format); - } - return euresys_color_format_type; -} - -int gst_euresys_camera_map[] = { - MC_Camera_CAMERA_EIA, - MC_Camera_CAMERA_NTSC, - MC_Camera_CAMERA_CCIR, - MC_Camera_CAMERA_PAL -}; - -#define GST_TYPE_EURESYS_CAMERA (gst_euresys_camera_get_type()) -static GType -gst_euresys_camera_get_type (void) -{ - static GType euresys_camera_type = 0; - static const GEnumValue euresys_camera[] = { - {GST_EURESYS_CAMERA_EIA, "EIA", "EIA broadcasting standard"}, - {GST_EURESYS_CAMERA_NTSC, "NTSC", "NTSC broadcasting standard"}, - {GST_EURESYS_CAMERA_CCIR, "CCIR", "CCIR broadcasting standard"}, - {GST_EURESYS_CAMERA_PAL, "PAL", "PAL broadcasting standard"}, - {0, NULL, NULL}, - }; - - if (!euresys_camera_type) { - euresys_camera_type = - g_enum_register_static ("GstEuresysCamera", euresys_camera); - } - return euresys_camera_type; -} - -int gst_euresys_pixel_timing_map[] = { - MC_PixelTiming_SQUARE, - MC_PixelTiming_BROADCAST -}; - -#define GST_TYPE_EURESYS_PIXEL_TIMING (gst_euresys_pixel_timing_get_type()) -static GType -gst_euresys_pixel_timing_get_type (void) -{ - static GType euresys_pixel_timing_type = 0; - static const GEnumValue euresys_pixel_timing[] = { - {GST_EURESYS_PIXEL_TIMING_SQUARE, "square", "Produce square pixels"}, - {GST_EURESYS_PIXEL_TIMING_BROADCAST, "broadcast", - "Produce broadcast pixels"}, - {0, NULL, NULL}, - }; - - if (!euresys_pixel_timing_type) { - euresys_pixel_timing_type = - g_enum_register_static ("GstEuresysPixelTiming", euresys_pixel_timing); - } - return euresys_pixel_timing_type; -} - -/* class initialization */ -G_DEFINE_TYPE (GstEuresys, gst_euresys, GST_TYPE_PUSH_SRC); - -static GstVideoFormat -gst_euresys_color_format_to_video_format (INT32 color_format) -{ - switch (color_format) { - case MC_ColorFormat_Y8: - case MC_ColorFormat_RAW8: - return GST_VIDEO_FORMAT_GRAY8; - /* TODO: possibly use different formats for each of the following */ - case MC_ColorFormat_Y10: - case MC_ColorFormat_Y12: - case MC_ColorFormat_Y14: - case MC_ColorFormat_Y16: - case MC_ColorFormat_RAW10: - case MC_ColorFormat_RAW12: - case MC_ColorFormat_RAW14: - case MC_ColorFormat_RAW16: - return GST_VIDEO_FORMAT_GRAY16_LE; - case MC_ColorFormat_Y41P: - case MC_ColorFormat_YUV411: - return gst_video_format_from_fourcc (GST_MAKE_FOURCC ('Y', '4', '1', - 'P')); - case MC_ColorFormat_YUV422: - case MC_ColorFormat_Y42P: - return gst_video_format_from_fourcc (GST_MAKE_FOURCC ('Y', '4', '2', - 'P')); - case MC_ColorFormat_YUV444: - case MC_ColorFormat_IYU2: - return gst_video_format_from_fourcc (GST_MAKE_FOURCC ('I', 'Y', 'U', - '2')); - case MC_ColorFormat_YUV411PL: - case MC_ColorFormat_Y41B: - return GST_VIDEO_FORMAT_Y41B; - case MC_ColorFormat_YUV422PL: - case MC_ColorFormat_Y42B: - return GST_VIDEO_FORMAT_Y42B; - case MC_ColorFormat_YUV444PL: - return GST_VIDEO_FORMAT_Y444; - case MC_ColorFormat_YUV422PL_DEC: - case MC_ColorFormat_I420: - case MC_ColorFormat_IYUV: - case MC_ColorFormat_YV12: - return GST_VIDEO_FORMAT_I420; - case MC_ColorFormat_YUV411PL_DEC: - case MC_ColorFormat_YUV9: - case MC_ColorFormat_YVU9: - return gst_video_format_from_fourcc (GST_MAKE_FOURCC ('Y', 'V', 'U', - '9')); - case MC_ColorFormat_RGB15: - return GST_VIDEO_FORMAT_RGB15; - case MC_ColorFormat_RGB16: - return GST_VIDEO_FORMAT_RGB16; - case MC_ColorFormat_RGB24: - return GST_VIDEO_FORMAT_BGR; - case MC_ColorFormat_RGB32: - case MC_ColorFormat_ARGB32: - return GST_VIDEO_FORMAT_BGRx; - default: - return GST_VIDEO_FORMAT_UNKNOWN; - } -}; - -static void -gst_euresys_class_init (GstEuresysClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "euresyssrc", 0, - "Euresys MultiCam source"); - - gobject_class->set_property = gst_euresys_set_property; - gobject_class->get_property = gst_euresys_get_property; - gobject_class->dispose = gst_euresys_dispose; - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_BOARD_INDEX, - g_param_spec_int ("board", "Board", "Index of board connected to camera", - 0, 15, DEFAULT_PROP_BOARD_INDEX, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_CAMERA_TYPE, - g_param_spec_enum ("camera", "Camera", "Camera type", - GST_TYPE_EURESYS_CAMERA, DEFAULT_PROP_CAMERA_TYPE, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_CONNECTOR, - g_param_spec_enum ("connector", "Connector", - "Connector where camera is attached", GST_TYPE_EURESYS_CONNECTOR, - DEFAULT_PROP_CONNECTOR, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_COLOR_FORMAT, - g_param_spec_enum ("color-format", "Color format", - "Color format of the camera", GST_TYPE_EURESYS_COLOR_FORMAT, - DEFAULT_PROP_COLOR_FORMAT, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_PIXEL_TIMING, - g_param_spec_enum ("pixel-timing", "Pixel timing", - "Pixel timing that produces square or broadcast timing", - GST_TYPE_EURESYS_PIXEL_TIMING, DEFAULT_PROP_PIXEL_TIMING, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_int ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 2, 4095, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_euresys_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Euresys MultiCam Video Source", "Source/Video", - "Euresys MultiCam framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_euresys_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_euresys_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_euresys_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_euresys_set_caps); - - gstpushsrc_class->fill = GST_DEBUG_FUNCPTR (gst_euresys_fill); -} - -static void -gst_euresys_init (GstEuresys * euresys) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (euresys), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (euresys), GST_FORMAT_TIME); - - /* initialize member variables */ - euresys->boardIdx = DEFAULT_PROP_BOARD_INDEX; - euresys->cameraType = DEFAULT_PROP_CAMERA_TYPE; - euresys->connector = DEFAULT_PROP_CONNECTOR; - euresys->colorFormat = DEFAULT_PROP_COLOR_FORMAT; - euresys->pixelTiming = DEFAULT_PROP_PIXEL_TIMING; - euresys->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - - euresys->hChannel = 0; - - euresys->acq_started = FALSE; - - euresys->last_time_code = -1; - euresys->dropped_frame_count = 0; - - GST_INFO_OBJECT (euresys, "About to open driver"); - if (McOpenDriver (NULL) != MC_OK) { - GST_ELEMENT_ERROR (euresys, LIBRARY, INIT, (NULL), (NULL)); - return; - } -} - -void -gst_euresys_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstEuresys *euresys; - - g_return_if_fail (GST_IS_EURESYS (object)); - euresys = GST_EURESYS (object); - - switch (property_id) { - case PROP_BOARD_INDEX: - euresys->boardIdx = g_value_get_int (value); - break; - case PROP_CAMERA_TYPE: - euresys->cameraType = g_value_get_enum (value); - break; - case PROP_CONNECTOR: - euresys->connector = g_value_get_enum (value); - break; - case PROP_COLOR_FORMAT: - euresys->colorFormat = g_value_get_enum (value); - break; - case PROP_PIXEL_TIMING: - euresys->pixelTiming = g_value_get_enum (value); - break; - case PROP_NUM_CAPTURE_BUFFERS: - euresys->num_capture_buffers = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_euresys_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstEuresys *euresys; - - g_return_if_fail (GST_IS_EURESYS (object)); - euresys = GST_EURESYS (object); - - switch (property_id) { - case PROP_BOARD_INDEX: - g_value_set_int (value, euresys->boardIdx); - break; - case PROP_CAMERA_TYPE: - g_value_set_enum (value, euresys->cameraType); - break; - case PROP_CONNECTOR: - g_value_set_enum (value, euresys->connector); - break; - case PROP_COLOR_FORMAT: - g_value_set_enum (value, euresys->colorFormat); - break; - case PROP_PIXEL_TIMING: - g_value_set_enum (value, euresys->pixelTiming); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_int (value, euresys->num_capture_buffers); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_euresys_dispose (GObject * object) -{ - GstEuresys *euresys; - - g_return_if_fail (GST_IS_EURESYS (object)); - euresys = GST_EURESYS (object); - - /* clean up as possible. may be called multiple times */ - - /* Close the MultiCam driver */ - McCloseDriver (); - - G_OBJECT_CLASS (gst_euresys_parent_class)->dispose (object); -} - -static gboolean -gst_euresys_start (GstBaseSrc * bsrc) -{ - GstEuresys *euresys = GST_EURESYS (bsrc); - MCSTATUS status = 0; - - GST_DEBUG_OBJECT (euresys, "start"); - - status = - McGetParamInt (MC_BOARD + euresys->boardIdx, MC_BoardType, - &euresys->boardType); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to get board type.")), (NULL)); - return FALSE; - } - - /* Only Windows supports error message boxes */ - /* McSetParamInt (MC_CONFIGURATION, MC_ErrorHandling, MC_ErrorHandling_MSGBOX); */ - - /* Set error log file */ - /* McSetParamStr (MC_CONFIGURATION, MC_ErrorLog, "mc_error.log"); */ - - /* Create a channel */ - status = McCreate (MC_CHANNEL, &euresys->hChannel); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, FAILED, - (("Failed to create channel.")), (NULL)); - return FALSE; - } - - /* Link the channel to a board */ - status = McSetParamInt (euresys->hChannel, MC_DriverIndex, euresys->boardIdx); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to link channel to board.")), (NULL)); - goto error; - } - - /* Select the video connector */ - status = - McSetParamInt (euresys->hChannel, MC_Connector, - gst_euresys_connector_map[euresys->connector]); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set connector to channel.")), (NULL)); - goto error; - } - - /* Select the video signal type */ - status = - McSetParamInt (euresys->hChannel, MC_Camera, - gst_euresys_camera_map[euresys->cameraType]); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set camera type = %d."), euresys->cameraType), (NULL)); - goto error; - } - - /* Set the color format */ - status = - McSetParamInt (euresys->hChannel, MC_ColorFormat, - gst_euresys_color_format_map[euresys->colorFormat]); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set color format = %d."), euresys->colorFormat), (NULL)); - goto error; - } - - /* Set the pixel timing */ - status = - McSetParamInt (euresys->hChannel, MC_PixelTiming, - gst_euresys_pixel_timing_map[euresys->pixelTiming]); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set pixel timing = %d."), euresys->pixelTiming), (NULL)); - goto error; - } - - /* Acquire images continuously */ - status = McSetParamInt (euresys->hChannel, MC_SeqLength_Fr, MC_INDETERMINATE); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set sequence length to indeterminate value.")), (NULL)); - goto error; - } - - /* Set number of buffers in ring */ - status = - McSetParamInt (euresys->hChannel, MC_SurfaceCount, - euresys->num_capture_buffers); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to set surface count.")), (NULL)); - goto error; - } - - /* Enable signals */ - status = - McSetParamInt (euresys->hChannel, - MC_SignalEnable + MC_SIG_SURFACE_PROCESSING, MC_SignalEnable_ON); - status |= - McSetParamInt (euresys->hChannel, - MC_SignalEnable + MC_SIG_ACQUISITION_FAILURE, MC_SignalEnable_ON); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, SETTINGS, - (("Failed to enable signals.")), (NULL)); - goto error; - } - - return TRUE; - -error: - if (euresys->hChannel) { - McDelete (euresys->hChannel); - euresys->hChannel = 0; - } - return FALSE; -} - -static gboolean -gst_euresys_stop (GstBaseSrc * src) -{ - GstEuresys *euresys = GST_EURESYS (src); - MCSTATUS status = 0; - - GST_DEBUG_OBJECT (euresys, "stop"); - - /* Stop the acquisition */ - McSetParamInt (euresys->hChannel, MC_ChannelState, MC_ChannelState_IDLE); - - /* Delete the channel */ - if (euresys->hChannel) - McDelete (euresys->hChannel); - euresys->hChannel = 0; - - euresys->dropped_frame_count = 0; - euresys->last_time_code = -1; - - return TRUE; -} - -static GstCaps * -gst_euresys_get_camera_caps (GstEuresys * src) -{ - INT32 colorFormat; - GstVideoFormat videoFormat; - GstCaps *caps; - GstVideoInfo vinfo; - gint32 width, height; - int status; - - g_assert (src->hChannel != 0); - - status = McGetParamInt (src->hChannel, MC_ColorFormat, &colorFormat); - status |= McGetParamInt (src->hChannel, MC_ImageSizeX, &width); - status |= McGetParamInt (src->hChannel, MC_ImageSizeY, &height); - if (status != MC_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - (("Failed to get color format, width, and/or height.")), (NULL)); - return NULL; - } - - videoFormat = gst_euresys_color_format_to_video_format (colorFormat); - if (videoFormat == GST_VIDEO_FORMAT_UNKNOWN) { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - (("Unknown or unsupported color format.")), (NULL)); - return NULL; - } - - gst_video_info_init (&vinfo); - gst_video_info_set_format (&vinfo, videoFormat, width, height); - vinfo.fps_n = 30; - vinfo.fps_d = 1; - caps = gst_video_info_to_caps (&vinfo); - - if (caps == NULL) { - GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, - (("Failed to generate caps from video format.")), (NULL)); - return NULL; - } - - return caps; -} - -static GstCaps * -gst_euresys_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstEuresys *src = GST_EURESYS (bsrc); - GstCaps *caps; - - if (src->hChannel == 0) - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - else - caps = gst_euresys_get_camera_caps (src); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - return caps; -} - -static gboolean -gst_euresys_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstVideoInfo vinfo; - - GST_DEBUG_OBJECT (bsrc, "set_caps with caps=%" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - /* TODO: check stride alignment */ - gst_base_src_set_blocksize (bsrc, GST_VIDEO_INFO_SIZE (&vinfo)); - - return TRUE; -} - -GstFlowReturn -gst_euresys_fill (GstPushSrc * src, GstBuffer * buf) -{ - GstEuresys *euresys = GST_EURESYS (src); - MCSTATUS status = 0; - MCSIGNALINFO siginfo; - MCHANDLE hSurface; - int *pImage; - INT32 timeCode; - INT64 timeStamp; - int newsize; - int dropped_frame_count; - GstMapInfo minfo; - - /* Start acquisition */ - if (!euresys->acq_started) { - status = - McSetParamInt (euresys->hChannel, MC_ChannelState, - MC_ChannelState_ACTIVE); - if (status != MC_OK) { - GST_ELEMENT_ERROR (euresys, RESOURCE, FAILED, - (("Failed to set channel state to ACTIVE.")), (NULL)); - return GST_FLOW_ERROR; - } - euresys->acq_started = TRUE; - } - - /* Wait for next surface (frame) */ - while (TRUE) { - /* Wait up to 5000 msecs for a signal */ - status = McWaitSignal (euresys->hChannel, MC_SIG_ANY, 5000, &siginfo); - if (status == MC_TIMEOUT) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Timeout waiting for signal.")), (("Timeout waiting for signal."))); - return GST_FLOW_ERROR; - } else if (siginfo.Signal == MC_SIG_ACQUISITION_FAILURE) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Acquisition failure due to timeout.")), (NULL)); - return GST_FLOW_ERROR; - } else if (siginfo.Signal == MC_SIG_SURFACE_PROCESSING) { - break; - } else { - continue; - } - } - - /* Get pointer to image data and other info */ - hSurface = (MCHANDLE) siginfo.SignalInfo; - /* "number of bytes actually written into the surface" */ - status = McGetParamInt (hSurface, MC_FillCount, &newsize); - /* "Internal numbering of surface during acquisition sequence" (zero-based) */ - status |= McGetParamInt (hSurface, MC_TimeCode, &timeCode); - /* "number of microseconds elapsed since midnight (00:00:00), - * January 1, 1970, coordinated universal time (UTC), according - * to the system clock when the surface is filled" */ - status |= McGetParamInt64 (hSurface, MC_TimeStamp_us, &timeStamp); - status |= McGetParamPtr (hSurface, MC_SurfaceAddr, (PVOID *) & pImage); - if (G_UNLIKELY (status != MC_OK)) { - GST_ELEMENT_ERROR (euresys, RESOURCE, FAILED, - (("Failed to read surface parameter.")), (NULL)); - return GST_FLOW_ERROR; - } - - GST_INFO ("Got surface #%05d", timeCode); - - dropped_frame_count = timeCode - (euresys->last_time_code + 1); - if (dropped_frame_count != 0) { - euresys->dropped_frame_count += dropped_frame_count; - GST_WARNING ("Dropped %d frames (%d total)", dropped_frame_count, - euresys->dropped_frame_count); - /* TODO: emit message here about dropped frames */ - } - euresys->last_time_code = timeCode; - - /* Copy image to buffer from surface */ - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - /* TODO: fix strides? */ - g_assert (minfo.size == newsize); - memcpy (minfo.data, pImage, newsize); - gst_buffer_unmap (buf, &minfo); - - /* TODO: set buffer timestamp based on MC_TimeStamp_us */ - GST_BUFFER_TIMESTAMP (buf) = - gst_clock_get_time (GST_ELEMENT_CLOCK (src)) - - GST_ELEMENT_CAST (src)->base_time; - - /* Done processing surface, release control */ - McSetParamInt (hSurface, MC_SurfaceState, MC_SurfaceState_FREE); - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - gst_element_register (plugin, "euresyssrc", GST_RANK_NONE, - gst_euresys_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - euresys, - "Euresys Multicam source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/euresys/gsteuresyssrc.h b/sys/euresys/gsteuresyssrc.h deleted file mode 100644 index 76bb7e9..0000000 --- a/sys/euresys/gsteuresyssrc.h +++ /dev/null @@ -1,100 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_EURESYS_H_ -#define _GST_EURESYS_H_ - -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_EURESYS (gst_euresys_get_type()) -#define GST_EURESYS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EURESYS,GstEuresys)) -#define GST_EURESYS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EURESYS,GstEuresysClass)) -#define GST_IS_EURESYS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EURESYS)) -#define GST_IS_EURESYS_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EURESYS)) - -typedef struct _GstEuresys GstEuresys; -typedef struct _GstEuresysClass GstEuresysClass; - -/** -* GstEuresysConnector: -* @MC_Connector_VID<1..16>: channel is linked to camera at the VID<1..16> input -* @MC_Connector_YC: channel is linked to a camera at the YC input -* -* -* Identifies the connector that the camera is connected to. -*/ -typedef enum { - GST_EURESYS_CONNECTOR_VID1, - GST_EURESYS_CONNECTOR_VID2, - GST_EURESYS_CONNECTOR_VID3, - GST_EURESYS_CONNECTOR_VID4 -} GstEuresysConnectorEnum; - -typedef enum { - GST_EURESYS_COLOR_FORMAT_Y8, - GST_EURESYS_COLOR_FORMAT_RGB24, - GST_EURESYS_COLOR_FORMAT_RGB32, - GST_EURESYS_COLOR_FORMAT_ARGB32 -} GstEuresysColorFormatEnum; - -typedef enum { - GST_EURESYS_CAMERA_EIA, - GST_EURESYS_CAMERA_NTSC, - GST_EURESYS_CAMERA_CCIR, - GST_EURESYS_CAMERA_PAL -} GstEuresysCameraEnum; - -typedef enum { - GST_EURESYS_PIXEL_TIMING_SQUARE, - GST_EURESYS_PIXEL_TIMING_BROADCAST -} GstEuresysPixelTimingEnum; - -struct _GstEuresys -{ - GstPushSrc base_euresys; - - gint dropped_frame_count; - gboolean acq_started; - - INT32 last_time_code; - MCHANDLE hChannel; - INT32 boardType; - - /* properties */ - INT32 boardIdx; - GstEuresysCameraEnum cameraType; - GstEuresysConnectorEnum connector; - GstEuresysColorFormatEnum colorFormat; - GstEuresysPixelTimingEnum pixelTiming; - gint num_capture_buffers; -}; - -struct _GstEuresysClass -{ - GstPushSrcClass base_euresys_class; -}; - -GType gst_euresys_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/gentl/CMakeLists.txt b/sys/gentl/CMakeLists.txt deleted file mode 100644 index 4406430..0000000 --- a/sys/gentl/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -set (SOURCES - gstgentlsrc.c - ioapi.c - unzip.c) - -set (HEADERS - gstgentlsrc.h) - -include_directories (AFTER - ${GSTREAMER_INCLUDE_DIR}/.. - ${PROJECT_SOURCE_DIR}/common - ) - -set (libname gstgentl) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${ZLIB_LIBRARIES} - ) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/gentl/GenTL_v1_5.h b/sys/gentl/GenTL_v1_5.h deleted file mode 100644 index 41cfc40..0000000 --- a/sys/gentl/GenTL_v1_5.h +++ /dev/null @@ -1,791 +0,0 @@ -/**************************************************************************** -(c) 2004-2015 by GenICam GenTL Subcommittee - -License: This file is published under the license of the EMVA GenICam Standard Group. -A text file describing the legal terms is included in your installation as 'license.txt'. -If for some reason you are missing this file please contact the EMVA or visit the website -(http://www.genicam.org) for a full copy. - -THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -******************************************************************************/ - -/* \file GenTL.h - * \brief GenICam Transport Layer Client Interface - * \version 1.5 - * \author GenTL Subcommittee - * \date 2015 - * - * \par Version history - * \li Version 0.1.0 First official version from the meeting in Pilsen - * \li Version 0.1.1 rst (SI) 0.4.160 - * - added _E_INTERFACE_INFO_CMD_LIST_T_ enum name - * - added _E_DEVICE_ACCCESS_STATUS_TYPE_T_ to be used - * with the /a IFGetDeviceInfo and DevGetInfo - * - rename of the enum value DEVICE_INFO_ACCESSMODE to - * DEVICE_INFO_ACCESS_STATUS which now refers to - * _E_DEVICE_ACCCESS_STATUS_TYPE_T_ - * - added Timeout parameter to update interface list and - * device list. - * \li Version 0.1.2 - change datatype of timeout parameter of - * TLUpdateInterfaceList and IFUpdateDeviceList to - * uint64_t to match with the timeout in the event object. - * - changed all enums to have a typedef to uint32_t - * with them to allow custom ids - * - changed type of string constants to be char * instead - * of gcstring - * \li Version 0.1.3 rst (SI), cbi (IDS) 0.4.163 - * - adjusted parameter names to be closer aligned with - * the standard text - * - changed typedefs for enums from uint32_t to int32_t - * - removed default parameter - * - added parameter name to DevGetPort function - * \li Version 0.1.4 jb (LV) - * - fixes to align the file with standard text - * - make the file self-contained, independent on GenApi - * \li Version 0.1.5 rst (SI) cbi (IDS) jb (LV) tho (MVTec) - * - Adjust it for Linux - * - Cosmetics - * \li Version 1.0 rst (SI) cbi (IDS) jb (LV) tho (MVTec) - * - Adjust for Standard 1.0 - * - Make it plain C compliant - * - Cosmetics - * \li Version 1.2 rst (SI) jb (LV) tho (MVTec) - * - Adjust for Standard 1.2 - * - adjust packing - * - Cosmetics - * \li Version 1.3 (Stemmer, Leutron, Matrix Vision, MVTec, MathWorks) - * - Adjust for Standard 1.3 - * - added chunk handling - * - added Mac OS X - * - Cosmetics - * \li Version 1.3.1 (MathWorks) - * - Spelling corrections in comments - * \li Version 1.4 GenTL Subcommittee - * \li Version 1.5 GenTL Subcommittee - * - Changed namespace to GenTL - * - Changes for GenTL 1.5, Please refer to the GenTL spec - * for a list of changes. - */ - - -#ifndef GC_TLI_CLIENT_H_ -#define GC_TLI_CLIENT_H_ 1 - -#ifndef GC_USER_DEFINED_TYPES -/* The types should be the same as defined in GCTypes.h from GenApi. But in - * case you do not have this header the necessary types are defined here. */ -# if defined(_WIN32) -# if defined(_MSC_VER) && _MSC_VER >= 1600 /* VS2010 provides stdint.h */ -# include -# elif !defined _STDINT_H && !defined _STDINT - /* stdint.h is usually not available under Windows */ - typedef unsigned char uint8_t; - typedef __int32 int32_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; -# endif -# else -# include -# endif - -# ifdef __cplusplus - typedef bool bool8_t; -# else - typedef uint8_t bool8_t; -# endif -#endif /* GC_DEFINE_TYPES */ - -#include - - -/* Function declaration modifiers */ -#if defined (_WIN32) -# ifndef GCTLI_NO_DECLSPEC_STATEMENTS -# ifdef GCTLIDLL -# define GC_IMPORT_EXPORT __declspec(dllexport) -# else -# define GC_IMPORT_EXPORT __declspec(dllimport) -# endif -# else -# define GC_IMPORT_EXPORT -# endif /* # ifndef GCTLI_NO_DECLSPEC_STATEMENTS */ -# if defined (_M_IX86) || defined (__i386__) -# define GC_CALLTYPE __stdcall -# else -# define GC_CALLTYPE /* default */ -# endif -# ifndef EXTERN_C -# define EXTERN_C extern "C" -# endif - -#elif defined (__GNUC__) && (__GNUC__ >= 4) && (defined (__linux__) || defined (__APPLE__)) -# define GC_IMPORT_EXPORT __attribute__((visibility("default"))) -# if defined (__i386__) -# define GC_CALLTYPE __attribute__((stdcall)) -# else -# define GC_CALLTYPE /* default */ -# endif -# ifndef EXTERN_C -# define EXTERN_C extern "C" -# endif - -#else -# error Unknown platform, file needs adaption -#endif - -#ifdef __cplusplus -extern "C" { - namespace GenTL { -#endif - - /* Errors */ - enum GC_ERROR_LIST - { - GC_ERR_SUCCESS = 0, - GC_ERR_ERROR = -1001, - GC_ERR_NOT_INITIALIZED = -1002, - GC_ERR_NOT_IMPLEMENTED = -1003, - GC_ERR_RESOURCE_IN_USE = -1004, - GC_ERR_ACCESS_DENIED = -1005, - GC_ERR_INVALID_HANDLE = -1006, - GC_ERR_INVALID_ID = -1007, - GC_ERR_NO_DATA = -1008, - GC_ERR_INVALID_PARAMETER = -1009, - GC_ERR_IO = -1010, - GC_ERR_TIMEOUT = -1011, - GC_ERR_ABORT = -1012, /* GenTL v1.1 */ - GC_ERR_INVALID_BUFFER = -1013, /* GenTL v1.1 */ - GC_ERR_NOT_AVAILABLE = -1014, /* GenTL v1.2 */ - GC_ERR_INVALID_ADDRESS = -1015, /* GenTL v1.3 */ - GC_ERR_BUFFER_TOO_SMALL = -1016, /* GenTL v1.4 */ - GC_ERR_INVALID_INDEX = -1017, /* GenTL v1.4 */ - GC_ERR_PARSING_CHUNK_DATA = -1018, /* GenTL v1.4 */ - GC_ERR_INVALID_VALUE = -1019, /* GenTL v1.4 */ - GC_ERR_RESOURCE_EXHAUSTED = -1020, /* GenTL v1.4 */ - GC_ERR_OUT_OF_MEMORY = -1021, /* GenTL v1.4 */ - GC_ERR_BUSY = -1022, /* GenTL v1.5 */ - - GC_ERR_CUSTOM_ID = -10000 - }; - typedef int32_t GC_ERROR; - -# ifndef GC_GENTL_HEADER_VERSION - -# define GenTLMajorVersion 1 /* defines the major version of the GenICam GenTL standard version this header is based on */ -# define GenTLMinorVersion 5 /* defines the minor version of the GenICam GenTL standard version this header is based on */ -# define GenTLSubMinorVersion 0 /* defines the sub minor version of the GenICam GenTL standard version this header is based on */ - -# define GC_GENTL_HEADER_VERSION_CODE(major,minor,subminor) (((major)<<24)+((minor)<<16)+(subminor)) -# define GC_GENTL_HEADER_VERSION GC_GENTL_HEADER_VERSION_CODE(GenTLMajorVersion,GenTLMinorVersion,GenTLSubMinorVersion) - -# endif /* GC_GENTL_HEADER_VERSION */ - -# ifndef GC_GENTL_DONT_USE_TYPE_DEFINITIONS -# define TLTypeMixedName "Mixed" /* Type to use for several supported technologies */ -# define TLTypeCustomName "Custom" /* Type to use for custom technologies */ -# define TLTypeGEVName "GEV" /* Type to use for GigE Vision technology */ -# define TLTypeCLName "CL" /* Type to use for Camera Link technology */ -# define TLTypeIIDCName "IIDC" /* Type to use for IIDC 1394 technology */ -# define TLTypeUVCName "UVC" /* Type to use for USB video class devices */ -# define TLTypeCXPName "CXP" /* Type to use for CoaXPress, V1.3 */ -# define TLTypeCLHSName "CLHS" /* Type to use for Camera Link HS, V1.3 */ -# define TLTypeU3VName "U3V" /* Type to use for USB3 Vision Standard, V1.4 */ -# define TLTypeETHERNETName "Ethernet" /* Type to use for Ethernet devices, V1.3 */ -# define TLTypePCIName "PCI" /* Type to use for PCI/PCIe devices, V1.3 */ -# endif /* GC_GENTL_DONT_USE_TYPE_DEFINITIONS */ - -# ifndef GC_GENTL_DONT_USE_MODULE_NAMES -# define TLSystemModuleName "TLSystem" /* Name to identify a system module */ -# define TLInterfaceModuleName "TLInterface" /* Name to identify a interface module */ -# define TLDeviceModuleName "TLDevice" /* Name to identify a device module */ -# define TLDataStreamModuleName "TLDataStream" /* Name to identify a data stream module */ -# define TLBufferModuleName "TLBuffer" /* Name to identify a buffer module */ -# define TLRemoteDeviceModuleName "Device" /* Name to identify a remote device module */ -# endif /* GC_GENTL_DONT_USE_MODULE_NAMES */ - - /* Handles */ - typedef void * TL_HANDLE; /* Transport Layer handle, obtained through the TLOpen */ - typedef void * IF_HANDLE; /* Interface handle, obtained through ::TLOpenInterface */ - typedef void * DEV_HANDLE; /* Device Handle, obtained through the ::IFOpenDevice */ - typedef void * DS_HANDLE; /* Handle to an image stream object, obtained through DevOpenDataStream */ - typedef void * PORT_HANDLE; /* A Port handle is used to access the register space of a port */ - /* a PORT_HANDLE can be one of the following TL_HANDLE, IF_HANDLE, */ - /* DEV_HANDLE, handle to a device port, obtained through ::DevGetPort, */ - /* DS_HANDLE, BUFFER_HANDLE */ - - typedef void * BUFFER_HANDLE; /* BufferHandle, obtained through the ::DSAnnounceBuffer function */ - typedef void * EVENTSRC_HANDLE; /* A Event source handle is used to register a OS Event and to retrieve a GenTL event handle */ - /* a EVENTSRC_HANDLE can be on of the following TL_HANDLE, */ - /* IF_HANDLE, DEV_HANDLE, A handle to a device port, obtained through ::DevGetPort */ - /* DS_HANDLE, BUFFER_HANDLE */ - typedef void * EVENT_HANDLE; /* Event Handle */ - -# define GENTL_INVALID_HANDLE NULL /* Invalid handle value, V1.4 */ -# define GENTL_INFINITE 0xFFFFFFFFFFFFFFFFULL /* Infinite value to be used in various function calls, V1.4 */ - - /* Defines the data type possible for the various Info functions. */ - enum INFO_DATATYPE_LIST - { - INFO_DATATYPE_UNKNOWN = 0, /* Unknown data type */ - INFO_DATATYPE_STRING = 1, /* NULL-terminated C string (ASCII encoded). */ - INFO_DATATYPE_STRINGLIST = 2, /* Concatenated INFO_DATATYPE_STRING list. End of list is signaled with an additional NULL. */ - INFO_DATATYPE_INT16 = 3, /* Signed 16 bit integer. */ - INFO_DATATYPE_UINT16 = 4, /* Unsigned 16 bit integer */ - INFO_DATATYPE_INT32 = 5, /* Signed 32 bit integer */ - INFO_DATATYPE_UINT32 = 6, /* Unsigned 32 bit integer */ - INFO_DATATYPE_INT64 = 7, /* Signed 64 bit integer */ - INFO_DATATYPE_UINT64 = 8, /* Unsigned 64 bit integer */ - INFO_DATATYPE_FLOAT64 = 9, /* Signed 64 bit floating point number. */ - INFO_DATATYPE_PTR = 10, /* Pointer type (void*). Size is platform dependent (32 bit on 32 bit platforms). */ - INFO_DATATYPE_BOOL8 = 11, /* Boolean value occupying 8 bit. 0 for false and anything for true. */ - INFO_DATATYPE_SIZET = 12, /* Platform dependent unsigned integer (32 bit on 32 bit platforms). */ - INFO_DATATYPE_BUFFER = 13, /* Like a INFO_DATATYPE_STRING but with arbitrary data and no NULL termination. */ - INFO_DATATYPE_PTRDIFF = 14, /* Platform dependent signed integer (32 bit on 32 bit platforms). GenTL v1.3 */ - - INFO_DATATYPE_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ - }; - typedef int32_t INFO_DATATYPE; - - /* Defines char encoding schemes used by the producer, GenTL v1.4 */ - enum TL_CHAR_ENCODING_LIST - { - TL_CHAR_ENCODING_ASCII = 0, - TL_CHAR_ENCODING_UTF8 = 1 - }; - typedef int32_t TL_CHAR_ENCODING; /* GenTL v1.4 */ - - /* System module information commands for the GenICam::TL::Client::TLGetInfo and GenICam::TL::Client::GCGetInfo functions. */ - enum TL_INFO_CMD_LIST - { - TL_INFO_ID = 0, /* STRING Transport layer ID. */ - TL_INFO_VENDOR = 1, /* STRING Transport layer vendor name. */ - TL_INFO_MODEL = 2, /* STRING Transport layer model name. */ - TL_INFO_VERSION = 3, /* STRING Transport layer version. */ - TL_INFO_TLTYPE = 4, /* STRING Transport layer technology that is supported. */ - TL_INFO_NAME = 5, /* STRING File name including extension of the library. */ - TL_INFO_PATHNAME = 6, /* STRING Full path including file name and extension of the library. */ - TL_INFO_DISPLAYNAME = 7, /* STRING User readable name of the device. If this is not defined in the device this should be VENDOR MODEL (ID). */ - TL_INFO_CHAR_ENCODING = 8, /* INT32 Reporting the char encoding used by this Producer, GenTL v1.4 */ - TL_INFO_GENTL_VER_MAJOR = 9, /* UINT32 Major number of the GenTL spec this producer complies with, GenTL v1.5 */ - TL_INFO_GENTL_VER_MINOR = 10, /* UINT32 Minor number of the GenTL spec this producer complies with, GenTL v1.5 */ - TL_INFO_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ - }; - typedef int32_t TL_INFO_CMD; - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::IFGetInfo function from the Interface module. */ - enum INTERFACE_INFO_CMD_LIST - { - INTERFACE_INFO_ID = 0, /* STRING Unique ID of the interface. */ - INTERFACE_INFO_DISPLAYNAME = 1, /* STRING User readable name of the interface. */ - INTERFACE_INFO_TLTYPE = 2, /* STRING Transport layer technology that is supported. */ - - INTERFACE_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t INTERFACE_INFO_CMD; - - /* This enumeration defines flags of how a device is to be opened with the GenICam::TL::Client::IFOpenDevice function. */ - enum DEVICE_ACCESS_FLAGS_LIST - { - DEVICE_ACCESS_UNKNOWN = 0, /* Not used in a command. Can be used to initialize a variable to query that information. */ - DEVICE_ACCESS_NONE = 1, /* This either means that the device is not open because it was not opened before or the access to it was denied. */ - DEVICE_ACCESS_READONLY = 2, /* Open the device read only. All Port functions can only read from the device. */ - DEVICE_ACCESS_CONTROL = 3, /* Open the device in a way that other hosts/processes can have read only access to the device. Device access level is read/write for this process. */ - DEVICE_ACCESS_EXCLUSIVE = 4, /* Open the device in a way that only this host/process can have access to the device. Device access level is read/write for this process. */ - - DEVICE_ACCESS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t DEVICE_ACCESS_FLAGS; - - /* This enumeration defines values for the accessibility of the device to be returned in the GenICam::TL::Client::DevGetInfo function on a device handle. */ - enum DEVICE_ACCESS_STATUS_LIST - { - DEVICE_ACCESS_STATUS_UNKNOWN = 0, /* The device accessibility is not known. */ - DEVICE_ACCESS_STATUS_READWRITE = 1, /* The device is available for read/write access. */ - DEVICE_ACCESS_STATUS_READONLY = 2, /* The device is available for read only access. */ - DEVICE_ACCESS_STATUS_NOACCESS = 3, /* The device is not accessible. */ - DEVICE_ACCESS_STATUS_BUSY = 4, /* The device has already been opened by another process/host. GenTL v1.5 */ - DEVICE_ACCESS_STATUS_OPEN_READWRITE = 5, /* The device has already been opened by this process. GenTL v1.5 */ - DEVICE_ACCESS_STATUS_OPEN_READONLY = 6, /* The device has already been opened by this process. GenTL v1.5 */ - - DEVICE_ACCESS_STATUS_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ - }; - typedef int32_t DEVICE_ACCESS_STATUS; - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DevGetInfo function on a device handle. */ - enum DEVICE_INFO_CMD_LIST - { - DEVICE_INFO_ID = 0, /* STRING Unique ID of the device. */ - DEVICE_INFO_VENDOR = 1, /* STRING Device vendor name. */ - DEVICE_INFO_MODEL = 2, /* STRING Device model name. */ - DEVICE_INFO_TLTYPE = 3, /* STRING Transport layer technology that is supported. */ - DEVICE_INFO_DISPLAYNAME = 4, /* STRING String containing a display name for the device ( including a unique id ) */ - DEVICE_INFO_ACCESS_STATUS = 5, /* INT32 Gets the access mode the GenTL Producer has on the opened device. (DEVICE_ACCESS_STATUS enumeration value). */ - DEVICE_INFO_USER_DEFINED_NAME = 6, /* STRING String containing the user defined name, GenTL v1.4 */ - DEVICE_INFO_SERIAL_NUMBER = 7, /* STRING String containing the device's serial number, GenTL v1.4 */ - DEVICE_INFO_VERSION = 8, /* STRING String containing the device version, GenTL v1.4 */ - DEVICE_INFO_TIMESTAMP_FREQUENCY = 9, /* UINT64 Tick-frequency of the time stamp clock, GenTL v1.4 */ - - DEVICE_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t DEVICE_INFO_CMD; - - /* This enumeration defines special stop flags for the acquisition engine. The function used is GenICam::TL::Client::DSStopAcquisition. */ - enum ACQ_STOP_FLAGS_LIST - { - ACQ_STOP_FLAGS_DEFAULT = 0, /* Stop the acquisition engine when the currently running tasks like filling a buffer are completed (default behavior). */ - ACQ_STOP_FLAGS_KILL = 1, /* Stop the acquisition engine immediately and leave buffers currently being filled in the Input Buffer Pool. */ - - ACQ_STOP_FLAGS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t ACQ_STOP_FLAGS; - - /* This enumeration defines special start flags for the acquisition engine. The function used is GenICam::TL::Client::DSStartAcquisition. */ - enum ACQ_START_FLAGS_LIST - { - ACQ_START_FLAGS_DEFAULT = 0, /* Default behavior. */ - - ACQ_START_FLAGS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t ACQ_START_FLAGS; - - /* This enumeration commands from which to which queue/pool buffers are flushed with the GenICam::TL::Client::DSFlushQueue function. */ - enum ACQ_QUEUE_TYPE_LIST - { - ACQ_QUEUE_INPUT_TO_OUTPUT = 0, /* Flushes the input pool to the output queue and if necessary adds entries in the New Buffer event data queue. */ - ACQ_QUEUE_OUTPUT_DISCARD = 1, /* Discards all buffers in the output queue and if necessary remove the entries from the event data queue. */ - ACQ_QUEUE_ALL_TO_INPUT = 2, /* Puts all buffers in the input pool. Even those in the output queue and discard entries in the event data queue. */ - ACQ_QUEUE_UNQUEUED_TO_INPUT = 3, /* Puts all buffers that are not in the input pool or the output queue in the input pool. */ - ACQ_QUEUE_ALL_DISCARD = 4, /* Discards all buffers in the input pool and output queue. */ - - ACQ_QUEUE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t ACQ_QUEUE_TYPE; - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DSGetInfo function on a data stream handle */ - enum STREAM_INFO_CMD_LIST - { - STREAM_INFO_ID = 0, /* STRING Unique ID of the data stream. */ - STREAM_INFO_NUM_DELIVERED = 1, /* UINT64 Number of delivered buffers since last acquisition start. */ - STREAM_INFO_NUM_UNDERRUN = 2, /* UINT64 Number of lost buffers due to queue underrun. */ - STREAM_INFO_NUM_ANNOUNCED = 3, /* SIZET Number of announced buffers. */ - STREAM_INFO_NUM_QUEUED = 4, /* SIZET Number of buffers in the input pool. */ - STREAM_INFO_NUM_AWAIT_DELIVERY = 5, /* SIZET Number of buffers in the output queue. */ - STREAM_INFO_NUM_STARTED = 6, /* UINT64 Number of buffers started in the acquisition engine. */ - STREAM_INFO_PAYLOAD_SIZE = 7, /* SIZET Size of the expected data in bytes. */ - STREAM_INFO_IS_GRABBING = 8, /* BOOL8 Flag indicating whether the acquisition engine is started or not. */ - STREAM_INFO_DEFINES_PAYLOADSIZE = 9, /* BOOL8 Flag that indicated that this data stream defines a payload size independent from the remote device. */ - STREAM_INFO_TLTYPE = 10, /* STRING Transport layer technology that is supported. */ - STREAM_INFO_NUM_CHUNKS_MAX = 11, /* SIZET Max number of chunks in a buffer, if known. GenTL v1.3 */ - STREAM_INFO_BUF_ANNOUNCE_MIN = 12, /* SIZET Min number of buffers to announce before acq can start, if known. GenTL v1.3 */ - STREAM_INFO_BUF_ALIGNMENT = 13, /* SIZET Buffer alignment in bytes. GenTL v1.3 */ - - STREAM_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t STREAM_INFO_CMD; - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DSGetBufferInfo function on a buffer handle. */ - enum BUFFER_INFO_CMD_LIST - { - BUFFER_INFO_BASE = 0, /* PTR Base address of the buffer memory. */ - BUFFER_INFO_SIZE = 1, /* SIZET Size of the buffer in bytes. */ - BUFFER_INFO_USER_PTR = 2, /* PTR Private data pointer of the GenTL Consumer. */ - BUFFER_INFO_TIMESTAMP = 3, /* UINT64 Timestamp the buffer was acquired. */ - BUFFER_INFO_NEW_DATA = 4, /* BOOL8 Flag to indicate that the buffer contains new data since the last call. */ - BUFFER_INFO_IS_QUEUED = 5, /* BOOL8 Flag to indicate if the buffer is in the input pool or output queue. */ - BUFFER_INFO_IS_ACQUIRING = 6, /* BOOL8 Flag to indicate that the buffer is currently being filled with data. */ - BUFFER_INFO_IS_INCOMPLETE = 7, /* BOOL8 Flag to indicate that a buffer was filled but an error occurred during that process. */ - BUFFER_INFO_TLTYPE = 8, /* STRING Transport layer technology that is supported. */ - BUFFER_INFO_SIZE_FILLED = 9, /* SIZET Number of bytes written into the buffer last time it has been filled. This value is reset to 0 when the buffer is placed into the Input Buffer Pool. */ - BUFFER_INFO_WIDTH = 10, /* SIZET GenTL v1.2 */ - BUFFER_INFO_HEIGHT = 11, /* SIZET GenTL v1.2 */ - BUFFER_INFO_XOFFSET = 12, /* SIZET GenTL v1.2 */ - BUFFER_INFO_YOFFSET = 13, /* SIZET GenTL v1.2 */ - BUFFER_INFO_XPADDING = 14, /* SIZET GenTL v1.2 */ - BUFFER_INFO_YPADDING = 15, /* SIZET GenTL v1.2 */ - BUFFER_INFO_FRAMEID = 16, /* UINT64 GenTL v1.2 */ - BUFFER_INFO_IMAGEPRESENT = 17, /* BOOL8 GenTL v1.2 */ - BUFFER_INFO_IMAGEOFFSET = 18, /* SIZET GenTL v1.2 */ - BUFFER_INFO_PAYLOADTYPE = 19, /* SIZET GenTL v1.2 */ - BUFFER_INFO_PIXELFORMAT = 20, /* UINT64 GenTL v1.2 */ - BUFFER_INFO_PIXELFORMAT_NAMESPACE = 21, /* UINT64 GenTL v1.2 */ - BUFFER_INFO_DELIVERED_IMAGEHEIGHT = 22, /* SIZET GenTL v1.2 */ - BUFFER_INFO_DELIVERED_CHUNKPAYLOADSIZE = 23, /* SIZET GenTL v1.2 */ - BUFFER_INFO_CHUNKLAYOUTID = 24, /* UINT64 GenTL v1.2 */ - BUFFER_INFO_FILENAME = 25, /* STRING GenTL v1.2 */ - BUFFER_INFO_PIXEL_ENDIANNESS = 26, /* INT32 GenTL v1.4 */ - BUFFER_INFO_DATA_SIZE = 27, /* SIZET GenTL v1.4 */ - BUFFER_INFO_TIMESTAMP_NS = 28, /* UINT64 GenTL v1.4 */ - BUFFER_INFO_DATA_LARGER_THAN_BUFFER = 29, /* BOOL8 GenTL v1.4 */ - BUFFER_INFO_CONTAINS_CHUNKDATA = 30, /* BOOL8 GenTL v1.4 */ - - BUFFER_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t BUFFER_INFO_CMD; - - /* This enumeration defines commands to retrieve information about individual data parts in a multi-part buffer - using the GenICam::TL::Client::DSGetBufferPartInfo function. Introduced in GenTL v1.5. */ - enum BUFFER_PART_INFO_CMD_LIST - { - BUFFER_PART_INFO_BASE = 0, /* PTR Base address of the buffer part memory. */ - BUFFER_PART_INFO_DATA_SIZE = 1, /* SIZET Size of the buffer part in bytes. */ - BUFFER_PART_INFO_DATA_TYPE = 2, /* SIZET Type of the data in given part (PARTDATATYPE_ID enumeration value). */ - BUFFER_PART_INFO_DATA_FORMAT = 3, /* UINT64 Format of individual items (such as pixels) in the buffer part. */ - BUFFER_PART_INFO_DATA_FORMAT_NAMESPACE = 4, /* UINT64 Allows interpretation of BUFFER_PART_INFO_DATA_FORMAT (PIXELFORMAT_NAMESPACE_ID enumeration value). */ - BUFFER_PART_INFO_WIDTH = 5, /* SIZET Width of data in the buffer part in pixels. */ - BUFFER_PART_INFO_HEIGHT = 6, /* SIZET Expected height of data in the buffer part in pixels . */ - BUFFER_PART_INFO_XOFFSET = 7, /* SIZET Horizontal offset of data in the buffer part in pixels. */ - BUFFER_PART_INFO_YOFFSET = 8, /* SIZET Vertical offset of data in the buffer part in pixels. */ - BUFFER_PART_INFO_XPADDING = 9, /* SIZET Horizontal padding of data in the buffer part in pixels. */ - BUFFER_PART_INFO_SOURCE_ID = 10, /* UINT64 Identifier allowing to group data parts belonging to the same source. */ - BUFFER_PART_INFO_DELIVERED_IMAGEHEIGHT = 11, /* SIZET Height of the data currently in the buffer part in pixels*/ - BUFFER_PART_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t BUFFER_PART_INFO_CMD; /* GenTL v1.5 */ - - /* Enumeration of TLType dependent payload types. Introduced in GenTL v1.2 */ - enum PAYLOADTYPE_INFO_IDS - { - PAYLOAD_TYPE_UNKNOWN = 0, /* GenTL v1.2 */ - PAYLOAD_TYPE_IMAGE = 1, /* GenTL v1.2 */ - PAYLOAD_TYPE_RAW_DATA = 2, /* GenTL v1.2 */ - PAYLOAD_TYPE_FILE = 3, /* GenTL v1.2 */ - PAYLOAD_TYPE_CHUNK_DATA = 4, /* GenTL v1.2, Deprecated in GenTL 1.5*/ - PAYLOAD_TYPE_JPEG = 5, /* GenTL v1.4 */ - PAYLOAD_TYPE_JPEG2000 = 6, /* GenTL v1.4 */ - PAYLOAD_TYPE_H264 = 7, /* GenTL v1.4 */ - PAYLOAD_TYPE_CHUNK_ONLY = 8, /* GenTL v1.4 */ - PAYLOAD_TYPE_DEVICE_SPECIFIC = 9, /* GenTL v1.4 */ - PAYLOAD_TYPE_MULTI_PART = 10, /* GenTL v1.5 */ - - PAYLOAD_TYPE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t PAYLOADTYPE_INFO_ID; - - /* Enumeration of TLType dependent pixel format namespaces introduced GenTL v1.2 */ - enum PIXELFORMAT_NAMESPACE_IDS - { - PIXELFORMAT_NAMESPACE_UNKNOWN = 0, /* GenTL v1.2 */ - PIXELFORMAT_NAMESPACE_GEV = 1, /* GenTL v1.2 */ - PIXELFORMAT_NAMESPACE_IIDC = 2, /* GenTL v1.2 */ - PIXELFORMAT_NAMESPACE_PFNC_16BIT = 3, /* GenTL v1.4 */ - PIXELFORMAT_NAMESPACE_PFNC_32BIT = 4, /* GenTL v1.4 */ - - PIXELFORMAT_NAMESPACE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t PIXELFORMAT_NAMESPACE_ID; /* GenTL v1.2 */ - - /* Enumeration of pixel endianness values. Introduced in GenTL v1.4 */ - enum PIXELENDIANNESS_IDS - { - PIXELENDIANNESS_UNKNOWN = 0, /* Unknown pixel endianness. GenTL v1.4 */ - PIXELENDIANNESS_LITTLE = 1, /* Little endian pixel data. GenTL v1.4 */ - PIXELENDIANNESS_BIG = 2 /* Big endian pixel data. GenTL v1.4 */ - }; - typedef int32_t PIXELENDIANNESS_ID; /* GenTL v1.4*/ - - /* Enumeration describing which data type is present in given buffer part. Introduced in GenTL v1.5 */ - enum PARTDATATYPE_IDS - { - PART_DATATYPE_UNKNOWN = 0, /* Unknown data type */ - PART_DATATYPE_2D_IMAGE = 1, /* Color or monochrome 2D image. */ - PART_DATATYPE_2D_PLANE_BIPLANAR = 2, /* Single color plane of a planar 2D image consisting of 2 planes. */ - PART_DATATYPE_2D_PLANE_TRIPLANAR = 3, /* Single color plane of a planar 2D image consisting of 3 planes. */ - PART_DATATYPE_2D_PLANE_QUADPLANAR = 4, /* Single color plane of a planar 2D image consisting of 4 planes. */ - PART_DATATYPE_3D_IMAGE = 5, /* 3D image (pixel coordinates). */ - PART_DATATYPE_3D_PLANE_BIPLANAR = 6, /* Single plane of a planar 3D image consisting of 2 planes. */ - PART_DATATYPE_3D_PLANE_TRIPLANAR = 7, /* Single plane of a planar 3D image consisting of 3 planes. */ - PART_DATATYPE_3D_PLANE_QUADPLANAR = 8, /* Single plane of a planar 3D image consisting of 4 planes. */ - PART_DATATYPE_CONFIDENCE_MAP = 9, /* Confidence of the individual pixel values. */ - - PART_DATATYPE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t PARTDATATYPE_ID; /* GenTL v1.5*/ - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::GCGetPortInfo function on a module or remote device handle. */ - enum PORT_INFO_CMD_LIST - { - PORT_INFO_ID = 0, /* STRING Unique ID of the port. */ - PORT_INFO_VENDOR = 1, /* STRING Port vendor name. */ - PORT_INFO_MODEL = 2, /* STRING Port model name. */ - PORT_INFO_TLTYPE = 3, /* STRING Transport layer technology that is supported. */ - PORT_INFO_MODULE = 4, /* STRING GenTL Module the port refers to. */ - PORT_INFO_LITTLE_ENDIAN = 5, /* BOOL8 Flag indicating that the port data is little endian. */ - PORT_INFO_BIG_ENDIAN = 6, /* BOOL8 Flag indicating that the port data is big endian. */ - PORT_INFO_ACCESS_READ = 7, /* BOOL8 Port has read access. */ - PORT_INFO_ACCESS_WRITE = 8, /* BOOL8 Port has write access. */ - PORT_INFO_ACCESS_NA = 9, /* BOOL8 Port is not accessible. */ - PORT_INFO_ACCESS_NI = 10, /* BOOL8 Port is not implemented. */ - PORT_INFO_VERSION = 11, /* STRING Version of the port. */ - PORT_INFO_PORTNAME = 12, /* STRING Name of the port as referenced in the XML description. */ - - PORT_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t PORT_INFO_CMD; - - /* This enumeration defines enum values returned by the URL_INFO_SCHEME command. - introduced in GenTL v1.5 */ - enum URL_SCHEME_IDS - { - URL_SCHEME_LOCAL = 0, /* The XML can be read from the local register map */ - URL_SCHEME_HTTP = 1, /* The XML can be downloaded from a http server */ - URL_SCHEME_FILE = 2, /* The XML can be read from the local hard drive */ - - URL_SCHEME_CUSTOM_ID = 1000 /* Starting value for custom scheme locations */ - }; - typedef int32_t URL_SCHEME_ID; - - /* This enumeration defines commands to retrieve information with the GenICam::TL::Client::GCGetPortURLInfo - function on a module or remote device handle. Introduced in GenTL v1.1 */ - enum URL_INFO_CMD_LIST - { - URL_INFO_URL = 0, /* STRING URL as defined in chapter 4.1.2 GenTL v1.1 */ - URL_INFO_SCHEMA_VER_MAJOR = 1, /* INT32 Major version of the schema this URL refers to. GenTL v1.1 */ - URL_INFO_SCHEMA_VER_MINOR = 2, /* INT32 Minor version of the schema this URL refers to. GenTL v1.1 */ - URL_INFO_FILE_VER_MAJOR = 3, /* INT32 Major version of the XML-file this URL refers to. GenTL v1.1 */ - URL_INFO_FILE_VER_MINOR = 4, /* INT32 Minor version of the XML-file this URL refers to. GenTL v1.1 */ - URL_INFO_FILE_VER_SUBMINOR = 5, /* INT32 Subminor version of the XML-file this URL refers to. GenTL v1.1 */ - URL_INFO_FILE_SHA1_HASH = 6, /* BUFFER 160-bit SHA1 Hash code of XML-file. GenTL v1.4 */ - URL_INFO_FILE_REGISTER_ADDRESS = 7, /* UINT64 Register address in the device's register map. GenTL v1.5 */ - URL_INFO_FILE_SIZE = 8, /* UINT64 File size in bytes. GenTL v1.5 */ - URL_INFO_SCHEME = 9, /* INT32 Scheme of the URL as defined in URL_SCHEME_IDS. GenTL v1.5 */ - URL_INFO_FILENAME = 10, /* STRING File name if the scheme of the URL is file. GenTL v1.5 */ - - URL_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t URL_INFO_CMD; /* GenTL v1.1 */ - - /* Known event types that can be registered on certain modules with the GenICam::TL::Client::GCRegisterEvent function. */ - enum EVENT_TYPE_LIST - { - EVENT_ERROR = 0, /* Notification on module errors. */ - EVENT_NEW_BUFFER = 1, /* Notification on newly filled buffers. */ - EVENT_FEATURE_INVALIDATE = 2, /* Notification if a feature was changed by the GenTL Producer library and thus needs to be invalidated in the GenICam GenApi instance using the module. */ - EVENT_FEATURE_CHANGE = 3, /* Notification if the GenTL Producer library wants to manually set a feature in the GenICam GenApi instance using the module. */ - EVENT_REMOTE_DEVICE = 4, /* Notification if the GenTL Producer wants to inform the GenICam GenApi instance of the remote device that a GenApi compatible event was fired. */ - EVENT_MODULE = 5, /* Notification if the GenTL Producer wants to inform the GenICam GenApi instance of the module that a GenApi compatible event was fired. GenTL v1.4 */ - - EVENT_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t EVENT_TYPE; - - /* Event info command */ - enum EVENT_INFO_CMD_LIST - { - EVENT_EVENT_TYPE = 0, /* INT32 The event type of the event handle (EVENT_TYPE enum value). */ - EVENT_NUM_IN_QUEUE = 1, /* SIZET Number of events in the event data queue. */ - EVENT_NUM_FIRED = 2, /* UINT64 Number of events that were fired since the creation of the module. */ - EVENT_SIZE_MAX = 3, /* SIZET Max size of data carried with an event in bytes. GenTL v1.2 */ - EVENT_INFO_DATA_SIZE_MAX = 4, /* SIZET Max size of data provided through EventGetDataInfo in bytes. GenTL v1.2 */ - - EVENT_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t EVENT_INFO_CMD; - - /* Event data info command */ - enum EVENT_DATA_INFO_CMD_LIST - { - EVENT_DATA_ID = 0, /* Event specific Unique Event ID (String or Number)*/ - EVENT_DATA_VALUE = 1, /* Event specific Data */ - EVENT_DATA_NUMID = 2, /* UINT64 Numeric representation of the unique Event ID, GenTL v1.3. */ - - EVENT_DATA_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ - }; - typedef int32_t EVENT_DATA_INFO_CMD; - - /* Structure of the data returned from a signaled "New Buffer" event. */ -# pragma pack (push, 1) - typedef struct S_EVENT_NEW_BUFFER - { - BUFFER_HANDLE BufferHandle; /* Buffer handle which contains new data. */ - void* pUserPointer; /* User pointer provided at announcement of the buffer. */ - } EVENT_NEW_BUFFER_DATA; -# pragma pack (pop) - - /* Structure to be use with GCWritePortStacked and GCReadPortStacked. */ -# pragma pack (push, 1) - typedef struct S_PORT_REGISTER_STACK_ENTRY - { - uint64_t Address; /* Address of the register. */ - void* pBuffer; /* Pointer to the buffer containing the data. */ - size_t Size; /* Number of bytes to read write. */ - } PORT_REGISTER_STACK_ENTRY; -# pragma pack (pop) - -# pragma pack (push, 1) - /* Structure carrying information about a single chunk in the buffer, V1.3 */ - typedef struct S_SINGLE_CHUNK_DATA - { - uint64_t ChunkID; /* Numeric representation of ChunkID */ - ptrdiff_t ChunkOffset; /* Chunk offset in the buffer */ - size_t ChunkLength; /* Size of the chunk data */ - } SINGLE_CHUNK_DATA; -# pragma pack (pop) - - - /* C API Interface Functions */ -# define GC_API GC_IMPORT_EXPORT GC_ERROR GC_CALLTYPE - GC_API GCGetInfo ( TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - GC_API GCGetLastError ( GC_ERROR *piErrorCode, char *sErrText, size_t *piSize ); - - GC_API GCInitLib ( void ); - GC_API GCCloseLib ( void ); - - GC_API GCReadPort ( PORT_HANDLE hPort, uint64_t iAddress, void *pBuffer, size_t *piSize ); - GC_API GCWritePort ( PORT_HANDLE hPort, uint64_t iAddress, const void *pBuffer, size_t *piSize ); - GC_API GCGetPortURL ( PORT_HANDLE hPort, char *sURL, size_t *piSize ); - - GC_API GCGetPortInfo ( PORT_HANDLE hPort, PORT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - GC_API GCRegisterEvent ( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID, EVENT_HANDLE *phEvent ); - GC_API GCUnregisterEvent ( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID ); - - GC_API EventGetData ( EVENT_HANDLE hEvent, void *pBuffer, size_t *piSize, uint64_t iTimeout ); - GC_API EventGetDataInfo ( EVENT_HANDLE hEvent, const void *pInBuffer, size_t iInSize, EVENT_DATA_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pOutBuffer, size_t *piOutSize ); - GC_API EventGetInfo ( EVENT_HANDLE hEvent, EVENT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API EventFlush ( EVENT_HANDLE hEvent ); - GC_API EventKill ( EVENT_HANDLE hEvent ); - - GC_API TLOpen ( TL_HANDLE *phTL ); - GC_API TLClose ( TL_HANDLE hTL ); - GC_API TLGetInfo ( TL_HANDLE hTL, TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - GC_API TLGetNumInterfaces ( TL_HANDLE hTL, uint32_t *piNumIfaces ); - GC_API TLGetInterfaceID ( TL_HANDLE hTL, uint32_t iIndex, char *sID, size_t *piSize ); - GC_API TLGetInterfaceInfo ( TL_HANDLE hTL, const char *sIfaceID, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API TLOpenInterface ( TL_HANDLE hTL, const char *sIfaceID, IF_HANDLE *phIface ); - GC_API TLUpdateInterfaceList ( TL_HANDLE hTL, bool8_t *pbChanged, uint64_t iTimeout ); - - GC_API IFClose ( IF_HANDLE hIface ); - GC_API IFGetInfo ( IF_HANDLE hIface, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - GC_API IFGetNumDevices ( IF_HANDLE hIface, uint32_t *piNumDevices ); - GC_API IFGetDeviceID ( IF_HANDLE hIface, uint32_t iIndex, char *sIDeviceID, size_t *piSize ); - GC_API IFUpdateDeviceList ( IF_HANDLE hIface, bool8_t *pbChanged, uint64_t iTimeout ); - GC_API IFGetDeviceInfo ( IF_HANDLE hIface, const char *sDeviceID, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API IFOpenDevice ( IF_HANDLE hIface, const char *sDeviceID, DEVICE_ACCESS_FLAGS iOpenFlags, DEV_HANDLE *phDevice ); - - GC_API DevGetPort ( DEV_HANDLE hDevice, PORT_HANDLE *phRemoteDevice ); - GC_API DevGetNumDataStreams ( DEV_HANDLE hDevice, uint32_t *piNumDataStreams ); - GC_API DevGetDataStreamID ( DEV_HANDLE hDevice, uint32_t iIndex, char *sDataStreamID, size_t *piSize ); - GC_API DevOpenDataStream ( DEV_HANDLE hDevice, const char *sDataStreamID, DS_HANDLE *phDataStream ); - GC_API DevGetInfo ( DEV_HANDLE hDevice, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API DevClose ( DEV_HANDLE hDevice ); - - GC_API DSAnnounceBuffer ( DS_HANDLE hDataStream, void *pBuffer, size_t iSize, void *pPrivate, BUFFER_HANDLE *phBuffer ); - GC_API DSAllocAndAnnounceBuffer( DS_HANDLE hDataStream, size_t iSize, void *pPrivate, BUFFER_HANDLE *phBuffer ); - GC_API DSFlushQueue ( DS_HANDLE hDataStream, ACQ_QUEUE_TYPE iOperation ); - GC_API DSStartAcquisition ( DS_HANDLE hDataStream, ACQ_START_FLAGS iStartFlags, uint64_t iNumToAcquire ); - GC_API DSStopAcquisition ( DS_HANDLE hDataStream, ACQ_STOP_FLAGS iStopFlags ); - GC_API DSGetInfo ( DS_HANDLE hDataStream, STREAM_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API DSGetBufferID ( DS_HANDLE hDataStream, uint32_t iIndex, BUFFER_HANDLE *phBuffer ); - GC_API DSClose ( DS_HANDLE hDataStream ); - - GC_API DSRevokeBuffer ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, void **pBuffer, void **pPrivate ); - GC_API DSQueueBuffer ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer ); - GC_API DSGetBufferInfo ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, BUFFER_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - /* GenTL v1.1 */ - GC_API GCGetNumPortURLs ( PORT_HANDLE hPort, uint32_t *piNumURLs ); - GC_API GCGetPortURLInfo ( PORT_HANDLE hPort, uint32_t iURLIndex, URL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API GCReadPortStacked ( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); - GC_API GCWritePortStacked ( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); - - /* GenTL v1.3 */ - GC_API DSGetBufferChunkData ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, SINGLE_CHUNK_DATA *pChunkData, size_t *piNumChunks ); - - /* GenTL v1.4 */ - GC_API IFGetParentTL ( IF_HANDLE hIface, TL_HANDLE *phSystem ); - GC_API DevGetParentIF ( DEV_HANDLE hDevice, IF_HANDLE *phIface ); - GC_API DSGetParentDev ( DS_HANDLE hDataStream, DEV_HANDLE *phDevice ); - - /* GenTL v1.5 */ - GC_API DSGetNumBufferParts ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t *piNumParts ); - GC_API DSGetBufferPartInfo ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t iPartIndex, BUFFER_PART_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - /* typedefs for dynamic loading */ -# define GC_API_P(function) typedef GC_ERROR( GC_CALLTYPE *function ) - GC_API_P(PGCGetInfo )( TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PGCGetLastError )( GC_ERROR *piErrorCode, char *sErrText, size_t *piSize ); - GC_API_P(PGCInitLib )( void ); - GC_API_P(PGCCloseLib )( void ); - GC_API_P(PGCReadPort )( PORT_HANDLE hPort, uint64_t iAddress, void *pBuffer, size_t *piSize ); - GC_API_P(PGCWritePort )( PORT_HANDLE hPort, uint64_t iAddress, const void *pBuffer, size_t *piSize ); - GC_API_P(PGCGetPortURL )( PORT_HANDLE hPort, char *sURL, size_t *piSize ); - GC_API_P(PGCGetPortInfo )( PORT_HANDLE hPort, PORT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - GC_API_P(PGCRegisterEvent )( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID, EVENT_HANDLE *phEvent ); - GC_API_P(PGCUnregisterEvent )( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID ); - GC_API_P(PEventGetData )( EVENT_HANDLE hEvent, void *pBuffer, size_t *piSize, uint64_t iTimeout ); - GC_API_P(PEventGetDataInfo )( EVENT_HANDLE hEvent, const void *pInBuffer, size_t iInSize, EVENT_DATA_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pOutBuffer, size_t *piOutSize ); - GC_API_P(PEventGetInfo )( EVENT_HANDLE hEvent, EVENT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PEventFlush )( EVENT_HANDLE hEvent ); - GC_API_P(PEventKill )( EVENT_HANDLE hEvent ); - GC_API_P(PTLOpen )( TL_HANDLE *phTL ); - GC_API_P(PTLClose )( TL_HANDLE hTL ); - GC_API_P(PTLGetInfo )( TL_HANDLE hTL, TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PTLGetNumInterfaces )( TL_HANDLE hTL, uint32_t *piNumIfaces ); - GC_API_P(PTLGetInterfaceID )( TL_HANDLE hTL, uint32_t iIndex, char *sID, size_t *piSize ); - GC_API_P(PTLGetInterfaceInfo )( TL_HANDLE hTL, const char *sIfaceID, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PTLOpenInterface )( TL_HANDLE hTL, const char *sIfaceID, IF_HANDLE *phIface ); - GC_API_P(PTLUpdateInterfaceList )( TL_HANDLE hTL, bool8_t *pbChanged, uint64_t iTimeout ); - GC_API_P(PIFClose )( IF_HANDLE hIface ); - GC_API_P(PIFGetInfo )( IF_HANDLE hIface, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PIFGetNumDevices )( IF_HANDLE hIface, uint32_t *piNumDevices ); - GC_API_P(PIFGetDeviceID )( IF_HANDLE hIface, uint32_t iIndex, char *sIDeviceID, size_t *piSize ); - GC_API_P(PIFUpdateDeviceList )( IF_HANDLE hIface, bool8_t *pbChanged, uint64_t iTimeout ); - GC_API_P(PIFGetDeviceInfo )( IF_HANDLE hIface, const char *sDeviceID, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PIFOpenDevice )( IF_HANDLE hIface, const char *sDeviceID, DEVICE_ACCESS_FLAGS iOpenFlags, DEV_HANDLE *phDevice ); - - GC_API_P(PDevGetPort )( DEV_HANDLE hDevice, PORT_HANDLE *phRemoteDevice ); - GC_API_P(PDevGetNumDataStreams )( DEV_HANDLE hDevice, uint32_t *piNumDataStreams ); - GC_API_P(PDevGetDataStreamID )( DEV_HANDLE hDevice, uint32_t iIndex, char *sDataStreamID, size_t *piSize ); - GC_API_P(PDevOpenDataStream )( DEV_HANDLE hDevice, const char *sDataStreamID, DS_HANDLE *phDataStream ); - GC_API_P(PDevGetInfo )( DEV_HANDLE hDevice, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PDevClose )( DEV_HANDLE hDevice ); - - GC_API_P(PDSAnnounceBuffer )( DS_HANDLE hDataStream, void *pBuffer, size_t iSize, void *pPrivate, BUFFER_HANDLE *phBuffer ); - GC_API_P(PDSAllocAndAnnounceBuffer)( DS_HANDLE hDataStream, size_t iSize, void *pPrivate, BUFFER_HANDLE *phBuffer ); - GC_API_P(PDSFlushQueue )( DS_HANDLE hDataStream, ACQ_QUEUE_TYPE iOperation ); - GC_API_P(PDSStartAcquisition )( DS_HANDLE hDataStream, ACQ_START_FLAGS iStartFlags, uint64_t iNumToAcquire ); - GC_API_P(PDSStopAcquisition )( DS_HANDLE hDataStream, ACQ_STOP_FLAGS iStopFlags ); - GC_API_P(PDSGetInfo )( DS_HANDLE hDataStream, STREAM_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PDSGetBufferID )( DS_HANDLE hDataStream, uint32_t iIndex, BUFFER_HANDLE *phBuffer ); - GC_API_P(PDSClose )( DS_HANDLE hDataStream ); - GC_API_P(PDSRevokeBuffer )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, void **pBuffer, void **pPrivate ); - GC_API_P(PDSQueueBuffer )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer ); - GC_API_P(PDSGetBufferInfo )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, BUFFER_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - - /* GenTL v1.1 */ - GC_API_P(PGCGetNumPortURLs )( PORT_HANDLE hPort, uint32_t *iNumURLs ); - GC_API_P(PGCGetPortURLInfo )( PORT_HANDLE hPort, uint32_t iURLIndex, URL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); - GC_API_P(PGCReadPortStacked )( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); - GC_API_P(PGCWritePortStacked )( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); - - /* GenTL v1.3 */ - GC_API_P(PDSGetBufferChunkData )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, SINGLE_CHUNK_DATA *pChunkData, size_t *piNumChunks ); - - /* GenTL v1.4 */ - GC_API_P(PIFGetParentTL )( IF_HANDLE hIface, TL_HANDLE *phSystem ); - GC_API_P(PDevGetParentIF )( DEV_HANDLE hDevice, IF_HANDLE *phIface ); - GC_API_P(PDSGetParentDev )( DS_HANDLE hDataStream, DEV_HANDLE *phDevice ); - - /* GenTL v1.5 */ - GC_API_P(PDSGetNumBufferParts )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t *piNumParts ); - GC_API_P(PDSGetBufferPartInfo )( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t iPartIndex, BUFFER_PART_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, void *pBuffer, size_t *piSize ); -#ifdef __cplusplus - } /* end of namespace GenTL */ -} /* end of extern "C" */ -#endif -#endif /* GC_TLI_CLIENT_H_ */ diff --git a/sys/gentl/gstgentlsrc.c b/sys/gentl/gstgentlsrc.c deleted file mode 100644 index b58fec0..0000000 --- a/sys/gentl/gstgentlsrc.c +++ /dev/null @@ -1,2090 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstgentlsrc - * - * The gentlsrc element is a source for GenTL producers. - * - * - * Example launch line - * |[ - * gst-launch -v gentlsrc ! videoconvert ! autovideosink - * ]| - * Shows video from the first found GenTL producer. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include - -#include "genicampixelformat.h" -#include "get_unix_ns.h" - -#include "unzip.h" - -#include "gstgentlsrc.h" - -#ifdef HAVE_ORC -#include -#else -#define orc_memcpy memcpy -#endif - -// "C:\\BitFlow SDK 6.20\\Bin64\\BFGTL.cti"; -// "C:\\Program Files\\Basler\\pylon 5\\Runtime\\x64\\ProducerGEV.cti"; - -static void -initialize_evt_addresses (GstGenTlProducer * producer) -{ - memset (producer, 0, sizeof (producer)); - producer->cti_path = - g_strdup ("C:\\Program Files\\EVT\\eSDK\\bin\\EmergentGenTL.cti"); - producer->acquisition_mode_value = 0; - producer->timestamp_control_latch_value = 2; - producer->width = 0xA000; - producer->height = 0xA004; - producer->pixel_format = 0xA008; - producer->payload_size = 0xD008; - producer->acquisition_mode = 0xB000; - producer->acquisition_start = 0xB004; - producer->acquisition_stop = 0xB008; - producer->tick_frequency_low = 0x0940; - producer->tick_frequency_high = 0x093C; - producer->timestamp_control_latch = 0x944; - producer->timestamp_low = 0x094C; - producer->timestamp_high = 0x0948; - producer->port_endianness = G_BIG_ENDIAN; -} - -static void -initialize_basler_addresses (GstGenTlProducer * producer) -{ - memset (producer, 0, sizeof (producer)); - producer->cti_path = - g_strdup - ("C:\\Program Files\\Basler\\pylon 5\\Runtime\\x64\\ProducerGEV.cti"); - producer->acquisition_mode_value = 2; - producer->width = 0x30204; - producer->height = 0x30224; - producer->pixel_format = 0x30024; - producer->payload_size = 0x10088; - producer->acquisition_mode = 0x40004; - producer->acquisition_start = 0x40024; - producer->acquisition_stop = 0x40044; - producer->port_endianness = G_BIG_ENDIAN; -} - -static void -initialize_flir_addresses (GstGenTlProducer * producer) -{ - memset (producer, 0, sizeof (producer)); - producer->cti_path = - g_strdup - ("C:\\Program Files\\FLIR Systems\\Spinnaker\\cti64\\vs2015\\FLIR_GenTL_v140.cti"); - producer->acquisition_mode_value = 0; - producer->timestamp_control_latch_value = 1; - producer->width = 0x00081084; - producer->height = 0x00081064; - producer->pixel_format = 0x00086008; - producer->payload_size = 0x20002008; - producer->acquisition_mode = 0x000C00C8; - producer->acquisition_start = 0x000C0004; - producer->acquisition_stop = 0x000C0024; - producer->timestamp_control_latch = 0x1F8; - producer->timestamp = 0x1F0; - producer->port_endianness = G_LITTLE_ENDIAN; -} - - -#define GST_TYPE_GENTLSRC_PRODUCER (gst_gentlsrc_producer_get_type()) -static GType -gst_gentlsrc_producer_get_type (void) -{ - static GType gentlsrc_producer_type = 0; - static const GEnumValue gentlsrc_producer[] = { - {GST_GENTLSRC_PRODUCER_BASLER, "Basler producer", "basler"}, - {GST_GENTLSRC_PRODUCER_EVT, "EVT producer", "evt"}, - {GST_GENTLSRC_PRODUCER_FLIR, "FLIR producer", "flir"}, - {0, NULL, NULL}, - }; - - if (!gentlsrc_producer_type) { - gentlsrc_producer_type = - g_enum_register_static ("GstGenTlSrcProducer", gentlsrc_producer); - } - return gentlsrc_producer_type; -} - -GST_DEBUG_CATEGORY_STATIC (gst_gentlsrc_debug); -#define GST_CAT_DEFAULT gst_gentlsrc_debug - -/* prototypes */ -static void gst_gentlsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_gentlsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_gentlsrc_dispose (GObject * object); -static void gst_gentlsrc_finalize (GObject * object); - -static gboolean gst_gentlsrc_start (GstBaseSrc * src); -static gboolean gst_gentlsrc_stop (GstBaseSrc * src); -static GstCaps *gst_gentlsrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_gentlsrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_gentlsrc_unlock (GstBaseSrc * src); -static gboolean gst_gentlsrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_gentlsrc_create (GstPushSrc * src, GstBuffer ** buf); - -static gchar *gst_gentlsrc_get_error_string (GstGenTlSrc * src); -static void gst_gentlsrc_cleanup_tl (GstGenTlSrc * src); -static gboolean gst_gentlsrc_src_latch_timestamps (GstGenTlSrc * src); - -enum -{ - PROP_0, - PROP_PRODUCER, - PROP_INTERFACE_INDEX, - PROP_INTERFACE_ID, - PROP_DEVICE_INDEX, - PROP_DEVICE_ID, - PROP_DEVICE_USER_ID, - PROP_STREAM_INDEX, - PROP_STREAM_ID, - PROP_NUM_CAPTURE_BUFFERS, - PROP_TIMEOUT, - PROP_ATTRIBUTES -}; - -#define DEFAULT_PROP_PRODUCER GST_GENTLSRC_PRODUCER_BASLER -#define DEFAULT_PROP_INTERFACE_INDEX 0 -#define DEFAULT_PROP_INTERFACE_ID "" -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_DEVICE_ID "" -#define DEFAULT_PROP_DEVICE_USER_ID "" -#define DEFAULT_PROP_STREAM_INDEX 0 -#define DEFAULT_PROP_STREAM_ID "" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_TIMEOUT 1000 -#define DEFAULT_PROP_ATTRIBUTES "" - -/* pad templates */ - -static GstStaticPadTemplate gst_gentlsrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGRA, UYVY }") ";" - GST_GENICAM_PIXEL_FORMAT_MAKE_BAYER8 ("{ bggr, grbg, rggb, gbrg }") ";" - GST_GENICAM_PIXEL_FORMAT_MAKE_BAYER16 - ("{ bggr16, grbg16, rggb16, gbrg16 }", "1234") - ) - ); - -#define HANDLE_GTL_ERROR(arg) \ - if (ret != GC_ERR_SUCCESS) { \ - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, \ - (arg ": %s", gst_gentlsrc_get_error_string (src)), (NULL)); \ - goto error; \ - } - -#define HANDLE_GTL_WARNING(arg) \ - if (ret != GC_ERR_SUCCESS) { \ - GST_ELEMENT_WARNING (src, LIBRARY, FAILED, \ - (arg ": %s", gst_gentlsrc_get_error_string (src)), (NULL)); \ - goto error; \ - } - -PGCGetInfo GTL_GCGetInfo; -PGCGetLastError GTL_GCGetLastError; -PGCInitLib GTL_GCInitLib; -PGCCloseLib GTL_GCCloseLib; -PGCReadPort GTL_GCReadPort; -PGCWritePort GTL_GCWritePort; -PGCGetPortURL GTL_GCGetPortURL; -PGCGetPortInfo GTL_GCGetPortInfo; -PGCRegisterEvent GTL_GCRegisterEvent; -PGCUnregisterEvent GTL_GCUnregisterEvent; -PEventGetData GTL_EventGetData; -PEventGetDataInfo GTL_EventGetDataInfo; -PEventGetInfo GTL_EventGetInfo; -PEventFlush GTL_EventFlush; -PEventKill GTL_EventKill; -PTLOpen GTL_TLOpen; -PTLClose GTL_TLClose; -PTLGetInfo GTL_TLGetInfo; -PTLGetNumInterfaces GTL_TLGetNumInterfaces; -PTLGetInterfaceID GTL_TLGetInterfaceID; -PTLGetInterfaceInfo GTL_TLGetInterfaceInfo; -PTLOpenInterface GTL_TLOpenInterface; -PTLUpdateInterfaceList GTL_TLUpdateInterfaceList; -PIFClose GTL_IFClose; -PIFGetInfo GTL_IFGetInfo; -PIFGetNumDevices GTL_IFGetNumDevices; -PIFGetDeviceID GTL_IFGetDeviceID; -PIFUpdateDeviceList GTL_IFUpdateDeviceList; -PIFGetDeviceInfo GTL_IFGetDeviceInfo; -PIFOpenDevice GTL_IFOpenDevice; -PDevGetPort GTL_DevGetPort; -PDevGetNumDataStreams GTL_DevGetNumDataStreams; -PDevGetDataStreamID GTL_DevGetDataStreamID; -PDevOpenDataStream GTL_DevOpenDataStream; -PDevGetInfo GTL_DevGetInfo; -PDevClose GTL_DevClose; -PDSAnnounceBuffer GTL_DSAnnounceBuffer; -PDSAllocAndAnnounceBuffer GTL_DSAllocAndAnnounceBuffer; -PDSFlushQueue GTL_DSFlushQueue; -PDSStartAcquisition GTL_DSStartAcquisition; -PDSStopAcquisition GTL_DSStopAcquisition; -PDSGetInfo GTL_DSGetInfo; -PDSGetBufferID GTL_DSGetBufferID; -PDSClose GTL_DSClose; -PDSRevokeBuffer GTL_DSRevokeBuffer; -PDSQueueBuffer GTL_DSQueueBuffer; -PDSGetBufferInfo GTL_DSGetBufferInfo; -PGCGetNumPortURLs GTL_GCGetNumPortURLs; -PGCGetPortURLInfo GTL_GCGetPortURLInfo; - -#define GTL_BIND(fcn) if (!g_module_symbol (module, G_STRINGIFY(fcn), (gpointer *) & GTL_##fcn)) { \ - GST_DEBUG_OBJECT(src, "Failed to bind function " G_STRINGIFY(fcn)); goto error; } - -gboolean -gst_gentlsrc_bind_functions (GstGenTlSrc * src) -{ - GModule *module; - const char *cti_path = src->producer.cti_path; - gboolean ret = TRUE; - - GST_DEBUG_OBJECT (src, "Trying to bind functions from '%s'", cti_path); - - module = g_module_open (cti_path, G_MODULE_BIND_LAZY); - if (!module) { - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - ("GenTL CTI %s could not be opened: %s", cti_path, g_module_error ()), - (NULL)); - return FALSE; - } - - GTL_BIND (GCGetInfo); - GTL_BIND (GCGetLastError); - GTL_BIND (GCInitLib); - GTL_BIND (GCCloseLib); - GTL_BIND (GCReadPort); - GTL_BIND (GCWritePort); - GTL_BIND (GCGetPortURL); - GTL_BIND (GCGetPortInfo); - GTL_BIND (GCRegisterEvent); - GTL_BIND (GCUnregisterEvent); - GTL_BIND (EventGetData); - GTL_BIND (EventGetDataInfo); - GTL_BIND (EventGetInfo); - GTL_BIND (EventFlush); - GTL_BIND (EventKill); - GTL_BIND (TLOpen); - GTL_BIND (TLClose); - GTL_BIND (TLGetInfo); - GTL_BIND (TLGetNumInterfaces); - GTL_BIND (TLGetInterfaceID); - GTL_BIND (TLGetInterfaceInfo); - GTL_BIND (TLOpenInterface); - GTL_BIND (TLUpdateInterfaceList); - GTL_BIND (IFClose); - GTL_BIND (IFGetInfo); - GTL_BIND (IFGetNumDevices); - GTL_BIND (IFGetDeviceID); - GTL_BIND (IFUpdateDeviceList); - GTL_BIND (IFGetDeviceInfo); - GTL_BIND (IFOpenDevice); - GTL_BIND (DevGetPort); - GTL_BIND (DevGetNumDataStreams); - GTL_BIND (DevGetDataStreamID); - GTL_BIND (DevOpenDataStream); - GTL_BIND (DevGetInfo); - GTL_BIND (DevClose); - GTL_BIND (DSAnnounceBuffer); - GTL_BIND (DSAllocAndAnnounceBuffer); - GTL_BIND (DSFlushQueue); - GTL_BIND (DSStartAcquisition); - GTL_BIND (DSStopAcquisition); - GTL_BIND (DSGetInfo); - GTL_BIND (DSGetBufferID); - GTL_BIND (DSClose); - GTL_BIND (DSRevokeBuffer); - GTL_BIND (DSQueueBuffer); - GTL_BIND (DSGetBufferInfo); - GTL_BIND (GCGetNumPortURLs); - GTL_BIND (GCGetPortURLInfo); - - return TRUE; - -error: - GST_ERROR_OBJECT (src, "One or more functions doesn't exist in %s", cti_path); - return FALSE; -} - - -/* class initialization */ - -G_DEFINE_TYPE (GstGenTlSrc, gst_gentlsrc, GST_TYPE_PUSH_SRC); - -static void -gst_gentlsrc_class_init (GstGenTlSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_gentlsrc_set_property; - gobject_class->get_property = gst_gentlsrc_get_property; - gobject_class->dispose = gst_gentlsrc_dispose; - gobject_class->finalize = gst_gentlsrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_gentlsrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "GenTL Video Source", "Source/Video", - "GenTL framegrabber video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_gentlsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_gentlsrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_gentlsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_gentlsrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_gentlsrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_gentlsrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_gentlsrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_PRODUCER, - g_param_spec_enum ("producer", "Producer", "GenTL producer", - GST_TYPE_GENTLSRC_PRODUCER, DEFAULT_PROP_PRODUCER, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_PLAYING)); - - g_object_class_install_property (gobject_class, PROP_INTERFACE_INDEX, - g_param_spec_uint ("interface-index", "Interface index", - "Interface index number, zero-based, overridden by interface-id", - 0, G_MAXUINT, DEFAULT_PROP_INTERFACE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_INTERFACE_ID, - g_param_spec_string ("interface-id", "Interface ID", - "Interface ID, overrides interface-index if not empty string", - DEFAULT_PROP_INTERFACE_ID, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_uint ("device-index", "Device index", - "Device index number, zero-based, overridden by device-id", - 0, G_MAXUINT, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_ID, - g_param_spec_string ("device-id", "Device ID", - "Device ID, overrides device-index if not empty string", - DEFAULT_PROP_DEVICE_ID, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_USER_ID, - g_param_spec_string ("device-user-id", "Device User ID", - "Device User ID, overrides all other interface/device properties", - DEFAULT_PROP_DEVICE_USER_ID, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_STREAM_INDEX, - g_param_spec_uint ("stream-index", "Stream index", - "Stream index number, zero-based, overridden by stream-id", - 0, G_MAXUINT, DEFAULT_PROP_STREAM_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_STREAM_ID, - g_param_spec_string ("stream-id", "Stream ID", - "Stream ID, overrides stream-index if not empty string", - DEFAULT_PROP_STREAM_ID, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_ATTRIBUTES, g_param_spec_string ("attributes", - "Attributes", "Attributes to change, comma separated key=value pairs", - DEFAULT_PROP_ATTRIBUTES, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - - klass->hTL = NULL; - g_mutex_init (&klass->tl_mutex); - klass->tl_refcount = 0; -} - -static void -gst_gentlsrc_reset (GstGenTlSrc * src) -{ - src->gentl_latched_ns = 0; - src->unix_latched_ns = 0; - - src->error_string[0] = 0; - src->last_frame_count = 0; - src->total_dropped_frames = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } -} - -static void -gst_gentlsrc_init (GstGenTlSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->producer_prop = DEFAULT_PROP_PRODUCER; - src->interface_index = DEFAULT_PROP_INTERFACE_INDEX; - src->interface_id = g_strdup (DEFAULT_PROP_INTERFACE_ID); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->timeout = DEFAULT_PROP_TIMEOUT; - src->attributes = g_strdup (DEFAULT_PROP_ATTRIBUTES); - - src->stop_requested = FALSE; - src->caps = NULL; - - src->hTL = NULL; - src->hIF = NULL; - src->hDEV = NULL; - src->hDS = NULL; - - gst_gentlsrc_reset (src); -} - -void -gst_gentlsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstGenTlSrc *src; - - src = GST_GENTL_SRC (object); - - switch (property_id) { - case PROP_PRODUCER: - src->producer_prop = g_value_get_enum (value); - break; - case PROP_INTERFACE_INDEX: - src->interface_index = g_value_get_uint (value); - break; - case PROP_INTERFACE_ID: - g_free (src->interface_id); - src->interface_id = g_strdup (g_value_get_string (value)); - break; - case PROP_DEVICE_INDEX: - src->device_index = g_value_get_uint (value); - break; - case PROP_DEVICE_ID: - g_free (src->device_id); - src->device_id = g_strdup (g_value_get_string (value)); - break; - case PROP_DEVICE_USER_ID: - g_free (src->device_user_id); - src->device_user_id = g_strdup (g_value_get_string (value)); - break; - case PROP_STREAM_INDEX: - src->stream_index = g_value_get_uint (value); - break; - case PROP_STREAM_ID: - g_free (src->stream_id); - src->stream_id = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - src->num_capture_buffers = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - case PROP_ATTRIBUTES: - if (src->attributes) - g_free (src->attributes); - src->attributes = g_strdup (g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_gentlsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstGenTlSrc *src; - - g_return_if_fail (GST_IS_GENTL_SRC (object)); - src = GST_GENTL_SRC (object); - - switch (property_id) { - case PROP_PRODUCER: - g_value_set_enum (value, src->producer_prop); - break; - case PROP_INTERFACE_INDEX: - g_value_set_uint (value, src->interface_index); - break; - case PROP_INTERFACE_ID: - g_value_set_string (value, src->interface_id); - break; - case PROP_DEVICE_INDEX: - g_value_set_uint (value, src->device_index); - break; - case PROP_DEVICE_ID: - g_value_set_string (value, src->device_id); - break; - case PROP_DEVICE_USER_ID: - g_value_set_string (value, src->device_user_id); - break; - case PROP_STREAM_INDEX: - g_value_set_uint (value, src->stream_index); - break; - case PROP_STREAM_ID: - g_value_set_string (value, src->stream_id); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - case PROP_ATTRIBUTES: - g_value_set_string (value, src->attributes); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_gentlsrc_dispose (GObject * object) -{ - GstGenTlSrc *src; - - g_return_if_fail (GST_IS_GENTL_SRC (object)); - src = GST_GENTL_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_gentlsrc_parent_class)->dispose (object); -} - -void -gst_gentlsrc_finalize (GObject * object) -{ - GstGenTlSrc *src; - - g_return_if_fail (GST_IS_GENTL_SRC (object)); - src = GST_GENTL_SRC (object); - - /* clean up object here */ - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - G_OBJECT_CLASS (gst_gentlsrc_parent_class)->finalize (object); -} - -#define GTL_MAX_STR_SIZE 256 - -void -gst_gentl_print_gentl_impl_info (GstGenTlSrc * src) -{ - size_t str_size; - char id[GTL_MAX_STR_SIZE]; - char vendor[GTL_MAX_STR_SIZE]; - char model[GTL_MAX_STR_SIZE]; - char version[GTL_MAX_STR_SIZE]; - char tl_type[GTL_MAX_STR_SIZE]; - char name[GTL_MAX_STR_SIZE]; - char path_name[GTL_MAX_STR_SIZE]; - char display_name[GTL_MAX_STR_SIZE]; - INFO_DATATYPE datatype; - - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_ID, &datatype, id, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_VENDOR, &datatype, vendor, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_MODEL, &datatype, model, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_VERSION, &datatype, version, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_TLTYPE, &datatype, tl_type, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_NAME, &datatype, name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_PATHNAME, &datatype, path_name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_GCGetInfo (TL_INFO_DISPLAYNAME, &datatype, display_name, &str_size); - - GST_DEBUG_OBJECT (src, - "ID=%s, Vendor=%s, Model=%s, Version=%s, TL_Type=%s, Name=%s, Path_Name=%s, Display_Name=%s", - id, vendor, model, version, tl_type, name, path_name, display_name); -} - -void -gst_gentl_print_system_info (GstGenTlSrc * src) -{ - size_t str_size; - char id[GTL_MAX_STR_SIZE]; - char vendor[GTL_MAX_STR_SIZE]; - char model[GTL_MAX_STR_SIZE]; - char version[GTL_MAX_STR_SIZE]; - char tl_type[GTL_MAX_STR_SIZE]; - char name[GTL_MAX_STR_SIZE]; - char path_name[GTL_MAX_STR_SIZE]; - char display_name[GTL_MAX_STR_SIZE]; - INFO_DATATYPE datatype; - - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_ID, &datatype, id, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_VENDOR, &datatype, vendor, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_MODEL, &datatype, model, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_VERSION, &datatype, version, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_TLTYPE, &datatype, tl_type, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_NAME, &datatype, name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_PATHNAME, &datatype, path_name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInfo (src->hTL, TL_INFO_DISPLAYNAME, &datatype, display_name, - &str_size); - - GST_DEBUG_OBJECT (src, - "System: ID=%s, Vendor=%s, Model=%s, Version=%s, TL_Type=%s, Name=%s, Path_Name=%s, Display_Name=%s", - id, vendor, model, version, tl_type, name, path_name, display_name); -} - -void -gst_gentl_print_interface_info (GstGenTlSrc * src, uint32_t index) -{ - GC_ERROR ret; - size_t str_size; - char iface_id[GTL_MAX_STR_SIZE]; - char id[GTL_MAX_STR_SIZE]; - char tl_type[GTL_MAX_STR_SIZE]; - char display_name[GTL_MAX_STR_SIZE]; - INFO_DATATYPE datatype; - - str_size = GTL_MAX_STR_SIZE; - ret = GTL_TLGetInterfaceID (src->hTL, index, iface_id, &str_size); - if (ret != GC_ERR_SUCCESS) { - GST_WARNING_OBJECT (src, "Failed to get interface id (error=%d): %s", ret, - gst_gentlsrc_get_error_string (src)); - return; - } - - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInterfaceInfo (src->hTL, iface_id, INTERFACE_INFO_ID, &datatype, id, - &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInterfaceInfo (src->hTL, iface_id, INTERFACE_INFO_DISPLAYNAME, - &datatype, display_name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_TLGetInterfaceInfo (src->hTL, iface_id, INTERFACE_INFO_TLTYPE, &datatype, - tl_type, &str_size); - - GST_DEBUG_OBJECT (src, "Interface %d: ID=%s, TL_Type=%s, Display_Name=%s", - index, id, tl_type, display_name); -} - -void -gst_gentl_print_device_info (GstGenTlSrc * src, uint32_t index) -{ - GC_ERROR ret; - size_t str_size; - char dev_id[GTL_MAX_STR_SIZE]; - char id[GTL_MAX_STR_SIZE]; - char vendor[GTL_MAX_STR_SIZE]; - char model[GTL_MAX_STR_SIZE]; - char tl_type[GTL_MAX_STR_SIZE]; - char display_name[GTL_MAX_STR_SIZE]; - char user_defined_name[GTL_MAX_STR_SIZE]; - gint32 access_status; - INFO_DATATYPE datatype; - - str_size = GTL_MAX_STR_SIZE; - ret = GTL_IFGetDeviceID (src->hIF, index, dev_id, &str_size); - if (ret != GC_ERR_SUCCESS) { - GST_WARNING_OBJECT (src, "Failed to get device id: %s", - gst_gentlsrc_get_error_string (src)); - return; - } - - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_ID, &datatype, id, - &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_VENDOR, &datatype, vendor, - &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_MODEL, &datatype, model, - &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_TLTYPE, &datatype, tl_type, - &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_DISPLAYNAME, &datatype, - display_name, &str_size); - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_USER_DEFINED_NAME, - &datatype, user_defined_name, &str_size); - str_size = sizeof (access_status); - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_ACCESS_STATUS, &datatype, - &access_status, &str_size); - - GST_DEBUG_OBJECT (src, - "Device %d: ID=%s, Vendor=%s, Model=%s, TL_Type=%s, Display_Name=%s, User_Name=%s, Access_Status=%d", - index, id, vendor, model, tl_type, display_name, user_defined_name, - access_status); -} - -//void gst_gentl_print_stream_info (GstGenTlSrc * src) -//{ -// GC_ERROR ret; -// size_t str_size; -// char dev_id[GTL_MAX_STR_SIZE]; -// char id[GTL_MAX_STR_SIZE]; -// char vendor[GTL_MAX_STR_SIZE]; -// char model[GTL_MAX_STR_SIZE]; -// char tl_type[GTL_MAX_STR_SIZE]; -// char display_name[GTL_MAX_STR_SIZE]; -// gint32 access_status; -// INFO_DATATYPE datatype; -// -// //ret = GTL_DevGetDataStreamID(src->hIF, index, dev_id, &str_size); -// //if (ret != GC_ERR_SUCCESS) { -// // GST_WARNING_OBJECT (src, "Failed to get stream id: %s", gst_gentlsrc_get_error_string(src)); -// // return; -// //} -// -// str_size = GTL_MAX_STR_SIZE; -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_ID, &datatype, id, &str_size); -// str_size = GTL_MAX_STR_SIZE; -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_VENDOR, &datatype, vendor, &str_size); -// str_size = GTL_MAX_STR_SIZE; -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_MODEL, &datatype, model, &str_size); -// str_size = GTL_MAX_STR_SIZE; -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_TLTYPE, &datatype, tl_type, &str_size); -// str_size = GTL_MAX_STR_SIZE; -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_DISPLAYNAME, &datatype, display_name, &str_size); -// str_size = sizeof(access_status); -// GTL_DSGetInfo(src->hDEV, DEVICE_INFO_ACCESS_STATUS, &datatype, &access_status, &str_size); -// -// GST_DEBUG_OBJECT (src, "Device %d: ID=%s, Vendor=%s, Model=%s, TL_Type=%s, Display_Name=%s, Access_Status=%d", -// index, id, vendor, model, tl_type, display_name, access_status); -//} - - -static guint32 -read_uint32 (GstGenTlSrc * src, guint64 addr, GC_ERROR * ret) -{ - guint32 value; - size_t datasize = 4; - - *ret = GTL_GCReadPort (src->hDevPort, addr, &value, &datasize); - if (*ret != GC_ERR_SUCCESS) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to read address: %s", gst_gentlsrc_get_error_string (src)), - (NULL)); - goto error; - } - - if (src->producer.port_endianness == G_BIG_ENDIAN) - value = GUINT32_FROM_BE (value); - else - value = GUINT32_FROM_LE (value); - - return value; - -error: - return 0; -} - -static gboolean -write_uint32 (GstGenTlSrc * src, guint64 addr, guint32 value) -{ - GC_ERROR ret; - size_t datasize = 4; - - if (src->producer.port_endianness == G_BIG_ENDIAN) - value = GUINT32_TO_BE (value); - else - value = GUINT32_TO_LE (value); - - ret = GTL_GCWritePort (src->hDevPort, addr, &value, &datasize); - HANDLE_GTL_ERROR ("Failed to write address"); - - return ret; - -error: - return ret; -} - -static guint64 -read_uint64_single (GstGenTlSrc * src, guint64 addr, GC_ERROR * ret) -{ - guint64 value; - size_t datasize = 8; - - *ret = GTL_GCReadPort (src->hDevPort, addr, &value, &datasize); - if (*ret != GC_ERR_SUCCESS) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to read address: %s", gst_gentlsrc_get_error_string (src)), - (NULL)); - goto error; - } - - if (src->producer.port_endianness == G_BIG_ENDIAN) - value = GUINT64_FROM_BE (value); - else - value = GUINT64_FROM_LE (value); - - return value; - -error: - return 0; -} - -static guint64 -read_uint64 (GstGenTlSrc * src, guint64 low_addr, guint64 high_addr, - GC_ERROR * ret) -{ - guint32 low, high; - size_t datasize = 4; - guint64 value; - - *ret = GTL_GCReadPort (src->hDevPort, low_addr, &low, &datasize); - if (*ret != GC_ERR_SUCCESS) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to read lower address: %s", - gst_gentlsrc_get_error_string (src)), (NULL)); - goto error; - } - *ret = GTL_GCReadPort (src->hDevPort, high_addr, &high, &datasize); - if (*ret != GC_ERR_SUCCESS) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to read upper address: %s", - gst_gentlsrc_get_error_string (src)), (NULL)); - goto error; - } - - if (src->producer.port_endianness == G_BIG_ENDIAN) - value = GUINT64_FROM_BE ((guint64) low << 32 | high); - else - value = GUINT64_FROM_LE ((guint64) low << 32 | high); - - return value; - -error: - return 0; -} - - -static size_t -gst_gentlsrc_get_payload_size (GstGenTlSrc * src) -{ - GC_ERROR ret; - INFO_DATATYPE info_datatype; - size_t info_size; - bool8_t size_defined; - size_t payload_size = 0; - - info_size = sizeof (size_defined); - ret = - GTL_DSGetInfo (src->hDS, STREAM_INFO_DEFINES_PAYLOADSIZE, &info_datatype, - &size_defined, &info_size); - - if (size_defined) { - info_size = sizeof (payload_size); - ret = - GTL_DSGetInfo (src->hDS, STREAM_INFO_PAYLOAD_SIZE, &info_datatype, - &payload_size, &info_size); - GST_DEBUG_OBJECT (src, "Payload size defined by stream info: %d", - payload_size); - } else { - guint32 val = 0; - // TODO: use node map - payload_size = read_uint32 (src, src->producer.payload_size, &ret); - HANDLE_GTL_ERROR ("Failed to get payload size"); - GST_DEBUG_OBJECT (src, "Payload size defined by node map: %d", - payload_size); - - //PORT_HANDLE port_handle; - //ret = GTL_DevGetPort(src->hDEV, &port_handle); - - //GTL_GCGetNum - - //GTL_GCReadPort(port_handle, ) - ////GTL_GCGetPortInfo(port_handle, ) - } - - return payload_size; - -error: - return 0; -} - -static gboolean -gst_gentlsrc_prepare_buffers (GstGenTlSrc * src) -{ - size_t payload_size; - guint i; - BUFFER_HANDLE hBuffer; - GC_ERROR ret; - - /* TODO: query Data Stream features to find min/max num_buffers */ - payload_size = gst_gentlsrc_get_payload_size (src); - if (payload_size == 0) { - GST_DEBUG_OBJECT (src, "Payload size is zero"); - return FALSE; - } - - for (i = 0; i < src->num_capture_buffers; ++i) { - ret = GTL_DSAllocAndAnnounceBuffer (src->hDS, payload_size, NULL, &hBuffer); - HANDLE_GTL_ERROR ("Failed to alloc and announce buffer"); - - ret = GTL_DSQueueBuffer (src->hDS, hBuffer); - HANDLE_GTL_ERROR ("Failed to queue buffer"); - } - - ret = GTL_DSFlushQueue (src->hDS, ACQ_QUEUE_ALL_TO_INPUT); - HANDLE_GTL_ERROR ("Failed to queue all buffers to input"); - - return TRUE; - -error: - return FALSE; -} - -static guint64 -gst_gentlsrc_get_gev_tick_frequency (GstGenTlSrc * src) -{ - GC_ERROR ret; - - if (!src->producer.tick_frequency_high || !src->producer.tick_frequency_low) { - // latch timestamps once - if (gst_gentlsrc_src_latch_timestamps (src)) { - GST_DEBUG_OBJECT (src, "Assuming timestamps are in nanoseconds"); - return GST_SECOND; - } else { - GST_ERROR_OBJECT (src, "Tick frequency addresses aren't defined"); - return 0; - } - } - - guint64 tick_frequency = read_uint64 (src, src->producer.tick_frequency_low, - src->producer.tick_frequency_high, &ret); - GST_DEBUG_OBJECT (src, "GEV Timestamp tick frequency is %llu", - tick_frequency); - - return tick_frequency; -} - -static guint64 -gst_gentlsrc_get_gev_timestamp_ns (GstGenTlSrc * src) -{ - GC_ERROR ret; - guint64 timestamp_ns; - - ret = - write_uint32 (src, src->producer.timestamp_control_latch, - src->producer.timestamp_control_latch_value); - HANDLE_GTL_WARNING ("Failed to latch timestamp GevTimestampControlLatch"); - - if (src->producer.timestamp) { - timestamp_ns = read_uint64_single (src, src->producer.timestamp, &ret); - HANDLE_GTL_WARNING ("Failed to read device timestamp"); - } else { - guint64 ticks = read_uint64 (src, src->producer.timestamp_low, - src->producer.timestamp_high, &ret); - HANDLE_GTL_WARNING ("Failed to read timestamp ticks"); - GST_LOG_OBJECT (src, "Timestamp ticks are %llu", ticks); - - if (src->tick_frequency == 0) { - GST_WARNING_OBJECT (src, - "Tick frequency undefined, can't timestamp accurately"); - goto error; - } - timestamp_ns = ((guint64) - (ticks * ((double) GST_SECOND / src->tick_frequency)));; - } - - GST_LOG_OBJECT (src, "Device timestamp in ns is %llu", timestamp_ns); - - return timestamp_ns; - -error: - return 0; -} - -static gboolean -gst_gentlsrc_src_latch_timestamps (GstGenTlSrc * src) -{ - guint64 unix_ts, gev_ts; - - unix_ts = get_unix_ns (); - gev_ts = gst_gentlsrc_get_gev_timestamp_ns (src); - - if (gev_ts != 0) { - src->unix_latched_ns = unix_ts; - src->gentl_latched_ns = gev_ts; - GST_LOG_OBJECT (src, "Latched system time: %llu", src->unix_latched_ns); - GST_LOG_OBJECT (src, "Latched GenTL time : %llu", src->gentl_latched_ns); - return TRUE; - } else { - GST_WARNING_OBJECT (src, "Failed to latch GEV time, using old latch value"); - return FALSE; - } -} - -static void -gst_gentlsrc_set_attributes (GstGenTlSrc * src) -{ - gchar **pairs; - int i; - GC_ERROR ret; - - if (!src->attributes || src->attributes == 0) { - return; - } - - GST_DEBUG_OBJECT (src, "Trying to set following attributes: '%s'", - src->attributes); - - pairs = g_strsplit (src->attributes, ";", 0); - - for (i = 0;; i++) { - gchar **pair; - - if (!pairs[i]) - break; - - pair = g_strsplit (pairs[i], "=", 2); - - if (!pair[0] || !pair[1]) { - GST_WARNING_OBJECT (src, "Failed to parse attribute/value: '%s'", pair); - continue; - } - - GST_DEBUG_OBJECT (src, "Setting attribute, '%s'='%s'", pair[0], pair[1]); - - ret = write_uint32 (src, strtol (pair[0], NULL, 16), atoi (pair[1])); - if (ret != GC_ERR_SUCCESS) { - GST_WARNING_OBJECT (src, "Failed to set attribute: %s", - gst_gentlsrc_get_error_string (src)); - } - g_strfreev (pair); - } - g_strfreev (pairs); - - if (src->attributes) { - g_free (src->attributes); - src->attributes = NULL; - } -} - -static gboolean -gst_gentlsrc_open_tl (GstGenTlSrc * src) -{ - GstGenTlSrcClass *klass = GST_GENTL_SRC_GET_CLASS (src); - GC_ERROR ret; - uint32_t i, num_ifaces; - - /* open framegrabber if it isn't already opened */ - if (klass->tl_refcount > 0) { - GST_DEBUG_OBJECT (src, - "Framegrabber interface already opened in this process, reusing"); - src->hTL = klass->hTL; - klass->tl_refcount++; - } else { - /* initialize library and print info */ - ret = GTL_GCInitLib (); - //HANDLE_GTL_ERROR ("GenTL Producer library could not be initialized"); - - gst_gentl_print_gentl_impl_info (src); - - /* open GenTL, print info, and update interface list */ - ret = GTL_TLOpen (&src->hTL); - HANDLE_GTL_ERROR ("System module failed to open"); - - gst_gentl_print_system_info (src); - - ret = GTL_TLUpdateInterfaceList (src->hTL, NULL, src->timeout); - HANDLE_GTL_ERROR ("Failed to update interface list within timeout"); - - /* print info for all interfaces and open specified interface */ - ret = GTL_TLGetNumInterfaces (src->hTL, &num_ifaces); - HANDLE_GTL_ERROR ("Failed to get number of interfaces"); - if (num_ifaces > 0) { - GST_DEBUG_OBJECT (src, "Found %d GenTL interfaces", num_ifaces); - for (i = 0; i < num_ifaces; ++i) { - gst_gentl_print_interface_info (src, i); - } - } else { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, ("No interfaces found"), (NULL)); - goto error; - } - - klass->hTL = src->hTL; - klass->tl_refcount++; - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_gentlsrc_open_interface (GstGenTlSrc * src) -{ - GstGenTlSrcClass *klass = GST_GENTL_SRC_GET_CLASS (src); - GC_ERROR ret; - - if (!src->interface_id || src->interface_id[0] == 0) { - size_t id_size; - GST_DEBUG_OBJECT (src, "Trying to find interface ID at index %d", - src->interface_index); - - ret = GTL_TLGetInterfaceID (src->hTL, src->interface_index, NULL, &id_size); - HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); - if (src->interface_id) { - g_free (src->interface_id); - } - src->interface_id = (gchar *) g_malloc (id_size); - ret = - GTL_TLGetInterfaceID (src->hTL, src->interface_index, src->interface_id, - &id_size); - HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); - } - - GST_DEBUG_OBJECT (src, "Trying to open interface '%s'", src->interface_id); - ret = GTL_TLOpenInterface (src->hTL, src->interface_id, &src->hIF); - HANDLE_GTL_ERROR ("Interface module failed to open"); - - return TRUE; - -error: - return FALSE; -} - -static void -gst_gentlsrc_close_interface (GstGenTlSrc * src) -{ - if (src->hIF) { - GTL_IFClose (src->hIF); - src->hIF = NULL; - } -} - -static void -get_gentlsrc_select_user_id (GstGenTlSrc * src) -{ - GstGenTlSrcClass *klass = GST_GENTL_SRC_GET_CLASS (src); - GC_ERROR ret; - uint32_t num_ifaces, num_devs; - char dev_id[GTL_MAX_STR_SIZE]; - - ret = GTL_TLGetNumInterfaces (src->hTL, &num_ifaces); - HANDLE_GTL_ERROR ("Failed to get number of interfaces"); - - GST_DEBUG_OBJECT (src, - "Trying to find device-user-id='%s' on all %d interfaces", - src->device_user_id, num_ifaces); - - for (src->interface_index = 0; src->interface_index < num_ifaces; - src->interface_index++) { - size_t id_size; - GST_DEBUG_OBJECT (src, "Trying to find interface ID at index %d", - src->interface_index); - - ret = GTL_TLGetInterfaceID (src->hTL, src->interface_index, NULL, &id_size); - HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); - if (src->interface_id) { - g_free (src->interface_id); - } - src->interface_id = (gchar *) g_malloc (id_size); - ret = - GTL_TLGetInterfaceID (src->hTL, src->interface_index, src->interface_id, - &id_size); - HANDLE_GTL_ERROR ("Failed to get interface ID at specified index"); - GST_DEBUG_OBJECT (src, "Trying to open interface '%s'", src->interface_id); - ret = GTL_TLOpenInterface (src->hTL, src->interface_id, &src->hIF); - if (ret != GC_ERR_SUCCESS) { - GST_WARNING_OBJECT (src, "Interface failed to open"); - continue; - } - - ret = GTL_IFUpdateDeviceList (src->hIF, NULL, src->timeout); - HANDLE_GTL_ERROR ("Failed to update device list within timeout"); - - ret = GTL_IFGetNumDevices (src->hIF, &num_devs); - HANDLE_GTL_ERROR ("Failed to get number of devices"); - if (num_devs == 0) { - gst_gentlsrc_close_interface (src); - continue; - } - GST_DEBUG_OBJECT (src, "Found %d devices on interface", num_devs); - for (src->device_index = 0; src->device_index < num_devs; - ++src->device_index) { - size_t str_size; - char user_defined_name[GTL_MAX_STR_SIZE]; - INFO_DATATYPE datatype; - - str_size = GTL_MAX_STR_SIZE; - ret = GTL_IFGetDeviceID (src->hIF, src->device_index, dev_id, &str_size); - if (ret != GC_ERR_SUCCESS) { - GST_WARNING_OBJECT (src, "Failed to get device id: %s", - gst_gentlsrc_get_error_string (src)); - return; - } - - str_size = GTL_MAX_STR_SIZE; - GTL_IFGetDeviceInfo (src->hIF, dev_id, DEVICE_INFO_USER_DEFINED_NAME, - &datatype, user_defined_name, &str_size); - - GST_DEBUG_OBJECT (src, "Comparing specified user ID='%s', to '%s'", - src->device_user_id, user_defined_name); - - if (g_strcmp0 (src->device_user_id, user_defined_name) == 0) { - GST_DEBUG_OBJECT (src, "Device matches!"); - gst_gentlsrc_close_interface (src); - return; - } else { - GST_DEBUG_OBJECT (src, "Device doesn't match, continuing"); - } - } // looping over devices - gst_gentlsrc_close_interface (src); - } // looping over interfaces - - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to find device using device-user-id='%s'", src->device_user_id), - (NULL)); - return; - -error: - return; -} - -static gboolean -gst_gentlsrc_start (GstBaseSrc * bsrc) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - GstGenTlSrcClass *klass = GST_GENTL_SRC_GET_CLASS (src); - GC_ERROR ret; - uint32_t i, num_devs; - guint32 width, height; - - GST_DEBUG_OBJECT (src, "start"); - - if (src->producer_prop == GST_GENTLSRC_PRODUCER_BASLER) { - initialize_basler_addresses (&src->producer); - } else if (src->producer_prop == GST_GENTLSRC_PRODUCER_EVT) { - initialize_evt_addresses (&src->producer); - } else if (src->producer_prop == GST_GENTLSRC_PRODUCER_FLIR) { - initialize_flir_addresses (&src->producer); - } else { - g_assert_not_reached (); - } - - /* bind functions from CTI */ - /* TODO: Enumerate CTI files in env var GENTL_GENTL64_PATH */ - if (!gst_gentlsrc_bind_functions (src)) { - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - ("GenTL CTI could not be opened: %s", g_module_error ()), (NULL)); - return FALSE; - } - - g_mutex_lock (&klass->tl_mutex); - - if (!gst_gentlsrc_open_tl (src)) { - g_mutex_unlock (&klass->tl_mutex); - goto error; - } - - if (src->device_user_id && src->device_user_id[0] != 0) { - get_gentlsrc_select_user_id (src); - } - - if (!gst_gentlsrc_open_interface (src)) { - g_mutex_unlock (&klass->tl_mutex); - goto error; - } - - g_mutex_unlock (&klass->tl_mutex); - - ret = GTL_IFUpdateDeviceList (src->hIF, NULL, src->timeout); - HANDLE_GTL_ERROR ("Failed to update device list within timeout"); - - /* print info for all devices and open specified device */ - ret = GTL_IFGetNumDevices (src->hIF, &num_devs); - HANDLE_GTL_ERROR ("Failed to get number of devices"); - if (num_devs > 0) { - GST_DEBUG_OBJECT (src, "Found %d devices on interface", num_devs); - for (i = 0; i < num_devs; ++i) { - gst_gentl_print_device_info (src, i); - } - } else { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("No devices found on interface"), (NULL)); - goto error; - } - - if (!src->device_id || src->device_id[0] == 0) { - size_t id_size; - GST_DEBUG_OBJECT (src, "Trying to find device ID at index %d", - src->device_index); - - GTL_IFGetDeviceID (src->hIF, src->device_index, NULL, &id_size); - HANDLE_GTL_ERROR ("Failed to get device ID at specified index"); - if (src->device_id) { - g_free (src->device_id); - } - src->device_id = (gchar *) g_malloc (id_size); - GTL_IFGetDeviceID (src->hIF, src->device_index, src->device_id, &id_size); - HANDLE_GTL_ERROR ("Failed to get device ID at specified index"); - } - - GST_DEBUG_OBJECT (src, "Trying to open device '%s'", src->device_id); - ret = - GTL_IFOpenDevice (src->hIF, src->device_id, DEVICE_ACCESS_CONTROL, - &src->hDEV); - HANDLE_GTL_ERROR ("Failed to open device"); - - uint32_t num_data_streams; - ret = GTL_DevGetNumDataStreams (src->hDEV, &num_data_streams); - HANDLE_GTL_ERROR ("Failed to get number of data streams"); - GST_DEBUG_OBJECT (src, "Found %d data streams", num_data_streams); - - /* find and open specified data stream id */ - if (!src->stream_id || src->stream_id[0] == 0) { - size_t id_size; - GST_DEBUG_OBJECT (src, "Trying to find stream ID at index %d", - src->stream_index); - - GTL_DevGetDataStreamID (src->hDEV, src->stream_index, NULL, &id_size); - HANDLE_GTL_ERROR ("Failed to get stream ID at specified index"); - if (src->stream_id) { - g_free (src->stream_id); - } - src->stream_id = (gchar *) g_malloc (id_size); - GTL_DevGetDataStreamID (src->hDEV, src->stream_index, src->stream_id, - &id_size); - HANDLE_GTL_ERROR ("Failed to get stream ID at specified index"); - } - - GST_DEBUG_OBJECT (src, "Trying to open data stream '%s'", src->stream_id); - ret = GTL_DevOpenDataStream (src->hDEV, src->stream_id, &src->hDS); - HANDLE_GTL_ERROR ("Failed to open data stream"); - - { - uint32_t num_urls = 0; - char url[2048]; - size_t url_len = sizeof (url); - INFO_DATATYPE datatype; - const uint32_t url_index = 0; - - ret = GTL_DevGetPort (src->hDEV, &src->hDevPort); - HANDLE_GTL_ERROR ("Failed to get port on device"); - ret = GTL_GCGetNumPortURLs (src->hDevPort, &num_urls); - HANDLE_GTL_ERROR ("Failed to get number of port URLs"); - - GST_DEBUG_OBJECT (src, "Found %d port URLs", num_urls); - - GST_DEBUG_OBJECT (src, "Trying to get URL index %d", url_index); - GTL_GCGetPortURLInfo (src->hDevPort, url_index, URL_INFO_URL, &datatype, - url, &url_len); - HANDLE_GTL_ERROR ("Failed to get URL"); - GST_DEBUG_OBJECT (src, "Found URL '%s'", url); - - g_assert (url_len > 6); - if (g_str_has_prefix (url, "file")) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("file url not supported yet"), (NULL)); - goto error; - } else if (g_ascii_strncasecmp (url, "local", 5) == 0) { - GError *err = NULL; - GMatchInfo *matchInfo; - GRegex *regex; - gchar *filename, *addr_str, *len_str; - uint64_t addr; - size_t len; - gchar *buf; - - regex = - g_regex_new - ("[lL]ocal:(?:///)?(?[^;]+);(?
[^;]+);(?[^?]+)(?:[?]SchemaVersion=([^&]+))?", - (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, &err); - if (!regex) { - goto error; - } - g_regex_match (regex, url, (GRegexMatchFlags) 0, &matchInfo); - filename = g_match_info_fetch_named (matchInfo, "filename"); - addr_str = g_match_info_fetch_named (matchInfo, "address"); - len_str = g_match_info_fetch_named (matchInfo, "length"); - if (!filename || !addr_str || !len_str) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to parse local URL"), (NULL)); - goto error; - } - - addr = g_ascii_strtoull (addr_str, NULL, 16); - len = g_ascii_strtoull (len_str, NULL, 16); - buf = (gchar *) g_malloc (len); - GTL_GCReadPort (src->hDevPort, addr, buf, &len); - HANDLE_GTL_ERROR ("Failed to read XML from port"); - - if (g_str_has_suffix (filename, "zip")) { - gchar *zipfilepath; - unzFile uf; - unz_file_info64 fileinfo; - gchar xmlfilename[2048]; - gchar *xml; - - zipfilepath = g_build_filename (g_get_tmp_dir (), filename, NULL); - GST_DEBUG_OBJECT (src, "Writing XML ZIP file to %s", zipfilepath); - if (!g_file_set_contents (zipfilepath, buf, len, &err)) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to write zipped XML to %s", zipfilepath), (NULL)); - goto error; - } - uf = unzOpen64 (zipfilepath); - if (!uf) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to open zipped XML %s", zipfilepath), (NULL)); - goto error; - } - //ret = unzGetGlobalInfo64(uf, &gi); - ret = - unzGetCurrentFileInfo64 (uf, &fileinfo, xmlfilename, - sizeof (xmlfilename), NULL, 0, NULL, 0); - if (ret != UNZ_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to query zip file %s", zipfilepath), (NULL)); - goto error; - } - - ret = unzOpenCurrentFile (uf); - if (ret != UNZ_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to extract file %s", xmlfilename), (NULL)); - goto error; - } - - xml = (gchar *) g_malloc (fileinfo.uncompressed_size); - if (!xml) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to allocate memory to extract XML file"), (NULL)); - goto error; - } - - ret = unzReadCurrentFile (uf, xml, fileinfo.uncompressed_size); - if (ret != fileinfo.uncompressed_size) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Failed to extract XML file %s", xmlfilename), (NULL)); - goto error; - } - unzClose (uf); - g_free (zipfilepath); - - zipfilepath = g_build_filename (g_get_tmp_dir (), xmlfilename, NULL); - GST_DEBUG_OBJECT (src, "Writing XML file to %s", zipfilepath); - g_file_set_contents (zipfilepath, xml, fileinfo.uncompressed_size, - &err); - g_free (zipfilepath); - - g_free (xml); - //GZlibDecompressor *decompress; - //char *unzipped; - //gsize outbuf_size, bytes_read, bytes_written; - //GInputStream *zippedstream, *unzippedstream; - //decompress = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB); - - ////zippedstream = g_memory_input_stream_new_from_data(buf, len, g_free); - ////unzippedstream = g_converter_input_stream_new (zippedstream, G_CONVERTER(decompress)); - ////g_input_stream_read_all (G_INPUT_STREAM(unzippedstream), - //// g_converter_output_stream - //outbuf_size = 10000000; - //unzipped = (gchar*) g_malloc(outbuf_size); - //g_converter_convert (G_CONVERTER (decompress), buf, len, unzipped, outbuf_size, G_CONVERTER_NO_FLAGS, &bytes_read, &bytes_written, &err); - //GST_DEBUG_OBJECT (src, unzipped); - } - - g_free (filename); - g_free (addr_str); - g_free (len_str); - g_free (buf); - } else if (g_str_has_prefix (url, "http")) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("file url not supported yet"), (NULL)); - goto error; - } - } - - gst_gentlsrc_set_attributes (src); - - { - // TODO: use GenTl node map for this - width = read_uint32 (src, src->producer.width, &ret); - HANDLE_GTL_ERROR ("Failed to get width"); - height = read_uint32 (src, src->producer.height, &ret); - HANDLE_GTL_ERROR ("Failed to get height"); - GST_DEBUG_OBJECT (src, "Width and height %dx%d", width, height); - - guint32 pixfmt_enum = read_uint32 (src, src->producer.pixel_format, &ret); - HANDLE_GTL_ERROR ("Failed to get pixel format"); - const char *genicam_pixfmt; - switch (pixfmt_enum) { - case 0x1: // Basler Ace - case 0x01080001: - genicam_pixfmt = "Mono8"; - break; - case 0x5: // Basler Ace - case 0x01100005: - genicam_pixfmt = "Mono12"; - break; - case 0x1100007: - genicam_pixfmt = "Mono16"; - break; - case 0x1100010: // Basler Ace - genicam_pixfmt = "BayerGR12"; - break; - case 0x01080009: - genicam_pixfmt = "BayerRG8"; - break; - case 0x01100011: - genicam_pixfmt = "BayerRG12"; - break; - case 0x0110002E: - genicam_pixfmt = "BayerGR16"; - break; - case 0x0110002F: - genicam_pixfmt = "BayerRG16"; - break; - case 0x02180014: - genicam_pixfmt = "RGB8Packed"; - break; - case 0x02180015: - genicam_pixfmt = "BGR8Packed"; - break; - case 0x0210001F: - genicam_pixfmt = "YUV422Packed"; - break; - case 0x02180020: - genicam_pixfmt = "YUV444Packed"; - break; - default: - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, - ("Unrecognized PixelFormat enum value: 0x%x", pixfmt_enum), (NULL)); - goto error; - } - - /* create caps */ - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - src->caps = - gst_genicam_pixel_format_caps_from_pixel_format (genicam_pixfmt, - G_LITTLE_ENDIAN, width, height, 30, 1, 1, 1); - if (!src->caps) { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Unknown or unsupported pixel format (%s).", genicam_pixfmt), - (NULL)); - goto error; - } - - src->height = height; - src->gst_stride = - gst_genicam_pixel_format_get_stride (genicam_pixfmt, G_LITTLE_ENDIAN, - width); - GST_DEBUG_OBJECT (src, "Height=%d, stride=%d", src->height, - src->gst_stride); - } - - if (!gst_gentlsrc_prepare_buffers (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, TOO_LAZY, ("Failed to prepare buffers"), - (NULL)); - goto error; - } - - { - ret = - GTL_GCRegisterEvent (src->hDS, EVENT_NEW_BUFFER, &src->hNewBufferEvent); - HANDLE_GTL_ERROR ("Failed to register New Buffer event"); - } - - ret = - GTL_DSStartAcquisition (src->hDS, ACQ_START_FLAGS_DEFAULT, - GENTL_INFINITE); - HANDLE_GTL_ERROR ("Failed to start stream acquisition"); - - { - // TODO: use GenTl node map for this - - /* set AcquisitionMode to Continuous */ - // TODO: "Continuous" value can have different integer values, we need - // to look it up in the node map (EVT is 0, Basler is 2) - ret = - write_uint32 (src, src->producer.acquisition_mode, - src->producer.acquisition_mode_value); - HANDLE_GTL_ERROR ("Failed to start device acquisition"); - - /* send AcquisitionStart command */ - ret = write_uint32 (src, src->producer.acquisition_start, 1); - HANDLE_GTL_ERROR ("Failed to start device acquisition"); - } - - GST_DEBUG_OBJECT (src, "starting acquisition"); -//TODO: start acquisition engine - - /* TODO: check timestamps on buffers vs start time */ - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - - src->tick_frequency = gst_gentlsrc_get_gev_tick_frequency (src); - - return TRUE; - -error: - if (src->hDS) { - GTL_DSClose (src->hDS); - src->hDS = NULL; - } - - if (src->hDEV) { - GTL_DevClose (src->hDEV); - src->hDEV = NULL; - } - - gst_gentlsrc_close_interface (src); - - gst_gentlsrc_cleanup_tl (src); - - return FALSE; -} - -static void -gst_gentlsrc_cleanup_tl (GstGenTlSrc * src) -{ - GstGenTlSrcClass *klass = GST_GENTL_SRC_GET_CLASS (src); - if (src->hTL) { - g_mutex_lock (&klass->tl_mutex); - GST_DEBUG_OBJECT (src, "Framegrabber open with refcount=%d", - klass->tl_refcount); - klass->tl_refcount--; - if (klass->tl_refcount == 0) { - GST_DEBUG_OBJECT (src, "Framegrabber ref dropped to 0, closing"); - GTL_TLClose (src->hTL); - src->hTL = NULL; - } - g_mutex_unlock (&klass->tl_mutex); - src->hTL = NULL; - - // don't close library, otherwise we can't reopen in the same process - //GTL_GCCloseLib (); - } -} - -static gboolean -gst_gentlsrc_stop (GstBaseSrc * bsrc) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - if (src->hDS) { - /* command AcquisitionStop */ - GC_ERROR ret; - ret = write_uint32 (src, src->producer.acquisition_stop, 1); - - GTL_DSStopAcquisition (src->hDS, ACQ_STOP_FLAGS_DEFAULT); - GTL_DSFlushQueue (src->hDS, ACQ_QUEUE_INPUT_TO_OUTPUT); - GTL_DSFlushQueue (src->hDS, ACQ_QUEUE_OUTPUT_DISCARD); - GTL_DSClose (src->hDS); - src->hDS = NULL; - } - - if (src->hDEV) { - GTL_DevClose (src->hDEV); - src->hDEV = NULL; - } - - if (src->hIF) { - GTL_IFClose (src->hIF); - src->hIF = NULL; - } - - gst_gentlsrc_cleanup_tl (src); - - GST_DEBUG_OBJECT (src, "Closed data stream, device, interface, and library"); - - gst_gentlsrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_gentlsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - GstCaps *caps; - - if (src->hDS == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_gentlsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - - GST_ERROR ("Stride is %d", src->gst_stride); - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - int endianness; - const char *genicam_pixfmt = - gst_genicam_pixel_format_from_caps (caps, &endianness); - GST_ERROR ("Format is %s, Stride is %d", genicam_pixfmt, src->gst_stride); - if (genicam_pixfmt) - src->gst_stride = - gst_genicam_pixel_format_get_stride (genicam_pixfmt, G_LITTLE_ENDIAN, - vinfo.width); - else - goto unsupported_caps; - GST_ERROR ("Format is %s, Stride is %d", genicam_pixfmt, src->gst_stride); - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_gentlsrc_unlock (GstBaseSrc * bsrc) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_gentlsrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstGenTlSrc *src = GST_GENTL_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix"); - -static GstBuffer * -gst_gentlsrc_get_buffer (GstGenTlSrc * src) -{ - GC_ERROR ret; - EVENT_NEW_BUFFER_DATA new_buffer_data; - INFO_DATATYPE datatype; - size_t datasize; - GstBuffer *buf = NULL; - size_t payload_type, buffer_size; - uint64_t frame_id; - bool8_t buffer_is_incomplete, is_acquiring; - guint8 *data_ptr; - GstMapInfo minfo; - GstClockTime unix_ts; - uint64_t buf_timestamp_ticks, buf_timestamp_ns; - - - /* sometimes we get non-image payloads, try several times for an image */ - for (int i = 0; i < 5; ++i) { - datasize = sizeof (new_buffer_data); - ret = - GTL_EventGetData (src->hNewBufferEvent, &new_buffer_data, &datasize, - src->timeout); - HANDLE_GTL_ERROR ("Failed to get New Buffer event within timeout period"); - - datasize = sizeof (payload_type); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_PAYLOADTYPE, &datatype, &payload_type, &datasize); - HANDLE_GTL_ERROR ("Failed to get payload type"); - if (payload_type != PAYLOAD_TYPE_IMAGE) { - GST_WARNING_OBJECT (src, "Non-image payload type, trying again"); - continue; - } else { - break; - } - } - - if (payload_type != PAYLOAD_TYPE_IMAGE) { - GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, - ("Unsupported payload type: %d", payload_type), (NULL)); - goto error; - } - - datasize = sizeof (buf_timestamp_ns); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_TIMESTAMP_NS, &datatype, &buf_timestamp_ns, &datasize); - if (ret == GC_ERR_SUCCESS) { - GST_LOG_OBJECT (src, "Buffer GentTL timestamp: %llu ns", buf_timestamp_ns); - } else { - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_TIMESTAMP, &datatype, &buf_timestamp_ticks, &datasize); - HANDLE_GTL_ERROR ("Failed to get buffer timestamp"); - buf_timestamp_ns = (gint64) - (buf_timestamp_ticks * ((double) GST_SECOND / src->tick_frequency)); - GST_LOG_OBJECT (src, "Buffer GentTL timestamp: %llu ticks, %llu ns", - buf_timestamp_ticks, buf_timestamp_ns); - } - - datasize = sizeof (frame_id); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_FRAMEID, &datatype, &frame_id, &datasize); - HANDLE_GTL_ERROR ("Failed to get frame id"); - - datasize = sizeof (buffer_is_incomplete); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_IS_INCOMPLETE, &datatype, &buffer_is_incomplete, &datasize); - HANDLE_GTL_ERROR ("Failed to get complete flag"); - if (buffer_is_incomplete) { - GST_WARNING_OBJECT (src, "Buffer is incomplete"); - } - - datasize = sizeof (buffer_size); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_SIZE, &datatype, &buffer_size, &datasize); - HANDLE_GTL_ERROR ("Failed to get buffer size"); - - datasize = sizeof (data_ptr); - ret = - GTL_DSGetBufferInfo (src->hDS, new_buffer_data.BufferHandle, - BUFFER_INFO_BASE, &datatype, &data_ptr, &datasize); - HANDLE_GTL_ERROR ("Failed to get buffer pointer"); - - // TODO: what if strides aren't same? - - guint64 image_size = (size_t) src->height * src->gst_stride; - if (buffer_size < image_size) { - GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, - ("Buffer size (%d) is smaller than expected image size (%llu)", - buffer_size, image_size), (NULL)); - goto error; - } - - buf = gst_buffer_new_allocate (NULL, image_size, NULL); - if (!buf) { - GST_ELEMENT_ERROR (src, STREAM, TOO_LAZY, - ("Failed to allocate buffer"), (NULL)); - goto error; - } - // TODO: try to eliminate this memcpy by using gst_buffer_new_wrapped_full - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - orc_memcpy (minfo.data, (void *) data_ptr, minfo.size); - gst_buffer_unmap (buf, &minfo); - - GTL_DSQueueBuffer (src->hDS, new_buffer_data.BufferHandle); - HANDLE_GTL_ERROR ("Failed to queue buffer"); - - GST_BUFFER_OFFSET (buf) = frame_id; - - if (src->tick_frequency) { - gint64 nanoseconds_after_latch; - - /* resync system clock and buffer clock periodically */ - if (GST_CLOCK_DIFF (src->unix_latched_ns, get_unix_ns ()) > GST_SECOND) { - gst_gentlsrc_src_latch_timestamps (src); - } - - nanoseconds_after_latch = buf_timestamp_ns - src->gentl_latched_ns; - unix_ts = src->unix_latched_ns + nanoseconds_after_latch; - GST_LOG_OBJECT (src, "Adding Unix timestamp: %llu", unix_ts); - gst_buffer_add_reference_timestamp_meta (buf, - gst_static_caps_get (&unix_reference), unix_ts, GST_CLOCK_TIME_NONE); - } - - return buf; - -error: - if (buf) { - gst_buffer_unref (buf); - } - return NULL; -} - -static GstFlowReturn -gst_gentlsrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstGenTlSrc *src = GST_GENTL_SRC (psrc); - guint32 dropped_frames = 0; - GstClock *clock; - GstClockTime clock_time; - - GST_LOG_OBJECT (src, "create"); - - gst_gentlsrc_set_attributes (src); - - *buf = gst_gentlsrc_get_buffer (src); - if (!*buf) { - return GST_FLOW_ERROR; - } - - clock = gst_element_get_clock (GST_ELEMENT (src)); - clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - - /* check for dropped frames and disrupted signal */ - //dropped_frames = (circ_handle.FrameCount - src->last_frame_count) - 1; - if (dropped_frames > 0) { - src->total_dropped_frames += dropped_frames; - GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - src->total_dropped_frames); - } else if (dropped_frames < 0) { - GST_WARNING_OBJECT (src, "Frame count non-monotonic, signal disrupted?"); - } - //src->last_frame_count = circ_handle.FrameCount; - - /* create GstBuffer then release circ buffer back to acquisition */ - //*buf = gst_gentlsrc_create_buffer_from_circ_handle (src, &circ_handle); - //ret = - // BiCirStatusSet (src->board, &src->buffer_array, circ_handle, BIAVAILABLE); - //if (ret != BI_OK) { - // GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - // ("Failed to release buffer: %s", gst_gentlsrc_get_error_string (src, - // ret)), (NULL)); - // return GST_FLOW_ERROR; - //} - - /* TODO: understand why timestamps for circ_handle are sometimes 0 */ - //GST_BUFFER_TIMESTAMP (*buf) = - // GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - // src->acq_start_time + circ_handle.HiResTimeStamp.totalSec * GST_SECOND); - GST_BUFFER_TIMESTAMP (*buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - clock_time); - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - -gchar * -gst_gentlsrc_get_error_string (GstGenTlSrc * src) -{ - size_t error_string_size = MAX_ERROR_STRING_LEN; - GC_ERROR error_code; - GTL_GCGetLastError (&error_code, src->error_string, &error_string_size); - return src->error_string; -} - - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_gentlsrc_debug, "gentlsrc", 0, - "debug category for gentlsrc element"); - gst_element_register (plugin, "gentlsrc", GST_RANK_NONE, - gst_gentlsrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - gentl, - "GenTL frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN); diff --git a/sys/gentl/gstgentlsrc.h b/sys/gentl/gstgentlsrc.h deleted file mode 100644 index 93019a5..0000000 --- a/sys/gentl/gstgentlsrc.h +++ /dev/null @@ -1,135 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_GENTL_SRC_H_ -#define _GST_GENTL_SRC_H_ - -#include - -#undef __cplusplus -#include "GenTL_v1_5.h" - -#define MAX_ERROR_STRING_LEN 256 - -G_BEGIN_DECLS - -#define GST_TYPE_GENTL_SRC (gst_gentlsrc_get_type()) -#define GST_GENTL_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GENTL_SRC,GstGenTlSrc)) -#define GST_GENTL_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GENTL_SRC,GstGenTlSrcClass)) -#define GST_IS_GENTL_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GENTL_SRC)) -#define GST_IS_GENTL_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GENTL_SRC)) -#define GST_GENTL_SRC_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_GENTL_SRC, GstGenTlSrcClass)) - -typedef struct _GstGenTlSrc GstGenTlSrc; -typedef struct _GstGenTlSrcClass GstGenTlSrcClass; - -typedef struct _GstGenTlProducer GstGenTlProducer; -struct _GstGenTlProducer -{ - gchar* cti_path; - guint32 acquisition_mode_value; - guint32 timestamp_control_latch_value; - - guint64 width; - guint64 height; - guint64 pixel_format; - guint64 payload_size; - guint64 acquisition_mode; - guint64 acquisition_start; - guint64 acquisition_stop; - guint64 tick_frequency_low; - guint64 tick_frequency_high; - guint64 timestamp_control_latch; // GevTimestampControlLatch - guint64 timestamp; // TimestampLatchValue - guint64 timestamp_low; // GevTimestampValueLow - guint64 timestamp_high; // GevTimestampValueHigh - guint16 port_endianness; -}; - - -/** -* GstGenTlSrcProducer: -* @GST_GENTLSRC_PRODUCER_BASLER: Basler producer -* @GST_GENTLSRC_PRODUCER_EVT: EVT producer -* -* Producer to use. -*/ -typedef enum { - GST_GENTLSRC_PRODUCER_BASLER, - GST_GENTLSRC_PRODUCER_EVT, - GST_GENTLSRC_PRODUCER_FLIR, -} GstGenTlSrcProducer; - - -struct _GstGenTlSrc -{ - GstPushSrc base_gentlsrc; - - /* camera handle */ - TL_HANDLE hTL; - IF_HANDLE hIF; - DEV_HANDLE hDEV; - DS_HANDLE hDS; - PORT_HANDLE hDevPort; - EVENT_HANDLE hNewBufferEvent; - char error_string[MAX_ERROR_STRING_LEN]; - GstGenTlProducer producer; - - /* properties */ - GstGenTlSrcProducer producer_prop; - guint interface_index; - gchar *interface_id; - guint device_index; - gchar *device_id; - gchar *device_user_id; - guint stream_index; - gchar *stream_id; - guint num_capture_buffers; - gint timeout; - gchar* attributes; - - GstClockTime acq_start_time; - guint32 last_frame_count; - guint32 total_dropped_frames; - - guint64 tick_frequency; - guint64 unix_latched_ns; - guint64 gentl_latched_ns; - - GstCaps *caps; - gint height; - gint gst_stride; - - gboolean stop_requested; -}; - -struct _GstGenTlSrcClass -{ - GstPushSrcClass base_gentlsrc_class; - TL_HANDLE hTL; - GMutex tl_mutex; - guint tl_refcount; -}; - -GType gst_gentlsrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/gentl/ioapi.c b/sys/gentl/ioapi.c deleted file mode 100644 index 7f5c191..0000000 --- a/sys/gentl/ioapi.c +++ /dev/null @@ -1,247 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) - #define _CRT_SECURE_NO_WARNINGS -#endif - -#if defined(__APPLE__) || defined(IOAPI_NO_64) -// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions -#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -#define FTELLO_FUNC(stream) ftello(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) -#else -#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -#define FTELLO_FUNC(stream) ftello64(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) -#endif - - -#include "ioapi.h" - -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ - if (pfilefunc->zfile_func64.zopen64_file != NULL) - return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); - else - { - return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); - } -} - -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); - else - { - uLong offsetTruncated = (uLong)offset; - if (offsetTruncated != offset) - return -1; - else - return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); - } -} - -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); - else - { - uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); - if ((tell_uLong) == MAXU32) - return (ZPOS64_T)-1; - else - return tell_uLong; - } -} - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ - p_filefunc64_32->zfile_func64.zopen64_file = NULL; - p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; - p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; - p_filefunc64_32->zfile_func64.ztell64_file = NULL; - p_filefunc64_32->zfile_func64.zseek64_file = NULL; - p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; - p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; - p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; -} - - - -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); - return file; -} - -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = FOPEN_FUNC((const char*)filename, mode_fopen); - return file; -} - - -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ - long ret; - ret = ftell((FILE *)stream); - return ret; -} - - -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret; - ret = FTELLO_FUNC((FILE *)stream); - return ret; -} - -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - if (fseek((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - return ret; -} - -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - - if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - - return ret; -} - - -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = fclose((FILE *)stream); - return ret; -} - -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = ferror((FILE *)stream); - return ret; -} - -void fill_fopen_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = fopen64_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell64_file = ftell64_file_func; - pzlib_filefunc_def->zseek64_file = fseek64_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} diff --git a/sys/gentl/ioapi.h b/sys/gentl/ioapi.h deleted file mode 100644 index 8dcbdb0..0000000 --- a/sys/gentl/ioapi.h +++ /dev/null @@ -1,208 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - Changes - - Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) - Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. - More if/def section may be needed to support other platforms - Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. - (but you should use iowin32.c for windows instead) - -*/ - -#ifndef _ZLIBIOAPI64_H -#define _ZLIBIOAPI64_H - -#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) - - // Linux needs this to support file operation on files larger then 4+GB - // But might need better if/def to select just the platforms that needs them. - - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif - -#endif - -#include -#include -#include "zlib.h" - -#if defined(USE_FILE32API) -#define fopen64 fopen -#define ftello64 ftell -#define fseeko64 fseek -#else -#ifdef __FreeBSD__ -#define fopen64 fopen -#define ftello64 ftello -#define fseeko64 fseeko -#endif -#ifdef _MSC_VER - #define fopen64 fopen - #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) - #define ftello64 _ftelli64 - #define fseeko64 _fseeki64 - #else // old MSC - #define ftello64 ftell - #define fseeko64 fseek - #endif -#endif -#endif - -/* -#ifndef ZPOS64_T - #ifdef _WIN32 - #define ZPOS64_T fpos_t - #else - #include - #define ZPOS64_T uint64_t - #endif -#endif -*/ - -#ifdef HAVE_MINIZIP64_CONF_H -#include "mz64conf.h" -#endif - -/* a type choosen by DEFINE */ -#ifdef HAVE_64BIT_INT_CUSTOM -typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; -#else -#ifdef HAS_STDINT_H -#include "stdint.h" -typedef uint64_t ZPOS64_T; -#else - -/* Maximum unsigned 32-bit value used as placeholder for zip64 */ -#define MAXU32 0xffffffff - -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef unsigned __int64 ZPOS64_T; -#else -typedef unsigned long long int ZPOS64_T; -#endif -#endif -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) - #define ZCALLBACK CALLBACK - #else - #define ZCALLBACK - #endif -#endif - - - - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); - - -/* here is the "old" 32 bits structure structure */ -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - -typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); - -typedef struct zlib_filefunc64_def_s -{ - open64_file_func zopen64_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell64_file_func ztell64_file; - seek64_file_func zseek64_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc64_def; - -void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -/* now internal definition, only for zip.c and unzip.h */ -typedef struct zlib_filefunc64_32_def_s -{ - zlib_filefunc64_def zfile_func64; - open_file_func zopen32_file; - tell_file_func ztell32_file; - seek_file_func zseek32_file; -} zlib_filefunc64_32_def; - - -#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) -//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) -#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) - -voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); -long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); -ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); - -#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) -#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) -#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/sys/gentl/unzip.c b/sys/gentl/unzip.c deleted file mode 100644 index affad4b..0000000 --- a/sys/gentl/unzip.c +++ /dev/null @@ -1,2125 +0,0 @@ -/* unzip.c -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - - ------------------------------------------------------------------------------------ - Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of - compatibility with older software. The following is from the original crypt.c. - Code woven in by Terry Thorsen 1/2003. - - Copyright (c) 1990-2000 Info-ZIP. All rights reserved. - - See the accompanying file LICENSE, version 2000-Apr-09 or later - (the contents of which are also included in zip.h) for terms of use. - If, for some reason, all these files are missing, the Info-ZIP license - also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html - - crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - ------------------------------------------------------------------------------------ - - Changes in unzip.c - - 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos - 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* - 2007-2008 - Even Rouault - Remove old C style function prototypes - 2007-2008 - Even Rouault - Add unzip support for ZIP64 - - Copyright (C) 2007-2008 Even Rouault - - - Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). - Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G - should only read the compressed/uncompressed size from the Zip64 format if - the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) - Patch created by Daniel Borca - - Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer - - Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson - -*/ - - -#include -#include -#include - -#ifndef NOUNCRYPT - #define NOUNCRYPT -#endif - -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - -#ifndef CASESENSITIVITYDEFAULT_NO -# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) -# define CASESENSITIVITYDEFAULT_NO -# endif -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - -const char unz_copyright[] = - " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - -/* unz_file_info_interntal contain internal info about a file in zipfile*/ -typedef struct unz_file_info64_internal_s -{ - ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ -} unz_file_info64_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - -#ifdef HAVE_BZIP2 - bz_stream bstream; /* bzLib stream structure for bziped */ -#endif - - ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ - - ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ - ZPOS64_T total_out_64; - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ - ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - int raw; -} file_in_zip64_read_info_s; - - -/* unz64_s contain internal information about the zipfile -*/ -typedef struct -{ - zlib_filefunc64_32_def z_filefunc; - int is64bitOpenFunction; - voidpf filestream; /* io structore of the zipfile */ - unz_global_info64 gi; /* public global information */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - ZPOS64_T num_file; /* number of the current file in the zipfile*/ - ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ - ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ - ZPOS64_T central_pos; /* position of the beginning of the central dir*/ - - ZPOS64_T size_central_dir; /* size of the central directory */ - ZPOS64_T offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info64 cur_file_info; /* public info about the current file in zip*/ - unz_file_info64_internal cur_file_info_internal; /* private info about it*/ - file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ - int encrypted; - - int isZip64; - -# ifndef NOUNCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; -# endif -} unz64_s; - - -#ifndef NOUNCRYPT -#include "crypt.h" -#endif - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ - - -local int unz64local_getByte OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ZERROR64(*pzlib_filefunc_def,filestream)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unz64local_getShort OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX)); - - -local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX) -{ - ZPOS64_T x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<24; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<32; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<40; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<48; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<56; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, - const char* fileName2, - int iCaseSensitivity) - -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - - -/* - Locate the Central directory 64 of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream)); - -local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - uLong uL; - ZPOS64_T relativeOffset; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - if (uPosFound == 0) - return 0; - - /* Zip64 end of central directory locator */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature, already checked */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - /* number of the disk with the start of the zip64 end of central directory */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 0) - return 0; - - /* relative offset of the zip64 end of central directory record */ - if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) - return 0; - - /* total number of disks */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 1) - return 0; - - /* Goto end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - if (uL != 0x06064b50) - return 0; - - return relativeOffset; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer - "zlib/zlib114.zip". - If the zipfile cannot be opened (file doesn't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -local unzFile unzOpenInternal (const void *path, - zlib_filefunc64_32_def* pzlib_filefunc64_32_def, - int is64bitOpenFunction) -{ - unz64_s us; - unz64_s *s; - ZPOS64_T central_pos; - uLong uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - ZPOS64_T number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - us.z_filefunc.zseek32_file = NULL; - us.z_filefunc.ztell32_file = NULL; - if (pzlib_filefunc64_32_def==NULL) - fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); - else - us.z_filefunc = *pzlib_filefunc64_32_def; - us.is64bitOpenFunction = is64bitOpenFunction; - - - - us.filestream = ZOPEN64(us.z_filefunc, - path, - ZLIB_FILEFUNC_MODE_READ | - ZLIB_FILEFUNC_MODE_EXISTING); - if (us.filestream==NULL) - return NULL; - - central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); - if (central_pos) - { - uLong uS; - ZPOS64_T uL64; - - us.isZip64 = 1; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* size of zip64 end of central directory record */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version made by */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version needed to extract */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory on this disk */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - us.gi.size_comment = 0; - } - else - { - central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); - if (central_pos==0) - err=UNZ_ERRNO; - - us.isZip64 = 0; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.gi.number_entry = uL; - - /* total number of entries in the central dir */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - number_entry_CD = uL; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.size_central_dir = uL; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.offset_central_dir = uL; - - /* zipfile comment length */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - } - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - ZCLOSE64(s->z_filefunc, s->filestream); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - -extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - /* to do : check if number_entry is not truncated */ - pglobal_info32->number_entry = (uLong)s->gi.number_entry; - pglobal_info32->size_comment = s->gi.size_comment; - return UNZ_OK; -} -/* - Translate date/time from Dos format to tm_unz (readable more easilty) -*/ -local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) -{ - ZPOS64_T uDate; - uDate = (ZPOS64_T)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unz64local_GetCurrentFileInfoInternal (unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize) -{ - unz64_s* s; - unz_file_info64 file_info; - unz_file_info64_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - uLong uL; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pos_in_central_dir+s->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.compressed_size = uL; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.uncompressed_size = uL; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - // relative offset of local header - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info_internal.offset_curfile = uL; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - // Read extrafield - if ((err==UNZ_OK) && (extraField!=NULL)) - { - ZPOS64_T uSizeRead ; - if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - - lSeek += file_info.size_file_extra - (uLong)uSizeRead; - } - else - lSeek += file_info.size_file_extra; - - - if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) - { - uLong acc = 0; - - // since lSeek now points to after the extra field we need to move back - lSeek -= file_info.size_file_extra; - - if (lSeek!=0) - { - if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - while(acc < file_info.size_file_extra) - { - uLong headerId; - uLong dataSize; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) - err=UNZ_ERRNO; - - /* ZIP64 extra fields */ - if (headerId == 0x0001) - { - uLong uL; - - if(file_info.uncompressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.compressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info_internal.offset_curfile == MAXU32) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.disk_num_start == MAXU32) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - } - - } - else - { - if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) - err=UNZ_ERRNO; - } - - acc += 2 + 2 + dataSize; - } - } - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek+=file_info.size_file_comment - uSizeRead; - } - else - lSeek+=file_info.size_file_comment; - - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, - unz_file_info64 * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, - unz_file_info * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - int err; - unz_file_info64 file_info64; - err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); - if ((err==UNZ_OK) && (pfile_info != NULL)) - { - pfile_info->version = file_info64.version; - pfile_info->version_needed = file_info64.version_needed; - pfile_info->flag = file_info64.flag; - pfile_info->compression_method = file_info64.compression_method; - pfile_info->dosDate = file_info64.dosDate; - pfile_info->crc = file_info64.crc; - - pfile_info->size_filename = file_info64.size_filename; - pfile_info->size_file_extra = file_info64.size_file_extra; - pfile_info->size_file_comment = file_info64.size_file_comment; - - pfile_info->disk_num_start = file_info64.disk_num_start; - pfile_info->internal_fa = file_info64.internal_fa; - pfile_info->external_fa = file_info64.external_fa; - - pfile_info->tmu_date = file_info64.tmu_date, - - - pfile_info->compressed_size = (uLong)file_info64.compressed_size; - pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; - - } - return err; -} -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -extern int ZEXPORT unzGoToFirstFile (unzFile file) -{ - int err=UNZ_OK; - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -extern int ZEXPORT unzGoToNextFile (unzFile file) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ - if (s->num_file+1==s->gi.number_entry) - return UNZ_END_OF_LIST_OF_FILE; - - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; - s->num_file++; - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzipStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) -{ - unz64_s* s; - int err; - - /* We remember the 'current' position in the file so that we can jump - * back there if we fail. - */ - unz_file_info64 cur_file_infoSaved; - unz_file_info64_internal cur_file_info_internalSaved; - ZPOS64_T num_fileSaved; - ZPOS64_T pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - /* Save the current state */ - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - cur_file_infoSaved = s->cur_file_info; - cur_file_info_internalSaved = s->cur_file_info_internal; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - err = unzGetCurrentFileInfo64(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (err == UNZ_OK) - { - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - } - - /* We failed, so restore the state of the 'current file' to where we - * were. - */ - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - s->cur_file_info = cur_file_infoSaved; - s->cur_file_info_internal = cur_file_info_internalSaved; - return err; -} - - -/* -/////////////////////////////////////////// -// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) -// I need random access -// -// Further optimization could be realized by adding an ability -// to cache the directory in memory. The goal being a single -// comprehensive file read to put the file I need in a memory. -*/ - -/* -typedef struct unz_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; // offset in file - ZPOS64_T num_of_file; // # of file -} unz_file_pos; -*/ - -extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) -{ - unz64_s* s; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - file_pos->pos_in_zip_directory = s->pos_in_central_dir; - file_pos->num_of_file = s->num_file; - - return UNZ_OK; -} - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - int err = unzGetFilePos64(file,&file_pos64); - if (err==UNZ_OK) - { - file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; - file_pos->num_of_file = (uLong)file_pos64.num_of_file; - } - return err; -} - -extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) -{ - unz64_s* s; - int err; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - /* jump to the right spot */ - s->pos_in_central_dir = file_pos->pos_in_zip_directory; - s->num_file = file_pos->num_of_file; - - /* set the current file */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - /* return results */ - s->current_file_ok = (err == UNZ_OK); - return err; -} - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - if (file_pos == NULL) - return UNZ_PARAMERROR; - - file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; - file_pos64.num_of_file = file_pos->num_of_file; - return unzGoToFilePos64(file,&file_pos64); -} - -/* -// Unzip Helper Functions - should be here? -/////////////////////////////////////////// -*/ - -/* - Read the local header of the current zipfile - Check the coherency of the local header and info in the end of central - directory about this file - store in *piSizeVar the size of extra info in local header - (filename and size of extra field data) -*/ -local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, - ZPOS64_T * poffset_local_extrafield, - uInt * psize_local_extrafield) -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - Open for reading data the current file in the zipfile. - If there is no error and the file is opened, the return value is UNZ_OK. -*/ -extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, - int* level, int raw, const char* password) -{ - int err=UNZ_OK; - uInt iSizeVar; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ -# ifndef NOUNCRYPT - char source[12]; -# else - if (password != NULL) - return UNZ_PARAMERROR; -# endif - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; - pfile_in_zip_read_info->pos_local_extrafield=0; - pfile_in_zip_read_info->raw=raw; - - if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if (method!=NULL) - *method = (int)s->cur_file_info.compression_method; - - if (level!=NULL) - { - *level = 6; - switch (s->cur_file_info.flag & 0x06) - { - case 6 : *level = 1; break; - case 4 : *level = 2; break; - case 2 : *level = 9; break; - } - } - - if ((s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) - - err=UNZ_BADZIPFILE; - - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->total_out_64=0; - pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; - pfile_in_zip_read_info->filestream=s->filestream; - pfile_in_zip_read_info->z_filefunc=s->z_filefunc; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) - { -#ifdef HAVE_BZIP2 - pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; - pfile_in_zip_read_info->bstream.bzfree = (free_func)0; - pfile_in_zip_read_info->bstream.opaque = (voidpf)0; - pfile_in_zip_read_info->bstream.state = (voidpf)0; - - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = (voidpf)0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } -#else - pfile_in_zip_read_info->raw=1; -#endif - } - else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) - { - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = 0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - s->pfile_in_zip_read = pfile_in_zip_read_info; - s->encrypted = 0; - -# ifndef NOUNCRYPT - if (password != NULL) - { - int i; - s->pcrc_32_tab = get_crc_table(); - init_keys(password,s->keys,s->pcrc_32_tab); - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pfile_in_zip_read->pos_in_zipfile + - s->pfile_in_zip_read->byte_before_the_zipfile, - SEEK_SET)!=0) - return UNZ_INTERNALERROR; - if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) - return UNZ_INTERNALERROR; - - for (i = 0; i<12; i++) - zdecode(s->keys,s->pcrc_32_tab,source[i]); - - s->pfile_in_zip_read->pos_in_zipfile+=12; - s->encrypted=1; - } -# endif - - - return UNZ_OK; -} - -extern int ZEXPORT unzOpenCurrentFile (unzFile file) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); -} - -extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, password); -} - -extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) -{ - return unzOpenCurrentFile3(file, method, level, raw, NULL); -} - -/** Addition for GDAL : START */ - -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - s=(unz64_s*)file; - if (file==NULL) - return 0; //UNZ_PARAMERROR; - pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) - return 0; //UNZ_PARAMERROR; - return pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile; -} - -/** Addition for GDAL : END */ - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) -{ - int err=UNZ_OK; - uInt iRead = 0; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if (pfile_in_zip_read_info->read_buffer == NULL) - return UNZ_END_OF_LIST_OF_FILE; - if (len==0) - return 0; - - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; - - pfile_in_zip_read_info->stream.avail_out = (uInt)len; - - if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && - (!(pfile_in_zip_read_info->raw))) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - if ((len>pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in) && - (pfile_in_zip_read_info->raw)) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->read_buffer, - uReadThis)!=uReadThis) - return UNZ_ERRNO; - - -# ifndef NOUNCRYPT - if(s->encrypted) - { - uInt i; - for(i=0;iread_buffer[i] = - zdecode(s->keys,s->pcrc_32_tab, - pfile_in_zip_read_info->read_buffer[i]); - } -# endif - - - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - pfile_in_zip_read_info->stream.next_in = - (Bytef*)pfile_in_zip_read_info->read_buffer; - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; - } - - if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) - { - uInt uDoCopy,i ; - - if ((pfile_in_zip_read_info->stream.avail_in == 0) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - return (iRead==0) ? UNZ_EOF : iRead; - - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - - pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; - pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; - pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; - pfile_in_zip_read_info->bstream.total_in_hi32 = 0; - pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; - pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; - pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; - pfile_in_zip_read_info->bstream.total_out_hi32 = 0; - - uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; - bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; - - err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); - - uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); - pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; - pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; - pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; - pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; - pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; - pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; - - if (err==BZ_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=BZ_OK) - break; -#endif - } // end Z_BZIP2ED - else - { - ZPOS64_T uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - ZPOS64_T uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) - err = Z_DATA_ERROR; - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -extern z_off_t ZEXPORT unztell (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - -extern ZPOS64_T ZEXPORT unztell64 (unzFile file) -{ - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return (ZPOS64_T)-1; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return (ZPOS64_T)-1; - - return pfile_in_zip_read_info->total_out_64; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -extern int ZEXPORT unzeof (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* -Read extra field from the current file (opened by unzOpenCurrentFile) -This is the local-header version of the extra field (sometimes, there is -more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - uInt read_now; - ZPOS64_T size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->offset_local_extrafield + - pfile_in_zip_read_info->pos_local_extrafield, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - buf,read_now)!=read_now) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzipOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -extern int ZEXPORT unzCloseCurrentFile (unzFile file) -{ - int err=UNZ_OK; - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && - (!pfile_in_zip_read_info->raw)) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) - inflateEnd(&pfile_in_zip_read_info->stream); -#ifdef HAVE_BZIP2 - else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) - BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); -#endif - - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) -{ - unz64_s* s; - uLong uReadThis ; - if (file==NULL) - return (int)UNZ_PARAMERROR; - s=(unz64_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} - -/* Additions by RX '2004 */ -extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) -{ - unz64_s* s; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return 0; - if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) - if (s->num_file==s->gi.number_entry) - return 0; - return s->pos_in_central_dir; -} - -extern uLong ZEXPORT unzGetOffset (unzFile file) -{ - ZPOS64_T offset64; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - offset64 = unzGetOffset64(file); - return (uLong)offset64; -} - -extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - s->pos_in_central_dir = pos; - s->num_file = s->gi.number_entry; /* hack */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) -{ - return unzSetOffset64(file,pos); -} diff --git a/sys/gentl/unzip.h b/sys/gentl/unzip.h deleted file mode 100644 index 3183968..0000000 --- a/sys/gentl/unzip.h +++ /dev/null @@ -1,437 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - --------------------------------------------------------------------------------- - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - --------------------------------------------------------------------------------- - - Changes - - See header of unzip64.c - -*/ - -#ifndef _unz64_H -#define _unz64_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -#include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info64_s -{ - ZPOS64_T number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info64; - -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info64_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - ZPOS64_T compressed_size; /* compressed size 8 bytes */ - ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info64; - -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -extern unzFile ZEXPORT unzOpen64 OF((const void *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. - the "64" function take a const void* pointer, because the path is just the - value passed to the open64_file_func callback. - Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path - is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* - does not describe the reality -*/ - - -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unz64Open, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); - -extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -typedef struct unz64_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ - ZPOS64_T num_of_file; /* # of file */ -} unz64_file_pos; - -extern int ZEXPORT unzGetFilePos64( - unzFile file, - unz64_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos64( - unzFile file, - const unz64_file_pos* file_pos); - -/* ****************************************** */ - -extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - - -/** Addition for GDAL : START */ - -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); - -/** Addition for GDAL : END */ - - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); - -extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -/***************************************************************************/ - -/* Get the current file offset */ -extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); -extern uLong ZEXPORT unzGetOffset (unzFile file); - -/* Set the current file offset */ -extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); - - - -#ifdef __cplusplus -} -#endif - -#endif /* _unz64_H */ diff --git a/sys/imperxflex/CMakeLists.txt b/sys/imperxflex/CMakeLists.txt deleted file mode 100644 index 565321d..0000000 --- a/sys/imperxflex/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstframelinksrc.c) - -set (HEADERS - gstframelinksrc.h) - -include_directories (AFTER - ${IMPERX_FLEX_INCLUDE_DIR}) - -set (libname gstimperxflex) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${IMPERX_FLEX_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/imperxflex/gstframelinksrc.c b/sys/imperxflex/gstframelinksrc.c deleted file mode 100644 index 9a39c4a..0000000 --- a/sys/imperxflex/gstframelinksrc.c +++ /dev/null @@ -1,778 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstimperxflexsrc - * - * The imperxflexsrc element is a source for IMPERX and FrameLink Express framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v imperxflexsrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default IMPERX FrameLink Express framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstframelinksrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_framelinksrc_debug); -#define GST_CAT_DEFAULT gst_framelinksrc_debug - -/* prototypes */ -static void gst_framelinksrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_framelinksrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_framelinksrc_dispose (GObject * object); -static void gst_framelinksrc_finalize (GObject * object); - -static gboolean gst_framelinksrc_start (GstBaseSrc * src); -static gboolean gst_framelinksrc_stop (GstBaseSrc * src); -static GstCaps *gst_framelinksrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_framelinksrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_framelinksrc_unlock (GstBaseSrc * src); -static gboolean gst_framelinksrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_framelinksrc_create (GstPushSrc * src, - GstBuffer ** buf); - -static GstCaps *gst_framelinksrc_create_caps (GstFramelinkSrc * src); -enum -{ - PROP_0, - PROP_FORMAT_FILE, - PROP_NUM_CAPTURE_BUFFERS, - PROP_BOARD, - PROP_CHANNEL, - PROP_TIMEOUT -}; - -#define DEFAULT_PROP_FORMAT_FILE "" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 2 -#define DEFAULT_PROP_BOARD 0 -#define DEFAULT_PROP_CHANNEL 0 -#define DEFAULT_PROP_TIMEOUT 1000 - -/* pad templates */ - -static GstStaticPadTemplate gst_framelinksrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGRA }")) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstFramelinkSrc, gst_framelinksrc, GST_TYPE_PUSH_SRC); - -static void -gst_framelinksrc_class_init (GstFramelinkSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_framelinksrc_set_property; - gobject_class->get_property = gst_framelinksrc_get_property; - gobject_class->dispose = gst_framelinksrc_dispose; - gobject_class->finalize = gst_framelinksrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_framelinksrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "IMPERX FrameLink Express Video Source", "Source/Video", - "IMPERX FrameLink Express framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_framelinksrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_framelinksrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_framelinksrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_framelinksrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_framelinksrc_unlock); - gstbasesrc_class->unlock_stop = - GST_DEBUG_FUNCPTR (gst_framelinksrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_framelinksrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_FORMAT_FILE, - g_param_spec_string ("config-file", "Config file", - "Filepath of the video file for the selected camera", - DEFAULT_PROP_FORMAT_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_uint ("board", "Board", "Board number", 0, 7, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CHANNEL, - g_param_spec_uint ("channel", "Channel", "Channel number", 0, - 1, DEFAULT_PROP_CHANNEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - -} - -static void -gst_framelinksrc_reset (GstFramelinkSrc * src) -{ - g_assert (src->grabber == NULL); - - src->acq_started = FALSE; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } -} - -static void -gst_framelinksrc_init (GstFramelinkSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->format_file = g_strdup (DEFAULT_PROP_FORMAT_FILE); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->board = DEFAULT_PROP_BOARD; - src->channel = DEFAULT_PROP_CHANNEL; - src->timeout = DEFAULT_PROP_TIMEOUT; - - g_mutex_init (&src->mutex); - g_cond_init (&src->cond); - src->stop_requested = FALSE; - src->caps = NULL; - src->buffer = NULL; - - gst_framelinksrc_reset (src); -} - -void -gst_framelinksrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstFramelinkSrc *src; - - src = GST_FRAMELINK_SRC (object); - - switch (property_id) { - case PROP_FORMAT_FILE: - g_free (src->format_file); - src->format_file = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - if (src->acq_started) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - src->num_capture_buffers = g_value_get_uint (value); - } - break; - case PROP_BOARD: - src->board = g_value_get_uint (value); - break; - case PROP_CHANNEL: - src->channel = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_framelinksrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstFramelinkSrc *src; - - g_return_if_fail (GST_IS_FRAMELINK_SRC (object)); - src = GST_FRAMELINK_SRC (object); - - switch (property_id) { - case PROP_FORMAT_FILE: - g_value_set_string (value, src->format_file); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_uint (value, src->board); - break; - case PROP_CHANNEL: - g_value_set_uint (value, src->channel); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_framelinksrc_dispose (GObject * object) -{ - GstFramelinkSrc *src; - - g_return_if_fail (GST_IS_FRAMELINK_SRC (object)); - src = GST_FRAMELINK_SRC (object); - - /* clean up as possible. may be called multiple times */ - - g_mutex_clear (&src->mutex); - g_cond_clear (&src->cond); - - G_OBJECT_CLASS (gst_framelinksrc_parent_class)->dispose (object); -} - -void -gst_framelinksrc_finalize (GObject * object) -{ - GstFramelinkSrc *src; - - g_return_if_fail (GST_IS_FRAMELINK_SRC (object)); - src = GST_FRAMELINK_SRC (object); - - /* clean up object here */ - g_free (src->format_file); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - G_OBJECT_CLASS (gst_framelinksrc_parent_class)->finalize (object); -} - -static gboolean -gst_framelinksrc_start (GstBaseSrc * bsrc) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - VCECLB_ConfigurationA camConfig; - VCECLB_Error err; - GstVideoInfo vinfo; - VCECLB_CameraDataEx *ci; - VCECLB_EnumData enumData; - HANDLE hDevEnum; - - GST_DEBUG_OBJECT (src, "start"); - - if (!strlen (src->format_file)) { - GST_ERROR_OBJECT (src, "Format file must be specified"); - return FALSE; - } - - if (!g_file_test (src->format_file, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Format file does not exist: %s", src->format_file), (NULL)); - return FALSE; - } - - /* get configuration from file */ - camConfig.cchAlias = MAX_PATH; - camConfig.lpszAlias = g_new (gchar, MAX_PATH); - camConfig.cchDescription = MAX_PATH; - camConfig.lpszDescription = g_new (gchar, MAX_PATH); - camConfig.cchManufacturer = MAX_PATH; - camConfig.lpszManufacturer = g_new (gchar, MAX_PATH); - camConfig.cchModel = MAX_PATH; - camConfig.lpszModel = g_new (gchar, MAX_PATH); - - err = VCECLB_LoadConfigA (src->format_file, &camConfig); - if (err != VCECLB_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to load configuration file: %s", src->format_file), (NULL)); - return FALSE; - } - - GST_INFO_OBJECT (src, "Loaded config file for %s - %s", - camConfig.lpszManufacturer, camConfig.lpszModel); - g_free (camConfig.lpszAlias); - g_free (camConfig.lpszDescription); - g_free (camConfig.lpszManufacturer); - g_free (camConfig.lpszModel); - - /* use shortcut since we use this struct a lot */ - ci = &camConfig.pixelInfo.cameraData; - - /* copy pixel info struct to be used when unpacking data */ - memcpy (&src->pixInfo, &camConfig.pixelInfo, sizeof (VCECLB_RawPixelInfoEx)); - - if (ci->Packed == 1) { - GST_LOG_OBJECT (src, "Pixel data is packed, we'll unpack it"); - } - - /* enumerate devices */ - enumData.cbSize = sizeof (VCECLB_EnumData); - hDevEnum = VCECLB_EnumInit (); - while (VCECLB_EnumNext (hDevEnum, &enumData) == VCECLB_Err_Success) { - GST_DEBUG_OBJECT (src, "Found device: slot #%d, name '%s'", - enumData.dwSlot, enumData.pSlotName); - - if (enumData.dwSlot == src->board) { - src->grabber = VCECLB_InitByHandle (enumData.pDeviceData, 0); - break; - } - } - VCECLB_EnumClose (hDevEnum); - - if (src->grabber == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Invalid board/device number or failed to initialize grabber (code %d)", - VCECLB_CardLastError ()), (NULL)); - return FALSE; - } - - err = VCECLB_GetDMAAccessEx (src->grabber, src->channel); - if (err != VCECLB_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to get DMA access to port on grabber (code %d)", err), (NULL)); - return FALSE; - } - - err = VCECLB_PrepareEx (src->grabber, src->channel, ci); - if (err != VCECLB_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to configure grabber (code %d)", err), (NULL)); - return FALSE; - } - - /* create caps */ - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - gst_video_info_init (&vinfo); - - ci->BitDepth = ci->BitDepth; - if (ci->BitDepth <= 8) { - GstVideoFormat format; - if (src->pixInfo.BayerPattern == 0) { - format = GST_VIDEO_FORMAT_GRAY8; - } else if (src->pixInfo.BayerPattern == 1 || src->pixInfo.BayerPattern == 2) { - /* Bayer and TRUESENSE will be demosaiced by Imperx into BGRA */ - format = GST_VIDEO_FORMAT_BGRA; - } - gst_video_info_set_format (&vinfo, format, ci->Width, ci->Height); - src->caps = gst_video_info_to_caps (&vinfo); - } else if (ci->BitDepth > 8 && ci->BitDepth <= 16) { - GstVideoFormat format; - GValue val = G_VALUE_INIT; - GstStructure *s; - - if (src->pixInfo.BayerPattern != 0) { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Bayer greater than 8-bit not supported yet."), (NULL)); - return FALSE; - } - - if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { - format = GST_VIDEO_FORMAT_GRAY16_LE; - } else if (G_BYTE_ORDER == G_BIG_ENDIAN) { - format = GST_VIDEO_FORMAT_GRAY16_BE; - } - gst_video_info_set_format (&vinfo, format, ci->Width, ci->Height); - src->caps = gst_video_info_to_caps (&vinfo); - - /* set bpp, extra info for GRAY16 so elements can scale properly */ - s = gst_caps_get_structure (src->caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, ci->BitDepth); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } else if (ci->BitDepth == 24) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_BGRA, ci->Width, - ci->Height); - src->caps = gst_video_info_to_caps (&vinfo); - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Unknown or unsupported bit depth (%d).", ci->BitDepth), (NULL)); - return FALSE; - } - - src->height = vinfo.height; - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - - return TRUE; -} - -static gboolean -gst_framelinksrc_stop (GstBaseSrc * bsrc) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - VCECLB_Error err; - - GST_DEBUG_OBJECT (src, "stop"); - - if (src->acq_started) { - err = VCECLB_StopGrabEx (src->grabber, src->channel); - if (err) { - GST_WARNING_OBJECT (src, "Error calling VCECLB_StopGrabEx: %d", err); - } - src->acq_started = FALSE; - } - - if (src->grabber) { - err = VCECLB_ReleaseDMAAccessEx (src->grabber, src->channel); - if (err) { - GST_WARNING_OBJECT (src, "Error calling VCECLB_ReleaseDMAAccessEx: %d", - err); - } - err = VCECLB_Done (src->grabber); - if (err) { - GST_WARNING_OBJECT (src, "Error calling VCECLB_Done: %d", err); - } - src->grabber = NULL; - } - - gst_framelinksrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_framelinksrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - GstCaps *caps; - - if (src->grabber == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_framelinksrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_framelinksrc_unlock (GstBaseSrc * bsrc) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - g_mutex_lock (&src->mutex); - src->stop_requested = TRUE; - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); - - return TRUE; -} - -static gboolean -gst_framelinksrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstBuffer * -gst_framelinksrc_create_buffer_from_frameinfo (GstFramelinkSrc * src, - VCECLB_FrameInfoEx * pFrameInfo) -{ - GstMapInfo minfo; - GstBuffer *buf; - INT_PTR strideSize; - unsigned long outputBitDepth; - VCECLB_Error err; - unsigned char outputFormat; - - /* TODO: use allocator or use from pool */ - buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - /* Copy image to buffer from surface */ - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (src, - "GstBuffer size=%d, gst_stride=%d, number=%d, timestamp=%d", - minfo.size, src->gst_stride, pFrameInfo->number, pFrameInfo->timestamp); - -#if GST_FRAMELINKSRC_COPY_EXPLICITLY - guint flex_stride = - (ci->WidthPreValid + ci->Width + ci->WidthPostValid) * Bpp; - gint widthBytesPreValid = ci->WidthPreValid * Bpp; - gint widthBytes = ci->Width * Bpp; - gint heightPreValid = ci->HeightPreValid; - /* TODO: use orc_memcpy */ - if (src->gst_stride == flex_stride) { - memcpy (minfo.data, - ((guint8 *) pFrameInfo->lpRawBuffer) + - flex_stride * heightPreValid, minfo.size); - } else { - int i; - GST_LOG_OBJECT (src, "Image strides not identical, copy will be slower."); - for (i = 0; i < src->height; i++) { - memcpy (minfo.data + i * src->gst_stride, - ((guint8 *) pFrameInfo->lpRawBuffer) + - (heightPreValid + i) * flex_stride + widthBytesPreValid, widthBytes); - } - } -#else - outputFormat = - VCECLB_EX_FMT_16BIT | VCECLB_EX_FMT_TopDown | VCECLB_EX_FMT_4Channel; - strideSize = src->gst_stride; - err = - VCECLB_UnpackRawPixelsEx (&src->pixInfo, pFrameInfo->lpRawBuffer, - minfo.data, &strideSize, outputFormat, &outputBitDepth); - if (err != VCECLB_Err_Success) { - GST_ELEMENT_ERROR (src, STREAM, DECODE, - ("Failed to unpack raw pixels (code %d)", err), (NULL)); - goto Error; - } -#endif - gst_buffer_unmap (buf, &minfo); - - return buf; - -Error: - if (minfo.memory != NULL) - gst_buffer_unmap (buf, &minfo); - - if (buf) - gst_buffer_unref (buf); - - return NULL; -} - -static void __stdcall -gst_framelinksrc_callback (void *lpUserData, VCECLB_FrameInfoEx * pFrameInfo) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (lpUserData); - gint dropped_frames; - static guint64 last_frame_number = 0; - static guint64 buffers_processed = 0; - static guint64 total_dropped_frames = 0; - GstClock *clock; - GstClockTime timestamp; - - g_assert (src != NULL); - - clock = gst_element_get_clock (GST_ELEMENT (src)); - timestamp = GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - gst_clock_get_time (clock)); - gst_object_unref (clock); - - /* check for DMA errors */ - if (pFrameInfo->dma_status == VCECLB_DMA_STATUS_FRAME_DROP) { - /* TODO: save this in dropped frame total? */ - GST_WARNING_OBJECT (src, "Frame dropped from DMA system."); - return; - } else if (pFrameInfo->dma_status == VCECLB_DMA_STATUS_FIFO_OVERRUN) { - GST_WARNING_OBJECT (src, "DMA system reports FIFO overrun"); - return; - } else if (pFrameInfo->dma_status == VCECLB_DMA_STATUS_ABORTED) { - GST_WARNING_OBJECT (src, "DMA system reports acquisition was aborted"); - return; - } else if (pFrameInfo->dma_status == VCECLB_DMA_STATUS_DICONNECTED) { - GST_WARNING_OBJECT (src, "DMA system reports camera is disconnected"); - return; - } else if (pFrameInfo->dma_status != VCECLB_DMA_STATUS_OK) { - GST_WARNING_OBJECT (src, "DMA system reports unknown error"); - return; - } - - /* check for dropped frames and disrupted signal */ - dropped_frames = (pFrameInfo->number - last_frame_number) - 1; - if (dropped_frames > 0) { - total_dropped_frames += dropped_frames; - GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - total_dropped_frames); - } else if (dropped_frames < 0) { - GST_WARNING_OBJECT (src, - "Signal disrupted, frames likely dropped and timestamps inaccurate"); - - /* frame timestamps reset, so adjust start time, accuracy reduced */ - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))) - - pFrameInfo->timestamp * GST_USECOND; - } - last_frame_number = pFrameInfo->number; - - g_mutex_lock (&src->mutex); - - if (src->buffer) { - /* TODO: save this in dropped frame total? */ - GST_WARNING_OBJECT (src, - "Got new buffer before old handled, dropping old."); - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - src->buffer = gst_framelinksrc_create_buffer_from_frameinfo (src, pFrameInfo); - - GST_BUFFER_TIMESTAMP (src->buffer) = timestamp; - - GST_BUFFER_OFFSET (src->buffer) = buffers_processed; - ++buffers_processed; - - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); -} - -static GstFlowReturn -gst_framelinksrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstFramelinkSrc *src = GST_FRAMELINK_SRC (psrc); - VCECLB_Error err; - gint64 end_time; - - GST_LOG_OBJECT (src, "create"); - - /* Start acquisition if not already started */ - if (G_UNLIKELY (!src->acq_started)) { - GST_LOG_OBJECT (src, "starting acquisition"); - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - err = - VCECLB_StartGrabEx (src->grabber, src->channel, 0, - gst_framelinksrc_callback, src); - - if (err != VCECLB_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to start grabbing (code %d)", err), (NULL)); - return GST_FLOW_ERROR; - } - src->acq_started = TRUE; - } - - /* wait for a buffer to be ready */ - g_mutex_lock (&src->mutex); - end_time = g_get_monotonic_time () + src->timeout * G_TIME_SPAN_MILLISECOND; - while (!src->buffer && !src->stop_requested) { - if (!g_cond_wait_until (&src->cond, &src->mutex, end_time)) { - g_mutex_unlock (&src->mutex); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Timeout, no data received after %d ms", src->timeout), (NULL)); - return GST_FLOW_ERROR; - } - } - *buf = src->buffer; - src->buffer = NULL; - g_mutex_unlock (&src->mutex); - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_framelinksrc_debug, "imperxflexsrc", 0, - "debug category for framelinksrc element"); - gst_element_register (plugin, "imperxflexsrc", GST_RANK_NONE, - gst_framelinksrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - imperxflex, - "IMPERX FrameLink Express frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/imperxflex/gstframelinksrc.h b/sys/imperxflex/gstframelinksrc.h deleted file mode 100644 index ea25ab5..0000000 --- a/sys/imperxflex/gstframelinksrc.h +++ /dev/null @@ -1,80 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_FRAMELINK_SRC_H_ -#define _GST_FRAMELINK_SRC_H_ - -#include - -#define WIN32_LEAN_AND_MEAN -#include - -#define bool gboolean -#include - -G_BEGIN_DECLS - -#define GST_TYPE_FRAMELINK_SRC (gst_framelinksrc_get_type()) -#define GST_FRAMELINK_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FRAMELINK_SRC,GstFramelinkSrc)) -#define GST_FRAMELINK_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FRAMELINK_SRC,GstFramelinkSrcClass)) -#define GST_IS_FRAMELINK_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FRAMELINK_SRC)) -#define GST_IS_FRAMELINK_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FRAMELINK_SRC)) - -typedef struct _GstFramelinkSrc GstFramelinkSrc; -typedef struct _GstFramelinkSrcClass GstFramelinkSrcClass; - -struct _GstFramelinkSrc -{ - GstPushSrc base_framelinksrc; - - gboolean acq_started; - - /* camera handle */ - HANDLE grabber; - - /* properties */ - gchar *format_file; - guint num_capture_buffers; - guint board; - guint channel; - gint timeout; - - GstBuffer *buffer; - GstClockTime acq_start_time; - - GstCaps *caps; - gint height; - gint gst_stride; - VCECLB_RawPixelInfoEx pixInfo; - - GMutex mutex; - GCond cond; - gboolean stop_requested; -}; - -struct _GstFramelinkSrcClass -{ - GstPushSrcClass base_framelinksrc_class; -}; - -GType gst_framelinksrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/imperxsdi/CMakeLists.txt b/sys/imperxsdi/CMakeLists.txt deleted file mode 100644 index 223123a..0000000 --- a/sys/imperxsdi/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstimperxsdisrc.cpp) - -set (HEADERS - gstimperxsdisrc.h) - -include_directories (AFTER - ${IMPERX_SDI_INCLUDE_DIR}) - -set (libname gstimperxsdi) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${IMPERX_SDI_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/imperxsdi/gstimperxsdisrc.cpp b/sys/imperxsdi/gstimperxsdisrc.cpp deleted file mode 100644 index eb5288c..0000000 --- a/sys/imperxsdi/gstimperxsdisrc.cpp +++ /dev/null @@ -1,892 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstimperxsdisrc - * - * The imperxsdisrc element is a source for IMPERX HD-SDI Express framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v imperxsdisrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default IMPERX HD-SDI Express framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifdef HAVE_ORC -#include -#else -#define orc_memcpy memcpy -#endif - -#include "gstimperxsdisrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_imperxsdisrc_debug); -#define GST_CAT_DEFAULT gst_imperxsdisrc_debug - -#define PORT_VIDEO 0 -#define PORT_AUDIO 1 - -/* prototypes */ -static void gst_imperxsdisrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_imperxsdisrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_imperxsdisrc_dispose (GObject * object); -static void gst_imperxsdisrc_finalize (GObject * object); - -static gboolean gst_imperxsdisrc_start (GstBaseSrc * src); -static gboolean gst_imperxsdisrc_stop (GstBaseSrc * src); -static GstCaps *gst_imperxsdisrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_imperxsdisrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_imperxsdisrc_unlock (GstBaseSrc * src); -static gboolean gst_imperxsdisrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_imperxsdisrc_create (GstPushSrc * src, - GstBuffer ** buf); - -static GstCaps *gst_imperxsdisrc_create_caps (GstImperxSdiSrc * src); -enum -{ - PROP_0, - PROP_NUM_CAPTURE_BUFFERS, - PROP_BOARD, - PROP_TIMEOUT -}; - -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_BOARD 0 -#define DEFAULT_PROP_TIMEOUT 1000 - -/* pad templates */ - -static GstStaticPadTemplate gst_imperxsdisrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ v210, AYUV64, YUY2, BGR }")) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstImperxSdiSrc, gst_imperxsdisrc, GST_TYPE_PUSH_SRC); - -static void -gst_imperxsdisrc_class_init (GstImperxSdiSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_imperxsdisrc_set_property; - gobject_class->get_property = gst_imperxsdisrc_get_property; - gobject_class->dispose = gst_imperxsdisrc_dispose; - gobject_class->finalize = gst_imperxsdisrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_imperxsdisrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "IMPERX HD-SDI Express Video Source", "Source/Video", - "IMPERX HD-SDI Express framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_unlock); - gstbasesrc_class->unlock_stop = - GST_DEBUG_FUNCPTR (gst_imperxsdisrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_imperxsdisrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 3, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_uint ("board", "Board", "Board number", 0, 7, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - -} - -static void -gst_imperxsdisrc_reset (GstImperxSdiSrc * src) -{ - g_assert (src->grabber == NULL); - - src->acq_started = FALSE; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - src->width = 0; - src->height = 0; - src->framerate = 0; - src->is_interlaced = FALSE; -} - -static void -gst_imperxsdisrc_init (GstImperxSdiSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->board = DEFAULT_PROP_BOARD; - src->timeout = DEFAULT_PROP_TIMEOUT; - - g_mutex_init (&src->mutex); - g_cond_init (&src->cond); - src->stop_requested = FALSE; - src->caps = NULL; - src->buffer = NULL; - - gst_imperxsdisrc_reset (src); -} - -void -gst_imperxsdisrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstImperxSdiSrc *src; - - src = GST_IMPERX_SDI_SRC (object); - - switch (property_id) { - case PROP_NUM_CAPTURE_BUFFERS: - if (src->acq_started) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - src->num_capture_buffers = g_value_get_uint (value); - } - break; - case PROP_BOARD: - src->board = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_imperxsdisrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstImperxSdiSrc *src; - - g_return_if_fail (GST_IS_IMPERX_SDI_SRC (object)); - src = GST_IMPERX_SDI_SRC (object); - - switch (property_id) { - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_uint (value, src->board); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_imperxsdisrc_dispose (GObject * object) -{ - GstImperxSdiSrc *src; - - g_return_if_fail (GST_IS_IMPERX_SDI_SRC (object)); - src = GST_IMPERX_SDI_SRC (object); - - /* clean up as possible. may be called multiple times */ - - g_mutex_clear (&src->mutex); - g_cond_clear (&src->cond); - - G_OBJECT_CLASS (gst_imperxsdisrc_parent_class)->dispose (object); -} - -void -gst_imperxsdisrc_finalize (GObject * object) -{ - GstImperxSdiSrc *src; - - g_return_if_fail (GST_IS_IMPERX_SDI_SRC (object)); - src = GST_IMPERX_SDI_SRC (object); - - /* clean up object here */ - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - G_OBJECT_CLASS (gst_imperxsdisrc_parent_class)->finalize (object); -} - -static const gchar * -gst_imperxsdisrc_get_error (VCESDI_Error err) -{ - switch (err) { - case VCESDI_Err_Success: - return "Operation successful"; - case VCESDI_Err_badArgument: - return "Argument is invalid"; - case VCESDI_Err_noDriver: - "Driver is not installed"; - case VCESDI_Err_noDevicePresent: - return "Device is not present"; - case VCESDI_Err_DeviceBusy: - return "Device busy or not responding"; - case VCESDI_Err_noMemory: - return "Not enough memory to perform operation"; - case VCESDI_Err_notInitialized: - return "Sub-component has not been initialized"; - case VCESDI_Err_notSupported: - return "Operation is not supported"; - case VCESDI_Err_UnknownError: - return "Unknown (system) error occurs"; - default: - return "Invalid error code"; - } -} - -static gboolean -gst_imperxsdisrc_start (GstBaseSrc * bsrc) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - VCESDI_Error err; - VCESDI_EnumData enumData; - VCESDI_ENUM hDevEnum; - guint8 camera_connected; - VCESDI_CameraStatus camera_status; - gint fps_n, fps_d; - - GST_DEBUG_OBJECT (src, "start"); - - /* enumerate devices */ - enumData.cbSize = sizeof (VCESDI_EnumData); - hDevEnum = VCESDI_EnumInit (); - while (VCESDI_EnumNext (hDevEnum, &enumData) == VCESDI_Err_Success) { - GST_DEBUG_OBJECT (src, "Found device: slot #%d, name '%s'", - enumData.dwSlot, enumData.pSlotName); - - if (enumData.dwSlot == src->board) { - src->grabber = VCESDI_InitByHandle (enumData.deviceData); - break; - } - } - VCESDI_EnumClose (hDevEnum); - - if (src->grabber == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Invalid board/device number or failed to initialize grabber"), - (NULL)); - return FALSE; - } - - err = VCESDI_IsCameraConnected (src->grabber, PORT_VIDEO, &camera_connected); - if (err != VCESDI_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to get camera connected status (%s)", - gst_imperxsdisrc_get_error (err)), (NULL)); - return FALSE; - } - - if (camera_connected) { - GST_DEBUG_OBJECT (src, "Camera has been detected"); - } else { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("No camera detected"), (NULL)); - return FALSE; - } - - err = VCESDI_GetCameraStatus (src->grabber, PORT_VIDEO, &camera_status); - if (err != VCESDI_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to get camera status (%s)", gst_imperxsdisrc_get_error (err)), - (NULL)); - return FALSE; - } - - src->width = camera_status.Width; - src->height = camera_status.Height; - src->framerate = camera_status.FrameRate; - src->is_interlaced = (camera_status.Mode == VCESDI_CameraMode_Interlaced); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - fps_n = (gint) (src->framerate * 1000); - fps_d = 1000; - src->caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - src->caps = gst_caps_make_writable (src->caps); - gst_caps_set_simple (src->caps, - "width", G_TYPE_INT, src->width, - "height", G_TYPE_INT, src->height, - "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL); - GST_DEBUG_OBJECT (src, "Detected video is %dx%d@%d", src->width, src->height, - src->framerate); - - return TRUE; -} - -static void -unpack_YVYU10 (gpointer dest, const gpointer data, - const gint stride, gint x, gint y, gint width) -{ - int i; - const guint8 *restrict s = (guint8 *) (data) + stride * y; - guint16 *restrict d = (guint16 *) dest; - guint32 a0, a1, a2, a3; - guint16 y0, y1, y2, y3, y4, y5; - guint16 u0, u2, u4; - guint16 v0, v2, v4; - - s += x * 2; - for (i = 0; i < width; i += 6) { - a0 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 0); - a1 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 4); - a2 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 8); - a3 = GST_READ_UINT32_LE (s + (i / 6) * 16 + 12); - - y0 = ((a0 >> 0) & 0x3ff) << 6; - u0 = ((a0 >> 10) & 0x3ff) << 6; - y1 = ((a0 >> 20) & 0x3ff) << 6; - v0 = (((a0 >> 30) | (a1 << 2)) & 0x3ff) << 6; - y2 = ((a1 >> 8) & 0x3ff) << 6; - u2 = ((a1 >> 18) & 0x3ff) << 6; - - y3 = ((a2 >> 0) & 0x3ff) << 6; - v2 = ((a2 >> 10) & 0x3ff) << 6; - y4 = ((a2 >> 20) & 0x3ff) << 6; - u4 = (((a2 >> 30) | (a3 << 2)) & 0x3ff) << 6; - y5 = ((a3 >> 8) & 0x3ff) << 6; - v4 = ((a3 >> 18) & 0x3ff) << 6; - - d[4 * (i + 0) + 0] = 0xffff; - d[4 * (i + 0) + 1] = y0; - d[4 * (i + 0) + 2] = u0; - d[4 * (i + 0) + 3] = v0; - - if (i < width - 1) { - d[4 * (i + 1) + 0] = 0xffff; - d[4 * (i + 1) + 1] = y1; - d[4 * (i + 1) + 2] = u0; - d[4 * (i + 1) + 3] = v0; - } - if (i < width - 2) { - d[4 * (i + 2) + 0] = 0xffff; - d[4 * (i + 2) + 1] = y2; - d[4 * (i + 2) + 2] = u2; - d[4 * (i + 2) + 3] = v2; - } - if (i < width - 3) { - d[4 * (i + 3) + 0] = 0xffff; - d[4 * (i + 3) + 1] = y3; - d[4 * (i + 3) + 2] = u2; - d[4 * (i + 3) + 3] = v2; - } - if (i < width - 4) { - d[4 * (i + 4) + 0] = 0xffff; - d[4 * (i + 4) + 1] = y4; - d[4 * (i + 4) + 2] = u4; - d[4 * (i + 4) + 3] = v4; - } - if (i < width - 5) { - d[4 * (i + 5) + 0] = 0xffff; - d[4 * (i + 5) + 1] = y5; - d[4 * (i + 5) + 2] = u4; - d[4 * (i + 5) + 3] = v4; - } - } -} - -static void -repack_YVYU10_to_v210 (gpointer dest, const gpointer data, - const gint stride, gint x, gint y, gint width) -{ - int i; - const guint8 *restrict s = (guint8 *) (data) + stride * y; - guint32 *restrict d = (guint32 *) dest; - guint32 a0, a1, a2, a3; - guint16 y0, y1, y2, y3, y4, y5; - guint16 u0, u2, u4; - guint16 v0, v2, v4; - - s += x * 2; - for (i = 0; i < width; i += 4) { - a0 = GST_READ_UINT32_LE (s + (i / 4) * 16 + 0); - a1 = GST_READ_UINT32_LE (s + (i / 4) * 16 + 4); - a2 = GST_READ_UINT32_LE (s + (i / 4) * 16 + 8); - a3 = GST_READ_UINT32_LE (s + (i / 4) * 16 + 12); - - y0 = ((a0 >> 0) & 0x3ff); - u0 = ((a0 >> 10) & 0x3ff); - y1 = ((a0 >> 20) & 0x3ff); - v0 = (((a0 >> 30) | (a1 << 2)) & 0x3ff); - y2 = ((a1 >> 8) & 0x3ff); - u2 = ((a1 >> 18) & 0x3ff); - - y3 = ((a2 >> 0) & 0x3ff); - v2 = ((a2 >> 10) & 0x3ff); - y4 = ((a2 >> 20) & 0x3ff); - u4 = (((a2 >> 30) | (a3 << 2)) & 0x3ff); - y5 = ((a3 >> 8) & 0x3ff); - v4 = ((a3 >> 18) & 0x3ff); - - d[i + 0] = (v0 << 20) | (y0 << 10) | u0; - d[i + 1] = (y2 << 20) | (u2 << 10) | y1; - d[i + 2] = (u4 << 20) | (y3 << 10) | v2; - d[i + 3] = (y5 << 20) | (v4 << 10) | y4; - } -} - -static GstBuffer * -gst_imperxsdisrc_create_buffer_from_frameinfo (GstImperxSdiSrc * src, - VCESDI_FrameInfo * pFrameInfo) -{ - GstMapInfo minfo; - GstBuffer *buf; - int buffer_size; - - if (src->is_interlaced - && src->camera_data.Format != VCESDI_OutputFormat_YCrCb10) { - VCESDI_Decode (&src->camera_data, NULL, NULL, &src->imperx_stride, - src->camera_data.Format, NULL, NULL); - buffer_size = src->camera_data.CameraStatus.Height * src->imperx_stride; - } else { - buffer_size = src->height * src->gst_stride; - } - - buf = gst_buffer_new_and_alloc (buffer_size); - - /* Copy image to buffer from surface */ - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (src, - "SrcSize=%d, SrcStride=%d, DstSize=%d, DstStride=%d, number=%d, timestamp=%d", - pFrameInfo->bufferSize, src->imperx_stride, minfo.size, src->gst_stride, - pFrameInfo->number, pFrameInfo->timestamp); - - if (src->is_interlaced - && src->camera_data.Format != VCESDI_OutputFormat_YCrCb10) { - VCESDI_Decode (&src->camera_data, pFrameInfo->lpRawBuffer, minfo.data, - &src->imperx_stride, src->camera_data.Format, NULL, NULL); - } else { - if (src->format == GST_VIDEO_FORMAT_AYUV64) { - gint row; - if (src->is_interlaced) { - gint hh = src->height / 2; - /* assumes even number of rows, which is the case for all formats */ - for (row = 0; row < hh; row++) { - unpack_YVYU10 (minfo.data + src->gst_stride * (row * 2), - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row, src->width); - unpack_YVYU10 (minfo.data + src->gst_stride * (row * 2 + 1), - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row + hh, - src->width); - } - } else { - for (row = 0; row < src->height; row++) { - unpack_YVYU10 (minfo.data + src->gst_stride * row, - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row, src->width); - } - } - } else if (src->format == GST_VIDEO_FORMAT_v210) { - gint row; - if (src->is_interlaced) { - gint hh = src->height / 2; - /* assumes even number of rows, which is the case for all formats */ - for (row = 0; row < hh; row++) { - repack_YVYU10_to_v210 (minfo.data + src->gst_stride * (row * 2), - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row, src->width); - repack_YVYU10_to_v210 (minfo.data + src->gst_stride * (row * 2 + 1), - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row + hh, - src->width); - } - } else { - for (row = 0; row < src->height; row++) { - repack_YVYU10_to_v210 (minfo.data + src->gst_stride * row, - pFrameInfo->lpRawBuffer, src->imperx_stride, 0, row, src->width); - } - } - } else { - /* all supported formats should already be 4-byte aligned */ - g_assert (pFrameInfo->bufferSize >= minfo.size); - orc_memcpy (minfo.data, pFrameInfo->lpRawBuffer, minfo.size); - } - } - - gst_buffer_unmap (buf, &minfo); - - return buf; -} - -static void __stdcall -gst_imperxsdisrc_callback (void *lpUserData, VCESDI_FrameInfo * pFrameInfo) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (lpUserData); - gint dropped_frames; - static guint32 last_frame_number = 0; - static guint64 buffers_processed = 0; - static guint64 total_dropped_frames = 0; - - g_assert (src != NULL); - - /* check for DMA errors */ - if (pFrameInfo->dma_status == DMA_STATUS_FRAME_DROPED) { - /* TODO: save this in dropped frame total? */ - GST_WARNING_OBJECT (src, "Frame dropped from DMA system."); - return; - } else if (pFrameInfo->dma_status == DMA_STATUS_FIFO_OVERRUN) { - GST_WARNING_OBJECT (src, "DMA system reports FIFO overrun"); - return; - } else if (pFrameInfo->dma_status == DMA_STATUS_ABORTED) { - GST_WARNING_OBJECT (src, "DMA system reports acquisition was aborted"); - return; - } else if (pFrameInfo->dma_status == DMA_STATUS_DICONNECTED) { - GST_WARNING_OBJECT (src, "DMA system reports camera is disconnected"); - return; - } else if (pFrameInfo->dma_status != DMA_STATUS_OK) { - GST_WARNING_OBJECT (src, "DMA system reports unknown error"); - return; - } - - /* check for dropped frames and disrupted signal */ - dropped_frames = (pFrameInfo->number - last_frame_number) - 1; - if (dropped_frames > 0) { - total_dropped_frames += dropped_frames; - GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - total_dropped_frames); - } else if (dropped_frames < 0) { - GST_WARNING_OBJECT (src, - "Signal disrupted, frames likely dropped and timestamps inaccurate"); - - /* frame timestamps reset, so adjust start time, accuracy reduced */ - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))) - - pFrameInfo->timestamp * GST_USECOND; - } - last_frame_number = pFrameInfo->number; - - g_mutex_lock (&src->mutex); - - if (src->buffer) { - /* TODO: save this in dropped frame total? */ - GST_WARNING_OBJECT (src, - "Got new buffer before old handled, dropping old."); - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - src->buffer = gst_imperxsdisrc_create_buffer_from_frameinfo (src, pFrameInfo); - - GST_BUFFER_TIMESTAMP (src->buffer) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - src->acq_start_time + pFrameInfo->timestamp * GST_USECOND); - GST_BUFFER_OFFSET (src->buffer) = buffers_processed; - ++buffers_processed; - - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); -} - -static gboolean -gst_imperxsdisrc_start_grab (GstImperxSdiSrc * src) -{ - GstBaseSrc *basesrc = GST_BASE_SRC (src); - GstCaps *peercaps; - VCESDI_Error err; - GstVideoInfo vinfo; - - /* we've already fixated width, height, framerate */ - peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), src->caps); - peercaps = gst_caps_fixate (peercaps); - gst_caps_replace (&src->caps, peercaps); - gst_video_info_from_caps (&vinfo, src->caps); - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - - src->format = GST_VIDEO_INFO_FORMAT (&vinfo); - switch (src->format) { - case GST_VIDEO_FORMAT_v210: - case GST_VIDEO_FORMAT_AYUV64: - src->camera_data.Format = VCESDI_OutputFormat_YCrCb10; - /* 12 components (6 pixels), in 16 bytes */ - src->imperx_stride = GST_ROUND_UP_4 ((int) ((src->width * 16) / 6.0)); - break; - case GST_VIDEO_FORMAT_YUY2: - src->camera_data.Format = VCESDI_OutputFormat_YCrCb8; - src->imperx_stride = src->width * 2; - break; - case GST_VIDEO_FORMAT_BGR: - src->camera_data.Format = VCESDI_OutputFormat_RGB24; - src->imperx_stride = src->width * 3; - break; - default: - g_assert_not_reached (); - } - - err = VCESDI_GetDMAAccess (src->grabber, PORT_VIDEO); - if (err != VCESDI_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to get DMA access to port on grabber (%s)", - gst_imperxsdisrc_get_error (err)), (NULL)); - return FALSE; - } - - err = - VCESDI_SetBufferCount (src->grabber, PORT_VIDEO, - src->num_capture_buffers); - if (err != VCESDI_Err_Success) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to set buffer count (%s)", gst_imperxsdisrc_get_error (err)), - (NULL)); - return FALSE; - } - - src->camera_data.TransferMode = VCESDI_TransferMode_Frames; - err = - VCESDI_StartGrab (src->grabber, PORT_VIDEO, 0, &src->camera_data, - (VCESDI_GrabFrame_Callback) gst_imperxsdisrc_callback, src); - - return TRUE; -} - -static gboolean -gst_imperxsdisrc_stop (GstBaseSrc * bsrc) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - VCESDI_Error err; - - GST_DEBUG_OBJECT (src, "stop"); - - if (src->acq_started) { - err = VCESDI_StopGrab (src->grabber, PORT_VIDEO); - if (err) { - GST_WARNING_OBJECT (src, "Error stopping grab: '%s'", - gst_imperxsdisrc_get_error (err)); - } - src->acq_started = FALSE; - } - - if (src->grabber) { - err = VCESDI_ReleaseDMAAccess (src->grabber, PORT_VIDEO); - if (err) { - GST_WARNING_OBJECT (src, "Error releasing DMA accessx: %s", - gst_imperxsdisrc_get_error (err)); - } - err = VCESDI_Done (src->grabber); - if (err) { - GST_WARNING_OBJECT (src, "Error closing grabber: %s", - gst_imperxsdisrc_get_error (err)); - } - src->grabber = NULL; - } - - gst_imperxsdisrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_imperxsdisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - GstCaps *caps; - - if (src->grabber == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_imperxsdisrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_imperxsdisrc_unlock (GstBaseSrc * bsrc) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - g_mutex_lock (&src->mutex); - src->stop_requested = TRUE; - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); - - return TRUE; -} - -static gboolean -gst_imperxsdisrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstFlowReturn -gst_imperxsdisrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstImperxSdiSrc *src = GST_IMPERX_SDI_SRC (psrc); - gint64 end_time; - - GST_LOG_OBJECT (src, "create"); - - /* Start acquisition if not already started */ - if (G_UNLIKELY (!src->acq_started)) { - GST_LOG_OBJECT (src, "starting acquisition"); - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - if (!gst_imperxsdisrc_start_grab (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to start grabbing"), (NULL)); - return GST_FLOW_ERROR; - } - src->acq_started = TRUE; - } - - /* wait for a buffer to be ready */ - g_mutex_lock (&src->mutex); - end_time = g_get_monotonic_time () + src->timeout * G_TIME_SPAN_MILLISECOND; - while (!src->buffer && !src->stop_requested) { - if (!g_cond_wait_until (&src->cond, &src->mutex, end_time)) { - g_mutex_unlock (&src->mutex); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Timeout, no data received after %d ms", src->timeout), (NULL)); - return GST_FLOW_ERROR; - } - } - *buf = src->buffer; - src->buffer = NULL; - g_mutex_unlock (&src->mutex); - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_imperxsdisrc_debug, "imperxsdisrc", 0, - "debug category for imperxsdisrc element"); - gst_element_register (plugin, "imperxsdisrc", GST_RANK_NONE, - gst_imperxsdisrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - imperxsdi, - "IMPERX HD-SDI Express frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/imperxsdi/gstimperxsdisrc.h b/sys/imperxsdi/gstimperxsdisrc.h deleted file mode 100644 index 897a8eb..0000000 --- a/sys/imperxsdi/gstimperxsdisrc.h +++ /dev/null @@ -1,83 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_IMPERX_SDI_SRC_H_ -#define _GST_IMPERX_SDI_SRC_H_ - -#include - -#define WIN32_LEAN_AND_MEAN -#include - -#define bool gboolean -#include - -G_BEGIN_DECLS - -#define GST_TYPE_IMPERX_SDI_SRC (gst_imperxsdisrc_get_type()) -#define GST_IMPERX_SDI_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IMPERX_SDI_SRC,GstImperxSdiSrc)) -#define GST_IMPERX_SDI_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IMPERX_SDI_SRC,GstImperxSdiSrcClass)) -#define GST_IS_IMPERX_SDI_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IMPERX_SDI_SRC)) -#define GST_IS_IMPERX_SDI_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IMPERX_SDI_SRC)) - -typedef struct _GstImperxSdiSrc GstImperxSdiSrc; -typedef struct _GstImperxSdiSrcClass GstImperxSdiSrcClass; - -struct _GstImperxSdiSrc -{ - GstPushSrc base_imperxsdisrc; - - gboolean acq_started; - - /* camera handle */ - VCESDI_GRABBER grabber; - VCESDI_CameraData camera_data; - - /* properties */ - guint num_capture_buffers; - guint board; - gint timeout; - - GstBuffer *buffer; - GstClockTime acq_start_time; - - GstCaps *caps; - GstVideoFormat format; - gint width; - gint height; - gfloat framerate; - gboolean is_interlaced; - gint gst_stride; - gint imperx_stride; - - GMutex mutex; - GCond cond; - gboolean stop_requested; -}; - -struct _GstImperxSdiSrcClass -{ - GstPushSrcClass base_imperxsdisrc_class; -}; - -GType gst_imperxsdisrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/iotechdaqx/CMakeLists.txt b/sys/iotechdaqx/CMakeLists.txt deleted file mode 100644 index 0a548d7..0000000 --- a/sys/iotechdaqx/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -add_definitions(-DHAVE_CONFIG_H) - -set ( SOURCES - gstiotechdaqx.c ) - -set ( HEADERS - gstiotechdaqx.h ) - -include_directories ( AFTER - . - ${WAVEBOOK_INCLUDE_DIR} ) - -add_library ( libgstiotechdaqx MODULE - ${SOURCES} - ${HEADERS} ) - -target_link_libraries ( libgstiotechdaqx - ${GLIB2_LIBRARIES} - ${GSTREAMER_LIBRARIES} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_INTERFACE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${IOTECHDAQX_LIBRARIES}) - -install (TARGETS libgstiotechdaqx - LIBRARY DESTINATION lib/gstreamer-0.10) \ No newline at end of file diff --git a/sys/iotechdaqx/gstiotechdaqx.c b/sys/iotechdaqx/gstiotechdaqx.c deleted file mode 100644 index 456b6b7..0000000 --- a/sys/iotechdaqx/gstiotechdaqx.c +++ /dev/null @@ -1,525 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstiotechdaqx - * - * The iotechdaqx element is a source for data acquisition devices supported by the IOtechDaqX driver. - * - * - * Example launch line - * |[ - * gst-launch -v iotechdaqx ! FIXME - * ]| - * FIXME from the default IOtechDaqX device - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include "gstiotechdaqx.h" - -#define NULL 0 - -GST_DEBUG_CATEGORY_STATIC (gst_iotechdaqx_debug); -#define GST_CAT_DEFAULT gst_iotechdaqx_debug - -/* prototypes */ - - -static void gst_iotechdaqx_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_iotechdaqx_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_iotechdaqx_dispose (GObject * object); -static void gst_iotechdaqx_finalize (GObject * object); - -static GstCaps *gst_iotechdaqx_get_caps (GstBaseSrc * src); -static gboolean gst_iotechdaqx_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_iotechdaqx_newsegment (GstBaseSrc * src); -static gboolean gst_iotechdaqx_start (GstBaseSrc * src); -static gboolean gst_iotechdaqx_stop (GstBaseSrc * src); -static void -gst_iotechdaqx_get_times (GstBaseSrc * src, GstBuffer * buffer, - GstClockTime * start, GstClockTime * end); -static gboolean gst_iotechdaqx_get_size (GstBaseSrc * src, guint64 * size); -static gboolean gst_iotechdaqx_is_seekable (GstBaseSrc * src); -static gboolean gst_iotechdaqx_query (GstBaseSrc * src, GstQuery * query); -static gboolean gst_iotechdaqx_check_get_range (GstBaseSrc * src); -static void gst_iotechdaqx_fixate (GstBaseSrc * src, GstCaps * caps); -static GstFlowReturn gst_iotechdaqx_create (GstPushSrc * src, GstBuffer ** buf); - -enum -{ - PROP_0, - PROP_BOARD_INDEX - /* FILL ME */ -}; - -#define DEFAULT_PROP_BOARD_INDEX 0 - -/* pad templates */ - -static GstStaticPadTemplate gst_iotechdaqx_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - //GST_AUDIO_INT_PAD_TEMPLATE_CAPS) - "audio/x-raw-int, " - "rate = (int) 10000, " - "channels = (int) 1, " - "endianness = (int) BYTE_ORDER, " - "width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true") - ); - -/* class initialization */ - -GST_BOILERPLATE (GstIOtechDaqX, gst_iotechdaqx, GstPushSrc, GST_TYPE_PUSH_SRC); - - - char *GetProtocol (DaqProtocol protocol) -{ - /*This function is used to display the protcol name; since the - protcol itself is stored as a number, this function associates - the protocol number with a string. - */ - char *protocolName[64]; - - switch (protocol) { - case DaqProtocolNone: - *protocolName = "DaqProtocolNone"; - break; - case DaqProtocol4: - *protocolName = "DaqProtocol4"; - break; - case DaqProtocol8: - *protocolName = "DaqProtocol8"; - break; - case DaqProtocolSMC666: - *protocolName = "DaqProtocolSMC666"; - break; - case DaqProtocolFastEPP: - *protocolName = "DaqProtocolFastEPP"; - break; - case DaqProtocolECP: - *protocolName = "DaqProtocolECP"; - break; - case DaqProtocol8BitEPP: - *protocolName = "DaqProtocol8BitEPP"; - break; - case DaqProtocolTCPIP: - *protocolName = "DaqProtocolTCPIP"; - break; - case DaqProtocolISA: - *protocolName = "DaqProtocolISA"; - break; - case DaqProtocolPcCard: - *protocolName = "DaqProtocolPcCard"; - break; - case DaqProtocolUSB: - *protocolName = "DaqProtocolUSB"; - break; - case DaqProtocolPCI: - *protocolName = "DaqProtocolPCI"; - break; - case DaqProtocolCPCI: - *protocolName = "DaqProtocolCPCI"; - break; - default: - *protocolName = "Unknown"; - break; - } - return *protocolName; -} - - -static void -gst_iotechdaqx_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_iotechdaqx_src_template)); - - gst_element_class_set_details_simple (element_class, - "IOtechDaqX Data Source", "Source/Audio", - "IOtechDaqX data source", "Joshua Doe "); -} - -static void -gst_iotechdaqx_class_init (GstIOtechDaqXClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstBaseSrcClass *base_src_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *push_src_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_iotechdaqx_set_property; - gobject_class->get_property = gst_iotechdaqx_get_property; - gobject_class->dispose = gst_iotechdaqx_dispose; - gobject_class->finalize = gst_iotechdaqx_finalize; - base_src_class->get_caps = GST_DEBUG_FUNCPTR (gst_iotechdaqx_get_caps); - base_src_class->set_caps = GST_DEBUG_FUNCPTR (gst_iotechdaqx_set_caps); - base_src_class->newsegment = GST_DEBUG_FUNCPTR (gst_iotechdaqx_newsegment); - base_src_class->start = GST_DEBUG_FUNCPTR (gst_iotechdaqx_start); - base_src_class->stop = GST_DEBUG_FUNCPTR (gst_iotechdaqx_stop); - base_src_class->get_times = GST_DEBUG_FUNCPTR (gst_iotechdaqx_get_times); - base_src_class->get_size = GST_DEBUG_FUNCPTR (gst_iotechdaqx_get_size); - base_src_class->is_seekable = GST_DEBUG_FUNCPTR (gst_iotechdaqx_is_seekable); - base_src_class->query = GST_DEBUG_FUNCPTR (gst_iotechdaqx_query); - base_src_class->check_get_range = - GST_DEBUG_FUNCPTR (gst_iotechdaqx_check_get_range); - base_src_class->fixate = GST_DEBUG_FUNCPTR (gst_iotechdaqx_fixate); - - push_src_class->create = GST_DEBUG_FUNCPTR (gst_iotechdaqx_create); - - - /* Install GObject properties */ - //g_object_class_install_property (gobject_class, PROP_BOARD_INDEX, - // g_param_spec_int ("board", "Board", "Index of board connected to camera", - // 0, 15, DEFAULT_PROP_BOARD_INDEX, G_PARAM_READWRITE)); - -} - -static void -gst_iotechdaqx_init (GstIOtechDaqX * iotechdaqx, - GstIOtechDaqXClass * iotechdaqx_class) -{ - iotechdaqx->srcpad = - gst_pad_new_from_static_template (&gst_iotechdaqx_src_template, "src"); - - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (iotechdaqx), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (iotechdaqx), GST_FORMAT_TIME); - - /* initialize member variables */ - iotechdaqx->caps = NULL; - iotechdaqx->handle = -1; - iotechdaqx->opened = FALSE; - - // FIXME: initialize ALL member variables -} - -void -gst_iotechdaqx_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstIOtechDaqX *iotechdaqx; - - g_return_if_fail (GST_IS_IOTECHDAQX (object)); - iotechdaqx = GST_IOTECHDAQX (object); - - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_iotechdaqx_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstIOtechDaqX *iotechdaqx; - - g_return_if_fail (GST_IS_IOTECHDAQX (object)); - iotechdaqx = GST_IOTECHDAQX (object); - - switch (property_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_iotechdaqx_dispose (GObject * object) -{ - GstIOtechDaqX *iotechdaqx; - - g_return_if_fail (GST_IS_IOTECHDAQX (object)); - iotechdaqx = GST_IOTECHDAQX (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -void -gst_iotechdaqx_finalize (GObject * object) -{ - GstIOtechDaqX *iotechdaqx; - - g_return_if_fail (GST_IS_IOTECHDAQX (object)); - iotechdaqx = GST_IOTECHDAQX (object); - - /* clean up object here */ - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - - -static GstCaps * -gst_iotechdaqx_get_caps (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "get_caps"); - - /* return template caps if we don't know the actual camera caps */ - if (!iotechdaqx->caps) { - return - gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD - (iotechdaqx))); - } - - return gst_caps_copy (iotechdaqx->caps); - - return NULL; -} - -static gboolean -gst_iotechdaqx_set_caps (GstBaseSrc * src, GstCaps * caps) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - GstStructure *structure; - gboolean ret; - - GST_DEBUG_OBJECT (iotechdaqx, "set_caps"); - - if (iotechdaqx->caps) { - gst_caps_unref (iotechdaqx->caps); - iotechdaqx->caps = gst_caps_copy (caps); - } - - /* parse caps */ - - if (gst_caps_get_size (caps) < 1) - return FALSE; - - structure = gst_caps_get_structure (caps, 0); - - ret = gst_structure_get (structure, - "width", G_TYPE_INT, &iotechdaqx->width, - "rate", G_TYPE_INT, &iotechdaqx->rate, - "channels", G_TYPE_INT, &iotechdaqx->channels, NULL); - - if (!ret) { - GST_DEBUG ("Failed to retrieve width and height"); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_iotechdaqx_newsegment (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "newsegment"); - - return TRUE; -} - -static gboolean -gst_iotechdaqx_start (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - DaqDeviceListT *devList; - DaqDevicePropsT devProps; - DWORD devCount, deviceIndex; - - GST_DEBUG_OBJECT (iotechdaqx, "start"); - - - // Find out how many devices are installed and allocate memory for device list - daqGetDeviceCount (&devCount); - devList = (DaqDeviceListT *) malloc (sizeof (DaqDeviceListT) * devCount); - - GST_DEBUG ("Found %d devices", devCount); - - // Get the names of all installed devices and the device count - daqGetDeviceList (devList, &devCount); - - deviceIndex = 0; - do { - // Get the device properties for each device - daqGetDeviceProperties (devList[deviceIndex].daqName, &devProps); - - GST_DEBUG ("Device %i: %s", deviceIndex, devList[deviceIndex].daqName); - deviceIndex++; - - // Loop until a WaveBook is found or all the devices have been searched - } while (deviceIndex < devCount); - - // We are done with the device list - free (devList); - - iotechdaqx->handle = daqOpen (devProps.daqName); - GST_DEBUG ("Connected to %s on LPT%d\n", devProps.daqName, - devProps.basePortAddress + 1); - GST_DEBUG ("Protocol: %s \n", GetProtocol (devProps.protocol)); - - //FIXME check for errors! - - return TRUE; -} - -static gboolean -gst_iotechdaqx_stop (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "stop"); - - /* Stop the acquisition */ - daqAdcTransferStop (iotechdaqx->handle); - daqClose (iotechdaqx->handle); - - gst_caps_unref (iotechdaqx->caps); - iotechdaqx->caps = NULL; - - iotechdaqx->opened = FALSE; - - return TRUE; -} - -static void -gst_iotechdaqx_get_times (GstBaseSrc * src, GstBuffer * buffer, - GstClockTime * start, GstClockTime * end) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - //GST_DEBUG_OBJECT (iotechdaqx, "get_times"); -} - -static gboolean -gst_iotechdaqx_get_size (GstBaseSrc * src, guint64 * size) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "get_size"); - - return TRUE; -} - -static gboolean -gst_iotechdaqx_is_seekable (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "is_seekable"); - - return FALSE; -} - -static gboolean -gst_iotechdaqx_query (GstBaseSrc * src, GstQuery * query) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "query"); - - return TRUE; -} - -static gboolean -gst_iotechdaqx_check_get_range (GstBaseSrc * src) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "get_range"); - - return FALSE; -} - -static void -gst_iotechdaqx_fixate (GstBaseSrc * src, GstCaps * caps) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - - GST_DEBUG_OBJECT (iotechdaqx, "fixate"); -} - -static GstFlowReturn -gst_iotechdaqx_create (GstPushSrc * src, GstBuffer ** buf) -{ - GstIOtechDaqX *iotechdaqx = GST_IOTECHDAQX (src); - DWORD retCount; - - //GST_DEBUG ("create (handle=%d)", iotechdaqx->handle); - - if (!iotechdaqx->opened) { - DWORD channels[1] = { 1 }; - DaqAdcGain gains[1] = { DgainX1 }; - DWORD flags[1] = { DafAnalog | DafBipolar }; - - GST_DEBUG ("Setting up acquisition: rate=%d", iotechdaqx->rate); - - daqAdcSetScan (iotechdaqx->handle, channels, gains, flags, 1); - daqAdcSetAcq (iotechdaqx->handle, DaamInfinitePost, 0, 0); - daqSetTriggerEvent (iotechdaqx->handle, DatsSoftware, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, DaqStartEvent); - //daqSetTriggerEvent (iotechdaqx->handle, DatsSoftware, NULL, NULL, NULL, NULL, NULL, NULL, NULL, DaqStopEvent); - daqAdcSetFreq (iotechdaqx->handle, (float) iotechdaqx->rate); - daqAdcTransferSetBuffer (iotechdaqx->handle, NULL, 44100, - DatmCycleOn | DatmDriverBuf); - - daqAdcTransferStart (iotechdaqx->handle); - daqAdcArm (iotechdaqx->handle); - daqAdcSoftTrig (iotechdaqx->handle); //FIXME: put in create() and use has_started flag - - iotechdaqx->opened = TRUE; - } - - gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (GST_BASE_SRC (src)), 0, - 2048 * 2, iotechdaqx->caps, buf); - - daqAdcTransferBufData (iotechdaqx->handle, GST_BUFFER_DATA (*buf), 2048, - DabtmOldest | DabtmWait, &retCount); - - //GST_DEBUG ("Asked for %d samples, got %d", 2048, retCount); - - //memcpy(GST_BUFFER_DATA (*buf), tmp, 16*sizeof(SHORT)); - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_iotechdaqx_debug, "iotechdaqx", 0, - "debug category for iotechdaqx element"); - gst_element_register (plugin, "iotechdaqx", GST_RANK_NONE, - gst_iotechdaqx_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "iotechdaqx", - "IOtechDaqX source", - plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/sys/iotechdaqx/gstiotechdaqx.h b/sys/iotechdaqx/gstiotechdaqx.h deleted file mode 100644 index 3d7ebd1..0000000 --- a/sys/iotechdaqx/gstiotechdaqx.h +++ /dev/null @@ -1,66 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_IOTECHDAQX_H_ -#define _GST_IOTECHDAQX_H_ - -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_IOTECHDAQX (gst_iotechdaqx_get_type()) -#define GST_IOTECHDAQX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IOTECHDAQX,GstIOtechDaqX)) -#define GST_IOTECHDAQX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IOTECHDAQX,GstIOtechDaqXClass)) -#define GST_IS_IOTECHDAQX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IOTECHDAQX)) -#define GST_IS_IOTECHDAQX_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IOTECHDAQX)) - -typedef struct _GstIOtechDaqX GstIOtechDaqX; -typedef struct _GstIOtechDaqXClass GstIOtechDaqXClass; - -struct _GstIOtechDaqX -{ - GstPushSrc base_iotechdaqx; - - GstPad *srcpad; - - GstCaps *caps; - gint rate; - gint channels; - gint endianness; - gint width; - gint depth; - gboolean is_signed; - - gboolean opened; - - DaqHandleT handle; -}; - -struct _GstIOtechDaqXClass -{ - GstPushSrcClass base_iotechdaqx_class; -}; - -GType gst_iotechdaqx_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/kaya/CMakeLists.txt b/sys/kaya/CMakeLists.txt deleted file mode 100644 index 0959136..0000000 --- a/sys/kaya/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -set (SOURCES - gstkayaplugin.c - gstkayasink.c - gstkayasrc.c - ) - -set (HEADERS - gstkayasink.h - gstkayasrc.h) - -include_directories (AFTER - ${GSTREAMER_INCLUDE_DIR}/.. - ${KAYA_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/common - ) - -set (libname gstkaya) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${KAYA_LIBRARIES} - ) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/kaya/gstkayaplugin.c b/sys/kaya/gstkayaplugin.c deleted file mode 100644 index af31106..0000000 --- a/sys/kaya/gstkayaplugin.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include "gstkayasink.h" -#include "gstkayasrc.h" - -GST_DEBUG_CATEGORY_STATIC (kayaplugin_debug); -#define GST_CAT_DEFAULT kayaplugin_debug - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (kayaplugin_debug, "kaya", 0, - "debug category for kaya plugin"); - - if (!gst_element_register (plugin, "kayasink", GST_RANK_NONE, - gst_kayasink_get_type ())) - return FALSE; - - if (!gst_element_register (plugin, "kayasrc", GST_RANK_NONE, - gst_kayasrc_get_type ())) - return FALSE; - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - kaya, - "Kaya plugin", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN); diff --git a/sys/kaya/gstkayasink.c b/sys/kaya/gstkayasink.c deleted file mode 100644 index d99b61f..0000000 --- a/sys/kaya/gstkayasink.c +++ /dev/null @@ -1,784 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstkayasink - * - * The kayasink element is a sink for Kaya Chameleon CoaXPress devices. - * - * Note that kayasink requires a steady framerate to match the framerate in - * the caps, so you might need to add a videorate element before the sink. - * - * - * Example launch line - * |[ - * gst-launch -v videotestsrc ! videoconvert ! videorate ! kayasink - * ]| - * Outputs test pattern using Kaya Chameleon. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include - -#include "gstkayasink.h" - - -/* GObject prototypes */ -static void gst_kayasink_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_kayasink_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_kayasink_dispose (GObject * object); - -/* GstBaseSink prototypes */ -static gboolean gst_kayasink_start (GstBaseSink * basesink); -static gboolean gst_kayasink_stop (GstBaseSink * basesink); -static GstCaps *gst_kayasink_get_caps (GstBaseSink * basesink, - GstCaps * filter_caps); -static gboolean gst_kayasink_set_caps (GstBaseSink * basesink, GstCaps * caps); -static GstFlowReturn gst_kayasink_render (GstBaseSink * basesink, - GstBuffer * buffer); -static gboolean gst_kayasink_unlock (GstBaseSink * basesink); -static gboolean gst_kayasink_unlock_stop (GstBaseSink * basesink); - -static void gst_kayasink_camera_callback (GstKayaSink * sink, - STREAM_HANDLE streamHandle); -static void gst_kayasink_device_event_callback (GstKayaSink * sink, - KYDEVICE_EVENT * pEvent); -static gboolean gst_kayasink_set_kaya_caps (GstKayaSink * sink, GstCaps * caps); - -enum -{ - PROP_0, - PROP_INTERFACE_INDEX, - PROP_DEVICE_INDEX, - PROP_NUM_RENDER_BUFFERS, - PROP_TIMEOUT, - PROP_PROJECT_FILE, - PROP_XML_FILE, - PROP_WAIT_FOR_RECEIVER, - PROP_WAIT_TIMEOUT -}; - -#define DEFAULT_PROP_INTERFACE_INDEX 0 -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_NUM_RENDER_BUFFERS 3 -#define DEFAULT_PROP_TIMEOUT 1000 -#define DEFAULT_PROP_PROJECT_FILE NULL -#define DEFAULT_PROP_XML_FILE NULL -#define DEFAULT_PROP_WAIT_FOR_RECEIVER TRUE -#define DEFAULT_PROP_WAIT_TIMEOUT 10000 - -/* pad templates */ - -static GstStaticPadTemplate gst_kayasink_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, RGB, RGBA, IYU1, IYU2, UYVY }")) - ); - -/* class initialization */ - -/* setup debug */ -GST_DEBUG_CATEGORY_STATIC (kayasink_debug); -#define GST_CAT_DEFAULT kayasink_debug - -G_DEFINE_TYPE (GstKayaSink, gst_kayasink, GST_TYPE_BASE_SINK); - -static void -gst_kayasink_class_init (GstKayaSinkClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "kayasink", 0, - "Kaya Chameleon CoaXPress simulator sink"); - - gobject_class->set_property = gst_kayasink_set_property; - gobject_class->get_property = gst_kayasink_get_property; - gobject_class->dispose = gst_kayasink_dispose; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_kayasink_sink_template)); - - gst_element_class_set_details_simple (gstelement_class, - "Kaya Chameleon Sink", "Sink/Video", - "Kaya Chameleon Sink to output CoaXPress video", - "Joshua M. Doe "); - - gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_kayasink_start); - gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_kayasink_stop); - gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_kayasink_set_caps); - gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_kayasink_render); - gstbasesink_class->unlock = GST_DEBUG_FUNCPTR (gst_kayasink_unlock); - gstbasesink_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_kayasink_unlock_stop); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_INTERFACE_INDEX, - g_param_spec_int ("interface-index", "Interface index", - "Interface index number (zero-based)", - 0, KAYA_SINK_MAX_FG_HANDLES, DEFAULT_PROP_INTERFACE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_int ("device-index", "Device index", - "Device index number, zero-based", - 0, G_MAXINT, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_RENDER_BUFFERS, - g_param_spec_int ("num-render-buffers", "Number of render buffers", - "Number of render buffers", 1, G_MAXINT, - DEFAULT_PROP_NUM_RENDER_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMEOUT, - g_param_spec_int ("timeout", "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, PROP_PROJECT_FILE, - g_param_spec_string ("project-file", "Project file", - "Filepath of a project file to configure frame grabber", - DEFAULT_PROP_PROJECT_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_XML_FILE, - g_param_spec_string ("xml-file", "XML file", - "Filepath of a XML file to use with camera, or NULL to use camera's native XML", - DEFAULT_PROP_XML_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_WAIT_FOR_RECEIVER, g_param_spec_boolean ("wait-for-receiver", - "Wait for receiver", - "If true, wait until receiver starts stream, else drop buffers.", - DEFAULT_PROP_WAIT_FOR_RECEIVER, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, PROP_WAIT_TIMEOUT, - g_param_spec_int ("wait-timeout", "Receiver wait timeout (ms)", - "Time to wait for receiver to start stream (ms)", 0, G_MAXINT, - DEFAULT_PROP_WAIT_TIMEOUT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -} - -static void -gst_kayasink_cleanup (GstKayaSink * sink) -{ - GST_LOG_OBJECT (sink, "cleanup"); - - sink->stop_requested = FALSE; - sink->acquisition_started = FALSE; - - if (sink->cam_handle != INVALID_CAMHANDLE) { - KYFG_CameraCallbackUnregister (sink->cam_handle, - gst_kayasink_camera_callback); - KYFG_CameraStop (sink->cam_handle); - KYFG_CameraClose (sink->cam_handle); - sink->stream_handle = INVALID_STREAMHANDLE; - sink->cam_handle = INVALID_CAMHANDLE; - } - - if (sink->fg_data) { - g_mutex_lock (&sink->fg_data->fg_mutex); - GST_DEBUG_OBJECT (sink, "Framegrabber open with refcount=%d", - sink->fg_data->ref_count); - sink->fg_data->ref_count--; - if (sink->fg_data->ref_count == 0) { - GST_DEBUG_OBJECT (sink, "Framegrabber ref dropped to 0, closing"); - KYFG_Close (sink->fg_data->fg_handle); - sink->fg_data->fg_handle = INVALID_FGHANDLE; - } - g_mutex_unlock (&sink->fg_data->fg_mutex); - sink->fg_data = NULL; - } -} - -static void -gst_kayasink_init (GstKayaSink * sink) -{ - /* properties */ - sink->interface_index = DEFAULT_PROP_INTERFACE_INDEX; - sink->num_render_buffers = DEFAULT_PROP_NUM_RENDER_BUFFERS; - sink->timeout = DEFAULT_PROP_TIMEOUT; - sink->project_file = DEFAULT_PROP_PROJECT_FILE; - sink->xml_file = DEFAULT_PROP_PROJECT_FILE; - sink->num_render_buffers = 3; - sink->wait_for_receiver = TRUE; - sink->wait_timeout = 10000; - - sink->queue = g_async_queue_new (); - - sink->receiver_connected = FALSE; - - sink->acquisition_started = FALSE; - sink->stop_requested = FALSE; - - g_mutex_init (&sink->mutex); - g_cond_init (&sink->cond); -} - -void -gst_kayasink_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstKayaSink *sink; - - g_return_if_fail (GST_IS_KAYASINK (object)); - sink = GST_KAYASINK (object); - - switch (property_id) { - case PROP_INTERFACE_INDEX: - sink->interface_index = g_value_get_int (value); - break; - case PROP_DEVICE_INDEX: - sink->device_index = g_value_get_int (value); - break; - case PROP_NUM_RENDER_BUFFERS: - sink->num_render_buffers = g_value_get_int (value); - break; - case PROP_TIMEOUT: - sink->timeout = g_value_get_int (value); - break; - case PROP_PROJECT_FILE: - g_free (sink->project_file); - sink->project_file = g_value_dup_string (value); - break; - case PROP_XML_FILE: - g_free (sink->xml_file); - sink->xml_file = g_value_dup_string (value); - break; - case PROP_WAIT_FOR_RECEIVER: - sink->wait_for_receiver = g_value_get_boolean (value); - break; - case PROP_WAIT_TIMEOUT: - sink->wait_timeout = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_kayasink_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstKayaSink *sink; - - g_return_if_fail (GST_IS_KAYASINK (object)); - sink = GST_KAYASINK (object); - - switch (property_id) { - case PROP_INTERFACE_INDEX: - g_value_set_int (value, sink->interface_index); - break; - case PROP_DEVICE_INDEX: - g_value_set_int (value, sink->device_index); - break; - case PROP_NUM_RENDER_BUFFERS: - g_value_set_int (value, sink->num_render_buffers); - break; - case PROP_TIMEOUT: - g_value_set_int (value, sink->timeout); - break; - case PROP_PROJECT_FILE: - g_value_set_string (value, sink->project_file); - break; - case PROP_XML_FILE: - g_value_set_string (value, sink->xml_file); - break; - case PROP_WAIT_FOR_RECEIVER: - g_value_set_boolean (value, sink->wait_for_receiver); - break; - case PROP_WAIT_TIMEOUT: - g_value_set_int (value, sink->wait_timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_kayasink_dispose (GObject * object) -{ - GstKayaSink *sink; - - g_return_if_fail (GST_IS_KAYASINK (object)); - sink = GST_KAYASINK (object); - - /* clean up as possible. may be called multiple times */ - - g_mutex_clear (&sink->mutex); - g_cond_clear (&sink->cond); - - g_free (sink->project_file); - g_free (sink->xml_file); - - G_OBJECT_CLASS (gst_kayasink_parent_class)->dispose (object); -} - -gboolean -gst_kayasink_start (GstBaseSink * basesink) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - GstKayaSinkClass *sinkclass = GST_KAYA_SINK_GET_CLASS (sink); - int ret = 0; - int i, num_ifaces = 0; - KY_DEVICE_INFO devinfo; - GstKayaSinkFramegrabber *fg_data; - - GST_DEBUG_OBJECT (sink, "Starting"); - - /* find and list all KAYA interfaces */ - num_ifaces = KYFG_Scan (NULL, 0); - if (num_ifaces == 0) { - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, ("No KAYA interfaces found"), - (NULL)); - goto error; - } - for (i = 0; i < num_ifaces; ++i) { - ret = KY_DeviceInfo (i, &devinfo); - GST_DEBUG_OBJECT (sink, - "Found KAYA interface '%s', index=%d, bus=%d, slot=%d, fcn=%d, PID=%d, isVirtual=%s", - devinfo.szDeviceDisplayName, i, devinfo.nBus, devinfo.nSlot, - devinfo.nFunction, devinfo.DevicePID, - (devinfo.isVirtual ? "Yes" : "No")); - } - - g_assert (sink->interface_index >= 0 - && sink->interface_index < KAYA_SINK_MAX_FG_HANDLES); - if (sink->interface_index >= num_ifaces) { - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Interface index provided (%d) out of bounds [0,%d]", - sink->interface_index, num_ifaces - 1), (NULL)); - goto error; - } - - /* lock mutex until we have a camera opened */ - fg_data = &(sinkclass->fg_data[sink->interface_index]); - g_mutex_lock (&fg_data->fg_mutex); - - /* open framegrabber if it isn't already opened */ - if (fg_data->ref_count > 0) { - GST_DEBUG_OBJECT (sink, - "Framegrabber interface already opened in this process, reusing"); - if (sink->project_file && strlen (sink->project_file) > 0) { - GST_ELEMENT_WARNING (sink, RESOURCE, SETTINGS, - ("Project file specified, but framegrabber is already opened, so it won't be used."), - (NULL)); - } - } else { - g_assert (fg_data->ref_count == 0); - - /* project files are optional */ - if (sink->project_file && strlen (sink->project_file) > 0) { - if (!g_file_test (sink->project_file, G_FILE_TEST_EXISTS)) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, - ("Project file specified does not exist: %s", sink->project_file), - (NULL)); - goto error; - } - - GST_DEBUG_OBJECT (sink, - "About to open interface at index %d with project file '%s'", - sink->interface_index, sink->project_file); - fg_data->fg_handle = - KYFG_OpenEx (sink->interface_index, sink->project_file); - } else { - GST_DEBUG_OBJECT (sink, "About to open interface at index %d", - sink->interface_index); - fg_data->fg_handle = KYFG_Open (sink->interface_index); - } - - if (fg_data->fg_handle == INVALID_FGHANDLE) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to open interface at index %d", sink->interface_index), - (NULL)); - goto error; - } - - if (fg_data->num_cams == 0) { - GST_DEBUG_OBJECT (sink, "Scanning for cameras"); - /* find and list all cameras */ - fg_data->num_cams = KAYA_SINK_MAX_CAM_HANDLES; - ret = - KYFG_UpdateCameraList (fg_data->fg_handle, fg_data->cam_handles, - &fg_data->num_cams); - GST_DEBUG_OBJECT (sink, "Found %d cameras connected", fg_data->num_cams); - if (fg_data->num_cams == 0) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to detect any cameras on interface"), (NULL)); - goto error; - } - } - for (i = 0; i < fg_data->num_cams; ++i) { - KYFGCAMERA_INFO caminfo; - ret = KYFG_CameraInfo (fg_data->cam_handles[i], &caminfo); - GST_DEBUG_OBJECT (sink, - "Found camera '%s', index=%d, %s, %s %s, %s, ver=%s", - caminfo.deviceUserID, i, caminfo.deviceID, caminfo.deviceVendorName, - caminfo.deviceModelName, caminfo.deviceManufacturerInfo, - caminfo.deviceVersion); - } - } - - if (sink->device_index >= fg_data->num_cams) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Camera device index provided out of bounds"), (NULL)); - goto error; - } - GST_DEBUG_OBJECT (sink, "About to open camera at index %d", - sink->device_index); - if (sink->xml_file && strlen (sink->xml_file) > 0) { - if (!g_file_test (sink->xml_file, G_FILE_TEST_EXISTS)) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, - ("XML file specified does not exist: %s", sink->xml_file), (NULL)); - goto error; - } - } - ret = - KYFG_CameraOpen2 (fg_data->cam_handles[sink->device_index], - sink->xml_file); - if (ret != FGSTATUS_OK) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to open camera at index %d", sink->device_index), (NULL)); - goto error; - } - sink->cam_handle = fg_data->cam_handles[sink->device_index]; - - /* increase refcount since we now have a camera open */ - sink->fg_data = fg_data; - sink->fg_data->ref_count++; - g_mutex_unlock (&sink->fg_data->fg_mutex); - - ret = - KYFG_CameraCallbackRegister (sink->cam_handle, - gst_kayasink_camera_callback, sink); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to register stream callback function"), (NULL)); - goto error; - } - - ret = - KYDeviceEventCallBackRegister (sink->fg_data->fg_handle, - gst_kayasink_device_event_callback, sink); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to register device callback function"), (NULL)); - goto error; - } - - sink->acquisition_started = FALSE; - sink->stop_requested = FALSE; - - return TRUE; - -error: - return FALSE; -} - -gboolean -gst_kayasink_stop (GstBaseSink * basesink) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - - gst_kayasink_cleanup (sink); - - return TRUE; -} - -gboolean -gst_kayasink_set_caps (GstBaseSink * basesink, GstCaps * caps) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - - GST_DEBUG_OBJECT (sink, "Caps being set"); - - if (!gst_kayasink_set_kaya_caps (sink, caps)) - return FALSE; - - return TRUE; -} - -gboolean -gst_kayasink_set_kaya_caps (GstKayaSink * sink, GstCaps * caps) -{ - FGSTATUS ret; - const char *format; - float fps; - - g_assert (caps); - g_assert (sink->cam_handle != INVALID_CAMHANDLE); - - gst_video_info_from_caps (&sink->vinfo, caps); - fps = (float) sink->vinfo.fps_n / sink->vinfo.fps_d; - - GST_DEBUG_OBJECT (sink, "Setting video output to %dx%d@%.2fHz", - sink->vinfo.width, sink->vinfo.height, fps); - - // set from caps: - ret = KYFG_SetCameraValueInt (sink->cam_handle, "Width", sink->vinfo.width); - if (ret != FGSTATUS_OK) - goto error; - ret = KYFG_SetCameraValueInt (sink->cam_handle, "Height", sink->vinfo.height); - if (ret != FGSTATUS_OK) - goto error; - ret = - KYFG_SetCameraValueFloat (sink->cam_handle, "AcquisitionFrameRate", fps); - if (ret != FGSTATUS_OK) - goto error; - - switch (GST_VIDEO_INFO_FORMAT (&sink->vinfo)) { - case GST_VIDEO_FORMAT_GRAY8: - format = "Mono8"; - break; - case GST_VIDEO_FORMAT_GRAY16_LE: - format = "Mono16"; - break; - case GST_VIDEO_FORMAT_RGB: - format = "RGB8"; - break; - case GST_VIDEO_FORMAT_RGBA: - format = "RGBA8"; - break; - case GST_VIDEO_FORMAT_IYU1: - format = "YUV411_8_UYYVYY"; - break; - case GST_VIDEO_FORMAT_IYU2: - format = "YUV8_UYV"; - break; - case GST_VIDEO_FORMAT_UYVY: - format = "YUV422_8"; - break; - default: - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Unsupported pixel format: %s.", - gst_video_format_to_string (GST_VIDEO_INFO_FORMAT - (&sink->vinfo))), (NULL)); - return FALSE; - } - - ret = - KYFG_SetCameraValueEnum_ByValueName (sink->cam_handle, "PixelFormat", - format); - if (ret != FGSTATUS_OK) - goto error; - - return TRUE; - -error: - GST_ELEMENT_ERROR (sink, LIBRARY, FAILED, - ("Failed to set width, height, FPS, or pixel format."), (NULL)); - return FALSE; -} - -GstFlowReturn -gst_kayasink_render (GstBaseSink * basesink, GstBuffer * buffer) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - GST_LOG_OBJECT (sink, "Rendering buffer"); - - if (!sink->receiver_connected) { - if (sink->wait_for_receiver) { - gint64 end_time; - /* wait for receiver/framegrabber to start */ - end_time = - g_get_monotonic_time () + - sink->wait_timeout * G_TIME_SPAN_MILLISECOND; - g_mutex_lock (&sink->mutex); - while (!sink->receiver_connected && !sink->stop_requested) { - GST_DEBUG_OBJECT (sink, - "Neither stream started nor stop requested, waiting %dms", - sink->wait_timeout); - if (!g_cond_wait_until (&sink->cond, &sink->mutex, end_time)) { - g_mutex_unlock (&sink->mutex); - GST_ELEMENT_WARNING (sink, RESOURCE, FAILED, - ("Timed out waiting for receiver to start stream."), (NULL)); - return GST_FLOW_ERROR; - } - } - g_mutex_unlock (&sink->mutex); - } else { - GST_WARNING_OBJECT (sink, "No receiver connected, dropping buffer"); - /* TODO: use flag to either queue or drop frames */ - return GST_FLOW_OK; - } - } - - if (sink->stop_requested) { - GST_DEBUG_OBJECT (sink, "stop requested, flushing"); - return GST_FLOW_FLUSHING; - } - ///* wait for client to send AcquisitionStart command */ - //g_mutex_lock (&sink->mutex); - //end_time = g_get_monotonic_time () + sink->timeout * G_TIME_SPAN_MILLISECOND; - //while (!sink->acquisition_started && !sink->stop_requested) { - // GST_DEBUG_OBJECT (sink, "acq not started and stop not requested, waiting"); - // if (!g_cond_wait_until (&sink->cond, &sink->mutex, end_time)) { - // g_mutex_unlock (&sink->mutex); - // GST_ELEMENT_WARNING (sink, RESOURCE, FAILED, - // ("Timed out waiting for client to send AcquisitionStart, dropping frame"), - // (NULL)); - // return GST_FLOW_OK; - // } - //} - //if (sink->stop_requested) { - // GST_DEBUG_OBJECT (sink, "stop requested, flushing"); - // g_mutex_unlock (&sink->mutex); - // return GST_FLOW_FLUSHING; - //} - //g_mutex_unlock (&sink->mutex); - - g_async_queue_push (sink->queue, gst_buffer_ref (buffer)); - - return GST_FLOW_OK; -} - -gboolean -gst_kayasink_unlock (GstBaseSink * basesink) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - - g_mutex_lock (&sink->mutex); - sink->stop_requested = TRUE; - g_cond_signal (&sink->cond); - g_mutex_unlock (&sink->mutex); - - return TRUE; -} - -gboolean -gst_kayasink_unlock_stop (GstBaseSink * basesink) -{ - GstKayaSink *sink = GST_KAYASINK (basesink); - - sink->stop_requested = FALSE; - - return TRUE; -} - -void -gst_kayasink_device_event_callback (GstKayaSink * sink, KYDEVICE_EVENT * pEvent) -{ - FGSTATUS ret; - - switch (pEvent->eventId) { - case KYDEVICE_EVENT_CAMERA_START_REQUEST: - { - CAMHANDLE eventCameraHandle = - ((KYDEVICE_EVENT_CAMERA_START *) pEvent)->camHandle; - if (eventCameraHandle == sink->cam_handle) { - GST_DEBUG_OBJECT (sink, "Detected remote request to start generation"); - //StartGeneration(); - ret = - KYFG_StreamCreateAndAlloc (sink->cam_handle, &sink->stream_handle, - sink->num_render_buffers, 0); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_WARNING (sink, RESOURCE, FAILED, - ("Failed to create stream"), (NULL)); - return; - } - - GST_DEBUG_OBJECT (sink, "Starting camera output"); - ret = KYFG_CameraStart (sink->cam_handle, sink->stream_handle, 0); - - g_mutex_lock (&sink->mutex); - sink->receiver_connected = TRUE; - g_cond_signal (&sink->cond); - g_mutex_unlock (&sink->mutex); - } else { - GST_WARNING_OBJECT (sink, - "Got start request for invalid camera handle"); - } - } - break; - } -} - -void -gst_kayasink_camera_callback (GstKayaSink * sink, STREAM_HANDLE streamHandle) -{ - uint32_t currentIndex; // Indicates the Nth frame that was currently send. - void *ptr; // Pointer to current frame the data - int64_t size; // Size of each frame in bytes - GstBuffer *buf; - GstMapInfo minfo; - - if (!streamHandle) { - // callback with streamHandle == 0 indicates that stream generation has stopped - // any data retrieved using this handle (frame index, buffer pointer, etc.) won't be valid - GST_DEBUG_OBJECT (sink, "Stream generation stopped"); - - g_mutex_lock (&sink->mutex); - sink->receiver_connected = FALSE; - g_cond_signal (&sink->cond); - g_mutex_unlock (&sink->mutex); - - return; - } - - currentIndex = KYFG_StreamGetFrameIndex (streamHandle); - - ptr = KYFG_StreamGetPtr (streamHandle, currentIndex); - size = KYFG_StreamGetSize (streamHandle); - - GST_DEBUG_OBJECT (sink, "Copying new frame to index %d", currentIndex); - - //g_mutex_lock(&sink->mutex); - - //while (g_async_queue_length(sink->queue) == 0 && !sink->flushing) { - // g_cond_wait(&sink->cond, &sink->mutex); - //} - //if (sink->flushing) { - // return; - //} - buf = - GST_BUFFER (g_async_queue_timeout_pop (sink->queue, - sink->timeout * 1000)); - if (!buf) { - GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ, - ("Failed to get buffer in %d ms", sink->timeout), (NULL)); - return; - } - - gst_buffer_map (buf, &minfo, GST_MAP_READ); - /* TODO: fix stride? */ - g_assert (minfo.size <= (gsize) size); - memcpy (ptr, minfo.data, minfo.size); - gst_buffer_unmap (buf, &minfo); - gst_buffer_unref (buf); -} diff --git a/sys/kaya/gstkayasink.h b/sys/kaya/gstkayasink.h deleted file mode 100644 index 538d332..0000000 --- a/sys/kaya/gstkayasink.h +++ /dev/null @@ -1,96 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_KAYA_SINK_H_ -#define _GST_KAYA_SINK_H_ - -#include -#include - -#include - -#define KAYA_SINK_MAX_FG_HANDLES 16 -#define KAYA_SINK_MAX_CAM_HANDLES 4 - -G_BEGIN_DECLS - -#define GST_TYPE_KAYASINK (gst_kayasink_get_type()) -#define GST_KAYASINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_KAYASINK,GstKayaSink)) -#define GST_KAYASINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_KAYASINK,GstKayaSinkClass)) -#define GST_IS_KAYASINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_KAYASINK)) -#define GST_IS_KAYASINK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_KAYASINK)) -#define GST_KAYA_SINK_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_KAYA_SINK, GstKayaSinkClass)) - -typedef struct _GstKayaSink GstKayaSink; -typedef struct _GstKayaSinkClass GstKayaSinkClass; - -typedef struct _GstKayaSinkFramegrabber GstKayaSinkFramegrabber; - -struct _GstKayaSink -{ - GstBaseSink base; - - GstKayaSinkFramegrabber* fg_data; - CAMHANDLE cam_handle; - STREAM_HANDLE stream_handle; - STREAM_BUFFER_HANDLE* buffer_handles; - - /* properties */ - guint interface_index; - guint device_index; - guint num_render_buffers; - gint timeout; - gchar* project_file; - gchar* xml_file; - gboolean wait_for_receiver; - gint wait_timeout; - - gboolean receiver_connected; - GstVideoInfo vinfo; - - GAsyncQueue* queue; - - GMutex mutex; - GCond cond; - gboolean acquisition_started; - gboolean stop_requested; -}; - -struct _GstKayaSinkFramegrabber -{ - FGHANDLE fg_handle; - guint32 ref_count; - CAMHANDLE cam_handles[KAYA_SINK_MAX_CAM_HANDLES]; - int num_cams; - GMutex fg_mutex; -}; - -struct _GstKayaSinkClass -{ - GstBaseSinkClass base_class; - - GstKayaSinkFramegrabber fg_data[KAYA_SINK_MAX_FG_HANDLES]; -}; - -GType gst_kayasink_get_type (void); - -G_END_DECLS - -#endif /* _GST_KAYA_SINK_H_ */ \ No newline at end of file diff --git a/sys/kaya/gstkayasrc.c b/sys/kaya/gstkayasrc.c deleted file mode 100644 index f7f044a..0000000 --- a/sys/kaya/gstkayasrc.c +++ /dev/null @@ -1,947 +0,0 @@ -/* GStreamer - * Copyright (c) 2018 outside US, United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstkayasrc - * - * The kayasrc element is a source for KAYA framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v kayasrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default KAYA framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include -#include -#include - -#include "get_unix_ns.h" -#include "gstkayasrc.h" -#include "genicampixelformat.h" - -#ifdef HAVE_ORC -#include -#else -#define orc_memcpy memcpy -#endif - -GST_DEBUG_CATEGORY_STATIC (gst_kayasrc_debug); -#define GST_CAT_DEFAULT gst_kayasrc_debug - -/* prototypes */ -static void gst_kayasrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_kayasrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_kayasrc_dispose (GObject * object); -static void gst_kayasrc_finalize (GObject * object); - -static gboolean gst_kayasrc_start (GstBaseSrc * src); -static gboolean gst_kayasrc_stop (GstBaseSrc * src); -static GstCaps *gst_kayasrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_kayasrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_kayasrc_unlock (GstBaseSrc * src); -static gboolean gst_kayasrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_kayasrc_create (GstPushSrc * src, GstBuffer ** buf); - -static void gst_kayasrc_stream_buffer_callback (STREAM_BUFFER_HANDLE - buffer_handle, void *context); -static void gst_kayasrc_stream_callback (void *context, - STREAM_HANDLE stream_handle); - - -enum -{ - PROP_0, - PROP_INTERFACE_INDEX, - PROP_DEVICE_INDEX, - PROP_NUM_CAPTURE_BUFFERS, - PROP_TIMEOUT, - PROP_PROJECT_FILE, - PROP_XML_FILE, - PROP_EXPOSURE_TIME, - PROP_EXECUTE_COMMAND -}; - -#define DEFAULT_PROP_INTERFACE_INDEX 0 -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_TIMEOUT 1000 -#define DEFAULT_PROP_PROJECT_FILE NULL -#define DEFAULT_PROP_XML_FILE NULL -#define DEFAULT_PROP_EXPOSURE_TIME 0 -#define DEFAULT_PROP_EXECUTE_COMMAND NULL - -/* pad templates */ - -static GstStaticPadTemplate gst_kayasrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGRA, UYVY }") ";" - GST_GENICAM_PIXEL_FORMAT_MAKE_BAYER8 ("{ bggr, grbg, rggb, gbrg }") ";" - GST_GENICAM_PIXEL_FORMAT_MAKE_BAYER16 - ("{ bggr16, grbg16, rggb16, gbrg16 }", "1234") - ) - ); - - -#if GST_CHECK_VERSION(1,14,0) -static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix"); -#endif - - -/* class initialization */ - -G_DEFINE_TYPE (GstKayaSrc, gst_kayasrc, GST_TYPE_PUSH_SRC); - -static void -gst_kayasrc_class_init (GstKayaSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - int i; - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "kayasrc", 0, - "Kaya CoaXPress video source"); - - gobject_class->set_property = gst_kayasrc_set_property; - gobject_class->get_property = gst_kayasrc_get_property; - gobject_class->dispose = gst_kayasrc_dispose; - gobject_class->finalize = gst_kayasrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_kayasrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "KAYA Video Source", "Source/Video", - "KAYA framegrabber video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_kayasrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_kayasrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_kayasrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_kayasrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_kayasrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_kayasrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_kayasrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_INTERFACE_INDEX, - g_param_spec_uint ("interface-index", "Interface index", - "Interface index number (zero-based)", - 0, KAYA_SRC_MAX_FG_HANDLES, DEFAULT_PROP_INTERFACE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_uint ("device-index", "Device index", - "Device index number, zero-based", - 0, G_MAXUINT, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (gobject_class, PROP_PROJECT_FILE, - g_param_spec_string ("project-file", "Project file", - "Filepath of a project file to configure frame grabber", - DEFAULT_PROP_PROJECT_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_XML_FILE, - g_param_spec_string ("xml-file", "XML file", - "Filepath of a XML file to use with camera, or NULL to use camera's native XML", - DEFAULT_PROP_XML_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_EXPOSURE_TIME, g_param_spec_float ("exposure-time", - "Exposure time (us)", - "Sets the exposure time in microseconds", - 0, G_MAXFLOAT, DEFAULT_PROP_EXPOSURE_TIME, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (gobject_class, PROP_EXECUTE_COMMAND, - g_param_spec_string ("execute-command", "Command to execute", - "Name of a command to execute after opening the camera (e.g., UserSetLoadReg)", - DEFAULT_PROP_EXECUTE_COMMAND, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - - for (i = 0; i < KAYA_SRC_MAX_FG_HANDLES; i++) { - klass->fg_data[i].fg_handle = INVALID_FGHANDLE; - klass->fg_data[i].ref_count = 0; - memset (klass->fg_data[i].cam_handles, 0, sizeof (CAMHANDLE) * 4); - klass->fg_data[i].num_cams = 0; - g_mutex_init (&klass->fg_data[i].fg_mutex); - } -} - -static void -gst_kayasrc_cleanup (GstKayaSrc * src) -{ - GST_LOG_OBJECT (src, "cleanup"); - - src->frame_size = 0; - src->frame_count = 0; - src->dropped_frames = 0; - src->stop_requested = FALSE; - src->acquisition_started = FALSE; - src->kaya_base = GST_CLOCK_TIME_NONE; - src->unix_base = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->stream_handle != INVALID_STREAMHANDLE) { - KYFG_StreamBufferCallbackUnregister (src->stream_handle, - gst_kayasrc_stream_buffer_callback); - // FIXME: we seem to get exceptions later on if we call this - //KYFG_StreamDelete (src->stream_handle); - src->stream_handle = INVALID_STREAMHANDLE; - } - - if (src->cam_handle != INVALID_CAMHANDLE) { - KYFG_CameraCallbackUnregister (src->cam_handle, - gst_kayasrc_stream_callback); - KYFG_CameraStop (src->cam_handle); - KYFG_CameraClose (src->cam_handle); - src->cam_handle = INVALID_CAMHANDLE; - } - - if (src->fg_data) { - g_mutex_lock (&src->fg_data->fg_mutex); - GST_DEBUG_OBJECT (src, "Framegrabber open with refcount=%d", - src->fg_data->ref_count); - src->fg_data->ref_count--; - if (src->fg_data->ref_count == 0) { - GST_DEBUG_OBJECT (src, "Framegrabber ref dropped to 0, closing"); - KYFG_Close (src->fg_data->fg_handle); - src->fg_data->fg_handle = INVALID_FGHANDLE; - } - g_mutex_unlock (&src->fg_data->fg_mutex); - src->fg_data = NULL; - } -} - -static void -gst_kayasrc_init (GstKayaSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->interface_index = DEFAULT_PROP_INTERFACE_INDEX; - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->timeout = DEFAULT_PROP_TIMEOUT; - src->project_file = DEFAULT_PROP_PROJECT_FILE; - src->xml_file = DEFAULT_PROP_PROJECT_FILE; - src->exposure_time = DEFAULT_PROP_EXPOSURE_TIME; - src->execute_command = DEFAULT_PROP_EXECUTE_COMMAND; - - src->queue = g_async_queue_new (); - src->caps = NULL; - - src->fg_data = NULL; - src->cam_handle = INVALID_CAMHANDLE; - src->stream_handle = INVALID_STREAMHANDLE; - src->buffer_handles = NULL; - - src->kaya_base = GST_CLOCK_TIME_NONE; -} - -static void -gst_kayasrc_get_exposure_time (GstKayaSrc * src) -{ - if (src->cam_handle != INVALID_CAMHANDLE) { - src->exposure_time = - KYFG_GetCameraValueFloat (src->cam_handle, "ExposureTime"); - } -} - -static void -gst_kayasrc_set_exposure_time (GstKayaSrc * src) -{ - if (src->cam_handle != INVALID_CAMHANDLE && src->exposure_time > 0) { - FGSTATUS ret = KYFG_SetCameraValueFloat (src->cam_handle, "ExposureTime", - src->exposure_time); - if (ret != FGSTATUS_OK) { - GST_WARNING_OBJECT (src, "Exposure time %.3f invalid", - src->exposure_time); - } - } -} - -void -gst_kayasrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstKayaSrc *src; - - src = GST_KAYA_SRC (object); - - switch (property_id) { - case PROP_INTERFACE_INDEX: - src->interface_index = g_value_get_uint (value); - break; - case PROP_DEVICE_INDEX: - src->device_index = g_value_get_uint (value); - break; - case PROP_NUM_CAPTURE_BUFFERS: - src->num_capture_buffers = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - case PROP_PROJECT_FILE: - g_free (src->project_file); - src->project_file = g_value_dup_string (value); - break; - case PROP_XML_FILE: - g_free (src->xml_file); - src->xml_file = g_value_dup_string (value); - break; - case PROP_EXPOSURE_TIME: - src->exposure_time = g_value_get_float (value); - gst_kayasrc_set_exposure_time (src); - break; - case PROP_EXECUTE_COMMAND: - g_free (src->execute_command); - src->execute_command = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_kayasrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstKayaSrc *src; - - g_return_if_fail (GST_IS_KAYA_SRC (object)); - src = GST_KAYA_SRC (object); - - switch (property_id) { - case PROP_INTERFACE_INDEX: - g_value_set_uint (value, src->interface_index); - break; - case PROP_DEVICE_INDEX: - g_value_set_uint (value, src->device_index); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - case PROP_PROJECT_FILE: - g_value_set_string (value, src->project_file); - break; - case PROP_XML_FILE: - g_value_set_string (value, src->xml_file); - break; - case PROP_EXPOSURE_TIME: - gst_kayasrc_get_exposure_time (src); - g_value_set_float (value, src->exposure_time); - break; - case PROP_EXECUTE_COMMAND: - g_value_set_string (value, src->execute_command); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_kayasrc_dispose (GObject * object) -{ - GstKayaSrc *src; - - g_return_if_fail (GST_IS_KAYA_SRC (object)); - src = GST_KAYA_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_kayasrc_parent_class)->dispose (object); -} - -void -gst_kayasrc_finalize (GObject * object) -{ - GstKayaSrc *src; - - g_return_if_fail (GST_IS_KAYA_SRC (object)); - src = GST_KAYA_SRC (object); - - /* clean up object here */ - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - G_OBJECT_CLASS (gst_kayasrc_parent_class)->finalize (object); -} - -static gboolean -gst_kayasrc_start (GstBaseSrc * bsrc) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - GstKayaSrcClass *srcclass = GST_KAYA_SRC_GET_CLASS (src); - FGSTATUS ret; - uint32_t i, num_ifaces; - guint32 width, height; - gchar camera_pixel_format[256], grabber_pixel_format[256]; - guint32 str_size; - KY_DEVICE_INFO devinfo; - size_t frame_alignment; - GstKayaSrcFramegrabber *fg_data; - - GST_DEBUG_OBJECT (src, "start"); - - gst_kayasrc_cleanup (src); - - /* find and list all KAYA interfaces */ - num_ifaces = KYFG_Scan (NULL, 0); - if (num_ifaces == 0) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, ("No KAYA interfaces found"), - (NULL)); - goto error; - } - for (i = 0; i < num_ifaces; ++i) { - ret = KY_DeviceInfo (i, &devinfo); - GST_DEBUG_OBJECT (src, - "Found KAYA interface '%s', index=%d, bus=%d, slot=%d, fcn=%d, PID=%d, isVirtual=%s", - devinfo.szDeviceDisplayName, i, devinfo.nBus, devinfo.nSlot, - devinfo.nFunction, devinfo.DevicePID, - (devinfo.isVirtual ? "Yes" : "No")); - } - - g_assert (src->interface_index >= 0 - && src->interface_index < KAYA_SRC_MAX_FG_HANDLES); - if (src->interface_index >= num_ifaces) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Interface index provided (%d) out of bounds [0,%d]", - src->interface_index, num_ifaces - 1), (NULL)); - goto error; - } - - /* lock mutex until we have a camera opened */ - fg_data = &(srcclass->fg_data[src->interface_index]); - g_mutex_lock (&fg_data->fg_mutex); - - /* open framegrabber if it isn't already opened */ - if (srcclass->fg_data[src->interface_index].ref_count > 0) { - GST_DEBUG_OBJECT (src, - "Framegrabber interface already opened in this process, reusing"); - if (src->project_file && strlen (src->project_file) > 0) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Project file specified, but framegrabber is already opened, so it won't be used."), - (NULL)); - } - } else { - g_assert (fg_data->ref_count == 0); - - /* project files are optional */ - if (src->project_file && strlen (src->project_file) > 0) { - if (!g_file_test (src->project_file, G_FILE_TEST_EXISTS)) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Project file specified does not exist: %s", src->project_file), - (NULL)); - goto error; - } - - GST_DEBUG_OBJECT (src, - "About to open interface at index %d with project file '%s'", - src->interface_index, src->project_file); - fg_data->fg_handle = - KYFG_OpenEx (src->interface_index, src->project_file); - } else { - GST_DEBUG_OBJECT (src, "About to open interface at index %d", - src->interface_index); - fg_data->fg_handle = KYFG_Open (src->interface_index); - } - - if (fg_data->fg_handle == INVALID_FGHANDLE) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to open interface at index %d", src->interface_index), - (NULL)); - goto error; - } - - /* find and list all cameras */ - ret = - KYFG_CameraScan (fg_data->fg_handle, fg_data->cam_handles, - &fg_data->num_cams); - GST_DEBUG_OBJECT (src, "Found %d cameras connected", fg_data->num_cams); - if (fg_data->num_cams == 0) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to detect any cameras on interface"), (NULL)); - goto error; - } - for (i = 0; i < fg_data->num_cams; ++i) { - KYFGCAMERA_INFO caminfo; - ret = KYFG_CameraInfo (fg_data->cam_handles[i], &caminfo); - GST_DEBUG_OBJECT (src, - "Found camera '%s', index=%d, %s, %s %s, %s, ver=%s", - caminfo.deviceUserID, i, caminfo.deviceID, caminfo.deviceVendorName, - caminfo.deviceModelName, caminfo.deviceManufacturerInfo, - caminfo.deviceVersion); - } - } - - if (src->device_index >= fg_data->num_cams) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Camera device index provided out of bounds"), (NULL)); - goto error; - } - GST_DEBUG_OBJECT (src, "About to open camera at index %d", src->device_index); - if (src->xml_file && strlen (src->xml_file) > 0) { - if (!g_file_test (src->xml_file, G_FILE_TEST_EXISTS)) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("XML file specified does not exist: %s", src->xml_file), (NULL)); - goto error; - } - } - ret = - KYFG_CameraOpen2 (fg_data->cam_handles[src->device_index], src->xml_file); - if (ret != FGSTATUS_OK) { - g_mutex_unlock (&fg_data->fg_mutex); - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to open camera at index %d", src->device_index), (NULL)); - goto error; - } - src->cam_handle = fg_data->cam_handles[src->device_index]; - - /* increase refcount since we now have a camera open */ - src->fg_data = fg_data; - src->fg_data->ref_count++; - g_mutex_unlock (&src->fg_data->fg_mutex); - - /* if execute-command property is set, run it now */ - if (src->execute_command && src->execute_command[0] != 0) { - KYFG_CameraExecuteCommand (src->cam_handle, src->execute_command); - } - - gst_kayasrc_set_exposure_time (src); - - ret = - KYFG_CameraCallbackRegister (src->cam_handle, gst_kayasrc_stream_callback, - src); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to register stream callback function"), (NULL)); - goto error; - } - - ret = KYFG_StreamCreate (src->cam_handle, &src->stream_handle, 0); - if (ret != FGSTATUS_OK || src->stream_handle == INVALID_STREAMHANDLE) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to create stream"), (NULL)); - goto error; - } - - ret = - KYFG_StreamBufferCallbackRegister (src->stream_handle, - gst_kayasrc_stream_buffer_callback, src); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_ERROR (src, LIBRARY, FAILED, - ("Failed to register stream buffer callback function"), (NULL)); - goto error; - } - - KYFG_StreamGetInfo (src->stream_handle, KY_STREAM_INFO_PAYLOAD_SIZE, - &src->frame_size, NULL, NULL); - KYFG_StreamGetInfo (src->stream_handle, KY_STREAM_INFO_BUF_ALIGNMENT, - &frame_alignment, NULL, NULL); - - if (src->buffer_handles) { - g_free (src->buffer_handles); - } - src->buffer_handles = g_new (STREAM_BUFFER_HANDLE, src->num_capture_buffers); - for (i = 0; i < src->num_capture_buffers; ++i) { - void *frame = _aligned_malloc (src->frame_size, frame_alignment); - ret = - KYFG_BufferAnnounce (src->stream_handle, frame, src->frame_size, NULL, - &src->buffer_handles[i]); - } - - ret = - KYFG_BufferQueueAll (src->stream_handle, KY_ACQ_QUEUE_UNQUEUED, - KY_ACQ_QUEUE_INPUT); - - width = (guint32) KYFG_GetCameraValueInt (src->cam_handle, "Width"); - height = (guint32) KYFG_GetCameraValueInt (src->cam_handle, "Height"); - GST_DEBUG_OBJECT (src, "Camera resolution is %dx%d", width, height); - - str_size = sizeof (grabber_pixel_format); - ret = KYFG_GetGrabberValueStringCopy (src->cam_handle, "PixelFormat", - grabber_pixel_format, &str_size); - str_size = sizeof (camera_pixel_format); - ret = KYFG_GetCameraValueStringCopy (src->cam_handle, "PixelFormat", - camera_pixel_format, &str_size); - GST_DEBUG_OBJECT (src, "PixelFormat of camera is %s, grabber is %s", - camera_pixel_format, grabber_pixel_format); - - /* check if PixelFormat is Normal, in which case we use camera value */ - if (g_strcmp0 (grabber_pixel_format, "Normal") == 0) { - g_strlcpy (grabber_pixel_format, camera_pixel_format, - sizeof (grabber_pixel_format)); - } - - /* create caps */ - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - src->caps = - gst_genicam_pixel_format_caps_from_pixel_format (grabber_pixel_format, - G_BYTE_ORDER, width, height, 30, 1, 1, 1); - - if (src->caps == NULL) { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Unknown or unsupported pixel format '%s'.", grabber_pixel_format), - (NULL)); - return FALSE; - } - - src->stop_requested = FALSE; - src->dropped_frames = 0; - - return TRUE; - -error: - gst_kayasrc_cleanup (src); - - return FALSE; -} - -static gboolean -gst_kayasrc_stop (GstBaseSrc * bsrc) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - gst_kayasrc_cleanup (src); - - return TRUE; -} - -static GstCaps * -gst_kayasrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - GstCaps *caps; - - if (src->stream_handle == INVALID_STREAMHANDLE) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_kayasrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) == GST_VIDEO_FORMAT_UNKNOWN) { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static gboolean -gst_kayasrc_unlock (GstBaseSrc * bsrc) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_kayasrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstKayaSrc *src = GST_KAYA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -typedef struct -{ - GstKayaSrc *src; - STREAM_BUFFER_HANDLE buf_handle; - guint32 buf_id; -} VideoFrame; - -static void -buffer_release (void *data) -{ - VideoFrame *frame = (VideoFrame *) data; - GST_TRACE_OBJECT (frame->src, "Releasing buffer id=%d", frame->buf_id); - KYFG_BufferToQueue (frame->buf_handle, KY_ACQ_QUEUE_INPUT); - g_free (frame); -} - -static void -gst_kayasrc_stream_buffer_callback (STREAM_BUFFER_HANDLE buffer_handle, - void *context) -{ - GstKayaSrc *src = GST_KAYA_SRC (context); - GstBuffer *buf; - unsigned char *data; - guint32 buf_id; - GstClockTime timestamp; - VideoFrame *vf; - GstClock *clock; - - KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_TIMESTAMP, - ×tamp, NULL, NULL); - KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_BASE, &data, NULL, - NULL); - KYFG_BufferGetInfo (buffer_handle, KY_STREAM_BUFFER_INFO_ID, &buf_id, NULL, - NULL); - - GST_TRACE_OBJECT (src, "Got buffer id=%d, total_num=%d", buf_id, - src->frame_count); - - vf = g_new0 (VideoFrame, 1); - vf->src = src; - vf->buf_handle = buffer_handle; - vf->buf_id = buf_id; - buf = - gst_buffer_new_wrapped_full ((GstMemoryFlags) GST_MEMORY_FLAG_NO_SHARE, - (gpointer) data, src->frame_size, 0, src->frame_size, vf, - (GDestroyNotify) buffer_release); - - GST_BUFFER_OFFSET (buf) = src->frame_count; - src->frame_count++; - - guint64 cur_time = get_unix_ns(); - if (cur_time - src->unix_base > GST_SECOND) { - // assume delay between these two calls is negligible (one measurement showed <100ns) - src->kaya_base = KYFG_GetGrabberValueInt (src->cam_handle, "Timestamp"); - src->unix_base = get_unix_ns (); - } - -#if GST_CHECK_VERSION(1,14,0) - { - GstClockTime unix_ts = src->unix_base + (timestamp - src->kaya_base); - gst_buffer_add_reference_timestamp_meta (buf, - gst_static_caps_get (&unix_reference), unix_ts, GST_CLOCK_TIME_NONE); - GST_LOG_OBJECT (src, "Buffer #%d, adding unix timestamp: %llu", - GST_BUFFER_OFFSET (buf), unix_ts); - /*{ - GDateTime *frame_time, *tmpdt; - tmpdt = g_date_time_new_from_unix_utc (0); - frame_time = g_date_time_add_seconds(tmpdt, (gdouble)unix_ts / GST_SECOND); - g_date_time_unref (tmpdt); - GST_LOG ("Unix timestamp added is: %s.%d", g_date_time_format (frame_time, "%Y-%m-%d %H:%M:%S"), g_date_time_get_microsecond(frame_time)); - g_date_time_unref (frame_time); - } */ - } -#endif - - clock = gst_element_get_clock (GST_ELEMENT (src)); - GST_BUFFER_TIMESTAMP (buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - gst_clock_get_time (clock)); - gst_object_unref (clock); - - g_async_queue_push (src->queue, buf); -} - -static void -gst_kayasrc_stream_callback (void *context, STREAM_HANDLE stream_handle) -{ - GstKayaSrc *src = GST_KAYA_SRC (context); -} - -static GstFlowReturn -gst_kayasrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstKayaSrc *src = GST_KAYA_SRC (psrc); - gint64 dropped_frames = 0; - static FILE *temperature_file = NULL; - static gint64 temp_log_last_time = 0; - GST_LOG_OBJECT (src, "create"); - - if (g_getenv ("GST_KAYA_FPGA_TEMP_LOG")) { - if (temperature_file == NULL) { - const char *envvar = g_getenv ("GST_KAYA_FPGA_TEMP_LOG"); - gboolean write_header; - gchar *log_filename; - if (atoi (envvar) == 1) { - GDateTime *dt = g_date_time_new_now_local (); - log_filename = - g_date_time_format (dt, "kaya_fgpa_temp_%Y%m%d_%H%M%S.csv"); - g_date_time_unref (dt); - } else { - log_filename = g_strdup (envvar); - } - - write_header = !g_file_test (log_filename, G_FILE_TEST_EXISTS); - - GST_DEBUG_OBJECT (src, "Opening FPGA temp log file (%s)", log_filename); - temperature_file = fopen (log_filename, "a"); - if (!temperature_file) { - GST_ERROR_OBJECT (src, "Failed to open log file"); - return GST_FLOW_ERROR; - } - g_free (log_filename); - - if (write_header) { - fprintf (temperature_file, "IsoTime, UnixTime, KayaFpgaTemp\n"); - } - } - - if (temperature_file && g_get_real_time () - temp_log_last_time >= 1000000) { - GDateTime *dt = g_date_time_new_now_local (); - gchar *time_str = g_date_time_format (dt, "%Y-%m-%dT%H:%M:%S, %s"); - int fg_temp = KYFG_GetGrabberValueInt (src->fg_data->fg_handle, - "DeviceTemperature"); - GST_DEBUG_OBJECT (src, "FPGA temp: %d", fg_temp); - fprintf (temperature_file, "%s, %d\n", time_str, fg_temp); - fflush (temperature_file); - g_date_time_unref (dt); - g_free (time_str); - temp_log_last_time = g_get_real_time (); - } - } - - if (!src->acquisition_started) { - FGSTATUS ret; - GST_DEBUG_OBJECT (src, "starting acquisition"); - ret = KYFG_CameraStart (src->cam_handle, src->stream_handle, 0); - if (ret != FGSTATUS_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to start camera acquisition"), (NULL)); - goto error; - } - src->acquisition_started = TRUE; - } - - *buf = - GST_BUFFER (g_async_queue_timeout_pop (src->queue, src->timeout * 1000)); - if (!*buf) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to get buffer in %d ms", src->timeout), (NULL)); - goto error; - } - - dropped_frames = - KYFG_GetGrabberValueInt (src->cam_handle, "DropFrameCounter"); - if (dropped_frames > src->dropped_frames) { - GstStructure *info_msg; - gint64 just_dropped = dropped_frames - src->dropped_frames; - src->dropped_frames = dropped_frames; - - GST_WARNING_OBJECT (src, "Just dropped %d frames (%d total)", just_dropped, - src->dropped_frames); - - info_msg = gst_structure_new ("dropped-frame-info", - "num-dropped-frames", G_TYPE_INT, just_dropped, - "total-dropped-frames", G_TYPE_INT, src->dropped_frames, - "timestamp", GST_TYPE_CLOCK_TIME, GST_BUFFER_TIMESTAMP (buf), NULL); - gst_element_post_message (GST_ELEMENT (src), - gst_message_new_element (GST_OBJECT (src), info_msg)); - src->dropped_frames = dropped_frames; - } - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; - -error: - return GST_FLOW_ERROR; -} diff --git a/sys/kaya/gstkayasrc.h b/sys/kaya/gstkayasrc.h deleted file mode 100644 index 7355088..0000000 --- a/sys/kaya/gstkayasrc.h +++ /dev/null @@ -1,97 +0,0 @@ -/* GStreamer - * Copyright (c) 2018 outside US, United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_KAYA_SRC_H_ -#define _GST_KAYA_SRC_H_ - -#include - -#include - -#define KAYA_SRC_MAX_FG_HANDLES 16 - -G_BEGIN_DECLS - -#define GST_TYPE_KAYA_SRC (gst_kayasrc_get_type()) -#define GST_KAYA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_KAYA_SRC,GstKayaSrc)) -#define GST_KAYA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_KAYA_SRC,GstKayaSrcClass)) -#define GST_IS_KAYA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_KAYA_SRC)) -#define GST_IS_KAYA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_KAYA_SRC)) -#define GST_KAYA_SRC_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_KAYA_SRC, GstKayaSrcClass)) - -typedef struct _GstKayaSrc GstKayaSrc; -typedef struct _GstKayaSrcClass GstKayaSrcClass; - -typedef struct _GstKayaSrcFramegrabber GstKayaSrcFramegrabber; - -struct _GstKayaSrc -{ - GstPushSrc base_kayasrc; - - /* handles */ - GstKayaSrcFramegrabber *fg_data; - CAMHANDLE cam_handle; - STREAM_HANDLE stream_handle; - STREAM_BUFFER_HANDLE *buffer_handles; - size_t frame_size; - - /* properties */ - guint interface_index; - guint device_index; - guint num_capture_buffers; - gint timeout; - gchar *project_file; - gchar *xml_file; - gfloat exposure_time; - gchar *execute_command; - - gboolean acquisition_started; - guint64 frame_count; - gboolean stop_requested; - gint64 dropped_frames; - - GstCaps *caps; - GAsyncQueue *queue; - - GstClockTime unix_base; - GstClockTime kaya_base; -}; - -struct _GstKayaSrcFramegrabber -{ - FGHANDLE fg_handle; - guint32 ref_count; - CAMHANDLE cam_handles[4]; - int num_cams; - GMutex fg_mutex; -}; - -struct _GstKayaSrcClass -{ - GstPushSrcClass base_kayasrc_class; - - GstKayaSrcFramegrabber fg_data[KAYA_SRC_MAX_FG_HANDLES]; -}; - -GType gst_kayasrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/matrox/CMakeLists.txt b/sys/matrox/CMakeLists.txt deleted file mode 100644 index e4fe301..0000000 --- a/sys/matrox/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstmatroxsrc.c) - -set (HEADERS - gstmatroxsrc.h) - -include_directories (AFTER - ${MATROX_INCLUDE_DIR}) - -set (libname gstmatrox) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${MATROX_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/matrox/gstmatroxsrc.c b/sys/matrox/gstmatroxsrc.c deleted file mode 100644 index c3004a8..0000000 --- a/sys/matrox/gstmatroxsrc.c +++ /dev/null @@ -1,889 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstimperxflexsrc - * - * The imperxflexsrc element is a source for IMPERX and FrameLink Express framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v imperxflexsrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default IMPERX FrameLink Express framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstmatroxsrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_matroxsrc_debug); -#define GST_CAT_DEFAULT gst_matroxsrc_debug - -/* prototypes */ -static void gst_matroxsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_matroxsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_matroxsrc_dispose (GObject * object); -static void gst_matroxsrc_finalize (GObject * object); - -static gboolean gst_matroxsrc_start (GstBaseSrc * src); -static gboolean gst_matroxsrc_stop (GstBaseSrc * src); -static GstCaps *gst_matroxsrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_matroxsrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_matroxsrc_unlock (GstBaseSrc * src); -static gboolean gst_matroxsrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_matroxsrc_create (GstPushSrc * src, GstBuffer ** buf); - -static GstCaps *gst_matroxsrc_create_caps (GstMatroxSrc * src); -static MIL_INT MFTYPE -gst_matroxsrc_callback (MIL_INT HookType, MIL_ID EventId, void *UserDataPtr); - -#define VIDEO_CAPS_MAKE_BAYER8(format) \ - "video/x-bayer, " \ - "format = (string) " format ", " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -#define VIDEO_CAPS_MAKE_BAYER16(format) \ - "video/x-bayer, " \ - "format = (string) " format ", " \ - "endianness = (int) 1234, " \ - "bpp = (int) {16, 14, 12, 10}, " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -enum -{ - PROP_0, - PROP_SYSTEM, - PROP_BOARD, - PROP_CHANNEL, - PROP_CONFIG_FILE, - PROP_NUM_CAPTURE_BUFFERS, - PROP_TIMEOUT, - PROP_BAYER_MODE -}; - -#define DEFAULT_PROP_SYSTEM 0 -#define DEFAULT_PROP_BOARD -1 -#define DEFAULT_PROP_CHANNEL -1 -#define DEFAULT_PROP_CONFIG_FILE "M_DEFAULT" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 2 -#define DEFAULT_PROP_TIMEOUT 1000 -#define DEFAULT_PROP_BAYER_MODE GST_MATROX_BAYER_MODE_BAYER - - -#define GST_TYPE_MATROX_BAYER_MODE (gst_matrox_bayer_mode_get_type()) -static GType -gst_matrox_bayer_mode_get_type (void) -{ - static GType matrox_bayer_mode_type = 0; - static const GEnumValue matrox_bayer_mode[] = { - {GST_MATROX_BAYER_MODE_BAYER, "bayer", "Get raw bayer"}, - {GST_MATROX_BAYER_MODE_GRAY, "gray", "Get raw bayer as grayscale"}, - {GST_MATROX_BAYER_MODE_RGB, "rgb", "Get demosaiced RGB"}, - {0, NULL, NULL}, - }; - - if (!matrox_bayer_mode_type) { - matrox_bayer_mode_type = - g_enum_register_static ("GstMatroxBayerMode", matrox_bayer_mode); - } - return matrox_bayer_mode_type; -} - -static const GEnumValue matrox_system_enum[] = { - {0, "Default from MilConfig", "M_SYSTEM_DEFAULT"}, - {1, "Clarity UHD", "M_SYSTEM_CLARITY_UHD"}, - {2, "GigE Vision", "M_SYSTEM_GIGE_VISION"}, - {3, "Host", "M_SYSTEM_HOST"}, - {4, "Iris GTR", "M_SYSTEM_IRIS_GTR"}, - {5, "Morphis Dual/Quad", "M_SYSTEM_MORPHIS"}, - {6, "Morphis QxT", "M_SYSTEM_MORPHISQXT"}, - {7, "Orion HD", "M_SYSTEM_ORION_HD"}, - {8, "Radient eCL", "M_SYSTEM_RADIENT"}, - {9, "Radient eV-CL", "M_SYSTEM_RADIENTEVCL"}, - {10, "Radient eV-CLHS", "M_SYSTEM_RADIENTCLHS"}, - {11, "Radient eV-CXP", "M_SYSTEM_RADIENTCXP"}, - {12, "RadientPro CL", "M_SYSTEM_RADIENTPRO"}, - {13, "Rapixo CXP", "M_SYSTEM_RAPIXOCXP"}, - {14, "Solios", "M_SYSTEM_SOLIOS"}, - {15, "USB3 Vision", "M_SYSTEM_USB3_VISION"}, - {0, NULL, NULL}, -}; - -#define GST_TYPE_MATROX_SYSTEM (gst_matrox_system_get_type()) -static GType -gst_matrox_system_get_type (void) -{ - static GType matrox_system_type = 0; - - - if (!matrox_system_type) { - matrox_system_type = - g_enum_register_static ("GstMatroxSystem", matrox_system_enum); - } - return matrox_system_type; -} - - -/* pad templates */ - -static GstStaticPadTemplate gst_matroxsrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGRA }") ";" - VIDEO_CAPS_MAKE_BAYER8 ("{ bggr, grbg, rggb, gbrg }") ";" - VIDEO_CAPS_MAKE_BAYER16 ("{ bggr, grbg, rggb, gbrg }") - ) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstMatroxSrc, gst_matroxsrc, GST_TYPE_PUSH_SRC); - -static MIL_ID g_milapp = M_NULL; -static int g_milapp_use_count = 0; - -/* Matrox only wants an Application object to be created once per process, - * and it must be freed in the same thread it was created in */ -static MIL_ID -gst_matroxsrc_milapp_get () -{ - if (g_once_init_enter (&g_milapp)) { - MIL_ID setup_value = M_NULL; - g_assert (g_milapp_use_count == 0); - MappAlloc (M_NULL, M_DEFAULT, &setup_value); - MappControl (setup_value, M_ERROR, M_PRINT_DISABLE); - g_once_init_leave (&g_milapp, setup_value); - } - g_milapp_use_count += 1; - return g_milapp; -} - -static void -gst_matroxsrc_milapp_unref () -{ - g_milapp_use_count--; - if (g_milapp_use_count == 0) { - MappFree (g_milapp); - g_milapp = M_NULL; - } -} - - -static void -gst_matroxsrc_class_init (GstMatroxSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_matroxsrc_set_property; - gobject_class->get_property = gst_matroxsrc_get_property; - gobject_class->dispose = gst_matroxsrc_dispose; - gobject_class->finalize = gst_matroxsrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_matroxsrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Matrox Imaging Library Video Source", "Source/Video", - "Matrox Imaging Library video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_matroxsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_matroxsrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_matroxsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_matroxsrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_matroxsrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_matroxsrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_matroxsrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_SYSTEM, - g_param_spec_enum ("system", "System", - "System descriptor, default is specified in MilConfig", - GST_TYPE_MATROX_SYSTEM, DEFAULT_PROP_SYSTEM, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_int ("board", "Board", - "Board number, -1 uses default specified in MilConfig", -1, 15, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CHANNEL, - g_param_spec_int ("channel", "Channel", - "Channel number, -1 uses default specified in MilConfig", -1, 15, - DEFAULT_PROP_CHANNEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CONFIG_FILE, - g_param_spec_string ("config-file", "Format or format file", - "Format, as predefined string or DCF file path, default is specified in MilConfig", - DEFAULT_PROP_CONFIG_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMEOUT, - g_param_spec_int ("timeout", "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BAYER_MODE, - g_param_spec_enum ("bayer-mode", "Bayer mode", - "Pull Bayer frames as raw bayer, grayscale, or demosaiced RGB", - GST_TYPE_MATROX_BAYER_MODE, DEFAULT_PROP_BAYER_MODE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -} - -static void -gst_matroxsrc_reset (GstMatroxSrc * src) -{ - gint i; - src->acq_started = FALSE; - - src->height = 0; - src->gst_stride = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - if (src->MilGrabBufferList) { - for (i = 0; i < src->num_capture_buffers; ++i) { - if (src->MilGrabBufferList[i]) { - MbufFree (src->MilGrabBufferList[i]); - src->MilGrabBufferList[i] = NULL; - } - } - g_free (src->MilGrabBufferList); - src->MilGrabBufferList = NULL; - } - - if (src->MilDigitizer) { - MdigFree (src->MilDigitizer); - src->MilDigitizer = M_NULL; - } - - if (src->MilSystem) { - MsysFree (src->MilSystem); - src->MilSystem = M_NULL; - } -} - -static void -gst_matroxsrc_init (GstMatroxSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->system = DEFAULT_PROP_SYSTEM; - src->board = DEFAULT_PROP_BOARD; - src->channel = DEFAULT_PROP_CHANNEL; - src->config_file = g_strdup (DEFAULT_PROP_CONFIG_FILE); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->timeout = DEFAULT_PROP_TIMEOUT; - src->bayer_mode = DEFAULT_PROP_BAYER_MODE; - - g_mutex_init (&src->mutex); - g_cond_init (&src->cond); - src->stop_requested = FALSE; - src->caps = NULL; - src->buffer = NULL; - - src->MilApplication = M_NULL; - src->MilSystem = M_NULL; - src->MilDigitizer = M_NULL; - src->MilGrabBufferList = NULL; - - gst_matroxsrc_reset (src); - - if (src->MilApplication == M_NULL) { - src->MilApplication = gst_matroxsrc_milapp_get (); - } -} - -void -gst_matroxsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstMatroxSrc *src; - - src = GST_MATROX_SRC (object); - - switch (property_id) { - case PROP_SYSTEM: - src->system = g_value_get_enum (value); - break; - case PROP_NUM_CAPTURE_BUFFERS: - if (src->acq_started) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - src->num_capture_buffers = g_value_get_uint (value); - } - break; - case PROP_BOARD: - src->board = g_value_get_int (value); - break; - case PROP_CHANNEL: - src->channel = g_value_get_int (value); - break; - case PROP_CONFIG_FILE: - g_free (src->config_file); - src->config_file = g_strdup (g_value_get_string (value)); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - case PROP_BAYER_MODE: - src->bayer_mode = g_value_get_enum (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_matroxsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstMatroxSrc *src; - - g_return_if_fail (GST_IS_MATROX_SRC (object)); - src = GST_MATROX_SRC (object); - - switch (property_id) { - case PROP_SYSTEM: - g_value_set_enum (value, src->system); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_int (value, src->board); - break; - case PROP_CHANNEL: - g_value_set_int (value, src->channel); - break; - case PROP_CONFIG_FILE: - g_value_set_string (value, src->config_file); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - case PROP_BAYER_MODE: - g_value_set_enum (value, src->bayer_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_matroxsrc_dispose (GObject * object) -{ - GstMatroxSrc *src; - - g_return_if_fail (GST_IS_MATROX_SRC (object)); - src = GST_MATROX_SRC (object); - - /* clean up as possible. may be called multiple times */ - - g_mutex_clear (&src->mutex); - g_cond_clear (&src->cond); - - G_OBJECT_CLASS (gst_matroxsrc_parent_class)->dispose (object); -} - -void -gst_matroxsrc_finalize (GObject * object) -{ - GstMatroxSrc *src; - - g_return_if_fail (GST_IS_MATROX_SRC (object)); - src = GST_MATROX_SRC (object); - - /* clean up object here */ - g_free (src->config_file); - - gst_matroxsrc_reset (src); - - gst_matroxsrc_milapp_unref (); - - G_OBJECT_CLASS (gst_matroxsrc_parent_class)->finalize (object); -} - -static gboolean -gst_matroxsrc_start (GstBaseSrc * bsrc) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - MIL_ID ret; - gint i; - gint width; - gint height; - gint bpp; - gint n_bands; - gint bayer_pattern; - gchar bayer_pattern_format[5]; - gint is_bayer_conversion; - GstVideoInfo vinfo; - - GST_DEBUG_OBJECT (src, "start"); - - if (src->MilApplication == M_NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate a MIL application"), (NULL)); - return FALSE; - } - - /* create System */ - if (src->board == -1) { - ret = - MsysAlloc (src->MilApplication, - matrox_system_enum[src->system].value_nick, M_DEFAULT, M_DEFAULT, - &src->MilSystem); - } else { - ret = - MsysAlloc (src->MilApplication, - matrox_system_enum[src->system].value_nick, src->board, M_DEFAULT, - &src->MilSystem); - } - if (ret == M_NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate a MIL system"), (NULL)); - goto error; - } - - /* create Digitizer */ - if (src->channel == -1) { - ret = MdigAlloc (src->MilSystem, M_DEFAULT, src->config_file, M_DEFAULT, - &src->MilDigitizer); - } else { - ret = MdigAlloc (src->MilSystem, src->channel, src->config_file, M_DEFAULT, - &src->MilDigitizer); - } - if (ret == M_NULL) { - MIL_TEXT_CHAR err_msg[M_ERROR_MESSAGE_SIZE]; - MappGetError (M_DEFAULT, M_CURRENT | M_MESSAGE, err_msg); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate a MIL digitizer: %s", err_msg), (NULL)); - goto error; - } - - /* get format info and create caps */ - bayer_pattern = MdigInquire (src->MilDigitizer, M_BAYER_PATTERN, M_NULL); - is_bayer_conversion = - MdigInquire (src->MilDigitizer, M_BAYER_CONVERSION, M_NULL); - if (bayer_pattern != M_NULL) { - if (src->bayer_mode == GST_MATROX_BAYER_MODE_RGB) { - MdigControl (src->MilDigitizer, M_BAYER_CONVERSION, M_ENABLE); - } else { - MdigControl (src->MilDigitizer, M_BAYER_CONVERSION, M_DISABLE); - } - - switch (bayer_pattern) { - case M_BAYER_BG: - g_strlcpy (bayer_pattern_format, "bggr", 5); - break; - case M_BAYER_GB: - g_strlcpy (bayer_pattern_format, "gbrg", 5); - break; - case M_BAYER_GR: - g_strlcpy (bayer_pattern_format, "grbg", 5); - break; - case M_BAYER_RG: - g_strlcpy (bayer_pattern_format, "rggb", 5); - break; - default: - g_assert_not_reached (); - } - } - - width = MdigInquire (src->MilDigitizer, M_SIZE_X, M_NULL); - height = MdigInquire (src->MilDigitizer, M_SIZE_Y, M_NULL); - bpp = MdigInquire (src->MilDigitizer, M_SIZE_BIT, M_NULL); - n_bands = MdigInquire (src->MilDigitizer, M_SIZE_BAND, M_NULL); - src->mil_type = MdigInquire (src->MilDigitizer, M_TYPE, M_NULL); - - gst_video_info_init (&vinfo); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - /* bayer is described as 3 bands even before demosaic */ - if (n_bands == 1) { - if (bpp == 8) { - src->video_format = GST_VIDEO_FORMAT_GRAY8; - - if (bayer_pattern != M_NULL - && src->bayer_mode == GST_MATROX_BAYER_MODE_BAYER) { - src->caps = - gst_caps_new_simple ("video/x-bayer", "format", G_TYPE_STRING, - bayer_pattern_format, "width", G_TYPE_INT, width, "height", - G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, - G_MAXINT, 1, NULL); - } - } else if (bpp > 8 && bpp <= 16) { - src->video_format = GST_VIDEO_FORMAT_GRAY16_LE; - - if (bayer_pattern != M_NULL - && src->bayer_mode == GST_MATROX_BAYER_MODE_BAYER) { - src->caps = - gst_caps_new_simple ("video/x-bayer", "format", G_TYPE_STRING, - bayer_pattern_format, "bpp", G_TYPE_INT, bpp, "endianness", - G_TYPE_INT, G_LITTLE_ENDIAN, "width", G_TYPE_INT, width, "height", - G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, - G_MAXINT, 1, NULL); - } else { - GValue val = G_VALUE_INIT; - GstStructure *s; - src->video_format = GST_VIDEO_FORMAT_GRAY16_LE; - gst_video_info_set_format (&vinfo, src->video_format, width, height); - src->caps = gst_video_info_to_caps (&vinfo); - - /* set bpp, extra info for GRAY16 so elements can scale properly */ - s = gst_caps_get_structure (src->caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, bpp); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - ("Unknown or unsupported bit depth (%d).", bpp), (NULL)); - goto error; - } - } else if (n_bands == 3) { - /* TODO: handle non-Solios color formats */ - src->video_format = GST_VIDEO_FORMAT_BGRx; - } - - /* note that we abuse formats with Bayer */ - gst_video_info_set_format (&vinfo, src->video_format, width, height); - - if (!src->caps) { - src->caps = gst_video_info_to_caps (&vinfo); - } - - src->height = height; - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - - g_assert (src->MilGrabBufferList == NULL); - src->MilGrabBufferList = g_new (MIL_ID, src->num_capture_buffers); - for (i = 0; i < src->num_capture_buffers; i++) { - if (n_bands == 1) { - MbufAlloc2d (src->MilSystem, width, height, src->mil_type, - M_IMAGE + M_GRAB + M_PROC, &src->MilGrabBufferList[i]); - } else { - MbufAllocColor (src->MilSystem, - n_bands, - width, - height, - src->mil_type, M_IMAGE + M_GRAB + M_PROC + M_PACKED + M_BGR32, - &src->MilGrabBufferList[i]); - } - - if (src->MilGrabBufferList[i]) { - MbufClear (src->MilGrabBufferList[i], 0xFF); - } else { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate a MIL buffer"), (NULL)); - goto error; - } - } - - return TRUE; - -error: - gst_matroxsrc_reset (src); - - return FALSE; -} - -static gboolean -gst_matroxsrc_stop (GstBaseSrc * bsrc) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - if (src->acq_started) { - MdigProcess (src->MilDigitizer, src->MilGrabBufferList, - src->num_capture_buffers, M_STOP, M_DEFAULT, gst_matroxsrc_callback, - src); - src->acq_started = FALSE; - } - - gst_matroxsrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_matroxsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - GstCaps *caps; - - if (src->MilDigitizer == M_NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_matroxsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - return TRUE; -} - -static gboolean -gst_matroxsrc_unlock (GstBaseSrc * bsrc) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - g_mutex_lock (&src->mutex); - src->stop_requested = TRUE; - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); - - return TRUE; -} - -static gboolean -gst_matroxsrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstMatroxSrc *src = GST_MATROX_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstBuffer * -gst_matroxsrc_create_buffer_from_id (GstMatroxSrc * src, MIL_ID buffer_id) -{ - GstMapInfo minfo; - GstBuffer *buf; - - /* TODO: use allocator or use from pool */ - buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - /* map buffer so we can copy to it */ - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (src, - "GstBuffer size=%d, gst_stride=%d", minfo.size, src->gst_stride); - - /* copy MilBuffer to GstBuffer, possibly performing conversion in the process */ - if (src->video_format == GST_VIDEO_FORMAT_GRAY8 || - src->video_format == GST_VIDEO_FORMAT_GRAY16_LE || - src->video_format == GST_VIDEO_FORMAT_GRAY16_BE) { - MbufGet (buffer_id, minfo.data); - } else { - /* TODO: add support for planar color and YUV */ - MbufGetColor (buffer_id, M_PACKED | M_BGR32, M_ALL_BANDS, minfo.data); - } - - gst_buffer_unmap (buf, &minfo); - - return buf; -} - - -static MIL_INT MFTYPE -gst_matroxsrc_callback (MIL_INT HookType, MIL_ID EventId, void *UserDataPtr) -{ - GstMatroxSrc *src = GST_MATROX_SRC (UserDataPtr); - MIL_ID ModifiedBufferId; - gint dropped_frames; - static guint64 last_frame_number = 0; - static guint64 buffers_processed = 0; - static guint64 total_dropped_frames = 0; - GstClock *clock; - GstClockTime clock_time; - - g_assert (src != NULL); - - clock = gst_element_get_clock (GST_ELEMENT (src)); - clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - - /* Retrieve the MIL_ID of the grabbed buffer. */ - MdigGetHookInfo (EventId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId); - - ///* check for dropped frames and disrupted signal */ - //dropped_frames = (pFrameInfo->number - last_frame_number) - 1; - //if (dropped_frames > 0) { - // total_dropped_frames += dropped_frames; - // GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - // total_dropped_frames); - //} else if (dropped_frames < 0) { - // GST_WARNING_OBJECT (src, - // "Signal disrupted, frames likely dropped and timestamps inaccurate"); - - // /* frame timestamps reset, so adjust start time, accuracy reduced */ - // src->acq_start_time = - // gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))) - - // pFrameInfo->timestamp * GST_USECOND; - //} - //last_frame_number = pFrameInfo->number; - - g_mutex_lock (&src->mutex); - - if (src->buffer) { - /* TODO: save this in dropped frame total? */ - GST_WARNING_OBJECT (src, - "Got new buffer before old handled, dropping old."); - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - src->buffer = gst_matroxsrc_create_buffer_from_id (src, ModifiedBufferId); - - GST_BUFFER_TIMESTAMP (src->buffer) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - clock_time); - GST_BUFFER_OFFSET (src->buffer) = buffers_processed; - ++buffers_processed; - - g_cond_signal (&src->cond); - g_mutex_unlock (&src->mutex); - - return M_NULL; -} - -static GstFlowReturn -gst_matroxsrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstMatroxSrc *src = GST_MATROX_SRC (psrc); - gint64 end_time; - - GST_LOG_OBJECT (src, "create"); - - /* Start acquisition if not already started */ - if (G_UNLIKELY (!src->acq_started)) { - GST_LOG_OBJECT (src, "starting acquisition"); - src->acq_start_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - - MdigProcess (src->MilDigitizer, src->MilGrabBufferList, - src->num_capture_buffers, M_START, M_DEFAULT, gst_matroxsrc_callback, - src); - - src->acq_started = TRUE; - } - - /* wait for a buffer to be ready */ - g_mutex_lock (&src->mutex); - end_time = g_get_monotonic_time () + src->timeout * G_TIME_SPAN_MILLISECOND; - while (!src->buffer && !src->stop_requested) { - if (!g_cond_wait_until (&src->cond, &src->mutex, end_time)) { - g_mutex_unlock (&src->mutex); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Timeout, no data received after %d ms", src->timeout), (NULL)); - return GST_FLOW_ERROR; - } - } - *buf = src->buffer; - src->buffer = NULL; - g_mutex_unlock (&src->mutex); - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_matroxsrc_debug, "matroxsrc", 0, - "debug category for matroxsrc element"); - gst_element_register (plugin, "matroxsrc", GST_RANK_NONE, - gst_matroxsrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - matrox, - "Matrox Imaging Library video source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/matrox/gstmatroxsrc.h b/sys/matrox/gstmatroxsrc.h deleted file mode 100644 index 3a3eccc..0000000 --- a/sys/matrox/gstmatroxsrc.h +++ /dev/null @@ -1,88 +0,0 @@ -/* GStreamer - * Copyright (C) 2017 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_MATROX_SRC_H_ -#define _GST_MATROX_SRC_H_ - -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_MATROX_SRC (gst_matroxsrc_get_type()) -#define GST_MATROX_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MATROX_SRC,GstMatroxSrc)) -#define GST_MATROX_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MATROX_SRC,GstMatroxSrcClass)) -#define GST_IS_MATROX_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MATROX_SRC)) -#define GST_IS_MATROX_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MATROX_SRC)) - -typedef struct _GstMatroxSrc GstMatroxSrc; -typedef struct _GstMatroxSrcClass GstMatroxSrcClass; - -typedef enum { - GST_MATROX_BAYER_MODE_BAYER, - GST_MATROX_BAYER_MODE_GRAY, - GST_MATROX_BAYER_MODE_RGB -} GstMatroxBayerModeEnum; - -struct _GstMatroxSrc -{ - GstPushSrc base_matroxsrc; - - gboolean acq_started; - - /* MIL handles */ - MIL_ID MilApplication; - MIL_ID MilSystem; - MIL_ID MilDigitizer; - MIL_ID *MilGrabBufferList; - - /* properties */ - gint system; - gint board; - gint channel; - gchar *config_file; - guint num_capture_buffers; - gint timeout; - GstMatroxBayerModeEnum bayer_mode; - - GstBuffer *buffer; - GstClockTime acq_start_time; - - GstCaps *caps; - gint height; - gint gst_stride; - MIL_INT mil_type; - GstVideoFormat video_format; - - GMutex mutex; - GCond cond; - gboolean stop_requested; -}; - -struct _GstMatroxSrcClass -{ - GstPushSrcClass base_matroxsrc_class; -}; - -GType gst_matroxsrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/niimaq/CMakeLists.txt b/sys/niimaq/CMakeLists.txt deleted file mode 100644 index 60cd889..0000000 --- a/sys/niimaq/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstniimaq.c) - -set (HEADERS - gstniimaq.h) - -include_directories (AFTER - ${NIIMAQ_INCLUDE_DIR}) - -set (libname gstniimaq) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${NIIMAQ_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/niimaq/gstniimaq.c b/sys/niimaq/gstniimaq.c deleted file mode 100644 index f97075f..0000000 --- a/sys/niimaq/gstniimaq.c +++ /dev/null @@ -1,986 +0,0 @@ -/* GStreamer - * Copyright (C) <2006> Eric Jonas - * Copyright (C) <2006> Antoine Tremblay - * Copyright (C) 2010 United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * SECTION:element-niimaqsrc - * - * Source for National Instruments IMAQ frame grabber (Camera Link and analog cameras) - * - * - * Example launch line - * |[ - * gst-launch -v niimaqsrc ! ffmpegcolorspace ! autovideosink - * ]| - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstniimaq.h" - -#include -#include - -#include - -/* prototype for private function to disable 32-bit memory check */ -USER_FUNC niimaquDisable32bitPhysMemLimitEnforcement (SESSION_ID sid); - -GST_DEBUG_CATEGORY (niimaqsrc_debug); -#define GST_CAT_DEFAULT niimaqsrc_debug - -enum -{ - PROP_0, - PROP_DEVICE, - PROP_RING_BUFFER_COUNT, - PROP_IS_SIGNED, - PROP_TIMEOUT -}; - -#define DEFAULT_PROP_DEVICE "img0" -#define DEFAULT_PROP_RING_BUFFER_COUNT 2 -#define DEFAULT_PROP_IS_SIGNED FALSE -#define DEFAULT_PROP_TIMEOUT 0 - -static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ GRAY8, GRAY16_LE, GRAY16_BE }")) - ); - -G_DEFINE_TYPE (GstNiImaqSrc, gst_niimaqsrc, GST_TYPE_PUSH_SRC); - -/* GObject virtual methods */ -static void gst_niimaqsrc_dispose (GObject * object); -static void gst_niimaqsrc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_niimaqsrc_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); - -/* GstBaseSrc virtual methods */ -static gboolean gst_niimaqsrc_start (GstBaseSrc * bsrc); -static gboolean gst_niimaqsrc_stop (GstBaseSrc * bsrc); -static gboolean gst_niimaqsrc_query (GstBaseSrc * bsrc, GstQuery * query); -static GstCaps *gst_niimaqsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter); -static gboolean gst_niimaqsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps); - -/* GstPushSrc virtual methods */ -static GstFlowReturn gst_niimaqsrc_create (GstPushSrc * psrc, - GstBuffer ** buffer); - -/* GstNiImaq methods */ -static GstCaps *gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src); -static gboolean gst_niimaqsrc_close_interface (GstNiImaqSrc * src); - -#define gst_niimaqsrc_report_imaq_error(code) \ -{ \ - static char imaq_error_string[256]; \ - if (code) { \ - imgShowError (code, imaq_error_string); \ - GST_ERROR_OBJECT (src, "IMAQ error: %s", imaq_error_string); \ - } \ -} - -#if GST_CHECK_VERSION(1,14,0) -static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix"); -#endif - -uInt32 -gst_niimaqsrc_aq_in_progress_callback (SESSION_ID sid, IMG_ERR err, - IMG_SIGNAL_TYPE signal_type, uInt32 signal_identifier, void *userdata) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (userdata); - if (src->session_started) - GST_ERROR_OBJECT (src, "Session already started"); - src->session_started = TRUE; - return 0; /* don't re-arm */ -} - -uInt32 -gst_niimaqsrc_aq_done_callback (SESSION_ID sid, IMG_ERR err, - IMG_SIGNAL_TYPE signal_type, uInt32 signal_identifier, void *userdata) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (userdata); - if (!src->session_started) - GST_ERROR_OBJECT (src, "Session not started"); - src->session_started = FALSE; - return 0; /* don't re-arm */ -} - -typedef struct _GstNiImaqSrcTimeEntry GstNiImaqSrcTimeEntry; -struct _GstNiImaqSrcTimeEntry -{ - guint64 frame_index; - GstClockTime clock_time; -}; - -/* This will be called "at the start of acquisition into each image buffer." - * If acquisition blocks because we don't copy buffers fast enough, the number - * of times this function is called will be less than the IMAQ cumulative - * buffer count. */ -uInt32 -gst_niimaqsrc_frame_start_callback (SESSION_ID sid, IMG_ERR err, - IMG_SIGNAL_TYPE signal_type, uInt32 signal_identifier, void *userdata) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (userdata); - GstNiImaqSrcTimeEntry *time_entry; - - time_entry = g_new (GstNiImaqSrcTimeEntry, 1); - - /* get clock time */ - time_entry->clock_time = - gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src))); - time_entry->frame_index = src->imaqFrameStartNum; - - g_async_queue_push (src->time_queue, time_entry); - - src->imaqFrameStartNum++; - - /* return 1 to rearm the callback */ - return 1; -} - -/* TODO: reimplement this when device discovery is added, see #678402 */ -#if 0 -/** -* gst_niimaqsrc_class_probe_interfaces: -* @klass: #GstNiImaqClass -* @check: whether to enumerate interfaces -* -* Probes NI-IMAQ driver for available interfaces -* -* Returns: TRUE always -*/ -static gboolean -gst_niimaqsrc_class_probe_interfaces (GstNiImaqSrcClass * klass, gboolean check) -{ - if (!check) { - guint32 n; - gchar name[256]; - - /* clear interface list */ - while (interfaces) { - gchar *iface = interfaces->data; - interfaces = g_list_remove (interfaces, iface); - g_free (iface); - } - - GST_LOG_OBJECT (klass, "About to probe for IMAQ interfaces"); - - /* enumerate interfaces, limiting ourselves to the first 64 */ - for (n = 0; n < 64; n++) { - guint32 iid; - guint32 nports; - guint32 port; - gchar *iname; - uInt32 rval; - - /* get interface names until there are no more */ - if (rval = imgInterfaceQueryNames (n, name) != 0) { - gst_niimaqsrc_report_imaq_error (rval); - break; - } - - /* ignore NICFGen */ - if (g_strcmp0 (name, "NICFGen.iid") == 0) - continue; - - /* try and open the interface */ - if (rval = imgInterfaceOpen (name, &iid) != 0) { - gst_niimaqsrc_report_imaq_error (rval); - continue; - } - - /* find how many ports the interface provides */ - rval = imgGetAttribute (iid, IMG_ATTR_NUM_PORTS, &nports); - gst_niimaqsrc_report_imaq_error (rval); - rval = imgClose (iid, TRUE); - gst_niimaqsrc_report_imaq_error (rval); - - /* iterate over all the available ports */ - for (port = 0; port < nports; port++) { - /* if the there are multiple ports append the port number */ - if (nports > 1) - iname = g_strdup_printf ("%s::%d", name, port); - else - iname = g_strdup (name); - - /* TODO: should check to see if a camera is actually attached */ - interfaces = g_list_append (interfaces, iname); - - GST_DEBUG_OBJECT (klass, "Adding interface '%s' to list", iname); - } - } - - init = TRUE; - } - - klass->interfaces = interfaces; - - return init; -} -#endif - -/** -* gst_niimaqsrc_class_init: -* klass: #GstNiImaqClass to initialize -* -* Initialize #GstNiImaqClass, which occurs only once no matter how many -* instances of the class there are -*/ -static void -gst_niimaqsrc_class_init (GstNiImaqSrcClass * klass) -{ - /* get pointers to base classes */ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - /* install GObject vmethod implementations */ - gobject_class->dispose = gst_niimaqsrc_dispose; - gobject_class->set_property = gst_niimaqsrc_set_property; - gobject_class->get_property = gst_niimaqsrc_get_property; - - /* install GObject properties */ - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_DEVICE, g_param_spec_string ("device", - "Device", - "NI-IMAQ interface to open (e.g., img0::0)", DEFAULT_PROP_DEVICE, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_RING_BUFFER_COUNT, g_param_spec_int ("ring-buffer-count", - "Number of frames in the IMAQ ringbuffer", - "The number of frames in the IMAQ ringbuffer", 1, G_MAXINT, - DEFAULT_PROP_RING_BUFFER_COUNT, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_IS_SIGNED, - g_param_spec_boolean ("is-signed", "Image is signed 16-bit", - "Image is signed 16-bit, shift to unsigned 16-bit", - DEFAULT_PROP_IS_SIGNED, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TIMEOUT, g_param_spec_int ("timeout", - "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&src_factory)); - - gst_element_class_set_static_metadata (gstelement_class, - "NI-IMAQ Video Source", "Source/Video", - "National Instruments IMAQ based source, supports Camera Link and analog cameras", - "Joshua M. Doe "); - - /* install GstBaseSrc vmethod implementations */ - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_niimaqsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_niimaqsrc_stop); - gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_niimaqsrc_query); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_niimaqsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_niimaqsrc_set_caps); - - /* install GstPushSrc vmethod implementations */ - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_niimaqsrc_create); -} - -static void -gst_niimaqsrc_init (GstNiImaqSrc * src) -{ - GstPad *srcpad = GST_BASE_SRC_PAD (src); - - GST_DEBUG_OBJECT (src, "init"); - - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - src->time_queue = g_async_queue_new (); - - /* initialize properties */ - src->bufsize = DEFAULT_PROP_RING_BUFFER_COUNT; - src->interface_name = g_strdup (DEFAULT_PROP_DEVICE); - src->is_signed = DEFAULT_PROP_IS_SIGNED; - src->timeout = DEFAULT_PROP_TIMEOUT; - - src->clock = NULL; -} - -/** -* gst_niimaqsrc_dispose: -* object: #GObject to dispose -* -* Disposes of the #GObject as part of object destruction -*/ -static void -gst_niimaqsrc_dispose (GObject * object) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (object); - - GST_DEBUG_OBJECT (src, "dispose"); - - gst_niimaqsrc_close_interface (src); - - /* free memory allocated */ - g_free (src->interface_name); - src->interface_name = NULL; - - g_async_queue_unref (src->time_queue); - - /* chain dispose fuction of parent class */ - G_OBJECT_CLASS (gst_niimaqsrc_parent_class)->dispose (object); -} - -static void -gst_niimaqsrc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (object); - - switch (prop_id) { - case PROP_DEVICE: - if (src->interface_name) - g_free (src->interface_name); - src->interface_name = g_strdup (g_value_get_string (value)); - break; - case PROP_RING_BUFFER_COUNT: - src->bufsize = g_value_get_int (value); - break; - case PROP_IS_SIGNED: - src->is_signed = g_value_get_boolean (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - default: - break; - } -} - -static void -gst_niimaqsrc_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (object); - - switch (prop_id) { - case PROP_DEVICE: - g_value_set_string (value, src->interface_name); - break; - case PROP_RING_BUFFER_COUNT: - g_value_set_int (value, src->bufsize); - break; - case PROP_IS_SIGNED: - g_value_set_boolean (value, src->is_signed); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -gboolean -gst_niimaqsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); - gboolean res = TRUE; - int depth, ncomps; - GstVideoInfo vinfo; - - res = gst_video_info_from_caps (&vinfo, caps); - if (!res) { - GST_WARNING_OBJECT (src, "Unable to parse video info from caps"); - return res; - } - src->format = GST_VIDEO_INFO_FORMAT (&vinfo); - src->width = GST_VIDEO_INFO_WIDTH (&vinfo); - src->height = GST_VIDEO_INFO_HEIGHT (&vinfo); - - /* this will handle byte alignment (i.e. row multiple of 4 bytes) */ - src->framesize = GST_VIDEO_INFO_SIZE (&vinfo); - - gst_base_src_set_blocksize (bsrc, src->framesize); - - ncomps = GST_VIDEO_INFO_N_COMPONENTS (&vinfo); - depth = GST_VIDEO_INFO_COMP_DEPTH (&vinfo, 0); - - /* use this so NI can give us proper byte alignment */ - src->rowpixels = - GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0) / (ncomps * depth / 8); - - GST_LOG_OBJECT (src, "Caps set, framesize=%d, rowpixels=%d", - src->framesize, src->rowpixels); - - return res; -} - -static void -gst_niimaqsrc_reset (GstNiImaqSrc * src) -{ - GST_LOG_OBJECT (src, "Resetting instance"); - - /* initialize member variables */ - src->cumbufnum = 0; - src->imaqFrameStartNum = 0; - src->n_dropped_frames = 0; - src->sid = 0; - src->iid = 0; - src->session_started = FALSE; - src->format = GST_VIDEO_FORMAT_UNKNOWN; - src->width = 0; - src->height = 0; - src->rowpixels = 0; - - g_free (src->buflist); - src->buflist = NULL; - - if (src->time_queue) { - g_async_queue_unref (src->time_queue); - } - src->time_queue = g_async_queue_new (); - - if (src->clock) { - gst_object_unref (src->clock); - } -} - -static gboolean -gst_niimaqsrc_start_acquisition (GstNiImaqSrc * src) -{ - int i; - gint32 rval; - - g_assert (!src->session_started); - - GST_DEBUG_OBJECT (src, "Starting acquisition"); - - /* try to open the camera five times */ - for (i = 0; i < 5; i++) { - rval = imgSessionStartAcquisition (src->sid); - if (rval == IMG_ERR_GOOD) { - return TRUE; - } else { - gst_niimaqsrc_report_imaq_error (rval); - GST_LOG_OBJECT (src, "camera is still off , wait 50ms and retry"); - g_usleep (50000); - } - } - - /* we tried five times and failed, so we error */ - gst_niimaqsrc_close_interface (src); - - return FALSE; -} - -static GstFlowReturn -gst_niimaqsrc_create (GstPushSrc * psrc, GstBuffer ** buffer) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (psrc); - GstFlowReturn ret = GST_FLOW_OK; - GstClockTime timestamp = GST_CLOCK_TIME_NONE; - uInt32 copied_number; - uInt32 copied_index; - Int32 rval; - uInt32 dropped; - GstMapInfo minfo; - - GST_LOG_OBJECT (src, "create"); - - /* start the IMAQ acquisition session if we haven't done so yet */ - if (!src->session_started) { - if (!gst_niimaqsrc_start_acquisition (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unable to start acquisition."), (NULL)); - return GST_FLOW_ERROR; - } - - src->clock = gst_element_get_clock (GST_ELEMENT (src)); - /* assume delay between these two calls is negligible */ - src->unix_base = g_get_real_time () * 1000; - src->stream_base = gst_clock_get_time (src->clock); - } - - GST_LOG_OBJECT (src, "Allocating memory for IMAQ buffer #%d, size %d", - src->cumbufnum, src->framesize); - ret = - GST_BASE_SRC_CLASS (gst_niimaqsrc_parent_class)->alloc (GST_BASE_SRC - (src), 0, src->framesize, buffer); - if (ret != GST_FLOW_OK) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to allocate buffer"), - ("Failed to get downstream pad to allocate buffer")); - goto error; - } - - gst_buffer_map (*buffer, &minfo, GST_MAP_WRITE); - rval = imgSessionCopyAreaByNumber (src->sid, src->cumbufnum, 0, 0, - src->height, src->width, minfo.data, src->rowpixels, - IMG_OVERWRITE_GET_OLDEST, &copied_number, &copied_index); - gst_buffer_unmap (*buffer, &minfo); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("failed to copy buffer %d", src->cumbufnum), - ("failed to copy buffer %d", src->cumbufnum)); - goto error; - } - - while (timestamp == GST_CLOCK_TIME_NONE) { - /* wait 100 ms, shouldn't be needed if callback is working as expected */ - GstNiImaqSrcTimeEntry *entry = - (GstNiImaqSrcTimeEntry *) g_async_queue_timeout_pop (src->time_queue, - 100000); - if (entry == NULL) { - GST_WARNING_OBJECT (src, "No timestamps received, callback failed?"); - break; - } - - if (entry->frame_index < copied_number) { - GST_DEBUG_OBJECT (src, - "Got clocktime for frame %d while handling frame %d, frames dropped?", - entry->frame_index, copied_number); - g_free (entry); - continue; - } else if (entry->frame_index > copied_number) { - GST_DEBUG_OBJECT (src, - "Failed to get clocktime for frame %d, got one for frame %d instead", - copied_number, entry->frame_index); - g_free (entry); - break; - } - timestamp = entry->clock_time; - g_free (entry); - } - - /* TODO: do this above to reduce copying overhead */ - if (src->is_signed) { - gint16 *srcp; - guint16 *dstp; - guint i; - gst_buffer_map (*buffer, &minfo, GST_MAP_READWRITE); - srcp = minfo.data; - dstp = minfo.data; - - GST_DEBUG_OBJECT (src, "Shifting signed to unsigned"); - - /* TODO: make this faster */ - for (i = 0; i < minfo.size / 2; i++) - *dstp++ = *srcp++ + 32768; - - gst_buffer_unmap (*buffer, &minfo); - } - - GST_BUFFER_OFFSET (*buffer) = copied_number; - GST_BUFFER_OFFSET_END (*buffer) = copied_number + 1; - GST_BUFFER_TIMESTAMP (*buffer) = - timestamp - gst_element_get_base_time (GST_ELEMENT (src)); -#if GST_CHECK_VERSION(1,14,0) - { - GstClockTime unix_ts = src->unix_base + (timestamp - src->stream_base); - gst_buffer_add_reference_timestamp_meta (*buffer, - gst_static_caps_get (&unix_reference), unix_ts, GST_CLOCK_TIME_NONE); - GST_LOG_OBJECT (src, "Buffer #%d, adding unix timestamp: %llu", - GST_BUFFER_OFFSET (buffer), unix_ts); - /*{ - GDateTime *frame_time, *tmpdt; - tmpdt = g_date_time_new_from_unix_utc (0); - frame_time = g_date_time_add_seconds(tmpdt, (gdouble)unix_ts / GST_SECOND); - g_date_time_unref (tmpdt); - GST_LOG ("Unix timestamp added is: %s.%d", g_date_time_format (frame_time, "%Y-%m-%d %H:%M:%S"), g_date_time_get_microsecond(frame_time)); - g_date_time_unref (frame_time); - } */ - } -#endif - - dropped = copied_number - src->cumbufnum; - if (dropped > 0) { - src->n_dropped_frames += dropped; - GST_WARNING_OBJECT (src, - "Asked to copy buffer #%d but was given #%d; just dropped %d frames (%d total)", - src->cumbufnum, copied_number, dropped, src->n_dropped_frames); - } - - /* set cumulative buffer number to get next frame */ - src->cumbufnum = copied_number + 1; - - return ret; - -error: - { - /* make sure we return an error */ - if (ret == GST_FLOW_OK) - ret = GST_FLOW_ERROR; - return ret; - } -} - -/** -* gst_niimaqsrc_get_cam_caps: -* src: #GstNiImaq instance -* -* Get caps of camera attached to open IMAQ interface -* -* Returns: the #GstCaps of the src pad. Unref the caps when you no longer need it. -*/ -GstCaps * -gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src) -{ - GstCaps *gcaps = NULL; - Int32 rval; - uInt32 val; - gint width, height, depth, bpp; - GstVideoInfo vinfo; - GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN; - - if (!src->iid) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Camera interface not open"), ("Camera interface not open")); - goto error; - } - - gst_video_info_init (&vinfo); - - GST_LOG_OBJECT (src, "Retrieving attributes from IMAQ interface"); - rval = imgGetAttribute (src->iid, IMG_ATTR_BITSPERPIXEL, &val); - gst_niimaqsrc_report_imaq_error (rval); - bpp = val; - rval &= imgGetAttribute (src->iid, IMG_ATTR_BYTESPERPIXEL, &val); - gst_niimaqsrc_report_imaq_error (rval); - depth = val * 8; - rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_WIDTH, &val); - gst_niimaqsrc_report_imaq_error (rval); - width = val; - rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_HEIGHT, &val); - gst_niimaqsrc_report_imaq_error (rval); - height = val; - - if (rval) { - GST_ELEMENT_ERROR (src, STREAM, FAILED, - ("attempt to read attributes failed"), - ("attempt to read attributes failed")); - goto error; - } - - if (depth == 8) - format = GST_VIDEO_FORMAT_GRAY8; - else if (depth == 16) - format = GST_VIDEO_FORMAT_GRAY16_LE; - else if (depth == 32) - format = GST_VIDEO_FORMAT_BGRA; - else { - GST_ERROR_OBJECT (src, "Depth %d (%d-bit) not supported yet", depth, bpp); - goto error; - } - - gst_video_info_set_format (&vinfo, format, width, height); - - vinfo.fps_n = 30; - vinfo.fps_d = 1; - /* hard code framerate and par as IMAQ doesn't tell us anything about it */ - gcaps = gst_video_info_to_caps (&vinfo); - GST_LOG_OBJECT (src, "the camera caps are %" GST_PTR_FORMAT, gcaps); - - return gcaps; - -error: - - if (gcaps) { - gst_caps_unref (gcaps); - } - - return NULL; -} - -/** -* gst_niimaqsrc_start: -* src: #GstBaseSrc instance -* -* Open necessary resources -* -* Returns: TRUE on success -*/ -static gboolean -gst_niimaqsrc_start (GstBaseSrc * bsrc) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); - Int32 rval; - gint i; - uInt32 timeout; - - GST_DEBUG_OBJECT (src, "start"); - - gst_niimaqsrc_reset (src); - - GST_LOG_OBJECT (src, "Opening IMAQ interface: %s", src->interface_name); - - /* open IMAQ interface */ - rval = imgInterfaceOpen (src->interface_name, &(src->iid)); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to open IMAQ interface"), - ("Failed to open camera interface %s", src->interface_name)); - goto error; - } - - GST_LOG_OBJECT (src, "Opening IMAQ session: %s", src->interface_name); - - /* open IMAQ session */ - rval = imgSessionOpen (src->iid, &(src->sid)); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to open IMAQ session"), ("Failed to open IMAQ session %d", - src->sid)); - goto error; - } - - /* Allow use of 1428 and other 32-bit DMA cards on 64-bit systems with - greater than 3GB of memory. */ - niimaquDisable32bitPhysMemLimitEnforcement (src->sid); - - GST_LOG_OBJECT (src, "Creating ring with %d buffers", src->bufsize); - - /* create array of pointers to give to IMAQ for creating internal buffers */ - src->buflist = g_new (guint32 *, src->bufsize); - for (i = 0; i < src->bufsize; i++) { - src->buflist[i] = 0; - } - /* CAUTION: if this is ever changed to manually allocate memory, we must - be careful about allocating 64-bit addresses, as some IMAQ cards don't - support this, and can give a runtime error. See above call to - niimaquDisable32bitPhysMemLimitEnforcement */ - rval = - imgRingSetup (src->sid, src->bufsize, (void **) (src->buflist), 0, FALSE); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to create ring buffer"), - ("Failed to create ring buffer with %d buffers", src->bufsize)); - goto error; - } - - GST_LOG_OBJECT (src, "Registering callback functions"); - rval = imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, - IMG_FRAME_START, IMG_SIGNAL_STATE_RISING, - gst_niimaqsrc_frame_start_callback, src); - rval |= imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, - IMG_AQ_IN_PROGRESS, IMG_SIGNAL_STATE_RISING, - gst_niimaqsrc_aq_in_progress_callback, src); - rval |= imgSessionWaitSignalAsync2 (src->sid, IMG_SIGNAL_STATUS, - IMG_AQ_DONE, IMG_SIGNAL_STATE_RISING, - gst_niimaqsrc_aq_done_callback, src); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to register callback(s)"), ("Failed to register callback(s)")); - goto error; - } - - imgGetAttribute (src->iid, IMG_ATTR_FRAMEWAIT_MSEC, &timeout); - if (src->timeout != 0) { - rval = imgSetAttribute2 (src->sid, IMG_ATTR_FRAMEWAIT_MSEC, src->timeout); - if (rval) { - gst_niimaqsrc_report_imaq_error (rval); - GST_WARNING_OBJECT (src, "Failed to change timeout from %d to %d msecs", - timeout, src->timeout); - } else { - GST_DEBUG_OBJECT (src, "Changed timeout from %d to %d msecs", timeout, - src->timeout); - } - } else { - src->timeout = timeout; - GST_DEBUG_OBJECT (src, "Current timeout is %d msecs", timeout); - } - - return TRUE; - -error: - gst_niimaqsrc_close_interface (src); - - return FALSE;; - -} - -/** -* gst_niimaqsrc_stop: -* src: #GstBaseSrc instance -* -* Close resources opened by gst_niimaqsrc_start -* -* Returns: TRUE on success -*/ -static gboolean -gst_niimaqsrc_stop (GstBaseSrc * bsrc) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); - Int32 rval; - gboolean result = TRUE; - - GST_DEBUG_OBJECT (src, "stop"); - - /* stop IMAQ session */ - if (src->session_started) { - uInt32 last_buf_num; - rval = imgSessionAbort (src->sid, &last_buf_num); - GST_DEBUG_OBJECT (src, "Last good buffer number is %d", last_buf_num); - if (rval != IMG_ERR_GOOD) { - gst_niimaqsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unable to stop acquisition"), ("Unable to stop acquisition")); - result = FALSE; - } - src->session_started = FALSE; - GST_DEBUG_OBJECT (src, "Acquisition stopped"); - } - - result &= gst_niimaqsrc_close_interface (src); - - gst_niimaqsrc_reset (src); - - return result; -} - -static gboolean -gst_niimaqsrc_query (GstBaseSrc * bsrc, GstQuery * query) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); - gboolean res; - - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_LATENCY:{ - if (!src->session_started) { - GST_WARNING_OBJECT (src, "Can't give latency since device isn't open!"); - res = FALSE; - } else { - GstClockTime min_latency, max_latency; - /* TODO: this is a ballpark figure, estimate from FVAL times */ - min_latency = 33 * GST_MSECOND; - max_latency = 33 * GST_MSECOND * src->bufsize; - - GST_LOG_OBJECT (src, - "report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT, - GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency)); - - gst_query_set_latency (query, TRUE, min_latency, max_latency); - - res = TRUE; - } - } - default: - res = - GST_BASE_SRC_CLASS (gst_niimaqsrc_parent_class)->query (bsrc, query); - break; - } - - return res; -} - -static GstCaps * -gst_niimaqsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); - GstCaps *caps; - - if (!src->sid) - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - else - caps = gst_niimaqsrc_get_cam_caps (src); - - if (filter) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - return caps; -} - -/** -* gst_niimaqsrc_close_interface: -* src: #GstNiImaqSrc instance -* -* Close IMAQ session and interface -* -*/ -static gboolean -gst_niimaqsrc_close_interface (GstNiImaqSrc * src) -{ - Int32 rval; - gboolean result = TRUE; - - /* close IMAQ session and interface */ - if (src->sid) { - rval = imgClose (src->sid, TRUE); - if (rval != IMG_ERR_GOOD) { - gst_niimaqsrc_report_imaq_error (rval); - result = FALSE; - } else - GST_LOG_OBJECT (src, "IMAQ session closed"); - src->sid = 0; - } - if (src->iid) { - rval = imgClose (src->iid, TRUE); - if (rval != IMG_ERR_GOOD) { - gst_niimaqsrc_report_imaq_error (rval); - result = FALSE; - } else { - GST_LOG_OBJECT (src, "IMAQ interface closed"); - } - src->iid = 0; - } - - return result; -} - -/** -* plugin_init: -* plugin: #GstPlugin -* -* Initialize plugin by registering elements -* -* Returns: TRUE on success -*/ -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (niimaqsrc_debug, "niimaqsrc", 0, - "NI-IMAQ interface"); - - /* we only have one element in this plugin */ - return gst_element_register (plugin, "niimaqsrc", GST_RANK_NONE, - GST_TYPE_NIIMAQSRC); - -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - niimaq, - "NI-IMAQ source element", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/niimaq/gstniimaq.h b/sys/niimaq/gstniimaq.h deleted file mode 100644 index 0419f1d..0000000 --- a/sys/niimaq/gstniimaq.h +++ /dev/null @@ -1,93 +0,0 @@ -/* GStreamer - * Copyright (C) <2006> Eric Jonas - * Copyright (C) <2006> Antoine Tremblay - * Copyright (C) 2010 United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GST_NIIMAQSRC_H__ -#define __GST_NIIMAQSRC_H__ - -#include -#include -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_NIIMAQSRC \ - (gst_niimaqsrc_get_type()) -#define GST_NIIMAQSRC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NIIMAQSRC,GstNiImaqSrc)) -#define GST_NIIMAQSRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NIIMAQSRC,GstNiImaqSrcClass)) -#define GST_IS_NIIMAQSRC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NIIMAQSRC)) -#define GST_IS_NIIMAQSRC_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NIIMAQSRC)) -#define GST_NIIMAQSRC_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_NIIMAQSRC, GstNiImaqSrcClass)) - -typedef struct _GstNiImaqSrc GstNiImaqSrc; -typedef struct _GstNiImaqSrcClass GstNiImaqSrcClass; - -struct _GstNiImaqSrc { - GstPushSrc element; - - /* properties */ - gchar *interface_name; - gint bufsize; - gboolean is_signed; - guint32 timeout; - - /* image info */ - GstVideoFormat format; - int width; - int height; - gint framesize; - int rowpixels; - - guint64 imaqFrameStartNum; - uInt32 cumbufnum; - gint64 n_dropped_frames; - - guint32** buflist; - INTERFACE_ID iid; - SESSION_ID sid; - - gboolean session_started; - - GAsyncQueue *time_queue; - - GstClock *clock; - GstClockTime stream_base; - GstClockTime unix_base; -}; - -struct _GstNiImaqSrcClass { - GstPushSrcClass parent_class; - - /* probed interfaces */ - GList *interfaces; -}; - -GType gst_niimaqsrc_get_type (void); - -G_END_DECLS - -#endif /* __GST_NIIMAQSRC_H__ */ diff --git a/sys/niimaqdx/CMakeLists.txt b/sys/niimaqdx/CMakeLists.txt deleted file mode 100644 index c833781..0000000 --- a/sys/niimaqdx/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -set (SOURCES - gstniimaqdx.c) - -set (HEADERS - gstniimaqdx.h) - -include_directories (AFTER - ${NIIMAQDX_INCLUDE_DIR}) - -set (libname gstniimaqdx) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -# National Instruments doesn't provide a .lib for 64-bit, so use our own -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set (NIIMAQDX_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/win64/niimaqdx.lib") -endif () - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${NIIMAQDX_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/niimaqdx/gstniimaqdx.c b/sys/niimaqdx/gstniimaqdx.c deleted file mode 100644 index a36fbe1..0000000 --- a/sys/niimaqdx/gstniimaqdx.c +++ /dev/null @@ -1,1355 +0,0 @@ -/* GStreamer - * Copyright (C) <2006> Eric Jonas - * Copyright (C) <2006> Antoine Tremblay - * Copyright (C) 2013 United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * SECTION:element-niimaqdxdxsrc - * - * Source for National Instruments IMAQdx (FireWire, USB, GigE Vision) - * - * - * Example launch line - * |[ - * gst-launch -v niimaqdxdxsrc ! ffmpegcolorspace ! autovideosink - * ]| - * - */ - -/* TODO: Firewire cameras that have an ROI less than the full frame will be - corrupted, the only fix is to use NI Vision library */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstniimaqdx.h" - -#include -#include - -#include - -GST_DEBUG_CATEGORY (niimaqdxsrc_debug); -#define GST_CAT_DEFAULT niimaqdxsrc_debug - -enum -{ - PROP_0, - PROP_DEVICE, - PROP_RING_BUFFER_COUNT, - PROP_ATTRIBUTES, - PROP_BAYER_AS_GRAY, - PROP_IS_CONTROLLER -}; - -#define DEFAULT_PROP_DEVICE "cam0" -#define DEFAULT_PROP_RING_BUFFER_COUNT 3 -#define DEFAULT_PROP_ATTRIBUTES "" -#define DEFAULT_PROP_BAYER_AS_GRAY FALSE -#define DEFAULT_PROP_IS_CONTROLLER TRUE - -static void gst_niimaqdxsrc_init_interfaces (GType type); - -G_DEFINE_TYPE (GstNiImaqDxSrc, gst_niimaqdxsrc, GST_TYPE_PUSH_SRC); - -/* GObject virtual methods */ -static void gst_niimaqdxsrc_dispose (GObject * object); -static void gst_niimaqdxsrc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_niimaqdxsrc_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); - -/* GstBaseSrc virtual methods */ -static gboolean gst_niimaqdxsrc_start (GstBaseSrc * src); -static gboolean gst_niimaqdxsrc_stop (GstBaseSrc * src); -static gboolean gst_niimaqdxsrc_query (GstBaseSrc * src, GstQuery * query); -static GstCaps *gst_niimaqdxsrc_get_caps (GstBaseSrc * bsrc, - GstCaps * caps_filter); -static gboolean gst_niimaqdxsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps); - -/* GstPushSrc virtual methods */ -static GstFlowReturn gst_niimaqdxsrc_fill (GstPushSrc * src, GstBuffer * buf); - -/* GstNiImaqDx methods */ -static GstCaps *gst_niimaqdxsrc_get_cam_caps (GstNiImaqDxSrc * src); -static gboolean gst_niimaqdxsrc_close_interface (GstNiImaqDxSrc * src); -static void gst_niimaqdxsrc_reset (GstNiImaqDxSrc * src); -static void gst_niimaqdxsrc_set_dx_attributes (GstNiImaqDxSrc * src); - -const char * -gst_niimaqdxsrc_get_imaq_error_str (IMAQdxError code) -{ - static char imaqdx_error_string[IMAQDX_MAX_API_STRING_LENGTH]; - if (code) { - IMAQdxGetErrorString (code, imaqdx_error_string, - IMAQDX_MAX_API_STRING_LENGTH); - return imaqdx_error_string; - } else { - return "No IMAQdx error"; - } -} - -IMAQdxError -gst_niimaqdxsrc_report_imaq_error (IMAQdxError code) -{ - static char imaqdx_error_string[IMAQDX_MAX_API_STRING_LENGTH]; - if (code) { - IMAQdxGetErrorString (code, imaqdx_error_string, - IMAQDX_MAX_API_STRING_LENGTH); - GST_ERROR ("IMAQdx error %d: %s", code, imaqdx_error_string); - } - return code; -} - -typedef struct _GstNiImaqDxSrcTimeEntry GstNiImaqDxSrcTimeEntry; -struct _GstNiImaqDxSrcTimeEntry -{ - guint64 frame_index; - GstClockTime clock_time; -}; - -/* This will be called "when a frame done event occurs", so not start of frame */ -uInt32 NI_FUNC -gst_niimaqdxsrc_frame_done_callback (IMAQdxSession session, uInt32 bufferNumber, - void *userdata) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (userdata); - GstNiImaqDxSrcTimeEntry *time_entry; - - time_entry = g_new (GstNiImaqDxSrcTimeEntry, 1); - - /* get clock time */ - time_entry->clock_time = gst_clock_get_time (src->clock); - time_entry->frame_index = bufferNumber; - - g_async_queue_push (src->time_queue, time_entry); - - /* return 1 to rearm the callback */ - return 1; -} - -#if GST_CHECK_VERSION(1,14,0) -static GstStaticCaps unix_reference = GST_STATIC_CAPS ("timestamp/x-unix"); -#endif - -#define VIDEO_CAPS_MAKE_BAYER8(format) \ - "video/x-bayer, " \ - "format = (string) { " format " }, " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -#define VIDEO_CAPS_MAKE_BAYER16(format,endianness) \ - "video/x-bayer, " \ - "format = (string) { " format " }, " \ - "endianness = (int) { " endianness " }, " \ - "bpp = (int) {16, 14, 12, 10}, " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -/* TODO: handle the format mappings more intelligently */ -/* All pixel format names below have no spaces, as when comparing spaces - will be removed */ -ImaqDxCapsInfo imaq_dx_caps_infos[] = { - {"Mono8", 0, GST_VIDEO_CAPS_MAKE ("GRAY8"), 8, 8, 4} - , - {"8BitMonochrome", 0, GST_VIDEO_CAPS_MAKE ("GRAY8"), 8, 8, 4} - , - {"Mono10", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 10, 16, 4} - , - {"10BitMonochrome", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 10, - 16, 4} - , - {"Mono10", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 10, 16, 4} - , - {"10BitMonochrome", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 10, 16, 4} - , - {"Mono12", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 12, 16, 4} - , - {"12BitMonochrome", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 12, - 16, 4} - , - {"Mono12", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 12, 16, 4} - , - {"12BitMonochrome", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 12, 16, 4} - , - {"Mono14", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 14, 16, 4} - , - {"Mono14", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 14, 16, 4} - , - {"Mono16", G_LITTLE_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_LE"), 16, 16, 4} - , - {"Mono16", G_BIG_ENDIAN, GST_VIDEO_CAPS_MAKE ("GRAY16_BE"), 16, 16, 4} - , - {"RGB8", 0, GST_VIDEO_CAPS_MAKE ("RGB"), 24, 24, 4} - , - {"BGR8", 0, GST_VIDEO_CAPS_MAKE ("BGR"), 24, 24, 4} - , - {"RGBa8", 0, GST_VIDEO_CAPS_MAKE ("RGBA"), 32, 32, 4} - , - {"BGRa8", 0, GST_VIDEO_CAPS_MAKE ("BGRA"), 32, 32, 4} - , - {"BGRA8Packed", 0, GST_VIDEO_CAPS_MAKE ("BGRA"), 32, 32, 4} - , - {"YUV411_8_UYYVYY", 0, GST_VIDEO_CAPS_MAKE ("IYU1"), 16, 16, 4} - , /* deprecated by YUV411_8_UYYVYY */ - {"YUV411Packed", 0, GST_VIDEO_CAPS_MAKE ("IYU1"), 16, 16, 4} - , - {"YUV422_8_UYVY", 0, GST_VIDEO_CAPS_MAKE ("UYVY"), 16, 16, 4} - , /* deprecated by YUV422_8_UYVY */ - {"YUV422Packed", 0, GST_VIDEO_CAPS_MAKE ("UYVY"), 16, 16, 4} - , - {"YUV8_UYV", 0, GST_VIDEO_CAPS_MAKE ("v308"), 16, 16, 4} - , /* deprecated by YUV8_UYV */ - {"YUV444Packed", 0, GST_VIDEO_CAPS_MAKE ("v308"), 16, 16, 4} - , - {"BayerBG8", 0, VIDEO_CAPS_MAKE_BAYER8 ("bggr"), 8, 8, 1} - , - {"BayerGR8", 0, VIDEO_CAPS_MAKE_BAYER8 ("grbg"), 8, 8, 1} - , - {"BayerRG8", 0, VIDEO_CAPS_MAKE_BAYER8 ("rggb"), 8, 8, 1} - , - {"BayerGB8", 0, VIDEO_CAPS_MAKE_BAYER8 ("gbrg"), 8, 8, 1} - , - {"BayerBG10", 0, VIDEO_CAPS_MAKE_BAYER16 ("bggr16", "1234"), 10, 16, 1} - , - {"BayerGR10", 0, VIDEO_CAPS_MAKE_BAYER16 ("grbg16", "1234"), 10, 16, 1} - , - {"BayerRG10", 0, VIDEO_CAPS_MAKE_BAYER16 ("rggb16", "1234"), 10, 16, 1} - , - {"BayerGB10", 0, VIDEO_CAPS_MAKE_BAYER16 ("gbrg16", "1234"), 10, 16, 1} - , - {"BayerBG12", 0, VIDEO_CAPS_MAKE_BAYER16 ("bggr16", "1234"), 12, 16, 1} - , - {"BayerGR12", 0, VIDEO_CAPS_MAKE_BAYER16 ("grbg16", "1234"), 12, 16, 1} - , - {"BayerRG12", 0, VIDEO_CAPS_MAKE_BAYER16 ("rggb16", "1234"), 12, 16, 1} - , - {"BayerGB12", 0, VIDEO_CAPS_MAKE_BAYER16 ("gbrg16", "1234"), 12, 16, 1} - , - //TODO: use a caps string that agrees with Aravis - {"BayerBG16", 0, VIDEO_CAPS_MAKE_BAYER16 ("bggr16", "1234"), 16, 16, 1} - , - {"BayerGR16", 0, VIDEO_CAPS_MAKE_BAYER16 ("grbg16", "1234"), 16, 16, 1} - , - {"BayerRG16", 0, VIDEO_CAPS_MAKE_BAYER16 ("rggb16", "1234"), 16, 16, 1} - , - {"BayerGB16", 0, VIDEO_CAPS_MAKE_BAYER16 ("gbrg16", "1234"), 16, 16, 1} - , - {"JPEG", 0, "image/jpeg", 8, 8, 1} -}; - -static const ImaqDxCapsInfo * -gst_niimaqdxsrc_get_caps_info (const char *pixel_format, int endianness) -{ - int i; - /* some cameras include spaces in pixel format names, so remove them */ - char **split = g_strsplit (pixel_format, " ", -1); - char *pix_fmt = g_strjoinv (NULL, split); - g_strfreev (split); - - for (i = 0; i < G_N_ELEMENTS (imaq_dx_caps_infos); i++) { - ImaqDxCapsInfo *info = &imaq_dx_caps_infos[i]; - if (g_strcmp0 (pix_fmt, info->pixel_format) == 0 && - (info->endianness == endianness || info->endianness == 0)) { - g_free (pix_fmt); - return info; - } - } - - g_free (pix_fmt); - - GST_WARNING ("PixelFormat '%s' is not supported", pixel_format); - - return NULL; -} - -static const char * -gst_niimaqdxsrc_pixel_format_to_caps_string (const char *pixel_format, - int endianness) -{ - const ImaqDxCapsInfo *info = - gst_niimaqdxsrc_get_caps_info (pixel_format, endianness); - - if (!info) - return NULL; - - return info->gst_caps_string; -} - -static const char * -gst_niimaqdxsrc_pixel_format_from_caps (const GstCaps * caps, int *endianness) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (imaq_dx_caps_infos); i++) { - GstCaps *super_caps; - super_caps = gst_caps_from_string (imaq_dx_caps_infos[i].gst_caps_string); - if (gst_caps_is_subset (caps, super_caps)) { - *endianness = imaq_dx_caps_infos[i].endianness; - return imaq_dx_caps_infos[i].pixel_format; - } - } - - return NULL; -} - -static int -gst_niimaqdxsrc_pixel_format_get_depth (const char *pixel_format, - int endianness) -{ - const ImaqDxCapsInfo *info = - gst_niimaqdxsrc_get_caps_info (pixel_format, endianness); - - if (!info) - return 0; - - return info->depth; -} - -static int -gst_niimaqdxsrc_pixel_format_get_stride (const char *pixel_format, - int endianness, int width) -{ - return width * gst_niimaqdxsrc_pixel_format_get_depth (pixel_format, - endianness) / 8; -} - -static GstCaps * -gst_niimaqdxsrc_new_caps_from_pixel_format (const char *pixel_format, - int endianness, int width, int height, int framerate_n, int framerate_d, - int par_n, int par_d) -{ - const char *caps_string; - GstCaps *caps; - GstStructure *structure; - - GST_DEBUG - ("Trying to create caps from: %s, endianness=%d, %dx%d, fps=%d/%d, par=%d/%d", - pixel_format, endianness, width, height, framerate_n, framerate_d, par_n, - par_d); - - caps_string = - gst_niimaqdxsrc_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, framerate_n, framerate_d, - "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, NULL); - - caps = gst_caps_new_empty (); - gst_caps_append_structure (caps, structure); - - return caps; -} - - -static void _____BEGIN_FUNCTIONS_____ (); - -static gboolean _imaqdx_init = FALSE; -static GList *_imaqdx_devices = NULL; - -#if 0 -/** -* gst_niimaqdxsrc_class_probe_devices: -* @klass: #GstNiImaqDxClass -* @check: whether to enumerate devices -* -* Probes NI-IMAQdx driver for available interfaces -* -* Returns: TRUE always -*/ -static gboolean -gst_niimaqdxsrc_class_probe_devices (GstNiImaqDxSrcClass * klass, - gboolean check) -{ - if (!check) { - guint32 i; - uInt32 count; - IMAQdxError rval = IMAQdxErrorSuccess; - IMAQdxCameraInformation *cameraInformationArray = NULL; - - /* clear device list */ - while (_imaqdx_devices) { - gchar *iface = _imaqdx_devices->data; - _imaqdx_devices = g_list_remove (_imaqdx_devices, iface); - g_free (iface); - } - - GST_LOG_OBJECT (klass, "About to probe for IMAQdx interfaces"); - - // get count of connected cameras - rval = IMAQdxEnumerateCameras (NULL, &count, TRUE); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - return FALSE; - } - - cameraInformationArray = g_new (IMAQdxCameraInformation, count); - - rval = IMAQdxEnumerateCameras (cameraInformationArray, &count, TRUE); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - return FALSE; - } - - /* enumerate devices */ - for (i = 0; i < count; i++) { - gchar *iname; - IMAQdxCameraInformation *info = &cameraInformationArray[i]; - - GST_DEBUG_OBJECT (klass, "Found camera %s: %s, %s, %s, %s", - info->InterfaceName, info->VendorName, info->ModelName, - info->CameraFileName, info->CameraAttributeURL); - - iname = g_strdup (info->InterfaceName); - _imaqdx_devices = g_list_append (_imaqdx_devices, iname); - } - g_free (cameraInformationArray); - - _imaqdx_init = TRUE; - } - - klass->devices = _imaqdx_devices; - - return _imaqdx_init; -} -#endif - -/** -* gst_niimaqdxsrc_class_init: -* klass: #GstNiImaqDxClass to initialize -* -* Initialize #GstNiImaqDxClass, which occurs only once no matter how many -* instances of the class there are -*/ -static void -gst_niimaqdxsrc_class_init (GstNiImaqDxSrcClass * klass) -{ - /* get pointers to base classes */ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - /* install GObject vmethod implementations */ - gobject_class->dispose = gst_niimaqdxsrc_dispose; - gobject_class->set_property = gst_niimaqdxsrc_set_property; - gobject_class->get_property = gst_niimaqdxsrc_get_property; - - /* install GObject properties */ - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_DEVICE, g_param_spec_string ("device", - "Device", "NI-IMAQdx camera to open", DEFAULT_PROP_DEVICE, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_RING_BUFFER_COUNT, g_param_spec_int ("ring-buffer-count", - "Ring Buffer Count", - "The number of buffers in the internal IMAQdx ringbuffer", 1, - G_MAXINT, DEFAULT_PROP_RING_BUFFER_COUNT, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_ATTRIBUTES, g_param_spec_string ("attributes", - "Attributes", "Attributes to change, comma separated key=value pairs", - DEFAULT_PROP_ATTRIBUTES, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BAYER_AS_GRAY, - g_param_spec_boolean ("bayer-as-gray", "Bayer as gray", - "For Bayer sources use GRAY caps", DEFAULT_PROP_BAYER_AS_GRAY, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_IS_CONTROLLER, - g_param_spec_boolean ("is-controller", "Open as controller", - "True for controller mode, false for listener mode", - DEFAULT_PROP_IS_CONTROLLER, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - { - GstCaps *caps = gst_caps_new_empty (); - int i; - - for (i = 0; i < G_N_ELEMENTS (imaq_dx_caps_infos); i++) { - ImaqDxCapsInfo *info = &imaq_dx_caps_infos[i]; - gst_caps_merge (caps, gst_caps_from_string (info->gst_caps_string)); - } - caps = gst_caps_simplify (caps); - gst_element_class_add_pad_template (gstelement_class, - gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps)); - } - - gst_element_class_set_static_metadata (gstelement_class, - "NI-IMAQdx Video Source", "Source/Video", - "National Instruments IMAQdx source, supports FireWire, USB, and GigE Vision cameras", - "Joshua M. Doe "); - - /* install GstBaseSrc vmethod implementations */ - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_stop); - gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_query); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_set_caps); - - /* install GstPushSrc vmethod implementations */ - gstpushsrc_class->fill = GST_DEBUG_FUNCPTR (gst_niimaqdxsrc_fill); -} - -/** -* gst_niimaqdxsrc_init: -* src: the #GstNiImaqDx instance to initialize -* g_class: #GstNiImaqDxClass -* -* Initialize this instance of #GstNiImaqDx -*/ -static void -gst_niimaqdxsrc_init (GstNiImaqDxSrc * src) -{ - GstPad *srcpad = GST_BASE_SRC_PAD (src); - - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize properties */ - src->ringbuffer_count = DEFAULT_PROP_RING_BUFFER_COUNT; - src->device_name = g_strdup (DEFAULT_PROP_DEVICE); - src->attributes = g_strdup (DEFAULT_PROP_ATTRIBUTES); - src->bayer_as_gray = DEFAULT_PROP_BAYER_AS_GRAY; - src->is_controller = DEFAULT_PROP_IS_CONTROLLER; - - /* initialize pointers, then call reset to initialize the rest */ - src->temp_buffer = NULL; - src->time_queue = NULL; - src->clock = NULL; - gst_niimaqdxsrc_reset (src); -} - -/** -* gst_niimaqdxsrc_dispose: -* object: #GObject to dispose -* -* Disposes of the #GObject as part of object destruction -*/ -static void -gst_niimaqdxsrc_dispose (GObject * object) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (object); - - gst_niimaqdxsrc_close_interface (src); - - /* free memory allocated */ - g_free (src->device_name); - src->device_name = NULL; - - /* unref objects */ - g_async_queue_unref (src->time_queue); - - /* chain dispose fuction of parent class */ - G_OBJECT_CLASS (gst_niimaqdxsrc_parent_class)->dispose (object); -} - -static void -gst_niimaqdxsrc_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (object); - - switch (prop_id) { - case PROP_DEVICE: - if (src->device_name) - g_free (src->device_name); - src->device_name = g_strdup (g_value_get_string (value)); - break; - case PROP_RING_BUFFER_COUNT: - src->ringbuffer_count = g_value_get_int (value); - break; - case PROP_ATTRIBUTES: - if (src->attributes) - g_free (src->attributes); - src->attributes = g_strdup (g_value_get_string (value)); - break; - case PROP_BAYER_AS_GRAY: - src->bayer_as_gray = g_value_get_boolean (value); - break; - case PROP_IS_CONTROLLER: - src->is_controller = g_value_get_boolean (value); - break; - default: - break; - } -} - -static void -gst_niimaqdxsrc_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (object); - - switch (prop_id) { - case PROP_DEVICE: - g_value_set_string (value, src->device_name); - break; - case PROP_RING_BUFFER_COUNT: - g_value_set_int (value, src->ringbuffer_count); - break; - case PROP_ATTRIBUTES: - g_value_set_string (value, src->attributes); - break; - case PROP_BAYER_AS_GRAY: - g_value_set_boolean (value, src->bayer_as_gray); - break; - case PROP_IS_CONTROLLER: - g_value_set_boolean (value, src->is_controller); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gst_niimaqdxsrc_reset (GstNiImaqDxSrc * src) -{ - GST_LOG_OBJECT (src, "Resetting instance"); - - /* initialize member variables */ - src->cumbufnum = 0; - src->n_dropped_frames = 0; - src->session = 0; - src->session_started = FALSE; - src->width = 0; - src->height = 0; - src->dx_row_stride = 0; - src->dx_framesize = 0; - src->gst_row_stride = 0; - src->gst_framesize = 0; - src->caps_info = NULL; - src->pixel_format[0] = 0; - - g_free (src->temp_buffer); - src->temp_buffer = NULL; - - if (src->time_queue) { - g_async_queue_unref (src->time_queue); - } - src->time_queue = g_async_queue_new (); - - if (src->clock) { - gst_object_unref (src->clock); - src->clock = NULL; - } -} - -static gboolean -gst_niimaqdxsrc_start_acquisition (GstNiImaqDxSrc * src) -{ - int i; - IMAQdxError rval; - - g_assert (!src->session_started); - - GST_DEBUG_OBJECT (src, "Starting acquisition"); - - /* try to open the camera five times */ - for (i = 0; i < 5; i++) { - rval = IMAQdxStartAcquisition (src->session); - if (rval == IMAQdxErrorSuccess) { - src->session_started = TRUE; - return TRUE; - } else { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_LOG_OBJECT (src, "camera is still off , wait 50ms and retry"); - g_usleep (50000); - } - } - - /* we tried five times and failed, so we error */ - gst_niimaqdxsrc_close_interface (src); - - return FALSE; -} - -#define ROUND_UP_N(num, n) (((num)+((n)-1))&~((n)-1)) - -static GstFlowReturn -gst_niimaqdxsrc_fill (GstPushSrc * psrc, GstBuffer * buf) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (psrc); - GstClockTime timestamp = GST_CLOCK_TIME_NONE; - GstClockTime duration; - uInt32 copied_number; - IMAQdxError rval; - uInt32 dropped; - gboolean do_align_stride; - GstMapInfo minfo; - - /* start the IMAQ acquisition session if we haven't done so yet */ - if (!src->session_started) { - src->clock = gst_element_get_clock (GST_ELEMENT (src)); - - if (!gst_niimaqdxsrc_start_acquisition (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unable to start acquisition"), (NULL)); - return GST_FLOW_ERROR; - } - - /* assume delay between these two calls is negligible */ - src->unix_base = g_get_real_time () * 1000; - src->stream_base = gst_clock_get_time (src->clock); - } - - /* will change attributes if provided */ - gst_niimaqdxsrc_set_dx_attributes (src); - - if (src->caps_info == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to create caps, possibly unsupported format (%s).", - src->pixel_format), (NULL)); - return GST_FLOW_ERROR; - } - - GST_LOG_OBJECT (src, "Trying to copy IMAQ buffer #%d, buffersize %d", - src->cumbufnum, gst_buffer_get_size (buf)); - - do_align_stride = src->dx_row_stride != src->gst_row_stride; - - if (!do_align_stride) { - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - // we have properly aligned strides, copy directly to buffer - rval = IMAQdxGetImageData (src->session, minfo.data, - minfo.size, IMAQdxBufferNumberModeBufferNumber, - src->cumbufnum, &copied_number); - gst_buffer_unmap (buf, &minfo); - } else { - // we don't have aligned strides, copy to temp buffer - rval = IMAQdxGetImageData (src->session, src->temp_buffer, - src->dx_framesize, IMAQdxBufferNumberModeBufferNumber, - src->cumbufnum, &copied_number); - } - - if (rval) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("failed to copy buffer %d: %s", src->cumbufnum, - gst_niimaqdxsrc_get_imaq_error_str (rval)), (NULL)); - return GST_FLOW_ERROR; - } - - if (src->cumbufnum == 0 && src->cumbufnum != copied_number) { - /* with some cameras we always lose the first few frames, don't report - these as dropped frames */ - GST_DEBUG_OBJECT (src, "Asked to copy buffer %d, was given %d instead", - src->cumbufnum, copied_number); - src->cumbufnum = copied_number; - } - - if (src->is_jpeg) { - /* JPEG sources don't seem to give reliable callbacks, just pull clock */ - timestamp = gst_clock_get_time (src->clock); - } - - while (timestamp == GST_CLOCK_TIME_NONE) { - /* wait 100 ms, shouldn't be needed if callback is working as expected */ - GstNiImaqDxSrcTimeEntry *entry = - (GstNiImaqDxSrcTimeEntry *) g_async_queue_timeout_pop (src->time_queue, - 100000); - if (entry == NULL) { - GST_WARNING_OBJECT (src, "No timestamps received, callback failed?"); - break; - } - - if (entry->frame_index < copied_number) { - GST_LOG_OBJECT (src, - "Discarding timestamp for frame %d while searching for frame %d", - entry->frame_index, copied_number); - g_free (entry); - continue; - } else if (entry->frame_index > copied_number) { - GST_WARNING_OBJECT (src, - "Failed to get clocktime for frame %d, got one for frame %d instead", - copied_number, entry->frame_index); - g_free (entry); - break; - } - timestamp = entry->clock_time; - g_free (entry); - } - - // adjust for row stride if needed (must be multiple of 4) - if (do_align_stride) { - int i; - guint8 *tmpbuf = src->temp_buffer; - guint8 *dst; - - gst_buffer_map (buf, &minfo, GST_MAP_WRITE); - dst = minfo.data; - GST_LOG_OBJECT (src, - "Row stride not aligned, copying %d -> %d", - src->dx_row_stride, src->gst_row_stride); - g_assert (minfo.size >= src->gst_framesize); - for (i = 0; i < src->height; i++) - memcpy (dst + i * src->gst_row_stride, tmpbuf + i * src->dx_row_stride, - src->dx_row_stride); - gst_buffer_unmap (buf, &minfo); - } - - /* make guess of duration from timestamp and cumulative buffer number */ - if (GST_CLOCK_TIME_IS_VALID (timestamp)) { - duration = timestamp / (copied_number + 1); - } else { - duration = 33 * GST_MSECOND; - } - - GST_BUFFER_OFFSET (buf) = copied_number; - GST_BUFFER_OFFSET_END (buf) = copied_number + 1; - GST_BUFFER_TIMESTAMP (buf) = - timestamp - gst_element_get_base_time (GST_ELEMENT (src)); - // TODO: fix duration - //GST_BUFFER_DURATION (buf) = duration; -#if GST_CHECK_VERSION(1,14,0) - { - GstClockTime unix_ts = src->unix_base + (timestamp - src->stream_base); - gst_buffer_add_reference_timestamp_meta (buf, - gst_static_caps_get (&unix_reference), unix_ts, GST_CLOCK_TIME_NONE); - GST_LOG_OBJECT (src, "Buffer #%d, adding unix timestamp: %llu", - GST_BUFFER_OFFSET (buf), unix_ts); - /*{ - GDateTime *frame_time, *tmpdt; - tmpdt = g_date_time_new_from_unix_utc (0); - frame_time = g_date_time_add_seconds(tmpdt, (gdouble)unix_ts / GST_SECOND); - g_date_time_unref (tmpdt); - GST_LOG ("Unix timestamp added is: %s.%d", g_date_time_format (frame_time, "%Y-%m-%d %H:%M:%S"), g_date_time_get_microsecond(frame_time)); - g_date_time_unref (frame_time); - } */ - } -#endif - - dropped = copied_number - src->cumbufnum; - if (dropped > 0) { - GstStructure *infoStruct; - - src->n_dropped_frames += dropped; - GST_WARNING_OBJECT (src, - "Asked to copy buffer #%d but was given #%d; just dropped %d frames (%d total)", - src->cumbufnum, copied_number, dropped, src->n_dropped_frames); - - infoStruct = gst_structure_new ("dropped-frame-info", - "num-dropped-frames", G_TYPE_INT, dropped, - "total-dropped-frames", G_TYPE_INT, src->n_dropped_frames, - "timestamp", GST_TYPE_CLOCK_TIME, GST_BUFFER_TIMESTAMP (buf), NULL); - gst_element_post_message (GST_ELEMENT (src), - gst_message_new_element (GST_OBJECT (src), infoStruct)); - } - - /* set cumulative buffer number to get next frame */ - src->cumbufnum = copied_number + 1; - - return GST_FLOW_OK; -} - -void -gst_niimaqdxsrc_list_attributes (GstNiImaqDxSrc * src) -{ - IMAQdxAttributeInformation *attributeInfoArray = NULL; - uInt32 attributeCount; - guint i; - IMAQdxError rval; - IMAQdxSession session = src->session; - char *attributeTypeStrings[] = { "U32", "I64", - "F64", - "String", - "Enum", - "Bool", - "Command", - "Blob" - }; - char attributeString[IMAQDX_MAX_API_STRING_LENGTH]; - - rval = - IMAQdxEnumerateAttributes2 (session, NULL, &attributeCount, "", - IMAQdxAttributeVisibilityAdvanced); - attributeInfoArray = g_new (IMAQdxAttributeInformation, attributeCount); - rval = - IMAQdxEnumerateAttributes2 (session, attributeInfoArray, &attributeCount, - "", IMAQdxAttributeVisibilityAdvanced); - GST_DEBUG_OBJECT (src, "Enumerating %d attributes", attributeCount); - for (i = 0; i < attributeCount; i++) { - IMAQdxAttributeInformation *info = attributeInfoArray + i; - g_assert (info); - - if (info->Readable) { - rval = - IMAQdxGetAttribute (session, info->Name, IMAQdxValueTypeString, - attributeString); - if (rval != IMAQdxErrorSuccess) { - GST_WARNING_OBJECT (src, - "Failed to read value of attribute %s", info->Name); - continue; - } - } else - attributeString[0] = 0; - - GST_LOG_OBJECT (src, "%s, %s/%s, %s, %s\n", - info->Name, info->Readable ? "R" : "-", - info->Writable ? "W" : "-", - attributeTypeStrings[info->Type], attributeString); - } - g_free (attributeInfoArray); -} - -/** -* gst_niimaqdxsrc_get_cam_caps: -* src: #GstNiImaqDx instance -* -* Get caps of camera attached to open IMAQ interface -* -* Returns: the #GstCaps of the src pad. Unref the caps when you no longer need it. -*/ -GstCaps * -gst_niimaqdxsrc_get_cam_caps (GstNiImaqDxSrc * src) -{ - GstCaps *caps = NULL; - IMAQdxError rval; - uInt32 val; - char pixel_format[IMAQDX_MAX_API_STRING_LENGTH]; - int endianness; - IMAQdxBusType bus_type; - gint width, height; - - if (!src->session) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Camera not open"), (NULL)); - goto error; - } - - GST_LOG_OBJECT (src, "Retrieving attributes from IMAQdx device"); - - rval = IMAQdxGetAttribute (src->session, IMAQdxAttributePixelFormat, - IMAQdxValueTypeString, &pixel_format); - gst_niimaqdxsrc_report_imaq_error (rval); - rval &= IMAQdxGetAttribute (src->session, IMAQdxAttributeBusType, - IMAQdxValueTypeU32, &val); - bus_type = (IMAQdxBusType) val; - gst_niimaqdxsrc_report_imaq_error (rval); - rval &= IMAQdxGetAttribute (src->session, IMAQdxAttributeWidth, - IMAQdxValueTypeU32, &val); - gst_niimaqdxsrc_report_imaq_error (rval); - width = val; - rval &= IMAQdxGetAttribute (src->session, IMAQdxAttributeHeight, - IMAQdxValueTypeU32, &val); - gst_niimaqdxsrc_report_imaq_error (rval); - height = val; - - if (rval) { - GST_ELEMENT_ERROR (src, STREAM, FAILED, - ("attempt to read attributes failed: %s", - gst_niimaqdxsrc_get_imaq_error_str (rval)), - ("attempt to read attributes failed")); - goto error; - } - - g_strlcpy (src->pixel_format, pixel_format, IMAQDX_MAX_API_STRING_LENGTH); - - /* confirmed FireWire is big-endian, GigE and USB3 are little-endian */ - if (bus_type == IMAQdxBusTypeEthernet || bus_type == IMAQdxBusTypeUSB3Vision) { - endianness = G_LITTLE_ENDIAN; - } else { - endianness = G_BIG_ENDIAN; - } - - GST_DEBUG_OBJECT (src, "Camera has pixel format '%s'", pixel_format); - - if (g_str_has_prefix (pixel_format, "Bayer") && src->bayer_as_gray) { - const ImaqDxCapsInfo *info = - gst_niimaqdxsrc_get_caps_info (pixel_format, endianness); - if (info->depth == 8) { - g_strlcpy (pixel_format, "Mono 8", IMAQDX_MAX_API_STRING_LENGTH); - } else if (info->depth == 16) { - g_strlcpy (pixel_format, "Mono 16", IMAQDX_MAX_API_STRING_LENGTH); - } - } - //TODO: add all available caps by enumerating PixelFormat's available, and query for framerate - caps = - gst_niimaqdxsrc_new_caps_from_pixel_format (pixel_format, endianness, - width, height, 30, 1, 1, 1); - if (!caps) { - GST_ERROR_OBJECT (src, "PixelFormat '%s' not supported yet", pixel_format); - goto error; - } - - GST_LOG_OBJECT (caps, "are the camera caps"); - - return caps; - -error: - - if (caps) { - gst_caps_unref (caps); - } - - return NULL; -} - -static void -gst_niimaqdxsrc_set_dx_attributes (GstNiImaqDxSrc * src) -{ - gchar **pairs; - int i; - IMAQdxError rval; - - if (!src->attributes || src->attributes == 0) { - return; - } - - GST_DEBUG_OBJECT (src, "Trying to set following attributes: '%s'", - src->attributes); - - pairs = g_strsplit (src->attributes, ";", 0); - - for (i = 0;; i++) { - gchar **pair; - - if (!pairs[i]) - break; - - pair = g_strsplit (pairs[i], "=", 2); - - if (!pair[0] || !pair[1]) { - GST_WARNING_OBJECT (src, "Failed to parse attribute/value: '%s'", pair); - continue; - } - - GST_DEBUG_OBJECT (src, "Setting attribute, '%s'='%s'", pair[0], pair[1]); - - rval = - IMAQdxSetAttribute (src->session, pair[0], - IMAQdxValueTypeString, (const char *) pair[1]); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - } - g_strfreev (pair); - } - g_strfreev (pairs); - - if (src->attributes) { - g_free (src->attributes); - src->attributes = NULL; - } -} - -/** -* gst_niimaqdxsrc_start: -* src: #GstBaseSrc instance -* -* Open necessary resources -* -* Returns: TRUE on success -*/ -static gboolean -gst_niimaqdxsrc_start (GstBaseSrc * bsrc) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (bsrc); - IMAQdxError rval; - IMAQdxCameraControlMode control_mode; - - gst_niimaqdxsrc_reset (src); - - if (src->is_controller) { - control_mode = IMAQdxCameraControlModeController; - GST_LOG_OBJECT (src, "Opening IMAQdx interface '%s' in controller mode", - src->device_name); - } else { - control_mode = IMAQdxCameraControlModeListener; - GST_LOG_OBJECT (src, "Opening IMAQxd interface '%s' in listener mode", - src->device_name); - } - - /* open IMAQ interface */ - rval = IMAQdxOpenCamera (src->device_name, control_mode, &src->session); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_WARNING_OBJECT (src, "Failed to open camera '%s', will try resetting.", - src->device_name); - - rval = IMAQdxResetCamera (src->device_name, FALSE); - rval = IMAQdxOpenCamera (src->device_name, control_mode, &src->session); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to open IMAQdx interface %s: %s", src->device_name, - gst_niimaqdxsrc_get_imaq_error_str (rval)), - ("Failed to open camera interface %s", src->device_name)); - goto error; - } - } - - gst_niimaqdxsrc_list_attributes (src); - - GST_LOG_OBJECT (src, "Creating ring with %d buffers", src->ringbuffer_count); - - rval = IMAQdxConfigureAcquisition (src->session, TRUE, src->ringbuffer_count); - if (rval) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to create ring buffer: %s", - gst_niimaqdxsrc_get_imaq_error_str (rval)), - ("Failed to create ring buffer with %d buffers", - src->ringbuffer_count)); - goto error; - } - - if (src->is_jpeg) { - GST_DEBUG_OBJECT (src, "Source is JPEG, just use clock time"); - } else { - GST_LOG_OBJECT (src, "Registering callback functions"); - rval = - IMAQdxRegisterFrameDoneEvent (src->session, 1, - gst_niimaqdxsrc_frame_done_callback, src); - if (rval) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to register callback(s): %s", - gst_niimaqdxsrc_get_imaq_error_str (rval)), (NULL)); - goto error; - } - } - - gst_niimaqdxsrc_set_dx_attributes (src); - - return TRUE; - -error: - gst_niimaqdxsrc_close_interface (src); - - return FALSE;; - -} - -/** -* gst_niimaqdxsrc_stop: -* src: #GstBaseSrc instance -* -* Close resources opened by gst_niimaqdxsrc_start -* -* Returns: TRUE on success -*/ -static gboolean -gst_niimaqdxsrc_stop (GstBaseSrc * bsrc) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (bsrc); - IMAQdxError rval; - gboolean result = TRUE; - - /* stop IMAQ session */ - if (src->session_started) { - rval = IMAQdxStopAcquisition (src->session); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unable to stop acquisition: %s", - gst_niimaqdxsrc_get_imaq_error_str (rval)), (NULL)); - result = FALSE; - } - src->session_started = FALSE; - GST_DEBUG_OBJECT (src, "Acquisition stopped"); - } - - result &= gst_niimaqdxsrc_close_interface (src); - - gst_niimaqdxsrc_reset (src); - - return result; -} - -static gboolean -gst_niimaqdxsrc_query (GstBaseSrc * bsrc, GstQuery * query) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (bsrc); - gboolean res; - - switch (GST_QUERY_TYPE (query)) { - case GST_QUERY_LATENCY:{ - if (!src->session_started) { - GST_WARNING_OBJECT (src, "Can't give latency since device isn't open!"); - res = FALSE; - } else { - GstClockTime min_latency, max_latency; - /* TODO: this is a ballpark figure, estimate from FVAL times */ - min_latency = 33 * GST_MSECOND; - max_latency = 33 * GST_MSECOND * src->ringbuffer_count; - - GST_LOG_OBJECT (src, - "report latency min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT, - GST_TIME_ARGS (min_latency), GST_TIME_ARGS (max_latency)); - - gst_query_set_latency (query, TRUE, min_latency, max_latency); - - res = TRUE; - } - } - default: - res = - GST_BASE_SRC_CLASS (gst_niimaqdxsrc_parent_class)->query (bsrc, - query); - break; - } - - return res; -} - -static GstCaps * -gst_niimaqdxsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter_caps) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (bsrc); - GstCaps *caps; - - if (!src->session) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else - caps = gst_niimaqdxsrc_get_cam_caps (src); - - if (caps == NULL) { - GST_ERROR_OBJECT (src, "Unable to create caps"); - return NULL; - } - - GST_DEBUG_OBJECT (src, "get_caps, pre-filter=%" GST_PTR_FORMAT, caps); - - if (filter_caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter_caps); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, - "with filter %" GST_PTR_FORMAT ", post-filter=%" GST_PTR_FORMAT, - filter_caps, caps); - - return caps; -} - -static gboolean -gst_niimaqdxsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstNiImaqDxSrc *src = GST_NIIMAQDXSRC (bsrc); - GstStructure *structure; - const char *pixel_format; - int endianness; - - GST_DEBUG_OBJECT (src, "set_caps with caps=%" GST_PTR_FORMAT, caps); - - structure = gst_caps_get_structure (caps, 0); - - gst_structure_get_int (structure, "width", &src->width); - gst_structure_get_int (structure, "height", &src->height); - - pixel_format = gst_niimaqdxsrc_pixel_format_from_caps (caps, &endianness); - g_assert (pixel_format); - - src->caps_info = gst_niimaqdxsrc_get_caps_info (pixel_format, endianness); - - if (g_strcmp0 (pixel_format, "JPEG") == 0) { - src->is_jpeg = TRUE; - } else { - src->is_jpeg = FALSE; - } - - src->dx_row_stride = - gst_niimaqdxsrc_pixel_format_get_stride (pixel_format, endianness, - src->width); - - src->dx_framesize = src->dx_row_stride * src->height; - - src->gst_row_stride = - ROUND_UP_N (src->dx_row_stride, src->caps_info->row_multiple); - - src->gst_framesize = src->gst_row_stride * src->height; - - /* TODO: don't use default_alloc, app can change blocksize */ - gst_base_src_set_blocksize (bsrc, src->gst_framesize); - - if (src->temp_buffer) - g_free (src->temp_buffer); - src->temp_buffer = g_malloc (src->dx_framesize); - - GST_DEBUG ("Size %dx%d", src->width, src->height); - - GST_LOG_OBJECT (src, "Caps set, framesize=%d", src->dx_framesize); - - return TRUE; -} - -/** -* gst_niimaqdxsrc_close_interface: -* src: #GstNiImaqDxSrc instance -* -* Close IMAQ session and interface -* -*/ -static gboolean -gst_niimaqdxsrc_close_interface (GstNiImaqDxSrc * src) -{ - IMAQdxError rval; - gboolean result = TRUE; - - /* close IMAQ session and interface */ - if (src->session) { - rval = IMAQdxCloseCamera (src->session); - if (rval != IMAQdxErrorSuccess) { - gst_niimaqdxsrc_report_imaq_error (rval); - result = FALSE; - } else - GST_LOG_OBJECT (src, "IMAQdx session closed"); - src->session = 0; - } - - return result; -} - -/** -* plugin_init: -* plugin: #GstPlugin -* -* Initialize plugin by registering elements -* -* Returns: TRUE on success -*/ -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (niimaqdxsrc_debug, "niimaqdxsrc", 0, - "NI-IMAQdx interface"); - - /* we only have one element in this plugin */ - return gst_element_register (plugin, "niimaqdxsrc", GST_RANK_NONE, - GST_TYPE_NIIMAQDXSRC); - -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, niimaqdx, - "NI-IMAQdx source element", plugin_init, GST_PACKAGE_VERSION, - GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/sys/niimaqdx/gstniimaqdx.h b/sys/niimaqdx/gstniimaqdx.h deleted file mode 100644 index b65dcec..0000000 --- a/sys/niimaqdx/gstniimaqdx.h +++ /dev/null @@ -1,106 +0,0 @@ -/* GStreamer - * Copyright (C) <2006> Eric Jonas - * Copyright (C) <2006> Antoine Tremblay - * Copyright (C) 2013 United States Government, Joshua M. Doe - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GST_NIIMAQDXSRC_H__ -#define __GST_NIIMAQDXSRC_H__ - -#include -#include -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_NIIMAQDXSRC \ - (gst_niimaqdxsrc_get_type()) -#define GST_NIIMAQDXSRC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NIIMAQDXSRC,GstNiImaqDxSrc)) -#define GST_NIIMAQDXSRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NIIMAQDXSRC,GstNiImaqDxSrcClass)) -#define GST_IS_NIIMAQDXSRC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NIIMAQDXSRC)) -#define GST_IS_NIIMAQDXSRC_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NIIMAQDXSRC)) -#define GST_NIIMAQDXSRC_GET_CLASS(klass) \ - (G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_NIIMAQDXSRC, GstNiImaqDxSrcClass)) - -typedef struct _GstNiImaqDxSrc GstNiImaqDxSrc; -typedef struct _GstNiImaqDxSrcClass GstNiImaqDxSrcClass; - -typedef struct -{ - const char *pixel_format; - int endianness; - const char *gst_caps_string; - int bpp; - int depth; - int row_multiple; -} ImaqDxCapsInfo; - -struct _GstNiImaqDxSrc { - GstPushSrc element; - - /* properties */ - gchar *device_name; - gint ringbuffer_count; - gchar *attributes; - gboolean bayer_as_gray; - gboolean is_controller; - - /* image info */ - char pixel_format[IMAQDX_MAX_API_STRING_LENGTH]; - int width; - int height; - int dx_row_stride; - gint dx_framesize; - int gst_row_stride; - gint gst_framesize; - guint8 *temp_buffer; - const ImaqDxCapsInfo *caps_info; - gboolean is_jpeg; - - uInt32 cumbufnum; - gint64 n_dropped_frames; - - IMAQdxSession session; - - gboolean session_started; - - GAsyncQueue *time_queue; - - GstClock *clock; - GstClockTime stream_base; - GstClockTime unix_base; -}; - -struct _GstNiImaqDxSrcClass { - GstPushSrcClass parent_class; - - /* probed interfaces */ - GList *devices; -}; - -GType gst_niimaqdxsrc_get_type (void); - -G_END_DECLS - -#endif /* __GST_NIIMAQDXSRC_H__ */ diff --git a/sys/niimaqdx/win64/niimaqdx.def b/sys/niimaqdx/win64/niimaqdx.def deleted file mode 100644 index 21bb7e2..0000000 --- a/sys/niimaqdx/win64/niimaqdx.def +++ /dev/null @@ -1,92 +0,0 @@ -EXPORTS -IMAQdxAllocate -IMAQdxBenchmarkGenICamXMLLoad -IMAQdxCalculateBayerGains -IMAQdxCalculatePacketSize -IMAQdxCloseCamera -IMAQdxConfigureAcquisition -IMAQdxConfigureGrab -IMAQdxDebugAttributesToFile -IMAQdxDiscoverEthernetCameras -IMAQdxDispose -IMAQdxEnumerateAttributeValues -IMAQdxEnumerateAttributeValuesCW -IMAQdxEnumerateAttributes -IMAQdxEnumerateAttributes2 -IMAQdxEnumerateAttributes2CW -IMAQdxEnumerateAttributes3 -IMAQdxEnumerateAttributes3CW -IMAQdxEnumerateAttributesCW -IMAQdxEnumerateCameraFiles -IMAQdxEnumerateCameras -IMAQdxEnumerateCamerasCW -IMAQdxEnumerateVideoModes -IMAQdxEnumerateVideoModesCW -IMAQdxGetActionCommandPort -IMAQdxGetAttribute -IMAQdxGetAttributeCW -IMAQdxGetAttributeDescription -IMAQdxGetAttributeDescriptionCW -IMAQdxGetAttributeDisplayName -IMAQdxGetAttributeDisplayNameCW -IMAQdxGetAttributeIncrement -IMAQdxGetAttributeIncrementCW -IMAQdxGetAttributeMaximum -IMAQdxGetAttributeMaximumCW -IMAQdxGetAttributeMinimum -IMAQdxGetAttributeMinimumCW -IMAQdxGetAttributeRepresentation -IMAQdxGetAttributeTooltip -IMAQdxGetAttributeTooltipCW -IMAQdxGetAttributeType -IMAQdxGetAttributeUnits -IMAQdxGetAttributeUnitsCW -IMAQdxGetAttributeVisibility -IMAQdxGetCameraProperty -IMAQdxGetCameraStatus -IMAQdxGetDriverName -IMAQdxGetDriverName2 -IMAQdxGetDriverVersion -IMAQdxGetErrorString -IMAQdxGetErrorStringCW -IMAQdxGetFullyQualifiedAttributeName -IMAQdxGetImage -IMAQdxGetImageCW -IMAQdxGetImageData -IMAQdxGetImageDataCW -IMAQdxGetRawBufferSize -IMAQdxGrab -IMAQdxGrabCW -IMAQdxIsAttributeReadable -IMAQdxIsAttributeReadableCW -IMAQdxIsAttributeWritable -IMAQdxIsAttributeWritableCW -IMAQdxOpenCamera -IMAQdxReadAttributes -IMAQdxReadAttributesFromString -IMAQdxReadMemory -IMAQdxReadRegister -IMAQdxRegisterAttributeUpdatedEvent -IMAQdxRegisterFrameDoneEvent -IMAQdxRegisterPnpEvent -IMAQdxRenameInterface -IMAQdxResetCamera -IMAQdxResetEthernetCameraAddress -IMAQdxSequence -IMAQdxSequenceCW -IMAQdxSetAttribute -IMAQdxSetAttributeCW -IMAQdxSetAttributeFromParamInfo -IMAQdxSetAttributeFromVoidPtr -IMAQdxSnap -IMAQdxSnapCW -IMAQdxStartAcquisition -IMAQdxStopAcquisition -IMAQdxSwitchCameraDriver -IMAQdxUnconfigureAcquisition -IMAQdxValidateAcquisition -IMAQdxWriteAttributes -IMAQdxWriteAttributesToString -IMAQdxWriteMemory -IMAQdxWriteRegister -IMAQdxWriteSettingsToRegistry diff --git a/sys/niimaqdx/win64/niimaqdx.lib b/sys/niimaqdx/win64/niimaqdx.lib deleted file mode 100644 index 018a9ae..0000000 Binary files a/sys/niimaqdx/win64/niimaqdx.lib and /dev/null differ diff --git a/sys/phoenix/CMakeLists.txt b/sys/phoenix/CMakeLists.txt deleted file mode 100644 index 70a93a3..0000000 --- a/sys/phoenix/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstphoenixsrc.c) - -set (HEADERS - gstphoenixsrc.h) - -include_directories (AFTER - ${PHOENIX_INCLUDE_DIR}) - -set (libname gstphoenix) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${PHOENIX_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/phoenix/gstphoenixsrc.c b/sys/phoenix/gstphoenixsrc.c deleted file mode 100644 index fc91a65..0000000 --- a/sys/phoenix/gstphoenixsrc.c +++ /dev/null @@ -1,974 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstphoenixsrc - * - * The phoenixsrc element is a source for framegrabbers supported by the Active Silicon Phoenix driver. - * - * - * Example launch line - * |[ - * gst-launch -v phoenixsrc ! ffmpegcolorspace ! autovideosink - * ]| - * Shows video from the default Phoenix framegrabber - * - */ - -/* TODO: - * allow for use of onboard LUT (rare, since we usually want raw data) - * allow for colorspace conversions (again rare) - * test sending of API-provided buffers, using gst_memory_new_wrapped -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstphoenixsrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_phoenixsrc_debug); -#define GST_CAT_DEFAULT gst_phoenixsrc_debug - -/* prototypes */ -static void gst_phoenixsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_phoenixsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_phoenixsrc_dispose (GObject * object); -static void gst_phoenixsrc_finalize (GObject * object); - -static gboolean gst_phoenixsrc_start (GstBaseSrc * src); -static gboolean gst_phoenixsrc_stop (GstBaseSrc * src); -static GstCaps *gst_phoenixsrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_phoenixsrc_set_caps (GstBaseSrc * src, GstCaps * caps); - -static GstFlowReturn gst_phoenixsrc_create (GstPushSrc * src, GstBuffer ** buf); - -static GstCaps *gst_phoenixsrc_create_caps (GstPhoenixSrc * src); -enum -{ - PROP_0, - PROP_CAMERA_CONFIG_FILEPATH, - PROP_NUM_CAPTURE_BUFFERS, - PROP_BOARD, - PROP_CHANNEL -}; - -#define DEFAULT_PROP_CAMERA_CONFIG_FILEPATH NULL /* defaults to 640x480x8bpp */ -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 2 -#define DEFAULT_PROP_BOARD 0 -#define DEFAULT_PROP_CHANNEL 0 - -/* pad templates */ - -static GstStaticPadTemplate gst_phoenixsrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, RGB, xRGB, RGB_15, RGB_16 }") ";" - "video/x-bayer,format=(string){bggr,grbg,gbrg,rggb}," - "width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX];" - "video/x-bayer,format=(string){bggr16,grbg16,gbrg16,rggb16}," - "bpp=(int){10,12,14,16},endianness={1234,4321}," - "width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX]") - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstPhoenixSrc, gst_phoenixsrc, GST_TYPE_PUSH_SRC); - -static void -gst_phoenixsrc_class_init (GstPhoenixSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_phoenixsrc_set_property; - gobject_class->get_property = gst_phoenixsrc_get_property; - gobject_class->dispose = gst_phoenixsrc_dispose; - gobject_class->finalize = gst_phoenixsrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_phoenixsrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Active Silicon Phoenix Video Source", "Source/Video", - "Active Silicon Phoenix framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_phoenixsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_phoenixsrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_phoenixsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_phoenixsrc_set_caps); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_phoenixsrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_CAMERA_CONFIG_FILEPATH, - g_param_spec_string ("config-file", "Config file", - "Camera configuration filepath", DEFAULT_PROP_CAMERA_CONFIG_FILEPATH, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_uint ("board", "Board", - "Board number (0 for auto)", 0, 7, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CHANNEL, - g_param_spec_uint ("channel", "Channel", - "Channel number (0 for auto)", 0, 2, - DEFAULT_PROP_CHANNEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); -} - -static void -gst_phoenixsrc_init (GstPhoenixSrc * phoenixsrc) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (phoenixsrc), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (phoenixsrc), GST_FORMAT_TIME); - - /* initialize member variables */ - phoenixsrc->config_filepath = g_strdup (DEFAULT_PROP_CAMERA_CONFIG_FILEPATH); - phoenixsrc->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - - phoenixsrc->first_phoenix_ts = GST_CLOCK_TIME_NONE; - phoenixsrc->frame_start_times = - g_new (guint64, phoenixsrc->num_capture_buffers); - phoenixsrc->frame_end_times = - g_new (guint64, phoenixsrc->num_capture_buffers); - phoenixsrc->buffer_ready = FALSE; - phoenixsrc->timeout_occurred = FALSE; - phoenixsrc->fifo_overflow_occurred = FALSE; - - phoenixsrc->buffer_ready_count = 0; - phoenixsrc->buffer_processed_count = 0; - phoenixsrc->frame_end_count = 0; - phoenixsrc->frame_start_count = 0; - /*phoenixsrc->frame_count = 0; */ - - phoenixsrc->hCamera = 0; - - g_mutex_init (&phoenixsrc->mutex); - g_cond_init (&phoenixsrc->cond); -} - -void -gst_phoenixsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstPhoenixSrc *phoenixsrc; - - g_return_if_fail (GST_IS_PHOENIX_SRC (object)); - phoenixsrc = GST_PHOENIX_SRC (object); - - switch (property_id) { - case PROP_CAMERA_CONFIG_FILEPATH: - g_free (phoenixsrc->config_filepath); - phoenixsrc->config_filepath = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - if (phoenixsrc->acq_started) { - GST_ELEMENT_WARNING (phoenixsrc, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - phoenixsrc->num_capture_buffers = g_value_get_uint (value); - - g_free (phoenixsrc->frame_start_times); - phoenixsrc->frame_start_times = - g_new (guint64, phoenixsrc->num_capture_buffers); - - g_free (phoenixsrc->frame_end_times); - phoenixsrc->frame_end_times = - g_new (guint64, phoenixsrc->num_capture_buffers); - } - break; - case PROP_BOARD: - phoenixsrc->board = g_value_get_uint (value); - break; - case PROP_CHANNEL: - phoenixsrc->channel = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_phoenixsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstPhoenixSrc *phoenixsrc; - - g_return_if_fail (GST_IS_PHOENIX_SRC (object)); - phoenixsrc = GST_PHOENIX_SRC (object); - - switch (property_id) { - case PROP_CAMERA_CONFIG_FILEPATH: - g_value_set_string (value, phoenixsrc->config_filepath); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, phoenixsrc->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_uint (value, phoenixsrc->board); - break; - case PROP_CHANNEL: - g_value_set_uint (value, phoenixsrc->channel); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_phoenixsrc_dispose (GObject * object) -{ - GstPhoenixSrc *phoenixsrc; - - g_return_if_fail (GST_IS_PHOENIX_SRC (object)); - phoenixsrc = GST_PHOENIX_SRC (object); - - /* clean up as possible. may be called multiple times */ - - g_free (phoenixsrc->config_filepath); - - G_OBJECT_CLASS (gst_phoenixsrc_parent_class)->dispose (object); -} - -void -gst_phoenixsrc_finalize (GObject * object) -{ - GstPhoenixSrc *phoenixsrc; - - g_return_if_fail (GST_IS_PHOENIX_SRC (object)); - phoenixsrc = GST_PHOENIX_SRC (object); - - /* clean up object here */ - g_free (phoenixsrc->frame_start_times); - g_free (phoenixsrc->frame_end_times); - - G_OBJECT_CLASS (gst_phoenixsrc_parent_class)->finalize (object); -} - -static inline GstClockTime -gst_phoenix_get_timestamp (GstPhoenixSrc * phoenixsrc) -{ - ui32 dwParam; - guint64 timestamp; - - /* get time in microseconds from start of acquisition */ - /* TODO: check for rollover */ - PHX_ParameterGet (phoenixsrc->hCamera, PHX_EVENTCOUNT, &dwParam); - timestamp = (guint64) 1000 *dwParam; - - if (phoenixsrc->first_phoenix_ts == GST_CLOCK_TIME_NONE) { - phoenixsrc->first_phoenix_ts = timestamp; - } - return timestamp - phoenixsrc->first_phoenix_ts; -} - -/* Callback function to handle image capture events. */ -void -phx_callback (tHandle hCamera, ui32 dwMask, void *pvParams) -{ - GstPhoenixSrc *phoenixsrc = GST_PHOENIX_SRC (pvParams); - GstClockTime ct = gst_phoenix_get_timestamp (phoenixsrc); - gboolean signal_create_func = FALSE; - guint n; - - g_mutex_lock (&phoenixsrc->mutex); - - /* Note that more than one interrupt can be sent, so no "else if" */ - - /* called when frame valid signal goes high */ - if (PHX_INTRPT_FRAME_START & dwMask) { - /* FIXME: this will work until frames are dropped */ - n = phoenixsrc->frame_start_count % phoenixsrc->num_capture_buffers; - phoenixsrc->frame_start_times[n] = ct; - - phoenixsrc->frame_start_count++; - } - - /* called when frame valid signal goes low */ - if (PHX_INTRPT_FRAME_END & dwMask) { - /* FIXME: this will work until frames are dropped */ - n = (phoenixsrc->frame_end_count - 1) % phoenixsrc->num_capture_buffers; - phoenixsrc->frame_end_times[n] = ct; - - phoenixsrc->frame_end_count++; - } - - if (PHX_INTRPT_BUFFER_READY & dwMask) { - /* we have a buffer */ - phoenixsrc->buffer_ready = TRUE; - phoenixsrc->buffer_ready_count++; - signal_create_func = TRUE; - } - - if (PHX_INTRPT_TIMEOUT & dwMask) { - /* TODO: we could offer to try and ABORT then re-START capture */ - phoenixsrc->timeout_occurred = TRUE; - signal_create_func = TRUE; - } - - if (PHX_INTRPT_FIFO_OVERFLOW & dwMask) { - phoenixsrc->fifo_overflow_occurred = TRUE; - signal_create_func = TRUE; - } - - - - if (signal_create_func) - g_cond_signal (&phoenixsrc->cond); - g_mutex_unlock (&phoenixsrc->mutex); - /* after unlocking, _create will check for these errors and copy data */ -} - -static gboolean -gst_phoenixsrc_start (GstBaseSrc * src) -{ - GstPhoenixSrc *phoenixsrc = GST_PHOENIX_SRC (src); - etStat eStat = PHX_OK; /* Status variable */ - etParamValue eParamValue = PHX_INVALID_PARAMVALUE; - ui32 dwParamValue = 0; - guint eCamConfig; - - GST_DEBUG_OBJECT (phoenixsrc, "start"); - - if (phoenixsrc->config_filepath == NULL) { - GST_WARNING_OBJECT (phoenixsrc, - "No config file set, using default 640x480x8bpp"); - } else if (!g_file_test (phoenixsrc->config_filepath, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (phoenixsrc, RESOURCE, NOT_FOUND, - ("Camera config file does not exist: %s", phoenixsrc->config_filepath), - (NULL)); - goto Error; - } - - /* TODO: hacky, use enums or something */ - eCamConfig = PHX_DIGITAL; - switch (phoenixsrc->board) { - case 0: - eCamConfig |= PHX_BOARD_AUTO; - break; - case 1: - eCamConfig |= PHX_BOARD1; - break; - case 2: - eCamConfig |= PHX_BOARD2; - break; - case 3: - eCamConfig |= PHX_BOARD3; - break; - case 4: - eCamConfig |= PHX_BOARD4; - break; - case 5: - eCamConfig |= PHX_BOARD5; - break; - case 6: - eCamConfig |= PHX_BOARD6; - break; - case 7: - eCamConfig |= PHX_BOARD7; - break; - default: - g_assert_not_reached (); - } - - switch (phoenixsrc->channel) { - case 0: - eCamConfig |= PHX_CHANNEL_AUTO; - break; - case 1: - eCamConfig |= PHX_CHANNEL1; - break; - case 2: - eCamConfig |= PHX_CHANNEL2; - break; - } - - /* Initialize board */ - eStat = - PHX_CameraConfigLoad (&phoenixsrc->hCamera, phoenixsrc->config_filepath, - (etCamConfigLoad) eCamConfig, PHX_ErrHandlerDefault); - if (eStat != PHX_OK) { - GST_ELEMENT_ERROR (phoenixsrc, LIBRARY, INIT, (NULL), (NULL)); - goto Error; - } - - /* capture frames continuously */ - eParamValue = PHX_ENABLE; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_ACQ_CONTINUOUS, &eParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - - /* capture in blocking fashion, i.e. don't overwrite un-processed buffers */ - eParamValue = PHX_DISABLE; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_ACQ_BLOCKING, &eParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - - /* use event counter to count time from start of acquisition */ - eParamValue = PHX_EVENTCOUNT_TIME; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_EVENTCOUNT_SRC, &eParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - eParamValue = PHX_EVENTGATE_ACQ; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_EVENTGATE_SRC, &eParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - - /* Tell Phoenix to use N buffers. */ - eParamValue = phoenixsrc->num_capture_buffers; - PHX_ParameterSet (phoenixsrc->hCamera, PHX_ACQ_NUM_IMAGES, &eParamValue); - - /* Setup a one second timeout value (milliseconds) */ - dwParamValue = 1000; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_TIMEOUT_DMA, - (void *) &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - - /* The BUFFER_READY interrupt is already enabled by default, - * but we must enable other interrupts here. */ - eParamValue = - PHX_INTRPT_TIMEOUT | PHX_INTRPT_FIFO_OVERFLOW | PHX_INTRPT_FRAME_END | - PHX_INTRPT_FRAME_START; - eStat = - PHX_ParameterSet (phoenixsrc->hCamera, PHX_INTRPT_SET, - (void *) &eParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - - return TRUE; - -ResourceSettingsError: - GST_ELEMENT_ERROR (phoenixsrc, RESOURCE, SETTINGS, - (("Failed to get Phoenix parameters.")), (NULL)); - -Error: - /* Now cease all captures */ - if (phoenixsrc->hCamera) - PHX_Acquire (phoenixsrc->hCamera, PHX_ABORT, NULL); - - /* TODO Free all the user allocated memory */ - //psImageBuff = pasImageBuffs; - //if ( NULL != pasImageBuffs ) { - // while ( NULL != psImageBuff->pvAddress ) { - // free( psImageBuff->pvAddress ); - // psImageBuff++; - // } - // free( pasImageBuffs ); - //} - - /* Release the Phoenix board */ - if (phoenixsrc->hCamera) - PHX_CameraRelease (&phoenixsrc->hCamera); - - return FALSE; -} - -static gboolean -gst_phoenixsrc_stop (GstBaseSrc * src) -{ - GstPhoenixSrc *phoenixsrc = GST_PHOENIX_SRC (src); - - GST_DEBUG_OBJECT (phoenixsrc, "stop"); - - if (phoenixsrc->hCamera) { - /* Stop the acquisition */ - /* TODO: should we use PHX_STOP (finished current image) instead? */ - PHX_Acquire (phoenixsrc->hCamera, PHX_ABORT, NULL); - - /* Deallocates hardware and software resources, setting handle to null */ - PHX_CameraRelease (&phoenixsrc->hCamera); - } - - phoenixsrc->dropped_frame_count = 0; - /*phoenixsrc->last_time_code = -1; */ - - return TRUE; -} - -static GstCaps * -gst_phoenixsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstPhoenixSrc *src = GST_PHOENIX_SRC (bsrc); - etStat eStat = PHX_OK; /* Status variable */ - etParamValue eParamValue = PHX_INVALID_PARAMVALUE; - ui32 dwParamValue = 0; - guint32 phx_format; - gint width, height; - gint bpp, depth, endianness; - GstVideoFormat videoFormat; - gboolean is_gray16 = FALSE, is_bayer = FALSE; - GstVideoInfo vinfo; - GstCaps *caps; - - if (!src->hCamera) { - return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } - - /* Create video info */ - gst_video_info_init (&vinfo); - - /* Get format (mono, Bayer, RBG, etc.) */ - eStat = PHX_ParameterGet (src->hCamera, PHX_DST_FORMAT, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - phx_format = dwParamValue; - - /* Get endianness */ - eStat = PHX_ParameterGet (src->hCamera, PHX_DST_ENDIAN, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - endianness = - (dwParamValue == PHX_DST_LITTLE_ENDIAN) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; - - /* get width */ - eStat = - PHX_ParameterGet (src->hCamera, PHX_ROI_XLENGTH_SCALED, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - width = dwParamValue; - - /* get height */ - eStat = - PHX_ParameterGet (src->hCamera, PHX_ROI_YLENGTH_SCALED, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - height = dwParamValue; - - switch (phx_format) { - case PHX_DST_FORMAT_Y8: - videoFormat = GST_VIDEO_FORMAT_GRAY8; - break; - case PHX_DST_FORMAT_Y10: - bpp = 10; - is_gray16 = TRUE; - break; - case PHX_DST_FORMAT_Y12: - bpp = 12; - is_gray16 = TRUE; - break; - case PHX_DST_FORMAT_Y14: - bpp = 14; - is_gray16 = TRUE; - break; - case PHX_DST_FORMAT_Y16: - bpp = 16; - is_gray16 = TRUE; - break; - case PHX_DST_FORMAT_BAY8: - bpp = 8; - depth = 8; - is_bayer = TRUE; - break; - case PHX_DST_FORMAT_BAY10: - bpp = 10; - depth = 16; - is_bayer = TRUE; - break; - case PHX_DST_FORMAT_BAY12: - bpp = 12; - depth = 16; - is_bayer = TRUE; - break; - case PHX_DST_FORMAT_BAY14: - bpp = 14; - depth = 16; - is_bayer = TRUE; - break; - case PHX_DST_FORMAT_BAY16: - bpp = 16; - depth = 16; - is_bayer = TRUE; - break; - case PHX_DST_FORMAT_RGB15: - videoFormat = GST_VIDEO_FORMAT_RGB15; - break; - case PHX_DST_FORMAT_RGB16: - videoFormat = GST_VIDEO_FORMAT_RGB16; - break; - case PHX_DST_FORMAT_RGB24: - videoFormat = GST_VIDEO_FORMAT_RGB; - break; - case PHX_DST_FORMAT_RGB32: /* FIXME: what is the format of this? */ - case PHX_DST_FORMAT_XRGB32: - videoFormat = GST_VIDEO_FORMAT_xRGB; - break; - default: - videoFormat = GST_VIDEO_FORMAT_UNKNOWN; - } - - if (is_gray16) - videoFormat = (endianness == G_LITTLE_ENDIAN) ? - GST_VIDEO_FORMAT_GRAY16_LE : GST_VIDEO_FORMAT_GRAY16_BE; - - if (is_bayer) { - const gchar *bay_fmt; - eStat = PHX_ParameterGet (src->hCamera, PHX_CAM_SRC_COL, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - switch (dwParamValue) { - case PHX_CAM_SRC_BAY_RGGB: - bay_fmt = (depth == 16) ? "rggb16" : "rggb"; - break; - case PHX_CAM_SRC_BAY_GRBG: - bay_fmt = (depth == 16) ? "grbg16" : "grbg"; - break; - case PHX_CAM_SRC_BAY_GBRG: - bay_fmt = (depth == 16) ? "gbrg16" : "gbrg"; - break; - case PHX_CAM_SRC_BAY_BGGR: - bay_fmt = (depth == 16) ? "bggr16" : "bggr"; - break; - default: - GST_ERROR_OBJECT (src, "Unknown PHX_CAM_SRC_COL=%d", dwParamValue); - goto Error; - } - - if (depth == 8) { - caps = gst_caps_new_simple ("video/x-bayer", - "format", G_TYPE_STRING, bay_fmt, - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); - } else if (depth == 16) { - caps = gst_caps_new_simple ("video/x-bayer", - "format", G_TYPE_STRING, bay_fmt, - "bpp", G_TYPE_INT, bpp, - "endianness", G_TYPE_INT, endianness, - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); - } - } else if (videoFormat != GST_VIDEO_FORMAT_UNKNOWN) { - gst_video_info_set_format (&vinfo, videoFormat, width, height); - caps = gst_video_info_to_caps (&vinfo); - - if (is_gray16) { - GValue val = G_VALUE_INIT; - GstStructure *s = gst_caps_get_structure (caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, bpp); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - (("Unknown or unsupported color format.")), (NULL)); - goto Error; - } - - /* get buffer size; width (in bytes) and height (in lines) */ - eStat = PHX_ParameterGet (src->hCamera, PHX_BUF_DST_XLENGTH, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - src->phx_stride = dwParamValue; - eStat = PHX_ParameterGet (src->hCamera, PHX_BUF_DST_YLENGTH, &dwParamValue); - if (PHX_OK != eStat) - goto ResourceSettingsError; - /* TODO: should we be using PHX_BUF_DST_YLENGTH or PHX_ROI_YLENGTH_SCALED - for height? */ - g_assert (dwParamValue == height); - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; - -ResourceSettingsError: - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - (("Failed to get Phoenix parameters.")), (NULL)); - -Error: - return NULL; -} - -static gboolean -gst_phoenixsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstPhoenixSrc *src = GST_PHOENIX_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (g_str_equal ("video/x-bayer", gst_structure_get_name (s))) { - gint width; - const gchar *format; - gst_structure_get_int (s, "width", &width); - gst_structure_get_int (s, "height", &src->height); - format = gst_structure_get_string (s, "format"); - if (g_str_has_suffix (format, "16")) - src->gst_stride = GST_ROUND_UP_4 (width * 2); - else - src->gst_stride = GST_ROUND_UP_4 (width); - } else if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - src->height = vinfo.height; - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static guint -gst_phoenixsrc_get_fpga_temperature (GstPhoenixSrc * src) -{ - etStat eStat = PHX_OK; /* Phoenix status variable */ - ui32 fpga_temp = 0; /* Phoenix Get/Set intermediate variable */ - eStat = PHX_ParameterGet (src->hCamera, PHX_FPGA_CORE_TEMP, &fpga_temp); - if (PHX_OK != eStat) { - GST_WARNING_OBJECT (src, "Failed to query FPGA temperature"); - return 0; - } - return fpga_temp; -} - -static void -gst_phoenixsrc_log_fpga_temperature (GstPhoenixSrc * src) -{ - static FILE *temperature_file = NULL; - static gint64 temp_log_last_time = 0; - - if (g_getenv ("GST_PHOENIX_FPGA_TEMP_LOG")) { - if (temperature_file == NULL) { - const char *envvar = g_getenv ("GST_PHOENIX_FPGA_TEMP_LOG"); - gboolean write_header; - gchar *log_filename; - if (atoi (envvar) == 1) { - GDateTime *dt = g_date_time_new_now_local (); - log_filename = - g_date_time_format (dt, "phoenix_fgpa_temp_%Y%m%d_%H%M%S.csv"); - g_date_time_unref (dt); - } else { - log_filename = g_strdup (envvar); - } - - write_header = !g_file_test (log_filename, G_FILE_TEST_EXISTS); - - GST_DEBUG_OBJECT (src, "Opening FPGA temp log file (%s)", log_filename); - temperature_file = fopen (log_filename, "a"); - if (!temperature_file) { - GST_ERROR_OBJECT (src, "Failed to open log file"); - return; - } - g_free (log_filename); - - if (write_header) { - fprintf (temperature_file, "IsoTime, UnixTime, KayaFpgaTemp\n"); - } - } - - if (temperature_file && g_get_real_time () - temp_log_last_time >= 1000000) { - GDateTime *dt = g_date_time_new_now_local (); - gchar *time_str = g_date_time_format (dt, "%Y-%m-%dT%H:%M:%S, %s"); - float fg_temp = gst_phoenixsrc_get_fpga_temperature (src); - GST_DEBUG_OBJECT (src, "FPGA temp: %,3f", fg_temp); - fprintf (temperature_file, "%s, %.3f\n", time_str, fg_temp); - fflush (temperature_file); - g_date_time_unref (dt); - g_free (time_str); - temp_log_last_time = g_get_real_time (); - } - } -} - -static GstFlowReturn -gst_phoenixsrc_create (GstPushSrc * src, GstBuffer ** buf) -{ - GstPhoenixSrc *phoenixsrc = GST_PHOENIX_SRC (src); - etStat eStat = PHX_OK; /* Phoenix status variable */ - ui32 dwParamValue = 0; /* Phoenix Get/Set intermediate variable */ - stImageBuff phx_buffer; - guint dropped_frame_count = 0; - guint new_dropped_frames; - gint i; - guint n; - GstMapInfo minfo; - - GST_LOG_OBJECT (src, "create"); - - gst_phoenixsrc_log_fpga_temperature (src); - - /* Start acquisition */ - if (!phoenixsrc->acq_started) { - GST_LOG_OBJECT (src, "starting acquisition"); - - /* make class instance pointer available to the callback, and flush cache */ - PHX_ParameterSet (phoenixsrc->hCamera, - PHX_EVENT_CONTEXT | PHX_CACHE_FLUSH, (void *) phoenixsrc); - - /* Now start our capture */ - eStat = PHX_Acquire (phoenixsrc->hCamera, PHX_START, (void *) phx_callback); - if (PHX_OK != eStat) { - GST_ELEMENT_ERROR (phoenixsrc, RESOURCE, FAILED, - (("Failed to start acquisition.")), (NULL)); - return GST_FLOW_ERROR; /* TODO: make sure _stop is called if this happens to release resources */ - } - phoenixsrc->acq_started = TRUE; - } - - /* about to read/write variables modified by phx_callback */ - g_mutex_lock (&phoenixsrc->mutex); - - /* wait for callback (we should always get at least a timeout( */ - g_cond_wait (&phoenixsrc->cond, &phoenixsrc->mutex); - - if (phoenixsrc->fifo_overflow_occurred) { - /* TODO: we could offer to try and ABORT then re-START capture */ - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Acquisition failure due to FIFO overflow.")), (NULL)); - g_mutex_unlock (&phoenixsrc->mutex); - return GST_FLOW_ERROR; - } - - if (phoenixsrc->timeout_occurred) { - /* TODO: we could offer to try and ABORT then re-START capture */ - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Acquisition failure due to timeout.")), (NULL)); - g_mutex_unlock (&phoenixsrc->mutex); - return GST_FLOW_ERROR; - } - - if (!phoenixsrc->buffer_ready) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("You should not see this error, something very bad happened.")), - (NULL)); - g_mutex_unlock (&phoenixsrc->mutex); - return GST_FLOW_ERROR; - } - - GST_LOG_OBJECT (phoenixsrc, - "Processing new buffer %d (Frame start: %d), ready-processed = %d", - phoenixsrc->buffer_ready_count, phoenixsrc->frame_start_count, - phoenixsrc->buffer_ready_count - phoenixsrc->buffer_processed_count); - phoenixsrc->buffer_ready = FALSE; - - /* frame_start is always >= buffer_ready */ - dropped_frame_count = - phoenixsrc->frame_start_count - phoenixsrc->buffer_ready_count; - - g_mutex_unlock (&phoenixsrc->mutex); - - eStat = PHX_Acquire (phoenixsrc->hCamera, PHX_BUFFER_GET, &phx_buffer); - if (PHX_OK != eStat) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Failed to get buffer.")), (NULL)); - return GST_FLOW_ERROR; - } - - /* TODO: use allocator or use from Phoenix pool */ - *buf = gst_buffer_new_and_alloc (phoenixsrc->height * phoenixsrc->gst_stride); - - /* Copy image to buffer from surface TODO: use orc_memcpy */ - gst_buffer_map (*buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (phoenixsrc, - "GstBuffer size=%d, gst_stride=%d, phx_stride=%d", minfo.size, - phoenixsrc->gst_stride, phoenixsrc->phx_stride); - for (i = 0; i < phoenixsrc->height; i++) { - memcpy (minfo.data + i * phoenixsrc->gst_stride, - ((guint8 *) phx_buffer.pvAddress) + i * phoenixsrc->phx_stride, - phoenixsrc->gst_stride); - } - gst_buffer_unmap (*buf, &minfo); - - /* Having processed the data, release the buffer ready for further image data */ - eStat = PHX_Acquire (phoenixsrc->hCamera, PHX_BUFFER_RELEASE, NULL); - phoenixsrc->buffer_processed_count++; - - /* check for dropped frames (can only detect more than one) */ - new_dropped_frames = dropped_frame_count - phoenixsrc->dropped_frame_count; - if (new_dropped_frames > 0) { - phoenixsrc->dropped_frame_count = dropped_frame_count; - GST_WARNING ("Dropped %d frames (%d total)", new_dropped_frames, - phoenixsrc->dropped_frame_count); - /* TODO: emit message here about dropped frames */ - } - - /* use time from capture board */ - n = (phoenixsrc->buffer_processed_count - - 1) % phoenixsrc->num_capture_buffers; - GST_BUFFER_TIMESTAMP (*buf) = phoenixsrc->frame_start_times[n]; - GST_BUFFER_DURATION (*buf) = - GST_CLOCK_DIFF (phoenixsrc->frame_start_times[n], - phoenixsrc->frame_end_times[n]); - GST_BUFFER_OFFSET (*buf) = phoenixsrc->buffer_processed_count - 1; - GST_BUFFER_OFFSET_END (*buf) = GST_BUFFER_OFFSET (*buf); - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_phoenixsrc_debug, "phoenixsrc", 0, - "debug category for phoenixsrc element"); - gst_element_register (plugin, "phoenixsrc", GST_RANK_NONE, - gst_phoenixsrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - phoenix, - "Phoenix frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/phoenix/gstphoenixsrc.h b/sys/phoenix/gstphoenixsrc.h deleted file mode 100644 index 1bc7fc2..0000000 --- a/sys/phoenix/gstphoenixsrc.h +++ /dev/null @@ -1,96 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_PHOENIX_SRC_H_ -#define _GST_PHOENIX_SRC_H_ - -#include - -// TODO: if/elif for linux/mac/etc -#define _PHX_WIN32 -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PHOENIX_SRC (gst_phoenixsrc_get_type()) -#define GST_PHOENIX_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PHOENIX_SRC,GstPhoenixSrc)) -#define GST_PHOENIX_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PHOENIX_SRC,GstPhoenixSrcClass)) -#define GST_IS_PHOENIX_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PHOENIX_SRC)) -#define GST_IS_PHOENIX_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PHOENIX_SRC)) - -typedef struct _GstPhoenixSrc GstPhoenixSrc; -typedef struct _GstPhoenixSrcClass GstPhoenixSrcClass; - -/** -* GstPhoenixSrcConnector: -* @MC_Connector_VID<1..16>: channel is linked to camera at the VID<1..16> input -* @MC_Connector_YC: channel is linked to a camera at the YC input -* -* -* Identifies the connector that the camera is connected to. -*/ -typedef enum { - -} GstPhoenixSrcConnector; - -struct _GstPhoenixSrc -{ - GstPushSrc base_phoenixsrc; - - gint dropped_frame_count; - gboolean acq_started; - - /* camera handle */ - tHandle hCamera; - - /* properties */ - gchar *config_filepath; - guint num_capture_buffers; - guint board; - guint channel; - - GstClockTime first_phoenix_ts; - guint64 *frame_start_times; - guint64 *frame_end_times; - gboolean buffer_ready; - guint buffer_ready_count; - guint frame_start_count; - guint frame_end_count; - guint buffer_processed_count; - gboolean timeout_occurred; - gboolean fifo_overflow_occurred; - - gint height; - gint gst_stride; - guint phx_stride; - - GMutex mutex; - GCond cond; -}; - -struct _GstPhoenixSrcClass -{ - GstPushSrcClass base_phoenixsrc_class; -}; - -GType gst_phoenixsrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/pixci/CMakeLists.txt b/sys/pixci/CMakeLists.txt deleted file mode 100644 index 8659a74..0000000 --- a/sys/pixci/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set (SOURCES - gstpixcisrc.c) - -set (HEADERS - gstpixcisrc.h) - -include_directories (AFTER - ${XCLIB_INCLUDE_DIR}) - -set (libname gstpixci) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${XCLIB_LIBRARIES}) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/pixci/gstpixcisrc.c b/sys/pixci/gstpixcisrc.c deleted file mode 100644 index bac6ef1..0000000 --- a/sys/pixci/gstpixcisrc.c +++ /dev/null @@ -1,796 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstpixcisrc - * - * The pixcisrc element is a source for EPIX PIXCI framegrabbers supported by EPIX XCLIB. - * - * - * Example launch line - * |[ - * gst-launch -v pixcisrc ! ffmpegcolorspace ! autovideosink - * ]| - * Shows video from the default Pixci framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstpixcisrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_pixcisrc_debug); -#define GST_CAT_DEFAULT gst_pixcisrc_debug - -/* prototypes */ -static void gst_pixcisrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_pixcisrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_pixcisrc_dispose (GObject * object); -static void gst_pixcisrc_finalize (GObject * object); - -static gboolean gst_pixcisrc_start (GstBaseSrc * src); -static gboolean gst_pixcisrc_stop (GstBaseSrc * src); -static GstCaps *gst_pixcisrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_pixcisrc_set_caps (GstBaseSrc * src, GstCaps * caps); - -static GstFlowReturn gst_pixcisrc_create (GstPushSrc * src, GstBuffer ** buf); - -static GstCaps *gst_pixcisrc_create_caps (GstPixciSrc * src); -enum -{ - PROP_0, - PROP_FORMAT_NAME, - PROP_FORMAT_FILE, - PROP_DRIVER_PARAMS, - PROP_NUM_CAPTURE_BUFFERS, - PROP_BOARD, - PROP_CHANNEL, - PROP_TIMEOUT -}; - -#define DEFAULT_PROP_FORMAT_NAME GST_PIXCI_VIDEO_FORMAT_RS_170 -#define DEFAULT_PROP_FORMAT_FILE "" -#define DEFAULT_PROP_DRIVER_PARAMS "" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 2 -#define DEFAULT_PROP_BOARD 0 -#define DEFAULT_PROP_CHANNEL 0 -#define DEFAULT_PROP_TIMEOUT 0 - -/* pad templates */ - -static GstStaticPadTemplate gst_pixcisrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ GRAY8, GRAY16_LE, GRAY16_BE }")) - ); - - -#define GST_TYPE_PIXCI_VIDEO_FORMAT (gst_pixci_video_format_get_type()) -static GType -gst_pixci_video_format_get_type (void) -{ - static GType pixci_video_format_type = 0; - static const GEnumValue pixci_video_format[] = { - {GST_PIXCI_VIDEO_FORMAT_CCIR, "CCIR", - "CCIR composite video, capturing 720 pixels per line, 574 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_CCIR_SQR, "CCIR(SQR)", - "CCIR composite video, capturing 768 pixels per line, 576 lines, monochrome grey level pixels, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC, "NTSC", - "NTSC composite video, capturing 720 pixels per line, 480 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC_4_43, "NTSC(4.43)", - "NTSC(4.43) composite video, capturing 720 pixels per line, 480 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC_J, "NTSC(J)", - "NTSC(J) composite video, capturing 720 pixels per line, 480 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC_SQR, "NTSC(SQR)", - "NTSC composite video, capturing 640 pixels per line, 480 lines, color YCrCb pixels using the High Density BNC connector closest to the S-Video connector, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC_YC, "NTSC/YC", - "NTSC S-Video, capturing 720 pixels per line, 480 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_NTSC_YC_SQR, "NTSC/YC(SQR)", - "NTSC S-Video, capturing 640 pixels per line, 480 lines, color YCrCb pixels using the S-Video connector, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_PAL, "PAL", - "PAL (B,D,G,H,I) composite video, capturing 720 pixels per line, 576 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_60, "PAL(60)", - "PAL(60) composite video, capturing 720 pixels per line, 576 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_M, "PAL(M)", - "PAL(M) composite video, capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_M_YC, "PAL(M)/YC", - "PAL(M) S-VIDEO (Super VHS), capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_N, "PAL(N)", - "PAL(N) composite video, capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_N_YC, "PAL(N)/YC", - "PAL(N) S-VIDEO (Super VHS), capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_SQR, "PAL(SQR)", - "PAL (B,D,G,H,I) composite video, capturing 768 pixels per line, 576 lines, color YCrCb pixels, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_YC, "PAL/YC", - "PAL (B,D,G,H,I) S-Video, capturing 720 pixels per line, 576 lines, color YCrCb pixels."}, - {GST_PIXCI_VIDEO_FORMAT_PAL_YC_SQR, "PAL/YC(SQR)", - "PAL (B,D,G,H,I) S-Video, capturing 768 pixels per line, 576 lines, color YCrCb pixels using the S-Video connector, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_RS_170, "RS-170", - "RS-170 composite video, capturing 720 pixels per line, 480 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_RS_170_SQR, "RS-170(SQR)", - "RS-170 composite video, capturing 640 pixels per line, 480 lines, monochrome grey level pixels using the High Density BNC connector closest to the S-Video connector, yielding pixels with a 1:1 aspect ratio."}, - {GST_PIXCI_VIDEO_FORMAT_RS343_875i_60Hz, "RS343 875i 60Hz", - "Composite interlaced RS-343 video, 875 total lines per frame, 60 Hz, capturing 1332 pixels per line, 806 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_RS343_875i_60Hz_RGB, "RS343 875i 60Hz RGB", - "Interlaced RS-343 RGB component video, composite sync on green, 875 total lines per frame, 60 Hz, capturing 1332 pixels per line, 806 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_SECAM, "SECAM", - "SECAM composite video, capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_SECAM_YC, "SECAM/YC", - "SECAM S-VIDEO (Super VHS), capturing 920 pixels per line, 576 lines, color YCrCb or color RGB."}, - {GST_PIXCI_VIDEO_FORMAT_SVGA_800x600_60Hz_RGB, "SVGA 800x600 60Hz RGB", - "Progressive RGB+HSYNC+VSYNC component SVGA video, 60.371 Hz, capturing 800 pixels per line, 600 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_SXGA_1280x1024_60Hz_RGB, "SXGA 1280x1024 60Hz RGB", - "Progressive RGB+HSYNC+VSYNC component SXGA video, 60.02 Hz, capturing 1280 pixels per line, 1024 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_VGA_640x480_60Hz_RGB, "VGA 640x480 60Hz RGB", - "Progressive RGB+HSYNC+VSYNC component VGA video, 59.94 Hz, capturing 640 pixels per line, 480 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_50Hz, "Video 1280x720p 50Hz", - "Composite progressive video, 50 Hz, capturing 1280 pixels per line, 720 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_50Hz_RGB, - "Video 1280x720p 50Hz RGB", - "Progressive RGB component video, composite sync on green, 50 Hz, capturing 1280 pixels per line, 720 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_60Hz, "Video 1280x720p 60Hz", - "Composite progressive video, 60 Hz, capturing 1280 pixels per line, 720 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_60Hz_RGB, - "Video 1280x720p 60Hz RGB", - "Progressive RGB component video, composite sync on green, 60 Hz, capturing 1280 pixels per line, 720 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_50Hz, "Video 1920x1080i 50Hz", - "Composite interlaced video, 50 Hz, capturing 1920 pixels per line, 1080 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_50Hz_RGB, - "Video 1920x1080i 50Hz RGB", - "Interlaced RGB component video, composite sync on green, 50 Hz, capturing 1920 pixels per line, 1080 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_60Hz, "Video 1920x1080i 60Hz", - "Composite interlaced video, 60 Hz, capturing 1920 pixels per line, 1080 lines, monochrome grey level pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_60Hz_RGB, - "Video 1920x1080i 60Hz RGB", - "Interlaced RGB component video, composite sync on green, 60 Hz, capturing 1920 pixels per line, 1080 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz, "Video 720x480i 60Hz", - "Composite interlaced video, 525 total lines per frame, 60 Hz, capturing 720 pixels per line, 480 lines, monochrome grey level pixels. Same as 'RS-170'."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_Color, - "Video 720x480i 60Hz Color", - "Composite video, capturing 720 pixels per line, 480 lines, color YCrCb pixels. Same as 'NTSC'."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_RGB, "Video 720x480i 60Hz RGB", - "Interlaced RGB component video, composite sync on green, 525 total lines per frame, 60 Hz, capturing 720 pixels per line, 480 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_Y_Color, - "Video 720x480i 60Hz Y/Color", - "NTSC S-Video, capturing 720 pixels per line, 480 lines, color YCrCb pixels. Same as 'NTSC/YC'."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz, "Video 720x576i 50Hz", - "Composite interlaced video, 625 total lines per frame, 50 Hz, capturing 720 pixels per line, 576 lines, monochrome grey level pixels. Same as 'CCIR'."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_Color, - "Video 720x576i 50Hz Color", - "Composite video, capturing 720 pixels per line, 576 lines, color YCrCb pixels. Same as 'PAL'."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_RGB, "Video 720x576i 50Hz RGB", - "Interlaced RGB component video, composite sync on green, 625 total lines per frame, 50 Hz, capturing 720 pixels per line, 576 lines, RGB color pixels."}, - {GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_Y_Color, - "Video 720x576i 50Hz Y/Color", - "PAL (B,D,G,H,I) S-Video, capturing 720 pixels per line, 576 lines, color YCrCb pixels. Same as 'PAL/YC'."}, - {GST_PIXCI_VIDEO_FORMAT_XGA_1024x768_60Hz_RGB, "XGA 1024x768 60Hz RGB", - "Progressive RGB+HSYNC+VSYNC component XGA video, 60 Hz, capturing 1024 pixels per line, 768 lines, RGB color pixels."}, - {0, NULL, NULL}, - }; - - if (!pixci_video_format_type) { - pixci_video_format_type = - g_enum_register_static ("GstPixciVideoFormat", pixci_video_format); - } - return pixci_video_format_type; -} - - -/* class initialization */ - -G_DEFINE_TYPE (GstPixciSrc, gst_pixcisrc, GST_TYPE_PUSH_SRC); - -static void -gst_pixcisrc_class_init (GstPixciSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_pixcisrc_set_property; - gobject_class->get_property = gst_pixcisrc_get_property; - gobject_class->dispose = gst_pixcisrc_dispose; - gobject_class->finalize = gst_pixcisrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_pixcisrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "EPIX PIXCI Video Source", "Source/Video", - "EPIX PIXCI framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_pixcisrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_pixcisrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_pixcisrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_pixcisrc_set_caps); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_pixcisrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_FORMAT_NAME, - g_param_spec_enum ("format-name", "Format name", - "Video format of the camera. If set, format-file will override this.", - GST_TYPE_PIXCI_VIDEO_FORMAT, DEFAULT_PROP_FORMAT_NAME, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | - GST_PARAM_MUTABLE_READY)); - g_object_class_install_property (gobject_class, PROP_FORMAT_FILE, - g_param_spec_string ("format-file", "Format file", - "Filepath of the video file for the selected camera " - "(if set this will override format-name)", DEFAULT_PROP_FORMAT_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DRIVER_PARAMS, - g_param_spec_string ("driver-params", "Driver parameters", - "Driver parameters to use when initializing XCLIB", - DEFAULT_PROP_DRIVER_PARAMS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BOARD, - g_param_spec_uint ("board", "Board", "Board number (0 for auto)", 0, 7, - DEFAULT_PROP_BOARD, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CHANNEL, - g_param_spec_uint ("channel", "Channel", "Channel number (0 for auto)", 0, - 2, DEFAULT_PROP_CHANNEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TIMEOUT, - g_param_spec_uint ("timeout", "Timeout", - "Timeout in milliseconds (0 for default)", 0, G_MAXUINT, - DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); -} - -static void -gst_pixcisrc_init (GstPixciSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->format_name = DEFAULT_PROP_FORMAT_NAME; - src->format_file = g_strdup (DEFAULT_PROP_FORMAT_FILE); - src->driver_params = g_strdup (DEFAULT_PROP_DRIVER_PARAMS); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - - /* this selects the first unit, make this a property? */ - src->unitmap = 1; - src->pixci_open = FALSE; - - src->first_pixci_ts = GST_CLOCK_TIME_NONE; - src->frame_start_times = g_new (guint64, src->num_capture_buffers); - src->frame_end_times = g_new (guint64, src->num_capture_buffers); - src->buffer_ready = FALSE; - src->timeout_occurred = FALSE; - src->fifo_overflow_occurred = FALSE; - - src->buffer_ready_count = 0; - src->buffer_processed_count = 0; - src->frame_end_count = 0; - src->frame_start_count = 0; - /*pixcisrc->frame_count = 0; */ - - g_mutex_init (&src->mutex); - g_cond_init (&src->cond); -} - -void -gst_pixcisrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstPixciSrc *src; - - src = GST_PIXCI_SRC (object); - - switch (property_id) { - case PROP_FORMAT_NAME: - src->format_name = g_value_get_enum (value); - break; - case PROP_FORMAT_FILE: - g_free (src->format_file); - src->format_file = g_strdup (g_value_get_string (value)); - break; - case PROP_DRIVER_PARAMS: - g_free (src->driver_params); - src->driver_params = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - if (src->acq_started) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - src->num_capture_buffers = g_value_get_uint (value); - - g_free (src->frame_start_times); - src->frame_start_times = g_new (guint64, src->num_capture_buffers); - - g_free (src->frame_end_times); - src->frame_end_times = g_new (guint64, src->num_capture_buffers); - } - break; - case PROP_BOARD: - src->board = g_value_get_uint (value); - break; - case PROP_CHANNEL: - src->channel = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pixcisrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstPixciSrc *src; - - g_return_if_fail (GST_IS_PIXCI_SRC (object)); - src = GST_PIXCI_SRC (object); - - switch (property_id) { - case PROP_FORMAT_NAME: - g_value_set_enum (value, src->format_name); - break; - case PROP_FORMAT_FILE: - g_value_set_string (value, src->format_file); - break; - case PROP_DRIVER_PARAMS: - g_value_set_string (value, src->driver_params); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_BOARD: - g_value_set_uint (value, src->board); - break; - case PROP_CHANNEL: - g_value_set_uint (value, src->channel); - break; - case PROP_TIMEOUT: - g_value_set_uint (value, src->timeout); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pixcisrc_dispose (GObject * object) -{ - GstPixciSrc *src; - - g_return_if_fail (GST_IS_PIXCI_SRC (object)); - src = GST_PIXCI_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_pixcisrc_parent_class)->dispose (object); -} - -void -gst_pixcisrc_finalize (GObject * object) -{ - GstPixciSrc *src; - - g_return_if_fail (GST_IS_PIXCI_SRC (object)); - src = GST_PIXCI_SRC (object); - - /* clean up object here */ - g_free (src->format_file); - g_free (src->driver_params); - - g_free (src->frame_start_times); - g_free (src->frame_end_times); - - G_OBJECT_CLASS (gst_pixcisrc_parent_class)->finalize (object); -} - -//static inline GstClockTime -//gst_pixci_get_timestamp (GstPixciSrc * pixcisrc) -//{ -// ui32 dwParam; -// guint64 timestamp; -// -// /* get time in microseconds from start of acquisition */ -// /* TODO: check for rollover */ -// PHX_ParameterGet (pixcisrc->hCamera, PHX_EVENTCOUNT, &dwParam); -// timestamp = (guint64) 1000 *dwParam; -// -// if (pixcisrc->first_pixci_ts == GST_CLOCK_TIME_NONE) { -// pixcisrc->first_pixci_ts = timestamp; -// } -// return timestamp - pixcisrc->first_pixci_ts; -//} - -/* Callback function to handle image capture events. */ -//void -//phx_callback (tHandle hCamera, ui32 dwMask, void *pvParams) -//{ -// GstPixciSrc *pixcisrc = GST_PIXCI_SRC (pvParams); -// GstClockTime ct = gst_pixci_get_timestamp (pixcisrc); -// gboolean signal_create_func = FALSE; -// guint n; -// -// g_mutex_lock (&pixcisrc->mutex); -// -// /* Note that more than one interrupt can be sent, so no "else if" */ -// -// /* called when frame valid signal goes high */ -// if (PHX_INTRPT_FRAME_START & dwMask) { -// /* FIXME: this will work until frames are dropped */ -// n = pixcisrc->frame_start_count % pixcisrc->num_capture_buffers; -// pixcisrc->frame_start_times[n] = ct; -// -// pixcisrc->frame_start_count++; -// } -// -// /* called when frame valid signal goes low */ -// if (PHX_INTRPT_FRAME_END & dwMask) { -// /* FIXME: this will work until frames are dropped */ -// n = (pixcisrc->frame_end_count - 1) % pixcisrc->num_capture_buffers; -// pixcisrc->frame_end_times[n] = ct; -// -// pixcisrc->frame_end_count++; -// } -// -// if (PHX_INTRPT_BUFFER_READY & dwMask) { -// /* we have a buffer */ -// pixcisrc->buffer_ready = TRUE; -// pixcisrc->buffer_ready_count++; -// signal_create_func = TRUE; -// } -// -// if (PHX_INTRPT_TIMEOUT & dwMask) { -// /* TODO: we could offer to try and ABORT then re-START capture */ -// pixcisrc->timeout_occurred = TRUE; -// signal_create_func = TRUE; -// } -// -// if (PHX_INTRPT_FIFO_OVERFLOW & dwMask) { -// pixcisrc->fifo_overflow_occurred = TRUE; -// signal_create_func = TRUE; -// } -// -// -// -// if (signal_create_func) -// g_cond_signal (&pixcisrc->cond); -// g_mutex_unlock (&pixcisrc->mutex); -// /* after unlocking, _create will check for these errors and copy data */ -//} - -static gboolean -gst_pixcisrc_start (GstBaseSrc * bsrc) -{ - GstPixciSrc *src = GST_PIXCI_SRC (bsrc); - int pxerr; - - GST_DEBUG_OBJECT (src, "start"); - - /* open with either a format name or config file */ - if (strlen (src->format_file)) { - if (!g_file_test (src->format_file, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Format file does not exist: %s", src->format_file), (NULL)); - return FALSE; - } - - pxerr = pxd_PIXCIopen (src->driver_params, NULL, src->format_file); - } else { - GEnumClass *video_format_enum_class; - GEnumValue *video_format_enum_value; - video_format_enum_class = g_type_class_ref (GST_TYPE_PIXCI_VIDEO_FORMAT); - video_format_enum_value = - g_enum_get_value (video_format_enum_class, src->format_name); - pxerr = - pxd_PIXCIopen (src->driver_params, video_format_enum_value->value_name, - NULL); - g_type_class_unref (video_format_enum_class); - } - - if (pxerr) { - char buf[1024]; - pxd_mesgFaultText (src->unitmap, buf, 1024); - GST_ELEMENT_ERROR (src, LIBRARY, INIT, - ("Failed to open XCLIB library and driver"), ("%s", buf)); - return FALSE; - } - src->pixci_open = TRUE; - - GST_DEBUG_OBJECT (src, "DriverId: %s", pxd_infoDriverId ()); - GST_DEBUG_OBJECT (src, "LibraryId: %s", pxd_infoLibraryId ()); - GST_DEBUG_OBJECT (src, "Frame buffer memory: %d", - pxd_infoMemsize (src->unitmap)); - GST_DEBUG_OBJECT (src, "Model: %d", pxd_infoModel (src->unitmap)); - GST_DEBUG_OBJECT (src, "SubModel: %d", pxd_infoSubmodel (src->unitmap)); - GST_DEBUG_OBJECT (src, "Units: %d", pxd_infoUnits ()); - - return TRUE; -} - -static gboolean -gst_pixcisrc_stop (GstBaseSrc * bsrc) -{ - GstPixciSrc *src = GST_PIXCI_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - pxd_PIXCIclose (); - src->pixci_open = FALSE; - - /* TODO: stop acq/release cam? */ - - src->dropped_frame_count = 0; - /*pixcisrc->last_time_code = -1; */ - - return TRUE; -} - -static GstCaps * -gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstPixciSrc *src = GST_PIXCI_SRC (bsrc); - GstCaps *caps; - gint width, height; - - if (!src->pixci_open) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - gint components, bits_per_component; - gdouble par; - GstVideoInfo vinfo; - - /* Create video info */ - gst_video_info_init (&vinfo); - - width = pxd_imageXdim (); - height = pxd_imageYdim (); - - par = pxd_imageAspectRatio (); - if (par != 0) { - vinfo.par_d = 10000; - vinfo.par_n = (gint) (par * vinfo.par_d); - } - - bits_per_component = pxd_imageBdim (); - components = pxd_imageCdim (); - - if (components == 1 && bits_per_component <= 8) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height); - caps = gst_video_info_to_caps (&vinfo); - } else if (components == 1 && - bits_per_component > 8 && bits_per_component <= 16) { - GValue val = G_VALUE_INIT; - GstStructure *s; - - if (G_BYTE_ORDER == G_LITTLE_ENDIAN) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width, - height); - } else if (G_BYTE_ORDER == G_BIG_ENDIAN) { - gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_BE, width, - height); - } - caps = gst_video_info_to_caps (&vinfo); - - /* set bpp, extra info for GRAY16 so elements can scale properly */ - s = gst_caps_get_structure (caps, 0); - g_value_init (&val, G_TYPE_INT); - g_value_set_int (&val, bits_per_component); - gst_structure_set_value (s, "bpp", &val); - g_value_unset (&val); - } else { - GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, - (("Unknown or unsupported color format.")), (NULL)); - goto Error; - } - - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; - -Error: - return NULL; -} - -static gboolean -gst_pixcisrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstPixciSrc *src = GST_PIXCI_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - src->height = vinfo.height; - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static GstFlowReturn -gst_pixcisrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstPixciSrc *src = GST_PIXCI_SRC (psrc); - guint dropped_frame_count = 0; - guint new_dropped_frames; - gint i; - guint n; - GstMapInfo minfo; - pxbuffer_t buffer = 1; - int pxerr; - - /* Start acquisition */ - if (!src->acq_started) { - /* TODO: start capture, goLive? */ - src->acq_started = TRUE; - } - - /* about to read/write variables modified by phx_callback */ - //g_mutex_lock (&src->mutex); - - /* wait for callback (we should always get at least a timeout( */ - /*g_cond_wait (&src->cond, &src->mutex); */ - - //if (src->fifo_overflow_occurred) { - // /* TODO: we could offer to try and ABORT then re-START capture */ - // GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - // (("Acquisition failure due to FIFO overflow.")), (NULL)); - // g_mutex_unlock (&src->mutex); - // return GST_FLOW_ERROR; - //} - - //if (src->timeout_occurred) { - // /* TODO: we could offer to try and ABORT then re-START capture */ - // GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - // (("Acquisition failure due to timeout.")), (NULL)); - // g_mutex_unlock (&src->mutex); - // return GST_FLOW_ERROR; - //} - - //if (!src->buffer_ready) { - // GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - // (("You should not see this error, something very bad happened.")), - // (NULL)); - // g_mutex_unlock (&src->mutex); - // return GST_FLOW_ERROR; - //} - - //GST_LOG_OBJECT (src, - // "Processing new buffer %d (Frame start: %d), ready-processed = %d", - // src->buffer_ready_count, src->frame_start_count, - // src->buffer_ready_count - src->buffer_processed_count); - //src->buffer_ready = FALSE; - - ///* frame_start is always >= buffer_ready */ - //dropped_frame_count = - // src->frame_start_count - src->buffer_ready_count; - - //g_mutex_unlock (&src->mutex); - pxerr = pxd_doSnap (src->unitmap, buffer, src->timeout); - if (pxerr) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - (("Failed to get buffer.")), (NULL)); - return GST_FLOW_ERROR; - } - - /* TODO: use allocator or use from Pixci pool */ - *buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - /* Copy image to buffer from surface TODO: use orc_memcpy */ - gst_buffer_map (*buf, &minfo, GST_MAP_WRITE); - GST_LOG_OBJECT (src, - "GstBuffer size=%d, gst_stride=%d, phx_stride=%d", minfo.size, - src->gst_stride, src->px_stride); - /* TODO: must use readuchar for 8-bit buffers */ - pxd_readushort (src->unitmap, buffer, 0, 0, -1, -1, minfo.data, minfo.size, - "Grey"); - //for (i = 0; i < src->height; i++) { - // memcpy (minfo.data + i * src->gst_stride, - // ((guint8 *) buffer.pvAddress) + i * src->px_stride, - // src->gst_stride); - //} - gst_buffer_unmap (*buf, &minfo); - - /* Having processed the data, release the buffer ready for further image data */ - //src->buffer_processed_count++; - - /* check for dropped frames (can only detect more than one) */ - //new_dropped_frames = dropped_frame_count - src->dropped_frame_count; - //if (new_dropped_frames > 0) { - // src->dropped_frame_count = dropped_frame_count; - // GST_WARNING ("Dropped %d frames (%d total)", new_dropped_frames, - // src->dropped_frame_count); - // /* TODO: emit message here about dropped frames */ - //} - - /* use time from capture board */ - //n = (src->buffer_processed_count - - // 1) % src->num_capture_buffers; - //GST_BUFFER_TIMESTAMP (*buf) = src->frame_start_times[n]; - //GST_BUFFER_DURATION (*buf) = - // GST_CLOCK_DIFF (src->frame_start_times[n], - // src->frame_end_times[n]); - //GST_BUFFER_OFFSET (*buf) = src->buffer_processed_count - 1; - //GST_BUFFER_OFFSET_END (*buf) = GST_BUFFER_OFFSET (*buf); - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_pixcisrc_debug, "pixcisrc", 0, - "debug category for pixcisrc element"); - gst_element_register (plugin, "pixcisrc", GST_RANK_NONE, - gst_pixcisrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - pixci, - "Pixci frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/pixci/gstpixcisrc.h b/sys/pixci/gstpixcisrc.h deleted file mode 100644 index 8cd52ea..0000000 --- a/sys/pixci/gstpixcisrc.h +++ /dev/null @@ -1,146 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_PIXCI_SRC_H_ -#define _GST_PIXCI_SRC_H_ - -#include - -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PIXCI_SRC (gst_pixcisrc_get_type()) -#define GST_PIXCI_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PIXCI_SRC,GstPixciSrc)) -#define GST_PIXCI_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PIXCI_SRC,GstPixciSrcClass)) -#define GST_IS_PIXCI_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PIXCI_SRC)) -#define GST_IS_PIXCI_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PIXCI_SRC)) - -typedef struct _GstPixciSrc GstPixciSrc; -typedef struct _GstPixciSrcClass GstPixciSrcClass; - -/** -* GstPixciSrcConnector: -* @MC_Connector_VID<1..16>: channel is linked to camera at the VID<1..16> input -* @MC_Connector_YC: channel is linked to a camera at the YC input -* -* -* Identifies the connector that the camera is connected to. -*/ -typedef enum { - -} GstPixciSrcConnector; - -typedef enum { - GST_PIXCI_VIDEO_FORMAT_CCIR, - GST_PIXCI_VIDEO_FORMAT_CCIR_SQR, - GST_PIXCI_VIDEO_FORMAT_NTSC, - GST_PIXCI_VIDEO_FORMAT_NTSC_4_43, - GST_PIXCI_VIDEO_FORMAT_NTSC_J, - GST_PIXCI_VIDEO_FORMAT_NTSC_SQR, - GST_PIXCI_VIDEO_FORMAT_NTSC_YC, - GST_PIXCI_VIDEO_FORMAT_NTSC_YC_SQR, - GST_PIXCI_VIDEO_FORMAT_PAL, - GST_PIXCI_VIDEO_FORMAT_PAL_60, - GST_PIXCI_VIDEO_FORMAT_PAL_M, - GST_PIXCI_VIDEO_FORMAT_PAL_M_YC, - GST_PIXCI_VIDEO_FORMAT_PAL_N, - GST_PIXCI_VIDEO_FORMAT_PAL_N_YC, - GST_PIXCI_VIDEO_FORMAT_PAL_SQR, - GST_PIXCI_VIDEO_FORMAT_PAL_YC, - GST_PIXCI_VIDEO_FORMAT_PAL_YC_SQR, - GST_PIXCI_VIDEO_FORMAT_RS_170, - GST_PIXCI_VIDEO_FORMAT_RS_170_SQR, - GST_PIXCI_VIDEO_FORMAT_RS343_875i_60Hz, - GST_PIXCI_VIDEO_FORMAT_RS343_875i_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_SECAM, - GST_PIXCI_VIDEO_FORMAT_SECAM_YC, - GST_PIXCI_VIDEO_FORMAT_SVGA_800x600_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_SXGA_1280x1024_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_VGA_640x480_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_50Hz, - GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_50Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_60Hz, - GST_PIXCI_VIDEO_FORMAT_Video_1280x720p_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_50Hz, - GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_50Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_60Hz, - GST_PIXCI_VIDEO_FORMAT_Video_1920x1080i_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz, - GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_Color, - GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_720x480i_60Hz_Y_Color, - GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz, - GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_Color, - GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_RGB, - GST_PIXCI_VIDEO_FORMAT_Video_720x576i_50Hz_Y_Color, - GST_PIXCI_VIDEO_FORMAT_XGA_1024x768_60Hz_RGB -} GstPixciVideoFormatEnum; - -struct _GstPixciSrc -{ - GstPushSrc base_pixcisrc; - - gint dropped_frame_count; - gboolean acq_started; - - /* camera handle */ - - /* properties */ - GstPixciVideoFormatEnum format_name; - gchar *format_file; - gchar *driver_params; - guint num_capture_buffers; - guint board; - guint channel; - guint timeout; - - gboolean pixci_open; - int unitmap; - - GstClockTime first_pixci_ts; - guint64 *frame_start_times; - guint64 *frame_end_times; - gboolean buffer_ready; - guint buffer_ready_count; - guint frame_start_count; - guint frame_end_count; - guint buffer_processed_count; - gboolean timeout_occurred; - gboolean fifo_overflow_occurred; - - gint height; - gint gst_stride; - guint px_stride; - - GMutex mutex; - GCond cond; -}; - -struct _GstPixciSrcClass -{ - GstPushSrcClass base_pixcisrc_class; -}; - -GType gst_pixcisrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/pleora/CMakeLists.txt b/sys/pleora/CMakeLists.txt deleted file mode 100644 index da65b83..0000000 --- a/sys/pleora/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -if (ENABLE_KLV) - add_definitions(-DGST_PLUGINS_VISION_ENABLE_KLV) -endif () - -if (UNIX) - add_definitions(-D_UNIX_) -endif () - -add_definitions(-D_XKEYCHECK_H) - -set (SOURCES - gstpleora.cpp - gstpleorasrc.cpp) - -set (HEADERS - gstpleorasrc.h) - -if (Pleora_VERSION_MAJOR GREATER 5) - set (SOURCES - ${SOURCES} - gstpleorasink.cpp - streamingchannelsource.cpp) - set (HEADERS - ${HEADERS} - gstpleorasink.h - streamingchannelsource.h) -endif () - -include_directories (AFTER - ${Pleora_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/common - ${PROJECT_SOURCE_DIR}/gst-libs/klv - ) - -link_directories(${Pleora_LIBRARY_DIR}) - -set (libname gstpleora${Pleora_VERSION_MAJOR}) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -set (LIBRARIES - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${Pleora_LIBRARIES} - ) - -if (ENABLE_KLV) - set (LIBRARIES ${LIBRARIES} gstklv-1.0-0) -endif () - -target_link_libraries (${libname} - ${LIBRARIES} - ) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/pleora/gstpleora.cpp b/sys/pleora/gstpleora.cpp deleted file mode 100644 index 1f61c1a..0000000 --- a/sys/pleora/gstpleora.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "PvVersion.h" -#if VERSION_MAJOR >= 6 -#include "gstpleorasink.h" -#endif - -#include "gstpleorasrc.h" - -#define GST_CAT_DEFAULT gst_pleora_debug -GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "pleora", 0, - "debug category for pleora plugin"); - -#if VERSION_MAJOR >= 6 - /* eBUS 6 is needed for this sink element */ - if (!gst_element_register (plugin, "pleorasink", GST_RANK_NONE, - gst_pleorasink_get_type ())) { - return FALSE; - } -#endif - - if (!gst_element_register (plugin, "pleorasrc", GST_RANK_NONE, - gst_pleorasrc_get_type ())) { - return FALSE; - } - - return TRUE; -} - -#define PLUGIN_NAME G_PASTE(pleora, VERSION_MAJOR) - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - PLUGIN_NAME, - "Pleora eBUS video elements", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/pleora/gstpleorasink.cpp b/sys/pleora/gstpleorasink.cpp deleted file mode 100644 index 027daf3..0000000 --- a/sys/pleora/gstpleorasink.cpp +++ /dev/null @@ -1,722 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstpleorasink - * - * The pleorasink element is a sink for Pleora eBUS SDK to output a GigE Vision video stream. - * - * - * Example launch line - * |[ - * gst-launch -v videotestsrc ! pleorasink - * ]| - * Outputs test pattern using Pleora eBUS SDK GigE Vision Tx. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include - -#include "gstpleorasink.h" -#include "streamingchannelsource.h" - - -/* GObject prototypes */ -static void gst_pleorasink_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_pleorasink_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_pleorasink_dispose (GObject * object); - -/* GstBaseSink prototypes */ -static gboolean gst_pleorasink_start (GstBaseSink * basesink); -static gboolean gst_pleorasink_stop (GstBaseSink * basesink); -static GstCaps *gst_pleorasink_get_caps (GstBaseSink * basesink, - GstCaps * filter_caps); -static gboolean gst_pleorasink_set_caps (GstBaseSink * basesink, - GstCaps * caps); -static GstFlowReturn gst_pleorasink_render (GstBaseSink * basesink, - GstBuffer * buffer); -static gboolean gst_pleorasink_unlock (GstBaseSink * basesink); -static gboolean gst_pleorasink_unlock_stop (GstBaseSink * basesink); - -gboolean gst_pleorasink_start_multicasting (GstPleoraSink * sink); -void gst_pleorasink_stop_multicasting (GstPleoraSink * sink); - -enum -{ - PROP_0, - PROP_NUM_INTERNAL_BUFFERS, - PROP_ADDRESS, - PROP_MANUFACTURER, - PROP_MODEL, - PROP_VERSION, - PROP_INFO, - PROP_SERIAL, - PROP_MAC, - PROP_OUTPUT_KLV, - PROP_AUTO_MULTICAST, - PROP_MULTICAST_GROUP, - PROP_MULTICAST_PORT, - PROP_PACKET_SIZE -}; - -#define DEFAULT_PROP_NUM_INTERNAL_BUFFERS 3 -#define DEFAULT_PROP_ADDRESS "" -#define DEFAULT_PROP_MANUFACTURER "Pleora" -#define DEFAULT_PROP_MODEL "eBUS GStreamer" -#define DEFAULT_PROP_VERSION "0.1" -#define DEFAULT_PROP_INFO "Pleora eBUS GStreamer Sink" -#define DEFAULT_PROP_SERIAL "0001" -#define DEFAULT_PROP_MAC "" -#define DEFAULT_PROP_OUTPUT_KLV FALSE -#define DEFAULT_PROP_AUTO_MULTICAST FALSE -#define DEFAULT_PROP_MULTICAST_GROUP "239.192.1.1" -#define DEFAULT_PROP_MULTICAST_PORT 1042 -#define DEFAULT_PROP_PACKET_SIZE 1492 - -/* pad templates */ - -static GstStaticPadTemplate gst_pleorasink_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, RGB, RGBA, BGR, BGRA }")) - ); - -/* class initialization */ - -/* setup debug */ -GST_DEBUG_CATEGORY (pleorasink_debug); -#define GST_CAT_DEFAULT pleorasink_debug - -G_DEFINE_TYPE (GstPleoraSink, gst_pleorasink, GST_TYPE_BASE_SINK); - -static void -gst_pleorasink_class_init (GstPleoraSinkClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "pleorasink", 0, - "Pleora eBUS SDK sink"); - - gobject_class->set_property = gst_pleorasink_set_property; - gobject_class->get_property = gst_pleorasink_get_property; - gobject_class->dispose = gst_pleorasink_dispose; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_pleorasink_sink_template)); - - gst_element_class_set_details_simple (gstelement_class, - "Pleora eBUS GEV Tx Sink", "Sink/Video", - "Pleora eBUS SDK sink to output GigE Vision video", - "Joshua M. Doe "); - - gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_pleorasink_start); - gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_pleorasink_stop); - gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_pleorasink_set_caps); - gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_pleorasink_render); - gstbasesink_class->unlock = GST_DEBUG_FUNCPTR (gst_pleorasink_unlock); - gstbasesink_class->unlock_stop = - GST_DEBUG_FUNCPTR (gst_pleorasink_unlock_stop); - - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_NUM_INTERNAL_BUFFERS, g_param_spec_int ("num-internal-buffers", - "Number of internal buffers", - "Number of buffers for the internal queue", 0, 64, - DEFAULT_PROP_NUM_INTERNAL_BUFFERS, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, PROP_ADDRESS, - g_param_spec_string ("address", "IP address", - "The IP address of the network interface to bind to (default is first found)", - DEFAULT_PROP_ADDRESS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - - g_object_class_install_property (gobject_class, PROP_MANUFACTURER, - g_param_spec_string ("manufacturer", "Manufacturer", - "Manufacturer of the virtual camera", - DEFAULT_PROP_MANUFACTURER, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_MODEL, - g_param_spec_string ("model", "Model", - "Model of the virtual camera", - DEFAULT_PROP_MODEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_VERSION, - g_param_spec_string ("version", "Version", - "Version of the virtual camera", - DEFAULT_PROP_VERSION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_INFO, - g_param_spec_string ("info", "Info", - "Info of the virtual camera", - DEFAULT_PROP_INFO, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_SERIAL, - g_param_spec_string ("serial", "Serial", - "Serial of the virtual camera", - DEFAULT_PROP_SERIAL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_MAC, - g_param_spec_string ("mac", "MAC address", - "MAC address of the network interface to bind to (default is first found)", - DEFAULT_PROP_MAC, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -#ifdef GST_PLUGINS_VISION_ENABLE_KLV - g_object_class_install_property (gobject_class, PROP_OUTPUT_KLV, - g_param_spec_boolean ("output-klv", "Output KLV", - "Whether to output KLV as chunk data according to MISB ST1608", - DEFAULT_PROP_OUTPUT_KLV, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -#endif - g_object_class_install_property (gobject_class, PROP_AUTO_MULTICAST, - g_param_spec_boolean ("auto-multicast", "Auto multicast", - "Automatically multicast video, removing the need for a controller", - DEFAULT_PROP_AUTO_MULTICAST, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_MULTICAST_GROUP, - g_param_spec_string ("multicast-group", "Multicast group IP address", - "The address of the multicast group to stream video (if auto-multicast is TRUE)", - DEFAULT_PROP_MULTICAST_GROUP, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MULTICAST_PORT, - g_param_spec_int ("port", "Multicast port", - "The port of the multicast group to stream video (if auto-multicast is TRUE)", - 0, 65535, DEFAULT_PROP_MULTICAST_PORT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PACKET_SIZE, - g_param_spec_int ("packet-size", "Packet size", - "Packet size (if auto-multicast is TRUE)", 576, 65535, - DEFAULT_PROP_PACKET_SIZE, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); -} - -static void -gst_pleorasink_init (GstPleoraSink * sink) -{ - /* properties */ - sink->num_internal_buffers = DEFAULT_PROP_NUM_INTERNAL_BUFFERS; - sink->address = g_strdup (DEFAULT_PROP_ADDRESS); - sink->manufacturer = g_strdup (DEFAULT_PROP_MANUFACTURER); - sink->model = g_strdup (DEFAULT_PROP_MODEL); - sink->version = g_strdup (DEFAULT_PROP_VERSION); - sink->info = g_strdup (DEFAULT_PROP_INFO); - sink->serial = g_strdup (DEFAULT_PROP_SERIAL); - sink->mac = g_strdup (DEFAULT_PROP_MAC); - sink->output_klv = DEFAULT_PROP_OUTPUT_KLV; - sink->auto_multicast = DEFAULT_PROP_AUTO_MULTICAST; - sink->multicast_group = g_strdup (DEFAULT_PROP_MULTICAST_GROUP); - sink->multicast_port = DEFAULT_PROP_MULTICAST_PORT; - sink->packet_size = DEFAULT_PROP_PACKET_SIZE; - - sink->camera_connected = FALSE; - - sink->acquisition_started = FALSE; - sink->stop_requested = FALSE; - - sink->source = new GstStreamingChannelSource (); - sink->source->SetSink (sink); - sink->device = new PvSoftDeviceGEV (); -} - -void -gst_pleorasink_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstPleoraSink *sink; - - g_return_if_fail (GST_IS_PLEORASINK (object)); - sink = GST_PLEORASINK (object); - - switch (property_id) { - case PROP_NUM_INTERNAL_BUFFERS: - sink->num_internal_buffers = g_value_get_int (value); - break; - case PROP_ADDRESS: - g_free (sink->address); - sink->address = g_strdup (g_value_get_string (value)); - break; - case PROP_MANUFACTURER: - g_free (sink->manufacturer); - sink->manufacturer = g_strdup (g_value_get_string (value)); - break; - case PROP_MODEL: - g_free (sink->model); - sink->model = g_strdup (g_value_get_string (value)); - break; - case PROP_VERSION: - g_free (sink->version); - sink->version = g_strdup (g_value_get_string (value)); - break; - case PROP_INFO: - g_free (sink->info); - sink->info = g_strdup (g_value_get_string (value)); - break; - case PROP_SERIAL: - g_free (sink->serial); - sink->serial = g_strdup (g_value_get_string (value)); - break; - case PROP_MAC: - g_free (sink->mac); - sink->mac = g_strdup (g_value_get_string (value)); - break; - case PROP_OUTPUT_KLV: - sink->output_klv = g_value_get_boolean (value); - sink->source->SetKlvEnabled ((bool) sink->output_klv); - break; - case PROP_AUTO_MULTICAST: - sink->auto_multicast = g_value_get_boolean (value); - break; - case PROP_MULTICAST_GROUP: - g_free (sink->multicast_group); - sink->multicast_group = g_strdup (g_value_get_string (value)); - case PROP_MULTICAST_PORT: - sink->multicast_port = g_value_get_int (value); - break; - case PROP_PACKET_SIZE: - sink->packet_size = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pleorasink_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstPleoraSink *sink; - - g_return_if_fail (GST_IS_PLEORASINK (object)); - sink = GST_PLEORASINK (object); - - switch (property_id) { - case PROP_NUM_INTERNAL_BUFFERS: - g_value_set_int (value, sink->num_internal_buffers); - break; - case PROP_ADDRESS: - g_value_set_string (value, sink->address); - break; - case PROP_MANUFACTURER: - g_value_set_string (value, sink->manufacturer); - break; - case PROP_MODEL: - g_value_set_string (value, sink->model); - break; - case PROP_VERSION: - g_value_set_string (value, sink->version); - break; - case PROP_INFO: - g_value_set_string (value, sink->info); - break; - case PROP_SERIAL: - g_value_set_string (value, sink->serial); - break; - case PROP_MAC: - g_value_set_string (value, sink->mac); - break; - case PROP_OUTPUT_KLV: - g_value_set_boolean (value, sink->output_klv); - break; - case PROP_AUTO_MULTICAST: - g_value_set_boolean (value, sink->auto_multicast); - break; - case PROP_MULTICAST_GROUP: - g_value_set_string (value, sink->multicast_group); - break; - case PROP_MULTICAST_PORT: - g_value_set_int (value, sink->multicast_port); - break; - case PROP_PACKET_SIZE: - g_value_set_int (value, sink->packet_size); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pleorasink_dispose (GObject * object) -{ - GstPleoraSink *sink; - - g_return_if_fail (GST_IS_PLEORASINK (object)); - sink = GST_PLEORASINK (object); - - /* clean up as possible. may be called multiple times */ - if (sink->device) { - delete sink->device; - sink->device = NULL; - } - if (sink->source) { - delete sink->source; - sink->source = NULL; - } - - g_free (sink->address); - - G_OBJECT_CLASS (gst_pleorasink_parent_class)->dispose (object); -} - -gboolean -gst_pleorasink_select_interface (GstPleoraSink * sink) -{ - PvSystem lSystem; - const PvNetworkAdapter *selected_nic = NULL; - guint iface_count; - gchar *desired_mac = NULL; - gchar *found_mac = NULL; - - /* we'll compare uppercase version of MAC */ - desired_mac = g_ascii_strup (sink->mac, -1); - - iface_count = lSystem.GetInterfaceCount (); - - GST_DEBUG_OBJECT (sink, "Found %d interface(s)", iface_count); - - for (guint32 i = 0; i < iface_count; i++) { - const PvNetworkAdapter *lNIC = NULL; - lNIC = dynamic_cast < const PvNetworkAdapter *>(lSystem.GetInterface (i)); - - GST_DEBUG_OBJECT (sink, - "Found network interface '%s', MAC: %s, IP: %s, Subnet: %s", - lNIC->GetDescription ().GetAscii (), - lNIC->GetMACAddress ().GetAscii (), - lNIC->GetIPAddress (0).GetAscii (), - lNIC->GetSubnetMask (0).GetAscii ()); - - if ((lNIC == NULL) || - (lNIC->GetIPAddressCount () == 0) || - (lNIC->GetIPAddress (0) == "0.0.0.0")) { - GST_DEBUG_OBJECT (sink, "Interface %d has no valid IP address", i); - continue; - } - - /* we'll compare uppercase version of MAC */ - found_mac = g_ascii_strup (lNIC->GetMACAddress ().GetAscii (), -1); - if (g_strcmp0 (sink->mac, "") == 0 && g_strcmp0 (sink->address, "") == 0) { - /* no MAC or IP set, use first found */ - GST_DEBUG_OBJECT (sink, "Selecting first interface we found"); - selected_nic = lNIC; - - /* set properties */ - g_free (sink->mac); - sink->mac = g_strdup (lNIC->GetMACAddress ().GetAscii ()); - g_free (sink->address); - sink->address = g_strdup (lNIC->GetIPAddress (0).GetAscii ()); - } else if (g_strcmp0 (desired_mac, found_mac) == 0) { - GST_DEBUG_OBJECT (sink, "Selecting interface from MAC '%s'", sink->mac); - selected_nic = lNIC; - - /* set properties */ - g_free (sink->address); - sink->address = g_strdup (lNIC->GetIPAddress (0).GetAscii ()); - } else { - guint32 num_ips = lNIC->GetIPAddressCount (); - for (guint32 i = 0; i < num_ips; i++) { - if (g_strcmp0 (sink->address, lNIC->GetIPAddress (i).GetAscii ()) == 0) { - GST_DEBUG_OBJECT (sink, "Selecting interface from IP '%s'", - sink->address); - selected_nic = lNIC; - - /* set properties */ - g_free (sink->mac); - sink->mac = g_strdup (lNIC->GetMACAddress ().GetAscii ()); - - break; - } - } - } - g_free (found_mac); - - if (selected_nic) { - break; - } - } - g_free (desired_mac); - - if (selected_nic == NULL) { - if (g_strcmp0 (sink->mac, "") != 0) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to find network interface by MAC address '%s'", sink->mac), - (NULL)); - } else if (g_strcmp0 (sink->address, "") != 0) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to find network interface by IP address '%s'", - sink->address), (NULL)); - } else { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to find any network interfaces"), (NULL)); - } - return FALSE; - } else { - GST_DEBUG_OBJECT (sink, - "Selecting network interface '%s', MAC: %s, IP: %s, Subnet: %s", - selected_nic->GetDescription ().GetAscii (), - selected_nic->GetMACAddress ().GetAscii (), - selected_nic->GetIPAddress (0).GetAscii (), - selected_nic->GetSubnetMask (0).GetAscii ()); - return TRUE; - } -} - -gboolean -gst_pleorasink_start (GstBaseSink * basesink) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - - IPvSoftDeviceGEVInfo *info = sink->device->GetInfo (); - if (info) { - info->SetManufacturerName (sink->manufacturer); - info->SetModelName (sink->model); - info->SetDeviceVersion (sink->version); - info->SetManufacturerInformation (sink->info); - info->SetSerialNumber (sink->serial); - } - - return TRUE; -} - -gboolean -gst_pleorasink_stop (GstBaseSink * basesink) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - - gst_pleorasink_stop_multicasting (sink); - - sink->device->Stop (); - - sink->camera_connected = FALSE; - - sink->acquisition_started = FALSE; - sink->stop_requested = FALSE; - - return TRUE; -} - -gboolean -gst_pleorasink_find_registers (GstPleoraSink * sink) -{ - sink->register_SCDA0 = NULL; - sink->register_SCPS0 = NULL; - sink->register_SCP0 = NULL; - sink->register_AcquisitionStart0 = NULL; - sink->register_AcquisitionStop0 = NULL; - - IPvRegisterMap *regmap = sink->device->GetRegisterMap (); - size_t regcount = regmap->GetRegisterCount (); - for (size_t i = 0; i < regcount; i++) { - IPvRegister *reg = regmap->GetRegisterByIndex (i); - const char *reg_name = reg->GetName ().GetAscii (); - - if (g_strcmp0 ("SCDA0", reg_name) == 0) { - sink->register_SCDA0 = reg; - } else if (g_strcmp0 ("SCPS0", reg_name) == 0) { - sink->register_SCPS0 = reg; - } else if (g_strcmp0 ("SCP0", reg_name) == 0) { - sink->register_SCP0 = reg; - } else if (g_strcmp0 ("AcquisitionStart0", reg_name) == 0) { - sink->register_AcquisitionStart0 = reg; - } else if (g_strcmp0 ("AcquisitionStop0", reg_name) == 0) { - sink->register_AcquisitionStop0 = reg; - } - } - - if (!sink->register_SCDA0 || !sink->register_SCPS0 || !sink->register_SCP0 - || !sink->register_AcquisitionStart0 - || !sink->register_AcquisitionStop0) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to find registers necessary to start auto multicasting"), - (NULL)); - return FALSE; - } - - return TRUE; -} - -gboolean -gst_pleorasink_start_multicasting (GstPleoraSink * sink) -{ - PvResult pvRes; - - if (!gst_pleorasink_find_registers (sink)) - return FALSE; - gchar **addr_elems = g_strsplit (sink->multicast_group, ".", 4); - if (g_strv_length (addr_elems) != 4) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Multicast-group is not a valid IP address: %s", - sink->multicast_group), (NULL)); - return FALSE; - } - - guint8 multiaddr[4] = - { atoi (addr_elems[3]), atoi (addr_elems[2]), atoi (addr_elems[1]), - atoi (addr_elems[0]) - }; - pvRes = sink->register_SCDA0->Write (multiaddr, 4); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to set multicast-group address %s as 0x%08x", - sink->multicast_group, multiaddr), (NULL)); - return FALSE; - } - - pvRes = sink->register_SCPS0->Write (0x40000000 | sink->packet_size); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to set packet size %d", sink->packet_size), (NULL)); - return FALSE; - } - - pvRes = sink->register_SCP0->Write (sink->multicast_port); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to set multicast-port %d", sink->multicast_port), (NULL)); - return FALSE; - } - - pvRes = sink->register_AcquisitionStart0->Write (1); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to set AcquisitionStart0 register"), (NULL)); - return FALSE; - } - - return TRUE; -} - -void -gst_pleorasink_stop_multicasting (GstPleoraSink * sink) -{ - PvResult pvRes; - if (sink->register_AcquisitionStop0) { - pvRes = sink->register_AcquisitionStop0->Write (1); - if (!pvRes.IsOK ()) { - GST_ERROR_OBJECT (sink, "Failed to set AcquisitionStop0 register"); - } - } -} - -gboolean -gst_pleorasink_set_caps (GstBaseSink * basesink, GstCaps * caps) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - PvResult pvRes; - - GST_DEBUG_OBJECT (sink, "Caps being set"); - - gst_video_info_from_caps (&sink->vinfo, caps); - - sink->source->SetCaps (caps); - - GST_DEBUG_OBJECT (sink, "Adding stream to device"); - pvRes = sink->device->AddStream (sink->source); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to add stream to device (%s)", - pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - - GST_DEBUG_OBJECT (sink, "Searching for interface"); - if (!gst_pleorasink_select_interface (sink)) { - /* error already sent */ - return FALSE; - } - - GST_DEBUG_OBJECT (sink, "Starting device"); - pvRes = sink->device->Start (sink->mac); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, - ("Failed to start device (%s)", - pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - - sink->acquisition_started = TRUE; - sink->stop_requested = FALSE; - - if (sink->auto_multicast) { - if (!gst_pleorasink_start_multicasting (sink)) { - return FALSE; - } - } - - return TRUE; -} - -GstFlowReturn -gst_pleorasink_render (GstBaseSink * basesink, GstBuffer * buffer) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - - if (sink->stop_requested) { - GST_DEBUG_OBJECT (sink, "stop requested, flushing"); - return GST_FLOW_FLUSHING; - } - - /* TODO: should we ever error out? */ - sink->source->SetBuffer (buffer); - - return GST_FLOW_OK; -} - -gboolean -gst_pleorasink_unlock (GstBaseSink * basesink) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - - sink->stop_requested = TRUE; - - return TRUE; -} - -gboolean -gst_pleorasink_unlock_stop (GstBaseSink * basesink) -{ - GstPleoraSink *sink = GST_PLEORASINK (basesink); - - sink->stop_requested = FALSE; - - return TRUE; -} diff --git a/sys/pleora/gstpleorasink.h b/sys/pleora/gstpleorasink.h deleted file mode 100644 index dd5891d..0000000 --- a/sys/pleora/gstpleorasink.h +++ /dev/null @@ -1,84 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_PLEORASINK_H_ -#define _GST_PLEORASINK_H_ - -#include -#include - -class GstStreamingChannelSource; -class PvSoftDeviceGEV; -class IPvRegister; - -G_BEGIN_DECLS - -#define GST_TYPE_PLEORASINK (gst_pleorasink_get_type()) -#define GST_PLEORASINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLEORASINK,GstPleoraSink)) -#define GST_PLEORASINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLEORASINK,GstPleoraSinkClass)) -#define GST_IS_PLEORASINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLEORASINK)) -#define GST_IS_PLEORASINK_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLEORASINK)) - -typedef struct _GstPleoraSink GstPleoraSink; -typedef struct _GstPleoraSinkClass GstPleoraSinkClass; - -struct _GstPleoraSink -{ - GstBaseSink base; - - GstStreamingChannelSource *source; - PvSoftDeviceGEV *device; - - gint num_internal_buffers; - gchar *address; - gchar *manufacturer; - gchar *model; - gchar *version; - gchar *info; - gchar *serial; - gchar *mac; - gboolean output_klv; - guint32 packet_size; - gboolean auto_multicast; - gchar *multicast_group; - gint multicast_port; - - gboolean camera_connected; - GstVideoInfo vinfo; - - gboolean acquisition_started; - gboolean stop_requested; - - IPvRegister *register_SCDA0; - IPvRegister *register_SCPS0; - IPvRegister *register_SCP0; - IPvRegister *register_AcquisitionStart0; - IPvRegister *register_AcquisitionStop0; -}; - -struct _GstPleoraSinkClass -{ - GstBaseSinkClass base_class; -}; - -GType gst_pleorasink_get_type (void); - -G_END_DECLS - -#endif /* _GST_PLEORASINK_H_ */ diff --git a/sys/pleora/gstpleorasrc.cpp b/sys/pleora/gstpleorasrc.cpp deleted file mode 100644 index d467559..0000000 --- a/sys/pleora/gstpleorasrc.cpp +++ /dev/null @@ -1,1767 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstpleorasrc - * - * The pleorasrc element is a source for Pleora eBUS - * - * - * Example launch line - * |[ - * gst-launch -v pleorasrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default Pleora device - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstpleorasrc.h" - -#include -#include -#include -#include -#include -#include -#include - -/* FIXME: include this for now until gst-plugins-base MR124 is accepted */ -#include "klv.h" - -GST_DEBUG_CATEGORY_STATIC (gst_pleorasrc_debug); -#define GST_CAT_DEFAULT gst_pleorasrc_debug - -/* prototypes */ -static void gst_pleorasrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_pleorasrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_pleorasrc_dispose (GObject * object); -static void gst_pleorasrc_finalize (GObject * object); - -static gboolean gst_pleorasrc_start (GstBaseSrc * src); -static gboolean gst_pleorasrc_stop (GstBaseSrc * src); -static GstCaps *gst_pleorasrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_pleorasrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_pleorasrc_unlock (GstBaseSrc * src); -static gboolean gst_pleorasrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_pleorasrc_create (GstPushSrc * src, GstBuffer ** buf); - -static PvBuffer *gst_pleorasrc_get_pvbuffer (GstPleoraSrc * src); - -enum -{ - PROP_0, - PROP_DEVICE, - PROP_DEVICE_INDEX, - PROP_NUM_CAPTURE_BUFFERS, - PROP_TIMEOUT, - PROP_DETECTION_TIMEOUT, - PROP_MULTICAST_GROUP, - PROP_PORT, - PROP_RECEIVER_ONLY, - PROP_PACKET_SIZE, - PROP_CONFIG_FILE, - PROP_CONFIG_FILE_CONNECT, - PROP_OUTPUT_KLV -}; - -#define DEFAULT_PROP_DEVICE "" -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_TIMEOUT 1000 -#define DEFAULT_PROP_DETECTION_TIMEOUT 1000 -#define DEFAULT_PROP_MULTICAST_GROUP "0.0.0.0" -#define DEFAULT_PROP_PORT 1042 -#define DEFAULT_PROP_RECEIVER_ONLY FALSE -#define DEFAULT_PROP_PACKET_SIZE 0 -#define DEFAULT_PROP_CONFIG_FILE "" -#define DEFAULT_PROP_CONFIG_FILE_CONNECT TRUE -#define DEFAULT_PROP_OUTPUT_KLV FALSE - -#define VIDEO_CAPS_MAKE_BAYER8(format) \ - "video/x-bayer, " \ - "format = (string) " format ", " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -#define VIDEO_CAPS_MAKE_BAYER16(format) \ - "video/x-bayer, " \ - "format = (string) " format ", " \ - "endianness = (int) 1234, " \ - "bpp = (int) {16, 14, 12, 10}, " \ - "width = " GST_VIDEO_SIZE_RANGE ", " \ - "height = " GST_VIDEO_SIZE_RANGE ", " \ - "framerate = " GST_VIDEO_FPS_RANGE - -/* pad templates */ -static GstStaticPadTemplate gst_pleorasrc_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_MAKE_BAYER16 - ("{ bggr16, grbg16, rggb16, gbrg16 }") ";" - VIDEO_CAPS_MAKE_BAYER8 ("{ bggr, grbg, rggb, gbrg }") ";" - GST_VIDEO_CAPS_MAKE ("{ GRAY16_LE, GRAY16_BE, GRAY8, UYVY, YUY2, RGB }") - ) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstPleoraSrc, gst_pleorasrc, GST_TYPE_PUSH_SRC); - -static void -gst_pleorasrc_class_init (GstPleoraSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "pleorasrc", 0, - "Pleora eBUS SDK source"); - - gobject_class->set_property = gst_pleorasrc_set_property; - gobject_class->get_property = gst_pleorasrc_get_property; - gobject_class->dispose = gst_pleorasrc_dispose; - gobject_class->finalize = gst_pleorasrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_pleorasrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Pleora Video Source", "Source/Video", - "Pleora eBUS video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_pleorasrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_pleorasrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_pleorasrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_pleorasrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_pleorasrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_pleorasrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_pleorasrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_DEVICE, - g_param_spec_string ("device", "Device ID", - "Device ID. For GEV use MAC, IP, or user id. For U3V, use GUID or user id.", - DEFAULT_PROP_DEVICE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_int ("device-index", "Device index", - "Index of device, use -1 to enumerate all and select last", -1, - G_MAXINT, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMEOUT, - g_param_spec_int ("timeout", "Timeout (ms)", - "Timeout in ms (0 to use default)", 0, G_MAXINT, DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_DETECTION_TIMEOUT, g_param_spec_int ("detection-timeout", - "Detection Timeout (ms)", "Timeout in ms to detect GigE cameras", 100, - 60000, DEFAULT_PROP_DETECTION_TIMEOUT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, PROP_MULTICAST_GROUP, - g_param_spec_string ("multicast-group", "Multicast group IP address", - "The address of the multicast group to join (default is unicast)", - DEFAULT_PROP_MULTICAST_GROUP, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT, - g_param_spec_int ("port", "Multicast port", - "The port of the multicast group.", 0, 65535, DEFAULT_PROP_PORT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_RECEIVER_ONLY, - g_param_spec_boolean ("receiver-only", "Receiver only", - "Only open video stream, don't open as controller", - DEFAULT_PROP_RECEIVER_ONLY, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PACKET_SIZE, - g_param_spec_int ("packet-size", "Packet size", - "Packet size (0 to auto negotiate)", 0, 65535, - DEFAULT_PROP_PACKET_SIZE, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (gobject_class, PROP_CONFIG_FILE, - g_param_spec_string ("config-file", "Config file", - "Filepath of the configuration file (*.pvcfg)", - DEFAULT_PROP_CONFIG_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_CONFIG_FILE_CONNECT, g_param_spec_boolean ("config-file-connect", - "Connect using config file", - "Connects to and configures camera from config-file, if false " - "connects using properties and then restores configuration", - DEFAULT_PROP_CONFIG_FILE_CONNECT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); -#ifdef GST_PLUGINS_VISION_ENABLE_KLV - g_object_class_install_property (gobject_class, PROP_OUTPUT_KLV, - g_param_spec_boolean ("output-klv", "Output KLV", - "Whether to output MISB ST1608 KLV as buffer meta", - DEFAULT_PROP_OUTPUT_KLV, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); -#endif -} - -static void -gst_pleorasrc_reset (GstPleoraSrc * src) -{ - src->device = NULL; - src->stream = NULL; - src->pipeline = NULL; - - src->last_frame_count = 0; - src->total_dropped_frames = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - src->pv_pixel_type = PvPixelUndefined; - src->width = 0; - src->height = 0; -} - -static void -gst_pleorasrc_init (GstPleoraSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->device_id = g_strdup (DEFAULT_PROP_DEVICE); - src->device_index = DEFAULT_PROP_DEVICE_INDEX; - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->timeout = DEFAULT_PROP_TIMEOUT; - src->detection_timeout = DEFAULT_PROP_DETECTION_TIMEOUT; - src->multicast_group = g_strdup (DEFAULT_PROP_MULTICAST_GROUP); - src->port = DEFAULT_PROP_PORT; - src->receiver_only = DEFAULT_PROP_RECEIVER_ONLY; - src->config_file = g_strdup (DEFAULT_PROP_CONFIG_FILE); - src->config_file_connect = DEFAULT_PROP_CONFIG_FILE_CONNECT; - src->output_klv = DEFAULT_PROP_OUTPUT_KLV; - - src->stop_requested = FALSE; - src->caps = NULL; - - src->pvbuffer = NULL; - - gst_pleorasrc_reset (src); -} - -void -gst_pleorasrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstPleoraSrc *src; - - src = GST_PLEORA_SRC (object); - - switch (property_id) { - case PROP_DEVICE: - g_free (src->device_id); - src->device_id = g_strdup (g_value_get_string (value)); - break; - case PROP_DEVICE_INDEX: - src->device_index = g_value_get_int (value); - break; - case PROP_NUM_CAPTURE_BUFFERS: - src->num_capture_buffers = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - case PROP_DETECTION_TIMEOUT: - src->detection_timeout = g_value_get_int (value); - break; - case PROP_MULTICAST_GROUP: - g_free (src->multicast_group); - src->multicast_group = g_strdup (g_value_get_string (value)); - break; - case PROP_PORT: - src->port = g_value_get_int (value); - break; - case PROP_RECEIVER_ONLY: - src->receiver_only = g_value_get_boolean (value); - break; - case PROP_PACKET_SIZE: - src->packet_size = g_value_get_int (value); - break; - case PROP_CONFIG_FILE: - g_free (src->config_file); - src->config_file = g_strdup (g_value_get_string (value)); - break; - case PROP_CONFIG_FILE_CONNECT: - src->config_file_connect = g_value_get_boolean (value); - break; - case PROP_OUTPUT_KLV: - src->output_klv = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pleorasrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstPleoraSrc *src; - - g_return_if_fail (GST_IS_PLEORA_SRC (object)); - src = GST_PLEORA_SRC (object); - - switch (property_id) { - case PROP_DEVICE: - g_value_set_string (value, src->device_id); - break; - case PROP_DEVICE_INDEX: - g_value_set_int (value, src->device_index); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - case PROP_DETECTION_TIMEOUT: - g_value_set_int (value, src->detection_timeout); - break; - case PROP_MULTICAST_GROUP: - g_value_set_string (value, src->multicast_group); - break; - case PROP_PORT: - g_value_set_int (value, src->port); - break; - case PROP_RECEIVER_ONLY: - g_value_set_boolean (value, src->receiver_only); - break; - case PROP_PACKET_SIZE: - g_value_set_int (value, src->packet_size); - break; - case PROP_CONFIG_FILE: - g_value_set_string (value, src->config_file); - break; - case PROP_CONFIG_FILE_CONNECT: - g_value_set_boolean (value, src->config_file_connect); - break; - case PROP_OUTPUT_KLV: - g_value_set_boolean (value, src->output_klv); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_pleorasrc_dispose (GObject * object) -{ - GstPleoraSrc *src; - - g_return_if_fail (GST_IS_PLEORA_SRC (object)); - src = GST_PLEORA_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_pleorasrc_parent_class)->dispose (object); -} - -void -gst_pleorasrc_finalize (GObject * object) -{ - GstPleoraSrc *src; - - g_return_if_fail (GST_IS_PLEORA_SRC (object)); - src = GST_PLEORA_SRC (object); - - /* clean up object here */ - if (src->device) { - g_free (src->device); - src->device = NULL; - } - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - G_OBJECT_CLASS (gst_pleorasrc_parent_class)->finalize (object); -} - -static const gchar * -usb_speed_str (PvUSBSpeed speed) -{ - static const gchar *array[] = { - "Unknown", "Low", "Full", "High", "Super" - }; - if (speed >= sizeof (array) / sizeof (const gchar *) || speed < 0) { - speed = PvUSBSpeedUnknown; - } - return array[speed]; -} - -static const void -gst_pleorasrc_print_device_info (GstPleoraSrc * src, - const PvDeviceInfo * device_info) -{ - GST_DEBUG_OBJECT (src, "Found device '%s'", - device_info->GetDisplayID ().GetAscii ()); - - const PvDeviceInfoGEV *device_info_GEV = - dynamic_cast < const PvDeviceInfoGEV * >(device_info); - const PvDeviceInfoU3V *device_info_U3V = - dynamic_cast < const PvDeviceInfoU3V * >(device_info); - const PvDeviceInfoUSB *device_info_USB = - dynamic_cast < const PvDeviceInfoUSB * >(device_info); - const PvDeviceInfoPleoraProtocol *device_info_pleora = - dynamic_cast < const PvDeviceInfoPleoraProtocol * >(device_info); - - const PvNetworkAdapter *iface_nic = - dynamic_cast < const PvNetworkAdapter * >(device_info->GetInterface ()); - const PvUSBHostController *iface_usb = - dynamic_cast < - const PvUSBHostController * >(device_info->GetInterface ()); - - if (iface_nic != NULL) { -#if VERSION_MAJOR == 4 -#define PLEORA_GET_PARAM -#else -#define PLEORA_GET_PARAM 0 -#endif - GST_DEBUG_OBJECT (src, - "Device found on network interface '%s', MAC: %s, IP: %s, Subnet: %s", - iface_nic->GetDescription ().GetAscii (), - iface_nic->GetMACAddress ().GetAscii (), - iface_nic->GetIPAddress (PLEORA_GET_PARAM).GetAscii (), - iface_nic->GetSubnetMask (PLEORA_GET_PARAM).GetAscii ()); - } else if (iface_usb != NULL) { - GST_DEBUG_OBJECT (src, - "Device found on USB interface, VEN_%04X&DEV_%04X&SUBSYS_%08X&REV_%02X, '%s', %s Speed", - iface_usb->GetVendorID (), iface_usb->GetDeviceID (), - iface_usb->GetSubsystemID (), iface_usb->GetRevision (), - iface_usb->GetName ().GetAscii (), - usb_speed_str (iface_usb->GetSpeed ())); - } - - if (device_info_GEV != NULL) { - GST_DEBUG_OBJECT (src, "GEV device: MAC: %s, IP: %s, S/N: %s", - device_info_GEV->GetMACAddress ().GetAscii (), - device_info_GEV->GetIPAddress ().GetAscii (), - device_info_GEV->GetSerialNumber ().GetAscii ()); - } else if (device_info_U3V != NULL) { - GST_DEBUG_OBJECT (src, "U3V device: GUID: %s, S/N: %s", - device_info_U3V->GetDeviceGUID ().GetAscii (), - device_info_U3V->GetSerialNumber ().GetAscii (), - device_info_U3V->GetInterface ()); - } else if (device_info_USB != NULL) { - GST_DEBUG_OBJECT (src, "Unidentified USB device"); - } else if (device_info_pleora != NULL) { - GST_DEBUG_OBJECT (src, "Pleora device: MAC: %s, IP: %s, S/N: %s", - device_info_pleora->GetMACAddress ().GetAscii (), - device_info_pleora->GetIPAddress ().GetAscii (), - device_info_pleora->GetSerialNumber ().GetAscii ()); - } -} - -static PvDeviceType -device_type_from_device_info_type (PvDeviceInfoType devinfotype) -{ - switch (devinfotype) { - case PvDeviceInfoTypeGEV: - case PvDeviceInfoTypePleoraProtocol: - return PvDeviceTypeGEV; - break; - case PvDeviceInfoTypeU3V: - case PvDeviceInfoTypeUSB: - return PvDeviceTypeU3V; - break; - default: - return PvDeviceTypeUnknown; - } -} - -static PvString -device_id_from_device_info (const PvDeviceInfo * device_info) -{ - PvString id; - const PvDeviceInfoGEV *device_info_GEV = - dynamic_cast < const PvDeviceInfoGEV * >(device_info); - const PvDeviceInfoU3V *device_info_U3V = - dynamic_cast < const PvDeviceInfoU3V * >(device_info); - const PvDeviceInfoPleoraProtocol *device_info_pleora = - dynamic_cast < const PvDeviceInfoPleoraProtocol * >(device_info); - - if (device_info_GEV) { - id = device_info_GEV->GetIPAddress (); - } else if (device_info_U3V) { - id = device_info_U3V->GetDeviceGUID (); - } else if (device_info_pleora) { - id = device_info_pleora->GetIPAddress (); - } - - return id; -} - -static gboolean -gst_pleorasrc_find_device (GstPleoraSrc * src) -{ - PvResult pvRes; - PvSystem lSystem; - const PvDeviceInfo *device_info = NULL; - - // time allowed to detect GEV cameras - lSystem.SetDetectionTimeout (src->detection_timeout); - - if (g_strcmp0 (src->device_id, "") != 0) { - GST_DEBUG_OBJECT (src, "Finding device based on ID: %s", src->device_id); - - pvRes = lSystem.FindDevice (src->device_id, &device_info); - - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Failed to find device ID '%s': %s", src->device_id, - pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - } else if (src->device_index >= 0) { - GST_DEBUG_OBJECT (src, "Finding device based on index: %d", - src->device_index); - - /* Find will block for detection_timeout */ - pvRes = lSystem.Find (); - - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Error finding devices: %s", pvRes.GetDescription ().GetAscii ()), - (NULL)); - return FALSE; - } - - if (lSystem.GetDeviceCount () < 1) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("No Pleora-compatible devices found"), (NULL)); - return FALSE; - } - - if (src->device_index >= lSystem.GetDeviceCount ()) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Device index specified (%d) does not exist, out of range [0, %d)", - src->device_index, lSystem.GetDeviceCount ()), (NULL)); - return FALSE; - } - - device_info = lSystem.GetDeviceInfo (src->device_index); - - if (device_info == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Failed to find device index %d", src->device_index), (NULL)); - return FALSE; - } - } else { - guint32 device_count; - - GST_DEBUG_OBJECT (src, "Enumerating devices and choosing last one"); - - pvRes = lSystem.Find (); - - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Error finding devices: %s", pvRes.GetDescription ().GetAscii ()), - (NULL)); - return FALSE; - } - - device_count = lSystem.GetDeviceCount (); - - if (device_count < 1) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("No Pleora-compatible devices found"), (NULL)); - return FALSE; - } - - GST_DEBUG_OBJECT (src, "Found a total of %d device(s)", device_count); - for (uint32_t x = 0; x < device_count; x++) { - device_info = lSystem.GetDeviceInfo (x); - gst_pleorasrc_print_device_info (src, device_info); - } - -#if 0 - // iterate through all interfaces on system - uint32_t lInterfaceCount = lSystem.GetInterfaceCount (); - for (uint32_t x = 0; x < lInterfaceCount; x++) { - const PvInterface *lInterface = lSystem.GetInterface (x); - - GST_DEBUG_OBJECT (src, "Found interface %d: '%s', '%s'", x, - lInterface->GetName ().GetAscii (), - lInterface->GetDisplayID ().GetAscii ()); - - const PvNetworkAdapter *lNIC = - dynamic_cast < const PvNetworkAdapter * >(lInterface); - if (lNIC != NULL) { - GST_DEBUG_OBJECT (src, "MAC: %s, IP: %s, Subnet: %s", - lNIC->GetMACAddress ().GetAscii (), - lNIC->GetIPAddress ().GetAscii (), - lNIC->GetSubnetMask ().GetAscii ()); - } - - const PvUSBHostController *lUSB = - dynamic_cast < const PvUSBHostController * >(lInterface); - if (lUSB != NULL) { - GST_DEBUG_OBJECT (src, "USB '%s'", lUSB->GetName ().GetAscii ()); - } - // iterate through all devices on interface - uint32_t lDeviceCount = lInterface->GetDeviceCount (); - - if (lDeviceCount == 0) { - GST_DEBUG_OBJECT (src, "No devices found on this interface"); - } - for (uint32_t y = 0; y < lDeviceCount; y++) { - const PvDeviceInfo *devinfo = lInterface->GetDeviceInfo (y); - - gst_pleorasrc_print_device_info (src, devinfo); - - // select last device - device_info = devinfo; - } - } -#endif - - } - - GST_DEBUG_OBJECT (src, "Info for device that will be opened:"); - gst_pleorasrc_print_device_info (src, device_info); - - if (g_strcmp0 (src->device_id, "") == 0) { - g_free (src->device_id); - src->device_id = - g_strdup (device_id_from_device_info (device_info).GetAscii ()); - } - - src->device_type = - device_type_from_device_info_type (device_info->GetType ()); - - return TRUE; -} - -static gboolean -gst_pleorasrc_restore_device_from_config (GstPleoraSrc * src) -{ - PvConfigurationReader lConfigReader; - PvResult pvRes; - - GST_DEBUG_OBJECT (src, "Loading config file (%s)", src->config_file); - pvRes = lConfigReader.Load (src->config_file); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to load config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - - if (lConfigReader.GetDeviceCount () == 0) { - GST_DEBUG_OBJECT (src, "Config file has no device configurations"); - return TRUE; - } else { - PvString name; - lConfigReader.GetDeviceName (0, name); - GST_DEBUG_OBJECT (src, "Loading device config named '%s'", - name.GetAscii ()); - } - - if (src->device == NULL) { - PvDeviceGEV *lDeviceGEV = new PvDeviceGEV (); - PvDeviceU3V *lDeviceU3V = new PvDeviceU3V (); - - GST_DEBUG_OBJECT (src, - "Restoring device connection and settings from config file"); - pvRes = lConfigReader.Restore (0, lDeviceGEV); - if (pvRes.IsOK ()) { - src->device = lDeviceGEV; - delete lDeviceU3V; - } else { - pvRes = lConfigReader.Restore (0, lDeviceU3V); - if (pvRes.IsOK ()) { - src->device = lDeviceU3V; - delete lDeviceGEV; - } else { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Failed to restore device from config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - } - } else { - GST_DEBUG_OBJECT (src, "Restoring device settings from config file"); - pvRes = lConfigReader.Restore (0, src->device); - if (!pvRes.IsOK ()) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Failed to restore device from config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - } - - return TRUE; -} - -static gboolean -gst_pleorasrc_restore_stream_from_config (GstPleoraSrc * src) -{ - PvConfigurationReader lConfigReader; - PvResult pvRes; - - GST_DEBUG_OBJECT (src, "Loading config file (%s)", src->config_file); - pvRes = lConfigReader.Load (src->config_file); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to load config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - - if (lConfigReader.GetStreamCount () == 0) { - GST_DEBUG_OBJECT (src, "Config file has no stream configurations"); - return TRUE; - } else { - PvString name; - lConfigReader.GetStreamName (0, name); - GST_DEBUG_OBJECT (src, "Loading stream config named '%s'", - name.GetAscii ()); - } - - if (src->stream == NULL) { - PvStreamGEV *lStreamGEV = new PvStreamGEV (); - PvStreamU3V *lStreamU3V = new PvStreamU3V (); - - GST_DEBUG_OBJECT (src, - "Restoring stream connection and settings from config file"); - pvRes = lConfigReader.Restore (0, lStreamGEV); - if (pvRes.IsOK ()) { - src->stream = lStreamGEV; - delete lStreamU3V; - } else { - pvRes = lConfigReader.Restore (0, lStreamU3V); - if (pvRes.IsOK ()) { - src->stream = lStreamU3V; - delete lStreamGEV; - } else { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Failed to restore stream from config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - } - } else { - GST_DEBUG_OBJECT (src, "Restoring stream settings from config file"); - pvRes = lConfigReader.Restore (0, src->stream); - if (!pvRes.IsOK ()) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Failed to restore stream from config file (%s): %s", - src->config_file, pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - } - - return TRUE; -} - -static gboolean -gst_pleorasrc_open_device (GstPleoraSrc * src) -{ - PvResult pvRes; - - /* open device */ - if (g_strcmp0 (src->config_file, DEFAULT_PROP_CONFIG_FILE) != 0 && - src->config_file_connect) { - /* open device from config file */ - if (!gst_pleorasrc_restore_device_from_config (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to load device config from file (%s)", - src->config_file), (NULL)); - return FALSE; - } - } else { - /* open device from element properties */ - if (!gst_pleorasrc_find_device (src)) { - /* error already sent */ - return FALSE; - } - - /* open device (for GEV, opening device means we're a controller */ - if (!src->receiver_only) { - GST_DEBUG_OBJECT (src, "Trying to connect to device as controller"); - - src->device = PvDevice::CreateAndConnect (src->device_id, &pvRes); - if (src->device == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Unable to connect to device as controller: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - GST_DEBUG_OBJECT (src, "Connected to device as controller"); - } - } - - return TRUE; -} - -static gboolean -gst_pleorasrc_open_stream (GstPleoraSrc * src) -{ - PvResult pvRes; - - /* open stream */ - if (g_strcmp0 (src->config_file, DEFAULT_PROP_CONFIG_FILE) != 0 && - src->config_file_connect) { - /* try to restore stream from config file */ - if (!gst_pleorasrc_restore_stream_from_config (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to load stream config from file (%s)", - src->config_file), (NULL)); - return FALSE; - } - } else { - /* get connection ID from device or scan for device info */ - if (g_strcmp0 (src->device_id, "") == 0) { - if (src->device) { - PvDeviceGEV *lDeviceGEV = dynamic_cast < PvDeviceGEV * >(src->device); - PvDeviceU3V *lDeviceU3V = dynamic_cast < PvDeviceU3V * >(src->device); - if (lDeviceGEV) { - g_free (src->device_id); - src->device_id = g_strdup (lDeviceGEV->GetIPAddress ().GetAscii ()); - src->device_type = PvDeviceTypeGEV; - } else if (lDeviceU3V) { - g_free (src->device_id); - src->device_id = g_strdup (lDeviceU3V->GetGUID ().GetAscii ()); - src->device_type = PvDeviceTypeU3V; - } else { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Unsupported device type %d", src->device->GetType ()), (NULL)); - return FALSE; - } - } else { - /* open device from element properties */ - if (!gst_pleorasrc_find_device (src)) { - /* error already sent */ - return FALSE; - } - } - } - - GST_DEBUG_OBJECT (src, "Using connection ID '%s'", src->device_id); - - if (src->device_type == PvDeviceTypeGEV) { - PvStreamGEV *stream = new PvStreamGEV; - if (g_strcmp0 (src->multicast_group, DEFAULT_PROP_MULTICAST_GROUP) != 0) { - GST_DEBUG_OBJECT (src, "Opening GEV stream in multicast mode, %s:%d", - src->multicast_group, src->port); - pvRes = stream->Open (src->device_id, src->multicast_group, src->port); - } else { - GST_DEBUG_OBJECT (src, "Opening GEV stream in unicast mode"); - pvRes = stream->Open (src->device_id); - } - - src->stream = stream; - } else { - src->stream = PvStream::CreateAndOpen (src->device_id, &pvRes); - } - } - - if (src->stream == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, ("Failed to open stream: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_pleorasrc_setup_stream (GstPleoraSrc * src) -{ - PvResult pvRes; - - if (!gst_pleorasrc_open_device (src)) { - return FALSE; - } - - if (!gst_pleorasrc_open_stream (src)) { - return FALSE; - } - - GST_DEBUG_OBJECT (src, "Stream created for device"); - - /* if acting as a GigE controller, configure stream */ - PvDeviceGEV *lDeviceGEV = dynamic_cast < PvDeviceGEV * >(src->device); - if (!src->receiver_only && lDeviceGEV != NULL) { -#if VERSION_MAJOR == 4 - PvStreamGEV *lStreamGEV = static_cast < PvStreamGEV * >(src->stream); -#else - const PvStreamGEV *lStreamGEV = static_cast < PvStreamGEV * >(src->stream); -#endif - - /* negotiate or set packet size */ - if (src->packet_size == 0) { - /* Negotiate packet size, use safe default if it fails */ - pvRes = lDeviceGEV->NegotiatePacketSize (0, 1476); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to negotiate packet size: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto stream_config_failed; - } - } else { - pvRes = lDeviceGEV->SetPacketSize (src->packet_size); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to set packet size to %d: %s", src->packet_size, - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto stream_config_failed; - } - } - - PvGenInteger *packetParam = - src->device->GetParameters ()->GetInteger ("GevSCPSPacketSize"); - if (packetParam) { - gint64 val; - packetParam->GetValue (val); - GST_DEBUG_OBJECT (src, "Packet size is currently %d", val); - src->packet_size = (gint) val; - } else { - GST_WARNING_OBJECT (src, "Couldn't get current packet size"); - } - - /* Configure device streaming destination */ - pvRes = - lDeviceGEV->SetStreamDestination (lStreamGEV->GetLocalIPAddress (), - lStreamGEV->GetLocalPort ()); - - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to set stream destination: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto stream_config_failed; - } - } - - /* load config file if specified */ - if (g_strcmp0 (src->config_file, DEFAULT_PROP_CONFIG_FILE) != 0 && - !src->config_file_connect) { - if (!gst_pleorasrc_restore_device_from_config (src)) { - goto stream_config_failed; - } - - if (!gst_pleorasrc_restore_stream_from_config (src)) { - goto stream_config_failed; - } - } - - src->pipeline = new PvPipeline (src->stream); - if (src->pipeline == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Unable to create pipeline from stream"), (NULL)); - goto stream_config_failed; - } - - pvRes = src->pipeline->SetBufferCount (src->num_capture_buffers); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Unable to set buffer count: %s", pvRes.GetDescription ().GetAscii ()), - (NULL)); - goto pipeline_config_failed; - } - - return TRUE; - -pipeline_config_failed: - if (src->pipeline) { - delete src->pipeline; - src->pipeline = NULL; - } - -stream_config_failed: - if (src->stream) { - src->stream->Close (); - PvStream::Free (src->stream); - src->stream = NULL; - } - - if (src->device) { - src->device->Disconnect (); - PvDevice::Free (src->device); - src->device = NULL; - } - return FALSE; -} - -// borrowed from Aravis, arvmisc.c -#define MAKE_FOURCC(a,b,c,d) ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24)) - -typedef struct -{ - PvPixelType pixel_type; - const char *gst_caps_string; - const char *name; - const char *format; - int bpp; - int depth; - guint32 fourcc; -} GstPleoraCapsInfos; - -GstPleoraCapsInfos gst_caps_infos[] = { - { - PvPixelMono8, - "video/x-raw, format=(string)GRAY8", - "video/x-raw", "GRAY8", - 8, 8, 0}, - { - PvPixelMono10, - "video/x-raw, format=(string)GRAY16_LE, bpp=(int)10", - "video/x-raw", "GRAY16_LE", - 10, 16, 0}, - { - PvPixelMono12, - "video/x-raw, format=(string)GRAY16_LE, bpp=(int)12", - "video/x-raw", "GRAY16_LE", - 12, 16, 0}, - { - PvPixelMono14, - "video/x-raw, format=(string)GRAY16_LE, bpp=(int)14", - "video/x-raw", "GRAY16_LE", - 14, 16, 0}, - { - PvPixelMono16, - "video/x-raw, format=(string)GRAY16_LE", - "video/x-raw", "GRAY16_LE", - 16, 16, 0}, - { - PvPixelBayerGR8, - "video/x-bayer, format=(string)grbg", - "video/x-bayer", "grbg", - 8, 8, MAKE_FOURCC ('g', 'r', 'b', 'g') - }, - { - PvPixelBayerRG8, - "video/x-bayer, format=(string)rggb", - "video/x-bayer", "rggb", - 8, 8, MAKE_FOURCC ('r', 'g', 'g', 'b') - }, - { - PvPixelBayerGB8, - "video/x-bayer, format=(string)gbrg", - "video/x-bayer", "gbrg", - 8, 8, MAKE_FOURCC ('g', 'b', 'r', 'g') - }, - { - PvPixelBayerBG8, - "video/x-bayer, format=(string)bggr", - "video/x-bayer", "bggr", - 8, 8, MAKE_FOURCC ('b', 'g', 'g', 'r') - }, - - /* The caps for non 8-bit bayer formats has not been agreed upon yet. - * This feature is discussed in bug https://bugzilla.gnome.org/show_bug.cgi?id=693666 .*/ - { - PvPixelBayerGR10, - "video/x-bayer, format=(string)grbg16, bpp=(int)10", - "video/x-bayer", "grbg", - 10, 16, 0}, - { - PvPixelBayerRG10, - "video/x-bayer, format=(string)rggb16, bpp=(int)10", - "video/x-bayer", "rggb", - 10, 16, 0}, - { - PvPixelBayerGB10, - "video/x-bayer, format=(string)gbrg16, bpp=(int)10", - "video/x-bayer", "gbrg", - 10, 16, 0}, - { - PvPixelBayerBG10, - "video/x-bayer, format=(string)bggr16, bpp=(int)10", - "video/x-bayer", "bggr", - 10, 16, 0}, - { - PvPixelBayerGR12, - "video/x-bayer, format=(string)grbg16, bpp=(int)12", - "video/x-bayer", "grbg", - 12, 16, 0}, - { - PvPixelBayerRG12, - "video/x-bayer, format=(string)rggb16, bpp=(int)12", - "video/x-bayer", "rggb", - 12, 16, 0}, - { - PvPixelBayerGB12, - "video/x-bayer, format=(string)gbrg16, bpp=(int)12", - "video/x-bayer", "gbrg", - 12, 16, 0}, - { - PvPixelBayerBG12, - "video/x-bayer, format=(string)bggr16, bpp=(int)12", - "video/x-bayer", "bggr", - 12, 16, 0}, - { - PvPixelBayerGR16, - "video/x-bayer, format=(string)grbg16, bpp=(int)16", - "video/x-bayer", "grbg", - 16, 16, 0}, - { - PvPixelBayerRG16, - "video/x-bayer, format=(string)rggb16, bpp=(int)16", - "video/x-bayer", "rggb", - 16, 16, 0}, - { - PvPixelBayerGB16, - "video/x-bayer, format=(string)gbrg16, bpp=(int)16", - "video/x-bayer", "gbrg", - 16, 16, 0}, - { - PvPixelBayerBG16, - "video/x-bayer, format=(string)bggr16, bpp=(int)16", - "video/x-bayer", "bggr", - 16, 16, 0}, - - { - PvPixelYUV422_8_UYVY, - "video/x-raw, format=(string)UYVY", - "video/x-raw", "UYVY", - 0, 0, MAKE_FOURCC ('U', 'Y', 'V', 'Y') - }, - { - PvPixelYUV411_8_UYYVYY, - "video/x-raw, format=(string)IYU1", - "video/x-raw", "IYU1", - 0, 0, MAKE_FOURCC ('I', 'Y', 'U', '1') - }, - { - PvPixelYUV8_UYV, - "video/x-raw, format=(string)IYU2", - "video/x-raw", "IYU2", - 0, 0, MAKE_FOURCC ('I', 'Y', 'U', '2') - }, - { - PvPixelYUV422_8, - "video/x-raw, format=(string)YUY2", - "video/x-raw", "YUY2", - 0, 0, MAKE_FOURCC ('Y', 'U', 'Y', '2') - }, - { - PvPixelRGB8, - "video/x-raw, format=(string)RGB", - "video/x-raw", "RGB", - 24, 24, 0}, - { - PvPixelRGBa8, - "video/x-raw, format=(string)RGBx", - "video/x-raw", "RGBx", - 32, 32, 0}, -}; - -/** - * arv_pixel_format_to_gst_caps_string: - * @pixel_format: a pixel format - * Return value: a gstreamer caps string describing the given @pixel_format. - */ - -const char * -gst_pleorasrc_pixel_type_to_gst_caps_string (PvPixelType pixel_type) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (gst_caps_infos); i++) - if (gst_caps_infos[i].pixel_type == pixel_type) - break; - - if (i == G_N_ELEMENTS (gst_caps_infos)) { - GST_WARNING ("Pixel type not currently supported: %d", pixel_type); - return NULL; - } - - GST_LOG ("Matched pixel type %d to caps %s", - pixel_type, gst_caps_infos[i].gst_caps_string); - - return gst_caps_infos[i].gst_caps_string; -} - -PvPixelType -gst_pleorasrc_pixel_type_from_gst_caps (const char *name, - const char *format, int bpp, int depth) -{ - unsigned int i; - - g_return_val_if_fail (name != NULL, PvPixelUndefined); - - for (i = 0; i < G_N_ELEMENTS (gst_caps_infos); i++) { - if (strcmp (name, gst_caps_infos[i].name) != 0 || - (depth > 0 && depth != gst_caps_infos[i].depth) || - (bpp > 0 && bpp != gst_caps_infos[i].bpp)) - continue; - - if (strcmp (name, "video/x-raw") == 0 && - strcmp (format, gst_caps_infos[i].format) == 0) - return gst_caps_infos[i].pixel_type; - - if (strcmp (name, "video/x-bayer") == 0 && - strcmp (format, gst_caps_infos[i].format) == 0) - return gst_caps_infos[i].pixel_type; - } - - return PvPixelUndefined; -} - -static gboolean -gst_pleorasrc_start (GstBaseSrc * bsrc) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - PvResult pvRes; - - GST_DEBUG_OBJECT (src, "start"); - - if (!gst_pleorasrc_setup_stream (src)) { - /* error already sent */ - goto error; - } - - /* Note: the pipeline must be initialized before we start acquisition */ - GST_DEBUG_OBJECT (src, "Starting pipeline"); - pvRes = src->pipeline->Start (); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to start pipeline: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto error; - } - - /* command stream to start */ - if (!src->receiver_only) { - PvGenParameterArray *lDeviceParams = src->device->GetParameters (); - PvGenCommand *start_cmd = - dynamic_cast < - PvGenCommand * >(lDeviceParams->Get ("AcquisitionStart")); - - GST_DEBUG_OBJECT (src, - "Opened as controller, so send AcquisitionStart command"); - - if (start_cmd == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to get device AcquisitionStart parameter"), (NULL)); - goto error; - } - pvRes = src->device->StreamEnable (); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to enable stream: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto error; - } - - GST_DEBUG_OBJECT (src, "Lock streaming-related parameters"); - lDeviceParams->SetIntegerValue ("TLParamsLocked", 1); - - pvRes = start_cmd->Execute (); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to start acquisition: %s", - pvRes.GetDescription ().GetAscii ()), (NULL)); - goto error; - } - } - - /* grab first buffer so we can set caps before _create */ - src->pvbuffer = gst_pleorasrc_get_pvbuffer (src); - if (!src->pvbuffer) { - goto error; - } - - return TRUE; - -error: - if (src->pipeline) { - delete src->pipeline; - src->pipeline = NULL; - } - - if (src->stream) { - src->stream->Close (); - PvStream::Free (src->stream); - src->stream = NULL; - } - - if (src->device) { - src->device->Disconnect (); - PvDevice::Free (src->device); - src->device = NULL; - } - - return FALSE; -} - -static gboolean -gst_pleorasrc_stop (GstBaseSrc * bsrc) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - GST_DEBUG_OBJECT (src, "stop"); - - if (!src->receiver_only) { - PvGenParameterArray *lDeviceParams = src->device->GetParameters (); - PvGenCommand *lStop = - dynamic_cast < PvGenCommand * >(lDeviceParams->Get ("AcquisitionStop")); - lStop->Execute (); - - GST_DEBUG_OBJECT (src, "Unlocking streaming-related parameters"); - lDeviceParams->SetIntegerValue ("TLParamsLocked", 0); - - src->device->StreamDisable (); - } - src->pipeline->Stop (); - - if (src->pipeline) { - delete src->pipeline; - src->pipeline = NULL; - } - - if (src->stream) { - src->stream->Close (); - PvStream::Free (src->stream); - src->stream = NULL; - } - - if (src->device) { - src->device->Disconnect (); - PvDevice::Free (src->device); - src->device = NULL; - } - - gst_pleorasrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_pleorasrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - GstCaps *caps; - - if (src->caps == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_pleorasrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - GstVideoInfo vinfo; - GstStructure *s = gst_caps_get_structure (caps, 0); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->height = GST_VIDEO_INFO_HEIGHT (&vinfo); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_ENCODED) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - } else { - GST_DEBUG (gst_structure_get_name (s)); - if (g_str_equal (gst_structure_get_name (s), "video/x-bayer")) { - const gchar *format = gst_structure_get_string (s, "format"); - gint width = GST_VIDEO_INFO_WIDTH (&vinfo); - - if (g_str_has_suffix (format, "16")) { - src->gst_stride = GST_ROUND_UP_4 (width * 2); - } else { - src->gst_stride = GST_ROUND_UP_4 (width); - } - } else { - goto unsupported_caps; - } - } - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unsupported caps: %" GST_PTR_FORMAT, caps), (NULL)); - return FALSE; -} - -static gboolean -gst_pleorasrc_unlock (GstBaseSrc * bsrc) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_pleorasrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -//static GstBuffer * -//gst_pleorasrc_create_buffer_from_pvimage (GstPleoraSrc * src, -// PvImage * pvimage) -//{ -// GstMapInfo minfo; -// GstBuffer *buf; -// -// /* TODO: use allocator or use from pool */ -// buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); -// -// /* Copy image to buffer from surface */ -// gst_buffer_map (buf, &minfo, GST_MAP_WRITE); -// GST_LOG_OBJECT (src, -// "GstBuffer size=%d, gst_stride=%d, buffer_num=%d, frame_count=%d, num_frames_on_queue=%d", -// minfo.size, src->gst_stride, circ_handle->BufferNumber, -// circ_handle->FrameCount, circ_handle->NumItemsOnQueue); -// GST_LOG_OBJECT (src, "Buffer timestamp %02d:%02d:%02d.%06d", -// circ_handle->HiResTimeStamp.hour, circ_handle->HiResTimeStamp.min, -// circ_handle->HiResTimeStamp.sec, circ_handle->HiResTimeStamp.usec); -// -// /* TODO: use orc_memcpy */ -// if (src->gst_stride == src->bf_stride) { -// memcpy (minfo.data, ((guint8 *) circ_handle->pBufData), minfo.size); -// } else { -// int i; -// GST_LOG_OBJECT (src, "Image strides not identical, copy will be slower."); -// for (i = 0; i < src->height; i++) { -// memcpy (minfo.data + i * src->gst_stride, -// ((guint8 *) circ_handle->pBufData) + -// i * src->bf_stride, src->bf_stride); -// } -// } -// gst_buffer_unmap (buf, &minfo); -// -// return buf; -//} - -typedef struct -{ - GstPleoraSrc *src; - PvBuffer *buffer; -} VideoFrame; - -static void -pvbuffer_release (void *data) -{ - VideoFrame *frame = (VideoFrame *) data; - if (frame->src->pipeline) { - // TODO: should use a mutex in case _stop is being called at the same time - frame->src->pipeline->ReleaseBuffer (frame->buffer); - } -} - -static PvBuffer * -gst_pleorasrc_get_pvbuffer (GstPleoraSrc * src) -{ - PvResult pvRes, opRes; - PvBuffer *pvbuffer; - PvImage *pvimage; - - while (TRUE) { - pvRes = src->pipeline->RetrieveNextBuffer (&pvbuffer, src->timeout, &opRes); - if (!pvRes.IsOK ()) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to retrieve buffer in timeout (%d ms): 0x%04x, '%s'", - src->timeout, pvRes.GetCode (), - pvRes.GetDescription ().GetAscii ()), (NULL)); - return NULL; - } - /* continue if we get a bad frame */ - if (!opRes.IsOK ()) { - GST_WARNING_OBJECT (src, "Failed to get buffer: 0x%04x, '%s'", - opRes.GetCode (), opRes.GetDescription ().GetAscii ()); - continue; - } - - if (pvbuffer->GetPayloadType () != PvPayloadTypeImage) { - /* TODO: are non-image buffers normal? */ - GST_ERROR_OBJECT (src, "Got buffer with non-image data"); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Got buffer with non-image data"), (NULL)); - src->pipeline->ReleaseBuffer (pvbuffer); - return NULL; - } - - break; - } - - pvimage = pvbuffer->GetImage (); - - if (src->pv_pixel_type != pvimage->GetPixelType () || - src->width != pvimage->GetWidth () || - src->height != pvimage->GetHeight ()) { - const char *caps_string = - gst_pleorasrc_pixel_type_to_gst_caps_string (pvimage->GetPixelType ()); - - if (caps_string != NULL) { - GstStructure *structure; - GstCaps *caps; - - caps = gst_caps_new_empty (); - structure = gst_structure_from_string (caps_string, NULL); - gst_structure_set (structure, - "width", G_TYPE_INT, pvimage->GetWidth (), - "height", G_TYPE_INT, pvimage->GetHeight (), - "framerate", GST_TYPE_FRACTION, 30, 1, NULL); - gst_caps_append_structure (caps, structure); - - if (src->caps) { - gst_caps_unref (src->caps); - } - src->caps = caps; - gst_base_src_set_caps (GST_BASE_SRC (src), src->caps); - - src->pv_pixel_type = pvimage->GetPixelType (); - src->width = pvimage->GetWidth (); - src->height = pvimage->GetHeight (); - - guint32 pixel_bpp = PvGetPixelBitCount (pvimage->GetPixelType ()); - src->pleora_stride = (pvimage->GetWidth () * pixel_bpp) / 8; - } else { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Pixel type %d not supported", - pvimage->GetPixelType ()), (NULL)); - src->pipeline->ReleaseBuffer (pvbuffer); - return NULL; - } - } - - return pvbuffer; -} - -static GstFlowReturn -gst_pleorasrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstPleoraSrc *src = GST_PLEORA_SRC (psrc); - PvResult pvRes; - GstClock *clock; - GstClockTime clock_time; - PvBuffer *pvbuffer; - PvImage *pvimage; - - GST_LOG_OBJECT (src, "create"); - - if (src->pvbuffer) { - /* we have a buffer from _start to handle */ - pvbuffer = src->pvbuffer; - src->pvbuffer = NULL; - } else { - pvbuffer = gst_pleorasrc_get_pvbuffer (src); - } - - if (!pvbuffer) { - /* error already posted */ - return GST_FLOW_ERROR; - } - - /* wrap or copy image data to buffer */ - pvimage = pvbuffer->GetImage (); - gpointer data = pvimage->GetDataPointer (); - if (src->pleora_stride == src->gst_stride) { - VideoFrame *vf = g_new0 (VideoFrame, 1); - vf->src = src; - vf->buffer = pvbuffer; - - gsize data_size = pvimage->GetImageSize (); - - *buf = - gst_buffer_new_wrapped_full ((GstMemoryFlags) GST_MEMORY_FLAG_READONLY, - (gpointer) data, data_size, 0, data_size, vf, - (GDestroyNotify) pvbuffer_release); - } else { - GstMapInfo minfo; - - GST_LOG_OBJECT (src, - "Row stride not aligned, copying %d -> %d", - src->pleora_stride, src->gst_stride); - - *buf = gst_buffer_new_and_alloc (src->height * src->gst_stride); - - guint8 *s = (guint8 *) data; - guint8 *d; - - gst_buffer_map (*buf, &minfo, GST_MAP_WRITE); - d = minfo.data; - - g_assert (minfo.size >= src->pleora_stride * src->height); - for (int i = 0; i < src->height; i++) - memcpy (d + i * src->gst_stride, s + i * src->pleora_stride, - src->pleora_stride); - gst_buffer_unmap (*buf, &minfo); - } - - /* TODO: use PvBuffer timestamps */ - clock = gst_element_get_clock (GST_ELEMENT (src)); - clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - -#ifdef GST_PLUGINS_VISION_ENABLE_KLV - if (src->output_klv && pvbuffer->HasChunks ()) { - guint32 num_chunks; - num_chunks = pvbuffer->GetChunkCount (); - GST_LOG_OBJECT (src, "Buffer has %d chunk(s) with layout ID %d", num_chunks, - pvbuffer->GetChunkLayoutID ()); - - /* TODO: spec says "Image must be the first chunk", but that doesn't seem - to be true, so check every chunk */ - for (guint i = 0; i < num_chunks; ++i) { - guint32 chunk_id, chunk_size; - const guint8 *chunk_data; - - pvRes = pvbuffer->GetChunkIDByIndex (i, chunk_id); - if (!pvRes.IsOK ()) { - GST_WARNING_OBJECT (src, "Failed to get chunk ID for index %d: '%s'", i, - pvRes.GetDescription ().GetAscii ()); - continue; - } - - chunk_size = pvbuffer->GetChunkSizeByIndex (i); - if (chunk_size == 0) { - GST_WARNING_OBJECT (src, "Chunk size reported as zero for index %d", i); - continue; - } - - chunk_data = pvbuffer->GetChunkRawDataByIndex (i); - if (chunk_data == NULL) { - GST_WARNING_OBJECT (src, "Chunk data is NULL for index %d", i); - continue; - } - - GST_LOG_OBJECT (src, - "Found chunk at index %d with ID %04x of size %d bytes", i, chunk_id, - chunk_size); - GST_MEMDUMP_OBJECT (src, "Chunk data", chunk_data, chunk_size); - - if (chunk_size < 17) { - GST_LOG_OBJECT (src, "Chunk data is too small to contain KLV"); - continue; - } - - if (GST_READ_UINT32_BE (chunk_data) != 0x060E2B34) { - GST_LOG_OBJECT (src, "Chunk doesn't contain KLV data"); - continue; - } - - GST_LOG_OBJECT (src, "Adding KLV meta to buffer"); - /* TODO: do we need to exclude padding that may be present? */ - gst_buffer_add_klv_meta_from_data (*buf, chunk_data, chunk_size); - } - } -#endif // GST_PLUGINS_VISION_ENABLE_KLV - - if (src->pleora_stride != src->gst_stride) { - src->pipeline->ReleaseBuffer (pvbuffer); - pvbuffer = NULL; - } - - /* check for dropped frames and disrupted signal */ - //dropped_frames = (circ_handle.FrameCount - src->last_frame_count) - 1; - //if (dropped_frames > 0) { - // src->total_dropped_frames += dropped_frames; - // GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - // src->total_dropped_frames); - //} else if (dropped_frames < 0) { - // GST_WARNING_OBJECT (src, "Frame count non-monotonic, signal disrupted?"); - //} - //src->last_frame_count = circ_handle.FrameCount; - - /* create GstBuffer then release circ buffer back to acquisition */ - //*buf = gst_pleorasrc_create_buffer_from_circ_handle (src, &circ_handle); - //ret = - // BiCirStatusSet (src->board, &src->buffer_array, circ_handle, BIAVAILABLE); - //if (ret != BI_OK) { - // GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - // ("Failed to release buffer: %s", gst_pleorasrc_get_error_string (src, - // ret)), (NULL)); - // return GST_FLOW_ERROR; - //} - - /* TODO: understand why timestamps for circ_handle are sometimes 0 */ - //GST_BUFFER_TIMESTAMP (*buf) = - // GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - // src->acq_start_time + circ_handle.HiResTimeStamp.totalSec * GST_SECOND); - GST_BUFFER_TIMESTAMP (*buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - clock_time); - //GST_BUFFER_OFFSET (*buf) = circ_handle.FrameCount - 1; - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - return GST_FLOW_OK; -} diff --git a/sys/pleora/gstpleorasrc.h b/sys/pleora/gstpleorasrc.h deleted file mode 100644 index 1aa19bd..0000000 --- a/sys/pleora/gstpleorasrc.h +++ /dev/null @@ -1,87 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_PLEORA_SRC_H_ -#define _GST_PLEORA_SRC_H_ - -#include - -#include -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_PLEORA_SRC (gst_pleorasrc_get_type()) -#define GST_PLEORA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLEORA_SRC,GstPleoraSrc)) -#define GST_PLEORA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLEORA_SRC,GstPleoraSrcClass)) -#define GST_IS_PLEORA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLEORA_SRC)) -#define GST_IS_PLEORA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLEORA_SRC)) - -typedef struct _GstPleoraSrc GstPleoraSrc; -typedef struct _GstPleoraSrcClass GstPleoraSrcClass; - -struct _GstPleoraSrc -{ - GstPushSrc base_pleorasrc; - - /* camera handle */ - PvPipeline *pipeline; - PvDevice *device; - PvStream *stream; - PvBuffer *pvbuffer; - PvDeviceType device_type; - - /* properties */ - gchar *device_id; - gint device_index; - guint num_capture_buffers; - gint timeout; - gint detection_timeout; - gchar *multicast_group; - gint port; - gboolean receiver_only; - gint packet_size; - gchar *config_file; - gboolean config_file_connect; - gboolean output_klv; - - guint32 last_frame_count; - guint32 total_dropped_frames; - - GstCaps *caps; - PvPixelType pv_pixel_type; - gint width; - gint height; - gint gst_stride; - gint pleora_stride; - - gboolean stop_requested; -}; - -struct _GstPleoraSrcClass -{ - GstPushSrcClass base_pleorasrc_class; -}; - -GType gst_pleorasrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/pleora/streamingchannelsource.cpp b/sys/pleora/streamingchannelsource.cpp deleted file mode 100644 index 23e7287..0000000 --- a/sys/pleora/streamingchannelsource.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ - -#include "streamingchannelsource.h" -#include "klv.h" - -/* setup debug */ -GST_DEBUG_CATEGORY_EXTERN (pleorasink_debug); -#define GST_CAT_DEFAULT pleorasink_debug - -/* these seem to be arbitrary */ -#define CHUNKLAYOUTID 0xABCD -#define KLV_CHUNKID 0xFEDC - -GstStreamingChannelSource::GstStreamingChannelSource () -: mBufferCount (0), - mChunkModeActive(TRUE), mChunkKlvEnabled(TRUE), mKlvChunkSize(0), - mStreamingStarted(false) -{ - mInputQueue = g_async_queue_new (); - mOutputQueue = g_async_queue_new (); -} - -void GstStreamingChannelSource::OnStreamingStart() -{ - GST_DEBUG_OBJECT(mSink, "Controller has requested streaming start"); - mStreamingStarted = true; -} - -void GstStreamingChannelSource::OnStreamingStop() -{ - GST_DEBUG_OBJECT(mSink, "Controller has requested streaming stop"); - mStreamingStarted = false; -} - -void -GstStreamingChannelSource::GetWidthInfo (uint32_t & aMin, uint32_t & aMax, - uint32_t & aInc) const -{ - aMin = mWidth; - aMax = aMin; - aInc = 2; -} - -void -GstStreamingChannelSource::GetHeightInfo (uint32_t & aMin, uint32_t & aMax, - uint32_t & aInc) const -{ - aMin = mHeight; - aMax = aMin; - aInc = 2; -} - -PvResult GstStreamingChannelSource::GetSupportedPixelType (int aIndex, - PvPixelType & aPixelType) const -{ - if (aIndex != 0) { - return PvResult::Code::INVALID_PARAMETER; - } - - aPixelType = mPixelType; - return PvResult::Code::OK; -} - -PvResult GstStreamingChannelSource::GetSupportedChunk (int aIndex, uint32_t &aID, PvString &aName) const -{ - switch (aIndex) { - case 0: - aID = KLV_CHUNKID; - aName = "KLV"; - return PvResult::Code::OK; - default: - break; - } - - return PvResult::Code::INVALID_PARAMETER; -} - -bool GstStreamingChannelSource::GetChunkEnable (uint32_t aChunkID) const -{ - switch (aChunkID) { - case KLV_CHUNKID: - return mChunkKlvEnabled; - default: - break; - } - - return false; -} - -PvResult GstStreamingChannelSource::SetChunkEnable (uint32_t aChunkID, bool aEnabled) -{ - switch (aChunkID) { - case KLV_CHUNKID: - mChunkKlvEnabled = aEnabled; - mSink->output_klv = mChunkKlvEnabled; - return PvResult::Code::OK; - default: - break; - } - - return PvResult::Code::INVALID_PARAMETER; -} - -uint32_t GstStreamingChannelSource::GetRequiredChunkSize() const -{ - if (mChunkModeActive && mChunkKlvEnabled) { - /* chunk data must be multiple of 4 bytes, and 16 bytes extra seem - to be needed for chunk ID and length */ - return GST_ROUND_UP_4 (mKlvChunkSize) + 16; - } else { - return 0; - } -} - -void GstStreamingChannelSource::SetKlvEnabled (bool enable) -{ - SetChunkEnable (KLV_CHUNKID, enable); -} - -gboolean GstStreamingChannelSource::GetKlvEnabled() -{ - return GetChunkEnable (KLV_CHUNKID); -} - -PvBuffer * GstStreamingChannelSource::AllocBuffer () -{ - if (mBufferCount < mSink->num_internal_buffers) { - GST_LOG_OBJECT(mSink, "Allocating buffer #%d", mBufferCount); - PvBuffer *buf = new PvBuffer; - buf->SetID(mBufferCount); - mBufferCount++; - - return buf; - } - return NULL; -} - -void GstStreamingChannelSource::FreeBuffer (PvBuffer * aBuffer) -{ - delete aBuffer; - mBufferCount--; -} - -PvResult GstStreamingChannelSource::QueueBuffer (PvBuffer * aBuffer) -{ - GST_LOG_OBJECT(mSink, "Pushing buffer #%d to input queue", aBuffer->GetID()); - g_async_queue_push(mInputQueue, aBuffer); - return PvResult::Code::OK; -} - -PvResult GstStreamingChannelSource::RetrieveBuffer(PvBuffer** aBuffer) -{ - guint64 timeout_ms = 50; - *aBuffer = (PvBuffer*)(g_async_queue_timeout_pop(mOutputQueue, timeout_ms * 1000)); - if (!*aBuffer) { - GST_WARNING_OBJECT(mSink, "No buffers available in output queue after %llu ms, possibly slow video framerate", timeout_ms); - return PvResult::Code::NO_AVAILABLE_DATA; - } - - GST_LOG_OBJECT (mSink, "Returning buffer #%llu from output queue to GEV streaming thread", (*aBuffer)->GetID()); - return PvResult::Code::OK; -} - -void -GstStreamingChannelSource::SetSink (GstPleoraSink * sink) -{ - mSink = sink; -} - -void -GstStreamingChannelSource::SetCaps (GstCaps * caps) -{ - GstVideoInfo vinfo; - gst_video_info_from_caps (&vinfo, caps); - - switch (GST_VIDEO_INFO_FORMAT (&vinfo)) { - case GST_VIDEO_FORMAT_GRAY8: - mPixelType = PvPixelMono8; - break; - case GST_VIDEO_FORMAT_GRAY16_LE: - mPixelType = PvPixelMono16; - break; - case GST_VIDEO_FORMAT_RGB: - mPixelType = PvPixelRGB8; - break; - case GST_VIDEO_FORMAT_RGBA: - mPixelType = PvPixelRGBa8; - break; - case GST_VIDEO_FORMAT_BGR: - mPixelType = PvPixelBGR8; - break; - case GST_VIDEO_FORMAT_BGRA: - mPixelType = PvPixelBGRa8; - break; - default: - mPixelType = PvPixelUndefined; - break; - } - - mWidth = GST_VIDEO_INFO_WIDTH (&vinfo); - mHeight = GST_VIDEO_INFO_HEIGHT (&vinfo); -} - -void -GstStreamingChannelSource::ResizeBufferIfNeeded (PvBuffer * aBuffer) -{ - uint32_t lRequiredChunkSize = GetRequiredChunkSize(); - PvImage *lImage = aBuffer->GetImage (); - if ((lImage->GetWidth () != mWidth) || - (lImage->GetHeight () != mHeight) || - (lImage->GetPixelType () != mPixelType) || - (lImage->GetMaximumChunkLength () != lRequiredChunkSize)) { - GST_LOG_OBJECT (mSink, "Width=%d, Height=%d, PixelType=%d, and/or ChunkLength=%d changed, reallocating buffer", mWidth, mHeight, mPixelType, lRequiredChunkSize); - lImage->Alloc (mWidth, mHeight, mPixelType, 0, 0, lRequiredChunkSize); - } -} - -void -GstStreamingChannelSource::SetBuffer (GstBuffer * buf) -{ - GByteArray * klv_byte_array = NULL; - - PvBuffer* pvBuffer; - - guint64 timeout_ms = 50; - pvBuffer = (PvBuffer*)(g_async_queue_timeout_pop (mInputQueue, timeout_ms * 1000)); - if (!pvBuffer) { - if (mStreamingStarted) { - GST_WARNING_OBJECT(mSink, "No free buffers, dropping frame. No consumers connected, or insufficient network bandwidth. Try increasing num-internal-buffers and/or packet-size."); - } - else { - GST_LOG_OBJECT(mSink, "Dropping frame as no controller has requested streaming to start"); - } - return; - } - - GST_LOG_OBJECT(mSink, "Got buffer #%llu from input queue to fill with video data", pvBuffer->GetID()); - - if (mChunkKlvEnabled) { - klv_byte_array = GetKlvByteArray (buf); - if (klv_byte_array) { - mKlvChunkSize = klv_byte_array->len; - } else { - mKlvChunkSize = 0; - } - } - - ResizeBufferIfNeeded (pvBuffer); - - /* TODO: avoid memcpy (when strides align) by attaching to PvBuffer */ - GstMapInfo minfo; - gst_buffer_map (buf, &minfo, GST_MAP_READ); - - - guint8 *dst = pvBuffer->GetDataPointer (); - if (!dst) { - GST_ERROR_OBJECT (mSink, "Have buffer to fill, but data pointer is invalid"); - //g_mutex_unlock (&mSink->mutex); - return; - } - g_assert (pvBuffer->GetSize () >= minfo.size); - /* TODO: fix stride if needed */ - memcpy (dst, minfo.data, minfo.size); - - gst_buffer_unmap (buf, &minfo); - - pvBuffer->ResetChunks(); - pvBuffer->SetChunkLayoutID(CHUNKLAYOUTID); - - if (mChunkKlvEnabled && klv_byte_array && klv_byte_array->len > 0) { - PvResult pvRes; - pvRes = pvBuffer->AddChunk (KLV_CHUNKID, (uint8_t*)klv_byte_array->data, klv_byte_array->len); - if (pvRes.IsOK ()) { - GST_LOG_OBJECT (mSink, "Added KLV as chunk data (len=%d)", klv_byte_array->len); - } else { - GST_WARNING_OBJECT (mSink, "Failed to add KLV as chunk data (len=%d): %s", - klv_byte_array->len, - pvRes.GetDescription ().GetAscii ()); - } - } - - if (klv_byte_array) { - g_byte_array_unref (klv_byte_array); - } - - GST_LOG_OBJECT(mSink, "Pushing buffer #%d to output queue", pvBuffer->GetID()); - g_async_queue_push(mOutputQueue, pvBuffer); -} - -GByteArray * GstStreamingChannelSource::GetKlvByteArray (GstBuffer * buf) -{ - GstKLVMeta *klv_meta; - gpointer iter = NULL; - GByteArray *byte_array; - - byte_array = g_byte_array_new (); - -#ifdef GST_PLUGINS_VISION_ENABLE_KLV - /* spec says KLV can all be in one chunk, or multiple chunks, we do one chunk */ - while ((klv_meta = (GstKLVMeta *) gst_buffer_iterate_meta_filtered (buf, - &iter, GST_KLV_META_API_TYPE))) { - gsize klv_size; - const guint8 *klv_data; - klv_data = gst_klv_meta_get_data (klv_meta, &klv_size); - if (!klv_data) { - GST_WARNING_OBJECT (mSink, "Failed to get KLV data from meta"); - break; - } - - g_byte_array_append (byte_array, klv_data, (guint)klv_size); - } - - /* chunk length must be multiple of 4 bytes */ - if (byte_array->len % 4 != 0) { - const guint8 padding[4] = {0}; - const guint padding_len = GST_ROUND_UP_4 (byte_array->len) - byte_array->len; - g_byte_array_append (byte_array, padding, padding_len); - } -#endif // GST_PLUGINS_VISION_ENABLE_KLV - - return byte_array; -} \ No newline at end of file diff --git a/sys/pleora/streamingchannelsource.h b/sys/pleora/streamingchannelsource.h deleted file mode 100644 index dc02cd3..0000000 --- a/sys/pleora/streamingchannelsource.h +++ /dev/null @@ -1,75 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ - -#include - -#include "gstpleorasink.h" - -class GstStreamingChannelSource:public PvStreamingChannelSourceDefault -{ -public: - GstStreamingChannelSource (); - - void OnStreamingStart(); - void OnStreamingStop(); - - void SetSink (GstPleoraSink * sink); - void SetCaps (GstCaps * caps); - void ResizeBufferIfNeeded (PvBuffer * aBuffer); - void SetBuffer (GstBuffer * buf); - - PvBuffer *AllocBuffer (); - void FreeBuffer (PvBuffer * aBuffer); - - PvResult QueueBuffer (PvBuffer * aBuffer); - PvResult RetrieveBuffer (PvBuffer ** aBuffer); - - void GetWidthInfo (uint32_t & aMin, uint32_t & aMax, uint32_t & aInc) const; - void GetHeightInfo (uint32_t & aMin, uint32_t & aMax, uint32_t & aInc) const; - PvResult GetSupportedPixelType (int aIndex, PvPixelType & aPixelType) const; - - PvResult GetSupportedChunk (int aIndex, uint32_t &aID, PvString &aName) const; - bool GetChunkEnable (uint32_t aChunkID) const; - PvResult SetChunkEnable (uint32_t aChunkID, bool aEnabled); - bool GetChunkModeActive() const { return mChunkModeActive; } - PvResult SetChunkModeActive( bool aEnabled ) { mChunkModeActive = aEnabled; return PvResult::Code::OK; } - uint32_t GetChunksSize() const { return GetRequiredChunkSize(); } - - uint32_t GetRequiredChunkSize () const; - void SetKlvEnabled (bool enable = true); - gboolean GetKlvEnabled (); - GByteArray * GetKlvByteArray (GstBuffer * buf); - -private: - GstPleoraSink * mSink; - GAsyncQueue* mInputQueue; - GAsyncQueue* mOutputQueue; - gint mBufferCount; - - gint mWidth; - gint mHeight; - PvPixelType mPixelType; - - bool mChunkModeActive; - bool mChunkKlvEnabled; - - gint mKlvChunkSize; - - bool mStreamingStarted; -}; \ No newline at end of file diff --git a/sys/pylon/CMakeLists.txt b/sys/pylon/CMakeLists.txt deleted file mode 100644 index 5a25a19..0000000 --- a/sys/pylon/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -set (SOURCES - gstpylonsrc.c - ) - -set (HEADERS - gstpylonsrc.h) - -include_directories (AFTER - ${GSTREAMER_INCLUDE_DIR}/.. - ${PYLON_INCLUDE_DIR} - ) - -set (libname gstpylon) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${PYLON_LIBRARIES} - ) - -if(MSVC) - target_compile_options(${libname} PRIVATE /W4) -else() - target_compile_options(${libname} PRIVATE -Wall) -endif() - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/pylon/gstpylonsrc.c b/sys/pylon/gstpylonsrc.c deleted file mode 100644 index 11ea266..0000000 --- a/sys/pylon/gstpylonsrc.c +++ /dev/null @@ -1,4421 +0,0 @@ -/* GStreamer - * Copyright (C) 2016-2017 Ingmars Melkis - * Copyright (C) 2018 Ingmars Melkis - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstpylonsrc - * - * The pylonsrc element uses Basler's pylonc API to get video from Basler's USB3 Vision cameras. - * - * - * Example launch line - * |[ - * gst-launch-1.0 -v pylonsrc ! bayer2rgb ! videoconvert ! xvimagesink - * ]| - * Outputs camera output to screen. - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstpylonsrc.h" -#include -#include - -#include "genapic/GenApiC.h" -#include "common/genicampixelformat.h" - - -static int plugin_counter = 0; - -int -gst_pylonsrc_ref_pylon_environment () -{ - if (plugin_counter == 0) { - GST_DEBUG ("pylonsrc: Initializing Pylon environment"); - if (PylonInitialize () != GENAPI_E_OK) { - return -1; - } - } - return ++plugin_counter; -} - -int -gst_pylonsrc_unref_pylon_environment () -{ - if (plugin_counter == 1) { - GST_DEBUG ("pylonsrc: Terminating Pylon environment"); - if (PylonTerminate () != GENAPI_E_OK) { - return -1; - } - } - - if (plugin_counter > 0) { - plugin_counter--; - } - - return plugin_counter; -} - -/* PylonC */ -_Bool pylonc_reset_camera (GstPylonSrc * src); -_Bool pylonc_connect_camera (GstPylonSrc * src); -void pylonc_disconnect_camera (GstPylonSrc * src); -void pylonc_print_camera_info (GstPylonSrc * src, - PYLON_DEVICE_HANDLE deviceHandle, int deviceId); - -/* debug category */ -GST_DEBUG_CATEGORY_STATIC (gst_pylonsrc_debug_category); -#define GST_CAT_DEFAULT gst_pylonsrc_debug_category -#define PYLONC_CHECK_ERROR(obj, res) if (res != GENAPI_E_OK) { char* errMsg; size_t length; GenApiGetLastErrorMessage( NULL, &length ); errMsg = (char*) malloc( length ); GenApiGetLastErrorMessage( errMsg, &length ); GST_CAT_LEVEL_LOG(GST_CAT_DEFAULT, GST_LEVEL_NONE, obj, "PylonC error: %s (%#08x).\n", errMsg, (unsigned int) res); free(errMsg); GenApiGetLastErrorDetail( NULL, &length ); errMsg = (char*) malloc( length ); GenApiGetLastErrorDetail( errMsg, &length ); GST_CAT_LEVEL_LOG(GST_CAT_DEFAULT, GST_LEVEL_NONE, obj, "PylonC error: %s\n", errMsg); free(errMsg); goto error; } - -/* prototypes */ -static void gst_pylonsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_pylonsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_pylonsrc_dispose (GObject * object); -static void gst_pylonsrc_finalize (GObject * object); - -static gboolean gst_pylonsrc_start (GstBaseSrc * bsrc); -static gboolean gst_pylonsrc_stop (GstBaseSrc * bsrc); -static GstCaps *gst_pylonsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter); -static gboolean gst_pylonsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps); - -static GstFlowReturn gst_pylonsrc_create (GstPushSrc * bsrc, GstBuffer ** buf); - -static void gst_pylonsrc_update_caps (GstPylonSrc * src); -static gchar *read_string_feature (GstPylonSrc * src, const char *feature); - -/* parameters */ -typedef enum _GST_PYLONSRC_PROP -{ - PROP_0, - PROP_CAMERA, - PROP_HEIGHT, - PROP_WIDTH, - PROP_BINNINGH, - PROP_BINNINGV, - PROP_LIMITBANDWIDTH, - PROP_MAXBANDWIDTH, - PROP_SENSORREADOUTMODE, - PROP_ACQUISITIONFRAMERATEENABLE, - PROP_FPS, - PROP_LIGHTSOURCE, - PROP_AUTOEXPOSURE, - PROP_EXPOSURE, - PROP_AUTOWHITEBALANCE, - PROP_BALANCERED, - PROP_BALANCEGREEN, - PROP_BALANCEBLUE, - PROP_COLORREDHUE, - PROP_COLORREDSATURATION, - PROP_COLORYELLOWHUE, - PROP_COLORYELLOWSATURATION, - PROP_COLORGREENHUE, - PROP_COLORGREENSATURATION, - PROP_COLORCYANHUE, - PROP_COLORCYANSATURATION, - PROP_COLORBLUEHUE, - PROP_COLORBLUESATURATION, - PROP_COLORMAGENTAHUE, - PROP_COLORMAGENTASATURATION, - PROP_COLORADJUSTMENTENABLE, - PROP_AUTOGAIN, - PROP_GAIN, - PROP_BLACKLEVEL, - PROP_GAMMA, - PROP_RESET, - PROP_TESTIMAGE, - PROP_TESTIMAGESOURCE, - PROP_CONTINUOUSMODE, - PROP_PIXEL_FORMAT, - PROP_USERID, - PROP_BASLERDEMOSAICING, - PROP_DEMOSAICINGNOISEREDUCTION, - PROP_DEMOSAICINGSHARPNESSENHANCEMENT, - PROP_OFFSETX, - PROP_CENTERX, - PROP_OFFSETY, - PROP_CENTERY, - PROP_FLIPX, - PROP_FLIPY, - PROP_AUTOEXPOSUREUPPERLIMIT, - PROP_AUTOEXPOSURELOWERLIMIT, - PROP_GAINUPPERLIMIT, - PROP_GAINLOWERLIMIT, - PROP_AUTOPROFILE, - PROP_AUTOBRIGHTNESSTARGET, - PROP_TRANSFORMATIONSELECTOR, - PROP_TRANSFORMATION00, - PROP_TRANSFORMATION01, - PROP_TRANSFORMATION02, - PROP_TRANSFORMATION10, - PROP_TRANSFORMATION11, - PROP_TRANSFORMATION12, - PROP_TRANSFORMATION20, - PROP_TRANSFORMATION21, - PROP_TRANSFORMATION22, - PROP_FRAMEDROPLIMIT, - PROP_GRABTIMEOUT, - PROP_PACKETSIZE, - PROP_INTERPACKETDELAY, - PROP_FRAMETRANSDELAY, - PROP_BANDWIDTHRESERVE, - PROP_BANDWIDTHRESERVEACC, - PROP_MAXTRANSFERSIZE, - - PROP_CONFIGFILE, - PROP_IGNOREDEFAULTS, - - PROP_NUM_PROPERTIES // Yes, there is PROP_0 that represent nothing, so actually there are (PROP_NUMPROPS - 1) properties. - // But this way you can intuitively access propFlags[] by index -} GST_PYLONSRC_PROP; - -G_STATIC_ASSERT ((int) PROP_NUM_PROPERTIES == GST_PYLONSRC_NUM_PROPS); - -typedef enum _GST_PYLONSRC_AUTOFEATURE -{ - AUTOF_GAIN, - AUTOF_EXPOSURE, - AUTOF_WHITEBALANCE, - - AUTOF_NUM_FEATURES, - - AUTOF_NUM_LIMITED = 2 -} GST_PYLONSRC_AUTOFEATURE; - -G_STATIC_ASSERT ((int) AUTOF_NUM_FEATURES == GST_PYLONSRC_NUM_AUTO_FEATURES); -G_STATIC_ASSERT ((int) AUTOF_NUM_LIMITED == GST_PYLONSRC_NUM_LIMITED_FEATURES); - -typedef struct _DemosaicingStrings -{ - const char *name; - const char *on; - const char *off; -} DemosaicingStrings; - -static const DemosaicingStrings featDemosaicing[2] = { - {"DemosaicingMode", "BaslerPGI", "Simple"}, - {"PgiMode", "On", "Off"} -}; -static const char *const featAutoFeature[AUTOF_NUM_FEATURES] = - { "GainAuto", "ExposureAuto", "BalanceWhiteAuto" }; -static const GST_PYLONSRC_PROP propAutoFeature[AUTOF_NUM_FEATURES] = - { PROP_AUTOGAIN, PROP_AUTOEXPOSURE, PROP_AUTOWHITEBALANCE }; -// Yes,there is no "WhiteBalance" feature, it is only used for logging -static const char *const featManualFeature[AUTOF_NUM_FEATURES] = - { "Gain", "ExposureTime", "WhiteBalance" }; -static const char *const featManualFeatureAlias[AUTOF_NUM_LIMITED] = - { "GainRaw", "ExposureTimeAbs" }; -static const char *const featLimitedLower[AUTOF_NUM_LIMITED] = - { "AutoGainLowerLimit", "AutoExposureTimeLowerLimit" }; -static const char *const featLimitedUpper[AUTOF_NUM_LIMITED] = - { "AutoGainUpperLimit", "AutoExposureTimeUpperLimit" }; -static const char *const featLimitedLowerAlias[AUTOF_NUM_LIMITED] = - { "AutoGainRawLowerLimit", "AutoExposureTimeAbsLowerLimit" }; -static const char *const featLimitedUpperAlias[AUTOF_NUM_LIMITED] = - { "AutoGainRawUpperLimit", "AutoExposureTimeAbsUpperLimit" }; -static const GST_PYLONSRC_PROP propManualFeature[AUTOF_NUM_LIMITED] = - { PROP_GAIN, PROP_EXPOSURE }; -static const GST_PYLONSRC_PROP propLimitedLower[AUTOF_NUM_LIMITED] = - { PROP_GAINLOWERLIMIT, PROP_AUTOEXPOSURELOWERLIMIT }; -static const GST_PYLONSRC_PROP propLimitedUpper[AUTOF_NUM_LIMITED] = - { PROP_GAINUPPERLIMIT, PROP_AUTOEXPOSUREUPPERLIMIT }; - -typedef enum _GST_PYLONSRC_AXIS -{ - AXIS_X, - AXIS_Y -} GST_PYLONSRC_AXIS; - -static const GST_PYLONSRC_AXIS otherAxis[2] = { AXIS_Y, AXIS_X }; - -static const char *const featOffset[2] = { "OffsetX", "OffsetY" }; -static const char *const featCenter[2] = { "CenterX", "CenterY" }; -static const char *const featCenterAlias[2] = { "BslCenterX", "BslCenterY" }; -static const GST_PYLONSRC_PROP propOffset[2] = { PROP_OFFSETX, PROP_OFFSETY }; -static const GST_PYLONSRC_PROP propCenter[2] = { PROP_CENTERX, PROP_CENTERY }; - -static const char *const featReverse[2] = { "ReverseX", "ReverseY" }; -static const GST_PYLONSRC_PROP propReverse[2] = { PROP_FLIPX, PROP_FLIPY }; - -static const GST_PYLONSRC_PROP propBinning[2] = - { PROP_BINNINGH, PROP_BINNINGV }; -static const GST_PYLONSRC_PROP propSize[2] = { PROP_WIDTH, PROP_HEIGHT }; -static const char *const featBinning[2] = - { "BinningHorizontal", "BinningVertical" }; -static const char *const featSize[2] = { "Width", "Height" }; -static const char *const featMaxSize[2] = { "WidthMax", "HeightMax" }; - -static const char *const featTransform[3][3] = { - {"Gain00", "Gain01", "Gain02"}, - {"Gain10", "Gain11", "Gain12"}, - {"Gain20", "Gain21", "Gain22"} -}; - -static const double defaultTransform[3][3] = { - {1.4375, -0.3125, -0.125}, - {-0.28125, 1.75, -0.46875}, - {0.0625, -0.8125, 1.75} -}; - -static const GST_PYLONSRC_PROP propTransform[3][3] = { - {PROP_TRANSFORMATION00, PROP_TRANSFORMATION01, PROP_TRANSFORMATION02}, - {PROP_TRANSFORMATION10, PROP_TRANSFORMATION11, PROP_TRANSFORMATION12}, - {PROP_TRANSFORMATION20, PROP_TRANSFORMATION21, PROP_TRANSFORMATION22} -}; - -typedef enum _GST_PYLONSRC_COLOUR -{ - COLOUR_RED, - COLOUR_GREEN, - COLOUR_BLUE, - COLOUR_CYAN, - COLOUR_MAGENTA, - COLOUR_YELLOW -} GST_PYLONSRC_COLOUR; - -static const char *const featColour[6] = - { "Red", "Green", "Blue", "Cyan", "Magenta", "Yellow" }; -static const GST_PYLONSRC_PROP propColourBalance[3] = - { PROP_BALANCERED, PROP_BALANCEGREEN, PROP_BALANCEBLUE }; -static const GST_PYLONSRC_PROP propColourHue[6] = - { PROP_COLORREDHUE, PROP_COLORGREENHUE, PROP_COLORBLUEHUE, - PROP_COLORCYANHUE, PROP_COLORMAGENTAHUE, PROP_COLORYELLOWHUE -}; - -static const GST_PYLONSRC_PROP propColourSaturation[6] = - { PROP_COLORREDSATURATION, PROP_COLORGREENSATURATION, - PROP_COLORBLUESATURATION, - PROP_COLORCYANSATURATION, PROP_COLORMAGENTASATURATION, - PROP_COLORYELLOWSATURATION -}; - -static inline const char * -boolalpha (_Bool arg) -{ - return arg ? "True" : "False"; -} - -static inline void -ascii_strdown (gchar * *str, gssize len) -{ - gchar *temp = g_ascii_strdown (*str, len); - g_free (*str); - *str = temp; -} - -#define DEFAULT_PROP_CAMERA 0 -#define DEFAULT_PROP_SIZE 0 -#define DEFAULT_PROP_BINNING 1 -#define DEFAULT_PROP_LIMITBANDWIDTH TRUE -#define DEFAULT_PROP_MAXBANDWIDTH 0 -#define DEFAULT_PROP_SENSORREADOUTMODE "normal" -#define DEFAULT_PROP_ACQUISITIONFRAMERATEENABLE FALSE -#define DEFAULT_PROP_FPS 0.0 -#define DEFAULT_PROP_LIGHTSOURCE "5000k" -#define DEFAULT_PROP_AUTOFEATURE "off" -#define DEFAULT_PROP_LIMITED_MANUAL 0.0 -#define DEFAULT_PROP_BALANCE 1.0 -#define DEFAULT_PROP_HUE 0.0 -#define DEFAULT_PROP_SATURATION 0.0 -#define DEFAULT_PROP_BLACKLEVEL 0.0 -#define DEFAULT_PROP_GAMMA 1.0 -#define DEFAULT_PROP_RESET "off" -#define DEFAULT_PROP_TESTIMAGE 0 -#define DEFAULT_PROP_TESTIMAGESOURCE "" -#define DEFAULT_PROP_CONTINUOUSMODE TRUE -#define DEFAULT_PROP_PIXEL_FORMAT "auto" -#define DEFAULT_PROP_USERID "" -#define DEFAULT_PROP_BASLERDEMOSAICING FALSE -#define DEFAULT_PROP_DEMOSAICINGNOISEREDUCTION 0.0 -#define DEFAULT_PROP_DEMOSAICINGSHARPNESSENHANCEMENT 1.0 -#define DEFAULT_PROP_OFFSET 0 -#define DEFAULT_PROP_CENTER FALSE -#define DEFAULT_PROP_FLIP FALSE -#define DEFAULT_PROP_AUTOEXPOSURELOWERLIMIT 105.0 -#define DEFAULT_PROP_AUTOEXPOSUREUPPERLIMIT 1000000.0 -#define DEFAULT_PROP_GAINLOWERLIMIT 0.0 -#define DEFAULT_PROP_GAINUPPERLIMIT 12.00921 -#define DEFAULT_PROP_AUTOBRIGHTNESSTARGET 0.50196 -#define DEFAULT_PROP_AUTOPROFILE "gain" -#define DEFAULT_PROP_TRANSFORMATIONSELECTOR "RGBRGB" -#define DEFAULT_PROP_CONFIGFILE "" -#define DEFAULT_PROP_IGNOREDEFAULTS FALSE -#define DEFAULT_PROP_COLORADJUSTMENTENABLE TRUE -#define DEFAULT_PROP_FRAMEDROPLIMIT 10 -#define DEFAULT_PROP_GRABTIMEOUT 1000 -#define DEFAULT_PROP_PACKETSIZE 1500 -#define DEFAULT_PROP_INTERPACKETDELAY 0 -#define DEFAULT_PROP_FRAMETRANSDELAY 0 -#define DEFAULT_PROP_BANDWIDTHRESERVE 10 -#define DEFAULT_PROP_BANDWIDTHRESERVEACC 10 -#define DEFAULT_PROP_MAXTRANSFERSIZE 262144 - -/* pad templates */ -static GstStaticPadTemplate gst_pylonsrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -/* class initialisation */ -G_DEFINE_TYPE_WITH_CODE (GstPylonSrc, gst_pylonsrc, GST_TYPE_PUSH_SRC, - GST_DEBUG_CATEGORY_INIT (gst_pylonsrc_debug_category, "pylonsrc", 0, - "debug category for pylonsrc element")); - -static void -gst_pylonsrc_class_init (GstPylonSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstPushSrcClass *push_src_class = GST_PUSH_SRC_CLASS (klass); - GstBaseSrcClass *base_src_class = GST_BASE_SRC_CLASS (klass); - - gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass), - &gst_pylonsrc_src_template); - - gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass), - "Basler Pylon Video Source", "Source/Video/Device", - "Baser Pylon video source", - "Ingmars Melkis "); - - gobject_class->set_property = gst_pylonsrc_set_property; - gobject_class->get_property = gst_pylonsrc_get_property; - gobject_class->dispose = gst_pylonsrc_dispose; - gobject_class->finalize = gst_pylonsrc_finalize; - - base_src_class->start = GST_DEBUG_FUNCPTR (gst_pylonsrc_start); - base_src_class->stop = GST_DEBUG_FUNCPTR (gst_pylonsrc_stop); - base_src_class->get_caps = GST_DEBUG_FUNCPTR (gst_pylonsrc_get_caps); - base_src_class->set_caps = GST_DEBUG_FUNCPTR (gst_pylonsrc_set_caps); - - push_src_class->create = GST_DEBUG_FUNCPTR (gst_pylonsrc_create); - - g_object_class_install_property (gobject_class, PROP_CAMERA, - g_param_spec_int ("camera", "camera", - "(Number) Camera ID as defined by Basler's API. If only one camera is connected this parameter will be ignored and the lone camera will be used. If there are multiple cameras and this parameter isn't defined, the plugin will output a list of available cameras and their IDs. Note that if there are multiple cameras available to the API and the camera parameter isn't defined then this plugin will not run.", - 0, 100, DEFAULT_PROP_CAMERA, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_HEIGHT, - g_param_spec_int ("height", "height", - "(Pixels) The height of the picture. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 0, 10000, DEFAULT_PROP_SIZE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_WIDTH, - g_param_spec_int ("width", "width", - "(Pixels) The width of the picture. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 0, 10000, DEFAULT_PROP_SIZE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BINNINGH, - g_param_spec_int ("binningh", "Horizontal binning", - "(Pixels) The number of pixels to be binned in horizontal direction. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 1, 6, DEFAULT_PROP_BINNING, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BINNINGV, - g_param_spec_int ("binningv", "Vertical binning", - "(Pixels) The number of pixels to be binned in vertical direction. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 1, 6, DEFAULT_PROP_BINNING, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_LIMITBANDWIDTH, - g_param_spec_boolean ("limitbandwidth", "Link Throughput limit mode", - "(true/false) Bandwidth limit mode. Disabling this will potentially allow the camera to reach higher frames per second, but can potentially damage your camera. Use with caution. Running the plugin without specifying this parameter will reset the value stored on the camera to `true`.", - DEFAULT_PROP_LIMITBANDWIDTH, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_MAXBANDWIDTH, - g_param_spec_int ("maxbandwidth", "Maximum bandwidth", - "(Bytes per second) This property sets the maximum bandwidth the camera can use. The camera will only use as much as it needs for the specified resolution and framerate. This setting will have no effect if limitbandwidth is set to off. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 0, 999999999, DEFAULT_PROP_MAXBANDWIDTH, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_SENSORREADOUTMODE, - g_param_spec_string ("sensorreadoutmode", "Sensor readout mode", - "(normal/fast) This property changes the sensor readout mode. Fast will allow for faster framerates, but might cause quality loss. It might be required to either increase max bandwidth or disabling bandwidth limiting for this to cause any noticeable change. Running the plugin without specifying this parameter will reset the value stored on the camera to \"normal\".", - DEFAULT_PROP_SENSORREADOUTMODE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, - PROP_ACQUISITIONFRAMERATEENABLE, - g_param_spec_boolean ("acquisitionframerateenable", "Custom FPS mode", - "(true/false) Enables the use of custom fps values. Will be set to true if the fps poperty is set. Running the plugin without specifying this parameter will reset the value stored on the camera to false.", - DEFAULT_PROP_ACQUISITIONFRAMERATEENABLE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_FPS, - g_param_spec_double ("fps", "Framerate", - "(Frames per second) Sets the framerate of the video coming from the camera. Setting the value too high might cause the plugin to crash. Note that if your pipeline proves to be too much for your computer then the resulting video won't be in the resolution you set. Setting this parameter will set acquisitionframerateenable to true. The value of this parameter will be saved to the camera, but it will have no effect unless either this or the acquisitionframerateenable parameters are set. Reconnect the camera or use the reset parameter to reset.", - 0.0, 1024.0, DEFAULT_PROP_FPS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_LIGHTSOURCE, - g_param_spec_string ("lightsource", "Lightsource preset", - "(off, 2800k, 5000k, 6500k) Changes the colour balance settings to ones defined by presests (if other values are supported by camera try setting them as specified in Basler documentation. E.g. \"Tungsten\" or \"Custom\"). Just pick one that's closest to your environment's lighting. Running the plugin without specifying this parameter will reset the value stored on the camera to \"5000k\"", - DEFAULT_PROP_LIGHTSOURCE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOEXPOSURE, - g_param_spec_string ("autoexposure", "Automatic exposure setting", - "(off, once, continuous) Controls whether or not the camera will try to adjust the exposure settings. Setting this parameter to anything but \"off\" will override the exposure parameter. Running the plugin without specifying this parameter will reset the value stored on the camera to \"off\"", - DEFAULT_PROP_AUTOFEATURE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_EXPOSURE, - g_param_spec_double ("exposure", "Exposure", - "(Microseconds) Exposure time for the camera in microseconds. Will only have an effect if autoexposure is set to off (default). Higher numbers will cause lower frame rate. Note that the camera will remember this setting, and will use values from the previous runs if you relaunch without specifying this parameter. Reconnect the camera or use the reset parameter to reset.", - 0.0, 1000000.0, DEFAULT_PROP_LIMITED_MANUAL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOWHITEBALANCE, - g_param_spec_string ("autowhitebalance", "Automatic colour balancing", - "(off, once, continuous) Controls whether or not the camera will try to adjust the white balance settings. Setting this parameter to anything but \"off\" will override the exposure parameter. Running the plugin without specifying this parameter will reset the value stored on the camera to \"off\"", - DEFAULT_PROP_AUTOFEATURE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BALANCERED, - g_param_spec_double ("balancered", "Red balance", - "Specifies the red colour balance. the autowhitebalance must be set to \"off\" for this property to have any effect. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 15.9, DEFAULT_PROP_BALANCE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BALANCEGREEN, - g_param_spec_double ("balancegreen", "Green balance", - "Specifies the green colour balance. the autowhitebalance must be set to \"off\" for this property to have any effect. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 15.9, DEFAULT_PROP_BALANCE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BALANCEBLUE, - g_param_spec_double ("balanceblue", "Blue balance", - "Specifies the blue colour balance. the autowhitebalance must be set to \"off\" for this property to have any effect. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 15.9, DEFAULT_PROP_BALANCE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORREDHUE, - g_param_spec_double ("colorredhue", "Red's hue", - "Specifies the red colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORREDSATURATION, - g_param_spec_double ("colorredsaturation", "Red's saturation", - "Specifies the red colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORYELLOWHUE, - g_param_spec_double ("coloryellowhue", "Yellow's hue", - "Specifies the yellow colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORYELLOWSATURATION, - g_param_spec_double ("coloryellowsaturation", "Yellow's saturation", - "Specifies the yellow colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORGREENHUE, - g_param_spec_double ("colorgreenhue", "Green's hue", - "Specifies the green colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORGREENSATURATION, - g_param_spec_double ("colorgreensaturation", "Green's saturation", - "Specifies the green colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORCYANHUE, - g_param_spec_double ("colorcyanhue", "Cyan's hue", - "Specifies the cyan colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORCYANSATURATION, - g_param_spec_double ("colorcyansaturation", "Cyan's saturation", - "Specifies the cyan colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORBLUEHUE, - g_param_spec_double ("colorbluehue", "Blue's hue", - "Specifies the blue colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORBLUESATURATION, - g_param_spec_double ("colorbluesaturation", "Blue's saturation", - "Specifies the blue colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORMAGENTAHUE, - g_param_spec_double ("colormagentahue", "Magenta's hue", - "Specifies the magenta colour's hue. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - -128.0, 127.0, DEFAULT_PROP_HUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORMAGENTASATURATION, - g_param_spec_double ("colormagentasaturation", "Magenta's saturation", - "Specifies the magenta colour's saturation. Note that the this value gets saved on the camera, and running this plugin again without specifying this value will cause the previous value being used. Use the reset parameter or reconnect the camera to reset.", - 0.0, 255.0, DEFAULT_PROP_SATURATION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_COLORADJUSTMENTENABLE, - g_param_spec_boolean ("coloradjustment", "Enable color adjustment", - "(true/false) On ace classic/U/L GigE Cameras enables/disables hue and saturation adjustments. Enabled implicitly if any hue or saturation property is set", - DEFAULT_PROP_COLORADJUSTMENTENABLE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOGAIN, - g_param_spec_string ("autogain", "Automatic gain", - "(off, once, continuous) Controls whether or not the camera will try to adjust the gain settings. Setting this parameter to anything but \"off\" will override the exposure parameter. Running the plugin without specifying this parameter will reset the value stored on the camera to \"off\"", - DEFAULT_PROP_AUTOFEATURE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_GAIN, - g_param_spec_double ("gain", "Gain", - "(dB or raw) Sets the gain added on the camera before sending the frame to the computer. The value of this parameter will be saved to the camera, but it will be set to 0 every time this plugin is launched without specifying gain or overriden if the autogain parameter is set to anything that's not \"off\". Reconnect the camera or use the reset parameter to reset the stored value.", - 0.0, 1000.0, DEFAULT_PROP_LIMITED_MANUAL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BLACKLEVEL, - g_param_spec_double ("blacklevel", "Black Level", - "(DN) Sets stream's black level. This parameter is processed on the camera before the picture is sent to the computer. The value of this parameter will be saved to the camera, but it will be set to 0 every time this plugin is launched without specifying this parameter. Reconnect the camera or use the reset parameter to reset the stored value.", - 0.0, 1000.0, DEFAULT_PROP_BLACKLEVEL, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_GAMMA, - g_param_spec_double ("gamma", "Gamma", - "Sets the gamma correction value. This parameter is processed on the camera before the picture is sent to the computer. The value of this parameter will be saved to the camera, but it will be set to 1.0 every time this plugin is launched without specifying this parameter. Reconnect the camera or use the reset parameter to reset the stored value.", - 0.0, 3.9, DEFAULT_PROP_GAMMA, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_RESET, - g_param_spec_string ("reset", "Camera reset settings", - "(off, before, after). Controls whether or when the camera's settings will be reset. Setting this to \"before\" will wipe the settings before the camera initialisation begins. Setting this to \"after\" will reset the device once the pipeline closes. This can be useful for debugging or when you want to use the camera with other software that doesn't reset the camera settings before use (such as PylonViewerApp).", - DEFAULT_PROP_RESET, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TESTIMAGE, - g_param_spec_int ("testimage", "Test image", - "(1-6) Specifies a test image to show instead of a video stream. Useful for debugging. Will be disabled by default.", - 0, 6, DEFAULT_PROP_TESTIMAGE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TESTIMAGESOURCE, - g_param_spec_string ("testimagesource", "Test image source", - "Specifies a test image (or image directory) to show instead of a video stream. Useful for debugging. Will be disabled by default.", - DEFAULT_PROP_TESTIMAGESOURCE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CONTINUOUSMODE, - g_param_spec_boolean ("continuous", "Continuous mode", - "(true/false) Used to switch between triggered and continuous mode. To switch to triggered mode this parameter has to be switched to false.", - DEFAULT_PROP_CONTINUOUSMODE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_PIXEL_FORMAT, - g_param_spec_string ("pixel-format", "Pixel format", - "Force the pixel format (e.g., Mono8). Default to 'auto', which will use GStreamer negotiation.", - DEFAULT_PROP_PIXEL_FORMAT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_USERID, - g_param_spec_string ("userid", "Custom Device User ID", - "() Sets the device custom id so that it can be identified later.", - DEFAULT_PROP_USERID, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_BASLERDEMOSAICING, - g_param_spec_boolean ("demosaicing", "Basler's Demosaicing mode'", - "(true/false) Switches between simple and Basler's Demosaicing (PGI) mode. Note that this will not work if bayer output is used.", - DEFAULT_PROP_BASLERDEMOSAICING, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, - PROP_DEMOSAICINGNOISEREDUCTION, g_param_spec_double ("noisereduction", - "Noise reduction", - "Specifies the amount of noise reduction to apply. To use this Basler's demosaicing mode must be enabled. Setting this will enable demosaicing mode.", - 0.0, 2.0, DEFAULT_PROP_DEMOSAICINGNOISEREDUCTION, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, - PROP_DEMOSAICINGSHARPNESSENHANCEMENT, - g_param_spec_double ("sharpnessenhancement", "Sharpness enhancement", - "Specifies the amount of sharpness enhancement to apply. To use this Basler's demosaicing mode must be enabled. Setting this will enable demosaicing mode.", - 1.0, 3.98, DEFAULT_PROP_DEMOSAICINGSHARPNESSENHANCEMENT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_OFFSETX, - g_param_spec_int ("offsetx", "horizontal offset", - "(0-10000) Determines the vertical offset. Note that the maximum offset value is calculated during initialisation, and will not be shown in this output.", - 0, 10000, DEFAULT_PROP_OFFSET, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_OFFSETY, - g_param_spec_int ("offsety", "vertical offset", - "(0-10000) Determines the vertical offset. Note that the maximum offset value is calculated during initialisation, and will not be shown in this output.", - 0, 10000, DEFAULT_PROP_OFFSET, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CENTERX, - g_param_spec_boolean ("centerx", "center horizontally", - "(true/false) Setting this will center the horizontal offset. Setting this to true this will cause the plugin to ignore offsetx value.", - DEFAULT_PROP_CENTER, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CENTERY, - g_param_spec_boolean ("centery", "center vertically", - "(true/false) Setting this will center the vertical offset. Setting this to true this will cause the plugin to ignore offsetx value.", - DEFAULT_PROP_CENTER, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_FLIPX, - g_param_spec_boolean ("flipx", "Flip horizontally", - "(true/false) Setting this will flip the image horizontally.", - DEFAULT_PROP_FLIP, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_FLIPY, - g_param_spec_boolean ("flipy", "Flip vertically", - "(true/false) Setting this will flip the image vertically.", - DEFAULT_PROP_FLIP, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOEXPOSURELOWERLIMIT, - g_param_spec_double ("exposurelowerlimit", "Auto exposure lower limit", - "(105-1000000) Sets the lower limit for the auto exposure function.", - 105.0, 1000000.0, DEFAULT_PROP_AUTOEXPOSURELOWERLIMIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOEXPOSUREUPPERLIMIT, - g_param_spec_double ("exposureupperlimit", "Auto exposure upper limit", - "(105-1000000) Sets the upper limit for the auto exposure function.", - 105.0, 1000000.0, DEFAULT_PROP_AUTOEXPOSUREUPPERLIMIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_GAINUPPERLIMIT, - g_param_spec_double ("gainupperlimit", "Auto gain upper limit", - "(0-1000 dB or raw) Sets the upper limit for the auto gain function.", - 0.0, 1000.0, DEFAULT_PROP_GAINUPPERLIMIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_GAINLOWERLIMIT, - g_param_spec_double ("gainlowerlimit", "Auto gain lower limit", - "(0-1000 dB or raw) Sets the lower limit for the auto gain function.", - 0.0, 1000.0, DEFAULT_PROP_GAINLOWERLIMIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOBRIGHTNESSTARGET, - g_param_spec_double ("autobrightnesstarget", "Auto brightness target", - "(0.19608-0.80392 or 50-205) Sets the brightness value the auto exposure/gain function should strive for.", - 0.19608, 205.0, DEFAULT_PROP_AUTOBRIGHTNESSTARGET, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_AUTOPROFILE, - g_param_spec_string ("autoprofile", "Auto function minimize profile", - "(gain/exposure) When the auto functions are on, this determines whether to focus on minimising gain or exposure.", - DEFAULT_PROP_AUTOPROFILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION00, - g_param_spec_double ("transformation00", - "Color Transformation selector 00", "Gain00 transformation selector.", - -8.0, 7.96875, defaultTransform[0][0], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION01, - g_param_spec_double ("transformation01", - "Color Transformation selector 01", "Gain01 transformation selector.", - -8.0, 7.96875, defaultTransform[0][1], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION02, - g_param_spec_double ("transformation02", - "Color Transformation selector 02", "Gain02 transformation selector.", - -8.0, 7.96875, defaultTransform[0][2], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION10, - g_param_spec_double ("transformation10", - "Color Transformation selector 10", "Gain10 transformation selector.", - -8.0, 7.96875, defaultTransform[1][0], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION11, - g_param_spec_double ("transformation11", - "Color Transformation selector 11", "Gain11 transformation selector.", - -8.0, 7.96875, defaultTransform[1][1], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION12, - g_param_spec_double ("transformation12", - "Color Transformation selector 12", "Gain12 transformation selector.", - -8.0, 7.96875, defaultTransform[1][2], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION20, - g_param_spec_double ("transformation20", - "Color Transformation selector 20", "Gain20 transformation selector.", - -8.0, 7.96875, defaultTransform[2][0], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION21, - g_param_spec_double ("transformation21", - "Color Transformation selector 21", "Gain21 transformation selector.", - -8.0, 7.96875, defaultTransform[2][1], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATION22, - g_param_spec_double ("transformation22", - "Color Transformation selector 22", "Gain22 transformation selector.", - -8.0, 7.96875, defaultTransform[2][2], - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_TRANSFORMATIONSELECTOR, - g_param_spec_string ("transformationselector", - "Color Transformation Selector", - "(RGBRGB, RGBYUV, YUVRGB) Sets the type of color transformation done by the color transformation selectors.", - DEFAULT_PROP_TRANSFORMATIONSELECTOR, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CONFIGFILE, - g_param_spec_string ("config-file", "Pylon Feature Stream (.pfs) file", - "Path to PFS file containing configurations for all features. PFS file can be obtained with PylonViewer or PylonFeaturePersistenceSave() function. Configuration file is applied prior to any other properties. Using configuration file implies setting \"ignore-defaults\"", - DEFAULT_PROP_CONFIGFILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_IGNOREDEFAULTS, - g_param_spec_boolean ("ignore-defaults", - "Ignore default values to other properties", - "(true/false) Apply features only if those are set explicitly. Can only be applied on plugin startup. This property is implicitly set to true if config-file is provided. Setting this to false while config-file is set will lead to strange result and is not recommended", - DEFAULT_PROP_IGNOREDEFAULTS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_FRAMEDROPLIMIT, - g_param_spec_int ("frame-drop-limit", "Failed frames", - "Specifies the number of consecutive frames to fail before failing everything", - 0, 100, DEFAULT_PROP_FRAMEDROPLIMIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_GRABTIMEOUT, - g_param_spec_int ("grab-timeout", "Initial load timeout", - "Specifies the number of miiliseconds to wait for frame to be grabed from the camera.", - 0, 60000, DEFAULT_PROP_GRABTIMEOUT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - //TODO: Limits may be co-dependent on other transport layer parameters. - g_object_class_install_property (gobject_class, PROP_PACKETSIZE, - g_param_spec_int ("packet-size", "Maximum size of data packet", - "The packetsize parameter specifies the maximum size of a data packet transmitted via Ethernet. The value is in bytes.", - 0, 16000, DEFAULT_PROP_PACKETSIZE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - //TODO: Limits may be co-dependent on other transport layer parameters. - g_object_class_install_property (gobject_class, PROP_INTERPACKETDELAY, - g_param_spec_int ("inter-packet-delay", - "Inter-Packet Delay between packet transmissions", - "If your network hardware can't handle the incoming packet rate, it is useful to increase the delay between packet transmissions.", - 0, 3435, DEFAULT_PROP_INTERPACKETDELAY, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - //TODO: Limits may be co-dependent on other transport layer parameters. - g_object_class_install_property (gobject_class, PROP_FRAMETRANSDELAY, - g_param_spec_int ("frame-trans-delay", - "Delay for begin transmitting frame.", - "Sets a delay in ticks between when camera begisn transmitting frame afther acquiring it. By default, one tick equals 8 ns. With PTP enabled, one tick equals 1 ns.", - 0, 50000000, DEFAULT_PROP_FRAMETRANSDELAY, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - //TODO: Limits may be co-dependent on other transport layer parameters. - g_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVE, - g_param_spec_int ("bandwidth-reserve", - "Portion of bandwidth reserved for packet resends.", - "The setting is expressed as a percentage of the assigned bandwidth.", - 0, 26, DEFAULT_PROP_BANDWIDTHRESERVE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - //TODO: Limits may be co-dependent on other transport layer parameters. - g_object_class_install_property (gobject_class, PROP_BANDWIDTHRESERVEACC, - g_param_spec_int ("bandwidth-reserve-acc", - "Pool of resends for unusual situations", - "For situations when the network connection becomes unstable. A larger number of packet resends may be needed to transmit an image", - 1, 32, DEFAULT_PROP_BANDWIDTHRESERVEACC, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_MAXTRANSFERSIZE, - g_param_spec_int ("max-transfer-size", - "Maximum USB data transfer size in bytes", - "Use the MaxTransferSize parameter to specify the maximum USB data transfer size in bytes. The default value is appropriate for most applications. Increase the value to lower the CPU load. USB host adapter drivers may require decreasing the value if the application fails to receive the image stream. The maximum value depends on the operating system.", - 0x400, 0x400000, DEFAULT_PROP_MAXTRANSFERSIZE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "pylonsrc", GST_RANK_NONE, - GST_TYPE_PYLONSRC); -} - -static void -gst_pylonsrc_init (GstPylonSrc * src) -{ - GST_DEBUG_OBJECT (src, "Initialising defaults"); - - src->deviceConnected = FALSE; - src->acquisition_configured = FALSE; - src->caps = NULL; - - // Default parameter values - src->continuousMode = DEFAULT_PROP_CONTINUOUSMODE; - src->limitBandwidth = DEFAULT_PROP_LIMITBANDWIDTH; - src->setFPS = DEFAULT_PROP_ACQUISITIONFRAMERATEENABLE; - src->demosaicing = DEFAULT_PROP_BASLERDEMOSAICING; - src->colorAdjustment = DEFAULT_PROP_COLORADJUSTMENTENABLE; - - for (int i = 0; i < 2; i++) { - src->binning[i] = DEFAULT_PROP_BINNING; - src->center[i] = DEFAULT_PROP_CENTER; - src->flip[i] = DEFAULT_PROP_FLIP; - src->offset[i] = DEFAULT_PROP_OFFSET; - src->size[i] = DEFAULT_PROP_SIZE; - src->maxSize[i] = G_MAXINT; - } - - src->cameraId = DEFAULT_PROP_CAMERA; - src->maxBandwidth = DEFAULT_PROP_MAXBANDWIDTH; - src->testImage = DEFAULT_PROP_TESTIMAGE; - src->testImageSource = g_strdup (DEFAULT_PROP_TESTIMAGESOURCE); - src->sensorMode = g_strdup (DEFAULT_PROP_SENSORREADOUTMODE); - src->lightsource = g_strdup (DEFAULT_PROP_LIGHTSOURCE); - - for (int i = 0; i < AUTOF_NUM_FEATURES; i++) { - src->autoFeature[i] = g_strdup (DEFAULT_PROP_AUTOFEATURE); - } - - src->reset = g_strdup (DEFAULT_PROP_RESET); - src->pixel_format = g_strdup (DEFAULT_PROP_PIXEL_FORMAT); - src->userid = g_strdup (DEFAULT_PROP_USERID); - src->autoprofile = g_strdup (DEFAULT_PROP_AUTOPROFILE); - src->transformationselector = g_strdup (DEFAULT_PROP_TRANSFORMATIONSELECTOR); - src->fps = DEFAULT_PROP_FPS; - - src->blacklevel = DEFAULT_PROP_BLACKLEVEL; - src->gamma = DEFAULT_PROP_GAMMA; - - for (int i = 0; i < 3; i++) { - src->balance[i] = DEFAULT_PROP_BALANCE; - } - - for (int i = 0; i < 6; i++) { - src->hue[i] = DEFAULT_PROP_HUE; - src->saturation[i] = DEFAULT_PROP_SATURATION; - } - - src->sharpnessenhancement = DEFAULT_PROP_DEMOSAICINGSHARPNESSENHANCEMENT; - src->noisereduction = DEFAULT_PROP_DEMOSAICINGNOISEREDUCTION; - - for (int i = 0; i < AUTOF_NUM_LIMITED; i++) { - src->limitedFeature[i].manual = DEFAULT_PROP_LIMITED_MANUAL; - } - - src->limitedFeature[AUTOF_EXPOSURE].lower = - DEFAULT_PROP_AUTOEXPOSURELOWERLIMIT; - src->limitedFeature[AUTOF_EXPOSURE].upper = - DEFAULT_PROP_AUTOEXPOSUREUPPERLIMIT; - - src->limitedFeature[AUTOF_GAIN].lower = DEFAULT_PROP_GAINLOWERLIMIT; - src->limitedFeature[AUTOF_GAIN].upper = DEFAULT_PROP_GAINUPPERLIMIT; - - src->brightnesstarget = DEFAULT_PROP_AUTOBRIGHTNESSTARGET; - for (int j = 0; j < 3; j++) { - for (int i = 0; i < 3; i++) { - src->transformation[j][i] = defaultTransform[j][i]; - } - } - - src->configFile = g_strdup (DEFAULT_PROP_CONFIGFILE); - src->ignoreDefaults = DEFAULT_PROP_IGNOREDEFAULTS; - - src->frameDropLimit = DEFAULT_PROP_FRAMEDROPLIMIT; - src->grabtimeout = DEFAULT_PROP_GRABTIMEOUT; - src->packetSize = DEFAULT_PROP_PACKETSIZE; - src->interPacketDelay = DEFAULT_PROP_INTERPACKETDELAY; - src->frameTransDelay = DEFAULT_PROP_FRAMETRANSDELAY; - src->bandwidthReserve = DEFAULT_PROP_BANDWIDTHRESERVE; - src->bandwidthReserveAcc = DEFAULT_PROP_BANDWIDTHRESERVEACC; - src->maxTransferSize = DEFAULT_PROP_MAXTRANSFERSIZE; - - for (int i = 0; i < PROP_NUM_PROPERTIES; i++) { - src->propFlags[i] = GST_PYLONSRC_PROPST_DEFAULT; - } - - // Mark this element as a live source (disable preroll) - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - gst_base_src_set_do_timestamp (GST_BASE_SRC (src), TRUE); -} - -// check if property is set explicitly -static inline _Bool -is_prop_set (const GstPylonSrc * src, GST_PYLONSRC_PROP prop) -{ - return src->propFlags[prop] == GST_PYLONSRC_PROPST_SET; -} - -// check if property is already processed (value is loaded to device) -static inline _Bool -is_prop_not_set (const GstPylonSrc * src, GST_PYLONSRC_PROP prop) -{ - return src->propFlags[prop] == GST_PYLONSRC_PROPST_NOT_SET; -} - -// check if property is defaulted -static inline _Bool -is_prop_default (const GstPylonSrc * src, GST_PYLONSRC_PROP prop) -{ - return src->propFlags[prop] == GST_PYLONSRC_PROPST_DEFAULT; -} - -// check if property is set implicitly, i.e. set explicitly or defaulted -static inline _Bool -is_prop_implicit (const GstPylonSrc * src, GST_PYLONSRC_PROP prop) -{ - return src->propFlags[prop] != GST_PYLONSRC_PROPST_NOT_SET; -} - -// mark property as processed -static inline void -reset_prop (GstPylonSrc * src, GST_PYLONSRC_PROP prop) -{ - src->propFlags[prop] = GST_PYLONSRC_PROPST_NOT_SET; -} - -// Use in gst_pylonsrc_set_property to set related boolean property -static inline void -set_prop_implicitly (GObject * object, GST_PYLONSRC_PROP prop, - GParamSpec * pspec) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - if (!is_prop_set (src, prop)) { - GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_BOOLEAN); - g_value_set_boolean (&val, TRUE); - gst_pylonsrc_set_property (object, prop, &val, pspec); - g_value_unset (&val); - } -} - -// Use in gst_pylonsrc_set_property to set related string property -static inline void -set_string_prop_implicitly (GObject * object, GST_PYLONSRC_PROP prop, - GParamSpec * pspec, const gchar * str_val) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - if (!is_prop_set (src, prop)) { - GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_STRING); - g_value_set_string (&val, str_val); - gst_pylonsrc_set_property (object, prop, &val, pspec); - g_value_unset (&val); - } -} - -/* plugin's parameters/properties */ -void -gst_pylonsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - - GST_DEBUG_OBJECT (src, "Setting a property: %u", property_id); - - switch (property_id) { - case PROP_CAMERA: - src->cameraId = g_value_get_int (value); - break; - case PROP_HEIGHT: - src->size[AXIS_Y] = g_value_get_int (value); - break; - case PROP_WIDTH: - src->size[AXIS_X] = g_value_get_int (value); - break; - case PROP_BINNINGH: - src->binning[AXIS_X] = g_value_get_int (value); - break; - case PROP_BINNINGV: - src->binning[AXIS_Y] = g_value_get_int (value); - break; - case PROP_OFFSETX: - src->offset[AXIS_X] = g_value_get_int (value); - break; - case PROP_OFFSETY: - src->offset[AXIS_Y] = g_value_get_int (value); - break; - case PROP_TESTIMAGE: - src->testImage = g_value_get_int (value); - break; - case PROP_TESTIMAGESOURCE: - g_free (src->testImageSource); - src->testImageSource = g_value_dup_string (value); - break; - case PROP_SENSORREADOUTMODE: - g_free (src->sensorMode); - src->sensorMode = g_value_dup_string (value); - break; - case PROP_LIGHTSOURCE: - g_free (src->lightsource); - src->lightsource = g_value_dup_string (value); - break; - case PROP_AUTOEXPOSURE: - g_free (src->autoFeature[AUTOF_EXPOSURE]); - src->autoFeature[AUTOF_EXPOSURE] = g_value_dup_string (value); - break; - case PROP_AUTOWHITEBALANCE: - g_free (src->autoFeature[AUTOF_WHITEBALANCE]); - src->autoFeature[AUTOF_WHITEBALANCE] = g_value_dup_string (value); - break; - case PROP_PIXEL_FORMAT: - g_free (src->pixel_format); - src->pixel_format = g_value_dup_string (value); - break; - case PROP_AUTOGAIN: - g_free (src->autoFeature[AUTOF_GAIN]); - src->autoFeature[AUTOF_GAIN] = g_value_dup_string (value); - break; - case PROP_RESET: - g_free (src->reset); - src->reset = g_value_dup_string (value); - break; - case PROP_AUTOPROFILE: - g_free (src->autoprofile); - src->autoprofile = g_value_dup_string (value); - break; - case PROP_TRANSFORMATIONSELECTOR: - g_free (src->transformationselector); - src->transformationselector = g_value_dup_string (value); - break; - case PROP_USERID: - g_free (src->userid); - src->userid = g_value_dup_string (value); - break; - case PROP_BALANCERED: - src->balance[COLOUR_RED] = g_value_get_double (value); - break; - case PROP_BALANCEGREEN: - src->balance[COLOUR_GREEN] = g_value_get_double (value); - break; - case PROP_BALANCEBLUE: - src->balance[COLOUR_BLUE] = g_value_get_double (value); - break; - case PROP_COLORREDHUE: - src->hue[COLOUR_RED] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORREDSATURATION: - src->saturation[COLOUR_RED] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORYELLOWHUE: - src->hue[COLOUR_YELLOW] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORYELLOWSATURATION: - src->saturation[COLOUR_YELLOW] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORGREENHUE: - src->hue[COLOUR_GREEN] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORGREENSATURATION: - src->saturation[COLOUR_GREEN] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORCYANHUE: - src->hue[COLOUR_CYAN] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORCYANSATURATION: - src->saturation[COLOUR_CYAN] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORBLUEHUE: - src->hue[COLOUR_BLUE] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORBLUESATURATION: - src->saturation[COLOUR_BLUE] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORMAGENTAHUE: - src->hue[COLOUR_MAGENTA] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORMAGENTASATURATION: - src->saturation[COLOUR_MAGENTA] = g_value_get_double (value); - set_prop_implicitly (object, PROP_COLORADJUSTMENTENABLE, pspec); - break; - case PROP_COLORADJUSTMENTENABLE: - src->colorAdjustment = g_value_get_boolean (value); - break; - case PROP_MAXBANDWIDTH: - src->maxBandwidth = g_value_get_int (value); - break; - case PROP_FLIPX: - src->flip[AXIS_X] = g_value_get_boolean (value); - break; - case PROP_FLIPY: - src->flip[AXIS_Y] = g_value_get_boolean (value); - break; - case PROP_CENTERX: - src->center[AXIS_X] = g_value_get_boolean (value); - break; - case PROP_CENTERY: - src->center[AXIS_Y] = g_value_get_boolean (value); - break; - case PROP_LIMITBANDWIDTH: - src->limitBandwidth = g_value_get_boolean (value); - break; - case PROP_ACQUISITIONFRAMERATEENABLE: - // if FPS is set, then AcquisitionFrameRateEnable is set implicitly - // This can be overriden if needed - src->setFPS = g_value_get_boolean (value); - break; - case PROP_CONTINUOUSMODE: - src->continuousMode = g_value_get_boolean (value); - break; - case PROP_BASLERDEMOSAICING: - src->demosaicing = g_value_get_boolean (value); - break; - case PROP_FPS: - src->fps = g_value_get_double (value); - // Setting fps implies setting AcquisitionFrameRateEnable if the latter is not set to false explicitly - set_prop_implicitly (object, PROP_ACQUISITIONFRAMERATEENABLE, pspec); - break; - case PROP_EXPOSURE: - src->limitedFeature[AUTOF_EXPOSURE].manual = g_value_get_double (value); - // disable autoexposure unless set explicitly - set_string_prop_implicitly (object, PROP_AUTOEXPOSURE, pspec, "off"); - break; - case PROP_GAIN: - src->limitedFeature[AUTOF_GAIN].manual = g_value_get_double (value); - // disable autoexposure unless set explicitly - set_string_prop_implicitly (object, PROP_AUTOGAIN, pspec, "off"); - break; - case PROP_BLACKLEVEL: - src->blacklevel = g_value_get_double (value); - break; - case PROP_GAMMA: - src->gamma = g_value_get_double (value); - break; - case PROP_DEMOSAICINGNOISEREDUCTION: - src->noisereduction = g_value_get_double (value); - // Setting NoiseReduction implies setting Basler Demosaising if the latter is not set to Simple explicitly - set_prop_implicitly (object, PROP_BASLERDEMOSAICING, pspec); - break; - case PROP_AUTOEXPOSUREUPPERLIMIT: - src->limitedFeature[AUTOF_EXPOSURE].upper = g_value_get_double (value); - break; - case PROP_AUTOEXPOSURELOWERLIMIT: - src->limitedFeature[AUTOF_EXPOSURE].lower = g_value_get_double (value); - break; - case PROP_GAINLOWERLIMIT: - src->limitedFeature[AUTOF_GAIN].lower = g_value_get_double (value); - break; - case PROP_GAINUPPERLIMIT: - src->limitedFeature[AUTOF_GAIN].upper = g_value_get_double (value); - break; - case PROP_AUTOBRIGHTNESSTARGET: - src->brightnesstarget = g_value_get_double (value); - break; - case PROP_DEMOSAICINGSHARPNESSENHANCEMENT: - src->sharpnessenhancement = g_value_get_double (value); - // Setting SharpnessEnhansement implies setting Basler Demosaising if the latter is not set to Simple explicitly - set_prop_implicitly (object, PROP_BASLERDEMOSAICING, pspec); - break; - case PROP_TRANSFORMATION00: - src->transformation[0][0] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION01: - src->transformation[0][1] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION02: - src->transformation[0][2] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION10: - src->transformation[1][0] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION11: - src->transformation[1][1] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION12: - src->transformation[1][2] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION20: - src->transformation[2][0] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION21: - src->transformation[2][1] = g_value_get_double (value); - break; - case PROP_TRANSFORMATION22: - src->transformation[2][2] = g_value_get_double (value); - break; - case PROP_CONFIGFILE: - g_free (src->configFile); - src->configFile = g_value_dup_string (value); - // Setting config-file implies setting ignore-defaults if the latter is not set to false explicitly - set_prop_implicitly (object, PROP_IGNOREDEFAULTS, pspec); - break; - case PROP_IGNOREDEFAULTS: - src->ignoreDefaults = g_value_get_boolean (value); - break; - case PROP_FRAMEDROPLIMIT: - src->frameDropLimit = g_value_get_int (value); - break; - case PROP_GRABTIMEOUT: - src->grabtimeout = g_value_get_int (value); - break; - case PROP_PACKETSIZE: - src->packetSize = g_value_get_int (value); - break; - case PROP_INTERPACKETDELAY: - src->interPacketDelay = g_value_get_int (value); - break; - case PROP_FRAMETRANSDELAY: - src->frameTransDelay = g_value_get_int (value); - break; - case PROP_BANDWIDTHRESERVE: - src->bandwidthReserve = g_value_get_int (value); - break; - case PROP_BANDWIDTHRESERVEACC: - src->bandwidthReserveAcc = g_value_get_int (value); - break; - case PROP_MAXTRANSFERSIZE: - src->maxTransferSize = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - return; - } - src->propFlags[property_id] = GST_PYLONSRC_PROPST_SET; -} - -void -gst_pylonsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - - GST_DEBUG_OBJECT (src, "Getting a property."); - - switch (property_id) { - case PROP_CAMERA: - g_value_set_int (value, src->cameraId); - break; - case PROP_HEIGHT: - g_value_set_int (value, src->size[AXIS_Y]); - break; - case PROP_WIDTH: - g_value_set_int (value, src->size[AXIS_X]); - break; - case PROP_BINNINGH: - g_value_set_int (value, src->binning[AXIS_X]); - break; - case PROP_BINNINGV: - g_value_set_int (value, src->binning[AXIS_Y]); - break; - case PROP_OFFSETX: - g_value_set_int (value, src->offset[AXIS_X]); - break; - case PROP_OFFSETY: - g_value_set_int (value, src->offset[AXIS_Y]); - break; - case PROP_TESTIMAGE: - g_value_set_int (value, src->testImage); - break; - case PROP_TESTIMAGESOURCE: - g_value_set_string (value, src->testImageSource); - break; - case PROP_SENSORREADOUTMODE: - g_value_set_string (value, src->sensorMode); - break; - case PROP_LIGHTSOURCE: - g_value_set_string (value, src->lightsource); - break; - case PROP_AUTOEXPOSURE: - g_value_set_string (value, src->autoFeature[AUTOF_EXPOSURE]); - break; - case PROP_AUTOWHITEBALANCE: - g_value_set_string (value, src->autoFeature[AUTOF_WHITEBALANCE]); - break; - case PROP_PIXEL_FORMAT: - g_value_set_string (value, src->pixel_format); - break; - case PROP_USERID: - g_value_set_string (value, src->userid); - break; - case PROP_AUTOGAIN: - g_value_set_string (value, src->autoFeature[AUTOF_GAIN]); - break; - case PROP_RESET: - g_value_set_string (value, src->reset); - break; - case PROP_AUTOPROFILE: - g_value_set_string (value, src->autoprofile); - break; - case PROP_TRANSFORMATIONSELECTOR: - g_value_set_string (value, src->transformationselector); - break; - case PROP_BALANCERED: - g_value_set_double (value, src->balance[COLOUR_RED]); - break; - case PROP_BALANCEGREEN: - g_value_set_double (value, src->balance[COLOUR_GREEN]); - break; - case PROP_BALANCEBLUE: - g_value_set_double (value, src->balance[COLOUR_BLUE]); - break; - case PROP_COLORREDHUE: - g_value_set_double (value, src->hue[COLOUR_RED]); - break; - case PROP_COLORREDSATURATION: - g_value_set_double (value, src->saturation[COLOUR_RED]); - break; - case PROP_COLORYELLOWHUE: - g_value_set_double (value, src->hue[COLOUR_YELLOW]); - break; - case PROP_COLORYELLOWSATURATION: - g_value_set_double (value, src->saturation[COLOUR_YELLOW]); - break; - case PROP_COLORGREENHUE: - g_value_set_double (value, src->hue[COLOUR_GREEN]); - break; - case PROP_COLORGREENSATURATION: - g_value_set_double (value, src->saturation[COLOUR_GREEN]); - break; - case PROP_COLORCYANHUE: - g_value_set_double (value, src->hue[COLOUR_CYAN]); - break; - case PROP_COLORCYANSATURATION: - g_value_set_double (value, src->saturation[COLOUR_CYAN]); - break; - case PROP_COLORBLUEHUE: - g_value_set_double (value, src->hue[COLOUR_BLUE]); - break; - case PROP_COLORBLUESATURATION: - g_value_set_double (value, src->saturation[COLOUR_BLUE]); - break; - case PROP_COLORMAGENTAHUE: - g_value_set_double (value, src->hue[COLOUR_MAGENTA]); - break; - case PROP_COLORMAGENTASATURATION: - g_value_set_double (value, src->saturation[COLOUR_MAGENTA]); - break; - case PROP_COLORADJUSTMENTENABLE: - g_value_set_boolean (value, src->colorAdjustment); - break; - case PROP_MAXBANDWIDTH: - g_value_set_int (value, src->maxBandwidth); - break; - case PROP_FLIPX: - g_value_set_boolean (value, src->flip[AXIS_X]); - break; - case PROP_FLIPY: - g_value_set_boolean (value, src->flip[AXIS_Y]); - break; - case PROP_CENTERX: - g_value_set_boolean (value, src->center[AXIS_X]); - break; - case PROP_CENTERY: - g_value_set_boolean (value, src->center[AXIS_Y]); - break; - case PROP_LIMITBANDWIDTH: - g_value_set_boolean (value, src->limitBandwidth); - break; - case PROP_ACQUISITIONFRAMERATEENABLE: - g_value_set_boolean (value, src->setFPS); - break; - case PROP_CONTINUOUSMODE: - g_value_set_boolean (value, src->continuousMode); - break; - case PROP_BASLERDEMOSAICING: - g_value_set_boolean (value, src->demosaicing); - break; - case PROP_FPS: - g_value_set_double (value, src->fps); - break; - case PROP_EXPOSURE: - g_value_set_double (value, src->limitedFeature[AUTOF_EXPOSURE].manual); - break; - case PROP_GAIN: - g_value_set_double (value, src->limitedFeature[AUTOF_GAIN].manual); - break; - case PROP_BLACKLEVEL: - g_value_set_double (value, src->blacklevel); - break; - case PROP_GAMMA: - g_value_set_double (value, src->gamma); - break; - case PROP_DEMOSAICINGNOISEREDUCTION: - g_value_set_double (value, src->noisereduction); - break; - case PROP_DEMOSAICINGSHARPNESSENHANCEMENT: - g_value_set_double (value, src->sharpnessenhancement); - break; - case PROP_AUTOEXPOSUREUPPERLIMIT: - g_value_set_double (value, src->limitedFeature[AUTOF_EXPOSURE].upper); - break; - case PROP_AUTOEXPOSURELOWERLIMIT: - g_value_set_double (value, src->limitedFeature[AUTOF_EXPOSURE].lower); - break; - case PROP_GAINLOWERLIMIT: - g_value_set_double (value, src->limitedFeature[AUTOF_GAIN].lower); - break; - case PROP_GAINUPPERLIMIT: - g_value_set_double (value, src->limitedFeature[AUTOF_GAIN].upper); - break; - case PROP_AUTOBRIGHTNESSTARGET: - g_value_set_double (value, src->brightnesstarget); - break; - case PROP_TRANSFORMATION00: - g_value_set_double (value, src->transformation[0][0]); - break; - case PROP_TRANSFORMATION01: - g_value_set_double (value, src->transformation[0][1]); - break; - case PROP_TRANSFORMATION02: - g_value_set_double (value, src->transformation[0][2]); - break; - case PROP_TRANSFORMATION10: - g_value_set_double (value, src->transformation[1][0]); - break; - case PROP_TRANSFORMATION11: - g_value_set_double (value, src->transformation[1][1]); - break; - case PROP_TRANSFORMATION12: - g_value_set_double (value, src->transformation[1][2]); - break; - case PROP_TRANSFORMATION20: - g_value_set_double (value, src->transformation[2][0]); - break; - case PROP_TRANSFORMATION21: - g_value_set_double (value, src->transformation[2][1]); - break; - case PROP_TRANSFORMATION22: - g_value_set_double (value, src->transformation[2][2]); - break; - case PROP_CONFIGFILE: - g_value_set_string (value, src->configFile); - break; - case PROP_IGNOREDEFAULTS: - g_value_set_boolean (value, src->ignoreDefaults); - break; - case PROP_FRAMEDROPLIMIT: - g_value_set_int (value, src->frameDropLimit); - break; - case PROP_GRABTIMEOUT: - g_value_set_int (value, src->grabtimeout); - break; - case PROP_PACKETSIZE: - g_value_set_int (value, src->packetSize); - break; - case PROP_INTERPACKETDELAY: - g_value_set_int (value, src->interPacketDelay); - break; - case PROP_FRAMETRANSDELAY: - g_value_set_int (value, src->frameTransDelay); - break; - case PROP_BANDWIDTHRESERVE: - g_value_set_int (value, src->bandwidthReserve); - break; - case PROP_BANDWIDTHRESERVEACC: - g_value_set_int (value, src->bandwidthReserveAcc); - break; - case PROP_MAXTRANSFERSIZE: - g_value_set_int (value, src->maxTransferSize); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -/* caps negotiation */ -static GstCaps * -gst_pylonsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstPylonSrc *src = GST_PYLONSRC (bsrc); - - GST_DEBUG_OBJECT (src, - "Received a request for caps. Filter:\n%" GST_PTR_FORMAT, filter); - if (!src->deviceConnected) { - GST_DEBUG_OBJECT (src, "Could not send caps - no camera connected."); - return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)); - } else { - gst_pylonsrc_update_caps (src); - GstCaps *result = gst_caps_copy (src->caps); - GST_DEBUG_OBJECT (src, "Return caps:\n%" GST_PTR_FORMAT, result); - return result; - } -} - -static gboolean -gst_pylonsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstPylonSrc *src = GST_PYLONSRC (bsrc); - gint i; - GString *format = g_string_new (NULL); - - GST_DEBUG_OBJECT (src, "Setting caps to %" GST_PTR_FORMAT, caps); - - g_free (src->pixel_format); - src->pixel_format = NULL; - for (i = 0; i < G_N_ELEMENTS (gst_genicam_pixel_format_infos); i++) { - GstCaps *super_caps; - GstGenicamPixelFormatInfo *info = &gst_genicam_pixel_format_infos[i]; - super_caps = gst_caps_from_string (info->gst_caps_string); - g_string_printf (format, "EnumEntry_PixelFormat_%s", info->pixel_format); - if (gst_caps_is_subset (caps, super_caps) - && PylonDeviceFeatureIsAvailable (src->deviceHandle, format->str)) { - src->pixel_format = g_strdup (info->pixel_format); - GST_DEBUG_OBJECT (src, "Set caps match PixelFormat '%s'", - src->pixel_format); - break; - } - } - g_string_free (format, TRUE); - - if (src->pixel_format != NULL) { - // check if we need to change PixelFormat - char *const current_format = read_string_feature (src, "PixelFormat"); - const _Bool is_current_format = - g_ascii_strcasecmp (src->pixel_format, current_format) == 0; - g_free (current_format); - - if (!is_current_format) { - GST_DEBUG_OBJECT (src, "Setting PixelFormat to %s", src->pixel_format); - GENAPIC_RESULT res; - res = - PylonDeviceFeatureFromString (src->deviceHandle, "PixelFormat", - src->pixel_format); - PYLONC_CHECK_ERROR (src, res); - } - - char *pixelSize = read_string_feature (src, "PixelSize"); - - if (pixelSize != NULL) { - GST_DEBUG_OBJECT (src, "Pixel is %s bits large.", pixelSize + 3); - g_free (pixelSize); - } - - return TRUE; - } - - GST_ERROR_OBJECT (bsrc, "Unsupported caps: %" GST_PTR_FORMAT, caps); -error: - return FALSE; -} - -static inline _Bool -feature_supported (const GstPylonSrc * src, const char *feature) -{ - if (PylonDeviceFeatureIsImplemented (src->deviceHandle, feature)) { - return TRUE; - } else { - GST_WARNING_OBJECT (src, "Camera does not implement feature: %s", feature); - return FALSE; - } -} - -static inline _Bool -feature_available (const GstPylonSrc * src, const char *feature) -{ - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, feature)) { - return TRUE; - } else { - GST_WARNING_OBJECT (src, "Feature is not available: %s", feature); - return FALSE; - } -} - -static inline const char * -feature_alias_available (const GstPylonSrc * src, const char *feature, - const char *alias) -{ - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, feature)) { - return feature; - } else if (PylonDeviceFeatureIsAvailable (src->deviceHandle, alias)) { - return alias; - } else { - GST_WARNING_OBJECT (src, "Feature is not available: %s or %s", feature, - alias); - return NULL; - } -} - -static inline _Bool -feature_readable (const GstPylonSrc * src, const char *feature) -{ - if (PylonDeviceFeatureIsReadable (src->deviceHandle, feature)) { - return TRUE; - } else { - GST_WARNING_OBJECT (src, "Feature is not readable: %s", feature); - return FALSE; - } -} - -static inline const char * -feature_alias_readable (const GstPylonSrc * src, const char *feature, - const char *alias) -{ - if (PylonDeviceFeatureIsReadable (src->deviceHandle, feature)) { - return feature; - } else if (PylonDeviceFeatureIsReadable (src->deviceHandle, alias)) { - return alias; - } else { - GST_WARNING_OBJECT (src, "Feature is not readable: %s or %s", feature, - alias); - return NULL; - } -} - -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 -gst_pylonsrc_set_trigger (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_CONTINUOUSMODE)) { - // Set camera trigger mode - const char *triggerSelectorValue = "FrameStart"; - _Bool isAvailAcquisitionStart = - PylonDeviceFeatureIsAvailable (src->deviceHandle, - "EnumEntry_TriggerSelector_AcquisitionStart"); - _Bool isAvailFrameStart = PylonDeviceFeatureIsAvailable (src->deviceHandle, - "EnumEntry_TriggerSelector_FrameStart"); - const char *triggerMode = (src->continuousMode) ? "Off" : "On"; - - GST_DEBUG_OBJECT (src, "Setting trigger mode."); - - // Check to see if the camera implements the acquisition start trigger mode only - if (isAvailAcquisitionStart && !isAvailFrameStart) { - // Select the software trigger as the trigger source - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - "AcquisitionStart"); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerMode", - triggerMode); - PYLONC_CHECK_ERROR (src, res); - triggerSelectorValue = "AcquisitionStart"; - } else { - // Camera may have the acquisition start trigger mode and the frame start trigger mode implemented. - // In this case, the acquisition trigger mode must be switched off. - if (isAvailAcquisitionStart) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - "AcquisitionStart"); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerMode", - "Off"); - PYLONC_CHECK_ERROR (src, res); - } - // Disable frame burst start trigger if available - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, - "EnumEntry_TriggerSelector_FrameBurstStart")) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - "FrameBurstStart"); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerMode", - "Off"); - PYLONC_CHECK_ERROR (src, res); - } - // To trigger each single frame by software or external hardware trigger: Enable the frame start trigger mode - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - "FrameStart"); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerMode", - triggerMode); - PYLONC_CHECK_ERROR (src, res); - } - - if (!src->continuousMode) { - // Set the acquisiton selector to FrameTrigger in case it was changed by something else before launching the plugin so we don't request frames when they're still capturing or something. - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "AcquisitionStatusSelector", "FrameTriggerWait"); - PYLONC_CHECK_ERROR (src, res); - } - GST_DEBUG_OBJECT (src, - "Using \"%s\" trigger selector. Software trigger mode is %s.", - triggerSelectorValue, triggerMode); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - triggerSelectorValue); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSource", - "Software"); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "AcquisitionMode", - "Continuous"); - PYLONC_CHECK_ERROR (src, res); - - reset_prop (src, PROP_CONTINUOUSMODE); - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_select_device (GstPylonSrc * src) -{ - int i; - size_t numDevices; - GENAPIC_RESULT res; - - res = PylonEnumerateDevices (&numDevices); - PYLONC_CHECK_ERROR (src, res); - GST_DEBUG_OBJECT (src, "src: found %i Basler device(s).", (int) numDevices); - if (numDevices == 0) { - GST_ERROR_OBJECT (src, "No devices connected, canceling initialisation."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("No camera connected")); - goto error; - } else if (numDevices == 1) { - if (is_prop_set (src, PROP_CAMERA) && src->cameraId != 0) { - GST_DEBUG_OBJECT (src, - "Camera id was set, but was ignored as only one camera was found."); - src->cameraId = 0; - } - } else if (numDevices > 1 && !is_prop_set (src, PROP_CAMERA)) { - GST_DEBUG_OBJECT (src, - "Multiple cameras found, and the user didn't specify which camera to use."); - GST_DEBUG_OBJECT (src, - "Please specify the camera using the CAMERA property."); - GST_DEBUG_OBJECT (src, "The camera IDs are as follows: "); - - for (i = 0; i < numDevices; i++) { - PYLON_DEVICE_HANDLE deviceHandle; - res = PylonCreateDeviceByIndex (i, &deviceHandle); - - if (res == GENAPI_E_OK) { - res = - PylonDeviceOpen (deviceHandle, - PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM); - PYLONC_CHECK_ERROR (src, res); - - pylonc_print_camera_info (src, deviceHandle, i); - } else { - GST_DEBUG_OBJECT (src, - "ID:%i, Name: Unavailable, Serial No: Unavailable, Status: In use?", - i); - } - - PylonDeviceClose (deviceHandle); - PylonDestroyDevice (deviceHandle); - } - - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("No camera selected")); - goto error; - } else if (is_prop_set (src, PROP_CAMERA) && src->cameraId >= numDevices) { - GST_DEBUG_OBJECT (src, "No camera found with id %i.", src->cameraId); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("No camera connected")); - goto error; - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_connect_device (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (!pylonc_connect_camera (src)) { - GST_ERROR_OBJECT (src, "Couldn't initialise the camera"); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("No camera connected")); - goto error; - } - - if (strcmp (src->userid, "") != 0) { - if (PylonDeviceFeatureIsWritable (src->deviceHandle, "DeviceUserID")) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, "DeviceUserID", - src->userid); - PYLONC_CHECK_ERROR (src, res); - } - } - // Print the name of the camera - pylonc_print_camera_info (src, src->deviceHandle, src->cameraId); - - // Reset the camera if required. - ascii_strdown (&src->reset, -1); - if (strcmp (src->reset, "before") == 0) { - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "DeviceReset")) { - size_t numDevices; - pylonc_reset_camera (src); - pylonc_disconnect_camera (src); - gst_pylonsrc_unref_pylon_environment (); - - GST_DEBUG_OBJECT (src, - "Camera reset. Waiting 6 seconds for it to fully reboot."); - g_usleep (6 * G_USEC_PER_SEC); - - gst_pylonsrc_ref_pylon_environment (); - res = PylonEnumerateDevices (&numDevices); - PYLONC_CHECK_ERROR (src, res); - - if (!pylonc_connect_camera (src)) { - GST_ERROR_OBJECT (src, - "Couldn't initialise the camera. It looks like the reset failed. Please manually reconnect the camera and try again."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("No camera connected")); - goto error; - } - } else { - GST_ERROR_OBJECT (src, - "Couldn't reset the device - feature not supported. Cancelling startup."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Camera couldn't be reset properly.")); - goto error; - } - } - - return TRUE; - -error: - return FALSE; -} - -static int64_t -gst_pylonsrc_read_max_size_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis); - -static _Bool -gst_pylonsrc_set_resolution_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - GENAPIC_RESULT res; - - // set binning of camera - if (is_prop_implicit (src, propBinning[axis])) { - if (feature_supported (src, featBinning[axis])) { - GST_DEBUG_OBJECT (src, "Setting %s to %d", featBinning[axis], - src->binning[axis]); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, featBinning[axis], - src->binning[axis]); - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, propBinning[axis]); - } - - if (is_prop_implicit (src, propSize[axis])) { - if (!feature_supported (src, featSize[axis])) { - GST_ERROR_OBJECT (src, - "The camera doesn't seem to be reporting it's resolution."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Camera isn't reporting it's resolution. (Unsupported device?)")); - goto error; - } - - if (is_prop_set (src, propSize[axis])) { - if (feature_supported (src, featMaxSize[axis])) { - src->maxSize[axis] = (gint) gst_pylonsrc_read_max_size_axis (src, axis); - } - // Check if custom resolution is even possible and set it - if (src->size[axis] > src->maxSize[axis]) { - GST_ERROR_OBJECT (src, "Set %s is above camera's capabilities.", - featSize[axis]); - goto error; - } - // Set the final resolution - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, featSize[axis], - src->size[axis]); - PYLONC_CHECK_ERROR (src, res); - } else { - // if defaulted, just read from camera - int64_t size = 0; - res = - PylonDeviceGetIntegerFeature (src->deviceHandle, featSize[axis], - &size); - PYLONC_CHECK_ERROR (src, res); - src->size[axis] = (gint) size; - } - - if (is_prop_not_set (src, propSize[otherAxis[axis]])) { - // if other axis is already configured - GST_DEBUG_OBJECT (src, "Max resolution is %dx%d.", src->maxSize[AXIS_X], - src->maxSize[AXIS_Y]); - GST_DEBUG_OBJECT (src, "Setting resolution to %dx%d.", src->size[AXIS_X], - src->size[AXIS_Y]); - } - - reset_prop (src, propSize[axis]); - } - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_resolution (GstPylonSrc * src) -{ - return (gst_pylonsrc_set_resolution_axis (src, AXIS_X) && - gst_pylonsrc_set_resolution_axis (src, AXIS_Y)); -} - -static gboolean -gst_pylonsrc_set_offset_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, propCenter[axis])) { - // Check if the user wants to center image first - if (feature_supported (src, featCenter[axis])) { - res = - PylonDeviceSetBooleanFeature (src->deviceHandle, featCenter[axis], - src->center[axis]); - PYLONC_CHECK_ERROR (src, res); - } else if (src->center[axis] - && feature_supported (src, featCenterAlias[axis])) { - res = - PylonDeviceExecuteCommandFeature (src->deviceHandle, - featCenterAlias[axis]); - PYLONC_CHECK_ERROR (src, res); - } else { - src->center[axis] = FALSE; - } - - GST_DEBUG_OBJECT (src, "%s: %s", featCenter[axis], - boolalpha (src->center[axis])); - - reset_prop (src, propCenter[axis]); - } - - if (is_prop_set (src, propOffset[axis])) { - if (src->center[axis]) { - GST_WARNING_OBJECT (src, "%s is ignored due to %s is set", - featOffset[axis], featCenter[axis]); - } else { - if (feature_supported (src, featOffset[axis])) { - const gint maxoffset = src->maxSize[axis] - src->size[axis]; - - if (maxoffset >= src->offset[axis]) { - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, featOffset[axis], - src->offset[axis]); - PYLONC_CHECK_ERROR (src, res); - GST_DEBUG_OBJECT (src, "Setting %s to %d", featOffset[axis], - src->offset[axis]); - } else { - GST_DEBUG_OBJECT (src, - "Set %s is above camera's capabilities. (%d > %d)", - featOffset[axis], src->offset[axis], maxoffset); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("Wrong %s specified", - featOffset[axis])); - goto error; - } - } // if (feature_supported (src, featOffset[axis])) - } // if(!src->center[axis]) - reset_prop (src, propOffset[axis]); - } // if(!is_prop_not_set(src, propOffset[axis])) - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_offset (GstPylonSrc * src) -{ - return gst_pylonsrc_set_offset_axis (src, AXIS_X) && - gst_pylonsrc_set_offset_axis (src, AXIS_Y); -} - -static _Bool -gst_pylonsrc_set_reverse_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, propReverse[axis])) { - // Flip the image - if (feature_supported (src, featReverse[axis])) { - res = - PylonDeviceSetBooleanFeature (src->deviceHandle, featReverse[axis], - src->flip[axis]); - PYLONC_CHECK_ERROR (src, res); - - GST_DEBUG_OBJECT (src, "%s: %s", featReverse[axis], - boolalpha (src->flip[axis])); - } else { - src->flip[axis] = FALSE; - } - reset_prop (src, propReverse[axis]); - } - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_reverse (GstPylonSrc * src) -{ - return gst_pylonsrc_set_reverse_axis (src, AXIS_X) && - gst_pylonsrc_set_reverse_axis (src, AXIS_Y); -} - -static GstCaps * -gst_pylonsrc_get_supported_caps (GstPylonSrc * src) -{ - GstCaps *caps; - int i; - GString *format = g_string_new (NULL); - gboolean auto_format = FALSE; - - if (g_ascii_strncasecmp (src->pixel_format, "auto", -1) == 0) { - auto_format = TRUE; - } - - caps = gst_caps_new_empty (); - - /* check every pixel format GStreamer supports */ - for (i = 0; i < G_N_ELEMENTS (gst_genicam_pixel_format_infos); i++) { - const GstGenicamPixelFormatInfo *info = &gst_genicam_pixel_format_infos[i]; - - if (!auto_format - && g_ascii_strncasecmp (src->pixel_format, info->pixel_format, - -1) != 0) { - continue; - } - - g_string_printf (format, "EnumEntry_PixelFormat_%s", info->pixel_format); - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, format->str)) { - GstCaps *format_caps; - - GST_DEBUG_OBJECT (src, "PixelFormat %s supported, adding to caps", - info->pixel_format); - - // TODO: query FPS - format_caps = - gst_genicam_pixel_format_caps_from_pixel_format_var - (info->pixel_format, G_BYTE_ORDER, src->size[AXIS_X], - src->size[AXIS_Y]); - - if (format_caps) - gst_caps_append (caps, format_caps); - } - } - - GST_DEBUG_OBJECT (src, "Supported caps are %" GST_PTR_FORMAT, caps); - - g_string_free (format, TRUE); - return caps; -} - -static void -gst_pylonsrc_update_caps (GstPylonSrc * src) -{ - if (src->caps != NULL) { - gst_caps_unref (src->caps); - } - src->caps = gst_pylonsrc_get_supported_caps (src); - // TODO: handle caps renegotiation -} - -static gboolean -gst_pylonsrc_set_pixel_format (GstPylonSrc * src) -{ - if (is_prop_implicit (src, PROP_PIXEL_FORMAT)) { - GST_DEBUG_OBJECT (src, "Using %s PixelFormat.", src->pixel_format); - reset_prop (src, PROP_PIXEL_FORMAT); - } - return TRUE; -} - -static gboolean -gst_pylonsrc_set_test_image (GstPylonSrc * src) -{ - if (is_prop_implicit (src, PROP_TESTIMAGE)) { - // Set whether test image will be shown - if (feature_supported (src, "TestImageSelector")) { - GENAPIC_RESULT res; - if (src->testImage != 0) { - char *ImageId; - GST_DEBUG_OBJECT (src, "Test image mode enabled."); - ImageId = g_strdup_printf ("Testimage%d", src->testImage); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "TestImageSelector", ImageId); - g_free (ImageId); - PYLONC_CHECK_ERROR (src, res); - } else { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "TestImageSelector", "Off"); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_TESTIMAGE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_test_image_source (GstPylonSrc * src) -{ - if (is_prop_implicit (src, PROP_TESTIMAGESOURCE) && - !(is_prop_default (src, PROP_TESTIMAGESOURCE))) { - // Set whether test image will be shown - if (feature_supported (src, "ImageFilename")) { - GENAPIC_RESULT res; - res = PylonDeviceFeatureFromString(src->deviceHandle, "TestImageSelector", "Off"); - PYLONC_CHECK_ERROR(src, res); - /* Enable custom test images */ - res = PylonDeviceFeatureFromString(src->deviceHandle, "ImageFileMode", "On"); - PYLONC_CHECK_ERROR(src, res); - - GST_DEBUG_OBJECT (src, "Test image source enabled and set to %s", src->testImageSource); - res = PylonDeviceFeatureFromString(src->deviceHandle, "ImageFilename", src->testImageSource); - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, PROP_TESTIMAGESOURCE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_readout (GstPylonSrc * src) -{ - if (is_prop_implicit (src, PROP_SENSORREADOUTMODE)) { - // Set sensor readout mode (default: Normal) - if (feature_supported (src, "SensorReadoutMode")) { - ascii_strdown (&src->sensorMode, -1); - GENAPIC_RESULT res; - if (strcmp (src->sensorMode, "normal") == 0) { - - GST_DEBUG_OBJECT (src, "Setting the sensor readout mode to normal."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "SensorReadoutMode", "Normal"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->sensorMode, "fast") == 0) { - GST_DEBUG_OBJECT (src, "Setting the sensor readout mode to fast."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "SensorReadoutMode", "Fast"); - PYLONC_CHECK_ERROR (src, res); - } else { - GST_ERROR_OBJECT (src, - "Invalid parameter value for sensorreadoutmode. Available values are normal/fast, while the value provided was \"%s\".", - src->sensorMode); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } - reset_prop (src, PROP_SENSORREADOUTMODE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_bandwidth (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - if (is_prop_implicit (src, PROP_LIMITBANDWIDTH)) { - // Set bandwidth limit mode (default: on) - if (feature_supported (src, "DeviceLinkThroughputLimitMode")) { - GST_DEBUG_OBJECT (src, "%s camera's bandwidth.", - src->limitBandwidth ? "Limiting" : "Unlocking"); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "DeviceLinkThroughputLimitMode", src->limitBandwidth ? "On" : "Off"); - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, PROP_LIMITBANDWIDTH); - } - - if (is_prop_implicit (src, PROP_MAXBANDWIDTH)) { - // Set bandwidth limit - if (is_prop_set (src, PROP_MAXBANDWIDTH)) { - if (feature_supported (src, "DeviceLinkThroughputLimit")) { - if (!src->limitBandwidth) { - GST_DEBUG_OBJECT (src, - "Saving bandwidth limits, but because throughput mode is disabled they will be ignored."); - } - - GST_DEBUG_OBJECT (src, "Setting bandwidth limit to %d B/s.", - src->maxBandwidth); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, - "DeviceLinkThroughputLimit", src->maxBandwidth); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_MAXBANDWIDTH); - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_framerate (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - if (is_prop_implicit (src, PROP_ACQUISITIONFRAMERATEENABLE)) { - if (feature_available (src, "AcquisitionFrameRateEnable")) { - res = - PylonDeviceSetBooleanFeature (src->deviceHandle, - "AcquisitionFrameRateEnable", src->setFPS); - PYLONC_CHECK_ERROR (src, res); - - GST_DEBUG_OBJECT (src, - "Limiting framerate: %s. See below for current framerate.", - boolalpha (src->setFPS)); - } - reset_prop (src, PROP_ACQUISITIONFRAMERATEENABLE); - } - - if (is_prop_implicit (src, PROP_FPS)) { - if (is_prop_set (src, PROP_FPS)) { - // apply only if it is set explicitly (default is zero) - res = gst_pylonsrc_set_float_feature_alias (src, "AcquisitionFrameRate", - "AcquisitionFrameRateAbs", src->fps); - if (res != GENAPI_E_NODE_NOT_FOUND) { - PYLONC_CHECK_ERROR (src, res); - } - if (src->setFPS) { - GST_DEBUG_OBJECT (src, "Capping framerate to %0.2lf.", src->fps); - } - } - reset_prop (src, PROP_FPS); - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_lightsource (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - char *original = NULL; - if (is_prop_implicit (src, PROP_LIGHTSOURCE)) { - // Set lightsource preset - const char *preset = feature_alias_available (src, "LightSourcePreset", - "LightSourceSelector"); - if (preset == NULL && feature_available (src, "BslLightSourcePreset")) { - preset = "BslLightSourcePreset"; - } - - if (preset != NULL) { - original = g_strdup (src->lightsource); - ascii_strdown (&src->lightsource, -1); - - if (strcmp (src->lightsource, "off") == 0) { - GST_DEBUG_OBJECT (src, "Not using a lightsource preset."); - res = PylonDeviceFeatureFromString (src->deviceHandle, preset, "Off"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->lightsource, "2800k") == 0) { - GST_DEBUG_OBJECT (src, - "Setting light preset to Tungsten 2800k (Incandescen light)."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - preset, "Tungsten2800K"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->lightsource, "5000k") == 0) { - GST_DEBUG_OBJECT (src, - "Setting light preset to Daylight 5000k (Daylight)."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - preset, "Daylight5000K"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->lightsource, "6500k") == 0) { - GST_DEBUG_OBJECT (src, - "Setting light preset to Daylight 6500k (Very bright day)."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - preset, "Daylight6500K"); - PYLONC_CHECK_ERROR (src, res); - } else { - // Lets try to set lightsourse as is - GST_DEBUG_OBJECT (src, "Setting light preset to %s", original); - res = - PylonDeviceFeatureFromString (src->deviceHandle, preset, original); - - if (res != GENAPI_E_OK) { - GST_ERROR_OBJECT (src, - "Invalid parameter value for lightsource. Available values are off/2800k/5000k/6500k (if other values are supported by camera try setting them as specified in Basler documentation. E.g. \"Tungsten\" or \"Custom\"), while the value provided was \"%s\".", - src->lightsource); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } - } else { - GST_WARNING_OBJECT (src, - "This camera doesn't have any lightsource presets"); - } - reset_prop (src, PROP_LIGHTSOURCE); - } - g_free (original); - return TRUE; - -error: - g_free (original); - return FALSE; -} - -static _Bool -gst_pylonsrc_set_auto_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (is_prop_implicit (src, propAutoFeature[feature])) { - // Enable/disable automatic feature - if (feature_available (src, featAutoFeature[feature])) { - GENAPIC_RESULT res; - ascii_strdown (&src->autoFeature[feature], -1); - if (strcmp (src->autoFeature[feature], "off") == 0) { - GST_DEBUG_OBJECT (src, "Disabling %s.", featAutoFeature[feature]); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - featAutoFeature[feature], "Off"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->autoFeature[feature], "once") == 0) { - GST_DEBUG_OBJECT (src, "Making the camera only calibrate %s once.", - featManualFeature[feature]); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - featAutoFeature[feature], "Once"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->autoFeature[feature], "continuous") == 0) { - GST_DEBUG_OBJECT (src, - "Making the camera calibrate %s automatically all the time.", - featManualFeature[feature]); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - featAutoFeature[feature], "Continuous"); - PYLONC_CHECK_ERROR (src, res); - } else { - GST_ERROR_OBJECT (src, - "Invalid parameter value for %s. Available values are off/once/continuous, while the value provided was \"%s\".", - featAutoFeature[feature], src->autoFeature[feature]); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } - reset_prop (src, propAutoFeature[feature]); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_limited_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (feature >= AUTOF_NUM_LIMITED) { - GST_WARNING_OBJECT (src, - "Trying to set limits for unsupported autofeature: %d", (int) feature); - } else { - GENAPIC_RESULT res; - - // Configure automatic exposure and gain settings - // Apply boundaries only if explicitly set - if (is_prop_set (src, propLimitedUpper[feature])) { - if (is_prop_default (src, propLimitedLower[feature])) { - GST_WARNING_OBJECT (src, "Only the upper bound is set for %s", - featManualFeature[feature]); - } - - if (feature == AUTOF_GAIN) { - res = gst_pylonsrc_set_float_feature_with_int_alias (src, - featLimitedUpper[feature], featLimitedUpperAlias[feature], - src->limitedFeature[feature].upper); - } else { - res = gst_pylonsrc_set_float_feature_alias (src, - featLimitedUpper[feature], featLimitedUpperAlias[feature], - src->limitedFeature[feature].upper); - } - if (res != GENAPI_E_NODE_NOT_FOUND) { - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, propLimitedUpper[feature]); - } - - if (is_prop_set (src, propLimitedLower[feature])) { - if (is_prop_default (src, propLimitedLower[feature])) { - GST_WARNING_OBJECT (src, "Only the lower bound is set for %s", - featManualFeature[feature]); - } else { - if (src->limitedFeature[feature].lower >= - src->limitedFeature[feature].upper) { - GST_ERROR_OBJECT (src, - "Invalid parameter value for %s. It seems like you're trying to set a lower limit (%.2f) that's higher than the upper limit (%.2f).", - featLimitedLower[feature], src->limitedFeature[feature].lower, - src->limitedFeature[feature].upper); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } - - if (feature == AUTOF_GAIN) { - res = gst_pylonsrc_set_float_feature_with_int_alias (src, - featLimitedLower[feature], featLimitedLowerAlias[feature], - src->limitedFeature[feature].lower); - } else { - res = gst_pylonsrc_set_float_feature_alias (src, - featLimitedLower[feature], featLimitedLowerAlias[feature], - src->limitedFeature[feature].lower); - } - if (res != GENAPI_E_NODE_NOT_FOUND) { - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, propLimitedLower[feature]); - } - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_auto_exp_gain_wb (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - for (int i = 0; i < AUTOF_NUM_FEATURES; i++) { - if (!gst_pylonsrc_set_auto_feature (src, (GST_PYLONSRC_AUTOFEATURE) i)) { - goto error; - } - } - - for (int i = 0; i < AUTOF_NUM_LIMITED; i++) { - if (!gst_pylonsrc_set_limited_feature (src, (GST_PYLONSRC_AUTOFEATURE) i)) { - goto error; - } - } - - if (is_prop_implicit (src, PROP_AUTOBRIGHTNESSTARGET)) { - if (is_prop_set (src, PROP_AUTOBRIGHTNESSTARGET)) { - res = - gst_pylonsrc_set_float_feature_with_int_alias (src, - "AutoTargetBrightness", "AutoTargetValue", src->brightnesstarget); - PYLONC_CHECK_ERROR (src, res); - } - reset_prop (src, PROP_AUTOBRIGHTNESSTARGET); - } - - if (is_prop_implicit (src, PROP_AUTOPROFILE)) { - if (is_prop_set (src, PROP_AUTOPROFILE)) { - ascii_strdown (&src->autoprofile, -1); - GST_DEBUG_OBJECT (src, "Setting automatic profile to minimise %s.", - src->autoprofile); - if (strcmp (src->autoprofile, "gain") == 0) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "AutoFunctionProfile", "MinimizeGain"); - if (res != GENAPI_E_OK) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "AutoFunctionProfile", "GainMinimum"); - PYLONC_CHECK_ERROR (src, res); - } - } else if (strcmp (src->autoprofile, "exposure") == 0) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "AutoFunctionProfile", "MinimizeExposureTime"); - if (res != GENAPI_E_OK) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "AutoFunctionProfile", "ExposureMinimum"); - PYLONC_CHECK_ERROR (src, res); - } - } else { - GST_ERROR_OBJECT (src, - "Invalid parameter value for autoprofile. Available values are gain/exposure, while the value provided was \"%s\".", - src->autoprofile); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } else { - GST_DEBUG_OBJECT (src, - "Using the auto profile currently saved on the device."); - } - reset_prop (src, PROP_AUTOPROFILE); - } - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_colour_balance (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_implicit (src, propColourBalance[colour])) { - if (is_prop_set (src, propColourBalance[colour])) { - if (strcmp (src->autoFeature[AUTOF_WHITEBALANCE], "off") == 0) { - if (feature_available (src, "BalanceRatioSelector")) { - GENAPIC_RESULT res; - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "BalanceRatioSelector", featColour[colour]); - PYLONC_CHECK_ERROR (src, res); - GST_DEBUG_OBJECT (src, "BalanceRatioSelector: %s", - featColour[colour]); - - res = - 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 { - GST_DEBUG_OBJECT (src, - "Auto White Balance is enabled. Not setting %s Balance Ratio.", - featColour[colour]); - } - } else { - GST_DEBUG_OBJECT (src, "Using current settings for the colour %s.", - featColour[colour]); - } - reset_prop (src, propColourBalance[colour]); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_colour_hue (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_implicit (src, propColourHue[colour])) { - if (is_prop_set (src, propColourHue[colour])) { - const char *selector = - feature_alias_available (src, "ColorAdjustmentSelector", - "BslColorAdjustmentSelector"); - if (selector != NULL) { - GENAPIC_RESULT res; - res = - PylonDeviceFeatureFromString (src->deviceHandle, - selector, featColour[colour]); - PYLONC_CHECK_ERROR (src, res); - - const char *hue = feature_alias_available (src, "ColorAdjustmentHue", - "BslColorAdjustmentHue"); - if (hue != NULL) { - res = - PylonDeviceSetFloatFeature (src->deviceHandle, hue, - src->hue[colour]); - PYLONC_CHECK_ERROR (src, res); - } else if (feature_available (src, "ColorAdjustmentHueRaw")) { - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, - "ColorAdjustmentHueRaw", (int64_t) src->hue[colour]); - PYLONC_CHECK_ERROR (src, res); - } - - GST_DEBUG_OBJECT (src, "%s hue set to %.2lf", featColour[colour], - src->hue[colour]); - } - } else { - GST_DEBUG_OBJECT (src, "Using saved %s hue.", featColour[colour]); - } - reset_prop (src, propColourHue[colour]); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_colour_saturation (GstPylonSrc * src, - GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_implicit (src, propColourSaturation[colour])) { - if (is_prop_set (src, propColourSaturation[colour])) { - const char *selector = - feature_alias_available (src, "ColorAdjustmentSelector", - "BslColorAdjustmentSelector"); - if (selector != NULL) { - GENAPIC_RESULT res; - res = - PylonDeviceFeatureFromString (src->deviceHandle, - selector, featColour[colour]); - PYLONC_CHECK_ERROR (src, res); - - const char *saturation = - feature_alias_available (src, "ColorAdjustmentSaturation", - "BslColorAdjustmentSaturation"); - if (saturation != NULL) { - res = - PylonDeviceSetFloatFeature (src->deviceHandle, saturation, - src->saturation[colour]); - PYLONC_CHECK_ERROR (src, res); - } else if (feature_available (src, "ColorAdjustmentSaturationRaw")) { - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, - "ColorAdjustmentSaturationRaw", - (int64_t) src->saturation[colour]); - PYLONC_CHECK_ERROR (src, res); - } - - GST_DEBUG_OBJECT (src, "%s saturation set to %.2lf", featColour[colour], - src->saturation[colour]); - } - } else { - GST_DEBUG_OBJECT (src, "Using saved %s saturation.", featColour[colour]); - } - reset_prop (src, propColourSaturation[colour]); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_colour_transformation (GstPylonSrc * src, int i, int j) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, propTransform[j][i])) { - if (is_prop_set (src, propTransform[j][i])) { - if (feature_available (src, "ColorTransformationSelector")) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "ColorTransformationValueSelector", featTransform[j][i]); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceSetFloatFeature (src->deviceHandle, - "ColorTransformationValue", src->transformation[j][i]); - PYLONC_CHECK_ERROR (src, res); - - GST_DEBUG_OBJECT (src, "%s set to %.2lf", featTransform[j][i], - src->transformation[j][i]); - } - } else { - GST_DEBUG_OBJECT (src, "Using saved %s transformation value. ", - featTransform[j][i]); - } - reset_prop (src, propTransform[j][i]); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_color (GstPylonSrc * src) -{ - for (int i = 0; i < 3; i++) { - if (!gst_pylonsrc_set_colour_balance (src, (GST_PYLONSRC_COLOUR) i)) { - goto error; - } - } - - if (is_prop_implicit (src, PROP_COLORADJUSTMENTENABLE)) { - if (is_prop_set (src, PROP_COLORADJUSTMENTENABLE)) { - if (feature_available (src, "ColorAdjustmentEnable")) { - GENAPIC_RESULT res = PylonDeviceSetBooleanFeature (src->deviceHandle, - "ColorAdjustmentEnable", src->colorAdjustment); - PYLONC_CHECK_ERROR (src, res); - } else { - src->colorAdjustment = TRUE; - } - } - reset_prop (src, PROP_COLORADJUSTMENTENABLE); - } - - if (src->colorAdjustment) { - // Configure colour adjustment - for (int i = 0; i < 6; i++) { - const GST_PYLONSRC_COLOUR colour = (GST_PYLONSRC_COLOUR) i; - if (!gst_pylonsrc_set_colour_hue (src, colour) || - !gst_pylonsrc_set_colour_saturation (src, colour)) { - goto error; - } - } - } - // Configure colour transformation - if (is_prop_implicit (src, PROP_TRANSFORMATIONSELECTOR)) { - if (is_prop_set (src, PROP_TRANSFORMATIONSELECTOR)) { - if (feature_available (src, "ColorTransformationSelector")) { - ascii_strdown (&src->transformationselector, -1); - GENAPIC_RESULT res; - if (strcmp (src->transformationselector, "rgbrgb") == 0) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "ColorTransformationSelector", "RGBtoRGB"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->transformationselector, "rgbyuv") == 0) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "ColorTransformationSelector", "RGBtoYUV"); - PYLONC_CHECK_ERROR (src, res); - } else if (strcmp (src->transformationselector, "yuvrgb") == 0) { - res = - PylonDeviceFeatureFromString (src->deviceHandle, - "ColorTransformationSelector", "YUVtoRGB"); - PYLONC_CHECK_ERROR (src, res); - } else { - GST_ERROR_OBJECT (src, - "Invalid parameter value for transformationselector. Available values are: RGBRGB, RGBYUV, YUVRGB. Value provided: \"%s\".", - src->transformationselector); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Invalid parameters provided")); - goto error; - } - } - } - reset_prop (src, PROP_TRANSFORMATIONSELECTOR); - } - - for (int j = 0; j < 3; j++) { - for (int i = 0; i < 3; i++) { - if (!gst_pylonsrc_set_colour_transformation (src, i, j)) { - goto error; - } - } - } - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_manual_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (feature >= AUTOF_NUM_LIMITED) { - GST_WARNING_OBJECT (src, - "Trying to set manual value for unsupported autofeature: %d", - (int) feature); - } else { - // Configure exposure/gain - if (is_prop_implicit (src, propManualFeature[feature])) { - if (is_prop_set (src, propManualFeature[feature])) { - if (strcmp (src->autoFeature[feature], "off") == 0) { - GENAPIC_RESULT res; - if (feature == AUTOF_GAIN) { - res = - gst_pylonsrc_set_float_feature_with_int_alias (src, - 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); - } - } else { - GST_WARNING_OBJECT (src, - "%s has been enabled, skipping setting manual %s.", - featAutoFeature[feature], featManualFeature[feature]); - } - } else { - GST_DEBUG_OBJECT (src, - "%s property not set, using the saved setting.", - featManualFeature[feature]); - } - reset_prop (src, propManualFeature[feature]); - } - } - - return TRUE; - -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_exposure_gain_level (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - for (int i = 0; i < AUTOF_NUM_LIMITED; i++) { - if (!gst_pylonsrc_set_manual_feature (src, (GST_PYLONSRC_AUTOFEATURE) i)) { - goto error; - } - } - - // Configure black level - if (is_prop_implicit (src, PROP_BLACKLEVEL)) { - res = - 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); - } - reset_prop (src, PROP_BLACKLEVEL); - } - // Configure gamma correction - if (is_prop_implicit (src, PROP_GAMMA)) { - if (is_prop_set (src, PROP_GAMMA)) { - if (feature_available (src, "GammaEnable")) { - res = - PylonDeviceSetBooleanFeature (src->deviceHandle, "GammaEnable", 1); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceFeatureFromString (src->deviceHandle, "GammaSelector", - "User"); - PYLONC_CHECK_ERROR (src, res); - } - - if (feature_available (src, "Gamma")) { - GST_DEBUG_OBJECT (src, "Setting gamma to %0.2lf", src->gamma); - res = - PylonDeviceSetFloatFeature (src->deviceHandle, "Gamma", src->gamma); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_GAMMA); - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_pgi (GstPylonSrc * src) -{ - if (is_prop_implicit (src, PROP_BASLERDEMOSAICING)) { - const char *demosaicing = - feature_alias_available (src, featDemosaicing[0].name, - featDemosaicing[1].name); - if (demosaicing != NULL) { - GENAPIC_RESULT res; - ptrdiff_t idx = (demosaicing == featDemosaicing[0].name) ? 0 : 1; - const char *pgiOn = featDemosaicing[idx].on; - const char *pgiOff = featDemosaicing[idx].off; - - if (src->demosaicing) { - if (strncmp ("bayer", src->pixel_format, 5) != 0) { - GST_DEBUG_OBJECT (src, "Enabling Basler's PGI."); - res = - PylonDeviceFeatureFromString (src->deviceHandle, - demosaicing, pgiOn); - PYLONC_CHECK_ERROR (src, res); - - // PGI Modules (Noise reduction and Sharpness enhancement). - if (is_prop_implicit (src, PROP_DEMOSAICINGNOISEREDUCTION)) { - if (is_prop_set (src, PROP_DEMOSAICINGNOISEREDUCTION)) { - res = gst_pylonsrc_set_float_feature_alias (src, "NoiseReduction", - "NoiseReductionAbs", src->noisereduction); - if (res != GENAPI_E_NODE_NOT_FOUND) { - PYLONC_CHECK_ERROR (src, res); - } - } else { - GST_DEBUG_OBJECT (src, - "Using the stored value for noise reduction."); - } - reset_prop (src, PROP_DEMOSAICINGNOISEREDUCTION); - } - - if (is_prop_implicit (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) { - if (is_prop_set (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) { - res = - gst_pylonsrc_set_float_feature_alias (src, - "SharpnessEnhancement", "SharpnessEnhancementAbs", - src->sharpnessenhancement); - if (res != GENAPI_E_NODE_NOT_FOUND) { - PYLONC_CHECK_ERROR (src, res); - } - } else { - GST_DEBUG_OBJECT (src, - "Using the stored value for sharpness enhancement."); - } - reset_prop (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT); - } - } else { - GST_WARNING_OBJECT (src, - "Usage of PGI is not permitted with bayer output. Skipping."); - } - } else { - res = - PylonDeviceFeatureFromString (src->deviceHandle, demosaicing, - pgiOff); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_BASLERDEMOSAICING); - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_packetsize (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_PACKETSIZE)) { - if (is_prop_set (src, PROP_PACKETSIZE)) { - if (feature_supported (src, "GevSCPSPacketSize")) { - GST_DEBUG_OBJECT (src, "Setting packetsize to %d", src->packetSize); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, - "GevSCPSPacketSize", src->packetSize); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_PACKETSIZE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_interPacketDelay (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_INTERPACKETDELAY)) { - if (is_prop_set (src, PROP_INTERPACKETDELAY)) { - if (feature_supported (src, "GevSCPD")) { - GST_DEBUG_OBJECT (src, "Setting inter packet delay to %d", - src->interPacketDelay); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, "GevSCPD", - src->interPacketDelay); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_INTERPACKETDELAY); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_frameTransDelay (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_FRAMETRANSDELAY)) { - if (is_prop_set (src, PROP_FRAMETRANSDELAY)) { - if (feature_supported (src, "GevSCFTD")) { - GST_DEBUG_OBJECT (src, "Setting frame transmission delay to %d", - src->frameTransDelay); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, "GevSCFTD", - src->frameTransDelay); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_FRAMETRANSDELAY); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_bandwidthReserve (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_BANDWIDTHRESERVE)) { - if (is_prop_set (src, PROP_BANDWIDTHRESERVE)) { - if (feature_supported (src, "GevSCBWR")) { - GST_DEBUG_OBJECT (src, "Setting bandwidth reserve to %d", - src->bandwidthReserve); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, "GevSCBWR", - src->bandwidthReserve); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_BANDWIDTHRESERVE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_bandwidthReserveAcc (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_BANDWIDTHRESERVEACC)) { - if (is_prop_set (src, PROP_BANDWIDTHRESERVEACC)) { - if (feature_supported (src, "GevSCBWRA")) { - GST_DEBUG_OBJECT (src, "Setting bandwidth reserve accumulation to %d", - src->bandwidthReserveAcc); - res = - PylonDeviceSetIntegerFeature (src->deviceHandle, "GevSCBWRA", - src->bandwidthReserveAcc); - PYLONC_CHECK_ERROR (src, res); - } - } - reset_prop (src, PROP_BANDWIDTHRESERVEACC); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_set_maxTransferSize (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - - if (is_prop_implicit (src, PROP_MAXTRANSFERSIZE)) { - if (is_prop_set (src, PROP_MAXTRANSFERSIZE)) { - NODE_HANDLE phNode = 0; - NODEMAP_HANDLE phStreamGrabberNodeMap = 0; - PylonStreamGrabberGetNodeMap (src->streamGrabber, - &phStreamGrabberNodeMap); - if (!phStreamGrabberNodeMap) - goto error; - GenApiNodeMapGetNode (phStreamGrabberNodeMap, "MaxTransferSize", &phNode); - if (phNode) { - _Bool isWritable = 0; - GenApiNodeIsWritable (phNode, &isWritable); - if (isWritable) { - GST_DEBUG_OBJECT (src, "Setting max transfer size to %d", - src->maxTransferSize); - res = GenApiIntegerSetValue (phNode, src->maxTransferSize); - PYLONC_CHECK_ERROR (src, res); - } - } - } - reset_prop (src, PROP_MAXTRANSFERSIZE); - } - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_pylonsrc_configure_start_acquisition (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - size_t i; - size_t num_streams; - - // Create a stream grabber - res = - PylonDeviceGetNumStreamGrabberChannels (src->deviceHandle, &num_streams); - PYLONC_CHECK_ERROR (src, res); - if (num_streams < 1) { - GST_ERROR_OBJECT (src, - "The transport layer doesn't support image streams."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Transport layer error"), - ("The system does not support image streams.")); - goto error; - } - // Open the stream grabber for the first channel - res = PylonDeviceGetStreamGrabber (src->deviceHandle, 0, &src->streamGrabber); - PYLONC_CHECK_ERROR (src, res); - res = PylonStreamGrabberOpen (src->streamGrabber); - PYLONC_CHECK_ERROR (src, res); - - // set the max transfer size in case of USB - gst_pylonsrc_set_maxTransferSize (src); - - // Get the wait object - res = PylonStreamGrabberGetWaitObject (src->streamGrabber, &src->waitObject); - PYLONC_CHECK_ERROR (src, res); - - // Get the size of each frame - res = - PylonDeviceGetIntegerFeatureInt32 (src->deviceHandle, "PayloadSize", - &src->payloadSize); - PYLONC_CHECK_ERROR (src, res); - - // Allocate the memory for the frame payloads - for (i = 0; i < GST_PYLONSRC_NUM_CAPTURE_BUFFERS; ++i) { - src->buffers[i] = (unsigned char *) malloc (src->payloadSize); - if (NULL == src->buffers[i]) { - GST_ERROR_OBJECT (src, "Memory allocation error."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Memory allocation error"), - ("Couldn't allocate memory.")); - goto error; - } - } - - // Define buffers - res = - PylonStreamGrabberSetMaxNumBuffer (src->streamGrabber, - GST_PYLONSRC_NUM_CAPTURE_BUFFERS); - PYLONC_CHECK_ERROR (src, res); - res = - PylonStreamGrabberSetMaxBufferSize (src->streamGrabber, src->payloadSize); - PYLONC_CHECK_ERROR (src, res); - - // Prepare the camera for grabbing - res = PylonStreamGrabberPrepareGrab (src->streamGrabber); - PYLONC_CHECK_ERROR (src, res); - - for (i = 0; i < GST_PYLONSRC_NUM_CAPTURE_BUFFERS; ++i) { - res = - PylonStreamGrabberRegisterBuffer (src->streamGrabber, src->buffers[i], - src->payloadSize, &src->bufferHandle[i]); - PYLONC_CHECK_ERROR (src, res); - } - - for (i = 0; i < GST_PYLONSRC_NUM_CAPTURE_BUFFERS; ++i) { - res = - PylonStreamGrabberQueueBuffer (src->streamGrabber, - src->bufferHandle[i], (void *) i); - PYLONC_CHECK_ERROR (src, res); - } - - // Output the bandwidth the camera will actually use [B/s] - if (feature_supported (src, "DeviceLinkCurrentThroughput") - && feature_supported (src, "DeviceLinkSpeed")) { - int64_t throughput = 0, linkSpeed = 0; - - res = - PylonDeviceGetIntegerFeature (src->deviceHandle, - "DeviceLinkCurrentThroughput", &throughput); - PYLONC_CHECK_ERROR (src, res); - res = - PylonDeviceGetIntegerFeature (src->deviceHandle, "DeviceLinkSpeed", - &linkSpeed); - PYLONC_CHECK_ERROR (src, res); - - if (throughput > linkSpeed) { - GST_ERROR_OBJECT (src, - "Not enough bandwidth for the specified parameters."); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("USB3 error"), - ("Not enough bandwidth.")); - goto error; - } - - GST_DEBUG_OBJECT (src, - "With current settings the camera requires %d/%d B/s (%.1lf out of %.1lf MB/s) of bandwidth.", - (gint) throughput, (gint) linkSpeed, (double) throughput / 1000000, - (double) linkSpeed / 1000000); - } - // Output sensor readout time [us] - if (feature_supported (src, "SensorReadoutTime")) { - double readoutTime = 0.0; - - res = - PylonDeviceGetFloatFeature (src->deviceHandle, "SensorReadoutTime", - &readoutTime); - PYLONC_CHECK_ERROR (src, res); - - GST_DEBUG_OBJECT (src, - "With these settings it will take approximately %.0lf microseconds to grab each frame.", - readoutTime); - } - // Output final frame rate [Hz] - const char *name = feature_alias_available (src, "ResultingFrameRate", - "ResultingFrameRateAbs"); - if (name != NULL) { - double frameRate = 0.0; - - res = PylonDeviceGetFloatFeature (src->deviceHandle, name, &frameRate); - PYLONC_CHECK_ERROR (src, res); - - GST_DEBUG_OBJECT (src, "The resulting framerate is %.0lf fps.", frameRate); - GST_DEBUG_OBJECT (src, - "Each frame is %d bytes big (%.1lf MB). That's %.1lfMB/s.", - src->payloadSize, (double) src->payloadSize / 1000000, - (src->payloadSize * frameRate) / 1000000); - } - // Tell the camera to start recording - res = - PylonDeviceExecuteCommandFeature (src->deviceHandle, "AcquisitionStart"); - PYLONC_CHECK_ERROR (src, res); - if (!src->continuousMode) { - res = - PylonDeviceExecuteCommandFeature (src->deviceHandle, "TriggerSoftware"); - PYLONC_CHECK_ERROR (src, res); - } - src->failedFrames = 0; - src->frameNumber = 0; - - GST_DEBUG_OBJECT (src, "Initialised successfully."); - return TRUE; - -error: - return FALSE; -} - -static gchar * -read_string_feature (GstPylonSrc * src, const char *feature) -{ - if (feature_readable (src, feature)) { - gchar *result = NULL; - size_t bufLen = 0; - - for (int i = 0; i < 2; i++) { - // g_malloc(0) == NULL - result = g_malloc (bufLen); - // get bufLen at first iteration - // read value at second iteration - GENAPIC_RESULT res = - PylonDeviceFeatureToString (src->deviceHandle, feature, result, - &bufLen); - PYLONC_CHECK_ERROR (src, res); - } - GST_DEBUG_OBJECT (src, "Reading string feature: %s = %s", feature, result); - return result; - - error: - g_free (result); - } - return NULL; -} - -static GENAPIC_RESULT -read_bool_feature (GstPylonSrc * src, const char *feature, _Bool *result) -{ - GENAPIC_RESULT res = GENAPI_E_FAIL; - if (feature_readable (src, feature)) { - res = PylonDeviceGetBooleanFeature (src->deviceHandle, feature, result); - if (res == GENAPI_E_OK) { - GST_DEBUG_OBJECT (src, "Reading bool feature: %s = %s", feature, - boolalpha (*result)); - } else { - GST_ERROR_OBJECT (src, "Failed to read %s", feature); - } - } - - return res; -} - -static GENAPIC_RESULT -read_integer_feature (GstPylonSrc * src, const char *feature, int64_t * result) -{ - GENAPIC_RESULT res = GENAPI_E_FAIL; - if (feature_readable (src, feature)) { - res = PylonDeviceGetIntegerFeature (src->deviceHandle, feature, result); - if (res == GENAPI_E_OK) { - GST_DEBUG_OBJECT (src, "Reading integer feature: %s = %ld", feature, - *result); - } else { - GST_ERROR_OBJECT (src, "Failed to read %s", feature); - } - } - - return res; -} - -static GENAPIC_RESULT -read_float_feature (GstPylonSrc * src, const char *feature, double *result) -{ - GENAPIC_RESULT res = GENAPI_E_FAIL; - if (feature_readable (src, feature)) { - res = PylonDeviceGetFloatFeature (src->deviceHandle, 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; -} - -static GENAPIC_RESULT -read_float_feature_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) { - res = PylonDeviceGetFloatFeature (src->deviceHandle, name, result); - if (res == GENAPI_E_OK) { - 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; -} - -static int64_t -gst_pylonsrc_read_max_size_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - int64_t maxSize; - GENAPIC_RESULT res = read_integer_feature (src, featMaxSize[axis], &maxSize); - if (res == GENAPI_E_OK) { - return maxSize; - } else { - res = - PylonDeviceGetIntegerFeatureMax (src->deviceHandle, featSize[axis], - &maxSize); - if (res == GENAPI_E_OK) { - GST_INFO_OBJECT (src, "Read %s value from upper bound of %s", - featMaxSize[axis], featSize[axis]); - return maxSize; - } else { - GST_ERROR_OBJECT (src, "Failed to get upper bound of %s", featSize[axis]); - return G_MAXINT; - } - } -} - -static void -gst_pylonsrc_read_offset_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - if (is_prop_not_set (src, propCenter[axis])) { - read_bool_feature (src, featCenter[axis], &src->center[axis]); - } - - if (is_prop_not_set (src, propOffset[axis])) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, featOffset[axis], &temp); - if (res == GENAPI_E_OK) { - src->offset[axis] = temp; - } - } -} - -static void -gst_pylonsrc_read_offset (GstPylonSrc * src) -{ - gst_pylonsrc_read_offset_axis (src, AXIS_X); - gst_pylonsrc_read_offset_axis (src, AXIS_Y); -} - -static void -gst_pylonsrc_read_reverse_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - if (is_prop_not_set (src, propReverse[axis])) { - read_bool_feature (src, featReverse[axis], &src->flip[axis]); - } -} - -static void -gst_pylonsrc_read_reverse (GstPylonSrc * src) -{ - gst_pylonsrc_read_reverse_axis (src, AXIS_X); - gst_pylonsrc_read_reverse_axis (src, AXIS_Y); -} - -static void -gst_pylonsrc_read_pixel_format (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_PIXEL_FORMAT)) { - g_free (src->pixel_format); - src->pixel_format = read_string_feature (src, "PixelFormat"); - if (src->pixel_format == NULL) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), ("Unable to read PixelFormat")); - } - } -} - -static void -gst_pylonsrc_read_test_image (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_TESTIMAGE)) { - static const char prefix[] = "Testimage"; - char *ImageID = read_string_feature (src, "TestImageSelector"); - - if ((ImageID != NULL) - && (g_ascii_strncasecmp (ImageID, prefix, sizeof (prefix) - 1) == 0)) { - src->testImage = atoi (&ImageID[sizeof (prefix) - 1]); - } else { - src->testImage = 0; - } - g_free (ImageID); - } -} - -static void -gst_pylonsrc_read_readout (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_SENSORREADOUTMODE)) { - g_free (src->sensorMode); - src->sensorMode = read_string_feature (src, "SensorReadoutMode"); - } -} - -static void -gst_pylonsrc_read_bandwidth (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_LIMITBANDWIDTH)) { - char *mode = read_string_feature (src, "DeviceLinkThroughputLimitMode"); - if ((mode != NULL) && (g_ascii_strncasecmp (mode, "On", -1) == 0)) { - src->limitBandwidth = TRUE; - } else { - src->limitBandwidth = FALSE; - } - g_free (mode); - } - - if (is_prop_not_set (src, PROP_MAXBANDWIDTH)) { - int64_t temp; - GENAPIC_RESULT res = - read_integer_feature (src, "DeviceLinkThroughputLimit", &temp); - if (res == GENAPI_E_OK) { - src->maxBandwidth = temp; - } - } -} - -static void -gst_pylonsrc_read_framerate (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_ACQUISITIONFRAMERATEENABLE)) { - GENAPIC_RESULT res = read_bool_feature (src, - "AcquisitionFrameRateEnable", &src->setFPS); - if (res != GENAPI_E_OK) { - src->setFPS = FALSE; - } - } - - if (is_prop_not_set (src, PROP_FPS)) { - GENAPIC_RESULT res = read_float_feature_alias (src, - "AcquisitionFrameRate", "AcquisitionFrameRateAbs", &src->fps); - if (res != GENAPI_E_OK) { - src->fps = 0.0; - } - } -} - -static void -gst_pylonsrc_read_lightsource (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_LIGHTSOURCE)) { - g_free (src->lightsource); - src->lightsource = NULL; - - char *temp = read_string_feature (src, "LightSourcePreset"); - if (temp == NULL) { - temp = read_string_feature (src, "BslLightSourcePreset"); - if (temp == NULL) { - temp = read_string_feature (src, "LightSourceSelector"); - } - } - - if (temp != NULL) { - // if temp is something like "Daylight5000K" - // We need to set src->lightsource to "5000K" - for (int i = 0; i < strlen (temp); i++) { - if (temp[i] >= '0' && temp[i] <= '9') { - // found digit - src->lightsource = g_strdup (&temp[i]); - break; - } - } - // if temp is "Custom" or "Off", use the entire string - if (src->lightsource == NULL) { - src->lightsource = temp; - } else { - g_free (temp); - } - } - - if (src->lightsource == NULL) { - src->lightsource = g_strdup ("off"); - } - } -} - -static void -gst_pylonsrc_read_auto_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (is_prop_not_set (src, propAutoFeature[feature])) { - g_free (src->autoFeature[feature]); - src->autoFeature[feature] = - read_string_feature (src, featAutoFeature[feature]); - if (src->autoFeature[feature] == NULL) { - src->autoFeature[feature] = g_strdup ("off"); - } - } -} - -static void -gst_pylonsrc_read_limited_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (feature >= AUTOF_NUM_LIMITED) { - GST_WARNING_OBJECT (src, - "Trying to read limits for unsupported autofeature: %d", (int) feature); - } else { - 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], - featLimitedUpperAlias[feature], - &src->limitedFeature[feature].upper); - } - } - - 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], - featLimitedLowerAlias[feature], - &src->limitedFeature[feature].lower); - } - } - } -} - - -static void -gst_pylonsrc_read_auto_exp_gain_wb (GstPylonSrc * src) -{ - for (int i = 0; i < AUTOF_NUM_FEATURES; i++) { - gst_pylonsrc_read_auto_feature (src, (GST_PYLONSRC_AUTOFEATURE) i); - } - - for (int i = 0; i < AUTOF_NUM_LIMITED; i++) { - gst_pylonsrc_read_limited_feature (src, (GST_PYLONSRC_AUTOFEATURE) i); - } - - if (is_prop_not_set (src, PROP_AUTOBRIGHTNESSTARGET)) { - read_float_feature_with_int_alias (src, "AutoTargetBrightness", - "AutoTargetValue", &src->brightnesstarget); - } - - if (is_prop_not_set (src, PROP_AUTOPROFILE)) { - static const char prefix[] = "Minimize"; - g_free (src->autoprofile); - - char *temp = read_string_feature (src, "AutoFunctionProfile"); - if ((temp != NULL)) { - if (g_ascii_strncasecmp (temp, prefix, sizeof (prefix) - 1) == 0) { - // "MinimizeGain" -> "gain" - src->autoprofile = g_ascii_strdown (&temp[sizeof (prefix) - 1], -1); - } else { - static const char gain[] = "Gain"; - static const char exposure[] = "Exposure"; - if (g_ascii_strncasecmp (temp, gain, sizeof (gain) - 1) == 0) { - src->autoprofile = g_strdup ("gain"); - } else if (g_ascii_strncasecmp (temp, exposure, - sizeof (exposure) - 1) == 0) { - src->autoprofile = g_strdup ("exposure"); - } else { - GST_WARNING_OBJECT (src, - "Unexpectd AutoFuncitonProfile value on device: %s", temp); - src->autoprofile = g_strdup (temp); - } - } - } else { - src->autoprofile = g_strdup ("off"); - } - g_free (temp); - } -} - -static void -gst_pylonsrc_read_colour_balance (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_not_set (src, propColourBalance[colour])) { - GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, - "BalanceRatioSelector", featColour[colour]); - if (res == GENAPI_E_OK) { - read_float_feature_alias (src, "BalanceRatio", "BalanceRatioAbs", - &src->balance[colour]); - } - } -} - -static void -gst_pylonsrc_read_colour_hue (GstPylonSrc * src, GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_not_set (src, propColourHue[colour])) { - const char *selector = - feature_alias_readable (src, "ColorAdjustmentSelector", - "BslColorAdjustmentSelector"); - GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, - selector, featColour[colour]); - if (res == GENAPI_E_OK) { - res = - read_float_feature_alias (src, "ColorAdjustmentHue", - "BslColorAdjustmentHue", &src->hue[colour]); - if (res != GENAPI_E_OK) { - int64_t hue; - res = read_integer_feature (src, "ColorAdjustmentHueRaw", &hue); - if (res == GENAPI_E_OK) { - src->hue[colour] = (double) hue; - } - } - } - } -} - -static void -gst_pylonsrc_read_colour_saturation (GstPylonSrc * src, - GST_PYLONSRC_COLOUR colour) -{ - if (is_prop_not_set (src, propColourSaturation[colour])) { - const char *selector = - feature_alias_readable (src, "ColorAdjustmentSelector", - "BslColorAdjustmentSelector"); - GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, - selector, featColour[colour]); - if (res == GENAPI_E_OK) { - res = - read_float_feature_alias (src, "ColorAdjustmentSaturation", - "BslColorAdjustmentSaturation", &src->saturation[colour]); - if (res != GENAPI_E_OK) { - int64_t saturation; - res = - read_integer_feature (src, "ColorAdjustmentSaturationRaw", - &saturation); - if (res == GENAPI_E_OK) { - src->saturation[colour] = (double) saturation; - } - } - } - } -} - -static void -gst_pylonsrc_read_colour_transformation (GstPylonSrc * src, int i, int j) -{ - if (is_prop_not_set (src, propTransform[j][i])) { - GENAPIC_RESULT res = PylonDeviceFeatureFromString (src->deviceHandle, - "ColorTransformationValueSelector", featTransform[j][i]); - if (res == GENAPI_E_OK) { - read_float_feature (src, - "ColorTransformationValue", &src->transformation[j][i]); - } - } -} - -static void -gst_pylonsrc_read_color (GstPylonSrc * src) -{ - for (int i = 0; i < 3; i++) { - gst_pylonsrc_read_colour_balance (src, (GST_PYLONSRC_COLOUR) i); - } - - if (is_prop_not_set (src, PROP_COLORADJUSTMENTENABLE)) { - src->colorAdjustment = TRUE; - read_bool_feature (src, "ColorAdjustmentEnable", &src->colorAdjustment); - } - - for (int i = 0; i < 6; i++) { - const GST_PYLONSRC_COLOUR colour = (GST_PYLONSRC_COLOUR) i; - gst_pylonsrc_read_colour_hue (src, colour); - gst_pylonsrc_read_colour_saturation (src, colour); - } - - // Configure colour transformation - if (is_prop_not_set (src, PROP_TRANSFORMATIONSELECTOR)) { - char *temp = read_string_feature (src, "ColorTransformationSelector"); - g_free (src->transformationselector); - src->transformationselector = NULL; - - if (temp != NULL) { - if (strcmp (temp, "RGBtoRGB") == 0) { - src->transformationselector = g_strdup ("rgbrgb"); - } else if (strcmp (temp, "RGBtoYUV") == 0) { - src->transformationselector = g_strdup ("rgbyuv"); - } else if (strcmp (temp, "YUVtoRGB") == 0) { - src->transformationselector = g_strdup ("yuvrgb"); - } - g_free (temp); - } - - if (src->transformationselector == NULL) { - src->transformationselector = g_strdup ("off"); - } - } - - for (int j = 0; j < 3; j++) { - for (int i = 0; i < 3; i++) { - gst_pylonsrc_read_colour_transformation (src, i, j); - } - } -} - -static void -gst_pylonsrc_read_manual_feature (GstPylonSrc * src, - GST_PYLONSRC_AUTOFEATURE feature) -{ - if (feature >= AUTOF_NUM_LIMITED) { - GST_WARNING_OBJECT (src, - "Trying to read manual value for unsupported autofeature: %d", - (int) feature); - } else { - 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], - featManualFeatureAlias[feature], - &src->limitedFeature[feature].manual); - } - } - } -} - -static void -gst_pylonsrc_read_exposure_gain_level (GstPylonSrc * src) -{ - for (int i = 0; i < AUTOF_NUM_LIMITED; i++) { - gst_pylonsrc_read_manual_feature (src, (GST_PYLONSRC_AUTOFEATURE) i); - } - - if (is_prop_not_set (src, PROP_BLACKLEVEL)) { - read_float_feature_with_int_alias (src, "BlackLevel", "BlackLevelRaw", - &src->blacklevel); - } - // Configure gamma correction - if (is_prop_not_set (src, PROP_GAMMA)) { - read_float_feature (src, "Gamma", &src->gamma); - } -} - -static void -gst_pylonsrc_read_pgi (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_BASLERDEMOSAICING)) { - const char *demosaicing = - feature_alias_readable (src, featDemosaicing[0].name, - featDemosaicing[1].name); - if (demosaicing != NULL) { - const ptrdiff_t idx = (demosaicing == featDemosaicing[0].name) ? 0 : 1; - const char *pgiOn = featDemosaicing[idx].on; - char *temp = read_string_feature (src, demosaicing); - if ((temp != NULL) && (strcmp (temp, pgiOn))) { - src->demosaicing = TRUE; - } else { - src->demosaicing = FALSE; - } - g_free (temp); - } else { - src->demosaicing = FALSE; - } - } - - if (is_prop_not_set (src, PROP_DEMOSAICINGNOISEREDUCTION)) { - read_float_feature_alias (src, "NoiseReduction", "NoiseReductionAbs", - &src->noisereduction); - } - - if (is_prop_not_set (src, PROP_DEMOSAICINGSHARPNESSENHANCEMENT)) { - read_float_feature_alias (src, - "SharpnessEnhancement", "SharpnessEnhancementAbs", - &src->sharpnessenhancement); - } -} - -static void -gst_pylonsrc_read_trigger_selector_mode (GstPylonSrc * src, - const char *trigger_selector) -{ - GST_DEBUG_OBJECT (src, "Reading trigger selector mode: %s", trigger_selector); - GENAPIC_RESULT res = - PylonDeviceFeatureFromString (src->deviceHandle, "TriggerSelector", - trigger_selector); - if (res == GENAPI_E_OK) { - char *temp = read_string_feature (src, "TriggerMode"); - GST_DEBUG_OBJECT (src, "Trigger mode: %s", temp); - if ((temp != NULL) && (strcmp (temp, "On") == 0)) { - src->continuousMode = FALSE; - } else { - src->continuousMode = TRUE; - } - g_free (temp); - } else { - GST_WARNING_OBJECT (src, - "Failed to get TriggerSelector. Assuming continuous acquisition"); - src->continuousMode = TRUE; - } -} - -static void -gst_pylonsrc_read_trigger (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_CONTINUOUSMODE)) { - _Bool isAvailAcquisitionStart = - PylonDeviceFeatureIsAvailable (src->deviceHandle, - "EnumEntry_TriggerSelector_AcquisitionStart"); - _Bool isAvailFrameStart = PylonDeviceFeatureIsAvailable (src->deviceHandle, - "EnumEntry_TriggerSelector_FrameStart"); - - if (isAvailAcquisitionStart && !isAvailFrameStart) { - gst_pylonsrc_read_trigger_selector_mode (src, "AcquisitionStart"); - } else { - gst_pylonsrc_read_trigger_selector_mode (src, "FrameStart"); - } - } -} - -static void -gst_pylonsrc_read_resolution_axis (GstPylonSrc * src, GST_PYLONSRC_AXIS axis) -{ - if (is_prop_not_set (src, propBinning[axis])) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, featBinning[axis], &temp); - if (res == GENAPI_E_OK) { - src->binning[axis] = temp; - } - } - - if (is_prop_not_set (src, propSize[axis])) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, featSize[axis], &temp); - if (res == GENAPI_E_OK) { - src->size[axis] = temp; - } else { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Camera isn't reporting it's resolution. (Unsupported device?)")); - } - - src->maxSize[axis] = (gint) gst_pylonsrc_read_max_size_axis (src, axis); - } -} - -static void -gst_pylonsrc_read_resolution (GstPylonSrc * src) -{ - gst_pylonsrc_read_resolution_axis (src, AXIS_X); - gst_pylonsrc_read_resolution_axis (src, AXIS_Y); -} - -static void -gst_pylonsrc_read_packetsize (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_PACKETSIZE)) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, "GevSCPSPacketSize", &temp); - if (res == GENAPI_E_OK) { - src->packetSize = temp; - } - } -} - -static void -gst_pylonsrc_read_interPacketDelay (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_INTERPACKETDELAY)) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, "GevSCPD", &temp); - if (res == GENAPI_E_OK) { - src->interPacketDelay = temp; - } - } -} - -static void -gst_pylonsrc_read_frameTransDelay (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_FRAMETRANSDELAY)) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, "GevSCFTD", &temp); - if (res == GENAPI_E_OK) { - src->frameTransDelay = temp; - } - } -} - -static void -gst_pylonsrc_read_bandwidthReserve (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_BANDWIDTHRESERVE)) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, "GevSCBWR", &temp); - if (res == GENAPI_E_OK) { - src->bandwidthReserve = temp; - } - } -} - -static void -gst_pylonsrc_read_bandwidthReserveAcc (GstPylonSrc * src) -{ - if (is_prop_not_set (src, PROP_BANDWIDTHRESERVEACC)) { - int64_t temp; - GENAPIC_RESULT res = read_integer_feature (src, "GevSCBWRA", &temp); - if (res == GENAPI_E_OK) { - src->bandwidthReserveAcc = temp; - } - } -} - -// read all features from device to plugin struct -static void -read_all_features (GstPylonSrc * src) -{ - gst_pylonsrc_read_offset (src); - gst_pylonsrc_read_reverse (src); - gst_pylonsrc_read_pixel_format (src); - gst_pylonsrc_read_test_image (src); - gst_pylonsrc_read_packetsize (src); - gst_pylonsrc_read_interPacketDelay (src); - gst_pylonsrc_read_frameTransDelay (src); - gst_pylonsrc_read_bandwidthReserve (src); - gst_pylonsrc_read_bandwidthReserveAcc (src); - gst_pylonsrc_read_readout (src); - gst_pylonsrc_read_bandwidth (src); - gst_pylonsrc_read_framerate (src); - gst_pylonsrc_read_lightsource (src); - gst_pylonsrc_read_auto_exp_gain_wb (src); - gst_pylonsrc_read_color (src); - gst_pylonsrc_read_exposure_gain_level (src); - gst_pylonsrc_read_pgi (src); - gst_pylonsrc_read_trigger (src); - gst_pylonsrc_read_resolution (src); -} - -// Load features from PFS file to device -static _Bool -gst_pylonsrc_load_configuration (GstPylonSrc * src) -{ - if (is_prop_set (src, PROP_CONFIGFILE)) { - GST_DEBUG_OBJECT (src, "Loading features from file: %s", src->configFile); - NODEMAP_HANDLE hMap; - GENAPIC_RESULT res = PylonDeviceGetNodeMap (src->deviceHandle, &hMap); - PYLONC_CHECK_ERROR (src, res); - // Do not verify features. This makes plugin more robust in case of floating point values being rounded - // For example trying to set AcquisitionFrameRate to 300 will result in 300.030003 and verification failure - res = PylonFeaturePersistenceLoad (hMap, src->configFile, FALSE); - PYLONC_CHECK_ERROR (src, res); - reset_prop (src, PROP_CONFIGFILE); - } - - if (is_prop_set (src, PROP_IGNOREDEFAULTS)) { - if (src->ignoreDefaults) { - GST_DEBUG_OBJECT (src, "Ignoring defaults"); - for (int i = 0; i < GST_PYLONSRC_NUM_PROPS; i++) { - const GST_PYLONSRC_PROP prop = (GST_PYLONSRC_PROP) i; - if (is_prop_default (src, prop)) { - reset_prop (src, prop); - } - } - read_all_features (src); - } - reset_prop (src, PROP_IGNOREDEFAULTS); - } - - return TRUE; -error: - return FALSE; -} - -static _Bool -gst_pylonsrc_set_properties (GstPylonSrc * src) -{ - return gst_pylonsrc_load_configuration (src) && // make sure configuration is loaded first - gst_pylonsrc_set_resolution (src) && // make sure resolution is set before offset - 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_test_image_source (src) && - gst_pylonsrc_set_packetsize (src) && - gst_pylonsrc_set_interPacketDelay (src) && - gst_pylonsrc_set_frameTransDelay (src) && - gst_pylonsrc_set_bandwidthReserve (src) && - gst_pylonsrc_set_bandwidthReserveAcc (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); -} - -static gboolean -gst_pylonsrc_start (GstBaseSrc * bsrc) -{ - GstPylonSrc *src = GST_PYLONSRC (bsrc); - - const int count = gst_pylonsrc_ref_pylon_environment (); - if (count <= 0) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to initialise the camera"), - ("Pylon library initialization failed")); - goto error; - } else if (count == 1) { - GST_DEBUG_OBJECT (src, "First object created"); - } - - - if (!gst_pylonsrc_select_device (src) || - !gst_pylonsrc_connect_device (src) || !gst_pylonsrc_set_properties (src)) - goto error; - - return TRUE; - -error: - pylonc_disconnect_camera (src); - return FALSE; -} - -typedef struct -{ - GstPylonSrc *src; - PYLON_STREAMBUFFER_HANDLE buffer_handle; -} VideoFrame; - - -static void -video_frame_free (void *data) -{ - VideoFrame *frame = (VideoFrame *) data; - GstPylonSrc *src = frame->src; - GENAPIC_RESULT res; - - // Release frame's memory - res = - PylonStreamGrabberQueueBuffer (src->streamGrabber, frame->buffer_handle, - NULL); - PYLONC_CHECK_ERROR (src, res); - g_free (frame); - -error: - return; -} - -static GstFlowReturn -gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstPylonSrc *src = GST_PYLONSRC (psrc); - GENAPIC_RESULT res; - PylonGrabResult_t grabResult; - _Bool bufferReady; - - if (!gst_pylonsrc_set_properties (src)) { - // TODO: Maybe just shot warning if setting is not critical - goto error; - } - - if (!src->acquisition_configured) { - if (!gst_pylonsrc_configure_start_acquisition (src)) - goto error; - src->acquisition_configured = TRUE; - } - // Wait for the buffer to be filled (up to n ms). Can fail on large frames if timeout set too low. - res = PylonWaitObjectWait (src->waitObject, src->grabtimeout, &bufferReady); - PYLONC_CHECK_ERROR (src, res); - if (!bufferReady) { - GST_ERROR_OBJECT (src, - "Camera couldn't prepare the buffer in time. Probably dead."); - goto error; - } - - res = - PylonStreamGrabberRetrieveResult (src->streamGrabber, &grabResult, - &bufferReady); - PYLONC_CHECK_ERROR (src, res); - if (!bufferReady) { - GST_ERROR_OBJECT (src, - "Couldn't get a buffer from the camera. Basler said this should be impossible. You just proved them wrong. Congratulations!"); - goto error; - } - - if (!src->continuousMode) { - // Trigger the next picture while we process this one - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "AcquisitionStatus")) { - _Bool isReady = FALSE; - do { - res = - PylonDeviceGetBooleanFeature (src->deviceHandle, - "AcquisitionStatus", &isReady); - PYLONC_CHECK_ERROR (src, res); - } while (!isReady); - } - res = - PylonDeviceExecuteCommandFeature (src->deviceHandle, "TriggerSoftware"); - PYLONC_CHECK_ERROR (src, res); - } - // Process the current buffer - if (grabResult.Status == Grabbed || src->failedFrames < src->frameDropLimit) { - VideoFrame *vf = (VideoFrame *) g_malloc0 (sizeof (VideoFrame)); - - *buf = - gst_buffer_new_wrapped_full ((GstMemoryFlags) GST_MEMORY_FLAG_READONLY, - (gpointer) grabResult.pBuffer, src->payloadSize, 0, src->payloadSize, - vf, (GDestroyNotify) video_frame_free); - - vf->buffer_handle = grabResult.hBuffer; - vf->src = src; - - if (grabResult.Status != Grabbed) { - src->failedFrames += 1; - GST_WARNING_OBJECT (src, - "Failed capture count=%d. Status=%d, ErrorCode=0x%.8X", src->failedFrames, - grabResult.Status, grabResult.ErrorCode); - } else - src->failedFrames = 0; - } else { - GST_ERROR_OBJECT (src, - "Error in the image processing loop. Status=%d, ErrorCode=0x%.8X", - grabResult.Status, grabResult.ErrorCode); - goto error; - } - - // Set frame offset - GST_BUFFER_OFFSET (*buf) = src->frameNumber; - src->frameNumber += 1; - GST_BUFFER_OFFSET_END (*buf) = src->frameNumber; - - return GST_FLOW_OK; -error: - return GST_FLOW_ERROR; -} - -static gboolean -gst_pylonsrc_stop (GstBaseSrc * bsrc) -{ - GstPylonSrc *src = GST_PYLONSRC (bsrc); - GST_DEBUG_OBJECT (src, "stop"); - - pylonc_disconnect_camera (src); - - return TRUE; -} - -void -gst_pylonsrc_dispose (GObject * object) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - GST_DEBUG_OBJECT (src, "dispose"); - G_OBJECT_CLASS (gst_pylonsrc_parent_class)->dispose (object); -} - -void -gst_pylonsrc_finalize (GObject * object) -{ - GstPylonSrc *src = GST_PYLONSRC (object); - GST_DEBUG_OBJECT (src, "finalize"); - - g_free (src->pixel_format); - g_free (src->sensorMode); - g_free (src->lightsource); - - for (int i = 0; i < AUTOF_NUM_FEATURES; i++) { - g_free (src->autoFeature[i]); - } - - g_free (src->reset); - g_free (src->autoprofile); - g_free (src->transformationselector); - g_free (src->userid); - g_free (src->configFile); - - - if (gst_pylonsrc_unref_pylon_environment () == 0) { - GST_DEBUG_OBJECT (src, "Last object finalized"); - } - - G_OBJECT_CLASS (gst_pylonsrc_parent_class)->finalize (object); -} - - -void -pylonc_disconnect_camera (GstPylonSrc * src) -{ - if (src->deviceConnected) { - if (strcmp (src->reset, "after") == 0) { - pylonc_reset_camera (src); - } - - PylonDeviceClose (src->deviceHandle); - PylonDestroyDevice (src->deviceHandle); - src->deviceConnected = FALSE; - GST_DEBUG_OBJECT (src, "Camera disconnected."); - } -} - -_Bool -pylonc_reset_camera (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - if (PylonDeviceFeatureIsAvailable (src->deviceHandle, "DeviceReset")) { - GST_DEBUG_OBJECT (src, "Resetting device..."); - res = PylonDeviceExecuteCommandFeature (src->deviceHandle, "DeviceReset"); - PYLONC_CHECK_ERROR (src, res); - return TRUE; - } - -error: - GST_ERROR_OBJECT (src, "ERROR: COULDN'T RESET THE DEVICE."); - return FALSE; -} - -_Bool -pylonc_connect_camera (GstPylonSrc * src) -{ - GENAPIC_RESULT res; - GST_DEBUG_OBJECT (src, "Connecting to the camera (index=%d)...", - src->cameraId); - - res = PylonCreateDeviceByIndex (src->cameraId, &src->deviceHandle); - PYLONC_CHECK_ERROR (src, res); - - res = - PylonDeviceOpen (src->deviceHandle, - PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM); - PYLONC_CHECK_ERROR (src, res); - - src->deviceConnected = TRUE; - return TRUE; - -error: - return FALSE; -} - -void -pylonc_print_camera_info (GstPylonSrc * src, PYLON_DEVICE_HANDLE deviceHandle, - int deviceId) -{ - char name[256]; - char serial[256]; - char id[256]; - size_t siz = 0; - GENAPIC_RESULT res; - - if (PylonDeviceFeatureIsAvailable (deviceHandle, "DeviceModelName")) { - siz = sizeof (name); - res = - PylonDeviceFeatureToString (deviceHandle, "DeviceModelName", name, - &siz); - PYLONC_CHECK_ERROR (src, res); - - siz = sizeof (serial); - res = - PylonDeviceFeatureToString (deviceHandle, "DeviceSerialNumber", serial, - &siz); - if (siz <= 2 || res != GENAPI_E_OK) { - if (PylonDeviceFeatureIsReadable (deviceHandle, "DeviceID")) { - siz = sizeof (serial); - res = - PylonDeviceFeatureToString (deviceHandle, "DeviceID", serial, &siz); - } else { - serial[0] = '0'; - serial[1] = '\0'; - } - } - if (PylonDeviceFeatureIsReadable (deviceHandle, "DeviceUserID")) { - - siz = sizeof (id); - res = PylonDeviceFeatureToString (deviceHandle, "DeviceUserID", id, &siz); - PYLONC_CHECK_ERROR (src, res); - } - - if (id[0] == (char) 0) { - g_strdup ("None"); - } - - if (src->cameraId != deviceId) { // We're listing cameras - GST_LOG_OBJECT (src, - "ID:%i, Name:%s, Serial No:%s, Status: Available. Custom ID: %s", - deviceId, name, serial, id); - } else { // We've connected to a camera - GST_LOG_OBJECT (src, - "Status: Using camera \"%s\" (serial number: %s, id: %i). Custom ID: %s", - name, serial, deviceId, id); - } - } else { - error: - GST_ERROR_OBJECT (src, - "ID:%i, Status: Could not properly identify connected camera, the camera might not be compatible with this plugin.", - deviceId); - } -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - pylon, - "Basler Pylon video elements", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/pylon/gstpylonsrc.h b/sys/pylon/gstpylonsrc.h deleted file mode 100644 index aed6aa5..0000000 --- a/sys/pylon/gstpylonsrc.h +++ /dev/null @@ -1,125 +0,0 @@ -/* GStreamer - * Copyright (C) 2016-2017 Ingmars Melkis - * Copyright (C) 2018 Ingmars Melkis - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _GST_PYLONSRC_H_ -#define _GST_PYLONSRC_H_ - -#include -#include "pylonc/PylonC.h" - -// pylonsrc plugin calls PylonInitialize when first plugin is created -// and PylonTerminate when the last plugin is finalized. -// Static variable is used to keep count of existing plugins -// These functions can be used to increase or decrease this counter, -// if pylon environment is needed beyond lifetime of plugins. -// On success return value is the new value of counter -// On failure return value is negative -int gst_pylonsrc_ref_pylon_environment (); -int gst_pylonsrc_unref_pylon_environment (); - -enum -{ - GST_PYLONSRC_NUM_CAPTURE_BUFFERS = 10, - GST_PYLONSRC_NUM_AUTO_FEATURES = 3, - GST_PYLONSRC_NUM_LIMITED_FEATURES = 2, - GST_PYLONSRC_NUM_PROPS = 75 -}; - -typedef enum _GST_PYLONSRC_PROPERTY_STATE -{ - GST_PYLONSRC_PROPST_DEFAULT, - GST_PYLONSRC_PROPST_NOT_SET, - GST_PYLONSRC_PROPST_SET -} GST_PYLONSRC_PROPERTY_STATE; - -typedef struct _GstPylonSrcLimitedFeature -{ - double lower; - double upper; - double manual; -} GstPylonSrcLimitedFeature; - -G_BEGIN_DECLS -#define GST_TYPE_PYLONSRC (gst_pylonsrc_get_type()) -#define GST_PYLONSRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PYLONSRC,GstPylonSrc)) -#define GST_PYLONSRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PYLONSRC,GstPylonSrcClass)) -#define GST_IS_PYLONSRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PYLONSRC)) -#define GST_IS_PYLONSRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PYLONSRC)) -typedef struct _GstPylonSrc GstPylonSrc; -typedef struct _GstPylonSrcClass GstPylonSrcClass; - -struct _GstPylonSrc -{ - GstPushSrc base_pylonsrc; - - GstCaps *caps; - - gint cameraId; - PYLON_DEVICE_HANDLE deviceHandle; // Handle for the camera. - PYLON_STREAMGRABBER_HANDLE streamGrabber; // Handler for camera's streams. - PYLON_WAITOBJECT_HANDLE waitObject; // Handles timing out in the main loop. - gboolean deviceConnected; - gboolean acquisition_configured; - - unsigned char *buffers[GST_PYLONSRC_NUM_CAPTURE_BUFFERS]; - PYLON_STREAMBUFFER_HANDLE bufferHandle[GST_PYLONSRC_NUM_CAPTURE_BUFFERS]; - - int32_t frameSize; // Size of a frame in bytes. - int32_t payloadSize; // Size of a frame in bytes. - guint64 frameNumber; // Fun note: At 120fps it will take around 4 billion years to overflow this variable. - gint failedFrames; // Count of concecutive frames that have failed. - - // Plugin parameters - _Bool setFPS, continuousMode, limitBandwidth, demosaicing, colorAdjustment; - _Bool center[2]; - _Bool flip[2]; - _Bool ignoreDefaults; - double fps, blacklevel, gamma, sharpnessenhancement, noisereduction, - brightnesstarget; - double balance[3]; - double hue[6]; - double saturation[6]; - double transformation[3][3]; - - GstPylonSrcLimitedFeature limitedFeature[GST_PYLONSRC_NUM_LIMITED_FEATURES]; - - gint maxBandwidth, testImage, frameDropLimit, grabtimeout, packetSize, - interPacketDelay, frameTransDelay, bandwidthReserve, bandwidthReserveAcc, - maxTransferSize; - gint size[2]; - gint binning[2]; - gint maxSize[2]; - gint offset[2]; - gchar *pixel_format, *sensorMode, *lightsource, *reset, *autoprofile, - *transformationselector, *userid, *testImageSource; - gchar *autoFeature[GST_PYLONSRC_NUM_AUTO_FEATURES]; - gchar *configFile; - GST_PYLONSRC_PROPERTY_STATE propFlags[GST_PYLONSRC_NUM_PROPS]; -}; - -struct _GstPylonSrcClass -{ - GstPushSrcClass base_pylonsrc_class; -}; - -GType gst_pylonsrc_get_type (void); - -G_END_DECLS -#endif diff --git a/sys/qcam/CMakeLists.txt b/sys/qcam/CMakeLists.txt deleted file mode 100644 index 0694ae7..0000000 --- a/sys/qcam/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -set (SOURCES - gstqcamsrc.c) - -set (HEADERS - gstqcamsrc.h) - -include_directories (AFTER - ${QCAM_INCLUDE_DIR} - ) - -set (libname gstqcam) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -set (LIBRARIES - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${QCAM_LIBRARIES} - ) - -target_link_libraries (${libname} - ${LIBRARIES} - ) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/qcam/gstqcamsrc.c b/sys/qcam/gstqcamsrc.c deleted file mode 100644 index 04e4f2f..0000000 --- a/sys/qcam/gstqcamsrc.c +++ /dev/null @@ -1,789 +0,0 @@ -/* GStreamer - * Copyright (C) 2021 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstqcamsrc - * - * The qcamsrc element is a source for QImaging QCam cameras like the Retiga 2000R - * - * - * Example launch line - * |[ - * gst-launch -v qcamsrc ! videoconvert ! autovideosink - * ]| - * Shows video from the default QCam device - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "gstqcamsrc.h" - -#include - -GST_DEBUG_CATEGORY_STATIC (gst_qcamsrc_debug); -#define GST_CAT_DEFAULT gst_qcamsrc_debug - -/* prototypes */ -static void gst_qcamsrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_qcamsrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_qcamsrc_dispose (GObject * object); -static void gst_qcamsrc_finalize (GObject * object); - -static gboolean gst_qcamsrc_start (GstBaseSrc * src); -static gboolean gst_qcamsrc_stop (GstBaseSrc * src); -static GstCaps *gst_qcamsrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_qcamsrc_set_caps (GstBaseSrc * src, GstCaps * caps); -static gboolean gst_qcamsrc_unlock (GstBaseSrc * src); -static gboolean gst_qcamsrc_unlock_stop (GstBaseSrc * src); - -static GstFlowReturn gst_qcamsrc_create (GstPushSrc * src, GstBuffer ** buf); - -static void gst_qcamsrc_frame_callback (void *userPtr, unsigned long userData, - QCam_Err errcode, unsigned long flags); - -enum -{ - PROP_0, - PROP_DEVICE_INDEX, - PROP_NUM_CAPTURE_BUFFERS, - PROP_TIMEOUT, - PROP_EXPOSURE, - PROP_GAIN, - PROP_OFFSET, - PROP_FORMAT, - PROP_X, - PROP_Y, - PROP_WIDTH, - PROP_HEIGHT, - PROP_BINNING -}; - -#define DEFAULT_PROP_DEVICE_INDEX 0 -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 3 -#define DEFAULT_PROP_TIMEOUT 500 -#define DEFAULT_PROP_EXPOSURE 16384 -#define DEFAULT_PROP_GAIN 1.0 -#define DEFAULT_PROP_OFFSET 0 -#define DEFAULT_PROP_FORMAT qfmtMono16 -#define DEFAULT_PROP_X 0 -#define DEFAULT_PROP_Y 0 -#define DEFAULT_PROP_WIDTH 0 -#define DEFAULT_PROP_HEIGHT 0 -#define DEFAULT_PROP_BINNING 1 - -/* pad templates */ -static GstStaticPadTemplate gst_qcamsrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ GRAY16_LE, GRAY8 }") - ) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstQcamSrc, gst_qcamsrc, GST_TYPE_PUSH_SRC); - -static int g_qcam_use_count = 0; - -static void -gst_qcamsrc_driver_ref () -{ - if (g_qcam_use_count == 0) { - QCam_LoadDriver (); - } - g_qcam_use_count++; -} - -static void -gst_qcamsrc_driver_unref () -{ - g_qcam_use_count--; - if (g_qcam_use_count == 0) { - QCam_ReleaseDriver (); - } -} - -static void -gst_qcamsrc_class_init (GstQcamSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qcamsrc", 0, - "QImaging QCam source"); - - gobject_class->set_property = gst_qcamsrc_set_property; - gobject_class->get_property = gst_qcamsrc_get_property; - gobject_class->dispose = gst_qcamsrc_dispose; - gobject_class->finalize = gst_qcamsrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_qcamsrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "QCam Video Source", "Source/Video", - "QImaging QCam video source", "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_qcamsrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_qcamsrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_qcamsrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_qcamsrc_set_caps); - gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_qcamsrc_unlock); - gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_qcamsrc_unlock_stop); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_qcamsrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX, - g_param_spec_int ("device-index", "Device index", - "Index of device, use -1 to enumerate all and select last", -1, - G_MAXINT, DEFAULT_PROP_DEVICE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMEOUT, - g_param_spec_int ("timeout", "Timeout (ms)", - "Timeout in ms to wait for a frame beyond exposure time", 0, G_MAXINT, - DEFAULT_PROP_TIMEOUT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_EXPOSURE, - g_param_spec_uint ("exposure", "Exposure (us)", - "Exposure time in microseconds", 0, G_MAXINT, DEFAULT_PROP_EXPOSURE, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_GAIN, - g_param_spec_double ("gain", "Normalized gain", "Normalized gain", 0, - 1000, DEFAULT_PROP_GAIN, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_OFFSET, - g_param_spec_int ("offset", "Offset", "Absolute offset", -G_MAXINT, - G_MAXINT, DEFAULT_PROP_OFFSET, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FORMAT, - g_param_spec_int ("format", "Image format", - "Image format (2=GRAY8, 3=GRAY16_LE)", 2, 3, DEFAULT_PROP_FORMAT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_X, - g_param_spec_int ("x", "ROI x pixel", "ROI x pixel position", 0, G_MAXINT, - DEFAULT_PROP_X, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_Y, - g_param_spec_int ("y", "ROI y pixel", "ROI y pixel position", 0, G_MAXINT, - DEFAULT_PROP_Y, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WIDTH, - g_param_spec_int ("width", "ROI width", "ROI width", 0, G_MAXINT, - DEFAULT_PROP_WIDTH, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HEIGHT, - g_param_spec_int ("height", "ROI height", "ROI height", 0, G_MAXINT, - DEFAULT_PROP_HEIGHT, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BINNING, - g_param_spec_int ("binning", "Binning", "Symmetrical binning", 1, 8, - DEFAULT_PROP_BINNING, - (GParamFlags) (G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE))); -} - -static void -gst_qcamsrc_reset (GstQcamSrc * src) -{ - src->handle = NULL; - - src->exposure = DEFAULT_PROP_EXPOSURE; - src->gain = DEFAULT_PROP_GAIN; - src->offset = DEFAULT_PROP_OFFSET; - src->format = DEFAULT_PROP_FORMAT; - src->x = DEFAULT_PROP_X; - src->y = DEFAULT_PROP_Y; - src->width = DEFAULT_PROP_WIDTH; - src->height = DEFAULT_PROP_HEIGHT; - src->binning = DEFAULT_PROP_BINNING; - - src->last_frame_count = 0; - src->total_dropped_frames = 0; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->queue) { - // TODO: remove dangling buffers - g_async_queue_unref (src->queue); - } - src->queue = g_async_queue_new (); -} - -static void -gst_qcamsrc_init (GstQcamSrc * src) -{ - GST_DEBUG_OBJECT (src, "Initialize instance"); - - gst_qcamsrc_driver_ref (); - - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->device_index = DEFAULT_PROP_DEVICE_INDEX; - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - src->timeout = DEFAULT_PROP_TIMEOUT; - - src->stop_requested = FALSE; - src->caps = NULL; - src->queue = NULL; - - gst_qcamsrc_reset (src); -} - - -static void -gst_qcamsrc_set_exposure (GstQcamSrc * src, unsigned long exposure) -{ - QCam_SetParam (&src->qsettings, qprmExposure, exposure); -} - -static void -gst_qcamsrc_set_gain (GstQcamSrc * src, float gain) -{ - QCam_SetParam (&src->qsettings, qprmNormalizedGain, - (unsigned long) (gain * 1000000)); -} - -static void -gst_qcamsrc_set_offset (GstQcamSrc * src, long offset) -{ - QCam_SetParamS32 (&src->qsettings, qprmS32AbsoluteOffset, offset); -} - - -void -gst_qcamsrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstQcamSrc *src; - - src = GST_QCAM_SRC (object); - - switch (property_id) { - case PROP_DEVICE_INDEX: - src->device_index = g_value_get_int (value); - break; - case PROP_NUM_CAPTURE_BUFFERS: - src->num_capture_buffers = g_value_get_uint (value); - break; - case PROP_TIMEOUT: - src->timeout = g_value_get_int (value); - break; - case PROP_EXPOSURE: - src->exposure = g_value_get_uint (value); - src->send_settings = TRUE; - break; - case PROP_GAIN: - src->gain = g_value_get_double (value); - src->send_settings = TRUE; - break; - case PROP_OFFSET: - src->offset = g_value_get_int (value); - src->send_settings = TRUE; - break; - case PROP_FORMAT: - src->format = g_value_get_int (value); - break; - case PROP_X: - src->x = g_value_get_int (value); - break; - case PROP_Y: - src->y = g_value_get_int (value); - break; - case PROP_WIDTH: - src->width = GST_ROUND_DOWN_4 (g_value_get_int (value)); - break; - case PROP_HEIGHT: - src->height = g_value_get_int (value); - break; - case PROP_BINNING: - src->binning = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_qcamsrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstQcamSrc *src; - - g_return_if_fail (GST_IS_QCAM_SRC (object)); - src = GST_QCAM_SRC (object); - - switch (property_id) { - case PROP_DEVICE_INDEX: - g_value_set_int (value, src->device_index); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_TIMEOUT: - g_value_set_int (value, src->timeout); - break; - case PROP_EXPOSURE: - g_value_set_uint (value, src->exposure); - break; - case PROP_GAIN: - g_value_set_double (value, src->gain); - break; - case PROP_OFFSET: - g_value_set_int (value, src->offset); - break; - case PROP_FORMAT: - g_value_set_int (value, src->format); - break; - case PROP_X: - g_value_set_int (value, src->x); - break; - case PROP_Y: - g_value_set_int (value, src->y); - break; - case PROP_WIDTH: - g_value_set_int (value, src->width); - break; - case PROP_HEIGHT: - g_value_set_int (value, src->height); - break; - case PROP_BINNING: - g_value_set_int (value, src->binning); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_qcamsrc_dispose (GObject * object) -{ - GstQcamSrc *src; - - g_return_if_fail (GST_IS_QCAM_SRC (object)); - src = GST_QCAM_SRC (object); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_qcamsrc_parent_class)->dispose (object); -} - -void -gst_qcamsrc_finalize (GObject * object) -{ - GstQcamSrc *src; - - g_return_if_fail (GST_IS_QCAM_SRC (object)); - src = GST_QCAM_SRC (object); - - /* clean up object here */ - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - gst_qcamsrc_driver_unref (); - - G_OBJECT_CLASS (gst_qcamsrc_parent_class)->finalize (object); -} - -typedef struct -{ - GstQcamSrc *src; - QCam_Frame frame; - GstClockTime clock_time; -} VideoFrame; - -static void -video_frame_queue (VideoFrame * frame) -{ - QCam_Err err; - g_assert (frame->src->handle); - - GST_TRACE_OBJECT (frame->src, "Queuing frame 0x%x", frame); - err = QCam_QueueFrame (frame->src->handle, - &frame->frame, - gst_qcamsrc_frame_callback, - qcCallbackDone | qcCallbackExposeDone, frame, 0); -} - -static void -video_frame_release (void *data) -{ - VideoFrame *frame = (VideoFrame *) data; - if (!frame->src->stop_requested && frame->src->handle) { - video_frame_queue (frame); - } -} - -static VideoFrame * -video_frame_create (GstQcamSrc * src, gsize buf_size) -{ - VideoFrame *frame = g_new (VideoFrame, 1); - frame->frame.pBuffer = g_malloc (buf_size); - - if (!frame->frame.pBuffer) { - GST_ERROR_OBJECT (src, "Failed to allocate buffer of size %d", buf_size); - g_free (frame); - return NULL; - } - frame->src = src; - frame->frame.bufferSize = buf_size; - - return frame; -} - - -static gboolean -gst_qcamsrc_setup_stream (GstQcamSrc * src) -{ - QCam_Err err; - QCam_CamListItem cam_list[255]; - unsigned long num_cams = 255; - unsigned long width, height, imageFormat, exposure, gain; - long offset; - - err = QCam_ListCameras (cam_list, &num_cams); - if (err != qerrSuccess) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to get list of cameras (errcode=%d)", err), (NULL)); - return FALSE; - } - - GST_DEBUG_OBJECT (src, "Found %d cameras", num_cams); - - if (src->device_index + 1 > num_cams) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("device-index (%d) exceeds number of cameras found (%d)", - src->device_index, num_cams), (NULL)); - return FALSE; - } - - err = QCam_OpenCamera (cam_list[src->device_index].cameraId, &src->handle); - if (err != qerrSuccess) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to open camera (errcode=%d)", err), (NULL)); - return FALSE; - } - - err = QCam_SetStreaming (src->handle, TRUE); - if (err != qerrSuccess) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to start streaming (errcode=%d)", err), (NULL)); - QCam_CloseCamera (src->handle); - return FALSE; - } - - err = QCam_ReadSettingsFromCam (src->handle, &src->qsettings); - if (err != qerrSuccess) { - GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, - ("Failed to read settings (errcode=%d)", err), (NULL)); - QCam_CloseCamera (src->handle); - return FALSE; - } - - err = QCam_SetParam (&src->qsettings, qprmImageFormat, src->format); - err = QCam_SetParam (&src->qsettings, qprmBinning, src->binning); - err = QCam_SetParam (&src->qsettings, qprmRoiX, src->x); - err = QCam_SetParam (&src->qsettings, qprmRoiX, src->y); - if (src->width > 0) - err = QCam_SetParam (&src->qsettings, qprmRoiWidth, src->width); - if (src->height > 0) - err = QCam_SetParam (&src->qsettings, qprmRoiHeight, src->height); - gst_qcamsrc_set_exposure (src, src->exposure); - gst_qcamsrc_set_gain (src, src->gain); - gst_qcamsrc_set_offset (src, src->offset); - QCam_SendSettingsToCam (src->handle, &src->qsettings); - src->send_settings = FALSE; - - err = QCam_GetInfo (src->handle, qinfCcdWidth, &width); - err = QCam_GetInfo (src->handle, qinfCcdHeight, &height); - - GST_DEBUG_OBJECT (src, "Opened camera with CCD width,height=%d,%d", width, - height); - - err = QCam_GetParam (&src->qsettings, qprmRoiWidth, &width); - err = QCam_GetParam (&src->qsettings, qprmRoiHeight, &height); - err = QCam_GetParam (&src->qsettings, qprmImageFormat, &imageFormat); - err = QCam_GetParam (&src->qsettings, qprmExposure, &exposure); - err = QCam_GetParam (&src->qsettings, qprmNormalizedGain, &gain); - err = QCam_GetParamS32 (&src->qsettings, qprmS32AbsoluteOffset, &offset); - GST_DEBUG_OBJECT (src, - "ROI configured with width,height,format,exposure,gain,offset=%d,%d,%d,%d,%d,%d,%d", - width, height, imageFormat, exposure, gain, offset); - - for (int i = 0; i < src->num_capture_buffers; ++i) { - unsigned long buf_size; - QCam_GetInfo (src->handle, qinfImageSize, &buf_size); - VideoFrame *frame = video_frame_create (src, buf_size); - video_frame_queue (frame); - } - - { - GstStructure *structure; - GstCaps *caps; - caps = gst_caps_new_empty (); - structure = gst_structure_from_string ("video/x-raw", NULL); - const char *gst_format; - if (imageFormat == qfmtMono8) - gst_format = "GRAY8"; - else if (imageFormat == qfmtMono16) - gst_format = "GRAY16_LE"; - gst_structure_set (structure, - "format", G_TYPE_STRING, gst_format, - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION, 30, 1, NULL); - gst_caps_append_structure (caps, structure); - - if (src->caps) { - gst_caps_unref (src->caps); - } - src->caps = caps; - gst_base_src_set_caps (GST_BASE_SRC (src), src->caps); - } - - return TRUE; -} - -static gboolean -gst_qcamsrc_start (GstBaseSrc * bsrc) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "start"); - - if (!gst_qcamsrc_setup_stream (src)) { - /* error already sent */ - goto error; - } - - return TRUE; - -error: - return FALSE; -} - -static gboolean -gst_qcamsrc_stop (GstBaseSrc * bsrc) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - GST_DEBUG_OBJECT (src, "stop"); - - if (src->handle) { - QCam_CloseCamera (src->handle); - src->handle = NULL; - } - - gst_qcamsrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_qcamsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - GstCaps *caps; - - if (src->caps == NULL) { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } else { - caps = gst_caps_copy (src->caps); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_qcamsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - return TRUE; -} - -static gboolean -gst_qcamsrc_unlock (GstBaseSrc * bsrc) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock"); - - src->stop_requested = TRUE; - - return TRUE; -} - -static gboolean -gst_qcamsrc_unlock_stop (GstBaseSrc * bsrc) -{ - GstQcamSrc *src = GST_QCAM_SRC (bsrc); - - GST_LOG_OBJECT (src, "unlock_stop"); - - src->stop_requested = FALSE; - - return TRUE; -} - -static GstFlowReturn -gst_qcamsrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstQcamSrc *src = GST_QCAM_SRC (psrc); - VideoFrame *video_frame; - GST_LOG_OBJECT (src, "create"); - - video_frame = - (VideoFrame *) g_async_queue_timeout_pop (src->queue, - (guint64) src->timeout * 1000 + src->exposure); - if (!video_frame) { - if (!src->stop_requested) { - GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, - ("Failed to get buffer in %d ms", src->timeout), (NULL)); - return GST_FLOW_ERROR; - } else { - return GST_FLOW_FLUSHING; - } - } - - *buf = gst_buffer_new_wrapped_full ((GstMemoryFlags) - GST_MEMORY_FLAG_PHYSICALLY_CONTIGUOUS, - (gpointer) video_frame->frame.pBuffer, video_frame->frame.bufferSize, 0, - video_frame->frame.bufferSize, video_frame, - (GDestroyNotify) video_frame_release); - - - /* check for dropped frames and disrupted signal */ - //dropped_frames = (circ_handle.FrameCount - src->last_frame_count) - 1; - //if (dropped_frames > 0) { - // src->total_dropped_frames += dropped_frames; - // GST_WARNING_OBJECT (src, "Dropped %d frames (%d total)", dropped_frames, - // src->total_dropped_frames); - //} else if (dropped_frames < 0) { - // GST_WARNING_OBJECT (src, "Frame count non-monotonic, signal disrupted?"); - //} - //src->last_frame_count = circ_handle.FrameCount; - - GST_BUFFER_TIMESTAMP (*buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - video_frame->clock_time); - - if (src->stop_requested) { - if (*buf != NULL) { - gst_buffer_unref (*buf); - *buf = NULL; - } - return GST_FLOW_FLUSHING; - } - - if (src->handle && src->send_settings) { - gst_qcamsrc_set_exposure (src, src->exposure); - gst_qcamsrc_set_gain (src, src->gain); - gst_qcamsrc_set_offset (src, src->offset); - QCam_QueueSettings (src->handle, &src->qsettings, NULL, 0, 0, 0); - src->send_settings = FALSE; - } - - return GST_FLOW_OK; -} - -void -gst_qcamsrc_frame_callback (void *userPtr, unsigned long userData, - QCam_Err errcode, unsigned long flags) -{ - VideoFrame *frame = (VideoFrame *) (userPtr); - - if (flags & qcCallbackExposeDone) { - GstClock *clock = gst_element_get_clock (GST_ELEMENT (frame->src)); - frame->clock_time = gst_clock_get_time (clock); - gst_object_unref (clock); - GST_TRACE_OBJECT (frame->src, "ExposeDone callback for frame 0x%x", frame); - } else if (flags & qcCallbackDone) { - GST_TRACE_OBJECT (frame->src, "FrameDone callback for frame 0x%x", frame); - - if (errcode != qerrSuccess) { - GST_WARNING_OBJECT (frame->src, "Error code in callback: %d", errcode); - } - - g_async_queue_push (frame->src->queue, frame); - } else { - g_assert_not_reached (); - } -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qcam", 0, - "debug category for qcam plugin"); - - if (!gst_element_register (plugin, "qcamsrc", GST_RANK_NONE, - gst_qcamsrc_get_type ())) { - return FALSE; - } - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - qcam, - "QImaging QCam video element", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/qcam/gstqcamsrc.h b/sys/qcam/gstqcamsrc.h deleted file mode 100644 index 8b4be0a..0000000 --- a/sys/qcam/gstqcamsrc.h +++ /dev/null @@ -1,81 +0,0 @@ -/* GStreamer - * Copyright (C) 2021 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_QCAM_SRC_H_ -#define _GST_QCAM_SRC_H_ - -#include - -#include - -G_BEGIN_DECLS - -#define GST_TYPE_QCAM_SRC (gst_qcamsrc_get_type()) -#define GST_QCAM_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QCAM_SRC,GstQcamSrc)) -#define GST_QCAM_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QCAM_SRC,GstQcamSrcClass)) -#define GST_IS_QCAM_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QCAM_SRC)) -#define GST_IS_QCAM_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QCAM_SRC)) - -typedef struct _GstQcamSrc GstQcamSrc; -typedef struct _GstQcamSrcClass GstQcamSrcClass; - -struct _GstQcamSrc -{ - GstPushSrc base_qcamsrc; - - /* camera handle */ - QCam_Handle handle; - gboolean send_settings; - QCam_Settings qsettings; - - /* properties */ - gint device_index; - guint num_capture_buffers; - gint timeout; - guint exposure; - gdouble gain; - gint offset; - gint format; - gint x; - gint y; - gint width; - gint height; - gint binning; - - GAsyncQueue *queue; - GstClockTime base_time; - - guint32 last_frame_count; - guint32 total_dropped_frames; - - GstCaps *caps; - - gboolean stop_requested; -}; - -struct _GstQcamSrcClass -{ - GstPushSrcClass base_qcamsrc_class; -}; - -GType gst_qcamsrc_get_type (void); - -G_END_DECLS - -#endif diff --git a/sys/sapera/CMakeLists.txt b/sys/sapera/CMakeLists.txt deleted file mode 100644 index 8e021a6..0000000 --- a/sys/sapera/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -set (SOURCES - gstsaperasrc.cpp) - -set (HEADERS - gstsaperasrc.h) - -include_directories (AFTER - ${SAPERA_INCLUDE_DIR}) - -set (libname gstsapera) - -add_library (${libname} MODULE - ${SOURCES} - ${HEADERS}) - -target_link_libraries (${libname} - ${GLIB2_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GSTREAMER_LIBRARY} - ${GSTREAMER_BASE_LIBRARY} - ${GSTREAMER_VIDEO_LIBRARY} - ${SAPERA_LIBRARIES} - "C:\\Program Files\\Teledyne DALSA\\Sapera\\Lib\\Win64\\corapi.lib" - ) - -if (WIN32) - install (FILES $ DESTINATION ${PDB_INSTALL_DIR} COMPONENT pdb OPTIONAL) -endif () -install(TARGETS ${libname} LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/sys/sapera/aq2_prm_user.h b/sys/sapera/aq2_prm_user.h deleted file mode 100644 index cf3ba70..0000000 --- a/sys/sapera/aq2_prm_user.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _AQ2_PRM_USER -#define _AQ2_PRM_USER - -// Device indexes for CORHW_DEVICE_PRM_GET_VOLTAGE -#define AQ2_VOLTAGE_INDEX_12V 0 -#define AQ2_VOLTAGE_INDEX_INPUT_THRESHOLD 1 -#define AQ2_VOLTAGE_INDEX_FPGA_VCCINT 2 -#define AQ2_VOLTAGE_INDEX_FPGA_VCCAUX 3 -#define AQ2_VOLTAGE_POCL0_RSENSE 4 -#define AQ2_VOLTAGE_POCL1_RSENSE 5 - -// Device indexes for CORHW_DEVICE_PRM_GET_TEMPERATURE -#define AQ2_TEMPERATURE_INDEX_FPGA 0 - -// Parameter indexes for CORHW_DEVICE_PRM_GET_LANES_STATS -#define AQ2_CLHS_LANES_CRC_ERROR_COUNT 0 -#define AQ2_CLHS_LANES_VIDEO_MSG_COUNT 1 -#define AQ2_CLHS_LANES_PACKET_BUFFER_OVERFLOW_COUNT 2 -#define AQ2_CLHS_LANES_RESEND_FLAG_COUNT 3 -#define AQ2_CLHS_LANES_8B_10B_ERROR_COUNT 4 - -#endif \ No newline at end of file diff --git a/sys/sapera/corhw_prm_user.h b/sys/sapera/corhw_prm_user.h deleted file mode 100644 index fc0e185..0000000 --- a/sys/sapera/corhw_prm_user.h +++ /dev/null @@ -1,151 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// corhw_prm_user.h (c) Teledyne DALSA 2013 -// -// Description: -// Hardware Control Parameters -// -////////////////////////////////////////////////////////////////////////////// -#ifndef _CORHW_PRM_USER_H_ -#define _CORHW_PRM_USER_H_ -#include "cordef.h" - -#ifdef _MSC_VER -#pragma pack(1) -#endif - -#ifdef __BORLANDC__ -#pragma option -a1 -#endif - -#ifndef COR_PACK - #if COR_LINUX - #define COR_PACK __attribute__((packed)) - #else - #define COR_PACK - #endif -#endif - -#define CORHW_USER_DEVICE_PRM_SET_MEMORY_TEST 0x80000007 // W -#define CORHW_USER_DEVICE_PRM_SET_DIAGNOSTIC_MODE 0x80000009 // W -#define CORHW_USER_DEVICE_PRM_RESET_LANES_STATS 0x80000011 // W - -#define CORHW_USER_DEVICE_PRM_LOAD_FIRWMARE 0x00000023 -#define CORHW_USER_DEVICE_PRM_GET_MEMORY_TEST_RESULT 0x00000025 // R -#define CORHW_USER_DEVICE_PRM_GET_VOLTAGE 0x00000026 // R -#define CORHW_USER_DEVICE_PRM_GET_TEMPERATURE 0x00000027 // R -#define CORHW_USER_DEVICE_PRM_GET_BANDWIDTH 0x00000028 // R -#define CORHW_USER_DEVICE_PRM_GET_PCI_BUS_NUMBER 0x00000029 // R -#define CORHW_USER_DEVICE_PRM_GET_IS_RESET_NEEDED 0x0000002B // R -#define CORHW_USER_DEVICE_PRM_GET_PCI_SLOT_NUMBER 0x0000002E // R -#define CORHW_USER_DEVICE_PRM_GET_PCI_FUNCTION_NUMBER 0x0000002F // R -#define CORHW_USER_DEVICE_PRM_GET_PCIE_BUS_NB_LANES 0x00000030 // R -#define CORHW_USER_DEVICE_PRM_GET_PCIE_BUS_BIT_TRANSFER_RATE 0x00000031 // R -#define CORHW_USER_DEVICE_PRM_GET_PCIE_BUS_PAYLOAD_SIZE 0x00000032 // R -#define CORHW_USER_DEVICE_PRM_GET_PCIE_BUS_REQUEST_SIZE 0x00000034 // R -#define CORHW_USER_DEVICE_PRM_GET_THEORETICAL_BANDWIDTH 0x00000037 // R -#define CORHW_USER_DEVICE_PRM_GET_LANES_STATS 0x00000038 // R -#define CORHW_USER_DEVICE_PRM_GET_EYE_DIAGRAM 0x00000039 // R -#define CORHW_USER_DEVICE_PRM_GET_NB_LANES 0x00000043 // R -#define CORHW_USER_DEVICE_PRM_GET_TRANSMISSION_ENCODING 0x00000044 // R - -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN 0 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_RAMP 1 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_RESET 2 - -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_00 0x10000000 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_01 0x10000001 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_02 0x10000002 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_03 0x10000003 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_04 0x10000004 -#define CORHW_DEVICE_PARAMETER_MEMORY_TEST_PATTERN_BOARD_05 0x10000005 - -typedef struct _CORHW_DEVICE_PARAMETER_SET_DIAGNOSTIC_MODE_DATA -{ - UINT32 mode; // 0=Disable 1=Enable; -} CORHW_DEVICE_PARAMETER_SET_DIAGNOSTIC_MODE_DATA, *PCORHW_DEVICE_PARAMETER_SET_DIAGNOSTIC_MODE_DATA; - -typedef struct _CORHW_DEVICE_PARAMETER_MEMORY_TEST_DATA -{ - UINT32 testNumber; - UINT32 timeoutMs; // in ms -} CORHW_DEVICE_PARAMETER_MEMORY_TEST_DATA, *PCORHW_DEVICE_PARAMETER_MEMORY_TEST_DATA; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_MEMORY_TEST_RESULT_DATA -{ - DWORD nErrors; - //char szSource[CORCMD_NAME_LENGTH];// string name of the memory e.g: "DDR2" - UINT32 addressSizeInByte; - UINT32 busSizeInByte; - UINT32 memSizeInByte; - ULONG_PTR pBuffer; - ULONG_PTR pResult; -} CORHW_DEVICE_PARAMETER_GET_MEMORY_TEST_RESULT_DATA, *PCORHW_DEVICE_PARAMETER_GET_MEMORY_TEST_RESULT_DATA; - -struct MEM_TEST_RESULT -{ - UINT32 address; - UINT8 *readData; - UINT8 *expectedData; -}; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_VOLTAGE_DATA -{ - DWORD min; // in mVolts - DWORD max; // in mVolts - DWORD value; // in mVolts -} CORHW_DEVICE_PARAMETER_GET_VOLTAGE_DATA, *PCORHW_DEVICE_PARAMETER_GET_VOLTAGE_DATA; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_TEMPERATURE_DATA -{ - DWORD min; // in 1/1000 C - DWORD max; // in 1/1000 C - DWORD value; // in 1/1000 C -} CORHW_DEVICE_PARAMETER_GET_TEMPERATURE_DATA, *PCORHW_DEVICE_PARAMETER_GET_TEMPERATURE_DATA; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_IN -{ - UINT32 type; - char* resolution; - void *fctCallback; - void *context; -} CORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_IN, *PCORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_IN; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_OUT -{ - void *pData; - UINT32 *pSize; - UINT32 *pWidth; - UINT32 *pHeight; - UINT32 *pPercent; -} CORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_OUT, *PCORHW_DEVICE_PARAMETER_GET_EYE_DIAGRAM_DATA_OUT; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_NB_REGISTRY_PARAMETERS -{ - DWORD value; //count -} CORHW_DEVICE_PARAMETER_GET_NB_REGISTRY_PARAMETERS, *PCORHW_DEVICE_PARAMETER_GET_NB_REGISTRY_PARAMETERS; - -typedef struct _CORHW_DEVICE_PARAMETER_GET_REGISTRY_PARAMETER -{ - DWORD index; - DWORD type; //1=Byte,2=Word,4=DWORD,8=QWORD,16=String - CHAR *key; - DWORD lengthKey; - void *value; - DWORD lengthValue; -} CORHW_DEVICE_PARAMETER_GET_REGISTRY_PARAMETER, *PCORHW_DEVICE_PARAMETER_GET_REGISTRY_PARAMETER; - -typedef struct _CORHW_DEVICE_PARAMETER_SET_REGISTRY_PARAMETER -{ - DWORD type; //1=Byte,2=Word,4=DWORD,8=QWORD,16=String - CHAR *key; - DWORD lengthKey; - void *value; - DWORD lengthValue; -} CORHW_DEVICE_PARAMETER_SET_REGISTRY_PARAMETER, *PCORHW_DEVICE_PARAMETER_SET_REGISTRY_PARAMETER; - - -#ifdef _MSC_VER -#pragma pack() -#endif - -#endif \ No newline at end of file diff --git a/sys/sapera/gstsaperasrc.cpp b/sys/sapera/gstsaperasrc.cpp deleted file mode 100644 index 0a6beeb..0000000 --- a/sys/sapera/gstsaperasrc.cpp +++ /dev/null @@ -1,873 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, - * Boston, MA 02110-1335, USA. - */ -/** - * SECTION:element-gstsaperasrc - * - * The saperasrc element is a source for Teledyne DALSA Sapera framegrabbers. - * - * - * Example launch line - * |[ - * gst-launch -v saperasrc ! ffmpegcolorspace ! autovideosink - * ]| - * Shows video from the default DALSA framegrabber - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "aq2_prm_user.h" -#include "corhw_prm_user.h" - -#include "gstsaperasrc.h" - -GST_DEBUG_CATEGORY_STATIC (gst_saperasrc_debug); -#define GST_CAT_DEFAULT gst_saperasrc_debug - -gboolean gst_saperasrc_create_objects (GstSaperaSrc * src); -gboolean gst_saperasrc_destroy_objects (GstSaperaSrc * src); - -class SapMyProcessing:public SapProcessing -{ -public: - SapMyProcessing (SapBuffer * pBuffers, SapProCallback pCallback, - void *pContext) - : SapProcessing (pBuffers, pCallback, pContext) - { - src = (GstSaperaSrc *) pContext; - } - - virtual ~ SapMyProcessing () - { - if (m_bInitOK) - Destroy (); - } - -protected: - virtual BOOL Run () { - // TODO: handle bayer - //if (src->sap_bayer->IsEnabled () && src->sap_bayer->IsSoftware ()) { - // src->sap_bayer->Convert (GetIndex()); - //} - - push_buffer (); - - return TRUE; - } - - gboolean push_buffer () - { - void *pData; - GstMapInfo minfo; - - // TODO: check for failure - src->sap_buffers->GetAddress (&pData); - int pitch = src->sap_buffers->GetPitch (); - int height = src->sap_buffers->GetHeight (); - gssize size = pitch * height; - - GstBuffer *buf; - /* create a new buffer assign to it the clock time as timestamp */ - buf = gst_buffer_new_and_alloc (size); - - gst_buffer_set_size (buf, size); - - GstClock *clock = gst_element_get_clock (GST_ELEMENT (src)); - GST_BUFFER_TIMESTAMP (buf) = - GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)), - gst_clock_get_time (clock)); - gst_object_unref (clock); - - // TODO: define duration? - //GST_BUFFER_DURATION (buf) = duration; - - if (!gst_buffer_map (buf, &minfo, GST_MAP_WRITE)) { - gst_buffer_unref (buf); - GST_ERROR_OBJECT (src, "Failed to map buffer"); - return FALSE; - } - // TODO: optimize this - if (src->channel_extract == 0) { - if (pitch == src->gst_stride) { - memcpy (minfo.data, pData, size); - } else { - for (int line = 0; line < src->height; line++) { - memcpy (minfo.data + (line * src->gst_stride), - (guint8 *) pData + (line * pitch), pitch); - } - } - } else { - guint32 mask = 0x0, shift = 0; - if (src->channel_extract == 1) { - mask = 0x3ff00000; - shift = 20; - } else if (src->channel_extract == 2) { - mask = 0xffc00; - shift = 10; - } else if (src->channel_extract == 3) { - mask = 0x3ff; - shift = 0; - } else - g_assert_not_reached (); - - guint32 *packed = (guint32 *) pData; - guint16 *dst = (guint16 *) minfo.data; - for (int r = 0; r < src->height; ++r) { - for (int c = 0; c < src->width; ++c) { - *dst = (*packed & mask) >> shift; - ++dst; - ++packed; - } - } - } - - src->sap_buffers->ReleaseAddress (pData); - - gst_buffer_unmap (buf, &minfo); - - GST_DEBUG ("push_buffer => pts %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); - - g_mutex_lock (&src->buffer_mutex); - if (src->buffer != NULL) - gst_buffer_unref (src->buffer); - src->buffer = buf; - g_cond_signal (&src->buffer_cond); - g_mutex_unlock (&src->buffer_mutex); - - return TRUE; - } - -protected: - GstSaperaSrc * src; -}; - -void -gst_saperasrc_xfer_callback (SapXferCallbackInfo * pInfo) -{ - GstSaperaSrc *src = (GstSaperaSrc *) pInfo->GetContext (); - - if (pInfo->IsTrash ()) { - /* TODO: update dropped buffer count */ - } else { - /* Process current buffer */ - src->sap_pro->Execute (); - } -} - -void -gst_saperasrc_pro_callback (SapProCallbackInfo * pInfo) -{ - /* GstSaperaSrc *src = (GstSaperaSrc *) pInfo->GetContext (); */ - - /* TODO: handle buffer */ -} - -typedef struct COR_PACK -{ - UINT32 deviceIndex; // device to access - UINT32 prmIndex; // one of CORHW_DEVICE_PRM_xxx - UINT32 prmSize; // size in bytes of the variable size input data following -} CORCMD_DEVICE_PARAMETER, *PCORCMD_DEVICE_PARAMETER; - -#define CORCMD_USER_DEVICE_PARAMETER_READ (CORMAN_CORECO_CMD + 97) - -float -gst_saperasrc_get_fpga_temperature (GstSaperaSrc * src) -{ - CORSERVER server; - CORCMD_DEVICE_PARAMETER parameters = { 0 }; - CORHW_DEVICE_PARAMETER_GET_TEMPERATURE_DATA data = { 0 }; - - if (!SapManager::GetServerHandle (src->server_index, &server)) { - GST_WARNING_OBJECT (src, "Failed to get server handle"); - return 0; - } - - parameters.prmIndex = CORHW_USER_DEVICE_PRM_GET_TEMPERATURE; - parameters.deviceIndex = AQ2_TEMPERATURE_INDEX_FPGA; //Board Specific - parameters.prmSize = sizeof (data); - - UINT32 status = - CorManControl (server, CORCMD_USER_DEVICE_PARAMETER_READ, ¶meters, - sizeof (parameters), &data, sizeof (data)); - if (status) { - GST_WARNING_OBJECT (src, "Failed to query temperature: %08X", status); - return 0; - } - - return data.value / 1000.0f; -} - -void -gst_saperasrc_log_fpga_temperature (GstSaperaSrc * src) -{ - static FILE *temperature_file = NULL; - static gint64 temp_log_last_time = 0; - - if (g_getenv ("GST_SAPERA_FPGA_TEMP_LOG")) { - if (temperature_file == NULL) { - const char *envvar = g_getenv ("GST_SAPERA_FPGA_TEMP_LOG"); - gboolean write_header; - gchar *log_filename; - if (atoi (envvar) == 1) { - GDateTime *dt = g_date_time_new_now_local (); - log_filename = - g_date_time_format (dt, "sapera_fgpa_temp_%Y%m%d_%H%M%S.csv"); - g_date_time_unref (dt); - } else { - log_filename = g_strdup (envvar); - } - - write_header = !g_file_test (log_filename, G_FILE_TEST_EXISTS); - - GST_DEBUG_OBJECT (src, "Opening FPGA temp log file (%s)", log_filename); - temperature_file = fopen (log_filename, "a"); - if (!temperature_file) { - GST_ERROR_OBJECT (src, "Failed to open log file"); - return; - } - g_free (log_filename); - - if (write_header) { - fprintf (temperature_file, "IsoTime, UnixTime, KayaFpgaTemp\n"); - } - } - - if (temperature_file && g_get_real_time () - temp_log_last_time >= 1000000) { - GDateTime *dt = g_date_time_new_now_local (); - gchar *time_str = g_date_time_format (dt, "%Y-%m-%dT%H:%M:%S, %s"); - float fg_temp = gst_saperasrc_get_fpga_temperature (src); - GST_DEBUG_OBJECT (src, "FPGA temp: %,3f", fg_temp); - fprintf (temperature_file, "%s, %.3f\n", time_str, fg_temp); - fflush (temperature_file); - g_date_time_unref (dt); - g_free (time_str); - temp_log_last_time = g_get_real_time (); - } - } -} - - -gboolean -gst_saperasrc_init_objects (GstSaperaSrc * src) -{ - char name[128]; - int server_count, resource_count; - - server_count = SapManager::GetServerCount (); - GST_DEBUG_OBJECT (src, "There are %d servers available", server_count); - - if (src->server_index > server_count || - !SapManager::GetServerName (src->server_index, name)) { - GST_ERROR_OBJECT (src, "Invalid server index %d", src->server_index); - return FALSE; - } - - GST_DEBUG_OBJECT (src, "Trying to open server index %d ('%s')", - src->server_index, name); - - resource_count = SapManager::GetResourceCount (src->server_index, - SapManager::ResourceAcq); - GST_DEBUG_OBJECT (src, "Resource count: %d", resource_count); - - if (src->resource_index > resource_count || - !SapManager::GetResourceName (src->server_index, SapManager::ResourceAcq, - src->resource_index, name, 128)) { - GST_ERROR_OBJECT (src, "Invalid resource index %d", src->resource_index); - return FALSE; - } - GST_DEBUG_OBJECT (src, "Trying to open resource index %d ('%s')", - src->resource_index, name); - - GST_DEBUG_OBJECT (src, "Using config file '%s'", src->format_file); - - SapLocation loc (src->server_index, src->resource_index); - src->sap_acq = new SapAcquisition (loc, src->format_file); - /* TODO: allow configuring buffer count? */ - src->sap_buffers = new SapBufferWithTrash (3, src->sap_acq); - src->sap_xfer = - new SapAcqToBuf (src->sap_acq, src->sap_buffers, - gst_saperasrc_xfer_callback, src); - // TODO: handle bayer - //src->sap_bayer = new SapBayer(m_Acq, m_Buffers); - src->sap_pro = - new SapMyProcessing (src->sap_buffers, gst_saperasrc_pro_callback, src); - - return TRUE; -} - -gboolean -gst_saperasrc_create_objects (GstSaperaSrc * src) -{ - //UINT32 video_type = 0; - - /* Create acquisition object */ - if (src->sap_acq && !*src->sap_acq) { - if (!src->sap_acq->Create ()) { - GST_ERROR_OBJECT (src, "Failed to create SapAcquisition"); - gst_saperasrc_destroy_objects (src); - return FALSE; - } - } - //if (!src->sap_acq->GetParameter (CORACQ_PRM_VIDEO, &video_type)) { - // gst_saperasrc_destroy_objects (src); - // return FALSE; - //} - - /* TODO: handle Bayer - //if (videoType != CORACQ_VAL_VIDEO_BAYER) - - // Enable/Disable bayer conversion - // This call may require to modify the acquisition output format. - // For this reason, it has to be done after creating the acquisition object but before - // creating the output buffer object. - //if( m_Bayer && !m_Bayer->Enable( m_BayerEnabled, m_BayerUseHardware)) - //{ - // m_BayerEnabled= FALSE; - //} */ - - // Create buffer objects - if (src->sap_buffers && !*src->sap_buffers) { - if (!src->sap_buffers->Create ()) { - GST_ERROR_OBJECT (src, "Failed to create SapBuffer"); - gst_saperasrc_destroy_objects (src); - return FALSE; - } - // Clear all buffers - src->sap_buffers->Clear (); - } - - /* TODO: handle Bayer - // Create bayer object - //if (m_Bayer && !*m_Bayer && !m_Bayer->Create()) - //{ - // DestroyObjects(); - // return FALSE; - //} */ - - /* Create transfer object */ - if (src->sap_xfer && !*src->sap_xfer) { - if (!src->sap_xfer->Create ()) { - GST_ERROR_OBJECT (src, "Failed to create SapTransfer"); - gst_saperasrc_destroy_objects (src); - return FALSE; - } - - src->sap_xfer->SetAutoEmpty (FALSE); - } - - /* Create processing object */ - if (src->sap_pro && !*src->sap_pro) { - if (!src->sap_pro->Create ()) { - GST_ERROR_OBJECT (src, "Failed to create SapProcessing"); - gst_saperasrc_destroy_objects (src); - return FALSE; - } - - src->sap_pro->SetAutoEmpty (TRUE); - } - - return TRUE; -} - -gboolean -gst_saperasrc_destroy_objects (GstSaperaSrc * src) -{ - if (src->sap_xfer && *src->sap_xfer) - src->sap_xfer->Destroy (); - - if (src->sap_pro && *src->sap_pro) - src->sap_pro->Destroy (); - - // TODO: handle bayer - //if (src->sap_bayer && *src->sap_bayer) src->sap_bayer->Destroy (); - - if (src->sap_buffers && *src->sap_buffers) - src->sap_buffers->Destroy (); - - if (src->sap_acq && *src->sap_acq) - src->sap_acq->Destroy (); - - return TRUE; -} - -/* prototypes */ -static void gst_saperasrc_set_property (GObject * object, - guint property_id, const GValue * value, GParamSpec * pspec); -static void gst_saperasrc_get_property (GObject * object, - guint property_id, GValue * value, GParamSpec * pspec); -static void gst_saperasrc_dispose (GObject * object); -static void gst_saperasrc_finalize (GObject * object); - -static gboolean gst_saperasrc_start (GstBaseSrc * src); -static gboolean gst_saperasrc_stop (GstBaseSrc * src); -static GstCaps *gst_saperasrc_get_caps (GstBaseSrc * src, GstCaps * filter); -static gboolean gst_saperasrc_set_caps (GstBaseSrc * src, GstCaps * caps); - -static GstFlowReturn gst_saperasrc_create (GstPushSrc * src, GstBuffer ** buf); - -static GstCaps *gst_saperasrc_create_caps (GstSaperaSrc * src); - -enum -{ - PROP_0, - PROP_FORMAT_FILE, - PROP_NUM_CAPTURE_BUFFERS, - PROP_SERVER_INDEX, - PROP_RESOURCE_INDEX, - PROP_CHANNEL_EXTRACT -}; - -#define DEFAULT_PROP_FORMAT_FILE "" -#define DEFAULT_PROP_NUM_CAPTURE_BUFFERS 2 -#define DEFAULT_PROP_SERVER_INDEX 1 -#define DEFAULT_PROP_RESOURCE_INDEX 0 -#define DEFAULT_PROP_CHANNEL_EXTRACT 0 - -/* pad templates */ - -static GstStaticPadTemplate gst_saperasrc_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE - ("{ GRAY8, GRAY16_LE, GRAY16_BE, BGR, BGRA }")) - ); - -/* class initialization */ - -G_DEFINE_TYPE (GstSaperaSrc, gst_saperasrc, GST_TYPE_PUSH_SRC); - -static void -gst_saperasrc_class_init (GstSaperaSrcClass * klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); - GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); - GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); - - gobject_class->set_property = gst_saperasrc_set_property; - gobject_class->get_property = gst_saperasrc_get_property; - gobject_class->dispose = gst_saperasrc_dispose; - gobject_class->finalize = gst_saperasrc_finalize; - - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&gst_saperasrc_src_template)); - - gst_element_class_set_static_metadata (gstelement_class, - "Teledyne DALSA Sapera Video Source", "Source/Video", - "Teledyne DALSA Sapera framegrabber video source", - "Joshua M. Doe "); - - gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_saperasrc_start); - gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_saperasrc_stop); - gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_saperasrc_get_caps); - gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_saperasrc_set_caps); - - gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_saperasrc_create); - - /* Install GObject properties */ - g_object_class_install_property (gobject_class, PROP_FORMAT_FILE, - g_param_spec_string ("config-file", "Config file", - "Camera configuration filepath", - DEFAULT_PROP_FORMAT_FILE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | - GST_PARAM_MUTABLE_READY))); - g_object_class_install_property (gobject_class, PROP_NUM_CAPTURE_BUFFERS, - g_param_spec_uint ("num-capture-buffers", "Number of capture buffers", - "Number of capture buffers", 1, G_MAXUINT, - DEFAULT_PROP_NUM_CAPTURE_BUFFERS, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_SERVER_INDEX, - g_param_spec_int ("server-index", "Server index", - "Server (frame grabber card) index", 0, G_MAXINT, - DEFAULT_PROP_SERVER_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_RESOURCE_INDEX, - g_param_spec_int ("resource-index", "Resource index", - "Resource index, such as different ports or configurations", 0, - G_MAXINT, DEFAULT_PROP_RESOURCE_INDEX, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); - g_object_class_install_property (gobject_class, PROP_CHANNEL_EXTRACT, - g_param_spec_int ("color-channel", "Color channel", "Color channel", 0, 3, - DEFAULT_PROP_CHANNEL_EXTRACT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); -} - -static void -gst_saperasrc_reset (GstSaperaSrc * src) -{ - src->dropped_frame_count = 0; - src->last_buffer_number = 0; - src->acq_started = FALSE; - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - gst_saperasrc_destroy_objects (src); - - if (src->sap_acq) { - delete src->sap_acq; - src->sap_acq = NULL; - } - if (src->sap_buffers) { - delete src->sap_buffers; - src->sap_buffers = NULL; - } - if (src->sap_bayer) { - delete src->sap_bayer; - src->sap_bayer = NULL; - } - if (src->sap_xfer) { - delete src->sap_xfer; - src->sap_xfer = NULL; - } - if (src->sap_pro) { - delete src->sap_pro; - src->sap_pro = NULL; - } -} - -static void -gst_saperasrc_init (GstSaperaSrc * src) -{ - /* set source as live (no preroll) */ - gst_base_src_set_live (GST_BASE_SRC (src), TRUE); - - /* override default of BYTES to operate in time mode */ - gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME); - - /* initialize member variables */ - src->format_file = g_strdup (DEFAULT_PROP_FORMAT_FILE); - src->num_capture_buffers = DEFAULT_PROP_NUM_CAPTURE_BUFFERS; - - g_mutex_init (&src->buffer_mutex); - g_cond_init (&src->buffer_cond); - - src->caps = NULL; - src->buffer = NULL; - - src->sap_acq = NULL; - src->sap_buffers = NULL; - src->sap_bayer = NULL; - src->sap_xfer = NULL; - src->sap_pro = NULL; - - gst_saperasrc_reset (src); -} - -void -gst_saperasrc_set_property (GObject * object, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - GstSaperaSrc *src; - - src = GST_SAPERA_SRC (object); - - switch (property_id) { - case PROP_FORMAT_FILE: - g_free (src->format_file); - src->format_file = g_strdup (g_value_get_string (value)); - break; - case PROP_NUM_CAPTURE_BUFFERS: - if (src->acq_started) { - GST_ELEMENT_WARNING (src, RESOURCE, SETTINGS, - ("Number of capture buffers cannot be changed after acquisition has started."), - (NULL)); - } else { - src->num_capture_buffers = g_value_get_uint (value); - } - break; - case PROP_SERVER_INDEX: - src->server_index = g_value_get_int (value); - break; - case PROP_RESOURCE_INDEX: - src->resource_index = g_value_get_int (value); - break; - case PROP_CHANNEL_EXTRACT: - src->channel_extract = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_saperasrc_get_property (GObject * object, guint property_id, - GValue * value, GParamSpec * pspec) -{ - GstSaperaSrc *src; - - g_return_if_fail (GST_IS_SAPERA_SRC (object)); - src = GST_SAPERA_SRC (object); - - switch (property_id) { - case PROP_FORMAT_FILE: - g_value_set_string (value, src->format_file); - break; - case PROP_NUM_CAPTURE_BUFFERS: - g_value_set_uint (value, src->num_capture_buffers); - break; - case PROP_SERVER_INDEX: - g_value_set_int (value, src->server_index); - break; - case PROP_RESOURCE_INDEX: - g_value_set_int (value, src->resource_index); - break; - case PROP_CHANNEL_EXTRACT: - g_value_set_int (value, src->channel_extract); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -void -gst_saperasrc_dispose (GObject * object) -{ - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (gst_saperasrc_parent_class)->dispose (object); -} - -void -gst_saperasrc_finalize (GObject * object) -{ - GstSaperaSrc *src; - - g_return_if_fail (GST_IS_SAPERA_SRC (object)); - src = GST_SAPERA_SRC (object); - - /* clean up object here */ - g_free (src->format_file); - - if (src->caps) { - gst_caps_unref (src->caps); - src->caps = NULL; - } - - if (src->buffer) { - gst_buffer_unref (src->buffer); - src->buffer = NULL; - } - - G_OBJECT_CLASS (gst_saperasrc_parent_class)->finalize (object); -} - -static gboolean -gst_saperasrc_start (GstBaseSrc * bsrc) -{ - GstSaperaSrc *src = GST_SAPERA_SRC (bsrc); - GstVideoInfo vinfo; - SapFormat sap_format; - GstVideoFormat gst_format; - - GST_DEBUG_OBJECT (src, "start"); - - if (!strlen (src->format_file)) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Configuration file has not been specified"), (NULL)); - return FALSE; - } - - if (!g_file_test (src->format_file, G_FILE_TEST_EXISTS)) { - GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, - ("Configuration file does not exist: %s", src->format_file), (NULL)); - return FALSE; - } - - GST_DEBUG_OBJECT (src, "About to initialize and create Sapera objects"); - if (!gst_saperasrc_init_objects (src) || !gst_saperasrc_create_objects (src)) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Failed to create Sapera objects"), (NULL)); - return FALSE; - } - - GST_DEBUG_OBJECT (src, "Creating caps from Sapera buffer format"); - sap_format = src->sap_buffers->GetFormat (); - switch (sap_format) { - case SapFormatMono8: - gst_format = GST_VIDEO_FORMAT_GRAY8; - break; - case SapFormatMono16: - gst_format = GST_VIDEO_FORMAT_GRAY16_LE; - break; - case SapFormatRGB888: - gst_format = GST_VIDEO_FORMAT_BGR; - break; - case SapFormatRGB8888: - gst_format = GST_VIDEO_FORMAT_BGRA; - break; - case SapFormatRGB101010: - gst_format = GST_VIDEO_FORMAT_GRAY16_LE; - break; - default: - gst_format = GST_VIDEO_FORMAT_UNKNOWN; - } - - if (gst_format == GST_VIDEO_FORMAT_UNKNOWN) { - char format_name[17]; - SapManager::GetStringFromFormat (sap_format, format_name); - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, - ("Unsupported format: %s", format_name), (NULL)); - return FALSE; - } - - gst_video_info_init (&vinfo); - gst_video_info_set_format (&vinfo, gst_format, src->sap_buffers->GetWidth (), - src->sap_buffers->GetHeight ()); - src->caps = gst_video_info_to_caps (&vinfo); - - src->width = vinfo.width; - src->height = vinfo.height; - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - - if (!src->sap_xfer->Grab ()) { - GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Failed to start grab"), (NULL)); - return FALSE; - } - - return TRUE; -} - -static gboolean -gst_saperasrc_stop (GstBaseSrc * bsrc) -{ - GstSaperaSrc *src = GST_SAPERA_SRC (bsrc); - - GST_DEBUG_OBJECT (src, "stop"); - - if (!src->sap_xfer->Freeze ()) { - GST_ERROR_OBJECT (src, "Failed to stop camera acquisition"); - return FALSE; - } - - if (!src->sap_xfer->Wait (250)) { - GST_ERROR_OBJECT (src, "Acquisition failed to stop camera, aborting"); - src->sap_xfer->Abort (); - return FALSE; - } - - gst_saperasrc_reset (src); - - return TRUE; -} - -static GstCaps * -gst_saperasrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter) -{ - GstSaperaSrc *src = GST_SAPERA_SRC (bsrc); - GstCaps *caps; - - if (src->sap_acq && *src->sap_acq) { - caps = gst_caps_copy (src->caps); - } else { - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); - } - - GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT, - caps); - - if (filter && caps) { - GstCaps *tmp = gst_caps_intersect (caps, filter); - gst_caps_unref (caps); - caps = tmp; - } - - GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps); - - return caps; -} - -static gboolean -gst_saperasrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) -{ - GstSaperaSrc *src = GST_SAPERA_SRC (bsrc); - GstVideoInfo vinfo; - - GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps); - - gst_video_info_from_caps (&vinfo, caps); - - if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) { - src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0); - } else { - goto unsupported_caps; - } - - return TRUE; - -unsupported_caps: - GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps); - return FALSE; -} - -static GstFlowReturn -gst_saperasrc_create (GstPushSrc * psrc, GstBuffer ** buf) -{ - GstSaperaSrc *src = GST_SAPERA_SRC (psrc); - - GST_LOG_OBJECT (src, "create"); - - gst_saperasrc_log_fpga_temperature (src); - - g_mutex_lock (&src->buffer_mutex); - while (src->buffer == NULL) - g_cond_wait (&src->buffer_cond, &src->buffer_mutex); - *buf = src->buffer; - src->buffer = NULL; - g_mutex_unlock (&src->buffer_mutex); - - GST_DEBUG ("saperasrc_create => pts %" GST_TIME_FORMAT " duration %" - GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (*buf)), - GST_TIME_ARGS (GST_BUFFER_DURATION (*buf))); - - return GST_FLOW_OK; -} - -static gboolean -plugin_init (GstPlugin * plugin) -{ - GST_DEBUG_CATEGORY_INIT (gst_saperasrc_debug, "saperasrc", 0, - "debug category for saperasrc element"); - gst_element_register (plugin, "saperasrc", GST_RANK_NONE, - gst_saperasrc_get_type ()); - - return TRUE; -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - sapera, - "Teledyne DALSA Sapera frame grabber source", - plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME, - GST_PACKAGE_ORIGIN) diff --git a/sys/sapera/gstsaperasrc.h b/sys/sapera/gstsaperasrc.h deleted file mode 100644 index 60eb765..0000000 --- a/sys/sapera/gstsaperasrc.h +++ /dev/null @@ -1,83 +0,0 @@ -/* GStreamer - * Copyright (C) 2011 FIXME - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef _GST_SAPERA_SRC_H_ -#define _GST_SAPERA_SRC_H_ - -#include - -#include -#include - -G_BEGIN_DECLS - -#define GST_TYPE_SAPERA_SRC (gst_saperasrc_get_type()) -#define GST_SAPERA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SAPERA_SRC,GstSaperaSrc)) -#define GST_SAPERA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SAPERA_SRC,GstSaperaSrcClass)) -#define GST_IS_SAPERA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SAPERA_SRC)) -#define GST_IS_SAPERA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SAPERA_SRC)) - -typedef struct _GstSaperaSrc GstSaperaSrc; -typedef struct _GstSaperaSrcClass GstSaperaSrcClass; - -class SapMyProcessing; - -struct _GstSaperaSrc -{ - GstPushSrc base_saperasrc; - - guint last_buffer_number; - gint dropped_frame_count; - gboolean acq_started; - - /* Sapera objects */ - SapAcquisition *sap_acq; - SapBuffer *sap_buffers; - SapBayer *sap_bayer; - SapTransfer *sap_xfer; - SapMyProcessing*sap_pro; - - /* properties */ - gchar *format_file; - guint num_capture_buffers; - gint server_index; - gint resource_index; - gint channel_extract; - - GstBuffer *buffer; - - GstCaps *caps; - gint width; - gint height; - gint gst_stride; - - GMutex buffer_mutex; - GCond buffer_cond; -}; - -struct _GstSaperaSrcClass -{ - GstPushSrcClass base_saperasrc_class; -}; - -GType gst_saperasrc_get_type (void); - -G_END_DECLS - -#endif