winlin

support server cycle handler. 2.0.153.

@@ -562,6 +562,7 @@ Supported operating systems and hardware: @@ -562,6 +562,7 @@ Supported operating systems and hardware:
562 562
563 ### SRS 2.0 history 563 ### SRS 2.0 history
564 564
  565 +* v2.0, 2015-03-31, support server cycle handler. 2.0.153.
565 * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152. 566 * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152.
566 * v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151. 567 * v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151.
567 * 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. 568 * 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.
@@ -61,15 +61,16 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M @@ -61,15 +61,16 @@ if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/utest; \$(M
61 # where srs module is a dir which contains a config file. 61 # where srs module is a dir which contains a config file.
62 SRS_MODULES=() 62 SRS_MODULES=()
63 __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do 63 __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do
64 - SRS_MODULES+="`dirname $__mfile`" 64 + SRS_MODULES+=("`dirname $__mfile`")
65 done 65 done
66 66
67 # variables for makefile for all modules. 67 # variables for makefile for all modules.
68 __mphonys="" && __mdefaults="" && __mcleanups="" 68 __mphonys="" && __mdefaults="" && __mcleanups=""
69 # add each modules for application 69 # add each modules for application
70 -for SRS_MODULE in $SRS_MODULES; do 70 +for SRS_MODULE in ${SRS_MODULES[*]}; do
71 echo "install module at: $SRS_MODULE" 71 echo "install module at: $SRS_MODULE"
72 . $SRS_MODULE/config 72 . $SRS_MODULE/config
  73 + if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi
73 __mphonys="$__mphonys $SRS_MODULE_NAME" 74 __mphonys="$__mphonys $SRS_MODULE_NAME"
74 __mdefaults="$__mdefaults $SRS_MODULE_NAME" 75 __mdefaults="$__mdefaults $SRS_MODULE_NAME"
75 __mcleanups="$__mcleanups $SRS_MODULE_NAME" 76 __mcleanups="$__mcleanups $SRS_MODULE_NAME"
@@ -177,9 +178,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -177,9 +178,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
177 "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call") 178 "srs_app_mpegts_udp" "srs_app_rtsp" "srs_app_listener" "srs_app_async_call")
178 DEFINES="" 179 DEFINES=""
179 # add each modules for app 180 # add each modules for app
180 - for SRS_MODULE in $SRS_MODULES; do 181 + for SRS_MODULE in ${SRS_MODULES[*]}; do
181 . $SRS_MODULE/config 182 . $SRS_MODULE/config
182 - MODULE_FILES+=($SRS_MODULE_APP) 183 + MODULE_FILES+=("${SRS_MODULE_APP[*]}")
183 DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}" 184 DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}"
184 done 185 done
185 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 186 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
@@ -201,9 +202,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -201,9 +202,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
201 ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibHttpParserRoot}) 202 ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibHttpParserRoot})
202 MODULE_FILES=("srs_main_server") 203 MODULE_FILES=("srs_main_server")
203 # add each modules for main 204 # add each modules for main
204 - for SRS_MODULE in $SRS_MODULES; do 205 + for SRS_MODULE in ${SRS_MODULES[*]}; do
205 . $SRS_MODULE/config 206 . $SRS_MODULE/config
206 - MODULE_FILES+=($SRS_MODULE_MAIN) 207 + MODULE_FILES+=("${SRS_MODULE_MAIN[*]}")
207 done 208 done
208 MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh 209 MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
209 MAIN_OBJS="${MODULE_OBJS[@]}" 210 MAIN_OBJS="${MODULE_OBJS[@]}"
@@ -218,9 +219,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -218,9 +219,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
218 # all main entrances 219 # all main entrances
219 MAIN_ENTRANCES=("srs_main_server") 220 MAIN_ENTRANCES=("srs_main_server")
220 # add each modules for main 221 # add each modules for main
221 - for SRS_MODULE in $SRS_MODULES; do 222 + for SRS_MODULE in ${SRS_MODULES[*]}; do
222 . $SRS_MODULE/config 223 . $SRS_MODULE/config
223 - MAIN_ENTRANCES+=($SRS_MODULE_MAIN) 224 + MAIN_ENTRANCES+=("${SRS_MODULE_MAIN[*]}")
224 done 225 done
225 # 226 #
226 # all depends libraries 227 # all depends libraries
@@ -232,8 +233,10 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -232,8 +233,10 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
232 # srs: srs(simple rtmp server) over st(state-threads) 233 # srs: srs(simple rtmp server) over st(state-threads)
233 BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh 234 BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh
234 # add each modules for application 235 # add each modules for application
235 - for SRS_MODULE in $SRS_MODULES; do 236 + for SRS_MODULE in ${SRS_MODULES[*]}; do
236 . $SRS_MODULE/config 237 . $SRS_MODULE/config
  238 + # no SRS_MODULE_MAIN
  239 + if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi
