1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

use fast log

This commit is contained in:
winlin 2014-03-01 18:06:20 +08:00
parent 382fd127e4
commit 7d570fb4f3
23 changed files with 517 additions and 273 deletions

2
trunk/configure vendored
View file

@ -153,7 +153,7 @@ MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_socket" "srs_core_source" 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_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") "srs_core_config" "srs_core_pithy_print")
MODULE_DIR="src/app" . auto/modules.sh MODULE_DIR="src/app" . auto/modules.sh
APP_OBJS="${MODULE_OBJS[@]}" APP_OBJS="${MODULE_OBJS[@]}"

View file

@ -50,12 +50,12 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt
rtmp = _rtmp; rtmp = _rtmp;
req = _req; req = _req;
if (!config->get_bw_check_enabled(req->vhost)) { if (!_srs_config->get_bw_check_enabled(req->vhost)) {
return ret; return ret;
} }
// validate the bandwidth check key // 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) { if (req->tcUrl.find(key) == std::string::npos) {
ret = ERROR_SYSTEM_BANDWIDTH_KEY; ret = ERROR_SYSTEM_BANDWIDTH_KEY;
srs_error("check the vhost=%s %s failed, tcUrl=%s, ret=%d", 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), // if client request check in the window(specifeid by interval),
// directly reject the request. // directly reject the request.
static int64_t last_check_time = 0; 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(); int64_t time_now = srs_get_system_time_ms();
// reject the connection in the interval window. // reject the connection in the interval window.
@ -149,7 +149,7 @@ int SrsBandwidth::do_bandwidth_check()
int publish_actual_duration_ms = 0; int publish_actual_duration_ms = 0;
int publish_bytes = 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(); int64_t start_time = srs_get_system_time_ms();

View file

@ -57,12 +57,12 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
#endif #endif
bandwidth = new SrsBandwidth(); bandwidth = new SrsBandwidth();
config->subscribe(this); _srs_config->subscribe(this);
} }
SrsClient::~SrsClient() SrsClient::~SrsClient()
{ {
config->unsubscribe(this); _srs_config->unsubscribe(this);
srs_freepa(ip); srs_freepa(ip);
srs_freep(req); srs_freep(req);
@ -104,7 +104,7 @@ int SrsClient::do_cycle()
srs_verbose("rtmp connect app success"); srs_verbose("rtmp connect app success");
// discovery vhost, resolve the vhost from config // 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) { if (parsed_vhost) {
req->vhost = parsed_vhost->arg0(); req->vhost = parsed_vhost->arg0();
} }
@ -173,7 +173,7 @@ int SrsClient::service_cycle()
srs_verbose("set peer bandwidth success"); srs_verbose("set peer bandwidth success");
// do bandwidth test if connect to the vhost which is for bandwidth check. // 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); return bandwidth->bandwidth_test(req, stfd, rtmp);
} }
@ -237,7 +237,7 @@ int SrsClient::stream_service_cycle()
rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US); rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US);
// set chunk size to larger. // 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) { if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
return ret; return ret;
@ -258,7 +258,7 @@ int SrsClient::stream_service_cycle()
return ret; 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); srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
source->set_cache(enabled_cache); source->set_cache(enabled_cache);
@ -329,14 +329,14 @@ int SrsClient::check_vhost()
srs_assert(req != NULL); srs_assert(req != NULL);
SrsConfDirective* vhost = config->get_vhost(req->vhost); SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost);
if (vhost == NULL) { if (vhost == NULL) {
ret = ERROR_RTMP_VHOST_NOT_FOUND; ret = ERROR_RTMP_VHOST_NOT_FOUND;
srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret); srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret);
return ret; return ret;
} }
if (!config->get_vhost_enabled(req->vhost)) { if (!_srs_config->get_vhost_enabled(req->vhost)) {
ret = ERROR_RTMP_VHOST_NOT_FOUND; ret = ERROR_RTMP_VHOST_NOT_FOUND;
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret); srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
return ret; return ret;
@ -347,7 +347,7 @@ int SrsClient::check_vhost()
req->vhost = vhost->arg0(); 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); srs_error("check refer failed. ret=%d", ret);
return ret; return ret;
} }
@ -364,7 +364,7 @@ int SrsClient::playing(SrsSource* source)
{ {
int ret = ERROR_SUCCESS; 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); srs_error("check play_refer failed. ret=%d", ret);
return ret; return ret;
} }
@ -451,7 +451,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle)
{ {
int ret = ERROR_SUCCESS; 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); srs_error("check publish_refer failed. ret=%d", ret);
return ret; return ret;
} }
@ -651,7 +651,7 @@ int SrsClient::on_connect()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// HTTP: on_connect // 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) { if (!on_connect) {
srs_info("ignore the empty http callback: on_connect"); srs_info("ignore the empty http callback: on_connect");
return ret; return ret;
@ -674,7 +674,7 @@ void SrsClient::on_close()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// whatever the ret code, notify the api hooks. // whatever the ret code, notify the api hooks.
// HTTP: on_close // 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) { if (!on_close) {
srs_info("ignore the empty http callback: on_close"); srs_info("ignore the empty http callback: on_close");
return; return;
@ -693,7 +693,7 @@ int SrsClient::on_publish()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// HTTP: on_publish // 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) { if (!on_publish) {
srs_info("ignore the empty http callback: on_publish"); srs_info("ignore the empty http callback: on_publish");
return ret; return ret;
@ -716,7 +716,7 @@ void SrsClient::on_unpublish()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// whatever the ret code, notify the api hooks. // whatever the ret code, notify the api hooks.
// HTTP: on_unpublish // 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) { if (!on_unpublish) {
srs_info("ignore the empty http callback: on_unpublish"); srs_info("ignore the empty http callback: on_unpublish");
return; return;
@ -735,7 +735,7 @@ int SrsClient::on_play()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// HTTP: on_play // 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) { if (!on_play) {
srs_info("ignore the empty http callback: on_play"); srs_info("ignore the empty http callback: on_play");
return ret; return ret;
@ -758,7 +758,7 @@ void SrsClient::on_stop()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// whatever the ret code, notify the api hooks. // whatever the ret code, notify the api hooks.
// HTTP: on_stop // 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) { if (!on_stop) {
srs_info("ignore the empty http callback: on_stop"); srs_info("ignore the empty http callback: on_stop");
return; return;

