diff --git a/trunk/3rdparty/st-srs/io.c b/trunk/3rdparty/st-srs/io.c index f4345aa89..7e05f99ae 100644 --- a/trunk/3rdparty/st-srs/io.c +++ b/trunk/3rdparty/st-srs/io.c @@ -742,17 +742,16 @@ int st_sendmsg(_st_netfd_t *fd, const struct msghdr *msg, int flags, st_utime_t return n; } - -#if defined(MD_HAVE_SENDMMSG) && defined(__linux__) && 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 st_mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout) { +#if defined(MD_HAVE_SENDMMSG) && defined(_GNU_SOURCE) int n; int left; struct mmsghdr *p; left = (int)vlen; while (left > 0) { - p = msgvec + (vlen - left); + p = (struct mmsghdr*)msgvec + (vlen - left); if ((n = sendmmsg(fd->osfd, p, left, flags)) < 0) { if (errno == EINTR) @@ -772,8 +771,30 @@ int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int fl return n; } return (int)vlen - left; -} +#else + struct st_mmsghdr *p; + int i, n; + + // @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html + for (i = 0; i < (int)vlen; ++i) { + p = msgvec + i; + n = st_sendmsg(fd, &p->msg_hdr, flags, timeout); + if (n < 0) { + // An error is returned only if no datagrams could be sent. + if (i == 0) { + return n; + } + return i + 1; + } + + p->msg_len = n; + } + + // Returns the number of messages sent from msgvec; if this is less than vlen, the caller can retry with a + // further sendmmsg() call to send the remaining messages. + return vlen; #endif +} /* diff --git a/trunk/3rdparty/st-srs/public.h b/trunk/3rdparty/st-srs/public.h index 332f3291c..80fd93346 100644 --- a/trunk/3rdparty/st-srs/public.h +++ b/trunk/3rdparty/st-srs/public.h @@ -151,9 +151,15 @@ extern int st_recvfrom(st_netfd_t fd, void *buf, int len, struct sockaddr *from, extern int st_sendto(st_netfd_t fd, const void *msg, int len, const struct sockaddr *to, int tolen, st_utime_t timeout); extern int st_recvmsg(st_netfd_t fd, struct msghdr *msg, int flags, st_utime_t timeout); extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_utime_t timeout); -#if defined(__linux__) && defined(_GNU_SOURCE) -extern int st_sendmmsg(st_netfd_t fd, struct mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout); -#endif + +// @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html +#include +struct st_mmsghdr { + struct msghdr msg_hdr; /* Message header */ + unsigned int msg_len; /* Number of bytes transmitted */ +}; +extern int st_sendmmsg(st_netfd_t fd, struct st_mmsghdr *msgvec, unsigned int vlen, int flags, st_utime_t timeout); + extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); #ifdef DEBUG diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index bcbfe95b8..772d0aeba 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -165,11 +165,6 @@ if [ $SRS_SENDMMSG = YES ]; then else srs_undefine_macro "SRS_SENDMMSG" $SRS_AUTO_HEADERS_H fi -if [ $SRS_HAS_SENDMMSG = YES ]; then - srs_define_macro "SRS_HAS_SENDMMSG" $SRS_AUTO_HEADERS_H -else - srs_undefine_macro "SRS_HAS_SENDMMSG" $SRS_AUTO_HEADERS_H -fi if [ $SRS_DEBUG = YES ]; then srs_define_macro "SRS_DEBUG" $SRS_AUTO_HEADERS_H diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index f9723193f..484ba2567 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -347,7 +347,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_LD=${SRS_TOOL_CC} && _ST_OBJ="DARWIN_`uname -r`_DBG" fi # For UDP sendmmsg, disable it if not suppported. - if [[ $SRS_HAS_SENDMMSG == YES ]]; then + if [[ $SRS_SENDMMSG == YES ]]; then echo "Build ST with UDP sendmmsg support." _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_SENDMMSG -D_GNU_SOURCE" else diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index cd7cfe8e4..97f6dcf92 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -118,11 +118,9 @@ SRS_EXTRA_FLAGS= # ##################################################################################### # Performance optimize. -SRS_NASM=YES -SRS_SRTP_ASM=YES -SRS_SENDMMSG=YES -SRS_HAS_SENDMMSG=YES -SRS_DETECT_SENDMMSG=YES +SRS_NASM=NO +SRS_SRTP_ASM=NO +SRS_SENDMMSG=NO SRS_DEBUG=NO ##################################################################################### @@ -257,8 +255,6 @@ function parse_user_option() { --export-librtmp-project) SRS_EXPORT_LIBRTMP_PROJECT=${value} ;; --export-librtmp-single) SRS_EXPORT_LIBRTMP_SINGLE=${value} ;; - --detect-sendmmsg) if [[ $value == off ]]; then SRS_DETECT_SENDMMSG=NO; else SRS_DETECT_SENDMMSG=YES; fi ;; - --has-sendmmsg) if [[ $value == off ]]; then SRS_HAS_SENDMMSG=NO; else SRS_HAS_SENDMMSG=YES; fi ;; --sendmmsg) if [[ $value == off ]]; then SRS_SENDMMSG=NO; else SRS_SENDMMSG=YES; fi ;; --without-srtp-nasm) SRS_SRTP_ASM=NO ;; @@ -613,29 +609,9 @@ function apply_user_detail_options() { SRS_SRTP_ASM=NO fi - # Detect whether has sendmmsg. - # @see http://man7.org/linux/man-pages/man2/sendmmsg.2.html - if [[ $SRS_DETECT_SENDMMSG == YES ]]; then - mkdir -p ${SRS_OBJS} && - echo " #include " > ${SRS_OBJS}/_tmp_sendmmsg_detect.c - echo " int main(int argc, char** argv) { " >> ${SRS_OBJS}/_tmp_sendmmsg_detect.c - echo " struct mmsghdr hdr; " >> ${SRS_OBJS}/_tmp_sendmmsg_detect.c - echo " hdr.msg_len = 0; " >> ${SRS_OBJS}/_tmp_sendmmsg_detect.c - echo " return 0; " >> ${SRS_OBJS}/_tmp_sendmmsg_detect.c - echo " } " >> ${SRS_OBJS}/_tmp_sendmmsg_detect.c - ${SRS_TOOL_CC} -c ${SRS_OBJS}/_tmp_sendmmsg_detect.c -D_GNU_SOURCE -o /dev/null >/dev/null 2>&1 - ret=$?; rm -f ${SRS_OBJS}/_tmp_sendmmsg_detect.c; - if [[ $ret -ne 0 ]]; then - SRS_HAS_SENDMMSG=NO - fi - fi - - # If system has no sendmmsg, disable sendmmsg. - if [[ $SRS_HAS_SENDMMSG == NO ]]; then - if [[ $SRS_SENDMMSG == YES ]]; then - echo "Disable UDP sendmmsg automatically" - SRS_SENDMMSG=NO - fi + if [[ $SRS_OSX == YES && $SRS_SENDMMSG == YES ]]; then + echo "Disable sendmmsg for OSX" + SRS_SENDMMSG=NO fi } apply_user_detail_options @@ -666,8 +642,6 @@ function regenerate_options() { if [ $SRS_NASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --nasm=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --nasm=off"; fi if [ $SRS_SRTP_ASM = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srtp-nasm=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srtp-nasm=off"; fi if [ $SRS_SENDMMSG = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sendmmsg=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sendmmsg=off"; fi - if [ $SRS_DETECT_SENDMMSG = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --detect-sendmmsg=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --detect-sendmmsg=off"; fi - if [ $SRS_HAS_SENDMMSG = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --has-sendmmsg=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --has-sendmmsg=off"; fi if [ $SRS_CLEAN = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --clean=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --clean=off"; fi if [ $SRS_GPERF = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gperf=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gperf=off"; fi if [ $SRS_GPERF_MC = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gmc=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gmc=off"; fi diff --git a/trunk/configure b/trunk/configure index 974a9163b..115e5f8d5 100755 --- a/trunk/configure +++ b/trunk/configure @@ -188,7 +188,7 @@ if [[ $SRS_GCOV == YES ]]; then SrsLinkOptions="${SrsLinkOptions} ${SrsGcov}"; fi # For FFMPEG/RTC. -if [[ $SRS_RTC == YES && $SRS_NASM == NO ]]; then +if [[ $SRS_RTC == YES && $SRS_NASM == NO && $SRS_OSX == NO ]]; then SrsLinkOptions="${SrsLinkOptions} -lrt"; fi diff --git a/trunk/research/players/rtc_player.html b/trunk/research/players/rtc_player.html index c78fcdb5b..28416fd4b 100644 --- a/trunk/research/players/rtc_player.html +++ b/trunk/research/players/rtc_player.html @@ -46,7 +46,7 @@ - +