237 BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="$SRS_MODULE_MAIN" APP_NAME="$SRS_MODULE_NAME" . auto/apps.sh 240 BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="$SRS_MODULE_MAIN" APP_NAME="$SRS_MODULE_NAME" . auto/apps.sh
238 done 241 done
239 fi 242 fi
@@ -340,7 +343,7 @@ server: _prepare_dir @@ -340,7 +343,7 @@ server: _prepare_dir
340 END 343 END
341 fi 344 fi
342 # generate all modules entry 345 # generate all modules entry
343 -for SRS_MODULE in $SRS_MODULES; do 346 +for SRS_MODULE in ${SRS_MODULES[*]}; do
344 . $SRS_MODULE/config 347 . $SRS_MODULE/config
345 # if export librtmp, donot build the bravo-ingest. 348 # if export librtmp, donot build the bravo-ingest.
346 if [ $SRS_EXPORT_LIBRTMP_PROJECT != NO ]; then 349 if [ $SRS_EXPORT_LIBRTMP_PROJECT != NO ]; then
@@ -596,7 +599,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -596,7 +599,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
596 echo -e "${GREEN}note: mips-ubuntu12 for srs are not builded${BLACK}" 599 echo -e "${GREEN}note: mips-ubuntu12 for srs are not builded${BLACK}"
597 fi 600 fi
598 # add each modules for application 601 # add each modules for application
599 - for SRS_MODULE in $SRS_MODULES; do 602 + for SRS_MODULE in ${SRS_MODULES[*]}; do
600 echo -e "${GREEN}module: $SRS_MODULE${BLACK}" 603 echo -e "${GREEN}module: $SRS_MODULE${BLACK}"
601 done 604 done
602 fi 605 fi
@@ -457,6 +457,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_string(string name) @@ -457,6 +457,21 @@ SrsJsonAny* SrsJsonObject::ensure_property_string(string name)
457 return prop; 457 return prop;
458 } 458 }
459 459
  460 +SrsJsonAny* SrsJsonObject::ensure_property_integer(string name)
  461 +{
  462 + SrsJsonAny* prop = get_property(name);
  463 +
  464 + if (!prop) {
  465 + return NULL;
  466 + }
  467 +
  468 + if (!prop->is_integer()) {
  469 + return NULL;
  470 + }
  471 +
  472 + return prop;
  473 +}
  474 +
