From 29667fce7c7145f95ec02a5b9e5b795c8322e3b0 Mon Sep 17 00:00:00 2001 From: Sebastiaan Lokhorst Date: Mon, 12 Dec 2016 01:46:44 +0100 Subject: [PATCH 1/2] Fix OpenBSD and NetBSD compilation --- conf.c | 4 ++-- conf.h | 2 +- logger.c | 2 +- motion.c | 6 +++--- motion.h | 9 +-------- netcam_rtsp.c | 4 +--- pwc-ioctl.h | 2 +- rotate.c | 8 +++++++- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/conf.c b/conf.c index 06131de9..d5021488 100644 --- a/conf.c +++ b/conf.c @@ -102,7 +102,7 @@ struct config conf_template = { .tuner_number = 0, .timelapse = 0, .timelapse_mode = DEF_TIMELAPSE_MODE, -#if (defined(__FreeBSD__)) +#ifdef __FreeBSD__ tuner_device: NULL, #endif .video_device = VIDEO_DEVICE, @@ -298,7 +298,7 @@ config_param config_params[] = { copy_int, print_int }, -#if (defined(__FreeBSD__)) +#ifdef __FreeBSD__ { "tunerdevice", "# Tuner device to be used for capturing using tuner as source (default /dev/tuner0)\n" diff --git a/conf.h b/conf.h index 9b91b73c..60ab991a 100644 --- a/conf.h +++ b/conf.h @@ -86,7 +86,7 @@ struct config { int tuner_number; int timelapse; const char *timelapse_mode; -#if (defined(BSD) || defined(__FreeBSD_kernel__)) +#ifdef __FreeBSD__ const char *tuner_device; #endif const char *video_device; diff --git a/logger.c b/logger.c index 6cde10ce..c1b5a8f3 100644 --- a/logger.c +++ b/logger.c @@ -192,7 +192,7 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . errno_save = errno; char threadname[32] = "unknown"; -#if (!defined(__FreeBSD__)) +#if (!defined(BSD) || defined(__APPLE__)) pthread_getname_np(pthread_self(), threadname, sizeof(threadname)); #endif diff --git a/motion.c b/motion.c index 41061424..b80cf4ee 100644 --- a/motion.c +++ b/motion.c @@ -13,7 +13,7 @@ #include "video_freebsd.h" #else #include "video.h" -#endif /* BSD */ +#endif #include "conf.h" #include "alg.h" @@ -2311,11 +2311,11 @@ static void become_daemon(void) MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not change directory"); -#if (defined(__FreeBSD__)) +#if (defined(BSD) && !defined(__APPLE__)) setpgrp(0, getpid()); #else setpgrp(); -#endif /* __FreeBSD__ */ +#endif if ((i = open("/dev/tty", O_RDWR)) >= 0) { diff --git a/motion.h b/motion.h index ca81d202..98f6123d 100644 --- a/motion.h +++ b/motion.h @@ -12,10 +12,6 @@ #include "config.h" -#if defined(__FreeBSD__) || defined(__NetBSD__) -#define BSD -#endif - /* Includes */ #ifdef HAVE_MYSQL #include @@ -58,7 +54,7 @@ #ifdef __APPLE__ #define MOTION_PTHREAD_SETNAME(name) pthread_setname_np(name) -#elif defined(__FreeBSD__) +#elif defined(BSD) #define MOTION_PTHREAD_SETNAME(name) pthread_set_name_np(pthread_self(), name) #else #define MOTION_PTHREAD_SETNAME(name) pthread_setname_np(pthread_self(), name) @@ -404,9 +400,6 @@ struct context { int missing_frame_counter; /* counts failed attempts to fetch picture frame from camera */ unsigned int lost_connection; -#if (defined(BSD)) - int tuner_dev; -#endif int video_dev; int pipe; int mpipe; diff --git a/netcam_rtsp.c b/netcam_rtsp.c index 811a66cc..60fabc92 100644 --- a/netcam_rtsp.c +++ b/netcam_rtsp.c @@ -463,10 +463,8 @@ static int netcam_rtsp_open_context(netcam_context_ptr netcam){ * desired name */ { char newtname[16]; -#if defined(__FreeBSD__) char curtname[16] = "unknown"; -#else - char curtname[16]; +#if (!defined(BSD) || defined(__APPLE__)) pthread_getname_np(pthread_self(), curtname, sizeof(curtname)); #endif snprintf(newtname, sizeof(newtname), "av%d%s%s", diff --git a/pwc-ioctl.h b/pwc-ioctl.h index 3dbbac35..5f44c082 100644 --- a/pwc-ioctl.h +++ b/pwc-ioctl.h @@ -323,6 +323,6 @@ struct pwc_raw_frame { __u8 rawframe[0]; /* frame_size = H/4*vbandlength */ } __attribute__ ((packed)); -#endif /* MOTION_V4L2 && (! BSD ) */ +#endif /* MOTION_V4L2 && __linux__ */ #endif diff --git a/rotate.c b/rotate.c index 0a7fd314..8b5d6985 100644 --- a/rotate.c +++ b/rotate.c @@ -34,9 +34,15 @@ #if defined(__APPLE__) #include #define bswap_32(x) OSSwapInt32(x) -#elif defined(BSD) +#elif defined(__FreeBSD__) #include #define bswap_32(x) bswap32(x) +#elif defined(__OpenBSD__) +#include +#define bswap_32(x) swap32(x) +#elif defined(__NetBSD__) +#include +#define bswap_32(x) bswap32(x) #else #include #endif From 92ea490df9889053364ca674b7d611fab011527b Mon Sep 17 00:00:00 2001 From: Sebastiaan Lokhorst Date: Mon, 12 Dec 2016 20:11:44 +0100 Subject: [PATCH 2/2] Fix track.c with V4L2 --- track.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/track.c b/track.c index 3bc77197..6e19ddcd 100644 --- a/track.c +++ b/track.c @@ -5,13 +5,11 @@ * Copyright 2000, Jeroen Vreeken * This program is published under the GNU Public license */ -#ifdef MOTION_V4L2 -#include -#endif /* MOTION_V4L2 */ #include #include "motion.h" -#if (defined(HAVE_LINUX_VIDEODEV_H) || defined(HAVE_SYS_VIDEOIO_H)) && (!defined(WITHOUT_V4L)) +#ifdef MOTION_V4L2 +#include #include "pwc-ioctl.h" #endif @@ -54,16 +52,14 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, struct images *imgs, unsigned int manual); static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs); -#if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L)) +#ifdef MOTION_V4L2 static unsigned int lqos_center(struct context *cnt, int dev, int xoff, int yoff); static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual); -#ifdef MOTION_V4L2 static unsigned int uvc_center(struct context *cnt, int dev, int xoff, int yoff); static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs, unsigned int manual); #endif /* MOTION_V4L2 */ -#endif /* WITHOUT_V4L */ /* Add a call to your functions here: */ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, @@ -83,14 +79,12 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, } else if (cnt->track.type == TRACK_TYPE_SERVO) { return servo_center(cnt, xoff, yoff); } -#if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L)) +#ifdef MOTION_V4L2 else if (cnt->track.type == TRACK_TYPE_PWC) return lqos_center(cnt, dev, xoff, yoff); -#ifdef MOTION_V4L2 else if (cnt->track.type == TRACK_TYPE_UVC) return uvc_center(cnt, dev, xoff, yoff); -#endif /* MOTION_V4L2 */ -#endif /* WITHOUT_V4L */ +#endif else if (cnt->track.type == TRACK_TYPE_IOMOJO) return iomojo_center(cnt, xoff, yoff); else if (cnt->track.type == TRACK_TYPE_GENERIC) @@ -114,14 +108,12 @@ unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct return stepper_move(cnt, cent, imgs); else if (cnt->track.type == TRACK_TYPE_SERVO) return servo_move(cnt, cent, imgs, manual); -#if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L)) +#ifdef MOTION_V4L2 else if (cnt->track.type == TRACK_TYPE_PWC) return lqos_move(cnt, dev, cent, imgs, manual); -#ifdef MOTION_V4L2 else if (cnt->track.type == TRACK_TYPE_UVC) return uvc_move(cnt, dev, cent, imgs, manual); -#endif /* MOTION_V4L2 */ -#endif /* WITHOUT_V4L */ +#endif else if (cnt->track.type == TRACK_TYPE_IOMOJO) return iomojo_move(cnt, dev, cent, imgs); else if (cnt->track.type == TRACK_TYPE_GENERIC) @@ -788,7 +780,7 @@ static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent Logitech QuickCam Orbit camera tracking code by folkert@vanheusden.com ******************************************************************************/ -#if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L)) +#ifdef MOTION_V4L2 static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y_angle) { int reset = 3; @@ -907,6 +899,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, return cnt->track.move_wait; } + /****************************************************************************** Logitech QuickCam Sphere camera tracking code by oBi @@ -915,8 +908,6 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, - for new API in uvcvideo - add Trace-steps for investigation ******************************************************************************/ -#ifdef MOTION_V4L2 - static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_angle) { /* CALC ABSOLUTE MOVING : Act.Position +/- delta to request X and Y */ @@ -1229,4 +1220,3 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, return cnt->track.move_wait; } #endif /* MOTION_V4L2 */ -#endif /* WITHOUT_V4L */