diff --git a/README.md b/README.md index ffafac8c2..b1c63937f 100755 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-12-24, Support disable CherryPy. 4.0.57 * v4.0, 2020-11-12, For [#1998][bug #1998], Support Firefox, use PT in offer. 4.0.55 * v4.0, 2020-11-11, For [#1508][bug #1508], Transform http header name to upper camel case. 4.0.54 * v4.0, 2020-11-06, For [#1657][bug #1657], Read cached data first in SSL. 4.0.48 diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index d76c72106..9aaa645fd 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -430,36 +430,38 @@ echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html ##################################################################################### # cherrypy for http hooks callback, CherryPy-3.2.4 ##################################################################################### -# Detect python or python2 -python --version >/dev/null 2>&1 && SYS_PYTHON=python; -python2 --version >/dev/null 2>&1 && SYS_PYTHON=python2; -# Install cherrypy for api server. -if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then - echo "CherryPy-3.2.4 is ok."; -else - echo "Installing CherryPy-3.2.4"; - ( - rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 && - $SYS_PYTHON setup.py install --user --prefix='' - ) -fi -# check status -ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi -if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi +if [[ $SRS_CHERRYPY == YES ]]; then + # Detect python or python2 + python --version >/dev/null 2>&1 && SYS_PYTHON=python; + python2 --version >/dev/null 2>&1 && SYS_PYTHON=python2; + # Install cherrypy for api server. + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then + echo "CherryPy-3.2.4 is ok."; + else + echo "Installing CherryPy-3.2.4"; + ( + rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} && + unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 && + $SYS_PYTHON setup.py install --user --prefix='' + ) + fi + # check status + ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi + if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi -echo "Link players to cherrypy static-dir" -rm -rf research/api-server/static-dir/players && -ln -sf `pwd`/research/players research/api-server/static-dir/players && -rm -f research/api-server/static-dir/crossdomain.xml && -ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml && -rm -rf research/api-server/static-dir/live && -mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live && -ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live && -rm -rf research/api-server/static-dir/forward && -mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward && -ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward -ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi + echo "Link players to cherrypy static-dir" + rm -rf research/api-server/static-dir/players && + ln -sf `pwd`/research/players research/api-server/static-dir/players && + rm -f research/api-server/static-dir/crossdomain.xml && + ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml && + rm -rf research/api-server/static-dir/live && + mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live && + ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live && + rm -rf research/api-server/static-dir/forward && + mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward && + ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward + ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi +fi ##################################################################################### # openssl, for rtmp complex handshake and HLS encryption. diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 3cfd64eb9..ed33b72fe 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -45,6 +45,7 @@ SRS_HTTP_API=YES SRS_HTTP_CORE=YES SRS_HLS=YES SRS_DVR=YES +SRS_CHERRYPY=YES # ################################################################ # FFmpeg stub is the stub code in SRS for ingester or encoder. @@ -317,6 +318,7 @@ function parse_user_option() { --with-utest) SRS_UTEST=YES ;; --without-utest) SRS_UTEST=NO ;; --utest) if [[ $value == off ]]; then SRS_UTEST=NO; else SRS_UTEST=YES; fi ;; + --cherrypy) if [[ $value == off ]]; then SRS_CHERRYPY=NO; else SRS_CHERRYPY=YES; fi ;; --with-srt) SRS_SRT=YES ;; --without-srt) SRS_SRT=NO ;; @@ -548,6 +550,7 @@ function regenerate_options() { if [ $SRS_STREAM_CASTER = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --stream-caster=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --stream-caster=off"; fi if [ $SRS_HTTP_API = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --http-api=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --http-api=off"; fi if [ $SRS_UTEST = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --utest=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --utest=off"; fi + if [ $SRS_CHERRYPY = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cherrypy=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cherrypy=off"; fi if [ $SRS_SRT = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srt=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srt=off"; fi if [ $SRS_RTC = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=off"; fi if [ $SRS_SIMULATOR = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=on"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=off"; fi diff --git a/trunk/research/st/cost.cpp b/trunk/research/st/cost.cpp new file mode 100644 index 000000000..c7caeb5fa --- /dev/null +++ b/trunk/research/st/cost.cpp @@ -0,0 +1,148 @@ +/* +g++ -g -O0 cost.cpp -o cost && ./cost | grep COST +*/ +#include +#include +#include +#include + +#define SRS_UTIME_MILLISECONDS 1000 +#define srsu2i(us) ((int)(us)) +#define srsu2ms(us) ((us) / SRS_UTIME_MILLISECONDS) +#define srsu2msi(us) int((us) / SRS_UTIME_MILLISECONDS) + +int64_t srs_update_system_time() +{ + timeval now; + ::gettimeofday(&now, NULL); + return ((int64_t)now.tv_sec) * 1000 * 1000 + (int64_t)now.tv_usec; +} + +int main(int argc, char** argv) +{ + // The cost for srs_update_system_time() itself. + if (true) { + int64_t start = srs_update_system_time(); + + int64_t ts_gettimeofday = srs_update_system_time(); + + printf("[COST] gettimeofday=%dus\n", srsu2i(ts_gettimeofday - start)); + } + + // The cost for allocate 1MB memory. + if (true) { + int64_t start = srs_update_system_time(); + + int size = 1024 * 1024; + char* p = new char[size]; + int64_t ts_allocate = srs_update_system_time(); + + for (int i = 0; i < size; i++) { + p[i] = 0x0F; + } + int64_t ts_init = srs_update_system_time(); + + printf("[COST] new[%d]=%dus, init=%dus\n", + size, + srsu2i(ts_allocate - start), + srsu2i(ts_init - ts_allocate) + ); + } + + // The cost for loop. + if (true) { + int64_t start = srs_update_system_time(); + + for (long long i = 0; i < 1000000LL; i++); + int64_t ts_loop = srs_update_system_time(); + + for (long long i = 0; i < 10000000LL; i++); + int64_t ts_loop2 = srs_update_system_time(); + + printf("[COST] loop 100w=%dus, 1000w=%dus\n", srsu2i(ts_loop - start), srsu2i(ts_loop2 - ts_loop)); + } + + // The cost for printf. + if (true) { + int64_t start = srs_update_system_time(); + + printf("TEST: OK\n"); + int64_t ts_printf = srs_update_system_time(); + + printf("TEST: OK OK\n"); + int64_t ts_printf2 = srs_update_system_time(); + + printf("TEST: OK OK %s\n", "OK"); + int64_t ts_printf3 = srs_update_system_time(); + + printf("[COST] printf=%dus %dus %dus\n", + srsu2i(ts_printf - start), + srsu2i(ts_printf2 - ts_printf), + srsu2i(ts_printf3 - ts_printf2) + ); + } + + // The cost for file open or close. + if (true) { + int64_t start = srs_update_system_time(); + + int fd = ::open("cost.log", O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int64_t ts_open = srs_update_system_time(); + + ::close(fd); + int64_t ts_close = srs_update_system_time(); + + printf("[COST] open=%dus, close=%dus\n", + srsu2i(ts_open - start), + srsu2i(ts_close - ts_open) + ); + } + + // The cost for file writing. + if (true) { + int64_t start = srs_update_system_time(); + + int fd = ::open("cost.log", O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int64_t ts_open = srs_update_system_time(); + + ::write(fd, "Hello\n", 6); + int64_t ts_write = srs_update_system_time(); + + ::write(fd, "HelloHello\n", 12); + int64_t ts_write2 = srs_update_system_time(); + + ::close(fd); + int64_t ts_close = srs_update_system_time(); + + printf("[COST] write=%dus %dus\n", + srsu2i(ts_write - ts_open), + srsu2i(ts_write2 - ts_write) + ); + } + + // The cost for file reading. + if (true) { + char buf[128]; + int64_t start = srs_update_system_time(); + + int fd = ::open("cost.log", O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int64_t ts_open = srs_update_system_time(); + + ::read(fd, buf, 6); + int64_t ts_read = srs_update_system_time(); + + ::read(fd, buf, 6); + int64_t ts_read2 = srs_update_system_time(); + + ::close(fd); + int64_t ts_close = srs_update_system_time(); + + printf("[COST] read=%dus %dus\n", + srsu2i(ts_read - ts_open), + srsu2i(ts_read2 - ts_read) + ); + } + + return 0; +} + diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 9fb9d1774..4b594c2df 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 56 +#define SRS_VERSION4_REVISION 57 #endif