正在显示
22 个修改的文件
包含
468 行增加
和
224 行删除
| @@ -153,7 +153,7 @@ MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") | @@ -153,7 +153,7 @@ MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") | ||
| 153 | ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) | 153 | ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) |
| 154 | MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_socket" "srs_core_source" | 154 | MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_socket" "srs_core_source" |
| 155 | "srs_core_codec" "srs_core_refer" "srs_core_hls" "srs_core_forward" "srs_core_encoder" | 155 | "srs_core_codec" "srs_core_refer" "srs_core_hls" "srs_core_forward" "srs_core_encoder" |
| 156 | - "srs_core_http" "srs_core_thread" "srs_core_bandwidth" "srs_core_st" "srs_core_log_context" | 156 | + "srs_core_http" "srs_core_thread" "srs_core_bandwidth" "srs_core_st" "srs_core_log" |
| 157 | "srs_core_config" "srs_core_pithy_print") | 157 | "srs_core_config" "srs_core_pithy_print") |
| 158 | MODULE_DIR="src/app" . auto/modules.sh | 158 | MODULE_DIR="src/app" . auto/modules.sh |
| 159 | APP_OBJS="${MODULE_OBJS[@]}" | 159 | APP_OBJS="${MODULE_OBJS[@]}" |
| @@ -50,12 +50,12 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt | @@ -50,12 +50,12 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt | ||
| 50 | rtmp = _rtmp; | 50 | rtmp = _rtmp; |
| 51 | req = _req; | 51 | req = _req; |
| 52 | 52 | ||
| 53 | - if (!config->get_bw_check_enabled(req->vhost)) { | 53 | + if (!_srs_config->get_bw_check_enabled(req->vhost)) { |
| 54 | return ret; | 54 | return ret; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | // validate the bandwidth check key | 57 | // validate the bandwidth check key |
| 58 | - std::string key = "key=" + config->get_bw_check_key(req->vhost); | 58 | + std::string key = "key=" + _srs_config->get_bw_check_key(req->vhost); |
| 59 | if (req->tcUrl.find(key) == std::string::npos) { | 59 | if (req->tcUrl.find(key) == std::string::npos) { |
| 60 | ret = ERROR_SYSTEM_BANDWIDTH_KEY; | 60 | ret = ERROR_SYSTEM_BANDWIDTH_KEY; |
| 61 | srs_error("check the vhost=%s %s failed, tcUrl=%s, ret=%d", | 61 | 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 | @@ -68,7 +68,7 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rt | ||
| 68 | // if client request check in the window(specifeid by interval), | 68 | // if client request check in the window(specifeid by interval), |
| 69 | // directly reject the request. | 69 | // directly reject the request. |
| 70 | static int64_t last_check_time = 0; | 70 | static int64_t last_check_time = 0; |
| 71 | - int interval_ms = config->get_bw_check_interval_ms(req->vhost); | 71 | + int interval_ms = _srs_config->get_bw_check_interval_ms(req->vhost); |
| 72 | 72 | ||
| 73 | int64_t time_now = srs_get_system_time_ms(); | 73 | int64_t time_now = srs_get_system_time_ms(); |
| 74 | // reject the connection in the interval window. | 74 | // reject the connection in the interval window. |
| @@ -149,7 +149,7 @@ int SrsBandwidth::do_bandwidth_check() | @@ -149,7 +149,7 @@ int SrsBandwidth::do_bandwidth_check() | ||
| 149 | int publish_actual_duration_ms = 0; | 149 | int publish_actual_duration_ms = 0; |
| 150 | int publish_bytes = 0; | 150 | int publish_bytes = 0; |
| 151 | 151 | ||
| 152 | - int limit_kbps = config->get_bw_check_limit_kbps(req->vhost); | 152 | + int limit_kbps = _srs_config->get_bw_check_limit_kbps(req->vhost); |
| 153 | 153 | ||
| 154 | int64_t start_time = srs_get_system_time_ms(); | 154 | int64_t start_time = srs_get_system_time_ms(); |
| 155 | 155 |
| @@ -57,12 +57,12 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) | @@ -57,12 +57,12 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) | ||
| 57 | #endif | 57 | #endif |
| 58 | bandwidth = new SrsBandwidth(); | 58 | bandwidth = new SrsBandwidth(); |
| 59 | 59 | ||
| 60 | - config->subscribe(this); | 60 | + _srs_config->subscribe(this); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | SrsClient::~SrsClient() | 63 | SrsClient::~SrsClient() |
| 64 | { | 64 | { |
| 65 | - config->unsubscribe(this); | 65 | + _srs_config->unsubscribe(this); |
| 66 | 66 | ||
| 67 | srs_freepa(ip); | 67 | srs_freepa(ip); |
| 68 | srs_freep(req); | 68 | srs_freep(req); |
| @@ -104,7 +104,7 @@ int SrsClient::do_cycle() | @@ -104,7 +104,7 @@ int SrsClient::do_cycle() | ||
| 104 | srs_verbose("rtmp connect app success"); | 104 | srs_verbose("rtmp connect app success"); |
| 105 | 105 | ||
| 106 | // discovery vhost, resolve the vhost from config | 106 | // discovery vhost, resolve the vhost from config |
| 107 | - SrsConfDirective* parsed_vhost = config->get_vhost(req->vhost); | 107 | + SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost); |
| 108 | if (parsed_vhost) { | 108 | if (parsed_vhost) { |
| 109 | req->vhost = parsed_vhost->arg0(); | 109 | req->vhost = parsed_vhost->arg0(); |
| 110 | } | 110 | } |
| @@ -173,7 +173,7 @@ int SrsClient::service_cycle() | @@ -173,7 +173,7 @@ int SrsClient::service_cycle() | ||
| 173 | srs_verbose("set peer bandwidth success"); | 173 | srs_verbose("set peer bandwidth success"); |
| 174 | 174 | ||
| 175 | // do bandwidth test if connect to the vhost which is for bandwidth check. | 175 | // do bandwidth test if connect to the vhost which is for bandwidth check. |
| 176 | - if (config->get_bw_check_enabled(req->vhost)) { | 176 | + if (_srs_config->get_bw_check_enabled(req->vhost)) { |
| 177 | return bandwidth->bandwidth_test(req, stfd, rtmp); | 177 | return bandwidth->bandwidth_test(req, stfd, rtmp); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| @@ -237,7 +237,7 @@ int SrsClient::stream_service_cycle() | @@ -237,7 +237,7 @@ int SrsClient::stream_service_cycle() | ||
| 237 | rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US); | 237 | rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US); |
| 238 | 238 | ||
| 239 | // set chunk size to larger. | 239 | // set chunk size to larger. |
| 240 | - int chunk_size = config->get_chunk_size(req->vhost); | 240 | + int chunk_size = _srs_config->get_chunk_size(req->vhost); |
| 241 | if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { | 241 | if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { |
| 242 | srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); | 242 | srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); |
| 243 | return ret; | 243 | return ret; |
| @@ -258,7 +258,7 @@ int SrsClient::stream_service_cycle() | @@ -258,7 +258,7 @@ int SrsClient::stream_service_cycle() | ||
| 258 | return ret; | 258 | return ret; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | - bool enabled_cache = config->get_gop_cache(req->vhost); | 261 | + bool enabled_cache = _srs_config->get_gop_cache(req->vhost); |
| 262 | srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); | 262 | srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); |
| 263 | source->set_cache(enabled_cache); | 263 | source->set_cache(enabled_cache); |
| 264 | 264 | ||
| @@ -329,14 +329,14 @@ int SrsClient::check_vhost() | @@ -329,14 +329,14 @@ int SrsClient::check_vhost() | ||
| 329 | 329 | ||
| 330 | srs_assert(req != NULL); | 330 | srs_assert(req != NULL); |
| 331 | 331 | ||
| 332 | - SrsConfDirective* vhost = config->get_vhost(req->vhost); | 332 | + SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost); |
| 333 | if (vhost == NULL) { | 333 | if (vhost == NULL) { |
| 334 | ret = ERROR_RTMP_VHOST_NOT_FOUND; | 334 | ret = ERROR_RTMP_VHOST_NOT_FOUND; |
| 335 | srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret); | 335 | srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret); |
| 336 | return ret; | 336 | return ret; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | - if (!config->get_vhost_enabled(req->vhost)) { | 339 | + if (!_srs_config->get_vhost_enabled(req->vhost)) { |
| 340 | ret = ERROR_RTMP_VHOST_NOT_FOUND; | 340 | ret = ERROR_RTMP_VHOST_NOT_FOUND; |
| 341 | srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret); | 341 | srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret); |
| 342 | return ret; | 342 | return ret; |
| @@ -347,7 +347,7 @@ int SrsClient::check_vhost() | @@ -347,7 +347,7 @@ int SrsClient::check_vhost() | ||
| 347 | req->vhost = vhost->arg0(); | 347 | req->vhost = vhost->arg0(); |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | - if ((ret = refer->check(req->pageUrl, config->get_refer(req->vhost))) != ERROR_SUCCESS) { | 350 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) { |
| 351 | srs_error("check refer failed. ret=%d", ret); | 351 | srs_error("check refer failed. ret=%d", ret); |
| 352 | return ret; | 352 | return ret; |
| 353 | } | 353 | } |
| @@ -364,7 +364,7 @@ int SrsClient::playing(SrsSource* source) | @@ -364,7 +364,7 @@ int SrsClient::playing(SrsSource* source) | ||
| 364 | { | 364 | { |
| 365 | int ret = ERROR_SUCCESS; | 365 | int ret = ERROR_SUCCESS; |
| 366 | 366 | ||
| 367 | - if ((ret = refer->check(req->pageUrl, config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { | 367 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) { |
| 368 | srs_error("check play_refer failed. ret=%d", ret); | 368 | srs_error("check play_refer failed. ret=%d", ret); |
| 369 | return ret; | 369 | return ret; |
| 370 | } | 370 | } |
| @@ -451,7 +451,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle) | @@ -451,7 +451,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle) | ||
| 451 | { | 451 | { |
| 452 | int ret = ERROR_SUCCESS; | 452 | int ret = ERROR_SUCCESS; |
| 453 | 453 | ||
| 454 | - if ((ret = refer->check(req->pageUrl, config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { | 454 | + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) { |
| 455 | srs_error("check publish_refer failed. ret=%d", ret); | 455 | srs_error("check publish_refer failed. ret=%d", ret); |
| 456 | return ret; | 456 | return ret; |
| 457 | } | 457 | } |
| @@ -651,7 +651,7 @@ int SrsClient::on_connect() | @@ -651,7 +651,7 @@ int SrsClient::on_connect() | ||
| 651 | 651 | ||
| 652 | #ifdef SRS_HTTP | 652 | #ifdef SRS_HTTP |
| 653 | // HTTP: on_connect | 653 | // HTTP: on_connect |
| 654 | - SrsConfDirective* on_connect = config->get_vhost_on_connect(req->vhost); | 654 | + SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost); |
| 655 | if (!on_connect) { | 655 | if (!on_connect) { |
| 656 | srs_info("ignore the empty http callback: on_connect"); | 656 | srs_info("ignore the empty http callback: on_connect"); |
| 657 | return ret; | 657 | return ret; |
| @@ -674,7 +674,7 @@ void SrsClient::on_close() | @@ -674,7 +674,7 @@ void SrsClient::on_close() | ||
| 674 | #ifdef SRS_HTTP | 674 | #ifdef SRS_HTTP |
| 675 | // whatever the ret code, notify the api hooks. | 675 | // whatever the ret code, notify the api hooks. |
| 676 | // HTTP: on_close | 676 | // HTTP: on_close |
| 677 | - SrsConfDirective* on_close = config->get_vhost_on_close(req->vhost); | 677 | + SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost); |
| 678 | if (!on_close) { | 678 | if (!on_close) { |
| 679 | srs_info("ignore the empty http callback: on_close"); | 679 | srs_info("ignore the empty http callback: on_close"); |
| 680 | return; | 680 | return; |
| @@ -693,7 +693,7 @@ int SrsClient::on_publish() | @@ -693,7 +693,7 @@ int SrsClient::on_publish() | ||
| 693 | 693 | ||
| 694 | #ifdef SRS_HTTP | 694 | #ifdef SRS_HTTP |
| 695 | // HTTP: on_publish | 695 | // HTTP: on_publish |
| 696 | - SrsConfDirective* on_publish = config->get_vhost_on_publish(req->vhost); | 696 | + SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost); |
| 697 | if (!on_publish) { | 697 | if (!on_publish) { |
| 698 | srs_info("ignore the empty http callback: on_publish"); | 698 | srs_info("ignore the empty http callback: on_publish"); |
| 699 | return ret; | 699 | return ret; |
| @@ -716,7 +716,7 @@ void SrsClient::on_unpublish() | @@ -716,7 +716,7 @@ void SrsClient::on_unpublish() | ||
| 716 | #ifdef SRS_HTTP | 716 | #ifdef SRS_HTTP |
| 717 | // whatever the ret code, notify the api hooks. | 717 | // whatever the ret code, notify the api hooks. |
| 718 | // HTTP: on_unpublish | 718 | // HTTP: on_unpublish |
| 719 | - SrsConfDirective* on_unpublish = config->get_vhost_on_unpublish(req->vhost); | 719 | + SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost); |
| 720 | if (!on_unpublish) { | 720 | if (!on_unpublish) { |
| 721 | srs_info("ignore the empty http callback: on_unpublish"); | 721 | srs_info("ignore the empty http callback: on_unpublish"); |
| 722 | return; | 722 | return; |
| @@ -735,7 +735,7 @@ int SrsClient::on_play() | @@ -735,7 +735,7 @@ int SrsClient::on_play() | ||
| 735 | 735 | ||
| 736 | #ifdef SRS_HTTP | 736 | #ifdef SRS_HTTP |
| 737 | // HTTP: on_play | 737 | // HTTP: on_play |
| 738 | - SrsConfDirective* on_play = config->get_vhost_on_play(req->vhost); | 738 | + SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost); |
| 739 | if (!on_play) { | 739 | if (!on_play) { |
| 740 | srs_info("ignore the empty http callback: on_play"); | 740 | srs_info("ignore the empty http callback: on_play"); |
| 741 | return ret; | 741 | return ret; |
| @@ -758,7 +758,7 @@ void SrsClient::on_stop() | @@ -758,7 +758,7 @@ void SrsClient::on_stop() | ||
| 758 | #ifdef SRS_HTTP | 758 | #ifdef SRS_HTTP |
| 759 | // whatever the ret code, notify the api hooks. | 759 | // whatever the ret code, notify the api hooks. |
| 760 | // HTTP: on_stop | 760 | // HTTP: on_stop |
| 761 | - SrsConfDirective* on_stop = config->get_vhost_on_stop(req->vhost); | 761 | + SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost); |
| 762 | if (!on_stop) { | 762 | if (!on_stop) { |
| 763 | srs_info("ignore the empty http callback: on_stop"); | 763 | srs_info("ignore the empty http callback: on_stop"); |
| 764 | return; | 764 | return; |
| @@ -429,8 +429,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg | @@ -429,8 +429,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg | ||
| 429 | return ret; | 429 | return ret; |
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | -SrsConfig* config = new SrsConfig(); | ||
| 433 | - | ||
| 434 | SrsConfig::SrsConfig() | 432 | SrsConfig::SrsConfig() |
| 435 | { | 433 | { |
| 436 | show_help = false; | 434 | show_help = false; |
| @@ -180,6 +180,6 @@ public: | @@ -180,6 +180,6 @@ public: | ||
| 180 | bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); | 180 | bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); |
| 181 | 181 | ||
| 182 | // global config | 182 | // global config |
| 183 | -extern SrsConfig* config; | 183 | +extern SrsConfig* _srs_config; |
| 184 | 184 | ||
| 185 | #endif | 185 | #endif |
| @@ -57,8 +57,8 @@ void SrsConnection::cycle() | @@ -57,8 +57,8 @@ void SrsConnection::cycle() | ||
| 57 | { | 57 | { |
| 58 | int ret = ERROR_SUCCESS; | 58 | int ret = ERROR_SUCCESS; |
| 59 | 59 | ||
| 60 | - log_context->generate_id(); | ||
| 61 | - connection_id = log_context->get_id(); | 60 | + _srs_context->generate_id(); |
| 61 | + connection_id = _srs_context->get_id(); | ||
| 62 | 62 | ||
| 63 | ret = do_cycle(); | 63 | ret = do_cycle(); |
| 64 | 64 |
| @@ -75,22 +75,22 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | @@ -75,22 +75,22 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | ||
| 75 | { | 75 | { |
| 76 | int ret = ERROR_SUCCESS; | 76 | int ret = ERROR_SUCCESS; |
| 77 | 77 | ||
| 78 | - config->get_engine_vfilter(engine, vfilter); | ||
| 79 | - vcodec = config->get_engine_vcodec(engine); | ||
| 80 | - vbitrate = config->get_engine_vbitrate(engine); | ||
| 81 | - vfps = config->get_engine_vfps(engine); | ||
| 82 | - vwidth = config->get_engine_vwidth(engine); | ||
| 83 | - vheight = config->get_engine_vheight(engine); | ||
| 84 | - vthreads = config->get_engine_vthreads(engine); | ||
| 85 | - vprofile = config->get_engine_vprofile(engine); | ||
| 86 | - vpreset = config->get_engine_vpreset(engine); | ||
| 87 | - config->get_engine_vparams(engine, vparams); | ||
| 88 | - acodec = config->get_engine_acodec(engine); | ||
| 89 | - abitrate = config->get_engine_abitrate(engine); | ||
| 90 | - asample_rate = config->get_engine_asample_rate(engine); | ||
| 91 | - achannels = config->get_engine_achannels(engine); | ||
| 92 | - config->get_engine_aparams(engine, aparams); | ||
| 93 | - output = config->get_engine_output(engine); | 78 | + _srs_config->get_engine_vfilter(engine, vfilter); |
| 79 | + vcodec = _srs_config->get_engine_vcodec(engine); | ||
| 80 | + vbitrate = _srs_config->get_engine_vbitrate(engine); | ||
| 81 | + vfps = _srs_config->get_engine_vfps(engine); | ||
| 82 | + vwidth = _srs_config->get_engine_vwidth(engine); | ||
| 83 | + vheight = _srs_config->get_engine_vheight(engine); | ||
| 84 | + vthreads = _srs_config->get_engine_vthreads(engine); | ||
| 85 | + vprofile = _srs_config->get_engine_vprofile(engine); | ||
| 86 | + vpreset = _srs_config->get_engine_vpreset(engine); | ||
| 87 | + _srs_config->get_engine_vparams(engine, vparams); | ||
| 88 | + acodec = _srs_config->get_engine_acodec(engine); | ||
| 89 | + abitrate = _srs_config->get_engine_abitrate(engine); | ||
| 90 | + asample_rate = _srs_config->get_engine_asample_rate(engine); | ||
| 91 | + achannels = _srs_config->get_engine_achannels(engine); | ||
| 92 | + _srs_config->get_engine_aparams(engine, aparams); | ||
| 93 | + output = _srs_config->get_engine_output(engine); | ||
| 94 | 94 | ||
| 95 | // ensure the size is even. | 95 | // ensure the size is even. |
| 96 | vwidth -= vwidth % 2; | 96 | vwidth -= vwidth % 2; |
| @@ -116,7 +116,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | @@ -116,7 +116,7 @@ int SrsFFMPEG::initialize(SrsRequest* req, SrsConfDirective* engine) | ||
| 116 | output = srs_replace(output, "[engine]", engine->arg0()); | 116 | output = srs_replace(output, "[engine]", engine->arg0()); |
| 117 | 117 | ||
| 118 | // write ffmpeg info to log file. | 118 | // write ffmpeg info to log file. |
| 119 | - log_file = config->get_log_dir(); | 119 | + log_file = _srs_config->get_log_dir(); |
| 120 | log_file += "/"; | 120 | log_file += "/"; |
| 121 | log_file += "encoder"; | 121 | log_file += "encoder"; |
| 122 | log_file += "-"; | 122 | log_file += "-"; |
| @@ -590,7 +590,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | @@ -590,7 +590,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | ||
| 590 | 590 | ||
| 591 | // parse vhost scope engines | 591 | // parse vhost scope engines |
| 592 | std::string scope = ""; | 592 | std::string scope = ""; |
| 593 | - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { | 593 | + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { |
| 594 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { | 594 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { |
| 595 | srs_error("parse vhost scope=%s transcode engines failed. " | 595 | srs_error("parse vhost scope=%s transcode engines failed. " |
| 596 | "ret=%d", scope.c_str(), ret); | 596 | "ret=%d", scope.c_str(), ret); |
| @@ -599,7 +599,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | @@ -599,7 +599,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | ||
| 599 | } | 599 | } |
| 600 | // parse app scope engines | 600 | // parse app scope engines |
| 601 | scope = req->app; | 601 | scope = req->app; |
| 602 | - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { | 602 | + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { |
| 603 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { | 603 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { |
| 604 | srs_error("parse app scope=%s transcode engines failed. " | 604 | srs_error("parse app scope=%s transcode engines failed. " |
| 605 | "ret=%d", scope.c_str(), ret); | 605 | "ret=%d", scope.c_str(), ret); |
| @@ -609,7 +609,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | @@ -609,7 +609,7 @@ int SrsEncoder::parse_scope_engines(SrsRequest* req) | ||
| 609 | // parse stream scope engines | 609 | // parse stream scope engines |
| 610 | scope += "/"; | 610 | scope += "/"; |
| 611 | scope += req->stream; | 611 | scope += req->stream; |
| 612 | - if ((conf = config->get_transcode(req->vhost, scope)) != NULL) { | 612 | + if ((conf = _srs_config->get_transcode(req->vhost, scope)) != NULL) { |
| 613 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { | 613 | if ((ret = parse_transcode(req, conf)) != ERROR_SUCCESS) { |
| 614 | srs_error("parse stream scope=%s transcode engines failed. " | 614 | srs_error("parse stream scope=%s transcode engines failed. " |
| 615 | "ret=%d", scope.c_str(), ret); | 615 | "ret=%d", scope.c_str(), ret); |
| @@ -627,14 +627,14 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | @@ -627,14 +627,14 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | ||
| 627 | srs_assert(conf); | 627 | srs_assert(conf); |
| 628 | 628 | ||
| 629 | // enabled | 629 | // enabled |
| 630 | - if (!config->get_transcode_enabled(conf)) { | 630 | + if (!_srs_config->get_transcode_enabled(conf)) { |
| 631 | srs_trace("ignore the disabled transcode: %s", | 631 | srs_trace("ignore the disabled transcode: %s", |
| 632 | conf->arg0().c_str()); | 632 | conf->arg0().c_str()); |
| 633 | return ret; | 633 | return ret; |
| 634 | } | 634 | } |
| 635 | 635 | ||
| 636 | // ffmpeg | 636 | // ffmpeg |
| 637 | - std::string ffmpeg_bin = config->get_transcode_ffmpeg(conf); | 637 | + std::string ffmpeg_bin = _srs_config->get_transcode_ffmpeg(conf); |
| 638 | if (ffmpeg_bin.empty()) { | 638 | if (ffmpeg_bin.empty()) { |
| 639 | srs_trace("ignore the empty ffmpeg transcode: %s", | 639 | srs_trace("ignore the empty ffmpeg transcode: %s", |
| 640 | conf->arg0().c_str()); | 640 | conf->arg0().c_str()); |
| @@ -643,7 +643,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | @@ -643,7 +643,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | ||
| 643 | 643 | ||
| 644 | // get all engines. | 644 | // get all engines. |
| 645 | std::vector<SrsConfDirective*> engines; | 645 | std::vector<SrsConfDirective*> engines; |
| 646 | - config->get_transcode_engines(conf, engines); | 646 | + _srs_config->get_transcode_engines(conf, engines); |
| 647 | if (engines.empty()) { | 647 | if (engines.empty()) { |
| 648 | srs_trace("ignore the empty transcode engine: %s", | 648 | srs_trace("ignore the empty transcode engine: %s", |
| 649 | conf->arg0().c_str()); | 649 | conf->arg0().c_str()); |
| @@ -653,7 +653,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | @@ -653,7 +653,7 @@ int SrsEncoder::parse_transcode(SrsRequest* req, SrsConfDirective* conf) | ||
| 653 | // create engine | 653 | // create engine |
| 654 | for (int i = 0; i < (int)engines.size(); i++) { | 654 | for (int i = 0; i < (int)engines.size(); i++) { |
| 655 | SrsConfDirective* engine = engines[i]; | 655 | SrsConfDirective* engine = engines[i]; |
| 656 | - if (!config->get_engine_enabled(engine)) { | 656 | + if (!_srs_config->get_engine_enabled(engine)) { |
| 657 | srs_trace("ignore the diabled transcode engine: %s %s", | 657 | srs_trace("ignore the diabled transcode engine: %s %s", |
| 658 | conf->arg0().c_str(), engine->arg0().c_str()); | 658 | conf->arg0().c_str(), engine->arg0().c_str()); |
| 659 | continue; | 659 | continue; |
| @@ -1149,18 +1149,18 @@ int SrsHls::on_publish(SrsRequest* req) | @@ -1149,18 +1149,18 @@ int SrsHls::on_publish(SrsRequest* req) | ||
| 1149 | std::string stream = req->stream; | 1149 | std::string stream = req->stream; |
| 1150 | std::string app = req->app; | 1150 | std::string app = req->app; |
| 1151 | 1151 | ||
| 1152 | - if (!config->get_hls_enabled(vhost)) { | 1152 | + if (!_srs_config->get_hls_enabled(vhost)) { |
| 1153 | return ret; | 1153 | return ret; |
| 1154 | } | 1154 | } |
| 1155 | 1155 | ||
| 1156 | // if enabled, open the muxer. | 1156 | // if enabled, open the muxer. |
| 1157 | hls_enabled = true; | 1157 | hls_enabled = true; |
| 1158 | 1158 | ||
| 1159 | - int hls_fragment = config->get_hls_fragment(vhost); | ||
| 1160 | - int hls_window = config->get_hls_window(vhost); | 1159 | + int hls_fragment = _srs_config->get_hls_fragment(vhost); |
| 1160 | + int hls_window = _srs_config->get_hls_window(vhost); | ||
| 1161 | 1161 | ||
| 1162 | // get the hls path config | 1162 | // get the hls path config |
| 1163 | - std::string hls_path = config->get_hls_path(vhost); | 1163 | + std::string hls_path = _srs_config->get_hls_path(vhost); |
| 1164 | 1164 | ||
| 1165 | // open muxer | 1165 | // open muxer |
| 1166 | if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { | 1166 | if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { |
trunk/src/app/srs_core_log.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_core_log.hpp> | ||
| 25 | + | ||
| 26 | +#include <stdarg.h> | ||
| 27 | +#include <sys/time.h> | ||
| 28 | + | ||
| 29 | +SrsThreadContext::SrsThreadContext() | ||
| 30 | +{ | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +SrsThreadContext::~SrsThreadContext() | ||
| 34 | +{ | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +void SrsThreadContext::generate_id() | ||
| 38 | +{ | ||
| 39 | + static int id = 1; | ||
| 40 | + cache[st_thread_self()] = id++; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +int SrsThreadContext::get_id() | ||
| 44 | +{ | ||
| 45 | + return cache[st_thread_self()]; | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +// the max size of a line of log. | ||
| 49 | +#define LOG_MAX_SIZE 4096 | ||
| 50 | + | ||
| 51 | +// the tail append to each log. | ||
| 52 | +#define LOG_TAIL '\n' | ||
| 53 | +// reserved for the end of log data, it must be strlen(LOG_TAIL) | ||
| 54 | +#define LOG_TAIL_SIZE 1 | ||
| 55 | + | ||
| 56 | +SrsFastLog::SrsFastLog() | ||
| 57 | +{ | ||
| 58 | + level = SrsLogLevel::Trace; | ||
| 59 | + log_data = new char[LOG_MAX_SIZE]; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +SrsFastLog::~SrsFastLog() | ||
| 63 | +{ | ||
| 64 | + srs_freepa(log_data); | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...) | ||
| 68 | +{ | ||
| 69 | + if (level > SrsLogLevel::Verbose) { | ||
| 70 | + return; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + int size = 0; | ||
| 74 | + if (!generate_header(tag, context_id, "verb", &size)) { | ||
| 75 | + return; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + va_list ap; | ||
| 79 | + va_start(ap, fmt); | ||
| 80 | + // we reserved 1 bytes for the new line. | ||
| 81 | + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | ||
| 82 | + va_end(ap); | ||
| 83 | + | ||
| 84 | + write_log(log_data, size); | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +void SrsFastLog::info(const char* tag, int context_id, const char* fmt, ...) | ||
| 88 | +{ | ||
| 89 | + if (level > SrsLogLevel::Info) { | ||
| 90 | + return; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + int size = 0; | ||
| 94 | + if (!generate_header(tag, context_id, "debug", &size)) { | ||
| 95 | + return; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + va_list ap; | ||
| 99 | + va_start(ap, fmt); | ||
| 100 | + // we reserved 1 bytes for the new line. | ||
| 101 | + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | ||
| 102 | + va_end(ap); | ||
| 103 | + | ||
| 104 | + write_log(log_data, size); | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +void SrsFastLog::trace(const char* tag, int context_id, const char* fmt, ...) | ||
| 108 | +{ | ||
| 109 | + if (level > SrsLogLevel::Trace) { | ||
| 110 | + return; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + int size = 0; | ||
| 114 | + if (!generate_header(tag, context_id, "trace", &size)) { | ||
| 115 | + return; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + va_list ap; | ||
| 119 | + va_start(ap, fmt); | ||
| 120 | + // we reserved 1 bytes for the new line. | ||
| 121 | + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | ||
| 122 | + va_end(ap); | ||
| 123 | + | ||
| 124 | + write_log(log_data, size); | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +void SrsFastLog::warn(const char* tag, int context_id, const char* fmt, ...) | ||
| 128 | +{ | ||
| 129 | + if (level > SrsLogLevel::Warn) { | ||
| 130 | + return; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + int size = 0; | ||
| 134 | + if (!generate_header(tag, context_id, "warn", &size)) { | ||
| 135 | + return; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + va_list ap; | ||
| 139 | + va_start(ap, fmt); | ||
| 140 | + // we reserved 1 bytes for the new line. | ||
| 141 | + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | ||
| 142 | + va_end(ap); | ||
| 143 | + | ||
| 144 | + write_log(log_data, size); | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | ||
| 148 | +{ | ||
| 149 | + if (level > SrsLogLevel::Error) { | ||
| 150 | + return; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + int size = 0; | ||
| 154 | + if (!generate_header(tag, context_id, "error", &size)) { | ||
| 155 | + return; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + va_list ap; | ||
| 159 | + va_start(ap, fmt); | ||
| 160 | + // we reserved 1 bytes for the new line. | ||
| 161 | + size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); | ||
| 162 | + va_end(ap); | ||
| 163 | + | ||
| 164 | + write_log(log_data, size); | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +bool SrsFastLog::generate_header(const char* tag, int context_id, const char* level_name, int* header_size) | ||
| 168 | +{ | ||
| 169 | + // clock time | ||
| 170 | + timeval tv; | ||
| 171 | + if (gettimeofday(&tv, NULL) == -1) { | ||
| 172 | + return false; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + // to calendar time | ||
| 176 | + struct tm* tm; | ||
| 177 | + if ((tm = localtime(&tv.tv_sec)) == NULL) { | ||
| 178 | + return false; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + // write log header | ||
| 182 | + int log_header_size = -1; | ||
| 183 | + | ||
| 184 | + if (tag) { | ||
| 185 | + log_header_size = snprintf(log_data, LOG_MAX_SIZE, | ||
| 186 | + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ", | ||
| 187 | + 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), | ||
| 188 | + level_name, tag, context_id, errno); | ||
| 189 | + } else { | ||
| 190 | + log_header_size = snprintf(log_data, LOG_MAX_SIZE, | ||
| 191 | + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ", | ||
| 192 | + 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), | ||
| 193 | + level_name, context_id, errno); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + if (log_header_size == -1) { | ||
| 197 | + return false; | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + // write the header size. | ||
| 201 | + *header_size = srs_min(LOG_MAX_SIZE - 1, log_header_size); | ||
| 202 | + | ||
| 203 | + return true; | ||
| 204 | +} | ||
| 205 | + | ||
| 206 | +void SrsFastLog::write_log(char* str_log, int size) | ||
| 207 | +{ | ||
| 208 | + // ensure the tail and EOF of string | ||
| 209 | + // LOG_TAIL_SIZE for the TAIL char. | ||
| 210 | + // 1 for the last char(0). | ||
| 211 | + size = srs_min(LOG_MAX_SIZE - 1 - LOG_TAIL_SIZE, size); | ||
| 212 | + | ||
| 213 | + // add some to the end of char. | ||
| 214 | + log_data[size++] = LOG_TAIL; | ||
| 215 | + log_data[size++] = 0; | ||
| 216 | + | ||
| 217 | + printf("%s", str_log); | ||
| 218 | +} |
| @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | -#ifndef SRS_CORE_LOG_CONTEXT_HPP | ||
| 25 | -#define SRS_CORE_LOG_CONTEXT_HPP | 24 | +#ifndef SRS_CORE_LOG_HPP |
| 25 | +#define SRS_CORE_LOG_HPP | ||
| 26 | 26 | ||
| 27 | /* | 27 | /* |
| 28 | -#include <srs_core_log_context.hpp> | 28 | +#include <srs_core_log.hpp> |
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
| @@ -34,37 +34,64 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,37 +34,64 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | #include <srs_kernel_log.hpp> | 34 | #include <srs_kernel_log.hpp> |
| 35 | 35 | ||
| 36 | #include <string.h> | 36 | #include <string.h> |
| 37 | -#include <sys/time.h> | ||
| 38 | 37 | ||
| 39 | #include <string> | 38 | #include <string> |
| 40 | #include <map> | 39 | #include <map> |
| 41 | 40 | ||
| 42 | -class SrsLogContext : public ILogContext | 41 | +/** |
| 42 | +* st thread context, get_id will get the st-thread id, | ||
| 43 | +* which identify the client. | ||
| 44 | +*/ | ||
| 45 | +class SrsThreadContext : public ISrsThreadContext | ||
| 43 | { | 46 | { |
| 44 | private: | 47 | private: |
| 45 | - class DateTime | ||
| 46 | - { | ||
| 47 | - private: | ||
| 48 | - // %d-%02d-%02d %02d:%02d:%02d.%03d | ||
| 49 | - #define DATE_LEN 24 | ||
| 50 | - char time_data[DATE_LEN]; | ||
| 51 | - public: | ||
| 52 | - DateTime(); | ||
| 53 | - virtual ~DateTime(); | ||
| 54 | - public: | ||
| 55 | - virtual const char* format_time(); | ||
| 56 | - }; | ||
| 57 | -private: | ||
| 58 | - DateTime time; | ||
| 59 | std::map<st_thread_t, int> cache; | 48 | std::map<st_thread_t, int> cache; |
| 60 | public: | 49 | public: |
| 61 | - SrsLogContext(); | ||
| 62 | - virtual ~SrsLogContext(); | 50 | + SrsThreadContext(); |
| 51 | + virtual ~SrsThreadContext(); | ||
| 63 | public: | 52 | public: |
| 64 | virtual void generate_id(); | 53 | virtual void generate_id(); |
| 65 | virtual int get_id(); | 54 | virtual int get_id(); |
| 55 | +}; | ||
| 56 | + | ||
| 57 | +/** | ||
| 58 | +* the log level, for example: | ||
| 59 | +* if specified Debug level, all level messages will be logged. | ||
| 60 | +* if specified Warn level, only Warn/Error/Fatal level messages will be logged. | ||
| 61 | +*/ | ||
| 62 | +class SrsLogLevel | ||
| 63 | +{ | ||
| 64 | +public: | ||
| 65 | + // only used for very verbose debug, generally, | ||
| 66 | + // we compile without this level for high performance. | ||
| 67 | + static const int Verbose = 0x01; | ||
| 68 | + static const int Info = 0x02; | ||
| 69 | + static const int Trace = 0x03; | ||
| 70 | + static const int Warn = 0x04; | ||
| 71 | + static const int Error = 0x05; | ||
| 72 | +}; | ||
| 73 | + | ||
| 74 | +/** | ||
| 75 | +* we use memory/disk cache and donot flush when write log. | ||
| 76 | +*/ | ||
| 77 | +class SrsFastLog : public ISrsLog | ||
| 78 | +{ | ||
| 79 | +private: | ||
| 80 | + // defined in SrsLogLevel. | ||
| 81 | + int level; | ||
| 82 | + char* log_data; | ||
| 83 | +public: | ||
| 84 | + SrsFastLog(); | ||
| 85 | + virtual ~SrsFastLog(); | ||
| 66 | public: | 86 | public: |
| 67 | - virtual const char* format_time(); | 87 | + virtual void verbose(const char* tag, int context_id, const char* fmt, ...); |
| 88 | + virtual void info(const char* tag, int context_id, const char* fmt, ...); | ||
| 89 | + virtual void trace(const char* tag, int context_id, const char* fmt, ...); | ||
| 90 | + virtual void warn(const char* tag, int context_id, const char* fmt, ...); | ||
| 91 | + virtual void error(const char* tag, int context_id, const char* fmt, ...); | ||
| 92 | +private: | ||
| 93 | + virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size); | ||
| 94 | + virtual void write_log(char* str_log, int size); | ||
| 68 | }; | 95 | }; |
| 69 | 96 | ||
| 70 | #endif | 97 | #endif |
trunk/src/app/srs_core_log_context.cpp
已删除
100644 → 0
| 1 | -/* | ||
| 2 | -The MIT License (MIT) | ||
| 3 | - | ||
| 4 | -Copyright (c) 2013-2014 winlin | ||
| 5 | - | ||
| 6 | -Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | -this software and associated documentation files (the "Software"), to deal in | ||
| 8 | -the Software without restriction, including without limitation the rights to | ||
| 9 | -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | -the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | -subject to the following conditions: | ||
| 12 | - | ||
| 13 | -The above copyright notice and this permission notice shall be included in all | ||
| 14 | -copies or substantial portions of the Software. | ||
| 15 | - | ||
| 16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | -*/ | ||
| 23 | - | ||
| 24 | -#include <srs_core_log_context.hpp> | ||
| 25 | - | ||
| 26 | -ILogContext* log_context = new SrsLogContext(); | ||
| 27 | - | ||
| 28 | -SrsLogContext::DateTime::DateTime() | ||
| 29 | -{ | ||
| 30 | - memset(time_data, 0, DATE_LEN); | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | -SrsLogContext::DateTime::~DateTime() | ||
| 34 | -{ | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -const char* SrsLogContext::DateTime::format_time() | ||
| 38 | -{ | ||
| 39 | - // clock time | ||
| 40 | - timeval tv; | ||
| 41 | - if (gettimeofday(&tv, NULL) == -1) { | ||
| 42 | - return ""; | ||
| 43 | - } | ||
| 44 | - // to calendar time | ||
| 45 | - struct tm* tm; | ||
| 46 | - if ((tm = localtime(&tv.tv_sec)) == NULL) { | ||
| 47 | - return ""; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - // log header, the time/pid/level of log | ||
| 51 | - // reserved 1bytes for the new line. | ||
| 52 | - snprintf(time_data, DATE_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d", | ||
| 53 | - 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, | ||
| 54 | - (int)(tv.tv_usec / 1000)); | ||
| 55 | - | ||
| 56 | - return time_data; | ||
| 57 | -} | ||
| 58 | - | ||
| 59 | -SrsLogContext::SrsLogContext() | ||
| 60 | -{ | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -SrsLogContext::~SrsLogContext() | ||
| 64 | -{ | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -void SrsLogContext::generate_id() | ||
| 68 | -{ | ||
| 69 | - static int id = 1; | ||
| 70 | - cache[st_thread_self()] = id++; | ||
| 71 | -} | ||
| 72 | - | ||
| 73 | -int SrsLogContext::get_id() | ||
| 74 | -{ | ||
| 75 | - return cache[st_thread_self()]; | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -const char* SrsLogContext::format_time() | ||
| 79 | -{ | ||
| 80 | - return time.format_time(); | ||
| 81 | -} |
| @@ -46,33 +46,33 @@ struct SrsStageInfo : public ISrsReloadHandler | @@ -46,33 +46,33 @@ struct SrsStageInfo : public ISrsReloadHandler | ||
| 46 | 46 | ||
| 47 | update_print_time(); | 47 | update_print_time(); |
| 48 | 48 | ||
| 49 | - config->subscribe(this); | 49 | + _srs_config->subscribe(this); |
| 50 | } | 50 | } |
| 51 | virtual ~SrsStageInfo() | 51 | virtual ~SrsStageInfo() |
| 52 | { | 52 | { |
| 53 | - config->unsubscribe(this); | 53 | + _srs_config->unsubscribe(this); |
| 54 | } | 54 | } |
| 55 | void update_print_time() | 55 | void update_print_time() |
| 56 | { | 56 | { |
| 57 | switch (stage_id) { | 57 | switch (stage_id) { |
| 58 | case SRS_STAGE_PLAY_USER: { | 58 | case SRS_STAGE_PLAY_USER: { |
| 59 | - pithy_print_time_ms = config->get_pithy_print_play(); | 59 | + pithy_print_time_ms = _srs_config->get_pithy_print_play(); |
| 60 | break; | 60 | break; |
| 61 | } | 61 | } |
| 62 | case SRS_STAGE_PUBLISH_USER: { | 62 | case SRS_STAGE_PUBLISH_USER: { |
| 63 | - pithy_print_time_ms = config->get_pithy_print_publish(); | 63 | + pithy_print_time_ms = _srs_config->get_pithy_print_publish(); |
| 64 | break; | 64 | break; |
| 65 | } | 65 | } |
| 66 | case SRS_STAGE_FORWARDER: { | 66 | case SRS_STAGE_FORWARDER: { |
| 67 | - pithy_print_time_ms = config->get_pithy_print_forwarder(); | 67 | + pithy_print_time_ms = _srs_config->get_pithy_print_forwarder(); |
| 68 | break; | 68 | break; |
| 69 | } | 69 | } |
| 70 | case SRS_STAGE_ENCODER: { | 70 | case SRS_STAGE_ENCODER: { |
| 71 | - pithy_print_time_ms = config->get_pithy_print_encoder(); | 71 | + pithy_print_time_ms = _srs_config->get_pithy_print_encoder(); |
| 72 | break; | 72 | break; |
| 73 | } | 73 | } |
| 74 | case SRS_STAGE_HLS: { | 74 | case SRS_STAGE_HLS: { |
| 75 | - pithy_print_time_ms = config->get_pithy_print_hls(); | 75 | + pithy_print_time_ms = _srs_config->get_pithy_print_hls(); |
| 76 | break; | 76 | break; |
| 77 | } | 77 | } |
| 78 | default: { | 78 | default: { |
| @@ -151,13 +151,13 @@ SrsServer::SrsServer() | @@ -151,13 +151,13 @@ SrsServer::SrsServer() | ||
| 151 | { | 151 | { |
| 152 | signal_reload = false; | 152 | signal_reload = false; |
| 153 | 153 | ||
| 154 | - srs_assert(config); | ||
| 155 | - config->subscribe(this); | 154 | + srs_assert(_srs_config); |
| 155 | + _srs_config->subscribe(this); | ||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | SrsServer::~SrsServer() | 158 | SrsServer::~SrsServer() |
| 159 | { | 159 | { |
| 160 | - config->unsubscribe(this); | 160 | + _srs_config->unsubscribe(this); |
| 161 | 161 | ||
| 162 | if (true) { | 162 | if (true) { |
| 163 | std::vector<SrsConnection*>::iterator it; | 163 | std::vector<SrsConnection*>::iterator it; |
| @@ -191,7 +191,7 @@ int SrsServer::initialize() | @@ -191,7 +191,7 @@ int SrsServer::initialize() | ||
| 191 | srs_verbose("st_init success"); | 191 | srs_verbose("st_init success"); |
| 192 | 192 | ||
| 193 | // set current log id. | 193 | // set current log id. |
| 194 | - log_context->generate_id(); | 194 | + _srs_context->generate_id(); |
| 195 | srs_info("log set id success"); | 195 | srs_info("log set id success"); |
| 196 | 196 | ||
| 197 | return ret; | 197 | return ret; |
| @@ -204,7 +204,7 @@ int SrsServer::listen() | @@ -204,7 +204,7 @@ int SrsServer::listen() | ||
| 204 | SrsConfDirective* conf = NULL; | 204 | SrsConfDirective* conf = NULL; |
| 205 | 205 | ||
| 206 | // stream service port. | 206 | // stream service port. |
| 207 | - conf = config->get_listen(); | 207 | + conf = _srs_config->get_listen(); |
| 208 | srs_assert(conf); | 208 | srs_assert(conf); |
| 209 | 209 | ||
| 210 | close_listeners(); | 210 | close_listeners(); |
| @@ -236,7 +236,7 @@ int SrsServer::cycle() | @@ -236,7 +236,7 @@ int SrsServer::cycle() | ||
| 236 | signal_reload = false; | 236 | signal_reload = false; |
| 237 | srs_info("get signal reload, to reload the config."); | 237 | srs_info("get signal reload, to reload the config."); |
| 238 | 238 | ||
| 239 | - if ((ret = config->reload()) != ERROR_SUCCESS) { | 239 | + if ((ret = _srs_config->reload()) != ERROR_SUCCESS) { |
| 240 | srs_error("reload config failed. ret=%d", ret); | 240 | srs_error("reload config failed. ret=%d", ret); |
| 241 | return ret; | 241 | return ret; |
| 242 | } | 242 | } |
| @@ -285,7 +285,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | @@ -285,7 +285,7 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | ||
| 285 | { | 285 | { |
| 286 | int ret = ERROR_SUCCESS; | 286 | int ret = ERROR_SUCCESS; |
| 287 | 287 | ||
| 288 | - int max_connections = config->get_max_connections(); | 288 | + int max_connections = _srs_config->get_max_connections(); |
| 289 | if ((int)conns.size() >= max_connections) { | 289 | if ((int)conns.size() >= max_connections) { |
| 290 | int fd = st_netfd_fileno(client_stfd); | 290 | int fd = st_netfd_fileno(client_stfd); |
| 291 | 291 | ||
| @@ -322,9 +322,3 @@ int SrsServer::on_reload_listen() | @@ -322,9 +322,3 @@ int SrsServer::on_reload_listen() | ||
| 322 | { | 322 | { |
| 323 | return listen(); | 323 | return listen(); |
| 324 | } | 324 | } |
| 325 | - | ||
| 326 | -SrsServer* _server() | ||
| 327 | -{ | ||
| 328 | - static SrsServer server; | ||
| 329 | - return &server; | ||
| 330 | -} |
| @@ -423,12 +423,12 @@ SrsSource::SrsSource(SrsRequest* _req) | @@ -423,12 +423,12 @@ SrsSource::SrsSource(SrsRequest* _req) | ||
| 423 | 423 | ||
| 424 | gop_cache = new SrsGopCache(); | 424 | gop_cache = new SrsGopCache(); |
| 425 | 425 | ||
| 426 | - config->subscribe(this); | 426 | + _srs_config->subscribe(this); |
| 427 | } | 427 | } |
| 428 | 428 | ||
| 429 | SrsSource::~SrsSource() | 429 | SrsSource::~SrsSource() |
| 430 | { | 430 | { |
| 431 | - config->unsubscribe(this); | 431 | + _srs_config->unsubscribe(this); |
| 432 | 432 | ||
| 433 | if (true) { | 433 | if (true) { |
| 434 | std::vector<SrsConsumer*>::iterator it; | 434 | std::vector<SrsConsumer*>::iterator it; |
| @@ -473,7 +473,7 @@ int SrsSource::on_reload_gop_cache(string vhost) | @@ -473,7 +473,7 @@ int SrsSource::on_reload_gop_cache(string vhost) | ||
| 473 | } | 473 | } |
| 474 | 474 | ||
| 475 | // gop cache changed. | 475 | // gop cache changed. |
| 476 | - bool enabled_cache = config->get_gop_cache(vhost); | 476 | + bool enabled_cache = _srs_config->get_gop_cache(vhost); |
| 477 | 477 | ||
| 478 | srs_trace("vhost %s gop_cache changed to %d, source url=%s", | 478 | srs_trace("vhost %s gop_cache changed to %d, source url=%s", |
| 479 | vhost.c_str(), enabled_cache, req->get_stream_url().c_str()); | 479 | vhost.c_str(), enabled_cache, req->get_stream_url().c_str()); |
| @@ -491,7 +491,7 @@ int SrsSource::on_reload_queue_length(string vhost) | @@ -491,7 +491,7 @@ int SrsSource::on_reload_queue_length(string vhost) | ||
| 491 | return ret; | 491 | return ret; |
| 492 | } | 492 | } |
| 493 | 493 | ||
| 494 | - double queue_size = config->get_queue_length(req->vhost); | 494 | + double queue_size = _srs_config->get_queue_length(req->vhost); |
| 495 | 495 | ||
| 496 | if (true) { | 496 | if (true) { |
| 497 | std::vector<SrsConsumer*>::iterator it; | 497 | std::vector<SrsConsumer*>::iterator it; |
| @@ -913,7 +913,7 @@ void SrsSource::on_unpublish() | @@ -913,7 +913,7 @@ void SrsSource::on_unpublish() | ||
| 913 | consumer = new SrsConsumer(this); | 913 | consumer = new SrsConsumer(this); |
| 914 | consumers.push_back(consumer); | 914 | consumers.push_back(consumer); |
| 915 | 915 | ||
| 916 | - double queue_size = config->get_queue_length(req->vhost); | 916 | + double queue_size = _srs_config->get_queue_length(req->vhost); |
| 917 | consumer->set_queue_size(queue_size); | 917 | consumer->set_queue_size(queue_size); |
| 918 | 918 | ||
| 919 | if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) { | 919 | if (cache_metadata && (ret = consumer->enqueue(cache_metadata->copy(), sample_rate, frame_rate)) != ERROR_SUCCESS) { |
| @@ -962,14 +962,14 @@ int SrsSource::create_forwarders() | @@ -962,14 +962,14 @@ int SrsSource::create_forwarders() | ||
| 962 | { | 962 | { |
| 963 | int ret = ERROR_SUCCESS; | 963 | int ret = ERROR_SUCCESS; |
| 964 | 964 | ||
| 965 | - SrsConfDirective* conf = config->get_forward(req->vhost); | 965 | + SrsConfDirective* conf = _srs_config->get_forward(req->vhost); |
| 966 | for (int i = 0; conf && i < (int)conf->args.size(); i++) { | 966 | for (int i = 0; conf && i < (int)conf->args.size(); i++) { |
| 967 | std::string forward_server = conf->args.at(i); | 967 | std::string forward_server = conf->args.at(i); |
| 968 | 968 | ||
| 969 | SrsForwarder* forwarder = new SrsForwarder(this); | 969 | SrsForwarder* forwarder = new SrsForwarder(this); |
| 970 | forwarders.push_back(forwarder); | 970 | forwarders.push_back(forwarder); |
| 971 | 971 | ||
| 972 | - double queue_size = config->get_queue_length(req->vhost); | 972 | + double queue_size = _srs_config->get_queue_length(req->vhost); |
| 973 | forwarder->set_queue_size(queue_size); | 973 | forwarder->set_queue_size(queue_size); |
| 974 | 974 | ||
| 975 | if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) { | 975 | if ((ret = forwarder->on_publish(req, forward_server)) != ERROR_SUCCESS) { |
| @@ -113,7 +113,7 @@ void SrsThread::thread_cycle() | @@ -113,7 +113,7 @@ void SrsThread::thread_cycle() | ||
| 113 | 113 | ||
| 114 | srs_assert(handler); | 114 | srs_assert(handler); |
| 115 | 115 | ||
| 116 | - log_context->generate_id(); | 116 | + _srs_context->generate_id(); |
| 117 | srs_trace("thread cycle start"); | 117 | srs_trace("thread cycle start"); |
| 118 | 118 | ||
| 119 | handler->on_end_cycle(); | 119 | handler->on_end_cycle(); |
| @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | // current release version | 31 | // current release version |
| 32 | -#define RTMP_SIG_SRS_VERSION "0.9.7" | 32 | +#define RTMP_SIG_SRS_VERSION "0.9.8" |
| 33 | // server info. | 33 | // server info. |
| 34 | #define RTMP_SIG_SRS_KEY "srs" | 34 | #define RTMP_SIG_SRS_KEY "srs" |
| 35 | #define RTMP_SIG_SRS_ROLE "origin server" | 35 | #define RTMP_SIG_SRS_ROLE "origin server" |
| @@ -23,11 +23,48 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -23,11 +23,48 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | 23 | ||
| 24 | #include <srs_kernel_log.hpp> | 24 | #include <srs_kernel_log.hpp> |
| 25 | 25 | ||
| 26 | -ILogContext::ILogContext() | 26 | +ISrsLog::ISrsLog() |
| 27 | { | 27 | { |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | -ILogContext::~ILogContext() | 30 | +ISrsLog::~ISrsLog() |
| 31 | { | 31 | { |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | +void ISrsLog::verbose(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | ||
| 35 | +{ | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +void ISrsLog::info(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | ||
| 39 | +{ | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +void ISrsLog::trace(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | ||
| 43 | +{ | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +void ISrsLog::warn(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | ||
| 47 | +{ | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +void ISrsLog::error(const char* /*tag*/, int /*context_id*/, const char* /*fmt*/, ...) | ||
| 51 | +{ | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +ISrsThreadContext::ISrsThreadContext() | ||
| 55 | +{ | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +ISrsThreadContext::~ISrsThreadContext() | ||
| 59 | +{ | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +void ISrsThreadContext::generate_id() | ||
| 63 | +{ | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +int ISrsThreadContext::get_id() | ||
| 67 | +{ | ||
| 68 | + return 0; | ||
| 69 | +} | ||
| 70 | + |
| @@ -35,43 +35,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -35,43 +35,78 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 35 | #include <errno.h> | 35 | #include <errno.h> |
| 36 | #include <string.h> | 36 | #include <string.h> |
| 37 | 37 | ||
| 38 | -// the context for multiple clients. | ||
| 39 | -class ILogContext | 38 | +/** |
| 39 | +* the log interface provides method to write log. | ||
| 40 | +* but we provides some macro, which enable us to disable the log when compile. | ||
| 41 | +* @see also SmtDebug/SmtTrace/SmtWarn/SmtError which is corresponding to Debug/Trace/Warn/Fatal. | ||
| 42 | +*/ | ||
| 43 | +class ISrsLog | ||
| 40 | { | 44 | { |
| 41 | public: | 45 | public: |
| 42 | - ILogContext(); | ||
| 43 | - virtual ~ILogContext(); | 46 | + ISrsLog(); |
| 47 | + virtual ~ISrsLog(); | ||
| 44 | public: | 48 | public: |
| 45 | - virtual void generate_id() = 0; | ||
| 46 | - virtual int get_id() = 0; | 49 | + /** |
| 50 | + * log for verbose, very verbose information. | ||
| 51 | + */ | ||
| 52 | + virtual void verbose(const char* tag, int context_id, const char* fmt, ...); | ||
| 53 | + /** | ||
| 54 | + * log for debug, detail information. | ||
| 55 | + */ | ||
| 56 | + virtual void info(const char* tag, int context_id, const char* fmt, ...); | ||
| 57 | + /** | ||
| 58 | + * log for trace, important information. | ||
| 59 | + */ | ||
| 60 | + virtual void trace(const char* tag, int context_id, const char* fmt, ...); | ||
| 61 | + /** | ||
| 62 | + * log for warn, warn is something should take attention, but not a error. | ||
| 63 | + */ | ||
| 64 | + virtual void warn(const char* tag, int context_id, const char* fmt, ...); | ||
| 65 | + /** | ||
| 66 | + * log for error, something error occur, do something about the error, ie. close the connection, | ||
| 67 | + * but we will donot abort the program. | ||
| 68 | + */ | ||
| 69 | + virtual void error(const char* tag, int context_id, const char* fmt, ...); | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +// the context for multiple clients. | ||
| 73 | +class ISrsThreadContext | ||
| 74 | +{ | ||
| 47 | public: | 75 | public: |
| 48 | - virtual const char* format_time() = 0; | 76 | + ISrsThreadContext(); |
| 77 | + virtual ~ISrsThreadContext(); | ||
| 78 | +public: | ||
| 79 | + virtual void generate_id(); | ||
| 80 | + virtual int get_id(); | ||
| 49 | }; | 81 | }; |
| 50 | 82 | ||
| 83 | +// user must provides a log object | ||
| 84 | +extern ISrsLog* _srs_log; | ||
| 85 | + | ||
| 51 | // user must implements the LogContext and define a global instance. | 86 | // user must implements the LogContext and define a global instance. |
| 52 | -extern ILogContext* log_context; | 87 | +extern ISrsThreadContext* _srs_context; |
| 53 | 88 | ||
| 54 | // donot print method | 89 | // donot print method |
| 55 | -#if 0 | ||
| 56 | - #define srs_verbose(msg, ...) printf("[%s][%d][verbs] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 57 | - #define srs_info(msg, ...) printf("[%s][%d][infos] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 58 | - #define srs_trace(msg, ...) printf("[%s][%d][trace] ", log_context->format_time(), log_context->get_id());printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 59 | - #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") | ||
| 60 | - #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") | 90 | +#if 1 |
| 91 | + #define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 92 | + #define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 93 | + #define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 94 | + #define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 95 | + #define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 61 | // use __FUNCTION__ to print c method | 96 | // use __FUNCTION__ to print c method |
| 62 | -#elif 1 | ||
| 63 | - #define srs_verbose(msg, ...) printf("[%s][%d][verbs][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 64 | - #define srs_info(msg, ...) printf("[%s][%d][infos][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 65 | - #define srs_trace(msg, ...) printf("[%s][%d][trace][%s] ", log_context->format_time(), log_context->get_id(), __FUNCTION__);printf(msg, ##__VA_ARGS__);printf("\n") | ||
| 66 | - #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") | ||
| 67 | - #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") | 97 | +#elif 0 |
| 98 | + #define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 99 | + #define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 100 | + #define srs_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 101 | + #define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 102 | + #define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 68 | // use __PRETTY_FUNCTION__ to print c++ class:method | 103 | // use __PRETTY_FUNCTION__ to print c++ class:method |
| 69 | #else | 104 | #else |
| 70 | - #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") | ||
| 71 | - #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") | ||
| 72 | - #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") | ||
| 73 | - #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") | ||
| 74 | - #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") | 105 | + #define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) |
| 106 | + #define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 107 | + #define srs_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 108 | + #define srs_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 109 | + #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) | ||
| 75 | #endif | 110 | #endif |
| 76 | 111 | ||
| 77 | #if 1 | 112 | #if 1 |
| @@ -35,6 +35,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -35,6 +35,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 35 | #include <srs_core_autofree.hpp> | 35 | #include <srs_core_autofree.hpp> |
| 36 | #include <srs_kernel_stream.hpp> | 36 | #include <srs_kernel_stream.hpp> |
| 37 | #include <srs_core_socket.hpp> | 37 | #include <srs_core_socket.hpp> |
| 38 | +#include <srs_core_config.hpp> | ||
| 39 | +#include <srs_core_log.hpp> | ||
| 40 | +#include <srs_core_server.hpp> | ||
| 41 | + | ||
| 42 | +// kernel module. | ||
| 43 | +ISrsLog* _srs_log = new SrsFastLog(); | ||
| 44 | +ISrsThreadContext* _srs_context = new ISrsThreadContext(); | ||
| 45 | +// app module. | ||
| 46 | +SrsConfig* _srs_config = NULL; | ||
| 47 | +SrsServer* _srs_server = NULL; | ||
| 38 | 48 | ||
| 39 | #include <st.h> | 49 | #include <st.h> |
| 40 | 50 |
| @@ -25,6 +25,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -25,6 +25,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 25 | #include <srs_kernel_error.hpp> | 25 | #include <srs_kernel_error.hpp> |
| 26 | #include <srs_core_server.hpp> | 26 | #include <srs_core_server.hpp> |
| 27 | #include <srs_core_config.hpp> | 27 | #include <srs_core_config.hpp> |
| 28 | +#include <srs_core_log.hpp> | ||
| 29 | + | ||
| 30 | +// kernel module. | ||
| 31 | +ISrsLog* _srs_log = new SrsFastLog(); | ||
| 32 | +ISrsThreadContext* _srs_context = new SrsThreadContext(); | ||
| 33 | +// app module. | ||
| 34 | +SrsConfig* _srs_config = new SrsConfig(); | ||
| 35 | +SrsServer* _srs_server = new SrsServer(); | ||
| 28 | 36 | ||
| 29 | #include <stdlib.h> | 37 | #include <stdlib.h> |
| 30 | #include <signal.h> | 38 | #include <signal.h> |
| @@ -32,7 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -32,7 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 32 | void handler(int signo) | 40 | void handler(int signo) |
| 33 | { | 41 | { |
| 34 | srs_trace("get a signal, signo=%d", signo); | 42 | srs_trace("get a signal, signo=%d", signo); |
| 35 | - _server()->on_signal(signo); | 43 | + _srs_server->on_signal(signo); |
| 36 | } | 44 | } |
| 37 | 45 | ||
| 38 | int main(int argc, char** argv){ | 46 | int main(int argc, char** argv){ |
| @@ -40,21 +48,21 @@ int main(int argc, char** argv){ | @@ -40,21 +48,21 @@ int main(int argc, char** argv){ | ||
| 40 | 48 | ||
| 41 | signal(SIGNAL_RELOAD, handler); | 49 | signal(SIGNAL_RELOAD, handler); |
| 42 | 50 | ||
| 43 | - if ((ret = config->parse_options(argc, argv)) != ERROR_SUCCESS) { | 51 | + if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { |
| 44 | return ret; | 52 | return ret; |
| 45 | } | 53 | } |
| 46 | 54 | ||
| 47 | - if ((ret = _server()->initialize()) != ERROR_SUCCESS) { | 55 | + if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { |
| 48 | return ret; | 56 | return ret; |
| 49 | } | 57 | } |
| 50 | 58 | ||
| 51 | - // TODO: create log dir in config->get_log_dir() | 59 | + // TODO: create log dir in _srs_config->get_log_dir() |
| 52 | 60 | ||
| 53 | - if ((ret = _server()->listen()) != ERROR_SUCCESS) { | 61 | + if ((ret = _srs_server->listen()) != ERROR_SUCCESS) { |
| 54 | return ret; | 62 | return ret; |
| 55 | } | 63 | } |
| 56 | 64 | ||
| 57 | - if ((ret = _server()->cycle()) != ERROR_SUCCESS) { | 65 | + if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) { |
| 58 | return ret; | 66 | return ret; |
| 59 | } | 67 | } |
| 60 | 68 |
| @@ -52,8 +52,8 @@ file | @@ -52,8 +52,8 @@ file | ||
| 52 | ..\app\srs_core_hls.cpp, | 52 | ..\app\srs_core_hls.cpp, |
| 53 | ..\app\srs_core_http.hpp, | 53 | ..\app\srs_core_http.hpp, |
| 54 | ..\app\srs_core_http.cpp, | 54 | ..\app\srs_core_http.cpp, |
| 55 | - ..\app\srs_core_log_context.hpp, | ||
| 56 | - ..\app\srs_core_log_context.cpp, | 55 | + ..\app\srs_core_log.hpp, |
| 56 | + ..\app\srs_core_log.cpp, | ||
| 57 | ..\app\srs_core_refer.hpp, | 57 | ..\app\srs_core_refer.hpp, |
| 58 | ..\app\srs_core_refer.cpp, | 58 | ..\app\srs_core_refer.cpp, |
| 59 | ..\app\srs_core_pithy_print.hpp, | 59 | ..\app\srs_core_pithy_print.hpp, |
-
请 注册 或 登录 后发表评论