Skip to content

Commit

Permalink
support config and reload the pithy print.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 10, 2013
1 parent 6c3b594 commit 3669419
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 96 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ url: rtmp://127.0.0.1:1935/live/livestream
* nginx v1.5.0: 139524 lines <br/>

### History
* v0.4, 2013-11-10, support config and reload the pithy print.
* v0.4, 2013-11-09, support reload config(vhost and its detail).
* v0.4, 2013-11-09, support reload config(listen and chunk_size) by SIGHUP(1).
* v0.4, 2013-11-09, support longtime(>4.6hours) publish/play.
Expand Down
Binary file added trunk/3rdparty/http-parser-2.1.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions trunk/auto/modules.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
# INCS
INCS_NAME="${MODULE_ID}_INCS"
echo "# the ${MODULE_ID} module." >> ${FILE}
echo "${MODULE_ID}_MODULE_INCS = -I ${MODULE_DIR} " >> ${FILE}
echo -n "${INCS_NAME} = -I ${MODULE_DIR} " >> ${FILE}
echo "${MODULE_ID}_MODULE_INCS = -I${MODULE_DIR} " >> ${FILE}
echo -n "${INCS_NAME} = -I${MODULE_DIR} " >> ${FILE}
for item in ${MODULE_DEPENDS[*]}; do
DEP_INCS_NAME="${item}_INCS"do
DEP_INCS_NAME="${item}_MODULE_INCS"
echo -n "\$(${DEP_INCS_NAME}) " >> ${FILE}
done
for item in ${ModuleLibIncs[*]}; do
echo -n "-I ${item} " >> ${FILE}
echo -n "-I${item} " >> ${FILE}
done
echo "" >> ${FILE}

Expand All @@ -50,7 +50,7 @@ for item in ${MODULE_FILES[*]}; do
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})-o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE}
fi
done
echo "" >> ${FILE}
Expand Down
15 changes: 13 additions & 2 deletions trunk/conf/srs.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# the listen ports, split by space.
listen 1935;
listen 1935;
# the default chunk size is 128, max is 65536,
# some client does not support chunk size change,
# however, most clients supports it and it can improve
# performance about 10%.
# if not specified, set to 4096.
chunk_size 65000;
chunk_size 65000;
# vhost list, the __defaultVhost__ is the default vhost
# for which cannot identify the required vhost.
vhost __defaultVhost__ {
Expand Down Expand Up @@ -47,4 +47,15 @@ vhost refer.anti_suck.com {
# default: not specified.
refer_play github.com github.io;
}
# config for the pithy print,
# which always print constant message specified by interval,
# whatever the clients in concurrency.
pithy_print {
# shared print interval for all publish clients, in milliseconds.
# if not specified, set to 1100.
publish 2000;
# shared print interval for all play clients, in milliseconds.
# if not specified, set to 1300.
play 3000;
}

49 changes: 36 additions & 13 deletions trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,36 @@ if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/o
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 ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug)
(
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
)
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

#####################################################################################
# generate Makefile.
#####################################################################################
Expand Down Expand Up @@ -53,18 +76,16 @@ END
echo 'generate Makefile ok!'

# the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt
#Performance="-pg"
#PerformanceLink="-pg"
Performance="-pg"
# enable gdb debug
GDBDebug="-g -O0"
# the warning level.
WarnLevel="-Wall -Wextra"
WarnLevel="-Wall"
# the compile standard.
CppStd="-std=c++98"
# other macros defined
UserMacros=""
CppStd="-ansi"
# the cxx flag generated.
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance} ${UserMacros}"
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}"
#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
CXXFLAGS = ${CXXFLAGS}
GCC = g++
Expand All @@ -78,19 +99,21 @@ default:
END

# Libraries
LibSTRoot="${GLOBAL_DIR_OBJS}/st-1.9/obj"
LibSTRoot="${GLOBAL_DIR_OBJS}/st"
LibSTfile="${LibSTRoot}/libst.a"
LibHttpParserRoot="${GLOBAL_DIR_OBJS}/hp"
LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"

#Core Module
MODULE_ID="CORE"
MODULE_DEPENDS=()
ModuleLibIncs=(${LibSTRoot})
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot})
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"
"srs_core_auto_free" "srs_core_protocol" "srs_core_amf0"
"srs_core_autofree" "srs_core_protocol" "srs_core_amf0"
"srs_core_stream" "srs_core_source" "srs_core_codec"
"srs_core_complex_handshake" "srs_core_pithy_print"
"srs_core_handshake" "srs_core_pithy_print"
"srs_core_config" "srs_core_refer" "srs_core_reload")
MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"
Expand All @@ -107,7 +130,7 @@ MAIN_OBJS="${MODULE_OBJS[@].o}"
MAIN_ENTRANCES=("srs_main_server")

# srs(simple rtmp server) over st(state-threads)
ModuleLibFiles=(${LibSTfile})
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" SO_PATH="" . auto/apps.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define SRS_CORE_AUTO_FREE_HPP

/*
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
*/

