From f187a7deef4a885a2e5fec58352d84188a4cc895 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 24 Sep 2015 12:15:12 +0800 Subject: [PATCH] refine the startup logs. --- trunk/auto/auto_headers.sh | 147 +++++++----- trunk/src/app/srs_app_kafka.cpp | 19 +- trunk/src/app/srs_app_kafka.hpp | 2 + trunk/src/app/srs_app_server.cpp | 3 +- trunk/src/app/srs_app_st.cpp | 2 +- trunk/src/app/srs_app_utility.cpp | 21 +- trunk/src/app/srs_app_utility.hpp | 5 + trunk/src/main/srs_main_server.cpp | 312 ++++++++++++------------- trunk/src/protocol/srs_protocol_io.hpp | 2 +- trunk/src/utest/srs_utest_core.cpp | 3 - 10 files changed, 273 insertions(+), 243 deletions(-) mode change 100644 => 100755 trunk/auto/auto_headers.sh diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh old mode 100644 new mode 100755 index 3c7b5b7af..7297cb33f --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -18,24 +18,45 @@ echo "#define SRS_AUTO_USER_CONFIGURE \"${SRS_AUTO_USER_CONFIGURE}\"" >> $SRS_AU echo "#define SRS_AUTO_CONFIGURE \"${SRS_AUTO_CONFIGURE}\"" >> $SRS_AUTO_HEADERS_H echo "" >> $SRS_AUTO_HEADERS_H +function srs_define_macro() +{ + macro=$1 && file=$2 + echo "#define $macro" >> $file + echo "#define ${macro}_BOOL true" >> $file +} + +function srs_define_macro_value() +{ + macro=$1 && value=$2 && file=$3 + echo "#define $macro $value" >> $file + echo "#define ${macro}_BOOL true" >> $file +} + +function srs_undefine_macro() +{ + macro=$1 && file=$2 + echo "#undef $macro" >> $file + echo "#define ${macro}_BOOL false" >> $file +} + # export the preset. if [ $SRS_OSX = YES ]; then - echo "#define SRS_OSX" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_OSX" $SRS_AUTO_HEADERS_H fi if [ $SRS_X86_X64 = YES ]; then - echo "#define SRS_X86_X64" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_X86_X64" $SRS_AUTO_HEADERS_H fi if [ $SRS_ARM_UBUNTU12 = YES ]; then - echo "#define SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_ARM_UBUNTU12" $SRS_AUTO_HEADERS_H fi if [ $SRS_MIPS_UBUNTU12 = YES ]; then - echo "#define SRS_MIPS_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_MIPS_UBUNTU12" $SRS_AUTO_HEADERS_H fi if [ $SRS_PI = YES ]; then - echo "#define SRS_PI" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_PI" $SRS_AUTO_HEADERS_H fi if [ $SRS_CUBIE = YES ]; then - echo "#define SRS_CUBIE" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_CUBIE" $SRS_AUTO_HEADERS_H fi echo "" >> $SRS_AUTO_HEADERS_H @@ -45,180 +66,180 @@ echo "" >> $SRS_AUTO_HEADERS_H ##################################################################################### # write to source file if [ $SRS_CROSS_BUILD = YES ]; then - echo "cc=$SrsArmCC gcc=$SrsArmGCC g++=$SrsArmCXX ar=$SrsArmAR ld=$SrsArmLD randlib=$SrsArmRANDLIB" - echo "#define SRS_AUTO_EMBEDED_TOOL_CHAIN \"cc=$SrsArmCC gcc=$SrsArmGCC g++=$SrsArmCXX ar=$SrsArmAR ld=$SrsArmLD randlib=$SrsArmRANDLIB\"" >> $SRS_AUTO_HEADERS_H + __TOOL_CHAIN="cc=$SrsArmCC gcc=$SrsArmGCC g++=$SrsArmCXX ar=$SrsArmAR ld=$SrsArmLD randlib=$SrsArmRANDLIB" && echo "$__TOOL_CHAIN" + srs_define_macro_value "SRS_AUTO_EMBEDED_TOOL_CHAIN" "\"$__TOOL_CHAIN\"" $SRS_AUTO_HEADERS_H else - echo "#define SRS_AUTO_EMBEDED_TOOL_CHAIN \"normal x86/x64 gcc\"" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_EMBEDED_TOOL_CHAIN" $SRS_AUTO_HEADERS_H fi echo "" >> $SRS_AUTO_HEADERS_H # auto headers in depends. if [ $SRS_HTTP_CORE = YES ]; then - echo "#define SRS_AUTO_HTTP_CORE" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HTTP_CORE" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HTTP_CORE" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HTTP_CORE" $SRS_AUTO_HEADERS_H fi if [ $SRS_HTTP_SERVER = YES ]; then - echo "#define SRS_AUTO_HTTP_SERVER" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HTTP_SERVER" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HTTP_SERVER" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HTTP_SERVER" $SRS_AUTO_HEADERS_H fi if [ $SRS_STREAM_CASTER = YES ]; then - echo "#define SRS_AUTO_STREAM_CASTER" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_STREAM_CASTER" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_STREAM_CASTER" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_STREAM_CASTER" $SRS_AUTO_HEADERS_H fi if [ $SRS_KAFKA = YES ]; then - echo "#define SRS_AUTO_KAFKA" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_KAFKA" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_KAFKA" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_KAFKA" $SRS_AUTO_HEADERS_H fi if [ $SRS_HTTP_API = YES ]; then - echo "#define SRS_AUTO_HTTP_API" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HTTP_API" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HTTP_API" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HTTP_API" $SRS_AUTO_HEADERS_H fi if [ $SRS_NGINX = YES ]; then - echo "#define SRS_AUTO_NGINX" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_NGINX" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_NGINX" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_NGINX" $SRS_AUTO_HEADERS_H fi if [ $SRS_DVR = YES ]; then - echo "#define SRS_AUTO_DVR" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_DVR" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_DVR" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_DVR" $SRS_AUTO_HEADERS_H fi if [ $SRS_HLS = YES ]; then - echo "#define SRS_AUTO_HLS" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HLS" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HLS" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HLS" $SRS_AUTO_HEADERS_H fi if [ $SRS_HDS = YES ]; then - echo "#define SRS_AUTO_HDS" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HDS" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HDS" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HDS" $SRS_AUTO_HEADERS_H fi if [ $SRS_HTTP_CALLBACK = YES ]; then - echo "#define SRS_AUTO_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_HTTP_CALLBACK" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_HTTP_CALLBACK" $SRS_AUTO_HEADERS_H fi if [ $SRS_SSL = YES ]; then - echo "#define SRS_AUTO_SSL" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_SSL" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_SSL" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_SSL" $SRS_AUTO_HEADERS_H fi if [ $SRS_MEM_WATCH = YES ]; then - echo "#define SRS_AUTO_MEM_WATCH" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_MEM_WATCH" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_MEM_WATCH" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_MEM_WATCH" $SRS_AUTO_HEADERS_H fi # whether compile ffmpeg tool if [ $SRS_FFMPEG_TOOL = YES ]; then - echo "#define SRS_AUTO_FFMPEG_TOOL" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_FFMPEG_TOOL" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_FFMPEG_TOOL" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_FFMPEG_TOOL" $SRS_AUTO_HEADERS_H fi # whatever the FFMPEG tools, if transcode and ingest specified, # srs always compile the FFMPEG tool stub which used to start the FFMPEG process. if [ $SRS_FFMPEG_STUB = YES ]; then - echo "#define SRS_AUTO_FFMPEG_STUB" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_FFMPEG_STUB" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_FFMPEG_STUB" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_FFMPEG_STUB" $SRS_AUTO_HEADERS_H fi if [ $SRS_TRANSCODE = YES ]; then - echo "#define SRS_AUTO_TRANSCODE" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_TRANSCODE" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_TRANSCODE" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_TRANSCODE" $SRS_AUTO_HEADERS_H fi if [ $SRS_INGEST = YES ]; then - echo "#define SRS_AUTO_INGEST" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_INGEST" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_INGEST" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_INGEST" $SRS_AUTO_HEADERS_H fi # for statistic. if [ $SRS_STAT = YES ]; then - echo "#define SRS_AUTO_STAT" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_STAT" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_STAT" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_STAT" $SRS_AUTO_HEADERS_H fi if [ $SRS_GPERF = YES ]; then - echo "#define SRS_AUTO_GPERF" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_GPERF" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_GPERF" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_GPERF" $SRS_AUTO_HEADERS_H fi if [ $SRS_GPERF_MC = YES ]; then - echo "#define SRS_AUTO_GPERF_MC" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_GPERF_MC" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_GPERF_MC" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_GPERF_MC" $SRS_AUTO_HEADERS_H fi if [ $SRS_GPERF_MP = YES ]; then - echo "#define SRS_AUTO_GPERF_MP" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_GPERF_MP" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_GPERF_MP" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_GPERF_MP" $SRS_AUTO_HEADERS_H fi if [ $SRS_GPERF_CP = YES ]; then - echo "#define SRS_AUTO_GPERF_CP" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_GPERF_CP" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_GPERF_CP" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_GPERF_CP" $SRS_AUTO_HEADERS_H fi ##################################################################################### # for embeded. ##################################################################################### if [ $SRS_CROSS_BUILD = YES ]; then - echo "#define SRS_AUTO_EMBEDED_CPU" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_EMBEDED_CPU" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_EMBEDED_CPU" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_EMBEDED_CPU" $SRS_AUTO_HEADERS_H fi # arm if [ $SRS_ARM_UBUNTU12 = YES ]; then - echo "#define SRS_AUTO_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_ARM_UBUNTU12" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_ARM_UBUNTU12" $SRS_AUTO_HEADERS_H fi # mips if [ $SRS_MIPS_UBUNTU12 = YES ]; then - echo "#define SRS_AUTO_MIPS_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_MIPS_UBUNTU12" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_MIPS_UBUNTU12" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_MIPS_UBUNTU12" $SRS_AUTO_HEADERS_H fi echo "" >> $SRS_AUTO_HEADERS_H # for log level compile settings if [ $SRS_LOG_VERBOSE = YES ]; then - echo "#define SRS_AUTO_VERBOSE" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_VERBOSE" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_VERBOSE" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_VERBOSE" $SRS_AUTO_HEADERS_H fi if [ $SRS_LOG_INFO = YES ]; then - echo "#define SRS_AUTO_INFO" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_INFO" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_INFO" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_INFO" $SRS_AUTO_HEADERS_H fi if [ $SRS_LOG_TRACE = YES ]; then - echo "#define SRS_AUTO_TRACE" >> $SRS_AUTO_HEADERS_H + srs_define_macro "SRS_AUTO_TRACE" $SRS_AUTO_HEADERS_H else - echo "#undef SRS_AUTO_TRACE" >> $SRS_AUTO_HEADERS_H + srs_undefine_macro "SRS_AUTO_TRACE" $SRS_AUTO_HEADERS_H fi # prefix diff --git a/trunk/src/app/srs_app_kafka.cpp b/trunk/src/app/srs_app_kafka.cpp index f94f1ef88..0dbcb556a 100644 --- a/trunk/src/app/srs_app_kafka.cpp +++ b/trunk/src/app/srs_app_kafka.cpp @@ -44,7 +44,13 @@ int SrsKafkaProducer::initialize() { int ret = ERROR_SUCCESS; - srs_trace("initialize kafka producer ok."); + // when kafka enabled, request metadata when startup. + if (_srs_config->get_kafka_enabled() && (ret = request_metadata()) != ERROR_SUCCESS) { + srs_error("request kafka metadata failed. ret=%d", ret); + return ret; + } + + srs_info("initialize kafka producer ok."); return ret; } @@ -58,7 +64,7 @@ int SrsKafkaProducer::start() return ret; } - srs_trace("start kafka async worker ok."); + srs_trace("kafka worker ok, enabled:%d", _srs_config->get_kafka_enabled()); return ret; } @@ -68,5 +74,14 @@ void SrsKafkaProducer::stop() worker->stop(); } +int SrsKafkaProducer::request_metadata() +{ + int ret = ERROR_SUCCESS; + + srs_info("update kafka metadata ok"); + + return ret; +} + #endif diff --git a/trunk/src/app/srs_app_kafka.hpp b/trunk/src/app/srs_app_kafka.hpp index 1fccf879a..946b8e4a6 100644 --- a/trunk/src/app/srs_app_kafka.hpp +++ b/trunk/src/app/srs_app_kafka.hpp @@ -47,6 +47,8 @@ public: virtual int initialize(); virtual int start(); virtual void stop(); +private: + virtual int request_metadata(); }; #endif diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index f6b48278e..c4af37664 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -440,7 +440,8 @@ int SrsSignalManager::start() sa.sa_flags = 0; sigaction(SRS_SIGNAL_PERSISTENCE_CONFIG, &sa, NULL); - srs_trace("signal installed"); + srs_trace("signal installed, reload=%d, dispose=%d, persistence=%d, grace_quit=%d", + SRS_SIGNAL_RELOAD, SRS_SIGNAL_DISPOSE, SRS_SIGNAL_PERSISTENCE_CONFIG, SRS_SIGNAL_GRACEFULLY_QUIT); return pthread->start(); } diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 949b46661..810eccdb5 100644 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -443,7 +443,7 @@ int srs_st_init() srs_error("st_set_eventsys use %s failed. ret=%d", st_get_eventsys_name(), ret); return ret; } - srs_trace("st_set_eventsys to %s", st_get_eventsys_name()); + srs_info("st_set_eventsys to %s", st_get_eventsys_name()); if(st_init() != 0){ ret = ERROR_ST_INITIALIZE; diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index e88aee644..e06d83b30 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -230,6 +230,10 @@ void srs_parse_endpoint(string ip_port, string& ip, int& port) port = ::atoi(the_port.c_str()); } +string srs_bool2switch(bool v) { + return v? "on" : "off"; +} + int srs_kill_forced(int& pid) { int ret = ERROR_SUCCESS; @@ -490,7 +494,7 @@ void srs_update_proc_stat() static int user_hz = 0; if (user_hz <= 0) { user_hz = (int)sysconf(_SC_CLK_TCK); - srs_trace("USER_HZ=%d", user_hz); + srs_info("USER_HZ=%d", user_hz); srs_assert(user_hz > 0); } @@ -1234,6 +1238,12 @@ void retrieve_local_ipv4_ips() return; } + stringstream ss0; + ss0 << "ips"; + + stringstream ss1; + ss1 << "devices"; + ifaddrs* p = ifap; while (p != NULL) { ifaddrs* cur = p; @@ -1257,20 +1267,23 @@ void retrieve_local_ipv4_ips() std::string ip = buf; if (ip != SRS_CONSTS_LOCALHOST) { - srs_trace("retrieve local ipv4 ip=%s, index=%d", ip.c_str(), (int)ips.size()); + ss0 << ", local[" << (int)ips.size() << "] ipv4 " << ip; ips.push_back(ip); } // set the device internet status. if (!srs_net_device_is_internet(inaddr->s_addr)) { - srs_trace("detect intranet address: %s, ifname=%s", ip.c_str(), cur->ifa_name); + ss1 << ", intranet "; _srs_device_ifs[cur->ifa_name] = false; } else { - srs_trace("detect internet address: %s, ifname=%s", ip.c_str(), cur->ifa_name); + ss1 << ", internet "; _srs_device_ifs[cur->ifa_name] = true; } + ss1 << cur->ifa_name << " " << ip; } } + srs_trace(ss0.str().c_str()); + srs_trace(ss1.str().c_str()); freeifaddrs(ifap); } diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 6e7c88ef3..76338ed79 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -82,6 +82,11 @@ extern std::string srs_path_build_timestamp(std::string template_path); extern void srs_parse_endpoint(std::string ip_port, std::string& ip, std::string& port); extern void srs_parse_endpoint(std::string ip_port, std::string& ip, int& port); +/** + * convert bool to switch value, true to "on", false to "off". + */ +extern std::string srs_bool2switch(bool v); + /** * kill the pid by SIGINT, then wait to quit, * kill the pid by SIGKILL again when exceed the timeout. diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 7d20ec2a1..71c090ef9 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -27,6 +27,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include +using namespace std; + #ifdef SRS_AUTO_GPERF_MP #include #endif @@ -40,6 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include // pre-declare int run(); @@ -60,185 +64,161 @@ SrsServer* _srs_server = new SrsServer(); */ void show_macro_features() { -#ifdef SRS_AUTO_SSL - srs_trace("check feature rtmp handshake: on"); -#else - srs_warn("check feature rtmp handshake: off"); -#endif - -#ifdef SRS_AUTO_HLS - srs_trace("check feature hls: on"); -#else - srs_warn("check feature hls: off"); -#endif - -#ifdef SRS_AUTO_HDS - srs_trace("check feature hds: on"); -#else - srs_warn("check feature hds: off"); -#endif - -#ifdef SRS_AUTO_HTTP_CALLBACK - srs_trace("check feature http callback: on"); -#else - srs_warn("check feature http callback: off"); -#endif - -#ifdef SRS_AUTO_HTTP_API - srs_trace("check feature http api: on"); -#else - srs_warn("check feature http api: off"); -#endif - -#ifdef SRS_AUTO_HTTP_SERVER - srs_trace("check feature http server: on"); -#else - srs_warn("check feature http server: off"); -#endif - -#ifdef SRS_AUTO_HTTP_CORE - srs_trace("check feature http parser: on"); -#else - srs_warn("check feature http parser: off"); -#endif - -#ifdef SRS_AUTO_DVR - srs_trace("check feature dvr: on"); -#else - srs_warn("check feature dvr: off"); -#endif - -#ifdef SRS_AUTO_TRANSCODE - srs_trace("check feature transcode: on"); -#else - srs_warn("check feature transcode: off"); -#endif - -#ifdef SRS_AUTO_INGEST - srs_trace("check feature ingest: on"); -#else - srs_warn("check feature ingest: off"); -#endif - -#ifdef SRS_AUTO_STAT - srs_trace("check feature system stat: on"); -#else - srs_warn("check feature system stat: off"); -#endif - -#ifdef SRS_AUTO_NGINX - srs_trace("check feature compile nginx: on"); -#else - srs_warn("check feature compile nginx: off"); -#endif - -#ifdef SRS_AUTO_FFMPEG_TOOL - srs_trace("check feature compile ffmpeg: on"); -#else - srs_warn("check feature compile ffmpeg: off"); -#endif - -#ifdef SRS_AUTO_STREAM_CASTER - srs_trace("stream caster: on"); -#else - srs_warn("stream caster: off"); -#endif - -#ifdef SRS_PERF_MERGED_READ - srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241)); -#else - srs_warn("MR(merged-read): off, @see %s", RTMP_SIG_SRS_ISSUES(241)); -#endif - - srs_trace("MR(merged-read) default %d sleep %d", SRS_PERF_MR_ENABLED, SRS_PERF_MR_SLEEP); - srs_trace("MW(merged-write) default sleep %d", SRS_PERF_MW_SLEEP); - srs_trace("read chunk stream cache cid [0, %d)", SRS_PERF_CHUNK_STREAM_CACHE); - srs_trace("default gop cache %d, play queue %ds", SRS_PERF_GOP_CACHE, SRS_PERF_PLAY_QUEUE); + if (true) { + stringstream ss; + + ss << "features"; + + // rch(rtmp complex handshake) + ss << ", rch:" << srs_bool2switch(SRS_AUTO_SSL_BOOL); + ss << ", hls:" << srs_bool2switch(SRS_AUTO_HLS_BOOL); + ss << ", hds:" << srs_bool2switch(SRS_AUTO_HDS_BOOL); + // hc(http callback) + ss << ", hc:" << srs_bool2switch(SRS_AUTO_HTTP_CALLBACK_BOOL); + // ha(http api) + ss << ", ha:" << srs_bool2switch(SRS_AUTO_HTTP_API_BOOL); + // hs(http server) + ss << ", hs:" << srs_bool2switch(SRS_AUTO_HTTP_SERVER_BOOL); + // hp(http parser) + ss << ", hp:" << srs_bool2switch(SRS_AUTO_HTTP_CORE_BOOL); + ss << ", dvr:" << srs_bool2switch(SRS_AUTO_DVR_BOOL); + // trans(transcode) + ss << ", trans:" << srs_bool2switch(SRS_AUTO_TRANSCODE_BOOL); + // inge(ingest) + ss << ", inge:" << srs_bool2switch(SRS_AUTO_INGEST_BOOL); + ss << ", kafka:" << srs_bool2switch(SRS_AUTO_KAFKA_BOOL); + ss << ", stat:" << srs_bool2switch(SRS_AUTO_STAT_BOOL); + ss << ", nginx:" << srs_bool2switch(SRS_AUTO_NGINX_BOOL); + // ff(ffmpeg) + ss << ", ff:" << srs_bool2switch(SRS_AUTO_FFMPEG_TOOL_BOOL); + // sc(stream-caster) + ss << ", sc:" << srs_bool2switch(SRS_AUTO_STREAM_CASTER_BOOL); + srs_trace(ss.str().c_str()); + } + if (true) { + stringstream ss; + ss << "SRS on "; +#ifdef SRS_OSX + ss << "OSX"; +#endif +#ifdef SRS_PI + ss << "RespberryPi"; +#endif +#ifdef SRS_CUBIE + ss << "CubieBoard"; +#endif +#ifdef SRS_ARM_UBUNTU12 + ss << "ARM(build on ubuntu)"; +#endif +#ifdef SRS_MIPS_UBUNTU12 + ss << "MIPS(build on ubuntu)"; +#endif + +#if defined(__amd64__) + ss << " amd64"; +#endif +#if defined(__x86_64__) + ss << " x86_64"; +#endif +#if defined(__i386__) + ss << " i386"; +#endif +#if defined(__arm__) + ss << "arm"; +#endif + +#ifndef SRS_OSX + ss << ", glibc" << (int)__GLIBC__ << "." (int)__GLIBC_MINOR__; +#endif + + ss << ", conf:" << _srs_config->config() << ", limit:" << _srs_config->get_max_connections() + << ", writev:" << sysconf(_SC_IOV_MAX) << ", encoding:" << (srs_is_little_endian()? "little-endian":"big-endian") + << ", HZ:" << (int)sysconf(_SC_CLK_TCK); + + srs_trace(ss.str().c_str()); + } + + if (true) { + stringstream ss; + + // mw(merged-write) + ss << "mw sleep:" << SRS_PERF_MW_SLEEP << "ms"; + + // mr(merged-read) + ss << ". mr "; +#ifdef SRS_PERF_MERGED_READ + ss << "enabled:on"; +#else + ss << "enabled:off"; +#endif + ss << ", default:" << SRS_PERF_MR_ENABLED << ", sleep:" << SRS_PERF_MR_SLEEP << "ms"; + ss << ", @see " << RTMP_SIG_SRS_ISSUES(241); + + srs_trace(ss.str().c_str()); + } + + if (true) { + stringstream ss; + + // gc(gop-cache) + ss << "gc:" << srs_bool2switch(SRS_PERF_GOP_CACHE); + // pq(play-queue) + ss << ", pq:" << SRS_PERF_PLAY_QUEUE << "s"; + // cscc(chunk stream cache cid) + ss << ", cscc:[0," << SRS_PERF_CHUNK_STREAM_CACHE << ")"; + // csa(complex send algorithm) + ss << ", csa:"; #ifndef SRS_PERF_COMPLEX_SEND - srs_warn("complex send algorithm disabled."); + ss << "off"; #else - srs_trace("complex send algorithm enabled."); + ss << "on"; #endif - + + // tn(TCP_NODELAY) + ss << ", tn:"; #ifdef SRS_PERF_TCP_NODELAY - srs_warn("TCP_NODELAY enabled, may hurts performance."); + ss << "on(may hurts performance)"; #else - srs_trace("TCP_NODELAY disabled."); + ss << "off"; #endif - + + // ss(SO_SENDBUF) + ss << ", ss:"; #ifdef SRS_PERF_SO_SNDBUF_SIZE - srs_warn("socket send buffer size %d", SRS_PERF_SO_SNDBUF_SIZE); + ss << SRS_PERF_SO_SNDBUF_SIZE; #else - srs_trace("auto guess socket send buffer by merged write"); + ss << "auto(guess by merged write)"; #endif - + + srs_trace(ss.str().c_str()); + } + + // others int possible_mr_latency = 0; #ifdef SRS_PERF_MERGED_READ possible_mr_latency = SRS_PERF_MR_SLEEP; #endif srs_trace("system default latency in ms: mw(0-%d) + mr(0-%d) + play-queue(0-%d)", - SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000); -} - -void check_macro_features() -{ - // important preset. -#ifdef SRS_OSX - srs_trace("SRS for OSX"); -#endif -#ifdef SRS_PI - srs_trace("SRS for pi"); -#endif -#ifdef SRS_CUBIE - srs_trace("SRS for cubieboard"); -#endif -#ifdef SRS_ARM_UBUNTU12 - srs_trace("SRS for arm(build on ubuntu)"); -#endif -#ifdef SRS_MIPS_UBUNTU12 - srs_trace("SRS for mips(build on ubuntu)"); -#endif - - // for special features. -#ifndef SRS_PERF_MERGED_READ - srs_warn("MR(merged-read) is disabled, hurts read performance. @see %s", RTMP_SIG_SRS_ISSUES(241)); -#endif - - srs_trace("writev limits write %d iovs a time", sysconf(_SC_IOV_MAX)); - -#if VERSION_MAJOR > VERSION_STABLE - #warning "current branch is not stable, please use stable branch instead." - srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH); -#endif + SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000); #ifdef SRS_AUTO_MEM_WATCH #warning "srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script." srs_warn("srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script."); #endif - + #if defined(SRS_AUTO_STREAM_CASTER) #warning "stream caster is experiment feature." srs_warn("stream caster is experiment feature."); #endif - -#if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF) - #error "SRS_PERF_SO_SNDBUF_SIZE depends on SRS_PERF_MW_SO_SNDBUF" + +#if VERSION_MAJOR > VERSION_STABLE + #warning "current branch is not stable, please use stable branch instead." + srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH); #endif -#ifndef SRS_OSX - #if defined(__amd64__) - srs_trace("cpu is amd64, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__); - #endif - #if defined(__x86_64__) - srs_trace("cpu is x86_64, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__); - #endif - #if defined(__i386__) - srs_trace("cpu is i386, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__); - #endif - #if defined(__arm__) - srs_trace("cpu is arm, glibc %d.%d", (int)__GLIBC__, (int)__GLIBC_MINOR__); - #endif +#if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF) + #error "SRS_PERF_SO_SNDBUF_SIZE depends on SRS_PERF_MW_SO_SNDBUF" #endif } @@ -284,28 +264,24 @@ int main(int argc, char** argv) if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { return ret; } + + // config already applied to log. + srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION", stable is "RTMP_SIG_SRS_PRIMARY); + srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT); + srs_trace("authors: "RTMP_SIG_SRS_AUTHROS); + srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS); + srs_trace("build: %s, configure:%s, uname: %s", SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME); + srs_trace("configure detail: "SRS_AUTO_CONFIGURE); +#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN + srs_trace("crossbuild tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); +#endif // we check the config when the log initialized. if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { return ret; } - srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION); - srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT); - srs_trace("primary/master: "RTMP_SIG_SRS_PRIMARY); - srs_trace("authors: "RTMP_SIG_SRS_AUTHROS); - srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS); - srs_trace("uname: "SRS_AUTO_UNAME); - srs_trace("build: %s, %s", SRS_AUTO_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian"); - srs_trace("configure: "SRS_AUTO_USER_CONFIGURE); - srs_trace("features: "SRS_AUTO_CONFIGURE); -#ifdef SRS_AUTO_ARM_UBUNTU12 - srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); -#endif - srs_trace("conf: %s, limit: %d", _srs_config->config().c_str(), _srs_config->get_max_connections()); - // features - check_macro_features(); show_macro_features(); /** diff --git a/trunk/src/protocol/srs_protocol_io.hpp b/trunk/src/protocol/srs_protocol_io.hpp index 632abcb5b..98ed3b671 100644 --- a/trunk/src/protocol/srs_protocol_io.hpp +++ b/trunk/src/protocol/srs_protocol_io.hpp @@ -41,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | IBufferReader | | IStatistic | | IBufferWriter | +---------------+ +--------------------+ +---------------+ | + read() | | + get_recv_bytes() | | + write() | -+------+--------+ | + get_recv_bytes() | | + writev() | ++------+--------+ | + get_send_bytes() | | + writev() | / \ +---+--------------+-+ +-------+-------+ | / \ / \ / \ | | | | diff --git a/trunk/src/utest/srs_utest_core.cpp b/trunk/src/utest/srs_utest_core.cpp index 77166b084..78f999054 100644 --- a/trunk/src/utest/srs_utest_core.cpp +++ b/trunk/src/utest/srs_utest_core.cpp @@ -58,9 +58,6 @@ VOID TEST(CoreMacroseTest, Check) #ifndef SRS_AUTO_CONFIGURE EXPECT_TRUE(false); #endif -#ifndef SRS_AUTO_EMBEDED_TOOL_CHAIN - EXPECT_TRUE(false); -#endif #ifndef SRS_AUTO_PREFIX EXPECT_TRUE(false); #endif