diff --git a/README.md b/README.md index e8e9a4598..4c23494ea 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ step 1: build srs
 tar xf simple-rtmp-server-*.*.tar.gz
 cd simple-rtmp-server-*.*/trunk
-./configure
+./configure --with-ssl --with-hls
 make
 
step 2: start srs
@@ -64,6 +64,8 @@ m3u8 url: http://127.0.0.1:80/live/livestream.m3u8 * nginx v1.5.0: 139524 lines
### History +* v0.6, 2013-11-27, support --with or --without -hls and -ssl options. +* v0.6, 2013-11-27, support AAC 44100HZ sample rate for iphone, adjust the timestamp. * v0.5, 2013-11-26, v0.5 released. 14449 lines. * v0.5, 2013-11-24, support HLS(m3u8), fragment and window. * v0.5, 2013-11-24, support record to ts file for HLS. diff --git a/trunk/auto/apps.sh b/trunk/auto/apps.sh index b0ba84a92..b2ac7afd6 100644 --- a/trunk/auto/apps.sh +++ b/trunk/auto/apps.sh @@ -1,8 +1,8 @@ #!/bin/bash # params: -# $GLOBAL_DIR_OBJS the objs directory. ie. objs -# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile +# $SRS_OBJS the objs directory. ie. objs +# $SRS_MAKEFILE the makefile name. ie. Makefile # $MAIN_ENTRANCES array, all main entrance, disable all except the $APP_MAIN itself # $MODULE_OBJS array, the objects to compile the app. # $BUILD_KEY a string indicates the build key for Makefile. ie. dump @@ -12,9 +12,9 @@ # $LINK_OPTIONS the linker options. # $SO_PATH the libssl.so.10 and other so file path. -FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} +FILE=${SRS_OBJS}/${SRS_MAKEFILE} -APP_TARGET="${GLOBAL_DIR_OBJS}/${APP_NAME}" +APP_TARGET="${SRS_OBJS}/${APP_NAME}" echo "generate app ${APP_NAME} depends..."; @@ -42,7 +42,7 @@ for item in ${MODULE_OBJS[*]}; do continue; fi - OBJ_FILE=${GLOBAL_DIR_OBJS}/$item + OBJ_FILE=${SRS_OBJS}/$item OBJ_FILE="${OBJ_FILE%.*}.o" echo -n "${OBJ_FILE} " >> ${FILE} done @@ -71,7 +71,7 @@ for item in ${MODULE_OBJS[*]}; do continue; fi - OBJ_FILE=${GLOBAL_DIR_OBJS}/$item + OBJ_FILE=${SRS_OBJS}/$item OBJ_FILE="${OBJ_FILE%.*}.o" echo -n "${OBJ_FILE} " >> ${FILE} done diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh new file mode 100644 index 000000000..36c625d82 --- /dev/null +++ b/trunk/auto/depends.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# TODO: check gcc/g++ +echo "check gcc/g++/gdb/make/openssl-devel" +echo "depends tools are ok" + +##################################################################################### +# st-1.9 +##################################################################################### +if [[ -f ${SRS_OBJS}/st-1.9/obj/libst.a && -f ${SRS_OBJS}/st-1.9/obj/libst.so ]]; then + echo "st-1.9t is ok."; +else + echo "build st-1.9t"; + ( + rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} && + unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug && + cd .. && rm -f st && ln -sf st-1.9/obj st + ) +fi +# check status +ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi +if [ ! -f ${SRS_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi +if [ ! -f ${SRS_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi + +##################################################################################### +# http-parser-2.1 +##################################################################################### +if [[ -f ${SRS_OBJS}/http-parser-2.1/http_parser.h && -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then + echo "http-parser-2.1 is ok."; +else + echo "build http-parser-2.1"; + ( + rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip && + cd http-parser-2.1 && + sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile && + sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile && + make package && + cd .. && rm -f hp && ln -sf http-parser-2.1 hp + ) +fi +# check status +ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi +if [[ ! -f ${SRS_OBJS}/http-parser-2.1/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi +if [[ ! -f ${SRS_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi + +##################################################################################### +# nginx for HLS, nginx-1.5.0 +##################################################################################### +if [ $SRS_HLS = YES ]; then + if [[ -f ${SRS_OBJS}/nginx-1.5.7/_release/sbin/nginx ]]; then + echo "nginx-1.5.7 is ok."; + else + echo "build nginx-1.5.7"; + ( + rm -rf ${SRS_OBJS}/nginx-1.5.7 && cd ${SRS_OBJS} && + unzip -q ../3rdparty/nginx-1.5.7.zip && cd nginx-1.5.7 && + ./configure --prefix=`pwd`/_release && make && make install && + ln -sf `pwd`/_release ../nginx + ) + fi + # check status + ret=$?; if [[ $ret -ne 0 ]]; then echo "build nginx-1.5.7 failed, ret=$ret"; exit $ret; fi + if [ ! -f ${SRS_OBJS}/nginx-1.5.7/_release/sbin/nginx ]; then echo "build nginx-1.5.7 failed."; exit -1; fi + + # use current user to config nginx, + # srs will write ts/m3u8 file use current user, + # nginx default use nobody, so cannot read the ts/m3u8 created by srs. + cp ${SRS_OBJS}/nginx/conf/nginx.conf ${SRS_OBJS}/nginx/conf/nginx.conf.bk + sed -i "s/^.user nobody;/user `whoami`;/g" ${SRS_OBJS}/nginx/conf/nginx.conf +fi + +if [ $SRS_HLS = YES ]; then + echo "#define SRS_HLS" >> $SRS_AUTO_HEADERS_H +else + echo "#undef SRS_HLS" >> $SRS_AUTO_HEADERS_H +fi + +##################################################################################### +# openssl, for rtmp complex handshake +##################################################################################### +if [ $SRS_SSL = YES ]; then + echo "#define SRS_SSL" >> $SRS_AUTO_HEADERS_H +else + echo "#undef SRS_SSL" >> $SRS_AUTO_HEADERS_H +fi diff --git a/trunk/auto/modules.sh b/trunk/auto/modules.sh old mode 100755 new mode 100644 index 6a30d706e..6d28eb299 --- a/trunk/auto/modules.sh +++ b/trunk/auto/modules.sh @@ -1,6 +1,6 @@ # params: -# $GLOBAL_DIR_OBJS the objs directory. ie. objs -# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile +# $SRS_OBJS the objs directory. ie. objs +# $SRS_MAKEFILE the makefile name. ie. Makefile # $MODULE_DIR the module dir. ie. src/os/linux # $MODULE_ID the id of module. ie. CORE # $MODULE_DEPENDS array, the denpend MODULEs id. ie. (CORE OS) @@ -10,7 +10,7 @@ # returns: # $MODULE_OBJS array, the objects of the modules. -FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} +FILE=${SRS_OBJS}/${SRS_MAKEFILE} # INCS INCS_NAME="${MODULE_ID}_INCS" @@ -46,16 +46,17 @@ echo "" >> ${FILE}; echo "" >> ${FILE} MODULE_OBJS=() for item in ${MODULE_FILES[*]}; do CPP_FILE="${MODULE_DIR}/${item}.cpp" - OBJ_FILE="${GLOBAL_DIR_OBJS}/${MODULE_DIR}/${item}.o" + OBJ_FILE="${SRS_OBJS}/${MODULE_DIR}/${item}.o" MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}" if [ -f ${CPP_FILE} ]; then echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE} - echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME})-o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE} + echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME})\\" >> ${FILE} + echo " -o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE} fi done echo "" >> ${FILE} # Makefile -echo " mkdir -p ${GLOBAL_DIR_OBJS}/${MODULE_DIR}" >> ${GLOBAL_FILE_MAKEFILE} +echo " mkdir -p ${SRS_OBJS}/${MODULE_DIR}" >> ${SRS_MAKEFILE} echo -n "generate module ${MODULE_ID} ok"; echo '!'; diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh new file mode 100644 index 000000000..4c5168994 --- /dev/null +++ b/trunk/auto/options.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +help=no + +SRS_HLS=RESERVED +SRS_SSL=RESERVED + +opt= + +for option +do + opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`" + + case "$option" in + -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; + *) value="" ;; + esac + + case "$option" in + --help) help=yes ;; + + --with-ssl) SRS_SSL=YES ;; + --with-hls) SRS_HLS=YES ;; + + --without-ssl) SRS_SSL=NO ;; + --without-hls) SRS_HLS=NO ;; + + *) + echo "$0: error: invalid option \"$option\"" + exit 1 + ;; + esac +done + +# save all config options to macro. +SRS_CONFIGURE="$opt" + +if [ $help = yes ]; then +cat << END + + --help print this message + + --with-ssl enable rtmp complex handshake, requires openssl-devel installed. + to delivery h264 video and aac audio to flash player. + --with-hls enable hls streaming, build nginx as http server for hls. + + --without-ssl disable rtmp complex handshake. + --without-hls disable hls, rtmp streaming only. + +END + + exit 1 +fi + +__check_ok=YES +if [ $SRS_SSL = RESERVED ]; then + echo "you must specifies the ssl, see: ./configure --help"; + __check_ok=NO +fi +if [ $SRS_HLS = RESERVED ]; then + echo "you must specifies the hls, see: ./configure --help"; + __check_ok=NO +fi +if [ $__check_ok = NO ]; then + exit 1; +fi \ No newline at end of file diff --git a/trunk/configure b/trunk/configure index 6dfd0b09a..d42c514d9 100755 --- a/trunk/configure +++ b/trunk/configure @@ -1,79 +1,34 @@ #!/bin/bash -GLOBAL_FILE_MAKEFILE="Makefile" -GLOBAL_DIR_OBJS="objs" +SRS_MAKEFILE="Makefile" +SRS_OBJS="objs" +SRS_AUTO_HEADERS_H="${SRS_OBJS}/srs_auto_headers.hpp" -mkdir -p ${GLOBAL_DIR_OBJS} +mkdir -p ${SRS_OBJS} -echo "check gcc/g++/gdb/make/openssl-devel" -echo "depends tools are ok" - -##################################################################################### -# prepare the depends tools -##################################################################################### -# st-1.9 -if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]]; then - echo "st-1.9t is ok."; -else - echo "build st-1.9t"; - ( - rm -rf ${GLOBAL_DIR_OBJS}/st-1.9 && cd ${GLOBAL_DIR_OBJS} && - unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug && - cd .. && rm -f st && ln -sf st-1.9/obj st - ) +# clean the exists +if [[ -f Makefile ]]; then + make clean fi -# check status -ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi -if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi -if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi -# http-parser-2.1 -if [[ -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/http_parser.h && -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then - echo "http-parser-2.1 is ok."; -else - echo "build http-parser-2.1"; - ( - rm -rf ${GLOBAL_DIR_OBJS}/http-parser-2.1 && cd ${GLOBAL_DIR_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip && - cd http-parser-2.1 && - sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile && - sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile && - make package && - cd .. && rm -f hp && ln -sf http-parser-2.1 hp - ) -fi -# check status -ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi -if [[ ! -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi -if [[ ! -f ${GLOBAL_DIR_OBJS}/http-parser-2.1/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi +# parse user options. +. auto/options.sh -# nginx for HLS, nginx-1.5.0 -if [[ -f ${GLOBAL_DIR_OBJS}/nginx-1.5.7/_release/sbin/nginx ]]; then - echo "nginx-1.5.7 is ok."; -else - echo "build nginx-1.5.7"; - ( - rm -rf ${GLOBAL_DIR_OBJS}/nginx-1.5.7 && cd ${GLOBAL_DIR_OBJS} && - unzip -q ../3rdparty/nginx-1.5.7.zip && cd nginx-1.5.7 && - ./configure --prefix=`pwd`/_release && make && make install && - ln -sf `pwd`/_release ../nginx - ) -fi -# check status -ret=$?; if [[ $ret -ne 0 ]]; then echo "build nginx-1.5.7 failed, ret=$ret"; exit $ret; fi -if [ ! -f ${GLOBAL_DIR_OBJS}/nginx-1.5.7/_release/sbin/nginx ]; then echo "build nginx-1.5.7 failed."; exit -1; fi +# generate the audo headers file. +echo "#define SRS_CONFIGURE \"${SRS_CONFIGURE}\"" > $SRS_AUTO_HEADERS_H -# use current user to config nginx, -# srs will write ts/m3u8 file use current user, -# nginx default use nobody, so cannot read the ts/m3u8 created by srs. -cp ${GLOBAL_DIR_OBJS}/nginx/conf/nginx.conf ${GLOBAL_DIR_OBJS}/nginx/conf/nginx.conf.bk -sed -i "s/^.user nobody;/user `whoami`;/g" ${GLOBAL_DIR_OBJS}/nginx/conf/nginx.conf +# apply user options. +. auto/depends.sh + +# new empty line to auto headers file. +echo "" >> $SRS_AUTO_HEADERS_H ##################################################################################### # generate Makefile. ##################################################################################### echo "generate Makefile" -cat << END > ${GLOBAL_FILE_MAKEFILE} +cat << END > ${SRS_MAKEFILE} .PHONY: default help clean server _prepare_dir default: server @@ -84,15 +39,15 @@ help: @echo " server build the srs(simple rtmp server) over st(state-threads)" clean: - (cd ${GLOBAL_DIR_OBJS}; rm -rf src st_*_load) + (rm -f Makefile; cd ${SRS_OBJS}; rm -rf Makefile *.hpp src st_*_load) server: _prepare_dir @echo "build the srs(simple rtmp server) over st(state-threads)" - \$(MAKE) -f ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} simple_rtmp_server + \$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} simple_rtmp_server # the ./configure will generate it. _prepare_dir: - @mkdir -p ${GLOBAL_DIR_OBJS} + @mkdir -p ${SRS_OBJS} END echo 'generate Makefile ok!' @@ -108,7 +63,7 @@ CppStd="-ansi" # the cxx flag generated. CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}" #CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}" -cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} +cat << END > ${SRS_OBJS}/${SRS_MAKEFILE} CXXFLAGS = ${CXXFLAGS} GCC = g++ LINK = \$(GCC) @@ -121,15 +76,15 @@ default: END # Libraries -LibSTRoot="${GLOBAL_DIR_OBJS}/st" +LibSTRoot="${SRS_OBJS}/st" LibSTfile="${LibSTRoot}/libst.a" -LibHttpParserRoot="${GLOBAL_DIR_OBJS}/hp" +LibHttpParserRoot="${SRS_OBJS}/hp" LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a" #Core Module MODULE_ID="CORE" MODULE_DEPENDS=() -ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot}) +ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" "srs_core_error" "srs_core_conn" "srs_core_client" "srs_core_rtmp" "srs_core_socket" "srs_core_buffer" @@ -144,7 +99,7 @@ CORE_OBJS="${MODULE_OBJS[@]}" #Main Module MODULE_ID="MAIN" MODULE_DEPENDS=("CORE") -ModuleLibIncs=(${LibSTRoot}) +ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS}) MODULE_FILES=("srs_main_server") MODULE_DIR="src/main" . auto/modules.sh MAIN_OBJS="${MODULE_OBJS[@].o}" @@ -155,7 +110,12 @@ MAIN_ENTRANCES=("srs_main_server") # srs(simple rtmp server) over st(state-threads) ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile}) MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}" -BUILD_KEY="simple_rtmp_server" APP_MAIN="srs_main_server" APP_NAME="simple_rtmp_server" LINK_OPTIONS="-ldl -lssl -lcrypto" SO_PATH="" . auto/apps.sh +if [ $SRS_SSL = YES ]; then + LINK_OPTIONS="-ldl -lssl -lcrypto" +else + LINK_OPTIONS="-ldl" +fi +BUILD_KEY="simple_rtmp_server" APP_MAIN="srs_main_server" APP_NAME="simple_rtmp_server" SO_PATH="" . auto/apps.sh echo 'configure ok! ' @@ -163,5 +123,7 @@ echo 'configure ok! ' echo "you can:" echo "\" make \" to build the srs(simple rtmp server)." echo "\" make help \" to get the usage of make" -echo "\" sudo ./objs/nginx/sbin/nginx \" to start the nginx http server for hls" +if [ $SRS_HLS = YES ]; then + echo "\" sudo ./objs/nginx/sbin/nginx \" to start the nginx http server for hls" +fi echo "\" ./objs/simple_rtmp_server -c conf/srs.conf \" to start the srs live server" diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index c884c277b..657eba0a5 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -46,6 +46,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +// generated by configure. +#include + // free the p and set to NULL. // p must be a T*. #define srs_freep(p) \ diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp index e8dde1853..22c2d57e0 100644 --- a/trunk/src/core/srs_core_config.cpp +++ b/trunk/src/core/srs_core_config.cpp @@ -703,6 +703,8 @@ int SrsConfig::parse_file(const char* filename) } // TODO: check the hls. // TODO: check other config. + // TODO: check hls. + // TODO: check ssl. return ret; } @@ -756,6 +758,7 @@ void SrsConfig::print_help(char** argv) { printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION " Copyright (c) 2013 winlin\n" + "configuration: "SRS_CONFIGURE"\n" "Usage: %s [-h?vV] [-c ]\n" "\n" "Options:\n" @@ -765,7 +768,8 @@ void SrsConfig::print_help(char** argv) "\n" RTMP_SIG_SRS_WEB"\n" RTMP_SIG_SRS_URL"\n" - "Email: "RTMP_SIG_SRS_EMAIL"\n", + "Email: "RTMP_SIG_SRS_EMAIL"\n" + "\n", argv[0]); } diff --git a/trunk/src/core/srs_core_handshake.cpp b/trunk/src/core/srs_core_handshake.cpp index 9877b596d..36efa5bae 100644 --- a/trunk/src/core/srs_core_handshake.cpp +++ b/trunk/src/core/srs_core_handshake.cpp @@ -44,6 +44,8 @@ void srs_random_generate(char* bytes, int size) } } +#ifdef SRS_SSL + // 68bytes FMS key which is used to sign the sever packet. u_int8_t SrsGenuineFMSKey[] = { 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, @@ -1055,6 +1057,8 @@ void c1s1::destroy_blocks() } } +#endif + SrsSimpleHandshake::SrsSimpleHandshake() { } @@ -1129,10 +1133,16 @@ SrsComplexHandshake::~SrsComplexHandshake() { } +#ifndef SRS_SSL +int SrsComplexHandshake::handshake(SrsSocket& /*skt*/, char* /*_c1*/) +{ + return ERROR_RTMP_TRY_SIMPLE_HS; +} +#else int SrsComplexHandshake::handshake(SrsSocket& skt, char* _c1) { int ret = ERROR_SUCCESS; - + ssize_t nsize; static bool _random_initialized = false; @@ -1204,4 +1214,5 @@ int SrsComplexHandshake::handshake(SrsSocket& skt, char* _c1) return ret; } +#endif diff --git a/trunk/src/core/srs_core_hls.cpp b/trunk/src/core/srs_core_hls.cpp index a8335aef2..42578e3ce 100644 --- a/trunk/src/core/srs_core_hls.cpp +++ b/trunk/src/core/srs_core_hls.cpp @@ -23,6 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#ifdef SRS_HLS + #include #include #include @@ -731,11 +733,11 @@ int SrsHls::reopen() } if (!segment_to_remove.empty()) { segments.erase(segments.begin(), segments.begin() + segment_to_remove.size()); - } - // refresh the m3u8, donot contains the removed ts - if ((ret = refresh_m3u8()) != ERROR_SUCCESS) { - return ret; + // refresh the m3u8, donot contains the removed ts + if ((ret = refresh_m3u8()) != ERROR_SUCCESS) { + return ret; + } } // remove the ts file. @@ -1152,3 +1154,5 @@ bool SrsTSMuxer::fresh() return _fresh; } +#endif + diff --git a/trunk/src/core/srs_core_hls.hpp b/trunk/src/core/srs_core_hls.hpp index 3e7a339be..87e829234 100644 --- a/trunk/src/core/srs_core_hls.hpp +++ b/trunk/src/core/srs_core_hls.hpp @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#ifdef SRS_HLS + #include #include @@ -173,4 +175,6 @@ public: virtual bool fresh(); }; +#endif + #endif \ No newline at end of file diff --git a/trunk/src/core/srs_core_source.cpp b/trunk/src/core/srs_core_source.cpp index 92c9e8536..c731aac80 100644 --- a/trunk/src/core/srs_core_source.cpp +++ b/trunk/src/core/srs_core_source.cpp @@ -257,7 +257,10 @@ SrsSource* SrsSource::find(std::string stream_url) SrsSource::SrsSource(std::string _stream_url) { stream_url = _stream_url; + +#ifdef SRS_HLS hls = new SrsHls(); +#endif cache_metadata = cache_sh_video = cache_sh_audio = NULL; @@ -282,17 +285,21 @@ SrsSource::~SrsSource() srs_freep(cache_sh_video); srs_freep(cache_sh_audio); +#ifdef SRS_HLS srs_freep(hls); +#endif } int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata) { int ret = ERROR_SUCCESS; +#ifdef SRS_HLS if ((ret = hls->on_meta_data(metadata)) != ERROR_SUCCESS) { srs_error("hls process onMetaData message failed. ret=%d", ret); return ret; } +#endif metadata->metadata->set("server", new SrsAmf0String( RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); @@ -363,10 +370,12 @@ int SrsSource::on_audio(SrsCommonMessage* audio) } srs_verbose("initialize shared ptr audio success."); +#ifdef SRS_HLS if ((ret = hls->on_audio(msg->copy())) != ERROR_SUCCESS) { srs_error("hls process audio message failed. ret=%d", ret); return ret; } +#endif // detach the original audio audio->payload = NULL; @@ -413,11 +422,12 @@ int SrsSource::on_video(SrsCommonMessage* video) } srs_verbose("initialize shared ptr video success."); - // TODO: when return error, crash. +#ifdef SRS_HLS if ((ret = hls->on_video(msg->copy())) != ERROR_SUCCESS) { srs_error("hls process video message failed. ret=%d", ret); return ret; } +#endif // detach the original audio video->payload = NULL; @@ -452,15 +462,24 @@ int SrsSource::on_video(SrsCommonMessage* video) return ret; } +#ifdef SRS_HLS int SrsSource::on_publish(std::string vhost, std::string app, std::string stream) { return hls->on_publish(vhost, app, stream); } +#else +int SrsSource::on_publish(std::string /*vhost*/, std::string /*app*/, std::string /*stream*/) +{ + return ERROR_SUCCESS; +} +#endif void SrsSource::on_unpublish() { +#ifdef SRS_HLS hls->on_unpublish(); - +#endif + clear_gop_cache(); srs_freep(cache_metadata); diff --git a/trunk/src/core/srs_core_source.hpp b/trunk/src/core/srs_core_source.hpp index e51382fa9..0d6a221eb 100644 --- a/trunk/src/core/srs_core_source.hpp +++ b/trunk/src/core/srs_core_source.hpp @@ -38,7 +38,9 @@ class SrsSource; class SrsCommonMessage; class SrsOnMetaDataPacket; class SrsSharedPtrMessage; +#ifdef SRS_HLS class SrsHls; +#endif /** * time jitter detect and correct, @@ -125,7 +127,9 @@ public: */ static SrsSource* find(std::string stream_url); private: +#ifdef SRS_HLS SrsHls* hls; +#endif std::string stream_url; std::vector consumers; // gop cache for client fast startup. diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp old mode 100644 new mode 100755 index 26df10cb8..08dcbb7a0 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -1,6 +1,8 @@ file main readonly separator, ..\main\srs_main_server.cpp, + auto readonly separator, + ..\..\objs\srs_auto_headers.hpp, core readonly separator, ..\core\srs_core.hpp, ..\core\srs_core.cpp,