diff --git a/.gitignore b/.gitignore index 9e38ca5..b730f6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,17 @@ *.log .svn/ *.o +.depend +motion +config.h +config.status +Makefile +motion-dist.conf +motion.init-Debian +motion.init-Fedora +motion.init-FreeBSD.sh +motion.spec +thread1.conf +thread2.conf +thread3.conf +thread4.conf diff --git a/CHANGELOG b/CHANGELOG index 10ca2c2..5b3d285 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,6 +49,40 @@ Features http://www.lavrsen.dk/foswiki/bin/view/Motion/OggTimelapse (Michael Luich) * Added support for ffmpeg 0.11 new API. * Added RSTP support for netcam ( merge https://github.com/hyperbolic2346/motion ) + * Merge tosiara/rtsp branch (commit 46cfcf31d, 2014/05/21) (Mr-Dave) + * 3fps bugfix from SVN rev559 (tosiara, Joerg Weber) + * Buffer overflow vulnerabilities (hyperbolic2346) + * Redundand -- boundary prefix (torao) + * Proper size for memset and allocation size (Alfred Klomp) + * Removed compiler warnings: (Mr-Dave) + logger.c,jpegutils.c,netcam_ftp.c,track.c, + picture.c,webhttpd.c,stream.c,ffmpeg.c + * Bug fix as part of warnings in webhttpd.c fixed(Mr-Dave) + * Removed compiler warning regarding ffmpeg being newer than 0.4 version(Mr-Dave) + * New configure script and identification of ffmpeg version and additional libs. (Mr-Dave) + * Resolve additional compiler warnings in ffmpeg (Mr-Dave) + * Revised INSTALL with samples(Mr-Dave) + * Revisions for RTSP and code standard.(Mr-Dave) + * Plugged most(?) memory leaks in RTSP. (Mr-Dave) + * Undo changes caused by code editor and other unnecessary changes (Mr-Dave) + * Moved call to netcam_shutdown_rtsp into netcam_cleanup where it belongs. (Mr-Dave) + * Regession fix for memory leaks and reconnection (Mr-Dave) + * Eliminated requirement to manually build FFMPEG for RTSP support. (Mr-Dave) + * Revised RTSP to support version 53 of libavformat (Mr-Dave) + * Revised FFMPEG.c to eliminate warnings and functions no longer supported by Libav/FFMPEG(Mr-Dave) + * Revised INSTALL to have sample PI configure option.(Mr-Dave) + * Revised configure.ac to generate compiler flag AVFMT_V53.(Mr-Dave) + * Revised INSTALL to indicate standard APT packages for RTSP (Mr-Dave) + * Revised configure.ac to recognize libavformat version 54 RTSP (Mr-Dave) + * Clean up the messaging for RTSP. + * Additional validations for RTSP connection and corrected free sequences + * Removed seg fault on failure to open first image, comments, isolation of RTSP + * Add AC_GNU_SOURCE macro to check for GNU C Library, fix compile when no FFMpeg. + * Implement inits of AV functions from bcl fork + * Add gray image upon disconnection + * Added tcp/udp transport config option from hyperbolic(commit 423ef7bb3) + * Revised comments to be in line with application standard. + * Restructure rtsp to handle rescaling and non YUV420 format, rotate, MJPEG input format Bugfixes * Avoid segfault detecting strerror_r() version GNU or SUSv3. (Angel Carpintero) diff --git a/INSTALL b/INSTALL index 5063740..8773bff 100644 --- a/INSTALL +++ b/INSTALL @@ -1,16 +1,61 @@ -Very simple: +NOTE: Versions come, versions go, packages change, etc. These instructions are intended as a starting point + and may need modification by the time you read this. -type: +********************************** +*** DEBIAN BASED SYSTEMS *** +Required Packages: + sudo apt-get install autoconf automake build-essential libtool libjpeg8-dev libzip-dev + +Obtain source code (via git) + sudo apt-get install git + cd ~ + git clone {https://github.com/your favorite fork} + +To rebuild the motion configure file use + autoreconf + +Optional: With FFMPEG support: + Build FFMPEG via their instructions + Configure with manually built ffmpeg which currently installs to ~/bin and ~/ffmpeg_build + Basic + ./configure --with-ffmpeg=$HOME/ffmpeg_build --with-ffmpeg-headers=$HOME/ffmpeg_build/include + + With extra libraries for ffmpeg IMPORTANT NOTE: Your libraries will vary depending upon your build of FFMPEG + ./configure --with-ffmpeg=$HOME/ffmpeg_build --with-ffmpeg-headers=$HOME/ffmpeg_build/include --with-ffmpeg-libs=" -lavformat -lswscale -lavcodec -lavutil -lfdk-aac -lswresample -lm -lopus -lz -lva -lvpx -lx264 -lmp3lame -lbz2 -ldl -lvorbisenc -lvorbis -ltheoraenc -ltheoradec " + + With extra libraries for ffmpeg and install to ~/motion_build + ./configure --prefix=$HOME/motion_build --with-ffmpeg=$HOME/ffmpeg_build --with-ffmpeg-headers=$HOME/ffmpeg_build/include --with-ffmpeg-libs=" -lavformat -lswscale -lavcodec -lavutil -lfdk-aac -lswresample -lm -lopus -lz -lva -lvpx -lx264 -lmp3lame -lbz2 -ldl -lvorbisenc -lvorbis -ltheoraenc -ltheoradec " + +With LIBAV APT versions of libraries + sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev libav-tools libswscale-dev + +Without any LIBAV/FFMPEG support or the installed version of libavcodec/libavformat ./configure -followed by: +Sample PI configuration with LIBAV + ./configure --with-ffmpeg=/usr/lib/arm-linux-gnueabihf --with-ffmpeg-headers=/usr/include + +Once configured type: make + make install -And +***************************** +*** OpenSUSE SYSTEM *** +sudo zypper install autoconf automake libtool git +sudo zypper install --type pattern devel_basis +sudo zypper install libjpeg8-devel +sudo zypper install -t pattern devel_C_C++ + +Optional: FFmpeg files +sudo zypper ar -f -n packman-essentials http://packman.inode.at/suse/openSUSE_13.1/Essentials/ packman-essentials +sudo zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_13.1/Multimedia/ packman-multimedia +sudo zypper install libffmpeg-devel + +./configure + make make install - -Next read the README +************************* diff --git a/alg.c b/alg.c index 93c260f..343ff47 100644 --- a/alg.c +++ b/alg.c @@ -534,7 +534,7 @@ static int alg_labeling(struct context *cnt) imgs->labels_above = 0; /* Init: 0 means no label set / not checked. */ - memset(labels, 0, width * height * sizeof(labels)); + memset(labels, 0, width * height * sizeof(*labels)); pixelpos = 0; for (iy = 0; iy < height - 1; iy++) { @@ -1363,6 +1363,6 @@ void alg_update_reference_frame(struct context *cnt, int action) /* Copy fresh image */ memcpy(cnt->imgs.ref, cnt->imgs.image_virgin, cnt->imgs.size); /* Reset static objects */ - memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(cnt->imgs.ref_dyn)); + memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(*cnt->imgs.ref_dyn)); } } diff --git a/conf.c b/conf.c index 2da0da6..cf905c6 100644 --- a/conf.c +++ b/conf.c @@ -146,6 +146,7 @@ struct config conf_template = { netcam_keepalive: "off", netcam_proxy: NULL, netcam_tolerant_check: 0, + rtsp_uses_tcp: 1, text_changes: 0, text_left: NULL, text_right: DEF_TIMESTAMP, @@ -411,6 +412,15 @@ config_param config_params[] = { print_bool }, { + "rtsp_uses_tcp", + "# RTSP connection uses TCP to communicate to the camera. Can prevent image corruption.\n" + "# Default: on", + 1, + CONF_OFFSET(rtsp_uses_tcp), + copy_bool, + print_bool + }, + { "auto_brightness", "# Let motion regulate the brightness of a video device (default: off).\n" "# The auto_brightness feature uses the brightness option as its target value.\n" @@ -1569,17 +1579,23 @@ static void conf_cmdline(struct context *cnt, int thread) cnt->log_level = (unsigned int)atoi(optarg); break; case 'k': - if (thread == -1) - strcpy(cnt->log_type_str, optarg); - break; + if (thread == -1) { + strncpy(cnt->log_type_str, optarg, sizeof(cnt->log_type_str) - 1); + cnt->log_type_str[sizeof(cnt->log_type_str) - 1] = '\0'; + } + break; case 'p': - if (thread == -1) - strcpy(cnt->pid_file, optarg); - break; + if (thread == -1) { + strncpy(cnt->pid_file, optarg, sizeof(cnt->pid_file) - 1); + cnt->pid_file[sizeof(cnt->pid_file) - 1] = '\0'; + } + break; case 'l': - if (thread == -1) - strcpy(cnt->log_file, optarg); - break; + if (thread == -1) { + strncpy(cnt->log_file, optarg, sizeof(cnt->log_file) - 1); + cnt->log_file[sizeof(cnt->log_file) - 1] = '\0'; + } + break; case 'm': cnt->pause = 1; break; @@ -1868,8 +1884,9 @@ struct context **conf_load(struct context **cnt) conf_cmdline(cnt[0], -1); if (cnt[0]->conf_filename[0]) { /* User has supplied filename on Command-line. */ - strcpy(filename, cnt[0]->conf_filename); - fp = fopen (filename, "r"); + strncpy(filename, cnt[0]->conf_filename, PATH_MAX-1); + filename[PATH_MAX-1] = '\0'; + fp = fopen (filename, "r"); } if (!fp) { /* Command-line didn't work, try current dir. */ @@ -1905,11 +1922,12 @@ struct context **conf_load(struct context **cnt) /* Now we process the motion.conf config file and close it. */ if (fp) { - strcpy(cnt[0]->conf_filename, filename); - MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", - filename); - cnt = conf_process(cnt, fp); - myfclose(fp); + strncpy(cnt[0]->conf_filename, filename, sizeof(cnt[0]->conf_filename) - 1); + cnt[0]->conf_filename[sizeof(cnt[0]->conf_filename) - 1] = '\0'; + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", + filename); + cnt = conf_process(cnt, fp); + myfclose(fp); } else { MOTION_LOG(CRT, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values"); } diff --git a/conf.h b/conf.h index b03397e..c487b9e 100644 --- a/conf.h +++ b/conf.h @@ -123,6 +123,7 @@ struct config { const char *netcam_keepalive; const char *netcam_proxy; unsigned int netcam_tolerant_check; + unsigned int rtsp_uses_tcp; int text_changes; const char *text_left; const char *text_right; diff --git a/config.h.in b/config.h.in index 31262da..ac42b9c 100644 --- a/config.h.in +++ b/config.h.in @@ -1,4 +1,4 @@ -/* config.h.in. Generated from configure.in by autoheader. */ +/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H @@ -108,20 +108,37 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif + + +/* Define to 1 if on MINIX. */ +#undef _MINIX + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#undef _POSIX_1_SOURCE + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#undef _POSIX_SOURCE + /* Define to empty if `const' does not conform to ANSI C. */ #undef const - -/* Define to 1 if you have av_avformat_alloc_context support */ -#undef have_av_avformat_alloc_context - -/* Define to 1 if you have av_get_media_type_string support */ -#undef have_av_get_media_type_string - -/* Define to 1 if you have av_register_protocol support */ -#undef have_av_register_protocol - -/* Define to 1 if you have av_register_protocol2 support */ -#undef have_av_register_protocol2 - -/* Define to 1 if you have avformat_alloc_context support */ -#undef have_avformat_alloc_context diff --git a/configure b/configure index 57b6bde..d6d7ee5 100755 --- a/configure +++ b/configure @@ -1,9 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for motion Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0. +# Generated by GNU Autoconf 2.68 for motion trunkREVUNKNOWN. # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -132,31 +134,6 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -190,8 +167,7 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -236,25 +212,21 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -356,14 +328,6 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -485,10 +449,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -523,16 +483,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -544,8 +504,28 @@ else as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -577,12 +557,11 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='motion' PACKAGE_TARNAME='motion' -PACKAGE_VERSION='Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0' -PACKAGE_STRING='motion Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0' +PACKAGE_VERSION='trunkREVUNKNOWN' +PACKAGE_STRING='motion trunkREVUNKNOWN' PACKAGE_BUGREPORT='' PACKAGE_URL='' -ac_unique_file="motion.c" # Factoring default headers for most tests. ac_includes_default="\ #include @@ -619,16 +598,17 @@ ac_includes_default="\ # include #endif" +ac_unique_file="motion.c" ac_subst_vars='LTLIBOBJS LIBOBJS BIN_PATH -EGREP -GREP -CPP RTPS_OBJ FFMPEG_OBJ SDL_OBJ VIDEO +EGREP +GREP +CPP OBJEXT EXEEXT ac_ct_CC @@ -686,6 +666,7 @@ with_jpeg_turbo with_jpeg_mmx with_ffmpeg with_ffmpeg_headers +with_ffmpeg_libs with_sqlite3 with_mysql with_mysql_lib @@ -1160,6 +1141,8 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1245,7 +1228,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures motion Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0 to adapt to many kinds of systems. +\`configure' configures motion trunkREVUNKNOWN to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1306,7 +1289,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of motion Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0:";; + short | recursive ) echo "Configuration of motion trunkREVUNKNOWN:";; esac cat <<\_ACEOF @@ -1344,6 +1327,8 @@ Optional Packages: --with-ffmpeg-headers=DIR Specify the prefix for ffmpeg headers. + --with-ffmpeg-libs=libs Specify the extra libs for ffmpeg + --without-sqlite3 Disable sqlite3 support in motion. --without-mysql Disable mysql support in motion. @@ -1454,10 +1439,10 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -motion configure Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0 -generated by GNU Autoconf 2.69 +motion configure trunkREVUNKNOWN +generated by GNU Autoconf 2.68 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1506,52 +1491,6 @@ fi } # ac_fn_c_try_compile -# ac_fn_c_try_link LINENO -# ----------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_link () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - test -x conftest$ac_exeext - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information - # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would - # interfere with the next link command; also delete a directory that is - # left behind by Apple's compiler. We do this before executing the actions. - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_link - # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. @@ -1589,48 +1528,6 @@ fi } # ac_fn_c_try_cpp -# ac_fn_c_try_run LINENO -# ---------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes -# that executables *can* be run. -ac_fn_c_try_run () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then : - ac_retval=0 -else - $as_echo "$as_me: program exited with status $ac_status" >&5 - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=$ac_status -fi - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_run - # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using @@ -1718,6 +1615,48 @@ fi } # ac_fn_c_check_header_mongrel +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in @@ -1749,6 +1688,52 @@ $as_echo "$ac_res" >&6; } } # ac_fn_c_check_header_compile +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly @@ -1887,8 +1872,7 @@ int main () { static int test_array [1 - 2 * !(($2) >= 0)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -1904,8 +1888,7 @@ int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -1931,8 +1914,7 @@ int main () { static int test_array [1 - 2 * !(($2) < 0)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -1948,8 +1930,7 @@ int main () { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -1983,8 +1964,7 @@ int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; -test_array [0] = 0; -return test_array [0]; +test_array [0] = 0 ; return 0; @@ -2056,8 +2036,8 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by motion $as_me Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by motion $as_me trunkREVUNKNOWN, which was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2404,9 +2384,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu - -ac_config_headers="$ac_config_headers config.h" - ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -2429,7 +2406,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2469,7 +2446,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2522,7 +2499,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2563,7 +2540,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2621,7 +2598,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2665,7 +2642,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3111,7 +3088,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3197,25 +3175,1028 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu - -THREAD_CFLAGS="" -THREAD_CHECK="/usr/include/pthread.h" - -Darwin="" -FreeBSD="" - -LINUXTHREADS="no" - -# Check whether --with-linuxthreads was given. -if test "${with_linuxthreads+set}" = set; then : - withval=$with_linuxthreads; LINUXTHREADS="$withval" - +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext -PWCBSD="no" - -# Check whether --with-pwcbsd was given. + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + + ac_fn_c_check_header_mongrel "$LINENO" "minix/config.h" "ac_cv_header_minix_config_h" "$ac_includes_default" +if test "x$ac_cv_header_minix_config_h" = xyes; then : + MINIX=yes +else + MINIX= +fi + + + if test "$MINIX" = yes; then + +$as_echo "#define _POSIX_SOURCE 1" >>confdefs.h + + +$as_echo "#define _POSIX_1_SOURCE 2" >>confdefs.h + + +$as_echo "#define _MINIX 1" >>confdefs.h + + fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5 +$as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; } +if ${ac_cv_safe_to_define___extensions__+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +# define __EXTENSIONS__ 1 + $ac_includes_default +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_safe_to_define___extensions__=yes +else + ac_cv_safe_to_define___extensions__=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_safe_to_define___extensions__" >&5 +$as_echo "$ac_cv_safe_to_define___extensions__" >&6; } + test $ac_cv_safe_to_define___extensions__ = yes && + $as_echo "#define __EXTENSIONS__ 1" >>confdefs.h + + $as_echo "#define _ALL_SOURCE 1" >>confdefs.h + + $as_echo "#define _GNU_SOURCE 1" >>confdefs.h + + $as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h + + $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h + + + + +ac_config_headers="$ac_config_headers config.h" + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +THREAD_CFLAGS="" +THREAD_CHECK="/usr/include/pthread.h" + +Darwin="" +FreeBSD="" + +LINUXTHREADS="no" + +# Check whether --with-linuxthreads was given. +if test "${with_linuxthreads+set}" = set; then : + withval=$with_linuxthreads; LINUXTHREADS="$withval" + +fi + + +PWCBSD="no" + +# Check whether --with-pwcbsd was given. if test "${with_pwcbsd+set}" = set; then : withval=$with_pwcbsd; PWCBSD="$withval" @@ -3303,7 +4284,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3343,7 +4324,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3396,7 +4377,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3437,7 +4418,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -3495,7 +4476,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3539,7 +4520,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3735,7 +4716,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3851,7 +4833,7 @@ fi if test "${BKTR}" = "no"; then - TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L" + TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L" fi else @@ -3885,10 +4867,10 @@ $as_echo_n "checking for linuxthreads... " >&6; } # Check for thread header # if test -f "${THREAD_CHECK}"; then - HEADERS_THREAD_CFLAGS="-I/usr/local/include/pthread/linuxthreads" - THREADS="yes" + HEADERS_THREAD_CFLAGS="-I/usr/local/include/pthread/linuxthreads" + THREADS="yes" else - THREADS="no" + THREADS="no" fi # @@ -3898,7 +4880,7 @@ $as_echo_n "checking for linuxthreads... " >&6; } THREADS="yes" LIB_THREAD="-llthread -llgcc_r" else - THREADS="no" + THREADS="no" fi # Checks for Library linuxthreads for FreeBSD @@ -3930,7 +4912,6 @@ elif test -f "${THREAD_CHECK}"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking threads" >&5 $as_echo_n "checking threads... " >&6; } - cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -4277,6 +5258,7 @@ fi # # Check for libavcodec and libavformat from ffmpeg # + FFMPEG_DIR="yes" FFMPEG_OK="no_found" FFMPEG_OBJ="" @@ -4300,6 +5282,18 @@ if test "${with_ffmpeg_headers+set}" = set; then : fi +# +# ffmpeg custom extra libraries +# +FFMPEG_EXTRALIBS=" -lavformat -lavcodec -lavutil -lm -lz -lswscale " + +# Check whether --with-ffmpeg-libs was given. +if test "${with_ffmpeg_libs+set}" = set; then : + withval=$with_ffmpeg_libs; FFMPEG_EXTRALIBS="$withval" + +fi + + # # --without-ffmpeg or with-ffmpeg=no # @@ -4340,6 +5334,12 @@ $as_echo "found in /usr/lib/x86_64-linux-gnu" >&6; } FFMPEG_OK="found" FFMPEG_LIB="/usr/lib/x86_64-linux-gnu" FFMPEG_DIR="/usr" + elif test -f /usr/lib/i386-linux-gnu/libavcodec.a -o -f /usr/lib/i386-linux-gnu/libavcodec.so && test /usr/lib/i386-linux-gnu/libavformat.a -o -f /usr/lib/i386-linux-gnu/libavformat.so ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: found in /usr/lib/i386-linux-gnu" >&5 +$as_echo "found in /usr/lib/i386-linux-gnu" >&6; } + FFMPEG_OK="found" + FFMPEG_LIB="/usr/lib/i386-linux-gnu" + FFMPEG_DIR="/usr" else { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 $as_echo "not found" >&6; } @@ -4385,51 +5385,63 @@ $as_echo "not found" >&6; } fi fi + # # Now check for ffmpeg headers ( avformat.h ) if ffmpeg libs were found # +AVFORMAT_DIR="" + if test "${FFMPEG_OK}" = "found"; then if test "${FFMPEG_HEADERS_DIR}" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffmpeg headers in ${FFMPEG_DIR}" >&5 $as_echo_n "checking for ffmpeg headers in ${FFMPEG_DIR}... " >&6; } - else + AVFORMAT_DIR="${FFMPEG_DIR}" + else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ffmpeg headers in ${FFMPEG_HEADERS_DIR}" >&5 $as_echo_n "checking for ffmpeg headers in ${FFMPEG_HEADERS_DIR}... " >&6; } FFMPEG_DIR="${FFMPEG_HEADERS_DIR}" + AVFORMAT_DIR="${FFMPEG_DIR}" fi if test -f ${FFMPEG_DIR}/include/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/include/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/include/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include" + AVFORMAT_DIR="${FFMPEG_DIR}/include/avformat.h" elif test -f ${FFMPEG_DIR}/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR}" + AVFORMAT_DIR="${FFMPEG_DIR}/avformat.h" elif test -f ${FFMPEG_DIR}/include/ffmpeg/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/include/ffmpeg/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/include/ffmpeg/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include/ffmpeg" + AVFORMAT_DIR="${FFMPEG_DIR}/include/ffmpeg/avformat.h" elif test -f ${FFMPEG_DIR}/include/libavformat/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/include/libavformat/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/include/libavformat/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include -DFFMPEG_NEW_INCLUDES" AVFORMAT="-I${FFMPEG_DIR}/include/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/include/libavformat/avformat.h" elif test -f ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include/ffmpeg -DFFMPEG_NEW_INCLUDES" AVFORMAT="-I${FFMPEG_DIR}/include/ffmpeg/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h" elif test -f ${FFMPEG_DIR}/libavformat/avformat.h; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${FFMPEG_DIR}/libavformat/avformat.h" >&5 $as_echo "found ${FFMPEG_DIR}/libavformat/avformat.h" >&6; } FFMPEG_CFLAGS="-I${FFMPEG_DIR} -DFFMPEG_NEW_INCLUDES" AVFORMAT="-I{FFMPEG_DIR}/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/libavformat/avformat.h" else { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 $as_echo "not found" >&6; } FFMPEG_OK="no_found" + AVFORMAT_DIR="avformat.h" echo "**********************************************" echo "* avformat.h not found: *" echo "* ALL FFMPEG FEATURES DISABLED *" @@ -4444,36 +5456,32 @@ $as_echo "not found" >&6; } # If ffmpeg libs and headers have been found # - if test "${FFMPEG_OK}" = "found"; then - TEMP_LIBS="$TEMP_LIBS -L${FFMPEG_LIB} -lavformat -lavcodec -lavutil -lm -lz" + if test "${FFMPEG_OK}" = "found"; then + TEMP_LIBS="$TEMP_LIBS -L${FFMPEG_LIB} ${FFMPEG_EXTRALIBS}" TEMP_LDFLAGS="${TEMP_LDFLAGS} -L${FFMPEG_LIB}" TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG ${FFMPEG_CFLAGS}" FFMPEG_OBJ="ffmpeg.o" - RTPS_OBJ="netcam_rtsp.o" - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking file_protocol is defined in ffmpeg ?" >&5 $as_echo_n "checking file_protocol is defined in ffmpeg ?... " >&6; } saved_CFLAGS=$CFLAGS saved_LIBS=$LIBS + CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" + LIBS="$TEMP_LIBS" - CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" - LIBS="$TEMP_LIBS" - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include - URLProtocol test_file_protocol; - int main(void){ - test_file_protocol.url_read = file_protocol.url_read; - return 0; - } + #include <${AVFORMAT_DIR}> + URLProtocol test_file_protocol; + int main(void){ + test_file_protocol.url_read = file_protocol.url_read; + return 0; + } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : @@ -4481,19 +5489,24 @@ if ac_fn_c_try_compile "$LINENO"; then : $as_echo "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_NEW" + TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_NEW" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - CFLAGS=$saved_CFLAGS - LIBS=$saved_LIBS - fi + CFLAGS=$saved_CFLAGS + LIBS=$saved_LIBS + fi fi fi +# Revised RTSP module so that it can be included +# whether or not FFMPEG is found. + + RTPS_OBJ="netcam_rtsp.o" + # # Check SQLITE3 @@ -4650,8 +5663,8 @@ $as_echo "skipped" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql headers in $MYSQL_HEADERS" >&5 $as_echo_n "checking for mysql headers in $MYSQL_HEADERS... " >&6; } # Manual detection for - if test -f $MYSQL_HEADERS/mysql.h; then - MYSQL_INCDIR=$MYSQL_HEADERS + if test -f $MYSQL_HEADERS/mysql.h; then + MYSQL_INCDIR=$MYSQL_HEADERS fi fi @@ -4673,7 +5686,7 @@ $as_echo "$MYSQL_INCDIR yes" >&6; } if test "${MYSQL_LIBS}" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking autodect mysql libs" >&5 $as_echo_n "checking autodect mysql libs... " >&6; } - # Autodetect + # Autodetect for w in /usr/lib64 /usr/lib /usr/local/lib /usr/mysql /usr/local/mysql /usr/local/mysql/lib /opt /opt/mysql /usr/lib/x86_64-linux-gnu; do # check for plain setups if test -f $w/libmysqlclient.a -o -f $w/libmysqlclient.so; then @@ -4692,7 +5705,7 @@ $as_echo_n "checking autodect mysql libs... " >&6; } fi done elif test "${MYSQL_LIBS}" = "no"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql libs" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mysql libs" >&5 $as_echo_n "checking for mysql libs... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: skipped" >&5 $as_echo "skipped" >&6; } @@ -4847,8 +5860,8 @@ $as_echo "skipped" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pgsql headers in $PGSQL_HEADERS" >&5 $as_echo_n "checking for pgsql headers in $PGSQL_HEADERS... " >&6; } # Manual detection for - if test -f $PGSQL_HEADERS/libpq-fe.h; then - PGSQL_INCDIR=$PGSQL_HEADERS + if test -f $PGSQL_HEADERS/libpq-fe.h; then + PGSQL_INCDIR=$PGSQL_HEADERS fi fi @@ -4872,377 +5885,109 @@ $as_echo "yes $PGSQL_INCDIR" >&6; } $as_echo_n "checking autodect pgsql libs... " >&6; } # Autodetect PGSQL_INCLUDE="-I$PGSQL_INCDIR" - PGSQL_LIBDIR=$PGSQL_DIR/lib - - if test -f /usr/lib64/libpq.so ; then - PGSQL_LIBDIR=/usr/lib64 - elif test -f $PGSQL_DIR/lib/pgsql/libpq.so ; then - PGSQL_LIBDIR=$PGSQL_DIR/lib/pgsql - elif test -f $PGSQL_DIR/lib/postgresql/libpq.so ; then - PGSQL_LIBDIR=$PGSQL_DIR/lib/postgresql - elif test -f $PGSQL_DIR/lib/libpq.so ; then - PGSQL_LIBDIR=$PGSQL_DIR/lib - else - PGSQL_LIBDIR="" - fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PGSQL_LIBDIR" >&5 -$as_echo "$PGSQL_LIBDIR" >&6; } - - elif test "${PGSQL_LIBS}" = "no"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pgsql libs" >&5 -$as_echo_n "checking for pgsql libs... " >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: result: skipped" >&5 -$as_echo "skipped" >&6; } - else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pgsql libs in $PGSQL_LIBS" >&5 -$as_echo_n "checking for pgsql libs in $PGSQL_LIBS... " >&6; } - # Manual detection for - if test -f $PGSQL_LIBS/libpq.a -o -f $PGSQL_LIBS/libpq.so; then - PGSQL_LIBDIR=$PGSQL_LIBS - fi - fi - - - if test -z "$PGSQL_LIBDIR" ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -$as_echo "not found" >&6; } - echo "Invalid PostgreSQL directory $PGSQL_LIBDIR - unable to find libpq.a or libpq.so." - else - #LDFLAGS="$TEMP_LDFLAGS -L$PGSQL_LIBDIR" - saved_CFLAGS=$CFLAGS - saved_LIBS=$LIBS - CFLAGS="-I$PGSQL_INCDIR" - LIBS="-L$PGSQL_LIBDIR" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PQconnectStart in -lpq" >&5 -$as_echo_n "checking for PQconnectStart in -lpq... " >&6; } -if ${ac_cv_lib_pq_PQconnectStart+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lpq $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char PQconnectStart (); -int -main () -{ -return PQconnectStart (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_pq_PQconnectStart=yes -else - ac_cv_lib_pq_PQconnectStart=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pq_PQconnectStart" >&5 -$as_echo "$ac_cv_lib_pq_PQconnectStart" >&6; } -if test "x$ac_cv_lib_pq_PQconnectStart" = xyes; then : - - PGSQL_SUPPORT="yes" - TEMP_LIBS="$TEMP_LIBS -L$PGSQL_LIBDIR -lpq" - TEMP_CFLAGS="$TEMP_CFLAGS -I$PGSQL_INCDIR" - -$as_echo "#define HAVE_PGSQL 1" >>confdefs.h - - -else - as_fn_error $? "PostgreSQL support can't build without PostgreSQL libraries" "$LINENO" 5 -fi - - LDFLAGS="" - CFLAGS=$saved_CFLAGS - LIBS=$saved_LIBS - fi - - fi # end pgsql-include , pgsql-libs - -# end PostgreSQL detection -fi - - -#Checks for header files. -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if ${ac_cv_prog_CPP+:} false; then : - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 -$as_echo "$CPP" >&6; } -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : + PGSQL_LIBDIR=$PGSQL_DIR/lib -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5; } -fi + if test -f /usr/lib64/libpq.so ; then + PGSQL_LIBDIR=/usr/lib64 + elif test -f $PGSQL_DIR/lib/pgsql/libpq.so ; then + PGSQL_LIBDIR=$PGSQL_DIR/lib/pgsql + elif test -f $PGSQL_DIR/lib/postgresql/libpq.so ; then + PGSQL_LIBDIR=$PGSQL_DIR/lib/postgresql + elif test -f $PGSQL_DIR/lib/libpq.so ; then + PGSQL_LIBDIR=$PGSQL_DIR/lib + else + PGSQL_LIBDIR="" + fi -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PGSQL_LIBDIR" >&5 +$as_echo "$PGSQL_LIBDIR" >&6; } + + elif test "${PGSQL_LIBS}" = "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pgsql libs" >&5 +$as_echo_n "checking for pgsql libs... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: skipped" >&5 +$as_echo "skipped" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pgsql libs in $PGSQL_LIBS" >&5 +$as_echo_n "checking for pgsql libs in $PGSQL_LIBS... " >&6; } + # Manual detection for + if test -f $PGSQL_LIBS/libpq.a -o -f $PGSQL_LIBS/libpq.so; then + PGSQL_LIBDIR=$PGSQL_LIBS + fi + fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if ${ac_cv_path_GREP+:} false; then : + if test -z "$PGSQL_LIBDIR" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 +$as_echo "not found" >&6; } + echo "Invalid PostgreSQL directory $PGSQL_LIBDIR - unable to find libpq.a or libpq.so." + else + #LDFLAGS="$TEMP_LDFLAGS -L$PGSQL_LIBDIR" + saved_CFLAGS=$CFLAGS + saved_LIBS=$LIBS + CFLAGS="-I$PGSQL_INCDIR" + LIBS="-L$PGSQL_LIBDIR" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PQconnectStart in -lpq" >&5 +$as_echo_n "checking for PQconnectStart in -lpq... " >&6; } +if ${ac_cv_lib_pq_PQconnectStart+:} false; then : $as_echo_n "(cached) " >&6 else - if test -z "$GREP"; then - ac_path_GREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_GREP" || continue -# Check for GNU ac_path_GREP and select it if it is found. - # Check for GNU $ac_path_GREP -case `"$ac_path_GREP" --version 2>&1` in -*GNU*) - ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" - "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_GREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_GREP="$ac_path_GREP" - ac_path_GREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpq $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ - $ac_path_GREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_GREP"; then - as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char PQconnectStart (); +int +main () +{ +return PQconnectStart (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pq_PQconnectStart=yes else - ac_cv_path_GREP=$GREP + ac_cv_lib_pq_PQconnectStart=no fi - +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } - GREP="$ac_cv_path_GREP" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pq_PQconnectStart" >&5 +$as_echo "$ac_cv_lib_pq_PQconnectStart" >&6; } +if test "x$ac_cv_lib_pq_PQconnectStart" = xyes; then : + PGSQL_SUPPORT="yes" + TEMP_LIBS="$TEMP_LIBS -L$PGSQL_LIBDIR -lpq" + TEMP_CFLAGS="$TEMP_CFLAGS -I$PGSQL_INCDIR" + +$as_echo "#define HAVE_PGSQL 1" >>confdefs.h -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 -$as_echo_n "checking for egrep... " >&6; } -if ${ac_cv_path_EGREP+:} false; then : - $as_echo_n "(cached) " >&6 -else - if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 - then ac_cv_path_EGREP="$GREP -E" - else - if test -z "$EGREP"; then - ac_path_EGREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in egrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - as_fn_executable_p "$ac_path_EGREP" || continue -# Check for GNU ac_path_EGREP and select it if it is found. - # Check for GNU $ac_path_EGREP -case `"$ac_path_EGREP" --version 2>&1` in -*GNU*) - ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'EGREP' >> "conftest.nl" - "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - as_fn_arith $ac_count + 1 && ac_count=$as_val - if test $ac_count -gt ${ac_path_EGREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_EGREP="$ac_path_EGREP" - ac_path_EGREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - $ac_path_EGREP_found && break 3 - done - done - done -IFS=$as_save_IFS - if test -z "$ac_cv_path_EGREP"; then - as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 - fi else - ac_cv_path_EGREP=$EGREP + as_fn_error $? "PostgreSQL support can't build without PostgreSQL libraries" "$LINENO" 5 fi - fi + LDFLAGS="" + CFLAGS=$saved_CFLAGS + LIBS=$saved_LIBS + fi + + fi # end pgsql-include , pgsql-libs + +# end PostgreSQL detection fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } - EGREP="$ac_cv_path_EGREP" +#Checks for header files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : @@ -5355,23 +6100,6 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi -# On IRIX 5.3, sys/types and inttypes.h are conflicting. -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default -" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - for ac_header in stdio.h unistd.h stdint.h fcntl.h time.h signal.h sys/ioctl.h sys/mman.h linux/videodev.h linux/videodev2.h sys/param.h sys/types.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` @@ -5704,11 +6432,11 @@ else int main () { - +/* FIXME: Include the comments suggested by Paul. */ #ifndef __cplusplus - /* Ultrix mips cc rejects this sort of thing. */ + /* Ultrix mips cc rejects this. */ typedef int charset[2]; - const charset cs = { 0, 0 }; + const charset cs; /* SunOS 4.1.1 cc rejects this. */ char const *const *pcpcc; char **ppc; @@ -5725,9 +6453,8 @@ main () ++pcpcc; ppc = (char**) pcpcc; pcpcc = (char const *const *) ppc; - { /* SCO 3.2v4 cc rejects this sort of thing. */ - char tx; - char *t = &tx; + { /* SCO 3.2v4 cc rejects this. */ + char *t; char const *s = 0 ? (char *) 0 : (char const *) 0; *t++ = 0; @@ -5743,10 +6470,10 @@ main () iptr p = 0; ++p; } - { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + { /* AIX XL C 1.02.0.0 rejects this saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ - struct s { int j; const int *ap[3]; } bx; - struct s *b = &bx; b->j = 5; + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; @@ -6039,43 +6766,6 @@ LIBS="${TEMP_LIBS}" LDFLAGS="${TEMP_LDFLAGS}" -ac_fn_c_check_func "$LINENO" "avformat_alloc_context" "ac_cv_func_avformat_alloc_context" -if test "x$ac_cv_func_avformat_alloc_context" = xyes; then : - -$as_echo "#define have_avformat_alloc_context 1" >>confdefs.h - -fi - -ac_fn_c_check_func "$LINENO" "av_avformat_alloc_context" "ac_cv_func_av_avformat_alloc_context" -if test "x$ac_cv_func_av_avformat_alloc_context" = xyes; then : - -$as_echo "#define have_av_avformat_alloc_context 1" >>confdefs.h - -fi - -ac_fn_c_check_func "$LINENO" "av_register_protocol2" "ac_cv_func_av_register_protocol2" -if test "x$ac_cv_func_av_register_protocol2" = xyes; then : - -$as_echo "#define have_av_register_protocol2 1" >>confdefs.h - -fi - -ac_fn_c_check_func "$LINENO" "av_register_protocol" "ac_cv_func_av_register_protocol" -if test "x$ac_cv_func_av_register_protocol" = xyes; then : - -$as_echo "#define have_av_register_protocol 1" >>confdefs.h - -fi - -ac_fn_c_check_func "$LINENO" "av_get_media_type_string" "ac_cv_func_av_get_media_type_string" -if test "x$ac_cv_func_av_get_media_type_string" = xyes; then : - -$as_echo "#define have_av_get_media_type_string 1" >>confdefs.h - -fi - - - # # Add the right exec path for rc scripts # @@ -6506,16 +7196,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -6575,16 +7265,28 @@ else as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -6605,8 +7307,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by motion $as_me Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by motion $as_me trunkREVUNKNOWN, which was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -6667,11 +7369,11 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -motion config.status Git-28b7cb2a4297c78b9c08c9ce29a648aeb22120d0 -configured by $0, generated by GNU Autoconf 2.69, +motion config.status trunkREVUNKNOWN +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -6759,7 +7461,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -7483,4 +8185,3 @@ echo "LDFLAGS: $LDFLAGS" echo echo "Install prefix: $prefix" echo - diff --git a/configure.in b/configure.ac old mode 100644 new mode 100755 similarity index 90% rename from configure.in rename to configure.ac index f551e9a..a92e8b8 --- a/configure.in +++ b/configure.ac @@ -1,6 +1,7 @@ # Process this file with autoconf to produce a configure script AC_INIT(motion, esyscmd(['./version.sh'])) +AC_GNU_SOURCE AC_CONFIG_SRCDIR([motion.c]) AC_CONFIG_HEADERS(config.h) AC_PROG_CC @@ -45,7 +46,7 @@ if test "${Darwin}" = ""; then if test "${LINUXTHREADS}" = "no"; then AC_MSG_CHECKING(Linuxthreads) AC_MSG_RESULT(skipping) - else + else THREAD_CHECK="/usr/local/include/pthread/linuxthreads/pthread.h" THREAD_LIB_CHECK="/usr/local/lib/liblthread.so" fi @@ -53,9 +54,9 @@ if test "${Darwin}" = ""; then if test "${PWCBSD}" != "no"; then VIDEO="video.o video2.o video_common.o" TEMP_CFLAGS="${CFLAGS} -I/usr/local/include -DPWCBSD" - else + else VIDEO="video_freebsd.o" - TEMP_CFLAGS="${CFLAGS} -I/usr/local/include" + TEMP_CFLAGS="${CFLAGS} -I/usr/local/include" fi TEMP_LDFLAGS="${LDFLAGS} -L/usr/local/lib" @@ -95,7 +96,7 @@ if test "${FreeBSD}" != "" && test "${PWCBSD}" = "no"; then TEMP_CFLAGS="${TEMP_CFLAGS} -DOLD_BKTR" fi # -# Check to Exclude BKTR +# Check to Exclude BKTR # BKTR="yes" AC_ARG_WITH(bktr, @@ -107,7 +108,7 @@ BKTR="$withval" ) if test "${BKTR}" = "no"; then - TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L" + TEMP_CFLAGS="${TEMP_CFLAGS} -DWITHOUT_V4L" fi else @@ -139,10 +140,10 @@ AC_MSG_CHECKING(for linuxthreads) # Check for thread header # if test -f "${THREAD_CHECK}"; then - HEADERS_THREAD_CFLAGS="-I/usr/local/include/pthread/linuxthreads" - THREADS="yes" + HEADERS_THREAD_CFLAGS="-I/usr/local/include/pthread/linuxthreads" + THREADS="yes" else - THREADS="no" + THREADS="no" fi # @@ -152,7 +153,7 @@ AC_MSG_CHECKING(for linuxthreads) THREADS="yes" LIB_THREAD="-llthread -llgcc_r" else - THREADS="no" + THREADS="no" fi # Checks for Library linuxthreads for FreeBSD @@ -198,12 +199,12 @@ if test x$PTHREAD_LIB != xyes; then fi PTHREAD_SUPPORT="yes" fi - AC_MSG_RESULT($PTHREAD_SUPPORT) + AC_MSG_RESULT($PTHREAD_SUPPORT) else - echo + echo echo "You do not have threads support" - echo + echo fi @@ -317,7 +318,7 @@ if test "${JPEG_MMX}" = "no" || test x$JPEG_SUPPORT != xyes; then elif test "${JPEG_MMX}" = "yes"; then # AUTODETECT STATIC LIB AC_MSG_CHECKING(for libjpeg-mmx autodetecting) - + if test -f /usr/lib/libjpeg-mmx.a ; then AC_MSG_RESULT(found) JPEG_MMX_OK="found" @@ -329,8 +330,8 @@ elif test "${JPEG_MMX}" = "yes"; then else AC_MSG_RESULT(not found) fi -else - AC_MSG_CHECKING(for libjpeg-mmx in -> [${JPEG_MMX}] <-) +else + AC_MSG_CHECKING(for libjpeg-mmx in -> [${JPEG_MMX}] <-) if test -f ${JPEG_MMX}/libjpeg-mmx.a ; then AC_MSG_RESULT(found) JPEG_MMX_OK="found" @@ -375,12 +376,13 @@ fi # # Check for libavcodec and libavformat from ffmpeg # + FFMPEG_DIR="yes" FFMPEG_OK="no_found" FFMPEG_OBJ="" AC_ARG_WITH(ffmpeg, [ --with-ffmpeg[=DIR] Specify the prefix for the install path for - libavcodec/libavformat (part of ffmpeg) be able to + libavcodec/libavformat (part of ffmpeg) be able to encode mpeg movies realtime. If this is not specified motion will try to find the libraries in /usr and /usr/local. @@ -388,7 +390,7 @@ AC_ARG_WITH(ffmpeg, FFMPEG_DIR="$withval" ) -# +# # ffmpeg headers custom location # FFMPEG_HEADERS_DIR="yes" @@ -398,6 +400,16 @@ AC_ARG_WITH(ffmpeg_headers, FFMPEG_HEADERS_DIR="$withval" ) +# +# ffmpeg custom extra libraries +# +FFMPEG_EXTRALIBS=" -lavformat -lavcodec -lavutil -lm -lz -lswscale " +AC_ARG_WITH(ffmpeg-libs, +[ --with-ffmpeg-libs[=libs] Specify the extra libs for ffmpeg + ], +FFMPEG_EXTRALIBS="$withval" +) + # # --without-ffmpeg or with-ffmpeg=no # @@ -408,7 +420,7 @@ if test "${FFMPEG_DIR}" = "no"; then # with-ffmpeg= or nothing # else if test "${FFMPEG_DIR}" = "yes"; then - # AUTODETECT STATIC/SHARED LIB + # AUTODETECT STATIC/SHARED LIB AC_MSG_CHECKING(for ffmpeg autodetecting libraries) if test -f /usr/lib64/libavcodec.a -o -f /usr/lib64/libavcodec.so && test -f /usr/lib64/libavformat.a -o -f /usr/lib64/libavformat.so ; then @@ -431,6 +443,11 @@ else if test "${FFMPEG_DIR}" = "yes"; then FFMPEG_OK="found" FFMPEG_LIB="/usr/lib/x86_64-linux-gnu" FFMPEG_DIR="/usr" + elif test -f /usr/lib/i386-linux-gnu/libavcodec.a -o -f /usr/lib/i386-linux-gnu/libavcodec.so && test /usr/lib/i386-linux-gnu/libavformat.a -o -f /usr/lib/i386-linux-gnu/libavformat.so ; then + AC_MSG_RESULT(found in /usr/lib/i386-linux-gnu) + FFMPEG_OK="found" + FFMPEG_LIB="/usr/lib/i386-linux-gnu" + FFMPEG_DIR="/usr" else AC_MSG_RESULT(not found) echo "" @@ -442,8 +459,8 @@ else if test "${FFMPEG_DIR}" = "yes"; then echo "* Please read the Motion Guide for help: *" echo "* http://motion.sourceforge.net *" echo "**********************************************" - echo "" - fi + echo "" + fi else AC_MSG_CHECKING(for ffmpeg libraries in -> [${FFMPEG_DIR}] <-) if test -f ${FFMPEG_DIR}/lib/libavcodec.a -o -f ${FFMPEG_DIR}/lib/libavcodec.so && test -f ${FFMPEG_DIR}/lib/libavformat.a -o -f ${FFMPEG_DIR}/lib/libavformat.so ; then @@ -471,42 +488,54 @@ else fi fi + # # Now check for ffmpeg headers ( avformat.h ) if ffmpeg libs were found # +AVFORMAT_DIR="" + if test "${FFMPEG_OK}" = "found"; then if test "${FFMPEG_HEADERS_DIR}" = "yes"; then AC_MSG_CHECKING(for ffmpeg headers in ${FFMPEG_DIR}) - else + AVFORMAT_DIR="${FFMPEG_DIR}" + else AC_MSG_CHECKING(for ffmpeg headers in ${FFMPEG_HEADERS_DIR}) FFMPEG_DIR="${FFMPEG_HEADERS_DIR}" + AVFORMAT_DIR="${FFMPEG_DIR}" fi if test -f ${FFMPEG_DIR}/include/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include" + AVFORMAT_DIR="${FFMPEG_DIR}/include/avformat.h" elif test -f ${FFMPEG_DIR}/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}" + AVFORMAT_DIR="${FFMPEG_DIR}/avformat.h" elif test -f ${FFMPEG_DIR}/include/ffmpeg/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/ffmpeg/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include/ffmpeg" + AVFORMAT_DIR="${FFMPEG_DIR}/include/ffmpeg/avformat.h" elif test -f ${FFMPEG_DIR}/include/libavformat/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/libavformat/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include -DFFMPEG_NEW_INCLUDES" - AVFORMAT="-I${FFMPEG_DIR}/include/libavformat" + AVFORMAT="-I${FFMPEG_DIR}/include/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/include/libavformat/avformat.h" elif test -f ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR}/include/ffmpeg -DFFMPEG_NEW_INCLUDES" - AVFORMAT="-I${FFMPEG_DIR}/include/ffmpeg/libavformat" + AVFORMAT="-I${FFMPEG_DIR}/include/ffmpeg/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/include/ffmpeg/libavformat/avformat.h" elif test -f ${FFMPEG_DIR}/libavformat/avformat.h; then AC_MSG_RESULT(found ${FFMPEG_DIR}/libavformat/avformat.h) FFMPEG_CFLAGS="-I${FFMPEG_DIR} -DFFMPEG_NEW_INCLUDES" AVFORMAT="-I{FFMPEG_DIR}/libavformat" + AVFORMAT_DIR="${FFMPEG_DIR}/libavformat/avformat.h" else AC_MSG_RESULT(not found) FFMPEG_OK="no_found" + AVFORMAT_DIR="avformat.h" echo "**********************************************" echo "* avformat.h not found: *" echo "* ALL FFMPEG FEATURES DISABLED *" @@ -518,49 +547,50 @@ if test "${FFMPEG_OK}" = "found"; then fi # -# If ffmpeg libs and headers have been found +# If ffmpeg libs and headers have been found # - if test "${FFMPEG_OK}" = "found"; then - TEMP_LIBS="$TEMP_LIBS -L${FFMPEG_LIB} -lavformat -lavcodec -lavutil -lm -lz" + if test "${FFMPEG_OK}" = "found"; then + TEMP_LIBS="$TEMP_LIBS -L${FFMPEG_LIB} ${FFMPEG_EXTRALIBS}" TEMP_LDFLAGS="${TEMP_LDFLAGS} -L${FFMPEG_LIB}" TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG ${FFMPEG_CFLAGS}" FFMPEG_OBJ="ffmpeg.o" AC_SUBST(FFMPEG_OBJ) - RTPS_OBJ="netcam_rtsp.o" - AC_SUBST(RTPS_OBJ) - AC_MSG_CHECKING([file_protocol is defined in ffmpeg ?]) saved_CFLAGS=$CFLAGS saved_LIBS=$LIBS - - CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" - LIBS="$TEMP_LIBS" - - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - [ - #include - URLProtocol test_file_protocol; - int main(void){ - test_file_protocol.url_read = file_protocol.url_read; - return 0; - } - ]])], - [AC_MSG_RESULT(yes)], - [ - AC_MSG_RESULT(no) - TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_NEW" - ] - ) - CFLAGS=$saved_CFLAGS - LIBS=$saved_LIBS - fi -fi + CFLAGS="${FFMPEG_CFLAGS} ${AVFORMAT}" + LIBS="$TEMP_LIBS" + + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + [ + #include <${AVFORMAT_DIR}> + URLProtocol test_file_protocol; + int main(void){ + test_file_protocol.url_read = file_protocol.url_read; + return 0; + } + ]])], + [AC_MSG_RESULT(yes)], + [ + AC_MSG_RESULT(no) + TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_FFMPEG_NEW" + ] + ) + CFLAGS=$saved_CFLAGS + LIBS=$saved_LIBS + fi +fi fi +# Revised RTSP module so that it can be included +# whether or not FFMPEG is found. + + RTPS_OBJ="netcam_rtsp.o" + AC_SUBST(RTPS_OBJ) # # Check SQLITE3 @@ -591,7 +621,7 @@ else CFLAGS=$saved_CFLAGS LIBS=$saved_LIBS -fi +fi # @@ -661,13 +691,13 @@ else fi done elif test "${MYSQL_HEADERS}" = "no"; then - AC_MSG_CHECKING(for mysql headers) + AC_MSG_CHECKING(for mysql headers) AC_MSG_RESULT(skipped) else AC_MSG_CHECKING(for mysql headers in $MYSQL_HEADERS) # Manual detection for - if test -f $MYSQL_HEADERS/mysql.h; then - MYSQL_INCDIR=$MYSQL_HEADERS + if test -f $MYSQL_HEADERS/mysql.h; then + MYSQL_INCDIR=$MYSQL_HEADERS fi fi @@ -686,7 +716,7 @@ else # ******* Search mysql libs ********* if test "${MYSQL_LIBS}" = "yes"; then AC_MSG_CHECKING(autodect mysql libs) - # Autodetect + # Autodetect for w in /usr/lib64 /usr/lib /usr/local/lib /usr/mysql /usr/local/mysql /usr/local/mysql/lib /opt /opt/mysql /usr/lib/x86_64-linux-gnu; do # check for plain setups if test -f $w/libmysqlclient.a -o -f $w/libmysqlclient.so; then @@ -705,7 +735,7 @@ else fi done elif test "${MYSQL_LIBS}" = "no"; then - AC_MSG_CHECKING(for mysql libs) + AC_MSG_CHECKING(for mysql libs) AC_MSG_RESULT(skipped) else AC_MSG_CHECKING(for mysql libs in $MYSQL_LIBS) @@ -726,13 +756,13 @@ else saved_LIBS=$LIBS CFLAGS="-I$MYSQL_INCDIR" LIBS="-L$MYSQL_LIBDIR" - AC_CHECK_LIB(mysqlclient,mysql_init,[ + AC_CHECK_LIB(mysqlclient,mysql_init,[ TEMP_LIBS="$TEMP_LIBS -L$MYSQL_LIBDIR -lmysqlclient -lz" TEMP_CFLAGS="$TEMP_CFLAGS -I$MYSQL_INCDIR" MYSQL_SUPPORT="yes" AC_DEFINE([HAVE_MYSQL],1,[Define to 1 if you have MySQL support]) ], - AC_MSG_ERROR(MySQL support can't build without MySQL libraries)) + AC_MSG_ERROR(MySQL support can't build without MySQL libraries)) CFLAGS=$saved_CFLAGS LIBS=$saved_LIBS fi @@ -752,7 +782,7 @@ PGSQL_SUPPORT="no" PGSQL_HEADERS="yes" PGSQL_LIBS="yes" -AC_DEFUN(PGSQL_INC_CHK,[if test -r $i$1/libpq-fe.h; then PGSQL_DIR=$i; PGSQL_INCDIR=$i$1]) +AC_DEFUN([PGSQL_INC_CHK],[if test -r $i$1/libpq-fe.h; then PGSQL_DIR=$i; PGSQL_INCDIR=$i$1]) AC_ARG_WITH(pgsql, [ --without-pgsql Disable PostgreSQL support in motion. @@ -799,15 +829,15 @@ else el[]PGSQL_INC_CHK(/include/postgresql) fi done - + elif test "${PGSQL_HEADERS}" = "no"; then - AC_MSG_CHECKING(for pgsql headers) + AC_MSG_CHECKING(for pgsql headers) AC_MSG_RESULT(skipped) else AC_MSG_CHECKING(for pgsql headers in $PGSQL_HEADERS) # Manual detection for - if test -f $PGSQL_HEADERS/libpq-fe.h; then - PGSQL_INCDIR=$PGSQL_HEADERS + if test -f $PGSQL_HEADERS/libpq-fe.h; then + PGSQL_INCDIR=$PGSQL_HEADERS fi fi @@ -833,10 +863,10 @@ else if test -f /usr/lib64/libpq.so ; then PGSQL_LIBDIR=/usr/lib64 elif test -f $PGSQL_DIR/lib/pgsql/libpq.so ; then - PGSQL_LIBDIR=$PGSQL_DIR/lib/pgsql + PGSQL_LIBDIR=$PGSQL_DIR/lib/pgsql elif test -f $PGSQL_DIR/lib/postgresql/libpq.so ; then PGSQL_LIBDIR=$PGSQL_DIR/lib/postgresql - elif test -f $PGSQL_DIR/lib/libpq.so ; then + elif test -f $PGSQL_DIR/lib/libpq.so ; then PGSQL_LIBDIR=$PGSQL_DIR/lib else PGSQL_LIBDIR="" @@ -845,7 +875,7 @@ else AC_MSG_RESULT($PGSQL_LIBDIR) elif test "${PGSQL_LIBS}" = "no"; then - AC_MSG_CHECKING(for pgsql libs) + AC_MSG_CHECKING(for pgsql libs) AC_MSG_RESULT(skipped) else AC_MSG_CHECKING(for pgsql libs in $PGSQL_LIBS) @@ -870,13 +900,13 @@ else TEMP_LIBS="$TEMP_LIBS -L$PGSQL_LIBDIR -lpq" TEMP_CFLAGS="$TEMP_CFLAGS -I$PGSQL_INCDIR" AC_DEFINE([HAVE_PGSQL],1,[Define to 1 if you have PostgreSQL support]) - ], + ], AC_MSG_ERROR(PostgreSQL support can't build without PostgreSQL libraries)) - LDFLAGS="" + LDFLAGS="" CFLAGS=$saved_CFLAGS LIBS=$saved_LIBS fi - + fi # end pgsql-include , pgsql-libs # end PostgreSQL detection @@ -897,17 +927,17 @@ if test "${V4L}" = "no"; then AC_MSG_CHECKING(for V42L support) AC_MSG_RESULT(skipping) else - AC_CHECK_TYPE([struct v4l2_buffer], - [SUPPORTED_V4L2=true], - [SUPPORTED_V4L2=false], - [#include + AC_CHECK_TYPE([struct v4l2_buffer], + [SUPPORTED_V4L2=true], + [SUPPORTED_V4L2=false], + [#include #include ]) AC_MSG_CHECKING(for V42L support) if test x$SUPPORTED_V4L2 = xtrue; then AC_MSG_RESULT(yes) TEMP_CFLAGS="${TEMP_CFLAGS} -DMOTION_V4L2" - else + else AC_MSG_RESULT(no) fi @@ -1033,12 +1063,12 @@ if test -e "/proc/cpuinfo" ; then amd[[1543]]="-march=athlon64" amd[[1544]]="-march=athlon64" amd[[1565]]="-march=opteron" - amd[[1572]]="-march=k8" + amd[[1572]]="-march=k8" via[[67]]="-march=c3" via[[68]]="-march=c3" - via[[69]]="-march=i686" + via[[69]]="-march=i686" via[[610]]="-march=i686" - + CPU_TYPE="known" CPU_FAMILY=`cat /proc/cpuinfo | grep "cpu family" | head -n1` CPU_MODEL=`cat /proc/cpuinfo | grep model[[^\ ]] | head -n1` @@ -1202,7 +1232,7 @@ AC_LINK_IFELSE([ TEMP_CFLAGS="${TEMP_CFLAGS} -DHAVE_BSWAP" AC_MSG_RESULT(yes) ], - [ + [ AC_MSG_RESULT(no) ]) @@ -1217,13 +1247,6 @@ LIBS="${TEMP_LIBS}" LDFLAGS="${TEMP_LDFLAGS}" -AC_CHECK_FUNC(avformat_alloc_context, AC_DEFINE([have_avformat_alloc_context],1,[Define to 1 if you have avformat_alloc_context support])) -AC_CHECK_FUNC(av_avformat_alloc_context, AC_DEFINE([have_av_avformat_alloc_context],1,[Define to 1 if you have av_avformat_alloc_context support])) -AC_CHECK_FUNC(av_register_protocol2, AC_DEFINE([have_av_register_protocol2],1,[Define to 1 if you have av_register_protocol2 support])) -AC_CHECK_FUNC(av_register_protocol, AC_DEFINE([have_av_register_protocol],1,[Define to 1 if you have av_register_protocol support])) -AC_CHECK_FUNC(av_get_media_type_string, AC_DEFINE([have_av_get_media_type_string],1,[Define to 1 if you have av_get_media_type_string support])) - - # # Add the right exec path for rc scripts # @@ -1264,14 +1287,14 @@ echo " **************************" echo " Configure status " echo " ${PACKAGE_NAME} ${PACKAGE_VERSION}" echo " **************************" -echo +echo if test "${Darwin}" != ""; then echo "OS : Darwin" elif test "${FreeBSD}" != ""; then - echo "OS : *BSD" -else + echo "OS : *BSD" +else echo "OS : Linux" fi @@ -1281,7 +1304,7 @@ else echo "pthread support: No" echo "**********************************************" echo "** Fatal Error YOU MUST HAVE pthread Support *" - echo "**********************************************" + echo "**********************************************" fi @@ -1319,7 +1342,7 @@ else fi if test x$SUPPORTED_V4L2 = xtrue; then - echo "V4L2 support: Yes" + echo "V4L2 support: Yes" else echo "V4L2 support: No" fi @@ -1354,11 +1377,10 @@ if test "${PGSQL_SUPPORT}" = "yes"; then else echo "PostgreSQL support: No" fi -echo +echo echo "CFLAGS: $CFLAGS" echo "LIBS: $LIBS" echo "LDFLAGS: $LDFLAGS" echo echo "Install prefix: $prefix" echo - diff --git a/event.c b/event.c index e93c8d5..f8a7d28 100644 --- a/event.c +++ b/event.c @@ -416,9 +416,9 @@ static void event_extpipe_end(struct context *cnt, int type ATTRIBUTE_UNUSED, if (cnt->extpipe_open) { cnt->extpipe_open = 0; fflush(cnt->extpipe); - MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: CLOSING: extpipe file desc %d, error state %d", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: CLOSING: extpipe file desc %d, error state %d", fileno(cnt->extpipe), ferror(cnt->extpipe)); - MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", pclose(cnt->extpipe)); event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); } diff --git a/ffmpeg.c b/ffmpeg.c index 57eeda4..6127542 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -22,19 +22,6 @@ * that padded with B frames to obtain the correct framerate. */ # define FFMPEG_NO_NONSTD_MPEG1 -# ifdef __GNUC__ -/* #warning is a non-standard gcc extension */ -# warning ************************************************** -# warning Your version of FFmpeg is newer than version 0.4.8 -# warning Newer versions of ffmpeg do not support MPEG1 with -# warning non-standard framerate. MPEG1 will be disabled for -# warning normal video output. You can still use mpeg4 and -# warning and mpeg4ms which are both better in terms of size -# warning and quality. MPEG1 is always used for timelapse. -# warning Please read the Motion Guide for more information. -# warning Note that this is not an error message! -# warning ************************************************** -# endif /* __GNUC__ */ #endif /* LIBAVCODEC_BUILD > 4680 */ #if defined LIBAVFORMAT_VERSION_MAJOR && defined LIBAVFORMAT_VERSION_MINOR @@ -163,89 +150,37 @@ URLProtocol mpeg1_file_protocol = { #include "avstring.h" #endif -/** - * file_open - * - */ -static int file_open(URLContext *h, const char *filename, int flags) -{ - const char *mode; - FILE *fh; - size_t bufsize = 0; - - av_strstart(filename, "file:", &filename); - - if (flags & URL_RDWR) { - mode = "wb+"; - bufsize = BUFSIZE_1MEG; - } else if (flags & URL_WRONLY) { - mode = "wb"; - bufsize = BUFSIZE_1MEG; - } else { - mode = "rb"; - } - fh = myfopen(filename, mode, bufsize); - if (fh == NULL) - return AVERROR(ENOENT); - h->priv_data = (void *)fh; - return 0; -} - -/** - * file_read - */ -static int file_read(URLContext *h, unsigned char *buf, int size) -{ - FILE *fh = (FILE *)h->priv_data; - return fread(buf, 1, size, fh); -} - -/** - * file_write - */ -static int file_write(URLContext *h, unsigned char *buf, int size) -{ - FILE *fh = (FILE *)h->priv_data; - return fwrite(buf, 1, size, fh); -} - -/** - * file_seek - */ -static int64_t file_seek(URLContext *h, int64_t pos, int whence) -{ - FILE *fh = (FILE *)h->priv_data; - if (fseek(fh, pos, whence)) - return -1; - return ftell(fh); -} +#endif // HAVE_FFMPEG_NEW -/** - * file_close - */ -static int file_close(URLContext *h) -{ - FILE *fh = (FILE *)h->priv_data; - return myfclose(fh); +#endif // FF_API_NEW_AVIO +/**************************************************************************** + * The section below is the "my" section of functions. + * These are designed to be extremely simple version specific + * variants of the libav functions. + ****************************************************************************/ +AVFrame *my_frame_alloc(void){ + AVFrame *pic; +#if (LIBAVFORMAT_VERSION_MAJOR >= 55) + pic = av_frame_alloc(); +#else + pic = avcodec_alloc_frame(); +#endif + return pic; } -URLProtocol file_protocol = { - "file", - file_open, - file_read, - file_write, - file_seek, - file_close, -#if LIBAVFORMAT_BUILD >= (52<<16 | 31<<8) - NULL, - NULL, - NULL, +void my_frame_free(AVFrame *frame){ +#if (LIBAVFORMAT_VERSION_MAJOR >= 55) + av_frame_free(&frame); +#else + //avcodec_free_frame(&frame); + //av_frame_free(&netcam->rtsp->frame); + av_freep(&frame); #endif -}; - -#endif // HAVE_FFMPEG_NEW +} -#endif // FF_API_NEW_AVIO +/**************************************************************************** + **************************************************************************** + ****************************************************************************/ /** * mpeg1_write_trailer @@ -257,16 +192,8 @@ URLProtocol file_protocol = { */ static int mpeg1_write_trailer(AVFormatContext *s) { -#if defined FF_API_NEW_AVIO avio_write(s->pb, mpeg1_trailer, 4); avio_flush(s->pb); -#elif LIBAVFORMAT_BUILD >= (52<<16) - put_buffer(s->pb, mpeg1_trailer, 4); - put_flush_packet(s->pb); -#else - put_buffer(&s->pb, mpeg1_trailer, 4); - put_flush_packet(&s->pb); -#endif /* FF_API_NEW_AVIO -- LIBAVFORMAT_BUILD >= (52<<16) */ return 0; /* success */ } @@ -290,28 +217,6 @@ void ffmpeg_init() av_log_set_level(AV_LOG_ERROR); #endif -#if defined FF_API_NEW_AVIO -#else - /* - * Copy the functions to use for the append file protocol from the standard - * file protocol. - */ - mpeg1_file_protocol.url_read = file_protocol.url_read; - mpeg1_file_protocol.url_write = file_protocol.url_write; - mpeg1_file_protocol.url_seek = file_protocol.url_seek; - mpeg1_file_protocol.url_close = file_protocol.url_close; - -/* Register the append file protocol. */ -#ifdef have_av_register_protocol2 - av_register_protocol2(&mpeg1_file_protocol, sizeof(mpeg1_file_protocol)); -#elif defined have_av_register_protocol - av_register_protocol(&mpeg1_file_protocol); -#else -# warning av_register_protocolXXX missing -#endif - -#endif // FF_API_NEW_AVIO - } /** @@ -473,12 +378,10 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, snprintf(ffmpeg->codec, sizeof(ffmpeg->codec), "%s", ffmpeg_video_codec); /* Allocation the output media context. */ -#ifdef have_avformat_alloc_context +#if (LIBAVFORMAT_VERSION_MAJOR >= 53) ffmpeg->oc = avformat_alloc_context(); -#elif defined have_av_avformat_alloc_context - ffmpeg->oc = av_alloc_format_context(); #else - ffmpeg->oc = av_mallocz(sizeof(AVFormatContext)); + ffmpeg->oc = av_alloc_format_context(); #endif if (!ffmpeg->oc) { @@ -500,11 +403,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* Create a new video stream and initialize the codecs. */ ffmpeg->video_st = NULL; if (ffmpeg->oc->oformat->video_codec != CODEC_ID_NONE) { -#if defined FF_API_NEW_AVIO ffmpeg->video_st = avformat_new_stream(ffmpeg->oc, NULL /* Codec */); -#else - ffmpeg->video_st = av_new_stream(ffmpeg->oc, 0); -#endif if (!ffmpeg->video_st) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: av_new_stream - could" " not alloc stream"); @@ -521,10 +420,10 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->c = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st); c->codec_id = ffmpeg->oc->oformat->video_codec; -#if LIBAVCODEC_VERSION_MAJOR < 53 - c->codec_type = CODEC_TYPE_VIDEO; -#else +#if (LIBAVFORMAT_VERSION_MAJOR >= 53) c->codec_type = AVMEDIA_TYPE_VIDEO; +#else + c->codec_type = CODEC_TYPE_VIDEO; #endif is_mpeg1 = c->codec_id == CODEC_ID_MPEG1VIDEO; @@ -566,18 +465,6 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, c->flags |= CODEC_FLAG_GLOBAL_HEADER; } -#if defined FF_API_NEW_AVIO -// pass the options to avformat_write_header directly -#else - /* Set the output parameters (must be done even if no parameters). */ - if (av_set_parameters(ffmpeg->oc, NULL) < 0) { - MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: av_set_parameters error:" - " Invalid output format parameters"); - ffmpeg_cleanups(ffmpeg); - return NULL; - } -#endif - /* Dump the format settings. This shows how the various streams relate to each other. */ //dump_format(ffmpeg->oc, 0, filename, 1); @@ -601,11 +488,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, pthread_mutex_lock(&global_lock); /* Open the codec */ -#if defined FF_API_NEW_AVIO ret = avcodec_open2(c, codec, NULL /* options */ ); -#else - ret = avcodec_open(c, codec); -#endif if (ret < 0) { /* Release the lock. */ @@ -632,7 +515,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, } /* Allocate the encoded raw picture. */ - ffmpeg->picture = avcodec_alloc_frame(); + ffmpeg->picture = my_frame_alloc(); if (!ffmpeg->picture) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_alloc_frame -" @@ -672,11 +555,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, snprintf(file_proto, sizeof(file_proto), "%s", filename); -#if defined FF_API_NEW_AVIO if (avio_open(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { -#else - if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { -#endif /* Path did not exist? */ if (errno == ENOENT) { /* Create path for file (don't use file_proto)... */ @@ -685,12 +564,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, return NULL; } -#if defined FF_API_NEW_AVIO if (avio_open(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { -#else - /* And retry opening the file (use file_proto). */ - if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { -#endif MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen -" " error opening file %s", filename); ffmpeg_cleanups(ffmpeg); @@ -714,11 +588,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, } /* Write the stream header, if any. */ -#if defined FF_API_NEW_AVIO avformat_write_header(ffmpeg->oc, NULL); -#else - av_write_header(ffmpeg->oc); -#endif // FF_API_NEW_AVIO return ffmpeg; } @@ -786,13 +656,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { /* Close the output file. */ -#if defined FF_API_NEW_AVIO avio_close(ffmpeg->oc->pb); -#elif LIBAVFORMAT_BUILD >= (52<<16) - url_fclose(ffmpeg->oc->pb); -#else - url_fclose(&ffmpeg->oc->pb); -#endif /* FF_API_NEW_AVIO -- LIBAVFORMAT_BUILD >= (52<<16) */ } @@ -853,7 +717,7 @@ int ffmpeg_put_other_image(struct ffmpeg *ffmpeg, unsigned char *y, */ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) { - int out_size, ret, got_packet_ptr; + int out_size, ret; #ifdef FFMPEG_AVWRITEFRAME_NEWAPI AVPacket pkt; @@ -880,6 +744,8 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) } else { /* Encodes the image. */ #if defined FF_API_NEW_AVIO + + int got_packet_ptr; pkt.data = ffmpeg->video_outbuf; pkt.size = ffmpeg->video_outbuf_size; @@ -949,7 +815,7 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y, { AVFrame *picture; - picture = avcodec_alloc_frame(); + picture = my_frame_alloc(); if (!picture) { MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not alloc frame"); @@ -998,7 +864,12 @@ void ffmpeg_deinterlace(unsigned char *img, int width, int height) picture.linesize[2] = width2; /* We assume using 'PIX_FMT_YUV420P' always */ +#if (LIBAVFORMAT_VERSION_MAJOR >= 53) + MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: Deinterlace depreciated for recent versions of FFMPEG."); +#else avpicture_deinterlace(&picture, &picture, PIX_FMT_YUV420P, width, height); +#endif + #if !defined(__SSE_MATH__) && (defined(__i386__) || defined(__x86_64__)) __asm__ __volatile__ ( "emms"); diff --git a/ffmpeg.h b/ffmpeg.h index a1e2e9d..c64fd9e 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -95,4 +95,9 @@ void ffmpeg_deinterlace(unsigned char *, int, int); /* Setup an avcodec log handler. */ void ffmpeg_avcodec_log(void *, int, const char *, va_list); +#ifdef HAVE_FFMPEG +AVFrame *my_frame_alloc(void); +void my_frame_free(AVFrame *frame); +#endif + #endif /* _INCLUDE_FFMPEG_H_ */ diff --git a/jpegutils.c b/jpegutils.c index 9c9bc44..8998034 100644 --- a/jpegutils.c +++ b/jpegutils.c @@ -478,7 +478,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, if (setjmp (jerr.setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error. */ jpeg_destroy_decompress (&dinfo); - return -1; + return 1; } jpeg_create_decompress (&dinfo); @@ -491,9 +491,9 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, */ jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; -#if JPEG_LIB_VERSION >= 70 +#if JPEG_LIB_VERSION >= 70 dinfo.do_fancy_upsampling = FALSE; -#endif +#endif dinfo.out_color_space = JCS_YCbCr; dinfo.dct_method = JDCT_IFAST; guarantee_huff_tables(&dinfo); @@ -584,9 +584,9 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, if (field > 0) { jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; -#if JPEG_LIB_VERSION >= 70 +#if JPEG_LIB_VERSION >= 70 dinfo.do_fancy_upsampling = FALSE; -#endif +#endif dinfo.out_color_space = JCS_YCbCr; dinfo.dct_method = JDCT_IFAST; jpeg_start_decompress (&dinfo); @@ -770,7 +770,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, unsigned int height, unsigned char *raw0, unsigned char *raw1, unsigned char *raw2) { - int numfields, hsf[3], field, yl, yc, xsl, xsc, xs, xd, hdown; + int numfields, field, yl, yc, xsl, xsc, xs, xd, hdown; unsigned int x, y, vsf[3]; JSAMPROW row0[16] = { buf0[0], buf0[1], buf0[2], buf0[3], @@ -805,7 +805,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, dinfo.raw_data_out = TRUE; #if JPEG_LIB_VERSION >= 70 dinfo.do_fancy_upsampling = FALSE; -#endif +#endif dinfo.out_color_space = JCS_GRAYSCALE; dinfo.dct_method = JDCT_IFAST; @@ -818,7 +818,6 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, guarantee_huff_tables(&dinfo); jpeg_start_decompress (&dinfo); - hsf[0] = 1; hsf[1] = 1; hsf[2] = 1; vsf[0]= 1; vsf[1] = 1; vsf[2] = 1; /* Height match image height or be exact twice the image height. */ @@ -874,7 +873,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, dinfo.raw_data_out = TRUE; #if JPEG_LIB_VERSION >= 70 dinfo.do_fancy_upsampling = FALSE; -#endif +#endif dinfo.out_color_space = JCS_GRAYSCALE; dinfo.dct_method = JDCT_IFAST; jpeg_start_decompress (&dinfo); diff --git a/logger.c b/logger.c index f76d2a3..aa47753 100644 --- a/logger.c +++ b/logger.c @@ -212,26 +212,29 @@ void motion_log(int level, unsigned int type, int errno_flag, const char *fmt, . /* Next add the user's message. */ va_start(ap, fmt); n += vsnprintf(buf + n, sizeof(buf) - n, fmt, ap); + buf[1023] = '\0'; /* If errno_flag is set, add on the library error message. */ if (errno_flag) { - strncat(buf, ": ", 1024 - strlen(buf)); - n += 2; + size_t buf_len = strlen(buf); + + // just knock off 10 characters if we're that close... + if (buf_len + 10 > 1024) { + buf[1024 - 10] = '\0'; + buf_len = 1024 - 10; + } + + strncat(buf, ": ", 1024 - buf_len); + n += 2; /* * This is bad - apparently gcc/libc wants to use the non-standard GNU * version of strerror_r, which doesn't actually put the message into * my buffer :-(. I have put in a 'hack' to get around this. */ #if defined(XSI_STRERROR_R) -#warning "************************************" -#warning "* Using XSI-COMPLIANT strerror_r() *" -#warning "************************************" /* XSI-compliant strerror_r() */ strerror_r(errno_save, buf + n, sizeof(buf) - n); /* 2 for the ': ' */ #else -#warning "************************************" -#warning "* Using GNU-COMPLIANT strerror_r() *" -#warning "************************************" /* GNU-specific strerror_r() */ strncat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)), 1024 - strlen(buf)); #endif diff --git a/motion-dist.conf.in b/motion-dist.conf.in index 630cbf8..51f4221 100644 --- a/motion-dist.conf.in +++ b/motion-dist.conf.in @@ -101,7 +101,7 @@ framerate 2 # This option is used when you want to capture images at a rate lower than 2 per second. minimum_frame_time 0 -# URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// mjpg:// rstp:// or file:///) +# URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// mjpg:// rtsp:// mjpeg:// or file:///) # Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined ; netcam_url value @@ -125,6 +125,10 @@ netcam_keepalive off # Default: off netcam_tolerant_check off +# RTSP connection uses TCP to communicate to the camera. Can prevent image corruption. +# Default: on +rtsp_uses_tcp on + # Let motion regulate the brightness of a video device (default: off). # The auto_brightness feature uses the brightness option as its target value. # If brightness is zero auto_brightness will adjust to average brightness value 128. diff --git a/motion.c b/motion.c index 5666770..fc48e64 100644 --- a/motion.c +++ b/motion.c @@ -723,13 +723,13 @@ static int motion_init(struct context *cnt) memset(cnt->imgs.out, 0, cnt->imgs.size); /* contains the moving objects of ref. frame */ - cnt->imgs.ref_dyn = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.ref_dyn)); + cnt->imgs.ref_dyn = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.ref_dyn)); cnt->imgs.image_virgin = mymalloc(cnt->imgs.size); cnt->imgs.smartmask = mymalloc(cnt->imgs.motionsize); cnt->imgs.smartmask_final = mymalloc(cnt->imgs.motionsize); - cnt->imgs.smartmask_buffer = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.smartmask_buffer)); - cnt->imgs.labels = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.labels)); - cnt->imgs.labelsize = mymalloc((cnt->imgs.motionsize/2+1) * sizeof(cnt->imgs.labelsize)); + cnt->imgs.smartmask_buffer = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.smartmask_buffer)); + cnt->imgs.labels = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.labels)); + cnt->imgs.labelsize = mymalloc((cnt->imgs.motionsize/2+1) * sizeof(*cnt->imgs.labelsize)); /* Set output picture type */ if (!strcmp(cnt->conf.picture_type, "ppm")) @@ -917,7 +917,7 @@ static int motion_init(struct context *cnt) /* Always initialize smart_mask - someone could turn it on later... */ memset(cnt->imgs.smartmask, 0, cnt->imgs.motionsize); memset(cnt->imgs.smartmask_final, 255, cnt->imgs.motionsize); - memset(cnt->imgs.smartmask_buffer, 0, cnt->imgs.motionsize*sizeof(cnt->imgs.smartmask_buffer)); + memset(cnt->imgs.smartmask_buffer, 0, cnt->imgs.motionsize * sizeof(*cnt->imgs.smartmask_buffer)); /* Set noise level */ cnt->noise = cnt->conf.noise; @@ -1294,7 +1294,7 @@ static void *motion_loop(void *arg) cnt->current_image->timestamp_tm = old_image->timestamp_tm; cnt->current_image->shot = old_image->shot; cnt->current_image->cent_dist = old_image->cent_dist; - cnt->current_image->flags = old_image->flags; + cnt->current_image->flags = old_image->flags & (~IMAGE_SAVED); cnt->current_image->location = old_image->location; cnt->current_image->total_labels = old_image->total_labels; } @@ -2714,8 +2714,12 @@ int main (int argc, char **argv) cnt_list[i]->threadnr = i ? i : 1; if (strcmp(cnt_list[i]->conf_filename, "")) + { + cnt_list[i]->conf_filename[sizeof(cnt_list[i]->conf_filename) - 1] = '\0'; + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", cnt_list[i]->threadnr, cnt_list[i]->conf_filename); + } MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: Thread %d is device: %s input %d", cnt_list[i]->threadnr, cnt_list[i]->conf.netcam_url ? @@ -3200,6 +3204,14 @@ size_t mystrftime(const struct context *cnt, char *s, size_t max, const char *us ++pos_userformat; break; + case 'w': // picture width + sprintf(tempstr, "%d", cnt->imgs.width); + break; + + case 'h': // picture height + sprintf(tempstr, "%d", cnt->imgs.height); + break; + case 'f': // filename -- or %fps if ((*(pos_userformat+1) == 'p') && (*(pos_userformat+2) == 's')) { sprintf(tempstr, "%d", cnt->movie_fps); diff --git a/netcam.c b/netcam.c index e327a2f..3c2b481 100644 --- a/netcam.c +++ b/netcam.c @@ -45,9 +45,7 @@ #include #include "netcam_ftp.h" -#ifdef have_av_get_media_type_string #include "netcam_rtsp.h" -#endif #define CONNECT_TIMEOUT 10 /* Timeout on remote connection attempt */ #define READ_TIMEOUT 5 /* Default timeout on recv requests */ @@ -149,13 +147,9 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) { char *s; int i; -#ifdef have_av_get_media_type_string - const char *re = "(http|ftp|mjpg|rtsp)://(((.*):(.*))@)?" - "([^/:]|[-.a-z0-9]+)(:([0-9]+))?($|(/[^:]*))"; -#else - const char *re = "(http|ftp|mjpg)://(((.*):(.*))@)?" + + const char *re = "(http|ftp|mjpg|mjpeg|rtsp)://(((.*):(.*))@)?" "([^/:]|[-.a-z0-9]+)(:([0-9]+))?($|(/[^:]*))"; -#endif regex_t pattbuf; regmatch_t matches[10]; @@ -211,10 +205,8 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) parse_url->port = 80; else if (!strcmp(parse_url->service, "ftp")) parse_url->port = 21; -#ifdef have_av_get_media_type_string else if (!strcmp(parse_url->service, "rtsp") && parse_url->port == 0) parse_url->port = 554; -#endif } regfree(&pattbuf); @@ -232,7 +224,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) * Returns: Nothing * */ -static void netcam_url_free(struct url_t *parse_url) +void netcam_url_free(struct url_t *parse_url) { if (parse_url->service) { free(parse_url->service); @@ -1270,7 +1262,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * module netcam_wget.c to do this job! */ - MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Potential split boundary - " "%d chars flushed, %d " "re-positioned", ix, @@ -2017,17 +2009,42 @@ static void *netcam_handler_loop(void *arg) */ } } - if (netcam->get_image(netcam) < 0) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error getting jpeg image"); - /* If FTP connection, attempt to re-connect to server. */ - if (netcam->ftp) { - close(netcam->ftp->control_file_desc); - if (ftp_connect(netcam) < 0) - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Trying to re-connect"); - + + if (netcam->caps.streaming == NCS_RTSP) { + if (netcam->rtsp->format_context == NULL) { // We must have disconnected. Try to reconnect + if (netcam->rtsp->status == RTSP_CONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Reconnecting with camera...."); + } + netcam->rtsp->status = RTSP_RECONNECTING; + netcam_connect_rtsp(netcam); + continue; + } else { + // We think we are connected... + if (netcam->get_image(netcam) < 0) { + if (netcam->rtsp->status == RTSP_CONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Bad image. Reconnecting with camera...."); + } + //Nope. We are not or got bad image. Reconnect + netcam->rtsp->status = RTSP_RECONNECTING; + netcam_connect_rtsp(netcam); + continue; + } + } + } + + if (netcam->caps.streaming != NCS_RTSP) { + if (netcam->get_image(netcam) < 0) { + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error getting jpeg image"); + /* If FTP connection, attempt to re-connect to server. */ + if (netcam->ftp) { + close(netcam->ftp->control_file_desc); + if (ftp_connect(netcam) < 0) + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Trying to re-connect"); + } + continue; } - continue; } + /* * FIXME * Need to check whether the image was received / decoded @@ -2413,71 +2430,6 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) return 0; } -#ifdef have_av_get_media_type_string -static int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url) -{ - struct context *cnt = netcam->cnt; - const char *ptr; - - netcam->caps.streaming = NCS_RTSP; - netcam->rtsp = rtsp_new_context(); - - if (netcam->rtsp == NULL) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to create rtsp context"); - return -1; - } - - /* - * Allocate space for a working string to contain the path. - * The extra 5 is for "://", ":" and string terminator. - */ - - // force port to a sane value - if (netcam->connect_port > 65536) { - netcam->connect_port = 65536; - } else if (netcam->connect_port < 0) { - netcam->connect_port = 0; - } - - ptr = mymalloc(strlen(url->service) + strlen(netcam->connect_host) - + 5 + strlen(url->path) + 5); - sprintf((char *)ptr, "%s://%s:%d%s", url->service, - netcam->connect_host, netcam->connect_port, url->path); - - netcam->rtsp->path = (char *)ptr; - - if (cnt->conf.netcam_userpass != NULL) { - ptr = cnt->conf.netcam_userpass; - } else { - ptr = url->userpass; /* Don't set this one NULL, gets freed. */ - } - - if (ptr != NULL) { - char *cptr; - - if ((cptr = strchr(ptr, ':')) == NULL) { - netcam->rtsp->user = mystrdup(ptr); - } else { - netcam->rtsp->user = mymalloc((cptr - ptr)); - memcpy(netcam->rtsp->user, ptr,(cptr - ptr)); - netcam->rtsp->pass = mystrdup(cptr + 1); - } - } - - netcam_url_free(url); - - /* - * The RTSP context should be all ready to attempt a connection with - * the server, so we try .... - */ - rtsp_connect(netcam); - - netcam->get_image = netcam_read_rtsp_image; - - return 0; -} -#endif - /** * netcam_recv * @@ -2658,6 +2610,10 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag) if (netcam->response != NULL) free(netcam->response); + + if (netcam->caps.streaming == NCS_RTSP) + netcam_shutdown_rtsp(netcam); + pthread_mutex_destroy(&netcam->mutex); pthread_cond_destroy(&netcam->cap_cond); pthread_cond_destroy(&netcam->pic_ready); @@ -2709,7 +2665,13 @@ int netcam_next(struct context *cnt, unsigned char *image) } if (netcam->caps.streaming == NCS_RTSP) { - memcpy(image, netcam->latest->ptr, netcam->latest->used); + + if (netcam->rtsp->status == RTSP_RECONNECTING) + return NETCAM_NOTHING_NEW_ERROR; + + if (netcam_next_rtsp(image , netcam) < 0) + return NETCAM_GENERAL_ERROR | NETCAM_JPEG_CONV_ERROR; + return 0; } @@ -2890,16 +2852,20 @@ int netcam_start(struct context *cnt) strcpy(url.service, "http"); /* Put back a real URL service. */ retval = netcam_setup_mjpg(netcam, &url); -#ifdef have_av_get_media_type_string + } else if ((url.service) && (!strcmp(url.service, "mjpeg"))) { + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_mjpeg()"); + + strcpy(url.service, "http"); /* Put back a real URL service. */ + retval = netcam_setup_rtsp(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "rtsp"))) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" " netcam_setup_rtsp()"); retval = netcam_setup_rtsp(netcam, &url); -#endif } else { MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam service '%s' - " - "must be http, ftp, mjpg or file.", url.service); + "must be http, ftp, mjpg, mjpeg or file.", url.service); netcam_url_free(&url); return -1; } @@ -2917,12 +2883,13 @@ int netcam_start(struct context *cnt) if ((retval = netcam->get_image(netcam)) != 0) { MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Failed trying to " "read first image - retval:%d", retval); + netcam->rtsp->status = RTSP_NOTCONNECTED; return -1; } -#ifdef have_av_get_media_type_string + if (netcam->caps.streaming != NCS_RTSP) { -#endif + /* * If an error occurs in the JPEG decompression which follows this, * jpeglib will return to the code within this 'if'. If such an error @@ -2937,29 +2904,23 @@ int netcam_start(struct context *cnt) netcam->netcam_tolerant_check = cnt->conf.netcam_tolerant_check; netcam->JFIF_marker = 0; netcam_get_dimensions(netcam); + } + /* + * Motion currently requires that image height and width is a + * multiple of 16. So we check for this. + */ + if (netcam->width % 8) { + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)" + " is not modulo 8", netcam->width); + return -3; + } - /* - * Motion currently requires that image height and width is a - * multiple of 16. So we check for this. - */ - if (netcam->width % 8) { - MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)" - " is not modulo 8", netcam->width); - return -3; - } - - if (netcam->height % 8) { - MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)" - " is not modulo 8", netcam->height); - return -3; - } -#ifdef have_av_get_media_type_string - } else { - // not jpeg, get the dimensions - netcam->width = netcam->rtsp->codec_context->width; - netcam->height = netcam->rtsp->codec_context->height; + if (netcam->height % 8) { + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)" + " is not modulo 8", netcam->height); + return -3; } -#endif + /* Fill in camera details into context structure. */ cnt->imgs.width = netcam->width; diff --git a/netcam.h b/netcam.h index 6062edf..3612f1a 100644 --- a/netcam.h +++ b/netcam.h @@ -107,6 +107,11 @@ typedef struct file_context { #define NCS_BLOCK 2 /* streaming is done via MJPG-block */ #define NCS_RTSP 3 /* streaming is done via RTSP */ + +#define RTSP_NOTCONNECTED 0 /* The camera has never connected */ +#define RTSP_CONNECTED 1 /* The camera is currently connected */ +#define RTSP_RECONNECTING 2 /* The camera is trying to reconnect*/ + /* * struct netcam_context contains all the structures and other data * for an individual netcam. @@ -297,5 +302,6 @@ int netcam_start (struct context *); int netcam_next (struct context *, unsigned char *); void netcam_cleanup (struct netcam_context *, int); ssize_t netcam_recv(netcam_context_ptr, void *, size_t); +void netcam_url_free(struct url_t *parse_url); #endif diff --git a/netcam_ftp.c b/netcam_ftp.c index 0a129b2..7a0451f 100644 --- a/netcam_ftp.c +++ b/netcam_ftp.c @@ -790,10 +790,10 @@ int ftp_get_socket(ftp_context_pointer ctxt) */ int ftp_send_type(ftp_context_pointer ctxt, char type) { - char buf[100], utype; + char buf[100]; int len, res; - utype = toupper(type); + toupper(type); /* Assure transfer will be in "image" mode. */ snprintf(buf, sizeof(buf), "TYPE I\r\n"); len = strlen(buf); diff --git a/netcam_rtsp.c b/netcam_rtsp.c index 1fe1357..4e5a55f 100644 --- a/netcam_rtsp.c +++ b/netcam_rtsp.c @@ -1,15 +1,81 @@ +/*********************************************************** + * In the top section are the functions that are used + * when processing the RTSP camera feed. Since these functions + * are internal to the RTSP module, and many require FFmpeg + * structures in their declarations, they are within the + * HAVE_FFMPEG block that eliminates them entirely when + * FFmpeg is not present. + * + * The functions: + * netcam_setup_rtsp + * netcam_connect_rtsp + * netcam_shutdown_rtsp + * netcam_next_rtsp + * are called from netcam.c therefore must be defined even + * if FFmpeg is not present. They must also not have FFmpeg + * structures in the declarations. Simple error + * messages are raised if called when no FFmpeg is found. + * + ***********************************************************/ + #include #include "netcam_rtsp.h" -#include "motion.h" +#include "rotate.h" /* already includes motion.h */ + +#ifdef HAVE_FFMPEG + +#include "ffmpeg.h" + +/** + * netcam_check_pixfmt + * + * Determine whether pix_format is YUV420P + */ +int netcam_check_pixfmt(netcam_context_ptr netcam){ + int retcd; -#ifdef have_av_get_media_type_string + retcd = -1; -/**************************************************** - * Duplicated static functions - FIXME - ****************************************************/ + if ((netcam->rtsp->codec_context->pix_fmt == PIX_FMT_YUV420P) || + (netcam->rtsp->codec_context->pix_fmt == PIX_FMT_YUVJ420P)) retcd = 0; + return retcd; + +} /** - * netcam_check_buffsize + * netcam_rtsp_null_context + * + * Null all the context + */ +void netcam_rtsp_null_context(netcam_context_ptr netcam){ + + netcam->rtsp->swsctx = NULL; + netcam->rtsp->swsframe_in = NULL; + netcam->rtsp->swsframe_out = NULL; + netcam->rtsp->frame = NULL; + netcam->rtsp->codec_context = NULL; + netcam->rtsp->format_context = NULL; + +} +/** + * netcam_rtsp_close_context + * + * Close all the context that could be open + */ +void netcam_rtsp_close_context(netcam_context_ptr netcam){ + + if (netcam->rtsp->swsctx != NULL) sws_freeContext(netcam->rtsp->swsctx); + if (netcam->rtsp->swsframe_in != NULL) my_frame_free(netcam->rtsp->swsframe_in); + if (netcam->rtsp->swsframe_out != NULL) my_frame_free(netcam->rtsp->swsframe_out); + if (netcam->rtsp->frame != NULL) my_frame_free(netcam->rtsp->frame); + if (netcam->rtsp->codec_context != NULL) avcodec_close(netcam->rtsp->codec_context); + if (netcam->rtsp->format_context != NULL) avformat_close_input(&netcam->rtsp->format_context); + + netcam_rtsp_null_context(netcam); +} + +/** + * netcam_buffsize_rtsp * * This routine checks whether there is enough room in a buffer to copy * some additional data. If there is not enough room, it will re-allocate @@ -21,8 +87,8 @@ * * Returns: Nothing */ -static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) -{ +static void netcam_buffsize_rtsp(netcam_buff_ptr buff, size_t numbytes){ + int min_size_to_alloc; int real_alloc; int new_size; @@ -37,7 +103,7 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) real_alloc += NETCAM_BUFFSIZE; new_size = buff->size + real_alloc; - + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", (int) buff->used, (int) buff->size, (int) buff->used, new_size); @@ -47,64 +113,98 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) buff->size = new_size; } -/**************************************************** - * End Duplicated static functions - FIXME - ****************************************************/ - -static int decode_packet(AVPacket *packet, netcam_buff_ptr buffer, AVFrame *frame, AVCodecContext *cc) -{ - int check = 0; - int ret = avcodec_decode_video2(cc, frame, &check, packet); - - if (ret < 0) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error decoding video packet"); - return 0; - } - - if (check == 0) { - // no frame could be decoded...keep trying - return 0; - } +/** + * decode_packet + * + * This routine takes in the packet from the read and decodes it into + * the frame. It then takes the frame and copies it into the netcam + * buffer + * + * Parameters: + * packet The packet that was read from av_read + * buffer The buffer that is the final destination + * frame The frame into which we decode the packet + * + * + * Returns: + * Failure 0(zero) + * Success The size of the frame decoded + */ +static int decode_packet(AVPacket *packet, netcam_buff_ptr buffer, AVFrame *frame, AVCodecContext *cc){ + int check = 0; + int frame_size = 0; + int ret = 0; - int frame_size = av_image_get_buffer_size(cc->pix_fmt, cc->width, cc->height, 1); + ret = avcodec_decode_video2(cc, frame, &check, packet); + if (ret < 0) { + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error decoding video packet"); + return 0; + } - /* Assure there's enough room in the buffer. */ - netcam_check_buffsize(buffer, frame_size); + if (check == 0) { + return 0; + } - av_image_copy_to_buffer((uint8_t *)buffer->ptr, frame_size, - (const uint8_t **)(frame->data), frame->linesize, - cc->pix_fmt, cc->width, cc->height, 1); + frame_size = avpicture_get_size(cc->pix_fmt, cc->width, cc->height); - buffer->used = frame_size; - - return frame_size; + netcam_buffsize_rtsp(buffer, frame_size); + + avpicture_layout((const AVPicture*)frame,cc->pix_fmt,cc->width,cc->height + ,(unsigned char *)buffer->ptr,frame_size ); + + buffer->used = frame_size; + + return frame_size; } -static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type) -{ +/** + * netcam_open_codec + * + * This routine opens the codec context for the indicated stream + * + * Parameters: + * stream_idx The index of the stream that was found as "best" + * fmt_ctx The format context that was created upon opening the stream + * type The type of media type (This is a constant) + * + * + * Returns: + * Failure Error code from FFmpeg (Negative number) + * Success 0(Zero) + */ +static int netcam_open_codec(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type){ int ret; + char errstr[128]; AVStream *st; AVCodecContext *dec_ctx = NULL; AVCodec *dec = NULL; + ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0); if (ret < 0) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Could not find stream %s in input!", av_get_media_type_string(type)); + av_strerror(ret, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Could not find stream in input!: %s",errstr); return ret; - } else { - *stream_idx = ret; - st = fmt_ctx->streams[*stream_idx]; - /* find decoder for the stream */ - dec_ctx = st->codec; - dec = avcodec_find_decoder(dec_ctx->codec_id); - if (!dec) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to find %s codec!", av_get_media_type_string(type)); - return ret; - } - if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) { - MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to open %s codec!", av_get_media_type_string(type)); - return ret; - } } + + *stream_idx = ret; + st = fmt_ctx->streams[*stream_idx]; + + /* find decoder for the stream */ + dec_ctx = st->codec; + dec = avcodec_find_decoder(dec_ctx->codec_id); + if (dec == NULL) { + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to find codec!"); + return -1; + } + + /* Open the codec */ + ret = avcodec_open2(dec_ctx, dec, NULL); + if (ret < 0) { + av_strerror(ret, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to open codec!: %s", errstr); + return ret; + } + return 0; } @@ -120,213 +220,693 @@ static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AV * Returns: Pointer to the newly-created structure, NULL if error. * */ -struct rtsp_context *rtsp_new_context(void) -{ - struct rtsp_context *ret; - - /* Note that mymalloc will exit on any problem. */ - ret = mymalloc(sizeof(struct rtsp_context)); - - memset(ret, 0, sizeof(struct rtsp_context)); - - return ret; +struct rtsp_context *rtsp_new_context(void){ + struct rtsp_context *ret; + + /* Note that mymalloc will exit on any problem. */ + ret = mymalloc(sizeof(struct rtsp_context)); + + memset(ret, 0, sizeof(struct rtsp_context)); + + return ret; } +/** +* netcam_interrupt_rtsp +* +* This function is called during the FFmpeg blocking functions. +* These include the opening of the format context as well as the +* reading of the packets from the stream. Since this is called +* during all blocking functions, the process uses the readingframe +* flag to determine whether to timeout the process. +* +* Parameters +* +* ctx We pass in the rtsp context to use it to look for the +* readingframe flag as well as the time that we started +* the read attempt. +* +* Returns: +* Failure -1(which triggers an interupt) +* Success 0(zero which indicates to let process continue) +* +*/ +static int netcam_interrupt_rtsp(void *ctx){ + struct rtsp_context *rtsp = (struct rtsp_context *)ctx; + if (rtsp->readingframe != 1) { + return 0; + } else { + struct timeval interrupttime; + if (gettimeofday(&interrupttime, NULL) < 0) { + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: get interrupt time failed"); + } + if ((interrupttime.tv_sec - rtsp->startreadtime.tv_sec ) > 10){ + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Reading picture timed out for %s",rtsp->path); + return 1; + } else{ + return 0; + } + } + + //should not be possible to get here + return 0; +} /** -* rtsp_free_context +* netcam_read_rtsp_image * -* Free the resources allocated for this context. +* This function reads the packet from the camera. +* It is called extensively so only absolutely essential +* functions and allocations are performed. * * Parameters * -* ctxt Pointer to the rtsp_context structure. +* netcam The netcam context to read from * -* Returns: Nothing +* Returns: +* Failure -1 +* Success 0(zero) * */ -static void rtsp_free_context(struct rtsp_context *ctxt) -{ - if (ctxt == NULL) - return; - - if (ctxt->path != NULL) - free(ctxt->path); - - if (ctxt->user) - free(ctxt->user); - - if (ctxt->pass) - free(ctxt->pass); - - if (ctxt->format_context != NULL) { - avformat_close_input(&ctxt->format_context); - } - - if (ctxt->codec_context != NULL) { - avcodec_close(ctxt->codec_context); - } - - free(ctxt); +int netcam_read_rtsp_image(netcam_context_ptr netcam){ + struct timeval curtime; + netcam_buff_ptr buffer; + AVPacket packet; + int size_decoded; + + /* Point to our working buffer. */ + buffer = netcam->receiving; + buffer->used = 0; + + av_init_packet(&packet); + packet.data = NULL; + packet.size = 0; + + size_decoded = 0; + + if (gettimeofday(&curtime, NULL) < 0) { + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); + } + netcam->rtsp->startreadtime = curtime; + + netcam->rtsp->readingframe = 1; + while (size_decoded == 0 && av_read_frame(netcam->rtsp->format_context, &packet) >= 0) { + if(packet.stream_index != netcam->rtsp->video_stream_index) { + av_free_packet(&packet); + av_init_packet(&packet); + packet.data = NULL; + packet.size = 0; + // not our packet, skip + continue; + } + size_decoded = decode_packet(&packet, buffer, netcam->rtsp->frame, netcam->rtsp->codec_context); + + av_free_packet(&packet); + av_init_packet(&packet); + packet.data = NULL; + packet.size = 0; + } + netcam->rtsp->readingframe = 0; + + // at this point, we are finished with the packet + av_free_packet(&packet); + + if (size_decoded == 0) { + // something went wrong, end of stream? Interupted? + netcam_rtsp_close_context(netcam); + return -1; + } + + /* + * read is complete - set the current 'receiving' buffer atomically + * as 'latest', and make the buffer previously in 'latest' become + * the new 'receiving' and signal pic_ready. + */ + netcam->receiving->image_time = curtime; + netcam->last_image = curtime; + netcam_buff *xchg; + + pthread_mutex_lock(&netcam->mutex); + xchg = netcam->latest; + netcam->latest = netcam->receiving; + netcam->receiving = xchg; + netcam->imgcnt++; + pthread_cond_signal(&netcam->pic_ready); + pthread_mutex_unlock(&netcam->mutex); + + return 0; } +/** +* netcam_rtsp_resize_ntc +* +* This function notifies the user of the need to transcode +* the netcam image which uses a lot of CPU resources +* +* Parameters +* +* netcam The netcam context to read from +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_rtsp_resize_ntc(netcam_context_ptr netcam){ + + if ((netcam->width != netcam->rtsp->codec_context->width) || + (netcam->height != netcam->rtsp->codec_context->height) || + (netcam_check_pixfmt(netcam) != 0) ){ + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: "); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: ****************************************************************"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: The network camera is sending pictures in a different"); + if ((netcam->width != netcam->rtsp->codec_context->width) || + (netcam->height != netcam->rtsp->codec_context->height)) { + if (netcam_check_pixfmt(netcam) != 0) { + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: size than specified in the config and also a "); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: different picture format. The picture is being"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: transcoded to YUV420P and into the size requested"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: in the config file. If possible change netcam to"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: be in YUV420P format and the size requested in the"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: config to possibly lower CPU usage."); + } else { + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: size than specified in the configuration file."); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: The picture is being transcoded into the size "); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: requested in the configuration. If possible change"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: netcam or configuration to indicate the same size"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: to possibly lower CPU usage."); + } + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Netcam: %d x %d => Config: %d x %d" + ,netcam->rtsp->codec_context->width,netcam->rtsp->codec_context->height + ,netcam->width,netcam->height); + } else { + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: format than YUV420P. The image sent is being "); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: trancoded to YUV420P. If possible change netcam "); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: picture format to YUV420P to possibly lower CPU usage."); + } + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: ****************************************************************"); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: "); + } -int rtsp_connect(netcam_context_ptr netcam) -{ - if (netcam->rtsp == NULL) { - netcam->rtsp = rtsp_new_context(); + return 0; - if (netcam->rtsp == NULL) { - MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to create context(%s)", netcam->rtsp->path); - return -1; +} +/** +* netcam_rtsp_open_context +* +* This function opens the format context for the camera. +* +* Parameters +* +* netcam The netcam context to read from +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_rtsp_open_context(netcam_context_ptr netcam){ + + int retcd; + char errstr[128]; + + if (netcam->rtsp->path == NULL) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Null path passed to connect (%s)", netcam->rtsp->path); + } + return -1; } - } - // open the network connection - AVDictionary *opts = 0; - av_dict_set(&opts, "rtsp_transport", "tcp", 0); + // open the network connection + AVDictionary *opts = 0; + netcam->rtsp->format_context = avformat_alloc_context(); + netcam->rtsp->format_context->interrupt_callback.callback = netcam_interrupt_rtsp; + netcam->rtsp->format_context->interrupt_callback.opaque = netcam->rtsp; - int ret = avformat_open_input(&netcam->rtsp->format_context, netcam->rtsp->path, NULL, &opts); - if (ret < 0) { - MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open input(%s): %d - %s", netcam->rtsp->path, ret, av_err2str(ret)); - rtsp_free_context(netcam->rtsp); - netcam->rtsp = NULL; - return -1; - } + if (strncmp(netcam->rtsp->path, "http", 4) == 0 ){ + netcam->rtsp->format_context->iformat = av_find_input_format("mjpeg"); + } else { + if (netcam->cnt->conf.rtsp_uses_tcp) { + av_dict_set(&opts, "rtsp_transport", "tcp", 0); + if (netcam->rtsp->status == RTSP_NOTCONNECTED) + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Using tcp transport"); + } else { + av_dict_set(&opts, "rtsp_transport", "udp", 0); + av_dict_set(&opts, "max_delay", "500000", 0); //100000 is the default + if (netcam->rtsp->status == RTSP_NOTCONNECTED) + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Using udp transport"); + } + } - // fill out stream information - ret = avformat_find_stream_info(netcam->rtsp->format_context, NULL); - if (ret < 0) { - MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to find stream info: %d", ret); - rtsp_free_context(netcam->rtsp); - netcam->rtsp = NULL; - return -1; - } + retcd = avformat_open_input(&netcam->rtsp->format_context, netcam->rtsp->path, NULL, &opts); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open input(%s): %s", netcam->rtsp->path,errstr); + } + av_dict_free(&opts); + //The format context gets freed upon any error from open_input. + return retcd; + } + av_dict_free(&opts); + + // fill out stream information + retcd = avformat_find_stream_info(netcam->rtsp->format_context, NULL); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to find stream info: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; + } - ret = open_codec_context(&netcam->rtsp->video_stream_index, netcam->rtsp->format_context, AVMEDIA_TYPE_VIDEO); - if (ret < 0) { - MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open codec context: %d", ret); - rtsp_free_context(netcam->rtsp); - netcam->rtsp = NULL; - return -1; - } - - netcam->rtsp->codec_context = netcam->rtsp->format_context->streams[netcam->rtsp->video_stream_index]->codec; - - // start up the feed - av_read_play(netcam->rtsp->format_context); + retcd = netcam_open_codec(&netcam->rtsp->video_stream_index, netcam->rtsp->format_context, AVMEDIA_TYPE_VIDEO); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to open codec context: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; + } + + netcam->rtsp->codec_context = netcam->rtsp->format_context->streams[netcam->rtsp->video_stream_index]->codec; + + netcam->rtsp->frame = my_frame_alloc(); + if (netcam->rtsp->frame == NULL) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to allocate frame. Fatal error. Check FFmpeg/Libav configuration"); + } + netcam_rtsp_close_context(netcam); + return -1; + } + + /* + * Validate that the previous steps opened the camera + */ + retcd = netcam_read_rtsp_image(netcam); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to read first image"); + } + netcam_rtsp_close_context(netcam); + return -1; + } + + return 0; - return 0; } +/** +* netcam_rtsp_open_sws +* +* This function opens the rescaling context components. +* +* Parameters +* +* netcam The netcam context to read from +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_rtsp_open_sws(netcam_context_ptr netcam){ -int netcam_read_rtsp_image(netcam_context_ptr netcam) -{ - if (netcam->rtsp == NULL) { - if (rtsp_connect(netcam) < 0) { - return -1; + netcam->width = ((netcam->cnt->conf.width / 8) * 8); + netcam->height = ((netcam->cnt->conf.height / 8) * 8); + + + netcam->rtsp->swsframe_in = my_frame_alloc(); + if (netcam->rtsp->swsframe_in == NULL) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to allocate frame. Fatal error. Check FFmpeg/Libav configuration"); + } + netcam_rtsp_close_context(netcam); + return -1; } - } - AVCodecContext *cc = netcam->rtsp->codec_context; - AVFormatContext *fc = netcam->rtsp->format_context; - netcam_buff_ptr buffer; + netcam->rtsp->swsframe_out = my_frame_alloc(); + if (netcam->rtsp->swsframe_out == NULL) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to allocate frame. Fatal error. Check FFmpeg/Libav configuration"); + } + netcam_rtsp_close_context(netcam); + return -1; + } - /* Point to our working buffer. */ - buffer = netcam->receiving; - buffer->used = 0; + /* + * The scaling context is used to change dimensions to config file and + * also if the format sent by the camera is not YUV420. + */ + netcam->rtsp->swsctx = sws_getContext( + netcam->rtsp->codec_context->width + ,netcam->rtsp->codec_context->height + ,netcam->rtsp->codec_context->pix_fmt + ,netcam->width + ,netcam->height + ,PIX_FMT_YUV420P + ,SWS_BICUBIC,NULL,NULL,NULL); + if (netcam->rtsp->swsctx == NULL) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to allocate scaling context. Fatal error. Check FFmpeg/Libav configuration"); + } + netcam_rtsp_close_context(netcam); + return -1; + } - AVFrame *frame = avcodec_alloc_frame(); + netcam->rtsp->swsframe_size = avpicture_get_size( + PIX_FMT_YUV420P + ,netcam->width + ,netcam->height); + if (netcam->rtsp->swsframe_size <= 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error determining size of frame out"); + } + netcam_rtsp_close_context(netcam); + return -1; + } - AVPacket packet; - - av_init_packet(&packet); + return 0; - packet.data = NULL; - packet.size = 0; +} +/** +* netcam_rtsp_resize +* +* This function reencodes the image to yuv420p with the desired size +* +* Parameters +* +* netcam The netcam context to read from +* image The destination image. +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_rtsp_resize(unsigned char *image , netcam_context_ptr netcam){ + + int retcd; + char errstr[128]; + uint8_t *buffer_out; + + retcd = avpicture_fill( + (AVPicture*)netcam->rtsp->swsframe_in + ,(uint8_t*)netcam->latest->ptr + ,netcam->rtsp->codec_context->pix_fmt + ,netcam->rtsp->codec_context->width + ,netcam->rtsp->codec_context->height); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error allocating picture in: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; + } - int size_decoded = 0; - static int usual_size_decoded = 0; - while (size_decoded == 0 && av_read_frame(fc, &packet) >= 0) { + buffer_out=(uint8_t *)av_malloc(netcam->rtsp->swsframe_size*sizeof(uint8_t)); - if(packet.stream_index != netcam->rtsp->video_stream_index) { - // not our packet, skip - continue; + retcd = avpicture_fill( + (AVPicture*)netcam->rtsp->swsframe_out + ,buffer_out + ,PIX_FMT_YUV420P + ,netcam->width + ,netcam->height); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error allocating picture out: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; } - size_decoded = decode_packet(&packet, buffer, frame, cc); - } + retcd = sws_scale( + netcam->rtsp->swsctx + ,(const uint8_t* const *)netcam->rtsp->swsframe_in->data + ,netcam->rtsp->swsframe_in->linesize + ,0 + ,netcam->rtsp->codec_context->height + ,netcam->rtsp->swsframe_out->data + ,netcam->rtsp->swsframe_out->linesize); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error resizing/reformatting: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; + } + + retcd = avpicture_layout( + (const AVPicture*)netcam->rtsp->swsframe_out + ,PIX_FMT_YUV420P + ,netcam->width + ,netcam->height + ,(unsigned char *)image + ,netcam->rtsp->swsframe_size ); + if (retcd < 0) { + if (netcam->rtsp->status == RTSP_NOTCONNECTED){ + av_strerror(retcd, errstr, sizeof(errstr)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error putting frame into output buffer: %s", errstr); + } + netcam_rtsp_close_context(netcam); + return -1; + } + + av_free(buffer_out); + + return 0; + +} +/********************************************************* + * This ends the section of functions that rely upon FFmpeg + ***********************************************************/ +#endif /* End HAVE_FFMPEG */ + +/** +* netcam_connect_rtsp +* +* This function initiates the connection to the rtsp camera. +* +* Parameters +* +* netcam The netcam context to open. +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_connect_rtsp(netcam_context_ptr netcam){ +#ifdef HAVE_FFMPEG + + if (netcam_rtsp_open_context(netcam) < 0) return -1; + + if (netcam_rtsp_open_sws(netcam) < 0) return -1; + + if (netcam_rtsp_resize_ntc(netcam) < 0 ) return -1; + + if (netcam_read_rtsp_image(netcam) < 0) return -1; + + netcam->rtsp->status = RTSP_CONNECTED; + + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Camera connected"); + + return 0; - if (size_decoded == 0) { - // something went wrong, end of stream? - MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: invalid frame!"); +#else /* No FFmpeg/Libav */ + netcam->rtsp->status = RTSP_NOTCONNECTED; + netcam->rtsp->format_context = NULL; + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FFmpeg/Libav not found on computer. No RTSP support"); return -1; - } +#endif /* End #ifdef HAVE_FFMPEG */ +} - if (size_decoded != usual_size_decoded) { - MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: unusual frame size of %d!", size_decoded); - usual_size_decoded = size_decoded; - } +/** +* netcam_shutdown_rtsp +* +* This function closes and frees all the items for rtsp +* +* Parameters +* +* netcam The netcam context to free. +* +* Returns: +* Failure nothing +* Success nothing +* +*/ +void netcam_shutdown_rtsp(netcam_context_ptr netcam){ +#ifdef HAVE_FFMPEG + + if (netcam->rtsp->status == RTSP_CONNECTED) { + netcam_rtsp_close_context(netcam); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO,"%s: netcam shut down"); + } + + if (netcam->rtsp->path != NULL) free(netcam->rtsp->path); + if (netcam->rtsp->user != NULL) free(netcam->rtsp->user); + if (netcam->rtsp->pass != NULL) free(netcam->rtsp->pass); + + free(netcam->rtsp); + netcam->rtsp = NULL; + +#else /* No FFmpeg/Libav */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FFmpeg/Libav not found on computer. No RTSP support"); +#endif /* End #ifdef HAVE_FFMPEG */ +} - // at this point, we are finished with the packet and frame, so free them. - av_free_packet(&packet); - av_free(frame); - - struct timeval curtime; - - if (gettimeofday(&curtime, NULL) < 0) { - MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); +/** +* netcam_setup_rtsp +* +* This function sets up all the necessary items for the +* rtsp camera. +* +* Parameters +* +* netcam The netcam context to free. +* url The URL of the camera +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url){ +#ifdef HAVE_FFMPEG + + struct context *cnt = netcam->cnt; + const char *ptr; + int ret = -1; + + netcam->caps.streaming = NCS_RTSP; + + netcam->rtsp = rtsp_new_context(); + + netcam_rtsp_null_context(netcam); + + if (netcam->rtsp == NULL) { + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: unable to create rtsp context"); + netcam_shutdown_rtsp(netcam); + return -1; } - - netcam->receiving->image_time = curtime; - + /* - * Calculate our "running average" time for this netcam's - * frame transmissions (except for the first time). - * Note that the average frame time is held in microseconds. + * Allocate space for a working string to contain the path. + * The extra 5 is for "://", ":" and string terminator. */ - if (netcam->last_image.tv_sec) { - netcam->av_frame_time = ((9.0 * netcam->av_frame_time) + 1000000.0 * - (curtime.tv_sec - netcam->last_image.tv_sec) + - (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - - MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", - netcam->av_frame_time); + + // force port to a sane value + if (netcam->connect_port > 65536) { + netcam->connect_port = 65536; + } else if (netcam->connect_port < 0) { + netcam->connect_port = 0; } - - netcam->last_image = curtime; - - netcam_buff *xchg; - - /* - * read is complete - set the current 'receiving' buffer atomically - * as 'latest', and make the buffer previously in 'latest' become - * the new 'receiving'. - */ - pthread_mutex_lock(&netcam->mutex); - xchg = netcam->latest; - netcam->latest = netcam->receiving; - netcam->receiving = xchg; - netcam->imgcnt++; - - /* - * We have a new frame ready. We send a signal so that - * any thread (e.g. the motion main loop) waiting for the - * next frame to become available may proceed. - */ - pthread_cond_signal(&netcam->pic_ready); - - pthread_mutex_unlock(&netcam->mutex); - + if (cnt->conf.netcam_userpass != NULL) { + ptr = cnt->conf.netcam_userpass; + } else { + ptr = url->userpass; /* Don't set this one NULL, gets freed. */ + } + + if (ptr != NULL) { + char *cptr; + if ((cptr = strchr(ptr, ':')) == NULL) { + netcam->rtsp->user = mystrdup(ptr); + } else { + netcam->rtsp->user = mymalloc((cptr - ptr)+2); //+2 for string terminator + memcpy(netcam->rtsp->user, ptr,(cptr - ptr)); + netcam->rtsp->pass = mystrdup(cptr + 1); + } + } + + /* + * Need a method to query the path and + * determine the authentication type + */ + if ((netcam->rtsp->user != NULL) && (netcam->rtsp->pass != NULL)) { + ptr = mymalloc(strlen(url->service) + strlen(netcam->connect_host) + + 5 + strlen(url->path) + 5 + + strlen(netcam->rtsp->user) + strlen(netcam->rtsp->pass) + 4 ); + sprintf((char *)ptr, "%s://%s:%s@%s:%d%s", + url->service,netcam->rtsp->user,netcam->rtsp->pass, + netcam->connect_host, netcam->connect_port, url->path); + } + else { + ptr = mymalloc(strlen(url->service) + strlen(netcam->connect_host) + + 5 + strlen(url->path) + 5); + sprintf((char *)ptr, "%s://%s:%d%s", url->service, + netcam->connect_host, netcam->connect_port, url->path); + } + netcam->rtsp->path = (char *)ptr; + + netcam_url_free(url); + + /* + * Now we need to set some flags + */ + netcam->rtsp->readingframe = 0; + netcam->rtsp->status = RTSP_NOTCONNECTED; + + av_register_all(); + avformat_network_init(); + avcodec_register_all(); + + /* + * The RTSP context should be all ready to attempt a connection with + * the server, so we try .... + */ + ret = netcam_connect_rtsp(netcam); + if (ret < 0){ + return ret; + } + + netcam->get_image = netcam_read_rtsp_image; + return 0; + +#else /* No FFmpeg/Libav */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FFmpeg/Libav not found on computer. No RTSP support"); + return -1; +#endif /* End #ifdef HAVE_FFMPEG */ } +/** +* netcam_next_rtsp +* +* This function moves the picture to the image buffer. +* If the picture is not in the correct format for size +* it will put it into the requested format +* +* Parameters +* +* netcam The netcam context to free. +* url The URL of the camera +* +* Returns: +* Failure -1 +* Success 0(zero) +* +*/ +int netcam_next_rtsp(unsigned char *image , netcam_context_ptr netcam){ +#ifdef HAVE_FFMPEG -void netcam_shutdown_rtsp(netcam_context_ptr netcam) -{ - if (netcam->rtsp != NULL) { - rtsp_free_context(netcam->rtsp); - netcam->rtsp = NULL; - } -} + if ((netcam->width != netcam->rtsp->codec_context->width) || + (netcam->height != netcam->rtsp->codec_context->height) || + (netcam_check_pixfmt(netcam) != 0) ){ + netcam_rtsp_resize(image ,netcam); + } else { + memcpy(image, netcam->latest->ptr, netcam->latest->used); + } + if (netcam->cnt->rotate_data.degrees > 0) + /* Rotate as specified */ + rotate_map(netcam->cnt, image); -#endif + return 0; +#else /* No FFmpeg/Libav */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FFmpeg/Libav not found on computer. No RTSP support"); + return -1; +#endif /* End #ifdef HAVE_FFMPEG */ +} diff --git a/netcam_rtsp.h b/netcam_rtsp.h index 38ef565..a09d295 100644 --- a/netcam_rtsp.h +++ b/netcam_rtsp.h @@ -1,22 +1,43 @@ #include "netcam.h" + +#ifdef HAVE_FFMPEG + #include #include #include #include #include +#include +#endif /* end HAVE_FFMPEG */ struct rtsp_context { - AVFormatContext* format_context; - AVCodecContext* codec_context; - int video_stream_index; - char* path; - char* user; - char* pass; +#ifdef HAVE_FFMPEG + AVFormatContext* format_context; + AVCodecContext* codec_context; + AVFrame* frame; + AVFrame* swsframe_in; + AVFrame* swsframe_out; + int swsframe_size; + int video_stream_index; + char* path; + char* user; + char* pass; + int readingframe; + int status; + struct timeval startreadtime; + struct SwsContext* swsctx; + +#else /* Do not have FFmpeg */ + int* format_context; + int readingframe; + int status; +#endif /* end HAVE_FFMPEG */ }; -//int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url); struct rtsp_context *rtsp_new_context(void); void netcam_shutdown_rtsp(netcam_context_ptr netcam); -int rtsp_connect(netcam_context_ptr netcam); +int netcam_connect_rtsp(netcam_context_ptr netcam); int netcam_read_rtsp_image(netcam_context_ptr netcam); +int netcam_setup_rtsp(netcam_context_ptr netcam, struct url_t *url); +int netcam_next_rtsp(unsigned char *image , netcam_context_ptr netcam); diff --git a/picture.c b/picture.c index 196f220..9284280 100644 --- a/picture.c +++ b/picture.c @@ -177,7 +177,7 @@ static void put_direntry(struct tiff_writing *into, const char *data, unsigned l } else { /* Longer entries are stored out-of-line */ unsigned offset = into->data_offset; - + while ((offset & 0x03) != 0) { /* Alignment */ into->base[offset] = 0; offset ++; @@ -324,7 +324,7 @@ static void put_jpeg_exif(j_compress_ptr cinfo, JOCTET *marker = malloc(buffer_size); memcpy(marker, exif_marker_start, 14); /* EXIF and TIFF headers */ - + struct tiff_writing writing = (struct tiff_writing) { .base = marker + 6, /* base address for intra-TIFF offsets */ .buf = marker + 14, /* current write position */ @@ -338,10 +338,10 @@ static void put_jpeg_exif(j_compress_ptr cinfo, if (description) put_stringentry(&writing, TIFF_TAG_IMAGE_DESCRIPTION, description, 0); - + if (datetime) put_stringentry(&writing, TIFF_TAG_DATETIME, datetime, 1); - + if (ifd1_tagcount > 0) { /* Offset of IFD1 - TIFF header + IFD0 size. */ unsigned ifd1_offset = 8 + 6 + ( 12 * ifd0_tagcount ); @@ -369,10 +369,10 @@ static void put_jpeg_exif(j_compress_ptr cinfo, if (datetime) put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME, datetime, 1); - + if (box) put_subjectarea(&writing, box); - + if (subtime) put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME_SS, subtime, 0); @@ -394,7 +394,7 @@ static void put_jpeg_exif(j_compress_ptr cinfo, if (description) free(description); - + free(marker); } @@ -679,7 +679,6 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i unsigned char *u = image + width * height; unsigned char *v = u + (width * height) / 4; int r, g, b; - int warningkiller; unsigned char rgb[3]; /* @@ -722,7 +721,7 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i v++; } /* ppm is rgb not bgr */ - warningkiller = fwrite(rgb, 1, 3, picture); + fwrite(rgb, 1, 3, picture); } if (y & 1) { u -= width / 2; diff --git a/stream.c b/stream.c index 1ed082a..a073617 100644 --- a/stream.c +++ b/stream.c @@ -242,7 +242,8 @@ static void* handle_basic_auth(void* param) pthread_exit(NULL); Error: - write(p->sock, request_auth_response_template, strlen (request_auth_response_template)); + if (write(p->sock, request_auth_response_template, strlen (request_auth_response_template)) < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write failure 1:handle_basic_auth"); Invalid_Request: close(p->sock); @@ -569,8 +570,10 @@ static void* handle_md5_digest(void* param) "Content-Length: %Zu\r\n\r\n", request_auth_response_template, server_nonce, KEEP_ALIVE_TIMEOUT, strlen(auth_failed_html_template)); - write(p->sock, buffer, strlen(buffer)); - write(p->sock, auth_failed_html_template, strlen(auth_failed_html_template)); + if (write(p->sock, buffer, strlen(buffer)) < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write failure 1:handle_md5_digest"); + if (write(p->sock, auth_failed_html_template, strlen(auth_failed_html_template)) < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write failure 2:handle_md5_digest"); } // OK - Access @@ -607,7 +610,8 @@ static void* handle_md5_digest(void* param) if(server_pass) free(server_pass); - write(p->sock, internal_error_template, strlen(internal_error_template)); + if (write(p->sock, internal_error_template, strlen(internal_error_template)) < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write failure 3:handle_md5_digest"); Invalid_Request: close(p->sock); @@ -955,7 +959,7 @@ static void stream_add_client(struct stream *list, int sc) "Cache-Control: no-cache, private\r\n" "Pragma: no-cache\r\n" "Content-Type: multipart/x-mixed-replace; " - "boundary=--BoundaryString\r\n\r\n"; + "boundary=BoundaryString\r\n\r\n"; memset(new, 0, sizeof(struct stream)); new->socket = sc; diff --git a/track.c b/track.c index 91e89d7..0d7e3b3 100644 --- a/track.c +++ b/track.c @@ -563,7 +563,6 @@ static unsigned int servo_status(struct context *cnt, unsigned int motor) static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset) { - unsigned int ret = 0; int x_offset_abs; int y_offset_abs; @@ -591,7 +590,7 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset if (x_offset_abs <= cnt->track.maxx && x_offset_abs >= cnt->track.minx) { /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); - ret = servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_ABSOLUTE, x_offset_abs); + servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_ABSOLUTE, x_offset_abs); } /* y-axis */ @@ -603,7 +602,7 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset if (y_offset_abs <= cnt->track.maxy && y_offset_abs >= cnt->track.minx) { /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed); - ret = servo_command(cnt, cnt->track.motory, SERVO_COMMAND_ABSOLUTE, y_offset_abs); + servo_command(cnt, cnt->track.motory, SERVO_COMMAND_ABSOLUTE, y_offset_abs); } return cnt->track.move_wait; diff --git a/version.sh b/version.sh index 68dc73e..5963498 100755 --- a/version.sh +++ b/version.sh @@ -3,4 +3,6 @@ SNV_VERSION=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2` test $SNV_VERSION || SNV_VERSION=`cd "$1" && grep revision .svn/entries 2>/dev/null | cut -d '"' -f2` test $SNV_VERSION || SNV_VERSION=UNKNOWN -echo -n "trunkREV$SNV_VERSION" +SNV_VERSION=`git show -s --format=%h` +echo -n "3.2.12-Git-$SNV_VERSION" + diff --git a/webhttpd.c b/webhttpd.c index 20fe4e8..f7449df 100644 --- a/webhttpd.c +++ b/webhttpd.c @@ -281,6 +281,8 @@ static void send_template_raw(int client_socket, char *res) { ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, res, strlen(res)); + if (nwrite < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write_nonblock returned value less than zero."); } /** @@ -290,6 +292,9 @@ static void send_template_end_client(int client_socket) { ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, end_template, strlen(end_template)); + if (nwrite < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write_nonblock returned value less than zero."); + } /** @@ -303,6 +308,9 @@ static void response_client(int client_socket, const char *template, char *back) send_template(client_socket, back); send_template_end_client(client_socket); } + if (nwrite < 0) + MOTION_LOG(DBG, TYPE_STREAM, SHOW_ERRNO, "%s: write_nonblock returned value less than zero."); + } /** @@ -370,9 +378,8 @@ static void url_decode(char *urlencoded, size_t length) *urldecoded++ = c[1]; } - } else if (*data == '+') { - *urldecoded++ = ' '; - + } else if (*data == '<' || *data == '+' || *data == '>') { + *urldecoded++ = ' '; } else { *urldecoded++ = *data; }