正在显示
20 个修改的文件
包含
234 行增加
和
96 行删除
| @@ -48,6 +48,7 @@ url: rtmp://127.0.0.1:1935/live/livestream | @@ -48,6 +48,7 @@ url: rtmp://127.0.0.1:1935/live/livestream | ||
| 48 | * nginx v1.5.0: 139524 lines <br/> | 48 | * nginx v1.5.0: 139524 lines <br/> |
| 49 | 49 | ||
| 50 | ### History | 50 | ### History |
| 51 | +* v0.4, 2013-11-10, support config and reload the pithy print. | ||
| 51 | * v0.4, 2013-11-09, support reload config(vhost and its detail). | 52 | * v0.4, 2013-11-09, support reload config(vhost and its detail). |
| 52 | * v0.4, 2013-11-09, support reload config(listen and chunk_size) by SIGHUP(1). | 53 | * v0.4, 2013-11-09, support reload config(listen and chunk_size) by SIGHUP(1). |
| 53 | * v0.4, 2013-11-09, support longtime(>4.6hours) publish/play. | 54 | * v0.4, 2013-11-09, support longtime(>4.6hours) publish/play. |
trunk/3rdparty/http-parser-2.1.zip
0 → 100644
不能预览此文件类型
trunk/auto/modules.sh
100644 → 100755
| @@ -15,15 +15,15 @@ FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} | @@ -15,15 +15,15 @@ FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} | ||
| 15 | # INCS | 15 | # INCS |
| 16 | INCS_NAME="${MODULE_ID}_INCS" | 16 | INCS_NAME="${MODULE_ID}_INCS" |
| 17 | echo "# the ${MODULE_ID} module." >> ${FILE} | 17 | echo "# the ${MODULE_ID} module." >> ${FILE} |
| 18 | -echo "${MODULE_ID}_MODULE_INCS = -I ${MODULE_DIR} " >> ${FILE} | ||
| 19 | -echo -n "${INCS_NAME} = -I ${MODULE_DIR} " >> ${FILE} | 18 | +echo "${MODULE_ID}_MODULE_INCS = -I${MODULE_DIR} " >> ${FILE} |
| 19 | +echo -n "${INCS_NAME} = -I${MODULE_DIR} " >> ${FILE} | ||
| 20 | for item in ${MODULE_DEPENDS[*]}; do | 20 | for item in ${MODULE_DEPENDS[*]}; do |
| 21 | DEP_INCS_NAME="${item}_INCS"do | 21 | DEP_INCS_NAME="${item}_INCS"do |
| 22 | DEP_INCS_NAME="${item}_MODULE_INCS" | 22 | DEP_INCS_NAME="${item}_MODULE_INCS" |
| 23 | echo -n "\$(${DEP_INCS_NAME}) " >> ${FILE} | 23 | echo -n "\$(${DEP_INCS_NAME}) " >> ${FILE} |
| 24 | done | 24 | done |
| 25 | for item in ${ModuleLibIncs[*]}; do | 25 | for item in ${ModuleLibIncs[*]}; do |
| 26 | - echo -n "-I ${item} " >> ${FILE} | 26 | + echo -n "-I${item} " >> ${FILE} |
| 27 | done | 27 | done |
| 28 | echo "" >> ${FILE} | 28 | echo "" >> ${FILE} |
| 29 | 29 | ||
| @@ -50,7 +50,7 @@ for item in ${MODULE_FILES[*]}; do | @@ -50,7 +50,7 @@ for item in ${MODULE_FILES[*]}; do | ||
| 50 | MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}" | 50 | MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}" |
| 51 | if [ -f ${CPP_FILE} ]; then | 51 | if [ -f ${CPP_FILE} ]; then |
| 52 | echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE} | 52 | echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE} |
| 53 | - echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME}) -o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE} | 53 | + echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME})-o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE} |
| 54 | fi | 54 | fi |
| 55 | done | 55 | done |
| 56 | echo "" >> ${FILE} | 56 | echo "" >> ${FILE} |
| 1 | # the listen ports, split by space. | 1 | # the listen ports, split by space. |
| 2 | -listen 1935; | 2 | +listen 1935; |
| 3 | # the default chunk size is 128, max is 65536, | 3 | # the default chunk size is 128, max is 65536, |
| 4 | # some client does not support chunk size change, | 4 | # some client does not support chunk size change, |
| 5 | # however, most clients supports it and it can improve | 5 | # however, most clients supports it and it can improve |
| 6 | # performance about 10%. | 6 | # performance about 10%. |
| 7 | # if not specified, set to 4096. | 7 | # if not specified, set to 4096. |
| 8 | -chunk_size 65000; | 8 | +chunk_size 65000; |
| 9 | # vhost list, the __defaultVhost__ is the default vhost | 9 | # vhost list, the __defaultVhost__ is the default vhost |
| 10 | # for which cannot identify the required vhost. | 10 | # for which cannot identify the required vhost. |
| 11 | vhost __defaultVhost__ { | 11 | vhost __defaultVhost__ { |
| @@ -47,4 +47,15 @@ vhost refer.anti_suck.com { | @@ -47,4 +47,15 @@ vhost refer.anti_suck.com { | ||
| 47 | # default: not specified. | 47 | # default: not specified. |
| 48 | refer_play github.com github.io; | 48 | refer_play github.com github.io; |
| 49 | } | 49 | } |
| 50 | +# config for the pithy print, | ||
| 51 | +# which always print constant message specified by interval, | ||
| 52 | +# whatever the clients in concurrency. | ||
| 53 | +pithy_print { | ||
| 54 | + # shared print interval for all publish clients, in milliseconds. | ||
| 55 | + # if not specified, set to 1100. | ||
| 56 | + publish 2000; | ||
| 57 | + # shared print interval for all play clients, in milliseconds. | ||
| 58 | + # if not specified, set to 1300. | ||
| 59 | + play 3000; | ||
| 60 | +} | ||
| 50 | 61 |
| @@ -16,13 +16,36 @@ if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/o | @@ -16,13 +16,36 @@ if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/o | ||
| 16 | echo "st-1.9t is ok."; | 16 | echo "st-1.9t is ok."; |
| 17 | else | 17 | else |
| 18 | echo "build st-1.9t"; | 18 | echo "build st-1.9t"; |
| 19 | - (rm -rf ${GLOBAL_DIR_OBJS}/st-1.9 && cd ${GLOBAL_DIR_OBJS} && unzip ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug) | 19 | + ( |
| 20 | + rm -rf ${GLOBAL_DIR_OBJS}/st-1.9 && cd ${GLOBAL_DIR_OBJS} && | ||
| 21 | + unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug && | ||
| 22 | + cd .. && rm -f st && ln -sf st-1.9/obj st | ||
| 23 | + ) | ||
| 20 | fi | 24 | fi |
| 21 | # check status | 25 | # check status |
| 22 | ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi | 26 | ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi |
| 23 | if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi | 27 | if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi |
| 24 | if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi | 28 | if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi |
| 25 | 29 | ||
| 30 | +# http-parser-2.1 | ||
| 31 | +if [[ -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/http_parser.h && -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then | ||
| 32 | + echo "http-parser-2.1 is ok."; | ||
| 33 | +else | ||
| 34 | + echo "build http-parser-2.1"; | ||
| 35 | + ( | ||
| 36 | + rm -rf ${GLOBAL_DIR_OBJS}/http-parser-2.1 && cd ${GLOBAL_DIR_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip && | ||
| 37 | + cd http-parser-2.1 && | ||
| 38 | + sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile && | ||
| 39 | + sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile && | ||
| 40 | + make package && | ||
| 41 | + cd .. && rm -f hp && ln -sf http-parser-2.1 hp | ||
| 42 | + ) | ||
| 43 | +fi | ||
| 44 | +# check status | ||
| 45 | +ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi | ||
| 46 | +if [[ ! -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi | ||
| 47 | +if [[ ! -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi | ||
| 48 | + | ||
| 26 | ##################################################################################### | 49 | ##################################################################################### |
| 27 | # generate Makefile. | 50 | # generate Makefile. |
| 28 | ##################################################################################### | 51 | ##################################################################################### |
| @@ -53,18 +76,16 @@ END | @@ -53,18 +76,16 @@ END | ||
| 53 | echo 'generate Makefile ok!' | 76 | echo 'generate Makefile ok!' |
| 54 | 77 | ||
| 55 | # the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt | 78 | # the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt |
| 56 | -#Performance="-pg" | ||
| 57 | -#PerformanceLink="-pg" | 79 | +Performance="-pg" |
| 58 | # enable gdb debug | 80 | # enable gdb debug |
| 59 | GDBDebug="-g -O0" | 81 | GDBDebug="-g -O0" |
| 60 | # the warning level. | 82 | # the warning level. |
| 61 | -WarnLevel="-Wall -Wextra" | 83 | +WarnLevel="-Wall" |
| 62 | # the compile standard. | 84 | # the compile standard. |
| 63 | -CppStd="-std=c++98" | ||
| 64 | -# other macros defined | ||
| 65 | -UserMacros="" | 85 | +CppStd="-ansi" |
| 66 | # the cxx flag generated. | 86 | # the cxx flag generated. |
| 67 | -CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance} ${UserMacros}" | 87 | +CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}" |
| 88 | +#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}" | ||
| 68 | cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} | 89 | cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} |
| 69 | CXXFLAGS = ${CXXFLAGS} | 90 | CXXFLAGS = ${CXXFLAGS} |
| 70 | GCC = g++ | 91 | GCC = g++ |
| @@ -78,19 +99,21 @@ default: | @@ -78,19 +99,21 @@ default: | ||
| 78 | END | 99 | END |
| 79 | 100 | ||
| 80 | # Libraries | 101 | # Libraries |
| 81 | -LibSTRoot="${GLOBAL_DIR_OBJS}/st-1.9/obj" | 102 | +LibSTRoot="${GLOBAL_DIR_OBJS}/st" |
| 82 | LibSTfile="${LibSTRoot}/libst.a" | 103 | LibSTfile="${LibSTRoot}/libst.a" |
| 104 | +LibHttpParserRoot="${GLOBAL_DIR_OBJS}/hp" | ||
| 105 | +LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a" | ||
| 83 | 106 | ||
| 84 | #Core Module | 107 | #Core Module |
| 85 | MODULE_ID="CORE" | 108 | MODULE_ID="CORE" |
| 86 | MODULE_DEPENDS=() | 109 | MODULE_DEPENDS=() |
| 87 | -ModuleLibIncs=(${LibSTRoot}) | 110 | +ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot}) |
| 88 | MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" | 111 | MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" |
| 89 | "srs_core_error" "srs_core_conn" "srs_core_client" | 112 | "srs_core_error" "srs_core_conn" "srs_core_client" |
| 90 | "srs_core_rtmp" "srs_core_socket" "srs_core_buffer" | 113 | "srs_core_rtmp" "srs_core_socket" "srs_core_buffer" |
| 91 | - "srs_core_auto_free" "srs_core_protocol" "srs_core_amf0" | 114 | + "srs_core_autofree" "srs_core_protocol" "srs_core_amf0" |
| 92 | "srs_core_stream" "srs_core_source" "srs_core_codec" | 115 | "srs_core_stream" "srs_core_source" "srs_core_codec" |
| 93 | - "srs_core_complex_handshake" "srs_core_pithy_print" | 116 | + "srs_core_handshake" "srs_core_pithy_print" |
| 94 | "srs_core_config" "srs_core_refer" "srs_core_reload") | 117 | "srs_core_config" "srs_core_refer" "srs_core_reload") |
| 95 | MODULE_DIR="src/core" . auto/modules.sh | 118 | MODULE_DIR="src/core" . auto/modules.sh |
| 96 | CORE_OBJS="${MODULE_OBJS[@]}" | 119 | CORE_OBJS="${MODULE_OBJS[@]}" |
| @@ -107,7 +130,7 @@ MAIN_OBJS="${MODULE_OBJS[@].o}" | @@ -107,7 +130,7 @@ MAIN_OBJS="${MODULE_OBJS[@].o}" | ||
| 107 | MAIN_ENTRANCES=("srs_main_server") | 130 | MAIN_ENTRANCES=("srs_main_server") |
| 108 | 131 | ||
| 109 | # srs(simple rtmp server) over st(state-threads) | 132 | # srs(simple rtmp server) over st(state-threads) |
| 110 | -ModuleLibFiles=(${LibSTfile}) | 133 | +ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile}) |
| 111 | MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}" | 134 | MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}" |
| 112 | BUILD_KEY="simple_rtmp_server" APP_MAIN="srs_main_server" APP_NAME="simple_rtmp_server" LINK_OPTIONS="-ldl -lssl" SO_PATH="" . auto/apps.sh | 135 | BUILD_KEY="simple_rtmp_server" APP_MAIN="srs_main_server" APP_NAME="simple_rtmp_server" LINK_OPTIONS="-ldl -lssl" SO_PATH="" . auto/apps.sh |
| 113 | 136 |
| @@ -21,4 +21,4 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,4 +21,4 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#include <srs_core_auto_free.hpp> | 24 | +#include <srs_core_autofree.hpp> |
| @@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 25 | #define SRS_CORE_AUTO_FREE_HPP | 25 | #define SRS_CORE_AUTO_FREE_HPP |
| 26 | 26 | ||
| 27 | /* | 27 | /* |
| 28 | -#include <srs_core_auto_free.hpp> | 28 | +#include <srs_core_autofree.hpp> |
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| @@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | #include <srs_core_log.hpp> | 30 | #include <srs_core_log.hpp> |
| 31 | #include <srs_core_rtmp.hpp> | 31 | #include <srs_core_rtmp.hpp> |
| 32 | #include <srs_core_protocol.hpp> | 32 | #include <srs_core_protocol.hpp> |
| 33 | -#include <srs_core_auto_free.hpp> | 33 | +#include <srs_core_autofree.hpp> |
| 34 | #include <srs_core_source.hpp> | 34 | #include <srs_core_source.hpp> |
| 35 | #include <srs_core_server.hpp> | 35 | #include <srs_core_server.hpp> |
| 36 | #include <srs_core_pithy_print.hpp> | 36 | #include <srs_core_pithy_print.hpp> |
| @@ -38,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -38,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 38 | 38 | ||
| 39 | #include <srs_core_error.hpp> | 39 | #include <srs_core_error.hpp> |
| 40 | #include <srs_core_log.hpp> | 40 | #include <srs_core_log.hpp> |
| 41 | -#include <srs_core_auto_free.hpp> | 41 | +#include <srs_core_autofree.hpp> |
| 42 | 42 | ||
| 43 | #define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR) | 43 | #define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR) |
| 44 | 44 | ||
| @@ -455,6 +455,18 @@ int SrsConfig::reload() | @@ -455,6 +455,18 @@ int SrsConfig::reload() | ||
| 455 | return ret; | 455 | return ret; |
| 456 | } | 456 | } |
| 457 | } | 457 | } |
| 458 | + srs_trace("reload listen success."); | ||
| 459 | + } | ||
| 460 | + // merge config: pithy_print | ||
| 461 | + if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) { | ||
| 462 | + for (it = subscribes.begin(); it != subscribes.end(); ++it) { | ||
| 463 | + SrsReloadHandler* subscribe = *it; | ||
| 464 | + if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) { | ||
| 465 | + srs_error("notify subscribes pithy_print listen failed. ret=%d", ret); | ||
| 466 | + return ret; | ||
| 467 | + } | ||
| 468 | + } | ||
| 469 | + srs_trace("reload pithy_print success."); | ||
| 458 | } | 470 | } |
| 459 | 471 | ||
| 460 | return ret; | 472 | return ret; |
| @@ -593,6 +605,26 @@ SrsConfDirective* SrsConfig::get_chunk_size() | @@ -593,6 +605,26 @@ SrsConfDirective* SrsConfig::get_chunk_size() | ||
| 593 | return root->get("chunk_size"); | 605 | return root->get("chunk_size"); |
| 594 | } | 606 | } |
| 595 | 607 | ||
| 608 | +SrsConfDirective* SrsConfig::get_pithy_print_publish() | ||
| 609 | +{ | ||
| 610 | + SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 611 | + if (!pithy) { | ||
| 612 | + return NULL; | ||
| 613 | + } | ||
| 614 | + | ||
| 615 | + return pithy->get("publish"); | ||
| 616 | +} | ||
| 617 | + | ||
| 618 | +SrsConfDirective* SrsConfig::get_pithy_print_play() | ||
| 619 | +{ | ||
| 620 | + SrsConfDirective* pithy = root->get("pithy_print"); | ||
| 621 | + if (!pithy) { | ||
| 622 | + return NULL; | ||
| 623 | + } | ||
| 624 | + | ||
| 625 | + return pithy->get("play"); | ||
| 626 | +} | ||
| 627 | + | ||
| 596 | int SrsConfig::parse_file(const char* filename) | 628 | int SrsConfig::parse_file(const char* filename) |
| 597 | { | 629 | { |
| 598 | int ret = ERROR_SUCCESS; | 630 | int ret = ERROR_SUCCESS; |
| @@ -114,6 +114,8 @@ public: | @@ -114,6 +114,8 @@ public: | ||
| 114 | virtual SrsConfDirective* get_refer_publish(std::string vhost); | 114 | virtual SrsConfDirective* get_refer_publish(std::string vhost); |
| 115 | virtual SrsConfDirective* get_listen(); | 115 | virtual SrsConfDirective* get_listen(); |
| 116 | virtual SrsConfDirective* get_chunk_size(); | 116 | virtual SrsConfDirective* get_chunk_size(); |
| 117 | + virtual SrsConfDirective* get_pithy_print_publish(); | ||
| 118 | + virtual SrsConfDirective* get_pithy_print_play(); | ||
| 117 | private: | 119 | private: |
| 118 | virtual int parse_file(const char* filename); | 120 | virtual int parse_file(const char* filename); |
| 119 | virtual int parse_argv(int& i, char** argv); | 121 | virtual int parse_argv(int& i, char** argv); |
| @@ -21,14 +21,14 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,14 +21,14 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#include <srs_core_complex_handshake.hpp> | 24 | +#include <srs_core_handshake.hpp> |
| 25 | 25 | ||
| 26 | #include <time.h> | 26 | #include <time.h> |
| 27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
| 28 | 28 | ||
| 29 | #include <srs_core_error.hpp> | 29 | #include <srs_core_error.hpp> |
| 30 | #include <srs_core_log.hpp> | 30 | #include <srs_core_log.hpp> |
| 31 | -#include <srs_core_auto_free.hpp> | 31 | +#include <srs_core_autofree.hpp> |
| 32 | #include <srs_core_socket.hpp> | 32 | #include <srs_core_socket.hpp> |
| 33 | 33 | ||
| 34 | // 68bytes FMS key which is used to sign the sever packet. | 34 | // 68bytes FMS key which is used to sign the sever packet. |
| @@ -1058,6 +1058,72 @@ void c1s1::destroy_blocks() | @@ -1058,6 +1058,72 @@ void c1s1::destroy_blocks() | ||
| 1058 | } | 1058 | } |
| 1059 | } | 1059 | } |
| 1060 | 1060 | ||
| 1061 | +SrsSimpleHandshake::SrsSimpleHandshake() | ||
| 1062 | +{ | ||
| 1063 | +} | ||
| 1064 | + | ||
| 1065 | +SrsSimpleHandshake::~SrsSimpleHandshake() | ||
| 1066 | +{ | ||
| 1067 | +} | ||
| 1068 | + | ||
| 1069 | +int SrsSimpleHandshake::handshake(SrsSocket& skt) | ||
| 1070 | +{ | ||
| 1071 | + int ret = ERROR_SUCCESS; | ||
| 1072 | + | ||
| 1073 | + ssize_t nsize; | ||
| 1074 | + | ||
| 1075 | + char* c0c1 = new char[1537]; | ||
| 1076 | + SrsAutoFree(char, c0c1, true); | ||
| 1077 | + if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) { | ||
| 1078 | + srs_warn("read c0c1 failed. ret=%d", ret); | ||
| 1079 | + return ret; | ||
| 1080 | + } | ||
| 1081 | + srs_verbose("read c0c1 success."); | ||
| 1082 | + | ||
| 1083 | + // plain text required. | ||
| 1084 | + if (c0c1[0] != 0x03) { | ||
| 1085 | + ret = ERROR_RTMP_PLAIN_REQUIRED; | ||
| 1086 | + srs_warn("only support rtmp plain text. ret=%d", ret); | ||
| 1087 | + return ret; | ||
| 1088 | + } | ||
| 1089 | + srs_verbose("check c0 success, required plain text."); | ||
| 1090 | + | ||
| 1091 | + // try complex handshake | ||
| 1092 | + SrsComplexHandshake complex_handshake; | ||
| 1093 | + ret = complex_handshake.handshake(skt, c0c1 + 1); | ||
| 1094 | + if (ret == ERROR_SUCCESS) { | ||
| 1095 | + srs_trace("complex handshake success."); | ||
| 1096 | + return ret; | ||
| 1097 | + } | ||
| 1098 | + if (ret != ERROR_RTMP_TRY_SIMPLE_HS) { | ||
| 1099 | + srs_error("complex handshake failed. ret=%d", ret); | ||
| 1100 | + return ret; | ||
| 1101 | + } | ||
| 1102 | + srs_info("complex handhskae failed, try simple. ret=%d", ret); | ||
| 1103 | + | ||
| 1104 | + char* s0s1s2 = new char[3073]; | ||
| 1105 | + SrsAutoFree(char, s0s1s2, true); | ||
| 1106 | + // plain text required. | ||
| 1107 | + s0s1s2[0] = 0x03; | ||
| 1108 | + if ((ret = skt.write(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) { | ||
| 1109 | + srs_warn("simple handshake send s0s1s2 failed. ret=%d", ret); | ||
| 1110 | + return ret; | ||
| 1111 | + } | ||
| 1112 | + srs_verbose("simple handshake send s0s1s2 success."); | ||
| 1113 | + | ||
| 1114 | + char* c2 = new char[1536]; | ||
| 1115 | + SrsAutoFree(char, c2, true); | ||
| 1116 | + if ((ret = skt.read_fully(c2, 1536, &nsize)) != ERROR_SUCCESS) { | ||
| 1117 | + srs_warn("simple handshake read c2 failed. ret=%d", ret); | ||
| 1118 | + return ret; | ||
| 1119 | + } | ||
| 1120 | + srs_verbose("simple handshake read c2 success."); | ||
| 1121 | + | ||
| 1122 | + srs_trace("simple handshake success."); | ||
| 1123 | + | ||
| 1124 | + return ret; | ||
| 1125 | +} | ||
| 1126 | + | ||
| 1061 | SrsComplexHandshake::SrsComplexHandshake() | 1127 | SrsComplexHandshake::SrsComplexHandshake() |
| 1062 | { | 1128 | { |
| 1063 | } | 1129 | } |
| @@ -21,8 +21,8 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,8 +21,8 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#ifndef SRS_CORE_COMPLEX_HANDSHKAE_HPP | ||
| 25 | -#define SRS_CORE_COMPLEX_HANDSHKAE_HPP | 24 | +#ifndef SRS_CORE_HANDSHKAE_HPP |
| 25 | +#define SRS_CORE_HANDSHKAE_HPP | ||
| 26 | 26 | ||
| 27 | /* | 27 | /* |
| 28 | #include <srs_core_complex_handshake.hpp> | 28 | #include <srs_core_complex_handshake.hpp> |
| @@ -33,6 +33,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | class SrsSocket; | 33 | class SrsSocket; |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | +* try complex handshake, if failed, fallback to simple handshake. | ||
| 37 | +*/ | ||
| 38 | +class SrsSimpleHandshake | ||
| 39 | +{ | ||
| 40 | +public: | ||
| 41 | + SrsSimpleHandshake(); | ||
| 42 | + virtual ~SrsSimpleHandshake(); | ||
| 43 | +public: | ||
| 44 | + /** | ||
| 45 | + * simple handshake. | ||
| 46 | + */ | ||
| 47 | + virtual int handshake(SrsSocket& skt); | ||
| 48 | +}; | ||
| 49 | + | ||
| 50 | +/** | ||
| 36 | * rtmp complex handshake, | 51 | * rtmp complex handshake, |
| 37 | * @see also crtmp(crtmpserver) or librtmp, | 52 | * @see also crtmp(crtmpserver) or librtmp, |
| 38 | * @see also: http://blog.csdn.net/win_lin/article/details/13006803 | 53 | * @see also: http://blog.csdn.net/win_lin/article/details/13006803 |
| @@ -23,15 +23,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -23,15 +23,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | 23 | ||
| 24 | #include <srs_core_pithy_print.hpp> | 24 | #include <srs_core_pithy_print.hpp> |
| 25 | 25 | ||
| 26 | +#include <stdlib.h> | ||
| 26 | #include <map> | 27 | #include <map> |
| 27 | 28 | ||
| 28 | #include <srs_core_log.hpp> | 29 | #include <srs_core_log.hpp> |
| 30 | +#include <srs_core_config.hpp> | ||
| 31 | +#include <srs_core_reload.hpp> | ||
| 32 | +#include <srs_core_error.hpp> | ||
| 29 | 33 | ||
| 30 | #define SRS_STAGE_DEFAULT_INTERVAL_MS 1200 | 34 | #define SRS_STAGE_DEFAULT_INTERVAL_MS 1200 |
| 31 | #define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300 | 35 | #define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300 |
| 32 | #define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100 | 36 | #define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100 |
| 33 | 37 | ||
| 34 | -struct SrsStageInfo | 38 | +struct SrsStageInfo : public SrsReloadHandler |
| 35 | { | 39 | { |
| 36 | int stage_id; | 40 | int stage_id; |
| 37 | int pithy_print_time_ms; | 41 | int pithy_print_time_ms; |
| @@ -40,19 +44,46 @@ struct SrsStageInfo | @@ -40,19 +44,46 @@ struct SrsStageInfo | ||
| 40 | SrsStageInfo(int _stage_id) | 44 | SrsStageInfo(int _stage_id) |
| 41 | { | 45 | { |
| 42 | stage_id = _stage_id; | 46 | stage_id = _stage_id; |
| 43 | - | ||
| 44 | - switch (_stage_id) { | ||
| 45 | - case SRS_STAGE_PLAY_USER: | 47 | + nb_clients = 0; |
| 48 | + | ||
| 49 | + update_print_time(); | ||
| 50 | + | ||
| 51 | + config->subscribe(this); | ||
| 52 | + } | ||
| 53 | + virtual ~SrsStageInfo() | ||
| 54 | + { | ||
| 55 | + config->unsubscribe(this); | ||
| 56 | + } | ||
| 57 | + void update_print_time() | ||
| 58 | + { | ||
| 59 | + switch (stage_id) { | ||
| 60 | + case SRS_STAGE_PLAY_USER: { | ||
| 46 | pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS; | 61 | pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS; |
| 47 | - case SRS_STAGE_PUBLISH_USER: | 62 | + SrsConfDirective* conf = config->get_pithy_print_play(); |
| 63 | + if (conf && !conf->arg0().empty()) { | ||
| 64 | + pithy_print_time_ms = ::atoi(conf->arg0().c_str()); | ||
| 65 | + } | ||
| 66 | + break; | ||
| 67 | + } | ||
| 68 | + case SRS_STAGE_PUBLISH_USER: { | ||
| 48 | pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS; | 69 | pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS; |
| 70 | + SrsConfDirective* conf = config->get_pithy_print_publish(); | ||
| 71 | + if (conf && !conf->arg0().empty()) { | ||
| 72 | + pithy_print_time_ms = ::atoi(conf->arg0().c_str()); | ||
| 73 | + } | ||
| 49 | break; | 74 | break; |
| 50 | - default: | 75 | + } |
| 76 | + default: { | ||
| 51 | pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS; | 77 | pithy_print_time_ms = SRS_STAGE_DEFAULT_INTERVAL_MS; |
| 52 | break; | 78 | break; |
| 79 | + } | ||
| 53 | } | 80 | } |
| 54 | - | ||
| 55 | - nb_clients = 0; | 81 | + } |
| 82 | +public: | ||
| 83 | + virtual int on_reload_pithy_print() | ||
| 84 | + { | ||
| 85 | + update_print_time(); | ||
| 86 | + return ERROR_SUCCESS; | ||
| 56 | } | 87 | } |
| 57 | }; | 88 | }; |
| 58 | static std::map<int, SrsStageInfo*> _srs_stages; | 89 | static std::map<int, SrsStageInfo*> _srs_stages; |
| @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | #include <srs_core_socket.hpp> | 29 | #include <srs_core_socket.hpp> |
| 30 | #include <srs_core_buffer.hpp> | 30 | #include <srs_core_buffer.hpp> |
| 31 | #include <srs_core_stream.hpp> | 31 | #include <srs_core_stream.hpp> |
| 32 | -#include <srs_core_auto_free.hpp> | 32 | +#include <srs_core_autofree.hpp> |
| 33 | 33 | ||
| 34 | /**************************************************************************** | 34 | /**************************************************************************** |
| 35 | ***************************************************************************** | 35 | ***************************************************************************** |
| @@ -35,7 +35,11 @@ SrsReloadHandler::~SrsReloadHandler() | @@ -35,7 +35,11 @@ SrsReloadHandler::~SrsReloadHandler() | ||
| 35 | 35 | ||
| 36 | int SrsReloadHandler::on_reload_listen() | 36 | int SrsReloadHandler::on_reload_listen() |
| 37 | { | 37 | { |
| 38 | - int ret = ERROR_SUCCESS; | ||
| 39 | - return ret; | 38 | + return ERROR_SUCCESS; |
| 39 | +} | ||
| 40 | + | ||
| 41 | +int SrsReloadHandler::on_reload_pithy_print() | ||
| 42 | +{ | ||
| 43 | + return ERROR_SUCCESS; | ||
| 40 | } | 44 | } |
| 41 | 45 |
| @@ -27,9 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -27,9 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | #include <srs_core_error.hpp> | 27 | #include <srs_core_error.hpp> |
| 28 | #include <srs_core_socket.hpp> | 28 | #include <srs_core_socket.hpp> |
| 29 | #include <srs_core_protocol.hpp> | 29 | #include <srs_core_protocol.hpp> |
| 30 | -#include <srs_core_auto_free.hpp> | 30 | +#include <srs_core_autofree.hpp> |
| 31 | #include <srs_core_amf0.hpp> | 31 | #include <srs_core_amf0.hpp> |
| 32 | -#include <srs_core_complex_handshake.hpp> | 32 | +#include <srs_core_handshake.hpp> |
| 33 | 33 | ||
| 34 | /** | 34 | /** |
| 35 | * the signature for packets to client. | 35 | * the signature for packets to client. |
| @@ -167,13 +167,11 @@ SrsRtmp::SrsRtmp(st_netfd_t client_stfd) | @@ -167,13 +167,11 @@ SrsRtmp::SrsRtmp(st_netfd_t client_stfd) | ||
| 167 | { | 167 | { |
| 168 | protocol = new SrsProtocol(client_stfd); | 168 | protocol = new SrsProtocol(client_stfd); |
| 169 | stfd = client_stfd; | 169 | stfd = client_stfd; |
| 170 | - complex_handshake = new SrsComplexHandshake(); | ||
| 171 | } | 170 | } |
| 172 | 171 | ||
| 173 | SrsRtmp::~SrsRtmp() | 172 | SrsRtmp::~SrsRtmp() |
| 174 | { | 173 | { |
| 175 | srs_freep(protocol); | 174 | srs_freep(protocol); |
| 176 | - srs_freep(complex_handshake); | ||
| 177 | } | 175 | } |
| 178 | 176 | ||
| 179 | void SrsRtmp::set_recv_timeout(int64_t timeout_us) | 177 | void SrsRtmp::set_recv_timeout(int64_t timeout_us) |
| @@ -225,58 +223,14 @@ int SrsRtmp::handshake() | @@ -225,58 +223,14 @@ int SrsRtmp::handshake() | ||
| 225 | { | 223 | { |
| 226 | int ret = ERROR_SUCCESS; | 224 | int ret = ERROR_SUCCESS; |
| 227 | 225 | ||
| 228 | - ssize_t nsize; | ||
| 229 | SrsSocket skt(stfd); | 226 | SrsSocket skt(stfd); |
| 230 | 227 | ||
| 231 | - char* c0c1 = new char[1537]; | ||
| 232 | - SrsAutoFree(char, c0c1, true); | ||
| 233 | - if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) { | ||
| 234 | - srs_warn("read c0c1 failed. ret=%d", ret); | 228 | + SrsSimpleHandshake hs; |
| 229 | + if ((ret = hs.handshake(skt)) != ERROR_SUCCESS) { | ||
| 235 | return ret; | 230 | return ret; |
| 236 | } | 231 | } |
| 237 | - srs_verbose("read c0c1 success."); | ||
| 238 | - | ||
| 239 | - // plain text required. | ||
| 240 | - if (c0c1[0] != 0x03) { | ||
| 241 | - ret = ERROR_RTMP_PLAIN_REQUIRED; | ||
| 242 | - srs_warn("only support rtmp plain text. ret=%d", ret); | ||
| 243 | - return ret; | ||
| 244 | - } | ||
| 245 | - srs_verbose("check c0 success, required plain text."); | ||
| 246 | 232 | ||
| 247 | - // try complex handshake | ||
| 248 | - ret = complex_handshake->handshake(skt, c0c1 + 1); | ||
| 249 | - if (ret == ERROR_SUCCESS) { | ||
| 250 | - srs_trace("complex handshake success."); | ||
| 251 | - return ret; | ||
| 252 | - } | ||
| 253 | - if (ret != ERROR_RTMP_TRY_SIMPLE_HS) { | ||
| 254 | - srs_error("complex handshake failed. ret=%d", ret); | ||
| 255 | - return ret; | ||
| 256 | - } | ||
| 257 | - srs_info("complex handhskae failed, try simple. ret=%d", ret); | ||
| 258 | - | ||
| 259 | - char* s0s1s2 = new char[3073]; | ||
| 260 | - SrsAutoFree(char, s0s1s2, true); | ||
| 261 | - // plain text required. | ||
| 262 | - s0s1s2[0] = 0x03; | ||
| 263 | - if ((ret = skt.write(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) { | ||
| 264 | - srs_warn("simple handshake send s0s1s2 failed. ret=%d", ret); | ||
| 265 | - return ret; | ||
| 266 | - } | ||
| 267 | - srs_verbose("simple handshake send s0s1s2 success."); | ||
| 268 | - | ||
| 269 | - char* c2 = new char[1536]; | ||
| 270 | - SrsAutoFree(char, c2, true); | ||
| 271 | - if ((ret = skt.read_fully(c2, 1536, &nsize)) != ERROR_SUCCESS) { | ||
| 272 | - srs_warn("simple handshake read c2 failed. ret=%d", ret); | ||
| 273 | - return ret; | ||
| 274 | - } | ||
| 275 | - srs_verbose("simple handshake read c2 success."); | ||
| 276 | - | ||
| 277 | - srs_trace("simple handshake success."); | ||
| 278 | - | ||
| 279 | - return ret; | 233 | + return ret; |
| 280 | } | 234 | } |
| 281 | 235 | ||
| 282 | int SrsRtmp::connect_app(SrsRequest* req) | 236 | int SrsRtmp::connect_app(SrsRequest* req) |
| @@ -39,7 +39,6 @@ class ISrsMessage; | @@ -39,7 +39,6 @@ class ISrsMessage; | ||
| 39 | class SrsCommonMessage; | 39 | class SrsCommonMessage; |
| 40 | class SrsCreateStreamPacket; | 40 | class SrsCreateStreamPacket; |
| 41 | class SrsFMLEStartPacket; | 41 | class SrsFMLEStartPacket; |
| 42 | -class SrsComplexHandshake; | ||
| 43 | class SrsPublishPacket; | 42 | class SrsPublishPacket; |
| 44 | 43 | ||
| 45 | /** | 44 | /** |
| @@ -101,7 +100,6 @@ enum SrsClientType | @@ -101,7 +100,6 @@ enum SrsClientType | ||
| 101 | class SrsRtmp | 100 | class SrsRtmp |
| 102 | { | 101 | { |
| 103 | private: | 102 | private: |
| 104 | - SrsComplexHandshake* complex_handshake; | ||
| 105 | SrsProtocol* protocol; | 103 | SrsProtocol* protocol; |
| 106 | st_netfd_t stfd; | 104 | st_netfd_t stfd; |
| 107 | public: | 105 | public: |
| @@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | 27 | ||
| 28 | #include <srs_core_log.hpp> | 28 | #include <srs_core_log.hpp> |
| 29 | #include <srs_core_protocol.hpp> | 29 | #include <srs_core_protocol.hpp> |
| 30 | -#include <srs_core_auto_free.hpp> | 30 | +#include <srs_core_autofree.hpp> |
| 31 | #include <srs_core_amf0.hpp> | 31 | #include <srs_core_amf0.hpp> |
| 32 | #include <srs_core_codec.hpp> | 32 | #include <srs_core_codec.hpp> |
| 33 | 33 |
| @@ -6,8 +6,8 @@ file | @@ -6,8 +6,8 @@ file | ||
| 6 | ..\core\srs_core.cpp, | 6 | ..\core\srs_core.cpp, |
| 7 | ..\core\srs_core_error.hpp, | 7 | ..\core\srs_core_error.hpp, |
| 8 | ..\core\srs_core_error.cpp, | 8 | ..\core\srs_core_error.cpp, |
| 9 | - ..\core\srs_core_auto_free.hpp, | ||
| 10 | - ..\core\srs_core_auto_free.cpp, | 9 | + ..\core\srs_core_autofree.hpp, |
| 10 | + ..\core\srs_core_autofree.cpp, | ||
| 11 | ..\core\srs_core_server.hpp, | 11 | ..\core\srs_core_server.hpp, |
| 12 | ..\core\srs_core_server.cpp, | 12 | ..\core\srs_core_server.cpp, |
| 13 | ..\core\srs_core_reload.hpp, | 13 | ..\core\srs_core_reload.hpp, |
| @@ -26,8 +26,8 @@ file | @@ -26,8 +26,8 @@ file | ||
| 26 | ..\core\srs_core_codec.cpp, | 26 | ..\core\srs_core_codec.cpp, |
| 27 | ..\core\srs_core_rtmp.hpp, | 27 | ..\core\srs_core_rtmp.hpp, |
| 28 | ..\core\srs_core_rtmp.cpp, | 28 | ..\core\srs_core_rtmp.cpp, |
| 29 | - ..\core\srs_core_complex_handshake.hpp, | ||
| 30 | - ..\core\srs_core_complex_handshake.cpp, | 29 | + ..\core\srs_core_handshake.hpp, |
| 30 | + ..\core\srs_core_handshake.cpp, | ||
| 31 | ..\core\srs_core_protocol.hpp, | 31 | ..\core\srs_core_protocol.hpp, |
| 32 | ..\core\srs_core_protocol.cpp, | 32 | ..\core\srs_core_protocol.cpp, |
| 33 | ..\core\srs_core_amf0.hpp, | 33 | ..\core\srs_core_amf0.hpp, |
-
请 注册 或 登录 后发表评论