diff --git a/README.md b/README.md index cab431fc9..f293c61f0 100755 --- a/README.md +++ b/README.md @@ -562,6 +562,7 @@ Supported operating systems and hardware: ### SRS 2.0 history +* v2.0, 2015-03-31, support server cycle handler. 2.0.153. * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152. * v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151. * v2.0, 2015-03-30, for [#351](https://github.com/winlinvip/simple-rtmp-server/issues/351), support config the m3u8/ts path for hls. 2.0.149. diff --git a/trunk/configure b/trunk/configure index 3169f954e..273fe6a53 100755 --- a/trunk/configure +++ b/trunk/configure @@ -61,15 +61,16 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M # where srs module is a dir which contains a config file. SRS_MODULES=() __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do - SRS_MODULES+="`dirname $__mfile`" + SRS_MODULES+=("`dirname $__mfile`") done # variables for makefile for all modules. __mphonys="" && __mdefaults="" && __mcleanups="" # add each modules for application -for SRS_MODULE in $SRS_MODULES; do +for SRS_MODULE in ${SRS_MODULES[*]}; do echo "install module at: $SRS_MODULE" . $SRS_MODULE/config + if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi __mphonys="$__mphonys $SRS_MODULE_NAME" __mdefaults="$__mdefaults $SRS_MODULE_NAME" __mcleanups="$__mcleanups $SRS_MODULE_NAME" @@ -177,9 +178,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call") DEFINES="" # add each modules for app - for SRS_MODULE in $SRS_MODULES; do + for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config - MODULE_FILES+=($SRS_MODULE_APP) + MODULE_FILES+=("${SRS_MODULE_APP[*]}") DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}" done APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh @@ -201,9 +202,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibHttpParserRoot}) MODULE_FILES=("srs_main_server") # add each modules for main - for SRS_MODULE in $SRS_MODULES; do + for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config - MODULE_FILES+=($SRS_MODULE_MAIN) + MODULE_FILES+=("${SRS_MODULE_MAIN[*]}") done MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh MAIN_OBJS="${MODULE_OBJS[@]}" @@ -218,9 +219,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then # all main entrances MAIN_ENTRANCES=("srs_main_server") # add each modules for main - for SRS_MODULE in $SRS_MODULES; do + for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config - MAIN_ENTRANCES+=($SRS_MODULE_MAIN) + MAIN_ENTRANCES+=("${SRS_MODULE_MAIN[*]}") done # # all depends libraries @@ -232,8 +233,10 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then # srs: srs(simple rtmp server) over st(state-threads) BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh # add each modules for application - for SRS_MODULE in $SRS_MODULES; do + for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config + # no SRS_MODULE_MAIN + if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="$SRS_MODULE_MAIN" APP_NAME="$SRS_MODULE_NAME" . auto/apps.sh done fi @@ -340,7 +343,7 @@ server: _prepare_dir END fi # generate all modules entry -for SRS_MODULE in $SRS_MODULES; do +for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config # if export librtmp, donot build the bravo-ingest. if [ $SRS_EXPORT_LIBRTMP_PROJECT != NO ]; then @@ -596,7 +599,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then echo -e "${GREEN}note: mips-ubuntu12 for srs are not builded${BLACK}" fi # add each modules for application - for SRS_MODULE in $SRS_MODULES; do + for SRS_MODULE in ${SRS_MODULES[*]}; do echo -e "${GREEN}module: $SRS_MODULE${BLACK}" done fi diff --git a/trunk/src/app/srs_app_json.cpp b/trunk/src/app/srs_app_json.cpp index cd1b9aaa8..76a1341c3 100644 --- a/trunk/src/app/srs_app_json.cpp +++ b/trunk/src/app/srs_app_json.cpp @@ -457,6 +457,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_string(string name) return prop; } +SrsJsonAny* SrsJsonObject::ensure_property_integer(string name) +{ + SrsJsonAny* prop = get_property(name); + + if (!prop) { + return NULL; + } + + if (!prop->is_integer()) { + return NULL; + } + + return prop; +} + SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name) { SrsJsonAny* prop = get_property(name); diff --git a/trunk/src/app/srs_app_json.hpp b/trunk/src/app/srs_app_json.hpp index bc36a7935..d94f86daa 100644 --- a/trunk/src/app/srs_app_json.hpp +++ b/trunk/src/app/srs_app_json.hpp @@ -149,6 +149,7 @@ public: virtual void set(std::string key, SrsJsonAny* value); virtual SrsJsonAny* get_property(std::string name); virtual SrsJsonAny* ensure_property_string(std::string name); + virtual SrsJsonAny* ensure_property_integer(std::string name); virtual SrsJsonAny* ensure_property_boolean(std::string name); }; diff --git a/trunk/src/app/srs_app_reload.cpp b/trunk/src/app/srs_app_reload.cpp index 85d368bfc..cd43faaeb 100644 --- a/trunk/src/app/srs_app_reload.cpp +++ b/trunk/src/app/srs_app_reload.cpp @@ -190,4 +190,8 @@ int ISrsReloadHandler::on_reload_ingest_updated(string /*vhost*/, string /*inges return ERROR_SUCCESS; } +int ISrsReloadHandler::on_reload_user_info() +{ + return ERROR_SUCCESS; +} diff --git a/trunk/src/app/srs_app_reload.hpp b/trunk/src/app/srs_app_reload.hpp index 39e3b6538..01068a7ca 100644 --- a/trunk/src/app/srs_app_reload.hpp +++ b/trunk/src/app/srs_app_reload.hpp @@ -75,6 +75,7 @@ public: virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id); virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id); virtual int on_reload_ingest_updated(std::string vhost, std::string ingest_id); + virtual int on_reload_user_info(); }; #endif diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index a8bef6452..84cc1b350 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -389,6 +389,14 @@ void SrsSignalManager::sig_catcher(int signo) errno = err; } +ISrsServerCycle::ISrsServerCycle() +{ +} + +ISrsServerCycle::~ISrsServerCycle() +{ +} + SrsServer::SrsServer() { signal_reload = false; @@ -397,6 +405,8 @@ SrsServer::SrsServer() signal_manager = NULL; + handler = NULL; + // donot new object in constructor, // for some global instance is not ready now, // new these objects in initialize instead. @@ -456,6 +466,8 @@ void SrsServer::destroy() srs_freep(signal_manager); + srs_freep(handler); + // @remark never destroy the connections, // for it's still alive. @@ -464,7 +476,7 @@ void SrsServer::destroy() // and segment fault. } -int SrsServer::initialize() +int SrsServer::initialize(ISrsServerCycle* cycle_handler) { int ret = ERROR_SUCCESS; @@ -480,6 +492,11 @@ int SrsServer::initialize() srs_assert(!signal_manager); signal_manager = new SrsSignalManager(this); + handler = cycle_handler; + if(handler && (ret = handler->initialize()) != ERROR_SUCCESS){ + return ret; + } + #ifdef SRS_AUTO_HTTP_API if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) { return ret; @@ -795,6 +812,11 @@ int SrsServer::do_cycle() // the deamon thread, update the time cache while (true) { + if(handler && (ret = handler->on_cycle(conns.size())) != ERROR_SUCCESS){ + srs_error("cycle handle failed. ret=%d", ret); + return ret; + } + // the interval in config. int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index f6279e608..45857b714 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -170,6 +170,25 @@ private: static void sig_catcher(int signo); }; +/** +* the handler to the handle cycle in SRS RTMP server. +*/ +class ISrsServerCycle +{ +public: + ISrsServerCycle(); + virtual ~ISrsServerCycle(); +public: + /** + * initialize the cycle handler. + */ + virtual int initialize() = 0; + /** + * do on_cycle while server doing cycle. + */ + virtual int on_cycle(int connections) = 0; +}; + /** * SRS RTMP server, initialize and listen, * start connection service thread, destroy client. @@ -211,6 +230,10 @@ private: */ SrsSignalManager* signal_manager; /** + * handle in server cycle. + */ + ISrsServerCycle* handler; + /** * user send the signal, convert to variable. */ bool signal_reload; @@ -227,7 +250,7 @@ public: virtual void destroy(); // server startup workflow, @see run_master() public: - virtual int initialize(); + virtual int initialize(ISrsServerCycle* cycle_handler); virtual int initialize_signal(); virtual int acquire_pid_file(); virtual int initialize_st(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index b79c0bc2f..fd3c06908 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 152 +#define VERSION_REVISION 153 // server info. #define RTMP_SIG_SRS_KEY "SRS" diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 2d49cc096..44f66bd57 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -288,7 +288,7 @@ int main(int argc, char** argv) * and use initialize to create members, set hooks for instance the reload handler, * all initialize will done in this stage. */ - if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { + if ((ret = _srs_server->initialize(NULL)) != ERROR_SUCCESS) { return ret; }