View file

@ -429,8 +429,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg
return ret; return ret;
} }
SrsConfig* config = new SrsConfig();
SrsConfig::SrsConfig() SrsConfig::SrsConfig()
{ {
show_help = false; show_help = false;

View file

@ -180,6 +180,6 @@ public:
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b);
// global config // global config
extern SrsConfig* config; extern SrsConfig* _srs_config;
#endif #endif

View file

@ -57,8 +57,8 @@ void SrsConnection::cycle()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
log_context->generate_id(); _srs_context->generate_id();
connection_id = log_context->get_id(); connection_id = _srs_context->get_id();
ret = do_cycle(); ret = do_cycle();

View file

@ -75,22 +75,22 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
config->get_engine_vfilter(engine, vfilter); _srs_config->get_engine_vfilter(engine, vfilter);
vcodec = config->get_engine_vcodec(engine); vcodec = _srs_config->get_engine_vcodec(engine);
vbitrate = config->get_engine_vbitrate(engine); vbitrate = _srs_config->get_engine_vbitrate(engine);
vfps = config->get_engine_vfps(engine); vfps = _srs_config->get_engine_vfps(engine);
vwidth = config->get_engine_vwidth(engine); vwidth = _srs_config->get_engine_vwidth(engine);
vheight = config->get_engine_vheight(engine); vheight = _srs_config->get_engine_vheight(engine);
vthreads = config->get_engine_vthreads(engine); vthreads = _srs_config->get_engine_vthreads(engine);
vprofile = config->get_engine_vprofile(engine); vprofile = _srs_config->get_engine_vprofile(engine);
vpreset = config->get_engine_vpreset(engine); vpreset = _srs_config->get_engine_vpreset(engine);
config->get_engine_vparams(engine, vparams); _srs_config->get_engine_vparams(engine, vparams);
acodec = config->get_engine_acodec(engine); acodec = _srs_config->get_engine_acodec(engine);
abitrate = config->get_engine_abitrate(engine); abitrate = _srs_config->get_engine_abitrate(engine);
asample_rate = config->get_engine_asample_rate(engine); asample_rate = _srs_config->get_engine_asample_rate(engine);
achannels = config->get_engine_achannels(engine); achannels = _srs_config->get_engine_achannels(engine);
config->get_engine_aparams(engine, aparams); _srs_config->get_engine_aparams(engine, aparams);
output = config->get_engine_output(engine); output = _srs_config->get_engine_output(engine);
// ensure the size is even. // ensure the size is even.
vwidth -= vwidth % 2; vwidth -= vwidth % 2;
@ -116,7 +116,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine)
output = srs_replace(output, "[engine]", engine->arg0()); output = srs_replace(output, "[engine]", engine->arg0());
// write ffmpeg info to log file. // write ffmpeg info to log file.
log_file = config->get_log_dir(); log_file = _srs_config->get_log_dir();
log_file += "/"; log_file += "/";
log_file += "encoder"; log_file += "encoder";
log_file += "-"; log_file += "-";
@ -590,7 +590,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req)
// parse vhost scope engines // parse vhost scope engines
std::string scope = ""; 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) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) {
srs_error("parse vhost scope=%s transcode engines failed. " srs_error("parse vhost scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret); "ret=%d", scope.c_str(), ret);
@ -599,7 +599,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req)
} }
// parse app scope engines // parse app scope engines
scope = req->app; 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) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) {
srs_error("parse app scope=%s transcode engines failed. " srs_error("parse app scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret); "ret=%d", scope.c_str(), ret);
@ -609,7 +609,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req)
// parse stream scope engines // parse stream scope engines
scope += "/"; scope += "/";
scope += req->stream; 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) { if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) {
srs_error("parse stream scope=%s transcode engines failed. " srs_error("parse stream scope=%s transcode engines failed. "
"ret=%d", scope.c_str(), ret); "ret=%d", scope.c_str(), ret);
@ -627,14 +627,14 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf)
srs_assert(conf); srs_assert(conf);
// enabled // enabled
if (!config->get_transcode_enabled(conf)) { if (!_srs_config->get_transcode_enabled(conf)) {
srs_trace("ignore the disabled transcode: %s", srs_trace("ignore the disabled transcode: %s",
conf->arg0().c_str()); conf->arg0().c_str());
return ret; return ret;
} }
// ffmpeg // ffmpeg
std::string ffmpeg_bin = config->get_transcode_ffmpeg(conf); std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf);
if (ffmpeg_bin.empty()) { if (ffmpeg_bin.empty()) {
srs_trace("ignore the empty ffmpeg transcode: %s", srs_trace("ignore the empty ffmpeg transcode: %s",
conf->arg0().c_str()); conf->arg0().c_str());
@ -643,7 +643,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf)
// get all engines. // get all engines.
std::vector<SrsConfDirective*> engines; std::vector<SrsConfDirective*> engines;
config->get_transcode_engines(conf, engines); _srs_config->get_transcode_engines(conf, engines);
if (engines.empty()) { if (engines.empty()) {
srs_trace("ignore the empty transcode engine: %s", srs_trace("ignore the empty transcode engine: %s",
conf->arg0().c_str()); conf->arg0().c_str());
@ -653,7 +653,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf)
// create engine // create engine
for (int i = 0; i < (int)engines.size(); i++) { for (int i = 0; i < (int)engines.size(); i++) {
SrsConfDirective* engine = engines[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", srs_trace("ignore the diabled transcode engine: %s %s",
conf->arg0().c_str(), engine->arg0().c_str()); conf->arg0().c_str(), engine->arg0().c_str());
continue; continue;

View file

@ -1149,18 +1149,18 @@ int SrsHls::on_publish(SrsRequest* req)
std::string stream = req->stream; std::string stream = req->stream;
std::string app = req->app; std::string app = req->app;
if (!config->get_hls_enabled(vhost)) { if (!_srs_config->get_hls_enabled(vhost)) {
return ret; return ret;
} }
// if enabled, open the muxer. // if enabled, open the muxer.
hls_enabled = true; hls_enabled = true;
int hls_fragment = config->get_hls_fragment(vhost); int hls_fragment = _srs_config->get_hls_fragment(vhost);
int hls_window = config->get_hls_window(vhost); int hls_window = _srs_config->get_hls_window(vhost);
// get the hls path config // 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 // open muxer
if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {

View file

@ -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 <srs_core_log.hpp>
#include <stdarg.h>
#include <sys/time.h>
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);
}

View file

@ -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 <srs_core_log.hpp>
*/
#include <srs_core.hpp>
#include <srs_core_st.hpp>
#include <srs_kernel_log.hpp>
#include <string.h>
#include <string>
#include <map>
/**
* st thread context, get_id will get the st-thread id,
* which identify the client.
*/
class SrsThreadContext : public ISrsThreadContext
{
private:
std::map<st_thread_t, int> 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

View file

@ -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 <srs_core_log_context.hpp>
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();
}

View file

@ -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 <srs_core_log_context.hpp>
*/
#include <srs_core.hpp>
#include <srs_core_st.hpp>
#include <srs_kernel_log.hpp>
#include <string.h>
#include <sys/time.h>
#include <string>
#include <map>
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<st_thread_t, int> cache;
public:
SrsLogContext();
virtual ~SrsLogContext();
public:
virtual void generate_id();
virtual int get_id();
public:
virtual const char* format_time();
};
#endif

View file

@ -46,33 +46,33 @@ struct SrsStageInfo : public ISrsReloadHandler
update_print_time(); update_print_time();
config->subscribe(this); _srs_config->subscribe(this);
} }
virtual ~SrsStageInfo() virtual ~SrsStageInfo()
{ {
config->unsubscribe(this); _srs_config->unsubscribe(this);
} }
void update_print_time() void update_print_time()
{ {
switch (stage_id) { switch (stage_id) {
case SRS_STAGE_PLAY_USER: { 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; break;
} }
case SRS_STAGE_PUBLISH_USER: { 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; break;
} }
case SRS_STAGE_FORWARDER: { case SRS_STAGE_FORWARDER: {
pithy_print_time_ms = config->get_pithy_print_forwarder(); pithy_print_time_ms = _srs_config->get_pithy_print_forwarder();
break; break;
} }
case SRS_STAGE_ENCODER: { case SRS_STAGE_ENCODER: {
pithy_print_time_ms = config->get_pithy_print_encoder(); pithy_print_time_ms = _srs_config->get_pithy_print_encoder();
break; break;
} }
case SRS_STAGE_HLS: { case SRS_STAGE_HLS: {
pithy_print_time_ms = config->get_pithy_print_hls(); pithy_print_time_ms = _srs_config->get_pithy_print_hls();
break; break;
} }
default: { default: {

View file

@ -151,13 +151,13 @@ SrsServer::SrsServer()
{ {
signal_reload = false; signal_reload = false;
srs_assert(config); srs_assert(_srs_config);
config->subscribe(this); _srs_config->subscribe(this);
} }
SrsServer::~SrsServer() SrsServer::~SrsServer()
{ {
config->unsubscribe(this); _srs_config->unsubscribe(this);
if (true) { if (true) {
std::vector<SrsConnection*>::iterator it; std::vector<SrsConnection*>::iterator it;
@ -191,7 +191,7 @@ int SrsServer::initialize()
srs_verbose("st_init success"); srs_verbose("st_init success");
// set current log id. // set current log id.
log_context->generate_id(); _srs_context->generate_id();
srs_info("log set id success"); srs_info("log set id success");
return ret; return ret;
@ -204,7 +204,7 @@ int SrsServer::listen()
SrsConfDirective* conf = NULL; SrsConfDirective* conf = NULL;
// stream service port. // stream service port.
conf = config->get_listen(); conf = _srs_config->get_listen();
srs_assert(conf); srs_assert(conf);
close_listeners(); close_listeners();
@ -236,7 +236,7 @@ int SrsServer::cycle()
signal_reload = false; signal_reload = false;
srs_info("get signal reload, to reload the config."); 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); srs_error("reload config failed. ret=%d", ret);
return ret; return ret;
} }
@ -285,7 +285,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
{ {
int ret = ERROR_SUCCESS; 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) { if ((int)conns.size() >= max_connections) {
int fd = st_netfd_fileno(client_stfd); int fd = st_netfd_fileno(client_stfd);
@ -322,9 +322,3 @@ int SrsServer::on_reload_listen()
{ {
return listen(); return listen();
} }
SrsServer* _server()
{
static SrsServer server;
return &server;
}

View file

@ -88,7 +88,5 @@ private:
public: public:
virtual int on_reload_listen(); virtual int on_reload_listen();
}; };
SrsServer* _server();
#endif #endif

View file

@ -423,12 +423,12 @@ SrsSource::SrsSource(SrsRequest* _req)
gop_cache = new SrsGopCache(); gop_cache = new SrsGopCache();
config->subscribe(this); _srs_config->subscribe(this);
} }
SrsSource::~SrsSource() SrsSource::~SrsSource()
{ {
config->unsubscribe(this); _srs_config->unsubscribe(this);
if (true) { if (true) {
std::vector<SrsConsumer*>::iterator it; std::vector<SrsConsumer*>::iterator it;
@ -473,7 +473,7 @@ int SrsSource::on_reload_gop_cache(string vhost)
} }
// gop cache changed. // 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", srs_trace("vhost %s gop_cache changed to %d, source url=%s",
vhost.c_str(), enabled_cache, req->get_stream_url().c_str()); 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; return ret;
} }
double queue_size = config->get_queue_length(req->vhost); double queue_size = _srs_config->get_queue_length(req->vhost);
if (true) { if (true) {
std::vector<SrsConsumer*>::iterator it; std::vector<SrsConsumer*>::iterator it;
@ -913,7 +913,7 @@ void SrsSource::on_unpublish()
consumer = new SrsConsumer(this); consumer = new SrsConsumer(this);
consumers.push_back(consumer); 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); consumer->set_queue_size(queue_size);
if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) { 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; 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++) { for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_server = conf->args.at(i); std::string forward_server = conf->args.at(i);
SrsForwarder* forwarder = new SrsForwarder(this); SrsForwarder* forwarder = new SrsForwarder(this);
forwarders.push_back(forwarder); 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); forwarder->set_queue_size(queue_size);
if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) { if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) {

View file

@ -113,7 +113,7 @@ void SrsThread::thread_cycle()
srs_assert(handler); srs_assert(handler);
log_context->generate_id(); _srs_context->generate_id();
srs_trace("thread cycle start"); srs_trace("thread cycle start");
handler->on_end_cycle(); handler->on_end_cycle();

View file

@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// current release version // current release version
#define RTMP_SIG_SRS_VERSION "0.9.7" #define RTMP_SIG_SRS_VERSION "0.9.8"
// server info. // server info.
#define RTMP_SIG_SRS_KEY "srs" #define RTMP_SIG_SRS_KEY "srs"
#define RTMP_SIG_SRS_ROLE "origin server" #define RTMP_SIG_SRS_ROLE "origin server"

View file

@ -23,11 +23,48 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_log.hpp> #include <srs_kernel_log.hpp>
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;
}

View file

@ -35,43 +35,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
// 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: public:
ILogContext(); ISrsLog();
virtual ~ILogContext(); virtual ~ISrsLog();
public: public:
virtual void generate_id() = 0; /**
virtual int get_id() = 0; * log for verbose, very verbose information.
public: */
virtual const char* format_time() = 0; 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. // user must implements the LogContext and define a global instance.
extern ILogContext* log_context; extern ISrsThreadContext* _srs_context;
// donot print method // donot print method
#if 0 #if 1
#define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
#define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
#define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") #define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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") #define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
// use __FUNCTION__ to print c method // use __FUNCTION__ to print c method
#elif 1 #elif 0
#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_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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") #define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
// use __PRETTY_FUNCTION__ to print c++ class:method // use __PRETTY_FUNCTION__ to print c++ class:method
#else #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_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#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_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
#endif #endif
#if 1 #if 1

View file

@ -35,6 +35,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>
#include <srs_core_socket.hpp> #include <srs_core_socket.hpp>
#include <srs_core_config.hpp>
#include <srs_core_log.hpp>
#include <srs_core_server.hpp>
// kernel module.
ISrsLog* _srs_log = new SrsFastLog();
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// app module.
SrsConfig* _srs_config = NULL;
SrsServer* _srs_server = NULL;
#include <st.h> #include <st.h>

View file

@ -25,6 +25,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_core_server.hpp> #include <srs_core_server.hpp>
#include <srs_core_config.hpp> #include <srs_core_config.hpp>
#include <srs_core_log.hpp>
// 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 <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
@ -32,7 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
void handler(int signo) void handler(int signo)
{ {
srs_trace("get a signal, signo=%d", signo); srs_trace("get a signal, signo=%d", signo);
_server()->on_signal(signo); _srs_server->on_signal(signo);
} }
int main(int argc, char** argv){ int main(int argc, char** argv){
@ -40,21 +48,21 @@ int main(int argc, char** argv){
signal(SIGNAL_RELOAD, handler); 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; return ret;
} }
if ((ret = _server()->initialize()) != ERROR_SUCCESS) { if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) {
return ret; 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; return ret;
} }
if ((ret = _server()->cycle()) != ERROR_SUCCESS) { if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
return ret; return ret;
} }

View file

@ -52,8 +52,8 @@ file
..\app\srs_core_hls.cpp, ..\app\srs_core_hls.cpp,
..\app\srs_core_http.hpp, ..\app\srs_core_http.hpp,
..\app\srs_core_http.cpp, ..\app\srs_core_http.cpp,
..\app\srs_core_log_context.hpp, ..\app\srs_core_log.hpp,
..\app\srs_core_log_context.cpp, ..\app\srs_core_log.cpp,
..\app\srs_core_refer.hpp, ..\app\srs_core_refer.hpp,
..\app\srs_core_refer.cpp, ..\app\srs_core_refer.cpp,
..\app\srs_core_pithy_print.hpp, ..\app\srs_core_pithy_print.hpp,