diff --git a/trunk/configure b/trunk/configure index 06eb5c8d2..6f70f83fa 100755 --- a/trunk/configure +++ b/trunk/configure @@ -153,7 +153,7 @@ MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_socket" "srs_core_source" "srs_core_codec" "srs_core_refer" "srs_core_hls" "srs_core_forward" "srs_core_encoder" - "srs_core_http" "srs_core_thread" "srs_core_bandwidth" "srs_core_st" "srs_core_log_context" + "srs_core_http" "srs_core_thread" "srs_core_bandwidth" "srs_core_st" "srs_core_log" "srs_core_config" "srs_core_pithy_print") MODULE_DIR="src/app" . auto/modules.sh APP_OBJS="${MODULE_OBJS[@]}" diff --git a/trunk/src/app/srs_core_bandwidth.cpp b/trunk/src/app/srs_core_bandwidth.cpp index 43aade768..19d8b4734 100644 --- a/trunk/src/app/srs_core_bandwidth.cpp +++ b/trunk/src/app/srs_core_bandwidth.cpp @@ -50,12 +50,12 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt rtmp = _rtmp; req = _req; - if (!config->get_bw_check_enabled(req->vhost)) { + if (!_srs_config->get_bw_check_enabled(req->vhost)) { return ret; } // validate the bandwidth check key - std::string key = "key=" + config->get_bw_check_key(req->vhost); + std::string key = "key=" + _srs_config->get_bw_check_key(req->vhost); if (req->tcUrl.find(key) == std::string::npos) { ret = ERROR_SYSTEM_BANDWIDTH_KEY; srs_error("check the vhost=%s %s failed, tcUrl=%s, ret=%d", @@ -68,7 +68,7 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt // if client request check in the window(specifeid by interval), // directly reject the request. static int64_t last_check_time = 0; - int interval_ms = config->get_bw_check_interval_ms(req->vhost); + int interval_ms = _srs_config->get_bw_check_interval_ms(req->vhost); int64_t time_now = srs_get_system_time_ms(); // reject the connection in the interval window. @@ -149,7 +149,7 @@ int SrsBandwidth::do_bandwidth_check() int publish_actual_duration_ms = 0; int publish_bytes = 0; - int limit_kbps = config->get_bw_check_limit_kbps(req->vhost); + int limit_kbps = _srs_config->get_bw_check_limit_kbps(req->vhost); int64_t start_time = srs_get_system_time_ms(); diff --git a/trunk/src/app/srs_core_client.cpp b/trunk/src/app/srs_core_client.cpp index 01b44943b..4bd551676 100644 --- a/trunk/src/app/srs_core_client.cpp +++ b/trunk/src/app/srs_core_client.cpp @@ -57,12 +57,12 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) #endif bandwidth = new SrsBandwidth(); - config->subscribe(this); + _srs_config->subscribe(this); } SrsClient::~SrsClient() { - config->unsubscribe(this); + _srs_config->unsubscribe(this); srs_freepa(ip); srs_freep(req); @@ -104,7 +104,7 @@ int SrsClient::do_cycle() srs_verbose("rtmp connect app success"); // discovery vhost, resolve the vhost from config - SrsConfDirective* parsed_vhost = config->get_vhost(req->vhost); + SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost); if (parsed_vhost) { req->vhost = parsed_vhost->arg0(); } @@ -173,7 +173,7 @@ int SrsClient::service_cycle() srs_verbose("set peer bandwidth success"); // do bandwidth test if connect to the vhost which is for bandwidth check. - if (config->get_bw_check_enabled(req->vhost)) { + if (_srs_config->get_bw_check_enabled(req->vhost)) { return bandwidth->bandwidth_test(req, stfd, rtmp); } @@ -237,7 +237,7 @@ int SrsClient::stream_service_cycle() rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US); // set chunk size to larger. - int chunk_size = config->get_chunk_size(req->vhost); + int chunk_size = _srs_config->get_chunk_size(req->vhost); if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); return ret; @@ -258,7 +258,7 @@ int SrsClient::stream_service_cycle() return ret; } - bool enabled_cache = config->get_gop_cache(req->vhost); + bool enabled_cache = _srs_config->get_gop_cache(req->vhost); srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); source->set_cache(enabled_cache); @@ -329,14 +329,14 @@ int SrsClient::check_vhost() srs_assert(req != NULL); - SrsConfDirective* vhost = config->get_vhost(req->vhost); + SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost); if (vhost == NULL) { ret = ERROR_RTMP_VHOST_NOT_FOUND; srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret); return ret; } - if (!config->get_vhost_enabled(req->vhost)) { + if (!_srs_config->get_vhost_enabled(req->vhost)) { ret = ERROR_RTMP_VHOST_NOT_FOUND; srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret); return ret; @@ -347,7 +347,7 @@ int SrsClient::check_vhost() req->vhost = vhost->arg0(); } - if ((ret = refer->check(req->pageUrl, config->get_refer(req->vhost))) != ERROR_SUCCESS) { + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) { srs_error("check refer failed. ret=%d", ret); return ret; } @@ -364,7 +364,7 @@ int SrsClient::playing(SrsSource* source) { int ret = ERROR_SUCCESS; - if ((ret = refer->check(req->pageUrl, config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { srs_error("check play_refer failed. ret=%d", ret); return ret; } @@ -451,7 +451,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle) { int ret = ERROR_SUCCESS; - if ((ret = refer->check(req->pageUrl, config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { srs_error("check publish_refer failed. ret=%d", ret); return ret; } @@ -651,7 +651,7 @@ int SrsClient::on_connect() #ifdef SRS_HTTP // HTTP: on_connect - SrsConfDirective* on_connect = config->get_vhost_on_connect(req->vhost); + SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost); if (!on_connect) { srs_info("ignore the empty http callback: on_connect"); return ret; @@ -674,7 +674,7 @@ void SrsClient::on_close() #ifdef SRS_HTTP // whatever the ret code, notify the api hooks. // HTTP: on_close - SrsConfDirective* on_close = config->get_vhost_on_close(req->vhost); + SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost); if (!on_close) { srs_info("ignore the empty http callback: on_close"); return; @@ -693,7 +693,7 @@ int SrsClient::on_publish() #ifdef SRS_HTTP // HTTP: on_publish - SrsConfDirective* on_publish = config->get_vhost_on_publish(req->vhost); + SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost); if (!on_publish) { srs_info("ignore the empty http callback: on_publish"); return ret; @@ -716,7 +716,7 @@ void SrsClient::on_unpublish() #ifdef SRS_HTTP // whatever the ret code, notify the api hooks. // HTTP: on_unpublish - SrsConfDirective* on_unpublish = config->get_vhost_on_unpublish(req->vhost); + SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost); if (!on_unpublish) { srs_info("ignore the empty http callback: on_unpublish"); return; @@ -735,7 +735,7 @@ int SrsClient::on_play() #ifdef SRS_HTTP // HTTP: on_play - SrsConfDirective* on_play = config->get_vhost_on_play(req->vhost); + SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost); if (!on_play) { srs_info("ignore the empty http callback: on_play"); return ret; @@ -758,7 +758,7 @@ void SrsClient::on_stop() #ifdef SRS_HTTP // whatever the ret code, notify the api hooks. // HTTP: on_stop - SrsConfDirective* on_stop = config->get_vhost_on_stop(req->vhost); + SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost); if (!on_stop) { srs_info("ignore the empty http callback: on_stop"); return; diff --git a/trunk/src/app/srs_core_config.cpp b/trunk/src/app/srs_core_config.cpp index 241c7c997..7c02e6bcc 100644 --- a/trunk/src/app/srs_core_config.cpp +++ b/trunk/src/app/srs_core_config.cpp @@ -429,8 +429,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector& arg return ret; } -SrsConfig* config = new SrsConfig(); - SrsConfig::SrsConfig() { show_help = false; diff --git a/trunk/src/app/srs_core_config.hpp b/trunk/src/app/srs_core_config.hpp index 918ce9a3f..39a28f2e0 100644 --- a/trunk/src/app/srs_core_config.hpp +++ b/trunk/src/app/srs_core_config.hpp @@ -180,6 +180,6 @@ public: bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); // global config -extern SrsConfig* config; +extern SrsConfig* _srs_config; #endif \ No newline at end of file diff --git a/trunk/src/app/srs_core_conn.cpp b/trunk/src/app/srs_core_conn.cpp index 92a2ba744..2476c417d 100644 --- a/trunk/src/app/srs_core_conn.cpp +++ b/trunk/src/app/srs_core_conn.cpp @@ -57,8 +57,8 @@ void SrsConnection::cycle() { int ret = ERROR_SUCCESS; - log_context->generate_id(); - connection_id = log_context->get_id(); + _srs_context->generate_id(); + connection_id = _srs_context->get_id(); ret = do_cycle(); diff --git a/trunk/src/app/srs_core_encoder.cpp b/trunk/src/app/srs_core_encoder.cpp index bfce24bcb..2915a5cfb 100644 --- a/trunk/src/app/srs_core_encoder.cpp +++ b/trunk/src/app/srs_core_encoder.cpp @@ -75,22 +75,22 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) { int ret = ERROR_SUCCESS; - config->get_engine_vfilter(engine, vfilter); - vcodec = config->get_engine_vcodec(engine); - vbitrate = config->get_engine_vbitrate(engine); - vfps = config->get_engine_vfps(engine); - vwidth = config->get_engine_vwidth(engine); - vheight = config->get_engine_vheight(engine); - vthreads = config->get_engine_vthreads(engine); - vprofile = config->get_engine_vprofile(engine); - vpreset = config->get_engine_vpreset(engine); - config->get_engine_vparams(engine, vparams); - acodec = config->get_engine_acodec(engine); - abitrate = config->get_engine_abitrate(engine); - asample_rate = config->get_engine_asample_rate(engine); - achannels = config->get_engine_achannels(engine); - config->get_engine_aparams(engine, aparams); - output = config->get_engine_output(engine); + _srs_config->get_engine_vfilter(engine, vfilter); + vcodec = _srs_config->get_engine_vcodec(engine); + vbitrate = _srs_config->get_engine_vbitrate(engine); + vfps = _srs_config->get_engine_vfps(engine); + vwidth = _srs_config->get_engine_vwidth(engine); + vheight = _srs_config->get_engine_vheight(engine); + vthreads = _srs_config->get_engine_vthreads(engine); + vprofile = _srs_config->get_engine_vprofile(engine); + vpreset = _srs_config->get_engine_vpreset(engine); + _srs_config->get_engine_vparams(engine, vparams); + acodec = _srs_config->get_engine_acodec(engine); + abitrate = _srs_config->get_engine_abitrate(engine); + asample_rate = _srs_config->get_engine_asample_rate(engine); + achannels = _srs_config->get_engine_achannels(engine); + _srs_config->get_engine_aparams(engine, aparams); + output = _srs_config->get_engine_output(engine); // ensure the size is even. vwidth -= vwidth % 2; @@ -116,7 +116,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) output = srs_replace(output, "[engine]", engine->arg0()); // write ffmpeg info to log file. - log_file = config->get_log_dir(); + log_file = _srs_config->get_log_dir(); log_file += "/"; log_file += "encoder"; log_file += "-"; @@ -590,7 +590,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) // parse vhost scope engines std::string scope = ""; - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { srs_error("parse vhost scope=%s transcode engines failed. " "ret=%d", scope.c_str(), ret); @@ -599,7 +599,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) } // parse app scope engines scope = req->app; - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { srs_error("parse app scope=%s transcode engines failed. " "ret=%d", scope.c_str(), ret); @@ -609,7 +609,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) // parse stream scope engines scope += "/"; scope += req->stream; - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { srs_error("parse stream scope=%s transcode engines failed. " "ret=%d", scope.c_str(), ret); @@ -627,14 +627,14 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) srs_assert(conf); // enabled - if (!config->get_transcode_enabled(conf)) { + if (!_srs_config->get_transcode_enabled(conf)) { srs_trace("ignore the disabled transcode: %s", conf->arg0().c_str()); return ret; } // ffmpeg - std::string ffmpeg_bin = config->get_transcode_ffmpeg(conf); + std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf); if (ffmpeg_bin.empty()) { srs_trace("ignore the empty ffmpeg transcode: %s", conf->arg0().c_str()); @@ -643,7 +643,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) // get all engines. std::vector engines; - config->get_transcode_engines(conf, engines); + _srs_config->get_transcode_engines(conf, engines); if (engines.empty()) { srs_trace("ignore the empty transcode engine: %s", conf->arg0().c_str()); @@ -653,7 +653,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) // create engine for (int i = 0; i < (int)engines.size(); i++) { SrsConfDirective* engine = engines[i]; - if (!config->get_engine_enabled(engine)) { + if (!_srs_config->get_engine_enabled(engine)) { srs_trace("ignore the diabled transcode engine: %s %s", conf->arg0().c_str(), engine->arg0().c_str()); continue; diff --git a/trunk/src/app/srs_core_hls.cpp b/trunk/src/app/srs_core_hls.cpp index 35dcb15a9..6cdb52f07 100644 --- a/trunk/src/app/srs_core_hls.cpp +++ b/trunk/src/app/srs_core_hls.cpp @@ -1149,18 +1149,18 @@ int SrsHls::on_publish(SrsRequest* req) std::string stream = req->stream; std::string app = req->app; - if (!config->get_hls_enabled(vhost)) { + if (!_srs_config->get_hls_enabled(vhost)) { return ret; } // if enabled, open the muxer. hls_enabled = true; - int hls_fragment = config->get_hls_fragment(vhost); - int hls_window = config->get_hls_window(vhost); + int hls_fragment = _srs_config->get_hls_fragment(vhost); + int hls_window = _srs_config->get_hls_window(vhost); // get the hls path config - std::string hls_path = config->get_hls_path(vhost); + std::string hls_path = _srs_config->get_hls_path(vhost); // open muxer if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { diff --git a/trunk/src/app/srs_core_log.cpp b/trunk/src/app/srs_core_log.cpp new file mode 100644 index 000000000..205cad336 --- /dev/null +++ b/trunk/src/app/srs_core_log.cpp @@ -0,0 +1,218 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +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 + +#include +#include + +SrsThreadContext::SrsThreadContext() +{ +} + +SrsThreadContext::~SrsThreadContext() +{ +} + +void SrsThreadContext::generate_id() +{ + static int id = 1; + cache[st_thread_self()] = id++; +} + +int SrsThreadContext::get_id() +{ + return cache[st_thread_self()]; +} + +// the max size of a line of log. +#define LOG_MAX_SIZE 4096 + +// the tail append to each log. +#define LOG_TAIL '\n' +// reserved for the end of log data, it must be strlen(LOG_TAIL) +#define LOG_TAIL_SIZE 1 + +SrsFastLog::SrsFastLog() +{ + level = SrsLogLevel::Trace; + log_data = new char[LOG_MAX_SIZE]; +} + +SrsFastLog::~SrsFastLog() +{ + srs_freepa(log_data); +} + +void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) +{ + if (level > SrsLogLevel::Verbose) { + return; + } + + int size = 0; + if (!generate_header(tag, context_id, "verb", &size)) { + return; + } + + va_list ap; + va_start(ap, fmt); + // we reserved 1 bytes for the new line. + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); + va_end(ap); + + write_log(log_data, size); +} + +void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) +{ + if (level > SrsLogLevel::Info) { + return; + } + + int size = 0; + if (!generate_header(tag, context_id, "debug", &size)) { + return; + } + + va_list ap; + va_start(ap, fmt); + // we reserved 1 bytes for the new line. + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); + va_end(ap); + + write_log(log_data, size); +} + +void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) +{ + if (level > SrsLogLevel::Trace) { + return; + } + + int size = 0; + if (!generate_header(tag, context_id, "trace", &size)) { + return; + } + + va_list ap; + va_start(ap, fmt); + // we reserved 1 bytes for the new line. + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); + va_end(ap); + + write_log(log_data, size); +} + +void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) +{ + if (level > SrsLogLevel::Warn) { + return; + } + + int size = 0; + if (!generate_header(tag, context_id, "warn", &size)) { + return; + } + + va_list ap; + va_start(ap, fmt); + // we reserved 1 bytes for the new line. + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); + va_end(ap); + + write_log(log_data, size); +} + +void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) +{ + if (level > SrsLogLevel::Error) { + return; + } + + int size = 0; + if (!generate_header(tag, context_id, "error", &size)) { + return; + } + + va_list ap; + va_start(ap, fmt); + // we reserved 1 bytes for the new line. + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); + va_end(ap); + + write_log(log_data, size); +} + +bool SrsFastLog::generate_header(const char* tag, int context_id, const char* level_name, int* header_size) +{ + // clock time + timeval tv; + if (gettimeofday(&tv, NULL) == -1) { + return false; + } + + // to calendar time + struct tm* tm; + if ((tm = localtime(&tv.tv_sec)) == NULL) { + return false; + } + + // write log header + int log_header_size = -1; + + if (tag) { + log_header_size = snprintf(log_data, LOG_MAX_SIZE, + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ", + 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), + level_name, tag, context_id, errno); + } else { + log_header_size = snprintf(log_data, LOG_MAX_SIZE, + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ", + 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), + level_name, context_id, errno); + } + + if (log_header_size == -1) { + return false; + } + + // write the header size. + *header_size = srs_min(LOG_MAX_SIZE - 1, log_header_size); + + return true; +} + +void SrsFastLog::write_log(char* str_log, int size) +{ + // ensure the tail and EOF of string + // LOG_TAIL_SIZE for the TAIL char. + // 1 for the last char(0). + size = srs_min(LOG_MAX_SIZE - 1 - LOG_TAIL_SIZE, size); + + // add some to the end of char. + log_data[size++] = LOG_TAIL; + log_data[size++] = 0; + + printf("%s", str_log); +} diff --git a/trunk/src/app/srs_core_log.hpp b/trunk/src/app/srs_core_log.hpp new file mode 100644 index 000000000..73b38201e --- /dev/null +++ b/trunk/src/app/srs_core_log.hpp @@ -0,0 +1,97 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013-2014 winlin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +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_LOG_HPP +#define SRS_CORE_LOG_HPP + +/* +#include +*/ + +#include + +#include +#include + +#include + +#include +#include + +/** +* st thread context, get_id will get the st-thread id, +* which identify the client. +*/ +class SrsThreadContext : public ISrsThreadContext +{ +private: + std::map cache; +public: + SrsThreadContext(); + virtual ~SrsThreadContext(); +public: + virtual void generate_id(); + virtual int get_id(); +}; + +/** +* the log level, for example: +* if specified Debug level, all level messages will be logged. +* if specified Warn level, only Warn/Error/Fatal level messages will be logged. +*/ +class SrsLogLevel +{ +public: + // only used for very verbose debug, generally, + // we compile without this level for high performance. + static const int Verbose = 0x01; + static const int Info = 0x02; + static const int Trace = 0x03; + static const int Warn = 0x04; + static const int Error = 0x05; +}; + +/** +* we use memory/disk cache and donot flush when write log. +*/ +class SrsFastLog : public ISrsLog +{ +private: + // defined in SrsLogLevel. + int level; + char* log_data; +public: + SrsFastLog(); + virtual ~SrsFastLog(); +public: + virtual void verbose(const char* tag, int context_id, const char* fmt, ...); + virtual void info(const char* tag, int context_id, const char* fmt, ...); + virtual void trace(const char* tag, int context_id, const char* fmt, ...); + virtual void warn(const char* tag, int context_id, const char* fmt, ...); + virtual void error(const char* tag, int context_id, const char* fmt, ...); +private: + virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size); + virtual void write_log(char* str_log, int size); +}; + +#endif diff --git a/trunk/src/app/srs_core_log_context.cpp b/trunk/src/app/srs_core_log_context.cpp deleted file mode 100644 index 369ac47f4..000000000 --- a/trunk/src/app/srs_core_log_context.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 winlin - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -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 - -ILogContext* log_context = new SrsLogContext(); - -SrsLogContext::DateTime::DateTime() -{ - memset(time_data, 0, DATE_LEN); -} - -SrsLogContext::DateTime::~DateTime() -{ -} - -const char* SrsLogContext::DateTime::format_time() -{ - // clock time - timeval tv; - if (gettimeofday(&tv, NULL) == -1) { - return ""; - } - // to calendar time - struct tm* tm; - if ((tm = localtime(&tv.tv_sec)) == NULL) { - return ""; - } - - // log header, the time/pid/level of log - // reserved 1bytes for the new line. - snprintf(time_data, DATE_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d", - 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, - (int)(tv.tv_usec / 1000)); - - return time_data; -} - -SrsLogContext::SrsLogContext() -{ -} - -SrsLogContext::~SrsLogContext() -{ -} - -void SrsLogContext::generate_id() -{ - static int id = 1; - cache[st_thread_self()] = id++; -} - -int SrsLogContext::get_id() -{ - return cache[st_thread_self()]; -} - -const char* SrsLogContext::format_time() -{ - return time.format_time(); -} diff --git a/trunk/src/app/srs_core_log_context.hpp b/trunk/src/app/srs_core_log_context.hpp deleted file mode 100644 index 8aa740a70..000000000 --- a/trunk/src/app/srs_core_log_context.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2013-2014 winlin - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -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_LOG_CONTEXT_HPP -#define SRS_CORE_LOG_CONTEXT_HPP - -/* -#include -*/ - -#include - -#include -#include - -#include -#include - -#include -#include - -class SrsLogContext : public ILogContext -{ -private: - class DateTime - { - private: - // %d-%02d-%02d %02d:%02d:%02d.%03d - #define DATE_LEN 24 - char time_data[DATE_LEN]; - public: - DateTime(); - virtual ~DateTime(); - public: - virtual const char* format_time(); - }; -private: - DateTime time; - std::map cache; -public: - SrsLogContext(); - virtual ~SrsLogContext(); -public: - virtual void generate_id(); - virtual int get_id(); -public: - virtual const char* format_time(); -}; - -#endif diff --git a/trunk/src/app/srs_core_pithy_print.cpp b/trunk/src/app/srs_core_pithy_print.cpp index 77593c05b..ea2a76404 100644 --- a/trunk/src/app/srs_core_pithy_print.cpp +++ b/trunk/src/app/srs_core_pithy_print.cpp @@ -46,33 +46,33 @@ struct SrsStageInfo : public ISrsReloadHandler update_print_time(); - config->subscribe(this); + _srs_config->subscribe(this); } virtual ~SrsStageInfo() { - config->unsubscribe(this); + _srs_config->unsubscribe(this); } void update_print_time() { switch (stage_id) { case SRS_STAGE_PLAY_USER: { - pithy_print_time_ms = config->get_pithy_print_play(); + pithy_print_time_ms = _srs_config->get_pithy_print_play(); break; } case SRS_STAGE_PUBLISH_USER: { - pithy_print_time_ms = config->get_pithy_print_publish(); + pithy_print_time_ms = _srs_config->get_pithy_print_publish(); break; } case SRS_STAGE_FORWARDER: { - pithy_print_time_ms = config->get_pithy_print_forwarder(); + pithy_print_time_ms = _srs_config->get_pithy_print_forwarder(); break; } case SRS_STAGE_ENCODER: { - pithy_print_time_ms = config->get_pithy_print_encoder(); + pithy_print_time_ms = _srs_config->get_pithy_print_encoder(); break; } case SRS_STAGE_HLS: { - pithy_print_time_ms = config->get_pithy_print_hls(); + pithy_print_time_ms = _srs_config->get_pithy_print_hls(); break; } default: { diff --git a/trunk/src/app/srs_core_server.cpp b/trunk/src/app/srs_core_server.cpp index 316f6ff4e..e52dd51a7 100644 --- a/trunk/src/app/srs_core_server.cpp +++ b/trunk/src/app/srs_core_server.cpp @@ -151,13 +151,13 @@ SrsServer::SrsServer() { signal_reload = false; - srs_assert(config); - config->subscribe(this); + srs_assert(_srs_config); + _srs_config->subscribe(this); } SrsServer::~SrsServer() { - config->unsubscribe(this); + _srs_config->unsubscribe(this); if (true) { std::vector::iterator it; @@ -191,7 +191,7 @@ int SrsServer::initialize() srs_verbose("st_init success"); // set current log id. - log_context->generate_id(); + _srs_context->generate_id(); srs_info("log set id success"); return ret; @@ -204,7 +204,7 @@ int SrsServer::listen() SrsConfDirective* conf = NULL; // stream service port. - conf = config->get_listen(); + conf = _srs_config->get_listen(); srs_assert(conf); close_listeners(); @@ -236,7 +236,7 @@ int SrsServer::cycle() signal_reload = false; srs_info("get signal reload, to reload the config."); - if ((ret = config->reload()) != ERROR_SUCCESS) { + if ((ret = _srs_config->reload()) != ERROR_SUCCESS) { srs_error("reload config failed. ret=%d", ret); return ret; } @@ -285,7 +285,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) { int ret = ERROR_SUCCESS; - int max_connections = config->get_max_connections(); + int max_connections = _srs_config->get_max_connections(); if ((int)conns.size() >= max_connections) { int fd = st_netfd_fileno(client_stfd); @@ -322,9 +322,3 @@ int SrsServer::on_reload_listen() { return listen(); } - -SrsServer* _server() -{ - static SrsServer server; - return &server; -} diff --git a/trunk/src/app/srs_core_server.hpp b/trunk/src/app/srs_core_server.hpp index 6272ed273..2eb38fada 100644 --- a/trunk/src/app/srs_core_server.hpp +++ b/trunk/src/app/srs_core_server.hpp @@ -88,7 +88,5 @@ private: public: virtual int on_reload_listen(); }; - -SrsServer* _server(); #endif \ No newline at end of file diff --git a/trunk/src/app/srs_core_source.cpp b/trunk/src/app/srs_core_source.cpp index 121b5a660..1aac3d4c5 100644 --- a/trunk/src/app/srs_core_source.cpp +++ b/trunk/src/app/srs_core_source.cpp @@ -423,12 +423,12 @@ SrsSource::SrsSource(SrsRequest* _req) gop_cache = new SrsGopCache(); - config->subscribe(this); + _srs_config->subscribe(this); } SrsSource::~SrsSource() { - config->unsubscribe(this); + _srs_config->unsubscribe(this); if (true) { std::vector::iterator it; @@ -473,7 +473,7 @@ int SrsSource::on_reload_gop_cache(string vhost) } // gop cache changed. - bool enabled_cache = config->get_gop_cache(vhost); + bool enabled_cache = _srs_config->get_gop_cache(vhost); srs_trace("vhost %s gop_cache changed to %d, source url=%s", vhost.c_str(), enabled_cache, req->get_stream_url().c_str()); @@ -491,7 +491,7 @@ int SrsSource::on_reload_queue_length(string vhost) return ret; } - double queue_size = config->get_queue_length(req->vhost); + double queue_size = _srs_config->get_queue_length(req->vhost); if (true) { std::vector::iterator it; @@ -913,7 +913,7 @@ void SrsSource::on_unpublish() consumer = new SrsConsumer(this); consumers.push_back(consumer); - double queue_size = config->get_queue_length(req->vhost); + double queue_size = _srs_config->get_queue_length(req->vhost); consumer->set_queue_size(queue_size); if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) { @@ -962,14 +962,14 @@ int SrsSource::create_forwarders() { int ret = ERROR_SUCCESS; - SrsConfDirective* conf = config->get_forward(req->vhost); + SrsConfDirective* conf = _srs_config->get_forward(req->vhost); for (int i = 0; conf && i < (int)conf->args.size(); i++) { std::string forward_server = conf->args.at(i); SrsForwarder* forwarder = new SrsForwarder(this); forwarders.push_back(forwarder); - double queue_size = config->get_queue_length(req->vhost); + double queue_size = _srs_config->get_queue_length(req->vhost); forwarder->set_queue_size(queue_size); if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) { diff --git a/trunk/src/app/srs_core_thread.cpp b/trunk/src/app/srs_core_thread.cpp index 51ee95530..0abaa9246 100644 --- a/trunk/src/app/srs_core_thread.cpp +++ b/trunk/src/app/srs_core_thread.cpp @@ -113,7 +113,7 @@ void SrsThread::thread_cycle() srs_assert(handler); - log_context->generate_id(); + _srs_context->generate_id(); srs_trace("thread cycle start"); handler->on_end_cycle(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index ddcf5e7ec..25c6db58b 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // current release version -#define RTMP_SIG_SRS_VERSION "0.9.7" +#define RTMP_SIG_SRS_VERSION "0.9.8" // server info. #define RTMP_SIG_SRS_KEY "srs" #define RTMP_SIG_SRS_ROLE "origin server" diff --git a/trunk/src/kernel/srs_kernel_log.cpp b/trunk/src/kernel/srs_kernel_log.cpp index 3b6bd411a..8518e7fc3 100644 --- a/trunk/src/kernel/srs_kernel_log.cpp +++ b/trunk/src/kernel/srs_kernel_log.cpp @@ -23,11 +23,48 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -ILogContext::ILogContext() +ISrsLog::ISrsLog() { } -ILogContext::~ILogContext() +ISrsLog::~ISrsLog() { } +void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) +{ +} + +void ISrsLog::info(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) +{ +} + +void ISrsLog::trace(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) +{ +} + +void ISrsLog::warn(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) +{ +} + +void ISrsLog::error(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) +{ +} + +ISrsThreadContext::ISrsThreadContext() +{ +} + +ISrsThreadContext::~ISrsThreadContext() +{ +} + +void ISrsThreadContext::generate_id() +{ +} + +int ISrsThreadContext::get_id() +{ + return 0; +} + diff --git a/trunk/src/kernel/srs_kernel_log.hpp b/trunk/src/kernel/srs_kernel_log.hpp index 352fddffb..ac4371663 100644 --- a/trunk/src/kernel/srs_kernel_log.hpp +++ b/trunk/src/kernel/srs_kernel_log.hpp @@ -35,43 +35,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -// the context for multiple clients. -class ILogContext +/** +* the log interface provides method to write log. +* but we provides some macro, which enable us to disable the log when compile. +* @see also SmtDebug/SmtTrace/SmtWarn/SmtError which is corresponding to Debug/Trace/Warn/Fatal. +*/ +class ISrsLog { public: - ILogContext(); - virtual ~ILogContext(); + ISrsLog(); + virtual ~ISrsLog(); public: - virtual void generate_id() = 0; - virtual int get_id() = 0; -public: - virtual const char* format_time() = 0; + /** + * log for verbose, very verbose information. + */ + virtual void verbose(const char* tag, int context_id, const char* fmt, ...); + /** + * log for debug, detail information. + */ + virtual void info(const char* tag, int context_id, const char* fmt, ...); + /** + * log for trace, important information. + */ + virtual void trace(const char* tag, int context_id, const char* fmt, ...); + /** + * log for warn, warn is something should take attention, but not a error. + */ + virtual void warn(const char* tag, int context_id, const char* fmt, ...); + /** + * log for error, something error occur, do something about the error, ie. close the connection, + * but we will donot abort the program. + */ + virtual void error(const char* tag, int context_id, const char* fmt, ...); }; +// the context for multiple clients. +class ISrsThreadContext +{ +public: + ISrsThreadContext(); + virtual ~ISrsThreadContext(); +public: + virtual void generate_id(); + virtual int get_id(); +}; + +// user must provides a log object +extern ISrsLog* _srs_log; + // user must implements the LogContext and define a global instance. -extern ILogContext* log_context; +extern ISrsThreadContext* _srs_context; // donot print method -#if 0 - #define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_warn(msg, ...) printf("[%s][%d][warns] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") - #define srs_error(msg, ...) printf("[%s][%d][error] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") +#if 1 + #define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) // use __FUNCTION__ to print c method -#elif 1 - #define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") - #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") +#elif 0 + #define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) // use __PRETTY_FUNCTION__ to print c++ class:method #else - #define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") - #define srs_warn(msg, ...) printf("[%s][%d][warns][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") - #define srs_error(msg, ...) printf("[%s][%d][error][%s] ", log_context->format_time(), log_context->get_id(), __PRETTY_FUNCTION__);printf(msg, ##__VA_ARGS__);printf(" errno=%d(%s)", errno, strerror(errno));printf("\n") + #define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) + #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) #endif #if 1 diff --git a/trunk/src/main/srs_main_bandcheck.cpp b/trunk/src/main/srs_main_bandcheck.cpp index f6b54fc45..f353419f7 100644 --- a/trunk/src/main/srs_main_bandcheck.cpp +++ b/trunk/src/main/srs_main_bandcheck.cpp @@ -35,6 +35,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include +#include +#include + +// kernel module. +ISrsLog* _srs_log = new SrsFastLog(); +ISrsThreadContext* _srs_context = new ISrsThreadContext(); +// app module. +SrsConfig* _srs_config = NULL; +SrsServer* _srs_server = NULL; #include diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 2b793ccd2..e48d1c870 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -25,6 +25,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include + +// kernel module. +ISrsLog* _srs_log = new SrsFastLog(); +ISrsThreadContext* _srs_context = new SrsThreadContext(); +// app module. +SrsConfig* _srs_config = new SrsConfig(); +SrsServer* _srs_server = new SrsServer(); #include #include @@ -32,7 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. void handler(int signo) { srs_trace("get a signal, signo=%d", signo); - _server()->on_signal(signo); + _srs_server->on_signal(signo); } int main(int argc, char** argv){ @@ -40,21 +48,21 @@ int main(int argc, char** argv){ signal(SIGNAL_RELOAD, handler); - if ((ret = config->parse_options(argc, argv)) != ERROR_SUCCESS) { + if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { return ret; } - if ((ret = _server()->initialize()) != ERROR_SUCCESS) { + if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { return ret; } - // TODO: create log dir in config->get_log_dir() + // TODO: create log dir in _srs_config->get_log_dir() - if ((ret = _server()->listen()) != ERROR_SUCCESS) { + if ((ret = _srs_server->listen()) != ERROR_SUCCESS) { return ret; } - if ((ret = _server()->cycle()) != ERROR_SUCCESS) { + if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 858ab13ab..2c5623728 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -52,8 +52,8 @@ file ..\app\srs_core_hls.cpp, ..\app\srs_core_http.hpp, ..\app\srs_core_http.cpp, - ..\app\srs_core_log_context.hpp, - ..\app\srs_core_log_context.cpp, + ..\app\srs_core_log.hpp, + ..\app\srs_core_log.cpp, ..\app\srs_core_refer.hpp, ..\app\srs_core_refer.cpp, ..\app\srs_core_pithy_print.hpp,