diff --git a/.gitignore b/.gitignore index bafcae5..a72cef6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,36 +2,10 @@ *.lo *.la *.a -/*.tar.xz -/*.md5sum .deps/ .libs/ .dirstamp -/Makefile -Makefile.in -/aclocal.m4 -/autom4te.cache -/build-aux/ -/dronecode-camera-manager.service -/config.h -/config.h.in -/config.log -/config.status -/configure -/include/mavlink -/libtool -/perf.data -/perf.data.old -/stamp-h1 +build -*~ -.*.swp -cscope.out -tags -/dcm -/test/test-camera-parameters -/test/test-custom-stream -/test/test-mavlink-protocol -/test/test-rtsp-udp-stream-discovery diff --git a/.gitmodules b/.gitmodules index 5b1c417..5cf4909 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "modules/mavlink"] path = modules/mavlink - url = https://github.com/mavlink/mavlink.git + url = https://github.com/mavlink/c_library_v2.git branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..78c55d0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.5) +project(CameraManager) +add_subdirectory(src) +add_subdirectory(test EXCLUDE_FROM_ALL) + diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 8c12f72..0000000 --- a/Makefile.am +++ /dev/null @@ -1,318 +0,0 @@ -DISTCLEAN_LOCAL_HOOKS = -EXTRA_DIST = -CLEANFILES = $(BUILT_FILES) -noinst_LTLIBRARIES = -bin_PROGRAMS = -noinst_PROGRAMS = -noinst_SCRIPTS = -BUILT_FILES = -ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -AM_MAKEFLAGS = --no-print-directory - -GCC_COLORS ?= 'yes' -export GCC_COLORS - -BUILT_SOURCES = -test_deps = - -clean-local: - rm -rf $(top_builddir)/include/mavlink - rm -rf $(EXTRA_PROGRAMS) - -#if SYSTEMD -systemdsystemunitdir = @SYSTEMD_SYSTEMUNITDIR@ -systemdsystemunit_DATA = dronecode-camera-manager.service -#endif - - -AM_CPPFLAGS = \ - -include $(abs_top_builddir)/config.h \ - -DSYSCONFDIR=\""$(sysconfdir)"\" - -AM_CFLAGS = \ - -pipe \ - -Wall \ - -W \ - -Wextra \ - -Wno-inline \ - -Wundef \ - -Wformat=2 \ - -Wlogical-op \ - -Wsign-compare \ - -Wformat-security \ - -Wmissing-include-dirs \ - -Wformat-nonliteral \ - -Wold-style-definition \ - -Wpointer-arith \ - -Winit-self \ - -Wdeclaration-after-statement \ - -Wfloat-equal \ - -Wmissing-prototypes \ - -Wstrict-prototypes \ - -Wredundant-decls \ - -Wmissing-declarations \ - -Wmissing-noreturn \ - -Wshadow \ - -Wendif-labels \ - -Wstrict-aliasing=3 \ - -Wwrite-strings \ - -Wno-long-long \ - -Wno-overlength-strings \ - -Wno-unused-parameter \ - -Wno-missing-field-initializers \ - -Wno-unused-result \ - -Wnested-externs \ - -Wchar-subscripts \ - -Wtype-limits \ - -Wuninitialized \ - -fno-common \ - -fdiagnostics-show-option \ - -fvisibility=hidden \ - -ffunction-sections \ - -fdata-sections \ - ${GST_CFLAGS} - -AM_CXXFLAGS = \ - -I$(top_builddir)/src \ - -I$(srcdir)/ \ - -pipe \ - -Wall \ - -W \ - -Wextra \ - -Wno-inline \ - -Wundef \ - -Wformat=2 \ - -Wlogical-op \ - -Wsign-compare \ - -Wformat-security \ - -Wmissing-include-dirs \ - -Wformat-nonliteral \ - -Wpointer-arith \ - -Winit-self \ - -Wfloat-equal \ - -Wredundant-decls \ - -Wmissing-declarations \ - -Wmissing-noreturn \ - -Wshadow \ - -Wendif-labels \ - -Wstrict-aliasing=3 \ - -Wwrite-strings \ - -Wno-long-long \ - -Wno-overlength-strings \ - -Wno-unused-parameter \ - -Wno-missing-field-initializers \ - -Wno-unused-result \ - -Wchar-subscripts \ - -Wtype-limits \ - -Wuninitialized \ - -fno-common \ - -fdiagnostics-show-option \ - -fvisibility=hidden \ - -ffunction-sections \ - -fdata-sections \ - ${GST_CFLAGS} - -AM_LDFLAGS = \ - -Wl,--as-needed \ - -Wl,--no-undefined \ - -Wl,--gc-sections - -BASE_FILES = \ - src/conf_file.cpp \ - src/conf_file.h \ - src/glib_mainloop.cpp \ - src/glib_mainloop.h \ - src/log.cpp \ - src/log.h \ - src/macro.h \ - src/mainloop.cpp \ - src/mainloop.h \ - src/pollable.cpp \ - src/pollable.h \ - src/socket.cpp \ - src/socket.h \ - src/util.c \ - src/util.h \ - src/CameraParameters.cpp \ - src/CameraParameters.h \ - src/CameraComponent.cpp \ - src/CameraComponent.h \ - src/CameraServer.cpp \ - src/CameraServer.h \ - src/CameraDevice.h \ - src/ImageCapture.h \ - src/ImageCaptureGst.h \ - src/ImageCaptureGst.cpp \ - src/VideoStream.h \ - src/VideoStreamUdp.h \ - src/VideoStreamUdp.cpp \ - src/VideoStreamRtsp.h \ - src/VideoStreamRtsp.cpp \ - src/VideoCapture.h \ - src/VideoCaptureGst.h \ - src/VideoCaptureGst.cpp \ - src/PluginManager.h \ - src/PluginManager.cpp \ - src/PluginBase.h \ - src/v4l2_interface.cpp \ - src/v4l2_interface.h \ - plugins/V4l2Camera/PluginV4l2.h\ - plugins/V4l2Camera/PluginV4l2.cpp \ - plugins/V4l2Camera/CameraDeviceV4l2.cpp \ - plugins/V4l2Camera/CameraDeviceV4l2.h - -if ENABLE_REALSENSE -BASE_FILES += \ - plugins/RealSenseCamera/PluginRealSense.h \ - plugins/RealSenseCamera/PluginRealSense.cpp \ - plugins/RealSenseCamera/CameraDeviceRealSense.h \ - plugins/RealSenseCamera/CameraDeviceRealSense.cpp -endif - -if ENABLE_AERO -BASE_FILES += \ - plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h \ - plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp \ - plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.h \ - plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.cpp -endif - -if ENABLE_CUSTOM -BASE_FILES += \ - plugins/CustomCamera/PluginCustom.h \ - plugins/CustomCamera/PluginCustom.cpp \ - plugins/CustomCamera/CameraDeviceCustom.h \ - plugins/CustomCamera/CameraDeviceCustom.cpp -endif - - -bin_PROGRAMS += dcm - -SED_PROCESS = $(AM_V_GEN) $(MKDIR_P) $(dir $@) && \ - $(SED) -e 's,@bindir\@,$(bindir),g' \ - < $< > $@ - -%.service: %.service.in Makefile - $(SED_PROCESS) - - -dcm_SOURCES = \ - ${BASE_FILES} \ - src/main.cpp - -dcm_LDADD = $(GLIB_LIBS) $(GST_LIBS) $(GZB_LIBS) - -CLEANFILES += dronecode-camera-manager.service - -#Samples -EXTRA_PROGRAMS = test/test-custom-stream - -test_test_custom_stream_LDADD = ${dcm_LDADD} - -test_test_custom_stream_SOURCES = \ - $(BASE_FILES) \ - src/main.cpp \ - plugins/CustomCamera/PluginCustom.cpp \ - plugins/CustomCamera/PluginCustom.h \ - plugins/CustomCamera/CameraDeviceCustom.cpp \ - plugins/CustomCamera/CameraDeviceCustom.h - -if ENABLE_AVAHI -EXTRA_PROGRAMS += test/test-rtsp-udp-stream-discovery -BASE_FILES += \ - src/avahi_publisher.cpp \ - src/avahi_publisher.h - -AM_CXXFLAGS += ${AVAHI_CFLAGS} -AM_CXXFLAGS += ${AVAHI_CFLAGS} -dcm_LDADD += $(AVAHI_LIBS) - -test_test_rtsp_udp_stream_discovery_SOURCES = \ - test/test_rtsp_udp_stream_discovery.cpp \ - src/log.cpp \ - src/log.h \ - src/glib_mainloop.cpp \ - src/glib_mainloop.h \ - src/mainloop.cpp \ - src/mainloop.h - -test_test_rtsp_udp_stream_discovery_LDADD = $(GLIB_LIBS) $(AVAHI_LIBS) -endif - -if ENABLE_MAVLINK - -EXTRA_PROGRAMS += test/test-camera-parameters - -test_test_camera_parameters_SOURCES = \ - src/CameraParameters.cpp \ - src/CameraParameters.h \ - test/test_camera_parameters.cpp \ - src/log.cpp \ - src/log.h \ - src/util.c \ - src/util.h - -test_test_camera_parameters_LDADD = $(GLIB_LIBS) - -EXTRA_PROGRAMS += test/test-mavlink-protocol - -BUILT_SOURCES += include/mavlink/ardupilotmega/mavlink.h -include/mavlink/ardupilotmega/mavlink.h: modules/mavlink/pymavlink/tools/mavgen.py modules/mavlink/message_definitions/v1.0/ardupilotmega.xml - $(AM_V_GEN)$(PYTHON) $(srcdir)/modules/mavlink/pymavlink/tools/mavgen.py \ - -o include/mavlink \ - --lang C \ - --wire-protocol 2.0 \ - $(srcdir)/modules/mavlink/message_definitions/v1.0/ardupilotmega.xml - -AM_CPPFLAGS += \ - -I$(abs_top_builddir)/include/mavlink \ - -I$(abs_top_builddir)/include/mavlink/ardupilotmega - -BASE_FILES += \ - src/mavlink_server.cpp \ - src/mavlink_server.h - -test_test_mavlink_protocol_SOURCES = \ - test/test_mavlink_protocol.cpp \ - src/log.cpp \ - src/log.h \ - src/glib_mainloop.cpp \ - src/glib_mainloop.h \ - src/mainloop.cpp \ - src/mainloop.h \ - src/pollable.cpp \ - src/pollable.h \ - src/socket.cpp \ - src/socket.h \ - src/util.c \ - src/util.h - -test_test_mavlink_protocol_LDADD = $(GLIB_LIBS) -if ENABLE_AVAHI -test_test_mavlink_protocol_LDADD += $(AVAHI_LIBS) -endif - -test_deps = test_test_mavlink_protocol_LDADD -endif - -if ENABLE_GAZEBO - -AM_CXXFLAGS += \ - ${GZB_CFLAGS} - -BASE_FILES += \ - plugins/GazeboCamera/PluginGazebo.h \ - plugins/GazeboCamera/PluginGazebo.cpp \ - plugins/GazeboCamera/CameraDeviceGazebo.h \ - plugins/GazeboCamera/CameraDeviceGazebo.cpp -endif - -.PHONY: test -test: $(test_deps) - $(MAKE) $(EXTRA_PROGRAMS) - -# ------------------------------------------------------------------------------ -# coverity -# ------------------------------------------------------------------------------ - -#TODO diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index fd46c46..0000000 --- a/autogen.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh - -set -e - -oldpwd=$(pwd) -topdir=$(dirname $0) -cd $topdir - -autoreconf --force --install --symlink - -libdir() { - echo $(cd "$1/$(gcc -print-multi-os-directory)"; pwd) -} - -args="\ ---sysconfdir=/etc \ ---localstatedir=/var \ ---libdir=$(libdir /usr/lib) \ -" - -if [ -f "$topdir/.config.args" ]; then - args="$args $(cat $topdir/.config.args)" -fi - -if [ ! -L /bin ]; then - args="$args \ - --with-rootprefix= \ - --with-rootlibdir=$(libdir /lib) \ - " -fi - -cd $oldpwd - -if [ $# -ge 1 ]; then - cmd=$1 - shift -fi - -args="$args $@" - -if [ "$cmd" = "c" ]; then - $topdir/configure CFLAGS='-g -O2' CXXFLAGS='-g -O2' $args - make clean -elif [ "$cmd" = "g" ]; then - $topdir/configure CFLAGS='-g -Og' CXXFLAGS='-g -O2' $args - make clean -elif [ "$cmd" = "l" ]; then - $topdir/configure CC=clang CXX=clang++ CFLAGS='-g -O2' CXXFLAGS='-g -O2' $args - make clean -elif [ "$cmd" = "a" ]; then - $topdir/configure CFLAGS='-g -O2 -Wsuggest-attribute=pure -Wsuggest-attribute=const' CXXFLAGS='-g -O2 -Wsuggest-attribute=pure -Wsuggest-attribute=const' $args - make clean -elif [ "$cmd" = "s" ]; then - scan-build $topdir/configure CFLAGS='-g -O0 -std=gnu11' CXXFLAGS='-g -O0 -std=gnu++11' $args - scan-build make -else - echo - echo "----------------------------------------------------------------" - echo "Initialized build system. For a common configuration please run:" - echo "----------------------------------------------------------------" - echo - echo "$topdir/configure CFLAGS='-g -O2' CXXFLAGS='-g -O2' $args" - echo -fi diff --git a/cmake/FindAvahi.cmake b/cmake/FindAvahi.cmake new file mode 100644 index 0000000..02a19fd --- /dev/null +++ b/cmake/FindAvahi.cmake @@ -0,0 +1,125 @@ +# Copyright (c) 2015 Damien Buhl (alias daminetreg) +# All rights reserved. +# https://github.com/ruslo/hunter + +# Try to find Avahi client and libdns_sd_compat library. +# It can be used as : +# +# find_package(Avahi REQUIRED) +# target_link_libraries(program Avahi::client Avahi::compat_libdns_sd) +# + +set(Avahi_FOUND OFF) +set(Avahi_COMMON_FOUND OFF) +set(Avahi_CLIENT_FOUND OFF) +set(Avahi_GLIB_FOUND OFF) +set(Avahi_COMPAT_LIBDNS_SD_FOUND OFF) + +# avahi-common & avahi-client +find_library(Avahi_COMMON_LIBRARY NAMES avahi-common) +find_library(Avahi_CLIENT_LIBRARY NAMES avahi-client) +find_path(Avahi_CLIENT_INCLUDE_DIRS avahi-client/publish.h) + +if (Avahi_COMMON_LIBRARY AND Avahi_CLIENT_LIBRARY AND Avahi_CLIENT_INCLUDE_DIRS) + set(Avahi_FOUND ON) + set(Avahi_COMMON_FOUND ON) + set(Avahi_CLIENT_FOUND ON) + + if (NOT TARGET "Avahi::common") + add_library("Avahi::common" UNKNOWN IMPORTED) + set_target_properties("Avahi::common" + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Avahi_CLIENT_INCLUDE_DIRS}" + IMPORTED_LOCATION "${Avahi_COMMON_LIBRARY}" + ) + + endif() + + if(NOT TARGET "Avahi::client") + add_library("Avahi::client" UNKNOWN IMPORTED) + set_target_properties("Avahi::client" + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Avahi_CLIENT_INCLUDE_DIRS}" + IMPORTED_LOCATION "${Avahi_CLIENT_LIBRARY}" + INTERFACE_LINK_LIBRARIES "Avahi::common" + ) + get_filename_component(AVAHI_LIB_DIR "${Avahi_COMMON_LIBRARY}" DIRECTORY CACHE) + + endif() + +endif() + +# avahi-glib +find_library(Avahi_GLIB_LIBRARY NAMES avahi-glib) + +if (Avahi_GLIB_LIBRARY) + set(Avahi_GLIB_FOUND ON) + + if (NOT TARGET "Avahi::glib") + add_library("Avahi::glib" UNKNOWN IMPORTED) + set_target_properties("Avahi::glib" + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Avahi_GLIB_INCLUDE_DIRS}" + IMPORTED_LOCATION "${Avahi_GLIB_LIBRARY}" + ) + + endif() + +endif() + +# avahi-compat-libdns_sd +find_library(Avahi_COMPAT_LIBDNS_SD_LIBRARY NAMES dns_sd) +find_path(Avahi_COMPAT_LIBDNS_SD_INCLUDE_DIRS avahi-compat-libdns_sd/dns_sd.h) + +if (Avahi_COMPAT_LIBDNS_SD_LIBRARY) + set(Avahi_COMPAT_LIBDNS_SD_FOUND ON) + + if(NOT TARGET "Avahi::compat_libdns_sd") + add_library("Avahi::compat_libdns_sd" UNKNOWN IMPORTED) + set_target_properties("Avahi::compat_libdns_sd" + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${Avahi_COMPAT_LIBDNS_SD_INCLUDE_DIRS}" + IMPORTED_LOCATION "${Avahi_COMPAT_LIBDNS_SD_LIBRARY}" + INTERFACE_LINK_LIBRARIES "Avahi::client" + INTERFACE_LINK_LIBRARIES "Avahi::common" + ) + + endif() + +endif() + +set(_Avahi_MISSING_COMPONENTS "") +foreach(COMPONENT ${Avahi_FIND_COMPONENTS}) + string(TOUPPER ${COMPONENT} COMPONENT) + + if(NOT Avahi_${COMPONENT}_FOUND) + string(TOLOWER ${COMPONENT} COMPONENT) + list(APPEND _Avahi_MISSING_COMPONENTS ${COMPONENT}) + endif() +endforeach() + +if (_Avahi_MISSING_COMPONENTS) + set(Avahi_FOUND OFF) + + set(Avahi_ERROR_REASON + "${Avahi_ERROR_REASON}\nCould not find the following") + set(Avahi_ERROR_REASON + "${Avahi_ERROR_REASON} Avahi libraries:\n") + foreach(COMPONENT ${_Avahi_MISSING_COMPONENTS}) + set(Avahi_ERROR_REASON + "${Avahi_ERROR_REASON} ${COMPONENT}\n") + endforeach() + + if (Avahi_FIND_REQUIRED) + message(SEND_ERROR "Unable to find the requested Avahi libraries.\n${Avahi_ERROR_REASON}") + else() + message(STATUS "Unable to find the requested but not required Avahi libraries.\n${Avahi_ERROR_REASON}") + endif() + +endif() + + +if(Avahi_FOUND) + set(Avahi_LIBRARIES ${Avahi_COMMON_LIBRARY} ${Avahi_CLIENT_LIBRARY} ${Avahi_COMPAT_LIBDNS_SD_LIBRARY}) + set(Avahi_INCLUDE_DIRS ${Avahi_CLIENT_INCLUDE_DIRS} ${Avahi_COMPAT_LIBDNS_SD_INCLUDE_DIRS}) +endif() diff --git a/cmake/FindRealSense.cmake b/cmake/FindRealSense.cmake new file mode 100644 index 0000000..7f238ba --- /dev/null +++ b/cmake/FindRealSense.cmake @@ -0,0 +1,77 @@ +# - Find librealsense (https://github.com/IntelRealSense/librealsense) +# +# RealSense_ROOT_DIR environment variable can be set to find the library. +# +# It sets the following variables: +# RealSense_FOUND - Set to false, or undefined, if RealSense isn't found. +# RealSenseSlam_FOUND - Set to false, or undefined, if RealSense slam module isn't found. +# RealSense_INCLUDE_DIRS - The RealSense include directory. +# RealSense_LIBRARIES - The RealSense library to link against. + +# Use find_package( RealSense COMPONENTS slam ) to search for realsense slam library +if( RealSense_FIND_COMPONENTS ) + foreach( component ${RealSense_FIND_COMPONENTS} ) + string( TOUPPER ${component} _COMPONENT ) + set( REALSENSE_USE_${_COMPONENT} 1 ) + endforeach() +endif() + +#RealSense library +find_path(RealSense_INCLUDE_DIRS NAMES librealsense/rs.hpp PATHS $ENV{RealSense_ROOT_DIR}/include) +if(CMAKE_CL_64) +find_library(RealSense_LIBRARY NAMES realsense PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/x64) +else() +find_library(RealSense_LIBRARY NAMES realsense PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/Win32) +endif() + +IF (RealSense_INCLUDE_DIRS AND RealSense_LIBRARY) + SET(RealSense_FOUND TRUE) +ENDIF (RealSense_INCLUDE_DIRS AND RealSense_LIBRARY) + +#SLAM +if(REALSENSE_USE_SLAM) + find_path(RealSenseSlam_INCLUDE_DIRS NAMES librealsense/slam/slam.h PATHS $ENV{RealSense_ROOT_DIR}/include) + if(CMAKE_CL_64) + find_library(RealSenseSlam_LIBRARY NAMES realsense_slam PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/x64) + find_library(RealSenseImage_LIBRARY NAMES realsense_image PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/x64) + find_library(RealSenseSP_Core_LIBRARY NAMES SP_Core PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/x64) + find_library(RealSenseTracker_LIBRARY NAMES tracker PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/x64) + else() + find_library(RealSenseSlam_LIBRARY NAMES realsense_slam PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/Win32) + find_library(RealSenseImage_LIBRARY NAMES realsense_image PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/Win32) + find_library(RealSenseSP_Core_LIBRARY NAMES SP_Core PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/Win32) + find_library(RealSenseTracker_LIBRARY NAMES tracker PATHS $ENV{RealSense_ROOT_DIR}/lib $ENV{RealSense_ROOT_DIR}/bin $ENV{RealSense_ROOT_DIR}/bin/Win32) + endif() +else() + set(RealSenseSlam_INCLUDE_DIRS "") +endif() + +IF (RealSense_FOUND) + + IF (RealSenseSlam_INCLUDE_DIRS AND RealSenseSlam_LIBRARY AND RealSenseImage_LIBRARY AND RealSenseSP_Core_LIBRARY AND RealSenseTracker_LIBRARY) + SET(RealSenseSlam_FOUND TRUE) + ENDIF (RealSenseSlam_INCLUDE_DIRS AND RealSenseSlam_LIBRARY AND RealSenseImage_LIBRARY AND RealSenseSP_Core_LIBRARY AND RealSenseTracker_LIBRARY) + + SET(RealSense_LIBRARIES ${RealSense_LIBRARY}) + IF (RealSenseSlam_FOUND) + IF (RealSenseSlam_INCLUDE_DIRS AND RealSenseSlam_LIBRARY AND RealSenseImage_LIBRARY AND RealSenseSP_Core_LIBRARY AND RealSenseTracker_LIBRARY) + SET(RealSenseSlam_FOUND TRUE) + ENDIF (RealSenseSlam_INCLUDE_DIRS AND RealSenseSlam_LIBRARY AND RealSenseImage_LIBRARY AND RealSenseSP_Core_LIBRARY AND RealSenseTracker_LIBRARY) + SET(RealSense_LIBRARIES + ${RealSense_LIBRARIES} + ${RealSenseSlam_LIBRARY} + ${RealSenseImage_LIBRARY} + ${RealSenseSP_Core_LIBRARY} + ${RealSenseTracker_LIBRARY}) + ENDIF(RealSenseSlam_FOUND) + + # show which RealSense was found only if not quiet + IF (NOT RealSense_FIND_QUIETLY) + MESSAGE(STATUS "Found RealSense: ${RealSense_LIBRARIES}") + ENDIF (NOT RealSense_FIND_QUIETLY) +ELSE (RealSense_FOUND) + # fatal error if RealSense is required but not found + IF (RealSense_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find RealSense (librealsense)") + ENDIF (RealSense_FIND_REQUIRED) +ENDIF (RealSense_FOUND) diff --git a/cmake/FindRealSense2.cmake b/cmake/FindRealSense2.cmake new file mode 100644 index 0000000..dc61f79 --- /dev/null +++ b/cmake/FindRealSense2.cmake @@ -0,0 +1,40 @@ +# - Find librealsense (https://github.com/IntelRealSense/librealsense) +# +# RealSense2_ROOT_DIR environment variable can be set to find the library. +# +# It sets the following variables: +# RealSense2_FOUND - Set to false, or undefined, if RealSense2 isn't found. +# RealSense2_INCLUDE_DIRS - The RealSense2 include directory. +# RealSense2_LIBRARIES - The RealSense2 library to link against. + +#RealSense library + +find_path(RealSense2_INCLUDE_DIRS NAMES librealsense2/rs.hpp PATHS $ENV{RealSense2_ROOT_DIR}/include) +if(CMAKE_CL_64) +find_library(RealSense2_LIBRARY NAMES realsense2 PATHS $ENV{RealSense2_ROOT_DIR}/lib $ENV{RealSense2_ROOT_DIR}/lib/x64 $ENV{RealSense2_ROOT_DIR}/bin $ENV{RealSense2_ROOT_DIR}/bin/x64) +else() +find_library(RealSense2_LIBRARY NAMES realsense2 PATHS $ENV{RealSense2_ROOT_DIR}/lib $ENV{RealSense2_ROOT_DIR}/lib/x86 $ENV{RealSense2_ROOT_DIR}/bin $ENV{RealSense2_ROOT_DIR}/bin/x86) +endif() + +IF (RealSense2_INCLUDE_DIRS AND RealSense2_LIBRARY) + SET(RealSense2_FOUND TRUE) +ENDIF (RealSense2_INCLUDE_DIRS AND RealSense2_LIBRARY) + +IF (RealSense2_FOUND) + SET(RealSense2_LIBRARIES ${RealSense2_LIBRARY}) + + # Compatibility with linux names + SET(realsense2_LIBRARIES ${RealSense2_LIBRARIES}) + SET(realsense2_INCLUDE_DIRS ${RealSense2_INCLUDE_DIRS}) + SET(realsense2_FOUND ${RealSense2_FOUND}) + + # show which RealSense was found only if not quiet + IF (NOT RealSense2_FIND_QUIETLY) + MESSAGE(STATUS "Found RealSense: ${RealSense2_LIBRARIES}") + ENDIF (NOT RealSense2_FIND_QUIETLY) +ELSE (RealSense2_FOUND) + # fatal error if RealSense is required but not found + IF (RealSense2_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find RealSense2 (librealsense2)") + ENDIF (RealSense2_FIND_REQUIRED) +ENDIF (RealSense2_FOUND) diff --git a/configure.ac b/configure.ac deleted file mode 100644 index abec51b..0000000 --- a/configure.ac +++ /dev/null @@ -1,203 +0,0 @@ -AC_PREREQ(2.64) -AC_INIT([dronecode-camera-manager], - [1], - [], - [dronecode-camera-manager], - []) - -PKG_CHECK_MODULES(GLIB, [glib-2.0]) -PKG_CHECK_MODULES(GST, [gstreamer-rtsp-1.0, gstreamer-1.0, gstreamer-rtsp-server-1.0 gstreamer-app-1.0]) - -AC_CONFIG_SRCDIR([src/main.cpp]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_HEADERS(config.h) -AC_CONFIG_AUX_DIR([build-aux]) -AC_ARG_ENABLE([realsense], AS_HELP_STRING([--enable-realsense], [Enable Realsense Support]), - [ - AC_SEARCH_LIBS([rs_create_context], [realsense], - [ - enable_realsense=yes - AM_CONDITIONAL([ENABLE_REALSENSE], true) - ], - [ - AC_MSG_ERROR([librealsense not installed, cannot enable realsense support]) - enable_realsense=no - AM_CONDITIONAL([ENABLE_REALSENSE], false) - ]) - ], - [ - enable_realsense=no - AM_CONDITIONAL([ENABLE_REALSENSE], false) - ]) -AC_ARG_ENABLE([aero], AS_HELP_STRING([--enable-aero], [Include streams specific for Intel Aero drone]), - [ - enable_aero=yes - AM_CONDITIONAL([ENABLE_AERO], true) - ], - [ - enable_aero=no - AM_CONDITIONAL([ENABLE_AERO], false) - ]) - -AC_ARG_ENABLE([custom], AS_HELP_STRING([--enable-custom], [Include custom camera device]), - [ - enable_custom=yes - AM_CONDITIONAL([ENABLE_CUSTOM], true) - ], - [ - enable_custom=no - AM_CONDITIONAL([ENABLE_CUSTOM], false) - ]) - -AC_ARG_ENABLE([mavlink], - AS_HELP_STRING([--enable-mavlink], [Enable MAVLink advertisement]), - [ - enable_mavlink=yes - AM_CONDITIONAL([ENABLE_MAVLINK], true) - AC_DEFINE(ENABLE_MAVLINK, 1, [Enable MAVLink advertisement]) - ], - [ - enable_mavlink=no - AM_CONDITIONAL([ENABLE_MAVLINK], false) - ]) - -AC_ARG_ENABLE([avahi], - AS_HELP_STRING([--enable-avahi], [Enable avahi advertisement]), - [ - PKG_CHECK_MODULES(AVAHI, [avahi-client, avahi-core, avahi-glib]) - enable_avahi=yes - AM_CONDITIONAL([ENABLE_AVAHI], true) - AC_DEFINE(ENABLE_AVAHI, 1, [Enable avahi advertisement]) - ], - [ - enable_avahi=no - AM_CONDITIONAL([ENABLE_AVAHI], false) - ]) - - -AC_ARG_ENABLE([gazebo], - AS_HELP_STRING([--enable-gazebo], [Enable Gazebo Simulator Mode]), - [ - PKG_CHECK_MODULES(GZB, [gazebo]) - enable_gazebo=yes - AM_CONDITIONAL([ENABLE_GAZEBO], true) - AC_DEFINE(ENABLE_GAZEBO, 1, [Enable Gazebo Simulator Mode]) - ], - [ - enable_gazebo=no - AM_CONDITIONAL([ENABLE_GAZEBO], false) - ]) - - -AC_USE_SYSTEM_EXTENSIONS -AC_SYS_LARGEFILE -AC_PREFIX_DEFAULT([/usr]) -PKG_PROG_PKG_CONFIG -AM_MAINTAINER_MODE([enable]) -AM_INIT_AUTOMAKE([check-news foreign 1.11 silent-rules tar-pax no-dist-gzip dist-xz subdir-objects color-tests parallel-tests]) -AM_SILENT_RULES([yes]) - -##################################################################### -# Program checks and configurations -##################################################################### - -AC_PROG_CC_C99 -AX_CXX_COMPILE_STDCXX([11], [ext], [mandatory]) -AM_PATH_PYTHON([2.7]) - -##################################################################### - -LT_INIT([disable-static pic-only]) - -##################################################################### -# Function and structure checks -##################################################################### - -AC_MSG_CHECKING([whether _Static_assert() is supported]) -AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[_Static_assert(1, "Test");]])], - [AC_DEFINE([HAVE_STATIC_ASSERT], [1], [Define if _Static_assert() is available]) - AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no])]) - -AC_MSG_CHECKING([whether _Noreturn is supported]) -AC_COMPILE_IFELSE( - [AC_LANG_SOURCE([[_Noreturn int foo(void) { exit(0); }]])], - [AC_DEFINE([HAVE_NORETURN], [1], [Define if _Noreturn is available]) - AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no])]) - - -##################################################################### -# --with- -##################################################################### - -AC_ARG_WITH([rootlibdir], - AS_HELP_STRING([--with-rootlibdir=DIR], [rootfs directory to install shared libraries]), - [], [with_rootlibdir=$libdir]) -AC_ARG_WITH([systemdsystemunitdir], - AC_HELP_STRING([--with-systemdsystemunitdir=DIR], - [path to systemd system unit directory]), - [path_systemunitdir=${withval}]) -if (test "${enable_systemd}" != "no" && test -z "${path_systemunitdir}"); then - AC_MSG_CHECKING([systemd system unit dir]) - path_systemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`" - if (test -z "${path_systemunitdir}"); then - AC_MSG_ERROR([systemd system unit directory is required]) - fi - AC_MSG_RESULT([${path_systemunitdir}]) -fi - -AC_SUBST([rootlibdir], [$with_rootlibdir]) - -##################################################################### -# --enable- -##################################################################### -AC_ARG_ENABLE(systemd, AC_HELP_STRING([--disable-systemd], - [disable systemd integration]), [enable_systemd=${enableval}]) -AM_CONDITIONAL(SYSTEMD, test "${enable_systemd}" != "no") - -##################################################################### -# Default CFLAGS and LDFLAGS -##################################################################### -DEFAULT_FLAGS=" -fstack-protector-all -fPIE -fPIC -O2 -D_FORTIFY_SOURCE=2 -pthread -Wformat -Wformat-security" -CFLAGS+=$DEFAULT_FLAGS -CXXFLAGS+=$DEFAULT_FLAGS -LDFLAGS+=" -z noexecstack -z relro -z now" - -##################################################################### -# Generate files from *.in -##################################################################### - -AC_CONFIG_FILES([ - Makefile -]) - -##################################################################### -AC_SUBST(SYSTEMD_SYSTEMUNITDIR, [${path_systemunitdir}]) - -AC_OUTPUT -AC_MSG_RESULT([ - $PACKAGE $VERSION - ========================== - - prefix: ${prefix} - sysconfdir: ${sysconfdir} - libdir: ${libdir} - rootlibdir: ${rootlibdir} - includedir: ${includedir} - bindir: ${bindir} - - C compiler: ${CC} - C++ compiler: ${CXX} - CFLAGS: ${CFLAGS} - CXXFLAGS: ${CXXFLAGS} - LDFLAGS: ${LDFLAGS} - - RealSense support: $enable_realsense - MAVLink support: $enable_mavlink - AVAHI support: $enable_avahi - Intel Aero support: $enable_aero - Gazebo support: $enable_gazebo - Custom support: $enable_custom -]) diff --git a/m4/.gitignore b/m4/.gitignore deleted file mode 100644 index d59889a..0000000 --- a/m4/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -libtool.m4 -ltoptions.m4 -ltsugar.m4 -ltversion.m4 -lt~obsolete.m4 -gtk-doc.m4 diff --git a/m4/attributes.m4 b/m4/attributes.m4 deleted file mode 100644 index c932fef..0000000 --- a/m4/attributes.m4 +++ /dev/null @@ -1,308 +0,0 @@ -dnl Macros to check the presence of generic (non-typed) symbols. -dnl Copyright (c) 2006-2008 Diego Pettenò -dnl Copyright (c) 2006-2008 xine project -dnl Copyright (c) 2012 Lucas De Marchi -dnl -dnl This program is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 2, or (at your option) -dnl any later version. -dnl -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with this program; if not, write to the Free Software -dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -dnl 02110-1301, USA. -dnl -dnl As a special exception, the copyright owners of the -dnl macro gives unlimited permission to copy, distribute and modify the -dnl configure scripts that are the output of Autoconf when processing the -dnl Macro. You need not follow the terms of the GNU General Public -dnl License when using or distributing such scripts, even though portions -dnl of the text of the Macro appear in them. The GNU General Public -dnl License (GPL) does govern all other use of the material that -dnl constitutes the Autoconf Macro. -dnl -dnl This special exception to the GPL applies to versions of the -dnl Autoconf Macro released by this project. When you make and -dnl distribute a modified version of the Autoconf Macro, you may extend -dnl this special exception to the GPL to apply to your modified version as -dnl well. - -dnl Check if FLAG in ENV-VAR is supported by compiler and append it -dnl to WHERE-TO-APPEND variable. Note that we invert -Wno-* checks to -dnl -W* as gcc cannot test for negated warnings. -dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG]) - -AC_DEFUN([CC_CHECK_FLAG_APPEND], [ - AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2], - AS_TR_SH([cc_cv_$2_$3]), - [eval "AS_TR_SH([cc_save_$2])='${$2}'" - eval "AS_TR_SH([$2])='-Werror `echo "$3" | sed 's/^-Wno-/-W/'`'" - AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; } ])], - [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"], - [eval "AS_TR_SH([cc_cv_$2_$3])='no'"]) - eval "AS_TR_SH([$2])='$cc_save_$2'"]) - - AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes], - [eval "$1='${$1} $3'"]) -]) - -dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2]) -AC_DEFUN([CC_CHECK_FLAGS_APPEND], [ - for flag in $3; do - CC_CHECK_FLAG_APPEND($1, $2, $flag) - done -]) - -dnl Check if the flag is supported by linker (cacheable) -dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) - - -dnl Check if the flag is supported by linker -dnl CC_CHECK_LDFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) -AC_DEFUN([CC_CHECK_LDFLAGS_SILENT], [ - AC_CACHE_VAL(AS_TR_SH([cc_cv_ldflags_$1]), - [ac_save_LDFLAGS="$LDFLAGS" - LDFLAGS="$LDFLAGS $1" - AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 1; }])], - [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"], - [eval "AS_TR_SH([cc_cv_ldflags_$1])="]) - LDFLAGS="$ac_save_LDFLAGS" - ]) - - AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], - [$2], [$3]) -]) - -dnl Check if the flag is supported by linker (cacheable) -dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND]) - -AC_DEFUN([CC_CHECK_LDFLAGS], [ - AC_CACHE_CHECK([if $CC supports $1 flag], - AS_TR_SH([cc_cv_ldflags_$1]), - CC_CHECK_LDFLAGS_SILENT([$1]) dnl Don't execute actions here! - ) - - AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes], - [$2], [$3]) -]) - -dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for -dnl the current linker to avoid undefined references in a shared object. -AC_DEFUN([CC_NOUNDEFINED], [ - dnl We check $host for which systems to enable this for. - AC_REQUIRE([AC_CANONICAL_HOST]) - - case $host in - dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads - dnl are requested, as different implementations are present; to avoid problems - dnl use -Wl,-z,defs only for those platform not behaving this way. - *-freebsd* | *-openbsd*) ;; - *) - dnl First of all check for the --no-undefined variant of GNU ld. This allows - dnl for a much more readable command line, so that people can understand what - dnl it does without going to look for what the heck -z defs does. - for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do - CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) - break - done - ;; - esac - - AC_SUBST([LDFLAGS_NOUNDEFINED]) -]) - -dnl Check for a -Werror flag or equivalent. -Werror is the GCC -dnl and ICC flag that tells the compiler to treat all the warnings -dnl as fatal. We usually need this option to make sure that some -dnl constructs (like attributes) are not simply ignored. -dnl -dnl Other compilers don't support -Werror per se, but they support -dnl an equivalent flag: -dnl - Sun Studio compiler supports -errwarn=%all -AC_DEFUN([CC_CHECK_WERROR], [ - AC_CACHE_CHECK( - [for $CC way to treat warnings as errors], - [cc_cv_werror], - [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror], - [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])]) - ]) -]) - -AC_DEFUN([CC_CHECK_ATTRIBUTE], [ - AC_REQUIRE([CC_CHECK_WERROR]) - AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], - AS_TR_SH([cc_cv_attribute_$1]), - [ac_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $cc_cv_werror" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], - [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"], - [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"]) - CFLAGS="$ac_save_CFLAGS" - ]) - - AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes], - [AC_DEFINE( - AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1, - [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))] - ) - $4], - [$5]) -]) - -AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [ - CC_CHECK_ATTRIBUTE( - [constructor],, - [void __attribute__((constructor)) ctor() { int a; }], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_FORMAT], [ - CC_CHECK_ATTRIBUTE( - [format], [format(printf, n, n)], - [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [ - CC_CHECK_ATTRIBUTE( - [format_arg], [format_arg(printf)], - [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [ - CC_CHECK_ATTRIBUTE( - [visibility_$1], [visibility("$1")], - [void __attribute__((visibility("$1"))) $1_function() { }], - [$2], [$3]) -]) - -AC_DEFUN([CC_ATTRIBUTE_NONNULL], [ - CC_CHECK_ATTRIBUTE( - [nonnull], [nonnull()], - [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_UNUSED], [ - CC_CHECK_ATTRIBUTE( - [unused], , - [void some_function(void *foo, __attribute__((unused)) void *bar);], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [ - CC_CHECK_ATTRIBUTE( - [sentinel], , - [void some_function(void *foo, ...) __attribute__((sentinel));], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [ - CC_CHECK_ATTRIBUTE( - [deprecated], , - [void some_function(void *foo, ...) __attribute__((deprecated));], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_ALIAS], [ - CC_CHECK_ATTRIBUTE( - [alias], [weak, alias], - [void other_function(void *foo) { } - void some_function(void *foo) __attribute__((weak, alias("other_function")));], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_MALLOC], [ - CC_CHECK_ATTRIBUTE( - [malloc], , - [void * __attribute__((malloc)) my_alloc(int n);], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_PACKED], [ - CC_CHECK_ATTRIBUTE( - [packed], , - [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));], - [$1], [$2]) -]) - -AC_DEFUN([CC_ATTRIBUTE_CONST], [ - CC_CHECK_ATTRIBUTE( - [const], , - [int __attribute__((const)) twopow(int n) { return 1 << n; } ], - [$1], [$2]) -]) - -AC_DEFUN([CC_FLAG_VISIBILITY], [ - AC_REQUIRE([CC_CHECK_WERROR]) - AC_CACHE_CHECK([if $CC supports -fvisibility=hidden], - [cc_cv_flag_visibility], - [cc_flag_visibility_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $cc_cv_werror" - CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden], - cc_cv_flag_visibility='yes', - cc_cv_flag_visibility='no') - CFLAGS="$cc_flag_visibility_save_CFLAGS"]) - - AS_IF([test "x$cc_cv_flag_visibility" = "xyes"], - [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1, - [Define this if the compiler supports the -fvisibility flag]) - $1], - [$2]) -]) - -AC_DEFUN([CC_CHECK_FUNC_BUILTIN], [ - m4_pushdef([UPNAME], m4_translit([$1], [-a-z], [_A-Z])) - AC_CACHE_CHECK([if compiler has $1 builtin function], - [cc_cv_have_$1], - [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [ - m4_case([$1], - [__builtin_clz], [$1(0)], - [__builtin_types_compatible_p], [$1(int, int)], - [__builtin_uaddl_overflow], [$1(0UL, 0UL, (void*)0)], - [__builtin_uaddll_overflow], [$1(0ULL, 0ULL, (void*)0)], - [__builtin_usubl_overflow], [$1(0UL, 0UL, (void*)0)], - [__builtin_usubll_overflow], [$1(0ULL, 0ULL, (void*)0)], - [__builtin_expect], [$1(0, 0)] - )])], - [cc_cv_have_$1=yes], - [cc_cv_have_$1=no])]) - - AS_IF([test "x$cc_cv_have_$1" = "xyes"], - [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 1, [Define to 1 if compiler has $1() builtin function]) - $2], - [AS_IF([test "x$3" = "x"], [AC_MSG_ERROR([*** builtin function not found: $1()])], - [AC_DEFINE([HAVE_]m4_defn([UPNAME]), 0) - $3])] - ) - m4_popdef([UPNAME]) -]) - -AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [ - AC_REQUIRE([CC_CHECK_WERROR]) - AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported], - [cc_cv_attribute_aligned], - [ac_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $cc_cv_werror" - for cc_attribute_align_try in 64 32 16 8 4 2; do - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - int main() { - static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0; - return c; - }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break]) - done - CFLAGS="$ac_save_CFLAGS" - ]) - - if test "x$cc_cv_attribute_aligned" != "x"; then - AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned], - [Define the highest alignment supported]) - fi -]) diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 deleted file mode 100644 index 2c18e49..0000000 --- a/m4/ax_cxx_compile_stdcxx.m4 +++ /dev/null @@ -1,562 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the specified -# version of the C++ standard. If necessary, add switches to CXX and -# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) -# or '14' (for the C++14 standard). -# -# The second argument, if specified, indicates whether you insist on an -# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. -# -std=c++11). If neither is specified, you get whatever works, with -# preference for an extended mode. -# -# The third argument, if specified 'mandatory' or if left unspecified, -# indicates that baseline support for the specified C++ standard is -# required and that the macro should error out if no mode with that -# support is found. If specified 'optional', then configuration proceeds -# regardless, after defining HAVE_CXX${VERSION} if and only if a -# supporting mode is found. -# -# LICENSE -# -# Copyright (c) 2008 Benjamin Kosnik -# Copyright (c) 2012 Zack Weinberg -# Copyright (c) 2013 Roy Stogner -# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov -# Copyright (c) 2015 Paul Norman -# Copyright (c) 2015 Moritz Klammler -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 4 - -dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro -dnl (serial version number 13). - -AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl - m4_if([$1], [11], [], - [$1], [14], [], - [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], - [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl - m4_if([$2], [], [], - [$2], [ext], [], - [$2], [noext], [], - [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl - m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], - [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], - [$3], [optional], [ax_cxx_compile_cxx$1_required=false], - [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) - AC_LANG_PUSH([C++])dnl - ac_success=no - AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, - ax_cv_cxx_compile_cxx$1, - [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [ax_cv_cxx_compile_cxx$1=yes], - [ax_cv_cxx_compile_cxx$1=no])]) - if test x$ax_cv_cxx_compile_cxx$1 = xyes; then - ac_success=yes - fi - - m4_if([$2], [noext], [], [dnl - if test x$ac_success = xno; then - for switch in -std=gnu++$1 -std=gnu++0x; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, - $cachevar, - [ac_save_CXX="$CXX" - CXX="$CXX $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXX="$ac_save_CXX"]) - if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi - ac_success=yes - break - fi - done - fi]) - - m4_if([$2], [ext], [], [dnl - if test x$ac_success = xno; then - dnl HP's aCC needs +std=c++11 according to: - dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf - dnl Cray's crayCC needs "-h std=c++11" - for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do - cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) - AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, - $cachevar, - [ac_save_CXX="$CXX" - CXX="$CXX $switch" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], - [eval $cachevar=yes], - [eval $cachevar=no]) - CXX="$ac_save_CXX"]) - if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi - ac_success=yes - break - fi - done - fi]) - AC_LANG_POP([C++]) - if test x$ax_cxx_compile_cxx$1_required = xtrue; then - if test x$ac_success = xno; then - AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) - fi - fi - if test x$ac_success = xno; then - HAVE_CXX$1=0 - AC_MSG_NOTICE([No compiler with C++$1 support was found]) - else - HAVE_CXX$1=1 - AC_DEFINE(HAVE_CXX$1,1, - [define if the compiler supports basic C++$1 syntax]) - fi - AC_SUBST(HAVE_CXX$1) -]) - - -dnl Test body for checking C++11 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 -) - - -dnl Test body for checking C++14 support - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], - _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 - _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 -) - - -dnl Tests for new features in C++11 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ - -// If the compiler admits that it is not ready for C++11, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201103L - -#error "This is not a C++11 compiler" - -#else - -namespace cxx11 -{ - - namespace test_static_assert - { - - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - } - - namespace test_final_override - { - - struct Base - { - virtual void f() {} - }; - - struct Derived : public Base - { - virtual void f() override {} - }; - - } - - namespace test_double_right_angle_brackets - { - - template < typename T > - struct check {}; - - typedef check single_type; - typedef check> double_type; - typedef check>> triple_type; - typedef check>>> quadruple_type; - - } - - namespace test_decltype - { - - int - f() - { - int a = 1; - decltype(a) b = 2; - return a + b; - } - - } - - namespace test_type_deduction - { - - template < typename T1, typename T2 > - struct is_same - { - static const bool value = false; - }; - - template < typename T > - struct is_same - { - static const bool value = true; - }; - - template < typename T1, typename T2 > - auto - add(T1 a1, T2 a2) -> decltype(a1 + a2) - { - return a1 + a2; - } - - int - test(const int c, volatile int v) - { - static_assert(is_same::value == true, ""); - static_assert(is_same::value == false, ""); - static_assert(is_same::value == false, ""); - auto ac = c; - auto av = v; - auto sumi = ac + av + 'x'; - auto sumf = ac + av + 1.0; - static_assert(is_same::value == true, ""); - static_assert(is_same::value == true, ""); - static_assert(is_same::value == true, ""); - static_assert(is_same::value == false, ""); - static_assert(is_same::value == true, ""); - return (sumf > 0.0) ? sumi : add(c, v); - } - - } - - namespace test_noexcept - { - - int f() { return 0; } - int g() noexcept { return 0; } - - static_assert(noexcept(f()) == false, ""); - static_assert(noexcept(g()) == true, ""); - - } - - namespace test_constexpr - { - - template < typename CharT > - unsigned long constexpr - strlen_c_r(const CharT *const s, const unsigned long acc) noexcept - { - return *s ? strlen_c_r(s + 1, acc + 1) : acc; - } - - template < typename CharT > - unsigned long constexpr - strlen_c(const CharT *const s) noexcept - { - return strlen_c_r(s, 0UL); - } - - static_assert(strlen_c("") == 0UL, ""); - static_assert(strlen_c("1") == 1UL, ""); - static_assert(strlen_c("example") == 7UL, ""); - static_assert(strlen_c("another\0example") == 7UL, ""); - - } - - namespace test_rvalue_references - { - - template < int N > - struct answer - { - static constexpr int value = N; - }; - - answer<1> f(int&) { return answer<1>(); } - answer<2> f(const int&) { return answer<2>(); } - answer<3> f(int&&) { return answer<3>(); } - - void - test() - { - int i = 0; - const int c = 0; - static_assert(decltype(f(i))::value == 1, ""); - static_assert(decltype(f(c))::value == 2, ""); - static_assert(decltype(f(0))::value == 3, ""); - } - - } - - namespace test_uniform_initialization - { - - struct test - { - static const int zero {}; - static const int one {1}; - }; - - static_assert(test::zero == 0, ""); - static_assert(test::one == 1, ""); - - } - - namespace test_lambdas - { - - void - test1() - { - auto lambda1 = [](){}; - auto lambda2 = lambda1; - lambda1(); - lambda2(); - } - - int - test2() - { - auto a = [](int i, int j){ return i + j; }(1, 2); - auto b = []() -> int { return '0'; }(); - auto c = [=](){ return a + b; }(); - auto d = [&](){ return c; }(); - auto e = [a, &b](int x) mutable { - const auto identity = [](int y){ return y; }; - for (auto i = 0; i < a; ++i) - a += b--; - return x + identity(a + b); - }(0); - return a + b + c + d + e; - } - - int - test3() - { - const auto nullary = [](){ return 0; }; - const auto unary = [](int x){ return x; }; - using nullary_t = decltype(nullary); - using unary_t = decltype(unary); - const auto higher1st = [](nullary_t f){ return f(); }; - const auto higher2nd = [unary](nullary_t f1){ - return [unary, f1](unary_t f2){ return f2(unary(f1())); }; - }; - return higher1st(nullary) + higher2nd(nullary)(unary); - } - - } - - namespace test_variadic_templates - { - - template - struct sum; - - template - struct sum - { - static constexpr auto value = N0 + sum::value; - }; - - template <> - struct sum<> - { - static constexpr auto value = 0; - }; - - static_assert(sum<>::value == 0, ""); - static_assert(sum<1>::value == 1, ""); - static_assert(sum<23>::value == 23, ""); - static_assert(sum<1, 2>::value == 3, ""); - static_assert(sum<5, 5, 11>::value == 21, ""); - static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); - - } - - // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae - // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function - // because of this. - namespace test_template_alias_sfinae - { - - struct foo {}; - - template - using member = typename T::member_type; - - template - void func(...) {} - - template - void func(member*) {} - - void test(); - - void test() { func(0); } - - } - -} // namespace cxx11 - -#endif // __cplusplus >= 201103L - -]]) - - -dnl Tests for new features in C++14 - -m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ - -// If the compiler admits that it is not ready for C++14, why torture it? -// Hopefully, this will speed up the test. - -#ifndef __cplusplus - -#error "This is not a C++ compiler" - -#elif __cplusplus < 201402L - -#error "This is not a C++14 compiler" - -#else - -namespace cxx14 -{ - - namespace test_polymorphic_lambdas - { - - int - test() - { - const auto lambda = [](auto&&... args){ - const auto istiny = [](auto x){ - return (sizeof(x) == 1UL) ? 1 : 0; - }; - const int aretiny[] = { istiny(args)... }; - return aretiny[0]; - }; - return lambda(1, 1L, 1.0f, '1'); - } - - } - - namespace test_binary_literals - { - - constexpr auto ivii = 0b0000000000101010; - static_assert(ivii == 42, "wrong value"); - - } - - namespace test_generalized_constexpr - { - - template < typename CharT > - constexpr unsigned long - strlen_c(const CharT *const s) noexcept - { - auto length = 0UL; - for (auto p = s; *p; ++p) - ++length; - return length; - } - - static_assert(strlen_c("") == 0UL, ""); - static_assert(strlen_c("x") == 1UL, ""); - static_assert(strlen_c("test") == 4UL, ""); - static_assert(strlen_c("another\0test") == 7UL, ""); - - } - - namespace test_lambda_init_capture - { - - int - test() - { - auto x = 0; - const auto lambda1 = [a = x](int b){ return a + b; }; - const auto lambda2 = [a = lambda1(x)](){ return a; }; - return lambda2(); - } - - } - - namespace test_digit_seperators - { - - constexpr auto ten_million = 100'000'000; - static_assert(ten_million == 100000000, ""); - - } - - namespace test_return_type_deduction - { - - auto f(int& x) { return x; } - decltype(auto) g(int& x) { return x; } - - template < typename T1, typename T2 > - struct is_same - { - static constexpr auto value = false; - }; - - template < typename T > - struct is_same - { - static constexpr auto value = true; - }; - - int - test() - { - auto x = 0; - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - return x; - } - - } - -} // namespace cxx14 - -#endif // __cplusplus >= 201402L - -]]) diff --git a/modules/mavlink b/modules/mavlink index 141637e..464ef27 160000 --- a/modules/mavlink +++ b/modules/mavlink @@ -1 +1 @@ -Subproject commit 141637e21e87a9c4ade90dbb9d544375294c106a +Subproject commit 464ef273bcee8fbc2a9c462b59b6e28b35136bdc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..c6594d5 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,164 @@ +cmake_minimum_required(VERSION 3.5) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + +find_package(PkgConfig REQUIRED) + +set(GSTREAMER_MINIMUM_VERSION 1.8) +pkg_check_modules(GST1_TEST gstreamer-1.0) + +if (NOT GST1_TEST_FOUND ) + message( FATAL_ERROR "GStreamer 1.8 required." ) +endif() +if ( ${GST1_TEST_VERSION} VERSION_LESS ${GSTREAMER_MINIMUM_VERSION} ) + message( FATAL_ERROR "GStreamer 1.8 required. Found ${GST1_TEST_VERSION} instead." ) +endif() + +pkg_check_modules(GST REQUIRED + gstreamer-rtsp-1.0 + gstreamer-1.0 + gstreamer-rtsp-server-1.0 + gstreamer-app-1.0 +) + +project(dcm) + +add_definitions( + -std=c++11 + -Wall + -Wextra + -Wno-unused-parameter + -Wno-unused-variable + -Wno-missing-field-initializers +) + +add_executable(${PROJECT_NAME} + avahi_publisher.cpp + conf_file.cpp + main.cpp + pollable.cpp + VideoCaptureGst.cpp + CameraComponent.cpp + glib_mainloop.cpp + mainloop.cpp + socket.cpp + VideoStreamRtsp.cpp + CameraParameters.cpp + ImageCaptureGst.cpp + mavlink_server.cpp + util.cpp + VideoStreamUdp.cpp + CameraServer.cpp + log.cpp + PluginManager.cpp + v4l2_interface.cpp +) + +target_link_libraries(${PROJECT_NAME} + V4l2Camera +) + +target_link_libraries(${PROJECT_NAME} + pthread + ${GST_LIBRARIES} +) + +include_directories( + ${GST_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} +) + +link_directories( + ${GST_LIBRARY_DIRS} +) + +target_compile_options(${PROJECT_NAME} PUBLIC + ${GST_CFLAGS} +) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${PROJECT_SOURCE_DIR}/../modules/mavlink/common + ${GST_INCLUDE_DIRS} +) + +add_subdirectory(Plugins/V4l2Camera) + +option(WITH_MAVLINK "Use Mavlink communication module" ON) +option(WITH_AVAHI "Use Avahi service discovery" OFF) +option(WITH_REALSENSE "Enable support for Realsense cameras" OFF) +option(WITH_GAZEBO "Enable support for Gazebo simulated cameras" OFF) +option(WITH_AERO "Enable support for Intel Aero cameras" OFF) +option(WITH_CUSTOM "Enable support for Custom cameras" OFF) + +if(WITH_MAVLINK) + add_definitions(-DENABLE_MAVLINK) +endif(WITH_MAVLINK) + +if(WITH_AERO) + add_definitions(-DENABLE_AERO) + add_subdirectory(Plugins/AeroAtomIspCamera) + target_link_libraries(${PROJECT_NAME} + AeroAtomIspCamera + ) +endif(WITH_AERO) + +if(WITH_CUSTOM) + add_definitions(-DENABLE_CUSTOM) + add_subdirectory(Plugins/CustomCamera) + target_link_libraries(${PROJECT_NAME} + CustomCamera + ) +endif(WITH_CUSTOM) + +if(WITH_AVAHI) + find_package(Avahi QUIET) + if(Avahi_FOUND) + add_definitions(-DENABLE_AVAHI) + target_link_libraries(${PROJECT_NAME} + Avahi::client + Avahi::glib + ) + MESSAGE(STATUS "Found Avahi: ${Avahi_CLIENT_INCLUDE_DIRS}") + endif(Avahi_FOUND) +endif(WITH_AVAHI) + +if(WITH_GAZEBO) + find_package(gazebo QUIET) + if(gazebo_FOUND) + add_subdirectory(Plugins/GazeboCamera) + add_definitions(-DENABLE_GAZEBO) + target_link_libraries(${PROJECT_NAME} + GazeboCamera + ${GAZEBO_LIBRARIES} + ) + MESSAGE(STATUS "Found Gazebo: ${GAZEBO_LIBRARIES}") + endif(gazebo_FOUND) +endif(WITH_GAZEBO) + +if(WITH_REALSENSE) + FIND_PACKAGE(RealSense QUIET) + if(RealSense_FOUND) + add_subdirectory(Plugins/RealSenseCamera) + add_definitions(-DENABLE_REALSENSE) + target_link_libraries(${PROJECT_NAME} + RealSenseCamera + ${RealSense_LIBRARIES} + ) + MESSAGE(STATUS "Found RealSense: ${RealSense_INCLUDE_DIRS}") + endif(RealSense_FOUND) +endif(WITH_REALSENSE) + +# RealSense2 +# Currently not supported - but it will be in the future +#FIND_PACKAGE(RealSense2 QUIET) +#if(RealSense2_FOUND) +# MESSAGE(STATUS "Found RealSense2: ${RealSense2_INCLUDE_DIRS}") +#endif(RealSense2_FOUND) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) + +set(SYSTEMD_CONFIG_DIR "/lib/systemd/system" CACHE STRING "Path to the systemd configuration dir") +set(SYSTEMD_UNIT_NAME "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.service") +configure_file("${PROJECT_SOURCE_DIR}/cmake/dronecode-camera-manager.service.in" "${SYSTEMD_UNIT_NAME}") +install(FILES "${SYSTEMD_UNIT_NAME}" DESTINATION "${SYSTEMD_CONFIG_DIR}/" COMPONENT Runtime) + diff --git a/src/CameraParameters.cpp b/src/CameraParameters.cpp index 4b3a4e4..51bdca3 100644 --- a/src/CameraParameters.cpp +++ b/src/CameraParameters.cpp @@ -165,33 +165,52 @@ std::string CameraParameters::getParameter(std::string key) void CameraParameters::initParamIdType() { - paramIdType[CAMERA_MODE] = std::make_pair(PARAM_ID_CAMERA_MODE, PARAM_TYPE_UINT32); - paramIdType[BRIGHTNESS] = std::make_pair(PARAM_ID_BRIGHTNESS, PARAM_TYPE_UINT32); - paramIdType[CONTRAST] = std::make_pair(PARAM_ID_CONTRAST, PARAM_TYPE_UINT32); - paramIdType[SATURATION] = std::make_pair(PARAM_ID_SATURATION, PARAM_TYPE_UINT32); - paramIdType[HUE] = std::make_pair(PARAM_ID_HUE, PARAM_TYPE_INT32); + paramIdType[CAMERA_MODE] + = std::make_pair(static_cast(PARAM_ID_CAMERA_MODE), PARAM_TYPE_UINT32); + paramIdType[BRIGHTNESS] + = std::make_pair(static_cast(PARAM_ID_BRIGHTNESS), PARAM_TYPE_UINT32); + paramIdType[CONTRAST] + = std::make_pair(static_cast(PARAM_ID_CONTRAST), PARAM_TYPE_UINT32); + paramIdType[SATURATION] + = std::make_pair(static_cast(PARAM_ID_SATURATION), PARAM_TYPE_UINT32); + paramIdType[HUE] + = std::make_pair(static_cast(PARAM_ID_HUE), PARAM_TYPE_INT32); paramIdType[WHITE_BALANCE_MODE] - = std::make_pair(PARAM_ID_WHITE_BALANCE_MODE, PARAM_TYPE_UINT32); - paramIdType[GAMMA] = std::make_pair(PARAM_ID_GAMMA, PARAM_TYPE_UINT32); - paramIdType[GAIN] = std::make_pair(PARAM_ID_GAIN, PARAM_TYPE_UINT32); + = std::make_pair(static_cast(PARAM_ID_WHITE_BALANCE_MODE), PARAM_TYPE_UINT32); + paramIdType[GAMMA] + = std::make_pair(static_cast(PARAM_ID_GAMMA), PARAM_TYPE_UINT32); + paramIdType[GAIN] + = std::make_pair(static_cast(PARAM_ID_GAIN), PARAM_TYPE_UINT32); paramIdType[POWER_LINE_FREQ_MODE] - = std::make_pair(PARAM_ID_POWER_LINE_FREQ_MODE, PARAM_TYPE_UINT32); + = std::make_pair(static_cast(PARAM_ID_POWER_LINE_FREQ_MODE), PARAM_TYPE_UINT32); paramIdType[WHITE_BALANCE_TEMPERATURE] - = std::make_pair(PARAM_ID_WHITE_BALANCE_TEMPERATURE, PARAM_TYPE_UINT32); - paramIdType[SHARPNESS] = std::make_pair(PARAM_ID_SHARPNESS, PARAM_TYPE_UINT32); + = std::make_pair(static_cast(PARAM_ID_WHITE_BALANCE_TEMPERATURE), PARAM_TYPE_UINT32); + paramIdType[SHARPNESS] + = std::make_pair(static_cast(PARAM_ID_SHARPNESS), PARAM_TYPE_UINT32); paramIdType[BACKLIGHT_COMPENSATION] - = std::make_pair(PARAM_ID_BACKLIGHT_COMPENSATION, PARAM_TYPE_UINT32); - paramIdType[EXPOSURE_MODE] = std::make_pair(PARAM_ID_EXPOSURE_MODE, PARAM_TYPE_UINT32); - paramIdType[EXPOSURE_ABSOLUTE] = std::make_pair(PARAM_ID_EXPOSURE_ABSOLUTE, PARAM_TYPE_UINT32); - paramIdType[IMAGE_SIZE] = std::make_pair(PARAM_ID_IMAGE_SIZE, PARAM_TYPE_UINT32); - paramIdType[IMAGE_FORMAT] = std::make_pair(PARAM_ID_IMAGE_FORMAT, PARAM_TYPE_UINT32); - paramIdType[PIXEL_FORMAT] = std::make_pair(PARAM_ID_PIXEL_FORMAT, PARAM_TYPE_UINT32); - paramIdType[SCENE_MODE] = std::make_pair(PARAM_ID_SCENE_MODE, PARAM_TYPE_UINT32); - paramIdType[VIDEO_SIZE] = std::make_pair(PARAM_ID_VIDEO_SIZE, PARAM_TYPE_UINT32); + = std::make_pair(static_cast(PARAM_ID_BACKLIGHT_COMPENSATION), PARAM_TYPE_UINT32); + paramIdType[EXPOSURE_MODE] + = std::make_pair(static_cast(PARAM_ID_EXPOSURE_MODE), PARAM_TYPE_UINT32); + paramIdType[EXPOSURE_ABSOLUTE] + = std::make_pair(static_cast(PARAM_ID_EXPOSURE_ABSOLUTE), PARAM_TYPE_UINT32); + paramIdType[IMAGE_SIZE] + = std::make_pair(static_cast(PARAM_ID_IMAGE_SIZE), PARAM_TYPE_UINT32); + paramIdType[IMAGE_FORMAT] + = std::make_pair(static_cast(PARAM_ID_IMAGE_FORMAT), PARAM_TYPE_UINT32); + paramIdType[PIXEL_FORMAT] + = std::make_pair(static_cast(PARAM_ID_PIXEL_FORMAT), PARAM_TYPE_UINT32); + paramIdType[SCENE_MODE] + = std::make_pair(static_cast(PARAM_ID_SCENE_MODE), PARAM_TYPE_UINT32); + paramIdType[VIDEO_SIZE] + = std::make_pair(static_cast(PARAM_ID_VIDEO_SIZE), PARAM_TYPE_UINT32); paramIdType[VIDEO_FRAME_FORMAT] - = std::make_pair(PARAM_ID_VIDEO_FRAME_FORMAT, PARAM_TYPE_UINT32); - paramIdType[IMAGE_CAPTURE] = std::make_pair(PARAM_ID_IMAGE_CAPTURE, PARAM_TYPE_UINT32); - paramIdType[VIDEO_CAPTURE] = std::make_pair(PARAM_ID_VIDEO_CAPTURE, PARAM_TYPE_UINT32); - paramIdType[VIDEO_SNAPSHOT] = std::make_pair(PARAM_ID_VIDEO_SNAPSHOT, PARAM_TYPE_UINT32); - paramIdType[IMAGE_VIDEOSHOT] = std::make_pair(PARAM_ID_IMAGE_VIDEOSHOT, PARAM_TYPE_UINT32); + = std::make_pair(static_cast(PARAM_ID_VIDEO_FRAME_FORMAT), PARAM_TYPE_UINT32); + paramIdType[IMAGE_CAPTURE] + = std::make_pair(static_cast(PARAM_ID_IMAGE_CAPTURE), PARAM_TYPE_UINT32); + paramIdType[VIDEO_CAPTURE] + = std::make_pair(static_cast(PARAM_ID_VIDEO_CAPTURE), PARAM_TYPE_UINT32); + paramIdType[VIDEO_SNAPSHOT] + = std::make_pair(static_cast(PARAM_ID_VIDEO_SNAPSHOT), PARAM_TYPE_UINT32); + paramIdType[IMAGE_VIDEOSHOT] + = std::make_pair(static_cast(PARAM_ID_IMAGE_VIDEOSHOT), PARAM_TYPE_UINT32); } diff --git a/src/PluginBase.h b/src/PluginBase.h index b69a6b8..d78febb 100644 --- a/src/PluginBase.h +++ b/src/PluginBase.h @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once #include #include diff --git a/src/PluginManager.h b/src/PluginManager.h index aaefb63..2601b60 100644 --- a/src/PluginManager.h +++ b/src/PluginManager.h @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once #include #include diff --git a/src/Plugins/AeroAtomIspCamera/CMakeLists.txt b/src/Plugins/AeroAtomIspCamera/CMakeLists.txt new file mode 100644 index 0000000..d610314 --- /dev/null +++ b/src/Plugins/AeroAtomIspCamera/CMakeLists.txt @@ -0,0 +1,9 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +add_library(AeroAtomIspCamera + CameraDeviceAeroAtomIsp.cpp + PluginAeroAtomIsp.cpp +) + diff --git a/plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.cpp b/src/Plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.cpp similarity index 100% rename from plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.cpp rename to src/Plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.cpp diff --git a/plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.h b/src/Plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.h similarity index 100% rename from plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.h rename to src/Plugins/AeroAtomIspCamera/CameraDeviceAeroAtomIsp.h diff --git a/plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp b/src/Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp similarity index 98% rename from plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp rename to src/Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp index 077e8b5..a0d158f 100644 --- a/plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp +++ b/src/Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.cpp @@ -21,8 +21,6 @@ #include "CameraDeviceAeroAtomIsp.h" #include "PluginAeroAtomIsp.h" -static PluginAeroAtomIsp aero; - PluginAeroAtomIsp::PluginAeroAtomIsp() : PluginBase() { diff --git a/plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h b/src/Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h similarity index 100% rename from plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h rename to src/Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h diff --git a/src/Plugins/CustomCamera/CMakeLists.txt b/src/Plugins/CustomCamera/CMakeLists.txt new file mode 100644 index 0000000..d22d613 --- /dev/null +++ b/src/Plugins/CustomCamera/CMakeLists.txt @@ -0,0 +1,7 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +add_library(CustomCamera + CameraDeviceCustom.cpp + PluginCustom.cpp) diff --git a/plugins/CustomCamera/CameraDeviceCustom.cpp b/src/Plugins/CustomCamera/CameraDeviceCustom.cpp similarity index 100% rename from plugins/CustomCamera/CameraDeviceCustom.cpp rename to src/Plugins/CustomCamera/CameraDeviceCustom.cpp diff --git a/plugins/CustomCamera/CameraDeviceCustom.h b/src/Plugins/CustomCamera/CameraDeviceCustom.h similarity index 100% rename from plugins/CustomCamera/CameraDeviceCustom.h rename to src/Plugins/CustomCamera/CameraDeviceCustom.h diff --git a/plugins/CustomCamera/PluginCustom.cpp b/src/Plugins/CustomCamera/PluginCustom.cpp similarity index 98% rename from plugins/CustomCamera/PluginCustom.cpp rename to src/Plugins/CustomCamera/PluginCustom.cpp index 669a824..14136cf 100644 --- a/plugins/CustomCamera/PluginCustom.cpp +++ b/src/Plugins/CustomCamera/PluginCustom.cpp @@ -22,8 +22,6 @@ #include "CameraDeviceCustom.h" #include "PluginCustom.h" -static PluginCustom custom; - PluginCustom::PluginCustom() : PluginBase() { diff --git a/plugins/CustomCamera/PluginCustom.h b/src/Plugins/CustomCamera/PluginCustom.h similarity index 98% rename from plugins/CustomCamera/PluginCustom.h rename to src/Plugins/CustomCamera/PluginCustom.h index 0a42ed7..c134f43 100644 --- a/plugins/CustomCamera/PluginCustom.h +++ b/src/Plugins/CustomCamera/PluginCustom.h @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#pragma once #include #include diff --git a/src/Plugins/GazeboCamera/CMakeLists.txt b/src/Plugins/GazeboCamera/CMakeLists.txt new file mode 100644 index 0000000..944ce9f --- /dev/null +++ b/src/Plugins/GazeboCamera/CMakeLists.txt @@ -0,0 +1,11 @@ +find_package(gazebo REQUIRED) + +include_directories( + ${GAZEBO_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +add_library(GazeboCamera + CameraDeviceGazebo.cpp + PluginGazebo.cpp) + diff --git a/plugins/GazeboCamera/CameraDeviceGazebo.cpp b/src/Plugins/GazeboCamera/CameraDeviceGazebo.cpp similarity index 100% rename from plugins/GazeboCamera/CameraDeviceGazebo.cpp rename to src/Plugins/GazeboCamera/CameraDeviceGazebo.cpp diff --git a/plugins/GazeboCamera/CameraDeviceGazebo.h b/src/Plugins/GazeboCamera/CameraDeviceGazebo.h similarity index 100% rename from plugins/GazeboCamera/CameraDeviceGazebo.h rename to src/Plugins/GazeboCamera/CameraDeviceGazebo.h diff --git a/plugins/GazeboCamera/PluginGazebo.cpp b/src/Plugins/GazeboCamera/PluginGazebo.cpp similarity index 98% rename from plugins/GazeboCamera/PluginGazebo.cpp rename to src/Plugins/GazeboCamera/PluginGazebo.cpp index 95c98a9..9af2e21 100644 --- a/plugins/GazeboCamera/PluginGazebo.cpp +++ b/src/Plugins/GazeboCamera/PluginGazebo.cpp @@ -27,8 +27,6 @@ #define GZB_CMD_TOPIC "gz topic -l | grep \"camera/image\" " -static PluginGazebo gzb; - PluginGazebo::PluginGazebo() : PluginBase() { diff --git a/plugins/GazeboCamera/PluginGazebo.h b/src/Plugins/GazeboCamera/PluginGazebo.h similarity index 98% rename from plugins/GazeboCamera/PluginGazebo.h rename to src/Plugins/GazeboCamera/PluginGazebo.h index e67b1ba..064b4cd 100644 --- a/plugins/GazeboCamera/PluginGazebo.h +++ b/src/Plugins/GazeboCamera/PluginGazebo.h @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once #include #include diff --git a/src/Plugins/RealSenseCamera/CMakeLists.txt b/src/Plugins/RealSenseCamera/CMakeLists.txt new file mode 100644 index 0000000..e1d0a89 --- /dev/null +++ b/src/Plugins/RealSenseCamera/CMakeLists.txt @@ -0,0 +1,8 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +add_library(RealSenseCamera + CameraDeviceRealSense.cpp + PluginRealSense.cpp) + diff --git a/plugins/RealSenseCamera/CameraDeviceRealSense.cpp b/src/Plugins/RealSenseCamera/CameraDeviceRealSense.cpp similarity index 100% rename from plugins/RealSenseCamera/CameraDeviceRealSense.cpp rename to src/Plugins/RealSenseCamera/CameraDeviceRealSense.cpp diff --git a/plugins/RealSenseCamera/CameraDeviceRealSense.h b/src/Plugins/RealSenseCamera/CameraDeviceRealSense.h similarity index 100% rename from plugins/RealSenseCamera/CameraDeviceRealSense.h rename to src/Plugins/RealSenseCamera/CameraDeviceRealSense.h diff --git a/plugins/RealSenseCamera/PluginRealSense.cpp b/src/Plugins/RealSenseCamera/PluginRealSense.cpp similarity index 98% rename from plugins/RealSenseCamera/PluginRealSense.cpp rename to src/Plugins/RealSenseCamera/PluginRealSense.cpp index 31151d9..2df598f 100644 --- a/plugins/RealSenseCamera/PluginRealSense.cpp +++ b/src/Plugins/RealSenseCamera/PluginRealSense.cpp @@ -22,8 +22,6 @@ #include "CameraDeviceRealSense.h" #include "PluginRealSense.h" -static PluginRealSense rs; - PluginRealSense::PluginRealSense() : PluginBase() { diff --git a/plugins/RealSenseCamera/PluginRealSense.h b/src/Plugins/RealSenseCamera/PluginRealSense.h similarity index 100% rename from plugins/RealSenseCamera/PluginRealSense.h rename to src/Plugins/RealSenseCamera/PluginRealSense.h diff --git a/src/Plugins/V4l2Camera/CMakeLists.txt b/src/Plugins/V4l2Camera/CMakeLists.txt new file mode 100644 index 0000000..d47a28f --- /dev/null +++ b/src/Plugins/V4l2Camera/CMakeLists.txt @@ -0,0 +1,8 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../.. +) + +add_library(V4l2Camera + CameraDeviceV4l2.cpp + PluginV4l2.cpp) + diff --git a/plugins/V4l2Camera/CameraDeviceV4l2.cpp b/src/Plugins/V4l2Camera/CameraDeviceV4l2.cpp similarity index 100% rename from plugins/V4l2Camera/CameraDeviceV4l2.cpp rename to src/Plugins/V4l2Camera/CameraDeviceV4l2.cpp diff --git a/plugins/V4l2Camera/CameraDeviceV4l2.h b/src/Plugins/V4l2Camera/CameraDeviceV4l2.h similarity index 100% rename from plugins/V4l2Camera/CameraDeviceV4l2.h rename to src/Plugins/V4l2Camera/CameraDeviceV4l2.h diff --git a/plugins/V4l2Camera/PluginV4l2.cpp b/src/Plugins/V4l2Camera/PluginV4l2.cpp similarity index 98% rename from plugins/V4l2Camera/PluginV4l2.cpp rename to src/Plugins/V4l2Camera/PluginV4l2.cpp index d3925f2..73c7a29 100644 --- a/plugins/V4l2Camera/PluginV4l2.cpp +++ b/src/Plugins/V4l2Camera/PluginV4l2.cpp @@ -21,8 +21,6 @@ #include "PluginV4l2.h" #include "v4l2_interface.h" -static PluginV4l2 v4l2; - PluginV4l2::PluginV4l2() : PluginBase() { diff --git a/plugins/V4l2Camera/PluginV4l2.h b/src/Plugins/V4l2Camera/PluginV4l2.h similarity index 98% rename from plugins/V4l2Camera/PluginV4l2.h rename to src/Plugins/V4l2Camera/PluginV4l2.h index 1d5d38a..c97e14a 100644 --- a/plugins/V4l2Camera/PluginV4l2.h +++ b/src/Plugins/V4l2Camera/PluginV4l2.h @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#pragma once #include #include diff --git a/dronecode-camera-manager.service.in b/src/cmake/dronecode-camera-manager.service.in similarity index 100% rename from dronecode-camera-manager.service.in rename to src/cmake/dronecode-camera-manager.service.in diff --git a/src/main.cpp b/src/main.cpp index fddf508..edc0a54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,10 +27,32 @@ #include "conf_file.h" #include "glib_mainloop.h" #include "log.h" -#include "settings.h" #include "util.h" #include "CameraServer.h" +#include "Plugins/V4l2Camera/PluginV4l2.h" +static PluginV4l2 pluginV4l2; + +#ifdef ENABLE_AERO +#include "Plugins/AeroAtomIspCamera/PluginAeroAtomIsp.h" +static PluginAeroAtomIsp pluginAeroAtomIsp; +#endif + +#ifdef ENABLE_CUSTOM +#include "Plugins/CustomCamera/PluginCustom.h" +static PluginCustom pluginCustom; +#endif + +#ifdef ENABLE_GAZEBO +#include "Plugins/GazeboCamera/PluginGazebo.h" +static PluginGazebo pluginGazebo; +#endif + +#ifdef ENABLE_REALSENSE +#include "Plugins/RealSenseCamera/PluginRealSense.h" +static PluginRealSense pluginRealSense; +#endif + #define DEFAULT_CONFFILE "/etc/dcm/main.conf" #define DEFAULT_CONF_DIR "/etc/dcm/config.d" diff --git a/src/mavlink_server.cpp b/src/mavlink_server.cpp index eed398a..cfbe9e8 100644 --- a/src/mavlink_server.cpp +++ b/src/mavlink_server.cpp @@ -160,8 +160,12 @@ void MavlinkServer::_handle_request_camera_settings(const struct sockaddr_in &ad CameraComponent *tgtComp = getCameraComponent(cmd.target_component); if (tgtComp) { + float zoomLevel = 0; + float focusLevel = 0; + mavlink_msg_camera_settings_pack(_system_id, cmd.target_component, &msg, 0, - dcm2mavCameraMode(tgtComp->getCameraMode())); + dcm2mavCameraMode(tgtComp->getCameraMode()), + zoomLevel, focusLevel); if (!_send_mavlink_message(&addr, msg)) { log_error("Sending camera setting failed for camera %d.", cmd.target_component); @@ -335,90 +339,6 @@ void MavlinkServer::_handle_request_camera_capture_status(const struct sockaddr_ _send_ack(addr, cmd.command, cmd.target_component, success); } -#if 0 -void MavlinkServer::_handle_camera_video_stream_request(const struct sockaddr_in &addr, int command, - unsigned int camera_id, unsigned int action) -{ - log_debug("%s", __func__); - - mavlink_message_t msg; - char query[35] = ""; - - if (action != 1) - return; - - for (auto const &s : _streams) { - if (camera_id == 0 || camera_id == s->id) { - const Stream::FrameSize *fs = s->sel_frame_size - ? s->sel_frame_size - : _find_best_frame_size(*s, UINT32_MAX, UINT32_MAX); - - if (s->sel_frame_size) { - int ret = snprintf(query, sizeof(query), "?width=%d&height=%d", - s->sel_frame_size->width, s->sel_frame_size->height); - if (ret > (int)sizeof(query)) { - log_error("Invalid requested resolution. Aborting request."); - return; - } - } - - mavlink_msg_video_stream_information_pack( - _system_id, _comp_id, &msg, s->id, s->is_streaming /* Status */, - 0 /* FPS */, fs->width, fs->height, 0 /* bitrate */, 0 /* Rotation */, - _rtsp.get_rtsp_uri(_rtsp_server_addr, *s, query).c_str()); - if (!_send_mavlink_message(&addr, msg)) { - log_error("Sending camera information failed for camera %d.", s->id); - return; - } - } - } -} - -const Stream::FrameSize *MavlinkServer::_find_best_frame_size(Stream &s, uint32_t w, uint32_t h) -{ - // Using strategy of getting the higher frame size that is lower than WxH, if the - // exact resolution is not found - const Stream::FrameSize *best = nullptr; - for (auto const &f : s.formats) { - for (auto const &fs : f.frame_sizes) { - if (fs.width == w && fs.height == h) - return &fs; - else if (!best || (fs.width <= w && fs.width >= best->width && fs.height <= h - && fs.height >= best->height)) - best = &fs; - } - } - return best; -} - -void MavlinkServer::_handle_camera_set_video_stream_settings(const struct sockaddr_in &addr, - mavlink_message_t *msg) -{ - log_debug("%s", __func__); - - mavlink_set_video_stream_settings_t settings; - Stream *stream = nullptr; - - mavlink_msg_set_video_stream_settings_decode(msg, &settings); - for (auto const &s : _streams) { - if (s->id == settings.camera_id) { - stream = &*s; - } - } - if (!stream) { - log_debug("SET_VIDEO_STREAM request in an invalid camera (camera_id = %d)", - settings.camera_id); - return; - } - - if (settings.resolution_h == 0 || settings.resolution_v == 0) - stream->sel_frame_size = nullptr; - else - stream->sel_frame_size - = _find_best_frame_size(*stream, settings.resolution_h, settings.resolution_v); -} -#endif - void MavlinkServer::_handle_param_ext_request_read(const struct sockaddr_in &addr, mavlink_message_t *msg) { @@ -655,11 +575,6 @@ void MavlinkServer::_handle_mavlink_message(const struct sockaddr_in &addr, mavl if (!_is_sys_id_found) this->_handle_heartbeat(addr, msg); break; - case MAVLINK_MSG_ID_SET_VIDEO_STREAM_SETTINGS: -#if 0 - this->_handle_camera_set_video_stream_settings(addr, msg); -#endif - break; case MAVLINK_MSG_ID_PARAM_EXT_REQUEST_READ: this->_handle_param_ext_request_read(addr, msg); break; diff --git a/src/settings.cpp b/src/settings.cpp deleted file mode 100644 index 35c36b8..0000000 --- a/src/settings.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the MAVLink Router project - * - * Copyright (C) 2017 Intel Corporation. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "settings.h" -#include "conf.h" -#include "log.h" - -Settings Settings::settings; -int Settings::import_conf_file(const char *filename) -{ - const char *section, *key, *value; - size_t section_len, key_len, value_len; - ConfFile conf(filename); - - while (conf.next(§ion, §ion_len, &key, &key_len, &value, &value_len) == 0) { - sections[std::string(section, section_len)][std::string(key, key_len)] - = std::string(value, value_len); - } - - return 0; -} - -std::set Settings::get_value_as_set(std::string section, std::string key) -{ - std::set value_set; - std::string &value = sections[section][key]; - size_t i = 0, j; - - j = value.find(' '); - while (j != std::string::npos) { - value_set.insert(value.substr(i, j - i)); - i = j + 1; - j = value.find(' ', j + 1); - } - value_set.insert(value.substr(i, j - i)); - - return value_set; -} diff --git a/src/settings.h b/src/settings.h deleted file mode 100644 index 316e8d4..0000000 --- a/src/settings.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MAVLink Router project - * - * Copyright (C) 2017 Intel Corporation. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once -#include -#include - -class Settings { -public: - ~Settings(){}; - static Settings &get_instance() { return settings; }; - - int import_conf_file(const char *filename); - std::map> &get_sections() { return sections; }; - std::set get_value_as_set(std::string section, std::string key); - -private: - std::map> sections; - Settings() {} - static Settings settings; -}; diff --git a/src/util.c b/src/util.cpp similarity index 100% rename from src/util.c rename to src/util.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..816a060 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,122 @@ +cmake_minimum_required(VERSION 3.5) + +project(CameraManager) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + +find_package(PkgConfig REQUIRED) + +set(GSTREAMER_MINIMUM_VERSION 1.8) +pkg_check_modules(GST1_TEST gstreamer-1.0) + +if (NOT GST1_TEST_FOUND ) + message( FATAL_ERROR "GStreamer 1.8 required." ) +endif() +if ( ${GST1_TEST_VERSION} VERSION_LESS ${GSTREAMER_MINIMUM_VERSION} ) + message( FATAL_ERROR "GStreamer 1.8 required. Found ${GST1_TEST_VERSION} instead." ) +endif() + +pkg_check_modules(GST REQUIRED + gstreamer-rtsp-1.0 + gstreamer-1.0 + gstreamer-rtsp-server-1.0 + gstreamer-app-1.0 +) + +# Avahi +find_package(Avahi QUIET) +IF(Avahi_FOUND) + SET(DEFINES "${DEFINES} -DENABLE_AVAHI") + MESSAGE(STATUS "Found Avahi: ${Avahi_CLIENT_INCLUDE_DIRS}") +ENDIF(Avahi_FOUND) + +add_custom_target(tests) +add_dependencies(tests + test_camera_parameters + test_mavlink_protocol + test_rtsp_udp_stream_discovery +) + +add_definitions( + -std=c++11 + -Wall + -Wextra + -Wno-unused-parameter + -Wno-unused-variable + -Wno-missing-field-initializers + ${DEFINES} +) + +add_executable(test_camera_parameters + test_camera_parameters.cpp + ../src/glib_mainloop.cpp + ../src/log.cpp + ../src/mainloop.cpp + ../src/socket.cpp + ../src/pollable.cpp + ../src/util.cpp + ../src/CameraParameters.cpp +) +target_include_directories(test_camera_parameters PUBLIC + ${PROJECT_SOURCE_DIR}/../modules/mavlink/common + ${PROJECT_SOURCE_DIR}/../src + ${GST_INCLUDE_DIRS} +) +target_link_libraries(test_camera_parameters + pthread + ${GST_LIBRARIES} +) +IF(Avahi_FOUND) + target_link_libraries(test_camera_parameters + Avahi::client + Avahi::glib + ) +ENDIF(Avahi_FOUND) + +add_executable(test_mavlink_protocol + test_mavlink_protocol.cpp + ../src/glib_mainloop.cpp + ../src/log.cpp + ../src/mainloop.cpp + ../src/socket.cpp + ../src/pollable.cpp +) +target_include_directories(test_mavlink_protocol PUBLIC + ${PROJECT_SOURCE_DIR}/../modules/mavlink/common + ${PROJECT_SOURCE_DIR}/../src + ${GST_INCLUDE_DIRS} +) +target_link_libraries(test_mavlink_protocol + pthread + ${GST_LIBRARIES} +) +IF(Avahi_FOUND) + target_link_libraries(test_mavlink_protocol + Avahi::client + Avahi::glib + ) +ENDIF(Avahi_FOUND) + +IF(Avahi_FOUND) + add_executable(test_rtsp_udp_stream_discovery + test_rtsp_udp_stream_discovery.cpp + ../src/glib_mainloop.cpp + ../src/log.cpp + ../src/mainloop.cpp + ) + target_include_directories(test_rtsp_udp_stream_discovery PUBLIC + ${PROJECT_SOURCE_DIR}/../modules/mavlink/common + ${PROJECT_SOURCE_DIR}/../src + ${GST_INCLUDE_DIRS} + ) + target_link_libraries(test_rtsp_udp_stream_discovery + Avahi::client + Avahi::glib + ) +ENDIF(Avahi_FOUND) + +target_link_libraries(test_rtsp_udp_stream_discovery + pthread + ${GST_LIBRARIES} +) +