From ee4bdbf34a438c59a9a3906b7d0ff7b5e667ea6b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 9 Mar 2021 10:07:10 +0100 Subject: [PATCH] Make zfec optional --- .github/scripts/install-common-deps.sh | 7 +++- Makefile.in | 1 - autogen.sh | 2 -- configure.ac | 21 +++++++++++- data/scripts/fetch_submodule.sh | 44 -------------------------- src/rtp/rs.cpp | 26 +++++++++++++++ 6 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 data/scripts/fetch_submodule.sh diff --git a/.github/scripts/install-common-deps.sh b/.github/scripts/install-common-deps.sh index 0f878b3b5..330777511 100755 --- a/.github/scripts/install-common-deps.sh +++ b/.github/scripts/install-common-deps.sh @@ -22,5 +22,10 @@ install_pcp() { rm -rf pcp } -install_pcp +install_zfec() { + ( cd $GITHUB_WORKSPACE && git submodule update --init ext-deps/zfec || exit 1 ) +} + +install_pcp +install_zfec diff --git a/Makefile.in b/Makefile.in index b160e87c3..537afb0ff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -56,7 +56,6 @@ GENERATED_HEADERS = @GENERATED_HEADERS@ ALL_INCLUDES = $(wildcard $(srcdir)/src/*.h $(srcdir)/src/*/*.h $(srcdir)/src/*/*/*.h $(srcdir)/src/*.hpp $(srcdir)/src/*/*.hpp) $(wildcard $(srcdir)/unittest/*.h) COMMON_OBJS = \ - ext-deps/zfec/zfec/fec.o \ src/bitstream.o \ src/control_socket.o \ src/debug.o \ diff --git a/autogen.sh b/autogen.sh index 939198b26..948810ddc 100755 --- a/autogen.sh +++ b/autogen.sh @@ -12,8 +12,6 @@ ORIGDIR=`pwd` cd $srcdir . ./data/scripts/add_cl_if_not_present.sh # add --with-cuda-host-compiler= to current params (Win) -. ./data/scripts/fetch_submodule.sh -fetch_submodule zfec https://files.pythonhosted.org/packages/1c/bf/b87a31205fcd2e0e4b4c9a3f7bf6f5a231e199bec5f654d7c5ac6fcec349/zfec-1.5.5.tar.gz https://github.com/tahoe-lafs/zfec # install config.guess config.sub install-sh missing echo "Running automake..." diff --git a/configure.ac b/configure.ac index 637a8690b..73e0d52ed 100644 --- a/configure.ac +++ b/configure.ac @@ -2504,12 +2504,30 @@ if test "$found_speexdsp" = yes -a "$speexdsp_req" != no; then COMMON_FLAGS="$COMMON_FLAGS${SPEEXDSP_COMMON_FLAGS:+${COMMON_FLAGS:+ }}$SPEEXDSP_COMMON_FLAGS" AC_DEFINE([HAVE_SPEEXDSP], [1], [Build with SpeexDSP support]) speexdsp=yes -elif test "speexdsp_req" = yes; then +elif test "$speexdsp_req" = yes; then AC_MSG_ERROR([SpeexDSP not found]); elif test "$found_speexdsp" = no -a "$speexdsp_req" != no; then AC_MSG_WARN([SpeexDSP was not found. Strongly recommending installing that, otherwise audio part of UG will be crippled.]) fi +# --------------------------------------------------------------------------- +# Zfec +# --------------------------------------------------------------------------- +zfec=no +AC_ARG_ENABLE(zfec, + AS_HELP_STRING([--disable-zfec], [disable zfec (default is auto)]), + [zfec_req=$enableval], + [zfec_req=$build_default]) +AC_CHECK_FILES([$srcdir/ext-deps/zfec/zfec/fec.c $srcdir/ext-deps/zfec/zfec/fec.h], [found_zfec=yes], [found_zfec=no]) + +if test "$found_zfec" = yes -a "$zfec_req" != no; then + OBJS="$OBJS ext-deps/zfec/zfec/fec.o" + AC_DEFINE([HAVE_ZFEC], [1], [Build with zfec support]) + zfec=yes +elif test "$zfec_req" = yes; then + AC_MSG_ERROR([Zfec not found]); +fi + # ------------------------------------------------------------------------------------------------- # # Jack stuff @@ -3310,6 +3328,7 @@ RESULT=`add_column "$RESULT" "Qt GUI" $qt_gui $?` RESULT=`add_column "$RESULT" "RT priority" $use_rt $?` RESULT=`add_column "$RESULT" "SpeexDSP" $speexdsp $?` RESULT=`add_column "$RESULT" "Standalone modules" $build_libraries $?` +RESULT=`add_column "$RESULT" "zfec" $zfec $?` RESULT=`end_section "$RESULT"` # audio diff --git a/data/scripts/fetch_submodule.sh b/data/scripts/fetch_submodule.sh deleted file mode 100644 index 6f5805392..000000000 --- a/data/scripts/fetch_submodule.sh +++ /dev/null @@ -1,44 +0,0 @@ -## fetches a submodule -## -## @param $1 name -## @param $2 fallback Gzip URL -## @param $3 fallback Git URL -## @param $4 if set to 1, report submodule update -## @retval 1 submodule was updated (and $4 was set to 1) -## @retval 0 otherwise -fetch_submodule() { - MODULE=$1 - FALLBACK_URL=$2 - FALLBACK_GIT_URL=$3 - SUBMODULE_UPDATED= # assume that submodule have not been updated - printf "Downloading ${MODULE}... " - if ! command -v git >/dev/null; then - if [ ! -d ext-deps/$MODULE ]; then - echo "git not found - trying to download a release" - mkdir -p ext-deps/tmp - curl -L $FALLBACK_URL | tar -C ext-deps/tmp -xz - [ -d ext-deps/$MODULE ] && rmdir ext-deps/$MODULE - mv ext-deps/tmp/* ext-deps/$MODULE - rmdir ext-deps/tmp - else - echo "skipped (ext-deps/$MODULE is already present)" - fi - elif ! git branch >/dev/null 2>&1; then - # we are not in UltraGrid git repository but can use git to download - if [ ! -d ext-deps/$MODULE ]; then - echo "git submodule found - trying to clone" - git clone $FALLBACK_GIT_URL ext-deps/$MODULE - else - echo "skipped (ext-deps/$MODULE is already present)" - fi - else - SUBMODULE_UPDATED=`git submodule update --init ext-deps/$MODULE` - if [ -z "$SUBMODULE_UPDATED" ]; then - echo "not needed" - return 0 - fi - return ${4:-0} - fi - return 0 -} - diff --git a/src/rtp/rs.cpp b/src/rtp/rs.cpp index 0fc127f97..b735c7700 100644 --- a/src/rtp/rs.cpp +++ b/src/rtp/rs.cpp @@ -46,6 +46,7 @@ #include "rtp/rs.h" #include "rtp/rtp_callback.h" #include "transmit.h" +#include "ug_runtime_error.hpp" #include "video.h" #define DEFAULT_K 200 @@ -54,12 +55,14 @@ #define MAX_K 255 #define MAX_N 255 +#ifdef HAVE_ZFEC extern "C" { #ifndef _MSC_VER #define restrict __restrict #endif #include "ext-deps/zfec/zfec/fec.h" } +#endif static void usage(); @@ -71,8 +74,12 @@ rs::rs(unsigned int k, unsigned int n) assert (k <= MAX_K); assert (n <= MAX_N); assert (m_k <= m_n); +#ifdef HAVE_ZFEC state = fec_new(m_k, m_n); assert(state != NULL); +#else + throw ug_runtime_error("zfec support is not compiled in"); +#endif } rs::rs(const char *c_cfg) @@ -99,17 +106,24 @@ rs::rs(const char *c_cfg) throw 1; } +#ifdef HAVE_ZFEC state = fec_new(m_k, m_n); assert(state != NULL); +#else + throw ug_runtime_error("zfec support is not compiled in"); +#endif } rs::~rs() { +#ifdef HAVE_ZFEC fec_free((fec_t *) state); +#endif } shared_ptr rs::encode(shared_ptr in) { +#ifdef HAVE_ZFEC video_payload_hdr_t hdr; format_video_header(in.get(), 0, 0, hdr); size_t hdr_len = sizeof(hdr); @@ -163,6 +177,10 @@ shared_ptr rs::encode(shared_ptr in) vf_free(frame); } }; +#else + (void) in; + return {}; +#endif // defined HAVE_ZFEC } int rs::get_ss(int hdr_len, int len) { @@ -172,6 +190,7 @@ int rs::get_ss(int hdr_len, int len) { bool rs::decode(char *in, int in_len, char **out, int *len, std::map const & c_m) { +#ifdef HAVE_ZFEC std::map m = c_m; // make private copy unsigned int ss = in_len / m_n; void *pkt[m_n]; @@ -307,6 +326,13 @@ bool rs::decode(char *in, int in_len, char **out, int *len, *len = out_sz; *out = (char *) in + sizeof(uint32_t); #endif +#else // !defined HAVE_ZFEC + (void) in; + (void) in_len; + (void) out; + (void) len; + (void) c_m; +#endif // defined HAVE_ZFEC return true; }