diff --git a/trunk/3rdparty/st-srs/Makefile b/trunk/3rdparty/st-srs/Makefile index 601d3e507..7e641d195 100644 --- a/trunk/3rdparty/st-srs/Makefile +++ b/trunk/3rdparty/st-srs/Makefile @@ -189,6 +189,10 @@ OTHER_FLAGS = -Wall ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes) DEFINES += -DMD_HAVE_EPOLL endif +# For SRS, sendmmsg +ifeq ($(shell grep -qs sendmmsg /usr/include/sys/socket.h && echo yes), yes) +DEFINES += -DMD_HAVE_SENDMMSG -D_GNU_SOURCE +endif endif ifeq ($(OS), NETBSD) @@ -282,6 +286,10 @@ endif # # make EXTRA_CFLAGS=-UMD_HAVE_EPOLL # +# or to enable sendmmsg(2) support: +# +# make EXTRA_CFLAGS="-DMD_HAVE_SENDMMSG -D_GNU_SOURCE" +# ########################## CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS) diff --git a/trunk/3rdparty/st-srs/io.c b/trunk/3rdparty/st-srs/io.c index 8b0e9294a..750099450 100644 --- a/trunk/3rdparty/st-srs/io.c +++ b/trunk/3rdparty/st-srs/io.c @@ -743,6 +743,7 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t } +#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE) int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout) { int n; @@ -772,6 +773,7 @@ int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int fl } return (int)vlen - left; } +#endif /* diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 73249d1b2..e43f424e0 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -160,6 +160,11 @@ if [ $SRS_OSX = YES ]; then else srs_undefine_macro "SRS_AUTO_OSX" $SRS_AUTO_HEADERS_H fi +if [ $SRS_SENDMMSG = YES ]; then + srs_define_macro "SRS_AUTO_SENDMMSG" $SRS_AUTO_HEADERS_H +else + srs_undefine_macro "SRS_AUTO_SENDMMSG" $SRS_AUTO_HEADERS_H +fi # prefix echo "" >> $SRS_AUTO_HEADERS_H diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index 1ed7e3aa3..1e8489a99 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -346,9 +346,14 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then if [[ $SRS_OSX == YES ]]; then _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_LD=${SRS_TOOL_CC} && _ST_OBJ="DARWIN_*" fi + # For UDP sendmmsg, disable it if not suppported. + if [[ $SRS_SENDMMSG == YES ]]; then + echo "Build ST with UDP sendmmsg support." + _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_SENDMMSG -D_GNU_SOURCE" + fi # Pass the global extra flags. if [[ $SRS_EXTRA_FLAGS != '' ]]; then - _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS" + _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS" fi # Patched ST from https://github.com/ossrs/state-threads/tree/srs if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st/libst.a ]]; then @@ -542,7 +547,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then echo "#if OPENSSL_VERSION_NUMBER >= 0x10100000L // v1.1.x" >> ${SRS_OBJS}/_tmp_srtp_asm_detect.c echo "#error \"SRTP only works with openssl-1.0.*\"" >> ${SRS_OBJS}/_tmp_srtp_asm_detect.c echo "#endif" >> ${SRS_OBJS}/_tmp_srtp_asm_detect.c - gcc -c ${SRS_OBJS}/_tmp_srtp_asm_detect.c -I${SRS_OBJS}/openssl/include -o /dev/null >/dev/null 2>&1 + ${SRS_TOOL_CC} -c ${SRS_OBJS}/_tmp_srtp_asm_detect.c -I${SRS_OBJS}/openssl/include -o /dev/null >/dev/null 2>&1 if [[ $? -ne 0 ]]; then SRS_SRTP_ASM=NO && echo "Warning: Disable SRTP ASM optimization, please update docker"; fi diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 152259ddb..3f2c79550 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -120,6 +120,7 @@ SRS_EXTRA_FLAGS= # Performance optimize. SRS_NASM=YES SRS_SRTP_ASM=YES +SRS_SENDMMSG=YES ##################################################################################### # menu @@ -187,6 +188,8 @@ Performance: @see https://blog.csdn.net/win_lin/article/details/5 --without-nasm Build FFMPEG for RTC without nasm support, for CentOS6 nasm is too old. --with-srtp-nasm Build SRTP with ASM(openssl-asm) support, requires RTC and openssl-1.0.*. --without-srtp-nasm Disable SRTP ASM support. + --with-sendmmsg Enable UDP sendmmsg support. @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html + --without-sendmmsg Disable UDP sendmmsg support. Toolchain options: @see https://github.com/ossrs/srs/issues/1547#issuecomment-576078411 --arm Enable crossbuild for ARM. @@ -249,6 +252,7 @@ function parse_user_option() { --with-gb28181) SRS_GB28181=YES ;; --with-nasm) SRS_NASM=YES ;; --with-srtp-nasm) SRS_SRTP_ASM=YES ;; + --with-sendmmsg) SRS_SENDMMSG=YES ;; --with-clean) SRS_CLEAN=YES ;; --with-gperf) SRS_GPERF=YES ;; --with-gmc) SRS_GPERF_MC=YES ;; @@ -270,6 +274,7 @@ function parse_user_option() { --without-gb28181) SRS_GB28181=NO ;; --without-nasm) SRS_NASM=NO ;; --without-srtp-nasm) SRS_SRTP_ASM=NO ;; + --without-sendmmsg) SRS_SENDMMSG=NO ;; --without-clean) SRS_CLEAN=NO ;; --without-gperf) SRS_GPERF=NO ;; --without-gmc) SRS_GPERF_MC=NO ;; @@ -547,6 +552,22 @@ function apply_user_detail_options() { SRS_GPROF=NO SRS_STATIC=NO fi + + if [[ $SRS_SRTP_ASM == YES && $SRS_RTC == NO ]]; then + echo "Disable SRTP ASM, because RTC is disabled." + SRS_SRTP_ASM=NO + fi + + if [[ $SRS_SRTP_ASM == YES && $SRS_NASM == NO ]]; then + echo "Disable SRTP ASM, because NASM is disabled." + SRS_SRTP_ASM=NO + fi + + grep -qs sendmmsg /usr/include/sys/socket.h + if [[ $? -ne 0 && $SRS_SENDMMSG == YES ]]; then + echo "Disable UDP sendmmsg automatically" + SRS_SENDMMSG=NO + fi } apply_user_detail_options @@ -574,6 +595,7 @@ function regenerate_options() { if [ $SRS_GB28181 = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gb28181"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gb28181"; fi if [ $SRS_NASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-nasm"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-nasm"; fi if [ $SRS_SRTP_ASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-srtp-nasm"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-srtp-nasm"; fi + if [ $SRS_SENDMMSG = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-sendmmsg"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-sendmmsg"; fi if [ $SRS_CLEAN = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-clean"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-clean"; fi if [ $SRS_GPERF = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gperf"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gperf"; fi if [ $SRS_GPERF_MC = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gmc"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gmc"; fi @@ -626,16 +648,6 @@ function check_option_conflicts() { exit -1 fi - if [[ $SRS_SRTP_ASM == YES && $SRS_RTC == NO ]]; then - echo "Disable SRTP ASM, because RTC is disabled." - SRS_SRTP_ASM=NO - fi - - if [[ $SRS_SRTP_ASM == YES && $SRS_NASM == NO ]]; then - echo "Disable SRTP ASM, because NASM is disabled." - SRS_SRTP_ASM=NO - fi - # TODO: FIXME: check more os. __check_ok=YES diff --git a/trunk/configure b/trunk/configure index 63e42986e..459d7efb8 100755 --- a/trunk/configure +++ b/trunk/configure @@ -528,12 +528,12 @@ clean_cherrypy: st: (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs && \$(MAKE) ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}") + (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs && \$(MAKE) clean && \$(MAKE) ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}") @echo "Please rebuild srs by: rm -f objs/srs && make" ffmpeg: (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) - (cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit && \$(MAKE) install-libs) + (cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit && \$(MAKE) && \$(MAKE) install-libs) @echo "Please rebuild srs by: rm -f objs/srs && make" END diff --git a/trunk/src/service/srs_service_st.cpp b/trunk/src/service/srs_service_st.cpp index 8ed113be2..d088f5cf4 100644 --- a/trunk/src/service/srs_service_st.cpp +++ b/trunk/src/service/srs_service_st.cpp @@ -409,7 +409,7 @@ int srs_sendmsg(srs_netfd_t stfd, const struct msghdr *msg, int flags, srs_utime int srs_sendmmsg(srs_netfd_t stfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, srs_utime_t timeout) { -#if defined(SRS_AUTO_OSX) +#if defined(SRS_AUTO_OSX) || !defined(SRS_AUTO_SENDMMSG) // @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html for (int i = 0; i < (int)vlen; ++i) { struct mmsghdr* p = msgvec + i; diff --git a/trunk/src/service/srs_service_st.hpp b/trunk/src/service/srs_service_st.hpp index ed10fd667..69c93a465 100644 --- a/trunk/src/service/srs_service_st.hpp +++ b/trunk/src/service/srs_service_st.hpp @@ -90,6 +90,15 @@ extern srs_netfd_t srs_netfd_open(int osfd); extern int srs_recvfrom(srs_netfd_t stfd, void *buf, int len, struct sockaddr *from, int *fromlen, srs_utime_t timeout); extern int srs_sendto(srs_netfd_t stfd, void *buf, int len, const struct sockaddr *to, int tolen, srs_utime_t timeout); extern int srs_sendmsg(srs_netfd_t stfd, const struct msghdr *msg, int flags, srs_utime_t timeout); + +#if !defined(SRS_AUTO_SENDMMSG) + // @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html + #include + struct mmsghdr { + struct msghdr msg_hdr; /* Message header */ + unsigned int msg_len; /* Number of bytes transmitted */ + }; +#endif extern int srs_sendmmsg(srs_netfd_t stfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, srs_utime_t timeout); extern srs_netfd_t srs_accept(srs_netfd_t stfd, struct sockaddr *addr, int *addrlen, srs_utime_t timeout);