#include <srs_core.hpp>
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_log.hpp>
#include <srs_core_rtmp.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_source.hpp>
#include <srs_core_server.hpp>
#include <srs_core_pithy_print.hpp>
Expand Down
34 changes: 33 additions & 1 deletion trunk/src/core/srs_core_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <srs_core_error.hpp>
#include <srs_core_log.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>

#define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR)

Expand Down Expand Up @@ -455,6 +455,18 @@ int SrsConfig::reload()
return ret;
}
}
srs_trace("reload listen success.");
}
// merge config: pithy_print
if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
SrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_pithy_print()) != ERROR_SUCCESS) {
srs_error("notify subscribes pithy_print listen failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload pithy_print success.");
}

return ret;
Expand Down Expand Up @@ -593,6 +605,26 @@ SrsConfDirective* SrsConfig::get_chunk_size()
return root->get("chunk_size");
}

SrsConfDirective* SrsConfig::get_pithy_print_publish()
{
SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) {
return NULL;
}

return pithy->get("publish");
}

SrsConfDirective* SrsConfig::get_pithy_print_play()
{
SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) {
return NULL;
}

return pithy->get("play");
}

int SrsConfig::parse_file(const char* filename)
{
int ret = ERROR_SUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/core/srs_core_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class SrsConfig
virtual SrsConfDirective* get_refer_publish(std::string vhost);
virtual SrsConfDirective* get_listen();
virtual SrsConfDirective* get_chunk_size();
virtual SrsConfDirective* get_pithy_print_publish();
virtual SrsConfDirective* get_pithy_print_play();
private:
virtual int parse_file(const char* filename);
virtual int parse_argv(int& i, char** argv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <srs_core_complex_handshake.hpp>
#include <srs_core_handshake.hpp>

#include <time.h>
#include <stdlib.h>

#include <srs_core_error.hpp>
#include <srs_core_log.hpp>
#include <srs_core_auto_free.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_socket.hpp>

// 68bytes FMS key which is used to sign the sever packet.
Expand Down Expand Up @@ -1058,6 +1058,72 @@ void c1s1::destroy_blocks()
}
}

SrsSimpleHandshake::SrsSimpleHandshake()
{
}

SrsSimpleHandshake::~SrsSimpleHandshake()
{
}

int SrsSimpleHandshake::handshake(SrsSocket& skt)
{
int ret = ERROR_SUCCESS;

ssize_t nsize;

char* c0c1 = new char[1537];
SrsAutoFree(char, c0c1, true);
if ((ret = skt.read_fully(c0c1, 1537, &nsize)) != ERROR_SUCCESS) {
srs_warn("read c0c1 failed. ret=%d", ret);
return ret;
}
srs_verbose("read c0c1 success.");

// plain text required.
if (c0c1[0] != 0x03) {
ret = ERROR_RTMP_PLAIN_REQUIRED;
srs_warn("only support rtmp plain text. ret=%d", ret);
return ret;
}
srs_verbose("check c0 success, required plain text.");

// try complex handshake
SrsComplexHandshake complex_handshake;
ret = complex_handshake.handshake(skt, c0c1 + 1);
if (ret == ERROR_SUCCESS) {
srs_trace("complex handshake success.");
return ret;
}
if (ret != ERROR_RTMP_TRY_SIMPLE_HS) {
srs_error("complex handshake failed. ret=%d", ret);
return ret;
}
srs_info("complex handhskae failed, try simple. ret=%d", ret);

char* s0s1s2 = new char[3073];
SrsAutoFree(char, s0s1s2, true);
// plain text required.
s0s1s2[0] = 0x03;
if ((ret = skt.write(s0s1s2, 3073, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake send s0s1s2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake send s0s1s2 success.");

char* c2 = new char[1536];
SrsAutoFree(char, c2, true);
if ((ret = skt.read_fully(c2, 1536, &nsize)) != ERROR_SUCCESS) {
srs_warn("simple handshake read c2 failed. ret=%d", ret);
return ret;
}
srs_verbose("simple handshake read c2 success.");

srs_trace("simple handshake success.");

return ret;
}

SrsComplexHandshake::SrsComplexHandshake()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef SRS_CORE_COMPLEX_HANDSHKAE_HPP
#define SRS_CORE_COMPLEX_HANDSHKAE_HPP
#ifndef SRS_CORE_HANDSHKAE_HPP
#define SRS_CORE_HANDSHKAE_HPP

/*
#include <srs_core_complex_handshake.hpp>
Expand All @@ -32,6 +32,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class SrsSocket;

/**
* try complex handshake, if failed, fallback to simple handshake.
*/
class SrsSimpleHandshake
{
public:
SrsSimpleHandshake();
virtual ~SrsSimpleHandshake();
public:
/**
* simple handshake.
*/
virtual int handshake(SrsSocket& skt);
};

/**
* rtmp complex handshake,
* @see also crtmp(crtmpserver) or librtmp,
Expand Down
Loading

0 comments on commit 3669419

Please sign in to comment.