From d2133b710223dee614597e873a06b0ab93811016 Mon Sep 17 00:00:00 2001 From: Josh Doe Date: Thu, 21 Apr 2011 17:09:18 -0400 Subject: [PATCH 1/2] Add CMake files for generating MSVC project files --- CMakeLists.txt | 35 +++++++++ cmake/modules/FindCairo.cmake | 15 ++++ cmake/modules/FindGSL.cmake | 29 +++++++ cmake/modules/FindGlib2.cmake | 53 +++++++++++++ cmake/modules/FindGstreamer.cmake | 123 ++++++++++++++++++++++++++++++ cmake/modules/FindLibIconv.cmake | 16 ++++ cmake/modules/FindLibXml2.cmake | 16 ++++ gst/CMakeLists.txt | 1 + gst/cairovis/CMakeLists.txt | 41 ++++++++++ set_paths_and_run_cmake.bat | 21 +++++ 10 files changed, 350 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/modules/FindCairo.cmake create mode 100644 cmake/modules/FindGSL.cmake create mode 100644 cmake/modules/FindGlib2.cmake create mode 100644 cmake/modules/FindGstreamer.cmake create mode 100644 cmake/modules/FindLibIconv.cmake create mode 100644 cmake/modules/FindLibXml2.cmake create mode 100644 gst/CMakeLists.txt create mode 100644 gst/cairovis/CMakeLists.txt create mode 100644 set_paths_and_run_cmake.bat diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f7d5a3e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required (VERSION "2.8.0") + +list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) + +project (gst-plugins-cairovis) + +find_package (Gstreamer REQUIRED) +find_package (Glib2 REQUIRED) +find_package (Cairo REQUIRED) +find_package (GSL REQUIRED) + +# conditional required packages +include (CheckIncludeFiles) +CHECK_INCLUDE_FILES ("${GSTREAMER_INCLUDE_DIR}/gst/gstconfig.h" GST_USING_BINARY_REGISTRY) +if (NOT GST_USING_BINARY_REGISTRY) + find_package (LIBXML2) + find_package (LIBICONV) + include_directories (AFTER + ${LIBXML2_INCLUDE_DIR} + ${LIBICONV_INCLUDE_DIR}) +endif (NOT GST_USING_BINARY_REGISTRY) + + +include_directories ( + . + ${GSTREAMER_INCLUDE_DIR} + ${GLIB2_INCLUDE_DIR} ) + +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + file (TO_CMAKE_PATH "${GSTREAMER_INCLUDE_DIR}/../.." PREFIX) + set (CMAKE_INSTALL_PREFIX + ${PREFIX} CACHE PATH "Directory to install plugins, under lib/gstreamer-0.10" FORCE) +endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + +add_subdirectory (gst) diff --git a/cmake/modules/FindCairo.cmake b/cmake/modules/FindCairo.cmake new file mode 100644 index 0000000..fa39109 --- /dev/null +++ b/cmake/modules/FindCairo.cmake @@ -0,0 +1,15 @@ +FILE(TO_CMAKE_PATH "$ENV{CAIRO_DIR}" TRY1_DIR) +FILE(TO_CMAKE_PATH "${CAIRO_DIR}" TRY2_DIR) +FILE(GLOB CAIRO_DIR ${TRY1_DIR} ${TRY2_DIR}) + +FIND_PATH(CAIRO_INCLUDE_DIR cairo.h + PATHS ${CAIRO_DIR}/include ${CAIRO_DIR}/include/cairo /usr/local/include/cairo /usr/include/cairo + ENV INCLUDE DOC "Directory containing cairo.h include file") + +FIND_LIBRARY(CAIRO_LIBRARIES cairo + PATHS ${CAIRO_DIR}/lib ${CAIRO_DIR}/lib/cairo /usr/local/lib/cairo /usr/lib/cairo + ENV LIB DOC "Directory containing cairo.lib file") + +IF (CAIRO_INCLUDE_DIR AND CAIRO_LIBRARIES) + SET(CAIRO_FOUND TRUE) +ENDIF (CAIRO_INCLUDE_DIR AND CAIRO_LIBRARIES) diff --git a/cmake/modules/FindGSL.cmake b/cmake/modules/FindGSL.cmake new file mode 100644 index 0000000..acabaf3 --- /dev/null +++ b/cmake/modules/FindGSL.cmake @@ -0,0 +1,29 @@ +FILE(TO_CMAKE_PATH "$ENV{GSL_DIR}" TRY1_DIR) +FILE(TO_CMAKE_PATH "${GSL_DIR}" TRY2_DIR) +FILE(GLOB GSL_DIR ${TRY1_DIR} ${TRY2_DIR}) + +FIND_PATH(GSL_INCLUDE_DIR gsl/gsl_blas.h + PATHS ${GSL_DIR}/include ${GSL_DIR} + ENV INCLUDE DOC "Directory containing gsl_blas.h include file") + +FIND_LIBRARY(GSL_ERR_LIBRARY NAMES gslerr + PATHS ${GSL_DIR}/lib + ENV LIB + DOC "gslerr library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) + +FIND_LIBRARY(GSL_INTERPOLATION_LIBRARY NAMES gslinterpolation + PATHS ${GSL_DIR}/lib + ENV LIB + DOC "gslinterpolation library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) + +FIND_LIBRARY(GSL_SYS_LIBRARY NAMES gslsys + PATHS ${GSL_DIR}/lib + ENV LIB + DOC "gslsys library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) + +IF (GSL_INCLUDE_DIR AND GSL_INTERPOLATION_LIBRARY AND GSL_ERROR_LIBRARY AND GSL_SYS_LIBRARY) + SET(GSL_FOUND TRUE) +ENDIF (GSL_INCLUDE_DIR AND GSL_INTERPOLATION_LIBRARY AND GSL_ERROR_LIBRARY AND GSL_SYS_LIBRARY) diff --git a/cmake/modules/FindGlib2.cmake b/cmake/modules/FindGlib2.cmake new file mode 100644 index 0000000..7204a9e --- /dev/null +++ b/cmake/modules/FindGlib2.cmake @@ -0,0 +1,53 @@ +if (NOT GLIB2_DIR) + set (GLIB2_DIR "" CACHE PATH "Directory containing glib-2 includes and libraries") +endif () + +FILE(TO_CMAKE_PATH "$ENV{GLIB2_DIR}" TRY1_DIR) +FILE(TO_CMAKE_PATH "${GLIB2_DIR}" TRY2_DIR) +FILE(GLOB GLIB2_DIR ${TRY1_DIR} ${TRY2_DIR}) + +FIND_PATH(GLIB_glib_2_INCLUDE_DIR glib.h + PATHS ${GLIB2_DIR}/include ${GLIB2_DIR}/include/glib-2.0 /usr/local/include/glib-2.0 /usr/include/glib-2.0 /opt/local/include/glib-2.0 + ENV INCLUDE DOC "Directory containing glib.h include file") +mark_as_advanced (GLIB_glib_2_INCLUDE_DIR) + +FIND_PATH(GLIB_glibconfig_2_INCLUDE_DIR glibconfig.h + PATHS ${GLIB2_DIR}/include ${GLIB2_DIR}/include/glib-2.0 ${GLIB2_DIR}/lib/include ${GLIB2_DIR}/lib/glib-2.0/include /usr/local/include/glib-2.0 /usr/include/glib-2.0 /usr/lib/glib-2.0/include /usr/local/lib/glib-2.0/include /opt/local/lib/glib-2.0/include + ENV INCLUDE DOC "Directory containing glibconfig.h include file") +mark_as_advanced (GLIB_glibconfig_2_INCLUDE_DIR) + +FIND_LIBRARY(GLIB_glib_2_LIBRARY NAMES glib-2.0 + PATHS ${GLIB2_DIR}/bin ${GLIB2_DIR}/win32/bin ${GLIB2_DIR}/lib ${GLIB2_DIR}/win32/lib /usr/local/lib /usr/lib /opt/local/lib + ENV LIB + DOC "glib library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) +mark_as_advanced (GLIB_glib_2_LIBRARY) + +FIND_LIBRARY(GLIB_gmodule_2_LIBRARY NAMES gmodule-2.0 + PATHS ${GLIB2_DIR}/bin ${GLIB2_DIR}/win32/bin ${GLIB2_DIR}/lib ${GLIB2_DIR}/win32/lib /usr/local/lib /usr/lib /opt/local/lib + ENV LIB + DOC "gmodule library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) +mark_as_advanced (GLIB_gmodule_2_LIBRARY) + +FIND_LIBRARY(GLIB_gobject_2_LIBRARY NAMES gobject-2.0 + PATHS ${GLIB2_DIR}/bin ${GLIB2_DIR}/win32/bin ${GLIB2_DIR}/lib ${GLIB2_DIR}/win32/lib /usr/local/lib /usr/lib /opt/local/lib + ENV LIB + DOC "gobject library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) +mark_as_advanced (GLIB_gobject_2_LIBRARY) + +FIND_LIBRARY(GLIB_gthread_2_LIBRARY NAMES gthread-2.0 + PATHS ${GLIB2_DIR}/bin ${GLIB2_DIR}/win32/bin ${GLIB2_DIR}/lib ${GLIB2_DIR}/win32/lib /usr/local/lib /usr/lib /opt/local/lib + ENV LIB + DOC "gthread library to link with" + NO_SYSTEM_ENVIRONMENT_PATH) +mark_as_advanced (GLIB_gthread_2_LIBRARY) + +IF (GLIB_glib_2_INCLUDE_DIR AND GLIB_glibconfig_2_INCLUDE_DIR AND GLIB_glib_2_LIBRARY AND GLIB_gmodule_2_LIBRARY AND GLIB_gobject_2_LIBRARY AND GLIB_gthread_2_LIBRARY) + SET(GLIB2_INCLUDE_DIR ${GLIB_glib_2_INCLUDE_DIR} ${GLIB_glibconfig_2_INCLUDE_DIR}) + list(REMOVE_DUPLICATES GLIB2_INCLUDE_DIR) + SET(GLIB2_LIBRARIES ${GLIB_glib_2_LIBRARY} ${GLIB_gmodule_2_LIBRARY} ${GLIB_gobject_2_LIBRARY} ${GLIB_gthread_2_LIBRARY}) + list(REMOVE_DUPLICATES GLIB2_LIBRARIES) + SET(GLIB2_FOUND TRUE) +ENDIF (GLIB_glib_2_INCLUDE_DIR AND GLIB_glibconfig_2_INCLUDE_DIR AND GLIB_glib_2_LIBRARY AND GLIB_gmodule_2_LIBRARY AND GLIB_gobject_2_LIBRARY AND GLIB_gthread_2_LIBRARY) diff --git a/cmake/modules/FindGstreamer.cmake b/cmake/modules/FindGstreamer.cmake new file mode 100644 index 0000000..07bcf37 --- /dev/null +++ b/cmake/modules/FindGstreamer.cmake @@ -0,0 +1,123 @@ +# - Try to find GStreamer +# Once done this will define +# +# GSTREAMER_FOUND - system has GStreamer +# GSTREAMER_INCLUDE_DIR - the GStreamer include directory +# GSTREAMER_LIBRARIES - the libraries needed to use GStreamer +# GSTREAMER_DEFINITIONS - Compiler switches required for using GStreamer + +# Copyright (c) 2006, Tim Beaulen +# Copyright (c) 2010, United States Government, Joshua M. Doe +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# TODO: Other versions --> GSTREAMER_X_Y_FOUND (Example: GSTREAMER_0_8_FOUND and GSTREAMER_0_10_FOUND etc) + +IF (GSTREAMER_INCLUDE_DIR AND GSTREAMER_LIBRARIES AND GSTREAMER_BASE_LIBRARY AND GSTREAMER_INTERFACE_LIBRARY) + # in cache already + SET(GStreamer_FIND_QUIETLY TRUE) +ELSE (GSTREAMER_INCLUDE_DIR AND GSTREAMER_LIBRARIES AND GSTREAMER_BASE_LIBRARY AND GSTREAMER_INTERFACE_LIBRARY) + SET(GStreamer_FIND_QUIETLY FALSE) +ENDIF (GSTREAMER_INCLUDE_DIR AND GSTREAMER_LIBRARIES AND GSTREAMER_BASE_LIBRARY AND GSTREAMER_INTERFACE_LIBRARY) + +SET (GSTREAMER_DIR ${GSTREAMER_DIR} CACHE PATH "Directory containing gstreamer") + +IF (NOT WIN32) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + FIND_PACKAGE(PkgConfig) + PKG_CHECK_MODULES(PC_GSTREAMER QUIET gstreamer-0.10) + #MESSAGE(STATUS "DEBUG: GStreamer include directory = ${GSTREAMER_INCLUDE_DIRS}") + #MESSAGE(STATUS "DEBUG: GStreamer link directory = ${GSTREAMER_LIBRARY_DIRS}") + #MESSAGE(STATUS "DEBUG: GStreamer CFlags = ${GSTREAMER_CFLAGS_OTHER}") + SET(GSTREAMER_DEFINITIONS ${PC_GSTREAMER_CFLAGS_OTHER}) +ELSE (NOT WIN32) + IF (NOT GSTREAMER_DIR) + SET (GSTREAMER_DIR "C:/gstreamer") + ENDIF (NOT GSTREAMER_DIR) +ENDIF (NOT WIN32) + +FIND_PATH(GSTREAMER_INCLUDE_DIR gst/gst.h + PATHS + ${GSTREAMER_DIR}/include/gstreamer-0.10 + ${PC_GSTREAMER_INCLUDEDIR} + ${PC_GSTREAMER_INCLUDE_DIRS} + #PATH_SUFFIXES gst + ) + +FIND_LIBRARY(GSTREAMER_LIBRARIES NAMES gstreamer-0.10 + PATHS + ${GSTREAMER_DIR}/lib + ${PC_GSTREAMER_LIBDIR} + ${PC_GSTREAMER_LIBRARY_DIRS} + ) + +FIND_LIBRARY(GSTREAMER_BASE_LIBRARY NAMES gstbase-0.10 + PATHS + ${GSTREAMER_DIR}/lib + ${PC_GSTREAMER_LIBDIR} + ${PC_GSTREAMER_LIBRARY_DIRS} + ) + +FIND_LIBRARY(GSTREAMER_CONTROLLER_LIBRARY NAMES gstcontroller-0.10 + PATHS + ${GSTREAMER_DIR}/lib + ${PC_GSTREAMER_LIBDIR} + ${PC_GSTREAMER_LIBRARY_DIRS} + ) + +FIND_LIBRARY(GSTREAMER_INTERFACE_LIBRARY NAMES gstinterfaces-0.10 + PATHS + ${GSTREAMER_DIR}/lib + ${PC_GSTREAMER_LIBDIR} + ${PC_GSTREAMER_LIBRARY_DIRS} + ) + +FIND_LIBRARY(GSTREAMER_VIDEO_LIBRARY NAMES gstvideo-0.10 + PATHS + ${GSTREAMER_DIR}/lib + ${PC_GSTREAMER_LIBDIR} + ${PC_GSTREAMER_LIBRARY_DIRS} + ) + +IF (GSTREAMER_INCLUDE_DIR) + #MESSAGE(STATUS "DEBUG: Found GStreamer include dir: ${GSTREAMER_INCLUDE_DIR}") +ELSE (GSTREAMER_INCLUDE_DIR) + MESSAGE(STATUS "GStreamer: WARNING: include dir not found") +ENDIF (GSTREAMER_INCLUDE_DIR) + +IF (GSTREAMER_LIBRARIES) + #MESSAGE(STATUS "DEBUG: Found GStreamer library: ${GSTREAMER_LIBRARIES}") +ELSE (GSTREAMER_LIBRARIES) + MESSAGE(STATUS "GStreamer: WARNING: library not found") +ENDIF (GSTREAMER_LIBRARIES) + +IF (GSTREAMER_BASE_LIBRARY) + #MESSAGE(STATUS "DEBUG: Found GStreamer base library: ${GSTREAMER_BASE_LIBRARY}") +ELSE (GSTREAMER_BASE_LIBRARY) + MESSAGE(STATUS "GStreamer: WARNING: base library not found") +ENDIF (GSTREAMER_BASE_LIBRARY) + +IF (GSTREAMER_CONTROLLER_LIBRARY) + #MESSAGE(STATUS "DEBUG: Found GStreamer controller library: ${GSTREAMER_CONTROLLER_LIBRARY}") +ELSE (GSTREAMER_CONTROLLER_LIBRARY) + MESSAGE(STATUS "GStreamer: WARNING: controller library not found") +ENDIF (GSTREAMER_CONTROLLER_LIBRARY) + +IF (GSTREAMER_INTERFACE_LIBRARY) + #MESSAGE(STATUS "DEBUG: Found GStreamer interface library: ${GSTREAMER_INTERFACE_LIBRARY}") +ELSE (GSTREAMER_INTERFACE_LIBRARY) + MESSAGE(STATUS "GStreamer: WARNING: interface library not found") +ENDIF (GSTREAMER_INTERFACE_LIBRARY) + +IF (GSTREAMER_VIDEO_LIBRARY) + #MESSAGE(STATUS "DEBUG: Found GStreamer video library: ${GSTREAMER_VIDEO_LIBRARY}") +ELSE (GSTREAMER_VIDEO_LIBRARY) + MESSAGE(STATUS "GStreamer: WARNING: video library not found") +ENDIF (GSTREAMER_VIDEO_LIBRARY) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GStreamer DEFAULT_MSG GSTREAMER_LIBRARIES GSTREAMER_INCLUDE_DIR GSTREAMER_BASE_LIBRARY GSTREAMER_CONTROLLER_LIBRARY GSTREAMER_INTERFACE_LIBRARY GSTREAMER_VIDEO_LIBRARY) + +MARK_AS_ADVANCED(GSTREAMER_INCLUDE_DIR GSTREAMER_LIBRARIES GSTREAMER_BASE_LIBRARY GSTREAMER_CONTROLLER_LIBRARY GSTREAMER_INTERFACE_LIBRARY GSTREAMER_VIDEO_LIBRARY) diff --git a/cmake/modules/FindLibIconv.cmake b/cmake/modules/FindLibIconv.cmake new file mode 100644 index 0000000..5206c01 --- /dev/null +++ b/cmake/modules/FindLibIconv.cmake @@ -0,0 +1,16 @@ +if (NOT LIBICONV_DIR) + set (LIBICONV_DIR "" CACHE PATH "Directory containing iconv.h") +endif () + +FILE(TO_CMAKE_PATH "$ENV{LIBICONV_DIR}" TRY1_DIR) +FILE(TO_CMAKE_PATH "${LIBICONV_DIR}" TRY2_DIR) +FILE(GLOB LIBICONV_DIR ${TRY1_DIR} ${TRY2_DIR}) + +FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h + PATHS ${LIBICONV_DIR}/include /usr/local/include /usr/include + ENV INCLUDE DOC "Directory containing iconv.h include file") +mark_as_advanced (LIBICONV_INCLUDE_DIR) + +IF (LIBICONV_INCLUDE_DIR) + SET(LIBICONV_FOUND TRUE) +ENDIF (LIBICONV_INCLUDE_DIR) diff --git a/cmake/modules/FindLibXml2.cmake b/cmake/modules/FindLibXml2.cmake new file mode 100644 index 0000000..c172566 --- /dev/null +++ b/cmake/modules/FindLibXml2.cmake @@ -0,0 +1,16 @@ +if (NOT LIBXML2_DIR) + set (LIBXML2_DIR "" CACHE PATH "Directory containing libxml") +endif () + +FILE(TO_CMAKE_PATH "$ENV{LIBXML2_DIR}" TRY1_DIR) +FILE(TO_CMAKE_PATH "${LIBXML2_DIR}" TRY2_DIR) +FILE(GLOB LIBXML2_DIR ${TRY1_DIR} ${TRY2_DIR}) + +FIND_PATH(LIBXML2_INCLUDE_DIR libxml/parser.h + PATHS ${LIBXML2_DIR}/include ${LIBXML2_DIR}/include/libxml2 /usr/local/include/libxml2 /usr/include/libxml2 + ENV INCLUDE DOC "Directory containing libxml/parser.h include file") +mark_as_advanced (LIBXML2_INCLUDE_DIR) + +IF (LIBXML2_INCLUDE_DIR) + SET(LIBXML2_FOUND TRUE) +ENDIF (LIBXML2_INCLUDE_DIR) diff --git a/gst/CMakeLists.txt b/gst/CMakeLists.txt new file mode 100644 index 0000000..ff24817 --- /dev/null +++ b/gst/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (cairovis) diff --git a/gst/cairovis/CMakeLists.txt b/gst/cairovis/CMakeLists.txt new file mode 100644 index 0000000..69f67fd --- /dev/null +++ b/gst/cairovis/CMakeLists.txt @@ -0,0 +1,41 @@ +add_definitions (-DHAVE_CONFIG_H) + +set (SOURCES + cairovis.c + cairovis_base.c + cairovis_histogram.c + cairovis_lineseries.c + cairovis_waterfall.c + colormap.c + colormap_data.c) + +set (HEADERS + cairovis_base.h + cairovis_histogram.h + cairovis_lineseries.h + cairovis_waterfall.h + colormap.h + colormap_data.h) + +include_directories(AFTER + ${CAIRO_INCLUDE_DIR} + ${GSL_INCLUDE_DIR} + . ) + +add_library (libgstcairovis MODULE + ${SOURCES} + ${HEADERS}) + +target_link_libraries (libgstcairovis + general ${GLIB2_LIBRARIES} + general ${GSTREAMER_LIBRARIES} + general ${GSTREAMER_BASE_LIBRARY} + general ${GSTREAMER_VIDEO_LIBRARY} + general ${CAIRO_LIBRARIES} + general ${GSL_INTERPOLATION_LIBRARY} + general ${GSL_ERR_LIBRARY} + general ${GSL_SYS_LIBRARY}) + +install (TARGETS libgstcairovis + LIBRARY DESTINATION lib/gstreamer-0.10) + \ No newline at end of file diff --git a/set_paths_and_run_cmake.bat b/set_paths_and_run_cmake.bat new file mode 100644 index 0000000..9620a83 --- /dev/null +++ b/set_paths_and_run_cmake.bat @@ -0,0 +1,21 @@ +rem ######################################################################## +set GSTREAMER_DIR=C:\gstreamer +set LIBXML2_DIR=%GSTREAMER_DIR% +set LIBICONV_DIR=%GSTREAMER_DIR% +set GLIB2_DIR=%GSTREAMER_DIR% +set CAIRO_DIR=%GSTREAMER_DIR% +set GSL_DIR=C:\Users\joshua.doe\Documents\Devel\gsl-1.8\dist + +rem Plugins will be installed under %CMAKE_PREFIX_PATH%\lib\gstreamer-0.10 +set CMAKE_PREFIX_PATH=C:\gstreamer + +rem cd mingw32 +rem del *ache* && cmake -G "MinGW Makefiles" .. + +rem cd vs9 +rem del *ache* && cmake -G "Visual Studio 9 2008" .. + +rem cmd +rem ######################################################################## + +cmake-gui \ No newline at end of file From 97076296927f94a54e36293c5838e0a082fe392f Mon Sep 17 00:00:00 2001 From: Josh Doe Date: Thu, 21 Apr 2011 17:11:35 -0400 Subject: [PATCH 2/2] Fixes to be compilable with MSVC9 MSVC doesn't fully support C99, including mixed declarations and definitions, struct initialization by name, and missing math defines and functions. This has not been tested on Linux. --- gst/cairovis/cairovis.c | 3 ++ gst/cairovis/cairovis_base.c | 37 ++++++++++--- gst/cairovis/cairovis_base.h | 8 +-- gst/cairovis/cairovis_histogram.c | 35 ++++++++---- gst/cairovis/cairovis_lineseries.c | 38 ++++++++----- gst/cairovis/cairovis_waterfall.c | 86 ++++++++++++++++++++---------- 6 files changed, 144 insertions(+), 63 deletions(-) diff --git a/gst/cairovis/cairovis.c b/gst/cairovis/cairovis.c index 4990a11..6e66be6 100644 --- a/gst/cairovis/cairovis.c +++ b/gst/cairovis/cairovis.c @@ -44,6 +44,9 @@ #include #include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* * ============================================================================ diff --git a/gst/cairovis/cairovis_base.c b/gst/cairovis/cairovis_base.c index 5088e93..77d9747 100644 --- a/gst/cairovis/cairovis_base.c +++ b/gst/cairovis/cairovis_base.c @@ -21,6 +21,12 @@ #include +#if defined(_MSC_VER) +__inline const int rint(float x){ + return (int)(x+0.5); +} +#define _USE_MATH_DEFINES +#endif /* _MSC_VER */ #include @@ -71,7 +77,7 @@ static void draw_minor_tick (cairo_t *cr, double x) } -void cairovis_draw_axis (cairo_t *restrict cr, const struct cairovis_axis_spec *restrict axis) +void cairovis_draw_axis (cairo_t * cr, const cairovis_axis_spec * axis) { cairo_text_extents_t extents; int ntick, nmintick, nmaxtick, nsubtick; @@ -326,6 +332,9 @@ void cairovis_draw_axes (CairoVisBase *element, cairo_t *cr, gint width, gint he cairo_text_extents_t text_extents; double padding, padded_width, padded_height; + cairovis_axis_spec xspec; + cairovis_axis_spec yspec; + gboolean xlog = (element->xscale == CAIROVIS_SCALE_LOG); gboolean ylog = (element->yscale == CAIROVIS_SCALE_LOG); @@ -389,8 +398,16 @@ void cairovis_draw_axes (CairoVisBase *element, cairo_t *cr, gint width, gint he cairo_translate (cr, padding, height - padding); /* Render x-axis tick marks */ - struct cairovis_axis_spec xspec = {element->xscale, CAIROVIS_SOUTH, padded_width, xmin, xmax}; - struct cairovis_axis_spec yspec = {element->yscale, CAIROVIS_WEST, padded_height, ymin, ymax}; + xspec.scale = element->xscale; + xspec.which_side = CAIROVIS_SOUTH; + xspec.device_max = padded_width; + xspec.data_min = xmin; + xspec.data_max = xmax; + yspec.scale = element->xscale; + yspec.which_side = CAIROVIS_WEST; + yspec.device_max = padded_height; + yspec.data_min = ymin; + yspec.data_max = ymax; cairovis_draw_axis(cr, &xspec); cairovis_draw_axis(cr, &yspec); @@ -700,11 +717,15 @@ GType cairovis_base_get_type(void) if (!type) { static const GTypeInfo info = { - .class_size = sizeof (CairoVisBaseClass), - .class_init = class_init, - .base_init = base_init, - .instance_size = sizeof (CairoVisBase), - .instance_init = instance_init, + sizeof (CairoVisBaseClass), + base_init, + NULL, + class_init, + NULL, + NULL, + sizeof (CairoVisBase), + NULL, + instance_init }; type = g_type_register_static (GST_TYPE_ELEMENT, "cairovis_base", &info, 0); } diff --git a/gst/cairovis/cairovis_base.h b/gst/cairovis/cairovis_base.h index 90c677e..7bf23df 100644 --- a/gst/cairovis/cairovis_base.h +++ b/gst/cairovis/cairovis_base.h @@ -56,14 +56,14 @@ enum cairovis_cardinal_direction }; -struct cairovis_axis_spec +typedef struct { enum cairovis_scale scale; enum cairovis_cardinal_direction which_side; double device_max; double data_min; double data_max; -}; +} cairovis_axis_spec; typedef struct @@ -90,8 +90,8 @@ typedef struct _CairoVisBase gboolean cairovis_base_negotiate_srcpad (CairoVisBase * element); GstFlowReturn cairovis_base_buffer_surface_alloc (CairoVisBase * element, GstBuffer ** buf, cairo_surface_t ** surf, gint * width, gint * height); -void cairovis_draw_axis (cairo_t * restrict cr, - const struct cairovis_axis_spec *restrict axis); +void cairovis_draw_axis (cairo_t * cr, + const cairovis_axis_spec * axis); void cairovis_draw_axes (CairoVisBase * element, cairo_t * cr, gint width, gint height); diff --git a/gst/cairovis/cairovis_histogram.c b/gst/cairovis/cairovis_histogram.c index 368b050..58a5373 100644 --- a/gst/cairovis/cairovis_histogram.c +++ b/gst/cairovis/cairovis_histogram.c @@ -21,6 +21,12 @@ #include +#if defined(_MSC_VER) +__inline const double log2( double n ) { return log( n ) / log( 2 ); } +__inline const int isfinite( double n) { return n != HUGE_VAL; } +#define INFINITY G_MAXDOUBLE +#endif /* _MSC_VER */ + GType cairovis_histogram_bins_get_type (void) @@ -55,7 +61,7 @@ increment_bin (CairoVisHistogram * element, double x, gchar value) element->total += value; if (isfinite (x) && x >= 0 && x < element->nbins) - element->bin_counts[(uint) floor (x)] += value; + element->bin_counts[(guint) floor (x)] += value; } @@ -93,6 +99,10 @@ chain (GstPad * pad, GstBuffer * inbuf) double *bin_heights, *bin_edges; guint i; double last_x; + guint available_bytes; + guint history_bytes; + gboolean xlog; + gboolean ylog; if (!element->bin_counts) { guint available_bytes = gst_adapter_available (element->adapter); @@ -113,8 +123,8 @@ chain (GstPad * pad, GstBuffer * inbuf) gst_adapter_push (element->adapter, inbuf); /* Remove oldest data from histogram */ - guint available_bytes = gst_adapter_available (element->adapter); - guint history_bytes = element->history * sizeof (double); + available_bytes = gst_adapter_available (element->adapter); + history_bytes = element->history * sizeof (double); if (available_bytes > history_bytes) { GstBuffer *buf = gst_adapter_take_buffer (element->adapter, @@ -123,8 +133,8 @@ chain (GstPad * pad, GstBuffer * inbuf) gst_buffer_unref (buf); } - gboolean xlog = base->xscale; - gboolean ylog = base->yscale; + xlog = base->xscale; + ylog = base->yscale; result = cairovis_base_buffer_surface_alloc (base, &outbuf, &surf, &width, @@ -461,11 +471,16 @@ cairovis_histogram_get_type (void) if (!type) { static const GTypeInfo info = { - .class_size = sizeof (CairoVisHistogramClass), - .class_init = class_init, - .base_init = base_init, - .instance_size = sizeof (CairoVisHistogram), - .instance_init = instance_init, + sizeof (CairoVisHistogramClass), + base_init, + NULL, + class_init, + NULL, + NULL, + sizeof (CairoVisHistogram), + 0, + instance_init, + NULL }; type = g_type_register_static (CAIROVIS_BASE_TYPE, "cairovis_histogram", &info, diff --git a/gst/cairovis/cairovis_lineseries.c b/gst/cairovis/cairovis_lineseries.c index 19e58e8..d37d1d3 100644 --- a/gst/cairovis/cairovis_lineseries.c +++ b/gst/cairovis/cairovis_lineseries.c @@ -21,6 +21,10 @@ #include +#if defined(_MSC_VER) +__inline const int isfinite( double n) { return n != HUGE_VAL; } +#define INFINITY G_MAXDOUBLE +#endif /* _MSC_VER */ static gboolean sink_setcaps (GstPad * pad, GstCaps * caps) @@ -47,6 +51,14 @@ chain (GstPad * pad, GstBuffer * inbuf) cairo_surface_t *surf; cairo_t *cr; + /* Determine number of samples, data pointer */ + const double *data = (const double *) GST_BUFFER_DATA (inbuf); + gulong nsamples = GST_BUFFER_SIZE (inbuf) / sizeof (double); + gint nchannels = element->nchannels; + gulong nsamples_per_channel = nsamples / nchannels; + gulong i; + gint channel; + gboolean xlog = base->xscale; gboolean ylog = base->yscale; @@ -59,14 +71,6 @@ chain (GstPad * pad, GstBuffer * inbuf) cr = cairo_create (surf); - /* Determine number of samples, data pointer */ - const double *data = (const double *) GST_BUFFER_DATA (inbuf); - gulong nsamples = GST_BUFFER_SIZE (inbuf) / sizeof (double); - gint nchannels = element->nchannels; - gulong nsamples_per_channel = nsamples / nchannels; - gulong i; - gint channel; - /* Determine x-axis limits */ if (base->xautoscale) { if (xlog) @@ -96,12 +100,13 @@ chain (GstPad * pad, GstBuffer * inbuf) gboolean was_finite = FALSE; for (i = 0; i < nsamples; i++) { + gboolean is_finite; double x = i, y = data[i * nchannels + channel]; if (xlog) x = log10 (x); if (ylog) y = log10 (y); - gboolean is_finite = isfinite (x) && isfinite (y); + is_finite = isfinite (x) && isfinite (y); if (!was_finite && is_finite) cairo_move_to (cr, x, y); else if (is_finite) @@ -219,11 +224,16 @@ cairovis_lineseries_get_type (void) if (!type) { static const GTypeInfo info = { - .class_size = sizeof (CairoVisLineSeriesClass), - .class_init = class_init, - .base_init = base_init, - .instance_size = sizeof (CairoVisLineSeries), - .instance_init = instance_init, + sizeof (CairoVisLineSeriesClass), + base_init, + NULL, + class_init, + NULL, + NULL, + sizeof (CairoVisLineSeries), + 0, + instance_init, + NULL }; type = g_type_register_static (CAIROVIS_BASE_TYPE, "cairovis_lineseries", diff --git a/gst/cairovis/cairovis_waterfall.c b/gst/cairovis/cairovis_waterfall.c index c3c162b..a97196e 100644 --- a/gst/cairovis/cairovis_waterfall.c +++ b/gst/cairovis/cairovis_waterfall.c @@ -21,6 +21,11 @@ #include +#if defined(_MSC_VER) +#define _USE_MATH_DEFINES +#define INFINITY G_MAXDOUBLE +#endif /* _MSC_VER */ + #include @@ -58,6 +63,11 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) guint i; gboolean zlog = (element->zscale == CAIROVIS_SCALE_LOG); gdouble zmin, zmax; + guint available_bytes; + guint stride_bytes; + guint available_samples; + gint fpsn, fpsd; + guint64 history_samples; if (base->xscale || base->yscale) { gst_buffer_unref (inbuf); @@ -89,17 +99,27 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) goto done; } - guint available_bytes = gst_adapter_available (element->adapter); - guint stride_bytes = sizeof (double) * element->nchannels; - guint available_samples = available_bytes / stride_bytes; - gint fpsn, fpsd; + available_bytes = gst_adapter_available (element->adapter); + stride_bytes = sizeof (double) * element->nchannels; + available_samples = available_bytes / stride_bytes; gst_video_parse_caps_framerate (GST_PAD_CAPS (base->srcpad), &fpsn, &fpsd); - guint64 history_samples = + history_samples = gst_util_uint64_scale_int_round (element->history, element->rate, GST_SECOND); /* FIXME: This doesn't really have to be an infinite loop. */ while (TRUE) { + guint64 desired_offset; + guint64 desired_offset_end; + guint64 desired_samples; + guint64 desired_bytes; + guint npixels; + gchar *nanos_str; + gchar *secs_str; + GstClockTime ts; + cairo_text_extents_t extents; + gchar *ts_str; + GST_INFO_OBJECT (element, "checking to see if we have enough data to draw frame %" G_GUINT64_FORMAT, element->frame_number); @@ -107,28 +127,29 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) fpsd); /* FIXME: check my timestamp math here; it's probably not perfect */ - guint64 desired_offset = + desired_offset = gst_util_uint64_scale_int_round (element->frame_number, fpsd * element->rate, fpsn); if (history_samples < desired_offset) desired_offset -= history_samples; else desired_offset = 0; - guint64 desired_offset_end = + desired_offset_end = gst_util_uint64_scale_int_round (element->frame_number, fpsd * element->rate, fpsn); - guint64 desired_samples = desired_offset_end - desired_offset; - guint64 desired_bytes = desired_samples * stride_bytes; + desired_samples = desired_offset_end - desired_offset; + desired_bytes = desired_samples * stride_bytes; GST_INFO_OBJECT (element, "we want offsets %" G_GUINT64_FORMAT " through %" G_GUINT64_FORMAT, desired_offset, desired_offset_end); if (element->last_offset_end < desired_offset) { + guint flush_bytes; guint flush_samples = desired_offset - element->last_offset_end; if (flush_samples > available_samples) flush_samples = available_samples; - guint flush_bytes = flush_samples * stride_bytes; + flush_bytes = flush_samples * stride_bytes; gst_adapter_flush (element->adapter, flush_bytes); available_samples -= flush_samples; available_bytes -= flush_bytes; @@ -172,7 +193,7 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) gst_util_uint64_scale_round (desired_offset_end, GST_SECOND, element->rate) + element->t0 - GST_BUFFER_TIMESTAMP (outbuf); - guint npixels = desired_samples * element->nchannels; + npixels = desired_samples * element->nchannels; if (desired_samples > 0) { double *orig_data = (double *) gst_adapter_peek (element->adapter, desired_bytes); @@ -223,35 +244,38 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) cairo_identity_matrix (cr); cairo_reset_clip (cr); /* Draw timestamp. */ - gchar *nanos_str = NULL; - gchar *secs_str = NULL; - GstClockTime ts = + nanos_str = NULL; + secs_str = NULL; + ts = GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf); for (i = 0; i < 3; ts /= 1000, i++) { gchar frag[4]; + gchar *new_str; g_snprintf (frag, sizeof (frag), "%03hu", (unsigned short) (ts % 1000)); - gchar *new_str = g_strjoin (" ", frag, nanos_str, NULL); + new_str = g_strjoin (" ", frag, nanos_str, NULL); g_free (nanos_str); nanos_str = new_str; } for (; ts >= 1000; ts /= 1000) { gchar frag[4]; + gchar *new_str; g_snprintf (frag, sizeof (frag), "%03hu", (unsigned short) (ts % 1000)); - gchar *new_str = g_strjoin (" ", frag, secs_str, NULL); + new_str = g_strjoin (" ", frag, secs_str, NULL); g_free (secs_str); secs_str = new_str; } if (ts > 0) { gchar frag[4]; + gchar *new_str; g_snprintf (frag, sizeof (frag), "%hu", (unsigned short) (ts % 1000)); - gchar *new_str = g_strjoin (" ", frag, secs_str, NULL); + new_str = g_strjoin (" ", frag, secs_str, NULL); g_free (secs_str); secs_str = new_str; } - gchar *ts_str = g_strdup_printf ("+ %s.%s", secs_str, nanos_str); + ts_str = g_strdup_printf ("+ %s.%s", secs_str, nanos_str); g_free (nanos_str); g_free (secs_str); - cairo_text_extents_t extents; + cairo_text_extents (cr, ts_str, &extents); cairo_move_to (cr, width - extents.width - 36, height - 18); cairo_show_text (cr, ts_str); @@ -260,10 +284,13 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) /* Draw pixels */ if (data) { - GST_INFO_OBJECT (element, "painting pixels for frame %" G_GUINT64_FORMAT, - element->frame_number); + cairo_surface_t *pixsurf; guint32 *pixdata = g_malloc (npixels * sizeof (guint32)); double invzspan = 1.0 / (zmax - zmin); + + GST_INFO_OBJECT (element, "painting pixels for frame %" G_GUINT64_FORMAT, + element->frame_number); + for (i = 0; i < npixels; i++) { double x = data[i]; if (x < zmin) @@ -274,7 +301,7 @@ sink_chain (GstPad * pad, GstBuffer * inbuf) x = (x - zmin) * invzspan; pixdata[i] = colormap_map (element->map, x); } - cairo_surface_t *pixsurf = + pixsurf = cairo_image_surface_create_for_data ((unsigned char *) pixdata, CAIRO_FORMAT_RGB24, element->nchannels, desired_samples, element->nchannels * 4); @@ -553,11 +580,16 @@ cairovis_waterfall_get_type (void) if (!type) { static const GTypeInfo info = { - .class_size = sizeof (CairoVisWaterfallClass), - .class_init = class_init, - .base_init = base_init, - .instance_size = sizeof (CairoVisWaterfall), - .instance_init = instance_init, + sizeof (CairoVisWaterfallClass), + base_init, + NULL, + class_init, + NULL, + NULL, + sizeof (CairoVisWaterfall), + 0, + instance_init, + NULL }; type = g_type_register_static (CAIROVIS_BASE_TYPE, "cairovis_waterfall", &info,