From b7269229613afe50eb18ff7a3d9d384214af96f7 Mon Sep 17 00:00:00 2001 From: "wenjie.zhao" <740936897@qq.com> Date: Tue, 21 Sep 2021 22:30:20 +0800 Subject: [PATCH 1/5] + add srs for windows support(with cygwin64) --- .../libsrtp-2-fit/crypto/math/datatypes.c | 2 +- trunk/auto/depends.sh | 188 +++++++++--------- trunk/auto/setup_variables.sh | 26 ++- trunk/auto/utest.sh | 6 +- trunk/configure | 14 +- trunk/src/app/srs_app_config.cpp | 4 +- trunk/src/app/srs_app_server.cpp | 6 +- trunk/src/app/srs_app_uuid.cpp | 6 - trunk/src/kernel/srs_kernel_error.hpp | 1 + trunk/src/protocol/srs_service_st.cpp | 10 +- 10 files changed, 143 insertions(+), 120 deletions(-) diff --git a/trunk/3rdparty/libsrtp-2-fit/crypto/math/datatypes.c b/trunk/3rdparty/libsrtp-2-fit/crypto/math/datatypes.c index 8a342e2af2..5a9e1a9382 100644 --- a/trunk/3rdparty/libsrtp-2-fit/crypto/math/datatypes.c +++ b/trunk/3rdparty/libsrtp-2-fit/crypto/math/datatypes.c @@ -79,7 +79,7 @@ int octet_get_weight(uint8_t octet) /* the value MAX_PRINT_STRING_LEN is defined in datatypes.h */ -char bit_string[MAX_PRINT_STRING_LEN]; +static char bit_string[MAX_PRINT_STRING_LEN]; uint8_t srtp_nibble_to_hex_char(uint8_t nibble) { diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index fac9b4583e..43ceeace26 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -322,6 +322,23 @@ function OSX_prepare() # donot prepare tools, for srs-librtmp depends only gcc and g++. OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi +##################################################################################### +# For windows with cygwin64 +##################################################################################### +OS_IS_WINDOWS_CYGWIN64=NO +function windows_cygwin64_prepare() +{ +# TODO auto install cygwin64 tools ? + if [[ $OSTYPE == cygwin ]]; then + OS_IS_WINDOWS_CYGWIN64=YES + SRS_WINDOWS=YES + fi + + return 0 +} + +windows_cygwin64_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "windows_cygwin64 prepare failed, ret=$ret"; exit $ret; fi + ##################################################################################### # for Centos, auto install tools by yum ##################################################################################### @@ -363,11 +380,12 @@ function _srs_link_file() ##################################################################################### # Only supports: # linux, centos/ubuntu as such, +# windows(with cygwin64 toolchain) # cross build for embeded system, for example, mips or arm, # directly build on arm/mips, for example, pi or cubie, # export srs-librtmp # others is invalid. -if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_CROSS_BUILD = NO ]]; then +if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_CROSS_BUILD = NO && $OS_IS_WINDOWS_CYGWIN64 = NO ]]; then echo "Your OS `uname -s` is not supported." exit 1 fi @@ -387,6 +405,10 @@ fi if [[ $SRS_OSX == YES ]]; then _ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG" fi +# for windows/cygwin +if [[ $OS_IS_WINDOWS_CYGWIN64 = YES ]]; then + _ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG" +fi # Whether enable debug stats. if [[ $SRS_DEBUG_STATS == YES ]]; then _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS" @@ -405,27 +427,21 @@ fi _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}" _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}" # Patched ST from https://github.com/ossrs/state-threads/tree/srs -if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ]]; then - echo "The state-threads is ok."; +if [[ -f ${SRS_3RD_ST_PATH}/libst.a ]]; then + echo -e "The state-threads is ok."; else echo "Building state-threads."; ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && - # Create a hidden directory .src - cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src && - # Link source files under .src - _srs_link_file .src/ ./ ./ && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && + cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && # Build source code. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} && - cd .. && rm -rf st && ln -sf st-srs/${_ST_OBJ} st + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_PATH} ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi -# Always update the links. -(cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf st && ln -sf st-srs/${_ST_OBJ} st) -(cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st) -if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi ##################################################################################### # nginx for HLS, nginx-1.5.0 @@ -457,23 +473,23 @@ html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=l # copy players to nginx html dir. rm -rf ${SRS_OBJS}/nginx/html/players && -ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players +cp -rf `pwd`/research/players ${SRS_OBJS}/nginx/html/ # for favicon.ico rm -rf ${SRS_OBJS}/nginx/html/favicon.ico && -ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico +cp -f `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico # For srs-console. rm -rf ${SRS_OBJS}/nginx/html/console && -ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console +cp -rf `pwd`/research/console ${SRS_OBJS}/nginx/html/ # For SRS signaling. rm -rf ${SRS_OBJS}/nginx/html/demos && -ln -sf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/demos +cp -rf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/ # For home page index.html rm -rf ${SRS_OBJS}/nginx/html/index.html && -ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html +cp -f `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html # nginx.html to detect whether nginx is alive echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html @@ -529,15 +545,15 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then OPENSSL_CONFIG="./Configure linux-generic32" if [[ $SRS_CROSS_BUILD_ARMV7 == YES ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi if [[ $SRS_CROSS_BUILD_AARCH64 == YES ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi - elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then + elif [[ ! -f ${SRS_3RD_OPENSSL_PATH}/lib/libssl.a ]]; then # Try to use exists libraries. - if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then - (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && - ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a && - mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig) - (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && - ln -sf /usr/local/ssl/include/openssl) - fi + #if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then + # (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && + # ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a && + # mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig) + # (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && + # ln -sf /usr/local/ssl/include/openssl) + #fi # Warning if not use the system ssl. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then echo "Warning: Local openssl is on, ignore system openssl" @@ -556,10 +572,10 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then # Use 1.0 if required. if [[ $SRS_SSL_1_0 == YES ]]; then OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild. - OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && OPENSSL_UNZIP="tar xf ../../3rdparty/$OPENSSL_CANDIDATE.tar.gz" + OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && OPENSSL_UNZIP="tar xf ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE.tar.gz" else OPENSSL_AR="$SRS_TOOL_AR" - OPENSSL_CANDIDATE="openssl-1.1-fit" && OPENSSL_UNZIP="cp -R ../../3rdparty/$OPENSSL_CANDIDATE ." + OPENSSL_CANDIDATE="openssl-1.1-fit" && OPENSSL_UNZIP="cp -R ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE ." fi # # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options @@ -570,28 +586,24 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then #OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers" # # cross build not specified, if exists flag, need to rebuild for no-arm platform. - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/$OPENSSL_CANDIDATE/_release/lib/libssl.a ]]; then + if [[ -f ${SRS_3RD_OPENSSL_PATH}/lib/libssl.a ]]; then echo "The $OPENSSL_CANDIDATE is ok."; else echo "Building $OPENSSL_CANDIDATE."; ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && cd ${SRS_OBJS}/${SRS_PLATFORM} && - ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=`pwd`/_release $OPENSSL_OPTIONS && - make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw && - cd .. && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && + ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=${SRS_3RD_OPENSSL_PATH} $OPENSSL_OPTIONS && + make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw ) fi # Which lib we use. - OPENSSL_LIB="$OPENSSL_CANDIDATE/_release" - if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then - OPENSSL_LIB="openssl" - fi + #OPENSSL_LIB="$OPENSSL_CANDIDATE/_release" + #if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then + # OPENSSL_LIB="openssl" + #fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl) - (cd ${SRS_OBJS} && rm -rf openssl && ln -sf ${SRS_PLATFORM}/${OPENSSL_LIB} openssl) - if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build $OPENSSL_CANDIDATE failed."; exit -1; fi fi ##################################################################################### @@ -601,7 +613,7 @@ SRTP_OPTIONS="" # If use ASM for SRTP, we enable openssl(with ASM). if [[ $SRS_SRTP_ASM == YES ]]; then SRTP_OPTIONS="--enable-openssl" - SRTP_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/openssl/lib/pkgconfig ./configure" + SRTP_CONFIGURE="env PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure" else SRTP_CONFIGURE="./configure" fi @@ -609,24 +621,23 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST" fi # Patched ST from https://github.com/ossrs/state-threads/tree/srs -if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/_release/lib/libsrtp2.a ]]; then +if [[ -f ${SRS_3RD_SRTP2_PATH}/lib/libsrtp2.a ]]; then echo "The libsrtp-2-fit is ok."; else echo "Building libsrtp-2-fit."; ( - rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit && - $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release && - make ${SRS_JOBS} && make install && - cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2 + rm -rf ${SRS_3RD_SRTP2_PATH} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && + rm -rf libsrtp-2-fit && + cp -R ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit . && + cd libsrtp-2-fit && + $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_3RD_SRTP2_PATH} && + make ${SRS_JOBS} && make install ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp-2-fit failed, ret=$ret"; exit $ret; fi -# Always update the links. -(cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2) -(cd ${SRS_OBJS} && rm -rf srtp2 && ln -sf ${SRS_PLATFORM}/libsrtp-2-fit/_release srtp2) -if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit static lib failed."; exit -1; fi +#if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit static lib failed."; exit -1; fi ##################################################################################### # libopus, for WebRTC to transcode AAC with Opus. @@ -637,24 +648,22 @@ if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then if [[ $SRS_SHARED_FFMPEG == NO ]]; then OPUS_OPTIONS="--disable-shared --disable-doc" fi - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1/_release/lib/libopus.a ]]; then + if [[ -f ${SRS_3RD_OPUS_PATH}/lib/libopus.a ]]; then echo "The opus-1.3.1 is ok."; else echo "Building opus-1.3.1."; ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - tar xf ../../3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 && - ./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS && - make ${SRS_JOBS} && make install && - cd .. && rm -rf opus && ln -sf opus-1.3.1/_release opus + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && + cd ${SRS_OBJS}/${SRS_PLATFORM} && + tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz && + cd opus-1.3.1 && + ./configure --prefix=${SRS_3RD_OPUS_PATH} --enable-static $OPUS_OPTIONS && + make ${SRS_JOBS} && + make install ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build opus-1.3.1 failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf opus && ln -sf opus-1.3.1/_release opus) - (cd ${SRS_OBJS} && rm -rf opus && ln -sf ${SRS_PLATFORM}/opus-1.3.1/_release opus) - if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi fi ##################################################################################### @@ -665,7 +674,7 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then if [[ $SRS_CROSS_BUILD == YES ]]; then FFMPEG_CONFIGURE=./configure else - FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/opus/lib/pkgconfig ./configure" + FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=${SRS_3RD_OPUS_PATH}/lib/pkgconfig ./configure" fi # If disable nasm, disable all ASMs. @@ -689,17 +698,17 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus" fi - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/_release/lib/libavcodec.a ]]; then + if [[ -f ${SRS_3RD_FFMPEG_PATH}/lib/libavcodec.a ]]; then echo "The ffmpeg-4-fit is ok."; else echo "Building ffmpeg-4-fit."; ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && - # Create a hidden directory .src - cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && cp -R ../../../3rdparty/ffmpeg-4-fit/* . && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && + cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && # Build source code. $FFMPEG_CONFIGURE \ - --prefix=`pwd`/_release --pkg-config=pkg-config \ + --prefix=${SRS_3RD_FFMPEG_PATH} --pkg-config=pkg-config \ --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \ --disable-everything ${FFMPEG_OPTIONS} \ --disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \ @@ -716,16 +725,11 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h && sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h fi && - make ${SRS_JOBS} && make install && - cd .. && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg + make ${SRS_JOBS} && make install ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg) - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg-4-fit/_release ffmpeg) - if [ ! -f ${SRS_OBJS}/ffmpeg/lib/libavcodec.a ]; then echo "Build ffmpeg-4-fit failed."; exit -1; fi fi ##################################################################################### @@ -760,12 +764,12 @@ fi # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119 ##################################################################################### if [[ $SRS_SRT == YES ]]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/srt/lib/libsrt.a ]]; then + if [[ -f ${SRS_3RD_SRT_PATH}/lib/libsrt.a ]]; then echo "libsrt-1-fit is ok."; else echo "Build srt-1-fit" ( - if [[ ! -d ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/pkgconfig ]]; then + if [[ ! -d ${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ]]; then echo "OpenSSL pkgconfig no found, build srt-1-fit failed."; exit -1; fi @@ -776,23 +780,21 @@ if [[ $SRS_SRT == YES ]]; then else LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0" fi + + if [[ $SRS_WINDOWS == YES ]]; then + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix" + fi + # Start build libsrt. - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} && - cp -R ../../3rdparty/srt-1-fit srt-1-fit && cd srt-1-fit && - PKG_CONFIG_PATH=../openssl/lib/pkgconfig ./configure --prefix=`pwd`/_release $LIBSRT_OPTIONS && - make ${SRS_JOBS} && make install && - cd .. && rm -rf srt && ln -sf srt-1-fit/_release srt && - # If exists lib64 of libsrt, link it to lib - if [[ -d srt/lib64 ]]; then - cd srt && ln -sf lib64 lib - fi + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && + cd ${SRS_OBJS}/${SRS_PLATFORM} && + cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM} && + cd srt-1-fit && + PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure --prefix=${SRS_3RD_SRT_PATH} $LIBSRT_OPTIONS && + make ${SRS_JOBS} && make install ) ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srt && ln -sf srt-1-fit/_release srt) - (cd ${SRS_OBJS} && rm -rf srt && ln -sf ${SRS_PLATFORM}/srt-1-fit/_release srt) - if [ ! -f ${SRS_OBJS}/srt/lib/libsrt.a ]; then echo "Build srt-1-fit failed."; exit -1; fi fi ##################################################################################### @@ -805,16 +807,12 @@ if [ $SRS_UTEST = YES ]; then echo "Build gtest-1.6.0"; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - unzip -q ../../3rdparty/gtest-1.6.0.zip && - rm -rf gtest && ln -sf gtest-1.6.0 gtest + unzip -q ${SRS_WORKDIR}/3rdparty/gtest-1.6.0.zip && + mv ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 ${SRS_OBJS}/${SRS_PLATFORM}/gtest ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest && ln -sf gtest-1.6.0 gtest) - (cd ${SRS_OBJS} && rm -rf gtest && ln -sf ${SRS_PLATFORM}/gtest-1.6.0 gtest) - if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "Build gtest-1.6.0 failed."; exit -1; fi fi ##################################################################################### diff --git a/trunk/auto/setup_variables.sh b/trunk/auto/setup_variables.sh index cf9b1a98b6..422c6c7a40 100755 --- a/trunk/auto/setup_variables.sh +++ b/trunk/auto/setup_variables.sh @@ -5,6 +5,10 @@ OS_KERNEL_NAME=$(uname -s) OS_KERNRL_RELEASE=$(uname -r|awk -F '-' '{print $1}') OS_PREFIX="Platform" +if [[ $OSTYPE == cygwin ]]; then + OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}') +fi + # Build platform cache. SRS_PLATFORM="${SRS_BUILD_TAG}${OS_PREFIX}-${OS_KERNEL_NAME}-${OS_KERNRL_RELEASE}" # Build platform cache with gcc version. @@ -23,17 +27,29 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then SRS_PLATFORM="${SRS_PLATFORM}-CROSSBUILD-$(echo $SRS_TOOL_CC|awk -F - '{print $1}')" fi +# 3rdparty lib path +SRS_3RD_ST_PATH=${SRS_OBJS}/st +SRS_3RD_FFMPEG_PATH=${SRS_OBJS}/ffmpeg +SRS_3RD_OPUS_PATH=${SRS_OBJS}/opus +SRS_3RD_SRTP2_PATH=${SRS_OBJS}/srtp2 +SRS_3RD_OPENSSL_PATH=${SRS_OBJS}/openssl +SRS_3RD_SRT_PATH=${SRS_OBJS}/srt + echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS_DIR: ${SRS_OBJS_DIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}" # For src object files on each platform. ( mkdir -p ${SRS_OBJS_DIR} && cd ${SRS_OBJS_DIR} && rm -rf src utest srs srs_utest research include lib srs_hls_ingester srs_mp4_parser && - mkdir -p ${SRS_PLATFORM}/src && ln -sf ${SRS_PLATFORM}/src && - mkdir -p ${SRS_PLATFORM}/utest && ln -sf ${SRS_PLATFORM}/utest && - mkdir -p ${SRS_PLATFORM}/research && ln -sf ${SRS_PLATFORM}/research && - mkdir -p ${SRS_PLATFORM}/include && ln -sf ${SRS_PLATFORM}/include && - mkdir -p ${SRS_PLATFORM}/lib && ln -sf ${SRS_PLATFORM}/lib + mkdir -p ${SRS_PLATFORM}/src && + mkdir -p ${SRS_PLATFORM}/research && + mkdir -p ${SRS_PLATFORM}/include && + mkdir -p ${SRS_PLATFORM}/lib && + mkdir -p ${SRS_3RD_ST_PATH} && + mkdir -p ${SRS_3RD_FFMPEG_PATH} && + mkdir -p ${SRS_3RD_OPUS_PATH} && + mkdir -p ${SRS_3RD_SRTP2_PATH} && + mkdir -p ${SRS_3RD_OPENSSL_PATH} ) if [[ $SRS_CLEAN == NO ]]; then echo "Fast cleanup, if need to do full cleanup, please use: make clean" diff --git a/trunk/auto/utest.sh b/trunk/auto/utest.sh index d77964e96b..f24b8f6b46 100755 --- a/trunk/auto/utest.sh +++ b/trunk/auto/utest.sh @@ -9,16 +9,16 @@ # $MODULE_DIR the src dir of utest code. ie. src/utest # $LINK_OPTIONS the link options for utest. ie. -lpthread -ldl -FILE=${SRS_OBJS}/utest/${SRS_MAKEFILE} +FILE=${SRS_OBJS}/${SRS_PLATFORM}/utest/${SRS_MAKEFILE} # create dir for Makefile -mkdir -p ${SRS_OBJS}/utest +mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/utest # the prefix to generate the objs/utest/Makefile # dirs relative to current dir(objs/utest), it's trunk/objs/utest # trunk of srs, which contains the src dir, relative to objs/utest, it's trunk SRS_TRUNK_PREFIX=../../.. # gest dir, relative to objs/utest, it's trunk/objs/gtest -GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/gtest +GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${SRS_PLATFORM}/gtest cat << END > ${FILE} # user must run make the ${SRS_OBJS_DIR}/utest dir diff --git a/trunk/configure b/trunk/configure index 51331458d8..b5bccc2e93 100755 --- a/trunk/configure +++ b/trunk/configure @@ -4,7 +4,7 @@ # the main output dir, all configure and make output are in this dir. ##################################################################################### # create the main objs -SRS_WORKDIR="." +SRS_WORKDIR=`pwd` SRS_OBJS_DIR="objs" SRS_OBJS="${SRS_WORKDIR}/${SRS_OBJS_DIR}" SRS_MAKEFILE="Makefile" @@ -87,6 +87,9 @@ CppStd="-ansi" if [[ $SRS_CXX11 == YES ]]; then CppStd="-std=c++11" fi +if [[ $SRS_WINDOWS == YES ]]; then + CppStd="-std=gnu++11" +fi if [[ $SRS_CXX14 == YES ]]; then CppStd="-std=c++14" fi @@ -164,7 +167,7 @@ fi # srt code path if [[ $SRS_SRT == YES ]]; then - SrsSRTRoot="${SRS_WORKDIR}/src/srt" + SrsSRTRoot="src/srt" LibSRTRoot="${SRS_OBJS_DIR}/srt/include"; LibSRTfile="${SRS_OBJS_DIR}/srt/lib/libsrt.a" if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-L${SRS_OBJS_DIR}/srt/lib -lsrt"; fi fi @@ -188,10 +191,15 @@ if [[ $SRS_GCOV == YES ]]; then fi # For FFMPEG/RTC on Linux. -if [[ $SRS_OSX != YES && $SRS_RTC == YES && $SRS_FFMPEG_FIT == YES ]]; then +if [[ $SRS_OSX != YES && $SRS_WINDOWS != YES && $SRS_RTC == YES && $SRS_FFMPEG_FIT == YES ]]; then SrsLinkOptions="${SrsLinkOptions} -lrt"; fi +# For FFMPEG/RTC on windows. +if [[ $SRS_WINDOWS == YES && $SRS_FFMPEG_FIT == YES ]]; then + SrsLinkOptions="${SrsLinkOptions} -lbcrypt"; +fi + ##################################################################################### # Modules, compile each module, then link to binary # diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 147dd1ed8f..a5827dbd26 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -4729,8 +4729,8 @@ int SrsConfig::get_rtc_server_reuseport() #if !defined(SO_REUSEPORT) if (v > 1) { - srs_warn("REUSEPORT not supported, reset %d to %d", reuseport, DEFAULT); - v = 1 + //srs_warn("REUSEPORT not supported, reset %d to %d", reuseport, DEFAULT); + //v = 1 } #endif diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 1fd14ff963..a815b20f55 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -13,7 +13,7 @@ #include #include #include -#ifndef SRS_OSX +#if !defined(SRS_OSX) && !defined(SRS_WINDOWS) #include #endif using namespace std; @@ -429,7 +429,7 @@ srs_error_t SrsInotifyWorker::start() { srs_error_t err = srs_success; -#ifndef SRS_OSX +#if !defined(SRS_OSX) && !defined(SRS_WINDOWS) // Whether enable auto reload config. bool auto_reload = _srs_config->inotify_auto_reload(); if (!auto_reload && _srs_in_docker && _srs_config->auto_reload_for_docker()) { @@ -509,7 +509,7 @@ srs_error_t SrsInotifyWorker::cycle() { srs_error_t err = srs_success; -#ifndef SRS_OSX +#if !defined(SRS_OSX) && !defined(SRS_WINDOWS) string config_path = _srs_config->config(); string config_file = srs_path_basename(config_path); string k8s_file = "..data"; diff --git a/trunk/src/app/srs_app_uuid.cpp b/trunk/src/app/srs_app_uuid.cpp index 721efbf7b3..4429f246e0 100644 --- a/trunk/src/app/srs_app_uuid.cpp +++ b/trunk/src/app/srs_app_uuid.cpp @@ -226,10 +226,6 @@ static inline __attribute__((const)) int is_power_of_2(unsigned long num) return (num != 0 && ((num & (num - 1)) == 0)); } -#ifndef HAVE_LOFF_T -typedef int64_t loff_t; -#endif - #if !defined(HAVE_DIRFD) && (!defined(HAVE_DECL_DIRFD) || HAVE_DECL_DIRFD == 0) && defined(HAVE_DIR_DD_FD) #include #include @@ -1075,8 +1071,6 @@ void uuid_generate(uuid_t out) #include #include -#include - //#include "randutils.h" #ifdef HAVE_TLS diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index d1067eefb1..0324c4a996 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -101,6 +101,7 @@ #define ERROR_SOCKET_SETREUSEADDR 1079 #define ERROR_SOCKET_SETCLOSEEXEC 1080 #define ERROR_SOCKET_ACCEPT 1081 +#define ERROR_ST_SET_SELECT 1082 /////////////////////////////////////////////////////// // RTMP protocol error. diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_service_st.cpp index 9b7c9b96ca..2d8c7e64eb 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_service_st.cpp @@ -49,9 +49,15 @@ srs_error_t srs_st_init() // Select the best event system available on the OS. In Linux this is // epoll(). On BSD it will be kqueue. - if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { - return srs_error_new(ERROR_ST_SET_EPOLL, "st enable st failed, current is %s", st_get_eventsys_name()); +#ifdef SRS_WINDOWS + if (st_set_eventsys(ST_EVENTSYS_SELECT) == -1) { + return srs_error_new(ERROR_ST_SET_SELECT, "st enable st failed, current is %s", st_get_eventsys_name()); } +#else + if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) { + return srs_error_new(ERROR_ST_SET_EPOLL, "st enable st failed, current is %s", st_get_eventsys_name()); + } +#endif // Before ST init, we might have already initialized the background cid. SrsContextId cid = _srs_context->get_id(); From 18a488b3f0616a545685b35e816b34927a9b7425 Mon Sep 17 00:00:00 2001 From: "wenjie.zhao" <740936897@qq.com> Date: Tue, 21 Sep 2021 23:04:54 +0800 Subject: [PATCH 2/5] * fix srt lib64 path issue --- trunk/auto/depends.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index 43ceeace26..4110368501 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -791,7 +791,12 @@ if [[ $SRS_SRT == YES ]]; then cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM} && cd srt-1-fit && PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure --prefix=${SRS_3RD_SRT_PATH} $LIBSRT_OPTIONS && - make ${SRS_JOBS} && make install + make ${SRS_JOBS} && make install && + + # If exists lib64 of libsrt, link it to lib + if [[ -d ${SRS_3RD_SRT_PATH}/lib64 ]]; then + mv ${SRS_3RD_SRT_PATH}/lib64 ${SRS_3RD_SRT_PATH}/lib + fi ) ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi fi From d2383dee6be5c2a59ee1e3560f1d773bd003c2bf Mon Sep 17 00:00:00 2001 From: "wenjie.zhao" <740936897@qq.com> Date: Wed, 22 Sep 2021 11:46:42 +0800 Subject: [PATCH 3/5] * fix ffmpeg path error --- trunk/auto/depends.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index 4110368501..ec90341275 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -739,13 +739,12 @@ fi SYSTEMP_FFMPEG_BIN=/usr/local/bin/ffmpeg if [[ ! -f $SYSTEMP_FFMPEG_BIN ]]; then SYSTEMP_FFMPEG_BIN=/usr/local/ffmpeg/bin/ffmpeg; fi # Always link the ffmpeg tools if exists. -if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then - mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin && - ln -sf $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg && - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg) +if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg ]]; then + mkdir -p ${SRS_OBJS}/ffmpeg/bin && + cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ffmpeg fi if [ $SRS_FFMPEG_TOOL = YES ]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg ]]; then + if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then echo "ffmpeg-4.1 is ok."; else echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}" @@ -754,10 +753,6 @@ if [ $SRS_FFMPEG_TOOL = YES ]; then echo -e "${RED} or disable it by --without-ffmpeg${BLACK}" exit -1; fi - # Always update the links. - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg) - fi fi ##################################################################################### From 5807e079855585b00a9f3418f018c41bfd8ab694 Mon Sep 17 00:00:00 2001 From: "wenjie.zhao" <740936897@qq.com> Date: Thu, 23 Sep 2021 00:10:23 +0800 Subject: [PATCH 4/5] * fix : tab to space --- trunk/auto/depends.sh | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index ec90341275..9909b1f1d7 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -329,12 +329,12 @@ OS_IS_WINDOWS_CYGWIN64=NO function windows_cygwin64_prepare() { # TODO auto install cygwin64 tools ? - if [[ $OSTYPE == cygwin ]]; then - OS_IS_WINDOWS_CYGWIN64=YES - SRS_WINDOWS=YES - fi - - return 0 + if [[ $OSTYPE == cygwin ]]; then + OS_IS_WINDOWS_CYGWIN64=YES + SRS_WINDOWS=YES + fi + + return 0 } windows_cygwin64_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "windows_cygwin64 prepare failed, ret=$ret"; exit $ret; fi @@ -380,7 +380,7 @@ function _srs_link_file() ##################################################################################### # Only supports: # linux, centos/ubuntu as such, -# windows(with cygwin64 toolchain) +# windows(with cygwin64 toolchain) # cross build for embeded system, for example, mips or arm, # directly build on arm/mips, for example, pi or cubie, # export srs-librtmp @@ -407,7 +407,7 @@ if [[ $SRS_OSX == YES ]]; then fi # for windows/cygwin if [[ $OS_IS_WINDOWS_CYGWIN64 = YES ]]; then - _ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG" + _ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG" fi # Whether enable debug stats. if [[ $SRS_DEBUG_STATS == YES ]]; then @@ -433,11 +433,11 @@ else echo "Building state-threads."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && - cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM} && + cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM} && cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && # Build source code. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} && - cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_PATH} + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_PATH} ) fi # check status @@ -592,7 +592,7 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then echo "Building $OPENSSL_CANDIDATE."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && - cd ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=${SRS_3RD_OPENSSL_PATH} $OPENSSL_OPTIONS && make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw ) @@ -627,10 +627,10 @@ else echo "Building libsrtp-2-fit."; ( rm -rf ${SRS_3RD_SRTP2_PATH} && - cd ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf libsrtp-2-fit && - cp -R ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit . && - cd libsrtp-2-fit && + cp -R ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit . && + cd libsrtp-2-fit && $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_3RD_SRTP2_PATH} && make ${SRS_JOBS} && make install ) @@ -654,12 +654,12 @@ if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then echo "Building opus-1.3.1."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && - cd ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz && - cd opus-1.3.1 && + cd opus-1.3.1 && ./configure --prefix=${SRS_3RD_OPUS_PATH} --enable-static $OPUS_OPTIONS && make ${SRS_JOBS} && - make install + make install ) fi # check status @@ -704,8 +704,8 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then echo "Building ffmpeg-4-fit."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && - cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM} && - cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && + cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && # Build source code. $FFMPEG_CONFIGURE \ --prefix=${SRS_3RD_FFMPEG_PATH} --pkg-config=pkg-config \ @@ -775,20 +775,20 @@ if [[ $SRS_SRT == YES ]]; then else LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0" fi - - if [[ $SRS_WINDOWS == YES ]]; then - LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix" - fi - + + if [[ $SRS_WINDOWS == YES ]]; then + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix" + fi + # Start build libsrt. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && - cd ${SRS_OBJS}/${SRS_PLATFORM} && + cd ${SRS_OBJS}/${SRS_PLATFORM} && cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM} && - cd srt-1-fit && + cd srt-1-fit && PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure --prefix=${SRS_3RD_SRT_PATH} $LIBSRT_OPTIONS && make ${SRS_JOBS} && make install && - - # If exists lib64 of libsrt, link it to lib + + # If exists lib64 of libsrt, link it to lib if [[ -d ${SRS_3RD_SRT_PATH}/lib64 ]]; then mv ${SRS_3RD_SRT_PATH}/lib64 ${SRS_3RD_SRT_PATH}/lib fi @@ -808,7 +808,7 @@ if [ $SRS_UTEST = YES ]; then ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 && cd ${SRS_OBJS}/${SRS_PLATFORM} && unzip -q ${SRS_WORKDIR}/3rdparty/gtest-1.6.0.zip && - mv ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 ${SRS_OBJS}/${SRS_PLATFORM}/gtest + mv ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 ${SRS_OBJS}/${SRS_PLATFORM}/gtest ) fi # check status From 07551e6ba0bdad38be668ca57508d60177c640b9 Mon Sep 17 00:00:00 2001 From: "wenjie.zhao" <740936897@qq.com> Date: Thu, 23 Sep 2021 16:26:51 +0800 Subject: [PATCH 5/5] + support platform-dependent compile --- trunk/auto/depends.sh | 75 ++++++++++++++++++++++------------- trunk/auto/setup_variables.sh | 38 +++++++++++++++--- 2 files changed, 79 insertions(+), 34 deletions(-) diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index 9909b1f1d7..654160a992 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -427,7 +427,9 @@ fi _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}" _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}" # Patched ST from https://github.com/ossrs/state-threads/tree/srs -if [[ -f ${SRS_3RD_ST_PATH}/libst.a ]]; then +if [[ -f ${SRS_3RD_ST_STORE_PATH}/libst.a ]]; then + rm -rf ${SRS_3RD_ST_PATH} && + cp -rf ${SRS_3RD_ST_STORE_PATH} ${SRS_OBJS} && echo -e "The state-threads is ok."; else echo "Building state-threads."; @@ -437,7 +439,8 @@ else cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && # Build source code. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} && - cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_PATH} + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_PATH} && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/* ${SRS_3RD_ST_STORE_PATH} ) fi # check status @@ -545,7 +548,7 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then OPENSSL_CONFIG="./Configure linux-generic32" if [[ $SRS_CROSS_BUILD_ARMV7 == YES ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi if [[ $SRS_CROSS_BUILD_AARCH64 == YES ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi - elif [[ ! -f ${SRS_3RD_OPENSSL_PATH}/lib/libssl.a ]]; then + elif [[ ! -f ${SRS_3RD_OPENSSL_STORE_PATH}/lib/libssl.a ]]; then # Try to use exists libraries. #if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then # (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && @@ -586,15 +589,18 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then #OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers" # # cross build not specified, if exists flag, need to rebuild for no-arm platform. - if [[ -f ${SRS_3RD_OPENSSL_PATH}/lib/libssl.a ]]; then + if [[ -f ${SRS_3RD_OPENSSL_STORE_PATH}/lib/libssl.a ]]; then + rm -rf ${SRS_3RD_OPENSSL_PATH} && + cp -rf ${SRS_3RD_OPENSSL_STORE_PATH} ${SRS_OBJS} && echo "The $OPENSSL_CANDIDATE is ok."; else echo "Building $OPENSSL_CANDIDATE."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && cd ${SRS_OBJS}/${SRS_PLATFORM} && - ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=${SRS_3RD_OPENSSL_PATH} $OPENSSL_OPTIONS && - make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw + ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=${SRS_3RD_OPENSSL_STORE_PATH} $OPENSSL_OPTIONS && + make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw && + cp -rf ${SRS_3RD_OPENSSL_STORE_PATH} ${SRS_OBJS} ) fi # Which lib we use. @@ -621,7 +627,9 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST" fi # Patched ST from https://github.com/ossrs/state-threads/tree/srs -if [[ -f ${SRS_3RD_SRTP2_PATH}/lib/libsrtp2.a ]]; then +if [[ -f ${SRS_3RD_SRTP2_STORE_PATH}/lib/libsrtp2.a ]]; then + rm -rf ${SRS_3RD_SRTP2_PATH} && + cp -rf ${SRS_3RD_SRTP2_STORE_PATH} ${SRS_OBJS} && echo "The libsrtp-2-fit is ok."; else echo "Building libsrtp-2-fit."; @@ -631,8 +639,9 @@ else rm -rf libsrtp-2-fit && cp -R ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit && - $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_3RD_SRTP2_PATH} && - make ${SRS_JOBS} && make install + $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_3RD_SRTP2_STORE_PATH} && + make ${SRS_JOBS} && make install && + cp -rf ${SRS_3RD_SRTP2_STORE_PATH} ${SRS_OBJS} ) fi # check status @@ -648,7 +657,9 @@ if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then if [[ $SRS_SHARED_FFMPEG == NO ]]; then OPUS_OPTIONS="--disable-shared --disable-doc" fi - if [[ -f ${SRS_3RD_OPUS_PATH}/lib/libopus.a ]]; then + if [[ -f ${SRS_3RD_OPUS_STORE_PATH}/lib/libopus.a ]]; then + rm -rf ${SRS_3RD_OPUS_PATH} && + cp -rf ${SRS_3RD_OPUS_STORE_PATH} ${SRS_OBJS} && echo "The opus-1.3.1 is ok."; else echo "Building opus-1.3.1."; @@ -657,9 +668,10 @@ if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then cd ${SRS_OBJS}/${SRS_PLATFORM} && tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 && - ./configure --prefix=${SRS_3RD_OPUS_PATH} --enable-static $OPUS_OPTIONS && + ./configure --prefix=${SRS_3RD_OPUS_STORE_PATH} --enable-static $OPUS_OPTIONS && make ${SRS_JOBS} && - make install + make install && + cp -rf ${SRS_3RD_OPUS_STORE_PATH} ${SRS_OBJS} ) fi # check status @@ -674,7 +686,7 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then if [[ $SRS_CROSS_BUILD == YES ]]; then FFMPEG_CONFIGURE=./configure else - FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=${SRS_3RD_OPUS_PATH}/lib/pkgconfig ./configure" + FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=${SRS_3RD_OPUS_STORE_PATH}/lib/pkgconfig ./configure" fi # If disable nasm, disable all ASMs. @@ -698,7 +710,9 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus" fi - if [[ -f ${SRS_3RD_FFMPEG_PATH}/lib/libavcodec.a ]]; then + if [[ -f ${SRS_3RD_FFMPEG_STORE_PATH}/lib/libavcodec.a ]]; then + rm -rf ${SRS_3RD_FFMPEG_PATH} && + cp -rf ${SRS_3RD_FFMPEG_STORE_PATH} ${SRS_OBJS} && echo "The ffmpeg-4-fit is ok."; else echo "Building ffmpeg-4-fit."; @@ -708,7 +722,7 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && # Build source code. $FFMPEG_CONFIGURE \ - --prefix=${SRS_3RD_FFMPEG_PATH} --pkg-config=pkg-config \ + --prefix=${SRS_3RD_FFMPEG_STORE_PATH} --pkg-config=pkg-config \ --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \ --disable-everything ${FFMPEG_OPTIONS} \ --disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \ @@ -725,7 +739,8 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h && sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h fi && - make ${SRS_JOBS} && make install + make ${SRS_JOBS} && make install && + cp -rf ${SRS_3RD_FFMPEG_STORE_PATH} ${SRS_OBJS} ) fi # check status @@ -736,15 +751,15 @@ fi # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2. ##################################################################################### # Guess whether the ffmpeg is. -SYSTEMP_FFMPEG_BIN=/usr/local/bin/ffmpeg -if [[ ! -f $SYSTEMP_FFMPEG_BIN ]]; then SYSTEMP_FFMPEG_BIN=/usr/local/ffmpeg/bin/ffmpeg; fi +SYSTEMP_FFMPEG_BIN=`which ffmpeg` # Always link the ffmpeg tools if exists. -if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg ]]; then +if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then mkdir -p ${SRS_OBJS}/ffmpeg/bin && - cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ffmpeg + cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ fi if [ $SRS_FFMPEG_TOOL = YES ]; then if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then + cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ && echo "ffmpeg-4.1 is ok."; else echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}" @@ -759,12 +774,14 @@ fi # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119 ##################################################################################### if [[ $SRS_SRT == YES ]]; then - if [[ -f ${SRS_3RD_SRT_PATH}/lib/libsrt.a ]]; then + if [[ -f ${SRS_3RD_SRT_STORE_PATH}/lib/libsrt.a ]]; then + rm -rf SRS_3RD_SRT_PATH && + cp -rf ${SRS_3RD_SRT_STORE_PATH} ${SRS_OBJS} && echo "libsrt-1-fit is ok."; else echo "Build srt-1-fit" ( - if [[ ! -d ${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ]]; then + if [[ ! -d ${SRS_3RD_OPENSSL_STORE_PATH}/lib/pkgconfig ]]; then echo "OpenSSL pkgconfig no found, build srt-1-fit failed."; exit -1; fi @@ -785,13 +802,15 @@ if [[ $SRS_SRT == YES ]]; then cd ${SRS_OBJS}/${SRS_PLATFORM} && cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM} && cd srt-1-fit && - PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure --prefix=${SRS_3RD_SRT_PATH} $LIBSRT_OPTIONS && + PKG_CONFIG_PATH=${SRS_3RD_OPENSSL_PATH}/lib/pkgconfig ./configure --prefix=${SRS_3RD_SRT_STORE_PATH} $LIBSRT_OPTIONS && make ${SRS_JOBS} && make install && # If exists lib64 of libsrt, link it to lib - if [[ -d ${SRS_3RD_SRT_PATH}/lib64 ]]; then - mv ${SRS_3RD_SRT_PATH}/lib64 ${SRS_3RD_SRT_PATH}/lib - fi + if [[ -d ${SRS_3RD_SRT_STORE_PATH}/lib64 ]]; then + mv ${SRS_3RD_SRT_STORE_PATH}/lib64 ${SRS_3RD_SRT_STORE_PATH}/lib + fi && + + cp -rf ${SRS_3RD_SRT_STORE_PATH} ${SRS_OBJS} ) ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi fi @@ -801,12 +820,12 @@ fi # build utest code ##################################################################################### if [ $SRS_UTEST = YES ]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0/include/gtest/gtest.h ]]; then + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest/include/gtest/gtest.h ]]; then echo "The gtest-1.6.0 is ok."; else echo "Build gtest-1.6.0"; ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 && cd ${SRS_OBJS}/${SRS_PLATFORM} && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gtest && cd ${SRS_OBJS}/${SRS_PLATFORM} && unzip -q ${SRS_WORKDIR}/3rdparty/gtest-1.6.0.zip && mv ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 ${SRS_OBJS}/${SRS_PLATFORM}/gtest ) diff --git a/trunk/auto/setup_variables.sh b/trunk/auto/setup_variables.sh index 422c6c7a40..1cea717f49 100755 --- a/trunk/auto/setup_variables.sh +++ b/trunk/auto/setup_variables.sh @@ -6,7 +6,7 @@ OS_KERNRL_RELEASE=$(uname -r|awk -F '-' '{print $1}') OS_PREFIX="Platform" if [[ $OSTYPE == cygwin ]]; then - OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}') + OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}') fi # Build platform cache. @@ -27,7 +27,9 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then SRS_PLATFORM="${SRS_PLATFORM}-CROSSBUILD-$(echo $SRS_TOOL_CC|awk -F - '{print $1}')" fi +#TODO find the link lib in objs/Platform_some_platfomr/3rdpatry/some-lib # 3rdparty lib path +# eg: objs/st, objs/ffmpeg etc. SRS_3RD_ST_PATH=${SRS_OBJS}/st SRS_3RD_FFMPEG_PATH=${SRS_OBJS}/ffmpeg SRS_3RD_OPUS_PATH=${SRS_OBJS}/opus @@ -35,21 +37,45 @@ SRS_3RD_SRTP2_PATH=${SRS_OBJS}/srtp2 SRS_3RD_OPENSSL_PATH=${SRS_OBJS}/openssl SRS_3RD_SRT_PATH=${SRS_OBJS}/srt +# 3rdparty lib store path +# eg: objs/Platform-CYGWIN_NT-10.0-3.2.0-GCC11.2.0-SRS5-x86_64/3rdpatry/st +SRS_3RD_ST_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st +SRS_3RD_FFMPEG_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg +SRS_3RD_OPUS_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus +SRS_3RD_SRTP2_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 +SRS_3RD_OPENSSL_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl +SRS_3RD_SRT_STORE_PATH=${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt + echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS_DIR: ${SRS_OBJS_DIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}" # For src object files on each platform. ( mkdir -p ${SRS_OBJS_DIR} && cd ${SRS_OBJS_DIR} && rm -rf src utest srs srs_utest research include lib srs_hls_ingester srs_mp4_parser && + # on windows, clean *.exe + rm -rf srs.exe srs_utest.exe srs_hls_ingester.exe srs_mp4_parser.exe && mkdir -p ${SRS_PLATFORM}/src && mkdir -p ${SRS_PLATFORM}/research && mkdir -p ${SRS_PLATFORM}/include && mkdir -p ${SRS_PLATFORM}/lib && - mkdir -p ${SRS_3RD_ST_PATH} && - mkdir -p ${SRS_3RD_FFMPEG_PATH} && - mkdir -p ${SRS_3RD_OPUS_PATH} && - mkdir -p ${SRS_3RD_SRTP2_PATH} && - mkdir -p ${SRS_3RD_OPENSSL_PATH} + mkdir -p ${SRS_PLATFORM}/utest && + + rm -rf st ffmpeg opus srtp2 openssl srt && + # objs/some-lib + mkdir -p ${SRS_3RD_ST_PATH} && + mkdir -p ${SRS_3RD_FFMPEG_PATH} && + mkdir -p ${SRS_3RD_OPUS_PATH} && + mkdir -p ${SRS_3RD_SRTP2_PATH} && + mkdir -p ${SRS_3RD_OPENSSL_PATH} && + mkdir -p ${SRS_3RD_SRT_STORE_PATH} && + + # objs/Platform_some_platform/3rdpatry/some-lib + mkdir -p ${SRS_3RD_ST_STORE_PATH} && + mkdir -p ${SRS_3RD_FFMPEG_STORE_PATH} && + mkdir -p ${SRS_3RD_OPUS_STORE_PATH} && + mkdir -p ${SRS_3RD_SRTP2_STORE_PATH} && + mkdir -p ${SRS_3RD_OPENSSL_STORE_PATH} && + mkdir -p ${SRS_3RD_SRT_STORE_PATH} ) if [[ $SRS_CLEAN == NO ]]; then echo "Fast cleanup, if need to do full cleanup, please use: make clean"