460 SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name) 475 SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name)
461 { 476 {
462 SrsJsonAny* prop = get_property(name); 477 SrsJsonAny* prop = get_property(name);
@@ -149,6 +149,7 @@ public: @@ -149,6 +149,7 @@ public:
149 virtual void set(std::string key, SrsJsonAny* value); 149 virtual void set(std::string key, SrsJsonAny* value);
150 virtual SrsJsonAny* get_property(std::string name); 150 virtual SrsJsonAny* get_property(std::string name);
151 virtual SrsJsonAny* ensure_property_string(std::string name); 151 virtual SrsJsonAny* ensure_property_string(std::string name);
  152 + virtual SrsJsonAny* ensure_property_integer(std::string name);
152 virtual SrsJsonAny* ensure_property_boolean(std::string name); 153 virtual SrsJsonAny* ensure_property_boolean(std::string name);
153 }; 154 };
154 155
@@ -190,4 +190,8 @@ int ISrsReloadHandler::on_reload_ingest_updated(string /*vhost*/, string /*inges @@ -190,4 +190,8 @@ int ISrsReloadHandler::on_reload_ingest_updated(string /*vhost*/, string /*inges
190 return ERROR_SUCCESS; 190 return ERROR_SUCCESS;
191 } 191 }
192 192
  193 +int ISrsReloadHandler::on_reload_user_info()
  194 +{
  195 + return ERROR_SUCCESS;
  196 +}
193 197
@@ -75,6 +75,7 @@ public: @@ -75,6 +75,7 @@ public:
75 virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id); 75 virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);
76 virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id); 76 virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id);
77 virtual int on_reload_ingest_updated(std::string vhost, std::string ingest_id); 77 virtual int on_reload_ingest_updated(std::string vhost, std::string ingest_id);
  78 + virtual int on_reload_user_info();
78 }; 79 };
79 80
80 #endif 81 #endif
@@ -389,6 +389,14 @@ void SrsSignalManager::sig_catcher(int signo) @@ -389,6 +389,14 @@ void SrsSignalManager::sig_catcher(int signo)
389 errno = err; 389 errno = err;
390 } 390 }
391 391
  392 +ISrsServerCycle::ISrsServerCycle()
  393 +{
  394 +}
  395 +
  396 +ISrsServerCycle::~ISrsServerCycle()
  397 +{
  398 +}
  399 +
392 SrsServer::SrsServer() 400 SrsServer::SrsServer()
393 { 401 {
394 signal_reload = false; 402 signal_reload = false;
@@ -397,6 +405,8 @@ SrsServer::SrsServer() @@ -397,6 +405,8 @@ SrsServer::SrsServer()
397 405
398 signal_manager = NULL; 406 signal_manager = NULL;
399 407
  408 + handler = NULL;
  409 +
400 // donot new object in constructor, 410 // donot new object in constructor,
401 // for some global instance is not ready now, 411 // for some global instance is not ready now,
402 // new these objects in initialize instead. 412 // new these objects in initialize instead.
@@ -456,6 +466,8 @@ void SrsServer::destroy() @@ -456,6 +466,8 @@ void SrsServer::destroy()
456 466
457 srs_freep(signal_manager); 467 srs_freep(signal_manager);
458 468
  469 + srs_freep(handler);
  470 +
459 // @remark never destroy the connections, 471 // @remark never destroy the connections,
460 // for it's still alive. 472 // for it's still alive.
461 473
@@ -464,7 +476,7 @@ void SrsServer::destroy() @@ -464,7 +476,7 @@ void SrsServer::destroy()
464 // and segment fault. 476 // and segment fault.
465 } 477 }
466 478
467 -int SrsServer::initialize() 479 +int SrsServer::initialize(ISrsServerCycle* cycle_handler)
468 { 480 {
469 int ret = ERROR_SUCCESS; 481 int ret = ERROR_SUCCESS;
470 482
@@ -480,6 +492,11 @@ int SrsServer::initialize() @@ -480,6 +492,11 @@ int SrsServer::initialize()
480 srs_assert(!signal_manager); 492 srs_assert(!signal_manager);
481 signal_manager = new SrsSignalManager(this); 493 signal_manager = new SrsSignalManager(this);
482 494
  495 + handler = cycle_handler;
  496 + if(handler && (ret = handler->initialize()) != ERROR_SUCCESS){
  497 + return ret;
  498 + }
  499 +
483 #ifdef SRS_AUTO_HTTP_API 500 #ifdef SRS_AUTO_HTTP_API
484 if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) { 501 if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) {
485 return ret; 502 return ret;
@@ -795,6 +812,11 @@ int SrsServer::do_cycle() @@ -795,6 +812,11 @@ int SrsServer::do_cycle()
795 812
796 // the deamon thread, update the time cache 813 // the deamon thread, update the time cache
797 while (true) { 814 while (true) {
  815 + if(handler && (ret = handler->on_cycle(conns.size())) != ERROR_SUCCESS){
  816 + srs_error("cycle handle failed. ret=%d", ret);
  817 + return ret;
  818 + }
  819 +
798 // the interval in config. 820 // the interval in config.
799 int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); 821 int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL);
800 822
@@ -171,6 +171,25 @@ private: @@ -171,6 +171,25 @@ private:
171 }; 171 };
172 172
173 /** 173 /**
  174 +* the handler to the handle cycle in SRS RTMP server.
  175 +*/
  176 +class ISrsServerCycle
  177 +{
  178 +public:
  179 + ISrsServerCycle();
  180 + virtual ~ISrsServerCycle();
  181 +public:
  182 + /**
  183 + * initialize the cycle handler.
  184 + */
  185 + virtual int initialize() = 0;
  186 + /**
  187 + * do on_cycle while server doing cycle.
  188 + */
  189 + virtual int on_cycle(int connections) = 0;
  190 +};
  191 +
  192 +/**
174 * SRS RTMP server, initialize and listen, 193 * SRS RTMP server, initialize and listen,
175 * start connection service thread, destroy client. 194 * start connection service thread, destroy client.
176 */ 195 */
@@ -211,6 +230,10 @@ private: @@ -211,6 +230,10 @@ private:
211 */ 230 */
212 SrsSignalManager* signal_manager; 231 SrsSignalManager* signal_manager;
213 /** 232 /**
  233 + * handle in server cycle.
  234 + */
  235 + ISrsServerCycle* handler;
  236 + /**
214 * user send the signal, convert to variable. 237 * user send the signal, convert to variable.
215 */ 238 */
216 bool signal_reload; 239 bool signal_reload;
@@ -227,7 +250,7 @@ public: @@ -227,7 +250,7 @@ public:
227 virtual void destroy(); 250 virtual void destroy();
228 // server startup workflow, @see run_master() 251 // server startup workflow, @see run_master()
229 public: 252 public:
230 - virtual int initialize(); 253 + virtual int initialize(ISrsServerCycle* cycle_handler);
231 virtual int initialize_signal(); 254 virtual int initialize_signal();
232 virtual int acquire_pid_file(); 255 virtual int acquire_pid_file();
233 virtual int initialize_st(); 256 virtual int initialize_st();
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 152 34 +#define VERSION_REVISION 153
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -288,7 +288,7 @@ int main(int argc, char** argv) @@ -288,7 +288,7 @@ int main(int argc, char** argv)
288 * and use initialize to create members, set hooks for instance the reload handler, 288 * and use initialize to create members, set hooks for instance the reload handler,
289 * all initialize will done in this stage. 289 * all initialize will done in this stage.
290 */ 290 */
291 - if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { 291 + if ((ret = _srs_server->initialize(NULL)) != ERROR_SUCCESS) {
292 return ret; 292 return ret;
293 } 293 }
294 294