1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #307, support configure with sendmmsg.

This commit is contained in:
winlin 2020-04-05 18:34:57 +08:00
parent b23525033b
commit dc3df926eb
8 changed files with 56 additions and 15 deletions

View file

@ -189,6 +189,10 @@ OTHER_FLAGS = -Wall
ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes) ifeq ($(shell test -f /usr/include/sys/epoll.h && echo yes), yes)
DEFINES += -DMD_HAVE_EPOLL DEFINES += -DMD_HAVE_EPOLL
endif 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 endif
ifeq ($(OS), NETBSD) ifeq ($(OS), NETBSD)
@ -282,6 +286,10 @@ endif
# #
# make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target> # make EXTRA_CFLAGS=-UMD_HAVE_EPOLL <target>
# #
# or to enable sendmmsg(2) support:
#
# make EXTRA_CFLAGS="-DMD_HAVE_SENDMMSG -D_GNU_SOURCE"
#
########################## ##########################
CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS) CFLAGS += $(DEFINES) $(OTHER_FLAGS) $(EXTRA_CFLAGS)

View file

@ -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 st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout)
{ {
int n; 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; return (int)vlen - left;
} }
#endif
/* /*

View file

@ -160,6 +160,11 @@ if [ $SRS_OSX = YES ]; then
else else
srs_undefine_macro "SRS_AUTO_OSX" $SRS_AUTO_HEADERS_H srs_undefine_macro "SRS_AUTO_OSX" $SRS_AUTO_HEADERS_H
fi 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 # prefix
echo "" >> $SRS_AUTO_HEADERS_H echo "" >> $SRS_AUTO_HEADERS_H

View file

@ -346,9 +346,14 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
if [[ $SRS_OSX == YES ]]; then if [[ $SRS_OSX == YES ]]; then
_ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_LD=${SRS_TOOL_CC} && _ST_OBJ="DARWIN_*" _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_LD=${SRS_TOOL_CC} && _ST_OBJ="DARWIN_*"
fi 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. # Pass the global extra flags.
if [[ $SRS_EXTRA_FLAGS != '' ]]; then if [[ $SRS_EXTRA_FLAGS != '' ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS" _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
fi fi
# Patched ST from https://github.com/ossrs/state-threads/tree/srs # Patched ST from https://github.com/ossrs/state-threads/tree/srs
if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st/libst.a ]]; then 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 "#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 "#error \"SRTP only works with openssl-1.0.*\"" >> ${SRS_OBJS}/_tmp_srtp_asm_detect.c
echo "#endif" >> ${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 if [[ $? -ne 0 ]]; then
SRS_SRTP_ASM=NO && echo "Warning: Disable SRTP ASM optimization, please update docker"; SRS_SRTP_ASM=NO && echo "Warning: Disable SRTP ASM optimization, please update docker";
fi fi

View file

@ -120,6 +120,7 @@ SRS_EXTRA_FLAGS=
# Performance optimize. # Performance optimize.
SRS_NASM=YES SRS_NASM=YES
SRS_SRTP_ASM=YES SRS_SRTP_ASM=YES
SRS_SENDMMSG=YES
##################################################################################### #####################################################################################
# menu # 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. --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.*. --with-srtp-nasm Build SRTP with ASM(openssl-asm) support, requires RTC and openssl-1.0.*.
--without-srtp-nasm Disable SRTP ASM support. --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 Toolchain options: @see https://github.com/ossrs/srs/issues/1547#issuecomment-576078411
--arm Enable crossbuild for ARM. --arm Enable crossbuild for ARM.
@ -249,6 +252,7 @@ function parse_user_option() {
--with-gb28181) SRS_GB28181=YES ;; --with-gb28181) SRS_GB28181=YES ;;
--with-nasm) SRS_NASM=YES ;; --with-nasm) SRS_NASM=YES ;;
--with-srtp-nasm) SRS_SRTP_ASM=YES ;; --with-srtp-nasm) SRS_SRTP_ASM=YES ;;
--with-sendmmsg) SRS_SENDMMSG=YES ;;
--with-clean) SRS_CLEAN=YES ;; --with-clean) SRS_CLEAN=YES ;;
--with-gperf) SRS_GPERF=YES ;; --with-gperf) SRS_GPERF=YES ;;
--with-gmc) SRS_GPERF_MC=YES ;; --with-gmc) SRS_GPERF_MC=YES ;;
@ -270,6 +274,7 @@ function parse_user_option() {
--without-gb28181) SRS_GB28181=NO ;; --without-gb28181) SRS_GB28181=NO ;;
--without-nasm) SRS_NASM=NO ;; --without-nasm) SRS_NASM=NO ;;
--without-srtp-nasm) SRS_SRTP_ASM=NO ;; --without-srtp-nasm) SRS_SRTP_ASM=NO ;;
--without-sendmmsg) SRS_SENDMMSG=NO ;;
--without-clean) SRS_CLEAN=NO ;; --without-clean) SRS_CLEAN=NO ;;
--without-gperf) SRS_GPERF=NO ;; --without-gperf) SRS_GPERF=NO ;;
--without-gmc) SRS_GPERF_MC=NO ;; --without-gmc) SRS_GPERF_MC=NO ;;
@ -547,6 +552,22 @@ function apply_user_detail_options() {
SRS_GPROF=NO SRS_GPROF=NO
SRS_STATIC=NO SRS_STATIC=NO
fi 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 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_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_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_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_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 = 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 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 exit -1
fi 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. # TODO: FIXME: check more os.
__check_ok=YES __check_ok=YES

4
trunk/configure vendored
View file

@ -528,12 +528,12 @@ clean_cherrypy:
st: st:
(cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) (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" @echo "Please rebuild srs by: rm -f objs/srs && make"
ffmpeg: ffmpeg:
(cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) (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" @echo "Please rebuild srs by: rm -f objs/srs && make"
END END

View file

@ -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) 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 // @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html
for (int i = 0; i < (int)vlen; ++i) { for (int i = 0; i < (int)vlen; ++i) {
struct mmsghdr* p = msgvec + i; struct mmsghdr* p = msgvec + i;

View file

@ -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_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_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); 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 <sys/socket.h>
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 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); extern srs_netfd_t srs_accept(srs_netfd_t stfd, struct sockaddr *addr, int *addrlen, srs_utime_t timeout);